|
2 | 2 | CrossAppEmbedding, |
3 | 3 | InlineCrossAppContent, |
4 | 4 | CrossAppNode, |
| 5 | + CrossAppNodeSchema, |
| 6 | + CrossAppRelationTypeSchema, |
| 7 | + CrossAppRelationTripleSchema, |
5 | 8 | } from "../crossAppContracts"; |
6 | 9 | import { LocalContentDataInput, LocalConceptDataInput } from "../inputTypes"; |
7 | 10 | import { Enums, CompositeTypes } from "../dbTypes"; |
@@ -79,3 +82,76 @@ export const crossAppNodeToDbConcept = ( |
79 | 82 | last_modified: node.modifiedAt?.toISOString(), |
80 | 83 | }); |
81 | 84 | }; |
| 85 | + |
| 86 | +export const crossAppNodeSchemaToDbConcept = ( |
| 87 | + node: CrossAppNodeSchema, |
| 88 | +): LocalConceptDataInput => { |
| 89 | + const literalInfo = filterUndefined({ |
| 90 | + template: node.templateTitle, |
| 91 | + template_content: node.template, |
| 92 | + }); |
| 93 | + return filterUndefined<LocalConceptDataInput>({ |
| 94 | + source_local_id: node.localId, |
| 95 | + name: node.label, |
| 96 | + author_local_id: node.authorId, |
| 97 | + is_schema: true, |
| 98 | + literal_content: |
| 99 | + Object.keys(literalInfo).length > 0 ? literalInfo : undefined, |
| 100 | + created: node.createdAt?.toISOString(), |
| 101 | + last_modified: node.modifiedAt?.toISOString(), |
| 102 | + }); |
| 103 | +}; |
| 104 | + |
| 105 | +export const crossAppRelationTypeSchemaToDbConcept = ( |
| 106 | + node: CrossAppRelationTypeSchema, |
| 107 | +): LocalConceptDataInput => { |
| 108 | + return filterUndefined<LocalConceptDataInput>({ |
| 109 | + source_local_id: node.localId, |
| 110 | + name: node.label, |
| 111 | + author_local_id: node.authorId, |
| 112 | + is_schema: true, |
| 113 | + literal_content: { |
| 114 | + roles: ["source", "destination"], |
| 115 | + label: node.label, |
| 116 | + complement: node.complement, |
| 117 | + }, |
| 118 | + created: node.createdAt?.toISOString(), |
| 119 | + last_modified: node.modifiedAt?.toISOString(), |
| 120 | + }); |
| 121 | +}; |
| 122 | + |
| 123 | +export const crossAppRelationTripleSchemaToDbConcept = ({ |
| 124 | + node, |
| 125 | + sourceNodeSchema, |
| 126 | + destinationNodeSchema, |
| 127 | + relationType, |
| 128 | +}: { |
| 129 | + node: CrossAppRelationTripleSchema; |
| 130 | + sourceNodeSchema: CrossAppNodeSchema; |
| 131 | + destinationNodeSchema: CrossAppNodeSchema; |
| 132 | + // used in Obsidian, not yet in Roam. |
| 133 | + relationType?: CrossAppRelationTypeSchema; |
| 134 | +}): LocalConceptDataInput | undefined => { |
| 135 | + if (!("label" in node) && relationType === undefined) return undefined; |
| 136 | + const label = "label" in node ? node.label : relationType!.label; |
| 137 | + const complement = |
| 138 | + "complement" in node ? node.complement : relationType!.complement; |
| 139 | + return filterUndefined<LocalConceptDataInput>({ |
| 140 | + source_local_id: node.localId, |
| 141 | + name: `${sourceNodeSchema.label} -${label}-> ${destinationNodeSchema.label}`, |
| 142 | + author_local_id: node.authorId, |
| 143 | + is_schema: true, |
| 144 | + literal_content: filterUndefined({ |
| 145 | + roles: ["source", "destination"], |
| 146 | + label, |
| 147 | + complement, |
| 148 | + }), |
| 149 | + local_reference_content: { |
| 150 | + relation_type: node.relation, |
| 151 | + source: node.sourceType, |
| 152 | + destination: node.destinationType, |
| 153 | + }, |
| 154 | + created: node.createdAt?.toISOString(), |
| 155 | + last_modified: node.modifiedAt?.toISOString(), |
| 156 | + }); |
| 157 | +}; |
0 commit comments