Browse Source

fix(extensions): typings for KvStore (#9932)

* fix(extensions): typings for KvStore

* Update useExtensions.ts
pull/9960/head
Aman Desai 1 week ago committed by GitHub
parent
commit
5fa827fd18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 19
      packages/nc-gui/composables/useExtensions.ts

19
packages/nc-gui/composables/useExtensions.ts

@ -45,6 +45,13 @@ export interface ExtensionManifest {
disabled?: boolean disabled?: boolean
} }
export interface IKvStore<T extends Record<string, any>> {
get<K extends keyof T>(key: K): T[K] | null;
set<K extends keyof T>(key: K, value: T[K]): Promise<void>;
delete<K extends keyof T>(key: K): Promise<void>;
serialize(): Record<string, T[keyof T]>;
}
abstract class ExtensionType { abstract class ExtensionType {
abstract id: string abstract id: string
abstract uiKey: number abstract uiKey: number
@ -52,7 +59,7 @@ abstract class ExtensionType {
abstract fkUserId: string abstract fkUserId: string
abstract extensionId: string abstract extensionId: string
abstract title: string abstract title: string
abstract kvStore: any abstract kvStore: IKvStore<any>
abstract meta: any abstract meta: any
abstract order: number abstract order: number
abstract setTitle(title: string): Promise<any> abstract setTitle(title: string): Promise<any>
@ -284,11 +291,11 @@ export const useExtensions = createSharedComposable(() => {
} }
} }
class KvStore { class KvStore<T = any> implements IKvStore<T> {
private _id: string private _id: string
private data: Record<string, any> private data: Record<string, T>
constructor(id: string, data: any) { constructor(id: string, data: Record<string, T>) {
this._id = id this._id = id
this.data = data || {} this.data = data || {}
} }
@ -302,9 +309,9 @@ export const useExtensions = createSharedComposable(() => {
return updateExtension(this._id, { kv_store: this.data }) return updateExtension(this._id, { kv_store: this.data })
} }
delete(key: string) { async delete(key: string) {
delete this.data[key] delete this.data[key]
return updateExtension(this._id, { kv_store: this.data }) await updateExtension(this._id, { kv_store: this.data })
} }
serialize() { serialize() {

Loading…
Cancel
Save