nosql-constraints
Version:
Helpers to manage constrants (i.e. cascade delete) in a NoSQL database
21 lines (20 loc) • 1.01 kB
TypeScript
import { PartialDeep } from 'type-fest';
import { PropertyPaths, UnknownStringRecord } from 'typesafe-utilities';
import { VertexWithId } from 'ya-digraph-js';
export type RefDocType<TDoc extends UnknownStringRecord> = PartialDeep<TDoc>;
export type DocumentReference<TDoc extends UnknownStringRecord> = {
containerId: string;
refDocType?: RefDocType<TDoc>;
};
export type ConstraintVertexWithId<TDoc extends UnknownStringRecord> = VertexWithId<DocumentReference<TDoc>>;
export type Constraint<TReferencing extends UnknownStringRecord, TReferenced extends UnknownStringRecord> = {
cascadeDelete?: true;
refProperties: Partial<Record<PropertyPaths<TReferencing>, PropertyPaths<TReferenced>>>;
};
export type ConstraintPathElement<TReferencing extends UnknownStringRecord, TReferenced extends UnknownStringRecord> = {
fromId: string;
toId: string;
from: DocumentReference<TReferenced>;
to: DocumentReference<TReferencing>;
constraint: Constraint<TReferenced, TReferencing>;
};