Skip to content

Commit 180590b

Browse files
committed
Merge branch 'eng-2017-add-converter-for-crossapp-schemas-to-localconceptdatainput' into 1865b
2 parents 812992f + 284254a commit 180590b

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

packages/database/src/lib/crossAppConverters.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {
22
CrossAppEmbedding,
33
InlineCrossAppContent,
44
CrossAppNode,
5+
CrossAppNodeSchema,
6+
CrossAppRelationTypeSchema,
7+
CrossAppRelationTripleSchema,
58
CrossAppRelation,
69
} from "../crossAppContracts";
710
import { LocalContentDataInput, LocalConceptDataInput } from "../inputTypes";
@@ -81,6 +84,79 @@ export const crossAppNodeToDbConcept = (
8184
});
8285
};
8386

87+
export const crossAppNodeSchemaToDbConcept = (
88+
node: CrossAppNodeSchema,
89+
): LocalConceptDataInput => {
90+
const literalInfo = filterUndefined({
91+
template: node.templateTitle,
92+
template_content: node.template,
93+
});
94+
return filterUndefined<LocalConceptDataInput>({
95+
source_local_id: node.localId,
96+
name: node.label,
97+
author_local_id: node.authorId,
98+
is_schema: true,
99+
literal_content:
100+
Object.keys(literalInfo).length > 0 ? literalInfo : undefined,
101+
created: node.createdAt?.toISOString(),
102+
last_modified: node.modifiedAt?.toISOString(),
103+
});
104+
};
105+
106+
export const crossAppRelationTypeSchemaToDbConcept = (
107+
node: CrossAppRelationTypeSchema,
108+
): LocalConceptDataInput => {
109+
return filterUndefined<LocalConceptDataInput>({
110+
source_local_id: node.localId,
111+
name: node.label,
112+
author_local_id: node.authorId,
113+
is_schema: true,
114+
literal_content: {
115+
roles: ["source", "destination"],
116+
label: node.label,
117+
complement: node.complement,
118+
},
119+
created: node.createdAt?.toISOString(),
120+
last_modified: node.modifiedAt?.toISOString(),
121+
});
122+
};
123+
124+
export const crossAppRelationTripleSchemaToDbConcept = ({
125+
node,
126+
sourceNodeSchema,
127+
destinationNodeSchema,
128+
relationType,
129+
}: {
130+
node: CrossAppRelationTripleSchema;
131+
sourceNodeSchema: CrossAppNodeSchema;
132+
destinationNodeSchema: CrossAppNodeSchema;
133+
relationType?: CrossAppRelationTypeSchema;
134+
}): LocalConceptDataInput | undefined => {
135+
// relationType must be provided if relation-based triple.
136+
if (!("label" in node) && relationType === undefined) return undefined;
137+
const label = "label" in node ? node.label : relationType!.label;
138+
const complement =
139+
"complement" in node ? node.complement : relationType!.complement;
140+
return filterUndefined<LocalConceptDataInput>({
141+
source_local_id: node.localId,
142+
name: `${sourceNodeSchema.label} -${label}-> ${destinationNodeSchema.label}`,
143+
author_local_id: node.authorId,
144+
is_schema: true,
145+
literal_content: filterUndefined({
146+
roles: ["source", "destination"],
147+
label,
148+
complement,
149+
}),
150+
local_reference_content: {
151+
relation_type: node.relation,
152+
source: node.sourceType,
153+
destination: node.destinationType,
154+
},
155+
created: node.createdAt?.toISOString(),
156+
last_modified: node.modifiedAt?.toISOString(),
157+
});
158+
};
159+
84160
export const crossAppRelationToDbConcept = (
85161
node: CrossAppRelation,
86162
): LocalConceptDataInput => {

0 commit comments

Comments
 (0)