Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/database/src/crossAppContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Rid = string;
// Common attributes for most types
export type CrossAppBase = {
localId: LocalId;
rid?: string;
createdAt: Date;
modifiedAt?: Date;
authorId: LocalId;
Expand Down
21 changes: 21 additions & 0 deletions packages/database/src/lib/crossAppConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CrossAppRelation,
} from "../crossAppContracts";
import { LocalContentDataInput, LocalConceptDataInput } from "../inputTypes";
import { ridToSpaceUriAndLocalId } from "./rid";
import { Enums, CompositeTypes } from "../dbTypes";

type InlineEmbeddingInput = CompositeTypes<"inline_embedding_input">;
Expand Down Expand Up @@ -70,7 +71,11 @@ export const crossAppNodeToDbContent = (
export const crossAppNodeToDbConcept = (
node: CrossAppNode,
): LocalConceptDataInput => {
const spaceUri = node.rid
? ridToSpaceUriAndLocalId(node.rid).spaceUri
: undefined;
return filterUndefined<LocalConceptDataInput>({
space_url: spaceUri,
source_local_id: node.localId,
name: node.content.direct.value,
author_local_id: node.authorId,
Expand All @@ -91,7 +96,11 @@ export const crossAppNodeSchemaToDbConcept = (
template: node.templateTitle,
template_content: node.template,
});
const spaceUri = node.rid
? ridToSpaceUriAndLocalId(node.rid).spaceUri
: undefined;
return filterUndefined<LocalConceptDataInput>({
space_url: spaceUri,
source_local_id: node.localId,
name: node.label,
author_local_id: node.authorId,
Expand All @@ -106,7 +115,11 @@ export const crossAppNodeSchemaToDbConcept = (
export const crossAppRelationTypeSchemaToDbConcept = (
node: CrossAppRelationTypeSchema,
): LocalConceptDataInput => {
const spaceUri = node.rid
? ridToSpaceUriAndLocalId(node.rid).spaceUri
: undefined;
return filterUndefined<LocalConceptDataInput>({
space_url: spaceUri,
source_local_id: node.localId,
name: node.label,
author_local_id: node.authorId,
Expand All @@ -130,7 +143,11 @@ export const crossAppRelationTripleSchemaToDbConcept = (
const label = "label" in node ? node.label : relationType!.label;
const complement =
"complement" in node ? node.complement : relationType!.complement;
const spaceUri = node.rid
? ridToSpaceUriAndLocalId(node.rid).spaceUri
: undefined;
return filterUndefined<LocalConceptDataInput>({
space_url: spaceUri,
source_local_id: node.localId,
name: node.localId, // has to be unique within space. Not seen yet.
author_local_id: node.authorId,
Expand All @@ -153,9 +170,13 @@ export const crossAppRelationTripleSchemaToDbConcept = (
export const crossAppRelationToDbConcept = (
node: CrossAppRelation,
): LocalConceptDataInput => {
const spaceUri = node.rid
? ridToSpaceUriAndLocalId(node.rid).spaceUri
: undefined;
return filterUndefined<LocalConceptDataInput>({
// use LocalIds... not ideal
name: `${node.localId}: ${node.source} -${node.relationType}-> ${node.destination}`,
space_url: spaceUri,
source_local_id: node.localId,
author_local_id: node.authorId,
schema_represented_by_local_id: node.relationType,
Expand Down