Skip to main content

API Reference

All exports are available from the @ddt-ct/implementation package entry point.

fragment.ts — Entity Resolution

ExportSignatureDescription
Fragment<K, V>interfaceA keyed fragment: finite set of records tagged with global keys
FragmentMorphism<K, V>interfaceA key-preserving map between fragments
fragment(records: Array<{key: K, value: V}>) => Fragment<K, V>Construct a fragment from records
colimitFragments(fragments: ReadonlyArray<Fragment<string, V>>, merge: (a: V, b: V) => V) => Fragment<string, V>Compute the colimit (entity resolution) of a diagram of fragments
canonicalInjection(source: Fragment<string, V>, colimit: Fragment<string, V>) => ReadonlyMap<number, number>Canonical injection from a fragment into its colimit
mediatingMorphism(colimit: Fragment<string, V>, target: Fragment<string, V>, coconeMaps: ...) => ReadonlyMap<number, number>Verify the universal property via the mediating morphism

semilattice.ts — Join-Semilattice

ExportSignatureDescription
JoinSemilattice<A>interface { join: (x: A, y: A) => A }A join-semilattice typeclass
LWW<A>interface { value: A, timestamp: number }Last-Writer-Wins register
lww(value: A, timestamp: number) => LWW<A>Construct an LWW register
maxSemilatticeJoinSemilattice<number>Max-based semilattice for numbers
setUnionSemilattice<A>() => JoinSemilattice<ReadonlySet<A>>Set-union semilattice
lwwSemilattice<A>() => JoinSemilattice<LWW<A>>LWW semilattice with deterministic tiebreaker
joinAll(S: JoinSemilattice<A>) => (values: [A, ...A[]]) => AFold a non-empty array using join
verifySemilatticeLaws(S, eq, x, y, z) => { commutative, associative, idempotent }Verify the three semilattice laws

crdt.ts — State-Based CRDT

ExportSignatureDescription
merge(S: JoinSemilattice<A>) => (local: A, remote: A) => AMerge two CRDT states via semilattice join
productSemilattice(sa: JoinSemilattice<A>, sb: JoinSemilattice<B>) => JoinSemilattice<[A, B]>Product semilattice for tuples
recordSemilattice(fields: { [K in keyof R]: JoinSemilattice<R[K]> }) => JoinSemilattice<R>Record-level semilattice from per-field semilattices

schema.ts — Functorial Schema Translation

ExportSignatureDescription
SchemaRecord<string, string>A schema: field names to type names
SchemaMorphismRecord<string, string>A schema morphism: source fields to target fields
Instance<S>{ [K in keyof S]: unknown }A database instance of schema S
deltaF(morphism: SchemaMorphism, targetInstance: Instance<T>) => Instance<S>Delta_F pullback / reindexing (safe direction)
sigmaF(morphism: SchemaMorphism, sourceInstance: Instance<S>) => Instance<T>Sigma_F pushforward (left adjoint)
preservesConstraint(morphism: SchemaMorphism, fkSource: string, fkTarget: string) => booleanCheck if a morphism preserves a referential integrity constraint

temporal.ts — Event Log Presheaf

ExportSignatureDescription
DomainEvent<E>interface { timestamp: number, payload: E }A timestamped domain event
EventLog<E>ReadonlyArray<DomainEvent<E>>An ordered event log
eventLogUpTo(log: EventLog<E>, t: number) => EventLog<E>Presheaf P(t): events up to time t
restrictLog(log: EventLog<E>, s: number) => EventLog<E>Restriction map P(t) -> P(s)
foldEvents(log: EventLog<E>, initial: S, apply: (s: S, e: E) => S) => SState reconstruction: fold events into state
stateAt(fullLog: EventLog<E>, t: number, initial: S, apply: ...) => SState at time t: compose presheaf with fold
verifyFunctoriality(log: EventLog<E>, s: number, t: number) => booleanVerify presheaf functoriality for s ≤ t

snapshot.ts — Snapshot-Accelerated Queries

ExportSignatureDescription
Snapshot<S>interface { timestamp: number, state: S }A state snapshot at a timestamp
SnapshotLog<E, S>interfaceEvent log augmented with periodic snapshots
createSnapshotLog(events, initial, apply, interval) => SnapshotLog<E, S>Build a snapshot log with snapshots at each interval
snapshotStateAt(slog: SnapshotLog<E, S>, t: number) => SReconstruct state from nearest snapshot
verifySnapshotEquivalence(slog, t, eq) => booleanVerify snapshot optimization correctness

provider.ts — Healthcare Domain Types

ExportSignatureDescription
AddressinterfaceStreet address
ProviderEventPayloadunion typeDiscriminated union of provider events
ProviderStateinterfaceFull provider state with LWW fields
ProviderRecordinterfacePartial provider record (from one context)
emptyAddressAddressZero-value address
initialProviderStateProviderStateZero-value provider state
providerSemilatticeJoinSemilattice<ProviderState>Record-level semilattice for provider state
applyProviderEvent(state, event) => ProviderStateApply event using Date.now() timestamps
applyProviderEventDeterministic(state, event, timestamp) => ProviderStateApply event with explicit timestamp
providerStateAt(log, t) => ProviderStateProvider state at time t
foldProviderLog(log) => ProviderStateFold provider event log with deterministic timestamps
mergeProviderRecords(a, b) => ProviderRecordMerge two partial records (last-defined-wins)
resolveProvider(fragments) => Fragment<string, ProviderRecord>Entity resolution: colimit of provider fragments
mergeProviderStates(local, remote) => ProviderStateCRDT merge for distributed provider state
ehrFragment(npi, name, address) => Fragment<string, ProviderRecord>Create an EHR bounded-context fragment
credentialingFragment(npi, name, license) => Fragment<string, ProviderRecord>Create a credentialing fragment
contractingFragment(npi, networks) => Fragment<string, ProviderRecord>Create a contracting fragment

logger.ts

ExportSignatureDescription
loggerwinston.LoggerShared structured logger (level via LOG_LEVEL env var)