PrimeBrickPrimeBrick
  • Docs
  • Contact
  • MIT License
  • Documentation
  • MCP Server
  • API Catalog
  • Services
  • Libraries
PrimeBrickPrimeBrick

© 2026 PrimeBrick. MIT License. v3.11.2

github
DAL Library
    Developer Guide
      Getting startedArchitectureEntities & decoratorsColumn typesQuery DSLRepositoryRepository PatternEntity Service FactoryConnections & transactionsAudit trailPartitioning & retentionOptimistic Locking & ConcurrencyCloneDatabase MigrationsChangelogAPI Reference
SDK Library
Decimal Library
powered by Zudoku
Developer Guide

title: API Reference description: Complete API reference for @primebrick/dal-pg — every exported symbol.

API Reference

Every exported symbol from @primebrick/dal-pg, rendered mechanically from the TypeDoc extraction. This page is regenerated from docs/dev-guide/_extracted/api.json on every pnpm extract-docs run — do not edit by hand.

Classes

AuditLogEntity

AuditLogEntity — generic audit trail entity.

Maps to any audit table (customers_audit, organizations_audit, user_profiles_audit, etc.) via the tableName override option on finders/writers.

All audit tables share the same column structure: id bigint identity PK entity_id bigint (the audited entity's ID) entity_uuid uuid (the audited entity's UUID) action text (INSERT, UPDATE, SOFT_DELETE, HARD_DELETE, RESTORE) changed_at timestamptz changed_by text (actor UUID or "system") version integer delta jsonb (field-level old/new diff)

This entity has NO

PropertyTypeDescription
idbigint
entity_idbigint
entity_uuidstring
actionstring
changed_atDate
changed_bystring
versionnumber
deltaRecord<string, { old: unknown; new: unknown }>

BulkTimeoutError

Thrown when a bulk write exceeds its wall-clock budget (DalConfig.bulkTimeoutMs or BulkOptions.timeoutMs). The surrounding transaction is rolled back — no partial writes survive.

Code: ERR06. TS-originated (the JS deadline fires between statements; a slow single statement is bounded by SET LOCAL statement_timeout → PG 57014 query_canceled). HTTP 408.

PropertyTypeDescription
code"ERR06"

BulkTimeoutError(message)

ParameterTypeDescription
messagestring

ConfigEntityBase

ConfigEntityBase — standard dictionary-style config table entity.

Every Primebrick config table (BE auth_configurations, microservice config) extends this base class to get the standard column set without copy-paste.

Columns: key varchar(100) NOT NULL UNIQUE — stable snake_case setting key value text nullable — raw TEXT; null = "not set" type varchar(50) NOT NULL — ConfigType (drives SDK coercion + FE widget) type_config text nullable — JSONB-text extra per-type config (badge values, list API URL, etc.) label_key varchar(100) nullable — i18n key for the setting title description_key varchar(100) nullable — i18n key for the explanatory text reserved boolean NOT NULL DEFAULT false — if true: editable but not deletable group_key varchar(100) nullable — UI grouping key (null/empty = ungrouped, top of list)

Plus standard audit columns (created_at/by, updated_at/by, version, deleted_at/by).

The consumer creates a concrete subclass: @Entity("config", "public") export class ConfigEntryEntity extends ConfigEntityBase {}

This class is DB-agnostic — it does NOT import from @primebrick/sdk. The SDK's IConfigEntity interface mirrors the field names for port-level use.

PropertyTypeDescription
idbigint
uuidstring
keystringUnique config key (e.g. "oidc_issuer_url", "enable_mfa"). Never renamed after release.
valuestring | nullRaw TEXT value. null means "the row exists but the value is not set".
typestringConfig value type — drives SDK coercion and FE widget selection.
type_configstring | nullJSONB-text extra per-type configuration (e.g. badge inline values, list API URL).
label_keystringi18n key for the setting title.
description_keystringi18n key for the explanatory description.
reservedbooleanIf true, the row is system-critical: editable but not deletable.
group_keystring | nullOptional grouping key for UI display. null/empty = ungrouped (top of list).
created_atDate
created_bystring
updated_atDate
updated_bystring
versionnumber
deleted_atDate
deleted_bystring

Dal

PropertyTypeDescription
configRequired<Pick<DalConfig, "connectionString" | "schemas" | "max" | "statementTimeoutMs" | "bulkTimeoutMs" | "connectionTimeoutMillis" | "idleTimeoutMillis" | "applicationName">> & Pick<DalConfig, "sharedTables" | "maxUses" | "repoDecorator">The resolved configuration (defaults merged with user-provided config).

Dal(config)

ParameterTypeDescription
configDalConfig

Dal.getPool(): Pool

The underlying pg.Pool. Exposed for snapshot/migration tooling that needs raw access.

Dal.close(timeoutMs): Promise<void>

Graceful shutdown — drains the pool with a timeout deadline.

  • Re-entrant: concurrent calls return immediately (the first call wins).
  • Timeout: if pool.end() doesn't complete within timeoutMs, the promise resolves anyway (the pool is left to be reaped by the OS/TCP stack).
  • Error containment: if pool.end() throws, the error is logged and swallowed.
  • Does NOT install process.on() handlers — that is a consumer-side concern.
ParameterTypeDescription
timeoutMsnumberMaximum time to wait for pool.end() to complete. Default: 10000.

