UNPKG

@ktarmyshov/nosql-constraints

Version:

Helpers to manage constrants (i.e. cascade delete) in a NoSQL database

21 lines (20 loc) 1.06 kB
import { VertexWithId } from '@ktarmyshov/digraph-js'; import { PropertyPaths, UnknownStringRecord } from '@ktarmyshov/typesafe-utilities'; import { PartialDeep } from 'type-fest'; 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> = { referencedId: string; referencingId: string; referenced: DocumentReference<TReferenced>; referencing: DocumentReference<TReferencing>; constraint: Constraint<TReferenced, TReferencing>; };