|
6 | 6 | CrossAppBase, |
7 | 7 | CrossAppNode, |
8 | 8 | } from "../crossAppContracts"; |
9 | | -import { LocalContentDataInput } from "../inputTypes"; |
| 9 | +import { LocalContentDataInput, LocalConceptDataInput } from "../inputTypes"; |
10 | 10 | import { Enums, CompositeTypes } from "../dbTypes"; |
11 | 11 |
|
12 | 12 | type InlineEmbeddingInput = CompositeTypes<"inline_embedding_input">; |
@@ -55,6 +55,9 @@ const filterUndefined = <T extends Record<string, unknown>>(data: T): T => { |
55 | 55 | ) as T; |
56 | 56 | }; |
57 | 57 |
|
| 58 | +const filterUndefinedArray = <T>(data: (T | undefined)[]): T[] => |
| 59 | + data.filter((v) => v !== undefined); |
| 60 | + |
58 | 61 | const inlineCrossAppContentToDbContent = ( |
59 | 62 | content: InlineCrossAppContent | undefined, |
60 | 63 | variant: Enums<"ContentVariant">, |
@@ -89,3 +92,20 @@ export const crossAppNodeToDbContent = ( |
89 | 92 | variant, |
90 | 93 | ); |
91 | 94 | }; |
| 95 | + |
| 96 | +export const crossAppNodeToDbConcept = ( |
| 97 | + node: CrossAppNode, |
| 98 | +): LocalConceptDataInput => { |
| 99 | + return filterUndefined<LocalConceptDataInput>({ |
| 100 | + ...decodeLocalRef(node, "source_local_id"), |
| 101 | + name: node.content.direct.value, |
| 102 | + ...decodeRef(node.author, "author_id", "author_local_id"), |
| 103 | + ...decodeRef(node.nodeType, "schema_id", "schema_represented_by_local_id"), |
| 104 | + contents_inline: filterUndefinedArray([ |
| 105 | + crossAppNodeToDbContent(node, "direct"), |
| 106 | + crossAppNodeToDbContent(node, "full"), |
| 107 | + ]), |
| 108 | + created: node.createdAt?.toISOString(), |
| 109 | + last_modified: node.modifiedAt?.toISOString(), |
| 110 | + }); |
| 111 | +}; |
0 commit comments