import { JunctionEdgeSpec, NodeSpec } from '@aphro/schema-api'; import { SID_of } from '@strut/sid'; import { Context } from './context.js'; type Disposer = () => void; export type ModelCreate, D extends {}> = { createFrom(context: Context, data: D, raw?: boolean): M; }; export type NodeSpecWithCreate, D extends {}> = ModelCreate & NodeSpec; export type EdgeSpecWithCreate, D extends {}> = ModelCreate & JunctionEdgeSpec; export type ModelSpecWithCreate, D extends {}> = ModelCreate & (NodeSpec | JunctionEdgeSpec); export interface IModel { readonly id: SID_of; readonly spec: ModelSpecWithCreate; subscribe(c: () => void): Disposer; subscribeTo(keys: (keyof T)[], c: () => void): Disposer; destroy(): void; // Internal only APIs. Exposed since TS doesn't understand package friends. // TODO: Or does it? I can extend a type that exists in a package from another package... // So why not do that to make these methods local to the package(s) that need them? _get(key: K): T[K]; _d(): T; _merge(newData: Partial): [Partial, Set<() => void>]; _isNoop(updates: Partial): boolean; } export interface INode extends IModel { readonly spec: NodeSpecWithCreate; } export interface IEdge extends IModel { readonly spec: EdgeSpecWithCreate; }