import { C as SqlRuntimeTargetDescriptor, H as decodeRow, S as SqlRuntimeExtensionInstance, V as buildDecodeContext, b as SqlRuntimeDriverInstance, f as ExecutionContext, i as Runtime, o as RuntimeOptions, v as SqlRuntimeAdapterDescriptor, x as SqlRuntimeExtensionDescriptor, y as SqlRuntimeAdapterInstance } from "../prepared-statement-BuDdY11z.mjs"; import { CodecDescriptor } from "@prisma-next/framework-components/codec"; import { ResultType } from "@prisma-next/framework-components/runtime"; import { Adapter, AnyQueryAst, Codec, ContractCodecRegistry, LoweredStatement, SelectAst } from "@prisma-next/sql-relational-core/ast"; import { RuntimeDriverDescriptor } from "@prisma-next/framework-components/execution"; import { ColumnDefault, Contract, ContractModelBase, ControlPolicy, JsonValue, NamespaceId, ValueSetRef } from "@prisma-next/contract/types"; import { IRNodeBase, NamespaceBase } from "@prisma-next/framework-components/ir"; import { SqlStorage, SqlStorageInput, StorageTableInput } from "@prisma-next/sql-contract/types"; import { DevDatabase, collectAsync, createDevDatabase, teardownTestDatabase, withClient } from "@prisma-next/test-utils"; import { SqlExecutionPlan, SqlQueryPlan } from "@prisma-next/sql-relational-core/plan"; import { Client } from "pg"; import "@prisma-next/framework-components/authoring"; //#region ../1-core/contract/src/ir/sql-node.d.ts /** * SQL family IR node base. Carries the family-level `kind` discriminator * `'sql'` and inherits the framework's `freezeNode` affordance. * * Single family-level discriminator (not per-leaf) reflects the fact that * SQL IR has no polymorphic dispatch today — verifiers and serializers * walk by structural position (`storage.tables[name].columns[name]`), * not by inspecting `kind`. The abstract bar for per-leaf discriminators * isn't earned until a future polymorphic consumer arrives. * * `kind` is installed as a non-enumerable own property on every instance, * which keeps three things clean simultaneously: * * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope * shape (no `kind` field), so emitted contract.json files and the * `validateSqlContractFully` arktype schemas stay unchanged. * - Test assertions that use `toEqual({...})` against the pre-lift flat * shape continue to pass — only enumerable own properties are * compared. * - Direct access (`node.kind`) and runtime narrowing * (`if (node.kind === 'sql')`) still work, so future polymorphic * dispatch can begin reading `kind` without a runtime change. * * Future per-leaf overrides land cleanly: a class that gains a * polymorphic-dispatch consumer (e.g. an enum type instance walked * alongside other types) overrides `kind` with its narrower literal * at that leaf level. Per-leaf overrides will use enumerable kind * (matching the Mongo per-class-discriminator precedent) because they * encode dispatch-relevant information that callers need to see in * JSON envelopes; the family-level `'sql'` is uniform across all SQL * IR and carries no dispatch-relevant information. */ declare abstract class SqlNode extends IRNodeBase { readonly kind?: string; constructor(); } //#endregion //#region ../1-core/contract/src/ir/check-constraint.d.ts /** * Hydration / construction input shape for {@link CheckConstraint}. * Mirrors the on-disk storage JSON envelope so the serializer hydration * walker can hand a validated literal straight to `new`. */ interface CheckConstraintInput { readonly name: string; readonly column: string; readonly valueSet: ValueSetRef; } /** * SQL Contract IR node for a table-level check constraint that restricts * a column to the permitted values of a value-set. * * The constraint is **structured** (names a column and a value-set * reference), not a raw SQL expression. Each target renders its own DDL * from the structured form, keeping the contract target-agnostic. * * Construction is idempotent: passing an existing `CheckConstraint` * instance as input produces a new instance with identical fields. * The constructor does not use `instanceof` for input discrimination — * it reads plain named properties, which is sufficient since * `CheckConstraintInput` is a structural type. */ declare class CheckConstraint extends SqlNode { readonly name: string; readonly column: string; readonly valueSet: ValueSetRef; constructor(input: CheckConstraintInput); } //#endregion //#region ../1-core/contract/src/ir/foreign-key-reference.d.ts /** * Input for a foreign-key reference (one side of a foreign-key declaration). * * When `spaceId` is absent the reference is local — the referenced table lives * in the same contract-space. When `spaceId` is present the reference is * cross-space — the referenced table lives in a different contract-space * identified by `spaceId`. * * Presence-based discrimination keeps local FK JSON byte-identical to * contracts authored before cross-space support was added. */ interface ForeignKeyReferenceInput { readonly namespaceId: string; readonly tableName: string; readonly columns: readonly string[]; readonly spaceId?: string; } /** * SQL Contract IR node for one side (source or target) of a foreign-key * declaration. Carries the full coordinate: namespace, table, and columns. * * Cross-space discrimination is based on `spaceId` presence: absent means * local (same contract-space); present means cross-space (the referenced * table lives in the contract-space identified by `spaceId`). * * For local references `spaceId` is absent from JSON, keeping the serialized * shape byte-identical to contracts authored before cross-space support was * added. For cross-space references `spaceId` appears in JSON so round-trips * are lossless. * * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir` * as the sentinel `namespaceId` for single-namespace (unbound) references. */ declare class ForeignKeyReference extends SqlNode { readonly namespaceId: NamespaceId; readonly tableName: string; readonly columns: readonly string[]; readonly spaceId?: string; constructor(input: ForeignKeyReferenceInput); } //#endregion //#region ../1-core/contract/src/ir/foreign-key.d.ts type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'; interface ForeignKeyInput { readonly source: ForeignKeyReference | ForeignKeyReferenceInput; readonly target: ForeignKeyReference | ForeignKeyReferenceInput; readonly name?: string; readonly onDelete?: ReferentialAction; readonly onUpdate?: ReferentialAction; } /** * SQL Contract IR node for a table-level foreign-key declaration — the * referential constraint only (source, target, `onDelete`/`onUpdate`). * * A persisted `foreignKeys[]` entry always denotes a real constraint: whether * to emit the constraint at all, and whether to back it with an index, are * authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint, * index })`) resolved once at `contract emit` — a `constraint: false` FK * simply has no entry here, and a backing index (if any) is its own discrete, * named entry in the table's `indexes[]`. * * Each FK carries explicit `source` and `target` {@link ForeignKeyReference} * coordinates (namespace, table, columns). For single-namespace contracts the * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides. * * The nested references are normalised to {@link ForeignKeyReference} * instances inside the constructor so downstream walks see a uniform AST * regardless of whether the input was a JSON literal or an already-constructed * class instance. */ declare class ForeignKey extends SqlNode { readonly source: ForeignKeyReference; readonly target: ForeignKeyReference; readonly name?: string; readonly onDelete?: ReferentialAction; readonly onUpdate?: ReferentialAction; constructor(input: ForeignKeyInput); } //#endregion //#region ../1-core/contract/src/ir/primary-key.d.ts interface PrimaryKeyInput { readonly columns: readonly string[]; readonly name?: string; } /** * SQL Contract IR node for a table's primary-key constraint. */ declare class PrimaryKey extends SqlNode { readonly columns: readonly string[]; readonly name?: string; constructor(input: PrimaryKeyInput); } //#endregion //#region ../1-core/contract/src/ir/sql-index.d.ts interface IndexInput { readonly columns: readonly string[]; readonly name?: string; readonly type?: string; readonly options?: Record; } /** * SQL Contract IR node for a table-level secondary index. * * Note that this class shadows the global TypeScript `Index` lib type * at the family-shared name; consumer files that need both should * alias one (e.g. * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`). */ declare class Index extends SqlNode { readonly columns: readonly string[]; readonly name?: string; readonly type?: string; readonly options?: Record; constructor(input: IndexInput); } //#endregion //#region ../1-core/contract/src/ir/storage-column.d.ts /** * Hydration / construction input shape for {@link StorageColumn}. Mirrors * the on-disk storage JSON envelope exactly so the family-base * serializer's hydration walker can hand an arktype-validated literal * straight to `new`. * * `typeParams` and `typeRef` remain mutually exclusive (one or the * other, not both); the constructor preserves whichever caller-side * choice the input encodes. */ interface StorageColumnInput { readonly nativeType: string; readonly codecId: string; readonly nullable: boolean; readonly many?: boolean; readonly typeParams?: Record; readonly typeRef?: string; readonly default?: ColumnDefault; readonly control?: ControlPolicy; readonly valueSet?: ValueSetRef; } /** * SQL Contract IR node for a single column entry in `StorageTable.columns`. * * Single concrete family-shared class — every SQL target reads the * same column shape today, so there is no per-target subclass. The * class type accepts any caller that constructs via * `new StorageColumn(input)`; literal construction sites must pass * through the constructor or the family-base hydration walker. * * The column's `name` is not on the class — columns are keyed by name * in the parent `StorageTable.columns: Record` * map, so a `name` field would be redundant with the key. */ declare class StorageColumn extends SqlNode { readonly nativeType: string; readonly codecId: string; readonly nullable: boolean; readonly many?: boolean; readonly typeParams?: Record; readonly typeRef?: string; readonly default?: ColumnDefault; readonly control?: ControlPolicy; readonly valueSet?: ValueSetRef; constructor(input: StorageColumnInput); } //#endregion //#region ../1-core/contract/src/ir/unique-constraint.d.ts interface UniqueConstraintInput { readonly columns: readonly string[]; readonly name?: string; } /** * SQL Contract IR node for a table-level unique constraint. */ declare class UniqueConstraint extends SqlNode { readonly columns: readonly string[]; readonly name?: string; constructor(input: UniqueConstraintInput); } //#endregion //#region ../1-core/contract/src/ir/storage-table.d.ts interface StorageTableInput$1 { readonly columns: Record; readonly primaryKey?: PrimaryKey | PrimaryKeyInput; readonly uniques: ReadonlyArray; readonly indexes: ReadonlyArray; readonly foreignKeys: ReadonlyArray; readonly control?: ControlPolicy; readonly checks?: ReadonlyArray; } /** * SQL Contract IR node for a single table entry in a namespace's * `tables` map. * * The constructor normalises nested IR-class fields (columns, primary * key, uniques, indexes, foreign keys) into the appropriate class * instances so downstream walks see a uniform AST regardless of whether * the input was a JSON literal or an already-constructed class. * * The table's `name` is not on the class — tables are keyed by name in * the parent namespace's `tables: Record` map. */ declare class StorageTable extends SqlNode { readonly columns: Readonly>; readonly uniques: ReadonlyArray; readonly indexes: ReadonlyArray; readonly foreignKeys: ReadonlyArray; readonly primaryKey?: PrimaryKey; readonly control?: ControlPolicy; readonly checks?: ReadonlyArray; constructor(input: StorageTableInput$1); /** * Runtime guard that a namespace `table` entry is really a `StorageTable`. * The compiler already types the entry as `StorageTable`, but a * freshly-deserialized contract may carry plain JSON at that slot until * hydration; this duck-types the structural shape. Accepts `undefined` so * optional-chained entry lookups pass straight through. */ static is(value: StorageTable | undefined): value is StorageTable; static assert(value: StorageTable | undefined, coordinate: string): asserts value is StorageTable; } //#endregion //#region ../1-core/contract/src/ir/storage-value-set.d.ts /** * Hydration / construction input shape for {@link StorageValueSet}. * Mirrors the on-disk storage JSON envelope so the serializer hydration * walker can hand a validated literal straight to `new`. */ interface StorageValueSetInput { readonly kind: 'valueSet'; /** Ordered permitted values, codec-encoded. Declaration order is preserved. */ readonly values: readonly JsonValue[]; } /** * SQL Contract IR node for a value-set entry in a namespace's `valueSet` * map (`SqlNamespace.entries.valueSet`). * * A value-set records the ordered set of permitted codec-encoded values for * an enum-like column restriction. It does not carry a `codecId` — the * column that references it already holds the codec; the value-set holds * only the permitted values. * * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope * carries the discriminator and the serializer hydration walker can * dispatch on it. This follows the per-leaf enumerable-kind convention * established in the SQL-node comment (future polymorphic dispatch on * namespace entries needs the discriminator in JSON). * * The entry's name is not on the class — value-sets are keyed by name in * the parent namespace's `valueSet: Record` map. */ declare class StorageValueSet extends SqlNode { readonly kind: "valueSet"; readonly values: readonly JsonValue[]; constructor(input: StorageValueSetInput); } //#endregion //#region ../1-core/contract/src/ir/sql-storage.d.ts interface SqlNamespaceInput { readonly id: string; readonly entries: Readonly>>>; } /** * SQL Contract IR root node for the `storage` field. * * Single concrete family-shared class — both Postgres and SQLite * consume this class today. Per-target storage subclasses are * introduced when each target's namespace shape earns its * target-specific concretion (target-specific derived fields, * target-specific storage extensions). * * Honours the framework `Storage` interface: every SQL IR carries a * `namespaces` map keyed by namespace id. Callers must supply fully * constructed `Namespace` instances — construction discipline lives * in the authoring builders and deserializer hydration paths. * * The constructor normalises optional `types` into class instances. * `types` is polymorphic per Decision 18 Option B: codec-triple inputs * are stamped with `kind: 'codec-instance'`; hydration of raw JSON * class-instance entries (carrying their narrower `kind` literal) is * the per-target serializer's responsibility (so the family base does * not import target-specific subclasses). */ /** * The typed `entries` shape for SQL family namespaces. The open dictionary * is intersected with optional known-kind maps so that `ns.entries.table` * and `ns.entries.valueSet` resolve without a cast, while unknown pack- * contributed kinds remain valid (the `Record` part allows any string key). */ type SqlNamespaceEntries = Readonly>>> & { readonly table?: Readonly>; readonly valueSet?: Readonly>; }; /** * Structural interface for SQL family namespaces. Generated `.d.ts` contract * types satisfy this structurally (no prototype methods). The runtime * abstract class `SqlNamespaceBase` extends this. * * `qualifyTable` and `isUnbound` are optional so JSON-shaped contract types * (which carry no methods) are accepted where `SqlNamespace` is required. * Hydrated `SqlNamespaceBase` instances always have both. */ interface SqlNamespace { readonly kind: string; readonly id: string; readonly entries: SqlNamespaceEntries; readonly isUnbound?: boolean; qualifyTable?(tableName: string): string; } /** * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`, * `SqliteDatabase`, …) extend this — it is never instantiated directly. * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]` * addresses any entity. */ declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace { abstract readonly id: string; abstract readonly entries: SqlNamespaceEntries; abstract qualifyTable(tableName: string): string; } //#endregion //#region ../1-core/contract/test/test-support.d.ts /** * Minimal concrete `SqlNamespaceBase` for use in `packages/2-sql/**` unit tests. * * This is a legitimate target concretion — not a materialised family * namespace. Production code never constructs one; the target-specific * concretions (`PostgresSchema`, `SqliteDatabase`) are used in production. */ declare class TestSqlNamespace extends SqlNamespaceBase { readonly kind: 'test-sql-namespace'; readonly id: string; readonly entries: SqlNamespaceEntries; constructor(input: SqlNamespaceInput); get table(): Readonly>; get valueSet(): Readonly> | undefined; qualifyTable(tableName: string): string; } declare function createTestSqlNamespace(input: SqlNamespaceInput): TestSqlNamespace; //#endregion //#region test/utils.d.ts type CreateTestRuntimeOptions> = Omit, 'adapter'> & { readonly stackInstance: { readonly adapter: RuntimeOptions['adapter']; }; }; /** * Test-only concrete runtime. Unpacks `stackInstance.adapter` and forwards * the rest into `TestSqlRuntime`, a trivial concrete leaf of the abstract * `SqlRuntimeBase`. */ declare function createTestRuntime>(options: CreateTestRuntimeOptions): Runtime; /** * Executes a plan and collects all results into an array. This helper DRYs up the common pattern of executing plans in tests. The return type is inferred from the plan's type parameter. */ declare function executePlanAndCollect

