Skip to content
Open
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
23 changes: 23 additions & 0 deletions packages/database/src/crossAppContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ type CrossAppBase = LocalRef & {
author: Ref;
};

// A node schema
export type CrossAppNodeSchema = CrossAppBase & {
label: string;
template?: string;
templateTitle?: string;
};

// A relation type schema
export type CrossAppRelationTypeSchema = CrossAppBase & {
label: string;
complement: string;
// should we add colour? format?
};

// A relation triple schema
export type CrossAppRelationTripleSchema = CrossAppBase & {
label: string;
complement: string;
relation?: Ref | CrossAppRelationTypeSchema;
sourceType: Ref;
destinationType: Ref;
};
Comment on lines +39 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data consistency issue: CrossAppRelationTripleSchema has redundant label and complement fields that conflict with the optional relation field of type CrossAppRelationTypeSchema, which also contains label and complement. This creates ambiguity about which values should be authoritative.

When relation is provided, there are now two sources of truth for label and complement, which can diverge and cause data inconsistency. Consider one of these approaches:

// Option 1: Remove redundant fields, require relation reference
export type CrossAppRelationTripleSchema = CrossAppBase & {
  relation: Ref | CrossAppRelationTypeSchema;
  sourceType: Ref;
  destinationType: Ref;
};

// Option 2: Make fields conditional based on relation presence
export type CrossAppRelationTripleSchema = CrossAppBase & (
  | { relation: Ref | CrossAppRelationTypeSchema; sourceType: Ref; destinationType: Ref; }
  | { label: string; complement: string; sourceType: Ref; destinationType: Ref; }
);
Suggested change
export type CrossAppRelationTripleSchema = CrossAppBase & {
label: string;
complement: string;
relation?: Ref | CrossAppRelationTypeSchema;
sourceType: Ref;
destinationType: Ref;
};
export type CrossAppRelationTripleSchema = CrossAppBase & (
| {
relation: Ref | CrossAppRelationTypeSchema;
sourceType: Ref;
destinationType: Ref;
}
| {
label: string;
complement: string;
sourceType: Ref;
destinationType: Ref;
}
);

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


// An inline vector semantic embedding
type CrossAppEmbedding = {
value: number[];
Expand Down