@@ -15,12 +15,42 @@ type DbRef = {
1515export type Ref = LocalRef | DbRef ;
1616
1717// Common attributes for most types
18- type CrossAppBase = LocalRef & {
18+ type BaseAttributes = {
1919 createdAt : Date ;
2020 modifiedAt ?: Date ;
2121 author : Ref ;
2222} ;
2323
24+ // Common attributes for most types
25+ type CrossAppBase = LocalRef & BaseAttributes ;
26+
27+ type SpaceRef = DbRef | { url : string ; sourceApp : Enums < "Platform" > } ;
28+
29+ export type LocalOrRemoteRef =
30+ | LocalRef
31+ | {
32+ localId : string ;
33+ // infer space from context if absent.
34+ space ?: SpaceRef ;
35+ }
36+ | {
37+ // A string that contains combined space and localId
38+ rid : string ;
39+ } ;
40+
41+ type WithOptionalLocalRef < Extra > = ( LocalRef & Extra ) | Extra ;
42+
43+ /*
44+ Note on Inline vs Standalone:
45+ The db `upsert_...` functions allow to put some objects inline inside related objects instead of passing a reference.
46+ Those objects will either get upserted or resolved by the upsert functions.
47+ When we provide an inline object, some shared attributes can be specified in the enclosing object.
48+ Hence, the inline version of the object has less required attributes than the standalone version.
49+ */
50+
51+ // Partial version of above, utility type for functions that can receive many of the above.
52+ export type InlineAbstractBase = WithOptionalLocalRef < Partial < BaseAttributes > > ;
53+
2454// A node schema
2555export type CrossAppNodeSchema = CrossAppBase & {
2656 label : string ;
@@ -50,25 +80,85 @@ export type CrossAppEmbedding = {
5080 embedding ?: Enums < "EmbeddingName" > ;
5181} ;
5282
53- // A Content object. It can be put inline inside a concept.
54- // Missing CrossAppBase attributes are inferred from enclosing object.
55- export type InlineCrossAppContent = Partial < CrossAppBase > & {
83+ // An asset reference
84+ export type CrossAppAsset = {
85+ content : ArrayBuffer ;
86+ mimetype : string ;
87+ createdAt : Date ;
88+ modifiedAt ?: Date ;
89+ filepath ?: string ;
90+ } ;
91+
92+ // Document fields
93+ type CrossAppDocumentExtras = {
94+ // MIME type
95+ contentType : string ;
96+ } ;
97+
98+ // An inline document, to put inside Content or Concept.
99+ // Currently, we fully infer Documents (setting content_as_document=true)
100+ // since our nodes are pages; so this is not used yet.
101+ export type InlineCrossAppDocument = WithOptionalLocalRef <
102+ Partial < BaseAttributes > & CrossAppDocumentExtras
103+ > ;
104+
105+ // A standalone document, for `upsert_documents`. Not currently used.
106+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
107+ type StandaloneCrossAppDocument = LocalRef &
108+ BaseAttributes &
109+ CrossAppDocumentExtras ;
110+
111+ // Content fields
112+ type CrossAppContentExtras = {
56113 value : string ;
57114 embedding ?: CrossAppEmbedding ;
58115 scale ?: Enums < "Scale" > ;
116+ partOf ?: Ref ;
117+ assets ?: CrossAppAsset [ ] ;
118+ document ?: InlineCrossAppDocument ;
59119 contentType ?: ContentType ;
60120} ;
61121
122+ // An inline content object, to be put inside a Concept.
123+ export type InlineCrossAppContent = Partial < CrossAppBase > &
124+ CrossAppContentExtras ;
125+
126+ // A standalone content object, for `upsert_content`
127+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
128+ type StandaloneCrossAppContent = LocalRef &
129+ BaseAttributes &
130+ CrossAppContentExtras ;
131+
62132// An inline Content with obligatory typing
63133export type InlineCrossAppTypedContent = InlineCrossAppContent & {
64134 contentType : ContentType ;
65135} ;
66136
137+ // A platform account
138+ // either standalone for `upsert_account_in_space`,
139+ // or inline in Content or Concept
140+ export type CrossAppAccount = {
141+ accountLocalId : string ;
142+ name ?: string ;
143+ email ?: string ;
144+ // agentType: Enums<"AgentType"> = 'person' // inferred
145+ // dgAccount?: string; // uuid
146+ } ;
147+
67148// A node instance
68149export type CrossAppNode = CrossAppBase & {
69150 nodeType : Ref ;
70151 content : {
71152 direct : InlineCrossAppContent ;
72153 full : InlineCrossAppTypedContent ;
73154 } ;
155+ // This is a way to define document globally for all contents
156+ document ?: InlineCrossAppDocument ;
157+ } ;
158+
159+ // A relation instance
160+ export type CrossAppRelation = CrossAppBase & {
161+ relationType : Ref ;
162+ source : LocalOrRemoteRef ;
163+ destination : LocalOrRemoteRef ;
74164} ;
0 commit comments