|
2 | 2 | CrossAppEmbedding, |
3 | 3 | InlineCrossAppContent, |
4 | 4 | CrossAppNode, |
| 5 | + CrossAppNodeSchema, |
| 6 | + CrossAppRelationTypeSchema, |
| 7 | + CrossAppRelationTripleSchema, |
5 | 8 | CrossAppRelation, |
6 | 9 | } from "../crossAppContracts"; |
7 | 10 | import { LocalContentDataInput, LocalConceptDataInput } from "../inputTypes"; |
@@ -81,6 +84,79 @@ export const crossAppNodeToDbConcept = ( |
81 | 84 | }); |
82 | 85 | }; |
83 | 86 |
|
| 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 | + |
84 | 160 | export const crossAppRelationToDbConcept = ( |
85 | 161 | node: CrossAppRelation, |
86 | 162 | ): LocalConceptDataInput => { |
|
0 commit comments