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 declarationsSELECT 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.

Use ./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 imports

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
Your view

Make room for your context.

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

Your context

The different parts of you

Choose a starting point

A useful mix of context, visuals and gentle guidance.

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

Reading comfort

Choose your language

Interface language changes text only. Markets, prices and workflows keep their own settings.

Translation coverage

Original source

Navigation151
Graph616
Categories378
Portfolio833
Examples2,035
Source preview1,542

More translations will be added as content is reviewed.

This preference is saved on this browser.

Search the website

Useful starting points

No results. Try a shorter phrase, an operation name or another search area.

A LITTLE ROOM TO EXPLORE

Find something to explore.

Open a closer look on this page, try a different perspective, or follow the detail into its own page.

How previews and controls work
01

Look before you leave

Hover a link or focus it with Tab to see a preview. Clicking the original link or pressing Enter always opens its destination.

02

Stay with the context

Move into the preview to explore its sections. Use Alt + ↓ from a focused link to enter it with the keyboard. Escape closes it.

03

Open the possibilities

Disclosure rows, perspective choices and highlighted controls reveal more. Your view changes reading comfort and the context you explore.

A separate button for a closer look

Show small preview buttons beside links where there is room. Tap the eye to inspect, or tap the link to go straight there. This choice stays in this tab.

No browsing history is collected. Reduced motion follows your device and Your view.