diff --git a/packages/database/src/crossAppContracts.ts b/packages/database/src/crossAppContracts.ts index 0d5c52b6c..446013da1 100644 --- a/packages/database/src/crossAppContracts.ts +++ b/packages/database/src/crossAppContracts.ts @@ -14,6 +14,28 @@ type DbRef = { // Generalized reference export type Ref = LocalRef | DbRef; +type SpaceRef = DbRef | { url: string; sourceApp: Enums<"Platform"> }; + +// A potentially cross-space reference +export type LocalOrRemoteRef = + | DbRef + | { + localId: string; + // Treat as LocalRef if space is absent + space?: SpaceRef; + // make the options mutually exclusive + dbId?: never; + rid?: never; + } + | { + // A string that contains combined space and localId + rid: string; + // make the options mutually exclusive + dbId?: never; + localId?: never; + space?: never; + }; + // Common attributes for most types export type CrossAppBase = LocalRef & { createdAt: Date; @@ -63,20 +85,71 @@ export type CrossAppEmbedding = { embedding?: Enums<"EmbeddingName">; }; -// A Content object. It can be put inline inside a concept. -// Missing CrossAppBase attributes are inferred from enclosing object. -export type InlineCrossAppContent = Partial & { +// An asset reference +export type CrossAppAsset = { + content: ArrayBuffer; + mimetype: string; + createdAt: Date; + modifiedAt?: Date; + filepath?: string; +}; + +// Document fields +type CrossAppDocumentExtras = { + // MIME type + contentType: string; +}; + +// An inline document, to put inside Content or Concept. +// Currently, we fully infer Documents (setting content_as_document=true) +// since our nodes are pages; so this is not used yet. +export type InlineCrossAppDocument = Partial & + CrossAppDocumentExtras; + +// A standalone document, for `upsert_documents`. Not currently used. +// eslint-disable-next-line @typescript-eslint/no-unused-vars +type StandaloneCrossAppDocument = LocalRef & + CrossAppBase & + CrossAppDocumentExtras; + +// Content fields +type CrossAppContentExtras = { value: string; embedding?: CrossAppEmbedding; scale?: Enums<"Scale">; + partOf?: Ref; + assets?: CrossAppAsset[]; + document?: InlineCrossAppDocument; contentType?: ContentType; }; +// A Content object. It can be put inline inside a concept. +// Missing CrossAppBase attributes are inferred from enclosing object. +export type InlineCrossAppContent = Partial & + CrossAppContentExtras; + +// A standalone content object, for `upsert_content` +// eslint-disable-next-line @typescript-eslint/no-unused-vars +type StandaloneCrossAppContent = LocalRef & + CrossAppBase & + CrossAppContentExtras; + // An inline Content with obligatory typing type InlineCrossAppTypedContent = InlineCrossAppContent & { contentType: ContentType; }; +// A platform account +// either standalone for `upsert_account_in_space`, +// or inline in Content or Concept +export type CrossAppAccount = { + accountLocalId: string; + name?: string; + email?: string; + // agentType: Enums<"AgentType"> = 'person' // inferred + // dgAccount?: string; // uuid +}; + // A node instance export type CrossAppNode = CrossAppBase & { nodeType: Ref; @@ -84,4 +157,13 @@ export type CrossAppNode = CrossAppBase & { direct: InlineCrossAppContent; full: InlineCrossAppTypedContent; }; + // This is a way to define document globally for all contents + document?: InlineCrossAppDocument; +}; + +// A relation instance +export type CrossAppRelation = CrossAppBase & { + relationType: Ref; + source: LocalOrRemoteRef; + destination: LocalOrRemoteRef; };