integrationPackage manifestv2.0.5

integration.provider-database

Database provider implementations for ContractSpec.

@lssm-tech/integration.provider-database
Source, release and verification context

Source snapshot bcc79fcc · Declared package version 2.0.5. This page combines the checked-in package guide and manifest; commands and runtime behavior were not executed in this review.

Package source ↗ Manifest ↗
servernode
EXPLORE THE PACKAGE

See where this package fits.

Follow a declared connection, inspect an import, then open the source guide when you need the detail.

THIS PACKAGEintegration.provider-databaseintegrations

Arrows point from a package to its direct dependency. Each count is derived from the captured manifests.

5 declaracionesSELECT TO INSPECT

@lssm-tech/integration.provider-database

Website: https://contractspec.io

Database provider implementations for ContractSpec.

Usage

Import the root entrypoint for the domain surface, or import a concrete implementation from the ./impls/* subpaths. Use ./governed-read when a contracts-spec DataViewQueryGenerator emits a database.query.readonly descriptor and you need to execute that governed read through a DatabaseProvider. The helper builds parameterized SQL from field mappings and keeps SQL construction inside this adapter package. Governed reads support offset descriptors and cursor descriptors from DataViewDatabaseBinding.pagination. Cursor descriptors add a parameterized cursorField > cursor predicate only when the cursor field is present in the contract-owned select mapping; unknown cursor fields fail before provider execution, and maxPageSize is enforced before the query reaches the provider. executeQuery exposes the governed read as a Transport-shaped resolver for the data-fetching engine: it executes a canonical QueryEnvelope and returns a ContractResult<QueryResultEnvelope> carrying a real versionToken (read from the entity's version column with versionTokenFromColumn()) for the engine's etag / optimistic-concurrency path.

Usar ./governed-mutation for first-class database writes after the owning domain command has planned a portable database.mutation.execute@2.0.0 envelope. The helper validates actor, tenant, domain-command authority, policy decision, idempotency key, transaction boundary, expected write set, audit refs, replay ref, and correlation ref before running the provider transaction. Drizzle/PostgreSQL rendering remains in this integration package, not in contracts-spec core.

Version-governed entities

Declare the entities whose writes need optimistic concurrency once, at the composition root, and pass the registry to every governed mutation:

ts
const versioning = createGovernedVersionRegistry([
	{ entity: 'workspace', table: 'workspaces' }, // schema public, column version
]);
await applyVersionColumnMigration(provider, buildVersionColumnMigration(versioning));

await executeGovernedMutation({
	descriptor: { ...renameDescriptor, expectedVersionToken: ctx.queryEnvelope?.versionToken },
	provider,
	versioning,
});
  • buildVersionColumnMigration(registry) returns idempotent up statements and down statements. up adds a missing column as bigint NOT NULL DEFAULT 1 (existing rows start at 1) and marks it with a column comment, or normalizes an existing smallint/integer/bigint column (NULLs backfilled to 1, NOT NULL DEFAULT 1; any other type fails the migration). It then installs a BEFORE UPDATE trigger that sets NEW.<column> = OLD.<column> + 1, so writers that bypass the store still advance the version. down removes the triggers and functions and drops only the columns up added. Building the migration fails when two entities of one schema would share a trigger function name.
  • A descriptor without a schema matches the one registered schema that governs its table and fails when several do; the governed SQL always names the registered schema, so it never depends on the connection's search_path.
  • On a governed table, insert returns the new versionToken; update and delete must carry expectedVersionToken, check it in the same statement (AND <column> = $n::bigint ... RETURNING <column>) and return the new token (update) or none (delete). Their where must name one row by its key: the store refuses a write that returns more than one row, but it does not see rows the version filter excluded.
  • A missing, stale or non-integer token (BIGINT range only), or a row that no longer matches, throws ContractSpecError with the typed Core version conflict (CONFLICT 409, metadata.versionConflict.reason = missing, stale or gone, and the stored version in versionToken when the row exists). The transaction rolls back and the idempotency key is not stored. The data engine resolves it with the mutation's conflict policy; under client-wins a gone row fails the mutation and rolls the optimistic write back.
  • A write that returns more than one row, a value for the version column itself, or an expectedVersionToken on a table that is not in the registry fails with an error.
  • Clients send the expected token as MutationRequest.versionToken; the engine forwards it as QueryEnvelope.versionToken and REST carries it as $versionToken, so handlers read ctx.queryEnvelope?.versionToken.

Managed and BYOK Postgres/Supabase deployments are the production posture. Local/PgLite remains a provider-binding compatibility mode for deterministic tests and demos, not a separate ownership mode.

Postgres statement parameters preserve the shared DatabaseProvider contract: Date values are serialized as ISO-8601 timestamps before reaching postgres.js, while bigint, byte, JSON-object, and array parameters retain their existing normalized representations.

Public subpaths

  • . re-exports the provider surface plus governed read/mutation helpers.
  • ./database re-exports the shared DatabaseProvider contracts.
  • ./governed-read executes portable DataView read descriptors through a provider.
  • ./governed-mutation executes governed mutation descriptors with transaction, idempotency, audit hooks and, for version-governed tables, the version precondition.
  • ./governed-versioning declares version-governed entities (createGovernedVersionRegistry).
  • ./version-column-migration builds and applies the per-entity version-column rollout (buildVersionColumnMigration, applyVersionColumnMigration, VERSION_COLUMN_ROLLOUT_MARKER).
  • ./version-token-source maps a stored version column to a VersionToken (versionTokenFromColumn, versionTokenFromValue) and a token back to its BIGINT bind value (parseVersionCounter).
  • ./impls and ./impls/supabase-psql expose concrete PostgreSQL/Supabase implementations.
  • ./postgres-json-semantics exports withPgJsonSemantics(client), which makes a raw postgres.js client pass JSON text through to json/jsonb parameters instead of double-encoding it (pg/PGlite semantics). It has no imports, so any runtime that builds its own postgres.js client can use it.

Compatibility

This package owns the database implementation slice split out of @lssm-tech/integration.providers-impls. The legacy package continues to re-export these subpaths for existing consumers.

Declared capabilities.

Integration Provider Database

Database provider implementations for ContractSpec.

Use it to

  • Adopt database provider implementations for contractspec

Requires

  • TypeScript

Choose another boundary when

  • The @lssm-tech/integration.provider-database package constraints do not match the target runtime or platform.

@lssm-tech/integration.provider-database

@lssm-tech/integration.provider-database/auth-seam

@lssm-tech/integration.provider-database/database

@lssm-tech/integration.provider-database/generated/contractspec-schema.generated

@lssm-tech/integration.provider-database/generated/contractspec-schema.manifest.generated

@lssm-tech/integration.provider-database/governed-execute-query

@lssm-tech/integration.provider-database/governed-mutation

@lssm-tech/integration.provider-database/governed-read

@lssm-tech/integration.provider-database/governed-relational-read

@lssm-tech/integration.provider-database/governed-sql-guards

@lssm-tech/integration.provider-database/impls

@lssm-tech/integration.provider-database/impls/drizzle-contractspec

Imports and export paths.

20 entries

These are package-manifest entry points. Named symbols listed above come from the capability catalogue; this is not an exhaustive TypeScript symbol reference.

20 importaciones

Dependencies and related packages.

Runtime dependencies 5
drizzle-orm
catalog:data
Development dependencies 7
@types/bun
catalog:types
postgres
^3.4.9
typescript
catalog:

Package scripts.

Commands declared by this package. Review its setup requirements before running them; no command here was executed by this review.

buildcontractspec-bun-build build
build:bundlecontractspec-bun-build transpile
build:typescontractspec-bun-build types
devcontractspec-bun-build dev
cleanrimraf dist .turbo
lint:checknode ../../../scripts/biome.cjs check .
lint:fixnode ../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../scripts/biome.cjs check --write .
testbun test
prebuildcontractspec-bun-build prebuild
typechecktsgo --noEmit
Tu vista

Make room for your context.

Shape the presentation around this moment. You can change it whenever you need.

Tu contexto

The different parts of you

Choose a starting point

Una mezcla útil de contexto, imágenes y orientación discreta.

Tune each dimension
Each dimension can change independently. Product permissions and available actions stay unchanged.

Support the way you begin and return

Tune your support

Comodidad de lectura

Elige tu idioma

El idioma de la interfaz solo cambia el texto. Los mercados, precios y flujos de trabajo conservan sus propios ajustes.

Cobertura de traducción

Parte del contenido se muestra en inglés.

Navegación151
Grafo616
Categorías188
Portafolio332
Ejemplos2035
Vista previa de la fuente41

Se añadirán más traducciones a medida que se revise el contenido.

Esta preferencia se guarda en este navegador.

Buscar en el sitio web

Puntos de partida útiles

Sin resultados. Prueba una frase más corta, un nombre de operación u otro ámbito de búsqueda.

UN POCO DE ESPACIO PARA EXPLORAR

Encuentra algo que explorar.

Abre una vista detallada en esta página, prueba otra perspectiva o sigue el detalle a su propia página.

Cómo funcionan las vistas previas y los controles
01

Mirar antes de salir

Pasa el cursor por un enlace o enfócalo con Tab para ver una vista previa. Hacer clic en el enlace original o pulsar Intro siempre abre su destino.

02

Mantener el contexto

Entra en la vista previa para explorar sus secciones. Usa Alt + ↓ desde un enlace enfocado para entrar con el teclado. Escape la cierra.

03

Abrir las posibilidades

Las filas desplegables, las perspectivas y los controles destacados revelan más. Tu vista cambia la comodidad de lectura y el contexto que exploras.

Un botón separado para mirar más de cerca

Muestra pequeños botones de vista previa junto a los enlaces donde haya espacio. Toca el ojo para inspeccionar o el enlace para ir directamente. Esta elección permanece en esta pestaña.

No se recoge historial de navegación. El movimiento reducido sigue tu dispositivo y Tu vista.