@@ -3,12 +3,14 @@ import {
33 Ref ,
44 CrossAppEmbedding ,
55 InlineCrossAppContent ,
6+ StandaloneCrossAppContent ,
67 CrossAppBase ,
78 CrossAppNode ,
89} from "../crossAppContracts" ;
910import { LocalContentDataInput , LocalConceptDataInput } from "../inputTypes" ;
1011import { Enums , CompositeTypes } from "../dbTypes" ;
1112
13+ type ContentDataInput = CompositeTypes < "content_local_input" > ;
1214type InlineEmbeddingInput = CompositeTypes < "inline_embedding_input" > ;
1315type InlineAbstractBase = Partial < CrossAppBase > ;
1416
@@ -39,6 +41,47 @@ const decodeRef = <DbVarName extends string, LocalVarName extends string>(
3941 return decodeLocalRef ( ref , localVarName ) ;
4042} ;
4143
44+ const decodeRefWithNulls = <
45+ DbVarName extends string ,
46+ LocalVarName extends string ,
47+ > (
48+ ref : Ref | undefined ,
49+ dbVarName : DbVarName ,
50+ localVarName : LocalVarName ,
51+ ) : Record < DbVarName , number | null > & Record < LocalVarName , string | null > => {
52+ return {
53+ [ dbVarName ] : ref && "dbId" in ref ? ref . dbId : null ,
54+ [ localVarName ] : ref && "localId" in ref ? ref . localId : null ,
55+ } as Record < DbVarName , number | null > & Record < LocalVarName , string | null > ;
56+ } ;
57+
58+ const decodeRefWithInlineNulls = <
59+ DbVarName extends string ,
60+ LocalVarName extends string ,
61+ InlineVarName extends string ,
62+ > ( {
63+ ref,
64+ dbVarName,
65+ localVarName,
66+ inlineVarName,
67+ } : {
68+ ref ?: Ref ;
69+ dbVarName : DbVarName ;
70+ localVarName : LocalVarName ;
71+ inlineVarName : InlineVarName ;
72+ } ) : Record < DbVarName , number | null > &
73+ Record < LocalVarName , string | null > &
74+ Record < InlineVarName , null > => {
75+ return {
76+ [ dbVarName ] : null ,
77+ [ localVarName ] : null ,
78+ [ inlineVarName ] : null ,
79+ ...decodeRef ( ref , dbVarName , localVarName ) ,
80+ } as Record < DbVarName , number | null > &
81+ Record < LocalVarName , string | null > &
82+ Record < InlineVarName , null > ;
83+ } ;
84+
4285const crossAppEmbeddingToDbEmbedding = (
4386 embedding : CrossAppEmbedding | undefined ,
4487) : InlineEmbeddingInput | undefined =>
@@ -76,6 +119,43 @@ const inlineCrossAppContentToDbContent = (
76119 } ) ;
77120} ;
78121
122+ export const crossAppStandaloneContentToDbContent = (
123+ content : StandaloneCrossAppContent | undefined ,
124+ space : Ref ,
125+ ) : ContentDataInput | undefined => {
126+ if ( content === undefined ) return undefined ;
127+ return {
128+ source_local_id : content . localId ,
129+ text : content . value ,
130+ scale : content . scale || "document" ,
131+ content_type : content . contentType || "text/plain" ,
132+ variant : content . variant ,
133+ created : content . createdAt . toISOString ( ) ,
134+ last_modified : ( content . modifiedAt || content . createdAt ) . toISOString ( ) ,
135+ embedding_inline : crossAppEmbeddingToDbEmbedding ( content . embedding ) || null ,
136+ ...decodeRefWithInlineNulls ( {
137+ ref : content . author ,
138+ dbVarName : "author_id" ,
139+ localVarName : "author_local_id" ,
140+ inlineVarName : "author_inline" ,
141+ } ) ,
142+ ...decodeRefWithNulls ( space , "space_id" , "space_url" ) ,
143+ // provide other explicit null values for type completion
144+ ...decodeRefWithInlineNulls ( {
145+ dbVarName : "creator_id" ,
146+ localVarName : "creator_local_id" ,
147+ inlineVarName : "creator_inline" ,
148+ } ) ,
149+ ...decodeRefWithInlineNulls ( {
150+ dbVarName : "document_id" ,
151+ localVarName : "document_local_id" ,
152+ inlineVarName : "document_inline" ,
153+ } ) ,
154+ ...decodeRefWithNulls ( undefined , "part_of_id" , "part_of_local_id" ) ,
155+ metadata : null ,
156+ } ;
157+ } ;
158+
79159export const crossAppNodeToDbContent = (
80160 node : CrossAppNode | undefined ,
81161 variant : "full" | "direct" ,
0 commit comments