import type { ModelValue } from "@canvas-js/modeldb"; import type { Action, Awaitable } from "@canvas-js/interfaces"; export type { ModelValue } from "@canvas-js/modeldb"; import type { ModelInit as DbModelInit, ModelSchema as DbModelSchema, DeriveModelTypes as DbDeriveModelTypes, DeriveModelType as DbDeriveModelType } from "@canvas-js/modeldb"; import { Contract } from "@canvas-js/core/contract"; import { SignedMessage } from "@canvas-js/gossiplog"; import { JSValue } from "@canvas-js/utils"; export type RulesInit = { create: string | boolean; update: string | boolean; delete: string | boolean; }; export type ModelInit = DbModelInit<{ $rules?: RulesInit; }>; export type ModelSchema = DbModelSchema<{ $rules?: RulesInit; }>; export type DeriveModelType = DbDeriveModelType; export type DeriveModelTypes = DbDeriveModelTypes; export type ContractClass = Contract & Record>> = { topic: string; models: ModelsT; new (...args: JSValue[]): InstanceT; }; export type ContractAction = (this: Contract, ...args: Args) => Promise; export type TypeError = Message; export type ActionAPI = (...args: Args) => Promise & { result: Result; }>; export type GetActionsType> = { [K in Exclude>]: InstanceT[K] extends ContractAction ? ActionAPI : InstanceT[K] extends (this: Contract, ...args: infer Args) => infer Result ? ActionAPI : never; }; export type ModelAPI = Record> = { id: () => string; random: () => number; get: (model: T, key: string) => Promise; set: (model: T, value: ModelTypes[T]) => Promise; delete: (model: T, key: string) => Promise; create: (model: T, value: ModelTypes[T]) => Promise; update: (model: T, value: Partial) => Promise; merge: (model: T, value: Partial) => Promise; link: (modelPath: `${T}.${string}`, source: string, target: string) => Promise; unlink: (modelPath: `${T}.${string}`, source: string, target: string) => Promise; transaction: (callback: () => Awaitable) => Promise; }; export type ActionContext = Record> = { db: ModelAPI; id: string; did: `did:${string}`; address: string; blockhash: string | null; timestamp: number; publicKey: string; };