|
|
|
@ -45,6 +45,13 @@ export interface ExtensionManifest {
|
|
|
|
|
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 id: string |
|
|
|
|
abstract uiKey: number |
|
|
|
@ -52,7 +59,7 @@ abstract class ExtensionType {
|
|
|
|
|
abstract fkUserId: string |
|
|
|
|
abstract extensionId: string |
|
|
|
|
abstract title: string |
|
|
|
|
abstract kvStore: any |
|
|
|
|
abstract kvStore: IKvStore<any> |
|
|
|
|
abstract meta: any |
|
|
|
|
abstract order: number |
|
|
|
|
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 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.data = data || {} |
|
|
|
|
} |
|
|
|
@ -302,9 +309,9 @@ export const useExtensions = createSharedComposable(() => {
|
|
|
|
|
return updateExtension(this._id, { kv_store: this.data }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete(key: string) { |
|
|
|
|
async delete(key: string) { |
|
|
|
|
delete this.data[key] |
|
|
|
|
return updateExtension(this._id, { kv_store: this.data }) |
|
|
|
|
await updateExtension(this._id, { kv_store: this.data }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
serialize() { |
|
|
|
|