> | SqlQueryPlan>>(runtime: Runtime, plan: P): Promise[]>; /** * Drains a plan execution, consuming all results without collecting them. Useful for testing side effects without memory overhead. */ declare function drainPlanExecution(runtime: Runtime, plan: SqlExecutionPlan | SqlQueryPlan): Promise; /** * Sets up database schema and data, then writes the contract marker. This helper DRYs up the common pattern of database setup in tests. * * Callers must supply `bootstrapMarkerTables` (typically * `bootstrapPostgresSignMarkerTables` from integration `postgres-bootstrap.ts`) * so this package does not depend on the postgres adapter/target packs. */ declare function setupTestDatabase(client: Client, contract: Contract, setupFn: (client: Client) => Promise, bootstrapMarkerTables: (client: Client) => Promise): Promise; interface SeedMarkerInput { /** Logical space for the marker row; defaults to {@link APP_SPACE_ID}. */ readonly space?: string; readonly storageHash: string; readonly profileHash: string; readonly contractJson?: unknown; readonly canonicalVersion?: number; readonly invariants?: readonly string[]; } /** * Seeds a contract marker row directly via raw SQL. Test-only: the production * write path goes through the control adapter SPI (`initMarker`/`updateMarker`), * which needs a `ControlDriverInstance`; these fixtures hold a raw `pg.Client`, * so they perform a minimal `INSERT` over the columns the runtime reads back. */ declare function seedTestMarker(client: Client, input: SeedMarkerInput): Promise; /** * Seeds the app-space marker for a contract. Thin wrapper over * {@link seedTestMarker} for the common "write the marker for this contract" case. */ declare function writeTestContractMarker(client: Client, contract: Contract): Promise; /** * Creates a test adapter descriptor from a raw adapter. Wraps the adapter in an SqlRuntimeAdapterDescriptor with static contributions derived from the adapter's codec registry. */ /** * Build a {@link ContractCodecRegistry} from a codec array for tests that exercise `encodeParam(s)` / `decodeRow` in isolation. The production runtime builds `ContractCodecRegistry` from contract walk + descriptor list and never goes through this helper; tests use it to wire a hand-built codec set into the surface those functions consume in production. */ declare function buildTestContractCodecs(codecs: ReadonlyArray>): ContractCodecRegistry; /** * Synthesize `CodecDescriptor`s from a codec array of non-parameterized codec instances. Test-only: the production synthesis bridge was retired under TML-2357. Lets the existing `createTestAdapterDescriptor` pattern keep wrapping a stub `Adapter` (whose `__codecs` slot still exposes the codec set) into the descriptor-list shape that `SqlStaticContributions.codecs:` now expects. The `Codec` instances carry * `traits`/`targetTypes`/`meta` via the SQL family extension; the structural narrow reads those fields directly. */ declare function descriptorsFromCodecs(codecs: ReadonlyArray>): ReadonlyArray; declare function createTestAdapterDescriptor(adapter: StubAdapter): SqlRuntimeAdapterDescriptor<'postgres'>; /** * Creates a test target descriptor with empty static contributions. */ declare function createTestTargetDescriptor(): SqlRuntimeTargetDescriptor<'postgres'>; /** * Creates an ExecutionContext for testing. This helper DRYs up the common pattern of context creation in tests. * * Accepts a raw adapter and optional extension descriptors, wrapping the adapter in a descriptor internally for descriptor-first context creation. */ declare function createTestContext>(contract: TContract, adapter: StubAdapter, options?: { extensionPacks?: ReadonlyArray>; }): ExecutionContext; declare function createTestStackInstance(options?: { extensionPacks?: ReadonlyArray>; driver?: RuntimeDriverDescriptor<'sql', 'postgres', unknown, SqlRuntimeDriverInstance<'postgres'>>; }): import("@prisma-next/framework-components/execution").ExecutionStackInstance<"sql", "postgres", SqlRuntimeAdapterInstance<"postgres">, SqlRuntimeDriverInstance<"postgres">, SqlRuntimeExtensionInstance<"postgres">>; /** * Stub-adapter type augments the public {@link Adapter} surface with a `__codecs` slot that exposes the test stub's runtime codec set to descriptor-shaping helpers (`createTestAdapterDescriptor`). Production adapters do not declare this slot — runtime codecs flow through the descriptor list from `SqlRuntimeAdapterDescriptor.codecs()` — so the augmentation is intentionally test-only. */ type StubAdapter = Adapter, LoweredStatement> & { readonly __codecs: ReadonlyArray>; }; /** * Creates a stub adapter for testing. This helper DRYs up the common pattern of adapter creation in tests. * * The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1) to enable type inference in tests without requiring the postgres adapter package. */ declare function createStubAdapter(): StubAdapter; declare function unboundNamespaceWithTables(tables: Record): ReturnType; declare function emptySqlTestDomain(): import("@prisma-next/contract/types").ApplicationDomain; declare function createTestContract(contract: Partial, 'profileHash' | 'storage' | 'domain'>> & { storageHash?: string; profileHash?: string; models?: Record; domain?: Contract['domain']; storage?: Partial>; }): Contract; declare function stubAst(): AnyQueryAst; //#endregion export { type DevDatabase, SeedMarkerInput, StubAdapter, buildDecodeContext, buildTestContractCodecs, collectAsync, createDevDatabase, createStubAdapter, createTestAdapterDescriptor, createTestContext, createTestContract, createTestRuntime, createTestStackInstance, createTestTargetDescriptor, decodeRow, descriptorsFromCodecs, drainPlanExecution, emptySqlTestDomain, executePlanAndCollect, seedTestMarker, setupTestDatabase, stubAst, teardownTestDatabase, unboundNamespaceWithTables, withClient, writeTestContractMarker }; //# sourceMappingURL=utils.d.mts.map