11import {
2- LocalRef ,
3- Ref ,
42 CrossAppEmbedding ,
53 InlineCrossAppContent ,
6- CrossAppBase ,
74 CrossAppNode ,
85} from "../crossAppContracts" ;
96import { LocalContentDataInput , LocalConceptDataInput } from "../inputTypes" ;
107import { Enums , CompositeTypes } from "../dbTypes" ;
118
129type InlineEmbeddingInput = CompositeTypes < "inline_embedding_input" > ;
13- type InlineAbstractBase = Partial < CrossAppBase > ;
14-
15- const decodeLocalRef = < LocalVarName extends string > (
16- ref : LocalRef | InlineAbstractBase | undefined ,
17- localVarName : LocalVarName ,
18- ) : Record < LocalVarName , string > | Record < string , never > => {
19- if ( ref === undefined ) return { } ;
20- if ( "localId" in ref ) {
21- return {
22- [ localVarName ] : ref . localId ,
23- } as Record < LocalVarName , string > ;
24- }
25- return { } ;
26- } ;
27-
28- const decodeRef = < DbVarName extends string , LocalVarName extends string > (
29- ref : Ref | undefined ,
30- dbVarName : DbVarName ,
31- localVarName : LocalVarName ,
32- ) :
33- | Record < DbVarName , number >
34- | Record < LocalVarName , string >
35- | Record < string , never > => {
36- if ( ref === undefined ) return { } ;
37- if ( "dbId" in ref )
38- return { [ dbVarName ] : ref . dbId } as Record < DbVarName , number > ;
39- return decodeLocalRef ( ref , localVarName ) ;
40- } ;
4110
4211const crossAppEmbeddingToDbEmbedding = (
4312 embedding : CrossAppEmbedding | undefined ,
@@ -64,14 +33,14 @@ const inlineCrossAppContentToDbContent = (
6433) : LocalContentDataInput | undefined => {
6534 if ( content === undefined ) return undefined ;
6635 return filterUndefined < LocalContentDataInput > ( {
67- ... decodeLocalRef ( content , " source_local_id" ) ,
36+ source_local_id : content . localId ,
6837 text : content . value ,
6938 scale : content . scale || "document" ,
7039 content_type : content . contentType || "text/plain" ,
7140 variant,
7241 created : content . createdAt ?. toISOString ( ) ,
7342 last_modified : content . modifiedAt ?. toISOString ( ) ,
74- ... decodeRef ( content . author , "author_id" , "author_local_id" ) ,
43+ author_local_id : content . authorId ,
7544 embedding_inline : crossAppEmbeddingToDbEmbedding ( content . embedding ) ,
7645 } ) ;
7746} ;
@@ -88,7 +57,7 @@ export const crossAppNodeToDbContent = (
8857 ...content ,
8958 createdAt : content . createdAt || node . createdAt ,
9059 modifiedAt : content . modifiedAt || node . modifiedAt ,
91- author : content . author || node . author ,
60+ authorId : content . authorId || node . authorId ,
9261 } ,
9362 variant ,
9463 ) ;
@@ -98,10 +67,10 @@ export const crossAppNodeToDbConcept = (
9867 node : CrossAppNode ,
9968) : LocalConceptDataInput => {
10069 return filterUndefined < LocalConceptDataInput > ( {
101- ... decodeLocalRef ( node , " source_local_id" ) ,
70+ source_local_id : node . localId ,
10271 name : node . content . direct . value ,
103- ... decodeRef ( node . author , "author_id" , "author_local_id" ) ,
104- ... decodeRef ( node . nodeType , "schema_id" , "schema_represented_by_local_id" ) ,
72+ author_local_id : node . authorId ,
73+ schema_represented_by_local_id : node . nodeType ,
10574 contents_inline : filterUndefinedArray ( [
10675 crossAppNodeToDbContent ( node , "direct" ) ,
10776 crossAppNodeToDbContent ( node , "full" ) ,
0 commit comments