Dal.findById(entity, id, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
idstring | bigint
optionsFindByIdOptions

Dal.findByUUID(entity, uuid, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
uuidstring
optionsFindByUUIDOptions

Dal.find(entity, fields, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
fieldsFieldProjector[] | null
optionsFindOptions

Dal.findAll(entity, fields, options): Promise<AsyncIterable<TResult, any, any> \| TResult[]>

ParameterTypeDescription
entityEntityClass
fieldsFieldProjector[] | null
optionsFindOptions

Dal.findByPage(entity, page, recordsPerPage, fields, options): Promise<PaginatedEntity<TResult>>

ParameterTypeDescription
entityEntityClass
pagenumber
recordsPerPagenumber
fieldsFieldProjector[] | null
optionsFindOptions

Dal.count(entity): Promise<bigint>

ParameterTypeDescription
entityEntityClass

Dal.vectorSearch(entity, vectorField, queryVector, options): Promise<TResult & { similarity: number; distance: number }[]>

pgvector nearest-neighbour search — see Repository.vectorSearch. ORDER BY <vectorField> <op> $n::vector LIMIT <topK> with the query vector bound as a parameter (HNSW/ivfflat-safe). similarity score for cosine (<=>), raw distance for other operators.

ParameterTypeDescription
entityEntityClass
vectorFieldFieldRef<TEntity, keyof TEntity & string>
queryVectorstring | number[]
optionsVectorSearchOptions<TEntity>

Dal.add(entity, row, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
rowPartial<Record<keyof TEntity & string, unknown>>
optionsAuditableWriteOptions<TEntity>

Dal.update(entity, updates, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
updatesPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Dal.delete(entity, match, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Dal.restore(entity, match, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Dal.hardDelete(entity, match, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Dal.addMany(entity, rows, options): Promise<BulkResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
rowsPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & BulkOptions

Dal.hardDeleteMany(entity, matches, options): Promise<BulkResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

Dal.restoreMany(entity, matches, options): Promise<BulkResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

Dal.updateMany(entity, updates, options): Promise<BulkResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
updatesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

Dal.deleteMany(entity, matches, options): Promise<BulkResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Dal.entityService(cfg): EntityService<TEntity>

The public path to the generic entity-service worker. The gateway injects its own (schema-domain-guarded, pool-scoped) Repository — the consumer never sees it. cfg.repo exists only as a decorator seam (e.g. BE withCache): leave it unset for the standard wiring.

ParameterTypeDescription
cfgEntityServiceConfig<TEntity>

Dal.tableAuditPort(): AuditPort

The standard {table}_audit writer port, bound to the gateway Repository. Use for adapters that need an AuditPort without exposing the Repository itself.

Dal.serverVersion(): Promise<{ server_version: string; version: string }>

Server version + connectivity probe in one call. A successful response already proves the connection is alive — there is deliberately no separate ping() (a dedicated SELECT 1 would be a redundant round-trip). Throws on connectivity/timeout failure.

Dal.transaction(fn, options): Promise<TResult>

Atomic multi-statement work — BEGIN/COMMIT/ROLLBACK around a tx-scoped Repository. Use for cascades, multi-write units, and any sequence that must commit or fail as one. Post-commit side effects (cache invalidation, events) belong AFTER this resolves, never inside.

ParameterTypeDescription
fn(txRepo: Repository) => Promise<TResult>
optionsTimeoutOverrideOptions

Dal.beginTransaction(options): DeferredTransaction

Deferred fluent transaction — buffer repository ops (tx.add, tx.update, tx.find, …) without executing, then tx.commit() compiles and runs them as ONE data-modifying CTE statement. Atomicity is PostgreSQL's single-statement guarantee — no BEGIN/COMMIT/ROLLBACK and no rollback path exist in this mode. Inter-op values flow via Deferred.ref(); conditional TS logic on mid-flow results stays in transaction(fn).

ParameterTypeDescription
optionsTimeoutOverrideOptions

Dal.truncate(entity, options): Promise<void>

Physical table reset — delegates to Repository.truncate (entity-resolved, schema-domain guarded). For auditable tables prefer soft-delete; TRUNCATE is for caches, KB stores, and test teardown.

ParameterTypeDescription
entityEntityClass
options{ restartIdentity: boolean; cascade: boolean }

Dal.partitionMaintenance(entities, options): Promise<PartitionMaintenanceReport>

pg_partman retention executor — metadata-driven, identical for every service. Purges @PartitionChildOf children of expired parents (before the partition drop), removes expired strays from the default partition, then runs partman.run_maintenance_proc(). Called by the service's jobs.due.system.<svc>.partition-maintenance consumer.

ParameterTypeDescription
entitiesreadonly EntityClass[]the service's entity registry (only @PartitionField
entities participate; everything else is ignored)
optionsTimeoutOverrideOptions

DalError

Generic DAL error with a stable code field.

PropertyTypeDescription
codestring

DalError(message)

ParameterTypeDescription
messagestring

Decimal

DecimalError

Errors raised by @primebrick/decimal.

Deferred

Handle for a buffered operation's future result. NOT a Promise — awaiting it pre-commit would deadlock (commit is never reached), so it deliberately exposes no then. Read .value only after await tx.commit().

Deferred.ref(field): DeferredFieldRef<T[K]>

Reference a RETURNING/SELECT column of this op for use in a LATER op.

ParameterTypeDescription
fieldK

DeferredFieldRef

Opaque marker produced by Deferred.ref("field") — embeddable in a later op's payload/match values. At compile time the $n it would occupy is rewritten to (SELECT "field" FROM "__rN") over the source op's RETURNING branch. Never a bound parameter — survives jsValueToPgParam untouched.

DeferredTransaction

DeferredTransaction.add(entity, row, options): Deferred<TResult>

Buffer an insert — see Repository.add. options.audit is rejected.

ParameterTypeDescription
entityEntityClass & () => TEntity
rowPartial<Record<keyof TEntity & string, unknown>>
optionsAuditableWriteOptions<TEntity>

DeferredTransaction.update(entity, updates, options): Deferred<TResult>

Buffer an update — see Repository.update. options.audit is rejected.

ParameterTypeDescription
entityEntityClass & () => TEntity
updatesPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

DeferredTransaction.delete(entity, match, options): Deferred<TResult>

Buffer a soft-delete — see Repository.delete. options.audit is rejected.

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

DeferredTransaction.restore(entity, match, options): Deferred<TResult>

Buffer a restore — see Repository.restore. options.audit is rejected.

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

DeferredTransaction.hardDelete(entity, match, options): Deferred<TResult>

Buffer a hard delete — see Repository.hardDelete. options.audit is rejected.

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

DeferredTransaction.find(entity, fields, options): Deferred<TResult \| null>

Buffer a single-row find — see Repository.find.

ParameterTypeDescription
entityEntityClass & () => TEntity
fieldsFieldProjector[] | null
optionsFindOptions

DeferredTransaction.findByUUID(entity, uuid, options): Deferred<TResult \| null>

Buffer a find-by-uuid — see Repository.findByUUID.

ParameterTypeDescription
entityEntityClass & () => TEntity
uuidstring
optionsFindByUUIDOptions

DeferredTransaction.findById(entity, id, options): Deferred<TResult \| null>

Buffer a find-by-id — see Repository.findById.

ParameterTypeDescription
entityEntityClass & () => TEntity
idstring | bigint
optionsFindByIdOptions

DeferredTransaction.findAll(entity, fields, options): Deferred<TResult[]>

Buffer a findAll — see Repository.findAll (stream rejected).

ParameterTypeDescription
entityEntityClass & () => TEntity
fieldsFieldProjector[] | null
optionsFindOptions

DeferredTransaction.findByPage(entity, page, recordsPerPage, fields, options): Deferred<PaginatedEntity<TResult>>

Buffer a paged find — see Repository.findByPage.

ParameterTypeDescription
entityEntityClass & () => TEntity
pagenumber
recordsPerPagenumber
fieldsFieldProjector[] | null
optionsFindOptions

DeferredTransaction.count(entity, options): Deferred<bigint>

Buffer a count — see Repository.count.

ParameterTypeDescription
entityEntityClass & () => TEntity
options{ tableName: string }

DeferredTransaction.vectorSearch(entity, vectorField, queryVector, options): Deferred<TResult & { similarity: number; distance: number }[]>

Buffer a pgvector search — see Repository.vectorSearch.

ParameterTypeDescription
entityEntityClass & () => TEntity
vectorFieldFieldRef<TEntity, keyof TEntity & string>
queryVectorstring | number[]
optionsVectorSearchOptions<TEntity>

DeferredTransaction.commit(): Promise<void>

Compile every buffered op into ONE statement and execute it. Atomicity is the statement's own: a failure anywhere (constraint, pg_raise guard, abort branch, timeout) rolls back every branch — no rollback code exists because none is needed. Resolves when all Deferred handles are materialized; rejects with the first failure.

DeferredTransaction.discard()

Abandon the buffer without executing anything. Nothing has run yet by design — this simply invalidates the transaction and its Deferred handles.

DeletedRecordConflictError

Unique-constraint conflict on a soft-deleted row — the row exists with deleted_at set and must be restored, never duplicated.

PG-originated via pg_raise('ERR05', ...); the existing row's uuid travels in the error detail so consumers can offer a direct restore. This class is provided for ergonomic instanceof checks.

Code: ERR05. HTTP 409.

PropertyTypeDescription
code"ERR05"

DeletedRecordConflictError(message)

ParameterTypeDescription
messagestring

DomainService

The contract every entity service must satisfy — enforced on the router.

PropertyTypeDescription
cfgEntityServiceConfig<TEntity>

DomainService(cfg)

ParameterTypeDescription
cfgEntityServiceConfig<TEntity>

DomainService.buildConfig(): EntityServiceConfig<TEntity>

Subclass seam for config enrichment (auditPort / actor / userEntity injection). Runs once, inside the lazy svc resolution — this.dal is available here.

DomainService.list(query): Promise<EntityListResult<TEntity>>

ParameterTypeDescription
queryEntityListQuery

DomainService.get(uuid): Promise<TEntity>

ParameterTypeDescription
uuidstring

DomainService.create(body, tx): Promise<TEntity>

ParameterTypeDescription
bodyRecord<string, unknown>
txRepository

DomainService.update(uuid, body, tx): Promise<TEntity>

ParameterTypeDescription
uuidstring
bodyRecord<string, unknown> & { version: number }
txRepository

DomainService.delete(uuid, version): Promise<TEntity>

ParameterTypeDescription
uuidstring
versionnumber

DomainService.restore(uuid, version): Promise<TEntity>

ParameterTypeDescription
uuidstring
versionnumber

DomainService.purge(uuid, version): Promise<TEntity>

ParameterTypeDescription
uuidstring
versionnumber

DomainService.duplicate(uuids): Promise<DuplicateResult>

ParameterTypeDescription
uuidsstring[]

DomainService.bulkDelete(items): Promise<unknown>

ParameterTypeDescription
itemsBulkItem[]

DomainService.bulkRestore(items): Promise<unknown>

ParameterTypeDescription
itemsBulkItem[]

DomainService.audit(uuid, page, limit): Promise<unknown>

ParameterTypeDescription
uuidstring
pagenumber
limitnumber

DomainService.stream(query): AsyncGenerator<TEntity>

ParameterTypeDescription
queryEntityListQuery

DuplicateRecordError

Unique-constraint conflict on a live row.

Normally PG-originated: the add() conflict-reporting CTE calls pg_raise('ERR04', ...), and node-postgres propagates it as a DatabaseError with err.code === 'ERR04' and a jsonb err.detail ({ entity, table, uuid, constraint }). The DAL throws this class only when the conflict cannot be attributed to any identifiable row (unique group whose attempted values are all DB-generated, e.g. a payload-less uuid). Provided in both cases for ergonomic instanceof checks.

Code: ERR04. HTTP 409.

PropertyTypeDescription
code"ERR04"

DuplicateRecordError(message)

ParameterTypeDescription
messagestring

EntityBase

Composition root — empty on purpose. extends Mixin(EntityBase).

ManifestError

PropertyTypeDescription
codestring

ManifestError(code, message)

ParameterTypeDescription
codestring
messagestring

MissingVersionError

Thrown when an auditable-entity write (update/upsert-ON-CONFLICT/delete/restore/hardDelete) is attempted without a version field in the payload.

Code: ERR02. TS-originated. HTTP 400.

PropertyTypeDescription
code"ERR02"
detailunknownStructured per-row detail for bulk ops (entity, table, missing count, rows[]).

MissingVersionError(message, detail)

ParameterTypeDescription
messagestring
detailunknown

MultipleRowsError

Thrown when a single-row finder (findById, find) returns more than one row.

PropertyTypeDescription
code"MULTIPLE_ROWS"

MultipleRowsError(message)

ParameterTypeDescription
messagestring

NotFoundError

Thrown when a finder returns zero rows and throwIfNotFound is true (the default).

PropertyTypeDescription
code"NOT_FOUND"

NotFoundError(message)

ParameterTypeDescription
messagestring

OptimisticLockError

TS wrapper for the PG-originated ERR01 optimistic concurrency violation.

The DAL does NOT throw this class in the happy/conflict path — PostgreSQL raises RAISE EXCEPTION ... USING ERRCODE = 'ERR01' and node-postgres propagates it as a DatabaseError with err.code === 'ERR01'. This class is provided only for ergonomic instanceof checks if a consumer wants to normalize PG errors into TS errors at a boundary.

Code: ERR01. PG-originated. HTTP 409.

PropertyTypeDescription
code"ERR01"

OptimisticLockError(message)

ParameterTypeDescription
messagestring

RecordVanishedError

Thrown when an auditable-entity write matches zero rows AND a disambiguation SELECT confirms the row no longer exists (was hard-deleted by another writer).

Code: ERR03. TS-originated. HTTP 404.

Distinct from NotFoundError (which is for finders): ERR03 specifically means "the row existed when you read it but is now gone".

PropertyTypeDescription
code"ERR03"

RecordVanishedError(message)

ParameterTypeDescription
messagestring

Repository

Repository(db, token, bulkTimeoutMs)

ParameterTypeDescription
dbQueryable
tokentypeof REPO_INTERNAL
bulkTimeoutMsnumberWhole-operation wall-clock budget (ms) for every
*Many method — the transaction must complete within this bound or it is
aborted and rolled back. 0/undefined disables the budget.
Per-call override: BulkOptions.timeoutMs.

Repository.findById(entity, id, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
idstring | bigint
optionsFindByIdOptions

Repository.findByUUID(entity, uuid, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
uuidstring
optionsFindByUUIDOptions

Repository.find(entity, fields, options): Promise<TResult \| null>

ParameterTypeDescription
entityEntityClass
fieldsFieldProjector[] | null
optionsFindOptions

Repository.findAll(entity, fields, options): Promise<AsyncIterable<TResult, any, any> \| TResult[]>

ParameterTypeDescription
entityEntityClass
fieldsFieldProjector[] | null
optionsFindOptions

Repository.vectorSearch(entity, vectorField, queryVector, options): Promise<TResult & { similarity: number; distance: number }[]>

pgvector nearest-neighbour search — the DAL-native replacement for raw <=>-style similarity queries.

Emits ORDER BY <vectorField> <op> $n::vector LIMIT <topK> with the query vector always bound as a parameter (required for HNSW/ivfflat index usage — never interpolated). Entity-generic: schema, tableName override, filters, projections and soft-delete scoping behave exactly like findAll.

The result carries a similarity score column when distance is the default "<=>" (cosine — 1 - distance, higher = closer). For other operators the projected column is distance (raw distance, lower = closer).

ParameterTypeDescription
entityEntityClass
vectorFieldFieldRef<TEntity, keyof TEntity & string>
queryVectorstring | number[]
optionsVectorSearchOptions<TEntity>

Repository.findByPage(entity, page, recordsPerPage, fields, options): Promise<PaginatedEntity<TResult>>

ParameterTypeDescription
entityEntityClass
pagenumber
recordsPerPagenumber
fieldsFieldProjector[] | null
optionsFindOptions

Repository.count(entity, options): Promise<bigint>

ParameterTypeDescription
entityEntityClass
options{ tableName: string }

Repository.truncate(entity, options): Promise<void>

Physical table reset — TRUNCATE TABLE <schema>.<table> resolved through entity metadata, like every other entity op: the schema-domain guard applies (entities outside the declared domain throw before any SQL). For auditable tables prefer soft-delete; TRUNCATE is for caches, KB stores, and test teardown.

ParameterTypeDescription
entityEntityClass
options{ restartIdentity: boolean; cascade: boolean }

Repository.add(entity, row, options): Promise<TResult>

Add — auditable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
rowPartial<Record<keyof TEntity & string, unknown>>
optionsAuditableWriteOptions<TEntity>

Repository.update(entity, updates, options): Promise<TResult>

Update — auditable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
updatesPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Repository.delete(entity, match, options): Promise<TResult>

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Repository.restore(entity, match, options): Promise<TResult>

Restore — auditable+deletable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Repository.hardDelete(entity, match, options): Promise<TResult>

Hard-delete — auditable entity (actor required for audit log).

ParameterTypeDescription
entityEntityClass & () => TEntity
matchPartial<Record<keyof TEntity & string, unknown>>
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Repository.clone(entity, sourceUuid, options): Promise<TEntity>

Clone an entity record by UUID.

Fetches the source record (including soft-deleted), builds a new row with:

  • PK column excluded (DB auto-generates)
  • Unique columns excluded (including uuid — a new uuid is generated)
ParameterTypeDescription
entityEntityClass & () => TEntity
sourceUuidstring
optionsAuditableWriteOptions

Repository.addMany(entity, rows, options): Promise<BulkResult>

Bulk add — auditable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
rowsPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & BulkOptions

Repository.deleteMany(entity, matches, options): Promise<BulkResult>

Bulk soft-delete — auditable+deletable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity>

Repository.hardDeleteMany(entity, matches, options): Promise<BulkResult>

Bulk hard-delete — auditable entity (actor required for audit).

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

Repository.restoreMany(entity, matches, options): Promise<BulkResult>

Bulk restore — auditable+deletable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
matchesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

Repository.updateMany(entity, updates, options): Promise<BulkResult>

Bulk update — auditable entity (actor required).

ParameterTypeDescription
entityEntityClass & () => TEntity
updatesPartial<Record<keyof TEntity & string, unknown>>[]
optionsWriteOptions<Record<string, unknown>> & { actor: string } & MatchByOptions<TEntity> & BulkOptions

SchemaDomainViolationError

Schema sovereignty domain — the set of PostgreSQL schemas a service is allowed to touch, declared via DATABASE_SCHEMA and pushed here by the Dal constructor (getDal({ schemas })).

Enforcement points:

  • boot: assertEntitySchemaDomain (schema-domain-assert.ts) — every registered
PropertyTypeDescription
code"SCHEMA_DOMAIN_VIOLATION"
details{ entity: string; schema: string; allowed: string[] }

SchemaDomainViolationError(message, details)

ParameterTypeDescription
messagestring
details{ entity: string; schema: string; allowed: string[] }

TranslationEntityBase

TranslationEntityBase — standard i18n translations table entity.

Schema = module boundary. Each module creates a concrete subclass with its own schema. The DAL's Repository resolves the schema natively via getQualifiedTableName(entity) — no raw SQL, no string interpolation.

BE creates entity classes for all modules it manages: @Entity("translations", "public") export class AppTranslationEntity extends TranslationEntityBase {}

@Entity("translations", "system") export class SystemTranslationEntity extends TranslationEntityBase {}

@Entity("translations", "emailsender") export class EmailsenderTranslationEntity extends TranslationEntityBase {}

The BE's central CRUD handler maps module code → entity class → Repository. US microservices do NOT create entity classes — the BE manages their schemas.

Columns: key varchar(255) NOT NULL — full dot-path (e.g. 'app.auth.login.title') language varchar(10) NOT NULL — BCP 47 tag (e.g. 'it-IT') value text NOT NULL — translated string

Composite unique: (key, language) — non-partial index: a soft-deleted row still reserves the key; recreating it surfaces a conflict (ERR05 → restore), never a deleted+live duplicate.

Plus standard audit columns (created_at/by, updated_at/by, version, deleted_at/by).

PropertyTypeDescription
created_atDate
created_bystring
updated_atDate
updated_bystring
versionnumber
deleted_atDate
deleted_bystring
idbigint
uuidstring
keystringFull dot-path translation key (e.g. 'app.auth.login.title').
languagestringBCP 47 language tag (e.g. 'it-IT', 'en-GB').
valuestringTranslated string value.

UnknownColumnError

Thrown when a write operation (add, update) receives a property not in entity metadata.

PropertyTypeDescription
code"UNKNOWN_COLUMN"

UnknownColumnError(message)

ParameterTypeDescription
messagestring

ValidationError

Thrown when a validation check fails (e.g. empty updates object, missing actor).

PropertyTypeDescription
code"VALIDATION"

ValidationError(message)

ParameterTypeDescription
messagestring

Vector

Vector — runtime-identifiable number[] for pgvector vector(N) columns.

A real class (not a brand) so the DAL can detect it with instanceof — array subclasses ARE number[]-assignable but carry runtime identity. That identity is load-bearing: vector params bind as the '[v1,v2,…]' literal, while plain number[] binds as a Postgres array '{v1,v2,…}'.

In entities, embedding: Vector maps to vector; @Column({ length: N }) sets the dimension (vector(N)).

Vector.toString(): string

'[1,2,3]' — the pgvector text input/output literal.

Vector.from(v): Vector

Parse the pgvector literal '[v1,v2,…]' (or a plain number array).

ParameterTypeDescription
vstring | readonly number[] | Vector

Vector.fromNumbers(v): Vector

ParameterTypeDescription
vreadonly number[]

Interfaces

AdvancedFilter

One advanced-filter entry (filters sheet / filters[i][...] URL params).

FieldTypeDescription
idstring
fieldstring
operatorFilterOperator
valueunknown

AggregateDecl

Declarative aggregate rollup projected into list rows.

FieldTypeDescription
namestringOutput column name, e.g. "user_count".
exprstringAggregate SQL expression over the join alias, e.g. "COUNT(u.id)".
caststringOptional result cast — emitted as CAST(<expr> [FILTER...] AS <cast>).
join{ entity: EntityClass; alias: string; base: string; joined: string; extra: string }LEFT join feeding the aggregate.

AuditPageOptions

FieldTypeDescription
tableNamestringe.g. "customers_audit" — the partition parent table name.
entityUuidstring
pagenumber
limitnumber

AuditPageResult

FieldTypeDescription
dataAuditRow[]
pagination{ page: number; limit: number; total: bigint; hasMore: boolean }

AuditPort

Audit port — consumers inject their own audit writer. The DAL calls writeAudit fire-and-forget (.catch(logger?.error ?? noop)).

AuditRow

FieldTypeDescription
idbigint
entity_idbigint
entity_uuidstring
actionstring
changed_atstring
changed_bystring
changed_by_display_namestring | null
changed_by_idp_codestring | null
versionnumber
deltaRecord<string, unknown>

BulkItem

FieldTypeDescription
uuidstring
versionnumber

CollaborationMeta

Collaboration fragment injected by assembleMeta at serve time.

FieldTypeDescription
enabledboolean
expose_editing_valueboolean

DalConfig

Configuration for the Dal gateway.

FieldTypeDescription
connectionStringstringPostgreSQL connection string. Required.
schemasstring[]Declared schema domain — the ONLY PostgreSQL schemas this service may
touch (from DATABASE_SCHEMA). schemas[0] is the owned/primary schema
(patch registry, config_entries live here). Entity operations resolving
outside this set throw SchemaDomainViolationError. Required.
sharedTablesstring[]Shared table names exempt from the schema-domain check — governed
cross-schema table contracts where every module schema carries the
same table and a designated manager reaches all of them. Today only
translations (the BE i18n gateway manages <module>.translations
for every registered module). The entity's schema pin still applies —
only the domain check is bypassed, for that table name only.
maxnumberMaximum pool size. Default: 10.
Formula: max ≤ (PG max_connections − reserved) / service_instances.
The lib cannot pick this for you, but it documents it.
statementTimeoutMsnumberPer-statement timeout in ms, set via SET statement_timeout on every connection.
Default: 30000. Set to 0 to disable.
This is the full wall-clock (command arrival → server completion → all rows transmitted).
bulkTimeoutMsnumberMaximum wall-clock budget in ms for a single *Many operation
(addMany/upsertMany/updateMany/deleteMany). The whole transaction must
complete within this budget — on expiry the work is aborted and the
transaction rolled back (no partial writes).
Default: 1800000 (30 min). Per-call override: BulkOptions.timeoutMs.
Set to 0 to disable.
connectionTimeoutMillisnumberTime to wait when acquiring a connection from the pool before erroring.
Default: 5000. Fail fast when pool exhausted — don't let requests queue forever.
idleTimeoutMillisnumberHow long an idle connection is kept before closing. Default: 30000 (pg default).
maxUsesnumberOptional: recycle connections after N uses to clear per-session state.
Default: undefined (off).
applicationNamestringOptional application_name for PG logging/observability. Default: "primebrick-dal".
repoDecorator(repo: Repository) => RepositoryOptional decorator applied to the Dal's internal root Repository at
construction — the governed seam for cross-cutting behavior such as
entity caching (withCache). The decorated repo backs dal.entityService,
dal.tableAuditPort, and every entity proxy on this instance, so the
decoration applies uniformly without consumers building their own
repositories. Tx-scoped repositories handed to dal.transaction(fn)
callbacks are NOT decorated — writes inside an open transaction must
not trigger cache writes/invalidation before commit.

DuplicateResult

FieldTypeDescription
uuidsstring[]
errors{ uuid: string; error: string }[]

EntityActionEndpoint

Backing route of an EntityAction — emitted by the BE route scan.

FieldTypeDescription
methodstringHTTP method of the backing route (GET, POST, PUT, DELETE, ...).
pathstringFull registered API path with :param placeholders verbatim
(e.g. /api/v1/auth/users/:uuid/restore). Consumers substitute
placeholders from the row (:uuid ← meta.uid).

EntityListQuery

FieldTypeDescription
searchstring
search_instring[]
sort_keystring
sort_dir"asc" | "desc"
pagenumber
page_sizenumber
filtersListFilterCondition[]
connector"AND" | "OR"
deleted_records"EXCLUDED" | "ONLY" | "INCLUDED"

EntityListResult

FieldTypeDescription
rowsTEntity[]
pagenumber
page_sizenumber
totalbigint

EntityMeta

Static entity meta — the shape every *.meta.ts file MUST satisfy. The schema is CLOSED for authored metas: undeclared properties are compile errors, so new meta props require extending this type first.

FieldTypeDescription
entitystringEntity name, snake_case singular (e.g. user_profile).
translation_keystringi18n prefix, snake_case singular — used to build dynamic keys.
entities_nsstringNamespace OWNING this entity's label keys — the module's own namespace
(job → job.entities.<translation_key>.*). Absent → system
(BE/core-owned entities keep system.entities.*).
This is a READ-side reference declared by the owning module — the
namespace write boundary (see translation-keys.ts) guarantees the
keys actually live in that module's <code>.translations schema.
title_keystringOptional i18n key overriding the canonical page title.
When absent, list/create/edit titles are built from the generic
system.entities.page_title.{list|create|edit} templates interpolated
with system.entities.<translation_key>.{plural|singular}.
Set only for custom pages needing a bespoke title — CRUD entity metas
must not declare it.
uidstringField key holding the entity primary key (usually uuid).
display_fieldstringCanonical display field — the column key identifying the entity's
human-readable label. Drives first-column/sticky table identity and
default display resolution.
display_namestringDisplay expression template (${field} syntax, dot-paths allowed).
OPTIONAL here: assembleMeta materializes it as
"${" + display_field + "}" when absent — it is always present in the
served response. Used automatically for edit-page titles; reusable for
comboboxes, lists, chips.
actions_overridesActionsOverridesPer-op enable overrides — may ONLY toggle enabled on route-backed
ops; a missing route already produces enabled: false.
columnsMetaColumn[]Entity field dictionary (root-level, transversal).
tableTableMetaTable options — omit when the entity has no table page
(e.g. a self-service form meta).

EntityService

The contract every entity service must satisfy — enforced on the router.

EntityServiceConfig

FieldTypeDescription
entityEntityClass & () => objectNewable entity class (DB row shape).
repoRepositoryRepository — INTERNAL injection point only. dal.entityService(cfg)
supplies the gateway-owned instance; callers of the free
makeEntityService (tests, decorators such as BE withCache) must
pass one explicitly. Consumer configs MUST NOT set it — a missing
repo is a hard error, not a fallback.
auditPortAuditPortAudit port — defaults to makeTableAuditPort(repo) (the standard
{table}_audit writer). Override only for ports with extra side
effects (e.g. the BE entity-changed marker publisher).
actor() => stringActor supplier for audit stamping (e.g. SDK requireActor).
userEntityEntityClassOptional auditable display-name join target (BE: UserProfileEntity).
auditTableNamestringAudit trail table override — default ${tableName}_audit.
list{ searchableKeys: readonly string[]; filterableKeys: ReadonlySet<string>; defaultSort: { key: string; dir: "asc" | "desc" }; extraFilters: (q: EntityListQuery) => FilterExpr[]; aggregates: AggregateDecl[] }
hooks{ afterWrite: (op: EntityAction, entity: TEntity) => void | Promise<void>; beforeCreate: (body: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>; beforeUpdate: (uuid: string, body: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>> }

IAuditableEntity

Entity has audit stamps (created_at/by, updated_at/by, version). Does NOT imply soft-delete — auditable and deletable are independent capabilities; compose with IAuditableEntity & IDeletableEntity where both are required (the Dal write-path signatures already do this).

FieldTypeDescription
created_atDate
created_bystring
updated_atDate
updated_bystring
versionnumber

IClonableEntity

Entity supports cloning (cloned_from stores UUID of source record).

FieldTypeDescription
cloned_fromstring

IDeletableEntity

Entity supports soft-delete (deleted_at / deleted_by).

FieldTypeDescription
deleted_atDate
deleted_bystring

IExposableEntity

Entity has a public UUID safe to expose outside the system.

FieldTypeDescription
uuidstring

ListFilterParamsOptions

FieldTypeDescription
filterValuesRecord<string, unknown>Toolbar quick-filter values keyed by column key.
columnsreadonly MetaColumn[]Entity columns (needed to map filterValues to the right operator).
advancedFiltersreadonly AdvancedFilter[]FiltersPanel conditions.
connectorstringGlobal connector for advanced filters (AND

ListResponse

The paged list response returned by every entity list endpoint. total is a bigint — parse JSON responses with a bigint-aware parser (extJsonParse from @primebrick/sdk), never JSON.parse.

FieldTypeDescription
rowsTRow[]
pagenumber
page_sizenumber
totalbigint

LoggerPort

Logger port — consumers inject their own logger.

PartitionMaintenanceReport

FieldTypeDescription
parentsPartitionParentReport[]
maintenance_ranbooleanWhether partman.run_maintenance_proc() ran.

PartitionParentReport

FieldTypeDescription
tablestring"schema"."table" of the partitioned parent.
partition_columnstring
retentionstring | nullEffective retention interval actually applied (part_config wins).
children_purgedRecord<string, number>"schema"."child" → rows deleted for expired parents.
strays_deletednumberExpired rows removed from the default partition (never dropped).
partitions_beforenumberLive partition count before/after run_maintenance_proc().
partitions_afternumber
skippedstringSet when the parent was skipped — reason string.

RowCustomAction

UI configuration for a non-standard row CTA (route-backed bare op).

FieldTypeDescription
action_namestringAction/op name — matches the bare op derived from the route
(e.g. change_password).
translation_keystringi18n key for the CTA label.
iconstringIcon name (Lucide in the reference FE).
text_colorstringOptional CSS color class for the label.
disabled_when_deletedbooleanDisable the CTA on soft-deleted rows.
required_permissionstring | string[]Permission required to see/use the action (filtered client-side
against the user's permission set).

SnapshotQueryable

Minimal queryable shape — pg.Pool, pg.PoolClient, or any adapter.

TableMeta

Table options — present only on entities with a table page.

FieldTypeDescription
default_viewViewNameInitial view (default "table").
default_sort{ key: string; dir: SortDir }
default_page_sizenumber
page_size_optionsnumber[]
row_custom_actionsRowCustomAction[]UI config for non-standard row actions (e.g. change password).
Standard ops (edit/delete/duplicate/preview) are derived from
meta.actions — never declared here.
filter_presetsreadonly FilterPreset[]Mutually-exclusive preset WHERE filters — each rendered as its own
toolbar control; the active option's conditions AND into every list
request (see FilterPreset).

TimeoutOverrideOptions

Per-operation timeout override for dedicated-client work (transaction, partitionMaintenance).

FieldTypeDescription
timeoutMsnumberOverride statement_timeout (ms). Transaction-scoped for transaction
(SET LOCAL, auto-resets at COMMIT/ROLLBACK); connection-scoped with
session-default restore for partitionMaintenance.

Types & Enums

AuditableFieldType

MemberValue
CREATED_AT"CREATED_AT"
CREATED_BY"CREATED_BY"
UPDATED_AT"UPDATED_AT"
UPDATED_BY"UPDATED_BY"
VERSION"VERSION"

AuditAction

Audit action enum (mirrors BE's AuditAction).

MemberValue
INSERT"INSERT"
UPDATE"UPDATE"
SOFT_DELETE"SOFT_DELETE"
HARD_DELETE"HARD_DELETE"
RESTORE"RESTORE"
CLONE"CLONE"

DeletableFieldType

MemberValue
DELETED_AT"DELETED_AT"
DELETED_BY"DELETED_BY"

SynchronizableFieldType

MemberValue
LAST_SYNCED_AT"LAST_SYNCED_AT"

ActionsOverrides

Per-op enable overrides — may ONLY toggle enabled on route-backed ops.

Type: Record<string, { enabled: boolean }>

AuditableWriteOptions

Write options for auditable entities — actor is required.

Type: WriteOptions<TEntity> & { actor: string }

AuditParams

Parameters passed to AuditPort.writeAudit.

BulkOptions

Bulk operation options (batch size, timeout).

BulkResult

Result summary of a bulk write (addMany/upsertMany/updateMany/deleteMany).

ColumnOptions

ColumnPgPersistenceHints

DalErrorCode

Type: typeof DalErrorCodes[keyof typeof DalErrorCodes]

DecimalInput

Anything coercion functions accept: Decimal, native number, bigint, or a decimal string.

Type: Decimal \| number \| bigint \| string

DeletionFilterMode

Soft-deletion visibility mode — maps to the deleted_records list param on the wire (non_deleted → EXCLUDED, deleted → ONLY, all → INCLUDED; absent param means the BE default, currently EXCLUDED).

Type: "non_deleted" \| "deleted" \| "all"

EntityAction

Type: "meta" \| "list" \| "export" \| "create" \| "duplicate" \| "bulkDelete" \| "bulkRestore" \| "get" \| "update" \| "delete" \| "purge" \| "restore" \| "audit"

EntityActionSentinel

Sentinel gates a route may declare instead of concrete permissions. Values mirror the Permission enum in @primebrick/sdk.

Type: "_public" \| "_authenticated_user" \| "_authenticated_admin"

EntityAnnotationInfo

Per-property type facts extracted from source.

EntityAnnotationMap

Result of extractEntityAnnotations — keyed by class name.

EntityClass

Entity metadata via legacy TypeScript decorators (WeakMap "reflection").

Convention: every "data" property on the class prototype is a SQL column with a name equal to the property name (snake_case). @Column() is only needed for: sqlName / pgType / nullable, or a short alias for the column name.

  • @Entity() — table name; optional argument if different from class name.
  • @Key() — primary key (one column only).
  • @Unique() — unique index (DDL patch).
  • @IsNotColumn() — excludes the property from persistence meta & DAL queries.
  • @AuditableField(type) — marks a field as audit (created_at, created_by, etc.).
  • @DeletableField(type) — marks a field as soft-delete (deleted_at, deleted_by).
  • @CloneField() — marks a field as clone tracking (cloned_from).
  • @AuditTrail() — marks the entity as having an audit trail table.

Type: (args: any[]) => object

EntityColumnTypeHints

EntityCtor

Entity capability mixins — declare shared audit/deletable columns ONCE, compose them per-entity instead of copy-pasting decorated fields.

Auditable and deletable are ORTHOGONAL capabilities:

  • audit-only (hard delete): class ApiKey extends Auditable(EntityBase)
  • delete-only: class Tag extends Deletable(EntityBase)
  • both (soft delete): class Customer extends Deletable(Auditable(EntityBase))
  • neither: class Telemetry extends EntityBase

The concrete entity still owns @Entity(table) and the opt-in @AuditTrail() (audit-log table — separate decision from audit columns). Field decorators on each anonymous mixin class register on that constructor; getEntityPersistenceMeta merges the whole prototype chain parent-first (see collectMetaChain), so subclass fields always win.

Extra per-entity capabilities (IExposableEntity, IClonableEntity, …) keep their implements on the concrete class — they are pure type contracts, not column sets.

Type: (args: any[]) => object

EntityMetaResponse

The served GET /api/v1/entities/{entity}/meta response: static meta + runtime-injected display_name, actions, collaboration.

Type: EntityMeta & { display_name: string; actions: EntityAction[]; collaboration: CollaborationMeta }

EntityPersistenceMeta

Serializable persistence metadata (for JSON compare with DB introspection).

EntityTypeWarning

Advisory warning — never fails a build, printed by primebrick-db.

ExprOperand

A parameterized SQL operand for Filter.expr — ? markers inside sql are replaced by $n bound parameters in order of appearance.

sql is a trusted literal (never interpolated user input); params carries the only dynamic data. Example: { sql: "to_tsvector(?, d.content)", params: ["simple"] }

FieldProjector

Type: { kind: "field"; field: FieldRef<any, any>; alias: string } \| { kind: "expr"; expr: string; alias: string; params: unknown[] }

FieldRef

FilterCondition

One WHERE condition of a filter preset — serialized verbatim as a filters[i] entry on the /list query string (same vocabulary as AdvancedFilter conditions: field/op/value).

FilterExpr

Type: { kind: "field_value"; left: FieldRef<any, any>; op: SqlOperator; right: unknown; operand: SqlExpressionOperand } \| { kind: "field_field"; left: FieldRef<any, any>; op: SqlOperator; right: FieldRef<any, any>; operand: SqlExpressionOperand } \| { kind: "raw"; left: string; op: SqlOperator; right: string; operand: SqlExpressionOperand } \| { kind: "expr"; left: ExprOperand; op: SqlOperator; right: ExprOperand; operand: SqlExpressionOperand } \| { kind: "group"; filters: FilterExpr[]; operand: SqlExpressionOperand; connector: SqlExpressionOperand }

FilterOperator

Filter operators available for advanced filters.

Type: "=" \| "!=" \| ">" \| "<" \| ">=" \| "<=" \| "contains" \| "startsWith" \| "endsWith" \| "BETWEEN"

FilterPreset

A mutually-exclusive preset filter group rendered as its own control in the table toolbar (tandem with the deletion-filter group). Exactly one option is always active — there is no "clear" affordance. Declared in meta.table.filter_presets; example: a schedule_type scope selector (recurring / once / all) on a jobs table.

FilterPresetOption

A single selectable option of a table filter preset.

FindByIdOptions

Options for findById.

FindByUUIDOptions

Options for findByUUID.

FindOptions

Options for find, findAll, findByPage.

ForeignKeyAction

Type: "restrict" \| "cascade" \| "set_null" \| "set_default" \| "no_action"

ForeignKeyOptions

Options for @ForeignKey() — REFERENCES target entity column.

GroupByOperand

GROUP BY operand — either an entity field reference or a parameterized SQL expression (? markers bind params in order). Expressions are required for grouping over computed values like date_trunc(?, created_at). Non-aggregate field projections are auto-added to GROUP BY by the builder; expression projections must be listed here explicitly when they are the grouping key.

Type: FieldRef<any, any> \| { kind: "expr"; sql: string; params: unknown[] }

HostApiFn

ctx.components.hostApi — the host's authenticated full-path fetch (apiFetch): reaches BE-owned /api/v1/… endpoints that ctx.api (ws-bound to the owning service) cannot. Remote pages bind it through bindRemoteCtx(ctx) → getServiceApi('host').

Type: (path: string, init: RequestInit) => Promise<Response>

HostMountHandle

Handle returned by ModulePageHost.mount_host — imperative channel to a host-mounted component root.

IndexMethod

Type: "btree" \| "hash" \| "gin" \| "gist" \| "spgist" \| "brin" \| "hnsw"

IndexOptions

Options for @Index() — plain (non-unique) secondary indexes of any PG access method.

ISODate

Type: string & { [isoDateBrand]: "ISODate" }

ISOTime

Type: string & { [isoTimeBrand]: "ISOTime" }

JoinExpr

KeyOptions

LikelyRename

ListConnector

Global connector joining the advanced-filter group.

Type: "AND" \| "OR"

ListFilterCondition

ListFilterOptions

MatchByOptions

Options for match-by operations (update, delete, restore, hardDelete, *Many).

MetaColumn

Entity field descriptor — the root-level columns dictionary. Transversal to every page type: table cells, form tooltips, labels.

Declared as a type alias (not interface): object literal types get an implicit index signature, keeping MetaColumn assignable to Record<string, unknown> — host/remotes pass columns through generic cell-snippet args typed as Record<string, unknown>.

MetaColumnType

UI column renderer type. NOTE: this is the UI type, not the DB type — e.g. roles is "text" here but jsonb on disk (never ILIKE-searchable).

Type: "text" \| "badge" \| "boolean" \| "color" \| "date" \| "datetime" \| "number" \| "sparkline"

MfaStepUpFn

ctx.components.mfaStepUp — host-bound step-up MFA bridge. The remote calls it exactly like the host's useMfaStepUp().executeWithToken: requestFn runs once with token = null; on a 403 response carrying mfa_step_up_required the host shows ITS OWN step-up dialog (host root, host runtime — nothing crosses the boundary), awaits verification, then retries requestFn with the action-authorization token. The promise resolves with the final Response — success or failure.

Type: (requestFn: (token: string \| null) => Promise<Response>, context: { action: string; target_resource: string }) => Promise<Response>

MigrationEngineOptions

Migration engine — apply side. Generation side lives in schema-diff/.

MigrationMode

Migration engine — apply side. Generation side lives in schema-diff/.

Type: "apply" \| "check" \| "off"

MigrationRunResult

Migration engine — apply side. Generation side lives in schema-diff/.

ModuleHostBase

Host-side context base handed to EVERY remote mount — pages (mountPage) and sheets (mountSheet) alike. Versioned via host_version — remote chunks can refuse incompatible hosts.

HARD CONSTRAINT — plain values and functions ONLY: Svelte rune state ($state/$derived/$effect) is bundle-local and cannot cross this boundary. UI building blocks come from @primebrick/ui bundled inside the remote chunk, not from ctx; components is reserved for the few host-coupled cases (see components doc).

ModuleHostComponents

ctx.components — the reserved well-known keys plus open caller-provided entries. remote is assigned by the host loader after the chunk resolves; mfaStepUp/openSheet/hostApi are built-ins the host always provides (a caller may override them in tests).

ModuleNavDeclaration

A module's self-described navigation declaration — the payload a service publishes in service.register (endpoints.nav) so the FE can render the module's sidebar nav and the census can resolve its routes WITHOUT the BE hardcoding another module's pages. This is the wiring that lets each module present its own nav — a remote page is owned by the service that ships it, never declared inside a host module's registry.

route_prefixes drive active-module resolution (longest-prefix match — a page under a shared prefix like /system/jobs resolves to the owning module, not to the module owning the broader /system prefix).

ModuleNavLink

One sidebar navigation link contributed by a module. children is the collapsible-group mechanism (the shell renders children under the parent).

ModuleNotifyInput

Notification payload accepted by ctx.notify — the minimal shape of the host's pushNotification input. Plain values only.

ModulePageHost

Host ctx handed to a remote page's mountPage(el, ctx) — the shared ModuleHostBase plus the page's own route axis (nav/meta).

Type: ModuleHostBase & { nav: PageRouteDeclaration; meta: EntityMeta }

ModuleSheetDecl

A remote sheet panel declared by a service inside endpoints.nav.sheets — the sheet analogue of a remote PageRouteDeclaration: the host owns the sheet ENGINE (open/close/chrome/state), the owning service owns the CONTENT — an esm-mount chunk exporting mountSheet(el, ctx), mounted at runtime into the host's global sheet surface.

key is the open-sheet address, <module>.<name> namespaced so a declared key can never collide across services (enforced at enrollment by the nav-declaration validator). Anyone holding the key can open it — host openSheet, ctx.components.openSheet — visibility is gated by access, never by import reachability.

ModuleSheetDefaults

Chrome defaults a sheet declaration may suggest. The caller's openSheet options always win over these — they are a hint, not a policy. content_class maps to the host engine's contentClass option.

ModuleSheetHost

Host ctx handed to a remote sheet's mountSheet(el, ctx) — the shared ModuleHostBase plus the sheet control surface: the declared key, the caller's props (opaque at the boundary — the owning module knows their shape), the current chrome, and the commands to mutate the host-owned frame. No nav/meta — a sheet is not a route; domain context arrives through sheet.props.

Type: ModuleHostBase & { sheet: { key: string; props: Record<string, unknown>; side: ModuleSheetSide; modal: boolean; close: () => void; replace: (props: Record<string, unknown>) => void; setExpanded: (expanded: boolean) => void } }

ModuleSheetSide

Sheet side — the two chrome slots the host sheet engine owns.

Type: "left" \| "right"

MountPageFn

The esm-mount chunk's entry contract — export function mountPage(el, ctx). May return the mount() result (disposed via unmount()), a custom dispose function, or a promise of either.

Type: (el: HTMLElement, ctx: ModulePageHost) => unknown

MountSectionFn

A chunk's section-mount export — same host ctx as mountPage, plus the section's own declaration (id, props, placement) as third argument.

Type: (el: HTMLElement, ctx: ModulePageHost, section: PageSectionDecl) => unknown

MountSheetFn

The sheet chunk's entry contract — export function mountSheet(el, ctx). The chunk is declared in endpoints.nav.sheets[] (ModuleSheetDecl) and mounted inside the host's global sheet surface. Same dispose rules as MountPageFn.

Type: (el: HTMLElement, ctx: ModuleSheetHost) => unknown

OnConflictMode

Insert conflict semantics for add().

Type: "raise" \| "ignore"

OpenSheetFn

ctx.components.openSheet — opens a sheet panel by key: a host-registered panel (shell.*/entity.*/config.*) or a remote-declared sheet (<module>.<name> from nav.sheets[], mounted at runtime). The panel registry, remote declarations and sheet state all live in the host — a remote page requests the panel, it never ships the engine. props are plain values (callback fns are allowed — they cross the boundary); options are the host's sheet options (side, contentClass, modal, keepMountedState). Unknown keys are rejected with a host notification — the remote cannot smuggle an undeclared panel.

Type: (panelKey: string, props: Record<string, unknown>, options: Record<string, unknown>) => void

PageLayoutDecl

Spatial arrangement of a page's sections — ONE archetype: CSS grid. A vertical stack is the degenerate case (columns defaults to "1fr", sections auto-flow in declaration order); a split is columns: "280px 1fr"; a dashboard is columns: "repeat(3, 1fr)" + per-section span. New container classes, when genuinely needed, arrive as new optional fields — the contract never grows a second placement vocabulary.

PageRouteComponentFormat

Remote component delivery format. Extensible — new literals are additive and non-breaking. esm-mount: a precompiled ESM chunk that exports mountPage(el, ctx) (or a default component as fallback).

Type: "esm-mount"

PageRouteDeclaration

One declared frontend route owned by a module. Modules MUST declare every FE path they own that is not deducible from nav links or entity conventions — the AI route census (derived from the consolidated GET /api/v1/modules discovery payload) depends on it. param marks dynamic segments using the FE convention ([uuid], [code]).

PageRouteKind

Page archetype vocabulary — what the route renders, regardless of delivery.

Type: "list" \| "detail" \| "create" \| "page"

PageRouteProps

page_props — free-form per-route metadata with a typed layout axis.

PageSectionDecl

One mountable block inside a layout — placement is grid-cell based.

PageSectionSource

Section mount target — remote:<export> = a named mount export of the page's own chunk (mod.mountModels(el, ctx, section)); host:<key> = a component registered in the host's section registry. The remote: form is the default for module-owned blocks; host: composes host-owned building blocks without shipping a chunk at all.

Type: templateLiteral \| templateLiteral

PaginatedEntity

Paginated result wrapper.

PartitionChildOfOptions

Options for @PartitionChildOf() — declares membership in a partitioned parent's atomic delete/retention unit.

PartitionFieldOptions

Options for @PartitionField() — the RANGE partition key declaration.

PatchManifest

PatchRegistryRow

PatchSegment

PatchStatus

Type: "pending" \| "applied" \| "failed" \| "pending_review" \| "approved" \| "resolved_manual"

PgColumnType

pgType values legal in @Column({ pgType }).

Type: PgScalarType \| templateLiteral \| templateLiteral \| "vector"

PgScalarType

PgColumnType — the canonical PostgreSQL column type vocabulary for @Column({ pgType }) and the entity type contract.

A closed union, not a free string: aliases like "timestamp with time zone" (write timestamptz) or "character varying" (write varchar) are compile errors, so the diff/snapshot pipeline never sees spelling variants.

Type modifiers are NEVER written inside pgType: varchar(N) comes from length, numeric(p,s) from precision/scale, vector(N) from length on a Vector prop. pgType carries the BASE name only (vector(N) literal is allowed for readability but length wins).

Type: "text" \| "varchar" \| "char" \| "citext" \| "uuid" \| "smallint" \| "int2" \| "integer" \| "int" \| "int4" \| "bigint" \| "int8" \| "real" \| "float4" \| "double precision" \| "float8" \| "numeric" \| "decimal" \| "boolean" \| "bool" \| "date" \| "time" \| "timetz" \| "timestamp" \| "timestamptz" \| "interval" \| "inet" \| "cidr" \| "macaddr" \| "macaddr8" \| "json" \| "jsonb" \| "bytea" \| "xml" \| "tsvector"

RemoteDepsManifest

<chunk>.deps.json — emitted next to each remote chunk at build time, declaring the vendor specifiers/versions it was compiled against.

RenameAmbiguity

RenameHeuristicResult

RoundingMode

Type: "UP" \| "DOWN" \| "CEILING" \| "FLOOR" \| "HALF_UP" \| "HALF_DOWN" \| "HALF_EVEN"

SchemaColumnMeta

Shared shapes for entity vs database schema snapshots (used by compare + heuristics).

SchemaDomain

SchemaMetaDiffV1

Type: SchemaMetaDiffV2

SchemaMetaDiffV2

SchemaSnapshot

Schema-diff: canonical entity-vs-database snapshot machinery. Generation side of the migration engine (migrations/ is the apply side).

SchemaTableMeta

Schema-diff: canonical entity-vs-database snapshot machinery. Generation side of the migration engine (migrations/ is the apply side).

SelectQueryInput

SnakeCaseSingular

Branded type that enforces snake_case singular (no uppercase letters). Used for translation_key in entity meta — the i18n key prefix.

The brand is applied via asSnakeCaseSingular(), which performs a runtime check rejecting strings containing A-Z. This catches camelCase (userProfile), PascalCase (RoleMapping), and UPPER_CASE (USER_PROFILE) at both compile time and runtime.

Type: string & { __snakeCaseSingularBrand: unique symbol }

SortDir

Sort direction for server-side list queries and header UI.

Type: "asc" \| "desc"

SortingExpr

Type: { field: FieldRef<any, any>; dir: SqlSortDirection } \| { kind: "alias"; alias: string; dir: SqlSortDirection } \| { kind: "expr"; sql: string; params: unknown[]; dir: SqlSortDirection }

SqlExpressionOperand

Type: "AND" \| "OR"

SqlJoinType

Type: "INNER" \| "LEFT" \| "RIGHT"

SqlOperator

Type: "=" \| "!=" \| "<>" \| "<" \| "<=" \| ">" \| ">=" \| "ILIKE" \| "LIKE" \| "IN" \| "NOT IN" \| "BETWEEN" \| "IS" \| "IS NOT" \| "<=>" \| "<->" \| "<#>" \| "<+>" \| "<~>" \| "<%>" \| "@@"

SqlQuery

SqlSortDirection

Type: "ASC" \| "DESC"

StandardOp

Type: typeof STANDARD_OPS[number]

TooltipPriority

Tooltip visual severity — drives icon and title color in priority tooltip renderers.

Type: "INFORMATION" \| "WARNING" \| "ERROR" \| "QUESTION" \| "HINT" \| "SUCCESS"

TrustedKey

UniqueOptions

Unique constraint options for composite unique indexes.

UpsertOptions

Upsert-specific options.

UUID

Type: string & { [uuidBrand]: "UUID" }

VectorDistanceOp

pgvector distance operator for vectorSearch — <=> cosine, <-> L2, <#> inner product, <+> L1.

Type: "<=>" \| "<->" \| "<#>" \| "<+>"

VectorHybridInput

VectorSearchOptions

Options for Repository.vectorSearch — entity-generic like FindOptions.

VendorManifest

Host vendor-manifest.json — specifier → published vendor asset.

Type: Record<string, { url: string; version: string }>

VendorMismatch

Type: { specifier: string; kind: "missing"; required: string } \| { specifier: string; kind: "version"; required: string; provided: string }

VendorResolution

Type: "external" \| "reject" \| "bundle"

VendorSpecifier

Type: typeof VENDOR_SPECIFIERS[number]

ViewName

Table view names supported by entity list pages.

Type: "table" \| "cards" \| "cards_list"

WithAuditableDisplayNames

Adds display name fields to a row type for auditable entities. Use this to type the result of queries that include auditable joins.

Type: T & { created_by_name: string; updated_by_name: string; deleted_by_name: string }

WithCreatorDisplayName

Adds only creator display name (for cases where you only need created_by).

Type: T & { created_by_name: string }

WithDeletedRecords

Controls how soft-deleted rows (deleted_at IS NOT NULL) are handled in finders.

Type: "EXCLUDED" \| "ONLY" \| "INCLUDED"

WithUpdaterDisplayName

Adds only updater display name (for cases where you only need updated_by).

Type: T & { updated_by_name: string }

WriteOptions

Base write options — no actor (for non-auditable entities).

Constants

DalErrorCodes

Stable error codes for DAL optimistic concurrency control.

These codes are used as PostgreSQL SQLSTATE values (via RAISE EXCEPTION USING ERRCODE = 'ERR01') and as TS DalError.code values. Consumers (BE, US, FE) branch on the string literal (e.g. err.code === 'ERR01') so that PG-originated errors and TS-originated errors share the same code.

Convention: ERR + 2 digits. The ER class is outside the SQL-standard SQLSTATE classes (00–99), so PostgreSQL accepts it as a custom code.

Type: { ERR01: "ERR01"; ERR02: "ERR02"; ERR03: "ERR03"; ERR04: "ERR04"; ERR05: "ERR05"; ERR06: "ERR06"; ERR07: "ERR07"; ERR08: "ERR08"; ERR09: "ERR09"; ERR10: "ERR10" }

FieldValue
ERR01"ERR01"
ERR02"ERR02"
ERR03"ERR03"
ERR04"ERR04"
ERR05"ERR05"
ERR06"ERR06"
ERR07"ERR07"
ERR08"ERR08"
ERR09"ERR09"
ERR10"ERR10"

decimalFromPG

Alias of dec() — parse a PostgreSQL numeric/decimal text value.

Type: typeof dec

Filter

Type: { fieldValue: ; fieldField: ; raw: ; expr: ; group: }

FieldValue
fieldValue""
fieldField""
raw""
expr""
group""

fromString

Type: typeof dec

fromWire

Alias of dec() — tolerates the "…d" wire suffix.

Type: typeof dec

GroupBy

Type: { expr: }

FieldValue
expr""

Join

Type: { on: }

FieldValue
on""

KEYS_FILENAME

Type: "keys.json"

MANIFEST_FILENAME

Type: "MANIFEST.json"

NUMERIC_MIN_SIG_DIGITS

Minimum significant digits preserved by automatic div scale — mirrors PostgreSQL NUMERIC_MIN_SIG_DIGITS (16). See pgDivScale.

Type: 16

ONE

Type: Decimal

PATCH_REGISTRY_TABLE

Per-service-schema patch registry (v2).

Each service owns <svc_schema>.primebrick_database_patches — the registry is domain data of the owning microservice, not a shared global table. The DDL is self-bootstrapping: the engine runs it unconditionally before any read, so an empty database upgrades itself.

Type: "primebrick_database_patches"

Project

Type: { field: ; expr: }

FieldValue
field""
expr""

RENAME_HEURISTIC_AGENT_INSTRUCTION

Type: "renameHeuristicUserReviewRequired is true: ambiguous rename candidates were detected. You MUST ask the user which renames (if any) to apply before running suggested ALTER ... RENAME COLUMN or generating migrations from likelyRenames."

RENAME_MATCH_RULE_LABELS

Ordered strict → loose; documented for consumers of diff-entities-vs-database.json.

Type: readonly string[]

Sort

Type: { by: ; byAlias: ; byExpr: }

FieldValue
by""
byAlias""
byExpr""

STANDARD_OPS

The canonical vocabulary of standard entity ops. Every op is always present in meta.actions — ops whose route is not registered are emitted with enabled: false (explicitly unavailable) instead of being omitted.

Type: readonly ["list", "meta", "get", "create.single", "update.single", "delete.single", "purge.single", "restore.single", "read.audit", "export", "delete.bulk", "restore.bulk", "duplicate.bulk"]

TEN

Type: Decimal

VENDOR_BLOCKED_PACKAGES

Packages that MUST NOT be imported raw inside a remote chunk — they are already served through a sanctioned vendor specifier (e.g. transformers is vendored behind @primebrick/ui/vendor/transformers). A raw import would bundle a second runtime copy (split caches, split env config) — reject it.

Type: readonly ["@huggingface/transformers", "clsx", "tailwind-merge", "tailwind-variants", "@lucide/svelte", "bits-ui"]

VENDOR_SPECIFIERS

Closed allowlist of bare specifiers remote chunks may import. A package's specifiers normally union into ONE bundle file so the browser dedupes by URL — a single runtime instance is guaranteed. Exception: svelte's public subpaths (events/reactivity/store/attachments) get their own files — their export names collide with the internal signal API (get/derived exist in both), and a flat union module cannot hold both. Shared internals still dedupe through the bundler's shared chunks.

Type: readonly ["svelte", "svelte/internal/client", "svelte/internal/disclose-version", "svelte/internal/flags/legacy", "svelte/events", "svelte/reactivity", "svelte/store", "svelte/attachments", "svelte/motion", "svelte/easing", "@primebrick/core", "@primebrick/ui", "@primebrick/ui/vendor/transformers", "@primebrick/ui/vendor/clsx", "@primebrick/ui/vendor/tailwind-merge", "@primebrick/ui/vendor/tailwind-variants", "@primebrick/ui/vendor/lucide", "@primebrick/ui/vendor/bits-ui"]

ZERO

Type: Decimal

Functions

abs(d): Decimal

ParameterTypeDescription
dDecimalInput

add(a, b): Decimal

ParameterTypeDescription
aDecimalInput
bDecimalInput

allowedKeyNamespaces(moduleCode): ReadonlySet<string>

Namespaces a module's meta/nav declarations may REFERENCE — the module's own namespace plus the CORE vocabularies (app, system).

ParameterTypeDescription
moduleCodestring

appendListFilterParams(params, opts, startIdx): number

ParameterTypeDescription
paramsURLSearchParams
optsListFilterParamsOptions
startIdxnumber

approvePendingReview(pool, schema, patchName, actor, note): Promise<boolean>

pending_review → approved for ONE named patch: the engine treats an approved row as review-cleared and applies the file on the next run.

ParameterTypeDescription
poolPool
schemastring
patchNamestring
actorstring
notestring

assertEntitySchemaDomain(entities, schemas, sharedTables): void

Boot-time check: every registered entity must resolve inside schemas (an explicit

ParameterTypeDescription
entitiesreadonly unknown[]
schemasreadonly string[]
sharedTablesreadonly string[]

assertPgTypeCompatible(annotation, explicitPgType, propertyKey): void

Throws when an explicit pgType is incompatible with the declared TS annotation family (e.g. UUID + pgType:"text", number + pgType: "int8"). Unmappable families pass — the explicit type is their contract.

ParameterTypeDescription
annotationEntityAnnotationInfo
explicitPgTypestring
propertyKeystring

asSnakeCaseSingular(value): SnakeCaseSingular

Branded constructor for SnakeCaseSingular. Throws if the value contains uppercase letters (camelCase/PascalCase/UPPER_CASE).

ParameterTypeDescription
valuestring

Auditable(Base): { prototype: AuditableEntity<any> } & TBase

Adds created_at / created_by / updated_at / updated_by / version (optimistic-lock column). Does NOT add soft-delete — compose Deletable when the entity needs it.

ParameterTypeDescription
BaseTBase

AuditableField(what): PropertyDecorator

Marks a field as auditable (created_at, created_by, updated_at, updated_by, version).

ParameterTypeDescription
whatAuditableFieldType

AuditTrail(): ClassDecorator

Marks an entity as having an audit trail table.

AuditTrailEntity(options): ClassDecorator

Marks a class as BEING an audit trail entity (e.g., AuditLogEntity). Distinct from @AuditTrail() which marks an entity as HAVING an audit trail. The changedByColumn specifies which property holds the actor (default: "changed_by").

ParameterTypeDescription
options{ changedByColumn: string }

buildAuditableJoins(entity, userEntity): JoinExpr[]

Standard join configuration for auditable entities. Automatically adds LEFT JOINs to the user entity table for created_by, updated_by, deleted_by fields.

Uses regex guardrail pattern to only join when the field contains a valid UUID. This prevents errors when the field contains non-UUID values like "system".

ParameterTypeDescription
entityEntityClassThe entity class implementing IAuditableEntity
userEntityEntityClassThe user entity class (e.g. UserProfileEntity) that has a uuid and display_name column

buildAuditableJoinsSelective(entity, userEntity, options): JoinExpr[]

Enhanced version that allows selective joins (e.g., only creator and updater). Useful when you only need specific audit fields to reduce query overhead.

ParameterTypeDescription
entityEntityClassThe entity class implementing IAuditableEntity
userEntityEntityClassThe user entity class (e.g. UserProfileEntity)
options{ includeCreator: boolean; includeUpdater: boolean; includeDeleter: boolean }Configuration for which joins to include

buildAuditTrailJoins(auditEntity, userEntity): { joins: JoinExpr[]; projections: FieldProjector[] }

Build LEFT JOIN + projections for audit trail entities (AuditLogEntity).

Audit trail entities have a single changed_by column (not created_by/updated_by/deleted_by). This function joins the user entity to resolve changed_by into display_name and idp_code.

Uses castRightTo: "uuid" + castLeftTo: "uuid" to trigger the regex guardrail (changed_by ~ '^[0-9a-fA-F-]{36}$') automatically in renderJoins(). This prevents errors when changed_by contains non-UUID values like "system".

Distinct from buildAuditableJoins() which uses castRightTo: "text" (no guardrail, text = text). buildAuditTrailJoins() uses castRightTo: "uuid" + castLeftTo: "uuid" (guardrail + uuid = uuid).

ParameterTypeDescription
auditEntityEntityClassThe audit trail entity class (e.g., AuditLogEntity)
userEntityEntityClassThe user entity class (e.g., UserProfileEntity) with uuid, display_name, idp_code columns

buildDatabaseSnapshot(db, tables, generatedAt): Promise<SchemaSnapshot>

Introspect given tables into the same SchemaSnapshot shape as entities. Uses pg_attribute / pg_type / format_type (pg-diff-api CatalogApi style) so PostGIS and other UDTs surface with real typname / typcategory, not only information_schema.data_type.

The caller owns the connection: pass a Pool (read-only fan-out) or a reserved client.

ParameterTypeDescription
dbSnapshotQueryable
tables{ schema: string; name: string }[]
generatedAtstring

buildEntitySnapshot(registry, opts, generatedAt): SchemaSnapshot

Canonical entity-intent snapshot for a service's entity registry. Parameterized on the registry — no service-specific imports live here.

ParameterTypeDescription
registryreadonly EntityClass[]
optsBuildEntitySnapshotOptions
generatedAtstring

buildPatchFilename(diff, d): string

ParameterTypeDescription
diffSchemaMetaDiffV2
dDate

buildSelectQuery(input): SqlQuery

ParameterTypeDescription
inputSelectQueryInput

buildSqlPatchFromMetaDiff(entitySnap, diff): string

Best-effort SQL to move TARGET database toward entity intent. Destructive changes (DROP) are never emitted — DB-only objects are WARN comments.

ParameterTypeDescription
entitySnapSchemaSnapshot
diffSchemaMetaDiffV2

buildVectorSearchQuery(input): SqlQuery

ParameterTypeDescription
inputVectorHybridInput

calculateDelta(oldEntity, newEntity): Record<string, { old: unknown; new: unknown }>

Calculate delta between old and new records for audit.

ParameterTypeDescription
oldEntityRecord<string, unknown>
newEntityRecord<string, unknown>

calculateDeltaWithForcedFields(oldEntity, newEntity, forceFields): Record<string, { old: unknown; new: unknown }>

Calculate delta and force include specific fields even when unchanged.

ParameterTypeDescription
oldEntityRecord<string, unknown>
newEntityRecord<string, unknown>
forceFieldsstring[]

canonicalJson(value): string

Stable JSON: object keys sorted recursively so signatures are deterministic.

ParameterTypeDescription
valueunknown

canonicalPgType(t): string

Fold alias spellings to canonical names (integer → int4, …).

ParameterTypeDescription
tstring

ceil(d): Decimal

Smallest integer >= d.

ParameterTypeDescription
dDecimalInput

checkDrift(registry, db, opts): Promise<SchemaMetaDiffV2>

ParameterTypeDescription
registryreadonly EntityClass[]
dbSnapshotQueryable
optsBuildEntitySnapshotOptions

classifyRenamePair(eMeta, dMeta): { matchTier: number; reasons: string[] } \| null

Assigns the single strictest tier that applies, or null if no rule matches.

ParameterTypeDescription
eMetaSchemaColumnMeta
dMetaSchemaColumnMeta

CloneField(): PropertyDecorator

Marks a field as clone tracking (cloned_from). Stores UUID of the source record.

cmp(a, b): -1 \| 0 \| 1

Numeric comparison ignoring scale: cmp(1.0, 1.00) === 0. Returns -1 | 0 | 1.

ParameterTypeDescription
aDecimalInput
bDecimalInput

collectEntityTypeWarnings(registry, annotations): EntityTypeWarning[]

Advisory authoring warnings across a registry — *_uuid columns that do not resolve to uuid, and pgType declarations that restate the inferred default. Requires the static annotation map; warnings never fail a gate.

ParameterTypeDescription
registryreadonly EntityClass[]
annotationsEntityAnnotationMap

Column(sqlName): PropertyDecorator

Override SQL name / pgType / nullable only; otherwise the property is already a column by convention.

ParameterTypeDescription
sqlNamestring

columnHintsFromMetaColumn(col): ColumnPgPersistenceHints

ParameterTypeDescription
col{ propertyKey: string; sqlName: string; isKey: boolean; isUnique: boolean; uniqueIndexName: string; uniqueIndexOrder: number; nullable: boolean; pgType: string; jsType: "vector" | "decimal" | "instant"; defaultSql: string; length: number; precision: number; scale: number; inferredPgType: string; usePostgresIdentity: boolean; isAuditable: boolean; auditableType: AuditableFieldType; isDeletable: boolean; deletableType: DeletableFieldType; isSynchronizable: boolean; synchronizableType: SynchronizableFieldType; isClone: boolean; castInJoin: string; isPartition: boolean; partitionOpts: PartitionFieldOptions }

columnTypeWarnings(entityName, h, resolved): EntityTypeWarning[]

Authoring warnings for one column:

  • uuid-name — a *_uuid/uuid column resolving to a non-uuid type. The name SAYS uuid; either the column should be uuid (retype the prop to UUID or set pgType:"uuid") or the name lies.
  • redundant-pgType — explicit pgType equal to what the annotation already infers; drop it (we never spell out the default).
ParameterTypeDescription
entityNamestring
hEntityColumnTypeHints
resolvedstring

comparablePgType(meta): string

Build a stable string for equality checks across entity hints and catalog introspection.

ParameterTypeDescription
metaPick<SchemaColumnMeta, "typname" | "typcategory" | "dataType" | "formatType">

compareSnapshots(entitySnap, dbSnap): SchemaMetaDiffV2

ParameterTypeDescription
entitySnapSchemaSnapshot
dbSnapSchemaSnapshot

configureSchemaDomain(schemas, sharedTables): SchemaDomain

Called once by the Dal constructor. Re-calls replace the domain (tests).

ParameterTypeDescription
schemasstring[]
sharedTablesstring[]

createStream(db, text, values): AsyncIterable<TResult>

Creates an AsyncIterable from a SQL query using pg-query-stream.

ParameterTypeDescription
dbQueryableThe pg Pool or PoolClient
textstringSQL query text
valuesunknown[]Parameter values

dec(input): Decimal

Decimal — pass-through. string — parsed (PG text form or "…d" wire form). number — via shortest round-trip toString so 0.1 stays "0.1". bigint — scale 0.

ParameterTypeDescription
inputDecimalInput

decimalToPG(d): string

PostgreSQL parameter form — plain canonical decimal string, no d suffix.

ParameterTypeDescription
dDecimalInput

defaultSearchGate(trimmed): boolean

search-gate — canonical "should this search query hit the server" predicate.

Mirrors the backend list-search gate: ≥3 "real" characters, or an escaped wildcard (\* / \?) with ≥1 real char. Prevents per-keystroke queries while still allowing single-char wildcard searches.

Canonical home for both the host FE and remote module pages — the gate must match the server-side rule byte-for-byte.

ParameterTypeDescription
trimmedstringthe search string, already .trim()ed by the caller

defaultVisibleColumnKeys(columns): string[]

Keys visible by default — from column flags.

ParameterTypeDescription
columnsMetaColumn[]

Deletable(Base): { prototype: DeletableEntity<any> } & TBase

Adds deleted_at / deleted_by — soft-delete markers.

ParameterTypeDescription
BaseTBase

DeletableField(what): PropertyDecorator

Marks a field as deletable (deleted_at, deleted_by).

ParameterTypeDescription
whatDeletableFieldType

diffVendorRequirements(requires, manifest): VendorMismatch[]

Vendor compatibility check — exact-match policy. A remote chunk compiled against a different version of a vendored package is incompatible: svelte/internal/* is not a stable API and each union bundle's export set may change between versions. The remedy is rebuilding the remote chunk — a semver-tolerant handshake would only defer an opaque import failure.

ParameterTypeDescription
requiresRecord<string, string>
manifestVendorManifest

div(a, b, opts): Decimal

a / b. Without scale, the result uses the PostgreSQL numeric division rule (pgDivScale — e.g. 1/3 → scale 20, 10/4 → 16), so Decimal↔DB computations compare equal digit-for-digit. Rounding defaults to HALF_UP. When the true quotient does not terminate at the target scale the result is flagged periodic (isPeriodic(d) → true).

div(1, 3) // 0.33333333333333333333 — periodic div(10, 4) // 2.5000000000000000 div(1, 3, 2) // 0.33 div(a, b, { scale: 6, rounding: "HALF_EVEN" })

ParameterTypeDescription
aDecimalInput
bDecimalInput
optsnumber | { scale: number; rounding: RoundingMode }

effectivePgStorageType(h): string

Effective storage type in PostgreSQL (explicit pgType wins over inference).

ParameterTypeDescription
hColumnPgPersistenceHints

Entity(tableName, schema): (ctor: T) => T

Maps the class to a DB table. Optional argument overrides the table name; if omitted, the table name equals the class name.

ParameterTypeDescription
tableNamestring
schemastring

entityDateToApiIso(value): string

ParameterTypeDescription
valueDate

eq(a, b): boolean

Numeric equality ignoring scale — eq(1.0, 1.00) is true.

ParameterTypeDescription
aDecimalInput
bDecimalInput

extJsonParse(text): T

Parse an Ext-JSON string.

ALL integers are returned as native bigint (via reviver). Floats (values with decimal point or scientific notation) are number. Strings, booleans, null are unaffected.

ParameterTypeDescription
textstring

extJsonStringify(data): string

Serialize a value to an Ext-JSON string. BigInt values serialize as JSON numbers (42n → "42"); floats stay numbers.

Use for request bodies carrying bigint values — the BE's ext-json body parser revives them to native bigint.

ParameterTypeDescription
dataunknown

extractEntityAnnotations(entryFile): Promise<EntityAnnotationMap>

Build the annotation map for every class reachable from entryFile (usually the entity registry module). compilerOptions are taken from the nearest tsconfig.json so path aliases resolve correctly.

ParameterTypeDescription
entryFilestring

field(entity, key): FieldRef<TEntity, K>

ParameterTypeDescription
entityEntityClass
keyK

findAuditPage(repo, opts): Promise<AuditPageResult>

Page through an entity audit table, newest first. userEntity — optional auditable-display-name join target (BE: UserProfileEntity). Without it, display-name columns are null.

ParameterTypeDescription
repoAuditQueryable
optsAuditPageOptions & { userEntity: EntityClass }

findLikelyRenames(schema, table, entityOnly, databaseOnly, entityColumns, databaseColumns): RenameHeuristicResult

Greedy 1:1 matching: process tiers 0→n, within each tier stable order, no floats. Uses ordinal indexing to avoid scanning all DB-only columns for every entity-only column.

ParameterTypeDescription
schemastring
tablestring
entityOnlystring[]
databaseOnlystring[]
entityColumnsRecord<string, SchemaColumnMeta>
databaseColumnsRecord<string, SchemaColumnMeta>

floor(d): Decimal

Largest integer <= d.

ParameterTypeDescription
dDecimalInput

ForeignKey(target, opts): PropertyDecorator

Declares a FOREIGN KEY constraint referencing another entity's column. target is a lazy thunk (() => CustomerEntity) so circular entity references resolve at meta-read time, not class-eval time. Minimal form @ForeignKey(() => CustomerEntity) references the target's @Key() column with ON DELETE RESTRICT / ON UPDATE NO ACTION — the zero-option path is the safest behavior. Note: a partitioned parent (@PartitionField) cannot be a plain FK target unless the referenced unique constraint includes the partition key — meta validation throws and points to @PartitionChildOf for that shape.

ParameterTypeDescription
target() => EntityClass
optsForeignKeyOptions

fromBigInt(v, scale): Decimal

ParameterTypeDescription
vbigint
scalenumber

fromNumber(n): Decimal

ParameterTypeDescription
nnumber

getColumnName(ctor, propertyKey): string

ParameterTypeDescription
ctorEntityClass
propertyKeystring | symbol

getDal(config): Dal

Returns the process-wide singleton Dal instance. Creates it on first call.

  • First call: requires config, creates the singleton.
  • Subsequent calls with NO config: returns the existing instance.
  • Subsequent calls with the SAME connectionString: returns the existing instance.
  • Subsequent calls with a DIFFERENT connectionString: throws (prevents accidental double-init with wrong params).

For multi-DB: construct new Dal(config) directly (bypasses the singleton).

ParameterTypeDescription
configDalConfig

getEntityName(ctor): string

Logical entity name: the class name (e.g. CustomerEntity).

ParameterTypeDescription
ctorEntityClass

getEntityPersistenceMeta(ctor, tableSchema): EntityPersistenceMeta

Snapshot fragment for one

ParameterTypeDescription
ctorEntityClass
tableSchemastring

getOperatorsForColumnType(columnType): FilterOperator[]

Operators available for a given column UI type.

ParameterTypeDescription
columnTypestring

getPrimaryKeyColumn(ctor): string

ParameterTypeDescription
ctorEntityClass

getQualifiedTableName(ctor): string

Returns a schema-qualified table reference for SQL generation. When the entity has an explicit @Entity("table", "schema") override, returns "schema"."table". Otherwise returns just "table" (relies on search_path).

ParameterTypeDescription
ctorEntityClass

getSchemaDomain(): SchemaDomain \| null

getTableName(ctor): string

ParameterTypeDescription
ctorEntityClass

hydrateEntityDateFieldsFromJson(instance, meta): void

After Object.assign from JSON, restore column-typed values on the entity: instant → Date, decimal → Decimal (wire "N.Nd" or a bare numeric string), vector → Vector.

ParameterTypeDescription
instanceT
metaEntityPersistenceMeta

Index(): PropertyDecorator

Declares a secondary (non-unique) index. Bare @Index() → single-column btree auto-named <table>_<col>_idx. Same name on multiple columns → composite index ordered by order. Supports every PG access method: @Index({ using: 'hnsw', opclass: 'vector_cosine_ops' }), @Index({ where: 'deleted_at IS NULL' }) for partial indexes. Unique indexes stay on @Unique().

isDecimal(v): v is Decimal

ParameterTypeDescription
vunknown

isDriftClean(diff): boolean

True when the diff contains only database-only objects (extras we never drop) — i.e. no unapplied entity intent remains.

ParameterTypeDescription
diffSchemaMetaDiffV2

isEntityClass(value): value is EntityClass

ParameterTypeDescription
valueunknown

isEntityOpEnabled(actions, op): boolean

Pure enablement check — true when op exists in the served actions array and carries enabled: true. FAIL-CLOSED: when actions is absent (meta without actions — contract violation) the op is not enabled.

This deliberately does NOT evaluate user permissions — that step lives in the consumer (e.g. FE isEntityOpAllowed composes this with the session permission check).

ParameterTypeDescription
actionsreadonly EntityAction[] | undefined
opstring

isISODate(v): v is ISODate

ParameterTypeDescription
vunknown

isISOTime(v): v is ISOTime

ParameterTypeDescription
vunknown

isLogicalJsDateColumn(h): boolean

Column carries a Date-valued property — an audit/deletable/sync *_AT field, an instant codec hint, or an explicit timestamptz/timestamp pgType. date/time/timetz columns are ISODate/ISOTime strings — NOT Dates — by contract.

ParameterTypeDescription
hColumnPgPersistenceHints

IsNotColumn(): PropertyDecorator

Excludes the property from meta schema / migration and from future DAL queries.

isoDateFromUTCDate(d): ISODate

Date → ISODate using the date's UTC calendar day.

ParameterTypeDescription
dDate

isPeriodic(d): boolean

true when the value was produced by a truncated non-terminating division.

ParameterTypeDescription
dDecimalInput

isSnakeCaseSingular(value): value is SnakeCaseSingular

Runtime validator for SnakeCaseSingular — rejects strings with uppercase letters. Use in meta-loading code to catch BE meta that violates the convention.

ParameterTypeDescription
valuestring

isUUID(v): v is UUID

Type guard — validates RFC 4122 layout (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, hex).

ParameterTypeDescription
vunknown

jsValueToPgParam(value, h): unknown

Value to pass to node-pg query parameters. Date → passthrough (timestamptz) or YYYY-MM-DD (SQL date); Decimal → plain numeric string; Vector/number[] → '[…]' literal; jsonb payloads → JSON string (nested bigint → number — jsonb numerics are doubles anyway and BigInt breaks JSON.stringify).

ParameterTypeDescription
valueunknown
hColumnPgPersistenceHints

Key(): PropertyDecorator

Marks the single-column primary key.

keyNamespaceOf(key): string \| null

First dotted segment of a translation key — job.entities.x → job.

ParameterTypeDescription
keystring

listEntityPersistencePropertyKeys(ctor): string[]

Property keys that map to SQL columns (implicit + decorated).

ParameterTypeDescription
ctorEntityClass

loadKeyring(keysPath): TrustedKey[]

ParameterTypeDescription
keysPathstring

loadManifest(manifestPath): PatchManifest \| null

ParameterTypeDescription
manifestPathstring

lookupEntityAnnotation(map, className, prop): EntityAnnotationInfo \| undefined

Walk the extends chain (subclass first — wins on conflicts, matching the decorator-merge semantics of getEntityPersistenceMeta). Returns the annotation info for prop on className, or undefined when the chain declares no such property.

ParameterTypeDescription
mapEntityAnnotationMap
classNamestring
propstring

makeEntityService(cfg): EntityService<TEntity>

ParameterTypeDescription
cfgEntityServiceConfig<TEntity>

makeTableAuditPort(repo): AuditPort

makeTableAuditPort — writes audit log rows to {tableName}_audit via the given repository. This is the service-side counterpart of the BE's EntityAuditPort, minus the Redis/NATS entity-changed markers (those belong to gateway collaboration infra). The audit row write itself is always performed.

ParameterTypeDescription
repoRepository

manifestPaths(dbMetaDir): { manifestPath: string; keysPath: string }

Resolve manifest + keyring paths for a service's db-meta dir.

ParameterTypeDescription
dbMetaDirstring

max(a, b): Decimal

ParameterTypeDescription
aDecimalInput
bDecimalInput

min(a, b): Decimal

ParameterTypeDescription
aDecimalInput
bDecimalInput

mod(a, b): Decimal

a mod b — remainder of truncated division at the common scale.

ParameterTypeDescription
aDecimalInput
bDecimalInput

mul(a, b): Decimal

ParameterTypeDescription
aDecimalInput
bDecimalInput

neg(d): Decimal

ParameterTypeDescription
dDecimalInput

normalize(d): Decimal

Strip trailing fractional zeros — 1.230 → 1.23, 12.000 → 12.

ParameterTypeDescription
dDecimalInput

normalizePatchEol(body): string

Patch integrity hashes are EOL-insensitive: a Windows checkout may materialize CRLF while the committed blob and the signed MANIFEST are LF. Normalize before hashing so manifest verification and the patch registry are platform-stable.

ParameterTypeDescription
bodystring

orderedColumns(columns): MetaColumn[]

Columns in display order: sticky group → normal group → audited group, each sorted by order.

ParameterTypeDescription
columnsreadonly MetaColumn[] | null | undefined

parseDecimal(input): Decimal

Parse a decimal string into unscaled form. Accepts: "12", "-0.5", ".5", "5.", "1.5e3", "1E-3", "+4". Rejects: NaN, Infinity, empty strings, hex, non-numeric garbage. Scale is preserved as written ("1.230" → scale 3).

ParameterTypeDescription
inputstring

parsePatchPragmas(raw): { requiresReview: boolean; noTransaction: boolean }

Parse the -- pb:* pragma header of a patch file.

ParameterTypeDescription
rawstring

parsePatchSegments(raw): PatchSegment[]

Split a patch file into execution segments. Default content is transactional (tx); statements inside -- pb:begin-no-transaction … -- pb:end-no-transaction run per-statement in autocommit (for CREATE INDEX CONCURRENTLY & friends). Whole-file -- pb:no-transaction is equivalent to wrapping everything.

ParameterTypeDescription
rawstring

PartitionChildOf(opts): ClassDecorator

Declares this entity a logical child of a @PartitionField-partitioned parent: it joins the parent's atomic delete and retention purge unit. Needed because a partitioned parent cannot host a plain FOREIGN KEY (unique constraints must contain the partition key) — the relationship is application-level, enforced by the repository cascade and the partition-maintenance purge. Entities that merely REFERENCE a parent (telemetry, logs) simply don't declare this.

ParameterTypeDescription
optsPartitionChildOfOptions

PartitionField(opts): PropertyDecorator

Marks a column as the RANGE partition key of the table (pg_partman, monthly/daily/…). Exactly ONE per entity. The column must be NOT NULL and date/timestamptz-typed; every unique group and the primary key emitted in DDL must include it (PostgreSQL requirement) — getEntityPersistenceMeta validates this and throws otherwise, so a partitioned entity can never produce an invalid table definition.

ParameterTypeDescription
optsPartitionFieldOptions

patchNameFromFilename(filename): string

The registry identity of a patch is its filename minus the .sql extension.

ParameterTypeDescription
filenamestring

patchRegistryDdl(schema): string

ParameterTypeDescription
schemastring

patchSlugFromDiff(diff): string

ParameterTypeDescription
diffSchemaMetaDiffV2

pgDivScale(a, b): number

PostgreSQL-faithful result scale for x / y (mirrors select_div_scale): max(16 - 4·qweight, x.scale, y.scale) — 16 significant digits minimum. Verified live: 1/3→20, 10/4→16, 1.00/8→20, 2/1→16, 100/3→16.

ParameterTypeDescription
aDecimalInput
bDecimalInput

pgTypeFromAnnotation(a): string \| null

Annotation → base pg type. Returns null for unmappable annotations — the caller decides whether that's an error (schema pipeline) or a non-authoritative runtime hint.

ParameterTypeDescription
aEntityAnnotationInfo

pgValueToJsValue(value, h): unknown

Normalise a driver value into the entity-side type: Date for date-like columns, Decimal for numeric columns, Vector for vector columns. Driver-native shapes (pg already returns Date/bigint/arrays) pass through unchanged.

ParameterTypeDescription
valueunknown
hColumnPgPersistenceHints

pow10(n): bigint

ParameterTypeDescription
nnumber

quoteIdent(ident): string

ParameterTypeDescription
identstring

registryStatus(pool, schema): Promise<PatchRegistryRow[]>

ParameterTypeDescription
poolPool
schemastring

rescale(d, newScale, mode): Decimal

Re-express d at newScale. Growing is exact; shrinking applies mode (default HALF_UP, matching PostgreSQL round()).

ParameterTypeDescription
dDecimalInput
newScalenumber
modeRoundingMode

resetDal(): Promise<void>

Resets the singleton. Closes the existing instance if any. Intended for tests — call in afterAll to release the pool.

resetSchemaDomain(): void

Test hook — clears the configured domain.

resolveEntitySchema(meta, fallback): string

Resolve the effective schema of an entity: the explicit

ParameterTypeDescription
meta{ tableSchema: string; tableName: string }
fallbackstring

resolveManually(pool, schema, patchName, actor, note): Promise<boolean>

Operator escape hatch: mark a failed/pending patch as manually resolved.

ParameterTypeDescription
poolPool
schemastring
patchNamestring
actorstring
notestring

resolvePgTypeForSchema(h): string

Authoritative resolve for the schema pipeline: explicit pgType, else semantic decorator pin, else annotation inference. Throws when none can produce a type — an unmappable entity property must never silently become text.

ParameterTypeDescription
hEntityColumnTypeHints

resolvePresetConditions(presets, selections): FilterCondition[]

Flatten the WHERE conditions of every preset's ACTIVE option — the conditions AND-ed into every /list call. selections maps preset.id → option id; invalid/absent ids resolve per resolvePresetSelection.

ParameterTypeDescription
presetsreadonly FilterPreset[] | undefined
selectionsRecord<string, string>

resolvePresetSelection(preset, selected): string

Resolve a preset's active option id — the caller-provided selection when it names a declared option, otherwise default_option (itself falling back to the first option when misconfigured, keeping the always-one invariant rather than failing closed).

ParameterTypeDescription
presetFilterPreset
selectedstring | undefined

resolveVendorSpecifier(specifier): VendorResolution

How a remote chunk's bundler must treat a bare import specifier. Both the host vendor build and every module chunk build derive behavior from this single function so the plane stays deterministic.

ParameterTypeDescription
specifierstring

retryFailedPatches(pool, schema, actor): Promise<number>

failed → pending: next runMigrations retries them (and past them, in order).

ParameterTypeDescription
poolPool
schemastring
actorstring

round(d, scale, mode): Decimal

Round to scale fractional digits (default HALF_UP).

ParameterTypeDescription
dDecimalInput
scalenumber
modeRoundingMode

runMigrations(opts): Promise<MigrationRunResult>

ParameterTypeDescription
optsMigrationEngineOptions

runPartitionMaintenance(client, entities): Promise<PartitionMaintenanceReport>

ParameterTypeDescription
clientPoolClient
entitiesreadonly EntityClass[]

sanitizeVisibleKeys(visibleKeys, columns): string[]

Drop unknown keys and fall back to defaults when nothing left.

ParameterTypeDescription
visibleKeysstring[]
columnsMetaColumn[]

searchableTextColumns(columns): MetaColumn[]

Text-physical searchable columns — the scope selector + default "all fields" search set.

ParameterTypeDescription
columnsMetaColumn[]

serviceApiBase(listBasePath): string

Service API base of an entity list basePath — strips the trailing /entities/<entity> segment so service-relative endpoints declared in meta (e.g. sparkline endpoint: "/actions/job-run-stats") resolve to /ws/<svc>/api/v1/actions/… or /api/v1/actions/… for BE entities.

ParameterTypeDescription
listBasePathstring

sha256Hex(body): string

ParameterTypeDescription
bodystring

signManifest(manifest, privateKeyB64): PatchManifest

Sign a manifest body (entries already updated) with a PEM/DER private key.

ParameterTypeDescription
manifestOmit<PatchManifest, "signature">
privateKeyB64string

signum(d): -1 \| 0 \| 1

ParameterTypeDescription
dDecimalInput

slugifyPatchSegment(s): string

ParameterTypeDescription
sstring

specifierTopPackage(specifier): string

Top-level npm package of a specifier ('svelte/internal/client' → 'svelte').

ParameterTypeDescription
specifierstring

splitSqlStatements(sql): string[]

Top-level SQL statement splitter for -- pb:no-transaction segments.

Needed because node-pg's simple query protocol executes a multi-statement string in a single implicit transaction — to get per-statement autocommit (required for CREATE INDEX CONCURRENTLY etc.) statements must be sent separately. Handles: single/double-quoted strings, dollar-quoted bodies ($$…$$, $tag$…$tag$), line comments, block comments.

ParameterTypeDescription
sqlstring

strictEq(a, b): boolean

Exact structural equality — value AND scale must match (strictEq(1.0, 1.00) is false).

ParameterTypeDescription
aDecimalInput
bDecimalInput

sub(a, b): Decimal

ParameterTypeDescription
aDecimalInput
bDecimalInput

SynchronizableField(what): PropertyDecorator

Marks a field as synchronizable (last_synced_at).

ParameterTypeDescription
whatSynchronizableFieldType

syncImplicitEntityColumns(ctor): void

Registers every implicit column + design:type / nullability when not already set by decorators.

ParameterTypeDescription
ctorFunction

tableKey(schema, name): string

ParameterTypeDescription
schemastring
namestring

toISODate(v): ISODate

ParameterTypeDescription
vstring

toISOTime(v): ISOTime

ParameterTypeDescription
vstring

toUUID(v): UUID

Validating constructor — throws on malformed input. Use at system boundaries (request bodies, env, user input).

ParameterTypeDescription
vstring

toWire(d): string

Wire form — "…d" suffixed string.

ParameterTypeDescription
dDecimalInput

translateFilterConditions(entity, conditions, options): FilterExpr[] \| null

ParameterTypeDescription
entityEntityClass
conditionsListFilterCondition[] | null | undefined
optionsListFilterOptions

translationKeyNamespace(schema): string

Owning PG schema → the only translation-key namespace writable there.

ParameterTypeDescription
schemastring

trunc(d): Decimal

Integer part, toward zero.

ParameterTypeDescription
dDecimalInput

trustedISODate(v): ISODate

Zero-cost cast for trusted sources (DB rows).

ParameterTypeDescription
vstring

trustedISOTime(v): ISOTime

Zero-cost cast for trusted sources (DB rows).

ParameterTypeDescription
vstring

trustedUUID(v): UUID

Zero-cost cast for trusted sources (DB rows, values already validated upstream). Named explicitly so reviews can spot it.

ParameterTypeDescription
vstring

typesCompatibleForRename(a, b): boolean

True if two metas are “same enough” for rename pairing (not for strict migration).

ParameterTypeDescription
aSchemaColumnMeta
bSchemaColumnMeta

Unique(): PropertyDecorator

Unique constraint (PostgreSQL: unique index in generated patches).

utcTimestampForFilename(d): string

ParameterTypeDescription
dDate

verifyManifest(manifest, keyring, allowedTrust): TrustedKey

Verify manifest signature against the keyring (filtered by allowed trust levels).

ParameterTypeDescription
manifestPatchManifest
keyringTrustedKey[]
allowedTrustreadonly "release" | "dev"[]

writeManifest(manifestPath, manifest): void

Write manifest (used by compare/sign tooling).

ParameterTypeDescription
manifestPathstring
manifestPatchManifest
Last modified on October 28, 2026
ChangelogOverview
On this page
  • Classes
    • AuditLogEntity
    • BulkTimeoutError
    • ConfigEntityBase
    • Dal
    • DalError
    • Decimal
    • DecimalError
    • Deferred
    • DeferredFieldRef
    • DeferredTransaction
    • DeletedRecordConflictError
    • DomainService
    • DuplicateRecordError
    • EntityBase
    • ManifestError
    • MissingVersionError
    • MultipleRowsError
    • NotFoundError
    • OptimisticLockError
    • RecordVanishedError
    • Repository
    • SchemaDomainViolationError
    • TranslationEntityBase
    • UnknownColumnError
    • ValidationError
    • Vector
  • Interfaces
    • AdvancedFilter
    • AggregateDecl
    • AuditPageOptions
    • AuditPageResult
    • AuditPort
    • AuditRow
    • BulkItem
    • CollaborationMeta
    • DalConfig
    • DuplicateResult
    • EntityActionEndpoint
    • EntityListQuery
    • EntityListResult
    • EntityMeta
    • EntityService
    • EntityServiceConfig
    • IAuditableEntity
    • IClonableEntity
    • IDeletableEntity
    • IExposableEntity
    • ListFilterParamsOptions
    • ListResponse
    • LoggerPort
    • PartitionMaintenanceReport
    • PartitionParentReport
    • RowCustomAction
    • SnapshotQueryable
    • TableMeta
    • TimeoutOverrideOptions
  • Types & Enums
    • AuditableFieldType
    • AuditAction
    • DeletableFieldType
    • SynchronizableFieldType
    • ActionsOverrides
    • AuditableWriteOptions
    • AuditParams
    • BulkOptions
    • BulkResult
    • ColumnOptions
    • ColumnPgPersistenceHints
    • DalErrorCode
    • DecimalInput
    • DeletionFilterMode
    • EntityAction
    • EntityActionSentinel
    • EntityAnnotationInfo
    • EntityAnnotationMap
    • EntityClass
    • EntityColumnTypeHints
    • EntityCtor
    • EntityMetaResponse
    • EntityPersistenceMeta
    • EntityTypeWarning
    • ExprOperand
    • FieldProjector
    • FieldRef
    • FilterCondition
    • FilterExpr
    • FilterOperator
    • FilterPreset
    • FilterPresetOption
    • FindByIdOptions
    • FindByUUIDOptions
    • FindOptions
    • ForeignKeyAction
    • ForeignKeyOptions
    • GroupByOperand
    • HostApiFn
    • HostMountHandle
    • IndexMethod
    • IndexOptions
    • ISODate
    • ISOTime
    • JoinExpr
    • KeyOptions
    • LikelyRename
    • ListConnector
    • ListFilterCondition
    • ListFilterOptions
    • MatchByOptions
    • MetaColumn
    • MetaColumnType
    • MfaStepUpFn
    • MigrationEngineOptions
    • MigrationMode
    • MigrationRunResult
    • ModuleHostBase
    • ModuleHostComponents
    • ModuleNavDeclaration
    • ModuleNavLink
    • ModuleNotifyInput
    • ModulePageHost
    • ModuleSheetDecl
    • ModuleSheetDefaults
    • ModuleSheetHost
    • ModuleSheetSide
    • MountPageFn
    • MountSectionFn
    • MountSheetFn
    • OnConflictMode
    • OpenSheetFn
    • PageLayoutDecl
    • PageRouteComponentFormat
    • PageRouteDeclaration
    • PageRouteKind
    • PageRouteProps
    • PageSectionDecl
    • PageSectionSource
    • PaginatedEntity
    • PartitionChildOfOptions
    • PartitionFieldOptions
    • PatchManifest
    • PatchRegistryRow
    • PatchSegment
    • PatchStatus
    • PgColumnType
    • PgScalarType
    • RemoteDepsManifest
    • RenameAmbiguity
    • RenameHeuristicResult
    • RoundingMode
    • SchemaColumnMeta
    • SchemaDomain
    • SchemaMetaDiffV1
    • SchemaMetaDiffV2
    • SchemaSnapshot
    • SchemaTableMeta
    • SelectQueryInput
    • SnakeCaseSingular
    • SortDir
    • SortingExpr
    • SqlExpressionOperand
    • SqlJoinType
    • SqlOperator
    • SqlQuery
    • SqlSortDirection
    • StandardOp
    • TooltipPriority
    • TrustedKey
    • UniqueOptions
    • UpsertOptions
    • UUID
    • VectorDistanceOp
    • VectorHybridInput
    • VectorSearchOptions
    • VendorManifest
    • VendorMismatch
    • VendorResolution
    • VendorSpecifier
    • ViewName
    • WithAuditableDisplayNames
    • WithCreatorDisplayName
    • WithDeletedRecords
    • WithUpdaterDisplayName
    • WriteOptions
  • Constants
    • DalErrorCodes
    • decimalFromPG
    • Filter
    • fromString
    • fromWire
    • GroupBy
    • Join
    • KEYS_FILENAME
    • MANIFEST_FILENAME
    • NUMERIC_MIN_SIG_DIGITS
    • ONE
    • PATCH_REGISTRY_TABLE
    • Project
    • RENAME_HEURISTIC_AGENT_INSTRUCTION
    • RENAME_MATCH_RULE_LABELS
    • Sort
    • STANDARD_OPS
    • TEN
    • VENDOR_BLOCKED_PACKAGES
    • VENDOR_SPECIFIERS
    • ZERO
  • Functions
    • abs(d): Decimal
    • add(a, b): Decimal
    • allowedKeyNamespaces(moduleCode): ReadonlySet<string>
    • appendListFilterParams(params, opts, startIdx): number
    • approvePendingReview(pool, schema, patchName, actor, note): Promise<boolean>
    • assertEntitySchemaDomain(entities, schemas, sharedTables): void
    • assertPgTypeCompatible(annotation, explicitPgType, propertyKey): void
    • asSnakeCaseSingular(value): SnakeCaseSingular
    • Auditable(Base): { prototype: AuditableEntity<any> } & TBase
    • AuditableField(what): PropertyDecorator
    • AuditTrail(): ClassDecorator
    • AuditTrailEntity(options): ClassDecorator
    • buildAuditableJoins(entity, userEntity): JoinExpr[]
    • buildAuditableJoinsSelective(entity, userEntity, options): JoinExpr[]
    • buildAuditTrailJoins(auditEntity, userEntity): { joins: JoinExpr[]; projections: FieldProjector[] }
    • buildDatabaseSnapshot(db, tables, generatedAt): Promise<SchemaSnapshot>
    • buildEntitySnapshot(registry, opts, generatedAt): SchemaSnapshot
    • buildPatchFilename(diff, d): string
    • buildSelectQuery(input): SqlQuery
    • buildSqlPatchFromMetaDiff(entitySnap, diff): string
    • buildVectorSearchQuery(input): SqlQuery
    • calculateDelta(oldEntity, newEntity): Record<string, { old: unknown; new: unknown }>
    • calculateDeltaWithForcedFields(oldEntity, newEntity, forceFields): Record<string, { old: unknown; new: unknown }>
    • canonicalJson(value): string
    • canonicalPgType(t): string
    • ceil(d): Decimal
    • checkDrift(registry, db, opts): Promise<SchemaMetaDiffV2>
    • classifyRenamePair(eMeta, dMeta): { matchTier: number; reasons: string[] } \| null
    • CloneField(): PropertyDecorator
    • cmp(a, b): -1 \| 0 \| 1
    • collectEntityTypeWarnings(registry, annotations): EntityTypeWarning[]
    • Column(sqlName): PropertyDecorator
    • columnHintsFromMetaColumn(col): ColumnPgPersistenceHints
    • columnTypeWarnings(entityName, h, resolved): EntityTypeWarning[]
    • comparablePgType(meta): string
    • compareSnapshots(entitySnap, dbSnap): SchemaMetaDiffV2
    • configureSchemaDomain(schemas, sharedTables): SchemaDomain
    • createStream(db, text, values): AsyncIterable<TResult>
    • dec(input): Decimal
    • decimalToPG(d): string
    • defaultSearchGate(trimmed): boolean
    • defaultVisibleColumnKeys(columns): string[]
    • Deletable(Base): { prototype: DeletableEntity<any> } & TBase
    • DeletableField(what): PropertyDecorator
    • diffVendorRequirements(requires, manifest): VendorMismatch[]
    • div(a, b, opts): Decimal
    • effectivePgStorageType(h): string
    • Entity(tableName, schema): (ctor: T) => T
    • entityDateToApiIso(value): string
    • eq(a, b): boolean
    • extJsonParse(text): T
    • extJsonStringify(data): string
    • extractEntityAnnotations(entryFile): Promise<EntityAnnotationMap>
    • field(entity, key): FieldRef<TEntity, K>
    • findAuditPage(repo, opts): Promise<AuditPageResult>
    • findLikelyRenames(schema, table, entityOnly, databaseOnly, entityColumns, databaseColumns): RenameHeuristicResult
    • floor(d): Decimal
    • ForeignKey(target, opts): PropertyDecorator
    • fromBigInt(v, scale): Decimal
    • fromNumber(n): Decimal
    • getColumnName(ctor, propertyKey): string
    • getDal(config): Dal
    • getEntityName(ctor): string
    • getEntityPersistenceMeta(ctor, tableSchema): EntityPersistenceMeta
    • getOperatorsForColumnType(columnType): FilterOperator[]
    • getPrimaryKeyColumn(ctor): string
    • getQualifiedTableName(ctor): string
    • getSchemaDomain(): SchemaDomain \| null
    • getTableName(ctor): string
    • hydrateEntityDateFieldsFromJson(instance, meta): void
    • Index(): PropertyDecorator
    • isDecimal(v): v is Decimal
    • isDriftClean(diff): boolean
    • isEntityClass(value): value is EntityClass
    • isEntityOpEnabled(actions, op): boolean
    • isISODate(v): v is ISODate
    • isISOTime(v): v is ISOTime
    • isLogicalJsDateColumn(h): boolean
    • IsNotColumn(): PropertyDecorator
    • isoDateFromUTCDate(d): ISODate
    • isPeriodic(d): boolean
    • isSnakeCaseSingular(value): value is SnakeCaseSingular
    • isUUID(v): v is UUID
    • jsValueToPgParam(value, h): unknown
    • Key(): PropertyDecorator
    • keyNamespaceOf(key): string \| null
    • listEntityPersistencePropertyKeys(ctor): string[]
    • loadKeyring(keysPath): TrustedKey[]
    • loadManifest(manifestPath): PatchManifest \| null
    • lookupEntityAnnotation(map, className, prop): EntityAnnotationInfo \| undefined
    • makeEntityService(cfg): EntityService<TEntity>
    • makeTableAuditPort(repo): AuditPort
    • manifestPaths(dbMetaDir): { manifestPath: string; keysPath: string }
    • max(a, b): Decimal
    • min(a, b): Decimal
    • mod(a, b): Decimal
    • mul(a, b): Decimal
    • neg(d): Decimal
    • normalize(d): Decimal
    • normalizePatchEol(body): string
    • orderedColumns(columns): MetaColumn[]
    • parseDecimal(input): Decimal
    • parsePatchPragmas(raw): { requiresReview: boolean; noTransaction: boolean }
    • parsePatchSegments(raw): PatchSegment[]
    • PartitionChildOf(opts): ClassDecorator
    • PartitionField(opts): PropertyDecorator
    • patchNameFromFilename(filename): string
    • patchRegistryDdl(schema): string
    • patchSlugFromDiff(diff): string
    • pgDivScale(a, b): number
    • pgTypeFromAnnotation(a): string \| null
    • pgValueToJsValue(value, h): unknown
    • pow10(n): bigint
    • quoteIdent(ident): string
    • registryStatus(pool, schema): Promise<PatchRegistryRow[]>
    • rescale(d, newScale, mode): Decimal
    • resetDal(): Promise<void>
    • resetSchemaDomain(): void
    • resolveEntitySchema(meta, fallback): string
    • resolveManually(pool, schema, patchName, actor, note): Promise<boolean>
    • resolvePgTypeForSchema(h): string
    • resolvePresetConditions(presets, selections): FilterCondition[]
    • resolvePresetSelection(preset, selected): string
    • resolveVendorSpecifier(specifier): VendorResolution
    • retryFailedPatches(pool, schema, actor): Promise<number>
    • round(d, scale, mode): Decimal
    • runMigrations(opts): Promise<MigrationRunResult>
    • runPartitionMaintenance(client, entities): Promise<PartitionMaintenanceReport>
    • sanitizeVisibleKeys(visibleKeys, columns): string[]
    • searchableTextColumns(columns): MetaColumn[]
    • serviceApiBase(listBasePath): string
    • sha256Hex(body): string
    • signManifest(manifest, privateKeyB64): PatchManifest
    • signum(d): -1 \| 0 \| 1
    • slugifyPatchSegment(s): string
    • specifierTopPackage(specifier): string
    • splitSqlStatements(sql): string[]
    • strictEq(a, b): boolean
    • sub(a, b): Decimal
    • SynchronizableField(what): PropertyDecorator
    • syncImplicitEntityColumns(ctor): void
    • tableKey(schema, name): string
    • toISODate(v): ISODate
    • toISOTime(v): ISOTime
    • toUUID(v): UUID
    • toWire(d): string
    • translateFilterConditions(entity, conditions, options): FilterExpr[] \| null
    • translationKeyNamespace(schema): string
    • trunc(d): Decimal
    • trustedISODate(v): ISODate
    • trustedISOTime(v): ISOTime
    • trustedUUID(v): UUID
    • typesCompatibleForRename(a, b): boolean
    • Unique(): PropertyDecorator
    • utcTimestampForFilename(d): string
    • verifyManifest(manifest, keyring, allowedTrust): TrustedKey
    • writeManifest(manifestPath, manifest): void