diff --git a/packages/database/src/crossAppContracts.ts b/packages/database/src/crossAppContracts.ts index c996332c3..94f97f9d7 100644 --- a/packages/database/src/crossAppContracts.ts +++ b/packages/database/src/crossAppContracts.ts @@ -1,5 +1,5 @@ import type { ContentType } from "@repo/content-model"; -import { Enums } from "./dbTypes"; +import { Enums, type Json } from "./dbTypes"; export type LocalRef = { // This localId is expected to be unique within the current space @@ -21,18 +21,67 @@ export type CrossAppBase = LocalRef & { author: Ref; }; +export type CrossAppSchemaBase = CrossAppBase & { + metadata?: Json; +}; + +type SpaceRef = DbRef | { url: string; sourceApp: Enums<"Platform"> }; + +export type LocalOrRemoteRef = + | LocalRef + | { + localId: string; + // infer space from context if absent. + space?: SpaceRef; + } + | { + // A string that contains combined space and localId + rid: string; + }; + +// A node schema +export type CrossAppNodeSchema = CrossAppSchemaBase & { + label: string; + template?: string; + templateTitle?: string; +}; + +// A relation type schema +export type CrossAppRelationTypeSchema = CrossAppSchemaBase & { + label: string; + complement: string; + // should we add colour? format? +}; + +// A relation triple schema +export type CrossAppRelationTripleSchema = CrossAppSchemaBase & { + label: string; + complement: string; + relation?: Ref | CrossAppRelationTypeSchema; + sourceType: Ref; + destinationType: Ref; +}; + // An inline vector semantic embedding export type CrossAppEmbedding = { value: number[]; embedding?: Enums<"EmbeddingName">; }; +// An inline document, to put inside Content (or Concept) +export type InlineCrossAppDocument = Partial & { + // MIME type + contentType: string; +}; + // A Content object. It can be put inline inside a concept. // Missing CrossAppBase attributes are inferred from enclosing object. export type InlineCrossAppContent = Partial & { value: string; embedding?: CrossAppEmbedding; scale?: Enums<"Scale">; + partOf?: Ref; + document?: InlineCrossAppDocument; contentType?: ContentType; }; @@ -48,4 +97,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; };