import { wrap } from "comlink"
import { nanoid } from "nanoid"
import { DataType } from "./DataType.enum"
import { Model } from "./models/Model"
export interface DataApi {
add
(model: Model): Promise
update>(model: T): Promise
remove(id: string): Promise
get>(id: string): Promise
getOrCreate>(
id: string,
initialValue: T
): Promise
getAll>(params: {
prefix?: string
includeDocs?: boolean
includeAttachments?: boolean
keys?: string[]
}): Promise
}
export const generateId = (type?: DataType | string, id?: string): string => {
if (!type) return id || nanoid()
return `${type}-${id || nanoid()}`
}
import DataWorker from "./data.worker?worker"
export const data = wrap(new DataWorker()) as unknown as DataApi