@@ -15,6 +15,7 @@ const getConceptMap = async (
1515 conceptIds : number [ ] ,
1616 spaceMap : Record < number , string > ,
1717) : Promise < Record < number , string > > => {
18+ if ( conceptIds . length === 0 ) return { } ;
1819 const request = await client
1920 . from ( "my_concepts" )
2021 . select ( "id, space_id, source_local_id" )
@@ -79,12 +80,22 @@ const asSimpleLocalId = (
7980 return rid ;
8081} ;
8182
82- export const dbNodeSchemaToCrossApp = (
83- schema : Concept ,
84- spaceMap : Record < number , string > ,
85- accountMap : Record < number , string > ,
86- ) : CrossAppNodeSchema => {
87- const { template, template_content, ...other } =
83+ export const dbNodeSchemaToCrossApp = ( {
84+ schema,
85+ spaceMap,
86+ accountMap,
87+ schemaMap,
88+ } : {
89+ schema : Concept ;
90+ spaceMap : Record < number , string > ;
91+ accountMap : Record < number , string > ;
92+ schemaMap : Record < number , string > ;
93+ } ) : CrossAppNodeSchema => {
94+ const referenceContent = ( schema . reference_content ?? { } ) as Record <
95+ string ,
96+ number
97+ > ;
98+ const { template, template_content, roles, ...other } =
8899 schema . literal_content as Record < string , Json > ;
89100 const authorId = accountMap [ schema . author_id || 0 ] ;
90101 if ( authorId === undefined ) throw new Error ( "Missing author" ) ;
@@ -95,6 +106,11 @@ export const dbNodeSchemaToCrossApp = (
95106 schema . source_local_id ! ,
96107 "schema" ,
97108 ) ;
109+ const slotDefinitions : Record < string , string > = Object . fromEntries (
110+ ( ( roles as string [ ] | undefined ) ?? [ ] )
111+ . map ( ( r ) => [ r , schemaMap [ referenceContent [ r ] ?? 0 ] ] )
112+ . filter ( ( [ , s ] ) => s !== undefined ) as [ string , string ] [ ] ,
113+ ) ;
98114 return {
99115 rid,
100116 localId : schema . source_local_id ! ,
@@ -105,6 +121,7 @@ export const dbNodeSchemaToCrossApp = (
105121 template : template_content as string | undefined ,
106122 templateTitle : template as string | undefined ,
107123 authorId,
124+ slotDefinitions,
108125 } ;
109126} ;
110127
@@ -126,7 +143,11 @@ export const dbNodeSchemasToCrossApp = async ({
126143 ) ;
127144 accountMap = await getAccountMap ( client , [ ...authorIds ] ) ;
128145 }
129- return schemas . map ( ( r ) => dbNodeSchemaToCrossApp ( r , spaceMap , accountMap ) ) ;
146+ const referredSchemaIds = schemas . flatMap ( ( schema ) => schema . refs ) ;
147+ const schemaMap = await getConceptMap ( client , referredSchemaIds , spaceMap ) ;
148+ return schemas . map ( ( schema ) =>
149+ dbNodeSchemaToCrossApp ( { schema, spaceMap, accountMap, schemaMap } ) ,
150+ ) ;
130151} ;
131152
132153export const dbRelationTypeSchemaToCrossApp = (
0 commit comments