🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@prisma-next/framework-components

Package Overview
Dependencies
Maintainers
3
Versions
408
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma-next/framework-components - npm Package Compare versions

Comparing version
0.13.0
to
0.14.0-dev.1
+204
dist/codec-types-yY3eSmi0.d.mts
import { JsonValue } from "@prisma-next/contract/types";
import { StandardSchemaV1 } from "@standard-schema/spec";
//#region src/shared/codec-descriptor.d.ts
/**
* Unified codec descriptor. Every codec in the framework registers through this shape — non-parameterized codecs use `P = void` and a constant factory that returns the same shared codec instance for every column; parameterized codecs use a non-empty `P` and a curried higher-order factory that returns a per-instance codec.
*
* The descriptor is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema` for JSON-boundary validation; optional `renderOutputType` for the `contract.d.ts` emit path). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.
*
* Whether a codec id "is parameterized" stops being a registration-time distinction — it's a property of `P` on the descriptor. The descriptor map indexes every descriptor by `codecId`; both `descriptorFor(codecId)` and `forColumn(table, column)` resolve through the same map without branching on parameterization.
*
* @template P - The shape of the params accepted by the factory (`void` for non-parameterized codecs; a record like `{ length: number }` for parameterized codecs).
*
* Codec-registry-unification project § Decision.
*/
interface CodecDescriptor<P = void> {
/** The codec ID this descriptor applies to (e.g. `pg/vector@1`, `pg/text@1`). */
readonly codecId: string;
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
readonly traits: readonly CodecTrait[];
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
readonly targetTypes: readonly string[];
/** Optional family-specific metadata (e.g. SQL-side `db.sql.postgres.nativeType`). */
readonly meta?: CodecMeta;
/** Standard Schema validator for the factory's params. Validates JSON-sourced params at the contract boundary (PSL → IR; `contract.json` → runtime). For non-parameterized codecs (`P = void`), the schema validates `void`/`undefined` — the framework supplies no params at the call boundary. */
readonly paramsSchema: StandardSchemaV1<P>;
/** Whether this descriptor is parameterized — i.e. its `paramsSchema` is something other than the singleton `voidParamsSchema`. Consumers that need to gate column-aware dispatch read this directly rather than threading a free-floating `(codecId) => boolean` callback. */
readonly isParameterized: boolean;
/** Emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for given params (e.g. `Vector<1536>`). Optional; absent renderers cause the emitter to fall back to the codec's base output type. Non-parameterized codecs typically omit it. */
readonly renderOutputType?: (params: P) => string | undefined;
/** Emit-path string renderer for the `contract.d.ts` *input* position (create/update values). Returns the TypeScript input type expression for given params. Optional; absent renderers fall back to the codec's base input type. A codec supplies this when its write type is narrower than the generic codec input — e.g. an enum whose input should be the literal member union, not `string`. */
readonly renderInputType?: (params: P) => string | undefined;
/** The curried higher-order codec. For non-parameterized codecs, the factory is constant — every call returns the same shared codec instance. For parameterized codecs, the factory is called once per `storage.types` instance (or once per inline-`typeParams` column), with `ctx` carrying the column set the resulting codec serves. */
readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;
}
/**
* Variance-erased {@link CodecDescriptor} alias. `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly), so `CodecDescriptor<P>` does not extend `CodecDescriptor<unknown>` for specific `P`. Heterogeneous descriptor collections — e.g. `SqlStaticContributions.codecs:` returning a list that mixes parameterized and non-parameterized descriptors — type against this alias and narrow per codec id at the consumer.
*
* Codec-registry-unification spec § Decision: every codec resolves through one descriptor map; reads are non-branching.
*/
type AnyCodecDescriptor = CodecDescriptor<any>;
/**
* Abstract base class for concrete codec descriptors.
*
* Codec authors extend this class with their typed `TParams` and declare `codecId`, `traits`, `targetTypes`, `paramsSchema`, the curried `factory(params)`, and (optionally) `renderOutputType`.
*
* Implements the {@link CodecDescriptor} interface so a concrete subclass instance is directly usable wherever the framework expects a `CodecDescriptor<P>`.
*/
declare abstract class CodecDescriptorImpl<TParams = void> implements CodecDescriptor<TParams> {
abstract readonly codecId: string;
abstract readonly traits: readonly CodecTrait[];
abstract readonly targetTypes: readonly string[];
readonly meta?: CodecMeta;
abstract readonly paramsSchema: StandardSchemaV1<TParams>;
/** Boolean derived from `paramsSchema`: `true` whenever the schema is not the singleton `voidParamsSchema`. */
get isParameterized(): boolean;
/** Optional emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for the given params (e.g. `Vector<1536>`). Non-parameterized codecs typically omit it. */
renderOutputType?(params: TParams): string | undefined;
/** Optional emit-path string renderer for the `contract.d.ts` input position. Returns the TypeScript input type expression for the given params; supplied when the write type is narrower than the generic codec input (e.g. an enum's literal member union). */
renderInputType?(params: TParams): string | undefined;
/**
* Materialize a curried codec factory for the given params. Concrete subclasses override with a typed return type (e.g. `factory<N>(params: { length: N }): (ctx) => VectorCodec<N>`); per-codec helpers read the typed return at the *direct* call site, which is what preserves method-level generics. Type extraction (e.g. `ReturnType<D['factory']>`) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.
*/
abstract factory(params: TParams): (ctx: CodecInstanceContext) => Codec<string, readonly CodecTrait[], unknown, unknown>;
}
//#endregion
//#region src/shared/codec.d.ts
/**
* A codec is the contract between an application value and its on-wire and on-contract-disk representations.
*
* The author's mental model is two JS-side types — `TInput` (the application JS type) and `TWire` (the database driver wire format) — plus `JsonValue` for build-time contract artifacts. The codec translates `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue` during contract emission and loading.
*
* Three representations participate:
* - **Input** (`TInput`): the JS type at the application boundary.
* - **Wire** (`TWire`): the format exchanged with the database driver.
* - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.
*
* The runtime instance carries only its `id` (the descriptor's `codecId`, set by the factory) and the four conversion methods. Static metadata (`traits`, `targetTypes`, `meta`) and the build-time `renderOutputType` renderer live on the {@link CodecDescriptor} keyed by `codecId` — the read-surface single source of truth. Consumers that need them resolve through `descriptorFor(codecId)`.
*
* Codec methods split into two groups:
*
* - **Query-time** methods (`encode`, `decode`) run per row/parameter at the IO boundary; they are required and Promise-returning. The per-family codec factory accepts sync or async author functions and lifts sync ones to Promise-shaped methods automatically.
* - **Build-time** methods (`encodeJson`, `decodeJson`) run when the contract is serialized or loaded. They stay synchronous so contract validation and client construction are synchronous.
*
* Target-family codec interfaces extend this base; family-specific concerns (e.g. the SQL `column?` per-call context) layer on through the `CodecCallContext` extension pattern.
*/
interface Codec<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown> {
/** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). The factory sets this to the descriptor's `codecId`; consumers use it as a back-reference for descriptor lookups and for decode-error diagnostics. */
readonly id: Id;
/** Phantom carrier for the `TTraits` generic; type-only, undefined at runtime. Runtime traits live on {@link CodecDescriptor.traits}. Implemented as a string-key phantom (`__codecTraits`) rather than `unique symbol` so bundlers that split `.d.ts` chunks do not strand symbol identity on chunk-private paths (the same `TS2742` family that the public re-export of `CodecTypes` works around). */
readonly __codecTraits?: TTraits;
/** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(value) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;
/** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(wire) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;
/** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */
encodeJson(value: TInput): JsonValue;
/** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `family.deserializeContract`. */
decodeJson(json: JsonValue): TInput;
}
/**
* Abstract base class for concrete codec implementations.
*
* Codec authors extend this class with their typed `Id`, `TTraits`, `TWire`, `TInput` and override `encode`/`decode` (and optionally `encodeJson`/`decodeJson`). The runtime instance carries only its `id` (proxied through the descriptor so alias subclasses inherit the descriptor's id automatically) and the conversion methods — static metadata lives on the {@link CodecDescriptor}.
*/
declare abstract class CodecImpl<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown> implements Codec<Id, TTraits, TWire, TInput> {
readonly descriptor: CodecDescriptor<any>;
/**
* Variance-erased descriptor reference. Concrete codec subclasses receive the typed descriptor in their own constructors and forward it via `super(descriptor)`; the variance erasure lives at this base because the abstract surface can't carry the concrete `TParams`.
*/
constructor(descriptor: CodecDescriptor<any>);
get id(): Id;
abstract encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;
abstract decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;
abstract encodeJson(value: TInput): JsonValue;
abstract decodeJson(json: JsonValue): TInput;
}
//#endregion
//#region src/shared/codec-types.d.ts
type CodecTrait = 'equality' | 'order' | 'boolean' | 'numeric' | 'textual';
/**
* Serializable codec identity carried by every codec-bearing AST node.
*
* `(codecId, typeParams?)` is the single fact the runtime needs to materialize a codec via `descriptorFor(codecId).factory(typeParams)(ctx)`. The pair is content-keyed: two refs with the same `codecId` and structurally equal `typeParams` (regardless of object key ordering) resolve to the same memoized {@link Codec} instance.
*
* `typeParams` is `JsonValue`-constrained so the ref survives JSON serialization (relevant for AST-embedded migration ops). Non-parameterized codecs leave `typeParams` undefined; the descriptor's `paramsSchema` validates the value at the JSON boundary.
*
* Family-agnostic by design — both SQL and Mongo AST nodes carry `codec: CodecRef | undefined`, and the resolver is the only dispatch path that survives serialization.
*/
interface CodecRef {
readonly codecId: string;
readonly typeParams?: JsonValue;
}
/**
* Per-call context the runtime threads to every `codec.encode` / `codec.decode` invocation for a single `runtime.execute()` call.
*
* The framework-level shape is family-agnostic and carries one field:
*
* - `signal?: AbortSignal` — per-query cancellation. The runtime returns a `RUNTIME.ABORTED` envelope when the signal aborts; codec authors who forward `signal` to their underlying SDK get true cancellation of in-flight network calls.
*
* Family layers extend this base with their own shape-of-call metadata: the SQL family adds `column?: SqlColumnRef` via `SqlCodecCallContext` (see `@prisma-next/sql-relational-core`). Mongo currently uses this framework type unchanged. Column metadata is intentionally **not** on the framework type — it is a SQL-family concept rooted in SQL's `(table, column)` addressing model and would not generalise to other families.
*
* The interface is named explicitly (not inlined) so future framework fields and family extensions can land additively without breaking codec author signatures.
*/
interface CodecCallContext {
readonly signal?: AbortSignal;
}
/**
* Codec-id-keyed read surface threaded into emit and authoring paths.
*
* - `get(id)` returns a representative {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults). For parameterized codecs whose factory requires concrete params, this may return `undefined` — use `CodecRegistry.forCodecRef` instead.
* - `targetTypesFor(id)` exposes the codec-id-keyed `targetTypes` metadata the runtime instance no longer carries (TML-2357). Returns the same array `CodecDescriptor.targetTypes` would; for Mongo (whose registration doesn't yet resolve through the unified descriptor map — TML-2324) the family-side assembly populates this directly from the contributor's codec metadata.
* - `metaFor(id)` exposes the codec-id-keyed `meta` (e.g. SQL-side `db.sql.postgres.nativeType`) the runtime instance no longer carries.
* - `renderOutputTypeFor(id, params)` exposes the codec-id-keyed `renderOutputType` renderer the runtime instance no longer carries. Returns `undefined` when the codec doesn't render a custom type or when the codec id is unknown.
*/
interface CodecLookup {
get(id: string): Codec | undefined;
targetTypesFor(id: string): readonly string[] | undefined;
metaFor(id: string): CodecMeta | undefined;
renderOutputTypeFor(id: string, params: Record<string, unknown>): string | undefined;
/** Codec-id-keyed `renderInputType` renderer for the `contract.d.ts` input position. Optional so existing lookups need not provide it; returns `undefined` when the codec renders no custom input type or the id is unknown. */
renderInputTypeFor?(id: string, params: Record<string, unknown>): string | undefined;
}
/**
* Full codec registry — the read surface of {@link CodecLookup} plus codec resolution by ref or
* column coordinate. Built once by `extractCodecLookup` and passed by reference to adapters and
* other consumers that need to materialise codecs at runtime.
*
* - `forCodecRef(ref)` materialises a codec from a {@link CodecRef}. Throws
* `RUNTIME.CODEC_DESCRIPTOR_MISSING` for unknown ids and `RUNTIME.TYPE_PARAMS_INVALID` on param
* schema rejection.
* - `forColumn(namespaceId, table, column)` returns the codec for a specific column coordinate, or
* `undefined` when no column-to-codec mapping is present. This registry is contract-free so it
* always returns `undefined` — the method exists so the object structurally satisfies the SQL
* `ContractCodecRegistry` interface.
*/
interface CodecRegistry extends CodecLookup {
forCodecRef(ref: CodecRef): Codec;
forColumn(namespaceId: string, table: string, column: string): Codec | undefined;
}
declare const emptyCodecLookup: CodecLookup;
/**
* Family-agnostic per-instance context supplied by the framework when applying a higher-order codec factory. Allows stateful codecs (e.g. column-scoped encryption) to derive per-instance state from the materialization site.
*
* - `name` — the family-agnostic instance identity. For SQL, the runtime populates this as the `storage.types` instance name (e.g. `Embedding1536`) for typeRef-shaped columns, an inline-column sentinel (`<col:Document.embedding>`) for inline-`typeParams` columns, a shared codec-id sentinel (`<codec:pg/text@1>`) for non-parameterized codec ids, or the canonical cache key (`<codecId>:<canonicalizeJson(typeParams)>`) for ad-hoc refs the contract walk did not pre-populate. Other families pick the analogous identity for their materialization sites.
*
* Family-specific extensions (e.g. {@link import('@prisma-next/sql-relational-core/ast').SqlCodecInstanceContext} in the SQL layer) augment this base with domain-shaped column-set metadata. Codec authors target the base when they don't read family-specific metadata; they target the family extension when they do.
*/
interface CodecInstanceContext {
readonly name: string;
}
/**
* Family-agnostic codec metadata. Family-specific extensions augment the base `db.<family>.<target>` block with native-type information; the base shape is an empty object so non-relational codecs can carry no metadata.
*/
interface CodecMeta {
readonly db?: Record<string, unknown>;
}
/**
* Standard Schema validator for `void` params. Accepts only `undefined` (or absent input); rejects any other value so a contract that tries to thread `typeParams` through a non-parameterized codec id fails fast at the JSON boundary instead of silently coercing the value away. Used by the framework-supplied non-parameterized descriptor synthesizer.
*/
declare const voidParamsSchema: StandardSchemaV1<void>;
//#endregion
export { CodecRef as a, emptyCodecLookup as c, CodecImpl as d, AnyCodecDescriptor as f, CodecMeta as i, voidParamsSchema as l, CodecDescriptorImpl as m, CodecInstanceContext as n, CodecRegistry as o, CodecDescriptor as p, CodecLookup as r, CodecTrait as s, CodecCallContext as t, Codec as u };
//# sourceMappingURL=codec-types-yY3eSmi0.d.mts.map
{"version":3,"file":"codec-types-yY3eSmi0.d.mts","names":[],"sources":["../src/shared/codec-descriptor.ts","../src/shared/codec.ts","../src/shared/codec-types.ts"],"mappings":";;;;;;;;;;;;;;;UA8BiB,eAAA;EAQC;EAAA,SANP,OAAA;EAQc;EAAA,SANd,MAAA,WAAiB,UAAA;EAQjB;EAAA,SANA,WAAA;EAQ4B;EAAA,SAN5B,IAAA,GAAO,SAAA;EAQP;EAAA,SANA,YAAA,EAAc,gBAAA,CAAiB,CAAA;EAMZ;EAAA,SAJnB,eAAA;EAMkB;EAAA,SAJlB,gBAAA,IAAoB,MAAA,EAAQ,CAAA;EAIE;EAAA,SAF9B,eAAA,IAAmB,MAAA,EAAQ,CAAA;EAE4B;EAAA,SAAvD,OAAA,GAAU,MAAA,EAAQ,CAAA,MAAO,GAAA,EAAK,oBAAA,KAAyB,KAAA;AAAA;AASlE;;;;AAAgD;AAAhD,KAAY,kBAAA,GAAqB,eAAe;;;;;;;;uBAS1B,mBAAA,4BAA+C,eAAA,CAAgB,OAAA;EAAA,kBACjE,OAAA;EAAA,kBACA,MAAA,WAAiB,UAAA;EAAA,kBACjB,WAAA;EAAA,SACT,IAAA,GAAO,SAAA;EAAA,kBAEE,YAAA,EAAc,gBAAA,CAAiB,OAAA;EANkB;EAAA,IAS/D,eAAA;EAT8E;EAclF,gBAAA,EAAkB,MAAA,EAAQ,OAAA;EAdyC;EAiBnE,eAAA,EAAiB,MAAA,EAAQ,OAAA;EAhBP;;;EAAA,SAqBT,OAAA,CACP,MAAA,EAAQ,OAAA,IACN,GAAA,EAAK,oBAAA,KAAyB,KAAA,kBAAuB,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;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mBAAA,CAAoB,EAAA,UAAY,MAAA,EAAQ,MAAA;EFUZ;EER5B,kBAAA,EAAoB,EAAA,UAAY,MAAA,EAAQ,MAAA;AAAA;AFQM;AAShD;;;;;;;;;;;;AATgD,UEQ/B,aAAA,SAAsB,WAAA;EACrC,WAAA,CAAY,GAAA,EAAK,QAAA,GAAW,KAAA;EAC5B,SAAA,CAAU,WAAA,UAAqB,KAAA,UAAe,MAAA,WAAiB,KAAA;AAAA;AAAA,cAGpD,gBAAA,EAAkB,WAK9B;;;;;;;;UASgB,oBAAA;EAAA,SACN,IAAI;AAAA;;;;UAME,SAAA;EAAA,SACN,EAAA,GAAK,MAAM;AAAA;;;;cAMT,gBAAA,EAAkB,gBAAgB"}
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { Contract, ContractModelBase } from "@prisma-next/contract/types";
//#region src/control/emission-types.d.ts
interface GenerateContractTypesOptions {
readonly queryOperationTypeImports?: ReadonlyArray<TypesImportSpec>;
}
interface ValidationContext {
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
readonly extensionIds?: ReadonlyArray<string>;
}
interface EmissionSpi {
readonly id: string;
generateStorageType(contract: Contract, storageHashTypeName: string): string;
generateModelStorageType(modelName: string, model: ContractModelBase): string;
getFamilyImports(): string[];
getFamilyTypeAliases(options?: GenerateContractTypesOptions): string;
getTypeMapsExpression(): string;
getContractWrapper(contractBaseName: string, typeMapsName: string): string;
/**
* Per-family resolver for typeParams that don't live inline on the
* framework-domain `ContractField`. Some families (notably SQL) let columns
* reference a named entry in `storage.types` via `typeRef`; the typeParams
* live on that named entry rather than on the domain field. The framework
* emit path consults this hook so the codec's `renderOutputType` can run
* for typeRef-shaped columns.
*
* Inline `field.type.typeParams` always takes precedence; the hook is only
* consulted when the domain field has no typeParams. Families without
* named storage types (e.g. mongo) don't implement this hook.
*
* Returns `undefined` when the field has no resolvable typeParams.
*/
resolveFieldTypeParams?(modelName: string, fieldName: string, model: ContractModelBase, contract: Contract): Record<string, unknown> | undefined;
}
//#endregion
export { GenerateContractTypesOptions as n, ValidationContext as r, EmissionSpi as t };
//# sourceMappingURL=emission-types-C561PwcN.d.mts.map
{"version":3,"file":"emission-types-C561PwcN.d.mts","names":[],"sources":["../src/control/emission-types.ts"],"mappings":";;;;UAGiB,4BAAA;EAAA,SACN,yBAAA,GAA4B,aAAa,CAAC,eAAA;AAAA;AAAA,UAGpC,iBAAA;EAAA,SACN,gBAAA,GAAmB,aAAA,CAAc,eAAA;EAAA,SACjC,YAAA,GAAe,aAAA;AAAA;AAAA,UAGT,WAAA;EAAA,SACN,EAAA;EAET,mBAAA,CAAoB,QAAA,EAAU,QAAA,EAAU,mBAAA;EAExC,wBAAA,CAAyB,SAAA,UAAmB,KAAA,EAAO,iBAAA;EAEnD,gBAAA;EAEA,oBAAA,CAAqB,OAAA,GAAU,4BAAA;EAE/B,qBAAA;EAEA,kBAAA,CAAmB,gBAAA,UAA0B,YAAA;EAjBjB;;;;;;;;;;AACS;AAGvC;;;EA6BE,sBAAA,EACE,SAAA,UACA,SAAA,UACA,KAAA,EAAO,iBAAA,EACP,QAAA,EAAU,QAAA,GACT,MAAA;AAAA"}
import { r as CodecLookup } from "./codec-types-yY3eSmi0.mjs";
import { ColumnDefault, ExecutionMutationDefaultPhases } from "@prisma-next/contract/types";
import { Type } from "arktype";
//#region src/shared/psl-extension-block.d.ts
/**
* Shape-only types for the PSL source-position primitives, diagnostic
* codes, extension-block descriptor vocabulary, and the uniform
* extension-block AST node base.
*
* These live in the shared plane so an extension's authoring descriptor
* (`AuthoringPslBlockDescriptor` in `framework-authoring`) can reference
* them without crossing the shared → migration-plane boundary. The
* migration-plane `psl-ast.ts` re-exports everything here for consumers
* that import PSL AST types from the control entrypoint.
*/
interface PslPosition {
readonly offset: number;
readonly line: number;
readonly column: number;
}
interface PslSpan {
readonly start: PslPosition;
readonly end: PslPosition;
}
type PslDiagnosticCode = 'PSL_UNTERMINATED_BLOCK' | 'PSL_UNSUPPORTED_TOP_LEVEL_BLOCK' | 'PSL_INVALID_NAMESPACE_BLOCK' | 'PSL_INVALID_ATTRIBUTE_SYNTAX' | 'PSL_INVALID_MODEL_MEMBER' | 'PSL_UNSUPPORTED_MODEL_ATTRIBUTE' | 'PSL_UNSUPPORTED_FIELD_ATTRIBUTE' | 'PSL_INVALID_RELATION_ATTRIBUTE' | 'PSL_INVALID_REFERENTIAL_ACTION' | 'PSL_INVALID_DEFAULT_VALUE' | 'PSL_INVALID_ENUM_MEMBER' | 'PSL_INVALID_TYPES_MEMBER' | 'PSL_INVALID_QUALIFIED_TYPE'
/**
* A qualified name (e.g. a dotted type or attribute reference) is structurally
* invalid, such as an over-qualified or trailing-separator name.
*/
| 'PSL_INVALID_QUALIFIED_NAME'
/**
* A reserved declaration keyword (`model`/`enum`/`namespace`/`type`) that
* committed the declaration kind on the keyword alone but is missing its name
* and/or opening brace. The recursive-descent parser produces a best-effort
* typed node for the malformed header and reports this code rather than
* `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`, which is reserved for a genuinely unknown
* top-level keyword.
*/
| 'PSL_INVALID_DECLARATION'
/**
* A malformed line inside an extension-contributed top-level block body, or
* a structurally invalid element inside a `list` parameter value.
*
* Replaces the overloaded `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK` code that the
* generic framework parser previously used for these two parse-error sites
* inside extension blocks — keeping `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK` for
* its original meaning (an unknown keyword at the top level) and giving
* extension-block parse errors their own code.
*/
| 'PSL_INVALID_EXTENSION_BLOCK_MEMBER'
/**
* A malformed JS-like object literal `{ key: value, … }` in value/argument
* position — a field missing its `:`, a field missing its value, or an
* unterminated `{`. The recursive-descent parser still produces a best-effort
* `ObjectLiteralExpr` node (preserving the lossless round-trip) and reports
* this code anchored on the offending token.
*/
| 'PSL_INVALID_OBJECT_LITERAL'
/**
* A string literal with no closing quote — the tokenizer stops the literal at
* a newline or at EOF when no terminating `"` is found, and the
* recursive-descent parser still consumes the token (preserving the lossless
* round-trip) but reports this code anchored on the string token's span.
*/
| 'PSL_UNTERMINATED_STRING'
/**
* An unknown parameter key in an extension-contributed block — a key present
* in the source block but absent from the descriptor's `parameters` map.
*/
| 'PSL_EXTENSION_UNKNOWN_PARAMETER'
/**
* A required parameter declared in the descriptor is absent from the parsed block.
*/
| 'PSL_EXTENSION_MISSING_REQUIRED_PARAMETER'
/**
* An `option`-kind parameter value is not one of the allowed tokens listed
* in the descriptor's `values` array.
*/
| 'PSL_EXTENSION_OPTION_OUT_OF_SET'
/**
* A `value`-kind parameter's raw text is not a valid JSON literal, or the
* parsed JSON value was rejected by the codec's `decodeJson` method, or the
* codec id is not registered in the lookup.
*/
| 'PSL_EXTENSION_INVALID_VALUE'
/**
* A `ref`-kind parameter identifier does not resolve to a declared entity of
* the required `refKind` within the declared scope.
*/
| 'PSL_EXTENSION_UNRESOLVED_REF'
/**
* A parameter key appears more than once in an extension block body.
* The first occurrence is kept; subsequent occurrences emit this diagnostic.
*/
| 'PSL_EXTENSION_DUPLICATE_PARAMETER'
/**
* A `@@`-prefixed block-attribute line inside an extension block has invalid syntax.
*/
| 'PSL_INVALID_EXTENSION_BLOCK_ATTRIBUTE';
/**
* Descriptor vocabulary for a single parameter on a declared block.
*
* Four kinds:
* - `ref` — the parameter value is an identifier that must resolve to a
* declared entity of `refKind` within the declared `scope`.
* - `value` — the parameter value is a PSL literal parsed and printed
* through the codec identified by `codecId`.
* - `option` — the parameter value is one of the literal tokens in `values`.
* Not a codec; not persisted data. A closed authoring-time constraint only.
* - `list` — a bracketed list whose elements each match the `of` descriptor.
*/
type PslBlockParam = PslBlockParamRef | PslBlockParamValue | PslBlockParamOption | PslBlockParamList;
interface PslBlockParamRef {
readonly kind: 'ref';
readonly refKind: string;
readonly scope: 'same-namespace' | 'same-space' | 'cross-space';
readonly required?: boolean;
}
interface PslBlockParamValue {
readonly kind: 'value';
readonly codecId: string;
readonly required?: boolean;
}
interface PslBlockParamOption {
readonly kind: 'option';
readonly values: readonly string[];
readonly required?: boolean;
}
interface PslBlockParamList {
readonly kind: 'list';
readonly of: PslBlockParam;
readonly required?: boolean;
}
/**
* The parsed representation of a single parameter value on a uniform
* extension-block AST node. Mirrors the `PslBlockParam` descriptor
* vocabulary, plus `bare` for keyonly entries:
*
* - `ref` → `PslExtensionBlockParamRef` — a raw identifier string
* (resolution runs in the validator, not the parser).
* - `value` → `PslExtensionBlockParamScalarValue` — a raw PSL literal string
* (codec validation runs in the validator).
* - `option` → `PslExtensionBlockParamOption` — the chosen token.
* - `list` → `PslExtensionBlockParamList` — ordered list of the above.
* - `bare` → `PslExtensionBlockParamBare` — a bare identifier line with no
* `= value` (e.g. `Low` in an enum block). The name is the key in
* `parameters`; the interpreting consumer decides the default value.
*
* These shapes are intentionally minimal. The validator and lowering refine
* and consume them; the generic framework parser produces them.
*/
type PslExtensionBlockParamValue = PslExtensionBlockParamRef | PslExtensionBlockParamScalarValue | PslExtensionBlockParamOption | PslExtensionBlockParamList | PslExtensionBlockParamBare;
interface PslExtensionBlockParamRef {
readonly kind: 'ref';
readonly identifier: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamScalarValue {
readonly kind: 'value';
readonly raw: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamOption {
readonly kind: 'option';
readonly token: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamList {
readonly kind: 'list';
readonly items: readonly PslExtensionBlockParamValue[];
readonly span: PslSpan;
}
/**
* A bare identifier line inside an extension block — a key with no `= value`.
* Emitted when a line matches `/^[A-Za-z_]\w*$/` with no assignment. The
* consumer decides what default value (if any) to apply.
*/
interface PslExtensionBlockParamBare {
readonly kind: 'bare';
readonly span: PslSpan;
}
/**
* A positional argument on a block attribute, e.g. the `"pg/text@1"` in
* `@@type("pg/text@1")`.
*/
interface PslExtensionBlockAttributeArg {
readonly kind: 'positional';
readonly value: string;
readonly span: PslSpan;
}
/**
* A `@@`-prefixed block-level attribute parsed inside an extension block,
* e.g. `@@type("pg/text@1")`. Block attributes are captured generically
* — the parser does not validate attribute names or argument shapes; that
* is a concern of the block's interpreter.
*/
interface PslExtensionBlockAttribute {
readonly name: string;
readonly args: readonly PslExtensionBlockAttributeArg[];
readonly span: PslSpan;
}
/**
* Base shape for a uniform extension-contributed top-level PSL block
* node, as produced by the generic framework parser and consumed by the
* validator and lowering factory.
*
* - `kind` is the routing discriminant, equal to the descriptor's
* `discriminator`. The framework parser sets this to
* `descriptor.discriminator` for every block it parses.
* - `name` is the block's declared name (the identifier after the keyword).
* - `parameters` is the descriptor-driven parameter map. Keys are
* parameter names from the descriptor; values are the parsed parameter
* representations. Only parameters present in the source are included
* — absence of a required parameter is a validator concern, not a
* parser concern. Insertion order is preserved; the first occurrence of a
* duplicate key is retained and subsequent occurrences emit
* `PSL_EXTENSION_DUPLICATE_PARAMETER`.
* - `blockAttributes` are `@@`-prefixed attribute lines inside the block, in
* declaration order. Captured generically — names and args are not validated
* by the parser.
* - `span` covers the full block from keyword to closing brace.
*/
interface PslExtensionBlock {
readonly kind: string;
readonly name: string;
readonly parameters: Record<string, PslExtensionBlockParamValue>;
readonly blockAttributes: readonly PslExtensionBlockAttribute[];
readonly span: PslSpan;
}
//#endregion
//#region src/shared/framework-authoring.d.ts
type AuthoringArgRef = {
readonly kind: 'arg';
readonly index: number;
readonly path?: readonly string[];
readonly default?: AuthoringTemplateValue;
};
type AuthoringTemplateValue = string | number | boolean | null | AuthoringArgRef | readonly AuthoringTemplateValue[] | {
readonly [key: string]: AuthoringTemplateValue;
};
interface AuthoringArgumentDescriptorCommon {
readonly name?: string;
readonly optional?: boolean;
}
type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon & ({
readonly kind: 'string';
} | {
readonly kind: 'boolean';
} | {
readonly kind: 'number';
readonly integer?: boolean;
readonly minimum?: number;
readonly maximum?: number;
} | {
readonly kind: 'stringArray';
} | {
readonly kind: 'object';
readonly properties: Record<string, AuthoringArgumentDescriptor>;
});
interface AuthoringStorageTypeTemplate {
readonly codecId: string;
readonly nativeType: AuthoringTemplateValue;
readonly typeParams?: Record<string, AuthoringTemplateValue>;
}
interface AuthoringTypeConstructorDescriptor {
readonly kind: 'typeConstructor';
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringStorageTypeTemplate;
}
interface AuthoringColumnDefaultTemplateLiteral {
readonly kind: 'literal';
readonly value: AuthoringTemplateValue;
}
interface AuthoringColumnDefaultTemplateFunction {
readonly kind: 'function';
readonly expression: AuthoringTemplateValue;
}
type AuthoringColumnDefaultTemplate = AuthoringColumnDefaultTemplateLiteral | AuthoringColumnDefaultTemplateFunction;
interface AuthoringExecutionDefaultsTemplate {
readonly onCreate?: AuthoringTemplateValue;
readonly onUpdate?: AuthoringTemplateValue;
}
interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {
readonly nullable?: boolean;
readonly default?: AuthoringColumnDefaultTemplate;
readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;
readonly id?: boolean;
readonly unique?: boolean;
}
interface AuthoringFieldPresetDescriptor {
readonly kind: 'fieldPreset';
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringFieldPresetOutput;
}
type AuthoringTypeNamespace = {
readonly [name: string]: AuthoringTypeConstructorDescriptor | AuthoringTypeNamespace;
};
type AuthoringFieldNamespace = {
readonly [name: string]: AuthoringFieldPresetDescriptor | AuthoringFieldNamespace;
};
/**
* Context surfaced to entity-type factories at call time. Currently a
* placeholder — sharpened as concrete consumers (enum, namespace, …)
* discover what the factory actually needs to read (codec lookup,
* namespace registry, …).
*/
/**
* A write-only sink that a factory may push authoring-time diagnostics into.
* The concrete type pushed must be structurally compatible with whatever the
* consumer accumulates (typically `ContractSourceDiagnostic[]`); the framework
* layer deliberately does not depend on that concrete type.
*/
interface AuthoringDiagnosticSink {
push(d: {
readonly code: string;
readonly message: string;
readonly sourceId: string;
readonly span?: unknown;
}): void;
}
interface AuthoringEntityContext {
readonly family: string;
readonly target: string;
/** Codec registry available to factories that need to validate or decode values. */
readonly codecLookup?: CodecLookup;
/** Source file identifier threaded into diagnostics emitted by the factory. */
readonly sourceId?: string;
/** Push channel for authoring-time diagnostics emitted by the factory. */
readonly diagnostics?: AuthoringDiagnosticSink;
}
interface AuthoringEntityTypeTemplateOutput {
readonly template: AuthoringTemplateValue;
}
/**
* Default `Input = never` is load-bearing for pack-bag-driven type
* narrowing. Factory parameter positions are contravariant, so a pack
* literal declaring `factory: (input: DemoEntityInput) => DemoEntity`
* is only assignable to the base descriptor's factory shape if the
* base's input is `never` (the bottom of the contravariant position).
* The concrete input/output types are recovered at the helper-derivation
* site via `EntityHelperFunction<Descriptor>`'s conditional inference,
* which reads them from the pack's `as const` literal factory signature
* — the base widening does not erase the literal because `satisfies`
* does not widen the declared type.
*/
interface AuthoringEntityTypeFactoryOutput<Input = never, Output = unknown> {
readonly factory: (input: Input, ctx: AuthoringEntityContext) => Output;
}
interface AuthoringEntityTypeDescriptor<Input = never, Output = unknown> {
readonly kind: 'entity';
readonly discriminator: string;
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringEntityTypeTemplateOutput | AuthoringEntityTypeFactoryOutput<Input, Output>;
/**
* arktype schema fragment for one entry whose envelope `kind` matches
* this descriptor's {@link discriminator}. The family validator composes
* contributed fragments into the per-namespace entry schema at
* validator construction time so the structural check covers
* pack-introduced kinds without the family core hard-coding the schema.
*
* Hydration uses {@link AuthoringEntityTypeFactoryOutput.factory}
* directly — the wire shape conforms structurally to the factory's
* `Input` after `validatorSchema` validates it.
*/
readonly validatorSchema?: Type<unknown>;
}
type AuthoringEntityTypeNamespace = {
readonly [name: string]: AuthoringEntityTypeDescriptor | AuthoringEntityTypeNamespace;
};
/**
* Declarative descriptor for an extension-contributed top-level PSL block.
*
* An extension registers one of these per keyword it contributes. The
* framework owns the generic parser, validator, and printer — no
* parsing or printing code runs from the extension.
*
* - `keyword` is the PSL top-level identifier this descriptor claims
* (`policy_select`, `role`, …).
* - `discriminator` is the routing key used by the printer dispatch and
* the `entityTypes` lowering factory lookup. Convention:
* `<target-or-family>-<kind>` (`postgres-policy-select`).
* - `name.required` declares whether the block must have a name token
* after the keyword. Currently always `true` — anonymous blocks are
* not part of the closed-grammar premise — but the field is explicit
* so the type can evolve without a breaking change.
* - `parameters` maps parameter names to their value-kind descriptors
* (`ref` / `value` / `option` / `list`). The generic parser and
* validator interpret these; the extension supplies no parser or
* printer function.
*/
interface AuthoringPslBlockDescriptor {
readonly kind: 'pslBlock';
readonly keyword: string;
readonly discriminator: string;
readonly name: {
readonly required: boolean;
};
readonly parameters: Record<string, PslBlockParam>;
/**
* When `true`, the block body accepts a variadic tail of parameters beyond
* the declared set. The block body may contain: fields (model-style),
* `key = value` parameters, and `@@` attributes. With `variadicParameters`,
* bare identifiers (keys without a `= value`) and undeclared `key = value`
* pairs flow into the variadic tail — their semantics belong to the
* lowering, not the parser.
*
* A key that IS declared in `parameters` must still be supplied as
* `key = value`; a bare occurrence of a declared key is a diagnostic.
*
* When `false` (default), the validator emits `PSL_EXTENSION_UNKNOWN_PARAMETER`
* for keys absent from `parameters`.
*/
readonly variadicParameters?: boolean;
}
type AuthoringPslBlockDescriptorNamespace = {
readonly [name: string]: AuthoringPslBlockDescriptor | AuthoringPslBlockDescriptorNamespace;
};
interface AuthoringContributions {
readonly type?: AuthoringTypeNamespace;
readonly field?: AuthoringFieldNamespace;
readonly entityTypes?: AuthoringEntityTypeNamespace;
/**
* Registry of declarative block descriptors this contribution registers,
* keyed by arbitrary path segments. Each leaf is an
* {@link AuthoringPslBlockDescriptor} that claims a PSL top-level keyword.
* The framework owns the generic parser, validator, and printer; the
* contribution supplies only these declarative descriptors.
*
* Contrast with the parsed block nodes themselves, which live in a
* namespace's `entries` under their discriminator key; this field holds the
* registry of descriptors that teach the parser how to read those blocks.
*/
readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;
}
declare function isAuthoringArgRef(value: unknown): value is AuthoringArgRef;
declare function isAuthoringTypeConstructorDescriptor(value: unknown): value is AuthoringTypeConstructorDescriptor;
declare function isAuthoringFieldPresetDescriptor(value: unknown): value is AuthoringFieldPresetDescriptor;
declare function isAuthoringEntityTypeDescriptor(value: unknown): value is AuthoringEntityTypeDescriptor;
declare function isAuthoringPslBlockDescriptor(value: unknown): value is AuthoringPslBlockDescriptor;
/**
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
*
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
* registration must NOT be treated as a "namespace" with sub-paths. Callers
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
*/
declare function hasRegisteredFieldNamespace(contributions: AuthoringContributions | undefined, namespace: string): boolean;
/**
* Merges `source` into `target` recursively at the descriptor-namespace
* level. `isLeafDescriptor` decides which values are descriptors (terminal
* merge points; same-path registrations across components are reported
* as duplicates) versus sub-namespaces (recursion targets).
*
* Path segments are validated against prototype-pollution names
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
* recognized leaf nor a plain object — e.g. a malformed descriptor
* where the canonical leaf guard rejected it for missing `output` —
* is reported as an invalid contribution rather than recursed into,
* which would either silently mangle state or infinite-loop on
* primitive properties.
*
* Within-registry duplicate detection is this walker's job;
* cross-registry detection runs separately via
* `assertNoCrossRegistryCollisions` after merging completes.
*/
declare function mergeAuthoringNamespaces(target: Record<string, unknown>, source: Record<string, unknown>, path: readonly string[], isLeafDescriptor: (value: unknown) => boolean, label: string): void;
declare function assertNoCrossRegistryCollisions(typeNamespace: AuthoringTypeNamespace, fieldNamespace: AuthoringFieldNamespace, entityTypeNamespace?: AuthoringEntityTypeNamespace, pslBlockNamespace?: AuthoringPslBlockDescriptorNamespace): void;
declare function resolveAuthoringTemplateValue(template: AuthoringTemplateValue, args: readonly unknown[]): unknown;
declare function validateAuthoringHelperArguments(helperPath: string, descriptors: readonly AuthoringArgumentDescriptor[] | undefined, args: readonly unknown[]): void;
declare function instantiateAuthoringTypeConstructor(descriptor: AuthoringTypeConstructorDescriptor, args: readonly unknown[]): {
readonly codecId: string;
readonly nativeType: string;
readonly typeParams?: Record<string, unknown>;
};
declare function instantiateAuthoringEntityType(helperPath: string, descriptor: AuthoringEntityTypeDescriptor, args: readonly unknown[], ctx: AuthoringEntityContext): unknown;
declare function instantiateAuthoringFieldPreset(descriptor: AuthoringFieldPresetDescriptor, args: readonly unknown[]): {
readonly descriptor: {
readonly codecId: string;
readonly nativeType: string;
readonly typeParams?: Record<string, unknown>;
};
readonly nullable: boolean;
readonly default?: ColumnDefault;
readonly executionDefaults?: ExecutionMutationDefaultPhases;
readonly id: boolean;
readonly unique: boolean;
};
//#endregion
export { mergeAuthoringNamespaces as A, PslExtensionBlockAttribute as B, instantiateAuthoringFieldPreset as C, isAuthoringFieldPresetDescriptor as D, isAuthoringEntityTypeDescriptor as E, PslBlockParamOption as F, PslExtensionBlockParamRef as G, PslExtensionBlockParamBare as H, PslBlockParamRef as I, PslPosition as J, PslExtensionBlockParamScalarValue as K, PslBlockParamValue as L, validateAuthoringHelperArguments as M, PslBlockParam as N, isAuthoringPslBlockDescriptor as O, PslBlockParamList as P, PslDiagnosticCode as R, instantiateAuthoringEntityType as S, isAuthoringArgRef as T, PslExtensionBlockParamList as U, PslExtensionBlockAttributeArg as V, PslExtensionBlockParamOption as W, PslSpan as Y, AuthoringTemplateValue as _, AuthoringDiagnosticSink as a, assertNoCrossRegistryCollisions as b, AuthoringEntityTypeFactoryOutput as c, AuthoringFieldNamespace as d, AuthoringFieldPresetDescriptor as f, AuthoringStorageTypeTemplate as g, AuthoringPslBlockDescriptorNamespace as h, AuthoringContributions as i, resolveAuthoringTemplateValue as j, isAuthoringTypeConstructorDescriptor as k, AuthoringEntityTypeNamespace as l, AuthoringPslBlockDescriptor as m, AuthoringArgumentDescriptor as n, AuthoringEntityContext as o, AuthoringFieldPresetOutput as p, PslExtensionBlockParamValue as q, AuthoringColumnDefaultTemplate as r, AuthoringEntityTypeDescriptor as s, AuthoringArgRef as t, AuthoringEntityTypeTemplateOutput as u, AuthoringTypeConstructorDescriptor as v, instantiateAuthoringTypeConstructor as w, hasRegisteredFieldNamespace as x, AuthoringTypeNamespace as y, PslExtensionBlock as z };
//# sourceMappingURL=framework-authoring-CJC4jwGo.d.mts.map
{"version":3,"file":"framework-authoring-CJC4jwGo.d.mts","names":[],"sources":["../src/shared/psl-extension-block.ts","../src/shared/framework-authoring.ts"],"mappings":";;;;;;;;;;AAYA;;;;;;UAAiB,WAAA;EAAA,SACN,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,OAAA;EAAA,SACN,KAAA,EAAO,WAAA;EAAA,SACP,GAAA,EAAK,WAAW;AAAA;AAAA,KAGf,iBAAA;;;AAHe;AAG3B;;;;AAA6B;AAqG7B;;;;;;;;;;;;;;AAIqB;AAErB;;;;;;;;;;AAOA;;;;;;AAAA;;AAGmB;AAGnB;;;;;;;;AAGmB;AAGnB;;;;;;;;;AAGmB;AAqBnB;;;AArBmB;;;;;;;;;;;;;AA0BW;AAE9B;;;;;;;;KAxDY,aAAA,GACR,gBAAA,GACA,kBAAA,GACA,mBAAA,GACA,iBAAA;AAAA,UAEa,gBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,KAAA;EAAA,SACA,QAAA;AAAA;AAAA,UAGM,kBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;AAAA;AAAA,UAGM,mBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA;AAAA;AAAA,UAGM,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,EAAA,EAAI,aAAa;EAAA,SACjB,QAAA;AAAA;AA8CX;;;;;;;;;;AAGwB;AAQxB;;;;;;;AAXA,KAzBY,2BAAA,GACR,yBAAA,GACA,iCAAA,GACA,4BAAA,GACA,0BAAA,GACA,0BAAA;AAAA,UAEa,yBAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA;EAAA,S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U1B,+BAAA,CACd,KAAA,YACC,KAAA,IAAS,6BAA6B;AAAA,iBAqBzB,6BAAA,CACd,KAAA,YACC,KAAA,IAAS,2BAA2B;;;;;;AA/Ra;AAAG;;iBAyUvC,2BAAA,CACd,aAAA,EAAe,sBAAsB,cACrC,SAAA;;AAvUiB;AAGnB;;;;;;;;;;;;;;;;iBAkXgB,wBAAA,CACd,MAAA,EAAQ,MAAA,mBACR,MAAA,EAAQ,MAAM,mBACd,IAAA,qBACA,gBAAA,GAAmB,KAAA,uBACnB,KAAA;AAAA,iBAsNc,+BAAA,CACd,aAAA,EAAe,sBAAA,EACf,cAAA,EAAgB,uBAAA,EAChB,mBAAA,GAAqB,4BAAA,EACrB,iBAAA,GAAmB,oCAAA;AAAA,iBA6CL,6BAAA,CACd,QAAA,EAAU,sBAAsB,EAChC,IAAA;AAAA,iBAiHc,gCAAA,CACd,UAAA,UACA,WAAA,WAAsB,2BAA2B,gBACjD,IAAA;AAAA,iBAmHc,mCAAA,CACd,UAAA,EAAY,kCAAA,EACZ,IAAA;EAAA,SAES,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;AAAA,iBAKd,8BAAA,CACd,UAAA,UACA,UAAA,EAAY,6BAAA,EACZ,IAAA,sBACA,GAAA,EAAK,sBAAsB;AAAA,iBA0Bb,+BAAA,CACd,UAAA,EAAY,8BAAA,EACZ,IAAA;EAAA,SAES,UAAA;IAAA,SACE,OAAA;IAAA,SACA,UAAA;IAAA,SACA,UAAA,GAAa,MAAA;EAAA;EAAA,SAEf,QAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,iBAAA,GAAoB,8BAAA;EAAA,SACpB,EAAA;EAAA,SACA,MAAA;AAAA"}
import { blindCast } from "@prisma-next/utils/casts";
import { isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue } from "@prisma-next/contract/types";
import { ifDefined } from "@prisma-next/utils/defined";
//#region src/shared/framework-authoring.ts
function isAuthoringArgRef(value) {
if (typeof value !== "object" || value === null || value.kind !== "arg") return false;
const { index, path } = value;
if (typeof index !== "number" || !Number.isInteger(index) || index < 0) return false;
if (path !== void 0 && (!Array.isArray(path) || path.some((s) => typeof s !== "string"))) return false;
return true;
}
function isAuthoringTemplateRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function isAuthoringTypeConstructorDescriptor(value) {
return typeof value === "object" && value !== null && value.kind === "typeConstructor" && typeof value.output === "object" && value.output !== null;
}
function isAuthoringFieldPresetDescriptor(value) {
return typeof value === "object" && value !== null && value.kind === "fieldPreset" && typeof value.output === "object" && value.output !== null;
}
function isAuthoringEntityTypeDescriptor(value) {
if (typeof value !== "object" || value === null || value.kind !== "entity") return false;
const discriminator = value.discriminator;
if (typeof discriminator !== "string" || discriminator.length === 0) return false;
const output = value.output;
if (typeof output !== "object" || output === null) return false;
const factory = output.factory;
const template = output.template;
return typeof factory === "function" || template !== void 0;
}
function isAuthoringPslBlockDescriptor(value) {
if (typeof value !== "object" || value === null) return false;
const record = blindCast(value);
if (record["kind"] !== "pslBlock") return false;
const keyword = record["keyword"];
if (typeof keyword !== "string" || keyword.length === 0) return false;
const discriminator = record["discriminator"];
if (typeof discriminator !== "string" || discriminator.length === 0) return false;
const name = record["name"];
if (typeof name !== "object" || name === null) return false;
if (typeof blindCast(name)["required"] !== "boolean") return false;
const parameters = record["parameters"];
return typeof parameters === "object" && parameters !== null && !Array.isArray(parameters);
}
/**
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
*
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
* registration must NOT be treated as a "namespace" with sub-paths. Callers
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
*/
function hasRegisteredFieldNamespace(contributions, namespace) {
if (contributions?.field === void 0 || !Object.hasOwn(contributions.field, namespace)) return false;
return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);
}
function isCopyableNamespaceObject(value) {
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
const proto = Object.getPrototypeOf(value);
return proto === Object.prototype || proto === null;
}
function deepCopyNamespace(source, isLeafDescriptor) {
const copy = {};
for (const [key, value] of Object.entries(source)) copy[key] = isCopyableNamespaceObject(value) && !isLeafDescriptor(value) ? deepCopyNamespace(value, isLeafDescriptor) : value;
return copy;
}
/**
* Merges `source` into `target` recursively at the descriptor-namespace
* level. `isLeafDescriptor` decides which values are descriptors (terminal
* merge points; same-path registrations across components are reported
* as duplicates) versus sub-namespaces (recursion targets).
*
* Path segments are validated against prototype-pollution names
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
* recognized leaf nor a plain object — e.g. a malformed descriptor
* where the canonical leaf guard rejected it for missing `output` —
* is reported as an invalid contribution rather than recursed into,
* which would either silently mangle state or infinite-loop on
* primitive properties.
*
* Within-registry duplicate detection is this walker's job;
* cross-registry detection runs separately via
* `assertNoCrossRegistryCollisions` after merging completes.
*/
function mergeAuthoringNamespaces(target, source, path, isLeafDescriptor, label) {
const assertSafePath = (currentPath) => {
const blockedSegment = currentPath.find((segment) => segment === "__proto__" || segment === "constructor" || segment === "prototype");
if (blockedSegment) throw new Error(`Invalid authoring ${label} helper "${currentPath.join(".")}". Helper path segments must not use "${blockedSegment}".`);
};
for (const [key, sourceValue] of Object.entries(source)) {
const currentPath = [...path, key];
assertSafePath(currentPath);
const hasExistingValue = Object.hasOwn(target, key);
const existingValue = hasExistingValue ? target[key] : void 0;
if (!hasExistingValue) {
target[key] = isCopyableNamespaceObject(sourceValue) && !isLeafDescriptor(sourceValue) ? deepCopyNamespace(sourceValue, isLeafDescriptor) : sourceValue;
continue;
}
const existingIsLeaf = isLeafDescriptor(existingValue);
const sourceIsLeaf = isLeafDescriptor(sourceValue);
if (existingIsLeaf || sourceIsLeaf) throw new Error(`Duplicate authoring ${label} helper "${currentPath.join(".")}". Helper names must be unique across composed packs.`);
if (!isCopyableNamespaceObject(existingValue) || !isCopyableNamespaceObject(sourceValue)) throw new Error(`Invalid authoring ${label} helper "${currentPath.join(".")}". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`);
mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, isLeafDescriptor, label);
}
}
function collectDescriptorPaths(namespace, isLeaf, path = []) {
const paths = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isLeaf(value)) {
paths.push(currentPath.join("."));
continue;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) paths.push(...collectDescriptorPaths(value, isLeaf, currentPath));
}
return paths;
}
function collectDescriptorEntries(namespace, isLeaf, label, path = []) {
const entries = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isLeaf(value)) {
const discriminator = blindCast(value)["discriminator"];
if (typeof discriminator === "string" && discriminator.length > 0) entries.push({
path: currentPath.join("."),
discriminator
});
continue;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
const record = blindCast(value);
if ((record["kind"] !== void 0 || record["keyword"] !== void 0 || record["discriminator"] !== void 0) && !isLeaf(value)) {
const hasKind = record["kind"] === "pslBlock";
const hasKeyword = typeof record["keyword"] === "string";
const hasDiscriminator = typeof record["discriminator"] === "string";
if (hasKind || hasKeyword && hasDiscriminator) throw new Error(`Malformed authoring ${label} contribution at "${currentPath.join(".")}". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the ${label} descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`);
}
entries.push(...collectDescriptorEntries(record, isLeaf, label, currentPath));
}
}
return entries;
}
/**
* Throws when two or more entries in the same namespace share a discriminator.
* Duplicate discriminators within a namespace make dispatch ambiguous — the
* lowering factory lookup dispatches by discriminator, so one would silently
* shadow the other. Catch duplicates before building any dispatch map.
*/
function assertUniqueDiscriminators(entries, label) {
const seen = /* @__PURE__ */ new Map();
for (const { path, discriminator } of entries) {
const existing = seen.get(discriminator);
if (existing !== void 0) throw new Error(`Duplicate ${label} discriminator "${discriminator}" registered at both "${existing}" and "${path}". Each ${label} contribution must use a unique discriminator.`);
seen.set(discriminator, path);
}
}
function collectPslBlockDescriptorEntries(namespace, path = []) {
const entries = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isAuthoringPslBlockDescriptor(value)) {
entries.push({
path: currentPath.join("."),
discriminator: value.discriminator
});
continue;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
const record = blindCast(value);
const hasKind = record["kind"] === "pslBlock";
const hasKeyword = typeof record["keyword"] === "string";
const hasDiscriminator = typeof record["discriminator"] === "string";
if (hasKind || hasKeyword && hasDiscriminator) throw new Error(`Malformed authoring pslBlock contribution at "${currentPath.join(".")}". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the pslBlock descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`);
entries.push(...collectPslBlockDescriptorEntries(record, currentPath));
}
}
return entries;
}
/**
* Every `pslBlockDescriptors` entry requires a matching `entityTypes` factory
* with the same discriminator. An `entityTypes` factory may stand alone (e.g.
* `enum`, reachable from the TypeScript builder without any PSL block).
*/
function assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace) {
const blockEntries = collectPslBlockDescriptorEntries(pslBlockNamespace);
const entityEntries = collectDescriptorEntries(entityTypeNamespace, isAuthoringEntityTypeDescriptor, "entityType");
assertUniqueDiscriminators(blockEntries, "pslBlock");
assertUniqueDiscriminators(entityEntries, "entityType");
const entityDiscriminators = new Set(entityEntries.map((entry) => entry.discriminator));
for (const block of blockEntries) if (!entityDiscriminators.has(block.discriminator)) throw new Error(`Incomplete extension contribution: pslBlock helper "${block.path}" registers discriminator "${block.discriminator}" but no entityType contribution shares that discriminator. An extension-contributed PSL block requires a matching entityType factory so the parsed AST node can lower to an IR class instance; add an entityType helper with discriminator "${block.discriminator}".`);
}
function assertNoCrossRegistryCollisions(typeNamespace, fieldNamespace, entityTypeNamespace = {}, pslBlockNamespace = {}) {
const typePaths = new Set(collectDescriptorPaths(typeNamespace, isAuthoringTypeConstructorDescriptor));
const fieldPaths = new Set(collectDescriptorPaths(fieldNamespace, isAuthoringFieldPresetDescriptor));
const entityPaths = new Set(collectDescriptorPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor));
const ambiguityHint = "Register each path in only one of authoringContributions.field / authoringContributions.type / authoringContributions.entityTypes.";
for (const fieldPath of fieldPaths) if (typePaths.has(fieldPath)) throw new Error(`Ambiguous authoring registry path "${fieldPath}". The same path is registered as both a type constructor and a field preset; PSL resolution would be ambiguous. ${ambiguityHint}`);
for (const entityPath of entityPaths) if (typePaths.has(entityPath) || fieldPaths.has(entityPath)) throw new Error(`Ambiguous authoring registry path "${entityPath}". The same path is registered as an entity contribution AND as a type constructor or field preset; PSL resolution would be ambiguous. ${ambiguityHint}`);
assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace);
}
function resolveAuthoringTemplateValue(template, args) {
if (isAuthoringArgRef(template)) {
let value = args[template.index];
for (const segment of template.path ?? []) {
if (!isAuthoringTemplateRecord(value) || !Object.hasOwn(value, segment)) {
value = void 0;
break;
}
value = value[segment];
}
if (value === void 0 && template.default !== void 0) return resolveAuthoringTemplateValue(template.default, args);
return value;
}
if (Array.isArray(template)) return template.map((value) => resolveAuthoringTemplateValue(value, args));
if (typeof template === "object" && template !== null) {
const resolved = {};
for (const [key, value] of Object.entries(template)) {
const resolvedValue = resolveAuthoringTemplateValue(value, args);
if (resolvedValue !== void 0) resolved[key] = resolvedValue;
}
return resolved;
}
return template;
}
function validateAuthoringArgument(descriptor, value, path) {
if (value === void 0) {
if (descriptor.optional) return;
throw new Error(`Missing required authoring helper argument at ${path}`);
}
if (descriptor.kind === "string") {
if (typeof value !== "string") throw new Error(`Authoring helper argument at ${path} must be a string`);
return;
}
if (descriptor.kind === "boolean") {
if (typeof value !== "boolean") throw new Error(`Authoring helper argument at ${path} must be a boolean`);
return;
}
if (descriptor.kind === "stringArray") {
if (!Array.isArray(value)) throw new Error(`Authoring helper argument at ${path} must be an array of strings`);
for (const entry of value) if (typeof entry !== "string") throw new Error(`Authoring helper argument at ${path} must be an array of strings`);
return;
}
if (descriptor.kind === "object") {
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`Authoring helper argument at ${path} must be an object`);
const input = value;
const expectedKeys = new Set(Object.keys(descriptor.properties));
for (const key of Object.keys(input)) if (!expectedKeys.has(key)) throw new Error(`Authoring helper argument at ${path} contains unknown property "${key}"`);
for (const [key, propertyDescriptor] of Object.entries(descriptor.properties)) validateAuthoringArgument(propertyDescriptor, input[key], `${path}.${key}`);
return;
}
if (typeof value !== "number" || Number.isNaN(value)) throw new Error(`Authoring helper argument at ${path} must be a number`);
if (descriptor.integer && !Number.isInteger(value)) throw new Error(`Authoring helper argument at ${path} must be an integer`);
if (descriptor.minimum !== void 0 && value < descriptor.minimum) throw new Error(`Authoring helper argument at ${path} must be >= ${descriptor.minimum}, received ${value}`);
if (descriptor.maximum !== void 0 && value > descriptor.maximum) throw new Error(`Authoring helper argument at ${path} must be <= ${descriptor.maximum}, received ${value}`);
}
function validateAuthoringHelperArguments(helperPath, descriptors, args) {
const expected = descriptors ?? [];
const minimumArgs = expected.reduce((count, descriptor, index) => descriptor.optional ? count : index + 1, 0);
if (args.length < minimumArgs || args.length > expected.length) throw new Error(`${helperPath} expects ${minimumArgs === expected.length ? expected.length : `${minimumArgs}-${expected.length}`} argument(s), received ${args.length}`);
expected.forEach((descriptor, index) => {
validateAuthoringArgument(descriptor, args[index], `${helperPath}[${index}]`);
});
}
function resolveAuthoringStorageTypeTemplate(template, args) {
const nativeType = resolveAuthoringTemplateValue(template.nativeType, args);
if (typeof nativeType !== "string") throw new Error(`Resolved authoring nativeType must be a string for codec "${template.codecId}", received ${String(nativeType)}`);
const typeParams = template.typeParams === void 0 ? void 0 : resolveAuthoringTemplateValue(template.typeParams, args);
if (typeParams !== void 0 && !isAuthoringTemplateRecord(typeParams)) throw new Error(`Resolved authoring typeParams must be an object for codec "${template.codecId}", received ${String(typeParams)}`);
return {
codecId: template.codecId,
nativeType,
...typeParams === void 0 ? {} : { typeParams }
};
}
function resolveAuthoringColumnDefaultTemplate(template, args) {
if (template.kind === "literal") {
const value = resolveAuthoringTemplateValue(template.value, args);
if (value === void 0) throw new Error("Resolved authoring literal default must not be undefined");
if (!isColumnDefaultLiteralInputValue(value)) throw new Error(`Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`);
return {
kind: "literal",
value
};
}
const expression = resolveAuthoringTemplateValue(template.expression, args);
if (expression === void 0 || typeof expression === "object" && expression !== null) throw new Error(`Resolved authoring function default expression must resolve to a primitive, received ${String(expression)}`);
return {
kind: "function",
expression: String(expression)
};
}
function resolveExecutionMutationDefaultPhase(phase, template, args) {
const value = resolveAuthoringTemplateValue(template, args);
if (!isExecutionMutationDefaultValue(value)) throw new Error(`Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`);
return value;
}
function resolveAuthoringExecutionDefaultsTemplate(template, args) {
return {
...ifDefined("onCreate", template.onCreate !== void 0 ? resolveExecutionMutationDefaultPhase("onCreate", template.onCreate, args) : void 0),
...ifDefined("onUpdate", template.onUpdate !== void 0 ? resolveExecutionMutationDefaultPhase("onUpdate", template.onUpdate, args) : void 0)
};
}
function instantiateAuthoringTypeConstructor(descriptor, args) {
return resolveAuthoringStorageTypeTemplate(descriptor.output, args);
}
function instantiateAuthoringEntityType(helperPath, descriptor, args, ctx) {
if ("factory" in descriptor.output) {
const input = args[0];
const factory = descriptor.output.factory;
return factory(input, ctx);
}
validateAuthoringHelperArguments(helperPath, descriptor.args, args);
return resolveAuthoringTemplateValue(descriptor.output.template, args);
}
function instantiateAuthoringFieldPreset(descriptor, args) {
return {
descriptor: resolveAuthoringStorageTypeTemplate(descriptor.output, args),
nullable: descriptor.output.nullable ?? false,
...ifDefined("default", descriptor.output.default !== void 0 ? resolveAuthoringColumnDefaultTemplate(descriptor.output.default, args) : void 0),
...ifDefined("executionDefaults", descriptor.output.executionDefaults !== void 0 ? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args) : void 0),
id: descriptor.output.id ?? false,
unique: descriptor.output.unique ?? false
};
}
//#endregion
export { instantiateAuthoringTypeConstructor as a, isAuthoringFieldPresetDescriptor as c, mergeAuthoringNamespaces as d, resolveAuthoringTemplateValue as f, instantiateAuthoringFieldPreset as i, isAuthoringPslBlockDescriptor as l, hasRegisteredFieldNamespace as n, isAuthoringArgRef as o, validateAuthoringHelperArguments as p, instantiateAuthoringEntityType as r, isAuthoringEntityTypeDescriptor as s, assertNoCrossRegistryCollisions as t, isAuthoringTypeConstructorDescriptor as u };
//# sourceMappingURL=framework-authoring-Dv5F3EFC.mjs.map
{"version":3,"file":"framework-authoring-Dv5F3EFC.mjs","names":[],"sources":["../src/shared/framework-authoring.ts"],"sourcesContent":["import type {\n ColumnDefault,\n ExecutionMutationDefaultPhases,\n ExecutionMutationDefaultValue,\n} from '@prisma-next/contract/types';\nimport {\n isColumnDefaultLiteralInputValue,\n isExecutionMutationDefaultValue,\n} from '@prisma-next/contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Type } from 'arktype';\nimport type { CodecLookup } from './codec-types';\nimport type { PslBlockParam } from './psl-extension-block';\n\nexport type AuthoringArgRef = {\n readonly kind: 'arg';\n readonly index: number;\n readonly path?: readonly string[];\n readonly default?: AuthoringTemplateValue;\n};\n\nexport type AuthoringTemplateValue =\n | string\n | number\n | boolean\n | null\n | AuthoringArgRef\n | readonly AuthoringTemplateValue[]\n | { readonly [key: string]: AuthoringTemplateValue };\n\ninterface AuthoringArgumentDescriptorCommon {\n readonly name?: string;\n readonly optional?: boolean;\n}\n\nexport type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon &\n (\n | { readonly kind: 'string' }\n | { readonly kind: 'boolean' }\n | {\n readonly kind: 'number';\n readonly integer?: boolean;\n readonly minimum?: number;\n readonly maximum?: number;\n }\n | { readonly kind: 'stringArray' }\n | {\n readonly kind: 'object';\n readonly properties: Record<string, AuthoringArgumentDescriptor>;\n }\n );\n\nexport interface AuthoringStorageTypeTemplate {\n readonly codecId: string;\n readonly nativeType: AuthoringTemplateValue;\n readonly typeParams?: Record<string, AuthoringTemplateValue>;\n}\n\nexport interface AuthoringTypeConstructorDescriptor {\n readonly kind: 'typeConstructor';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringStorageTypeTemplate;\n}\n\nexport interface AuthoringColumnDefaultTemplateLiteral {\n readonly kind: 'literal';\n readonly value: AuthoringTemplateValue;\n}\n\nexport interface AuthoringColumnDefaultTemplateFunction {\n readonly kind: 'function';\n readonly expression: AuthoringTemplateValue;\n}\n\nexport type AuthoringColumnDefaultTemplate =\n | AuthoringColumnDefaultTemplateLiteral\n | AuthoringColumnDefaultTemplateFunction;\n\nexport interface AuthoringExecutionDefaultsTemplate {\n readonly onCreate?: AuthoringTemplateValue;\n readonly onUpdate?: AuthoringTemplateValue;\n}\n\nexport interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {\n readonly nullable?: boolean;\n readonly default?: AuthoringColumnDefaultTemplate;\n readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;\n readonly id?: boolean;\n readonly unique?: boolean;\n}\n\nexport interface AuthoringFieldPresetDescriptor {\n readonly kind: 'fieldPreset';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringFieldPresetOutput;\n}\n\nexport type AuthoringTypeNamespace = {\n readonly [name: string]: AuthoringTypeConstructorDescriptor | AuthoringTypeNamespace;\n};\n\nexport type AuthoringFieldNamespace = {\n readonly [name: string]: AuthoringFieldPresetDescriptor | AuthoringFieldNamespace;\n};\n\n/**\n * Context surfaced to entity-type factories at call time. Currently a\n * placeholder — sharpened as concrete consumers (enum, namespace, …)\n * discover what the factory actually needs to read (codec lookup,\n * namespace registry, …).\n */\n/**\n * A write-only sink that a factory may push authoring-time diagnostics into.\n * The concrete type pushed must be structurally compatible with whatever the\n * consumer accumulates (typically `ContractSourceDiagnostic[]`); the framework\n * layer deliberately does not depend on that concrete type.\n */\nexport interface AuthoringDiagnosticSink {\n push(d: {\n readonly code: string;\n readonly message: string;\n readonly sourceId: string;\n readonly span?: unknown;\n }): void;\n}\n\nexport interface AuthoringEntityContext {\n readonly family: string;\n readonly target: string;\n /** Codec registry available to factories that need to validate or decode values. */\n readonly codecLookup?: CodecLookup;\n /** Source file identifier threaded into diagnostics emitted by the factory. */\n readonly sourceId?: string;\n /** Push channel for authoring-time diagnostics emitted by the factory. */\n readonly diagnostics?: AuthoringDiagnosticSink;\n}\n\nexport interface AuthoringEntityTypeTemplateOutput {\n readonly template: AuthoringTemplateValue;\n}\n\n/**\n * Default `Input = never` is load-bearing for pack-bag-driven type\n * narrowing. Factory parameter positions are contravariant, so a pack\n * literal declaring `factory: (input: DemoEntityInput) => DemoEntity`\n * is only assignable to the base descriptor's factory shape if the\n * base's input is `never` (the bottom of the contravariant position).\n * The concrete input/output types are recovered at the helper-derivation\n * site via `EntityHelperFunction<Descriptor>`'s conditional inference,\n * which reads them from the pack's `as const` literal factory signature\n * — the base widening does not erase the literal because `satisfies`\n * does not widen the declared type.\n */\nexport interface AuthoringEntityTypeFactoryOutput<Input = never, Output = unknown> {\n readonly factory: (input: Input, ctx: AuthoringEntityContext) => Output;\n}\n\nexport interface AuthoringEntityTypeDescriptor<Input = never, Output = unknown> {\n readonly kind: 'entity';\n readonly discriminator: string;\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output:\n | AuthoringEntityTypeTemplateOutput\n | AuthoringEntityTypeFactoryOutput<Input, Output>;\n /**\n * arktype schema fragment for one entry whose envelope `kind` matches\n * this descriptor's {@link discriminator}. The family validator composes\n * contributed fragments into the per-namespace entry schema at\n * validator construction time so the structural check covers\n * pack-introduced kinds without the family core hard-coding the schema.\n *\n * Hydration uses {@link AuthoringEntityTypeFactoryOutput.factory}\n * directly — the wire shape conforms structurally to the factory's\n * `Input` after `validatorSchema` validates it.\n */\n readonly validatorSchema?: Type<unknown>;\n}\n\nexport type AuthoringEntityTypeNamespace = {\n readonly [name: string]: AuthoringEntityTypeDescriptor | AuthoringEntityTypeNamespace;\n};\n\n/**\n * Declarative descriptor for an extension-contributed top-level PSL block.\n *\n * An extension registers one of these per keyword it contributes. The\n * framework owns the generic parser, validator, and printer — no\n * parsing or printing code runs from the extension.\n *\n * - `keyword` is the PSL top-level identifier this descriptor claims\n * (`policy_select`, `role`, …).\n * - `discriminator` is the routing key used by the printer dispatch and\n * the `entityTypes` lowering factory lookup. Convention:\n * `<target-or-family>-<kind>` (`postgres-policy-select`).\n * - `name.required` declares whether the block must have a name token\n * after the keyword. Currently always `true` — anonymous blocks are\n * not part of the closed-grammar premise — but the field is explicit\n * so the type can evolve without a breaking change.\n * - `parameters` maps parameter names to their value-kind descriptors\n * (`ref` / `value` / `option` / `list`). The generic parser and\n * validator interpret these; the extension supplies no parser or\n * printer function.\n */\nexport interface AuthoringPslBlockDescriptor {\n readonly kind: 'pslBlock';\n readonly keyword: string;\n readonly discriminator: string;\n readonly name: { readonly required: boolean };\n readonly parameters: Record<string, PslBlockParam>;\n /**\n * When `true`, the block body accepts a variadic tail of parameters beyond\n * the declared set. The block body may contain: fields (model-style),\n * `key = value` parameters, and `@@` attributes. With `variadicParameters`,\n * bare identifiers (keys without a `= value`) and undeclared `key = value`\n * pairs flow into the variadic tail — their semantics belong to the\n * lowering, not the parser.\n *\n * A key that IS declared in `parameters` must still be supplied as\n * `key = value`; a bare occurrence of a declared key is a diagnostic.\n *\n * When `false` (default), the validator emits `PSL_EXTENSION_UNKNOWN_PARAMETER`\n * for keys absent from `parameters`.\n */\n readonly variadicParameters?: boolean;\n}\n\nexport type AuthoringPslBlockDescriptorNamespace = {\n readonly [name: string]: AuthoringPslBlockDescriptor | AuthoringPslBlockDescriptorNamespace;\n};\n\nexport interface AuthoringContributions {\n readonly type?: AuthoringTypeNamespace;\n readonly field?: AuthoringFieldNamespace;\n readonly entityTypes?: AuthoringEntityTypeNamespace;\n /**\n * Registry of declarative block descriptors this contribution registers,\n * keyed by arbitrary path segments. Each leaf is an\n * {@link AuthoringPslBlockDescriptor} that claims a PSL top-level keyword.\n * The framework owns the generic parser, validator, and printer; the\n * contribution supplies only these declarative descriptors.\n *\n * Contrast with the parsed block nodes themselves, which live in a\n * namespace's `entries` under their discriminator key; this field holds the\n * registry of descriptors that teach the parser how to read those blocks.\n */\n readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport function isAuthoringArgRef(value: unknown): value is AuthoringArgRef {\n if (typeof value !== 'object' || value === null || (value as { kind?: unknown }).kind !== 'arg') {\n return false;\n }\n const { index, path } = value as { index?: unknown; path?: unknown };\n if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) {\n return false;\n }\n if (path !== undefined && (!Array.isArray(path) || path.some((s) => typeof s !== 'string'))) {\n return false;\n }\n return true;\n}\n\nfunction isAuthoringTemplateRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isAuthoringTypeConstructorDescriptor(\n value: unknown,\n): value is AuthoringTypeConstructorDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'typeConstructor' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function isAuthoringFieldPresetDescriptor(\n value: unknown,\n): value is AuthoringFieldPresetDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'fieldPreset' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function isAuthoringEntityTypeDescriptor(\n value: unknown,\n): value is AuthoringEntityTypeDescriptor {\n if (\n typeof value !== 'object' ||\n value === null ||\n (value as { kind?: unknown }).kind !== 'entity'\n ) {\n return false;\n }\n const discriminator = (value as { discriminator?: unknown }).discriminator;\n if (typeof discriminator !== 'string' || discriminator.length === 0) {\n return false;\n }\n const output = (value as { output?: unknown }).output;\n if (typeof output !== 'object' || output === null) {\n return false;\n }\n const factory = (output as { factory?: unknown }).factory;\n const template = (output as { template?: unknown }).template;\n return typeof factory === 'function' || template !== undefined;\n}\n\nexport function isAuthoringPslBlockDescriptor(\n value: unknown,\n): value is AuthoringPslBlockDescriptor {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const record = blindCast<\n Record<string, unknown>,\n 'type-guard probing an unknown candidate-descriptor object for known property names'\n >(value);\n if (record['kind'] !== 'pslBlock') {\n return false;\n }\n const keyword = record['keyword'];\n if (typeof keyword !== 'string' || keyword.length === 0) {\n return false;\n }\n const discriminator = record['discriminator'];\n if (typeof discriminator !== 'string' || discriminator.length === 0) {\n return false;\n }\n const name = record['name'];\n if (typeof name !== 'object' || name === null) {\n return false;\n }\n const nameRecord = blindCast<\n Record<string, unknown>,\n 'type-guard probing the name property of a candidate pslBlock descriptor'\n >(name);\n if (typeof nameRecord['required'] !== 'boolean') {\n return false;\n }\n const parameters = record['parameters'];\n return typeof parameters === 'object' && parameters !== null && !Array.isArray(parameters);\n}\n\n/**\n * Returns true when `namespace` is a non-leaf key in `contributions.field`.\n *\n * `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including\n * the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`\n * registration must NOT be treated as a \"namespace\" with sub-paths. Callers\n * use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).\n */\nexport function hasRegisteredFieldNamespace(\n contributions: AuthoringContributions | undefined,\n namespace: string,\n): boolean {\n if (contributions?.field === undefined || !Object.hasOwn(contributions.field, namespace)) {\n return false;\n }\n return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);\n}\n\nfunction isCopyableNamespaceObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const proto: unknown = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\nfunction deepCopyNamespace(\n source: Record<string, unknown>,\n isLeafDescriptor: (value: unknown) => boolean,\n): Record<string, unknown> {\n const copy: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(source)) {\n copy[key] =\n isCopyableNamespaceObject(value) && !isLeafDescriptor(value)\n ? deepCopyNamespace(value, isLeafDescriptor)\n : value;\n }\n return copy;\n}\n\n/**\n * Merges `source` into `target` recursively at the descriptor-namespace\n * level. `isLeafDescriptor` decides which values are descriptors (terminal\n * merge points; same-path registrations across components are reported\n * as duplicates) versus sub-namespaces (recursion targets).\n *\n * Path segments are validated against prototype-pollution names\n * (`__proto__`, `constructor`, `prototype`). A value that is neither a\n * recognized leaf nor a plain object — e.g. a malformed descriptor\n * where the canonical leaf guard rejected it for missing `output` —\n * is reported as an invalid contribution rather than recursed into,\n * which would either silently mangle state or infinite-loop on\n * primitive properties.\n *\n * Within-registry duplicate detection is this walker's job;\n * cross-registry detection runs separately via\n * `assertNoCrossRegistryCollisions` after merging completes.\n */\nexport function mergeAuthoringNamespaces(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n path: readonly string[],\n isLeafDescriptor: (value: unknown) => boolean,\n label: string,\n): void {\n const assertSafePath = (currentPath: readonly string[]) => {\n const blockedSegment = currentPath.find(\n (segment) => segment === '__proto__' || segment === 'constructor' || segment === 'prototype',\n );\n if (blockedSegment) {\n throw new Error(\n `Invalid authoring ${label} helper \"${currentPath.join('.')}\". Helper path segments must not use \"${blockedSegment}\".`,\n );\n }\n };\n\n for (const [key, sourceValue] of Object.entries(source)) {\n const currentPath = [...path, key];\n assertSafePath(currentPath);\n const hasExistingValue = Object.hasOwn(target, key);\n const existingValue = hasExistingValue ? target[key] : undefined;\n\n if (!hasExistingValue) {\n // Deep-copy plain-object sub-namespaces so subsequent merges don't mutate\n // objects owned by source packs. Leaf descriptors and class instances are\n // passed by reference — leaves are identity values; class instances carry\n // prototype getters that spread would destroy.\n target[key] =\n isCopyableNamespaceObject(sourceValue) && !isLeafDescriptor(sourceValue)\n ? deepCopyNamespace(sourceValue, isLeafDescriptor)\n : sourceValue;\n continue;\n }\n\n const existingIsLeaf = isLeafDescriptor(existingValue);\n const sourceIsLeaf = isLeafDescriptor(sourceValue);\n\n if (existingIsLeaf || sourceIsLeaf) {\n throw new Error(\n `Duplicate authoring ${label} helper \"${currentPath.join('.')}\". Helper names must be unique across composed packs.`,\n );\n }\n\n if (!isCopyableNamespaceObject(existingValue) || !isCopyableNamespaceObject(sourceValue)) {\n throw new Error(\n `Invalid authoring ${label} helper \"${currentPath.join('.')}\". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`,\n );\n }\n\n mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, isLeafDescriptor, label);\n }\n}\n\nfunction collectDescriptorPaths(\n namespace: Readonly<Record<string, unknown>>,\n isLeaf: (value: unknown) => boolean,\n path: readonly string[] = [],\n): string[] {\n const paths: string[] = [];\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeaf(value)) {\n paths.push(currentPath.join('.'));\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n paths.push(\n ...collectDescriptorPaths(value as Readonly<Record<string, unknown>>, isLeaf, currentPath),\n );\n }\n }\n return paths;\n}\n\ninterface DescriptorEntry {\n readonly path: string;\n readonly discriminator: string;\n}\n\nfunction collectDescriptorEntries(\n namespace: Readonly<Record<string, unknown>>,\n isLeaf: (value: unknown) => boolean,\n label: string,\n path: readonly string[] = [],\n): DescriptorEntry[] {\n const entries: DescriptorEntry[] = [];\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeaf(value)) {\n const record = blindCast<\n Record<string, unknown>,\n 'discriminator extraction from a leaf already validated by isLeaf'\n >(value);\n const discriminator = record['discriminator'];\n if (typeof discriminator === 'string' && discriminator.length > 0) {\n entries.push({ path: currentPath.join('.'), discriminator });\n }\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n const record = blindCast<\n Readonly<Record<string, unknown>>,\n 'walker inspects a non-leaf value for descriptor-shaped keys before recursing'\n >(value);\n // A value carrying descriptor-shaped keys (`kind`/`keyword`/`discriminator`)\n // but failing `isAuthoringPslBlockDescriptor` (e.g. missing `parameters`) is\n // a malformed declarative descriptor. Descending into it as a sub-namespace\n // would silently skip it, so a half-built contribution would pass validation.\n // Reject it at load time instead, naming the path and what's wrong.\n //\n // A valid sub-namespace whose key happens to be named `kind`, `keyword`, or\n // `discriminator` (but which does not look like a descriptor overall) must\n // still descend normally — the check requires descriptor-shaped keys present\n // AND the leaf guard rejecting it.\n if (\n (record['kind'] !== undefined ||\n record['keyword'] !== undefined ||\n record['discriminator'] !== undefined) &&\n !isLeaf(value)\n ) {\n const hasKind = record['kind'] === 'pslBlock';\n const hasKeyword = typeof record['keyword'] === 'string';\n const hasDiscriminator = typeof record['discriminator'] === 'string';\n if (hasKind || (hasKeyword && hasDiscriminator)) {\n throw new Error(\n `Malformed authoring ${label} contribution at \"${currentPath.join('.')}\". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the ${label} descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`,\n );\n }\n }\n entries.push(...collectDescriptorEntries(record, isLeaf, label, currentPath));\n }\n }\n return entries;\n}\n\n/**\n * Throws when two or more entries in the same namespace share a discriminator.\n * Duplicate discriminators within a namespace make dispatch ambiguous — the\n * lowering factory lookup dispatches by discriminator, so one would silently\n * shadow the other. Catch duplicates before building any dispatch map.\n */\nfunction assertUniqueDiscriminators(entries: readonly DescriptorEntry[], label: string): void {\n const seen = new Map<string, string>();\n for (const { path, discriminator } of entries) {\n const existing = seen.get(discriminator);\n if (existing !== undefined) {\n throw new Error(\n `Duplicate ${label} discriminator \"${discriminator}\" registered at both \"${existing}\" and \"${path}\". Each ${label} contribution must use a unique discriminator.`,\n );\n }\n seen.set(discriminator, path);\n }\n}\n\nfunction collectPslBlockDescriptorEntries(\n namespace: Readonly<Record<string, unknown>>,\n path: readonly string[] = [],\n): DescriptorEntry[] {\n const entries: DescriptorEntry[] = [];\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isAuthoringPslBlockDescriptor(value)) {\n entries.push({\n path: currentPath.join('.'),\n discriminator: value.discriminator,\n });\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n const record = blindCast<\n Readonly<Record<string, unknown>>,\n 'walker descends into psl block namespace'\n >(value);\n const hasKind = record['kind'] === 'pslBlock';\n const hasKeyword = typeof record['keyword'] === 'string';\n const hasDiscriminator = typeof record['discriminator'] === 'string';\n if (hasKind || (hasKeyword && hasDiscriminator)) {\n throw new Error(\n `Malformed authoring pslBlock contribution at \"${currentPath.join('.')}\". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the pslBlock descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`,\n );\n }\n entries.push(...collectPslBlockDescriptorEntries(record, currentPath));\n }\n }\n return entries;\n}\n\n/**\n * Every `pslBlockDescriptors` entry requires a matching `entityTypes` factory\n * with the same discriminator. An `entityTypes` factory may stand alone (e.g.\n * `enum`, reachable from the TypeScript builder without any PSL block).\n */\nfunction assertPslBlocksHaveFactories(\n entityTypeNamespace: AuthoringEntityTypeNamespace,\n pslBlockNamespace: AuthoringPslBlockDescriptorNamespace,\n): void {\n const blockEntries = collectPslBlockDescriptorEntries(pslBlockNamespace);\n const entityEntries = collectDescriptorEntries(\n entityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n 'entityType',\n );\n\n assertUniqueDiscriminators(blockEntries, 'pslBlock');\n assertUniqueDiscriminators(entityEntries, 'entityType');\n\n const entityDiscriminators = new Set(entityEntries.map((entry) => entry.discriminator));\n\n for (const block of blockEntries) {\n if (!entityDiscriminators.has(block.discriminator)) {\n throw new Error(\n `Incomplete extension contribution: pslBlock helper \"${block.path}\" registers discriminator \"${block.discriminator}\" but no entityType contribution shares that discriminator. An extension-contributed PSL block requires a matching entityType factory so the parsed AST node can lower to an IR class instance; add an entityType helper with discriminator \"${block.discriminator}\".`,\n );\n }\n }\n}\n\nexport function assertNoCrossRegistryCollisions(\n typeNamespace: AuthoringTypeNamespace,\n fieldNamespace: AuthoringFieldNamespace,\n entityTypeNamespace: AuthoringEntityTypeNamespace = {},\n pslBlockNamespace: AuthoringPslBlockDescriptorNamespace = {},\n): void {\n const typePaths = new Set(\n collectDescriptorPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),\n );\n const fieldPaths = new Set(\n collectDescriptorPaths(fieldNamespace, isAuthoringFieldPresetDescriptor),\n );\n const entityPaths = new Set(\n collectDescriptorPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor),\n );\n // Within-registry duplicate detection is handled upstream by the merge\n // walker (`mergeAuthoringNamespaces` in control-stack.ts and\n // `mergeHelperNamespaces` in composed-authoring-helpers.ts), which throws\n // on same-path registrations within any single registry before this check\n // runs. This function only handles the cross-registry case.\n //\n // Cross-registry collisions are checked among `type` / `field` /\n // `entityTypes` only — these three are user-facing helper paths that PSL\n // must resolve unambiguously. `pslBlockDescriptors` is an internal\n // framework index consumed by parser and printer dispatch, not a\n // user-facing helper path; the natural authoring pattern is the same\n // path key in `entityTypes` and `pslBlockDescriptors` for a single\n // contribution. The block→factory link is enforced by\n // `assertPslBlocksHaveFactories` via the discriminator string, not by path.\n const ambiguityHint =\n 'Register each path in only one of authoringContributions.field / authoringContributions.type / authoringContributions.entityTypes.';\n for (const fieldPath of fieldPaths) {\n if (typePaths.has(fieldPath)) {\n throw new Error(\n `Ambiguous authoring registry path \"${fieldPath}\". The same path is registered as both a type constructor and a field preset; PSL resolution would be ambiguous. ${ambiguityHint}`,\n );\n }\n }\n for (const entityPath of entityPaths) {\n if (typePaths.has(entityPath) || fieldPaths.has(entityPath)) {\n throw new Error(\n `Ambiguous authoring registry path \"${entityPath}\". The same path is registered as an entity contribution AND as a type constructor or field preset; PSL resolution would be ambiguous. ${ambiguityHint}`,\n );\n }\n }\n\n assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace);\n}\n\nexport function resolveAuthoringTemplateValue(\n template: AuthoringTemplateValue,\n args: readonly unknown[],\n): unknown {\n if (isAuthoringArgRef(template)) {\n let value = args[template.index];\n\n for (const segment of template.path ?? []) {\n if (!isAuthoringTemplateRecord(value) || !Object.hasOwn(value, segment)) {\n value = undefined;\n break;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n\n if (value === undefined && template.default !== undefined) {\n return resolveAuthoringTemplateValue(template.default, args);\n }\n\n return value;\n }\n if (Array.isArray(template)) {\n return template.map((value) => resolveAuthoringTemplateValue(value, args));\n }\n if (typeof template === 'object' && template !== null) {\n const resolved: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(template)) {\n const resolvedValue = resolveAuthoringTemplateValue(value, args);\n if (resolvedValue !== undefined) {\n resolved[key] = resolvedValue;\n }\n }\n return resolved;\n }\n return template;\n}\n\nfunction validateAuthoringArgument(\n descriptor: AuthoringArgumentDescriptor,\n value: unknown,\n path: string,\n): void {\n if (value === undefined) {\n if (descriptor.optional) {\n return;\n }\n throw new Error(`Missing required authoring helper argument at ${path}`);\n }\n\n if (descriptor.kind === 'string') {\n if (typeof value !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be a string`);\n }\n return;\n }\n\n if (descriptor.kind === 'boolean') {\n if (typeof value !== 'boolean') {\n throw new Error(`Authoring helper argument at ${path} must be a boolean`);\n }\n return;\n }\n\n if (descriptor.kind === 'stringArray') {\n if (!Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n for (const entry of value) {\n if (typeof entry !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n }\n return;\n }\n\n if (descriptor.kind === 'object') {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an object`);\n }\n\n const input = value as Record<string, unknown>;\n const expectedKeys = new Set(Object.keys(descriptor.properties));\n\n for (const key of Object.keys(input)) {\n if (!expectedKeys.has(key)) {\n throw new Error(`Authoring helper argument at ${path} contains unknown property \"${key}\"`);\n }\n }\n\n for (const [key, propertyDescriptor] of Object.entries(descriptor.properties)) {\n validateAuthoringArgument(propertyDescriptor, input[key], `${path}.${key}`);\n }\n\n return;\n }\n\n if (typeof value !== 'number' || Number.isNaN(value)) {\n throw new Error(`Authoring helper argument at ${path} must be a number`);\n }\n\n if (descriptor.integer && !Number.isInteger(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an integer`);\n }\n if (descriptor.minimum !== undefined && value < descriptor.minimum) {\n throw new Error(\n `Authoring helper argument at ${path} must be >= ${descriptor.minimum}, received ${value}`,\n );\n }\n if (descriptor.maximum !== undefined && value > descriptor.maximum) {\n throw new Error(\n `Authoring helper argument at ${path} must be <= ${descriptor.maximum}, received ${value}`,\n );\n }\n}\n\nexport function validateAuthoringHelperArguments(\n helperPath: string,\n descriptors: readonly AuthoringArgumentDescriptor[] | undefined,\n args: readonly unknown[],\n): void {\n const expected = descriptors ?? [];\n const minimumArgs = expected.reduce(\n (count, descriptor, index) => (descriptor.optional ? count : index + 1),\n 0,\n );\n if (args.length < minimumArgs || args.length > expected.length) {\n throw new Error(\n `${helperPath} expects ${minimumArgs === expected.length ? expected.length : `${minimumArgs}-${expected.length}`} argument(s), received ${args.length}`,\n );\n }\n\n expected.forEach((descriptor, index) => {\n validateAuthoringArgument(descriptor, args[index], `${helperPath}[${index}]`);\n });\n}\n\nfunction resolveAuthoringStorageTypeTemplate(\n template: AuthoringStorageTypeTemplate,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n const nativeType = resolveAuthoringTemplateValue(template.nativeType, args);\n if (typeof nativeType !== 'string') {\n throw new Error(\n `Resolved authoring nativeType must be a string for codec \"${template.codecId}\", received ${String(nativeType)}`,\n );\n }\n const typeParams =\n template.typeParams === undefined\n ? undefined\n : resolveAuthoringTemplateValue(template.typeParams, args);\n if (typeParams !== undefined && !isAuthoringTemplateRecord(typeParams)) {\n throw new Error(\n `Resolved authoring typeParams must be an object for codec \"${template.codecId}\", received ${String(typeParams)}`,\n );\n }\n\n return {\n codecId: template.codecId,\n nativeType,\n ...(typeParams === undefined ? {} : { typeParams }),\n };\n}\n\nfunction resolveAuthoringColumnDefaultTemplate(\n template: AuthoringColumnDefaultTemplate,\n args: readonly unknown[],\n): ColumnDefault {\n if (template.kind === 'literal') {\n const value = resolveAuthoringTemplateValue(template.value, args);\n if (value === undefined) {\n throw new Error('Resolved authoring literal default must not be undefined');\n }\n if (!isColumnDefaultLiteralInputValue(value)) {\n throw new Error(\n `Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`,\n );\n }\n return {\n kind: 'literal',\n value,\n };\n }\n\n const expression = resolveAuthoringTemplateValue(template.expression, args);\n if (expression === undefined || (typeof expression === 'object' && expression !== null)) {\n throw new Error(\n `Resolved authoring function default expression must resolve to a primitive, received ${String(expression)}`,\n );\n }\n return {\n kind: 'function',\n expression: String(expression),\n };\n}\n\nfunction resolveExecutionMutationDefaultPhase(\n phase: 'onCreate' | 'onUpdate',\n template: AuthoringTemplateValue,\n args: readonly unknown[],\n): ExecutionMutationDefaultValue {\n const value = resolveAuthoringTemplateValue(template, args);\n if (!isExecutionMutationDefaultValue(value)) {\n throw new Error(\n `Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`,\n );\n }\n return value;\n}\n\nfunction resolveAuthoringExecutionDefaultsTemplate(\n template: AuthoringExecutionDefaultsTemplate,\n args: readonly unknown[],\n): ExecutionMutationDefaultPhases {\n return {\n ...ifDefined(\n 'onCreate',\n template.onCreate !== undefined\n ? resolveExecutionMutationDefaultPhase('onCreate', template.onCreate, args)\n : undefined,\n ),\n ...ifDefined(\n 'onUpdate',\n template.onUpdate !== undefined\n ? resolveExecutionMutationDefaultPhase('onUpdate', template.onUpdate, args)\n : undefined,\n ),\n };\n}\n\nexport function instantiateAuthoringTypeConstructor(\n descriptor: AuthoringTypeConstructorDescriptor,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n return resolveAuthoringStorageTypeTemplate(descriptor.output, args);\n}\n\nexport function instantiateAuthoringEntityType(\n helperPath: string,\n descriptor: AuthoringEntityTypeDescriptor,\n args: readonly unknown[],\n ctx: AuthoringEntityContext,\n): unknown {\n // Factory-output entities carry their input contract on the factory\n // signature itself — TypeScript narrows callers via\n // `EntityHelperFunction`'s extracted `input` parameter, and the factory\n // is free to do its own runtime validation (e.g. arktype Type). The\n // descriptor-level `args` validator is reserved for template-output\n // entities (which mirror field/type's declarative argument shape).\n if ('factory' in descriptor.output) {\n const input = args[0];\n // The base `AuthoringEntityTypeDescriptor`'s factory is typed\n // `(input: never, ctx) => unknown` so concrete pack-literal factories\n // with narrower input types remain assignable through the\n // contravariant position (see the type's docstring). The runtime\n // delegates input validation to the pack's factory itself, so we\n // forward the supplied input here without a static input contract.\n const factory = descriptor.output.factory as (\n input: unknown,\n ctx: AuthoringEntityContext,\n ) => unknown;\n return factory(input, ctx);\n }\n validateAuthoringHelperArguments(helperPath, descriptor.args, args);\n return resolveAuthoringTemplateValue(descriptor.output.template, args);\n}\n\nexport function instantiateAuthoringFieldPreset(\n descriptor: AuthoringFieldPresetDescriptor,\n args: readonly unknown[],\n): {\n readonly descriptor: {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n };\n readonly nullable: boolean;\n readonly default?: ColumnDefault;\n readonly executionDefaults?: ExecutionMutationDefaultPhases;\n readonly id: boolean;\n readonly unique: boolean;\n} {\n return {\n descriptor: resolveAuthoringStorageTypeTemplate(descriptor.output, args),\n nullable: descriptor.output.nullable ?? false,\n ...ifDefined(\n 'default',\n descriptor.output.default !== undefined\n ? resolveAuthoringColumnDefaultTemplate(descriptor.output.default, args)\n : undefined,\n ),\n ...ifDefined(\n 'executionDefaults',\n descriptor.output.executionDefaults !== undefined\n ? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args)\n : undefined,\n ),\n id: descriptor.output.id ?? false,\n unique: descriptor.output.unique ?? false,\n };\n}\n"],"mappings":";;;;AAyPA,SAAgB,kBAAkB,OAA0C;CAC1E,IAAI,OAAO,UAAU,YAAY,UAAU,QAAS,MAA6B,SAAS,OACxF,OAAO;CAET,MAAM,EAAE,OAAO,SAAS;CACxB,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,GACnE,OAAO;CAET,IAAI,SAAS,KAAA,MAAc,CAAC,MAAM,QAAQ,IAAI,KAAK,KAAK,MAAM,MAAM,OAAO,MAAM,QAAQ,IACvF,OAAO;CAET,OAAO;AACT;AAEA,SAAS,0BAA0B,OAAkD;CACnF,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAgB,qCACd,OAC6C;CAC7C,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,qBACvC,OAAQ,MAA+B,WAAW,YACjD,MAA+B,WAAW;AAE/C;AAEA,SAAgB,iCACd,OACyC;CACzC,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,iBACvC,OAAQ,MAA+B,WAAW,YACjD,MAA+B,WAAW;AAE/C;AAEA,SAAgB,gCACd,OACwC;CACxC,IACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,UAEvC,OAAO;CAET,MAAM,gBAAiB,MAAsC;CAC7D,IAAI,OAAO,kBAAkB,YAAY,cAAc,WAAW,GAChE,OAAO;CAET,MAAM,SAAU,MAA+B;CAC/C,IAAI,OAAO,WAAW,YAAY,WAAW,MAC3C,OAAO;CAET,MAAM,UAAW,OAAiC;CAClD,MAAM,WAAY,OAAkC;CACpD,OAAO,OAAO,YAAY,cAAc,aAAa,KAAA;AACvD;AAEA,SAAgB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A,IAC1B,sCAAsC,WAAW,OAAO,SAAS,IAAI,IACrE,KAAA,CACN;EACA,GAAG,UACD,qBACA,WAAW,OAAO,sBAAsB,KAAA,IACpC,0CAA0C,WAAW,OAAO,mBAAmB,IAAI,IACnF,KAAA,CACN;EACA,IAAI,WAAW,OAAO,MAAM;EAC5B,QAAQ,WAAW,OAAO,UAAU;CACtC;AACF"}
import { f as AnyCodecDescriptor } from "./codec-types-yY3eSmi0.mjs";
import { i as AuthoringContributions } from "./framework-authoring-CJC4jwGo.mjs";
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { ColumnDefault, ExecutionMutationDefaultPhases, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
//#region src/shared/mutation-default-types.d.ts
interface SourcePosition {
readonly offset: number;
readonly line: number;
readonly column: number;
}
interface SourceSpan {
readonly start: SourcePosition;
readonly end: SourcePosition;
}
interface SourceDiagnostic {
readonly code: string;
readonly message: string;
readonly sourceId?: string;
readonly span?: SourceSpan;
readonly data?: Readonly<Record<string, unknown>>;
}
interface DefaultFunctionArgument {
readonly raw: string;
readonly span: SourceSpan;
}
interface ParsedDefaultFunctionCall {
readonly name: string;
readonly raw: string;
readonly args: readonly DefaultFunctionArgument[];
readonly span: SourceSpan;
}
interface DefaultFunctionLoweringContext {
readonly sourceId: string;
readonly modelName: string;
readonly fieldName: string;
readonly columnCodecId?: string;
}
type LoweredDefaultValue = {
readonly kind: 'storage';
readonly defaultValue: ColumnDefault;
} | {
readonly kind: 'execution';
readonly generated: ExecutionMutationDefaultValue;
};
type LoweredDefaultResult = {
readonly ok: true;
readonly value: LoweredDefaultValue;
} | {
readonly ok: false;
readonly diagnostic: SourceDiagnostic;
};
type DefaultFunctionLoweringHandler = (input: {
readonly call: ParsedDefaultFunctionCall;
readonly context: DefaultFunctionLoweringContext;
}) => LoweredDefaultResult;
interface DefaultFunctionRegistryEntry {
readonly lower: DefaultFunctionLoweringHandler;
readonly usageSignatures?: readonly string[];
}
type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistryEntry>;
interface MutationDefaultGeneratorDescriptor {
readonly id: string;
/**
* Codec ids the generator is compatible with when the codec choice
* and the generator choice are made independently by the contract
* author. Set when the registry-coherence check is meaningful
* (the codec and the generator can be paired arbitrarily by the
* caller); omitted when the generator is only reachable through a
* descriptor that co-registers a fixed codec, so coherence is
* structural and the list would be tautological.
*/
readonly applicableCodecIds?: readonly string[];
readonly resolveGeneratedColumnDescriptor?: (input: {
readonly generated: ExecutionMutationDefaultValue;
}) => {
readonly codecId: string;
readonly nativeType: string;
readonly typeRef?: string;
readonly typeParams?: Record<string, unknown>;
} | undefined;
/**
* Construct the `onCreate`/`onUpdate` phases value owned by this
* generator. Authoring layers (PSL `temporal.updatedAt()`, TS field presets) call
* this instead of building the literal inline so PSL/TS-authored
* contracts stay byte-equivalent for any future params-bearing generator.
*/
readonly buildPhases?: (args?: Record<string, unknown>) => ExecutionMutationDefaultPhases;
}
interface ControlMutationDefaultEntry {
readonly lower: (input: {
readonly call: ParsedDefaultFunctionCall;
readonly context: DefaultFunctionLoweringContext;
}) => LoweredDefaultResult;
readonly usageSignatures?: readonly string[];
}
type ControlMutationDefaultRegistry = ReadonlyMap<string, ControlMutationDefaultEntry>;
interface ControlMutationDefaults {
readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
readonly generatorDescriptors: readonly MutationDefaultGeneratorDescriptor[];
}
//#endregion
//#region src/shared/framework-components.d.ts
/**
* Declarative fields that describe component metadata.
*/
interface ComponentMetadata {
/** Component version (semver) */
readonly version: string;
/**
* Capabilities this component provides.
*
* For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`); keep these declarations in sync. Targets are identifiers/descriptors and typically do not declare capabilities.
*/
readonly capabilities?: Record<string, unknown>;
/** Type imports for contract.d.ts generation */
readonly types?: {
readonly codecTypes?: {
/**
* Base codec types import spec. Optional: adapters typically provide this, extensions usually don't.
*/
readonly import?: TypesImportSpec;
/**
* Additional type-only imports for parameterized codec branded types.
*
* These imports are included in generated `contract.d.ts` but are NOT treated as codec type maps (i.e., they should not be intersected into `export type CodecTypes = ...`).
*
* Example: `Vector<N>` for pgvector codecs that emit `Vector<1536>`
*/
readonly typeImports?: ReadonlyArray<TypesImportSpec>;
/**
* Optional control-plane hooks keyed by codecId. Used by family-specific planners/verifiers to handle storage types.
*/
readonly controlPlaneHooks?: Record<string, unknown>;
/**
* Codec descriptors contributed by this component. Source of truth for codec-id-keyed metadata (`traits`, `targetTypes`, `meta`, `renderOutputType`) consumed by `extractCodecLookup`, and used to materialize representative `Codec` instances for codec-dispatched type rendering during emission.
*/
readonly codecDescriptors?: ReadonlyArray<AnyCodecDescriptor>;
};
readonly queryOperationTypes?: {
readonly import: TypesImportSpec;
};
readonly storage?: ReadonlyArray<{
readonly typeId: string;
readonly familyId: string;
readonly targetId: string;
readonly nativeType?: string;
}>;
};
/**
* Optional pure-data authoring contributions exposed by this component.
*
* These contributions are safe to include on pack refs and descriptors because they contain only declarative metadata. Higher-level authoring packages may project them into concrete helper functions for TS-first workflows.
*/
readonly authoring?: AuthoringContributions;
/**
* Scalar type name to codec ID mapping contributed by this component. Assembled by `createControlStack` with duplicate detection.
*/
readonly scalarTypeDescriptors?: ReadonlyMap<string, string>;
/**
* Mutation default function handlers and generator descriptors contributed by this component. Assembled by `createControlStack` with duplicate detection.
*/
readonly controlMutationDefaults?: ControlMutationDefaults;
}
/**
* Base descriptor for any framework component.
*
* All component descriptors share these fundamental properties that identify the component and provide its metadata. This interface is extended by specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
*
* @template Kind - Discriminator literal identifying the component type. Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension', but the type accepts any string to allow ecosystem extensions.
*
* @example
* ```ts
* // All descriptors have these properties
* descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)
* descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')
* descriptor.version // Component version (semver)
* ```
*/
interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {
/** Discriminator identifying the component type */
readonly kind: Kind;
/** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */
readonly id: string;
}
interface ContractComponentRequirementsCheckInput {
readonly contract: {
readonly target: string;
readonly targetFamily?: string | undefined;
readonly extensionPacks?: Record<string, unknown> | undefined;
};
readonly expectedTargetFamily?: string | undefined;
readonly expectedTargetId?: string | undefined;
readonly providedComponentIds: Iterable<string>;
}
interface ContractComponentRequirementsCheckResult {
readonly familyMismatch?: {
readonly expected: string;
readonly actual: string;
} | undefined;
readonly targetMismatch?: {
readonly expected: string;
readonly actual: string;
} | undefined;
readonly missingExtensionPackIds: readonly string[];
}
declare function checkContractComponentRequirements(input: ContractComponentRequirementsCheckInput): ContractComponentRequirementsCheckResult;
/**
* Descriptor for a family component.
*
* A "family" represents a category of data sources with shared semantics (e.g., SQL databases, document stores). Families define:
* - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
* - Contract structure (tables vs collections, columns vs fields)
* - Type system and codecs
*
* Families are the top-level grouping. Each family contains multiple targets (e.g., SQL family contains Postgres, MySQL, SQLite targets).
*
* Extended by plane-specific descriptors:
* - `ControlFamilyDescriptor` - adds `emission` for CLI/tooling operations
* - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods
*
* @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
*
* @example
* ```ts
* import sql from '@prisma-next/family-sql/control';
*
* sql.kind // 'family'
* sql.familyId // 'sql'
* sql.id // 'sql'
* ```
*/
interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {
/** The family identifier (e.g., 'sql', 'document') */
readonly familyId: TFamilyId;
}
/**
* Descriptor for a target component.
*
* A "target" represents a specific database or data store within a family (e.g., Postgres, MySQL, MongoDB). Targets define:
* - Native type mappings (e.g., Postgres int4 → TypeScript number)
* - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
*
* Targets are bound to a family and provide the target-specific implementation details that adapters and drivers use.
*
* Extended by plane-specific descriptors:
* - `ControlTargetDescriptor` - adds optional `migrations` capability
* - `RuntimeTargetDescriptor` - adds runtime factory method
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
*
* @example
* ```ts
* import postgres from '@prisma-next/target-postgres/control';
*
* postgres.kind // 'target'
* postgres.familyId // 'sql'
* postgres.targetId // 'postgres'
* ```
*/
interface TargetDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'target'> {
/** The family this target belongs to */
readonly familyId: TFamilyId;
/** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
readonly targetId: TTargetId;
}
/**
* Base shape for any pack reference. Pack refs are pure JSON-friendly objects safe to import in authoring flows.
*/
interface PackRefBase<Kind extends string, TFamilyId extends string> extends ComponentMetadata {
readonly kind: Kind;
readonly id: string;
readonly familyId: TFamilyId;
readonly targetId?: string;
readonly authoring?: AuthoringContributions;
}
type FamilyPackRef<TFamilyId extends string = string> = PackRefBase<'family', TFamilyId>;
type TargetPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'target', TFamilyId> & {
readonly targetId: TTargetId; /** The namespace a bare (un-namespaced) entity name resolves to for this target (e.g. Postgres `'public'`). */
readonly defaultNamespaceId: string;
};
type AdapterPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'adapter', TFamilyId> & {
readonly targetId: TTargetId;
};
type ExtensionPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'extension', TFamilyId> & {
readonly targetId: TTargetId;
};
type DriverPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'driver', TFamilyId> & {
readonly targetId: TTargetId;
};
/**
* Descriptor for an adapter component.
*
* An "adapter" provides the protocol and dialect implementation for a target. Adapters handle:
* - SQL/query generation (lowering AST to target-specific syntax)
* - Codec registration (encoding/decoding between JS and wire types)
* - Type mappings and coercions
*
* Adapters are bound to a specific family+target combination and work with any compatible driver for that target.
*
* Extended by plane-specific descriptors:
* - `ControlAdapterDescriptor` - control-plane factory
* - `RuntimeAdapterDescriptor` - runtime factory
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import postgresAdapter from '@prisma-next/adapter-postgres/control';
*
* postgresAdapter.kind // 'adapter'
* postgresAdapter.familyId // 'sql'
* postgresAdapter.targetId // 'postgres'
* ```
*/
interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'adapter'> {
/** The family this adapter belongs to */
readonly familyId: TFamilyId;
/** The target this adapter is designed for */
readonly targetId: TTargetId;
}
/**
* Descriptor for a driver component.
*
* A "driver" provides the connection and execution layer for a target. Drivers handle:
* - Connection management (pooling, timeouts, retries)
* - Query execution (sending SQL/commands, receiving results)
* - Transaction management
* - Wire protocol communication
*
* Drivers are bound to a specific family+target and work with any compatible adapter. Multiple drivers can exist for the same target (e.g., node-postgres vs postgres.js for Postgres).
*
* Extended by plane-specific descriptors:
* - `ControlDriverDescriptor` - creates driver from connection URL
* - `RuntimeDriverDescriptor` - creates driver with runtime options
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import postgresDriver from '@prisma-next/driver-postgres/control';
*
* postgresDriver.kind // 'driver'
* postgresDriver.familyId // 'sql'
* postgresDriver.targetId // 'postgres'
* ```
*/
interface DriverDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'driver'> {
/** The family this driver belongs to */
readonly familyId: TFamilyId;
/** The target this driver connects to */
readonly targetId: TTargetId;
}
/**
* Descriptor for an extension component.
*
* An "extension" adds optional capabilities to a target. Extensions can provide:
* - Additional operations (e.g., vector similarity search with pgvector)
* - Custom types and codecs (e.g., vector type)
* - Extended query capabilities
*
* Extensions are bound to a specific family+target and are registered in the config alongside the core components. Multiple extensions can be used together.
*
* Extended by plane-specific descriptors:
* - `ControlExtensionDescriptor` - control-plane extension factory
* - `RuntimeExtensionDescriptor` - runtime extension factory
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import pgvector from '@prisma-next/extension-pgvector/control';
*
* pgvector.kind // 'extension'
* pgvector.familyId // 'sql'
* pgvector.targetId // 'postgres'
* ```
*/
interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'extension'> {
/** The family this extension belongs to */
readonly familyId: TFamilyId;
/** The target this extension is designed for */
readonly targetId: TTargetId;
}
/** Components bound to a specific family+target combination. */
type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> = TargetDescriptor<TFamilyId, TTargetId> | AdapterDescriptor<TFamilyId, TTargetId> | DriverDescriptor<TFamilyId, TTargetId> | ExtensionDescriptor<TFamilyId, TTargetId>;
interface FamilyInstance<TFamilyId extends string> {
readonly familyId: TFamilyId;
}
interface TargetInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface DriverInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
//#endregion
export { LoweredDefaultResult as A, ControlMutationDefaultEntry as C, DefaultFunctionLoweringHandler as D, DefaultFunctionLoweringContext as E, SourceSpan as F, MutationDefaultGeneratorDescriptor as M, ParsedDefaultFunctionCall as N, DefaultFunctionRegistry as O, SourceDiagnostic as P, checkContractComponentRequirements as S, ControlMutationDefaults as T, PackRefBase as _, ComponentMetadata as a, TargetInstance as b, DriverDescriptor as c, ExtensionDescriptor as d, ExtensionInstance as f, FamilyPackRef as g, FamilyInstance as h, ComponentDescriptor as i, LoweredDefaultValue as j, DefaultFunctionRegistryEntry as k, DriverInstance as l, FamilyDescriptor as m, AdapterInstance as n, ContractComponentRequirementsCheckInput as o, ExtensionPackRef as p, AdapterPackRef as r, ContractComponentRequirementsCheckResult as s, AdapterDescriptor as t, DriverPackRef as u, TargetBoundComponentDescriptor as v, ControlMutationDefaultRegistry as w, TargetPackRef as x, TargetDescriptor as y };
//# sourceMappingURL=framework-components-5hA9ij1v.d.mts.map
{"version":3,"file":"framework-components-5hA9ij1v.d.mts","names":[],"sources":["../src/shared/mutation-default-types.ts","../src/shared/framework-components.ts"],"mappings":";;;;;;UAMU,cAAA;EAAA,SACC,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,UAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,GAAA,EAAK,cAAc;AAAA;AAAA,UAGb,gBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA,GAAO,UAAA;EAAA,SACP,IAAA,GAAO,QAAA,CAAS,MAAA;AAAA;AAAA,UAGjB,uBAAA;EAAA,SACC,GAAA;EAAA,SACA,IAAA,EAAM,UAAU;AAAA;AAAA,UAGV,yBAAA;EAAA,SACN,IAAA;EAAA,SACA,GAAA;EAAA,SACA,IAAA,WAAe,uBAAA;EAAA,SACf,IAAA,EAAM,UAAU;AAAA;AAAA,UAGV,8BAAA;EAAA,SACN,QAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA;EAAA,SACA,aAAA;AAAA;AAAA,KAGC,mBAAA;EAAA,SACG,IAAA;EAAA,SAA0B,YAAA,EAAc,aAAA;AAAA;EAAA,SACxC,IAAA;EAAA,SAA4B,SAAA,EAAW,6BAA6B;AAAA;AAAA,KAEvE,oBAAA;EAAA,SACG,EAAA;EAAA,SAAmB,KAAA,EAAO,mBAAA;AAAA;EAAA,SAC1B,EAAA;EAAA,SAAoB,UAAA,EAAY,gBAAgB;AAAA;AAAA,KAEnD,8BAAA,IAAkC,KAAA;EAAA,SACnC,IAAA,EAA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QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,cAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,iBAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA"}
import { r as CodecLookup } from "./codec-types-yY3eSmi0.mjs";
import { R as PslDiagnosticCode, Y as PslSpan, h as AuthoringPslBlockDescriptorNamespace, z as PslExtensionBlock } from "./framework-authoring-CJC4jwGo.mjs";
//#region src/control/psl-ast.d.ts
interface PslDiagnostic {
readonly code: PslDiagnosticCode;
readonly message: string;
readonly sourceId: string;
readonly span: PslSpan;
}
interface PslDefaultFunctionValue {
readonly kind: 'function';
readonly name: 'autoincrement' | 'now';
}
interface PslDefaultLiteralValue {
readonly kind: 'literal';
readonly value: string | number | boolean;
}
type PslDefaultValue = PslDefaultFunctionValue | PslDefaultLiteralValue;
type PslAttributeTarget = 'field' | 'model' | 'enum' | 'namedType';
interface PslAttributePositionalArgument {
readonly kind: 'positional';
readonly value: string;
readonly span: PslSpan;
}
interface PslAttributeNamedArgument {
readonly kind: 'named';
readonly name: string;
readonly value: string;
readonly span: PslSpan;
}
type PslAttributeArgument = PslAttributePositionalArgument | PslAttributeNamedArgument;
interface PslTypeConstructorCall {
readonly kind: 'typeConstructor';
readonly path: readonly string[];
readonly args: readonly PslAttributeArgument[];
readonly span: PslSpan;
}
interface PslAttribute {
readonly kind: 'attribute';
readonly target: PslAttributeTarget;
readonly name: string;
readonly args: readonly PslAttributeArgument[];
readonly span: PslSpan;
}
type PslReferentialAction = string;
type PslFieldAttribute = PslAttribute;
interface PslField {
readonly kind: 'field';
readonly name: string;
/** Unqualified type name, e.g. `"User"` for both `User`, `auth.User`, and `supabase:auth.User`. */
readonly typeName: string;
/** Namespace qualifier from a dot-qualified type reference, e.g. `"auth"` for `auth.User` or `supabase:auth.User`. Absent for unqualified types. */
readonly typeNamespaceId?: string;
/**
* Contract-space qualifier from a colon-prefix type reference, e.g. `"supabase"` for
* `supabase:auth.User` or `supabase:User`. Absent for local (same-space) type references.
*
* When present, the field references a model from a different contract space. The namespace
* (`typeNamespaceId`) and model name (`typeName`) identify the target within that space.
* Physical table resolution against the extension contract is deferred to the aggregate stage (M3).
*/
readonly typeContractSpaceId?: string;
readonly typeConstructor?: PslTypeConstructorCall;
readonly optional: boolean;
readonly list: boolean;
readonly typeRef?: string;
readonly attributes: readonly PslFieldAttribute[];
readonly span: PslSpan;
}
interface PslUniqueConstraint {
readonly kind: 'unique';
readonly fields: readonly string[];
readonly span: PslSpan;
}
interface PslIndexConstraint {
readonly kind: 'index';
readonly fields: readonly string[];
readonly span: PslSpan;
}
type PslModelAttribute = PslAttribute;
interface PslModel {
readonly kind: 'model';
readonly name: string;
readonly fields: readonly PslField[];
readonly attributes: readonly PslModelAttribute[];
readonly span: PslSpan;
/**
* Optional leading comment line emitted above the `model` keyword by the
* printer. Producers (e.g. `sqlSchemaIrToPslAst`) attach introspection
* advisories such as "// WARNING: This table has no primary key in the
* database" here. The parser leaves this field unset; round-tripping a
* parsed schema does not re-attach comments.
*/
readonly comment?: string;
}
/**
* A reusable group of fields embedded in a model (a `type Name { … }` block) —
* e.g. a MongoDB embedded document or a Postgres composite type. Unlike
* {@link PslModel} it has no storage or identity of its own.
*/
interface PslCompositeType {
readonly kind: 'compositeType';
readonly name: string;
readonly fields: readonly PslField[];
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
interface PslNamedTypeDeclaration {
readonly kind: 'namedType';
readonly name: string;
/**
* Parser invariant: exactly one of `baseType` and `typeConstructor` is set.
* Expressing this as a discriminated union trips TypeScript narrowing when
* the declaration flows through helpers that accept the full union.
*/
readonly baseType?: string;
readonly typeConstructor?: PslTypeConstructorCall;
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
interface PslTypesBlock {
readonly kind: 'types';
readonly declarations: readonly PslNamedTypeDeclaration[];
readonly span: PslSpan;
}
/**
* Name of the synthesised namespace bucket the framework parser uses for
* top-level declarations that appear outside any `namespace { … }` block.
* The double-underscore decoration signals that the identifier is parser-
* synthesised and never appears in user-authored PSL source — writing
* `namespace __unspecified__ { … }` is a parse error.
*
* Distinct from the IR sentinel `__unbound__`: the PSL bucket describes
* syntactic absence at the parser layer; the IR sentinel describes a late-
* bound storage slot at the IR layer. Per-target interpreters decide how
* (or whether) to map the PSL bucket to the IR sentinel.
*/
declare const UNSPECIFIED_PSL_NAMESPACE_ID = "__unspecified__";
/** A value in {@link PslNamespace.entries}: a built-in entity node or an extension-contributed {@link PslExtensionBlock}. */
type PslNamespaceEntry = PslModel | PslCompositeType | PslExtensionBlock;
/**
* A namespace block, or the parser's synthesised `__unspecified__` bucket for
* declarations outside any `namespace { … }`. Same-name blocks reopen-merge;
* `span` points at the first opening.
*
* Entities are stored canonically (ADR 224) in `entries[kind][name]`, where
* `kind` is the PSL keyword for built-ins or the block discriminator for
* extension kinds, e.g. `entries['policy_select']['ReadPosts']`.
*/
interface PslNamespace {
readonly kind: 'namespace';
readonly name: string;
/** Canonical store: a frozen container of frozen per-kind maps. The accessors below derive from it. */
readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
/** Built-in models, from `entries['model']`. Extension kinds: {@link namespacePslExtensionBlocks}. */
readonly models: readonly PslModel[];
/** Built-in composite types, from `entries['compositeType']`. */
readonly compositeTypes: readonly PslCompositeType[];
readonly span: PslSpan;
}
/** Constructs a {@link PslNamespace}. Use this, never a namespace literal — the accessors must derive from `entries`. */
declare function makePslNamespace(init: {
readonly kind: 'namespace';
readonly name: string;
readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
readonly span: PslSpan;
}): PslNamespace;
/**
* Builds the frozen `entries[kind][name]` container from per-kind arrays.
* Built-ins key on their PSL keyword; extension blocks key on their `kind`
* discriminator. Call this rather than hand-building the literal.
*/
declare function makePslNamespaceEntries(models: readonly PslModel[], compositeTypes: readonly PslCompositeType[], extensionBlocks: readonly PslExtensionBlock[]): Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
interface PslDocumentAst {
readonly kind: 'document';
readonly sourceId: string;
readonly namespaces: readonly PslNamespace[];
readonly types?: PslTypesBlock;
readonly span: PslSpan;
}
/**
* Returns all models from every namespace in document order. Convenience
* for consumers that don't (yet) need namespace-awareness.
*/
declare function flatPslModels(ast: PslDocumentAst): readonly PslModel[];
/**
* Returns all composite types from every namespace in document order.
*/
declare function flatPslCompositeTypes(ast: PslDocumentAst): readonly PslCompositeType[];
/**
* The set of `entries` kind keys that the framework parser reserves for
* built-in PSL entity kinds. Any own-enumerable key on `PslNamespace.entries`
* that is **not** in this set was contributed by an extension-block descriptor.
*
* Built-in keys match the PSL keyword used on each block type:
* `'model'`, `'compositeType'`. The `'enum'` keyword is claimed by the
* extension-block grammar via a registered descriptor, so `entries['enum']`
* holds `PslExtensionBlock` nodes and is returned by `namespacePslExtensionBlocks`.
*/
declare const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string>;
/**
* Returns all extension-contributed blocks in the given namespace, in
* insertion order (the order the parser encountered them in the source).
*
* Reads from `namespace.entries`, skipping the built-in kind keys
* (`'model'`, `'compositeType'`). All remaining kind maps contain
* only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).
*/
declare function namespacePslExtensionBlocks(ns: PslNamespace): readonly PslExtensionBlock[];
interface ParsePslDocumentInput {
readonly schema: string;
readonly sourceId: string;
/**
* Registry of declarative block descriptors, keyed by arbitrary path
* segments with {@link AuthoringPslBlockDescriptor} leaves. The registry
* teaches the parser which top-level keywords belong to extension
* contributions: when the parser encounters an unknown keyword, it looks
* it up here and, when found, reads the block generically into a
* {@link PslExtensionBlock} node. Absent or undefined means no extension
* blocks are registered and any unknown keyword yields
* `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`.
*
* Contrast with the parsed block nodes themselves, which live in
* {@link PslNamespace.entries} under their discriminator key (read them with
* {@link namespacePslExtensionBlocks}); this field holds the registry of
* descriptors that teach the parser how to read those blocks.
*/
readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;
/**
* Codec lookup for validating `value`-kind extension block parameters.
* When provided alongside `pslBlockDescriptors`, the generic validator runs
* over every parsed extension block after the full AST is assembled,
* appending any diagnostics to the parse result. Absent or undefined means
* no codec validation runs; `ref` resolution still runs when namespace
* context is available (built from the assembled namespaces).
*/
readonly codecLookup?: CodecLookup;
}
interface ParsePslDocumentResult {
readonly ast: PslDocumentAst;
readonly diagnostics: readonly PslDiagnostic[];
readonly ok: boolean;
}
//#endregion
export { makePslNamespace as A, PslReferentialAction as C, UNSPECIFIED_PSL_NAMESPACE_ID as D, PslUniqueConstraint as E, namespacePslExtensionBlocks as M, flatPslCompositeTypes as O, PslNamespaceEntry as S, PslTypesBlock as T, PslIndexConstraint as _, PslAttributeArgument as a, PslNamedTypeDeclaration as b, PslAttributeTarget as c, PslDefaultLiteralValue as d, PslDefaultValue as f, PslFieldAttribute as g, PslField as h, PslAttribute as i, makePslNamespaceEntries as j, flatPslModels as k, PslCompositeType as l, PslDocumentAst as m, ParsePslDocumentInput as n, PslAttributeNamedArgument as o, PslDiagnostic as p, ParsePslDocumentResult as r, PslAttributePositionalArgument as s, BUILTIN_PSL_KIND_KEYS as t, PslDefaultFunctionValue as u, PslModel as v, PslTypeConstructorCall as w, PslNamespace as x, PslModelAttribute as y };
//# sourceMappingURL=psl-ast-B-C_9dWr.d.mts.map
{"version":3,"file":"psl-ast-B-C_9dWr.d.mts","names":[],"sources":["../src/control/psl-ast.ts"],"mappings":";;;;UA0BiB,aAAA;EAAA,SACN,IAAA,EAAM,iBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,uBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,UAGE,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAK;AAAA;AAAA,KAGJ,eAAA,GAAkB,uBAA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A,KACzB,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA,SAAe,iBAAA;AAAA,UAiClC,cAAA;EAAA,SACN,IAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA,WAAqB,YAAA;EAAA,SACrB,KAAA,GAAQ,aAAA;EAAA,SACR,IAAA,EAAM,OAAA;AAAA;;;;;iBAOD,aAAA,CAAc,GAAA,EAAK,cAAA,YAA0B,QAAQ;AAjK7C;AAGxB;;AAHwB,iBA4KR,qBAAA,CAAsB,GAAA,EAAK,cAAA,YAA0B,gBAAgB;;;;;;;;;;;cAmBxE,qBAAA,EAAuB,WAAW;;;;;AAjLvB;AAGxB;;;iBAwLgB,2BAAA,CAA4B,EAAA,EAAI,YAAA,YAAwB,iBAAiB;AAAA,UAgBxE,qBAAA;EAAA,SACN,MAAA;EAAA,SACA,QAAA;EAvMA;;;AAAa;AAexB;;;;AAAyC;AAGzC;;;;;;EAlBW,SAuNA,mBAAA,GAAsB,oCAAA;EArM8C;;;;;AAAA;AAW/E;;EAX+E,SA8MpE,WAAA,GAAc,WAAW;AAAA;AAAA,UAGnB,sBAAA;EAAA,SACN,GAAA,EAAK,cAAA;EAAA,SACL,WAAA,WAAsB,aAAa;EAAA,SACnC,EAAA;AAAA"}
import { n as runtimeError } from "./runtime-error-B2gWOtgH.mjs";
import { blindCast } from "@prisma-next/utils/casts";
//#region src/shared/resolve-codec.ts
const CONTRACT_CODEC_DESCRIPTOR_MISSING = "CONTRACT.CODEC_DESCRIPTOR_MISSING";
/**
* Look up a descriptor for `ref.codecId` using `descriptorFor`; throw
* `code` if none is found. Each plane names its own error path: the control
* plane resolves contract-stack descriptors (`CONTRACT.*`), the execution
* plane resolves at query time (`RUNTIME.*`).
*/
function resolveCodecDescriptorOrThrow(descriptorFor, ref, code) {
const descriptor = descriptorFor(ref.codecId);
if (!descriptor) throw runtimeError(code, `No codec descriptor registered for codecId '${ref.codecId}'.`, { codecId: ref.codecId });
return descriptor;
}
/**
* Validates `ref.typeParams` against `descriptor.paramsSchema`.
*
* Parameterized codecs that omit `typeParams` have it normalized to `{}` before
* validation (mirrors `ast-codec-resolver.ts` semantics). Throws
* `RUNTIME.TYPE_PARAMS_INVALID` when the validator returns a `Promise` or
* reports issues.
*/
function validateCodecTypeParams(descriptor, ref) {
const normalized = descriptor.isParameterized && ref.typeParams === void 0 ? {
...ref,
typeParams: {}
} : ref;
const result = blindCast(descriptor.paramsSchema["~standard"].validate(normalized.typeParams));
if (result instanceof Promise) throw runtimeError("RUNTIME.TYPE_PARAMS_INVALID", `paramsSchema for codec '${ref.codecId}' returned a Promise; runtime validation requires a synchronous Standard Schema validator.`, {
codecId: ref.codecId,
typeParams: ref.typeParams
});
if ("issues" in result && result.issues) {
const messages = result.issues.map((issue) => issue.message).join("; ");
throw runtimeError("RUNTIME.TYPE_PARAMS_INVALID", `Invalid typeParams for codec '${ref.codecId}': ${messages}`, {
codecId: ref.codecId,
typeParams: ref.typeParams
});
}
return blindCast(result).value;
}
/**
* Resolves a `Codec` instance: validates `ref.typeParams` via
* {@link validateCodecTypeParams} then calls `descriptor.factory(validated)(ctx)`.
*
* The descriptor's `factory` is typed against its own `P`; the registry erases
* `P` to `any`, so the factory is narrowed to `(params: unknown) => (ctx) => Codec`
* at the call boundary. The `paramsSchema` validates the input above before we
* forward it, so the narrowing is safe by construction.
*/
function materializeCodec(descriptor, ref, ctx) {
const validated = validateCodecTypeParams(descriptor, ref);
return blindCast(descriptor.factory)(validated)(ctx);
}
//#endregion
export { validateCodecTypeParams as i, materializeCodec as n, resolveCodecDescriptorOrThrow as r, CONTRACT_CODEC_DESCRIPTOR_MISSING as t };
//# sourceMappingURL=resolve-codec-D8EPZosv.mjs.map
{"version":3,"file":"resolve-codec-D8EPZosv.mjs","names":[],"sources":["../src/shared/resolve-codec.ts"],"sourcesContent":["import { blindCast } from '@prisma-next/utils/casts';\nimport type { Codec } from './codec';\nimport type { AnyCodecDescriptor } from './codec-descriptor';\nimport type { CodecInstanceContext, CodecRef } from './codec-types';\nimport { runtimeError } from './runtime-error';\n\nexport const CONTRACT_CODEC_DESCRIPTOR_MISSING = 'CONTRACT.CODEC_DESCRIPTOR_MISSING' as const;\n\n/**\n * Look up a descriptor for `ref.codecId` using `descriptorFor`; throw\n * `code` if none is found. Each plane names its own error path: the control\n * plane resolves contract-stack descriptors (`CONTRACT.*`), the execution\n * plane resolves at query time (`RUNTIME.*`).\n */\nexport function resolveCodecDescriptorOrThrow(\n descriptorFor: (codecId: string) => AnyCodecDescriptor | undefined,\n ref: CodecRef,\n code: 'CONTRACT.CODEC_DESCRIPTOR_MISSING' | 'RUNTIME.CODEC_DESCRIPTOR_MISSING',\n): AnyCodecDescriptor {\n const descriptor = descriptorFor(ref.codecId);\n if (!descriptor) {\n throw runtimeError(code, `No codec descriptor registered for codecId '${ref.codecId}'.`, {\n codecId: ref.codecId,\n });\n }\n return descriptor;\n}\n\n/**\n * Validates `ref.typeParams` against `descriptor.paramsSchema`.\n *\n * Parameterized codecs that omit `typeParams` have it normalized to `{}` before\n * validation (mirrors `ast-codec-resolver.ts` semantics). Throws\n * `RUNTIME.TYPE_PARAMS_INVALID` when the validator returns a `Promise` or\n * reports issues.\n */\nexport function validateCodecTypeParams(descriptor: AnyCodecDescriptor, ref: CodecRef): unknown {\n const normalized =\n descriptor.isParameterized && ref.typeParams === undefined ? { ...ref, typeParams: {} } : ref;\n\n const result = blindCast<\n { value: unknown } | { issues: ReadonlyArray<{ message: string }> } | Promise<unknown>,\n 'Standard Schema validate returns unknown; the spec guarantees this union shape'\n >(descriptor.paramsSchema['~standard'].validate(normalized.typeParams));\n\n if (result instanceof Promise) {\n throw runtimeError(\n 'RUNTIME.TYPE_PARAMS_INVALID',\n `paramsSchema for codec '${ref.codecId}' returned a Promise; runtime validation requires a synchronous Standard Schema validator.`,\n { codecId: ref.codecId, typeParams: ref.typeParams },\n );\n }\n\n if ('issues' in result && result.issues) {\n const messages = result.issues.map((issue) => issue.message).join('; ');\n throw runtimeError(\n 'RUNTIME.TYPE_PARAMS_INVALID',\n `Invalid typeParams for codec '${ref.codecId}': ${messages}`,\n { codecId: ref.codecId, typeParams: ref.typeParams },\n );\n }\n\n return blindCast<{ value: unknown }, 'issues guard above rules out the issues branch'>(result)\n .value;\n}\n\n/**\n * Resolves a `Codec` instance: validates `ref.typeParams` via\n * {@link validateCodecTypeParams} then calls `descriptor.factory(validated)(ctx)`.\n *\n * The descriptor's `factory` is typed against its own `P`; the registry erases\n * `P` to `any`, so the factory is narrowed to `(params: unknown) => (ctx) => Codec`\n * at the call boundary. The `paramsSchema` validates the input above before we\n * forward it, so the narrowing is safe by construction.\n */\nexport function materializeCodec(\n descriptor: AnyCodecDescriptor,\n ref: CodecRef,\n ctx: CodecInstanceContext,\n): Codec {\n const validated = validateCodecTypeParams(descriptor, ref);\n return blindCast<\n (params: unknown) => (ctx: CodecInstanceContext) => Codec,\n 'registry erases P to any; paramsSchema validates input before forwarding'\n >(descriptor.factory)(validated)(ctx);\n}\n"],"mappings":";;;AAMA,MAAa,oCAAoC;;;;;;;AAQjD,SAAgB,8BACd,eACA,KACA,MACoB;CACpB,MAAM,aAAa,cAAc,IAAI,OAAO;CAC5C,IAAI,CAAC,YACH,MAAM,aAAa,MAAM,+CAA+C,IAAI,QAAQ,KAAK,EACvF,SAAS,IAAI,QACf,CAAC;CAEH,OAAO;AACT;;;;;;;;;AAUA,SAAgB,wBAAwB,YAAgC,KAAwB;CAC9F,MAAM,aACJ,WAAW,mBAAmB,IAAI,eAAe,KAAA,IAAY;EAAE,GAAG;EAAK,YAAY,CAAC;CAAE,IAAI;CAE5F,MAAM,SAAS,UAGb,WAAW,aAAa,YAAY,CAAC,SAAS,WAAW,UAAU,CAAC;CAEtE,IAAI,kBAAkB,SACpB,MAAM,aACJ,+BACA,2BAA2B,IAAI,QAAQ,6FACvC;EAAE,SAAS,IAAI;EAAS,YAAY,IAAI;CAAW,CACrD;CAGF,IAAI,YAAY,UAAU,OAAO,QAAQ;EACvC,MAAM,WAAW,OAAO,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,KAAK,IAAI;EACtE,MAAM,aACJ,+BACA,iCAAiC,IAAI,QAAQ,KAAK,YAClD;GAAE,SAAS,IAAI;GAAS,YAAY,IAAI;EAAW,CACrD;CACF;CAEA,OAAO,UAAgF,MAAM,CAAC,CAC3F;AACL;;;;;;;;;;AAWA,SAAgB,iBACd,YACA,KACA,KACO;CACP,MAAM,YAAY,wBAAwB,YAAY,GAAG;CACzD,OAAO,UAGL,WAAW,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG;AACtC"}
//#region src/shared/runtime-error.ts
/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
function isRuntimeError(error) {
return error instanceof Error && "code" in error && typeof error.code === "string" && "category" in error && "severity" in error;
}
function runtimeError(code, message, details) {
const error = Object.assign(new Error(message), {
code,
category: resolveCategory(code),
severity: "error",
...details !== void 0 ? { details } : {}
});
Object.defineProperty(error, "name", {
value: "RuntimeError",
configurable: true
});
return error;
}
function resolveCategory(code) {
const prefix = code.split(".")[0] ?? "RUNTIME";
switch (prefix) {
case "PLAN":
case "CONTRACT":
case "LINT":
case "BUDGET": return prefix;
default: return "RUNTIME";
}
}
//#endregion
export { runtimeError as n, isRuntimeError as t };
//# sourceMappingURL=runtime-error-B2gWOtgH.mjs.map
{"version":3,"file":"runtime-error-B2gWOtgH.mjs","names":[],"sources":["../src/shared/runtime-error.ts"],"sourcesContent":["export interface RuntimeErrorEnvelope extends Error {\n readonly code: string;\n readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';\n readonly severity: 'error';\n readonly details?: Record<string, unknown>;\n}\n\n/**\n * Type guard for the runtime-error envelope produced by `runtimeError`.\n *\n * Prefer this over duck-typing on `error.code` directly so consumers stay\n * insulated from the envelope's internal shape.\n */\nexport function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope {\n return (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code?: unknown }).code === 'string' &&\n 'category' in error &&\n 'severity' in error\n );\n}\n\nexport function runtimeError(\n code: string,\n message: string,\n details?: Record<string, unknown>,\n): RuntimeErrorEnvelope {\n const error = Object.assign(new Error(message), {\n code,\n category: resolveCategory(code),\n severity: 'error' as const,\n ...(details !== undefined ? { details } : {}),\n });\n Object.defineProperty(error, 'name', { value: 'RuntimeError', configurable: true });\n return error;\n}\n\nfunction resolveCategory(code: string): RuntimeErrorEnvelope['category'] {\n const prefix = code.split('.')[0] ?? 'RUNTIME';\n switch (prefix) {\n case 'PLAN':\n case 'CONTRACT':\n case 'LINT':\n case 'BUDGET':\n return prefix;\n default:\n return 'RUNTIME';\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,eAAe,OAA+C;CAC5E,OACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA6B,SAAS,YAC9C,cAAc,SACd,cAAc;AAElB;AAEA,SAAgB,aACd,MACA,SACA,SACsB;CACtB,MAAM,QAAQ,OAAO,OAAO,IAAI,MAAM,OAAO,GAAG;EAC9C;EACA,UAAU,gBAAgB,IAAI;EAC9B,UAAU;EACV,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;CAC7C,CAAC;CACD,OAAO,eAAe,OAAO,QAAQ;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClF,OAAO;AACT;AAEA,SAAS,gBAAgB,MAAgD;CACvE,MAAM,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM;CACrC,QAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
import { blindCast } from '@prisma-next/utils/casts';
import type { Type } from 'arktype';
export interface EntityKindDescriptor<Input, Node> {
readonly kind: string;
// Type<unknown>, not Type<Input>: AnyEntityKindDescriptor widens Input to never, which would force an unusable Type<never>; concrete descriptors still carry their real schema.
readonly schema: Type<unknown>;
readonly construct: (input: Input) => Node;
}
export type AnyEntityKindDescriptor = EntityKindDescriptor<never, unknown>;
/**
* Hydrates a namespace's entities from raw JSON maps into IR class instances.
*
* For each kind in `entries`: if the descriptor map has a descriptor,
* construct each inner-map value; otherwise freeze-and-carry (`'carry'`)
* or throw naming the kind and nsId (`'fail'`).
*
* The single boundary cast hands `value` to `descriptor.construct` as its
* `Input`. The value satisfies the kind's `Input` either by the
* entries-input contract at authoring time or by prior `validateStorage`
* validation at hydration time.
*/
export function hydrateNamespaceEntities(
entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>,
kinds: ReadonlyMap<string, AnyEntityKindDescriptor>,
onUnknown: 'carry' | 'fail',
nsId?: string,
): Record<string, Readonly<Record<string, unknown>>> {
const result: Record<string, Readonly<Record<string, unknown>>> = {};
for (const [kind, rawMap] of Object.entries(entries)) {
const descriptor = kinds.get(kind);
if (descriptor !== undefined) {
const built: Record<string, unknown> = {};
for (const [name, value] of Object.entries(rawMap)) {
built[name] = descriptor.construct(
blindCast<
never,
"value is this kind's descriptor Input: when authoring, the typed entries-input contract produces it; when hydrating, it was validated against descriptor.schema before this loop. The never target is AnyEntityKindDescriptor's erased Input parameter."
>(value),
);
}
result[kind] = Object.freeze(built);
} else if (onUnknown === 'carry') {
result[kind] = Object.freeze(rawMap);
} else {
throw new Error(
`Unknown entries key "${kind}" in namespace "${nsId ?? '?'}"; no hydration factory registered for this entity kind`,
);
}
}
return result;
}
import { blindCast } from '@prisma-next/utils/casts';
import type { Codec } from './codec';
import type { AnyCodecDescriptor } from './codec-descriptor';
import type { CodecInstanceContext, CodecRef } from './codec-types';
import { runtimeError } from './runtime-error';
export const CONTRACT_CODEC_DESCRIPTOR_MISSING = 'CONTRACT.CODEC_DESCRIPTOR_MISSING' as const;
/**
* Look up a descriptor for `ref.codecId` using `descriptorFor`; throw
* `code` if none is found. Each plane names its own error path: the control
* plane resolves contract-stack descriptors (`CONTRACT.*`), the execution
* plane resolves at query time (`RUNTIME.*`).
*/
export function resolveCodecDescriptorOrThrow(
descriptorFor: (codecId: string) => AnyCodecDescriptor | undefined,
ref: CodecRef,
code: 'CONTRACT.CODEC_DESCRIPTOR_MISSING' | 'RUNTIME.CODEC_DESCRIPTOR_MISSING',
): AnyCodecDescriptor {
const descriptor = descriptorFor(ref.codecId);
if (!descriptor) {
throw runtimeError(code, `No codec descriptor registered for codecId '${ref.codecId}'.`, {
codecId: ref.codecId,
});
}
return descriptor;
}
/**
* Validates `ref.typeParams` against `descriptor.paramsSchema`.
*
* Parameterized codecs that omit `typeParams` have it normalized to `{}` before
* validation (mirrors `ast-codec-resolver.ts` semantics). Throws
* `RUNTIME.TYPE_PARAMS_INVALID` when the validator returns a `Promise` or
* reports issues.
*/
export function validateCodecTypeParams(descriptor: AnyCodecDescriptor, ref: CodecRef): unknown {
const normalized =
descriptor.isParameterized && ref.typeParams === undefined ? { ...ref, typeParams: {} } : ref;
const result = blindCast<
{ value: unknown } | { issues: ReadonlyArray<{ message: string }> } | Promise<unknown>,
'Standard Schema validate returns unknown; the spec guarantees this union shape'
>(descriptor.paramsSchema['~standard'].validate(normalized.typeParams));
if (result instanceof Promise) {
throw runtimeError(
'RUNTIME.TYPE_PARAMS_INVALID',
`paramsSchema for codec '${ref.codecId}' returned a Promise; runtime validation requires a synchronous Standard Schema validator.`,
{ codecId: ref.codecId, typeParams: ref.typeParams },
);
}
if ('issues' in result && result.issues) {
const messages = result.issues.map((issue) => issue.message).join('; ');
throw runtimeError(
'RUNTIME.TYPE_PARAMS_INVALID',
`Invalid typeParams for codec '${ref.codecId}': ${messages}`,
{ codecId: ref.codecId, typeParams: ref.typeParams },
);
}
return blindCast<{ value: unknown }, 'issues guard above rules out the issues branch'>(result)
.value;
}
/**
* Resolves a `Codec` instance: validates `ref.typeParams` via
* {@link validateCodecTypeParams} then calls `descriptor.factory(validated)(ctx)`.
*
* The descriptor's `factory` is typed against its own `P`; the registry erases
* `P` to `any`, so the factory is narrowed to `(params: unknown) => (ctx) => Codec`
* at the call boundary. The `paramsSchema` validates the input above before we
* forward it, so the narrowing is safe by construction.
*/
export function materializeCodec(
descriptor: AnyCodecDescriptor,
ref: CodecRef,
ctx: CodecInstanceContext,
): Codec {
const validated = validateCodecTypeParams(descriptor, ref);
return blindCast<
(params: unknown) => (ctx: CodecInstanceContext) => Codec,
'registry erases P to any; paramsSchema validates input before forwarding'
>(descriptor.factory)(validated)(ctx);
}
export interface RuntimeErrorEnvelope extends Error {
readonly code: string;
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
readonly severity: 'error';
readonly details?: Record<string, unknown>;
}
/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
export function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope {
return (
error instanceof Error &&
'code' in error &&
typeof (error as { code?: unknown }).code === 'string' &&
'category' in error &&
'severity' in error
);
}
export function runtimeError(
code: string,
message: string,
details?: Record<string, unknown>,
): RuntimeErrorEnvelope {
const error = Object.assign(new Error(message), {
code,
category: resolveCategory(code),
severity: 'error' as const,
...(details !== undefined ? { details } : {}),
});
Object.defineProperty(error, 'name', { value: 'RuntimeError', configurable: true });
return error;
}
function resolveCategory(code: string): RuntimeErrorEnvelope['category'] {
const prefix = code.split('.')[0] ?? 'RUNTIME';
switch (prefix) {
case 'PLAN':
case 'CONTRACT':
case 'LINT':
case 'BUDGET':
return prefix;
default:
return 'RUNTIME';
}
}
+2
-2

@@ -1,2 +0,2 @@

import { A as resolveAuthoringTemplateValue, B as PslExtensionBlockParamOption, C as instantiateAuthoringTypeConstructor, D as isAuthoringPslBlockDescriptor, E as isAuthoringFieldPresetDescriptor, F as PslBlockParamRef, H as PslExtensionBlockParamScalarValue, I as PslBlockParamValue, M as PslBlockParam, N as PslBlockParamList, O as isAuthoringTypeConstructorDescriptor, P as PslBlockParamOption, R as PslExtensionBlock, S as instantiateAuthoringFieldPreset, T as isAuthoringEntityTypeDescriptor, U as PslExtensionBlockParamValue, V as PslExtensionBlockParamRef, _ as AuthoringTypeConstructorDescriptor, a as AuthoringEntityContext, b as hasRegisteredFieldNamespace, c as AuthoringEntityTypeNamespace, d as AuthoringFieldPresetDescriptor, f as AuthoringFieldPresetOutput, g as AuthoringTemplateValue, h as AuthoringStorageTypeTemplate, i as AuthoringContributions, j as validateAuthoringHelperArguments, k as mergeAuthoringNamespaces, l as AuthoringEntityTypeTemplateOutput, m as AuthoringPslBlockDescriptorNamespace, n as AuthoringArgumentDescriptor, o as AuthoringEntityTypeDescriptor, p as AuthoringPslBlockDescriptor, r as AuthoringColumnDefaultTemplate, s as AuthoringEntityTypeFactoryOutput, t as AuthoringArgRef, u as AuthoringFieldNamespace, v as AuthoringTypeNamespace, w as isAuthoringArgRef, x as instantiateAuthoringEntityType, y as assertNoCrossRegistryCollisions, z as PslExtensionBlockParamList } from "./framework-authoring-R0TYCkvG.mjs";
export { type AuthoringArgRef, type AuthoringArgumentDescriptor, type AuthoringColumnDefaultTemplate, type AuthoringContributions, type AuthoringEntityContext, type AuthoringEntityTypeDescriptor, type AuthoringEntityTypeFactoryOutput, type AuthoringEntityTypeNamespace, type AuthoringEntityTypeTemplateOutput, type AuthoringFieldNamespace, type AuthoringFieldPresetDescriptor, type AuthoringFieldPresetOutput, type AuthoringPslBlockDescriptor, type AuthoringPslBlockDescriptorNamespace, type AuthoringStorageTypeTemplate, type AuthoringTemplateValue, type AuthoringTypeConstructorDescriptor, type AuthoringTypeNamespace, type PslBlockParam, type PslBlockParamList, type PslBlockParamOption, type PslBlockParamRef, type PslBlockParamValue, type PslExtensionBlock, type PslExtensionBlockParamList, type PslExtensionBlockParamOption, type PslExtensionBlockParamRef, type PslExtensionBlockParamScalarValue, type PslExtensionBlockParamValue, assertNoCrossRegistryCollisions, hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringArgRef, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, resolveAuthoringTemplateValue, validateAuthoringHelperArguments };
import { A as mergeAuthoringNamespaces, C as instantiateAuthoringFieldPreset, D as isAuthoringFieldPresetDescriptor, E as isAuthoringEntityTypeDescriptor, F as PslBlockParamOption, G as PslExtensionBlockParamRef, I as PslBlockParamRef, K as PslExtensionBlockParamScalarValue, L as PslBlockParamValue, M as validateAuthoringHelperArguments, N as PslBlockParam, O as isAuthoringPslBlockDescriptor, P as PslBlockParamList, S as instantiateAuthoringEntityType, T as isAuthoringArgRef, U as PslExtensionBlockParamList, W as PslExtensionBlockParamOption, _ as AuthoringTemplateValue, a as AuthoringDiagnosticSink, b as assertNoCrossRegistryCollisions, c as AuthoringEntityTypeFactoryOutput, d as AuthoringFieldNamespace, f as AuthoringFieldPresetDescriptor, g as AuthoringStorageTypeTemplate, h as AuthoringPslBlockDescriptorNamespace, i as AuthoringContributions, j as resolveAuthoringTemplateValue, k as isAuthoringTypeConstructorDescriptor, l as AuthoringEntityTypeNamespace, m as AuthoringPslBlockDescriptor, n as AuthoringArgumentDescriptor, o as AuthoringEntityContext, p as AuthoringFieldPresetOutput, q as PslExtensionBlockParamValue, r as AuthoringColumnDefaultTemplate, s as AuthoringEntityTypeDescriptor, t as AuthoringArgRef, u as AuthoringEntityTypeTemplateOutput, v as AuthoringTypeConstructorDescriptor, w as instantiateAuthoringTypeConstructor, x as hasRegisteredFieldNamespace, y as AuthoringTypeNamespace, z as PslExtensionBlock } from "./framework-authoring-CJC4jwGo.mjs";
export { type AuthoringArgRef, type AuthoringArgumentDescriptor, type AuthoringColumnDefaultTemplate, type AuthoringContributions, type AuthoringDiagnosticSink, type AuthoringEntityContext, type AuthoringEntityTypeDescriptor, type AuthoringEntityTypeFactoryOutput, type AuthoringEntityTypeNamespace, type AuthoringEntityTypeTemplateOutput, type AuthoringFieldNamespace, type AuthoringFieldPresetDescriptor, type AuthoringFieldPresetOutput, type AuthoringPslBlockDescriptor, type AuthoringPslBlockDescriptorNamespace, type AuthoringStorageTypeTemplate, type AuthoringTemplateValue, type AuthoringTypeConstructorDescriptor, type AuthoringTypeNamespace, type PslBlockParam, type PslBlockParamList, type PslBlockParamOption, type PslBlockParamRef, type PslBlockParamValue, type PslExtensionBlock, type PslExtensionBlockParamList, type PslExtensionBlockParamOption, type PslExtensionBlockParamRef, type PslExtensionBlockParamScalarValue, type PslExtensionBlockParamValue, assertNoCrossRegistryCollisions, hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringArgRef, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, resolveAuthoringTemplateValue, validateAuthoringHelperArguments };

@@ -1,2 +0,2 @@

import { a as instantiateAuthoringTypeConstructor, c as isAuthoringFieldPresetDescriptor, d as mergeAuthoringNamespaces, f as resolveAuthoringTemplateValue, i as instantiateAuthoringFieldPreset, l as isAuthoringPslBlockDescriptor, n as hasRegisteredFieldNamespace, o as isAuthoringArgRef, p as validateAuthoringHelperArguments, r as instantiateAuthoringEntityType, s as isAuthoringEntityTypeDescriptor, t as assertNoCrossRegistryCollisions, u as isAuthoringTypeConstructorDescriptor } from "./framework-authoring-CnwPJCO4.mjs";
import { a as instantiateAuthoringTypeConstructor, c as isAuthoringFieldPresetDescriptor, d as mergeAuthoringNamespaces, f as resolveAuthoringTemplateValue, i as instantiateAuthoringFieldPreset, l as isAuthoringPslBlockDescriptor, n as hasRegisteredFieldNamespace, o as isAuthoringArgRef, p as validateAuthoringHelperArguments, r as instantiateAuthoringEntityType, s as isAuthoringEntityTypeDescriptor, t as assertNoCrossRegistryCollisions, u as isAuthoringTypeConstructorDescriptor } from "./framework-authoring-Dv5F3EFC.mjs";
export { assertNoCrossRegistryCollisions, hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringArgRef, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, resolveAuthoringTemplateValue, validateAuthoringHelperArguments };

@@ -1,2 +0,2 @@

import { a as CodecDescriptorImpl, c as CodecLookup, d as CodecTrait, f as emptyCodecLookup, i as CodecDescriptor, l as CodecMeta, n as CodecImpl, o as CodecCallContext, p as voidParamsSchema, r as AnyCodecDescriptor, s as CodecInstanceContext, t as Codec, u as CodecRef } from "./codec-DCQAerzB.mjs";
import { a as CodecRef, c as emptyCodecLookup, d as CodecImpl, f as AnyCodecDescriptor, i as CodecMeta, l as voidParamsSchema, m as CodecDescriptorImpl, n as CodecInstanceContext, o as CodecRegistry, p as CodecDescriptor, r as CodecLookup, s as CodecTrait, t as CodecCallContext, u as Codec } from "./codec-types-yY3eSmi0.mjs";

@@ -47,3 +47,32 @@ //#region src/shared/column-spec.d.ts

//#endregion
export { type AnyCodecDescriptor, type Codec, type CodecCallContext, type CodecDescriptor, CodecDescriptorImpl, CodecImpl, type CodecInstanceContext, type CodecLookup, type CodecMeta, type CodecRef, type CodecTrait, type ColumnHelperFor, type ColumnHelperForStrict, type ColumnSpec, type ColumnTypeDescriptor, column, emptyCodecLookup, voidParamsSchema };
//#region src/shared/resolve-codec.d.ts
declare const CONTRACT_CODEC_DESCRIPTOR_MISSING: "CONTRACT.CODEC_DESCRIPTOR_MISSING";
/**
* Look up a descriptor for `ref.codecId` using `descriptorFor`; throw
* `code` if none is found. Each plane names its own error path: the control
* plane resolves contract-stack descriptors (`CONTRACT.*`), the execution
* plane resolves at query time (`RUNTIME.*`).
*/
declare function resolveCodecDescriptorOrThrow(descriptorFor: (codecId: string) => AnyCodecDescriptor | undefined, ref: CodecRef, code: 'CONTRACT.CODEC_DESCRIPTOR_MISSING' | 'RUNTIME.CODEC_DESCRIPTOR_MISSING'): AnyCodecDescriptor;
/**
* Validates `ref.typeParams` against `descriptor.paramsSchema`.
*
* Parameterized codecs that omit `typeParams` have it normalized to `{}` before
* validation (mirrors `ast-codec-resolver.ts` semantics). Throws
* `RUNTIME.TYPE_PARAMS_INVALID` when the validator returns a `Promise` or
* reports issues.
*/
declare function validateCodecTypeParams(descriptor: AnyCodecDescriptor, ref: CodecRef): unknown;
/**
* Resolves a `Codec` instance: validates `ref.typeParams` via
* {@link validateCodecTypeParams} then calls `descriptor.factory(validated)(ctx)`.
*
* The descriptor's `factory` is typed against its own `P`; the registry erases
* `P` to `any`, so the factory is narrowed to `(params: unknown) => (ctx) => Codec`
* at the call boundary. The `paramsSchema` validates the input above before we
* forward it, so the narrowing is safe by construction.
*/
declare function materializeCodec(descriptor: AnyCodecDescriptor, ref: CodecRef, ctx: CodecInstanceContext): Codec;
//#endregion
export { type AnyCodecDescriptor, CONTRACT_CODEC_DESCRIPTOR_MISSING, type Codec, type CodecCallContext, type CodecDescriptor, CodecDescriptorImpl, CodecImpl, type CodecInstanceContext, type CodecLookup, type CodecMeta, type CodecRef, type CodecRegistry, type CodecTrait, type ColumnHelperFor, type ColumnHelperForStrict, type ColumnSpec, type ColumnTypeDescriptor, column, emptyCodecLookup, materializeCodec, resolveCodecDescriptorOrThrow, validateCodecTypeParams, voidParamsSchema };
//# sourceMappingURL=codec.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"codec.d.mts","names":[],"sources":["../src/shared/column-spec.ts"],"mappings":";;;;;;;;;AAsBkB;KAJN,oBAAA;EAAA,SACD,OAAA,EAAS,QAAA;EAAA,SACT,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;EAAA,SACnB,OAAA;AAAA;;;;;;UAQM,UAAA,cAAwB,MAAA,uCAC/B,oBAAA;EAAA,SACC,YAAA,GAAe,GAAA,EAAK,oBAAA,KAAyB,CAAA;EAAA,SAC7C,UAAA,EAAY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A;;;;KAMpE,kBAAA,WAA6B,eAAA,SAChC,UAAA,CAAW,CAAA,wBAAyB,MAAA,oBAChC,UAAA,CAAW,CAAA;;;cC3EJ,iCAAA;;;;;;;iBAQG,6BAAA,CACd,aAAA,GAAgB,OAAA,aAAoB,kBAAA,cACpC,GAAA,EAAK,QAAA,EACL,IAAA,6EACC,kBAAA;;;;;ADIe;AAQlB;;;iBCMgB,uBAAA,CAAwB,UAAA,EAAY,kBAAA,EAAoB,GAAA,EAAK,QAAQ;;;;;;;;;;iBAuCrE,gBAAA,CACd,UAAA,EAAY,kBAAA,EACZ,GAAA,EAAK,QAAA,EACL,GAAA,EAAK,oBAAA,GACJ,KAAA"}

@@ -0,1 +1,2 @@

import { i as validateCodecTypeParams, n as materializeCodec, r as resolveCodecDescriptorOrThrow, t as CONTRACT_CODEC_DESCRIPTOR_MISSING } from "./resolve-codec-D8EPZosv.mjs";
//#region src/shared/codec.ts

@@ -67,4 +68,4 @@ /**

//#endregion
export { CodecDescriptorImpl, CodecImpl, column, emptyCodecLookup, voidParamsSchema };
export { CONTRACT_CODEC_DESCRIPTOR_MISSING, CodecDescriptorImpl, CodecImpl, column, emptyCodecLookup, materializeCodec, resolveCodecDescriptorOrThrow, validateCodecTypeParams, voidParamsSchema };
//# sourceMappingURL=codec.mjs.map

@@ -1,1 +0,1 @@

{"version":3,"file":"codec.mjs","names":[],"sources":["../src/shared/codec.ts","../src/shared/codec-types.ts","../src/shared/codec-descriptor.ts","../src/shared/column-spec.ts"],"sourcesContent":["/**\n * Codec interface (consumer surface) and abstract `CodecImpl` base (codec-author surface).\n *\n * Consumers depend on the {@link Codec} interface — it describes the runtime instance returned by a descriptor's curried factory and is what the framework threads through emit, validate, and execute paths.\n *\n * Codec authors `extend` the {@link CodecImpl} abstract class to declare a typed runtime codec instance. The class carries a variance-erased descriptor reference (`CodecDescriptor<any>`); `id` proxies through the descriptor so one source of truth governs both metadata reads and aliasing semantics (alias subclasses inherit the descriptor's id automatically).\n *\n * Class generic shape: `Id`, `TTraits`, `TWire`, `TInput`. Method generics on the codec subclass's own surface (e.g. arktype-json's schema generic, pgvector's dimension generic) flow through the subclass's constructor and propagate via the descriptor's typed `factory(params)` return at *direct* call sites.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecDescriptor } from './codec-descriptor';\nimport type { CodecCallContext, CodecTrait } from './codec-types';\n\n/**\n * A codec is the contract between an application value and its on-wire and on-contract-disk representations.\n *\n * The author's mental model is two JS-side types — `TInput` (the application JS type) and `TWire` (the database driver wire format) — plus `JsonValue` for build-time contract artifacts. The codec translates `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue` during contract emission and loading.\n *\n * Three representations participate:\n * - **Input** (`TInput`): the JS type at the application boundary.\n * - **Wire** (`TWire`): the format exchanged with the database driver.\n * - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.\n *\n * The runtime instance carries only its `id` (the descriptor's `codecId`, set by the factory) and the four conversion methods. Static metadata (`traits`, `targetTypes`, `meta`) and the build-time `renderOutputType` renderer live on the {@link CodecDescriptor} keyed by `codecId` — the read-surface single source of truth. Consumers that need them resolve through `descriptorFor(codecId)`.\n *\n * Codec methods split into two groups:\n *\n * - **Query-time** methods (`encode`, `decode`) run per row/parameter at the IO boundary; they are required and Promise-returning. The per-family codec factory accepts sync or async author functions and lifts sync ones to Promise-shaped methods automatically.\n * - **Build-time** methods (`encodeJson`, `decodeJson`) run when the contract is serialized or loaded. They stay synchronous so contract validation and client construction are synchronous.\n *\n * Target-family codec interfaces extend this base; family-specific concerns (e.g. the SQL `column?` per-call context) layer on through the `CodecCallContext` extension pattern.\n */\nexport interface Codec<\n Id extends string = string,\n TTraits extends readonly CodecTrait[] = readonly CodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> {\n /** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). The factory sets this to the descriptor's `codecId`; consumers use it as a back-reference for descriptor lookups and for decode-error diagnostics. */\n readonly id: Id;\n /** Phantom carrier for the `TTraits` generic; type-only, undefined at runtime. Runtime traits live on {@link CodecDescriptor.traits}. Implemented as a string-key phantom (`__codecTraits`) rather than `unique symbol` so bundlers that split `.d.ts` chunks do not strand symbol identity on chunk-private paths (the same `TS2742` family that the public re-export of `CodecTypes` works around). */\n readonly __codecTraits?: TTraits;\n /** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(value) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */\n encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;\n /** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(wire) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */\n decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;\n /** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */\n encodeJson(value: TInput): JsonValue;\n /** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `family.deserializeContract`. */\n decodeJson(json: JsonValue): TInput;\n}\n\n/**\n * Abstract base class for concrete codec implementations.\n *\n * Codec authors extend this class with their typed `Id`, `TTraits`, `TWire`, `TInput` and override `encode`/`decode` (and optionally `encodeJson`/`decodeJson`). The runtime instance carries only its `id` (proxied through the descriptor so alias subclasses inherit the descriptor's id automatically) and the conversion methods — static metadata lives on the {@link CodecDescriptor}.\n */\nexport abstract class CodecImpl<\n Id extends string = string,\n TTraits extends readonly CodecTrait[] = readonly CodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> implements Codec<Id, TTraits, TWire, TInput>\n{\n /**\n * Variance-erased descriptor reference. Concrete codec subclasses receive the typed descriptor in their own constructors and forward it via `super(descriptor)`; the variance erasure lives at this base because the abstract surface can't carry the concrete `TParams`.\n */\n // biome-ignore lint/suspicious/noExplicitAny: variance-erased descriptor reference; subclasses retain typed access via their own state\n constructor(public readonly descriptor: CodecDescriptor<any>) {}\n\n get id(): Id {\n return this.descriptor.codecId as Id;\n }\n\n abstract encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;\n abstract decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;\n abstract encodeJson(value: TInput): JsonValue;\n abstract decodeJson(json: JsonValue): TInput;\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Codec } from './codec';\n\nexport type CodecTrait = 'equality' | 'order' | 'boolean' | 'numeric' | 'textual';\n\n/**\n * Serializable codec identity carried by every codec-bearing AST node.\n *\n * `(codecId, typeParams?)` is the single fact the runtime needs to materialize a codec via `descriptorFor(codecId).factory(typeParams)(ctx)`. The pair is content-keyed: two refs with the same `codecId` and structurally equal `typeParams` (regardless of object key ordering) resolve to the same memoized {@link Codec} instance.\n *\n * `typeParams` is `JsonValue`-constrained so the ref survives JSON serialization (relevant for AST-embedded migration ops). Non-parameterized codecs leave `typeParams` undefined; the descriptor's `paramsSchema` validates the value at the JSON boundary.\n *\n * Family-agnostic by design — both SQL and Mongo AST nodes carry `codec: CodecRef | undefined`, and the resolver is the only dispatch path that survives serialization.\n */\nexport interface CodecRef {\n readonly codecId: string;\n readonly typeParams?: JsonValue;\n}\n\n/**\n * Per-call context the runtime threads to every `codec.encode` / `codec.decode` invocation for a single `runtime.execute()` call.\n *\n * The framework-level shape is family-agnostic and carries one field:\n *\n * - `signal?: AbortSignal` — per-query cancellation. The runtime returns a `RUNTIME.ABORTED` envelope when the signal aborts; codec authors who forward `signal` to their underlying SDK get true cancellation of in-flight network calls.\n *\n * Family layers extend this base with their own shape-of-call metadata: the SQL family adds `column?: SqlColumnRef` via `SqlCodecCallContext` (see `@prisma-next/sql-relational-core`). Mongo currently uses this framework type unchanged. Column metadata is intentionally **not** on the framework type — it is a SQL-family concept rooted in SQL's `(table, column)` addressing model and would not generalise to other families.\n *\n * The interface is named explicitly (not inlined) so future framework fields and family extensions can land additively without breaking codec author signatures.\n */\nexport interface CodecCallContext {\n readonly signal?: AbortSignal;\n}\n\n/**\n * Codec-id-keyed read surface threaded into emit and authoring paths.\n *\n * - `get(id)` returns the runtime {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults).\n * - `targetTypesFor(id)` exposes the codec-id-keyed `targetTypes` metadata the runtime instance no longer carries (TML-2357). Returns the same array `CodecDescriptor.targetTypes` would; for Mongo (whose registration doesn't yet resolve through the unified descriptor map — TML-2324) the family-side assembly populates this directly from the contributor's codec metadata.\n * - `metaFor(id)` exposes the codec-id-keyed `meta` (e.g. SQL-side `db.sql.postgres.nativeType`) the runtime instance no longer carries.\n * - `renderOutputTypeFor(id, params)` exposes the codec-id-keyed `renderOutputType` renderer the runtime instance no longer carries. Returns `undefined` when the codec doesn't render a custom type or when the codec id is unknown.\n */\nexport interface CodecLookup {\n get(id: string): Codec | undefined;\n targetTypesFor(id: string): readonly string[] | undefined;\n metaFor(id: string): CodecMeta | undefined;\n renderOutputTypeFor(id: string, params: Record<string, unknown>): string | undefined;\n}\n\nexport const emptyCodecLookup: CodecLookup = {\n get: () => undefined,\n targetTypesFor: () => undefined,\n metaFor: () => undefined,\n renderOutputTypeFor: () => undefined,\n};\n\n/**\n * Family-agnostic per-instance context supplied by the framework when applying a higher-order codec factory. Allows stateful codecs (e.g. column-scoped encryption) to derive per-instance state from the materialization site.\n *\n * - `name` — the family-agnostic instance identity. For SQL, the runtime populates this as the `storage.types` instance name (e.g. `Embedding1536`) for typeRef-shaped columns, an inline-column sentinel (`<col:Document.embedding>`) for inline-`typeParams` columns, a shared codec-id sentinel (`<codec:pg/text@1>`) for non-parameterized codec ids, or the canonical cache key (`<codecId>:<canonicalizeJson(typeParams)>`) for ad-hoc refs the contract walk did not pre-populate. Other families pick the analogous identity for their materialization sites.\n *\n * Family-specific extensions (e.g. {@link import('@prisma-next/sql-relational-core/ast').SqlCodecInstanceContext} in the SQL layer) augment this base with domain-shaped column-set metadata. Codec authors target the base when they don't read family-specific metadata; they target the family extension when they do.\n */\nexport interface CodecInstanceContext {\n readonly name: string;\n}\n\n/**\n * Family-agnostic codec metadata. Family-specific extensions augment the base `db.<family>.<target>` block with native-type information; the base shape is an empty object so non-relational codecs can carry no metadata.\n */\nexport interface CodecMeta {\n readonly db?: Record<string, unknown>;\n}\n\n/**\n * Standard Schema validator for `void` params. Accepts only `undefined` (or absent input); rejects any other value so a contract that tries to thread `typeParams` through a non-parameterized codec id fails fast at the JSON boundary instead of silently coercing the value away. Used by the framework-supplied non-parameterized descriptor synthesizer.\n */\nexport const voidParamsSchema: StandardSchemaV1<void> = {\n '~standard': {\n version: 1,\n vendor: 'prisma-next',\n validate: (input) =>\n input === undefined\n ? { value: undefined }\n : {\n issues: [\n {\n message: 'unexpected typeParams for non-parameterized codec (void params expected)',\n },\n ],\n },\n },\n};\n","/**\n * Codec descriptor interface (consumer surface) and abstract `CodecDescriptorImpl` base (codec-author surface).\n *\n * Consumers depend on the {@link CodecDescriptor} interface — it is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema`; optional `renderOutputType`). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.\n *\n * Codec authors `extend` the {@link CodecDescriptorImpl} abstract class to declare their codec id, traits, target types, params schema, the `factory(params)` that materializes a typed `Codec<...>`, and (optionally) a `renderOutputType(params)` for the emit path.\n *\n * The factory's method-level generic is the load-bearing piece for literal preservation: per-codec column helpers invoke `descriptor.factory(...)` *directly*, and the direct call binds the generic at its call site. Type extraction (`ReturnType<D['factory']>`, structural matching) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.\n */\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Codec } from './codec';\nimport {\n type CodecInstanceContext,\n type CodecMeta,\n type CodecTrait,\n voidParamsSchema,\n} from './codec-types';\n\n/**\n * Unified codec descriptor. Every codec in the framework registers through this shape — non-parameterized codecs use `P = void` and a constant factory that returns the same shared codec instance for every column; parameterized codecs use a non-empty `P` and a curried higher-order factory that returns a per-instance codec.\n *\n * The descriptor is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema` for JSON-boundary validation; optional `renderOutputType` for the `contract.d.ts` emit path). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.\n *\n * Whether a codec id \"is parameterized\" stops being a registration-time distinction — it's a property of `P` on the descriptor. The descriptor map indexes every descriptor by `codecId`; both `descriptorFor(codecId)` and `forColumn(table, column)` resolve through the same map without branching on parameterization.\n *\n * @template P - The shape of the params accepted by the factory (`void` for non-parameterized codecs; a record like `{ length: number }` for parameterized codecs).\n *\n * Codec-registry-unification project § Decision.\n */\nexport interface CodecDescriptor<P = void> {\n /** The codec ID this descriptor applies to (e.g. `pg/vector@1`, `pg/text@1`). */\n readonly codecId: string;\n /** Semantic traits for operator gating (e.g. equality, order, numeric). */\n readonly traits: readonly CodecTrait[];\n /** Database-native type names this codec handles (e.g. `['timestamptz']`). */\n readonly targetTypes: readonly string[];\n /** Optional family-specific metadata (e.g. SQL-side `db.sql.postgres.nativeType`). */\n readonly meta?: CodecMeta;\n /** Standard Schema validator for the factory's params. Validates JSON-sourced params at the contract boundary (PSL → IR; `contract.json` → runtime). For non-parameterized codecs (`P = void`), the schema validates `void`/`undefined` — the framework supplies no params at the call boundary. */\n readonly paramsSchema: StandardSchemaV1<P>;\n /** Whether this descriptor is parameterized — i.e. its `paramsSchema` is something other than the singleton `voidParamsSchema`. Consumers that need to gate column-aware dispatch read this directly rather than threading a free-floating `(codecId) => boolean` callback. */\n readonly isParameterized: boolean;\n /** Emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for given params (e.g. `Vector<1536>`). Optional; absent renderers cause the emitter to fall back to the codec's base output type. Non-parameterized codecs typically omit it. */\n readonly renderOutputType?: (params: P) => string | undefined;\n /** The curried higher-order codec. For non-parameterized codecs, the factory is constant — every call returns the same shared codec instance. For parameterized codecs, the factory is called once per `storage.types` instance (or once per inline-`typeParams` column), with `ctx` carrying the column set the resulting codec serves. */\n readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;\n}\n\n/**\n * Variance-erased {@link CodecDescriptor} alias. `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly), so `CodecDescriptor<P>` does not extend `CodecDescriptor<unknown>` for specific `P`. Heterogeneous descriptor collections — e.g. `SqlStaticContributions.codecs:` returning a list that mixes parameterized and non-parameterized descriptors — type against this alias and narrow per codec id at the consumer.\n *\n * Codec-registry-unification spec § Decision: every codec resolves through one descriptor map; reads are non-branching.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure for heterogeneous descriptor collections\nexport type AnyCodecDescriptor = CodecDescriptor<any>;\n\n/**\n * Abstract base class for concrete codec descriptors.\n *\n * Codec authors extend this class with their typed `TParams` and declare `codecId`, `traits`, `targetTypes`, `paramsSchema`, the curried `factory(params)`, and (optionally) `renderOutputType`.\n *\n * Implements the {@link CodecDescriptor} interface so a concrete subclass instance is directly usable wherever the framework expects a `CodecDescriptor<P>`.\n */\nexport abstract class CodecDescriptorImpl<TParams = void> implements CodecDescriptor<TParams> {\n abstract readonly codecId: string;\n abstract readonly traits: readonly CodecTrait[];\n abstract readonly targetTypes: readonly string[];\n readonly meta?: CodecMeta;\n\n abstract readonly paramsSchema: StandardSchemaV1<TParams>;\n\n /** Boolean derived from `paramsSchema`: `true` whenever the schema is not the singleton `voidParamsSchema`. */\n get isParameterized(): boolean {\n return this.paramsSchema !== voidParamsSchema;\n }\n\n /** Optional emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for the given params (e.g. `Vector<1536>`). Non-parameterized codecs typically omit it. */\n renderOutputType?(params: TParams): string | undefined;\n\n /**\n * Materialize a curried codec factory for the given params. Concrete subclasses override with a typed return type (e.g. `factory<N>(params: { length: N }): (ctx) => VectorCodec<N>`); per-codec helpers read the typed return at the *direct* call site, which is what preserves method-level generics. Type extraction (e.g. `ReturnType<D['factory']>`) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.\n */\n abstract factory(\n params: TParams,\n ): (ctx: CodecInstanceContext) => Codec<string, readonly CodecTrait[], unknown, unknown>;\n}\n","/**\n * `column()` packager + `ColumnSpec<R, P>` shape + `ColumnHelperFor<D>` variants for tying per-codec column helpers to their descriptor.\n *\n * `ColumnSpec<R, P>` extends {@link ColumnTypeDescriptor} so it remains a drop-in for contract authoring sites that consume `ColumnTypeDescriptor` shapes — both types live at the framework-components layer so the `extends` clause is real (no structural mirror).\n *\n * `column()` is a trivial, non-polymorphic packager. Generic over `R` (the codec instance type returned by the descriptor's curried factory) and `P` (the typeParams record). The framework does NOT try to infer `R` and `P` from a descriptor — that path is the variance trap. Per-codec helpers absorb the descriptor relationship instead and tie themselves to their descriptor via `satisfies ColumnHelperFor<D>` or `satisfies ColumnHelperForStrict<D>`.\n */\n\nimport type { CodecDescriptor } from './codec-descriptor';\nimport type { CodecInstanceContext } from './codec-types';\n\n/**\n * Authored column-type descriptor — the data shape an authoring site (PSL or TypeScript builders) attaches to a column to identify its codec and its native database type.\n *\n * Lives at the framework-components layer alongside the codec types so codec-author packages (e.g. column-spec / `column()` packagers) can extend it directly without crossing layer boundaries.\n *\n * @template TCodecId Narrowed codec id literal for sites that thread a specific codec id through the type system.\n */\nexport type ColumnTypeDescriptor<TCodecId extends string = string> = {\n readonly codecId: TCodecId;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown> | undefined;\n readonly typeRef?: string;\n};\n\n/**\n * Column spec carrying the codec factory closure alongside the {@link ColumnTypeDescriptor} fields. Codec authors return a `ColumnSpec` from per-codec column helpers; the runtime materializes the codec instance by calling `codecFactory(ctx)` once it knows the column's `CodecInstanceContext`.\n *\n * Extends {@link ColumnTypeDescriptor} so `ColumnSpec` instances flow directly into contract-authoring sites that consume the descriptor shape — no structural mirroring required.\n */\nexport interface ColumnSpec<R, P extends Record<string, unknown> | undefined>\n extends ColumnTypeDescriptor {\n readonly codecFactory: (ctx: CodecInstanceContext) => R;\n readonly typeParams: P;\n}\n\n/**\n * Trivial column packager. Per-codec helpers call this directly with the result of `descriptor.factory(params)` — direct method invocation binds the descriptor's method-level generic at the call site and the literal flows through `R`.\n *\n * `nativeType` is the column's database-native type spelling — the value the postgres adapter's migration planner, the SQL renderer's cast policy, and the contract's `meta.db.<family>.<target>.nativeType` slot read. Per-codec helpers pass the literal native-type string for their codec (e.g. `'text'`, `'int4'`, `'character varying'`); for codecs whose native-type spelling depends on parameters (none today; reserved for future shapes), the helper computes the rendered string before calling `column`. The framework does not derive the value from `codecId` — that mapping is target-specific and lives at the helper.\n */\nexport function column<R, P extends Record<string, unknown> | undefined>(\n codecFactory: (ctx: CodecInstanceContext) => R,\n codecId: string,\n typeParams: P,\n nativeType: string,\n): ColumnSpec<R, P> {\n return {\n codecFactory,\n codecId,\n typeParams,\n nativeType,\n };\n}\n\n/**\n * Coarse `satisfies` shape — checks the helper's typeParams record matches the descriptor's factory params. Catches \"wrong typeParams shape\" wiring mistakes; does NOT catch \"wrong descriptor's factory\" mistakes (the codec slot is left as `unknown`).\n *\n * Use when the codec's `ReturnType<factory>` is unstable (e.g. heavily overloaded factories where extraction widens too much).\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern\nexport type ColumnHelperFor<D extends CodecDescriptor<any>> = (\n // biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference\n ...args: any[]\n) => ColumnSpec<unknown, ColumnHelperParams<D>>;\n\n/**\n * Strict `satisfies` shape — also checks the helper's codec is at least the *base* codec instance type the descriptor's factory returns. `ReturnType<ReturnType<D['factory']>>` widens method generics to their constraint, so this only sanity-checks the wiring at the base type level. Literal preservation comes from the direct `descriptor.factory(...)` call inside the helper, not from `satisfies`.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern\nexport type ColumnHelperForStrict<D extends CodecDescriptor<any>> = (\n // biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference\n ...args: any[]\n) => ColumnSpec<ReturnType<ReturnType<D['factory']>>, ColumnHelperParams<D>>;\n\n/**\n * Coerce a descriptor's `factory` first parameter into the typeParams shape `ColumnSpec` accepts. Non-parameterized descriptors (factory with no params, or `params: void`) collapse to `undefined`; parameterized descriptors keep the params record shape.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — see above\ntype ColumnHelperParams<D extends CodecDescriptor<any>> =\n Parameters<D['factory']>[0] extends Record<string, unknown>\n ? Parameters<D['factory']>[0]\n : undefined;\n"],"mappings":";;;;;;AA0DA,IAAsB,YAAtB,MAMA;CAK8B;;;;CAA5B,YAAY,YAAkD;EAAlC,KAAA,aAAA;CAAmC;CAE/D,IAAI,KAAS;EACX,OAAO,KAAK,WAAW;CACzB;AAMF;;;AC7BA,MAAa,mBAAgC;CAC3C,WAAW,KAAA;CACX,sBAAsB,KAAA;CACtB,eAAe,KAAA;CACf,2BAA2B,KAAA;AAC7B;;;;AAuBA,MAAa,mBAA2C,EACtD,aAAa;CACX,SAAS;CACT,QAAQ;CACR,WAAW,UACT,UAAU,KAAA,IACN,EAAE,OAAO,KAAA,EAAU,IACnB,EACE,QAAQ,CACN,EACE,SAAS,2EACX,CACF,EACF;AACR,EACF;;;;;;;;;;AC7BA,IAAsB,sBAAtB,MAA8F;CAI5F;;CAKA,IAAI,kBAA2B;EAC7B,OAAO,KAAK,iBAAiB;CAC/B;AAWF;;;;;;;;AC7CA,SAAgB,OACd,cACA,SACA,YACA,YACkB;CAClB,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
{"version":3,"file":"codec.mjs","names":[],"sources":["../src/shared/codec.ts","../src/shared/codec-types.ts","../src/shared/codec-descriptor.ts","../src/shared/column-spec.ts"],"sourcesContent":["/**\n * Codec interface (consumer surface) and abstract `CodecImpl` base (codec-author surface).\n *\n * Consumers depend on the {@link Codec} interface — it describes the runtime instance returned by a descriptor's curried factory and is what the framework threads through emit, validate, and execute paths.\n *\n * Codec authors `extend` the {@link CodecImpl} abstract class to declare a typed runtime codec instance. The class carries a variance-erased descriptor reference (`CodecDescriptor<any>`); `id` proxies through the descriptor so one source of truth governs both metadata reads and aliasing semantics (alias subclasses inherit the descriptor's id automatically).\n *\n * Class generic shape: `Id`, `TTraits`, `TWire`, `TInput`. Method generics on the codec subclass's own surface (e.g. arktype-json's schema generic, pgvector's dimension generic) flow through the subclass's constructor and propagate via the descriptor's typed `factory(params)` return at *direct* call sites.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecDescriptor } from './codec-descriptor';\nimport type { CodecCallContext, CodecTrait } from './codec-types';\n\n/**\n * A codec is the contract between an application value and its on-wire and on-contract-disk representations.\n *\n * The author's mental model is two JS-side types — `TInput` (the application JS type) and `TWire` (the database driver wire format) — plus `JsonValue` for build-time contract artifacts. The codec translates `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue` during contract emission and loading.\n *\n * Three representations participate:\n * - **Input** (`TInput`): the JS type at the application boundary.\n * - **Wire** (`TWire`): the format exchanged with the database driver.\n * - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.\n *\n * The runtime instance carries only its `id` (the descriptor's `codecId`, set by the factory) and the four conversion methods. Static metadata (`traits`, `targetTypes`, `meta`) and the build-time `renderOutputType` renderer live on the {@link CodecDescriptor} keyed by `codecId` — the read-surface single source of truth. Consumers that need them resolve through `descriptorFor(codecId)`.\n *\n * Codec methods split into two groups:\n *\n * - **Query-time** methods (`encode`, `decode`) run per row/parameter at the IO boundary; they are required and Promise-returning. The per-family codec factory accepts sync or async author functions and lifts sync ones to Promise-shaped methods automatically.\n * - **Build-time** methods (`encodeJson`, `decodeJson`) run when the contract is serialized or loaded. They stay synchronous so contract validation and client construction are synchronous.\n *\n * Target-family codec interfaces extend this base; family-specific concerns (e.g. the SQL `column?` per-call context) layer on through the `CodecCallContext` extension pattern.\n */\nexport interface Codec<\n Id extends string = string,\n TTraits extends readonly CodecTrait[] = readonly CodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> {\n /** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). The factory sets this to the descriptor's `codecId`; consumers use it as a back-reference for descriptor lookups and for decode-error diagnostics. */\n readonly id: Id;\n /** Phantom carrier for the `TTraits` generic; type-only, undefined at runtime. Runtime traits live on {@link CodecDescriptor.traits}. Implemented as a string-key phantom (`__codecTraits`) rather than `unique symbol` so bundlers that split `.d.ts` chunks do not strand symbol identity on chunk-private paths (the same `TS2742` family that the public re-export of `CodecTypes` works around). */\n readonly __codecTraits?: TTraits;\n /** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(value) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */\n encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;\n /** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(wire) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */\n decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;\n /** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */\n encodeJson(value: TInput): JsonValue;\n /** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `family.deserializeContract`. */\n decodeJson(json: JsonValue): TInput;\n}\n\n/**\n * Abstract base class for concrete codec implementations.\n *\n * Codec authors extend this class with their typed `Id`, `TTraits`, `TWire`, `TInput` and override `encode`/`decode` (and optionally `encodeJson`/`decodeJson`). The runtime instance carries only its `id` (proxied through the descriptor so alias subclasses inherit the descriptor's id automatically) and the conversion methods — static metadata lives on the {@link CodecDescriptor}.\n */\nexport abstract class CodecImpl<\n Id extends string = string,\n TTraits extends readonly CodecTrait[] = readonly CodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> implements Codec<Id, TTraits, TWire, TInput>\n{\n /**\n * Variance-erased descriptor reference. Concrete codec subclasses receive the typed descriptor in their own constructors and forward it via `super(descriptor)`; the variance erasure lives at this base because the abstract surface can't carry the concrete `TParams`.\n */\n // biome-ignore lint/suspicious/noExplicitAny: variance-erased descriptor reference; subclasses retain typed access via their own state\n constructor(public readonly descriptor: CodecDescriptor<any>) {}\n\n get id(): Id {\n return this.descriptor.codecId as Id;\n }\n\n abstract encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;\n abstract decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;\n abstract encodeJson(value: TInput): JsonValue;\n abstract decodeJson(json: JsonValue): TInput;\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Codec } from './codec';\n\nexport type CodecTrait = 'equality' | 'order' | 'boolean' | 'numeric' | 'textual';\n\n/**\n * Serializable codec identity carried by every codec-bearing AST node.\n *\n * `(codecId, typeParams?)` is the single fact the runtime needs to materialize a codec via `descriptorFor(codecId).factory(typeParams)(ctx)`. The pair is content-keyed: two refs with the same `codecId` and structurally equal `typeParams` (regardless of object key ordering) resolve to the same memoized {@link Codec} instance.\n *\n * `typeParams` is `JsonValue`-constrained so the ref survives JSON serialization (relevant for AST-embedded migration ops). Non-parameterized codecs leave `typeParams` undefined; the descriptor's `paramsSchema` validates the value at the JSON boundary.\n *\n * Family-agnostic by design — both SQL and Mongo AST nodes carry `codec: CodecRef | undefined`, and the resolver is the only dispatch path that survives serialization.\n */\nexport interface CodecRef {\n readonly codecId: string;\n readonly typeParams?: JsonValue;\n}\n\n/**\n * Per-call context the runtime threads to every `codec.encode` / `codec.decode` invocation for a single `runtime.execute()` call.\n *\n * The framework-level shape is family-agnostic and carries one field:\n *\n * - `signal?: AbortSignal` — per-query cancellation. The runtime returns a `RUNTIME.ABORTED` envelope when the signal aborts; codec authors who forward `signal` to their underlying SDK get true cancellation of in-flight network calls.\n *\n * Family layers extend this base with their own shape-of-call metadata: the SQL family adds `column?: SqlColumnRef` via `SqlCodecCallContext` (see `@prisma-next/sql-relational-core`). Mongo currently uses this framework type unchanged. Column metadata is intentionally **not** on the framework type — it is a SQL-family concept rooted in SQL's `(table, column)` addressing model and would not generalise to other families.\n *\n * The interface is named explicitly (not inlined) so future framework fields and family extensions can land additively without breaking codec author signatures.\n */\nexport interface CodecCallContext {\n readonly signal?: AbortSignal;\n}\n\n/**\n * Codec-id-keyed read surface threaded into emit and authoring paths.\n *\n * - `get(id)` returns a representative {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults). For parameterized codecs whose factory requires concrete params, this may return `undefined` — use `CodecRegistry.forCodecRef` instead.\n * - `targetTypesFor(id)` exposes the codec-id-keyed `targetTypes` metadata the runtime instance no longer carries (TML-2357). Returns the same array `CodecDescriptor.targetTypes` would; for Mongo (whose registration doesn't yet resolve through the unified descriptor map — TML-2324) the family-side assembly populates this directly from the contributor's codec metadata.\n * - `metaFor(id)` exposes the codec-id-keyed `meta` (e.g. SQL-side `db.sql.postgres.nativeType`) the runtime instance no longer carries.\n * - `renderOutputTypeFor(id, params)` exposes the codec-id-keyed `renderOutputType` renderer the runtime instance no longer carries. Returns `undefined` when the codec doesn't render a custom type or when the codec id is unknown.\n */\nexport interface CodecLookup {\n get(id: string): Codec | undefined;\n targetTypesFor(id: string): readonly string[] | undefined;\n metaFor(id: string): CodecMeta | undefined;\n renderOutputTypeFor(id: string, params: Record<string, unknown>): string | undefined;\n /** Codec-id-keyed `renderInputType` renderer for the `contract.d.ts` input position. Optional so existing lookups need not provide it; returns `undefined` when the codec renders no custom input type or the id is unknown. */\n renderInputTypeFor?(id: string, params: Record<string, unknown>): string | undefined;\n}\n\n/**\n * Full codec registry — the read surface of {@link CodecLookup} plus codec resolution by ref or\n * column coordinate. Built once by `extractCodecLookup` and passed by reference to adapters and\n * other consumers that need to materialise codecs at runtime.\n *\n * - `forCodecRef(ref)` materialises a codec from a {@link CodecRef}. Throws\n * `RUNTIME.CODEC_DESCRIPTOR_MISSING` for unknown ids and `RUNTIME.TYPE_PARAMS_INVALID` on param\n * schema rejection.\n * - `forColumn(namespaceId, table, column)` returns the codec for a specific column coordinate, or\n * `undefined` when no column-to-codec mapping is present. This registry is contract-free so it\n * always returns `undefined` — the method exists so the object structurally satisfies the SQL\n * `ContractCodecRegistry` interface.\n */\nexport interface CodecRegistry extends CodecLookup {\n forCodecRef(ref: CodecRef): Codec;\n forColumn(namespaceId: string, table: string, column: string): Codec | undefined;\n}\n\nexport const emptyCodecLookup: CodecLookup = {\n get: () => undefined,\n targetTypesFor: () => undefined,\n metaFor: () => undefined,\n renderOutputTypeFor: () => undefined,\n};\n\n/**\n * Family-agnostic per-instance context supplied by the framework when applying a higher-order codec factory. Allows stateful codecs (e.g. column-scoped encryption) to derive per-instance state from the materialization site.\n *\n * - `name` — the family-agnostic instance identity. For SQL, the runtime populates this as the `storage.types` instance name (e.g. `Embedding1536`) for typeRef-shaped columns, an inline-column sentinel (`<col:Document.embedding>`) for inline-`typeParams` columns, a shared codec-id sentinel (`<codec:pg/text@1>`) for non-parameterized codec ids, or the canonical cache key (`<codecId>:<canonicalizeJson(typeParams)>`) for ad-hoc refs the contract walk did not pre-populate. Other families pick the analogous identity for their materialization sites.\n *\n * Family-specific extensions (e.g. {@link import('@prisma-next/sql-relational-core/ast').SqlCodecInstanceContext} in the SQL layer) augment this base with domain-shaped column-set metadata. Codec authors target the base when they don't read family-specific metadata; they target the family extension when they do.\n */\nexport interface CodecInstanceContext {\n readonly name: string;\n}\n\n/**\n * Family-agnostic codec metadata. Family-specific extensions augment the base `db.<family>.<target>` block with native-type information; the base shape is an empty object so non-relational codecs can carry no metadata.\n */\nexport interface CodecMeta {\n readonly db?: Record<string, unknown>;\n}\n\n/**\n * Standard Schema validator for `void` params. Accepts only `undefined` (or absent input); rejects any other value so a contract that tries to thread `typeParams` through a non-parameterized codec id fails fast at the JSON boundary instead of silently coercing the value away. Used by the framework-supplied non-parameterized descriptor synthesizer.\n */\nexport const voidParamsSchema: StandardSchemaV1<void> = {\n '~standard': {\n version: 1,\n vendor: 'prisma-next',\n validate: (input) =>\n input === undefined\n ? { value: undefined }\n : {\n issues: [\n {\n message: 'unexpected typeParams for non-parameterized codec (void params expected)',\n },\n ],\n },\n },\n};\n","/**\n * Codec descriptor interface (consumer surface) and abstract `CodecDescriptorImpl` base (codec-author surface).\n *\n * Consumers depend on the {@link CodecDescriptor} interface — it is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema`; optional `renderOutputType`). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.\n *\n * Codec authors `extend` the {@link CodecDescriptorImpl} abstract class to declare their codec id, traits, target types, params schema, the `factory(params)` that materializes a typed `Codec<...>`, and (optionally) a `renderOutputType(params)` for the emit path.\n *\n * The factory's method-level generic is the load-bearing piece for literal preservation: per-codec column helpers invoke `descriptor.factory(...)` *directly*, and the direct call binds the generic at its call site. Type extraction (`ReturnType<D['factory']>`, structural matching) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.\n */\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Codec } from './codec';\nimport {\n type CodecInstanceContext,\n type CodecMeta,\n type CodecTrait,\n voidParamsSchema,\n} from './codec-types';\n\n/**\n * Unified codec descriptor. Every codec in the framework registers through this shape — non-parameterized codecs use `P = void` and a constant factory that returns the same shared codec instance for every column; parameterized codecs use a non-empty `P` and a curried higher-order factory that returns a per-instance codec.\n *\n * The descriptor is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema` for JSON-boundary validation; optional `renderOutputType` for the `contract.d.ts` emit path). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.\n *\n * Whether a codec id \"is parameterized\" stops being a registration-time distinction — it's a property of `P` on the descriptor. The descriptor map indexes every descriptor by `codecId`; both `descriptorFor(codecId)` and `forColumn(table, column)` resolve through the same map without branching on parameterization.\n *\n * @template P - The shape of the params accepted by the factory (`void` for non-parameterized codecs; a record like `{ length: number }` for parameterized codecs).\n *\n * Codec-registry-unification project § Decision.\n */\nexport interface CodecDescriptor<P = void> {\n /** The codec ID this descriptor applies to (e.g. `pg/vector@1`, `pg/text@1`). */\n readonly codecId: string;\n /** Semantic traits for operator gating (e.g. equality, order, numeric). */\n readonly traits: readonly CodecTrait[];\n /** Database-native type names this codec handles (e.g. `['timestamptz']`). */\n readonly targetTypes: readonly string[];\n /** Optional family-specific metadata (e.g. SQL-side `db.sql.postgres.nativeType`). */\n readonly meta?: CodecMeta;\n /** Standard Schema validator for the factory's params. Validates JSON-sourced params at the contract boundary (PSL → IR; `contract.json` → runtime). For non-parameterized codecs (`P = void`), the schema validates `void`/`undefined` — the framework supplies no params at the call boundary. */\n readonly paramsSchema: StandardSchemaV1<P>;\n /** Whether this descriptor is parameterized — i.e. its `paramsSchema` is something other than the singleton `voidParamsSchema`. Consumers that need to gate column-aware dispatch read this directly rather than threading a free-floating `(codecId) => boolean` callback. */\n readonly isParameterized: boolean;\n /** Emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for given params (e.g. `Vector<1536>`). Optional; absent renderers cause the emitter to fall back to the codec's base output type. Non-parameterized codecs typically omit it. */\n readonly renderOutputType?: (params: P) => string | undefined;\n /** Emit-path string renderer for the `contract.d.ts` *input* position (create/update values). Returns the TypeScript input type expression for given params. Optional; absent renderers fall back to the codec's base input type. A codec supplies this when its write type is narrower than the generic codec input — e.g. an enum whose input should be the literal member union, not `string`. */\n readonly renderInputType?: (params: P) => string | undefined;\n /** The curried higher-order codec. For non-parameterized codecs, the factory is constant — every call returns the same shared codec instance. For parameterized codecs, the factory is called once per `storage.types` instance (or once per inline-`typeParams` column), with `ctx` carrying the column set the resulting codec serves. */\n readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;\n}\n\n/**\n * Variance-erased {@link CodecDescriptor} alias. `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly), so `CodecDescriptor<P>` does not extend `CodecDescriptor<unknown>` for specific `P`. Heterogeneous descriptor collections — e.g. `SqlStaticContributions.codecs:` returning a list that mixes parameterized and non-parameterized descriptors — type against this alias and narrow per codec id at the consumer.\n *\n * Codec-registry-unification spec § Decision: every codec resolves through one descriptor map; reads are non-branching.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure for heterogeneous descriptor collections\nexport type AnyCodecDescriptor = CodecDescriptor<any>;\n\n/**\n * Abstract base class for concrete codec descriptors.\n *\n * Codec authors extend this class with their typed `TParams` and declare `codecId`, `traits`, `targetTypes`, `paramsSchema`, the curried `factory(params)`, and (optionally) `renderOutputType`.\n *\n * Implements the {@link CodecDescriptor} interface so a concrete subclass instance is directly usable wherever the framework expects a `CodecDescriptor<P>`.\n */\nexport abstract class CodecDescriptorImpl<TParams = void> implements CodecDescriptor<TParams> {\n abstract readonly codecId: string;\n abstract readonly traits: readonly CodecTrait[];\n abstract readonly targetTypes: readonly string[];\n readonly meta?: CodecMeta;\n\n abstract readonly paramsSchema: StandardSchemaV1<TParams>;\n\n /** Boolean derived from `paramsSchema`: `true` whenever the schema is not the singleton `voidParamsSchema`. */\n get isParameterized(): boolean {\n return this.paramsSchema !== voidParamsSchema;\n }\n\n /** Optional emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for the given params (e.g. `Vector<1536>`). Non-parameterized codecs typically omit it. */\n renderOutputType?(params: TParams): string | undefined;\n\n /** Optional emit-path string renderer for the `contract.d.ts` input position. Returns the TypeScript input type expression for the given params; supplied when the write type is narrower than the generic codec input (e.g. an enum's literal member union). */\n renderInputType?(params: TParams): string | undefined;\n\n /**\n * Materialize a curried codec factory for the given params. Concrete subclasses override with a typed return type (e.g. `factory<N>(params: { length: N }): (ctx) => VectorCodec<N>`); per-codec helpers read the typed return at the *direct* call site, which is what preserves method-level generics. Type extraction (e.g. `ReturnType<D['factory']>`) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.\n */\n abstract factory(\n params: TParams,\n ): (ctx: CodecInstanceContext) => Codec<string, readonly CodecTrait[], unknown, unknown>;\n}\n","/**\n * `column()` packager + `ColumnSpec<R, P>` shape + `ColumnHelperFor<D>` variants for tying per-codec column helpers to their descriptor.\n *\n * `ColumnSpec<R, P>` extends {@link ColumnTypeDescriptor} so it remains a drop-in for contract authoring sites that consume `ColumnTypeDescriptor` shapes — both types live at the framework-components layer so the `extends` clause is real (no structural mirror).\n *\n * `column()` is a trivial, non-polymorphic packager. Generic over `R` (the codec instance type returned by the descriptor's curried factory) and `P` (the typeParams record). The framework does NOT try to infer `R` and `P` from a descriptor — that path is the variance trap. Per-codec helpers absorb the descriptor relationship instead and tie themselves to their descriptor via `satisfies ColumnHelperFor<D>` or `satisfies ColumnHelperForStrict<D>`.\n */\n\nimport type { CodecDescriptor } from './codec-descriptor';\nimport type { CodecInstanceContext } from './codec-types';\n\n/**\n * Authored column-type descriptor — the data shape an authoring site (PSL or TypeScript builders) attaches to a column to identify its codec and its native database type.\n *\n * Lives at the framework-components layer alongside the codec types so codec-author packages (e.g. column-spec / `column()` packagers) can extend it directly without crossing layer boundaries.\n *\n * @template TCodecId Narrowed codec id literal for sites that thread a specific codec id through the type system.\n */\nexport type ColumnTypeDescriptor<TCodecId extends string = string> = {\n readonly codecId: TCodecId;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown> | undefined;\n readonly typeRef?: string;\n};\n\n/**\n * Column spec carrying the codec factory closure alongside the {@link ColumnTypeDescriptor} fields. Codec authors return a `ColumnSpec` from per-codec column helpers; the runtime materializes the codec instance by calling `codecFactory(ctx)` once it knows the column's `CodecInstanceContext`.\n *\n * Extends {@link ColumnTypeDescriptor} so `ColumnSpec` instances flow directly into contract-authoring sites that consume the descriptor shape — no structural mirroring required.\n */\nexport interface ColumnSpec<R, P extends Record<string, unknown> | undefined>\n extends ColumnTypeDescriptor {\n readonly codecFactory: (ctx: CodecInstanceContext) => R;\n readonly typeParams: P;\n}\n\n/**\n * Trivial column packager. Per-codec helpers call this directly with the result of `descriptor.factory(params)` — direct method invocation binds the descriptor's method-level generic at the call site and the literal flows through `R`.\n *\n * `nativeType` is the column's database-native type spelling — the value the postgres adapter's migration planner, the SQL renderer's cast policy, and the contract's `meta.db.<family>.<target>.nativeType` slot read. Per-codec helpers pass the literal native-type string for their codec (e.g. `'text'`, `'int4'`, `'character varying'`); for codecs whose native-type spelling depends on parameters (none today; reserved for future shapes), the helper computes the rendered string before calling `column`. The framework does not derive the value from `codecId` — that mapping is target-specific and lives at the helper.\n */\nexport function column<R, P extends Record<string, unknown> | undefined>(\n codecFactory: (ctx: CodecInstanceContext) => R,\n codecId: string,\n typeParams: P,\n nativeType: string,\n): ColumnSpec<R, P> {\n return {\n codecFactory,\n codecId,\n typeParams,\n nativeType,\n };\n}\n\n/**\n * Coarse `satisfies` shape — checks the helper's typeParams record matches the descriptor's factory params. Catches \"wrong typeParams shape\" wiring mistakes; does NOT catch \"wrong descriptor's factory\" mistakes (the codec slot is left as `unknown`).\n *\n * Use when the codec's `ReturnType<factory>` is unstable (e.g. heavily overloaded factories where extraction widens too much).\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern\nexport type ColumnHelperFor<D extends CodecDescriptor<any>> = (\n // biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference\n ...args: any[]\n) => ColumnSpec<unknown, ColumnHelperParams<D>>;\n\n/**\n * Strict `satisfies` shape — also checks the helper's codec is at least the *base* codec instance type the descriptor's factory returns. `ReturnType<ReturnType<D['factory']>>` widens method generics to their constraint, so this only sanity-checks the wiring at the base type level. Literal preservation comes from the direct `descriptor.factory(...)` call inside the helper, not from `satisfies`.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern\nexport type ColumnHelperForStrict<D extends CodecDescriptor<any>> = (\n // biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference\n ...args: any[]\n) => ColumnSpec<ReturnType<ReturnType<D['factory']>>, ColumnHelperParams<D>>;\n\n/**\n * Coerce a descriptor's `factory` first parameter into the typeParams shape `ColumnSpec` accepts. Non-parameterized descriptors (factory with no params, or `params: void`) collapse to `undefined`; parameterized descriptors keep the params record shape.\n */\n// biome-ignore lint/suspicious/noExplicitAny: variance erasure — see above\ntype ColumnHelperParams<D extends CodecDescriptor<any>> =\n Parameters<D['factory']>[0] extends Record<string, unknown>\n ? Parameters<D['factory']>[0]\n : undefined;\n"],"mappings":";;;;;;;AA0DA,IAAsB,YAAtB,MAMA;CAK8B;;;;CAA5B,YAAY,YAAkD;EAAlC,KAAA,aAAA;CAAmC;CAE/D,IAAI,KAAS;EACX,OAAO,KAAK,WAAW;CACzB;AAMF;;;ACTA,MAAa,mBAAgC;CAC3C,WAAW,KAAA;CACX,sBAAsB,KAAA;CACtB,eAAe,KAAA;CACf,2BAA2B,KAAA;AAC7B;;;;AAuBA,MAAa,mBAA2C,EACtD,aAAa;CACX,SAAS;CACT,QAAQ;CACR,WAAW,UACT,UAAU,KAAA,IACN,EAAE,OAAO,KAAA,EAAU,IACnB,EACE,QAAQ,CACN,EACE,SAAS,2EACX,CACF,EACF;AACR,EACF;;;;;;;;;;AC/CA,IAAsB,sBAAtB,MAA8F;CAI5F;;CAKA,IAAI,kBAA2B;EAC7B,OAAO,KAAK,iBAAiB;CAC/B;AAcF;;;;;;;;AClDA,SAAgB,OACd,cACA,SACA,YACA,YACkB;CAClB,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}

@@ -1,2 +0,2 @@

import { S as checkContractComponentRequirements, _ as PackRefBase, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, g as FamilyPackRef, h as FamilyInstance, i as ComponentDescriptor, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, o as ContractComponentRequirementsCheckInput, p as ExtensionPackRef, r as AdapterPackRef, s as ContractComponentRequirementsCheckResult, t as AdapterDescriptor, u as DriverPackRef, v as TargetBoundComponentDescriptor, x as TargetPackRef, y as TargetDescriptor } from "./framework-components-DDQXmW0b.mjs";
import { S as checkContractComponentRequirements, _ as PackRefBase, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, g as FamilyPackRef, h as FamilyInstance, i as ComponentDescriptor, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, o as ContractComponentRequirementsCheckInput, p as ExtensionPackRef, r as AdapterPackRef, s as ContractComponentRequirementsCheckResult, t as AdapterDescriptor, u as DriverPackRef, v as TargetBoundComponentDescriptor, x as TargetPackRef, y as TargetDescriptor } from "./framework-components-5hA9ij1v.mjs";

@@ -3,0 +3,0 @@ //#region src/shared/capabilities.d.ts

@@ -1,7 +0,7 @@

import { c as AuthoringEntityTypeNamespace, i as AuthoringContributions, m as AuthoringPslBlockDescriptorNamespace, u as AuthoringFieldNamespace, v as AuthoringTypeNamespace } from "./framework-authoring-R0TYCkvG.mjs";
import { c as CodecLookup } from "./codec-DCQAerzB.mjs";
import { A as LoweredDefaultResult, C as ControlMutationDefaultEntry, D as DefaultFunctionLoweringHandler, E as DefaultFunctionLoweringContext, F as SourceSpan, M as MutationDefaultGeneratorDescriptor, N as ParsedDefaultFunctionCall, O as DefaultFunctionRegistry, P as SourceDiagnostic, T as ControlMutationDefaults, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, j as LoweredDefaultValue, k as DefaultFunctionRegistryEntry, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, v as TargetBoundComponentDescriptor, w as ControlMutationDefaultRegistry, y as TargetDescriptor } from "./framework-components-DDQXmW0b.mjs";
import { o as CodecRegistry } from "./codec-types-yY3eSmi0.mjs";
import { d as AuthoringFieldNamespace, h as AuthoringPslBlockDescriptorNamespace, i as AuthoringContributions, l as AuthoringEntityTypeNamespace, y as AuthoringTypeNamespace } from "./framework-authoring-CJC4jwGo.mjs";
import { A as LoweredDefaultResult, C as ControlMutationDefaultEntry, D as DefaultFunctionLoweringHandler, E as DefaultFunctionLoweringContext, F as SourceSpan, M as MutationDefaultGeneratorDescriptor, N as ParsedDefaultFunctionCall, O as DefaultFunctionRegistry, P as SourceDiagnostic, T as ControlMutationDefaults, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, j as LoweredDefaultValue, k as DefaultFunctionRegistryEntry, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, v as TargetBoundComponentDescriptor, w as ControlMutationDefaultRegistry, y as TargetDescriptor } from "./framework-components-5hA9ij1v.mjs";
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { t as EmissionSpi } from "./emission-types-vfpSTe63.mjs";
import { m as PslDocumentAst } from "./psl-ast-Cn50B-UG.mjs";
import { t as EmissionSpi } from "./emission-types-C561PwcN.mjs";
import { m as PslDocumentAst } from "./psl-ast-B-C_9dWr.mjs";
import { Contract, ContractMarkerRecord, ControlPolicy, LedgerEntryRecord } from "@prisma-next/contract/types";

@@ -349,3 +349,3 @@ import { ImportRequirement, ImportRequirement as ImportRequirement$1 } from "@prisma-next/ts-render";

readonly extensionIds: ReadonlyArray<string>;
readonly codecLookup: CodecLookup;
readonly codecLookup: CodecRegistry;
readonly authoringContributions: AssembledAuthoringContributions;

@@ -391,3 +391,3 @@ readonly scalarTypeDescriptors: ReadonlyMap<string, string>;

id: string;
}, 'types' | 'id'>>): CodecLookup;
}, 'types' | 'id'>>): CodecRegistry;
interface DependencyDeclaringDescriptor {

@@ -496,15 +496,2 @@ readonly id: string;

/**
* A lowered query statement as stored in ops.json.
* Contains the SQL string and parameter values — ready for execution.
* Lowering from query builder AST to SQL happens at verify time.
*
* The Postgres `dataTransform` factory uses this shape internally to
* carry the user's lowered `check`/`run` plans before wrapping them
* into precheck/execute/postcheck steps on the unified migration op.
*/
interface SerializedQueryPlan {
readonly sql: string;
readonly params: readonly unknown[];
}
/**
* Policy defining which operation classes are allowed during a migration.

@@ -591,5 +578,6 @@ */

* the return type via covariant return (e.g. SQL targets return
* `SqlMigrationPlanOperation<TTargetDetails>`).
* `SqlMigrationPlanOperation<TTargetDetails>`). May return a Promise when
* the lowering requires async codec resolution (e.g. DDL with literal defaults).
*/
toOp(): MigrationPlanOperation;
toOp(): MigrationPlanOperation | Promise<MigrationPlanOperation>;
}

@@ -625,4 +613,4 @@ /**

};
/** Ordered list of operations to execute. */
readonly operations: readonly MigrationPlanOperation[];
/** Ordered list of operations to execute. May contain Promises for ops that require async codec resolution. */
readonly operations: readonly (MigrationPlanOperation | Promise<MigrationPlanOperation>)[];
/**

@@ -1173,3 +1161,3 @@ * Sorted, deduplicated invariant ids declared by this plan's data-transform

//#endregion
export { APP_SPACE_ID, type AssembledAuthoringContributions, type BaseSchemaIssue, type ContractSerializer, type ContractSpace, type ContractSpaceHeadRef, type ControlAdapterDescriptor, type ControlAdapterInstance, type ControlDriverDescriptor, type ControlDriverInstance, type ControlExtensionDescriptor, type ControlExtensionInstance, type ControlFamilyDescriptor, type ControlFamilyInstance, type ControlMutationDefaultEntry, type ControlMutationDefaultRegistry, type ControlMutationDefaults, type ControlStack, type ControlTargetDescriptor, type ControlTargetInstance, type CoreSchemaView, type CreateControlStackInput, type DefaultFunctionLoweringContext, type DefaultFunctionLoweringHandler, type DefaultFunctionRegistry, type DefaultFunctionRegistryEntry, type EmitContractResult, type EnumValuesChangedIssue, type ImportRequirement, type IntrospectSchemaResult, type LoweredDefaultResult, type LoweredDefaultValue, type MigratableTargetDescriptor, type MigrationMetadata, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPackage, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanWithAuthoringSurface, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerFailureResult, type MigrationPlannerResult, type MigrationPlannerSuccessResult, type MigrationRunner, type MigrationRunnerExecutionChecks, type MigrationRunnerFailure, type MigrationRunnerPerSpaceOptions, type MigrationRunnerPerSpaceSuccessValue, type MigrationRunnerResult, type MigrationRunnerSuccessValue, type MigrationScaffoldContext, type MutationDefaultGeneratorDescriptor, type OpFactoryCall, type OperationContext, type OperationPreview, type OperationPreviewCapable, type OperationPreviewStatement, type ParsedDefaultFunctionCall, type PslContractInferCapable, type SchemaIssue, SchemaTreeNode, type SchemaTreeNodeOptions, type SchemaTreeVisitor, type SchemaVerificationNode, type SchemaVerifier, type SchemaVerifyOptions, type SchemaVerifyResult, type SchemaViewCapable, type SchemaViewNodeKind, type SerializedQueryPlan, type SignDatabaseResult, type SourceDiagnostic, type SourceSpan, type TargetMigrationsCapability, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, type VerificationStatus, type VerifierIssueCategory, type VerifierOutcome, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, assembleAuthoringContributions, assembleControlMutationDefaults, assembleScalarTypeDescriptors, assertUniqueCodecOwner, buildExtensionLoadOrder, createControlStack, dispositionForCategory, extractCodecLookup, extractCodecTypeImports, extractComponentIds, extractQueryOperationTypeImports, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaView };
export { APP_SPACE_ID, type AssembledAuthoringContributions, type BaseSchemaIssue, type ContractSerializer, type ContractSpace, type ContractSpaceHeadRef, type ControlAdapterDescriptor, type ControlAdapterInstance, type ControlDriverDescriptor, type ControlDriverInstance, type ControlExtensionDescriptor, type ControlExtensionInstance, type ControlFamilyDescriptor, type ControlFamilyInstance, type ControlMutationDefaultEntry, type ControlMutationDefaultRegistry, type ControlMutationDefaults, type ControlStack, type ControlTargetDescriptor, type ControlTargetInstance, type CoreSchemaView, type CreateControlStackInput, type DefaultFunctionLoweringContext, type DefaultFunctionLoweringHandler, type DefaultFunctionRegistry, type DefaultFunctionRegistryEntry, type EmitContractResult, type EnumValuesChangedIssue, type ImportRequirement, type IntrospectSchemaResult, type LoweredDefaultResult, type LoweredDefaultValue, type MigratableTargetDescriptor, type MigrationMetadata, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPackage, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanWithAuthoringSurface, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerFailureResult, type MigrationPlannerResult, type MigrationPlannerSuccessResult, type MigrationRunner, type MigrationRunnerExecutionChecks, type MigrationRunnerFailure, type MigrationRunnerPerSpaceOptions, type MigrationRunnerPerSpaceSuccessValue, type MigrationRunnerResult, type MigrationRunnerSuccessValue, type MigrationScaffoldContext, type MutationDefaultGeneratorDescriptor, type OpFactoryCall, type OperationContext, type OperationPreview, type OperationPreviewCapable, type OperationPreviewStatement, type ParsedDefaultFunctionCall, type PslContractInferCapable, type SchemaIssue, SchemaTreeNode, type SchemaTreeNodeOptions, type SchemaTreeVisitor, type SchemaVerificationNode, type SchemaVerifier, type SchemaVerifyOptions, type SchemaVerifyResult, type SchemaViewCapable, type SchemaViewNodeKind, type SignDatabaseResult, type SourceDiagnostic, type SourceSpan, type TargetMigrationsCapability, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, type VerificationStatus, type VerifierIssueCategory, type VerifierOutcome, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, assembleAuthoringContributions, assembleControlMutationDefaults, assembleScalarTypeDescriptors, assertUniqueCodecOwner, buildExtensionLoadOrder, createControlStack, dispositionForCategory, extractCodecLookup, extractCodecTypeImports, extractComponentIds, extractQueryOperationTypeImports, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaView };
//# sourceMappingURL=control.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"control.d.mts","names":[],"sources":["../src/control/contract-serializer.ts","../src/control/control-result-types.ts","../src/control/control-instances.ts","../src/control/control-stack.ts","../src/control/control-descriptors.ts","../src/control/control-migration-types.ts","../src/control/control-operation-preview.ts","../src/control/control-schema-view.ts","../src/control/control-capabilities.ts","../src/control/control-spaces.ts","../src/control/schema-verifier.ts","../src/control/verifier-disposition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;UAAiB,kBAAA;EAuBa;;;;;;;;;;;EAX5B,mBAAA,WAA8B,SAAA,GAAY,SAAA,EAAW,IAAA,YAAgB,CAAA;EAAA;;;;;;;;;EAWrE,iBAAA,CAAkB,QAAA,EAAU,SAAA,GAAY,UAAA;EAkBN;;;;AC5DpC;;;ED4DoC,SATzB,mBAAA,GAAsB,sBAAA;ECnDM;AACvC;;;;AAAsC;AACtC;EAFuC,SD4D5B,WAAA,GAAc,WAAA;AAAA;;;cC5DZ,0BAAA;AAAA,cACA,yBAAA;AAAA,cACA,2BAAA;AAAA,cACA,0BAAA;AAAA,UAEI,gBAAA;EAAA,SACN,YAAA;EAAA,SACA,UAAA;EAAA,SACA,IAAA,GAAO,QAAQ,CAAC,MAAA;AAAA;AAAA,UAGV,oBAAA;EAAA,SACN,EAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;IAAA,SACE,WAAA;IAAA,S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W,SAAA,IAAa,uBAAA;;;;;;;;;;;;;;AR9C7D;;;;;;;;cSGa,YAAA;;;;;;;;;;;UAYI,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAU;AAAA;;;;;;ATwBe;;;;AC5DpC;;;;AAAuC;UQqDtB,gBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,EAAU,iBAAA;EAAA,SACV,GAAA,WAAc,sBAAsB;AAAA;ARtD/C;;;;AAAwC;AACxC;;;;AAAuC;AAEvC;;;;;;;AAHA,UQ0EiB,aAAA,mBAAgC,QAAA,GAAW,QAAA;EAAA,SACjD,YAAA,EAAc,SAAA;EAAA,SACd,UAAA,WAAqB,gBAAA;EAAA,SACrB,OAAA,EAAS,oBAAA;AAAA;;;;;;;;;;;;;;;AT5DpB;;;;;;;;;;;UUMiB,cAAA;EACf,YAAA,CAAa,OAAA,EAAS,mBAAA,CAAoB,SAAA,EAAW,OAAA,IAAW,kBAAA;AAAA;;;;;;;UASjD,mBAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,MAAA,EAAQ,OAAO;AAAA;;;;;AVuBU;;;UUbnB,kBAAA;EAAA,SACN,EAAA;EAAA,SACA,MAAA,WAAiB,WAAW;AAAA;;;KC9C3B,kBAAA,GAAqB,sBAAsB;AAAA,KAE3C,eAAA,GAAkB,kBAAkB;;;;;;;;;;AXchD;;;;;;;KWIY,qBAAA;;;;;;;;;;iBAiBI,sBAAA,CACd,aAAA,EAAe,aAAA,EACf,QAAA,EAAU,qBAAA,GACT,eAAA"}
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/control/contract-serializer.ts","../src/control/control-result-types.ts","../src/control/control-instances.ts","../src/control/control-stack.ts","../src/control/control-descriptors.ts","../src/control/control-migration-types.ts","../src/control/control-operation-preview.ts","../src/control/control-schema-view.ts","../src/control/control-capabilities.ts","../src/control/control-spaces.ts","../src/control/schema-verifier.ts","../src/control/verifier-disposition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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,EAAQ,OAAO;AAAA;;;;;AVuBU;;;UUbnB,kBAAA;EAAA,SACN,EAAA;EAAA,SACA,MAAA,WAAiB,WAAW;AAAA;;;KC9C3B,kBAAA,GAAqB,sBAAsB;AAAA,KAE3C,eAAA,GAAkB,kBAAkB;;;;;;;;;;AXchD;;;;;;;KWIY,qBAAA;;;;;;;;;;iBAiBI,sBAAA,CACd,aAAA,EAAe,aAAA,EACf,QAAA,EAAU,qBAAA,GACT,eAAA"}

@@ -1,2 +0,3 @@

import { c as isAuthoringFieldPresetDescriptor, d as mergeAuthoringNamespaces, l as isAuthoringPslBlockDescriptor, s as isAuthoringEntityTypeDescriptor, t as assertNoCrossRegistryCollisions, u as isAuthoringTypeConstructorDescriptor } from "./framework-authoring-CnwPJCO4.mjs";
import { n as materializeCodec, r as resolveCodecDescriptorOrThrow, t as CONTRACT_CODEC_DESCRIPTOR_MISSING } from "./resolve-codec-D8EPZosv.mjs";
import { c as isAuthoringFieldPresetDescriptor, d as mergeAuthoringNamespaces, l as isAuthoringPslBlockDescriptor, s as isAuthoringEntityTypeDescriptor, t as assertNoCrossRegistryCollisions, u as isAuthoringTypeConstructorDescriptor } from "./framework-authoring-Dv5F3EFC.mjs";
import { blindCast } from "@prisma-next/utils/casts";

@@ -170,5 +171,7 @@ //#region src/control/control-capabilities.ts

const byId = /* @__PURE__ */ new Map();
const descriptorsById = /* @__PURE__ */ new Map();
const targetTypesById = /* @__PURE__ */ new Map();
const metaById = /* @__PURE__ */ new Map();
const renderersById = /* @__PURE__ */ new Map();
const inputRenderersById = /* @__PURE__ */ new Map();
const owners = /* @__PURE__ */ new Map();

@@ -187,5 +190,7 @@ for (const descriptor of descriptors) {

owners.set(codecDescriptor.codecId, descriptorId);
descriptorsById.set(codecDescriptor.codecId, codecDescriptor);
if (Array.isArray(codecDescriptor.targetTypes)) targetTypesById.set(codecDescriptor.codecId, codecDescriptor.targetTypes);
if (codecDescriptor.meta !== void 0) metaById.set(codecDescriptor.codecId, codecDescriptor.meta);
if (typeof codecDescriptor.renderOutputType === "function") renderersById.set(codecDescriptor.codecId, codecDescriptor.renderOutputType);
if (typeof codecDescriptor.renderInputType === "function") inputRenderersById.set(codecDescriptor.codecId, codecDescriptor.renderInputType);
if (!byId.has(codecDescriptor.codecId)) if (codecDescriptor.isParameterized) try {

@@ -203,5 +208,10 @@ const representative = codecDescriptor.factory({})({ name: `<lookup:${codecDescriptor.codecId}>` });

get: (id) => byId.get(id),
forCodecRef(ref) {
return materializeCodec(resolveCodecDescriptorOrThrow((id) => descriptorsById.get(id), ref, CONTRACT_CODEC_DESCRIPTOR_MISSING), ref, { name: `<ref:${ref.codecId}>` });
},
forColumn: () => void 0,
targetTypesFor: (id) => targetTypesById.get(id),
metaFor: (id) => metaById.get(id),
renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params)
renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params),
renderInputTypeFor: (id, params) => inputRenderersById.get(id)?.(params)
};

@@ -208,0 +218,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"control.mjs","names":[],"sources":["../src/control/control-capabilities.ts","../src/control/control-result-types.ts","../src/control/control-schema-view.ts","../src/control/control-spaces.ts","../src/control/control-stack.ts","../src/control/verifier-disposition.ts"],"sourcesContent":["import type { ControlTargetDescriptor } from './control-descriptors';\nimport type { ControlFamilyInstance } from './control-instances';\nimport type { MigrationPlanOperation, TargetMigrationsCapability } from './control-migration-types';\nimport type { OperationPreview } from './control-operation-preview';\nimport type { CoreSchemaView } from './control-schema-view';\nimport type { PslDocumentAst } from './psl-ast';\n\nexport interface MigratableTargetDescriptor<\n TFamilyId extends string,\n TTargetId extends string,\n TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<\n TFamilyId,\n unknown\n >,\n> extends ControlTargetDescriptor<TFamilyId, TTargetId> {\n readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, TFamilyInstance>;\n}\n\nexport function hasMigrations<TFamilyId extends string, TTargetId extends string>(\n target: ControlTargetDescriptor<TFamilyId, TTargetId>,\n): target is MigratableTargetDescriptor<TFamilyId, TTargetId> {\n return 'migrations' in target && !!(target as Record<string, unknown>)['migrations'];\n}\n\nexport interface SchemaViewCapable<TSchemaIR = unknown> {\n toSchemaView(schema: TSchemaIR): CoreSchemaView;\n}\n\nexport function hasSchemaView<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & SchemaViewCapable<TSchemaIR> {\n return (\n 'toSchemaView' in instance &&\n typeof (instance as Record<string, unknown>)['toSchemaView'] === 'function'\n );\n}\n\n/**\n * Capability declaring that a family can infer a PSL contract AST from its\n * opaque introspected schema IR. Consumed by `prisma-next contract infer`.\n */\nexport interface PslContractInferCapable<TSchemaIR = unknown> {\n inferPslContract(schemaIR: TSchemaIR): PslDocumentAst;\n}\n\nexport function hasPslContractInfer<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & PslContractInferCapable<TSchemaIR> {\n return (\n 'inferPslContract' in instance &&\n typeof (instance as Record<string, unknown>)['inferPslContract'] === 'function'\n );\n}\n\n/**\n * Capability declaring that a family can render a textual preview of migration\n * operations for the CLI's \"DDL preview\" output. SQL families emit\n * `language: 'sql'` statements; Mongo families emit `language: 'mongodb-shell'`.\n */\nexport interface OperationPreviewCapable {\n toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;\n}\n\nexport function hasOperationPreview<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & OperationPreviewCapable {\n return (\n 'toOperationPreview' in instance &&\n typeof (instance as Record<string, unknown>)['toOperationPreview'] === 'function'\n );\n}\n","export const VERIFY_CODE_MARKER_MISSING = 'PN-RUN-3001';\nexport const VERIFY_CODE_HASH_MISMATCH = 'PN-RUN-3002';\nexport const VERIFY_CODE_TARGET_MISMATCH = 'PN-RUN-3003';\nexport const VERIFY_CODE_SCHEMA_FAILURE = 'PN-RUN-3010';\n\nexport interface OperationContext {\n readonly contractPath?: string;\n readonly configPath?: string;\n readonly meta?: Readonly<Record<string, unknown>>;\n}\n\nexport interface VerifyDatabaseResult {\n readonly ok: boolean;\n readonly code?: string;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly marker?: {\n readonly storageHash?: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly missingCodecs?: readonly string[];\n readonly codecCoverageSkipped?: boolean;\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface BaseSchemaIssue {\n readonly kind:\n | 'missing_schema'\n | 'missing_table'\n | 'missing_column'\n | 'extra_table'\n | 'extra_column'\n | 'extra_primary_key'\n | 'extra_foreign_key'\n | 'extra_unique_constraint'\n | 'extra_index'\n | 'extra_validator'\n | 'type_mismatch'\n | 'type_missing'\n | 'type_values_mismatch'\n | 'nullability_mismatch'\n | 'primary_key_mismatch'\n | 'foreign_key_mismatch'\n | 'unique_constraint_mismatch'\n | 'index_mismatch'\n | 'default_missing'\n | 'default_mismatch'\n | 'extra_default'\n | 'check_missing'\n | 'check_removed'\n | 'check_mismatch';\n readonly table?: string;\n /**\n * Namespace coordinate of the issue's subject (e.g. the schema a SQL\n * table lives in). Populated by family verifiers that have the\n * coordinate in scope when constructing the issue; absent for issues\n * whose family has no namespace concept (e.g. Mongo collections) or\n * whose subject isn't in any contract namespace (e.g. an extra-table\n * issue raised for a table that exists in the live DB but not in the\n * contract).\n *\n * Downstream planners trust this field as the authoritative subject\n * coordinate and do not re-derive it by name lookup. A finer-grained\n * structural split between framework-shared and family-specific issue\n * fields is tracked under a follow-up ticket.\n */\n readonly namespaceId?: string;\n readonly column?: string;\n readonly indexOrConstraint?: string;\n readonly typeName?: string;\n readonly expected?: string;\n readonly actual?: string;\n readonly message: string;\n}\n\nexport interface EnumValuesChangedIssue {\n readonly kind: 'enum_values_changed';\n /**\n * Namespace coordinate of the enum type that changed values. Populated by\n * family verifiers that have the coordinate in scope when constructing the\n * issue. Downstream planners trust this field as the authoritative subject\n * coordinate and do not re-derive it by name lookup.\n */\n readonly namespaceId: string;\n readonly typeName: string;\n readonly addedValues: readonly string[];\n readonly removedValues: readonly string[];\n readonly message: string;\n}\n\nexport type SchemaIssue = BaseSchemaIssue | EnumValuesChangedIssue;\n\nexport interface SchemaVerificationNode {\n readonly status: 'pass' | 'warn' | 'fail';\n readonly kind: string;\n readonly name: string;\n readonly contractPath: string;\n readonly code: string;\n readonly message: string;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly children: readonly SchemaVerificationNode[];\n}\n\nexport interface VerifyDatabaseSchemaResult {\n readonly ok: boolean;\n readonly code?: string;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly schema: {\n readonly issues: readonly SchemaIssue[];\n readonly root: SchemaVerificationNode;\n readonly counts: {\n readonly pass: number;\n readonly warn: number;\n readonly fail: number;\n readonly totalNodes: number;\n };\n };\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath?: string;\n readonly strict: boolean;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface EmitContractResult {\n readonly contractJson: string;\n readonly contractDts: string;\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n}\n\nexport interface IntrospectSchemaResult<TSchemaIR> {\n readonly ok: true;\n readonly summary: string;\n readonly target: {\n readonly familyId: string;\n readonly id: string;\n };\n readonly schema: TSchemaIR;\n readonly meta?: {\n readonly configPath?: string;\n readonly dbUrl?: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface SignDatabaseResult {\n readonly ok: boolean;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly marker: {\n readonly created: boolean;\n readonly updated: boolean;\n readonly previous?: {\n readonly storageHash?: string;\n readonly profileHash?: string;\n };\n };\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n","/**\n * Core schema view types for family-agnostic schema visualization.\n *\n * These types provide a minimal, generic, tree-shaped representation of schemas\n * across families, designed for CLI visualization and lightweight tooling.\n *\n * Families can optionally project their family-specific Schema IR into this\n * core view via the `toSchemaView` method on `FamilyInstance`.\n */\n\nexport type SchemaViewNodeKind =\n | 'root'\n | 'namespace'\n | 'collection'\n | 'entity'\n | 'field'\n | 'index'\n | 'dependency';\n\nexport interface SchemaTreeVisitor<R> {\n visit(node: SchemaTreeNode): R;\n}\n\nexport interface SchemaTreeNodeOptions {\n readonly kind: SchemaViewNodeKind;\n readonly id: string;\n readonly label: string;\n readonly meta?: Record<string, unknown>;\n readonly children?: readonly SchemaTreeNode[];\n}\n\nexport class SchemaTreeNode {\n readonly kind: SchemaViewNodeKind;\n readonly id: string;\n readonly label: string;\n readonly meta?: Record<string, unknown>;\n readonly children?: readonly SchemaTreeNode[];\n\n constructor(options: SchemaTreeNodeOptions) {\n this.kind = options.kind;\n this.id = options.id;\n this.label = options.label;\n if (options.meta !== undefined) this.meta = options.meta;\n if (options.children !== undefined) this.children = options.children;\n Object.freeze(this);\n }\n\n accept<R>(visitor: SchemaTreeVisitor<R>): R {\n return visitor.visit(this);\n }\n}\n\n/**\n * Core schema view providing a family-agnostic tree representation of a schema.\n * Used by CLI and cross-family tooling for visualization.\n */\nexport interface CoreSchemaView {\n readonly root: SchemaTreeNode;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { MigrationMetadata, MigrationPlanOperation } from './control-migration-types';\n\n/**\n * Canonical control-plane identifiers for contract spaces.\n *\n * A contract space is the disjoint `(contract.json, migration-graph)` unit\n * the per-space planner / runner / verifier (project: extension contract\n * spaces, TML-2397) operates on. The application owns one well-known\n * space — the value below — and each loaded extension that contributes\n * schema owns a uniquely-named space.\n *\n * Lives in `framework-components/control` so every layer that has to\n * reason about space identity (the migration tooling, the SQL runtime's\n * marker reader, target-side statement builders, target-side adapters)\n * can import a single value rather than duplicating the literal. Raw\n * `'app'` string literals in framework / target / runtime / adapter\n * source code are forbidden and policed by\n * `scripts/lint-app-space-id.mjs` (wired into `pnpm lint:deps`).\n *\n * @see specs/framework-mechanism.spec.md § 3 — Layout convention (γ).\n */\nexport const APP_SPACE_ID = 'app' as const;\n\n/**\n * Head ref for a contract space — the `(hash, invariants)` tuple\n * a runner targets when applying that space's migration graph. Identical\n * in shape to the on-disk `migrations/<space-id>/refs/head.json` the\n * framework writes per loaded extension, and to the app-space\n * `<projectRoot>/refs/head.json`. Family-agnostic: SQL, Mongo, and any\n * future family share the same head-ref shape.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface ContractSpaceHeadRef {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\n/**\n * Canonical structural shape of a migration package — the unit a planner\n * produces and a runner consumes: a directory name, the metadata\n * envelope, and the operation list.\n *\n * In-memory by default. Readers in `@prisma-next/migration-tools`\n * (`readMigrationPackage` / `readMigrationsDir`) return the augmented\n * {@link import('@prisma-next/migration-tools/package').OnDiskMigrationPackage}\n * variant which adds `dirPath`; everything else operates against the\n * canonical shape so the same value flows through pre-emission\n * authoring, on-disk loading, and runner execution without conversion.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface MigrationPackage {\n readonly dirName: string;\n readonly metadata: MigrationMetadata;\n readonly ops: readonly MigrationPlanOperation[];\n}\n\n/**\n * Canonical structural shape of a contract space — one disjoint\n * `(contractJson, migration-graph)` unit the per-space planner / runner\n * / verifier operates on. The application owns one well-known space\n * ({@link APP_SPACE_ID}); each loaded extension that contributes schema\n * owns a uniquely-named space. Whether a value is the app's space or an\n * extension's space is a control-plane concern; the type carries no\n * such distinction.\n *\n * Generic over the contract so each family pins a typed contract value\n * at consumption time. The SQL family specialises to\n * `ContractSpace<Contract<SqlStorage>>` at the descriptor surface;\n * Mongo's symmetrical `ContractSpace<Contract<MongoStorage>>` will land\n * with that family.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface ContractSpace<TContract extends Contract = Contract> {\n readonly contractJson: TContract;\n readonly migrations: readonly MigrationPackage[];\n readonly headRef: ContractSpaceHeadRef;\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport type { Codec } from '../shared/codec';\nimport type { CodecLookup, CodecMeta } from '../shared/codec-types';\nimport type {\n AuthoringContributions,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n} from '../shared/framework-authoring';\nimport {\n assertNoCrossRegistryCollisions,\n isAuthoringEntityTypeDescriptor,\n isAuthoringFieldPresetDescriptor,\n isAuthoringPslBlockDescriptor,\n isAuthoringTypeConstructorDescriptor,\n mergeAuthoringNamespaces,\n} from '../shared/framework-authoring';\nimport type { ComponentMetadata } from '../shared/framework-components';\nimport type {\n ControlMutationDefaultEntry,\n ControlMutationDefaults,\n MutationDefaultGeneratorDescriptor,\n} from '../shared/mutation-default-types';\nimport type { TypesImportSpec } from '../shared/types-import-spec';\nimport type {\n ControlAdapterDescriptor,\n ControlDriverDescriptor,\n ControlExtensionDescriptor,\n ControlFamilyDescriptor,\n ControlTargetDescriptor,\n} from './control-descriptors';\n\nexport interface AssembledAuthoringContributions {\n readonly field: AuthoringFieldNamespace;\n readonly type: AuthoringTypeNamespace;\n readonly entityTypes: AuthoringEntityTypeNamespace;\n readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport interface ControlStack<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> {\n readonly family: ControlFamilyDescriptor<TFamilyId>;\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter?: ControlAdapterDescriptor<TFamilyId, TTargetId> | undefined;\n readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;\n readonly extensionPacks: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];\n\n readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly queryOperationTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds: ReadonlyArray<string>;\n readonly codecLookup: CodecLookup;\n readonly authoringContributions: AssembledAuthoringContributions;\n readonly scalarTypeDescriptors: ReadonlyMap<string, string>;\n readonly controlMutationDefaults: ControlMutationDefaults;\n}\n\nexport interface CreateControlStackInput<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> {\n readonly family: ControlFamilyDescriptor<TFamilyId>;\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter?: ControlAdapterDescriptor<TFamilyId, TTargetId> | undefined;\n readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;\n readonly extensionPacks?:\n | ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>\n | undefined;\n}\n\nfunction addUniqueId(ids: string[], seen: Set<string>, id: string): void {\n if (!seen.has(id)) {\n ids.push(id);\n seen.add(id);\n }\n}\n\nexport function assertUniqueCodecOwner(options: {\n readonly codecId: string;\n readonly owners: Map<string, string>;\n readonly descriptorId: string;\n readonly entityLabel: string;\n readonly entityOwnershipLabel: string;\n}): void {\n const existingOwner = options.owners.get(options.codecId);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate ${options.entityLabel} for codecId \"${options.codecId}\". ` +\n `Descriptor \"${options.descriptorId}\" conflicts with \"${existingOwner}\". ` +\n `Each codecId can only have one ${options.entityOwnershipLabel}.`,\n );\n }\n}\n\nexport function extractCodecTypeImports(\n descriptors: ReadonlyArray<Pick<ComponentMetadata, 'types'>>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const codecTypes = descriptor.types?.codecTypes;\n if (codecTypes?.import) {\n imports.push(codecTypes.import);\n }\n if (codecTypes?.typeImports) {\n imports.push(...codecTypes.typeImports);\n }\n }\n\n return imports;\n}\n\nexport function extractQueryOperationTypeImports(\n descriptors: ReadonlyArray<Pick<ComponentMetadata, 'types'>>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const queryOperationTypes = descriptor.types?.queryOperationTypes;\n if (queryOperationTypes?.import) {\n imports.push(queryOperationTypes.import);\n }\n }\n\n return imports;\n}\n\nexport function extractComponentIds(\n family: { readonly id: string },\n target: { readonly id: string },\n adapter: { readonly id: string } | undefined,\n extensions: ReadonlyArray<{ readonly id: string }>,\n): ReadonlyArray<string> {\n const ids: string[] = [];\n const seen = new Set<string>();\n\n addUniqueId(ids, seen, family.id);\n addUniqueId(ids, seen, target.id);\n if (adapter) {\n addUniqueId(ids, seen, adapter.id);\n }\n\n for (const ext of extensions) {\n addUniqueId(ids, seen, ext.id);\n }\n\n return ids;\n}\n\nexport function assembleAuthoringContributions(\n descriptors: ReadonlyArray<{ readonly authoring?: AuthoringContributions }>,\n): AssembledAuthoringContributions {\n const field = {} as Record<string, unknown>;\n const type = {} as Record<string, unknown>;\n const entityTypes = {} as Record<string, unknown>;\n const pslBlockDescriptors: Record<string, unknown> = {};\n\n for (const descriptor of descriptors) {\n if (descriptor.authoring?.field) {\n mergeAuthoringNamespaces(\n field,\n descriptor.authoring.field,\n [],\n isAuthoringFieldPresetDescriptor,\n 'field',\n );\n }\n if (descriptor.authoring?.type) {\n mergeAuthoringNamespaces(\n type,\n descriptor.authoring.type,\n [],\n isAuthoringTypeConstructorDescriptor,\n 'type',\n );\n }\n if (descriptor.authoring?.entityTypes) {\n mergeAuthoringNamespaces(\n entityTypes,\n descriptor.authoring.entityTypes,\n [],\n isAuthoringEntityTypeDescriptor,\n 'entity',\n );\n }\n if (descriptor.authoring?.pslBlockDescriptors) {\n mergeAuthoringNamespaces(\n pslBlockDescriptors,\n descriptor.authoring.pslBlockDescriptors,\n [],\n isAuthoringPslBlockDescriptor,\n 'pslBlock',\n );\n }\n }\n\n const fieldNamespace = field as AuthoringFieldNamespace;\n const typeNamespace = type as AuthoringTypeNamespace;\n const entityTypeNamespace = entityTypes as AuthoringEntityTypeNamespace;\n const pslBlockDescriptorNamespace = blindCast<\n AuthoringPslBlockDescriptorNamespace,\n 'merge target accumulator narrows to typed namespace post-merge'\n >(pslBlockDescriptors);\n assertNoCrossRegistryCollisions(\n typeNamespace,\n fieldNamespace,\n entityTypeNamespace,\n pslBlockDescriptorNamespace,\n );\n\n return {\n field: fieldNamespace,\n type: typeNamespace,\n entityTypes: entityTypeNamespace,\n pslBlockDescriptors: pslBlockDescriptorNamespace,\n };\n}\n\nexport function assembleScalarTypeDescriptors(\n descriptors: ReadonlyArray<\n Pick<ComponentMetadata, 'scalarTypeDescriptors'> & { readonly id?: string }\n >,\n): ReadonlyMap<string, string> {\n const result = new Map<string, string>();\n const owners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n const descriptorMap = descriptor.scalarTypeDescriptors;\n if (!descriptorMap) continue;\n const descriptorId = descriptor.id ?? '<unknown>';\n for (const [typeName, codecId] of descriptorMap) {\n const existingOwner = owners.get(typeName);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate scalar type descriptor \"${typeName}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n result.set(typeName, codecId);\n owners.set(typeName, descriptorId);\n }\n }\n\n return result;\n}\n\nexport function assembleControlMutationDefaults(\n descriptors: ReadonlyArray<\n Pick<ComponentMetadata, 'controlMutationDefaults'> & { readonly id?: string }\n >,\n): ControlMutationDefaults {\n const defaultFunctionRegistry = new Map<string, ControlMutationDefaultEntry>();\n const functionOwners = new Map<string, string>();\n const generatorMap = new Map<string, MutationDefaultGeneratorDescriptor>();\n const generatorOwners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n const contributions = descriptor.controlMutationDefaults;\n if (!contributions) continue;\n const descriptorId = descriptor.id ?? '<unknown>';\n\n for (const generatorDescriptor of contributions.generatorDescriptors) {\n const existingOwner = generatorOwners.get(generatorDescriptor.id);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate mutation default generator id \"${generatorDescriptor.id}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n generatorMap.set(generatorDescriptor.id, generatorDescriptor);\n generatorOwners.set(generatorDescriptor.id, descriptorId);\n }\n\n for (const [functionName, handler] of contributions.defaultFunctionRegistry) {\n const existingOwner = functionOwners.get(functionName);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate mutation default function \"${functionName}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n defaultFunctionRegistry.set(functionName, handler);\n functionOwners.set(functionName, descriptorId);\n }\n }\n\n return {\n defaultFunctionRegistry,\n generatorDescriptors: Array.from(generatorMap.values()),\n };\n}\n\nexport function extractCodecLookup(\n descriptors: ReadonlyArray<Pick<ComponentMetadata & { id: string }, 'types' | 'id'>>,\n): CodecLookup {\n const byId = new Map<string, Codec>();\n const targetTypesById = new Map<string, readonly string[]>();\n const metaById = new Map<string, CodecMeta>();\n const renderersById = new Map<string, (params: Record<string, unknown>) => string | undefined>();\n const owners = new Map<string, string>();\n for (const descriptor of descriptors) {\n const codecTypes = descriptor.types?.codecTypes;\n const descriptorId = descriptor.id;\n // Descriptor-side metadata is the single source of truth for `targetTypes` / `meta` / `renderOutputType`. Every contributor ships a `codecDescriptors` list on `types.codecTypes`.\n for (const codecDescriptor of codecTypes?.codecDescriptors ?? []) {\n assertUniqueCodecOwner({\n codecId: codecDescriptor.codecId,\n owners,\n descriptorId,\n entityLabel: 'codec descriptor',\n entityOwnershipLabel: 'codec descriptor provider',\n });\n owners.set(codecDescriptor.codecId, descriptorId);\n if (Array.isArray(codecDescriptor.targetTypes)) {\n targetTypesById.set(codecDescriptor.codecId, codecDescriptor.targetTypes);\n }\n if (codecDescriptor.meta !== undefined) {\n metaById.set(codecDescriptor.codecId, codecDescriptor.meta);\n }\n if (typeof codecDescriptor.renderOutputType === 'function') {\n renderersById.set(codecDescriptor.codecId, codecDescriptor.renderOutputType);\n }\n // Materialize a representative `Codec` instance for `byId.get()` so consumers reading the lookup's instance side (e.g. SQL renderer's cast-policy lookup, or the contract emitter's literal-default `encodeJson` resolver) keep finding the codec.\n //\n // Two cohorts:\n // - Non-parameterized descriptors: factory must succeed; any throw is a real bug and we let it propagate (no silent try/catch).\n // - Parameterized descriptors: try with empty params. Many parameterized codecs treat params as advisory (e.g. `pg/timestamptz@1` whose precision is rendered into the `nativeType` only and never read by the runtime codec), so an empty-params construction yields a usable representative for id-keyed lookups (e.g. emit-time literal-default encoding). Codecs whose factory genuinely requires params (e.g. `pg/vector@1` threading `length` into the runtime codec) will throw; for those, per-column instances are materialized at runtime by `buildContractCodecRegistry` and the id-keyed lookup miss is correct (the column-aware path resolves them).\n if (!byId.has(codecDescriptor.codecId)) {\n if (codecDescriptor.isParameterized) {\n try {\n const representative = codecDescriptor.factory({} as never)({\n name: `<lookup:${codecDescriptor.codecId}>`,\n } as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);\n byId.set(codecDescriptor.codecId, representative);\n } catch {\n // Factory requires concrete params; skip representative materialization. Per-column instances are built at runtime; id-keyed lookup miss is the correct outcome here.\n }\n } else {\n const representative = codecDescriptor.factory(undefined as never)({\n name: `<lookup:${codecDescriptor.codecId}>`,\n } as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);\n byId.set(codecDescriptor.codecId, representative);\n }\n }\n }\n }\n return {\n get: (id) => byId.get(id),\n targetTypesFor: (id) => targetTypesById.get(id),\n metaFor: (id) => metaById.get(id),\n renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params),\n };\n}\n\nexport function validateScalarTypeCodecIds(\n scalarTypeDescriptors: ReadonlyMap<string, string>,\n codecLookup: CodecLookup,\n): string[] {\n const errors: string[] = [];\n for (const [typeName, codecId] of scalarTypeDescriptors) {\n if (!codecLookup.get(codecId)) {\n errors.push(\n `Scalar type \"${typeName}\" references codec \"${codecId}\" which is not registered by any component.`,\n );\n }\n }\n return errors;\n}\n\ninterface DependencyDeclaringDescriptor {\n readonly id: string;\n readonly contractSpace?: {\n readonly contractJson?: {\n readonly extensionPacks?: Readonly<Record<string, unknown>>;\n };\n };\n}\n\nfunction readDeclaredDependencyIds(descriptor: DependencyDeclaringDescriptor): readonly string[] {\n const packs = descriptor.contractSpace?.contractJson?.extensionPacks;\n if (packs === null || typeof packs !== 'object') return [];\n return Object.keys(packs);\n}\n\n/**\n * Builds a dependency-respecting load order for the given extension descriptors\n * using Kahn's topological sort algorithm. Dependencies (packs declared in\n * `contractSpace.contractJson.extensionPacks`) are placed before the extensions\n * that depend on them.\n *\n * Throws if the dependency graph contains a cycle, with an error message that\n * names every extension involved in the cycle.\n *\n * Throws if any extension declares a dependency on a pack ID that is not present\n * in the provided list — add the missing pack to the `extensionPacks` list to\n * resolve the error.\n */\n\nexport function buildExtensionLoadOrder(\n extensions: ReadonlyArray<DependencyDeclaringDescriptor>,\n): readonly string[] {\n if (extensions.length === 0) return [];\n\n const idSet = new Set(extensions.map((e) => e.id));\n const inDegree = new Map<string, number>();\n const dependents = new Map<string, string[]>();\n\n for (const ext of extensions) {\n if (!inDegree.has(ext.id)) inDegree.set(ext.id, 0);\n if (!dependents.has(ext.id)) dependents.set(ext.id, []);\n }\n\n for (const ext of extensions) {\n for (const depId of readDeclaredDependencyIds(ext)) {\n if (!idSet.has(depId)) {\n throw new Error(\n `Extension \"${ext.id}\" declares a dependency on \"${depId}\", but \"${depId}\" is not in the provided extension set. Add the missing space to extensionPacks.`,\n );\n }\n inDegree.set(ext.id, (inDegree.get(ext.id) ?? 0) + 1);\n const list = dependents.get(depId);\n if (list !== undefined) list.push(ext.id);\n }\n }\n\n const queue: string[] = [];\n for (const [id, deg] of inDegree) {\n if (deg === 0) queue.push(id);\n }\n queue.sort();\n\n const result: string[] = [];\n while (queue.length > 0) {\n const id = queue.shift();\n if (id === undefined) break;\n result.push(id);\n const children = dependents.get(id) ?? [];\n children.sort();\n for (const childId of children) {\n const newDeg = (inDegree.get(childId) ?? 1) - 1;\n inDegree.set(childId, newDeg);\n if (newDeg === 0) queue.push(childId);\n }\n }\n\n if (result.length < extensions.length) {\n const cycleMembers = extensions\n .map((e) => e.id)\n .filter((id) => !result.includes(id))\n .sort();\n throw new Error(\n `Extension dependency cycle detected. Cycle members: ${cycleMembers.map((id) => `\"${id}\"`).join(', ')}.`,\n );\n }\n\n return result;\n}\n\nexport function createControlStack<TFamilyId extends string, TTargetId extends string>(\n input: CreateControlStackInput<TFamilyId, TTargetId>,\n): ControlStack<TFamilyId, TTargetId> {\n const { family, target, adapter, driver, extensionPacks = [] } = input;\n\n const orderedIds = buildExtensionLoadOrder(extensionPacks);\n const extensionById = new Map(extensionPacks.map((ext) => [ext.id, ext]));\n const orderedExtensionPacks = orderedIds\n .map((id) => extensionById.get(id))\n .filter((ext): ext is ControlExtensionDescriptor<TFamilyId, TTargetId> => ext !== undefined);\n\n const allDescriptors = [family, target, ...(adapter ? [adapter] : []), ...orderedExtensionPacks];\n\n const codecLookup = extractCodecLookup(allDescriptors);\n const scalarTypeDescriptors = assembleScalarTypeDescriptors(allDescriptors);\n\n return {\n family,\n target,\n adapter,\n driver,\n extensionPacks: orderedExtensionPacks,\n\n codecTypeImports: extractCodecTypeImports(allDescriptors),\n queryOperationTypeImports: extractQueryOperationTypeImports(allDescriptors),\n extensionIds: extractComponentIds(family, target, adapter, orderedExtensionPacks),\n codecLookup,\n authoringContributions: assembleAuthoringContributions(allDescriptors),\n scalarTypeDescriptors,\n controlMutationDefaults: assembleControlMutationDefaults(allDescriptors),\n };\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { SchemaVerificationNode } from './control-result-types';\n\nexport type VerificationStatus = SchemaVerificationNode['status'];\n\nexport type VerifierOutcome = VerificationStatus | 'suppress';\n\n/**\n * Target-neutral classification of a verifier finding, abstracted away from any\n * one storage model's vocabulary. Each family classifies its own concrete issue\n * kinds into these categories; the framework only grades the category against a\n * control policy.\n *\n * - `declaredMissing` — a declared object/element is absent from the database.\n * - `declaredIncompatible` — a declared object/element exists but its shape diverges.\n * - `valueDrift` — the value set of an existing type drifted (e.g. enum values).\n * - `extraNestedElement` — an undeclared element nested inside a declared object\n * (a SQL column, a document field).\n * - `extraAuxiliary` — an undeclared auxiliary attached to a declared object\n * (a SQL constraint/index, a Mongo index/validator).\n * - `extraTopLevelObject` — an undeclared top-level object (a SQL table, a\n * Mongo collection).\n */\nexport type VerifierIssueCategory =\n | 'declaredMissing'\n | 'declaredIncompatible'\n | 'valueDrift'\n | 'extraNestedElement'\n | 'extraAuxiliary'\n | 'extraTopLevelObject';\n\n/**\n * Grades a target-neutral issue category against a control policy.\n *\n * - `observed` warns on everything.\n * - `tolerated` suppresses only an extra nested element (everything else fails).\n * - `external` suppresses every extra category and value drift (existence and\n * declared-shape divergences still fail).\n * - `managed` (and any other) fails.\n */\nexport function dispositionForCategory(\n controlPolicy: ControlPolicy,\n category: VerifierIssueCategory,\n): VerifierOutcome {\n if (controlPolicy === 'observed') {\n return 'warn';\n }\n if (controlPolicy === 'tolerated' && category === 'extraNestedElement') {\n return 'suppress';\n }\n if (controlPolicy === 'external') {\n if (\n category === 'extraNestedElement' ||\n category === 'extraAuxiliary' ||\n category === 'extraTopLevelObject' ||\n category === 'valueDrift'\n ) {\n return 'suppress';\n }\n }\n return 'fail';\n}\n"],"mappings":";;;AAkBA,SAAgB,cACd,QAC4D;CAC5D,OAAO,gBAAgB,UAAU,CAAC,CAAE,OAAmC;AACzE;AAMA,SAAgB,cACd,UACwF;CACxF,OACE,kBAAkB,YAClB,OAAQ,SAAqC,oBAAoB;AAErE;AAUA,SAAgB,oBACd,UAC8F;CAC9F,OACE,sBAAsB,YACtB,OAAQ,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;EAC1E,cAAc,oBAAoB,QAAQ,QAAQ,SAAS,qBAAqB;EAChF;EACA,wBAAwB,+BAA+B,cAAc;EACrE;EACA,yBAAyB,gCAAgC,cAAc;CACzE;AACF;;;;;;;;;;;;ACncA,SAAgB,uBACd,eACA,UACiB;CACjB,IAAI,kBAAkB,YACpB,OAAO;CAET,IAAI,kBAAkB,eAAe,aAAa,sBAChD,OAAO;CAET,IAAI,kBAAkB;MAElB,aAAa,wBACb,aAAa,oBACb,aAAa,yBACb,aAAa,cAEb,OAAO;CAAA;CAGX,OAAO;AACT"}
{"version":3,"file":"control.mjs","names":[],"sources":["../src/control/control-capabilities.ts","../src/control/control-result-types.ts","../src/control/control-schema-view.ts","../src/control/control-spaces.ts","../src/control/control-stack.ts","../src/control/verifier-disposition.ts"],"sourcesContent":["import type { ControlTargetDescriptor } from './control-descriptors';\nimport type { ControlFamilyInstance } from './control-instances';\nimport type { MigrationPlanOperation, TargetMigrationsCapability } from './control-migration-types';\nimport type { OperationPreview } from './control-operation-preview';\nimport type { CoreSchemaView } from './control-schema-view';\nimport type { PslDocumentAst } from './psl-ast';\n\nexport interface MigratableTargetDescriptor<\n TFamilyId extends string,\n TTargetId extends string,\n TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<\n TFamilyId,\n unknown\n >,\n> extends ControlTargetDescriptor<TFamilyId, TTargetId> {\n readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, TFamilyInstance>;\n}\n\nexport function hasMigrations<TFamilyId extends string, TTargetId extends string>(\n target: ControlTargetDescriptor<TFamilyId, TTargetId>,\n): target is MigratableTargetDescriptor<TFamilyId, TTargetId> {\n return 'migrations' in target && !!(target as Record<string, unknown>)['migrations'];\n}\n\nexport interface SchemaViewCapable<TSchemaIR = unknown> {\n toSchemaView(schema: TSchemaIR): CoreSchemaView;\n}\n\nexport function hasSchemaView<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & SchemaViewCapable<TSchemaIR> {\n return (\n 'toSchemaView' in instance &&\n typeof (instance as Record<string, unknown>)['toSchemaView'] === 'function'\n );\n}\n\n/**\n * Capability declaring that a family can infer a PSL contract AST from its\n * opaque introspected schema IR. Consumed by `prisma-next contract infer`.\n */\nexport interface PslContractInferCapable<TSchemaIR = unknown> {\n inferPslContract(schemaIR: TSchemaIR): PslDocumentAst;\n}\n\nexport function hasPslContractInfer<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & PslContractInferCapable<TSchemaIR> {\n return (\n 'inferPslContract' in instance &&\n typeof (instance as Record<string, unknown>)['inferPslContract'] === 'function'\n );\n}\n\n/**\n * Capability declaring that a family can render a textual preview of migration\n * operations for the CLI's \"DDL preview\" output. SQL families emit\n * `language: 'sql'` statements; Mongo families emit `language: 'mongodb-shell'`.\n */\nexport interface OperationPreviewCapable {\n toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;\n}\n\nexport function hasOperationPreview<TFamilyId extends string, TSchemaIR>(\n instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,\n): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & OperationPreviewCapable {\n return (\n 'toOperationPreview' in instance &&\n typeof (instance as Record<string, unknown>)['toOperationPreview'] === 'function'\n );\n}\n","export const VERIFY_CODE_MARKER_MISSING = 'PN-RUN-3001';\nexport const VERIFY_CODE_HASH_MISMATCH = 'PN-RUN-3002';\nexport const VERIFY_CODE_TARGET_MISMATCH = 'PN-RUN-3003';\nexport const VERIFY_CODE_SCHEMA_FAILURE = 'PN-RUN-3010';\n\nexport interface OperationContext {\n readonly contractPath?: string;\n readonly configPath?: string;\n readonly meta?: Readonly<Record<string, unknown>>;\n}\n\nexport interface VerifyDatabaseResult {\n readonly ok: boolean;\n readonly code?: string;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly marker?: {\n readonly storageHash?: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly missingCodecs?: readonly string[];\n readonly codecCoverageSkipped?: boolean;\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface BaseSchemaIssue {\n readonly kind:\n | 'missing_schema'\n | 'missing_table'\n | 'missing_column'\n | 'extra_table'\n | 'extra_column'\n | 'extra_primary_key'\n | 'extra_foreign_key'\n | 'extra_unique_constraint'\n | 'extra_index'\n | 'extra_validator'\n | 'type_mismatch'\n | 'type_missing'\n | 'type_values_mismatch'\n | 'nullability_mismatch'\n | 'primary_key_mismatch'\n | 'foreign_key_mismatch'\n | 'unique_constraint_mismatch'\n | 'index_mismatch'\n | 'default_missing'\n | 'default_mismatch'\n | 'extra_default'\n | 'check_missing'\n | 'check_removed'\n | 'check_mismatch';\n readonly table?: string;\n /**\n * Namespace coordinate of the issue's subject (e.g. the schema a SQL\n * table lives in). Populated by family verifiers that have the\n * coordinate in scope when constructing the issue; absent for issues\n * whose family has no namespace concept (e.g. Mongo collections) or\n * whose subject isn't in any contract namespace (e.g. an extra-table\n * issue raised for a table that exists in the live DB but not in the\n * contract).\n *\n * Downstream planners trust this field as the authoritative subject\n * coordinate and do not re-derive it by name lookup. A finer-grained\n * structural split between framework-shared and family-specific issue\n * fields is tracked under a follow-up ticket.\n */\n readonly namespaceId?: string;\n readonly column?: string;\n readonly indexOrConstraint?: string;\n readonly typeName?: string;\n readonly expected?: string;\n readonly actual?: string;\n readonly message: string;\n}\n\nexport interface EnumValuesChangedIssue {\n readonly kind: 'enum_values_changed';\n /**\n * Namespace coordinate of the enum type that changed values. Populated by\n * family verifiers that have the coordinate in scope when constructing the\n * issue. Downstream planners trust this field as the authoritative subject\n * coordinate and do not re-derive it by name lookup.\n */\n readonly namespaceId: string;\n readonly typeName: string;\n readonly addedValues: readonly string[];\n readonly removedValues: readonly string[];\n readonly message: string;\n}\n\nexport type SchemaIssue = BaseSchemaIssue | EnumValuesChangedIssue;\n\nexport interface SchemaVerificationNode {\n readonly status: 'pass' | 'warn' | 'fail';\n readonly kind: string;\n readonly name: string;\n readonly contractPath: string;\n readonly code: string;\n readonly message: string;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly children: readonly SchemaVerificationNode[];\n}\n\nexport interface VerifyDatabaseSchemaResult {\n readonly ok: boolean;\n readonly code?: string;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly schema: {\n readonly issues: readonly SchemaIssue[];\n readonly root: SchemaVerificationNode;\n readonly counts: {\n readonly pass: number;\n readonly warn: number;\n readonly fail: number;\n readonly totalNodes: number;\n };\n };\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath?: string;\n readonly strict: boolean;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface EmitContractResult {\n readonly contractJson: string;\n readonly contractDts: string;\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n}\n\nexport interface IntrospectSchemaResult<TSchemaIR> {\n readonly ok: true;\n readonly summary: string;\n readonly target: {\n readonly familyId: string;\n readonly id: string;\n };\n readonly schema: TSchemaIR;\n readonly meta?: {\n readonly configPath?: string;\n readonly dbUrl?: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport interface SignDatabaseResult {\n readonly ok: boolean;\n readonly summary: string;\n readonly contract: {\n readonly storageHash: string;\n readonly profileHash?: string;\n };\n readonly target: {\n readonly expected: string;\n readonly actual?: string;\n };\n readonly marker: {\n readonly created: boolean;\n readonly updated: boolean;\n readonly previous?: {\n readonly storageHash?: string;\n readonly profileHash?: string;\n };\n };\n readonly meta?: {\n readonly configPath?: string;\n readonly contractPath: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n","/**\n * Core schema view types for family-agnostic schema visualization.\n *\n * These types provide a minimal, generic, tree-shaped representation of schemas\n * across families, designed for CLI visualization and lightweight tooling.\n *\n * Families can optionally project their family-specific Schema IR into this\n * core view via the `toSchemaView` method on `FamilyInstance`.\n */\n\nexport type SchemaViewNodeKind =\n | 'root'\n | 'namespace'\n | 'collection'\n | 'entity'\n | 'field'\n | 'index'\n | 'dependency';\n\nexport interface SchemaTreeVisitor<R> {\n visit(node: SchemaTreeNode): R;\n}\n\nexport interface SchemaTreeNodeOptions {\n readonly kind: SchemaViewNodeKind;\n readonly id: string;\n readonly label: string;\n readonly meta?: Record<string, unknown>;\n readonly children?: readonly SchemaTreeNode[];\n}\n\nexport class SchemaTreeNode {\n readonly kind: SchemaViewNodeKind;\n readonly id: string;\n readonly label: string;\n readonly meta?: Record<string, unknown>;\n readonly children?: readonly SchemaTreeNode[];\n\n constructor(options: SchemaTreeNodeOptions) {\n this.kind = options.kind;\n this.id = options.id;\n this.label = options.label;\n if (options.meta !== undefined) this.meta = options.meta;\n if (options.children !== undefined) this.children = options.children;\n Object.freeze(this);\n }\n\n accept<R>(visitor: SchemaTreeVisitor<R>): R {\n return visitor.visit(this);\n }\n}\n\n/**\n * Core schema view providing a family-agnostic tree representation of a schema.\n * Used by CLI and cross-family tooling for visualization.\n */\nexport interface CoreSchemaView {\n readonly root: SchemaTreeNode;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { MigrationMetadata, MigrationPlanOperation } from './control-migration-types';\n\n/**\n * Canonical control-plane identifiers for contract spaces.\n *\n * A contract space is the disjoint `(contract.json, migration-graph)` unit\n * the per-space planner / runner / verifier (project: extension contract\n * spaces, TML-2397) operates on. The application owns one well-known\n * space — the value below — and each loaded extension that contributes\n * schema owns a uniquely-named space.\n *\n * Lives in `framework-components/control` so every layer that has to\n * reason about space identity (the migration tooling, the SQL runtime's\n * marker reader, target-side statement builders, target-side adapters)\n * can import a single value rather than duplicating the literal. Raw\n * `'app'` string literals in framework / target / runtime / adapter\n * source code are forbidden and policed by\n * `scripts/lint-app-space-id.mjs` (wired into `pnpm lint:deps`).\n *\n * @see specs/framework-mechanism.spec.md § 3 — Layout convention (γ).\n */\nexport const APP_SPACE_ID = 'app' as const;\n\n/**\n * Head ref for a contract space — the `(hash, invariants)` tuple\n * a runner targets when applying that space's migration graph. Identical\n * in shape to the on-disk `migrations/<space-id>/refs/head.json` the\n * framework writes per loaded extension, and to the app-space\n * `<projectRoot>/refs/head.json`. Family-agnostic: SQL, Mongo, and any\n * future family share the same head-ref shape.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface ContractSpaceHeadRef {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\n/**\n * Canonical structural shape of a migration package — the unit a planner\n * produces and a runner consumes: a directory name, the metadata\n * envelope, and the operation list.\n *\n * In-memory by default. Readers in `@prisma-next/migration-tools`\n * (`readMigrationPackage` / `readMigrationsDir`) return the augmented\n * {@link import('@prisma-next/migration-tools/package').OnDiskMigrationPackage}\n * variant which adds `dirPath`; everything else operates against the\n * canonical shape so the same value flows through pre-emission\n * authoring, on-disk loading, and runner execution without conversion.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface MigrationPackage {\n readonly dirName: string;\n readonly metadata: MigrationMetadata;\n readonly ops: readonly MigrationPlanOperation[];\n}\n\n/**\n * Canonical structural shape of a contract space — one disjoint\n * `(contractJson, migration-graph)` unit the per-space planner / runner\n * / verifier operates on. The application owns one well-known space\n * ({@link APP_SPACE_ID}); each loaded extension that contributes schema\n * owns a uniquely-named space. Whether a value is the app's space or an\n * extension's space is a control-plane concern; the type carries no\n * such distinction.\n *\n * Generic over the contract so each family pins a typed contract value\n * at consumption time. The SQL family specialises to\n * `ContractSpace<Contract<SqlStorage>>` at the descriptor surface;\n * Mongo's symmetrical `ContractSpace<Contract<MongoStorage>>` will land\n * with that family.\n *\n * @see specs/framework-mechanism.spec.md § 1.\n */\nexport interface ContractSpace<TContract extends Contract = Contract> {\n readonly contractJson: TContract;\n readonly migrations: readonly MigrationPackage[];\n readonly headRef: ContractSpaceHeadRef;\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport type { Codec } from '../shared/codec';\nimport type { AnyCodecDescriptor } from '../shared/codec-descriptor';\nimport type { CodecLookup, CodecMeta, CodecRef, CodecRegistry } from '../shared/codec-types';\nimport type {\n AuthoringContributions,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n} from '../shared/framework-authoring';\nimport {\n assertNoCrossRegistryCollisions,\n isAuthoringEntityTypeDescriptor,\n isAuthoringFieldPresetDescriptor,\n isAuthoringPslBlockDescriptor,\n isAuthoringTypeConstructorDescriptor,\n mergeAuthoringNamespaces,\n} from '../shared/framework-authoring';\nimport type { ComponentMetadata } from '../shared/framework-components';\nimport type {\n ControlMutationDefaultEntry,\n ControlMutationDefaults,\n MutationDefaultGeneratorDescriptor,\n} from '../shared/mutation-default-types';\nimport {\n CONTRACT_CODEC_DESCRIPTOR_MISSING,\n materializeCodec,\n resolveCodecDescriptorOrThrow,\n} from '../shared/resolve-codec';\nimport type { TypesImportSpec } from '../shared/types-import-spec';\nimport type {\n ControlAdapterDescriptor,\n ControlDriverDescriptor,\n ControlExtensionDescriptor,\n ControlFamilyDescriptor,\n ControlTargetDescriptor,\n} from './control-descriptors';\n\nexport interface AssembledAuthoringContributions {\n readonly field: AuthoringFieldNamespace;\n readonly type: AuthoringTypeNamespace;\n readonly entityTypes: AuthoringEntityTypeNamespace;\n readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport interface ControlStack<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> {\n readonly family: ControlFamilyDescriptor<TFamilyId>;\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter?: ControlAdapterDescriptor<TFamilyId, TTargetId> | undefined;\n readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;\n readonly extensionPacks: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];\n\n readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly queryOperationTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds: ReadonlyArray<string>;\n readonly codecLookup: CodecRegistry;\n readonly authoringContributions: AssembledAuthoringContributions;\n readonly scalarTypeDescriptors: ReadonlyMap<string, string>;\n readonly controlMutationDefaults: ControlMutationDefaults;\n}\n\nexport interface CreateControlStackInput<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> {\n readonly family: ControlFamilyDescriptor<TFamilyId>;\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter?: ControlAdapterDescriptor<TFamilyId, TTargetId> | undefined;\n readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;\n readonly extensionPacks?:\n | ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>\n | undefined;\n}\n\nfunction addUniqueId(ids: string[], seen: Set<string>, id: string): void {\n if (!seen.has(id)) {\n ids.push(id);\n seen.add(id);\n }\n}\n\nexport function assertUniqueCodecOwner(options: {\n readonly codecId: string;\n readonly owners: Map<string, string>;\n readonly descriptorId: string;\n readonly entityLabel: string;\n readonly entityOwnershipLabel: string;\n}): void {\n const existingOwner = options.owners.get(options.codecId);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate ${options.entityLabel} for codecId \"${options.codecId}\". ` +\n `Descriptor \"${options.descriptorId}\" conflicts with \"${existingOwner}\". ` +\n `Each codecId can only have one ${options.entityOwnershipLabel}.`,\n );\n }\n}\n\nexport function extractCodecTypeImports(\n descriptors: ReadonlyArray<Pick<ComponentMetadata, 'types'>>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const codecTypes = descriptor.types?.codecTypes;\n if (codecTypes?.import) {\n imports.push(codecTypes.import);\n }\n if (codecTypes?.typeImports) {\n imports.push(...codecTypes.typeImports);\n }\n }\n\n return imports;\n}\n\nexport function extractQueryOperationTypeImports(\n descriptors: ReadonlyArray<Pick<ComponentMetadata, 'types'>>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const queryOperationTypes = descriptor.types?.queryOperationTypes;\n if (queryOperationTypes?.import) {\n imports.push(queryOperationTypes.import);\n }\n }\n\n return imports;\n}\n\nexport function extractComponentIds(\n family: { readonly id: string },\n target: { readonly id: string },\n adapter: { readonly id: string } | undefined,\n extensions: ReadonlyArray<{ readonly id: string }>,\n): ReadonlyArray<string> {\n const ids: string[] = [];\n const seen = new Set<string>();\n\n addUniqueId(ids, seen, family.id);\n addUniqueId(ids, seen, target.id);\n if (adapter) {\n addUniqueId(ids, seen, adapter.id);\n }\n\n for (const ext of extensions) {\n addUniqueId(ids, seen, ext.id);\n }\n\n return ids;\n}\n\nexport function assembleAuthoringContributions(\n descriptors: ReadonlyArray<{ readonly authoring?: AuthoringContributions }>,\n): AssembledAuthoringContributions {\n const field = {} as Record<string, unknown>;\n const type = {} as Record<string, unknown>;\n const entityTypes = {} as Record<string, unknown>;\n const pslBlockDescriptors: Record<string, unknown> = {};\n\n for (const descriptor of descriptors) {\n if (descriptor.authoring?.field) {\n mergeAuthoringNamespaces(\n field,\n descriptor.authoring.field,\n [],\n isAuthoringFieldPresetDescriptor,\n 'field',\n );\n }\n if (descriptor.authoring?.type) {\n mergeAuthoringNamespaces(\n type,\n descriptor.authoring.type,\n [],\n isAuthoringTypeConstructorDescriptor,\n 'type',\n );\n }\n if (descriptor.authoring?.entityTypes) {\n mergeAuthoringNamespaces(\n entityTypes,\n descriptor.authoring.entityTypes,\n [],\n isAuthoringEntityTypeDescriptor,\n 'entity',\n );\n }\n if (descriptor.authoring?.pslBlockDescriptors) {\n mergeAuthoringNamespaces(\n pslBlockDescriptors,\n descriptor.authoring.pslBlockDescriptors,\n [],\n isAuthoringPslBlockDescriptor,\n 'pslBlock',\n );\n }\n }\n\n const fieldNamespace = field as AuthoringFieldNamespace;\n const typeNamespace = type as AuthoringTypeNamespace;\n const entityTypeNamespace = entityTypes as AuthoringEntityTypeNamespace;\n const pslBlockDescriptorNamespace = blindCast<\n AuthoringPslBlockDescriptorNamespace,\n 'merge target accumulator narrows to typed namespace post-merge'\n >(pslBlockDescriptors);\n assertNoCrossRegistryCollisions(\n typeNamespace,\n fieldNamespace,\n entityTypeNamespace,\n pslBlockDescriptorNamespace,\n );\n\n return {\n field: fieldNamespace,\n type: typeNamespace,\n entityTypes: entityTypeNamespace,\n pslBlockDescriptors: pslBlockDescriptorNamespace,\n };\n}\n\nexport function assembleScalarTypeDescriptors(\n descriptors: ReadonlyArray<\n Pick<ComponentMetadata, 'scalarTypeDescriptors'> & { readonly id?: string }\n >,\n): ReadonlyMap<string, string> {\n const result = new Map<string, string>();\n const owners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n const descriptorMap = descriptor.scalarTypeDescriptors;\n if (!descriptorMap) continue;\n const descriptorId = descriptor.id ?? '<unknown>';\n for (const [typeName, codecId] of descriptorMap) {\n const existingOwner = owners.get(typeName);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate scalar type descriptor \"${typeName}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n result.set(typeName, codecId);\n owners.set(typeName, descriptorId);\n }\n }\n\n return result;\n}\n\nexport function assembleControlMutationDefaults(\n descriptors: ReadonlyArray<\n Pick<ComponentMetadata, 'controlMutationDefaults'> & { readonly id?: string }\n >,\n): ControlMutationDefaults {\n const defaultFunctionRegistry = new Map<string, ControlMutationDefaultEntry>();\n const functionOwners = new Map<string, string>();\n const generatorMap = new Map<string, MutationDefaultGeneratorDescriptor>();\n const generatorOwners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n const contributions = descriptor.controlMutationDefaults;\n if (!contributions) continue;\n const descriptorId = descriptor.id ?? '<unknown>';\n\n for (const generatorDescriptor of contributions.generatorDescriptors) {\n const existingOwner = generatorOwners.get(generatorDescriptor.id);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate mutation default generator id \"${generatorDescriptor.id}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n generatorMap.set(generatorDescriptor.id, generatorDescriptor);\n generatorOwners.set(generatorDescriptor.id, descriptorId);\n }\n\n for (const [functionName, handler] of contributions.defaultFunctionRegistry) {\n const existingOwner = functionOwners.get(functionName);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate mutation default function \"${functionName}\". ` +\n `Descriptor \"${descriptorId}\" conflicts with \"${existingOwner}\".`,\n );\n }\n defaultFunctionRegistry.set(functionName, handler);\n functionOwners.set(functionName, descriptorId);\n }\n }\n\n return {\n defaultFunctionRegistry,\n generatorDescriptors: Array.from(generatorMap.values()),\n };\n}\n\nexport function extractCodecLookup(\n descriptors: ReadonlyArray<Pick<ComponentMetadata & { id: string }, 'types' | 'id'>>,\n): CodecRegistry {\n const byId = new Map<string, Codec>();\n const descriptorsById = new Map<string, AnyCodecDescriptor>();\n const targetTypesById = new Map<string, readonly string[]>();\n const metaById = new Map<string, CodecMeta>();\n const renderersById = new Map<string, (params: Record<string, unknown>) => string | undefined>();\n const inputRenderersById = new Map<\n string,\n (params: Record<string, unknown>) => string | undefined\n >();\n const owners = new Map<string, string>();\n for (const descriptor of descriptors) {\n const codecTypes = descriptor.types?.codecTypes;\n const descriptorId = descriptor.id;\n // Descriptor-side metadata is the single source of truth for `targetTypes` / `meta` / `renderOutputType`. Every contributor ships a `codecDescriptors` list on `types.codecTypes`.\n for (const codecDescriptor of codecTypes?.codecDescriptors ?? []) {\n assertUniqueCodecOwner({\n codecId: codecDescriptor.codecId,\n owners,\n descriptorId,\n entityLabel: 'codec descriptor',\n entityOwnershipLabel: 'codec descriptor provider',\n });\n owners.set(codecDescriptor.codecId, descriptorId);\n descriptorsById.set(codecDescriptor.codecId, codecDescriptor);\n if (Array.isArray(codecDescriptor.targetTypes)) {\n targetTypesById.set(codecDescriptor.codecId, codecDescriptor.targetTypes);\n }\n if (codecDescriptor.meta !== undefined) {\n metaById.set(codecDescriptor.codecId, codecDescriptor.meta);\n }\n if (typeof codecDescriptor.renderOutputType === 'function') {\n renderersById.set(codecDescriptor.codecId, codecDescriptor.renderOutputType);\n }\n if (typeof codecDescriptor.renderInputType === 'function') {\n inputRenderersById.set(codecDescriptor.codecId, codecDescriptor.renderInputType);\n }\n // Materialize a representative `Codec` instance for `byId.get()` so consumers reading the lookup's instance side (e.g. SQL renderer's cast-policy lookup, or the contract emitter's literal-default `encodeJson` resolver) keep finding the codec.\n //\n // Two cohorts:\n // - Non-parameterized descriptors: factory must succeed; any throw is a real bug and we let it propagate (no silent try/catch).\n // - Parameterized descriptors: try with empty params. Many parameterized codecs treat params as advisory (e.g. `pg/timestamptz@1` whose precision is rendered into the `nativeType` only and never read by the runtime codec), so an empty-params construction yields a usable representative for id-keyed lookups (e.g. emit-time literal-default encoding). Codecs whose factory genuinely requires params (e.g. `pg/vector@1` threading `length` into the runtime codec) will throw; for those, per-column instances are materialized at runtime by `buildContractCodecRegistry` and the id-keyed lookup miss is correct (the column-aware path resolves them).\n if (!byId.has(codecDescriptor.codecId)) {\n if (codecDescriptor.isParameterized) {\n try {\n const representative = codecDescriptor.factory({} as never)({\n name: `<lookup:${codecDescriptor.codecId}>`,\n } as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);\n byId.set(codecDescriptor.codecId, representative);\n } catch {\n // Factory requires concrete params; skip representative materialization. Per-column instances are built at runtime; id-keyed lookup miss is the correct outcome here.\n }\n } else {\n const representative = codecDescriptor.factory(undefined as never)({\n name: `<lookup:${codecDescriptor.codecId}>`,\n } as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);\n byId.set(codecDescriptor.codecId, representative);\n }\n }\n }\n }\n return {\n get: (id) => byId.get(id),\n forCodecRef(ref: CodecRef) {\n const d = resolveCodecDescriptorOrThrow(\n (id) => descriptorsById.get(id),\n ref,\n CONTRACT_CODEC_DESCRIPTOR_MISSING,\n );\n return materializeCodec(d, ref, { name: `<ref:${ref.codecId}>` });\n },\n forColumn: () => undefined,\n targetTypesFor: (id) => targetTypesById.get(id),\n metaFor: (id) => metaById.get(id),\n renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params),\n renderInputTypeFor: (id, params) => inputRenderersById.get(id)?.(params),\n };\n}\n\nexport function validateScalarTypeCodecIds(\n scalarTypeDescriptors: ReadonlyMap<string, string>,\n codecLookup: CodecLookup,\n): string[] {\n const errors: string[] = [];\n for (const [typeName, codecId] of scalarTypeDescriptors) {\n if (!codecLookup.get(codecId)) {\n errors.push(\n `Scalar type \"${typeName}\" references codec \"${codecId}\" which is not registered by any component.`,\n );\n }\n }\n return errors;\n}\n\ninterface DependencyDeclaringDescriptor {\n readonly id: string;\n readonly contractSpace?: {\n readonly contractJson?: {\n readonly extensionPacks?: Readonly<Record<string, unknown>>;\n };\n };\n}\n\nfunction readDeclaredDependencyIds(descriptor: DependencyDeclaringDescriptor): readonly string[] {\n const packs = descriptor.contractSpace?.contractJson?.extensionPacks;\n if (packs === null || typeof packs !== 'object') return [];\n return Object.keys(packs);\n}\n\n/**\n * Builds a dependency-respecting load order for the given extension descriptors\n * using Kahn's topological sort algorithm. Dependencies (packs declared in\n * `contractSpace.contractJson.extensionPacks`) are placed before the extensions\n * that depend on them.\n *\n * Throws if the dependency graph contains a cycle, with an error message that\n * names every extension involved in the cycle.\n *\n * Throws if any extension declares a dependency on a pack ID that is not present\n * in the provided list — add the missing pack to the `extensionPacks` list to\n * resolve the error.\n */\n\nexport function buildExtensionLoadOrder(\n extensions: ReadonlyArray<DependencyDeclaringDescriptor>,\n): readonly string[] {\n if (extensions.length === 0) return [];\n\n const idSet = new Set(extensions.map((e) => e.id));\n const inDegree = new Map<string, number>();\n const dependents = new Map<string, string[]>();\n\n for (const ext of extensions) {\n if (!inDegree.has(ext.id)) inDegree.set(ext.id, 0);\n if (!dependents.has(ext.id)) dependents.set(ext.id, []);\n }\n\n for (const ext of extensions) {\n for (const depId of readDeclaredDependencyIds(ext)) {\n if (!idSet.has(depId)) {\n throw new Error(\n `Extension \"${ext.id}\" declares a dependency on \"${depId}\", but \"${depId}\" is not in the provided extension set. Add the missing space to extensionPacks.`,\n );\n }\n inDegree.set(ext.id, (inDegree.get(ext.id) ?? 0) + 1);\n const list = dependents.get(depId);\n if (list !== undefined) list.push(ext.id);\n }\n }\n\n const queue: string[] = [];\n for (const [id, deg] of inDegree) {\n if (deg === 0) queue.push(id);\n }\n queue.sort();\n\n const result: string[] = [];\n while (queue.length > 0) {\n const id = queue.shift();\n if (id === undefined) break;\n result.push(id);\n const children = dependents.get(id) ?? [];\n children.sort();\n for (const childId of children) {\n const newDeg = (inDegree.get(childId) ?? 1) - 1;\n inDegree.set(childId, newDeg);\n if (newDeg === 0) queue.push(childId);\n }\n }\n\n if (result.length < extensions.length) {\n const cycleMembers = extensions\n .map((e) => e.id)\n .filter((id) => !result.includes(id))\n .sort();\n throw new Error(\n `Extension dependency cycle detected. Cycle members: ${cycleMembers.map((id) => `\"${id}\"`).join(', ')}.`,\n );\n }\n\n return result;\n}\n\nexport function createControlStack<TFamilyId extends string, TTargetId extends string>(\n input: CreateControlStackInput<TFamilyId, TTargetId>,\n): ControlStack<TFamilyId, TTargetId> {\n const { family, target, adapter, driver, extensionPacks = [] } = input;\n\n const orderedIds = buildExtensionLoadOrder(extensionPacks);\n const extensionById = new Map(extensionPacks.map((ext) => [ext.id, ext]));\n const orderedExtensionPacks = orderedIds\n .map((id) => extensionById.get(id))\n .filter((ext): ext is ControlExtensionDescriptor<TFamilyId, TTargetId> => ext !== undefined);\n\n const allDescriptors = [family, target, ...(adapter ? [adapter] : []), ...orderedExtensionPacks];\n\n const codecLookup = extractCodecLookup(allDescriptors);\n const scalarTypeDescriptors = assembleScalarTypeDescriptors(allDescriptors);\n\n return {\n family,\n target,\n adapter,\n driver,\n extensionPacks: orderedExtensionPacks,\n\n codecTypeImports: extractCodecTypeImports(allDescriptors),\n queryOperationTypeImports: extractQueryOperationTypeImports(allDescriptors),\n extensionIds: extractComponentIds(family, target, adapter, orderedExtensionPacks),\n codecLookup,\n authoringContributions: assembleAuthoringContributions(allDescriptors),\n scalarTypeDescriptors,\n controlMutationDefaults: assembleControlMutationDefaults(allDescriptors),\n };\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { SchemaVerificationNode } from './control-result-types';\n\nexport type VerificationStatus = SchemaVerificationNode['status'];\n\nexport type VerifierOutcome = VerificationStatus | 'suppress';\n\n/**\n * Target-neutral classification of a verifier finding, abstracted away from any\n * one storage model's vocabulary. Each family classifies its own concrete issue\n * kinds into these categories; the framework only grades the category against a\n * control policy.\n *\n * - `declaredMissing` — a declared object/element is absent from the database.\n * - `declaredIncompatible` — a declared object/element exists but its shape diverges.\n * - `valueDrift` — the value set of an existing type drifted (e.g. enum values).\n * - `extraNestedElement` — an undeclared element nested inside a declared object\n * (a SQL column, a document field).\n * - `extraAuxiliary` — an undeclared auxiliary attached to a declared object\n * (a SQL constraint/index, a Mongo index/validator).\n * - `extraTopLevelObject` — an undeclared top-level object (a SQL table, a\n * Mongo collection).\n */\nexport type VerifierIssueCategory =\n | 'declaredMissing'\n | 'declaredIncompatible'\n | 'valueDrift'\n | 'extraNestedElement'\n | 'extraAuxiliary'\n | 'extraTopLevelObject';\n\n/**\n * Grades a target-neutral issue category against a control policy.\n *\n * - `observed` warns on everything.\n * - `tolerated` suppresses only an extra nested element (everything else fails).\n * - `external` suppresses every extra category and value drift (existence and\n * declared-shape divergences still fail).\n * - `managed` (and any other) fails.\n */\nexport function dispositionForCategory(\n controlPolicy: ControlPolicy,\n category: VerifierIssueCategory,\n): VerifierOutcome {\n if (controlPolicy === 'observed') {\n return 'warn';\n }\n if (controlPolicy === 'tolerated' && category === 'extraNestedElement') {\n return 'suppress';\n }\n if (controlPolicy === 'external') {\n if (\n category === 'extraNestedElement' ||\n category === 'extraAuxiliary' ||\n category === 'extraTopL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ACpC,KAAK;EACR,MAAM,IAAI,MACR,uDAAuD,aAAa,KAAK,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,EACxG;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,mBACd,OACoC;CACpC,MAAM,EAAE,QAAQ,QAAQ,SAAS,QAAQ,iBAAiB,CAAC,MAAM;CAEjE,MAAM,aAAa,wBAAwB,cAAc;CACzD,MAAM,gBAAgB,IAAI,IAAI,eAAe,KAAK,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;CACxE,MAAM,wBAAwB,WAC3B,KAAK,OAAO,cAAc,IAAI,EAAE,CAAC,CAAC,CAClC,QAAQ,QAAiE,QAAQ,KAAA,CAAS;CAE7F,MAAM,iBAAiB;EAAC;EAAQ;EAAQ,GAAI,UAAU,CAAC,OAAO,IAAI,CAAC;EAAI,GAAG;CAAqB;CAE/F,MAAM,cAAc,mBAAmB,cAAc;CACrD,MAAM,wBAAwB,8BAA8B,cAAc;CAE1E,OAAO;EACL;EACA;EACA;EACA;EACA,gBAAgB;EAEhB,kBAAkB,wBAAwB,cAAc;EACxD,2BAA2B,iCAAiC,cAAc;EAC1E,cAAc,oBAAoB,QAAQ,QAAQ,SAAS,qBAAqB;EAChF;EACA,wBAAwB,+BAA+B,cAAc;EACrE;EACA,yBAAyB,gCAAgC,cAAc;CACzE;AACF;;;;;;;;;;;;AC5dA,SAAgB,uBACd,eACA,UACiB;CACjB,IAAI,kBAAkB,YACpB,OAAO;CAET,IAAI,kBAAkB,eAAe,aAAa,sBAChD,OAAO;CAET,IAAI,kBAAkB;MAElB,aAAa,wBACb,aAAa,oBACb,aAAa,yBACb,aAAa,cAEb,OAAO;CAAA;CAGX,OAAO;AACT"}
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { n as GenerateContractTypesOptions, r as ValidationContext, t as EmissionSpi } from "./emission-types-vfpSTe63.mjs";
import { n as GenerateContractTypesOptions, r as ValidationContext, t as EmissionSpi } from "./emission-types-C561PwcN.mjs";
export type { EmissionSpi, GenerateContractTypesOptions, TypesImportSpec, ValidationContext };

@@ -1,2 +0,2 @@

import { b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, y as TargetDescriptor } from "./framework-components-DDQXmW0b.mjs";
import { b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, y as TargetDescriptor } from "./framework-components-5hA9ij1v.mjs";

@@ -3,0 +3,0 @@ //#region src/execution/execution-instances.d.ts

import { ApplicationDomain, StorageBase, StorageNamespace } from "@prisma-next/contract/types";
import { isPlainRecord } from "@prisma-next/contract/is-plain-record";
import { Type } from "arktype";

@@ -156,10 +158,17 @@ //#region src/ir/ir-node.d.ts

*
* Iterates each namespace's `entries` slot maps structurally. Skips
* Iterates each namespace's `entries` kind maps structurally. Skips
* non-object `entries`; `id` and `kind` are not walked (`kind` is
* non-enumerable on concretions). For every entity-kind key under
* `entries` whose value is a non-null object, yields one coordinate per
* entity name in that map. No family-specific slot vocabulary is required.
* entity name in that map. No family-specific kind vocabulary is required.
*/
declare function elementCoordinates(storage: Pick<StorageBase, 'namespaces'>): Generator<EntityCoordinate>;
/**
* Looks up a single entity in a `Storage`-shaped value by its full coordinate.
* Returns `undefined` if the namespace, entity kind, or entity name is absent.
* The type parameter is a caller assertion — the walk itself is structural
* and cannot verify the entity's shape.
*/
declare function entityAt<T = unknown>(storage: Pick<StorageBase, 'namespaces'>, coord: Pick<EntityCoordinate, 'namespaceId' | 'entityKind' | 'entityName'>): T | undefined;
/**
* Framework-level promise that every Contract IR / Schema IR carries a

@@ -179,3 +188,3 @@ * collection of namespaces keyed by namespace id. Family storage

* Extends `IRNode` so the framework's IR-walking surfaces (verifiers,
* serializers) can dispatch on `Storage`-typed slots through the same
* serializers) can dispatch on `Storage`-typed fields through the same
* IR-node alphabet as every other node — the structural dual already

@@ -214,2 +223,23 @@ * holds in code (every concrete storage class extends an IR-node base);

//#endregion
//#region src/ir/entity-kind.d.ts
interface EntityKindDescriptor<Input, Node> {
readonly kind: string;
readonly schema: Type<unknown>;
readonly construct: (input: Input) => Node;
}
type AnyEntityKindDescriptor = EntityKindDescriptor<never, unknown>;
/**
* Hydrates a namespace's entities from raw JSON maps into IR class instances.
*
* For each kind in `entries`: if the descriptor map has a descriptor,
* construct each inner-map value; otherwise freeze-and-carry (`'carry'`)
* or throw naming the kind and nsId (`'fail'`).
*
* The single boundary cast hands `value` to `descriptor.construct` as its
* `Input`. The value satisfies the kind's `Input` either by the
* entries-input contract at authoring time or by prior `validateStorage`
* validation at hydration time.
*/
declare function hydrateNamespaceEntities(entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>, kinds: ReadonlyMap<string, AnyEntityKindDescriptor>, onUnknown: 'carry' | 'fail', nsId?: string): Record<string, Readonly<Record<string, unknown>>>;
//#endregion
//#region src/ir/storage-type.d.ts

@@ -238,3 +268,3 @@ /**

//#endregion
export { type EntityCoordinate, type IRNode, IRNodeBase, type Namespace, NamespaceBase, type Storage, type StorageType, UNBOUND_NAMESPACE_ID, domainElementCoordinates, elementCoordinates, freezeNode };
export { type AnyEntityKindDescriptor, type EntityCoordinate, type EntityKindDescriptor, type IRNode, IRNodeBase, type Namespace, NamespaceBase, type Storage, type StorageType, UNBOUND_NAMESPACE_ID, domainElementCoordinates, elementCoordinates, entityAt, freezeNode, hydrateNamespaceEntities, isPlainRecord };
//# sourceMappingURL=ir.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"ir.d.mts","names":[],"sources":["../src/ir/ir-node.ts","../src/ir/namespace.ts","../src/ir/storage.ts","../src/ir/domain.ts","../src/ir/storage-type.ts"],"mappings":";;;;;;AAyCA;;;;AACe;AAGf;;;;AACwB;AAYxB;;;;;;;;;;;;;;AAA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,IAAI;AAAA"}
{"version":3,"file":"ir.d.mts","names":[],"sources":["../src/ir/ir-node.ts","../src/ir/namespace.ts","../src/ir/storage.ts","../src/ir/domain.ts","../src/ir/entity-kind.ts","../src/ir/storage-type.ts"],"mappings":";;;;;;;;;;AAyCA;;;;AACe;AAGf;;;;AACwB;AAYxB;;;;;;;;;;;;;;AAAwD;;;;AChCxD;;;;AAA0D;AAkC1D;;UDnBiB,MAAA;EAAA,SACN,IAAI;AAAA;AAAA,uBAGO,UAAA,YAAsB,MAAM;EAAA,kBAC9B,IAAI;AAAA;;;;;;;;;;iBAYR,UAAA,WAAqB,MAAA,EAAQ,IAAA,EAAM,CAAA,GAAI,CAAA;;;;;;AAjBvD;;;;AACe;AAGf;;;;AACwB;AAYxB;;;;;;;;;;cChCa,oBAAA;;;;ADgC2C;;;;AChCxD;;;;AAA0D;AAkC1D;;;;;;;;;;;;;;;;;;;;UAAiB,SAAA,SAAkB,MAAA,EAAQ,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;AAAA,uBAG/B,aAAA,SAAsB,UAAA,YAAsB,SAAA;EAAA,kBAC9C,EAAA;EAAA,kBACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;EAAA,kBACjC,IAAA;AAAA;;;AD3B7B;;;;AACe;AAGf;;;;AACwB;AAYxB;;;;;;AAjBA,UEjBiB,gBAAA;EAAA,SACN,KAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA;AAAA;;;AF8B6C;;;;AChCxD;;;;AAA0D;iBCgBzC,kBAAA,CACf,OAAA,EAAS,IAAA,CAAK,WAAA,kBACb,SAAA,CAAU,gBAAA;;;;;;;iBAmBG,QAAA,cACd,OAAA,EAAS,IAAA,CAAK,WAAA,iBACd,KAAA,EAAO,IAAA,CAAK,gBAAA,iDACX,CAAA;;;;;;;;;;;;;ADJwD;AAG3D;;;;;;;;;;;;;;;;;;;;;AAGiC;UC8ChB,OAAA,SAAgB,MAAA;EAAA,SACtB,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,SAAA;AAAA;;;;;;AF1E/C;;;;iBG/BiB,wBAAA,CACf,MAAA,EAAQ,IAAA,CAAK,iBAAA,kBACZ,SAAA,CAAU,gBAAA;;;UCTI,oBAAA;EAAA,SACN,IAAA;EAAA,SAEA,MAAA,EAAQ,IAAA;EAAA,SACR,SAAA,GAAY,KAAA,EAAO,KAAA,KAAU,IAAA;AAAA;AAAA,KAG5B,uBAAA,GAA0B,oBAAoB;;;AJgC3C;AAGf;;;;AACwB;AAYxB;;;;iBIlCgB,wBAAA,CACd,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA,sBAC1C,KAAA,EAAO,WAAA,SAAoB,uBAAA,GAC3B,SAAA,oBACA,IAAA,YACC,MAAA,SAAe,QAAA,CAAS,MAAA;;;;;;;AJY3B;;;;AACe;AAGf;;;;AACwB;AAYxB;;;;UKtCiB,WAAA,SAAoB,MAAM;EAAA,SAChC,IAAI;AAAA"}

@@ -0,1 +1,3 @@

import { blindCast } from "@prisma-next/utils/casts";
import { isPlainRecord } from "@prisma-next/contract/is-plain-record";
//#region src/ir/domain.ts

@@ -22,2 +24,29 @@ /**

//#endregion
//#region src/ir/entity-kind.ts
/**
* Hydrates a namespace's entities from raw JSON maps into IR class instances.
*
* For each kind in `entries`: if the descriptor map has a descriptor,
* construct each inner-map value; otherwise freeze-and-carry (`'carry'`)
* or throw naming the kind and nsId (`'fail'`).
*
* The single boundary cast hands `value` to `descriptor.construct` as its
* `Input`. The value satisfies the kind's `Input` either by the
* entries-input contract at authoring time or by prior `validateStorage`
* validation at hydration time.
*/
function hydrateNamespaceEntities(entries, kinds, onUnknown, nsId) {
const result = {};
for (const [kind, rawMap] of Object.entries(entries)) {
const descriptor = kinds.get(kind);
if (descriptor !== void 0) {
const built = {};
for (const [name, value] of Object.entries(rawMap)) built[name] = descriptor.construct(blindCast(value));
result[kind] = Object.freeze(built);
} else if (onUnknown === "carry") result[kind] = Object.freeze(rawMap);
else throw new Error(`Unknown entries key "${kind}" in namespace "${nsId ?? "?"}"; no hydration factory registered for this entity kind`);
}
return result;
}
//#endregion
//#region src/ir/ir-node.ts

@@ -72,7 +101,7 @@ var IRNodeBase = class {};

*
* Iterates each namespace's `entries` slot maps structurally. Skips
* Iterates each namespace's `entries` kind maps structurally. Skips
* non-object `entries`; `id` and `kind` are not walked (`kind` is
* non-enumerable on concretions). For every entity-kind key under
* `entries` whose value is a non-null object, yields one coordinate per
* entity name in that map. No family-specific slot vocabulary is required.
* entity name in that map. No family-specific kind vocabulary is required.
*/

@@ -83,5 +112,5 @@ function* elementCoordinates(storage) {

if (entries === null || typeof entries !== "object") continue;
for (const [entityKind, slot] of Object.entries(entries)) {
if (slot === null || typeof slot !== "object") continue;
for (const entityName of Object.keys(slot)) yield {
for (const [entityKind, kindMap] of Object.entries(entries)) {
if (kindMap === null || typeof kindMap !== "object") continue;
for (const entityName of Object.keys(kindMap)) yield {
plane: "storage",

@@ -95,5 +124,21 @@ namespaceId,

}
/**
* Looks up a single entity in a `Storage`-shaped value by its full coordinate.
* Returns `undefined` if the namespace, entity kind, or entity name is absent.
* The type parameter is a caller assertion — the walk itself is structural
* and cannot verify the entity's shape.
*/
function entityAt(storage, coord) {
const ns = storage.namespaces[coord.namespaceId];
if (ns === void 0) return void 0;
const entries = ns.entries;
if (!isPlainRecord(entries)) return void 0;
const kindMap = entries[coord.entityKind];
if (!isPlainRecord(kindMap)) return void 0;
if (!Object.hasOwn(kindMap, coord.entityName)) return void 0;
return blindCast(kindMap[coord.entityName]);
}
//#endregion
export { IRNodeBase, NamespaceBase, UNBOUND_NAMESPACE_ID, domainElementCoordinates, elementCoordinates, freezeNode };
export { IRNodeBase, NamespaceBase, UNBOUND_NAMESPACE_ID, domainElementCoordinates, elementCoordinates, entityAt, freezeNode, hydrateNamespaceEntities, isPlainRecord };
//# sourceMappingURL=ir.mjs.map

@@ -1,1 +0,1 @@

{"version":3,"file":"ir.mjs","names":[],"sources":["../src/ir/domain.ts","../src/ir/ir-node.ts","../src/ir/namespace.ts","../src/ir/storage.ts"],"sourcesContent":["import type { ApplicationDomain } from '@prisma-next/contract/types';\nimport type { EntityCoordinate } from './storage';\n\n/**\n * Lazy walk over every named domain entity in a {@link ApplicationDomain},\n * yielded as {@link EntityCoordinate} tuples with `plane: 'domain'`.\n *\n * Same structural rules as {@link elementCoordinates} over storage: skip\n * scalar `id`; each other object-valued property is an entity-kind slot.\n */\nexport function* domainElementCoordinates(\n domain: Pick<ApplicationDomain, 'namespaces'>,\n): Generator<EntityCoordinate> {\n for (const [namespaceId, ns] of Object.entries(domain.namespaces)) {\n for (const [entityKind, slot] of Object.entries(ns)) {\n if (entityKind === 'id') continue;\n if (slot === null || typeof slot !== 'object') continue;\n for (const entityName of Object.keys(slot)) {\n yield { plane: 'domain', namespaceId, entityKind, entityName };\n }\n }\n }\n}\n","/**\n * Framework-level IR alphabet.\n *\n * The framework's contribution to Contract IR / Schema IR is a common\n * root for the IR class hierarchy and a freeze affordance. Family\n * abstract bases (e.g. `SqlNode`, `MongoSchemaIRNode`) refine the alphabet\n * for their family shape; targets ship the concrete classes.\n *\n * `kind` is an optional discriminator on the base. Families and leaves\n * that benefit from discriminated-union dispatch declare their own\n * literal `kind` at the level that earns it — Mongo leaves carry\n * per-class literals (`readonly kind = 'mongo-collection' as const`)\n * because Mongo IR has polymorphic walkers; SQL declares a single\n * family-level `kind = 'sql'` on `SqlNode` because SQL IR has no\n * polymorphic dispatch today. No framework consumer dispatches on\n * `IRNode.kind` at the BASE type — every dispatch site narrows\n * through a union of leaves where each leaf carries a literal kind, so\n * requiring `kind` at the base would be unearned. Future leaves that\n * earn polymorphic dispatch override with a required literal at that\n * leaf (e.g. `override readonly kind = 'pack-contributed-kind' as const`).\n *\n * `IRNodeBase` carries no methods: the freeze-and-assign affordance\n * lives in the free `freezeNode` helper below. Keeping `freezeNode` out\n * of the class type means an emitted contract literal type\n * (`{ readonly kind: 'mongo-collection', ... }` or an unkeyed literal\n * like `{ nativeType, codecId, nullable }`) is structurally assignable\n * to its class type — a `protected freeze()` instance method would\n * otherwise leak into the public type surface and require the literal\n * to carry it too.\n *\n * Subclasses construct fields then call `freezeNode(this)` to seal the\n * instance. Frozen instances + plain readonly fields keep IR nodes\n * JSON-clean by construction, so `JSON.stringify(node)` produces canonical\n * JSON without a `toJSON()` method. The `ContractSerializer` SPI handles\n * round-trip from canonical JSON back to typed class instances.\n *\n * The name (`IRNode` / `IRNodeBase`) reflects the dual-hierarchy reality:\n * this base is the common root for both Contract IR and Schema IR class\n * hierarchies, not a Schema-IR-specific alphabet.\n */\n\nexport interface IRNode {\n readonly kind?: string;\n}\n\nexport abstract class IRNodeBase implements IRNode {\n abstract readonly kind?: string;\n}\n\n/**\n * Seal an IR class instance after its constructor has assigned all\n * fields. The free-helper form (rather than a `protected freeze()`\n * instance method) keeps the class type structurally narrow so emitted\n * contract literal types remain assignable to their class types.\n *\n * The helper name stays `freezeNode` — it operates on IR nodes\n * regardless of root naming.\n */\nexport function freezeNode<T extends IRNode>(node: T): T {\n Object.freeze(node);\n return node;\n}\n","import type { StorageNamespace } from '@prisma-next/contract/types';\nimport { type IRNode, IRNodeBase } from './ir-node';\n\n/**\n * Reserved sentinel namespace id for the late-bound storage slot —\n * the slot whose binding the target resolves at connection time\n * rather than at authoring time. Postgres uses it for `search_path`\n * late binding; SQLite uses it for the trivial singleton; Mongo uses\n * it for the connection's `db` binding.\n *\n * Materialised target-side as a singleton subclass of the target's\n * `NamespaceBase` concretion that overrides the namespace's\n * qualifier-emission methods to elide the prefix entirely. Call sites\n * stay polymorphic and never branch on `id === UNBOUND_NAMESPACE_ID`\n * — the singleton's overrides drop the qualifier so emitted SQL / Mongo\n * commands look unqualified.\n *\n * The double-underscore decoration marks the id as a framework-reserved\n * coordinate when it appears in a JSON envelope (cold-read-as-reserved\n * — no realistic collision with user-declared namespace names).\n *\n * Encoded as an exported const (rather than scattered string literals)\n * so the sentinel-id invariant is single-sourced: any production-source\n * site that constructs an unbound-namespace singleton imports this\n * constant.\n */\nexport const UNBOUND_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * Framework-level building block for a \"namespace\" — the database-level\n * grouping under which storage objects (tables, collections, enums, …)\n * reside. Each target's namespace concretion maps the framework concept to\n * a target-native binding:\n *\n * - Postgres: a schema (`CREATE SCHEMA …`); rendered as `\"<schema>\"`.\n * - SQLite: the singleton `UNBOUND_NAMESPACE_ID`; emitted SQL has no qualifier.\n * - Mongo: the connection's `db` field; addressed as a database name.\n *\n * See `UNBOUND_NAMESPACE_ID` above for the sentinel id and the\n * singleton-subclass pattern that materialises it.\n *\n * The framework promises only the coordinate (`id`) — the named storage\n * entities a namespace contains are family-typed (SQL contributes\n * `table` / `type`, Mongo contributes `collection`, future families pick\n * their own native idiom under `entries`). Generic consumers walking \"all\n * named entries\" go through a family-typed namespace, not the framework\n * `Namespace`.\n *\n * Every namespace concretion (e.g. family-built SQL namespaces,\n * `MongoUnboundNamespace`, target-promoted namespaces like\n * `PostgresSchema`) carries exactly: `id` (enumerable string),\n * `entries` (frozen object holding entity-kind slot maps), and `kind`\n * (non-enumerable string discriminator set via `Object.defineProperty`).\n * Each slot map under `entries` uses a singular essence key (`table`,\n * `type`, `collection`, …) mapping entity names to IR classes. No other\n * own-enumerable data lives on a namespace; non-entity computed data lives\n * on the surrounding storage or contract IR. The framework's\n * `elementCoordinates(storage)` walk relies on this invariant to enumerate\n * entities structurally without family-specific knowledge.\n */\nexport interface Namespace extends IRNode, StorageNamespace {\n readonly kind: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\nexport abstract class NamespaceBase extends IRNodeBase implements Namespace {\n abstract readonly id: string;\n abstract readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n abstract override readonly kind: string;\n}\n","import type { StorageBase } from '@prisma-next/contract/types';\nimport type { IRNode } from './ir-node';\nimport type { Namespace } from './namespace';\n\n/**\n * Canonical address for a named entity in Contract IR / Schema IR.\n *\n * `plane` is `'domain' | 'storage'`: which top-level contract plane the\n * entity lives on. Domain-side walks yield `plane: 'domain'` via\n * {@link domainElementCoordinates}; {@link elementCoordinates} over storage\n * yields `plane: 'storage'`.\n *\n * Cross-plane references obey a directional invariant: domain → storage is\n * allowed; storage → domain is forbidden. That rule is enforced by a\n * separate validator, not by constraining this coordinate shape — the\n * coordinate carries the axis the validator checks.\n *\n * Iteration order over namespace properties follows `Object.entries` order;\n * consumers that depend on ordering must sort.\n */\nexport interface EntityCoordinate {\n readonly plane: 'domain' | 'storage';\n readonly namespaceId: string;\n readonly entityKind: string;\n readonly entityName: string;\n}\n\n/**\n * Lazy walk over every named storage entity in a `Storage`-shaped\n * value, yielded as {@link EntityCoordinate} tuples with\n * `plane: 'storage'` (the parameter type binds the plane).\n *\n * Iterates each namespace's `entries` slot maps structurally. Skips\n * non-object `entries`; `id` and `kind` are not walked (`kind` is\n * non-enumerable on concretions). For every entity-kind key under\n * `entries` whose value is a non-null object, yields one coordinate per\n * entity name in that map. No family-specific slot vocabulary is required.\n */\nexport function* elementCoordinates(\n storage: Pick<StorageBase, 'namespaces'>,\n): Generator<EntityCoordinate> {\n for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {\n const entries = ns.entries;\n if (entries === null || typeof entries !== 'object') continue;\n for (const [entityKind, slot] of Object.entries(entries)) {\n if (slot === null || typeof slot !== 'object') continue;\n for (const entityName of Object.keys(slot)) {\n yield { plane: 'storage', namespaceId, entityKind, entityName };\n }\n }\n }\n}\n\n/**\n * Framework-level promise that every Contract IR / Schema IR carries a\n * collection of namespaces keyed by namespace id. Family storage\n * concretions (`SqlStorage`, `MongoStorage`) refine the shape with\n * family-specific fields (tables, collections, enums, …); target\n * concretions add target fields where the family vocabulary doesn't\n * reach.\n *\n * Keeping `namespaces` at the framework layer enforces that every storage\n * object — across any target — is namespace-scoped. The framework can\n * therefore walk the namespace map without knowing the family alphabet, and\n * the `(namespace.id, name)` keying that the verifier and planner depend on\n * is honest at every layer.\n *\n * Extends `IRNode` so the framework's IR-walking surfaces (verifiers,\n * serializers) can dispatch on `Storage`-typed slots through the same\n * IR-node alphabet as every other node — the structural dual already\n * holds in code (every concrete storage class extends an IR-node base);\n * the interface promotion makes the typing honest.\n *\n * **Persisted envelope shape is target-owned, not framework-promised.**\n * Whether the `namespaces` map appears in the on-disk JSON envelope is\n * a per-target decision made by `ContractSerializer.serializeContract`.\n * Some targets emit a JSON-clean namespace shape that round-trips\n * through `JSON.stringify` cleanly (SQL today via the family-layer\n * identity serializer); others ship runtime-only fields on their\n * namespace concretions and override `serializeContract` to strip\n * them (Mongo). Future open (F16): extend the per-target\n * `ContractSerializer` integration-test surface with an explicit\n * envelope-shape assertion for each target, so the strip-vs-pass-through\n * choice is locked at test time rather than implied by the override\n * presence/absence. Earned by PR2's per-target namespace lift, when\n * `PostgresSchema` / `SqliteUnboundDatabase` start carrying\n * target-specific fields.\n */\nexport interface Storage extends IRNode {\n readonly namespaces: Readonly<Record<string, Namespace>>;\n}\n"],"mappings":";;;;;;;;AAUA,UAAiB,yBACf,QAC6B;CAC7B,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,OAAO,UAAU,GAC9D,KAAK,MAAM,CAAC,YAAY,SAAS,OAAO,QAAQ,EAAE,GAAG;EACnD,IAAI,eAAe,MAAM;EACzB,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;EAC/C,KAAK,MAAM,cAAc,OAAO,KAAK,IAAI,GACvC,MAAM;GAAE,OAAO;GAAU;GAAa;GAAY;EAAW;CAEjE;AAEJ;;;ACuBA,IAAsB,aAAtB,MAAmD,CAEnD;;;;;;;;;;AAWA,SAAgB,WAA6B,MAAY;CACvD,OAAO,OAAO,IAAI;CAClB,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;ACnCA,MAAa,uBAAuB;AAuCpC,IAAsB,gBAAtB,cAA4C,WAAgC,CAI5E;;;;;;;;;;;;;;AC/BA,UAAiB,mBACf,SAC6B;CAC7B,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,QAAQ,UAAU,GAAG;EAClE,MAAM,UAAU,GAAG;EACnB,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU;EACrD,KAAK,MAAM,CAAC,YAAY,SAAS,OAAO,QAAQ,OAAO,GAAG;GACxD,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;GAC/C,KAAK,MAAM,cAAc,OAAO,KAAK,IAAI,GACvC,MAAM;IAAE,OAAO;IAAW;IAAa;IAAY;GAAW;EAElE;CACF;AACF"}
{"version":3,"file":"ir.mjs","names":[],"sources":["../src/ir/domain.ts","../src/ir/entity-kind.ts","../src/ir/ir-node.ts","../src/ir/namespace.ts","../src/ir/storage.ts"],"sourcesContent":["import type { ApplicationDomain } from '@prisma-next/contract/types';\nimport type { EntityCoordinate } from './storage';\n\n/**\n * Lazy walk over every named domain entity in a {@link ApplicationDomain},\n * yielded as {@link EntityCoordinate} tuples with `plane: 'domain'`.\n *\n * Same structural rules as {@link elementCoordinates} over storage: skip\n * scalar `id`; each other object-valued property is an entity-kind slot.\n */\nexport function* domainElementCoordinates(\n domain: Pick<ApplicationDomain, 'namespaces'>,\n): Generator<EntityCoordinate> {\n for (const [namespaceId, ns] of Object.entries(domain.namespaces)) {\n for (const [entityKind, slot] of Object.entries(ns)) {\n if (entityKind === 'id') continue;\n if (slot === null || typeof slot !== 'object') continue;\n for (const entityName of Object.keys(slot)) {\n yield { plane: 'domain', namespaceId, entityKind, entityName };\n }\n }\n }\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport type { Type } from 'arktype';\n\nexport interface EntityKindDescriptor<Input, Node> {\n readonly kind: string;\n // Type<unknown>, not Type<Input>: AnyEntityKindDescriptor widens Input to never, which would force an unusable Type<never>; concrete descriptors still carry their real schema.\n readonly schema: Type<unknown>;\n readonly construct: (input: Input) => Node;\n}\n\nexport type AnyEntityKindDescriptor = EntityKindDescriptor<never, unknown>;\n\n/**\n * Hydrates a namespace's entities from raw JSON maps into IR class instances.\n *\n * For each kind in `entries`: if the descriptor map has a descriptor,\n * construct each inner-map value; otherwise freeze-and-carry (`'carry'`)\n * or throw naming the kind and nsId (`'fail'`).\n *\n * The single boundary cast hands `value` to `descriptor.construct` as its\n * `Input`. The value satisfies the kind's `Input` either by the\n * entries-input contract at authoring time or by prior `validateStorage`\n * validation at hydration time.\n */\nexport function hydrateNamespaceEntities(\n entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n kinds: ReadonlyMap<string, AnyEntityKindDescriptor>,\n onUnknown: 'carry' | 'fail',\n nsId?: string,\n): Record<string, Readonly<Record<string, unknown>>> {\n const result: Record<string, Readonly<Record<string, unknown>>> = {};\n for (const [kind, rawMap] of Object.entries(entries)) {\n const descriptor = kinds.get(kind);\n if (descriptor !== undefined) {\n const built: Record<string, unknown> = {};\n for (const [name, value] of Object.entries(rawMap)) {\n built[name] = descriptor.construct(\n blindCast<\n never,\n \"value is this kind's descriptor Input: when authoring, the typed entries-input contract produces it; when hydrating, it was validated against descriptor.schema before this loop. The never target is AnyEntityKindDescriptor's erased Input parameter.\"\n >(value),\n );\n }\n result[kind] = Object.freeze(built);\n } else if (onUnknown === 'carry') {\n result[kind] = Object.freeze(rawMap);\n } else {\n throw new Error(\n `Unknown entries key \"${kind}\" in namespace \"${nsId ?? '?'}\"; no hydration factory registered for this entity kind`,\n );\n }\n }\n return result;\n}\n","/**\n * Framework-level IR alphabet.\n *\n * The framework's contribution to Contract IR / Schema IR is a common\n * root for the IR class hierarchy and a freeze affordance. Family\n * abstract bases (e.g. `SqlNode`, `MongoSchemaIRNode`) refine the alphabet\n * for their family shape; targets ship the concrete classes.\n *\n * `kind` is an optional discriminator on the base. Families and leaves\n * that benefit from discriminated-union dispatch declare their own\n * literal `kind` at the level that earns it — Mongo leaves carry\n * per-class literals (`readonly kind = 'mongo-collection' as const`)\n * because Mongo IR has polymorphic walkers; SQL declares a single\n * family-level `kind = 'sql'` on `SqlNode` because SQL IR has no\n * polymorphic dispatch today. No framework consumer dispatches on\n * `IRNode.kind` at the BASE type — every dispatch site narrows\n * through a union of leaves where each leaf carries a literal kind, so\n * requiring `kind` at the base would be unearned. Future leaves that\n * earn polymorphic dispatch override with a required literal at that\n * leaf (e.g. `override readonly kind = 'pack-contributed-kind' as const`).\n *\n * `IRNodeBase` carries no methods: the freeze-and-assign affordance\n * lives in the free `freezeNode` helper below. Keeping `freezeNode` out\n * of the class type means an emitted contract literal type\n * (`{ readonly kind: 'mongo-collection', ... }` or an unkeyed literal\n * like `{ nativeType, codecId, nullable }`) is structurally assignable\n * to its class type — a `protected freeze()` instance method would\n * otherwise leak into the public type surface and require the literal\n * to carry it too.\n *\n * Subclasses construct fields then call `freezeNode(this)` to seal the\n * instance. Frozen instances + plain readonly fields keep IR nodes\n * JSON-clean by construction, so `JSON.stringify(node)` produces canonical\n * JSON without a `toJSON()` method. The `ContractSerializer` SPI handles\n * round-trip from canonical JSON back to typed class instances.\n *\n * The name (`IRNode` / `IRNodeBase`) reflects the dual-hierarchy reality:\n * this base is the common root for both Contract IR and Schema IR class\n * hierarchies, not a Schema-IR-specific alphabet.\n */\n\nexport interface IRNode {\n readonly kind?: string;\n}\n\nexport abstract class IRNodeBase implements IRNode {\n abstract readonly kind?: string;\n}\n\n/**\n * Seal an IR class instance after its constructor has assigned all\n * fields. The free-helper form (rather than a `protected freeze()`\n * instance method) keeps the class type structurally narrow so emitted\n * contract literal types remain assignable to their class types.\n *\n * The helper name stays `freezeNode` — it operates on IR nodes\n * regardless of root naming.\n */\nexport function freezeNode<T extends IRNode>(node: T): T {\n Object.freeze(node);\n return node;\n}\n","import type { StorageNamespace } from '@prisma-next/contract/types';\nimport { type IRNode, IRNodeBase } from './ir-node';\n\n/**\n * Reserved sentinel namespace id for the late-bound storage slot —\n * the slot whose binding the target resolves at connection time\n * rather than at authoring time. Postgres uses it for `search_path`\n * late binding; SQLite uses it for the trivial singleton; Mongo uses\n * it for the connection's `db` binding.\n *\n * Materialised target-side as a singleton subclass of the target's\n * `NamespaceBase` concretion that overrides the namespace's\n * qualifier-emission methods to elide the prefix entirely. Call sites\n * stay polymorphic and never branch on `id === UNBOUND_NAMESPACE_ID`\n * — the singleton's overrides drop the qualifier so emitted SQL / Mongo\n * commands look unqualified.\n *\n * The double-underscore decoration marks the id as a framework-reserved\n * coordinate when it appears in a JSON envelope (cold-read-as-reserved\n * — no realistic collision with user-declared namespace names).\n *\n * Encoded as an exported const (rather than scattered string literals)\n * so the sentinel-id invariant is single-sourced: any production-source\n * site that constructs an unbound-namespace singleton imports this\n * constant.\n */\nexport const UNBOUND_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * Framework-level building block for a \"namespace\" — the database-level\n * grouping under which storage objects (tables, collections, enums, …)\n * reside. Each target's namespace concretion maps the framework concept to\n * a target-native binding:\n *\n * - Postgres: a schema (`CREATE SCHEMA …`); rendered as `\"<schema>\"`.\n * - SQLite: the singleton `UNBOUND_NAMESPACE_ID`; emitted SQL has no qualifier.\n * - Mongo: the connection's `db` field; addressed as a database name.\n *\n * See `UNBOUND_NAMESPACE_ID` above for the sentinel id and the\n * singleton-subclass pattern that materialises it.\n *\n * The framework promises only the coordinate (`id`) — the named storage\n * entities a namespace contains are family-typed (SQL contributes\n * `table` / `type`, Mongo contributes `collection`, future families pick\n * their own native idiom under `entries`). Generic consumers walking \"all\n * named entries\" go through a family-typed namespace, not the framework\n * `Namespace`.\n *\n * Every namespace concretion (e.g. family-built SQL namespaces,\n * `MongoUnboundNamespace`, target-promoted namespaces like\n * `PostgresSchema`) carries exactly: `id` (enumerable string),\n * `entries` (frozen object holding entity-kind slot maps), and `kind`\n * (non-enumerable string discriminator set via `Object.defineProperty`).\n * Each slot map under `entries` uses a singular essence key (`table`,\n * `type`, `collection`, …) mapping entity names to IR classes. No other\n * own-enumerable data lives on a namespace; non-entity computed data lives\n * on the surrounding storage or contract IR. The framework's\n * `elementCoordinates(storage)` walk relies on this invariant to enumerate\n * entities structurally without family-specific knowledge.\n */\nexport interface Namespace extends IRNode, StorageNamespace {\n readonly kind: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\nexport abstract class NamespaceBase extends IRNodeBase implements Namespace {\n abstract readonly id: string;\n abstract readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n abstract override readonly kind: string;\n}\n","import { isPlainRecord } from '@prisma-next/contract/is-plain-record';\nimport type { StorageBase } from '@prisma-next/contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { IRNode } from './ir-node';\nimport type { Namespace } from './namespace';\n\nexport { isPlainRecord };\n\n/**\n * Canonical address for a named entity in Contract IR / Schema IR.\n *\n * `plane` is `'domain' | 'storage'`: which top-level contract plane the\n * entity lives on. Domain-side walks yield `plane: 'domain'` via\n * {@link domainElementCoordinates}; {@link elementCoordinates} over storage\n * yields `plane: 'storage'`.\n *\n * Cross-plane references obey a directional invariant: domain → storage is\n * allowed; storage → domain is forbidden. That rule is enforced by a\n * separate validator, not by constraining this coordinate shape — the\n * coordinate carries the axis the validator checks.\n *\n * Iteration order over namespace properties follows `Object.entries` order;\n * consumers that depend on ordering must sort.\n */\nexport interface EntityCoordinate {\n readonly plane: 'domain' | 'storage';\n readonly namespaceId: string;\n readonly entityKind: string;\n readonly entityName: string;\n}\n\n/**\n * Lazy walk over every named storage entity in a `Storage`-shaped\n * value, yielded as {@link EntityCoordinate} tuples with\n * `plane: 'storage'` (the parameter type binds the plane).\n *\n * Iterates each namespace's `entries` kind maps structurally. Skips\n * non-object `entries`; `id` and `kind` are not walked (`kind` is\n * non-enumerable on concretions). For every entity-kind key under\n * `entries` whose value is a non-null object, yields one coordinate per\n * entity name in that map. No family-specific kind vocabulary is required.\n */\nexport function* elementCoordinates(\n storage: Pick<StorageBase, 'namespaces'>,\n): Generator<EntityCoordinate> {\n for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {\n const entries = ns.entries;\n if (entries === null || typeof entries !== 'object') continue;\n for (const [entityKind, kindMap] of Object.entries(entries)) {\n if (kindMap === null || typeof kindMap !== 'object') continue;\n for (const entityName of Object.keys(kindMap)) {\n yield { plane: 'storage', namespaceId, entityKind, entityName };\n }\n }\n }\n}\n\n/**\n * Looks up a single entity in a `Storage`-shaped value by its full coordinate.\n * Returns `undefined` if the namespace, entity kind, or entity name is absent.\n * The type parameter is a caller assertion — the walk itself is structural\n * and cannot verify the entity's shape.\n */\nexport function entityAt<T = unknown>(\n storage: Pick<StorageBase, 'namespaces'>,\n coord: Pick<EntityCoordinate, 'namespaceId' | 'entityKind' | 'entityName'>,\n): T | undefined {\n const ns = storage.namespaces[coord.namespaceId];\n if (ns === undefined) return undefined;\n const entries = ns.entries;\n if (!isPlainRecord(entries)) return undefined;\n const kindMap = entries[coord.entityKind];\n if (!isPlainRecord(kindMap)) return undefined;\n if (!Object.hasOwn(kindMap, coord.entityName)) return undefined;\n return blindCast<T | undefined, 'caller asserts the entity type at this coordinate'>(\n kindMap[coord.entityName],\n );\n}\n\n/**\n * Framework-level promise that every Contract IR / Schema IR carries a\n * collection of namespaces keyed by namespace id. Family storage\n * concretions (`SqlStorage`, `MongoStorage`) refine the shape with\n * family-specific fields (tables, collections, enums, …); target\n * concretions add target fields where the family vocabulary doesn't\n * reach.\n *\n * Keeping `namespaces` at the framework layer enforces that every storage\n * object — across any target — is namespace-scoped. The framework can\n * therefore walk the namespace map without knowing the family alphabet, and\n * the `(namespace.id, name)` keying that the verifier and planner depend on\n * is honest at every layer.\n *\n * Extends `IRNode` so the framework's IR-walking surfaces (verifiers,\n * serializers) can dispatch on `Storage`-typed fields through the same\n * IR-node alphabet as every other node — the structural dual already\n * holds in code (every concrete storage class extends an IR-node base);\n * the interface promotion makes the typing honest.\n *\n * **Persisted envelope shape is target-owned, not framework-promised.**\n * Whether the `namespaces` map appears in the on-disk JSON envelope is\n * a per-target decision made by `ContractSerializer.serializeContract`.\n * Some targets emit a JSON-clean namespace shape that round-trips\n * through `JSON.stringify` cleanly (SQL today via the family-layer\n * identity serializer); others ship runtime-only fields on their\n * namespace concretions and override `serializeContract` to strip\n * them (Mongo). Future open (F16): extend the per-target\n * `ContractSerializer` integration-test surface with an explicit\n * envelope-shape assertion for each target, so the strip-vs-pass-through\n * choice is locked at test time rather than implied by the override\n * presence/absence. Earned by PR2's per-target namespace lift, when\n * `PostgresSchema` / `SqliteUnboundDatabase` start carrying\n * target-specific fields.\n */\nexport interface Storage extends IRNode {\n readonly namespaces: Readonly<Record<string, Namespace>>;\n}\n"],"mappings":";;;;;;;;;;AAUA,UAAiB,yBACf,QAC6B;CAC7B,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,OAAO,UAAU,GAC9D,KAAK,MAAM,CAAC,YAAY,SAAS,OAAO,QAAQ,EAAE,GAAG;EACnD,IAAI,eAAe,MAAM;EACzB,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;EAC/C,KAAK,MAAM,cAAc,OAAO,KAAK,IAAI,GACvC,MAAM;GAAE,OAAO;GAAU;GAAa;GAAY;EAAW;CAEjE;AAEJ;;;;;;;;;;;;;;;ACEA,SAAgB,yBACd,SACA,OACA,WACA,MACmD;CACnD,MAAM,SAA4D,CAAC;CACnE,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,OAAO,GAAG;EACpD,MAAM,aAAa,MAAM,IAAI,IAAI;EACjC,IAAI,eAAe,KAAA,GAAW;GAC5B,MAAM,QAAiC,CAAC;GACxC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,GAC/C,MAAM,QAAQ,WAAW,UACvB,UAGE,KAAK,CACT;GAEF,OAAO,QAAQ,OAAO,OAAO,KAAK;EACpC,OAAO,IAAI,cAAc,SACvB,OAAO,QAAQ,OAAO,OAAO,MAAM;OAEnC,MAAM,IAAI,MACR,wBAAwB,KAAK,kBAAkB,QAAQ,IAAI,wDAC7D;CAEJ;CACA,OAAO;AACT;;;ACRA,IAAsB,aAAtB,MAAmD,CAEnD;;;;;;;;;;AAWA,SAAgB,WAA6B,MAAY;CACvD,OAAO,OAAO,IAAI;CAClB,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;ACnCA,MAAa,uBAAuB;AAuCpC,IAAsB,gBAAtB,cAA4C,WAAgC,CAI5E;;;;;;;;;;;;;;AC3BA,UAAiB,mBACf,SAC6B;CAC7B,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,QAAQ,UAAU,GAAG;EAClE,MAAM,UAAU,GAAG;EACnB,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU;EACrD,KAAK,MAAM,CAAC,YAAY,YAAY,OAAO,QAAQ,OAAO,GAAG;GAC3D,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU;GACrD,KAAK,MAAM,cAAc,OAAO,KAAK,OAAO,GAC1C,MAAM;IAAE,OAAO;IAAW;IAAa;IAAY;GAAW;EAElE;CACF;AACF;;;;;;;AAQA,SAAgB,SACd,SACA,OACe;CACf,MAAM,KAAK,QAAQ,WAAW,MAAM;CACpC,IAAI,OAAO,KAAA,GAAW,OAAO,KAAA;CAC7B,MAAM,UAAU,GAAG;CACnB,IAAI,CAAC,cAAc,OAAO,GAAG,OAAO,KAAA;CACpC,MAAM,UAAU,QAAQ,MAAM;CAC9B,IAAI,CAAC,cAAc,OAAO,GAAG,OAAO,KAAA;CACpC,IAAI,CAAC,OAAO,OAAO,SAAS,MAAM,UAAU,GAAG,OAAO,KAAA;CACtD,OAAO,UACL,QAAQ,MAAM,WAChB;AACF"}

@@ -1,4 +0,4 @@

import { B as PslExtensionBlockParamOption, F as PslBlockParamRef, G as PslSpan, H as PslExtensionBlockParamScalarValue, I as PslBlockParamValue, L as PslDiagnosticCode, M as PslBlockParam, N as PslBlockParamList, P as PslBlockParamOption, R as PslExtensionBlock, U as PslExtensionBlockParamValue, V as PslExtensionBlockParamRef, W as PslPosition, m as AuthoringPslBlockDescriptorNamespace, p as AuthoringPslBlockDescriptor, z as PslExtensionBlockParamList } from "./framework-authoring-R0TYCkvG.mjs";
import { c as CodecLookup } from "./codec-DCQAerzB.mjs";
import { A as flatPslCompositeTypes, C as PslNamespace, D as PslTypesBlock, E as PslTypeConstructorCall, F as namespacePslExtensionBlocks, M as flatPslModels, N as makePslNamespace, O as PslUniqueConstraint, P as makePslNamespaceEntries, S as PslNamedTypeDeclaration, T as PslReferentialAction, _ as PslField, a as PslAttributeArgument, b as PslModel, c as PslAttributeTarget, d as PslDefaultLiteralValue, f as PslDefaultValue, g as PslEnumValue, h as PslEnum, i as PslAttribute, j as flatPslEnums, k as UNSPECIFIED_PSL_NAMESPACE_ID, l as PslCompositeType, m as PslDocumentAst, n as ParsePslDocumentInput, o as PslAttributeNamedArgument, p as PslDiagnostic, r as ParsePslDocumentResult, s as PslAttributePositionalArgument, t as BUILTIN_PSL_KIND_KEYS, u as PslDefaultFunctionValue, v as PslFieldAttribute, w as PslNamespaceEntry, x as PslModelAttribute, y as PslIndexConstraint } from "./psl-ast-Cn50B-UG.mjs";
import { r as CodecLookup } from "./codec-types-yY3eSmi0.mjs";
import { B as PslExtensionBlockAttribute, F as PslBlockParamOption, G as PslExtensionBlockParamRef, H as PslExtensionBlockParamBare, I as PslBlockParamRef, J as PslPosition, K as PslExtensionBlockParamScalarValue, L as PslBlockParamValue, N as PslBlockParam, P as PslBlockParamList, R as PslDiagnosticCode, U as PslExtensionBlockParamList, V as PslExtensionBlockAttributeArg, W as PslExtensionBlockParamOption, Y as PslSpan, h as AuthoringPslBlockDescriptorNamespace, m as AuthoringPslBlockDescriptor, q as PslExtensionBlockParamValue, z as PslExtensionBlock } from "./framework-authoring-CJC4jwGo.mjs";
import { A as makePslNamespace, C as PslReferentialAction, D as UNSPECIFIED_PSL_NAMESPACE_ID, E as PslUniqueConstraint, M as namespacePslExtensionBlocks, O as flatPslCompositeTypes, S as PslNamespaceEntry, T as PslTypesBlock, _ as PslIndexConstraint, a as PslAttributeArgument, b as PslNamedTypeDeclaration, c as PslAttributeTarget, d as PslDefaultLiteralValue, f as PslDefaultValue, g as PslFieldAttribute, h as PslField, i as PslAttribute, j as makePslNamespaceEntries, k as flatPslModels, l as PslCompositeType, m as PslDocumentAst, n as ParsePslDocumentInput, o as PslAttributeNamedArgument, p as PslDiagnostic, r as ParsePslDocumentResult, s as PslAttributePositionalArgument, t as BUILTIN_PSL_KIND_KEYS, u as PslDefaultFunctionValue, v as PslModel, w as PslTypeConstructorCall, x as PslNamespace, y as PslModelAttribute } from "./psl-ast-B-C_9dWr.mjs";

@@ -36,3 +36,3 @@ //#region src/control/psl-extension-block-validator.d.ts

//#endregion
export { type AuthoringPslBlockDescriptorNamespace, BUILTIN_PSL_KIND_KEYS, type ExtensionBlockRefResolutionContext, ParsePslDocumentInput, ParsePslDocumentResult, PslAttribute, PslAttributeArgument, PslAttributeNamedArgument, PslAttributePositionalArgument, PslAttributeTarget, type PslBlockParam, type PslBlockParamList, type PslBlockParamOption, type PslBlockParamRef, type PslBlockParamValue, PslCompositeType, PslDefaultFunctionValue, PslDefaultLiteralValue, PslDefaultValue, PslDiagnostic, type PslDiagnosticCode, PslDocumentAst, PslEnum, PslEnumValue, type PslExtensionBlock, type PslExtensionBlockParamList, type PslExtensionBlockParamOption, type PslExtensionBlockParamRef, type PslExtensionBlockParamScalarValue, type PslExtensionBlockParamValue, PslField, PslFieldAttribute, PslIndexConstraint, PslModel, PslModelAttribute, PslNamedTypeDeclaration, PslNamespace, PslNamespaceEntry, type PslPosition, PslReferentialAction, type PslSpan, PslTypeConstructorCall, PslTypesBlock, PslUniqueConstraint, UNSPECIFIED_PSL_NAMESPACE_ID, flatPslCompositeTypes, flatPslEnums, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock };
export { type AuthoringPslBlockDescriptorNamespace, BUILTIN_PSL_KIND_KEYS, type ExtensionBlockRefResolutionContext, ParsePslDocumentInput, ParsePslDocumentResult, PslAttribute, PslAttributeArgument, PslAttributeNamedArgument, PslAttributePositionalArgument, PslAttributeTarget, type PslBlockParam, type PslBlockParamList, type PslBlockParamOption, type PslBlockParamRef, type PslBlockParamValue, PslCompositeType, PslDefaultFunctionValue, PslDefaultLiteralValue, PslDefaultValue, PslDiagnostic, type PslDiagnosticCode, PslDocumentAst, type PslExtensionBlock, type PslExtensionBlockAttribute, type PslExtensionBlockAttributeArg, type PslExtensionBlockParamBare, type PslExtensionBlockParamList, type PslExtensionBlockParamOption, type PslExtensionBlockParamRef, type PslExtensionBlockParamScalarValue, type PslExtensionBlockParamValue, PslField, PslFieldAttribute, PslIndexConstraint, PslModel, PslModelAttribute, PslNamedTypeDeclaration, PslNamespace, PslNamespaceEntry, type PslPosition, PslReferentialAction, type PslSpan, PslTypeConstructorCall, PslTypesBlock, PslUniqueConstraint, UNSPECIFIED_PSL_NAMESPACE_ID, flatPslCompositeTypes, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock };
//# sourceMappingURL=psl-ast.d.mts.map

@@ -35,5 +35,2 @@ import { blindCast } from "@prisma-next/utils/casts";

}
get enums() {
return blindCast(Object.values(this.entries["enum"] ?? {}));
}
get compositeTypes() {

@@ -52,3 +49,3 @@ return blindCast(Object.values(this.entries["compositeType"] ?? {}));

*/
function makePslNamespaceEntries(models, enums, compositeTypes, extensionBlocks) {
function makePslNamespaceEntries(models, compositeTypes, extensionBlocks) {
const container = {};

@@ -60,7 +57,2 @@ if (models.length > 0) {

}
if (enums.length > 0) {
const map = {};
for (const e of enums) map[e.name] = e;
container["enum"] = Object.freeze(map);
}
if (compositeTypes.length > 0) {

@@ -87,8 +79,2 @@ const map = {};

/**
* Returns all enums from every namespace in document order.
*/
function flatPslEnums(ast) {
return ast.namespaces.flatMap((ns) => blindCast(Object.values(ns.entries["enum"] ?? {})));
}
/**
* Returns all composite types from every namespace in document order.

@@ -105,9 +91,7 @@ */

* Built-in keys match the PSL keyword used on each block type:
* `'model'`, `'enum'`, `'compositeType'`.
* `'model'`, `'compositeType'`. The `'enum'` keyword is claimed by the
* extension-block grammar via a registered descriptor, so `entries['enum']`
* holds `PslExtensionBlock` nodes and is returned by `namespacePslExtensionBlocks`.
*/
const BUILTIN_PSL_KIND_KEYS = new Set([
"model",
"enum",
"compositeType"
]);
const BUILTIN_PSL_KIND_KEYS = new Set(["model", "compositeType"]);
/**

@@ -117,4 +101,4 @@ * Returns all extension-contributed blocks in the given namespace, in

*
* Reads from `namespace.entries`, skipping the three built-in kind keys
* (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain
* Reads from `namespace.entries`, skipping the built-in kind keys
* (`'model'`, `'compositeType'`). All remaining kind maps contain
* only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).

@@ -152,10 +136,12 @@ */

const nodeKeys = new Set(Object.keys(node.parameters));
for (const key of nodeKeys) if (!descriptorKeys.has(key)) {
const captured = node.parameters[key];
diagnostics.push({
code: "PSL_EXTENSION_UNKNOWN_PARAMETER",
message: `Unknown parameter "${key}" in "${descriptor.keyword}" block "${node.name}". The descriptor does not declare this parameter.`,
sourceId,
span: captured?.span ?? node.span
});
if (!descriptor.variadicParameters) {
for (const key of nodeKeys) if (!descriptorKeys.has(key)) {
const captured = node.parameters[key];
diagnostics.push({
code: "PSL_EXTENSION_UNKNOWN_PARAMETER",
message: `Unknown parameter "${key}" in "${descriptor.keyword}" block "${node.name}". The descriptor does not declare this parameter.`,
sourceId,
span: captured?.span ?? node.span
});
}
}

@@ -260,4 +246,4 @@ for (const [key, param] of Object.entries(descriptor.parameters)) if (param.required === true && !nodeKeys.has(key)) diagnostics.push({

//#endregion
export { BUILTIN_PSL_KIND_KEYS, UNSPECIFIED_PSL_NAMESPACE_ID, flatPslCompositeTypes, flatPslEnums, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock };
export { BUILTIN_PSL_KIND_KEYS, UNSPECIFIED_PSL_NAMESPACE_ID, flatPslCompositeTypes, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock };
//# sourceMappingURL=psl-ast.mjs.map

@@ -1,1 +0,1 @@

{"version":3,"file":"psl-ast.mjs","names":[],"sources":["../src/control/psl-ast.ts","../src/control/psl-extension-block-validator.ts"],"sourcesContent":["export type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring';\nexport type {\n PslBlockParam,\n PslBlockParamList,\n PslBlockParamOption,\n PslBlockParamRef,\n PslBlockParamValue,\n PslDiagnosticCode,\n PslExtensionBlock,\n PslExtensionBlockParamList,\n PslExtensionBlockParamOption,\n PslExtensionBlockParamRef,\n PslExtensionBlockParamScalarValue,\n PslExtensionBlockParamValue,\n PslPosition,\n PslSpan,\n} from '../shared/psl-extension-block';\n\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { CodecLookup } from '../shared/codec-types';\nimport type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring';\nimport type { PslDiagnosticCode, PslExtensionBlock, PslSpan } from '../shared/psl-extension-block';\n\nexport interface PslDiagnostic {\n readonly code: PslDiagnosticCode;\n readonly message: string;\n readonly sourceId: string;\n readonly span: PslSpan;\n}\n\nexport interface PslDefaultFunctionValue {\n readonly kind: 'function';\n readonly name: 'autoincrement' | 'now';\n}\n\nexport interface PslDefaultLiteralValue {\n readonly kind: 'literal';\n readonly value: string | number | boolean;\n}\n\nexport type PslDefaultValue = PslDefaultFunctionValue | PslDefaultLiteralValue;\n\nexport type PslAttributeTarget = 'field' | 'model' | 'enum' | 'namedType';\n\nexport interface PslAttributePositionalArgument {\n readonly kind: 'positional';\n readonly value: string;\n readonly span: PslSpan;\n}\n\nexport interface PslAttributeNamedArgument {\n readonly kind: 'named';\n readonly name: string;\n readonly value: string;\n readonly span: PslSpan;\n}\n\nexport type PslAttributeArgument = PslAttributePositionalArgument | PslAttributeNamedArgument;\n\nexport interface PslTypeConstructorCall {\n readonly kind: 'typeConstructor';\n readonly path: readonly string[];\n readonly args: readonly PslAttributeArgument[];\n readonly span: PslSpan;\n}\n\nexport interface PslAttribute {\n readonly kind: 'attribute';\n readonly target: PslAttributeTarget;\n readonly name: string;\n readonly args: readonly PslAttributeArgument[];\n readonly span: PslSpan;\n}\n\nexport type PslReferentialAction = string;\n\nexport type PslFieldAttribute = PslAttribute;\n\nexport interface PslField {\n readonly kind: 'field';\n readonly name: string;\n /** Unqualified type name, e.g. `\"User\"` for both `User`, `auth.User`, and `supabase:auth.User`. */\n readonly typeName: string;\n /** Namespace qualifier from a dot-qualified type reference, e.g. `\"auth\"` for `auth.User` or `supabase:auth.User`. Absent for unqualified types. */\n readonly typeNamespaceId?: string;\n /**\n * Contract-space qualifier from a colon-prefix type reference, e.g. `\"supabase\"` for\n * `supabase:auth.User` or `supabase:User`. Absent for local (same-space) type references.\n *\n * When present, the field references a model from a different contract space. The namespace\n * (`typeNamespaceId`) and model name (`typeName`) identify the target within that space.\n * Physical table resolution against the extension contract is deferred to the aggregate stage (M3).\n */\n readonly typeContractSpaceId?: string;\n readonly typeConstructor?: PslTypeConstructorCall;\n readonly optional: boolean;\n readonly list: boolean;\n readonly typeRef?: string;\n readonly attributes: readonly PslFieldAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslUniqueConstraint {\n readonly kind: 'unique';\n readonly fields: readonly string[];\n readonly span: PslSpan;\n}\n\nexport interface PslIndexConstraint {\n readonly kind: 'index';\n readonly fields: readonly string[];\n readonly span: PslSpan;\n}\n\nexport type PslModelAttribute = PslAttribute;\n\nexport interface PslModel {\n readonly kind: 'model';\n readonly name: string;\n readonly fields: readonly PslField[];\n readonly attributes: readonly PslModelAttribute[];\n readonly span: PslSpan;\n /**\n * Optional leading comment line emitted above the `model` keyword by the\n * printer. Producers (e.g. `sqlSchemaIrToPslAst`) attach introspection\n * advisories such as \"// WARNING: This table has no primary key in the\n * database\" here. The parser leaves this field unset; round-tripping a\n * parsed schema does not re-attach comments.\n */\n readonly comment?: string;\n}\n\nexport interface PslEnumValue {\n readonly kind: 'enumValue';\n readonly name: string;\n /**\n * Optional storage label for the enum member, captured from a trailing\n * `@map(\"...\")` attribute on the member line. The parser populates this\n * when the source PSL carries an explicit `@map`. Producers (e.g.\n * `sqlSchemaIrToPslAst`) leave it unset; the printer emits `@map(...)`\n * automatically when normalisation would change the printed member name\n * (so an enum value `'in-progress'` becomes `inProgress @map(\"in-progress\")`\n * in PSL, preserving the round-trip).\n */\n readonly mapName?: string;\n readonly span: PslSpan;\n}\n\nexport interface PslEnum {\n readonly kind: 'enum';\n readonly name: string;\n readonly values: readonly PslEnumValue[];\n readonly attributes: readonly PslAttribute[];\n readonly span: PslSpan;\n}\n\n/**\n * A reusable group of fields embedded in a model (a `type Name { … }` block) —\n * e.g. a MongoDB embedded document or a Postgres composite type. Unlike\n * {@link PslModel} it has no storage or identity of its own.\n */\nexport interface PslCompositeType {\n readonly kind: 'compositeType';\n readonly name: string;\n readonly fields: readonly PslField[];\n readonly attributes: readonly PslAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslNamedTypeDeclaration {\n readonly kind: 'namedType';\n readonly name: string;\n /**\n * Parser invariant: exactly one of `baseType` and `typeConstructor` is set.\n * Expressing this as a discriminated union trips TypeScript narrowing when\n * the declaration flows through helpers that accept the full union.\n */\n readonly baseType?: string;\n readonly typeConstructor?: PslTypeConstructorCall;\n readonly attributes: readonly PslAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslTypesBlock {\n readonly kind: 'types';\n readonly declarations: readonly PslNamedTypeDeclaration[];\n readonly span: PslSpan;\n}\n\n/**\n * Name of the synthesised namespace bucket the framework parser uses for\n * top-level declarations that appear outside any `namespace { … }` block.\n * The double-underscore decoration signals that the identifier is parser-\n * synthesised and never appears in user-authored PSL source — writing\n * `namespace __unspecified__ { … }` is a parse error.\n *\n * Distinct from the IR sentinel `__unbound__`: the PSL bucket describes\n * syntactic absence at the parser layer; the IR sentinel describes a late-\n * bound storage slot at the IR layer. Per-target interpreters decide how\n * (or whether) to map the PSL bucket to the IR sentinel.\n */\nexport const UNSPECIFIED_PSL_NAMESPACE_ID = '__unspecified__';\n\n/** A value in {@link PslNamespace.entries}: a built-in entity node or an extension-contributed {@link PslExtensionBlock}. */\nexport type PslNamespaceEntry = PslModel | PslEnum | PslCompositeType | PslExtensionBlock;\n\n/**\n * A namespace block, or the parser's synthesised `__unspecified__` bucket for\n * declarations outside any `namespace { … }`. Same-name blocks reopen-merge;\n * `span` points at the first opening.\n *\n * Entities are stored canonically (ADR 224) in `entries[kind][name]`, where\n * `kind` is the PSL keyword for built-ins or the block discriminator for\n * extension kinds, e.g. `entries['policy_select']['ReadPosts']`.\n */\nexport interface PslNamespace {\n readonly kind: 'namespace';\n readonly name: string;\n /** Canonical store: a frozen container of frozen per-kind maps. The accessors below derive from it. */\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n /** Built-in models, from `entries['model']`. Extension kinds: {@link namespacePslExtensionBlocks}. */\n readonly models: readonly PslModel[];\n /** Built-in enums, from `entries['enum']`. */\n readonly enums: readonly PslEnum[];\n /** Built-in composite types, from `entries['compositeType']`. */\n readonly compositeTypes: readonly PslCompositeType[];\n readonly span: PslSpan;\n}\n\n/**\n * Stores `entries`; exposes `models`/`enums`/`compositeTypes` as getters over\n * it. The getters are prototype members (non-enumerable), so spreading or\n * `JSON.stringify`-ing a namespace copies only `entries`, never a duplicate view.\n */\nclass PslNamespaceNode implements PslNamespace {\n readonly kind = 'namespace' as const;\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n\n constructor(init: {\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n }) {\n this.name = init.name;\n this.entries = init.entries;\n this.span = init.span;\n Object.freeze(this);\n }\n\n get models(): readonly PslModel[] {\n return blindCast<readonly PslModel[], 'entries[model] holds only PslModel by construction'>(\n Object.values(this.entries['model'] ?? {}),\n );\n }\n\n get enums(): readonly PslEnum[] {\n return blindCast<readonly PslEnum[], 'entries[enum] holds only PslEnum by construction'>(\n Object.values(this.entries['enum'] ?? {}),\n );\n }\n\n get compositeTypes(): readonly PslCompositeType[] {\n return blindCast<\n readonly PslCompositeType[],\n 'entries[compositeType] holds only PslCompositeType by construction'\n >(Object.values(this.entries['compositeType'] ?? {}));\n }\n}\n\n/** Constructs a {@link PslNamespace}. Use this, never a namespace literal — the accessors must derive from `entries`. */\nexport function makePslNamespace(init: {\n readonly kind: 'namespace';\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n}): PslNamespace {\n return new PslNamespaceNode(init);\n}\n\n/**\n * Builds the frozen `entries[kind][name]` container from per-kind arrays.\n * Built-ins key on their PSL keyword; extension blocks key on their `kind`\n * discriminator. Call this rather than hand-building the literal.\n */\nexport function makePslNamespaceEntries(\n models: readonly PslModel[],\n enums: readonly PslEnum[],\n compositeTypes: readonly PslCompositeType[],\n extensionBlocks: readonly PslExtensionBlock[],\n): Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>> {\n const container: Record<string, Readonly<Record<string, PslNamespaceEntry>>> = {};\n\n if (models.length > 0) {\n const map: Record<string, PslModel> = {};\n for (const m of models) {\n map[m.name] = m;\n }\n container['model'] = Object.freeze(map);\n }\n\n if (enums.length > 0) {\n const map: Record<string, PslEnum> = {};\n for (const e of enums) {\n map[e.name] = e;\n }\n container['enum'] = Object.freeze(map);\n }\n\n if (compositeTypes.length > 0) {\n const map: Record<string, PslCompositeType> = {};\n for (const ct of compositeTypes) {\n map[ct.name] = ct;\n }\n container['compositeType'] = Object.freeze(map);\n }\n\n for (const block of extensionBlocks) {\n const existing = container[block.kind];\n const newMap: Record<string, PslExtensionBlock> = existing\n ? blindCast<Record<string, PslExtensionBlock>, 'kind map holds only PslExtensionBlock'>({\n ...existing,\n })\n : {};\n newMap[block.name] = block;\n container[block.kind] = Object.freeze(newMap);\n }\n\n return Object.freeze(container);\n}\n\nexport interface PslDocumentAst {\n readonly kind: 'document';\n readonly sourceId: string;\n readonly namespaces: readonly PslNamespace[];\n readonly types?: PslTypesBlock;\n readonly span: PslSpan;\n}\n\n/**\n * Returns all models from every namespace in document order. Convenience\n * for consumers that don't (yet) need namespace-awareness.\n */\nexport function flatPslModels(ast: PslDocumentAst): readonly PslModel[] {\n return ast.namespaces.flatMap((ns) =>\n blindCast<PslModel[], 'model kind map contains only PslModel by construction'>(\n Object.values(ns.entries['model'] ?? {}),\n ),\n );\n}\n\n/**\n * Returns all enums from every namespace in document order.\n */\nexport function flatPslEnums(ast: PslDocumentAst): readonly PslEnum[] {\n return ast.namespaces.flatMap((ns) =>\n blindCast<PslEnum[], 'enum kind map contains only PslEnum by construction'>(\n Object.values(ns.entries['enum'] ?? {}),\n ),\n );\n}\n\n/**\n * Returns all composite types from every namespace in document order.\n */\nexport function flatPslCompositeTypes(ast: PslDocumentAst): readonly PslCompositeType[] {\n return ast.namespaces.flatMap((ns) =>\n blindCast<\n PslCompositeType[],\n 'compositeType kind map contains only PslCompositeType by construction'\n >(Object.values(ns.entries['compositeType'] ?? {})),\n );\n}\n\n/**\n * The set of `entries` kind keys that the framework parser reserves for\n * built-in PSL entity kinds. Any own-enumerable key on `PslNamespace.entries`\n * that is **not** in this set was contributed by an extension-block descriptor.\n *\n * Built-in keys match the PSL keyword used on each block type:\n * `'model'`, `'enum'`, `'compositeType'`.\n */\nexport const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string> = new Set([\n 'model',\n 'enum',\n 'compositeType',\n]);\n\n/**\n * Returns all extension-contributed blocks in the given namespace, in\n * insertion order (the order the parser encountered them in the source).\n *\n * Reads from `namespace.entries`, skipping the three built-in kind keys\n * (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain\n * only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).\n */\nexport function namespacePslExtensionBlocks(ns: PslNamespace): readonly PslExtensionBlock[] {\n const result: PslExtensionBlock[] = [];\n for (const [kindKey, kindMap] of Object.entries(ns.entries)) {\n if (BUILTIN_PSL_KIND_KEYS.has(kindKey)) continue;\n for (const entry of Object.values(kindMap)) {\n result.push(\n blindCast<\n PslExtensionBlock,\n 'non-builtin kind maps contain only PslExtensionBlock by construction'\n >(entry),\n );\n }\n }\n return result;\n}\n\nexport interface ParsePslDocumentInput {\n readonly schema: string;\n readonly sourceId: string;\n /**\n * Registry of declarative block descriptors, keyed by arbitrary path\n * segments with {@link AuthoringPslBlockDescriptor} leaves. The registry\n * teaches the parser which top-level keywords belong to extension\n * contributions: when the parser encounters an unknown keyword, it looks\n * it up here and, when found, reads the block generically into a\n * {@link PslExtensionBlock} node. Absent or undefined means no extension\n * blocks are registered and any unknown keyword yields\n * `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`.\n *\n * Contrast with the parsed block nodes themselves, which live in\n * {@link PslNamespace.entries} under their discriminator key (read them with\n * {@link namespacePslExtensionBlocks}); this field holds the registry of\n * descriptors that teach the parser how to read those blocks.\n */\n readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;\n /**\n * Codec lookup for validating `value`-kind extension block parameters.\n * When provided alongside `pslBlockDescriptors`, the generic validator runs\n * over every parsed extension block after the full AST is assembled,\n * appending any diagnostics to the parse result. Absent or undefined means\n * no codec validation runs; `ref` resolution still runs when namespace\n * context is available (built from the assembled namespaces).\n */\n readonly codecLookup?: CodecLookup;\n}\n\nexport interface ParsePslDocumentResult {\n readonly ast: PslDocumentAst;\n readonly diagnostics: readonly PslDiagnostic[];\n readonly ok: boolean;\n}\n","/**\n * Generic validator for extension-contributed top-level PSL blocks.\n *\n * One function — {@link validateExtensionBlock} — takes a parsed\n * {@link PslExtensionBlock}, its {@link AuthoringPslBlockDescriptor}, a\n * {@link CodecLookup} (for `value` parameters), and the set of\n * {@link PslNamespace} objects from the document (for `ref` resolution), and\n * returns the full list of {@link PslDiagnostic} objects for the block.\n *\n * Detection logic per failure mode:\n *\n * 1. **Unknown parameter** — keys present in `node.parameters` that are absent\n * from `descriptor.parameters` (key-set difference). The parser stores\n * unknown parameters as `kind:'value'` stubs; the validator discovers them\n * by comparing the key sets, not by inspecting the captured kind.\n *\n * 2. **Missing required parameter** — `descriptor.parameters` entries with\n * `required: true` whose key is absent from `node.parameters`.\n *\n * 3. **`option` value outside its set** — the captured `token` is not in\n * `descriptor.values`.\n *\n * 4. **`value` rejected by its codec** — the raw string is first parsed as\n * JSON (`JSON.parse(raw)`). If `JSON.parse` throws, the literal is not valid\n * JSON and a `PSL_EXTENSION_INVALID_VALUE` diagnostic is emitted. If parsing\n * succeeds but `codec.decodeJson(jsonValue)` throws, the JSON value is not\n * acceptable to the codec and a `PSL_EXTENSION_INVALID_VALUE` diagnostic is\n * emitted. If `codecLookup.get(codecId)` returns `undefined` (unknown codec\n * id), a `PSL_EXTENSION_INVALID_VALUE` diagnostic is also emitted.\n *\n * 5. **`ref` that does not resolve within its scope** — the captured\n * `identifier` is looked up in the PSL document's `PslNamespace` objects\n * according to `param.scope`:\n * - `same-namespace`: the referent must be in the same namespace as the\n * block (the namespace containing the block).\n * - `same-space`: the referent may be in any namespace in the document.\n * - `cross-space`: pass-through — enforcement is scoped to first-consumer\n * need (RLS roles). This case is documented and clearly flagged; the\n * caller is responsible for wiring cross-space resolution when needed.\n *\n * 6. **`list`** — each element is validated against `param.of` recursively.\n *\n * ### `char`/`varchar` length\n * Not enforced. RLS `using`/`check` strings are unbounded text and the codec\n * already rejects structurally invalid literals; length constraints are a\n * database-side concern, not a PSL authoring constraint.\n *\n * ### `cross-space` scope\n * Implemented as a documented pass-through. The spec permits scoping\n * cross-space enforcement to first-consumer need (RLS roles). When RLS roles\n * arrive, wire `cross-space` resolution through the cross-contract-space\n * coordinate model `(spaceId, namespaceId, entityKind, entityName)`.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { CodecLookup } from '../shared/codec-types';\nimport type { AuthoringPslBlockDescriptor } from '../shared/framework-authoring';\nimport type {\n PslBlockParam,\n PslBlockParamRef,\n PslExtensionBlock,\n PslExtensionBlockParamValue,\n PslSpan,\n} from '../shared/psl-extension-block';\nimport type { PslDiagnostic, PslNamespace } from './psl-ast';\n\n/**\n * Context for ref resolution during extension-block validation.\n *\n * - `ownerNamespace` is the `PslNamespace` that contains the block being\n * validated. Used for `same-namespace` scope checks.\n * - `allNamespaces` is every namespace in the document. Used for `same-space`\n * scope checks.\n */\nexport interface ExtensionBlockRefResolutionContext {\n readonly ownerNamespace: PslNamespace;\n readonly allNamespaces: readonly PslNamespace[];\n}\n\n/**\n * Validate a single parsed extension block against its descriptor.\n *\n * Returns an array of {@link PslDiagnostic} objects (possibly empty). The\n * caller is responsible for threading `sourceId` into each returned diagnostic\n * — the returned objects already have `sourceId` set from the `sourceId`\n * parameter.\n *\n * @param node - The parsed block node produced by the generic framework parser.\n * @param descriptor - The descriptor that claims this block's keyword.\n * @param sourceId - The PSL source file identifier (threaded into diagnostics).\n * @param codecLookup - Used to validate `value`-kind parameter literals via\n * `codecLookup.get(codecId)?.decodeJson(JSON.parse(raw))`.\n * @param refCtx - Namespace context for `ref`-kind scope resolution. Required\n * when any descriptor parameter is `kind: 'ref'`; may be omitted if none are.\n */\nexport function validateExtensionBlock(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n sourceId: string,\n codecLookup: CodecLookup,\n refCtx?: ExtensionBlockRefResolutionContext,\n): readonly PslDiagnostic[] {\n const diagnostics: PslDiagnostic[] = [];\n\n const descriptorKeys = new Set(Object.keys(descriptor.parameters));\n const nodeKeys = new Set(Object.keys(node.parameters));\n\n // 1. Unknown parameters — keys in the node not in the descriptor.\n for (const key of nodeKeys) {\n if (!descriptorKeys.has(key)) {\n const captured = node.parameters[key];\n diagnostics.push({\n code: 'PSL_EXTENSION_UNKNOWN_PARAMETER',\n message: `Unknown parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\". The descriptor does not declare this parameter.`,\n sourceId,\n span: captured?.span ?? node.span,\n });\n }\n }\n\n // 2. Missing required parameters — required descriptor keys absent from the node.\n for (const [key, param] of Object.entries(descriptor.parameters)) {\n if (param.required === true && !nodeKeys.has(key)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_MISSING_REQUIRED_PARAMETER',\n message: `Required parameter \"${key}\" is missing from \"${descriptor.keyword}\" block \"${node.name}\".`,\n sourceId,\n span: node.span,\n });\n }\n }\n\n // 3–5. Per-parameter validation for parameters that are present.\n for (const [key, param] of Object.entries(descriptor.parameters)) {\n const captured = node.parameters[key];\n if (captured === undefined) {\n continue;\n }\n validateParam(\n node,\n descriptor,\n key,\n param,\n captured,\n sourceId,\n codecLookup,\n refCtx,\n diagnostics,\n );\n }\n\n return diagnostics;\n}\n\nfunction validateParam(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n key: string,\n param: PslBlockParam,\n captured: PslExtensionBlockParamValue,\n sourceId: string,\n codecLookup: CodecLookup,\n refCtx: ExtensionBlockRefResolutionContext | undefined,\n diagnostics: PslDiagnostic[],\n): void {\n switch (param.kind) {\n case 'option': {\n if (captured.kind !== 'option') {\n return;\n }\n if (!param.values.includes(captured.token)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_OPTION_OUT_OF_SET',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" has value \"${captured.token}\" which is not one of the allowed values: ${param.values.map((v) => `\"${v}\"`).join(', ')}.`,\n sourceId,\n span: captured.span,\n });\n }\n return;\n }\n\n case 'value': {\n if (captured.kind !== 'value') {\n return;\n }\n const codec = codecLookup.get(param.codecId);\n if (codec === undefined) {\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" references unknown codec \"${param.codecId}\".`,\n sourceId,\n span: captured.span,\n });\n return;\n }\n let jsonValue: unknown;\n try {\n jsonValue = JSON.parse(captured.raw);\n } catch {\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" is not a valid JSON literal (expected a JSON string, number, boolean, or null): ${captured.raw}`,\n sourceId,\n span: captured.span,\n });\n return;\n }\n try {\n codec.decodeJson(\n blindCast<JsonValue, 'JSON.parse returns a JsonValue-compatible value'>(jsonValue),\n );\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err);\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" was rejected by codec \"${param.codecId}\": ${reason}`,\n sourceId,\n span: captured.span,\n });\n }\n return;\n }\n\n case 'ref': {\n if (captured.kind !== 'ref') {\n return;\n }\n validateRef(\n node,\n descriptor,\n key,\n param,\n captured.identifier,\n captured.span,\n sourceId,\n refCtx,\n diagnostics,\n );\n return;\n }\n\n case 'list': {\n if (captured.kind !== 'list') {\n return;\n }\n for (const item of captured.items) {\n validateParam(\n node,\n descriptor,\n key,\n param.of,\n item,\n sourceId,\n codecLookup,\n refCtx,\n diagnostics,\n );\n }\n return;\n }\n }\n}\n\nfunction validateRef(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n key: string,\n param: PslBlockParamRef,\n identifier: string,\n span: PslSpan,\n sourceId: string,\n refCtx: ExtensionBlockRefResolutionContext | undefined,\n diagnostics: PslDiagnostic[],\n): void {\n if (param.scope === 'cross-space') {\n // cross-space enforcement is a documented pass-through. The spec permits\n // scoping cross-space resolution to first-consumer need (RLS roles). When\n // that consumer arrives, wire resolution here through the\n // cross-contract-space coordinate model\n // (spaceId, namespaceId, entityKind, entityName).\n // For now, cross-space refs pass validation unconditionally.\n return;\n }\n\n if (refCtx === undefined) {\n // If no resolution context was provided, skip ref resolution. This matches\n // the closed-grammar invariant: callers that register ref parameters must\n // provide resolution context; callers without namespaces (e.g. unit tests\n // that only exercise other validation modes) can omit it.\n return;\n }\n\n const namespacesToSearch: readonly PslNamespace[] =\n param.scope === 'same-namespace' ? [refCtx.ownerNamespace] : refCtx.allNamespaces;\n\n if (!resolveEntityInNamespaces(identifier, param.refKind, namespacesToSearch)) {\n const scopeLabel =\n param.scope === 'same-namespace' ? 'the same namespace' : 'any namespace in the schema';\n diagnostics.push({\n code: 'PSL_EXTENSION_UNRESOLVED_REF',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" refers to \"${identifier}\" (expected ${param.refKind}), but no entity with that name and kind was found in ${scopeLabel}.`,\n sourceId,\n span,\n });\n }\n}\n\n/**\n * True if an entity named `name` of kind `refKind` exists in any of the given\n * namespaces. Built-in and extension kinds resolve the same way, through\n * `entries[refKind]`.\n */\nfunction resolveEntityInNamespaces(\n name: string,\n refKind: string,\n namespaces: readonly PslNamespace[],\n): boolean {\n for (const ns of namespaces) {\n const kindMap = ns.entries[refKind];\n if (kindMap !== undefined && Object.hasOwn(kindMap, name)) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyMA,MAAa,+BAA+B;;;;;;AAiC5C,IAAM,mBAAN,MAA+C;CAC7C,OAAgB;CAChB;CACA;CACA;CAEA,YAAY,MAIT;EACD,KAAK,OAAO,KAAK;EACjB,KAAK,UAAU,KAAK;EACpB,KAAK,OAAO,KAAK;EACjB,OAAO,OAAO,IAAI;CACpB;CAEA,IAAI,SAA8B;EAChC,OAAO,UACL,OAAO,OAAO,KAAK,QAAQ,YAAY,CAAC,CAAC,CAC3C;CACF;CAEA,IAAI,QAA4B;EAC9B,OAAO,UACL,OAAO,OAAO,KAAK,QAAQ,WAAW,CAAC,CAAC,CAC1C;CACF;CAEA,IAAI,iBAA8C;EAChD,OAAO,UAGL,OAAO,OAAO,KAAK,QAAQ,oBAAoB,CAAC,CAAC,CAAC;CACtD;AACF;;AAGA,SAAgB,iBAAiB,MAKhB;CACf,OAAO,IAAI,iBAAiB,IAA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AS,MACT,UACA,QACA,WACF;GACA;EAGF,KAAK;GACH,IAAI,SAAS,SAAS,QACpB;GAEF,KAAK,MAAM,QAAQ,SAAS,OAC1B,cACE,MACA,YACA,KACA,MAAM,IACN,MACA,UACA,aACA,QACA,WACF;GAEF;CAEJ;AACF;AAEA,SAAS,YACP,MACA,YACA,KACA,OACA,YACA,MACA,UACA,QACA,aACM;CACN,IAAI,MAAM,UAAU,eAOlB;CAGF,IAAI,WAAW,KAAA,GAKb;CAGF,MAAM,qBACJ,MAAM,UAAU,mBAAmB,CAAC,OAAO,cAAc,IAAI,OAAO;CAEtE,IAAI,CAAC,0BAA0B,YAAY,MAAM,SAAS,kBAAkB,GAAG;EAC7E,MAAM,aACJ,MAAM,UAAU,mBAAmB,uBAAuB;EAC5D,YAAY,KAAK;GACf,MAAM;GACN,SAAS,cAAc,IAAI,QAAQ,WAAW,QAAQ,WAAW,KAAK,KAAK,eAAe,WAAW,cAAc,MAAM,QAAQ,wDAAwD,WAAW;GACpM;GACA;EACF,CAAC;CACH;AACF;;;;;;AAOA,SAAS,0BACP,MACA,SACA,YACS;CACT,KAAK,MAAM,MAAM,YAAY;EAC3B,MAAM,UAAU,GAAG,QAAQ;EAC3B,IAAI,YAAY,KAAA,KAAa,OAAO,OAAO,SAAS,IAAI,GAAG,OAAO;CACpE;CACA,OAAO;AACT"}
{"version":3,"file":"psl-ast.mjs","names":[],"sources":["../src/control/psl-ast.ts","../src/control/psl-extension-block-validator.ts"],"sourcesContent":["export type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring';\nexport type {\n PslBlockParam,\n PslBlockParamList,\n PslBlockParamOption,\n PslBlockParamRef,\n PslBlockParamValue,\n PslDiagnosticCode,\n PslExtensionBlock,\n PslExtensionBlockAttribute,\n PslExtensionBlockAttributeArg,\n PslExtensionBlockParamBare,\n PslExtensionBlockParamList,\n PslExtensionBlockParamOption,\n PslExtensionBlockParamRef,\n PslExtensionBlockParamScalarValue,\n PslExtensionBlockParamValue,\n PslPosition,\n PslSpan,\n} from '../shared/psl-extension-block';\n\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { CodecLookup } from '../shared/codec-types';\nimport type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring';\nimport type { PslDiagnosticCode, PslExtensionBlock, PslSpan } from '../shared/psl-extension-block';\n\nexport interface PslDiagnostic {\n readonly code: PslDiagnosticCode;\n readonly message: string;\n readonly sourceId: string;\n readonly span: PslSpan;\n}\n\nexport interface PslDefaultFunctionValue {\n readonly kind: 'function';\n readonly name: 'autoincrement' | 'now';\n}\n\nexport interface PslDefaultLiteralValue {\n readonly kind: 'literal';\n readonly value: string | number | boolean;\n}\n\nexport type PslDefaultValue = PslDefaultFunctionValue | PslDefaultLiteralValue;\n\nexport type PslAttributeTarget = 'field' | 'model' | 'enum' | 'namedType';\n\nexport interface PslAttributePositionalArgument {\n readonly kind: 'positional';\n readonly value: string;\n readonly span: PslSpan;\n}\n\nexport interface PslAttributeNamedArgument {\n readonly kind: 'named';\n readonly name: string;\n readonly value: string;\n readonly span: PslSpan;\n}\n\nexport type PslAttributeArgument = PslAttributePositionalArgument | PslAttributeNamedArgument;\n\nexport interface PslTypeConstructorCall {\n readonly kind: 'typeConstructor';\n readonly path: readonly string[];\n readonly args: readonly PslAttributeArgument[];\n readonly span: PslSpan;\n}\n\nexport interface PslAttribute {\n readonly kind: 'attribute';\n readonly target: PslAttributeTarget;\n readonly name: string;\n readonly args: readonly PslAttributeArgument[];\n readonly span: PslSpan;\n}\n\nexport type PslReferentialAction = string;\n\nexport type PslFieldAttribute = PslAttribute;\n\nexport interface PslField {\n readonly kind: 'field';\n readonly name: string;\n /** Unqualified type name, e.g. `\"User\"` for both `User`, `auth.User`, and `supabase:auth.User`. */\n readonly typeName: string;\n /** Namespace qualifier from a dot-qualified type reference, e.g. `\"auth\"` for `auth.User` or `supabase:auth.User`. Absent for unqualified types. */\n readonly typeNamespaceId?: string;\n /**\n * Contract-space qualifier from a colon-prefix type reference, e.g. `\"supabase\"` for\n * `supabase:auth.User` or `supabase:User`. Absent for local (same-space) type references.\n *\n * When present, the field references a model from a different contract space. The namespace\n * (`typeNamespaceId`) and model name (`typeName`) identify the target within that space.\n * Physical table resolution against the extension contract is deferred to the aggregate stage (M3).\n */\n readonly typeContractSpaceId?: string;\n readonly typeConstructor?: PslTypeConstructorCall;\n readonly optional: boolean;\n readonly list: boolean;\n readonly typeRef?: string;\n readonly attributes: readonly PslFieldAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslUniqueConstraint {\n readonly kind: 'unique';\n readonly fields: readonly string[];\n readonly span: PslSpan;\n}\n\nexport interface PslIndexConstraint {\n readonly kind: 'index';\n readonly fields: readonly string[];\n readonly span: PslSpan;\n}\n\nexport type PslModelAttribute = PslAttribute;\n\nexport interface PslModel {\n readonly kind: 'model';\n readonly name: string;\n readonly fields: readonly PslField[];\n readonly attributes: readonly PslModelAttribute[];\n readonly span: PslSpan;\n /**\n * Optional leading comment line emitted above the `model` keyword by the\n * printer. Producers (e.g. `sqlSchemaIrToPslAst`) attach introspection\n * advisories such as \"// WARNING: This table has no primary key in the\n * database\" here. The parser leaves this field unset; round-tripping a\n * parsed schema does not re-attach comments.\n */\n readonly comment?: string;\n}\n\n/**\n * A reusable group of fields embedded in a model (a `type Name { … }` block) —\n * e.g. a MongoDB embedded document or a Postgres composite type. Unlike\n * {@link PslModel} it has no storage or identity of its own.\n */\nexport interface PslCompositeType {\n readonly kind: 'compositeType';\n readonly name: string;\n readonly fields: readonly PslField[];\n readonly attributes: readonly PslAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslNamedTypeDeclaration {\n readonly kind: 'namedType';\n readonly name: string;\n /**\n * Parser invariant: exactly one of `baseType` and `typeConstructor` is set.\n * Expressing this as a discriminated union trips TypeScript narrowing when\n * the declaration flows through helpers that accept the full union.\n */\n readonly baseType?: string;\n readonly typeConstructor?: PslTypeConstructorCall;\n readonly attributes: readonly PslAttribute[];\n readonly span: PslSpan;\n}\n\nexport interface PslTypesBlock {\n readonly kind: 'types';\n readonly declarations: readonly PslNamedTypeDeclaration[];\n readonly span: PslSpan;\n}\n\n/**\n * Name of the synthesised namespace bucket the framework parser uses for\n * top-level declarations that appear outside any `namespace { … }` block.\n * The double-underscore decoration signals that the identifier is parser-\n * synthesised and never appears in user-authored PSL source — writing\n * `namespace __unspecified__ { … }` is a parse error.\n *\n * Distinct from the IR sentinel `__unbound__`: the PSL bucket describes\n * syntactic absence at the parser layer; the IR sentinel describes a late-\n * bound storage slot at the IR layer. Per-target interpreters decide how\n * (or whether) to map the PSL bucket to the IR sentinel.\n */\nexport const UNSPECIFIED_PSL_NAMESPACE_ID = '__unspecified__';\n\n/** A value in {@link PslNamespace.entries}: a built-in entity node or an extension-contributed {@link PslExtensionBlock}. */\nexport type PslNamespaceEntry = PslModel | PslCompositeType | PslExtensionBlock;\n\n/**\n * A namespace block, or the parser's synthesised `__unspecified__` bucket for\n * declarations outside any `namespace { … }`. Same-name blocks reopen-merge;\n * `span` points at the first opening.\n *\n * Entities are stored canonically (ADR 224) in `entries[kind][name]`, where\n * `kind` is the PSL keyword for built-ins or the block discriminator for\n * extension kinds, e.g. `entries['policy_select']['ReadPosts']`.\n */\nexport interface PslNamespace {\n readonly kind: 'namespace';\n readonly name: string;\n /** Canonical store: a frozen container of frozen per-kind maps. The accessors below derive from it. */\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n /** Built-in models, from `entries['model']`. Extension kinds: {@link namespacePslExtensionBlocks}. */\n readonly models: readonly PslModel[];\n /** Built-in composite types, from `entries['compositeType']`. */\n readonly compositeTypes: readonly PslCompositeType[];\n readonly span: PslSpan;\n}\n\n/**\n * Stores `entries`; exposes `models`/`enums`/`compositeTypes` as getters over\n * it. The getters are prototype members (non-enumerable), so spreading or\n * `JSON.stringify`-ing a namespace copies only `entries`, never a duplicate view.\n */\nclass PslNamespaceNode implements PslNamespace {\n readonly kind = 'namespace' as const;\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n\n constructor(init: {\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n }) {\n this.name = init.name;\n this.entries = init.entries;\n this.span = init.span;\n Object.freeze(this);\n }\n\n get models(): readonly PslModel[] {\n return blindCast<readonly PslModel[], 'entries[model] holds only PslModel by construction'>(\n Object.values(this.entries['model'] ?? {}),\n );\n }\n\n get compositeTypes(): readonly PslCompositeType[] {\n return blindCast<\n readonly PslCompositeType[],\n 'entries[compositeType] holds only PslCompositeType by construction'\n >(Object.values(this.entries['compositeType'] ?? {}));\n }\n}\n\n/** Constructs a {@link PslNamespace}. Use this, never a namespace literal — the accessors must derive from `entries`. */\nexport function makePslNamespace(init: {\n readonly kind: 'namespace';\n readonly name: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;\n readonly span: PslSpan;\n}): PslNamespace {\n return new PslNamespaceNode(init);\n}\n\n/**\n * Builds the frozen `entries[kind][name]` container from per-kind arrays.\n * Built-ins key on their PSL keyword; extension blocks key on their `kind`\n * discriminator. Call this rather than hand-building the literal.\n */\nexport function makePslNamespaceEntries(\n models: readonly PslModel[],\n compositeTypes: readonly PslCompositeType[],\n extensionBlocks: readonly PslExtensionBlock[],\n): Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>> {\n const container: Record<string, Readonly<Record<string, PslNamespaceEntry>>> = {};\n\n if (models.length > 0) {\n const map: Record<string, PslModel> = {};\n for (const m of models) {\n map[m.name] = m;\n }\n container['model'] = Object.freeze(map);\n }\n\n if (compositeTypes.length > 0) {\n const map: Record<string, PslCompositeType> = {};\n for (const ct of compositeTypes) {\n map[ct.name] = ct;\n }\n container['compositeType'] = Object.freeze(map);\n }\n\n for (const block of extensionBlocks) {\n const existing = container[block.kind];\n const newMap: Record<string, PslExtensionBlock> = existing\n ? blindCast<Record<string, PslExtensionBlock>, 'kind map holds only PslExtensionBlock'>({\n ...existing,\n })\n : {};\n newMap[block.name] = block;\n container[block.kind] = Object.freeze(newMap);\n }\n\n return Object.freeze(container);\n}\n\nexport interface PslDocumentAst {\n readonly kind: 'document';\n readonly sourceId: string;\n readonly namespaces: readonly PslNamespace[];\n readonly types?: PslTypesBlock;\n readonly span: PslSpan;\n}\n\n/**\n * Returns all models from every namespace in document order. Convenience\n * for consumers that don't (yet) need namespace-awareness.\n */\nexport function flatPslModels(ast: PslDocumentAst): readonly PslModel[] {\n return ast.namespaces.flatMap((ns) =>\n blindCast<PslModel[], 'model kind map contains only PslModel by construction'>(\n Object.values(ns.entries['model'] ?? {}),\n ),\n );\n}\n\n/**\n * Returns all composite types from every namespace in document order.\n */\nexport function flatPslCompositeTypes(ast: PslDocumentAst): readonly PslCompositeType[] {\n return ast.namespaces.flatMap((ns) =>\n blindCast<\n PslCompositeType[],\n 'compositeType kind map contains only PslCompositeType by construction'\n >(Object.values(ns.entries['compositeType'] ?? {})),\n );\n}\n\n/**\n * The set of `entries` kind keys that the framework parser reserves for\n * built-in PSL entity kinds. Any own-enumerable key on `PslNamespace.entries`\n * that is **not** in this set was contributed by an extension-block descriptor.\n *\n * Built-in keys match the PSL keyword used on each block type:\n * `'model'`, `'compositeType'`. The `'enum'` keyword is claimed by the\n * extension-block grammar via a registered descriptor, so `entries['enum']`\n * holds `PslExtensionBlock` nodes and is returned by `namespacePslExtensionBlocks`.\n */\nexport const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string> = new Set(['model', 'compositeType']);\n\n/**\n * Returns all extension-contributed blocks in the given namespace, in\n * insertion order (the order the parser encountered them in the source).\n *\n * Reads from `namespace.entries`, skipping the built-in kind keys\n * (`'model'`, `'compositeType'`). All remaining kind maps contain\n * only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).\n */\nexport function namespacePslExtensionBlocks(ns: PslNamespace): readonly PslExtensionBlock[] {\n const result: PslExtensionBlock[] = [];\n for (const [kindKey, kindMap] of Object.entries(ns.entries)) {\n if (BUILTIN_PSL_KIND_KEYS.has(kindKey)) continue;\n for (const entry of Object.values(kindMap)) {\n result.push(\n blindCast<\n PslExtensionBlock,\n 'non-builtin kind maps contain only PslExtensionBlock by construction'\n >(entry),\n );\n }\n }\n return result;\n}\n\nexport interface ParsePslDocumentInput {\n readonly schema: string;\n readonly sourceId: string;\n /**\n * Registry of declarative block descriptors, keyed by arbitrary path\n * segments with {@link AuthoringPslBlockDescriptor} leaves. The registry\n * teaches the parser which top-level keywords belong to extension\n * contributions: when the parser encounters an unknown keyword, it looks\n * it up here and, when found, reads the block generically into a\n * {@link PslExtensionBlock} node. Absent or undefined means no extension\n * blocks are registered and any unknown keyword yields\n * `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`.\n *\n * Contrast with the parsed block nodes themselves, which live in\n * {@link PslNamespace.entries} under their discriminator key (read them with\n * {@link namespacePslExtensionBlocks}); this field holds the registry of\n * descriptors that teach the parser how to read those blocks.\n */\n readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;\n /**\n * Codec lookup for validating `value`-kind extension block parameters.\n * When provided alongside `pslBlockDescriptors`, the generic validator runs\n * over every parsed extension block after the full AST is assembled,\n * appending any diagnostics to the parse result. Absent or undefined means\n * no codec validation runs; `ref` resolution still runs when namespace\n * context is available (built from the assembled namespaces).\n */\n readonly codecLookup?: CodecLookup;\n}\n\nexport interface ParsePslDocumentResult {\n readonly ast: PslDocumentAst;\n readonly diagnostics: readonly PslDiagnostic[];\n readonly ok: boolean;\n}\n","/**\n * Generic validator for extension-contributed top-level PSL blocks.\n *\n * One function — {@link validateExtensionBlock} — takes a parsed\n * {@link PslExtensionBlock}, its {@link AuthoringPslBlockDescriptor}, a\n * {@link CodecLookup} (for `value` parameters), and the set of\n * {@link PslNamespace} objects from the document (for `ref` resolution), and\n * returns the full list of {@link PslDiagnostic} objects for the block.\n *\n * Detection logic per failure mode:\n *\n * 1. **Unknown parameter** — keys present in `node.parameters` that are absent\n * from `descriptor.parameters` (key-set difference). The parser stores\n * unknown parameters as `kind:'value'` stubs; the validator discovers them\n * by comparing the key sets, not by inspecting the captured kind.\n *\n * 2. **Missing required parameter** — `descriptor.parameters` entries with\n * `required: true` whose key is absent from `node.parameters`.\n *\n * 3. **`option` value outside its set** — the captured `token` is not in\n * `descriptor.values`.\n *\n * 4. **`value` rejected by its codec** — the raw string is first parsed as\n * JSON (`JSON.parse(raw)`). If `JSON.parse` throws, the literal is not valid\n * JSON and a `PSL_EXTENSION_INVALID_VALUE` diagnostic is emitted. If parsing\n * succeeds but `codec.decodeJson(jsonValue)` throws, the JSON value is not\n * acceptable to the codec and a `PSL_EXTENSION_INVALID_VALUE` diagnostic is\n * emitted. If `codecLookup.get(codecId)` returns `undefined` (unknown codec\n * id), a `PSL_EXTENSION_INVALID_VALUE` diagnostic is also emitted.\n *\n * 5. **`ref` that does not resolve within its scope** — the captured\n * `identifier` is looked up in the PSL document's `PslNamespace` objects\n * according to `param.scope`:\n * - `same-namespace`: the referent must be in the same namespace as the\n * block (the namespace containing the block).\n * - `same-space`: the referent may be in any namespace in the document.\n * - `cross-space`: pass-through — enforcement is scoped to first-consumer\n * need (RLS roles). This case is documented and clearly flagged; the\n * caller is responsible for wiring cross-space resolution when needed.\n *\n * 6. **`list`** — each element is validated against `param.of` recursively.\n *\n * ### `char`/`varchar` length\n * Not enforced. RLS `using`/`check` strings are unbounded text and the codec\n * already rejects structurally invalid literals; length constraints are a\n * database-side concern, not a PSL authoring constraint.\n *\n * ### `cross-space` scope\n * Implemented as a documented pass-through. The spec permits scoping\n * cross-space enforcement to first-consumer need (RLS roles). When RLS roles\n * arrive, wire `cross-space` resolution through the cross-contract-space\n * coordinate model `(spaceId, namespaceId, entityKind, entityName)`.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { CodecLookup } from '../shared/codec-types';\nimport type { AuthoringPslBlockDescriptor } from '../shared/framework-authoring';\nimport type {\n PslBlockParam,\n PslBlockParamRef,\n PslExtensionBlock,\n PslExtensionBlockParamValue,\n PslSpan,\n} from '../shared/psl-extension-block';\nimport type { PslDiagnostic, PslNamespace } from './psl-ast';\n\n/**\n * Context for ref resolution during extension-block validation.\n *\n * - `ownerNamespace` is the `PslNamespace` that contains the block being\n * validated. Used for `same-namespace` scope checks.\n * - `allNamespaces` is every namespace in the document. Used for `same-space`\n * scope checks.\n */\nexport interface ExtensionBlockRefResolutionContext {\n readonly ownerNamespace: PslNamespace;\n readonly allNamespaces: readonly PslNamespace[];\n}\n\n/**\n * Validate a single parsed extension block against its descriptor.\n *\n * Returns an array of {@link PslDiagnostic} objects (possibly empty). The\n * caller is responsible for threading `sourceId` into each returned diagnostic\n * — the returned objects already have `sourceId` set from the `sourceId`\n * parameter.\n *\n * @param node - The parsed block node produced by the generic framework parser.\n * @param descriptor - The descriptor that claims this block's keyword.\n * @param sourceId - The PSL source file identifier (threaded into diagnostics).\n * @param codecLookup - Used to validate `value`-kind parameter literals via\n * `codecLookup.get(codecId)?.decodeJson(JSON.parse(raw))`.\n * @param refCtx - Namespace context for `ref`-kind scope resolution. Required\n * when any descriptor parameter is `kind: 'ref'`; may be omitted if none are.\n */\nexport function validateExtensionBlock(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n sourceId: string,\n codecLookup: CodecLookup,\n refCtx?: ExtensionBlockRefResolutionContext,\n): readonly PslDiagnostic[] {\n const diagnostics: PslDiagnostic[] = [];\n\n const descriptorKeys = new Set(Object.keys(descriptor.parameters));\n const nodeKeys = new Set(Object.keys(node.parameters));\n\n // 1. Unknown parameters — keys in the node not in the descriptor.\n if (!descriptor.variadicParameters) {\n for (const key of nodeKeys) {\n if (!descriptorKeys.has(key)) {\n const captured = node.parameters[key];\n diagnostics.push({\n code: 'PSL_EXTENSION_UNKNOWN_PARAMETER',\n message: `Unknown parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\". The descriptor does not declare this parameter.`,\n sourceId,\n span: captured?.span ?? node.span,\n });\n }\n }\n }\n\n // 2. Missing required parameters — required descriptor keys absent from the node.\n for (const [key, param] of Object.entries(descriptor.parameters)) {\n if (param.required === true && !nodeKeys.has(key)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_MISSING_REQUIRED_PARAMETER',\n message: `Required parameter \"${key}\" is missing from \"${descriptor.keyword}\" block \"${node.name}\".`,\n sourceId,\n span: node.span,\n });\n }\n }\n\n // 3–5. Per-parameter validation for parameters that are present.\n for (const [key, param] of Object.entries(descriptor.parameters)) {\n const captured = node.parameters[key];\n if (captured === undefined) {\n continue;\n }\n validateParam(\n node,\n descriptor,\n key,\n param,\n captured,\n sourceId,\n codecLookup,\n refCtx,\n diagnostics,\n );\n }\n\n return diagnostics;\n}\n\nfunction validateParam(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n key: string,\n param: PslBlockParam,\n captured: PslExtensionBlockParamValue,\n sourceId: string,\n codecLookup: CodecLookup,\n refCtx: ExtensionBlockRefResolutionContext | undefined,\n diagnostics: PslDiagnostic[],\n): void {\n switch (param.kind) {\n case 'option': {\n if (captured.kind !== 'option') {\n return;\n }\n if (!param.values.includes(captured.token)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_OPTION_OUT_OF_SET',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" has value \"${captured.token}\" which is not one of the allowed values: ${param.values.map((v) => `\"${v}\"`).join(', ')}.`,\n sourceId,\n span: captured.span,\n });\n }\n return;\n }\n\n case 'value': {\n if (captured.kind !== 'value') {\n return;\n }\n const codec = codecLookup.get(param.codecId);\n if (codec === undefined) {\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" references unknown codec \"${param.codecId}\".`,\n sourceId,\n span: captured.span,\n });\n return;\n }\n let jsonValue: unknown;\n try {\n jsonValue = JSON.parse(captured.raw);\n } catch {\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" is not a valid JSON literal (expected a JSON string, number, boolean, or null): ${captured.raw}`,\n sourceId,\n span: captured.span,\n });\n return;\n }\n try {\n codec.decodeJson(\n blindCast<JsonValue, 'JSON.parse returns a JsonValue-compatible value'>(jsonValue),\n );\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err);\n diagnostics.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" was rejected by codec \"${param.codecId}\": ${reason}`,\n sourceId,\n span: captured.span,\n });\n }\n return;\n }\n\n case 'ref': {\n if (captured.kind !== 'ref') {\n return;\n }\n validateRef(\n node,\n descriptor,\n key,\n param,\n captured.identifier,\n captured.span,\n sourceId,\n refCtx,\n diagnostics,\n );\n return;\n }\n\n case 'list': {\n if (captured.kind !== 'list') {\n return;\n }\n for (const item of captured.items) {\n validateParam(\n node,\n descriptor,\n key,\n param.of,\n item,\n sourceId,\n codecLookup,\n refCtx,\n diagnostics,\n );\n }\n return;\n }\n }\n}\n\nfunction validateRef(\n node: PslExtensionBlock,\n descriptor: AuthoringPslBlockDescriptor,\n key: string,\n param: PslBlockParamRef,\n identifier: string,\n span: PslSpan,\n sourceId: string,\n refCtx: ExtensionBlockRefResolutionContext | undefined,\n diagnostics: PslDiagnostic[],\n): void {\n if (param.scope === 'cross-space') {\n // cross-space enforcement is a documented pass-through. The spec permits\n // scoping cross-space resolution to first-consumer need (RLS roles). When\n // that consumer arrives, wire resolution here through the\n // cross-contract-space coordinate model\n // (spaceId, namespaceId, entityKind, entityName).\n // For now, cross-space refs pass validation unconditionally.\n return;\n }\n\n if (refCtx === undefined) {\n // If no resolution context was provided, skip ref resolution. This matches\n // the closed-grammar invariant: callers that register ref parameters must\n // provide resolution context; callers without namespaces (e.g. unit tests\n // that only exercise other validation modes) can omit it.\n return;\n }\n\n const namespacesToSearch: readonly PslNamespace[] =\n param.scope === 'same-namespace' ? [refCtx.ownerNamespace] : refCtx.allNamespaces;\n\n if (!resolveEntityInNamespaces(identifier, param.refKind, namespacesToSearch)) {\n const scopeLabel =\n param.scope === 'same-namespace' ? 'the same namespace' : 'any namespace in the schema';\n diagnostics.push({\n code: 'PSL_EXTENSION_UNRESOLVED_REF',\n message: `Parameter \"${key}\" in \"${descriptor.keyword}\" block \"${node.name}\" refers to \"${identifier}\" (expected ${param.refKind}), but no entity with that name and kind was found in ${scopeLabel}.`,\n sourceId,\n span,\n });\n }\n}\n\n/**\n * True if an entity named `name` of kind `refKind` exists in any of the given\n * namespaces. Built-in and extension kinds resolve the same way, through\n * `entries[refKind]`.\n */\nfunction resolveEntityInNamespaces(\n name: string,\n refKind: string,\n namespaces: readonly PslNamespace[],\n): boolean {\n for (const ns of namespaces) {\n const kindMap = ns.entries[refKind];\n if (kindMap !== undefined && Object.hasOwn(kindMap, name)) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAoLA,MAAa,+BAA+B;;;;;;AA+B5C,IAAM,mBAAN,MAA+C;CAC7C,OAAgB;CAChB;CACA;CACA;CAEA,YAAY,MAIT;EACD,KAAK,OAAO,KAAK;EACjB,KAAK,UAAU,KAAK;EACpB,KAAK,OAAO,KAAK;EACjB,OAAO,OAAO,IAAI;CACpB;CAEA,IAAI,SAA8B;EAChC,OAAO,UACL,OAAO,OAAO,KAAK,QAAQ,YAAY,CAAC,CAAC,CAC3C;CACF;CAEA,IAAI,iBAA8C;EAChD,OAAO,UAGL,OAAO,OAAO,KAAK,QAAQ,oBAAoB,CAAC,CAAC,CAAC;CACtD;AACF;;AAGA,SAAgB,iBAAiB,MAKhB;CACf,OAAO,IAAI,iBAAiB,IAAI;AAClC;;;;;;AAOA,SAAgB,wBACd,QACA,gBACA,iBACuE;CACvE,MAAM,YAAyE,CAAC;CAEhF,IAAI,OAAO,SAAS,GAAG;EACrB,MAAM,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CAAC,0BAA0B,YAAY,MAAM,SAAS,kBAAkB,GAAG;EAC7E,MAAM,aACJ,MAAM,UAAU,mBAAmB,uBAAuB;EAC5D,YAAY,KAAK;GACf,MAAM;GACN,SAAS,cAAc,IAAI,QAAQ,WAAW,QAAQ,WAAW,KAAK,KAAK,eAAe,WAAW,cAAc,MAAM,QAAQ,wDAAwD,WAAW;GACpM;GACA;EACF,CAAC;CACH;AACF;;;;;;AAOA,SAAS,0BACP,MACA,SACA,YACS;CACT,KAAK,MAAM,MAAM,YAAY;EAC3B,MAAM,UAAU,GAAG,QAAQ;EAC3B,IAAI,YAAY,KAAA,KAAa,OAAO,OAAO,SAAS,IAAI,GAAG,OAAO;CACpE;CACA,OAAO;AACT"}

@@ -1,2 +0,2 @@

import { o as CodecCallContext } from "./codec-DCQAerzB.mjs";
import { t as CodecCallContext } from "./codec-types-yY3eSmi0.mjs";
import { PlanMeta } from "@prisma-next/contract/types";

@@ -620,3 +620,3 @@

//#endregion
//#region src/execution/runtime-error.d.ts
//#region src/shared/runtime-error.d.ts
interface RuntimeErrorEnvelope extends Error {

@@ -629,2 +629,12 @@ readonly code: string;

/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
declare function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope;
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
//#endregion
//#region src/execution/runtime-error.d.ts
/**
* Stable code emitted by the runtime when an in-flight `execute()`

@@ -647,10 +657,2 @@ * is cancelled via the per-query `AbortSignal`. The envelope's

/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
declare function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope;
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
/**
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the

@@ -657,0 +659,0 @@ * abort was observed — codec call sites (`encode` / `decode` / `stream`)

@@ -1,1 +0,1 @@

{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/annotations.ts","../src/execution/async-iterable-result.ts","../src/execution/query-plan.ts","../src/execution/runtime-middleware.ts","../src/execution/before-execute-chain.ts","../src/execution/runtime-error.ts","../src/execution/race-against-abort.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts","../src/meta-builder.ts"],"mappings":";;;;;;;;AAmBA;;;;AAAyB;AAazB;;;;;;;;KAbY,aAAA;;;;;;;;;;;;UAaK,eAAA,wBAAuC,aAAA;EAAA,SAC7C,YAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA,EAAO,OAAA;EAAA,SACP,YAAA,EAAc,WAAA,CAAY,KAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDxB;AAyBb;;;;;;;;;;AAEuC;AAwCvC;UAzEiB,gBAAA,wBAAwC,aAAA;EAAA,CACtD,KAAA,EAAO,OAAA,GAAU,eAAA,CAAgB,OAAA,EAAS,KAAA;EAAA,SAClC,SAAA;EAAA,SACA,YAAA,EAAc,WAAA,CAAY,KAAA;EACnC,IAAA,CAAK,IAAA;IAAA,SACM,IAAA;MAAA,SAAiB,WAAA,GAAc,MAAA;IAAA;EAAA,IACtC,OAAA;AAAA;;;;;;;;;;;AAqE8B;AA6FpC;;;;;;;;;;;UAzIiB,uBAAA,eAAsC,aAAA;EAAA,SAC5C,SAAA;EAAA,SACA,YAAA,WAAuB,KAAK;AAAA;;;;;;;;;;;;;;;;;;;;AA6IP;AA4BhC;;;;;;;;;;;;;;;AAGsB;;iBApIN,gBAAA,kCAAkD,aAAA,EAChE,OAAA,EAAS,uBAAA,CAAwB,KAAA,MAC9B,gBAAA,CAAiB,OAAA,EAAS,KAAA;;ACzJ/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KDsPY,gBAAA,WAC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AQ,OAAA,CAAQ,KAAA;ERoBrE;;;AAA4B;AAwCvC;;;;;;EAxCW,mBQRU,SAAA,CAAU,IAAA,EAAM,KAAA,GAAQ,aAAA,CAAc,MAAA;EAAA,SAEhD,KAAA,IAAS,OAAA;EAElB,OAAA,MACE,IAAA,EAAM,KAAA;IAAA,SAAmB,IAAA,GAAO,GAAA;EAAA,GAChC,OAAA,GAAU,qBAAA,GACT,mBAAA,CAAoB,GAAA;AAAA;;;;;;AR7FzB;;;;AAAyB;AAazB;;;;;;;;;;;;;;;;;;;;AAI0C;AA4C1C;US5CiB,WAAA,WAAsB,aAAA;EACrC,QAAA,kBAA0B,aAAA,EACxB,UAAA,EAAY,CAAA,SAAU,KAAA,GAAQ,eAAA,CAAgB,CAAA,EAAG,KAAA;AAAA;;;;;;;;;;;UAcpC,eAAA,WAA0B,aAAA,UAAuB,WAAA,CAAY,CAAA;EAAA,SACnE,WAAA,EAAa,WAAA,SAAoB,eAAA,UAAyB,aAAA;AAAA;;;;;;;;;;iBA0CrD,iBAAA,WAA4B,aAAA,EAC1C,IAAA,EAAM,CAAA,EACN,YAAA,WACC,eAAA,CAAgB,CAAA"}
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/annotations.ts","../src/execution/async-iterable-result.ts","../src/execution/query-plan.ts","../src/execution/runtime-middleware.ts","../src/execution/before-execute-chain.ts","../src/shared/runtime-error.ts","../src/execution/runtime-error.ts","../src/execution/race-against-abort.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts","../src/meta-builder.ts"],"mappings":";;;;;;;;AAmBA;;;;AAAyB;AAazB;;;;;;;;KAbY,aAAA;;;;;;;;;;;;UAaK,eAAA,wBAAuC,aAAA;EAAA,SAC7C,YAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA,EAAO,OAAA;EAAA,SACP,YAAA,EAAc,WAAA,CAAY,KAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDxB;AAyBb;;;;;;;;;;AAEuC;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nE,WAAA,EAAa,WAAA,SAAoB,eAAA,UAAyB,aAAA;AAAA;;;;;;;;;;iBA0CrD,iBAAA,WAA4B,aAAA,EAC1C,IAAA,EAAM,CAAA,EACN,YAAA,WACC,eAAA,CAAgB,CAAA"}

@@ -0,1 +1,2 @@

import { n as runtimeError, t as isRuntimeError } from "./runtime-error-B2gWOtgH.mjs";
//#region src/execution/runtime-error.ts

@@ -18,35 +19,2 @@ /**

/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
function isRuntimeError(error) {
return error instanceof Error && "code" in error && typeof error.code === "string" && "category" in error && "severity" in error;
}
function runtimeError(code, message, details) {
const error = new Error(message);
Object.defineProperty(error, "name", {
value: "RuntimeError",
configurable: true
});
return Object.assign(error, {
code,
category: resolveCategory(code),
severity: "error",
message,
details
});
}
function resolveCategory(code) {
const prefix = code.split(".")[0] ?? "RUNTIME";
switch (prefix) {
case "PLAN":
case "CONTRACT":
case "LINT":
case "BUDGET": return prefix;
default: return "RUNTIME";
}
}
/**
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the

@@ -53,0 +21,0 @@ * abort was observed — codec call sites (`encode` / `decode` / `stream`)

{
"name": "@prisma-next/framework-components",
"version": "0.13.0",
"version": "0.14.0-dev.1",
"license": "Apache-2.0",

@@ -9,6 +9,6 @@ "type": "module",

"dependencies": {
"@prisma-next/contract": "0.13.0",
"@prisma-next/operations": "0.13.0",
"@prisma-next/ts-render": "0.13.0",
"@prisma-next/utils": "0.13.0",
"@prisma-next/contract": "0.14.0-dev.1",
"@prisma-next/operations": "0.14.0-dev.1",
"@prisma-next/ts-render": "0.14.0-dev.1",
"@prisma-next/utils": "0.14.0-dev.1",
"@standard-schema/spec": "^1.1.0",

@@ -18,4 +18,4 @@ "arktype": "^2.2.0"

"devDependencies": {
"@prisma-next/tsconfig": "0.13.0",
"@prisma-next/tsdown": "0.13.0",
"@prisma-next/tsconfig": "0.14.0-dev.1",
"@prisma-next/tsdown": "0.14.0-dev.1",
"tsdown": "0.22.1",

@@ -22,0 +22,0 @@ "typescript": "5.9.3",

@@ -78,21 +78,3 @@ /**

// ============================================================================
// Serialized Query Plan
// ============================================================================
/**
* A lowered query statement as stored in ops.json.
* Contains the SQL string and parameter values — ready for execution.
* Lowering from query builder AST to SQL happens at verify time.
*
* The Postgres `dataTransform` factory uses this shape internally to
* carry the user's lowered `check`/`run` plans before wrapping them
* into precheck/execute/postcheck steps on the unified migration op.
*/
export interface SerializedQueryPlan {
readonly sql: string;
readonly params: readonly unknown[];
}
/**
* Policy defining which operation classes are allowed during a migration.

@@ -189,5 +171,6 @@ */

* the return type via covariant return (e.g. SQL targets return
* `SqlMigrationPlanOperation<TTargetDetails>`).
* `SqlMigrationPlanOperation<TTargetDetails>`). May return a Promise when
* the lowering requires async codec resolution (e.g. DDL with literal defaults).
*/
toOp(): MigrationPlanOperation;
toOp(): MigrationPlanOperation | Promise<MigrationPlanOperation>;
}

@@ -228,4 +211,4 @@

};
/** Ordered list of operations to execute. */
readonly operations: readonly MigrationPlanOperation[];
/** Ordered list of operations to execute. May contain Promises for ops that require async codec resolution. */
readonly operations: readonly (MigrationPlanOperation | Promise<MigrationPlanOperation>)[];
/**

@@ -232,0 +215,0 @@ * Sorted, deduplicated invariant ids declared by this plan's data-transform

import { blindCast } from '@prisma-next/utils/casts';
import type { Codec } from '../shared/codec';
import type { CodecLookup, CodecMeta } from '../shared/codec-types';
import type { AnyCodecDescriptor } from '../shared/codec-descriptor';
import type { CodecLookup, CodecMeta, CodecRef, CodecRegistry } from '../shared/codec-types';
import type {

@@ -25,2 +26,7 @@ AuthoringContributions,

} from '../shared/mutation-default-types';
import {
CONTRACT_CODEC_DESCRIPTOR_MISSING,
materializeCodec,
resolveCodecDescriptorOrThrow,
} from '../shared/resolve-codec';
import type { TypesImportSpec } from '../shared/types-import-spec';

@@ -55,3 +61,3 @@ import type {

readonly extensionIds: ReadonlyArray<string>;
readonly codecLookup: CodecLookup;
readonly codecLookup: CodecRegistry;
readonly authoringContributions: AssembledAuthoringContributions;

@@ -299,7 +305,12 @@ readonly scalarTypeDescriptors: ReadonlyMap<string, string>;

descriptors: ReadonlyArray<Pick<ComponentMetadata & { id: string }, 'types' | 'id'>>,
): CodecLookup {
): CodecRegistry {
const byId = new Map<string, Codec>();
const descriptorsById = new Map<string, AnyCodecDescriptor>();
const targetTypesById = new Map<string, readonly string[]>();
const metaById = new Map<string, CodecMeta>();
const renderersById = new Map<string, (params: Record<string, unknown>) => string | undefined>();
const inputRenderersById = new Map<
string,
(params: Record<string, unknown>) => string | undefined
>();
const owners = new Map<string, string>();

@@ -319,2 +330,3 @@ for (const descriptor of descriptors) {

owners.set(codecDescriptor.codecId, descriptorId);
descriptorsById.set(codecDescriptor.codecId, codecDescriptor);
if (Array.isArray(codecDescriptor.targetTypes)) {

@@ -329,2 +341,5 @@ targetTypesById.set(codecDescriptor.codecId, codecDescriptor.targetTypes);

}
if (typeof codecDescriptor.renderInputType === 'function') {
inputRenderersById.set(codecDescriptor.codecId, codecDescriptor.renderInputType);
}
// Materialize a representative `Codec` instance for `byId.get()` so consumers reading the lookup's instance side (e.g. SQL renderer's cast-policy lookup, or the contract emitter's literal-default `encodeJson` resolver) keep finding the codec.

@@ -356,5 +371,15 @@ //

get: (id) => byId.get(id),
forCodecRef(ref: CodecRef) {
const d = resolveCodecDescriptorOrThrow(
(id) => descriptorsById.get(id),
ref,
CONTRACT_CODEC_DESCRIPTOR_MISSING,
);
return materializeCodec(d, ref, { name: `<ref:${ref.codecId}>` });
},
forColumn: () => undefined,
targetTypesFor: (id) => targetTypesById.get(id),
metaFor: (id) => metaById.get(id),
renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params),
renderInputTypeFor: (id, params) => inputRenderersById.get(id)?.(params),
};

@@ -361,0 +386,0 @@ }

@@ -1,2 +0,2 @@

import type { Contract, ContractModel } from '@prisma-next/contract/types';
import type { Contract, ContractModelBase } from '@prisma-next/contract/types';
import type { TypesImportSpec } from '../shared/types-import-spec';

@@ -18,3 +18,3 @@

generateModelStorageType(modelName: string, model: ContractModel): string;
generateModelStorageType(modelName: string, model: ContractModelBase): string;

@@ -46,5 +46,5 @@ getFamilyImports(): string[];

fieldName: string,
model: ContractModel,
model: ContractModelBase,
contract: Contract,
): Record<string, unknown> | undefined;
}

@@ -10,2 +10,5 @@ export type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring';

PslExtensionBlock,
PslExtensionBlockAttribute,
PslExtensionBlockAttributeArg,
PslExtensionBlockParamBare,
PslExtensionBlockParamList,

@@ -134,26 +137,2 @@ PslExtensionBlockParamOption,

export interface PslEnumValue {
readonly kind: 'enumValue';
readonly name: string;
/**
* Optional storage label for the enum member, captured from a trailing
* `@map("...")` attribute on the member line. The parser populates this
* when the source PSL carries an explicit `@map`. Producers (e.g.
* `sqlSchemaIrToPslAst`) leave it unset; the printer emits `@map(...)`
* automatically when normalisation would change the printed member name
* (so an enum value `'in-progress'` becomes `inProgress @map("in-progress")`
* in PSL, preserving the round-trip).
*/
readonly mapName?: string;
readonly span: PslSpan;
}
export interface PslEnum {
readonly kind: 'enum';
readonly name: string;
readonly values: readonly PslEnumValue[];
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
/**

@@ -207,3 +186,3 @@ * A reusable group of fields embedded in a model (a `type Name { … }` block) —

/** A value in {@link PslNamespace.entries}: a built-in entity node or an extension-contributed {@link PslExtensionBlock}. */
export type PslNamespaceEntry = PslModel | PslEnum | PslCompositeType | PslExtensionBlock;
export type PslNamespaceEntry = PslModel | PslCompositeType | PslExtensionBlock;

@@ -226,4 +205,2 @@ /**

readonly models: readonly PslModel[];
/** Built-in enums, from `entries['enum']`. */
readonly enums: readonly PslEnum[];
/** Built-in composite types, from `entries['compositeType']`. */

@@ -262,8 +239,2 @@ readonly compositeTypes: readonly PslCompositeType[];

get enums(): readonly PslEnum[] {
return blindCast<readonly PslEnum[], 'entries[enum] holds only PslEnum by construction'>(
Object.values(this.entries['enum'] ?? {}),
);
}
get compositeTypes(): readonly PslCompositeType[] {

@@ -294,3 +265,2 @@ return blindCast<

models: readonly PslModel[],
enums: readonly PslEnum[],
compositeTypes: readonly PslCompositeType[],

@@ -309,10 +279,2 @@ extensionBlocks: readonly PslExtensionBlock[],

if (enums.length > 0) {
const map: Record<string, PslEnum> = {};
for (const e of enums) {
map[e.name] = e;
}
container['enum'] = Object.freeze(map);
}
if (compositeTypes.length > 0) {

@@ -361,13 +323,2 @@ const map: Record<string, PslCompositeType> = {};

/**
* Returns all enums from every namespace in document order.
*/
export function flatPslEnums(ast: PslDocumentAst): readonly PslEnum[] {
return ast.namespaces.flatMap((ns) =>
blindCast<PslEnum[], 'enum kind map contains only PslEnum by construction'>(
Object.values(ns.entries['enum'] ?? {}),
),
);
}
/**
* Returns all composite types from every namespace in document order.

@@ -390,9 +341,7 @@ */

* Built-in keys match the PSL keyword used on each block type:
* `'model'`, `'enum'`, `'compositeType'`.
* `'model'`, `'compositeType'`. The `'enum'` keyword is claimed by the
* extension-block grammar via a registered descriptor, so `entries['enum']`
* holds `PslExtensionBlock` nodes and is returned by `namespacePslExtensionBlocks`.
*/
export const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string> = new Set([
'model',
'enum',
'compositeType',
]);
export const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string> = new Set(['model', 'compositeType']);

@@ -403,4 +352,4 @@ /**

*
* Reads from `namespace.entries`, skipping the three built-in kind keys
* (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain
* Reads from `namespace.entries`, skipping the built-in kind keys
* (`'model'`, `'compositeType'`). All remaining kind maps contain
* only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).

@@ -407,0 +356,0 @@ */

@@ -110,11 +110,13 @@ /**

// 1. Unknown parameters — keys in the node not in the descriptor.
for (const key of nodeKeys) {
if (!descriptorKeys.has(key)) {
const captured = node.parameters[key];
diagnostics.push({
code: 'PSL_EXTENSION_UNKNOWN_PARAMETER',
message: `Unknown parameter "${key}" in "${descriptor.keyword}" block "${node.name}". The descriptor does not declare this parameter.`,
sourceId,
span: captured?.span ?? node.span,
});
if (!descriptor.variadicParameters) {
for (const key of nodeKeys) {
if (!descriptorKeys.has(key)) {
const captured = node.parameters[key];
diagnostics.push({
code: 'PSL_EXTENSION_UNKNOWN_PARAMETER',
message: `Unknown parameter "${key}" in "${descriptor.keyword}" block "${node.name}". The descriptor does not declare this parameter.`,
sourceId,
span: captured?.span ?? node.span,
});
}
}

@@ -121,0 +123,0 @@ }

@@ -1,8 +0,7 @@

export interface RuntimeErrorEnvelope extends Error {
readonly code: string;
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
readonly severity: 'error';
readonly details?: Record<string, unknown>;
}
import type { RuntimeErrorEnvelope } from '../shared/runtime-error';
import { runtimeError } from '../shared/runtime-error';
export type { RuntimeErrorEnvelope } from '../shared/runtime-error';
export { isRuntimeError, runtimeError } from '../shared/runtime-error';
/**

@@ -34,51 +33,2 @@ * Stable code emitted by the runtime when an in-flight `execute()`

/**
* Type guard for the runtime-error envelope produced by `runtimeError`.
*
* Prefer this over duck-typing on `error.code` directly so consumers stay
* insulated from the envelope's internal shape.
*/
export function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope {
return (
error instanceof Error &&
'code' in error &&
typeof (error as { code?: unknown }).code === 'string' &&
'category' in error &&
'severity' in error
);
}
export function runtimeError(
code: string,
message: string,
details?: Record<string, unknown>,
): RuntimeErrorEnvelope {
const error = new Error(message) as RuntimeErrorEnvelope;
Object.defineProperty(error, 'name', {
value: 'RuntimeError',
configurable: true,
});
return Object.assign(error, {
code,
category: resolveCategory(code),
severity: 'error' as const,
message,
details,
});
}
function resolveCategory(code: string): RuntimeErrorEnvelope['category'] {
const prefix = code.split('.')[0] ?? 'RUNTIME';
switch (prefix) {
case 'PLAN':
case 'CONTRACT':
case 'LINT':
case 'BUDGET':
return prefix;
default:
return 'RUNTIME';
}
}
/**
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the

@@ -85,0 +35,0 @@ * abort was observed — codec call sites (`encode` / `decode` / `stream`)

@@ -6,2 +6,3 @@ export type {

AuthoringContributions,
AuthoringDiagnosticSink,
AuthoringEntityContext,

@@ -8,0 +9,0 @@ AuthoringEntityTypeDescriptor,

@@ -19,2 +19,3 @@ /**

CodecRef,
CodecRegistry,
CodecTrait,

@@ -30,1 +31,7 @@ } from '../shared/codec-types';

export { column } from '../shared/column-spec';
export {
CONTRACT_CODEC_DESCRIPTOR_MISSING,
materializeCodec,
resolveCodecDescriptorOrThrow,
validateCodecTypeParams,
} from '../shared/resolve-codec';

@@ -50,3 +50,2 @@ export type { ImportRequirement } from '@prisma-next/ts-render';

OpFactoryCall,
SerializedQueryPlan,
TargetMigrationsCapability,

@@ -53,0 +52,0 @@ } from '../control/control-migration-types';

export { domainElementCoordinates } from '../ir/domain';
export type { AnyEntityKindDescriptor, EntityKindDescriptor } from '../ir/entity-kind';
export { hydrateNamespaceEntities } from '../ir/entity-kind';
export type { IRNode } from '../ir/ir-node';

@@ -7,3 +9,3 @@ export { freezeNode, IRNodeBase } from '../ir/ir-node';

export type { EntityCoordinate, Storage } from '../ir/storage';
export { elementCoordinates } from '../ir/storage';
export { elementCoordinates, entityAt, isPlainRecord } from '../ir/storage';
export type { StorageType } from '../ir/storage-type';

@@ -0,5 +1,9 @@

import { isPlainRecord } from '@prisma-next/contract/is-plain-record';
import type { StorageBase } from '@prisma-next/contract/types';
import { blindCast } from '@prisma-next/utils/casts';
import type { IRNode } from './ir-node';
import type { Namespace } from './namespace';
export { isPlainRecord };
/**

@@ -33,7 +37,7 @@ * Canonical address for a named entity in Contract IR / Schema IR.

*
* Iterates each namespace's `entries` slot maps structurally. Skips
* Iterates each namespace's `entries` kind maps structurally. Skips
* non-object `entries`; `id` and `kind` are not walked (`kind` is
* non-enumerable on concretions). For every entity-kind key under
* `entries` whose value is a non-null object, yields one coordinate per
* entity name in that map. No family-specific slot vocabulary is required.
* entity name in that map. No family-specific kind vocabulary is required.
*/

@@ -46,5 +50,5 @@ export function* elementCoordinates(

if (entries === null || typeof entries !== 'object') continue;
for (const [entityKind, slot] of Object.entries(entries)) {
if (slot === null || typeof slot !== 'object') continue;
for (const entityName of Object.keys(slot)) {
for (const [entityKind, kindMap] of Object.entries(entries)) {
if (kindMap === null || typeof kindMap !== 'object') continue;
for (const entityName of Object.keys(kindMap)) {
yield { plane: 'storage', namespaceId, entityKind, entityName };

@@ -57,2 +61,24 @@ }

/**
* Looks up a single entity in a `Storage`-shaped value by its full coordinate.
* Returns `undefined` if the namespace, entity kind, or entity name is absent.
* The type parameter is a caller assertion — the walk itself is structural
* and cannot verify the entity's shape.
*/
export function entityAt<T = unknown>(
storage: Pick<StorageBase, 'namespaces'>,
coord: Pick<EntityCoordinate, 'namespaceId' | 'entityKind' | 'entityName'>,
): T | undefined {
const ns = storage.namespaces[coord.namespaceId];
if (ns === undefined) return undefined;
const entries = ns.entries;
if (!isPlainRecord(entries)) return undefined;
const kindMap = entries[coord.entityKind];
if (!isPlainRecord(kindMap)) return undefined;
if (!Object.hasOwn(kindMap, coord.entityName)) return undefined;
return blindCast<T | undefined, 'caller asserts the entity type at this coordinate'>(
kindMap[coord.entityName],
);
}
/**
* Framework-level promise that every Contract IR / Schema IR carries a

@@ -72,3 +98,3 @@ * collection of namespaces keyed by namespace id. Family storage

* Extends `IRNode` so the framework's IR-walking surfaces (verifiers,
* serializers) can dispatch on `Storage`-typed slots through the same
* serializers) can dispatch on `Storage`-typed fields through the same
* IR-node alphabet as every other node — the structural dual already

@@ -75,0 +101,0 @@ * holds in code (every concrete storage class extends an IR-node base);

@@ -46,2 +46,4 @@ /**

readonly renderOutputType?: (params: P) => string | undefined;
/** Emit-path string renderer for the `contract.d.ts` *input* position (create/update values). Returns the TypeScript input type expression for given params. Optional; absent renderers fall back to the codec's base input type. A codec supplies this when its write type is narrower than the generic codec input — e.g. an enum whose input should be the literal member union, not `string`. */
readonly renderInputType?: (params: P) => string | undefined;
/** The curried higher-order codec. For non-parameterized codecs, the factory is constant — every call returns the same shared codec instance. For parameterized codecs, the factory is called once per `storage.types` instance (or once per inline-`typeParams` column), with `ctx` carrying the column set the resulting codec serves. */

@@ -82,2 +84,5 @@ readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;

/** Optional emit-path string renderer for the `contract.d.ts` input position. Returns the TypeScript input type expression for the given params; supplied when the write type is narrower than the generic codec input (e.g. an enum's literal member union). */
renderInputType?(params: TParams): string | undefined;
/**

@@ -84,0 +89,0 @@ * Materialize a curried codec factory for the given params. Concrete subclasses override with a typed return type (e.g. `factory<N>(params: { length: N }): (ctx) => VectorCodec<N>`); per-codec helpers read the typed return at the *direct* call site, which is what preserves method-level generics. Type extraction (e.g. `ReturnType<D['factory']>`) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.

@@ -39,3 +39,3 @@ import type { JsonValue } from '@prisma-next/contract/types';

*
* - `get(id)` returns the runtime {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults).
* - `get(id)` returns a representative {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults). For parameterized codecs whose factory requires concrete params, this may return `undefined` — use `CodecRegistry.forCodecRef` instead.
* - `targetTypesFor(id)` exposes the codec-id-keyed `targetTypes` metadata the runtime instance no longer carries (TML-2357). Returns the same array `CodecDescriptor.targetTypes` would; for Mongo (whose registration doesn't yet resolve through the unified descriptor map — TML-2324) the family-side assembly populates this directly from the contributor's codec metadata.

@@ -50,4 +50,24 @@ * - `metaFor(id)` exposes the codec-id-keyed `meta` (e.g. SQL-side `db.sql.postgres.nativeType`) the runtime instance no longer carries.

renderOutputTypeFor(id: string, params: Record<string, unknown>): string | undefined;
/** Codec-id-keyed `renderInputType` renderer for the `contract.d.ts` input position. Optional so existing lookups need not provide it; returns `undefined` when the codec renders no custom input type or the id is unknown. */
renderInputTypeFor?(id: string, params: Record<string, unknown>): string | undefined;
}
/**
* Full codec registry — the read surface of {@link CodecLookup} plus codec resolution by ref or
* column coordinate. Built once by `extractCodecLookup` and passed by reference to adapters and
* other consumers that need to materialise codecs at runtime.
*
* - `forCodecRef(ref)` materialises a codec from a {@link CodecRef}. Throws
* `RUNTIME.CODEC_DESCRIPTOR_MISSING` for unknown ids and `RUNTIME.TYPE_PARAMS_INVALID` on param
* schema rejection.
* - `forColumn(namespaceId, table, column)` returns the codec for a specific column coordinate, or
* `undefined` when no column-to-codec mapping is present. This registry is contract-free so it
* always returns `undefined` — the method exists so the object structurally satisfies the SQL
* `ContractCodecRegistry` interface.
*/
export interface CodecRegistry extends CodecLookup {
forCodecRef(ref: CodecRef): Codec;
forColumn(namespaceId: string, table: string, column: string): Codec | undefined;
}
export const emptyCodecLookup: CodecLookup = {

@@ -54,0 +74,0 @@ get: () => undefined,

@@ -13,2 +13,3 @@ import type {

import type { Type } from 'arktype';
import type { CodecLookup } from './codec-types';
import type { PslBlockParam } from './psl-extension-block';

@@ -113,5 +114,26 @@

*/
/**
* A write-only sink that a factory may push authoring-time diagnostics into.
* The concrete type pushed must be structurally compatible with whatever the
* consumer accumulates (typically `ContractSourceDiagnostic[]`); the framework
* layer deliberately does not depend on that concrete type.
*/
export interface AuthoringDiagnosticSink {
push(d: {
readonly code: string;
readonly message: string;
readonly sourceId: string;
readonly span?: unknown;
}): void;
}
export interface AuthoringEntityContext {
readonly family: string;
readonly target: string;
/** Codec registry available to factories that need to validate or decode values. */
readonly codecLookup?: CodecLookup;
/** Source file identifier threaded into diagnostics emitted by the factory. */
readonly sourceId?: string;
/** Push channel for authoring-time diagnostics emitted by the factory. */
readonly diagnostics?: AuthoringDiagnosticSink;
}

@@ -191,2 +213,17 @@

readonly parameters: Record<string, PslBlockParam>;
/**
* When `true`, the block body accepts a variadic tail of parameters beyond
* the declared set. The block body may contain: fields (model-style),
* `key = value` parameters, and `@@` attributes. With `variadicParameters`,
* bare identifiers (keys without a `= value`) and undeclared `key = value`
* pairs flow into the variadic tail — their semantics belong to the
* lowering, not the parser.
*
* A key that IS declared in `parameters` must still be supplied as
* `key = value`; a bare occurrence of a declared key is a diagnostic.
*
* When `false` (default), the validator emits `PSL_EXTENSION_UNKNOWN_PARAMETER`
* for keys absent from `parameters`.
*/
readonly variadicParameters?: boolean;
}

@@ -335,9 +372,25 @@

function isPlainNamespaceObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
function isCopyableNamespaceObject(value: unknown): value is Record<string, unknown> {
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
const proto: unknown = Object.getPrototypeOf(value);
return proto === Object.prototype || proto === null;
}
function deepCopyNamespace(
source: Record<string, unknown>,
isLeafDescriptor: (value: unknown) => boolean,
): Record<string, unknown> {
const copy: Record<string, unknown> = {};
for (const [key, value] of Object.entries(source)) {
copy[key] =
isCopyableNamespaceObject(value) && !isLeafDescriptor(value)
? deepCopyNamespace(value, isLeafDescriptor)
: value;
}
return copy;
}
/**
* Merges `source` into `target` recursively at the descriptor-namespace
* level. `leafGuard` decides which values are descriptors (terminal
* level. `isLeafDescriptor` decides which values are descriptors (terminal
* merge points; same-path registrations across components are reported

@@ -362,3 +415,3 @@ * as duplicates) versus sub-namespaces (recursion targets).

path: readonly string[],
leafGuard: (value: unknown) => boolean,
isLeafDescriptor: (value: unknown) => boolean,
label: string,

@@ -384,8 +437,15 @@ ): void {

if (!hasExistingValue) {
target[key] = sourceValue;
// Deep-copy plain-object sub-namespaces so subsequent merges don't mutate
// objects owned by source packs. Leaf descriptors and class instances are
// passed by reference — leaves are identity values; class instances carry
// prototype getters that spread would destroy.
target[key] =
isCopyableNamespaceObject(sourceValue) && !isLeafDescriptor(sourceValue)
? deepCopyNamespace(sourceValue, isLeafDescriptor)
: sourceValue;
continue;
}
const existingIsLeaf = leafGuard(existingValue);
const sourceIsLeaf = leafGuard(sourceValue);
const existingIsLeaf = isLeafDescriptor(existingValue);
const sourceIsLeaf = isLeafDescriptor(sourceValue);

@@ -398,3 +458,3 @@ if (existingIsLeaf || sourceIsLeaf) {

if (!isPlainNamespaceObject(existingValue) || !isPlainNamespaceObject(sourceValue)) {
if (!isCopyableNamespaceObject(existingValue) || !isCopyableNamespaceObject(sourceValue)) {
throw new Error(

@@ -405,7 +465,7 @@ `Invalid authoring ${label} helper "${currentPath.join('.')}". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`,

mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, leafGuard, label);
mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, isLeafDescriptor, label);
}
}
function collectAuthoringLeafPaths(
function collectDescriptorPaths(
namespace: Readonly<Record<string, unknown>>,

@@ -424,7 +484,3 @@ isLeaf: (value: unknown) => boolean,

paths.push(
...collectAuthoringLeafPaths(
value as Readonly<Record<string, unknown>>,
isLeaf,
currentPath,
),
...collectDescriptorPaths(value as Readonly<Record<string, unknown>>, isLeaf, currentPath),
);

@@ -436,3 +492,3 @@ }

interface AuthoringLeafEntry {
interface DescriptorEntry {
readonly path: string;

@@ -442,3 +498,3 @@ readonly discriminator: string;

function collectAuthoringLeafDiscriminators(
function collectDescriptorEntries(
namespace: Readonly<Record<string, unknown>>,

@@ -448,4 +504,4 @@ isLeaf: (value: unknown) => boolean,

path: readonly string[] = [],
): AuthoringLeafEntry[] {
const entries: AuthoringLeafEntry[] = [];
): DescriptorEntry[] {
const entries: DescriptorEntry[] = [];
for (const [key, value] of Object.entries(namespace)) {

@@ -494,3 +550,3 @@ const currentPath = [...path, key];

}
entries.push(...collectAuthoringLeafDiscriminators(record, isLeaf, label, currentPath));
entries.push(...collectDescriptorEntries(record, isLeaf, label, currentPath));
}

@@ -507,3 +563,3 @@ }

*/
function assertUniqueDiscriminators(entries: readonly AuthoringLeafEntry[], label: string): void {
function assertUniqueDiscriminators(entries: readonly DescriptorEntry[], label: string): void {
const seen = new Map<string, string>();

@@ -521,8 +577,39 @@ for (const { path, discriminator } of entries) {

function collectPslBlockDescriptorEntries(
namespace: Readonly<Record<string, unknown>>,
path: readonly string[] = [],
): DescriptorEntry[] {
const entries: DescriptorEntry[] = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isAuthoringPslBlockDescriptor(value)) {
entries.push({
path: currentPath.join('.'),
discriminator: value.discriminator,
});
continue;
}
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
const record = blindCast<
Readonly<Record<string, unknown>>,
'walker descends into psl block namespace'
>(value);
const hasKind = record['kind'] === 'pslBlock';
const hasKeyword = typeof record['keyword'] === 'string';
const hasDiscriminator = typeof record['discriminator'] === 'string';
if (hasKind || (hasKeyword && hasDiscriminator)) {
throw new Error(
`Malformed authoring pslBlock contribution at "${currentPath.join('.')}". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the pslBlock descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`,
);
}
entries.push(...collectPslBlockDescriptorEntries(record, currentPath));
}
}
return entries;
}
/**
* Every `pslBlockDescriptors` entry needs a matching `entityTypes` factory
* (same discriminator): the parser would otherwise produce an AST node
* nothing can lower to an IR class instance. The link is one-directional
* — an `entityTypes` factory may stand alone (e.g. `enum`, reachable from
* the TypeScript builder without any PSL block).
* Every `pslBlockDescriptors` entry requires a matching `entityTypes` factory
* with the same discriminator. An `entityTypes` factory may stand alone (e.g.
* `enum`, reachable from the TypeScript builder without any PSL block).
*/

@@ -533,8 +620,4 @@ function assertPslBlocksHaveFactories(

): void {
const blockEntries = collectAuthoringLeafDiscriminators(
pslBlockNamespace,
isAuthoringPslBlockDescriptor,
'pslBlock',
);
const entityEntries = collectAuthoringLeafDiscriminators(
const blockEntries = collectPslBlockDescriptorEntries(pslBlockNamespace);
const entityEntries = collectDescriptorEntries(
entityTypeNamespace,

@@ -566,9 +649,9 @@ isAuthoringEntityTypeDescriptor,

const typePaths = new Set(
collectAuthoringLeafPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),
collectDescriptorPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),
);
const fieldPaths = new Set(
collectAuthoringLeafPaths(fieldNamespace, isAuthoringFieldPresetDescriptor),
collectDescriptorPaths(fieldNamespace, isAuthoringFieldPresetDescriptor),
);
const entityPaths = new Set(
collectAuthoringLeafPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor),
collectDescriptorPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor),
);

@@ -575,0 +658,0 @@ // Within-registry duplicate detection is handled upstream by the merge

@@ -39,2 +39,16 @@ /**

/**
* A qualified name (e.g. a dotted type or attribute reference) is structurally
* invalid, such as an over-qualified or trailing-separator name.
*/
| 'PSL_INVALID_QUALIFIED_NAME'
/**
* A reserved declaration keyword (`model`/`enum`/`namespace`/`type`) that
* committed the declaration kind on the keyword alone but is missing its name
* and/or opening brace. The recursive-descent parser produces a best-effort
* typed node for the malformed header and reports this code rather than
* `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`, which is reserved for a genuinely unknown
* top-level keyword.
*/
| 'PSL_INVALID_DECLARATION'
/**
* A malformed line inside an extension-contributed top-level block body, or

@@ -51,2 +65,17 @@ * a structurally invalid element inside a `list` parameter value.

/**
* A malformed JS-like object literal `{ key: value, … }` in value/argument
* position — a field missing its `:`, a field missing its value, or an
* unterminated `{`. The recursive-descent parser still produces a best-effort
* `ObjectLiteralExpr` node (preserving the lossless round-trip) and reports
* this code anchored on the offending token.
*/
| 'PSL_INVALID_OBJECT_LITERAL'
/**
* A string literal with no closing quote — the tokenizer stops the literal at
* a newline or at EOF when no terminating `"` is found, and the
* recursive-descent parser still consumes the token (preserving the lossless
* round-trip) but reports this code anchored on the string token's span.
*/
| 'PSL_UNTERMINATED_STRING'
/**
* An unknown parameter key in an extension-contributed block — a key present

@@ -75,3 +104,12 @@ * in the source block but absent from the descriptor's `parameters` map.

*/
| 'PSL_EXTENSION_UNRESOLVED_REF';
| 'PSL_EXTENSION_UNRESOLVED_REF'
/**
* A parameter key appears more than once in an extension block body.
* The first occurrence is kept; subsequent occurrences emit this diagnostic.
*/
| 'PSL_EXTENSION_DUPLICATE_PARAMETER'
/**
* A `@@`-prefixed block-attribute line inside an extension block has invalid syntax.
*/
| 'PSL_INVALID_EXTENSION_BLOCK_ATTRIBUTE';

@@ -124,10 +162,13 @@ /**

* extension-block AST node. Mirrors the `PslBlockParam` descriptor
* vocabulary:
* vocabulary, plus `bare` for keyonly entries:
*
* - `ref` → `PslExtensionBlockParamRef` — a raw identifier string
* (resolution runs in the validator, not the parser).
* - `value` → `PslExtensionBlockParamValue` — a raw PSL literal string
* - `value` → `PslExtensionBlockParamScalarValue` — a raw PSL literal string
* (codec validation runs in the validator).
* - `option` → `PslExtensionBlockParamOption` — the chosen token.
* - `list` → `PslExtensionBlockParamList` — ordered list of the above.
* - `bare` → `PslExtensionBlockParamBare` — a bare identifier line with no
* `= value` (e.g. `Low` in an enum block). The name is the key in
* `parameters`; the interpreting consumer decides the default value.
*

@@ -141,3 +182,4 @@ * These shapes are intentionally minimal. The validator and lowering refine

| PslExtensionBlockParamOption
| PslExtensionBlockParamList;
| PslExtensionBlockParamList
| PslExtensionBlockParamBare;

@@ -169,2 +211,34 @@ export interface PslExtensionBlockParamRef {

/**
* A bare identifier line inside an extension block — a key with no `= value`.
* Emitted when a line matches `/^[A-Za-z_]\w*$/` with no assignment. The
* consumer decides what default value (if any) to apply.
*/
export interface PslExtensionBlockParamBare {
readonly kind: 'bare';
readonly span: PslSpan;
}
/**
* A positional argument on a block attribute, e.g. the `"pg/text@1"` in
* `@@type("pg/text@1")`.
*/
export interface PslExtensionBlockAttributeArg {
readonly kind: 'positional';
readonly value: string;
readonly span: PslSpan;
}
/**
* A `@@`-prefixed block-level attribute parsed inside an extension block,
* e.g. `@@type("pg/text@1")`. Block attributes are captured generically
* — the parser does not validate attribute names or argument shapes; that
* is a concern of the block's interpreter.
*/
export interface PslExtensionBlockAttribute {
readonly name: string;
readonly args: readonly PslExtensionBlockAttributeArg[];
readonly span: PslSpan;
}
/**
* Base shape for a uniform extension-contributed top-level PSL block

@@ -182,3 +256,8 @@ * node, as produced by the generic framework parser and consumed by the

* — absence of a required parameter is a validator concern, not a
* parser concern.
* parser concern. Insertion order is preserved; the first occurrence of a
* duplicate key is retained and subsequent occurrences emit
* `PSL_EXTENSION_DUPLICATE_PARAMETER`.
* - `blockAttributes` are `@@`-prefixed attribute lines inside the block, in
* declaration order. Captured generically — names and args are not validated
* by the parser.
* - `span` covers the full block from keyword to closing brace.

@@ -190,3 +269,4 @@ */

readonly parameters: Record<string, PslExtensionBlockParamValue>;
readonly blockAttributes: readonly PslExtensionBlockAttribute[];
readonly span: PslSpan;
}
import { JsonValue } from "@prisma-next/contract/types";
import { StandardSchemaV1 } from "@standard-schema/spec";
//#region src/shared/codec-types.d.ts
type CodecTrait = 'equality' | 'order' | 'boolean' | 'numeric' | 'textual';
/**
* Serializable codec identity carried by every codec-bearing AST node.
*
* `(codecId, typeParams?)` is the single fact the runtime needs to materialize a codec via `descriptorFor(codecId).factory(typeParams)(ctx)`. The pair is content-keyed: two refs with the same `codecId` and structurally equal `typeParams` (regardless of object key ordering) resolve to the same memoized {@link Codec} instance.
*
* `typeParams` is `JsonValue`-constrained so the ref survives JSON serialization (relevant for AST-embedded migration ops). Non-parameterized codecs leave `typeParams` undefined; the descriptor's `paramsSchema` validates the value at the JSON boundary.
*
* Family-agnostic by design — both SQL and Mongo AST nodes carry `codec: CodecRef | undefined`, and the resolver is the only dispatch path that survives serialization.
*/
interface CodecRef {
readonly codecId: string;
readonly typeParams?: JsonValue;
}
/**
* Per-call context the runtime threads to every `codec.encode` / `codec.decode` invocation for a single `runtime.execute()` call.
*
* The framework-level shape is family-agnostic and carries one field:
*
* - `signal?: AbortSignal` — per-query cancellation. The runtime returns a `RUNTIME.ABORTED` envelope when the signal aborts; codec authors who forward `signal` to their underlying SDK get true cancellation of in-flight network calls.
*
* Family layers extend this base with their own shape-of-call metadata: the SQL family adds `column?: SqlColumnRef` via `SqlCodecCallContext` (see `@prisma-next/sql-relational-core`). Mongo currently uses this framework type unchanged. Column metadata is intentionally **not** on the framework type — it is a SQL-family concept rooted in SQL's `(table, column)` addressing model and would not generalise to other families.
*
* The interface is named explicitly (not inlined) so future framework fields and family extensions can land additively without breaking codec author signatures.
*/
interface CodecCallContext {
readonly signal?: AbortSignal;
}
/**
* Codec-id-keyed read surface threaded into emit and authoring paths.
*
* - `get(id)` returns the runtime {@link Codec} instance for the codec id (used by `family.deserializeContract` for `decodeJson` of literal column defaults).
* - `targetTypesFor(id)` exposes the codec-id-keyed `targetTypes` metadata the runtime instance no longer carries (TML-2357). Returns the same array `CodecDescriptor.targetTypes` would; for Mongo (whose registration doesn't yet resolve through the unified descriptor map — TML-2324) the family-side assembly populates this directly from the contributor's codec metadata.
* - `metaFor(id)` exposes the codec-id-keyed `meta` (e.g. SQL-side `db.sql.postgres.nativeType`) the runtime instance no longer carries.
* - `renderOutputTypeFor(id, params)` exposes the codec-id-keyed `renderOutputType` renderer the runtime instance no longer carries. Returns `undefined` when the codec doesn't render a custom type or when the codec id is unknown.
*/
interface CodecLookup {
get(id: string): Codec | undefined;
targetTypesFor(id: string): readonly string[] | undefined;
metaFor(id: string): CodecMeta | undefined;
renderOutputTypeFor(id: string, params: Record<string, unknown>): string | undefined;
}
declare const emptyCodecLookup: CodecLookup;
/**
* Family-agnostic per-instance context supplied by the framework when applying a higher-order codec factory. Allows stateful codecs (e.g. column-scoped encryption) to derive per-instance state from the materialization site.
*
* - `name` — the family-agnostic instance identity. For SQL, the runtime populates this as the `storage.types` instance name (e.g. `Embedding1536`) for typeRef-shaped columns, an inline-column sentinel (`<col:Document.embedding>`) for inline-`typeParams` columns, a shared codec-id sentinel (`<codec:pg/text@1>`) for non-parameterized codec ids, or the canonical cache key (`<codecId>:<canonicalizeJson(typeParams)>`) for ad-hoc refs the contract walk did not pre-populate. Other families pick the analogous identity for their materialization sites.
*
* Family-specific extensions (e.g. {@link import('@prisma-next/sql-relational-core/ast').SqlCodecInstanceContext} in the SQL layer) augment this base with domain-shaped column-set metadata. Codec authors target the base when they don't read family-specific metadata; they target the family extension when they do.
*/
interface CodecInstanceContext {
readonly name: string;
}
/**
* Family-agnostic codec metadata. Family-specific extensions augment the base `db.<family>.<target>` block with native-type information; the base shape is an empty object so non-relational codecs can carry no metadata.
*/
interface CodecMeta {
readonly db?: Record<string, unknown>;
}
/**
* Standard Schema validator for `void` params. Accepts only `undefined` (or absent input); rejects any other value so a contract that tries to thread `typeParams` through a non-parameterized codec id fails fast at the JSON boundary instead of silently coercing the value away. Used by the framework-supplied non-parameterized descriptor synthesizer.
*/
declare const voidParamsSchema: StandardSchemaV1<void>;
//#endregion
//#region src/shared/codec-descriptor.d.ts
/**
* Unified codec descriptor. Every codec in the framework registers through this shape — non-parameterized codecs use `P = void` and a constant factory that returns the same shared codec instance for every column; parameterized codecs use a non-empty `P` and a curried higher-order factory that returns a per-instance codec.
*
* The descriptor is the codec-id-keyed source of truth for static metadata (`traits`, `targetTypes`, `meta`) and registration concerns (`paramsSchema` for JSON-boundary validation; optional `renderOutputType` for the `contract.d.ts` emit path). The runtime `Codec` instance returned by `factory(params)(ctx)` carries only the conversion behavior.
*
* Whether a codec id "is parameterized" stops being a registration-time distinction — it's a property of `P` on the descriptor. The descriptor map indexes every descriptor by `codecId`; both `descriptorFor(codecId)` and `forColumn(table, column)` resolve through the same map without branching on parameterization.
*
* @template P - The shape of the params accepted by the factory (`void` for non-parameterized codecs; a record like `{ length: number }` for parameterized codecs).
*
* Codec-registry-unification project § Decision.
*/
interface CodecDescriptor<P = void> {
/** The codec ID this descriptor applies to (e.g. `pg/vector@1`, `pg/text@1`). */
readonly codecId: string;
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
readonly traits: readonly CodecTrait[];
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
readonly targetTypes: readonly string[];
/** Optional family-specific metadata (e.g. SQL-side `db.sql.postgres.nativeType`). */
readonly meta?: CodecMeta;
/** Standard Schema validator for the factory's params. Validates JSON-sourced params at the contract boundary (PSL → IR; `contract.json` → runtime). For non-parameterized codecs (`P = void`), the schema validates `void`/`undefined` — the framework supplies no params at the call boundary. */
readonly paramsSchema: StandardSchemaV1<P>;
/** Whether this descriptor is parameterized — i.e. its `paramsSchema` is something other than the singleton `voidParamsSchema`. Consumers that need to gate column-aware dispatch read this directly rather than threading a free-floating `(codecId) => boolean` callback. */
readonly isParameterized: boolean;
/** Emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for given params (e.g. `Vector<1536>`). Optional; absent renderers cause the emitter to fall back to the codec's base output type. Non-parameterized codecs typically omit it. */
readonly renderOutputType?: (params: P) => string | undefined;
/** The curried higher-order codec. For non-parameterized codecs, the factory is constant — every call returns the same shared codec instance. For parameterized codecs, the factory is called once per `storage.types` instance (or once per inline-`typeParams` column), with `ctx` carrying the column set the resulting codec serves. */
readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;
}
/**
* Variance-erased {@link CodecDescriptor} alias. `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly), so `CodecDescriptor<P>` does not extend `CodecDescriptor<unknown>` for specific `P`. Heterogeneous descriptor collections — e.g. `SqlStaticContributions.codecs:` returning a list that mixes parameterized and non-parameterized descriptors — type against this alias and narrow per codec id at the consumer.
*
* Codec-registry-unification spec § Decision: every codec resolves through one descriptor map; reads are non-branching.
*/
type AnyCodecDescriptor = CodecDescriptor<any>;
/**
* Abstract base class for concrete codec descriptors.
*
* Codec authors extend this class with their typed `TParams` and declare `codecId`, `traits`, `targetTypes`, `paramsSchema`, the curried `factory(params)`, and (optionally) `renderOutputType`.
*
* Implements the {@link CodecDescriptor} interface so a concrete subclass instance is directly usable wherever the framework expects a `CodecDescriptor<P>`.
*/
declare abstract class CodecDescriptorImpl<TParams = void> implements CodecDescriptor<TParams> {
abstract readonly codecId: string;
abstract readonly traits: readonly CodecTrait[];
abstract readonly targetTypes: readonly string[];
readonly meta?: CodecMeta;
abstract readonly paramsSchema: StandardSchemaV1<TParams>;
/** Boolean derived from `paramsSchema`: `true` whenever the schema is not the singleton `voidParamsSchema`. */
get isParameterized(): boolean;
/** Optional emit-path string renderer for `contract.d.ts`. Returns the TypeScript output type expression for the given params (e.g. `Vector<1536>`). Non-parameterized codecs typically omit it. */
renderOutputType?(params: TParams): string | undefined;
/**
* Materialize a curried codec factory for the given params. Concrete subclasses override with a typed return type (e.g. `factory<N>(params: { length: N }): (ctx) => VectorCodec<N>`); per-codec helpers read the typed return at the *direct* call site, which is what preserves method-level generics. Type extraction (e.g. `ReturnType<D['factory']>`) widens method generics to their constraint — that's why the column-helper surface is per-codec, not polymorphic.
*/
abstract factory(params: TParams): (ctx: CodecInstanceContext) => Codec<string, readonly CodecTrait[], unknown, unknown>;
}
//#endregion
//#region src/shared/codec.d.ts
/**
* A codec is the contract between an application value and its on-wire and on-contract-disk representations.
*
* The author's mental model is two JS-side types — `TInput` (the application JS type) and `TWire` (the database driver wire format) — plus `JsonValue` for build-time contract artifacts. The codec translates `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue` during contract emission and loading.
*
* Three representations participate:
* - **Input** (`TInput`): the JS type at the application boundary.
* - **Wire** (`TWire`): the format exchanged with the database driver.
* - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.
*
* The runtime instance carries only its `id` (the descriptor's `codecId`, set by the factory) and the four conversion methods. Static metadata (`traits`, `targetTypes`, `meta`) and the build-time `renderOutputType` renderer live on the {@link CodecDescriptor} keyed by `codecId` — the read-surface single source of truth. Consumers that need them resolve through `descriptorFor(codecId)`.
*
* Codec methods split into two groups:
*
* - **Query-time** methods (`encode`, `decode`) run per row/parameter at the IO boundary; they are required and Promise-returning. The per-family codec factory accepts sync or async author functions and lifts sync ones to Promise-shaped methods automatically.
* - **Build-time** methods (`encodeJson`, `decodeJson`) run when the contract is serialized or loaded. They stay synchronous so contract validation and client construction are synchronous.
*
* Target-family codec interfaces extend this base; family-specific concerns (e.g. the SQL `column?` per-call context) layer on through the `CodecCallContext` extension pattern.
*/
interface Codec<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown> {
/** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). The factory sets this to the descriptor's `codecId`; consumers use it as a back-reference for descriptor lookups and for decode-error diagnostics. */
readonly id: Id;
/** Phantom carrier for the `TTraits` generic; type-only, undefined at runtime. Runtime traits live on {@link CodecDescriptor.traits}. Implemented as a string-key phantom (`__codecTraits`) rather than `unique symbol` so bundlers that split `.d.ts` chunks do not strand symbol identity on chunk-private paths (the same `TS2742` family that the public re-export of `CodecTypes` works around). */
readonly __codecTraits?: TTraits;
/** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(value) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;
/** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(wire) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;
/** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */
encodeJson(value: TInput): JsonValue;
/** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `family.deserializeContract`. */
decodeJson(json: JsonValue): TInput;
}
/**
* Abstract base class for concrete codec implementations.
*
* Codec authors extend this class with their typed `Id`, `TTraits`, `TWire`, `TInput` and override `encode`/`decode` (and optionally `encodeJson`/`decodeJson`). The runtime instance carries only its `id` (proxied through the descriptor so alias subclasses inherit the descriptor's id automatically) and the conversion methods — static metadata lives on the {@link CodecDescriptor}.
*/
declare abstract class CodecImpl<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown> implements Codec<Id, TTraits, TWire, TInput> {
readonly descriptor: CodecDescriptor<any>;
/**
* Variance-erased descriptor reference. Concrete codec subclasses receive the typed descriptor in their own constructors and forward it via `super(descriptor)`; the variance erasure lives at this base because the abstract surface can't carry the concrete `TParams`.
*/
constructor(descriptor: CodecDescriptor<any>);
get id(): Id;
abstract encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;
abstract decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;
abstract encodeJson(value: TInput): JsonValue;
abstract decodeJson(json: JsonValue): TInput;
}
//#endregion
export { CodecDescriptorImpl as a, CodecLookup as c, CodecTrait as d, emptyCodecLookup as f, CodecDescriptor as i, CodecMeta as l, CodecImpl as n, CodecCallContext as o, voidParamsSchema as p, AnyCodecDescriptor as r, CodecInstanceContext as s, Codec as t, CodecRef as u };
//# sourceMappingURL=codec-DCQAerzB.d.mts.map
{"version":3,"file":"codec-DCQAerzB.d.mts","names":[],"sources":["../src/shared/codec-types.ts","../src/shared/codec-descriptor.ts","../src/shared/codec.ts"],"mappings":";;;;KAIY,UAAA;AAAZ;;;;AAAsB;AAWtB;;;;AAXA,UAWiB,QAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA,GAAa,SAAS;AAAA;AAAA;AAcjC;;;;AAC+B;AAW/B;;;;;AA1BiC,UAchB,gBAAA;EAAA,SACN,MAAA,GAAS,WAAW;AAAA;;;;;;;;;UAWd,WAAA;EACf,GAAA,CAAI,EAAA,WAAa,KAAA;EACjB,cAAA,CAAe,EAAA;EACf,OAAA,CAAQ,EAAA,WAAa,SAAA;EACrB,mBAAA,CAAoB,EAAA,UAAY,MAAA,EAAQ,MAAA;AAAA;AAAA,cAG7B,gBAAA,EAAkB,WAK9B;;;;AAAA;AASD;;;UAAiB,oBAAA;EAAA,SACN,IAAI;AAAA;;;;UAME,SAAA;EAAA,SACN,EAAA,GAAK,MAAM;AAAA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,UAAA,CAAW,KAAA,EAAO,MAAA,GAAS,SAAA;EFDK;EEGhC,UAAA,CAAW,IAAA,EAAM,SAAA,GAAY,MAAA;AAAA;AFA/B;;;;AAKC;AALD,uBEQsB,SAAA,sDAEK,UAAA,cAAwB,UAAA,kDAGtC,KAAA,CAAM,EAAA,EAAI,OAAA,EAAS,KAAA,EAAO,MAAA;EAAA,SAMT,UAAA,EAAY,eAAA;;;AFJ3B;cEIe,UAAA,EAAY,eAAA;EAAA,IAEpC,EAAA,IAAM,EAAA;EAAA,SAID,MAAA,CAAO,KAAA,EAAO,MAAA,EAAQ,GAAA,EAAK,gBAAA,GAAmB,OAAA,CAAQ,KAAA;EAAA,SACtD,MAAA,CAAO,IAAA,EAAM,KAAA,EAAO,GAAA,EAAK,gBAAA,GAAmB,OAAA,CAAQ,MAAA;EAAA,SACpD,UAAA,CAAW,KAAA,EAAO,MAAA,GAAS,SAAA;EAAA,SAC3B,UAAA,CAAW,IAAA,EAAM,SAAA,GAAY,MAAA;AAAA"}
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { Contract, ContractModel } from "@prisma-next/contract/types";
//#region src/control/emission-types.d.ts
interface GenerateContractTypesOptions {
readonly queryOperationTypeImports?: ReadonlyArray<TypesImportSpec>;
}
interface ValidationContext {
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
readonly extensionIds?: ReadonlyArray<string>;
}
interface EmissionSpi {
readonly id: string;
generateStorageType(contract: Contract, storageHashTypeName: string): string;
generateModelStorageType(modelName: string, model: ContractModel): string;
getFamilyImports(): string[];
getFamilyTypeAliases(options?: GenerateContractTypesOptions): string;
getTypeMapsExpression(): string;
getContractWrapper(contractBaseName: string, typeMapsName: string): string;
/**
* Per-family resolver for typeParams that don't live inline on the
* framework-domain `ContractField`. Some families (notably SQL) let columns
* reference a named entry in `storage.types` via `typeRef`; the typeParams
* live on that named entry rather than on the domain field. The framework
* emit path consults this hook so the codec's `renderOutputType` can run
* for typeRef-shaped columns.
*
* Inline `field.type.typeParams` always takes precedence; the hook is only
* consulted when the domain field has no typeParams. Families without
* named storage types (e.g. mongo) don't implement this hook.
*
* Returns `undefined` when the field has no resolvable typeParams.
*/
resolveFieldTypeParams?(modelName: string, fieldName: string, model: ContractModel, contract: Contract): Record<string, unknown> | undefined;
}
//#endregion
export { GenerateContractTypesOptions as n, ValidationContext as r, EmissionSpi as t };
//# sourceMappingURL=emission-types-vfpSTe63.d.mts.map
{"version":3,"file":"emission-types-vfpSTe63.d.mts","names":[],"sources":["../src/control/emission-types.ts"],"mappings":";;;;UAGiB,4BAAA;EAAA,SACN,yBAAA,GAA4B,aAAa,CAAC,eAAA;AAAA;AAAA,UAGpC,iBAAA;EAAA,SACN,gBAAA,GAAmB,aAAA,CAAc,eAAA;EAAA,SACjC,YAAA,GAAe,aAAA;AAAA;AAAA,UAGT,WAAA;EAAA,SACN,EAAA;EAET,mBAAA,CAAoB,QAAA,EAAU,QAAA,EAAU,mBAAA;EAExC,wBAAA,CAAyB,SAAA,UAAmB,KAAA,EAAO,aAAA;EAEnD,gBAAA;EAEA,oBAAA,CAAqB,OAAA,GAAU,4BAAA;EAE/B,qBAAA;EAEA,kBAAA,CAAmB,gBAAA,UAA0B,YAAA;EAjBjB;;;;;;;;;;AACS;AAGvC;;;EA6BE,sBAAA,EACE,SAAA,UACA,SAAA,UACA,KAAA,EAAO,aAAA,EACP,QAAA,EAAU,QAAA,GACT,MAAA;AAAA"}
import { blindCast } from "@prisma-next/utils/casts";
import { isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue } from "@prisma-next/contract/types";
import { ifDefined } from "@prisma-next/utils/defined";
//#region src/shared/framework-authoring.ts
function isAuthoringArgRef(value) {
if (typeof value !== "object" || value === null || value.kind !== "arg") return false;
const { index, path } = value;
if (typeof index !== "number" || !Number.isInteger(index) || index < 0) return false;
if (path !== void 0 && (!Array.isArray(path) || path.some((s) => typeof s !== "string"))) return false;
return true;
}
function isAuthoringTemplateRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function isAuthoringTypeConstructorDescriptor(value) {
return typeof value === "object" && value !== null && value.kind === "typeConstructor" && typeof value.output === "object" && value.output !== null;
}
function isAuthoringFieldPresetDescriptor(value) {
return typeof value === "object" && value !== null && value.kind === "fieldPreset" && typeof value.output === "object" && value.output !== null;
}
function isAuthoringEntityTypeDescriptor(value) {
if (typeof value !== "object" || value === null || value.kind !== "entity") return false;
const discriminator = value.discriminator;
if (typeof discriminator !== "string" || discriminator.length === 0) return false;
const output = value.output;
if (typeof output !== "object" || output === null) return false;
const factory = output.factory;
const template = output.template;
return typeof factory === "function" || template !== void 0;
}
function isAuthoringPslBlockDescriptor(value) {
if (typeof value !== "object" || value === null) return false;
const record = blindCast(value);
if (record["kind"] !== "pslBlock") return false;
const keyword = record["keyword"];
if (typeof keyword !== "string" || keyword.length === 0) return false;
const discriminator = record["discriminator"];
if (typeof discriminator !== "string" || discriminator.length === 0) return false;
const name = record["name"];
if (typeof name !== "object" || name === null) return false;
if (typeof blindCast(name)["required"] !== "boolean") return false;
const parameters = record["parameters"];
return typeof parameters === "object" && parameters !== null && !Array.isArray(parameters);
}
/**
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
*
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
* registration must NOT be treated as a "namespace" with sub-paths. Callers
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
*/
function hasRegisteredFieldNamespace(contributions, namespace) {
if (contributions?.field === void 0 || !Object.hasOwn(contributions.field, namespace)) return false;
return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);
}
function isPlainNamespaceObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
/**
* Merges `source` into `target` recursively at the descriptor-namespace
* level. `leafGuard` decides which values are descriptors (terminal
* merge points; same-path registrations across components are reported
* as duplicates) versus sub-namespaces (recursion targets).
*
* Path segments are validated against prototype-pollution names
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
* recognized leaf nor a plain object — e.g. a malformed descriptor
* where the canonical leaf guard rejected it for missing `output` —
* is reported as an invalid contribution rather than recursed into,
* which would either silently mangle state or infinite-loop on
* primitive properties.
*
* Within-registry duplicate detection is this walker's job;
* cross-registry detection runs separately via
* `assertNoCrossRegistryCollisions` after merging completes.
*/
function mergeAuthoringNamespaces(target, source, path, leafGuard, label) {
const assertSafePath = (currentPath) => {
const blockedSegment = currentPath.find((segment) => segment === "__proto__" || segment === "constructor" || segment === "prototype");
if (blockedSegment) throw new Error(`Invalid authoring ${label} helper "${currentPath.join(".")}". Helper path segments must not use "${blockedSegment}".`);
};
for (const [key, sourceValue] of Object.entries(source)) {
const currentPath = [...path, key];
assertSafePath(currentPath);
const hasExistingValue = Object.hasOwn(target, key);
const existingValue = hasExistingValue ? target[key] : void 0;
if (!hasExistingValue) {
target[key] = sourceValue;
continue;
}
const existingIsLeaf = leafGuard(existingValue);
const sourceIsLeaf = leafGuard(sourceValue);
if (existingIsLeaf || sourceIsLeaf) throw new Error(`Duplicate authoring ${label} helper "${currentPath.join(".")}". Helper names must be unique across composed packs.`);
if (!isPlainNamespaceObject(existingValue) || !isPlainNamespaceObject(sourceValue)) throw new Error(`Invalid authoring ${label} helper "${currentPath.join(".")}". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`);
mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, leafGuard, label);
}
}
function collectAuthoringLeafPaths(namespace, isLeaf, path = []) {
const paths = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isLeaf(value)) {
paths.push(currentPath.join("."));
continue;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) paths.push(...collectAuthoringLeafPaths(value, isLeaf, currentPath));
}
return paths;
}
function collectAuthoringLeafDiscriminators(namespace, isLeaf, label, path = []) {
const entries = [];
for (const [key, value] of Object.entries(namespace)) {
const currentPath = [...path, key];
if (isLeaf(value)) {
const discriminator = blindCast(value)["discriminator"];
if (typeof discriminator === "string" && discriminator.length > 0) entries.push({
path: currentPath.join("."),
discriminator
});
continue;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
const record = blindCast(value);
if ((record["kind"] !== void 0 || record["keyword"] !== void 0 || record["discriminator"] !== void 0) && !isLeaf(value)) {
const hasKind = record["kind"] === "pslBlock";
const hasKeyword = typeof record["keyword"] === "string";
const hasDiscriminator = typeof record["discriminator"] === "string";
if (hasKind || hasKeyword && hasDiscriminator) throw new Error(`Malformed authoring ${label} contribution at "${currentPath.join(".")}". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the ${label} descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`);
}
entries.push(...collectAuthoringLeafDiscriminators(record, isLeaf, label, currentPath));
}
}
return entries;
}
/**
* Throws when two or more entries in the same namespace share a discriminator.
* Duplicate discriminators within a namespace make dispatch ambiguous — the
* lowering factory lookup dispatches by discriminator, so one would silently
* shadow the other. Catch duplicates before building any dispatch map.
*/
function assertUniqueDiscriminators(entries, label) {
const seen = /* @__PURE__ */ new Map();
for (const { path, discriminator } of entries) {
const existing = seen.get(discriminator);
if (existing !== void 0) throw new Error(`Duplicate ${label} discriminator "${discriminator}" registered at both "${existing}" and "${path}". Each ${label} contribution must use a unique discriminator.`);
seen.set(discriminator, path);
}
}
/**
* Every `pslBlockDescriptors` entry needs a matching `entityTypes` factory
* (same discriminator): the parser would otherwise produce an AST node
* nothing can lower to an IR class instance. The link is one-directional
* — an `entityTypes` factory may stand alone (e.g. `enum`, reachable from
* the TypeScript builder without any PSL block).
*/
function assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace) {
const blockEntries = collectAuthoringLeafDiscriminators(pslBlockNamespace, isAuthoringPslBlockDescriptor, "pslBlock");
const entityEntries = collectAuthoringLeafDiscriminators(entityTypeNamespace, isAuthoringEntityTypeDescriptor, "entityType");
assertUniqueDiscriminators(blockEntries, "pslBlock");
assertUniqueDiscriminators(entityEntries, "entityType");
const entityDiscriminators = new Set(entityEntries.map((entry) => entry.discriminator));
for (const block of blockEntries) if (!entityDiscriminators.has(block.discriminator)) throw new Error(`Incomplete extension contribution: pslBlock helper "${block.path}" registers discriminator "${block.discriminator}" but no entityType contribution shares that discriminator. An extension-contributed PSL block requires a matching entityType factory so the parsed AST node can lower to an IR class instance; add an entityType helper with discriminator "${block.discriminator}".`);
}
function assertNoCrossRegistryCollisions(typeNamespace, fieldNamespace, entityTypeNamespace = {}, pslBlockNamespace = {}) {
const typePaths = new Set(collectAuthoringLeafPaths(typeNamespace, isAuthoringTypeConstructorDescriptor));
const fieldPaths = new Set(collectAuthoringLeafPaths(fieldNamespace, isAuthoringFieldPresetDescriptor));
const entityPaths = new Set(collectAuthoringLeafPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor));
const ambiguityHint = "Register each path in only one of authoringContributions.field / authoringContributions.type / authoringContributions.entityTypes.";
for (const fieldPath of fieldPaths) if (typePaths.has(fieldPath)) throw new Error(`Ambiguous authoring registry path "${fieldPath}". The same path is registered as both a type constructor and a field preset; PSL resolution would be ambiguous. ${ambiguityHint}`);
for (const entityPath of entityPaths) if (typePaths.has(entityPath) || fieldPaths.has(entityPath)) throw new Error(`Ambiguous authoring registry path "${entityPath}". The same path is registered as an entity contribution AND as a type constructor or field preset; PSL resolution would be ambiguous. ${ambiguityHint}`);
assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace);
}
function resolveAuthoringTemplateValue(template, args) {
if (isAuthoringArgRef(template)) {
let value = args[template.index];
for (const segment of template.path ?? []) {
if (!isAuthoringTemplateRecord(value) || !Object.hasOwn(value, segment)) {
value = void 0;
break;
}
value = value[segment];
}
if (value === void 0 && template.default !== void 0) return resolveAuthoringTemplateValue(template.default, args);
return value;
}
if (Array.isArray(template)) return template.map((value) => resolveAuthoringTemplateValue(value, args));
if (typeof template === "object" && template !== null) {
const resolved = {};
for (const [key, value] of Object.entries(template)) {
const resolvedValue = resolveAuthoringTemplateValue(value, args);
if (resolvedValue !== void 0) resolved[key] = resolvedValue;
}
return resolved;
}
return template;
}
function validateAuthoringArgument(descriptor, value, path) {
if (value === void 0) {
if (descriptor.optional) return;
throw new Error(`Missing required authoring helper argument at ${path}`);
}
if (descriptor.kind === "string") {
if (typeof value !== "string") throw new Error(`Authoring helper argument at ${path} must be a string`);
return;
}
if (descriptor.kind === "boolean") {
if (typeof value !== "boolean") throw new Error(`Authoring helper argument at ${path} must be a boolean`);
return;
}
if (descriptor.kind === "stringArray") {
if (!Array.isArray(value)) throw new Error(`Authoring helper argument at ${path} must be an array of strings`);
for (const entry of value) if (typeof entry !== "string") throw new Error(`Authoring helper argument at ${path} must be an array of strings`);
return;
}
if (descriptor.kind === "object") {
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`Authoring helper argument at ${path} must be an object`);
const input = value;
const expectedKeys = new Set(Object.keys(descriptor.properties));
for (const key of Object.keys(input)) if (!expectedKeys.has(key)) throw new Error(`Authoring helper argument at ${path} contains unknown property "${key}"`);
for (const [key, propertyDescriptor] of Object.entries(descriptor.properties)) validateAuthoringArgument(propertyDescriptor, input[key], `${path}.${key}`);
return;
}
if (typeof value !== "number" || Number.isNaN(value)) throw new Error(`Authoring helper argument at ${path} must be a number`);
if (descriptor.integer && !Number.isInteger(value)) throw new Error(`Authoring helper argument at ${path} must be an integer`);
if (descriptor.minimum !== void 0 && value < descriptor.minimum) throw new Error(`Authoring helper argument at ${path} must be >= ${descriptor.minimum}, received ${value}`);
if (descriptor.maximum !== void 0 && value > descriptor.maximum) throw new Error(`Authoring helper argument at ${path} must be <= ${descriptor.maximum}, received ${value}`);
}
function validateAuthoringHelperArguments(helperPath, descriptors, args) {
const expected = descriptors ?? [];
const minimumArgs = expected.reduce((count, descriptor, index) => descriptor.optional ? count : index + 1, 0);
if (args.length < minimumArgs || args.length > expected.length) throw new Error(`${helperPath} expects ${minimumArgs === expected.length ? expected.length : `${minimumArgs}-${expected.length}`} argument(s), received ${args.length}`);
expected.forEach((descriptor, index) => {
validateAuthoringArgument(descriptor, args[index], `${helperPath}[${index}]`);
});
}
function resolveAuthoringStorageTypeTemplate(template, args) {
const nativeType = resolveAuthoringTemplateValue(template.nativeType, args);
if (typeof nativeType !== "string") throw new Error(`Resolved authoring nativeType must be a string for codec "${template.codecId}", received ${String(nativeType)}`);
const typeParams = template.typeParams === void 0 ? void 0 : resolveAuthoringTemplateValue(template.typeParams, args);
if (typeParams !== void 0 && !isAuthoringTemplateRecord(typeParams)) throw new Error(`Resolved authoring typeParams must be an object for codec "${template.codecId}", received ${String(typeParams)}`);
return {
codecId: template.codecId,
nativeType,
...typeParams === void 0 ? {} : { typeParams }
};
}
function resolveAuthoringColumnDefaultTemplate(template, args) {
if (template.kind === "literal") {
const value = resolveAuthoringTemplateValue(template.value, args);
if (value === void 0) throw new Error("Resolved authoring literal default must not be undefined");
if (!isColumnDefaultLiteralInputValue(value)) throw new Error(`Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`);
return {
kind: "literal",
value
};
}
const expression = resolveAuthoringTemplateValue(template.expression, args);
if (expression === void 0 || typeof expression === "object" && expression !== null) throw new Error(`Resolved authoring function default expression must resolve to a primitive, received ${String(expression)}`);
return {
kind: "function",
expression: String(expression)
};
}
function resolveExecutionMutationDefaultPhase(phase, template, args) {
const value = resolveAuthoringTemplateValue(template, args);
if (!isExecutionMutationDefaultValue(value)) throw new Error(`Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`);
return value;
}
function resolveAuthoringExecutionDefaultsTemplate(template, args) {
return {
...ifDefined("onCreate", template.onCreate !== void 0 ? resolveExecutionMutationDefaultPhase("onCreate", template.onCreate, args) : void 0),
...ifDefined("onUpdate", template.onUpdate !== void 0 ? resolveExecutionMutationDefaultPhase("onUpdate", template.onUpdate, args) : void 0)
};
}
function instantiateAuthoringTypeConstructor(descriptor, args) {
return resolveAuthoringStorageTypeTemplate(descriptor.output, args);
}
function instantiateAuthoringEntityType(helperPath, descriptor, args, ctx) {
if ("factory" in descriptor.output) {
const input = args[0];
const factory = descriptor.output.factory;
return factory(input, ctx);
}
validateAuthoringHelperArguments(helperPath, descriptor.args, args);
return resolveAuthoringTemplateValue(descriptor.output.template, args);
}
function instantiateAuthoringFieldPreset(descriptor, args) {
return {
descriptor: resolveAuthoringStorageTypeTemplate(descriptor.output, args),
nullable: descriptor.output.nullable ?? false,
...ifDefined("default", descriptor.output.default !== void 0 ? resolveAuthoringColumnDefaultTemplate(descriptor.output.default, args) : void 0),
...ifDefined("executionDefaults", descriptor.output.executionDefaults !== void 0 ? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args) : void 0),
id: descriptor.output.id ?? false,
unique: descriptor.output.unique ?? false
};
}
//#endregion
export { instantiateAuthoringTypeConstructor as a, isAuthoringFieldPresetDescriptor as c, mergeAuthoringNamespaces as d, resolveAuthoringTemplateValue as f, instantiateAuthoringFieldPreset as i, isAuthoringPslBlockDescriptor as l, hasRegisteredFieldNamespace as n, isAuthoringArgRef as o, validateAuthoringHelperArguments as p, instantiateAuthoringEntityType as r, isAuthoringEntityTypeDescriptor as s, assertNoCrossRegistryCollisions as t, isAuthoringTypeConstructorDescriptor as u };
//# sourceMappingURL=framework-authoring-CnwPJCO4.mjs.map
{"version":3,"file":"framework-authoring-CnwPJCO4.mjs","names":[],"sources":["../src/shared/framework-authoring.ts"],"sourcesContent":["import type {\n ColumnDefault,\n ExecutionMutationDefaultPhases,\n ExecutionMutationDefaultValue,\n} from '@prisma-next/contract/types';\nimport {\n isColumnDefaultLiteralInputValue,\n isExecutionMutationDefaultValue,\n} from '@prisma-next/contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Type } from 'arktype';\nimport type { PslBlockParam } from './psl-extension-block';\n\nexport type AuthoringArgRef = {\n readonly kind: 'arg';\n readonly index: number;\n readonly path?: readonly string[];\n readonly default?: AuthoringTemplateValue;\n};\n\nexport type AuthoringTemplateValue =\n | string\n | number\n | boolean\n | null\n | AuthoringArgRef\n | readonly AuthoringTemplateValue[]\n | { readonly [key: string]: AuthoringTemplateValue };\n\ninterface AuthoringArgumentDescriptorCommon {\n readonly name?: string;\n readonly optional?: boolean;\n}\n\nexport type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon &\n (\n | { readonly kind: 'string' }\n | { readonly kind: 'boolean' }\n | {\n readonly kind: 'number';\n readonly integer?: boolean;\n readonly minimum?: number;\n readonly maximum?: number;\n }\n | { readonly kind: 'stringArray' }\n | {\n readonly kind: 'object';\n readonly properties: Record<string, AuthoringArgumentDescriptor>;\n }\n );\n\nexport interface AuthoringStorageTypeTemplate {\n readonly codecId: string;\n readonly nativeType: AuthoringTemplateValue;\n readonly typeParams?: Record<string, AuthoringTemplateValue>;\n}\n\nexport interface AuthoringTypeConstructorDescriptor {\n readonly kind: 'typeConstructor';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringStorageTypeTemplate;\n}\n\nexport interface AuthoringColumnDefaultTemplateLiteral {\n readonly kind: 'literal';\n readonly value: AuthoringTemplateValue;\n}\n\nexport interface AuthoringColumnDefaultTemplateFunction {\n readonly kind: 'function';\n readonly expression: AuthoringTemplateValue;\n}\n\nexport type AuthoringColumnDefaultTemplate =\n | AuthoringColumnDefaultTemplateLiteral\n | AuthoringColumnDefaultTemplateFunction;\n\nexport interface AuthoringExecutionDefaultsTemplate {\n readonly onCreate?: AuthoringTemplateValue;\n readonly onUpdate?: AuthoringTemplateValue;\n}\n\nexport interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {\n readonly nullable?: boolean;\n readonly default?: AuthoringColumnDefaultTemplate;\n readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;\n readonly id?: boolean;\n readonly unique?: boolean;\n}\n\nexport interface AuthoringFieldPresetDescriptor {\n readonly kind: 'fieldPreset';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringFieldPresetOutput;\n}\n\nexport type AuthoringTypeNamespace = {\n readonly [name: string]: AuthoringTypeConstructorDescriptor | AuthoringTypeNamespace;\n};\n\nexport type AuthoringFieldNamespace = {\n readonly [name: string]: AuthoringFieldPresetDescriptor | AuthoringFieldNamespace;\n};\n\n/**\n * Context surfaced to entity-type factories at call time. Currently a\n * placeholder — sharpened as concrete consumers (enum, namespace, …)\n * discover what the factory actually needs to read (codec lookup,\n * namespace registry, …).\n */\nexport interface AuthoringEntityContext {\n readonly family: string;\n readonly target: string;\n}\n\nexport interface AuthoringEntityTypeTemplateOutput {\n readonly template: AuthoringTemplateValue;\n}\n\n/**\n * Default `Input = never` is load-bearing for pack-bag-driven type\n * narrowing. Factory parameter positions are contravariant, so a pack\n * literal declaring `factory: (input: DemoEntityInput) => DemoEntity`\n * is only assignable to the base descriptor's factory shape if the\n * base's input is `never` (the bottom of the contravariant position).\n * The concrete input/output types are recovered at the helper-derivation\n * site via `EntityHelperFunction<Descriptor>`'s conditional inference,\n * which reads them from the pack's `as const` literal factory signature\n * — the base widening does not erase the literal because `satisfies`\n * does not widen the declared type.\n */\nexport interface AuthoringEntityTypeFactoryOutput<Input = never, Output = unknown> {\n readonly factory: (input: Input, ctx: AuthoringEntityContext) => Output;\n}\n\nexport interface AuthoringEntityTypeDescriptor<Input = never, Output = unknown> {\n readonly kind: 'entity';\n readonly discriminator: string;\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output:\n | AuthoringEntityTypeTemplateOutput\n | AuthoringEntityTypeFactoryOutput<Input, Output>;\n /**\n * arktype schema fragment for one entry whose envelope `kind` matches\n * this descriptor's {@link discriminator}. The family validator composes\n * contributed fragments into the per-namespace entry schema at\n * validator construction time so the structural check covers\n * pack-introduced kinds without the family core hard-coding the schema.\n *\n * Hydration uses {@link AuthoringEntityTypeFactoryOutput.factory}\n * directly — the wire shape conforms structurally to the factory's\n * `Input` after `validatorSchema` validates it.\n */\n readonly validatorSchema?: Type<unknown>;\n}\n\nexport type AuthoringEntityTypeNamespace = {\n readonly [name: string]: AuthoringEntityTypeDescriptor | AuthoringEntityTypeNamespace;\n};\n\n/**\n * Declarative descriptor for an extension-contributed top-level PSL block.\n *\n * An extension registers one of these per keyword it contributes. The\n * framework owns the generic parser, validator, and printer — no\n * parsing or printing code runs from the extension.\n *\n * - `keyword` is the PSL top-level identifier this descriptor claims\n * (`policy_select`, `role`, …).\n * - `discriminator` is the routing key used by the printer dispatch and\n * the `entityTypes` lowering factory lookup. Convention:\n * `<target-or-family>-<kind>` (`postgres-policy-select`).\n * - `name.required` declares whether the block must have a name token\n * after the keyword. Currently always `true` — anonymous blocks are\n * not part of the closed-grammar premise — but the field is explicit\n * so the type can evolve without a breaking change.\n * - `parameters` maps parameter names to their value-kind descriptors\n * (`ref` / `value` / `option` / `list`). The generic parser and\n * validator interpret these; the extension supplies no parser or\n * printer function.\n */\nexport interface AuthoringPslBlockDescriptor {\n readonly kind: 'pslBlock';\n readonly keyword: string;\n readonly discriminator: string;\n readonly name: { readonly required: boolean };\n readonly parameters: Record<string, PslBlockParam>;\n}\n\nexport type AuthoringPslBlockDescriptorNamespace = {\n readonly [name: string]: AuthoringPslBlockDescriptor | AuthoringPslBlockDescriptorNamespace;\n};\n\nexport interface AuthoringContributions {\n readonly type?: AuthoringTypeNamespace;\n readonly field?: AuthoringFieldNamespace;\n readonly entityTypes?: AuthoringEntityTypeNamespace;\n /**\n * Registry of declarative block descriptors this contribution registers,\n * keyed by arbitrary path segments. Each leaf is an\n * {@link AuthoringPslBlockDescriptor} that claims a PSL top-level keyword.\n * The framework owns the generic parser, validator, and printer; the\n * contribution supplies only these declarative descriptors.\n *\n * Contrast with the parsed block nodes themselves, which live in a\n * namespace's `entries` under their discriminator key; this field holds the\n * registry of descriptors that teach the parser how to read those blocks.\n */\n readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport function isAuthoringArgRef(value: unknown): value is AuthoringArgRef {\n if (typeof value !== 'object' || value === null || (value as { kind?: unknown }).kind !== 'arg') {\n return false;\n }\n const { index, path } = value as { index?: unknown; path?: unknown };\n if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) {\n return false;\n }\n if (path !== undefined && (!Array.isArray(path) || path.some((s) => typeof s !== 'string'))) {\n return false;\n }\n return true;\n}\n\nfunction isAuthoringTemplateRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isAuthoringTypeConstructorDescriptor(\n value: unknown,\n): value is AuthoringTypeConstructorDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'typeConstructor' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function isAuthoringFieldPresetDescriptor(\n value: unknown,\n): value is AuthoringFieldPresetDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'fieldPreset' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function isAuthoringEntityTypeDescriptor(\n value: unknown,\n): value is AuthoringEntityTypeDescriptor {\n if (\n typeof value !== 'object' ||\n value === null ||\n (value as { kind?: unknown }).kind !== 'entity'\n ) {\n return false;\n }\n const discriminator = (value as { discriminator?: unknown }).discriminator;\n if (typeof discriminator !== 'string' || discriminator.length === 0) {\n return false;\n }\n const output = (value as { output?: unknown }).output;\n if (typeof output !== 'object' || output === null) {\n return false;\n }\n const factory = (output as { factory?: unknown }).factory;\n const template = (output as { template?: unknown }).template;\n return typeof factory === 'function' || template !== undefined;\n}\n\nexport function isAuthoringPslBlockDescriptor(\n value: unknown,\n): value is AuthoringPslBlockDescriptor {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const record = blindCast<\n Record<string, unknown>,\n 'type-guard probing an unknown candidate-descriptor object for known property names'\n >(value);\n if (record['kind'] !== 'pslBlock') {\n return false;\n }\n const keyword = record['keyword'];\n if (typeof keyword !== 'string' || keyword.length === 0) {\n return false;\n }\n const discriminator = record['discriminator'];\n if (typeof discriminator !== 'string' || discriminator.length === 0) {\n return false;\n }\n const name = record['name'];\n if (typeof name !== 'object' || name === null) {\n return false;\n }\n const nameRecord = blindCast<\n Record<string, unknown>,\n 'type-guard probing the name property of a candidate pslBlock descriptor'\n >(name);\n if (typeof nameRecord['required'] !== 'boolean') {\n return false;\n }\n const parameters = record['parameters'];\n return typeof parameters === 'object' && parameters !== null && !Array.isArray(parameters);\n}\n\n/**\n * Returns true when `namespace` is a non-leaf key in `contributions.field`.\n *\n * `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including\n * the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`\n * registration must NOT be treated as a \"namespace\" with sub-paths. Callers\n * use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).\n */\nexport function hasRegisteredFieldNamespace(\n contributions: AuthoringContributions | undefined,\n namespace: string,\n): boolean {\n if (contributions?.field === undefined || !Object.hasOwn(contributions.field, namespace)) {\n return false;\n }\n return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);\n}\n\nfunction isPlainNamespaceObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Merges `source` into `target` recursively at the descriptor-namespace\n * level. `leafGuard` decides which values are descriptors (terminal\n * merge points; same-path registrations across components are reported\n * as duplicates) versus sub-namespaces (recursion targets).\n *\n * Path segments are validated against prototype-pollution names\n * (`__proto__`, `constructor`, `prototype`). A value that is neither a\n * recognized leaf nor a plain object — e.g. a malformed descriptor\n * where the canonical leaf guard rejected it for missing `output` —\n * is reported as an invalid contribution rather than recursed into,\n * which would either silently mangle state or infinite-loop on\n * primitive properties.\n *\n * Within-registry duplicate detection is this walker's job;\n * cross-registry detection runs separately via\n * `assertNoCrossRegistryCollisions` after merging completes.\n */\nexport function mergeAuthoringNamespaces(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n path: readonly string[],\n leafGuard: (value: unknown) => boolean,\n label: string,\n): void {\n const assertSafePath = (currentPath: readonly string[]) => {\n const blockedSegment = currentPath.find(\n (segment) => segment === '__proto__' || segment === 'constructor' || segment === 'prototype',\n );\n if (blockedSegment) {\n throw new Error(\n `Invalid authoring ${label} helper \"${currentPath.join('.')}\". Helper path segments must not use \"${blockedSegment}\".`,\n );\n }\n };\n\n for (const [key, sourceValue] of Object.entries(source)) {\n const currentPath = [...path, key];\n assertSafePath(currentPath);\n const hasExistingValue = Object.hasOwn(target, key);\n const existingValue = hasExistingValue ? target[key] : undefined;\n\n if (!hasExistingValue) {\n target[key] = sourceValue;\n continue;\n }\n\n const existingIsLeaf = leafGuard(existingValue);\n const sourceIsLeaf = leafGuard(sourceValue);\n\n if (existingIsLeaf || sourceIsLeaf) {\n throw new Error(\n `Duplicate authoring ${label} helper \"${currentPath.join('.')}\". Helper names must be unique across composed packs.`,\n );\n }\n\n if (!isPlainNamespaceObject(existingValue) || !isPlainNamespaceObject(sourceValue)) {\n throw new Error(\n `Invalid authoring ${label} helper \"${currentPath.join('.')}\". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`,\n );\n }\n\n mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, leafGuard, label);\n }\n}\n\nfunction collectAuthoringLeafPaths(\n namespace: Readonly<Record<string, unknown>>,\n isLeaf: (value: unknown) => boolean,\n path: readonly string[] = [],\n): string[] {\n const paths: string[] = [];\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeaf(value)) {\n paths.push(currentPath.join('.'));\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n paths.push(\n ...collectAuthoringLeafPaths(\n value as Readonly<Record<string, unknown>>,\n isLeaf,\n currentPath,\n ),\n );\n }\n }\n return paths;\n}\n\ninterface AuthoringLeafEntry {\n readonly path: string;\n readonly discriminator: string;\n}\n\nfunction collectAuthoringLeafDiscriminators(\n namespace: Readonly<Record<string, unknown>>,\n isLeaf: (value: unknown) => boolean,\n label: string,\n path: readonly string[] = [],\n): AuthoringLeafEntry[] {\n const entries: AuthoringLeafEntry[] = [];\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeaf(value)) {\n const record = blindCast<\n Record<string, unknown>,\n 'discriminator extraction from a leaf already validated by isLeaf'\n >(value);\n const discriminator = record['discriminator'];\n if (typeof discriminator === 'string' && discriminator.length > 0) {\n entries.push({ path: currentPath.join('.'), discriminator });\n }\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n const record = blindCast<\n Readonly<Record<string, unknown>>,\n 'walker inspects a non-leaf value for descriptor-shaped keys before recursing'\n >(value);\n // A value carrying descriptor-shaped keys (`kind`/`keyword`/`discriminator`)\n // but failing `isAuthoringPslBlockDescriptor` (e.g. missing `parameters`) is\n // a malformed declarative descriptor. Descending into it as a sub-namespace\n // would silently skip it, so a half-built contribution would pass validation.\n // Reject it at load time instead, naming the path and what's wrong.\n //\n // A valid sub-namespace whose key happens to be named `kind`, `keyword`, or\n // `discriminator` (but which does not look like a descriptor overall) must\n // still descend normally — the check requires descriptor-shaped keys present\n // AND the leaf guard rejecting it.\n if (\n (record['kind'] !== undefined ||\n record['keyword'] !== undefined ||\n record['discriminator'] !== undefined) &&\n !isLeaf(value)\n ) {\n const hasKind = record['kind'] === 'pslBlock';\n const hasKeyword = typeof record['keyword'] === 'string';\n const hasDiscriminator = typeof record['discriminator'] === 'string';\n if (hasKind || (hasKeyword && hasDiscriminator)) {\n throw new Error(\n `Malformed authoring ${label} contribution at \"${currentPath.join('.')}\". The value carries descriptor keys (kind/keyword/discriminator) but does not satisfy the ${label} descriptor shape. Fix the contribution so it is a complete descriptor, or remove the stray keys if it was meant to be a sub-namespace.`,\n );\n }\n }\n entries.push(...collectAuthoringLeafDiscriminators(record, isLeaf, label, currentPath));\n }\n }\n return entries;\n}\n\n/**\n * Throws when two or more entries in the same namespace share a discriminator.\n * Duplicate discriminators within a namespace make dispatch ambiguous — the\n * lowering factory lookup dispatches by discriminator, so one would silently\n * shadow the other. Catch duplicates before building any dispatch map.\n */\nfunction assertUniqueDiscriminators(entries: readonly AuthoringLeafEntry[], label: string): void {\n const seen = new Map<string, string>();\n for (const { path, discriminator } of entries) {\n const existing = seen.get(discriminator);\n if (existing !== undefined) {\n throw new Error(\n `Duplicate ${label} discriminator \"${discriminator}\" registered at both \"${existing}\" and \"${path}\". Each ${label} contribution must use a unique discriminator.`,\n );\n }\n seen.set(discriminator, path);\n }\n}\n\n/**\n * Every `pslBlockDescriptors` entry needs a matching `entityTypes` factory\n * (same discriminator): the parser would otherwise produce an AST node\n * nothing can lower to an IR class instance. The link is one-directional\n * — an `entityTypes` factory may stand alone (e.g. `enum`, reachable from\n * the TypeScript builder without any PSL block).\n */\nfunction assertPslBlocksHaveFactories(\n entityTypeNamespace: AuthoringEntityTypeNamespace,\n pslBlockNamespace: AuthoringPslBlockDescriptorNamespace,\n): void {\n const blockEntries = collectAuthoringLeafDiscriminators(\n pslBlockNamespace,\n isAuthoringPslBlockDescriptor,\n 'pslBlock',\n );\n const entityEntries = collectAuthoringLeafDiscriminators(\n entityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n 'entityType',\n );\n\n assertUniqueDiscriminators(blockEntries, 'pslBlock');\n assertUniqueDiscriminators(entityEntries, 'entityType');\n\n const entityDiscriminators = new Set(entityEntries.map((entry) => entry.discriminator));\n\n for (const block of blockEntries) {\n if (!entityDiscriminators.has(block.discriminator)) {\n throw new Error(\n `Incomplete extension contribution: pslBlock helper \"${block.path}\" registers discriminator \"${block.discriminator}\" but no entityType contribution shares that discriminator. An extension-contributed PSL block requires a matching entityType factory so the parsed AST node can lower to an IR class instance; add an entityType helper with discriminator \"${block.discriminator}\".`,\n );\n }\n }\n}\n\nexport function assertNoCrossRegistryCollisions(\n typeNamespace: AuthoringTypeNamespace,\n fieldNamespace: AuthoringFieldNamespace,\n entityTypeNamespace: AuthoringEntityTypeNamespace = {},\n pslBlockNamespace: AuthoringPslBlockDescriptorNamespace = {},\n): void {\n const typePaths = new Set(\n collectAuthoringLeafPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),\n );\n const fieldPaths = new Set(\n collectAuthoringLeafPaths(fieldNamespace, isAuthoringFieldPresetDescriptor),\n );\n const entityPaths = new Set(\n collectAuthoringLeafPaths(entityTypeNamespace, isAuthoringEntityTypeDescriptor),\n );\n // Within-registry duplicate detection is handled upstream by the merge\n // walker (`mergeAuthoringNamespaces` in control-stack.ts and\n // `mergeHelperNamespaces` in composed-authoring-helpers.ts), which throws\n // on same-path registrations within any single registry before this check\n // runs. This function only handles the cross-registry case.\n //\n // Cross-registry collisions are checked among `type` / `field` /\n // `entityTypes` only — these three are user-facing helper paths that PSL\n // must resolve unambiguously. `pslBlockDescriptors` is an internal\n // framework index consumed by parser and printer dispatch, not a\n // user-facing helper path; the natural authoring pattern is the same\n // path key in `entityTypes` and `pslBlockDescriptors` for a single\n // contribution. The block→factory link is enforced by\n // `assertPslBlocksHaveFactories` via the discriminator string, not by path.\n const ambiguityHint =\n 'Register each path in only one of authoringContributions.field / authoringContributions.type / authoringContributions.entityTypes.';\n for (const fieldPath of fieldPaths) {\n if (typePaths.has(fieldPath)) {\n throw new Error(\n `Ambiguous authoring registry path \"${fieldPath}\". The same path is registered as both a type constructor and a field preset; PSL resolution would be ambiguous. ${ambiguityHint}`,\n );\n }\n }\n for (const entityPath of entityPaths) {\n if (typePaths.has(entityPath) || fieldPaths.has(entityPath)) {\n throw new Error(\n `Ambiguous authoring registry path \"${entityPath}\". The same path is registered as an entity contribution AND as a type constructor or field preset; PSL resolution would be ambiguous. ${ambiguityHint}`,\n );\n }\n }\n\n assertPslBlocksHaveFactories(entityTypeNamespace, pslBlockNamespace);\n}\n\nexport function resolveAuthoringTemplateValue(\n template: AuthoringTemplateValue,\n args: readonly unknown[],\n): unknown {\n if (isAuthoringArgRef(template)) {\n let value = args[template.index];\n\n for (const segment of template.path ?? []) {\n if (!isAuthoringTemplateRecord(value) || !Object.hasOwn(value, segment)) {\n value = undefined;\n break;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n\n if (value === undefined && template.default !== undefined) {\n return resolveAuthoringTemplateValue(template.default, args);\n }\n\n return value;\n }\n if (Array.isArray(template)) {\n return template.map((value) => resolveAuthoringTemplateValue(value, args));\n }\n if (typeof template === 'object' && template !== null) {\n const resolved: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(template)) {\n const resolvedValue = resolveAuthoringTemplateValue(value, args);\n if (resolvedValue !== undefined) {\n resolved[key] = resolvedValue;\n }\n }\n return resolved;\n }\n return template;\n}\n\nfunction validateAuthoringArgument(\n descriptor: AuthoringArgumentDescriptor,\n value: unknown,\n path: string,\n): void {\n if (value === undefined) {\n if (descriptor.optional) {\n return;\n }\n throw new Error(`Missing required authoring helper argument at ${path}`);\n }\n\n if (descriptor.kind === 'string') {\n if (typeof value !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be a string`);\n }\n return;\n }\n\n if (descriptor.kind === 'boolean') {\n if (typeof value !== 'boolean') {\n throw new Error(`Authoring helper argument at ${path} must be a boolean`);\n }\n return;\n }\n\n if (descriptor.kind === 'stringArray') {\n if (!Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n for (const entry of value) {\n if (typeof entry !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n }\n return;\n }\n\n if (descriptor.kind === 'object') {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an object`);\n }\n\n const input = value as Record<string, unknown>;\n const expectedKeys = new Set(Object.keys(descriptor.properties));\n\n for (const key of Object.keys(input)) {\n if (!expectedKeys.has(key)) {\n throw new Error(`Authoring helper argument at ${path} contains unknown property \"${key}\"`);\n }\n }\n\n for (const [key, propertyDescriptor] of Object.entries(descriptor.properties)) {\n validateAuthoringArgument(propertyDescriptor, input[key], `${path}.${key}`);\n }\n\n return;\n }\n\n if (typeof value !== 'number' || Number.isNaN(value)) {\n throw new Error(`Authoring helper argument at ${path} must be a number`);\n }\n\n if (descriptor.integer && !Number.isInteger(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an integer`);\n }\n if (descriptor.minimum !== undefined && value < descriptor.minimum) {\n throw new Error(\n `Authoring helper argument at ${path} must be >= ${descriptor.minimum}, received ${value}`,\n );\n }\n if (descriptor.maximum !== undefined && value > descriptor.maximum) {\n throw new Error(\n `Authoring helper argument at ${path} must be <= ${descriptor.maximum}, received ${value}`,\n );\n }\n}\n\nexport function validateAuthoringHelperArguments(\n helperPath: string,\n descriptors: readonly AuthoringArgumentDescriptor[] | undefined,\n args: readonly unknown[],\n): void {\n const expected = descriptors ?? [];\n const minimumArgs = expected.reduce(\n (count, descriptor, index) => (descriptor.optional ? count : index + 1),\n 0,\n );\n if (args.length < minimumArgs || args.length > expected.length) {\n throw new Error(\n `${helperPath} expects ${minimumArgs === expected.length ? expected.length : `${minimumArgs}-${expected.length}`} argument(s), received ${args.length}`,\n );\n }\n\n expected.forEach((descriptor, index) => {\n validateAuthoringArgument(descriptor, args[index], `${helperPath}[${index}]`);\n });\n}\n\nfunction resolveAuthoringStorageTypeTemplate(\n template: AuthoringStorageTypeTemplate,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n const nativeType = resolveAuthoringTemplateValue(template.nativeType, args);\n if (typeof nativeType !== 'string') {\n throw new Error(\n `Resolved authoring nativeType must be a string for codec \"${template.codecId}\", received ${String(nativeType)}`,\n );\n }\n const typeParams =\n template.typeParams === undefined\n ? undefined\n : resolveAuthoringTemplateValue(template.typeParams, args);\n if (typeParams !== undefined && !isAuthoringTemplateRecord(typeParams)) {\n throw new Error(\n `Resolved authoring typeParams must be an object for codec \"${template.codecId}\", received ${String(typeParams)}`,\n );\n }\n\n return {\n codecId: template.codecId,\n nativeType,\n ...(typeParams === undefined ? {} : { typeParams }),\n };\n}\n\nfunction resolveAuthoringColumnDefaultTemplate(\n template: AuthoringColumnDefaultTemplate,\n args: readonly unknown[],\n): ColumnDefault {\n if (template.kind === 'literal') {\n const value = resolveAuthoringTemplateValue(template.value, args);\n if (value === undefined) {\n throw new Error('Resolved authoring literal default must not be undefined');\n }\n if (!isColumnDefaultLiteralInputValue(value)) {\n throw new Error(\n `Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`,\n );\n }\n return {\n kind: 'literal',\n value,\n };\n }\n\n const expression = resolveAuthoringTemplateValue(template.expression, args);\n if (expression === undefined || (typeof expression === 'object' && expression !== null)) {\n throw new Error(\n `Resolved authoring function default expression must resolve to a primitive, received ${String(expression)}`,\n );\n }\n return {\n kind: 'function',\n expression: String(expression),\n };\n}\n\nfunction resolveExecutionMutationDefaultPhase(\n phase: 'onCreate' | 'onUpdate',\n template: AuthoringTemplateValue,\n args: readonly unknown[],\n): ExecutionMutationDefaultValue {\n const value = resolveAuthoringTemplateValue(template, args);\n if (!isExecutionMutationDefaultValue(value)) {\n throw new Error(\n `Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`,\n );\n }\n return value;\n}\n\nfunction resolveAuthoringExecutionDefaultsTemplate(\n template: AuthoringExecutionDefaultsTemplate,\n args: readonly unknown[],\n): ExecutionMutationDefaultPhases {\n return {\n ...ifDefined(\n 'onCreate',\n template.onCreate !== undefined\n ? resolveExecutionMutationDefaultPhase('onCreate', template.onCreate, args)\n : undefined,\n ),\n ...ifDefined(\n 'onUpdate',\n template.onUpdate !== undefined\n ? resolveExecutionMutationDefaultPhase('onUpdate', template.onUpdate, args)\n : undefined,\n ),\n };\n}\n\nexport function instantiateAuthoringTypeConstructor(\n descriptor: AuthoringTypeConstructorDescriptor,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n return resolveAuthoringStorageTypeTemplate(descriptor.output, args);\n}\n\nexport function instantiateAuthoringEntityType(\n helperPath: string,\n descriptor: AuthoringEntityTypeDescriptor,\n args: readonly unknown[],\n ctx: AuthoringEntityContext,\n): unknown {\n // Factory-output entities carry their input contract on the factory\n // signature itself — TypeScript narrows callers via\n // `EntityHelperFunction`'s extracted `input` parameter, and the factory\n // is free to do its own runtime validation (e.g. arktype Type). The\n // descriptor-level `args` validator is reserved for template-output\n // entities (which mirror field/type's declarative argument shape).\n if ('factory' in descriptor.output) {\n const input = args[0];\n // The base `AuthoringEntityTypeDescriptor`'s factory is typed\n // `(input: never, ctx) => unknown` so concrete pack-literal factories\n // with narrower input types remain assignable through the\n // contravariant position (see the type's docstring). The runtime\n // delegates input validation to the pack's factory itself, so we\n // forward the supplied input here without a static input contract.\n const factory = descriptor.output.factory as (\n input: unknown,\n ctx: AuthoringEntityContext,\n ) => unknown;\n return factory(input, ctx);\n }\n validateAuthoringHelperArguments(helperPath, descriptor.args, args);\n return resolveAuthoringTemplateValue(descriptor.output.template, args);\n}\n\nexport function instantiateAuthoringFieldPreset(\n descriptor: AuthoringFieldPresetDescriptor,\n args: readonly unknown[],\n): {\n readonly descriptor: {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n };\n readonly nullable: boolean;\n readonly default?: ColumnDefault;\n readonly executionDefaults?: ExecutionMutationDefaultPhases;\n readonly id: boolean;\n readonly unique: boolean;\n} {\n return {\n descriptor: resolveAuthoringStorageTypeTemplate(descriptor.output, args),\n nullable: descriptor.output.nullable ?? false,\n ...ifDefined(\n 'default',\n descriptor.output.default !== undefined\n ? resolveAuthoringColumnDefaultTemplate(descriptor.output.default, args)\n : undefined,\n ),\n ...ifDefined(\n 'executionDefaults',\n descriptor.output.executionDefaults !== undefined\n ? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args)\n : undefined,\n ),\n id: descriptor.output.id ?? false,\n unique: descriptor.output.unique ?? false,\n };\n}\n"],"mappings":";;;;AAoNA,SAAgB,kBAAkB,OAA0C;CAC1E,IAA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IAAI,IACrE,KAAA,CACN;EACA,GAAG,UACD,qBACA,WAAW,OAAO,sBAAsB,KAAA,IACpC,0CAA0C,WAAW,OAAO,mBAAmB,IAAI,IACnF,KAAA,CACN;EACA,IAAI,WAAW,OAAO,MAAM;EAC5B,QAAQ,WAAW,OAAO,UAAU;CACtC;AACF"}
import { ColumnDefault, ExecutionMutationDefaultPhases } from "@prisma-next/contract/types";
import { Type } from "arktype";
//#region src/shared/psl-extension-block.d.ts
/**
* Shape-only types for the PSL source-position primitives, diagnostic
* codes, extension-block descriptor vocabulary, and the uniform
* extension-block AST node base.
*
* These live in the shared plane so an extension's authoring descriptor
* (`AuthoringPslBlockDescriptor` in `framework-authoring`) can reference
* them without crossing the shared → migration-plane boundary. The
* migration-plane `psl-ast.ts` re-exports everything here for consumers
* that import PSL AST types from the control entrypoint.
*/
interface PslPosition {
readonly offset: number;
readonly line: number;
readonly column: number;
}
interface PslSpan {
readonly start: PslPosition;
readonly end: PslPosition;
}
type PslDiagnosticCode = 'PSL_UNTERMINATED_BLOCK' | 'PSL_UNSUPPORTED_TOP_LEVEL_BLOCK' | 'PSL_INVALID_NAMESPACE_BLOCK' | 'PSL_INVALID_ATTRIBUTE_SYNTAX' | 'PSL_INVALID_MODEL_MEMBER' | 'PSL_UNSUPPORTED_MODEL_ATTRIBUTE' | 'PSL_UNSUPPORTED_FIELD_ATTRIBUTE' | 'PSL_INVALID_RELATION_ATTRIBUTE' | 'PSL_INVALID_REFERENTIAL_ACTION' | 'PSL_INVALID_DEFAULT_VALUE' | 'PSL_INVALID_ENUM_MEMBER' | 'PSL_INVALID_TYPES_MEMBER' | 'PSL_INVALID_QUALIFIED_TYPE'
/**
* A malformed line inside an extension-contributed top-level block body, or
* a structurally invalid element inside a `list` parameter value.
*
* Replaces the overloaded `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK` code that the
* generic framework parser previously used for these two parse-error sites
* inside extension blocks — keeping `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK` for
* its original meaning (an unknown keyword at the top level) and giving
* extension-block parse errors their own code.
*/
| 'PSL_INVALID_EXTENSION_BLOCK_MEMBER'
/**
* An unknown parameter key in an extension-contributed block — a key present
* in the source block but absent from the descriptor's `parameters` map.
*/
| 'PSL_EXTENSION_UNKNOWN_PARAMETER'
/**
* A required parameter declared in the descriptor is absent from the parsed block.
*/
| 'PSL_EXTENSION_MISSING_REQUIRED_PARAMETER'
/**
* An `option`-kind parameter value is not one of the allowed tokens listed
* in the descriptor's `values` array.
*/
| 'PSL_EXTENSION_OPTION_OUT_OF_SET'
/**
* A `value`-kind parameter's raw text is not a valid JSON literal, or the
* parsed JSON value was rejected by the codec's `decodeJson` method, or the
* codec id is not registered in the lookup.
*/
| 'PSL_EXTENSION_INVALID_VALUE'
/**
* A `ref`-kind parameter identifier does not resolve to a declared entity of
* the required `refKind` within the declared scope.
*/
| 'PSL_EXTENSION_UNRESOLVED_REF';
/**
* Descriptor vocabulary for a single parameter on a declared block.
*
* Four kinds:
* - `ref` — the parameter value is an identifier that must resolve to a
* declared entity of `refKind` within the declared `scope`.
* - `value` — the parameter value is a PSL literal parsed and printed
* through the codec identified by `codecId`.
* - `option` — the parameter value is one of the literal tokens in `values`.
* Not a codec; not persisted data. A closed authoring-time constraint only.
* - `list` — a bracketed list whose elements each match the `of` descriptor.
*/
type PslBlockParam = PslBlockParamRef | PslBlockParamValue | PslBlockParamOption | PslBlockParamList;
interface PslBlockParamRef {
readonly kind: 'ref';
readonly refKind: string;
readonly scope: 'same-namespace' | 'same-space' | 'cross-space';
readonly required?: boolean;
}
interface PslBlockParamValue {
readonly kind: 'value';
readonly codecId: string;
readonly required?: boolean;
}
interface PslBlockParamOption {
readonly kind: 'option';
readonly values: readonly string[];
readonly required?: boolean;
}
interface PslBlockParamList {
readonly kind: 'list';
readonly of: PslBlockParam;
readonly required?: boolean;
}
/**
* The parsed representation of a single parameter value on a uniform
* extension-block AST node. Mirrors the `PslBlockParam` descriptor
* vocabulary:
*
* - `ref` → `PslExtensionBlockParamRef` — a raw identifier string
* (resolution runs in the validator, not the parser).
* - `value` → `PslExtensionBlockParamValue` — a raw PSL literal string
* (codec validation runs in the validator).
* - `option` → `PslExtensionBlockParamOption` — the chosen token.
* - `list` → `PslExtensionBlockParamList` — ordered list of the above.
*
* These shapes are intentionally minimal. The validator and lowering refine
* and consume them; the generic framework parser produces them.
*/
type PslExtensionBlockParamValue = PslExtensionBlockParamRef | PslExtensionBlockParamScalarValue | PslExtensionBlockParamOption | PslExtensionBlockParamList;
interface PslExtensionBlockParamRef {
readonly kind: 'ref';
readonly identifier: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamScalarValue {
readonly kind: 'value';
readonly raw: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamOption {
readonly kind: 'option';
readonly token: string;
readonly span: PslSpan;
}
interface PslExtensionBlockParamList {
readonly kind: 'list';
readonly items: readonly PslExtensionBlockParamValue[];
readonly span: PslSpan;
}
/**
* Base shape for a uniform extension-contributed top-level PSL block
* node, as produced by the generic framework parser and consumed by the
* validator and lowering factory.
*
* - `kind` is the routing discriminant, equal to the descriptor's
* `discriminator`. The framework parser sets this to
* `descriptor.discriminator` for every block it parses.
* - `name` is the block's declared name (the identifier after the keyword).
* - `parameters` is the descriptor-driven parameter map. Keys are
* parameter names from the descriptor; values are the parsed parameter
* representations. Only parameters present in the source are included
* — absence of a required parameter is a validator concern, not a
* parser concern.
* - `span` covers the full block from keyword to closing brace.
*/
interface PslExtensionBlock {
readonly kind: string;
readonly name: string;
readonly parameters: Record<string, PslExtensionBlockParamValue>;
readonly span: PslSpan;
}
//#endregion
//#region src/shared/framework-authoring.d.ts
type AuthoringArgRef = {
readonly kind: 'arg';
readonly index: number;
readonly path?: readonly string[];
readonly default?: AuthoringTemplateValue;
};
type AuthoringTemplateValue = string | number | boolean | null | AuthoringArgRef | readonly AuthoringTemplateValue[] | {
readonly [key: string]: AuthoringTemplateValue;
};
interface AuthoringArgumentDescriptorCommon {
readonly name?: string;
readonly optional?: boolean;
}
type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon & ({
readonly kind: 'string';
} | {
readonly kind: 'boolean';
} | {
readonly kind: 'number';
readonly integer?: boolean;
readonly minimum?: number;
readonly maximum?: number;
} | {
readonly kind: 'stringArray';
} | {
readonly kind: 'object';
readonly properties: Record<string, AuthoringArgumentDescriptor>;
});
interface AuthoringStorageTypeTemplate {
readonly codecId: string;
readonly nativeType: AuthoringTemplateValue;
readonly typeParams?: Record<string, AuthoringTemplateValue>;
}
interface AuthoringTypeConstructorDescriptor {
readonly kind: 'typeConstructor';
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringStorageTypeTemplate;
}
interface AuthoringColumnDefaultTemplateLiteral {
readonly kind: 'literal';
readonly value: AuthoringTemplateValue;
}
interface AuthoringColumnDefaultTemplateFunction {
readonly kind: 'function';
readonly expression: AuthoringTemplateValue;
}
type AuthoringColumnDefaultTemplate = AuthoringColumnDefaultTemplateLiteral | AuthoringColumnDefaultTemplateFunction;
interface AuthoringExecutionDefaultsTemplate {
readonly onCreate?: AuthoringTemplateValue;
readonly onUpdate?: AuthoringTemplateValue;
}
interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {
readonly nullable?: boolean;
readonly default?: AuthoringColumnDefaultTemplate;
readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;
readonly id?: boolean;
readonly unique?: boolean;
}
interface AuthoringFieldPresetDescriptor {
readonly kind: 'fieldPreset';
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringFieldPresetOutput;
}
type AuthoringTypeNamespace = {
readonly [name: string]: AuthoringTypeConstructorDescriptor | AuthoringTypeNamespace;
};
type AuthoringFieldNamespace = {
readonly [name: string]: AuthoringFieldPresetDescriptor | AuthoringFieldNamespace;
};
/**
* Context surfaced to entity-type factories at call time. Currently a
* placeholder — sharpened as concrete consumers (enum, namespace, …)
* discover what the factory actually needs to read (codec lookup,
* namespace registry, …).
*/
interface AuthoringEntityContext {
readonly family: string;
readonly target: string;
}
interface AuthoringEntityTypeTemplateOutput {
readonly template: AuthoringTemplateValue;
}
/**
* Default `Input = never` is load-bearing for pack-bag-driven type
* narrowing. Factory parameter positions are contravariant, so a pack
* literal declaring `factory: (input: DemoEntityInput) => DemoEntity`
* is only assignable to the base descriptor's factory shape if the
* base's input is `never` (the bottom of the contravariant position).
* The concrete input/output types are recovered at the helper-derivation
* site via `EntityHelperFunction<Descriptor>`'s conditional inference,
* which reads them from the pack's `as const` literal factory signature
* — the base widening does not erase the literal because `satisfies`
* does not widen the declared type.
*/
interface AuthoringEntityTypeFactoryOutput<Input = never, Output = unknown> {
readonly factory: (input: Input, ctx: AuthoringEntityContext) => Output;
}
interface AuthoringEntityTypeDescriptor<Input = never, Output = unknown> {
readonly kind: 'entity';
readonly discriminator: string;
readonly args?: readonly AuthoringArgumentDescriptor[];
readonly output: AuthoringEntityTypeTemplateOutput | AuthoringEntityTypeFactoryOutput<Input, Output>;
/**
* arktype schema fragment for one entry whose envelope `kind` matches
* this descriptor's {@link discriminator}. The family validator composes
* contributed fragments into the per-namespace entry schema at
* validator construction time so the structural check covers
* pack-introduced kinds without the family core hard-coding the schema.
*
* Hydration uses {@link AuthoringEntityTypeFactoryOutput.factory}
* directly — the wire shape conforms structurally to the factory's
* `Input` after `validatorSchema` validates it.
*/
readonly validatorSchema?: Type<unknown>;
}
type AuthoringEntityTypeNamespace = {
readonly [name: string]: AuthoringEntityTypeDescriptor | AuthoringEntityTypeNamespace;
};
/**
* Declarative descriptor for an extension-contributed top-level PSL block.
*
* An extension registers one of these per keyword it contributes. The
* framework owns the generic parser, validator, and printer — no
* parsing or printing code runs from the extension.
*
* - `keyword` is the PSL top-level identifier this descriptor claims
* (`policy_select`, `role`, …).
* - `discriminator` is the routing key used by the printer dispatch and
* the `entityTypes` lowering factory lookup. Convention:
* `<target-or-family>-<kind>` (`postgres-policy-select`).
* - `name.required` declares whether the block must have a name token
* after the keyword. Currently always `true` — anonymous blocks are
* not part of the closed-grammar premise — but the field is explicit
* so the type can evolve without a breaking change.
* - `parameters` maps parameter names to their value-kind descriptors
* (`ref` / `value` / `option` / `list`). The generic parser and
* validator interpret these; the extension supplies no parser or
* printer function.
*/
interface AuthoringPslBlockDescriptor {
readonly kind: 'pslBlock';
readonly keyword: string;
readonly discriminator: string;
readonly name: {
readonly required: boolean;
};
readonly parameters: Record<string, PslBlockParam>;
}
type AuthoringPslBlockDescriptorNamespace = {
readonly [name: string]: AuthoringPslBlockDescriptor | AuthoringPslBlockDescriptorNamespace;
};
interface AuthoringContributions {
readonly type?: AuthoringTypeNamespace;
readonly field?: AuthoringFieldNamespace;
readonly entityTypes?: AuthoringEntityTypeNamespace;
/**
* Registry of declarative block descriptors this contribution registers,
* keyed by arbitrary path segments. Each leaf is an
* {@link AuthoringPslBlockDescriptor} that claims a PSL top-level keyword.
* The framework owns the generic parser, validator, and printer; the
* contribution supplies only these declarative descriptors.
*
* Contrast with the parsed block nodes themselves, which live in a
* namespace's `entries` under their discriminator key; this field holds the
* registry of descriptors that teach the parser how to read those blocks.
*/
readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;
}
declare function isAuthoringArgRef(value: unknown): value is AuthoringArgRef;
declare function isAuthoringTypeConstructorDescriptor(value: unknown): value is AuthoringTypeConstructorDescriptor;
declare function isAuthoringFieldPresetDescriptor(value: unknown): value is AuthoringFieldPresetDescriptor;
declare function isAuthoringEntityTypeDescriptor(value: unknown): value is AuthoringEntityTypeDescriptor;
declare function isAuthoringPslBlockDescriptor(value: unknown): value is AuthoringPslBlockDescriptor;
/**
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
*
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
* registration must NOT be treated as a "namespace" with sub-paths. Callers
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
*/
declare function hasRegisteredFieldNamespace(contributions: AuthoringContributions | undefined, namespace: string): boolean;
/**
* Merges `source` into `target` recursively at the descriptor-namespace
* level. `leafGuard` decides which values are descriptors (terminal
* merge points; same-path registrations across components are reported
* as duplicates) versus sub-namespaces (recursion targets).
*
* Path segments are validated against prototype-pollution names
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
* recognized leaf nor a plain object — e.g. a malformed descriptor
* where the canonical leaf guard rejected it for missing `output` —
* is reported as an invalid contribution rather than recursed into,
* which would either silently mangle state or infinite-loop on
* primitive properties.
*
* Within-registry duplicate detection is this walker's job;
* cross-registry detection runs separately via
* `assertNoCrossRegistryCollisions` after merging completes.
*/
declare function mergeAuthoringNamespaces(target: Record<string, unknown>, source: Record<string, unknown>, path: readonly string[], leafGuard: (value: unknown) => boolean, label: string): void;
declare function assertNoCrossRegistryCollisions(typeNamespace: AuthoringTypeNamespace, fieldNamespace: AuthoringFieldNamespace, entityTypeNamespace?: AuthoringEntityTypeNamespace, pslBlockNamespace?: AuthoringPslBlockDescriptorNamespace): void;
declare function resolveAuthoringTemplateValue(template: AuthoringTemplateValue, args: readonly unknown[]): unknown;
declare function validateAuthoringHelperArguments(helperPath: string, descriptors: readonly AuthoringArgumentDescriptor[] | undefined, args: readonly unknown[]): void;
declare function instantiateAuthoringTypeConstructor(descriptor: AuthoringTypeConstructorDescriptor, args: readonly unknown[]): {
readonly codecId: string;
readonly nativeType: string;
readonly typeParams?: Record<string, unknown>;
};
declare function instantiateAuthoringEntityType(helperPath: string, descriptor: AuthoringEntityTypeDescriptor, args: readonly unknown[], ctx: AuthoringEntityContext): unknown;
declare function instantiateAuthoringFieldPreset(descriptor: AuthoringFieldPresetDescriptor, args: readonly unknown[]): {
readonly descriptor: {
readonly codecId: string;
readonly nativeType: string;
readonly typeParams?: Record<string, unknown>;
};
readonly nullable: boolean;
readonly default?: ColumnDefault;
readonly executionDefaults?: ExecutionMutationDefaultPhases;
readonly id: boolean;
readonly unique: boolean;
};
//#endregion
export { resolveAuthoringTemplateValue as A, PslExtensionBlockParamOption as B, instantiateAuthoringTypeConstructor as C, isAuthoringPslBlockDescriptor as D, isAuthoringFieldPresetDescriptor as E, PslBlockParamRef as F, PslSpan as G, PslExtensionBlockParamScalarValue as H, PslBlockParamValue as I, PslDiagnosticCode as L, PslBlockParam as M, PslBlockParamList as N, isAuthoringTypeConstructorDescriptor as O, PslBlockParamOption as P, PslExtensionBlock as R, instantiateAuthoringFieldPreset as S, isAuthoringEntityTypeDescriptor as T, PslExtensionBlockParamValue as U, PslExtensionBlockParamRef as V, PslPosition as W, AuthoringTypeConstructorDescriptor as _, AuthoringEntityContext as a, hasRegisteredFieldNamespace as b, AuthoringEntityTypeNamespace as c, AuthoringFieldPresetDescriptor as d, AuthoringFieldPresetOutput as f, AuthoringTemplateValue as g, AuthoringStorageTypeTemplate as h, AuthoringContributions as i, validateAuthoringHelperArguments as j, mergeAuthoringNamespaces as k, AuthoringEntityTypeTemplateOutput as l, AuthoringPslBlockDescriptorNamespace as m, AuthoringArgumentDescriptor as n, AuthoringEntityTypeDescriptor as o, AuthoringPslBlockDescriptor as p, AuthoringColumnDefaultTemplate as r, AuthoringEntityTypeFactoryOutput as s, AuthoringArgRef as t, AuthoringFieldNamespace as u, AuthoringTypeNamespace as v, isAuthoringArgRef as w, instantiateAuthoringEntityType as x, assertNoCrossRegistryCollisions as y, PslExtensionBlockParamList as z };
//# sourceMappingURL=framework-authoring-R0TYCkvG.d.mts.map
{"version":3,"file":"framework-authoring-R0TYCkvG.d.mts","names":[],"sources":["../src/shared/psl-extension-block.ts","../src/shared/framework-authoring.ts"],"mappings":";;;;;;;;AAYA;;;;;;;UAAiB,WAAA;EAAA,SACN,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,OAAA;EAAA,SACN,KAAA,EAAO,WAAA;EAAA,SACP,GAAA,EAAK,WAAW;AAAA;AAAA,KAGf,iBAAA;;AAHe;AAG3B;;;;AAA6B;AA+D7B;;;;;;;;;;;;;;AAIqB;AAErB;;;;;;;;;AA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S,6BAA6B;AAAA,iBAqBzB,6BAAA,CACd,KAAA,YACC,KAAA,IAAS,2BAA2B;;;;;;AA3Pa;AAAG;;iBAqSvC,2BAAA,CACd,aAAA,EAAe,sBAAsB,cACrC,SAAA;;AAnSiB;AAGnB;;;;;;;;;;;;;;;;iBA8TgB,wBAAA,CACd,MAAA,EAAQ,MAAA,mBACR,MAAA,EAAQ,MAAM,mBACd,IAAA,qBACA,SAAA,GAAY,KAAA,uBACZ,KAAA;AAAA,iBAwLc,+BAAA,CACd,aAAA,EAAe,sBAAA,EACf,cAAA,EAAgB,uBAAA,EAChB,mBAAA,GAAqB,4BAAA,EACrB,iBAAA,GAAmB,oCAAA;AAAA,iBA6CL,6BAAA,CACd,QAAA,EAAU,sBAAsB,EAChC,IAAA;AAAA,iBAiHc,gCAAA,CACd,UAAA,UACA,WAAA,WAAsB,2BAA2B,gBACjD,IAAA;AAAA,iBAmHc,mCAAA,CACd,UAAA,EAAY,kCAAA,EACZ,IAAA;EAAA,SAES,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;AAAA,iBAKd,8BAAA,CACd,UAAA,UACA,UAAA,EAAY,6BAAA,EACZ,IAAA,sBACA,GAAA,EAAK,sBAAsB;AAAA,iBA0Bb,+BAAA,CACd,UAAA,EAAY,8BAAA,EACZ,IAAA;EAAA,SAES,UAAA;IAAA,SACE,OAAA;IAAA,SACA,UAAA;IAAA,SACA,UAAA,GAAa,MAAA;EAAA;EAAA,SAEf,QAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,iBAAA,GAAoB,8BAAA;EAAA,SACpB,EAAA;EAAA,SACA,MAAA;AAAA"}
import { i as AuthoringContributions } from "./framework-authoring-R0TYCkvG.mjs";
import { r as AnyCodecDescriptor } from "./codec-DCQAerzB.mjs";
import { t as TypesImportSpec } from "./types-import-spec-DRKzrJ20.mjs";
import { ColumnDefault, ExecutionMutationDefaultPhases, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
//#region src/shared/mutation-default-types.d.ts
interface SourcePosition {
readonly offset: number;
readonly line: number;
readonly column: number;
}
interface SourceSpan {
readonly start: SourcePosition;
readonly end: SourcePosition;
}
interface SourceDiagnostic {
readonly code: string;
readonly message: string;
readonly sourceId?: string;
readonly span?: SourceSpan;
readonly data?: Readonly<Record<string, unknown>>;
}
interface DefaultFunctionArgument {
readonly raw: string;
readonly span: SourceSpan;
}
interface ParsedDefaultFunctionCall {
readonly name: string;
readonly raw: string;
readonly args: readonly DefaultFunctionArgument[];
readonly span: SourceSpan;
}
interface DefaultFunctionLoweringContext {
readonly sourceId: string;
readonly modelName: string;
readonly fieldName: string;
readonly columnCodecId?: string;
}
type LoweredDefaultValue = {
readonly kind: 'storage';
readonly defaultValue: ColumnDefault;
} | {
readonly kind: 'execution';
readonly generated: ExecutionMutationDefaultValue;
};
type LoweredDefaultResult = {
readonly ok: true;
readonly value: LoweredDefaultValue;
} | {
readonly ok: false;
readonly diagnostic: SourceDiagnostic;
};
type DefaultFunctionLoweringHandler = (input: {
readonly call: ParsedDefaultFunctionCall;
readonly context: DefaultFunctionLoweringContext;
}) => LoweredDefaultResult;
interface DefaultFunctionRegistryEntry {
readonly lower: DefaultFunctionLoweringHandler;
readonly usageSignatures?: readonly string[];
}
type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistryEntry>;
interface MutationDefaultGeneratorDescriptor {
readonly id: string;
/**
* Codec ids the generator is compatible with when the codec choice
* and the generator choice are made independently by the contract
* author. Set when the registry-coherence check is meaningful
* (the codec and the generator can be paired arbitrarily by the
* caller); omitted when the generator is only reachable through a
* descriptor that co-registers a fixed codec, so coherence is
* structural and the list would be tautological.
*/
readonly applicableCodecIds?: readonly string[];
readonly resolveGeneratedColumnDescriptor?: (input: {
readonly generated: ExecutionMutationDefaultValue;
}) => {
readonly codecId: string;
readonly nativeType: string;
readonly typeRef?: string;
readonly typeParams?: Record<string, unknown>;
} | undefined;
/**
* Construct the `onCreate`/`onUpdate` phases value owned by this
* generator. Authoring layers (PSL `temporal.updatedAt()`, TS field presets) call
* this instead of building the literal inline so PSL/TS-authored
* contracts stay byte-equivalent for any future params-bearing generator.
*/
readonly buildPhases?: (args?: Record<string, unknown>) => ExecutionMutationDefaultPhases;
}
interface ControlMutationDefaultEntry {
readonly lower: (input: {
readonly call: ParsedDefaultFunctionCall;
readonly context: DefaultFunctionLoweringContext;
}) => LoweredDefaultResult;
readonly usageSignatures?: readonly string[];
}
type ControlMutationDefaultRegistry = ReadonlyMap<string, ControlMutationDefaultEntry>;
interface ControlMutationDefaults {
readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
readonly generatorDescriptors: readonly MutationDefaultGeneratorDescriptor[];
}
//#endregion
//#region src/shared/framework-components.d.ts
/**
* Declarative fields that describe component metadata.
*/
interface ComponentMetadata {
/** Component version (semver) */
readonly version: string;
/**
* Capabilities this component provides.
*
* For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`); keep these declarations in sync. Targets are identifiers/descriptors and typically do not declare capabilities.
*/
readonly capabilities?: Record<string, unknown>;
/** Type imports for contract.d.ts generation */
readonly types?: {
readonly codecTypes?: {
/**
* Base codec types import spec. Optional: adapters typically provide this, extensions usually don't.
*/
readonly import?: TypesImportSpec;
/**
* Additional type-only imports for parameterized codec branded types.
*
* These imports are included in generated `contract.d.ts` but are NOT treated as codec type maps (i.e., they should not be intersected into `export type CodecTypes = ...`).
*
* Example: `Vector<N>` for pgvector codecs that emit `Vector<1536>`
*/
readonly typeImports?: ReadonlyArray<TypesImportSpec>;
/**
* Optional control-plane hooks keyed by codecId. Used by family-specific planners/verifiers to handle storage types.
*/
readonly controlPlaneHooks?: Record<string, unknown>;
/**
* Codec descriptors contributed by this component. Source of truth for codec-id-keyed metadata (`traits`, `targetTypes`, `meta`, `renderOutputType`) consumed by `extractCodecLookup`, and used to materialize representative `Codec` instances for codec-dispatched type rendering during emission.
*/
readonly codecDescriptors?: ReadonlyArray<AnyCodecDescriptor>;
};
readonly queryOperationTypes?: {
readonly import: TypesImportSpec;
};
readonly storage?: ReadonlyArray<{
readonly typeId: string;
readonly familyId: string;
readonly targetId: string;
readonly nativeType?: string;
}>;
};
/**
* Optional pure-data authoring contributions exposed by this component.
*
* These contributions are safe to include on pack refs and descriptors because they contain only declarative metadata. Higher-level authoring packages may project them into concrete helper functions for TS-first workflows.
*/
readonly authoring?: AuthoringContributions;
/**
* Scalar type name to codec ID mapping contributed by this component. Assembled by `createControlStack` with duplicate detection.
*/
readonly scalarTypeDescriptors?: ReadonlyMap<string, string>;
/**
* Mutation default function handlers and generator descriptors contributed by this component. Assembled by `createControlStack` with duplicate detection.
*/
readonly controlMutationDefaults?: ControlMutationDefaults;
}
/**
* Base descriptor for any framework component.
*
* All component descriptors share these fundamental properties that identify the component and provide its metadata. This interface is extended by specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
*
* @template Kind - Discriminator literal identifying the component type. Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension', but the type accepts any string to allow ecosystem extensions.
*
* @example
* ```ts
* // All descriptors have these properties
* descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)
* descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')
* descriptor.version // Component version (semver)
* ```
*/
interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {
/** Discriminator identifying the component type */
readonly kind: Kind;
/** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */
readonly id: string;
}
interface ContractComponentRequirementsCheckInput {
readonly contract: {
readonly target: string;
readonly targetFamily?: string | undefined;
readonly extensionPacks?: Record<string, unknown> | undefined;
};
readonly expectedTargetFamily?: string | undefined;
readonly expectedTargetId?: string | undefined;
readonly providedComponentIds: Iterable<string>;
}
interface ContractComponentRequirementsCheckResult {
readonly familyMismatch?: {
readonly expected: string;
readonly actual: string;
} | undefined;
readonly targetMismatch?: {
readonly expected: string;
readonly actual: string;
} | undefined;
readonly missingExtensionPackIds: readonly string[];
}
declare function checkContractComponentRequirements(input: ContractComponentRequirementsCheckInput): ContractComponentRequirementsCheckResult;
/**
* Descriptor for a family component.
*
* A "family" represents a category of data sources with shared semantics (e.g., SQL databases, document stores). Families define:
* - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
* - Contract structure (tables vs collections, columns vs fields)
* - Type system and codecs
*
* Families are the top-level grouping. Each family contains multiple targets (e.g., SQL family contains Postgres, MySQL, SQLite targets).
*
* Extended by plane-specific descriptors:
* - `ControlFamilyDescriptor` - adds `emission` for CLI/tooling operations
* - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods
*
* @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
*
* @example
* ```ts
* import sql from '@prisma-next/family-sql/control';
*
* sql.kind // 'family'
* sql.familyId // 'sql'
* sql.id // 'sql'
* ```
*/
interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {
/** The family identifier (e.g., 'sql', 'document') */
readonly familyId: TFamilyId;
}
/**
* Descriptor for a target component.
*
* A "target" represents a specific database or data store within a family (e.g., Postgres, MySQL, MongoDB). Targets define:
* - Native type mappings (e.g., Postgres int4 → TypeScript number)
* - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
*
* Targets are bound to a family and provide the target-specific implementation details that adapters and drivers use.
*
* Extended by plane-specific descriptors:
* - `ControlTargetDescriptor` - adds optional `migrations` capability
* - `RuntimeTargetDescriptor` - adds runtime factory method
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
*
* @example
* ```ts
* import postgres from '@prisma-next/target-postgres/control';
*
* postgres.kind // 'target'
* postgres.familyId // 'sql'
* postgres.targetId // 'postgres'
* ```
*/
interface TargetDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'target'> {
/** The family this target belongs to */
readonly familyId: TFamilyId;
/** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
readonly targetId: TTargetId;
}
/**
* Base shape for any pack reference. Pack refs are pure JSON-friendly objects safe to import in authoring flows.
*/
interface PackRefBase<Kind extends string, TFamilyId extends string> extends ComponentMetadata {
readonly kind: Kind;
readonly id: string;
readonly familyId: TFamilyId;
readonly targetId?: string;
readonly authoring?: AuthoringContributions;
}
type FamilyPackRef<TFamilyId extends string = string> = PackRefBase<'family', TFamilyId>;
type TargetPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'target', TFamilyId> & {
readonly targetId: TTargetId; /** The namespace a bare (un-namespaced) entity name resolves to for this target (e.g. Postgres `'public'`). */
readonly defaultNamespaceId: string;
};
type AdapterPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'adapter', TFamilyId> & {
readonly targetId: TTargetId;
};
type ExtensionPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'extension', TFamilyId> & {
readonly targetId: TTargetId;
};
type DriverPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'driver', TFamilyId> & {
readonly targetId: TTargetId;
};
/**
* Descriptor for an adapter component.
*
* An "adapter" provides the protocol and dialect implementation for a target. Adapters handle:
* - SQL/query generation (lowering AST to target-specific syntax)
* - Codec registration (encoding/decoding between JS and wire types)
* - Type mappings and coercions
*
* Adapters are bound to a specific family+target combination and work with any compatible driver for that target.
*
* Extended by plane-specific descriptors:
* - `ControlAdapterDescriptor` - control-plane factory
* - `RuntimeAdapterDescriptor` - runtime factory
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import postgresAdapter from '@prisma-next/adapter-postgres/control';
*
* postgresAdapter.kind // 'adapter'
* postgresAdapter.familyId // 'sql'
* postgresAdapter.targetId // 'postgres'
* ```
*/
interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'adapter'> {
/** The family this adapter belongs to */
readonly familyId: TFamilyId;
/** The target this adapter is designed for */
readonly targetId: TTargetId;
}
/**
* Descriptor for a driver component.
*
* A "driver" provides the connection and execution layer for a target. Drivers handle:
* - Connection management (pooling, timeouts, retries)
* - Query execution (sending SQL/commands, receiving results)
* - Transaction management
* - Wire protocol communication
*
* Drivers are bound to a specific family+target and work with any compatible adapter. Multiple drivers can exist for the same target (e.g., node-postgres vs postgres.js for Postgres).
*
* Extended by plane-specific descriptors:
* - `ControlDriverDescriptor` - creates driver from connection URL
* - `RuntimeDriverDescriptor` - creates driver with runtime options
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import postgresDriver from '@prisma-next/driver-postgres/control';
*
* postgresDriver.kind // 'driver'
* postgresDriver.familyId // 'sql'
* postgresDriver.targetId // 'postgres'
* ```
*/
interface DriverDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'driver'> {
/** The family this driver belongs to */
readonly familyId: TFamilyId;
/** The target this driver connects to */
readonly targetId: TTargetId;
}
/**
* Descriptor for an extension component.
*
* An "extension" adds optional capabilities to a target. Extensions can provide:
* - Additional operations (e.g., vector similarity search with pgvector)
* - Custom types and codecs (e.g., vector type)
* - Extended query capabilities
*
* Extensions are bound to a specific family+target and are registered in the config alongside the core components. Multiple extensions can be used together.
*
* Extended by plane-specific descriptors:
* - `ControlExtensionDescriptor` - control-plane extension factory
* - `RuntimeExtensionDescriptor` - runtime extension factory
*
* @template TFamilyId - Literal type for the family identifier
* @template TTargetId - Literal type for the target identifier
*
* @example
* ```ts
* import pgvector from '@prisma-next/extension-pgvector/control';
*
* pgvector.kind // 'extension'
* pgvector.familyId // 'sql'
* pgvector.targetId // 'postgres'
* ```
*/
interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'extension'> {
/** The family this extension belongs to */
readonly familyId: TFamilyId;
/** The target this extension is designed for */
readonly targetId: TTargetId;
}
/** Components bound to a specific family+target combination. */
type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> = TargetDescriptor<TFamilyId, TTargetId> | AdapterDescriptor<TFamilyId, TTargetId> | DriverDescriptor<TFamilyId, TTargetId> | ExtensionDescriptor<TFamilyId, TTargetId>;
interface FamilyInstance<TFamilyId extends string> {
readonly familyId: TFamilyId;
}
interface TargetInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface DriverInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {
readonly familyId: TFamilyId;
readonly targetId: TTargetId;
}
//#endregion
export { LoweredDefaultResult as A, ControlMutationDefaultEntry as C, DefaultFunctionLoweringHandler as D, DefaultFunctionLoweringContext as E, SourceSpan as F, MutationDefaultGeneratorDescriptor as M, ParsedDefaultFunctionCall as N, DefaultFunctionRegistry as O, SourceDiagnostic as P, checkContractComponentRequirements as S, ControlMutationDefaults as T, PackRefBase as _, ComponentMetadata as a, TargetInstance as b, DriverDescriptor as c, ExtensionDescriptor as d, ExtensionInstance as f, FamilyPackRef as g, FamilyInstance as h, ComponentDescriptor as i, LoweredDefaultValue as j, DefaultFunctionRegistryEntry as k, DriverInstance as l, FamilyDescriptor as m, AdapterInstance as n, ContractComponentRequirementsCheckInput as o, ExtensionPackRef as p, AdapterPackRef as r, ContractComponentRequirementsCheckResult as s, AdapterDescriptor as t, DriverPackRef as u, TargetBoundComponentDescriptor as v, ControlMutationDefaultRegistry as w, TargetPackRef as x, TargetDescriptor as y };
//# sourceMappingURL=framework-components-DDQXmW0b.d.mts.map
{"version":3,"file":"framework-components-DDQXmW0b.d.mts","names":[],"sources":["../src/shared/mutation-default-types.ts","../src/shared/framework-components.ts"],"mappings":";;;;;;UAMU,cAAA;EAAA,SACC,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,UAAA;EAAA,SACN,KAAA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AAA;EAhPwB;EAAA,SAkPvB,QAAA,EAAU,SAAA;EAhPR;EAAA,SAmPF,QAAA,EAAU,SAAA;AAAA;;;;;;;;;;;;;;AA3NuC;AAkB5D;;;;;;;;;;AAKa;AAGb;;UA+NiB,gBAAA,6DACP,mBAAA;EAxN+B;EAAA,SA0N9B,QAAA,EAAU,SAAA;EAhOR;EAAA,SAmOF,QAAA,EAAU,SAAA;AAAA;;;;;;;AA7NoB;AAGzC;;;;;;;;;;;;AAGkC;AAGlC;;;;;;UAiPiB,mBAAA,6DACP,mBAAA;EAhPiC;EAAA,SAkPhC,QAAA,EAAU,SAAA;EAvLJ;EAAA,SA0LN,QAAA,EAAU,SAAA;AAAA;;KAIT,8BAAA,uDACR,gBAAA,CAAiB,SAAA,EAAW,SAAA,IAC5B,iBAAA,CAAkB,SAAA,EAAW,SAAA,IAC7B,gBAAA,CAAiB,SAAA,EAAW,SAAA,IAC5B,mBAAA,CAAoB,SAAA,EAAW,SAAA;AAAA,UAElB,cAAA;EAAA,SACN,QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,cAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,eAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,cAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA;AAAA,UAGb,iBAAA;EAAA,SACN,QAAA,EAAU,SAAA;EAAA,SACV,QAAA,EAAU,SAAS;AAAA"}
import { G as PslSpan, L as PslDiagnosticCode, R as PslExtensionBlock, m as AuthoringPslBlockDescriptorNamespace } from "./framework-authoring-R0TYCkvG.mjs";
import { c as CodecLookup } from "./codec-DCQAerzB.mjs";
//#region src/control/psl-ast.d.ts
interface PslDiagnostic {
readonly code: PslDiagnosticCode;
readonly message: string;
readonly sourceId: string;
readonly span: PslSpan;
}
interface PslDefaultFunctionValue {
readonly kind: 'function';
readonly name: 'autoincrement' | 'now';
}
interface PslDefaultLiteralValue {
readonly kind: 'literal';
readonly value: string | number | boolean;
}
type PslDefaultValue = PslDefaultFunctionValue | PslDefaultLiteralValue;
type PslAttributeTarget = 'field' | 'model' | 'enum' | 'namedType';
interface PslAttributePositionalArgument {
readonly kind: 'positional';
readonly value: string;
readonly span: PslSpan;
}
interface PslAttributeNamedArgument {
readonly kind: 'named';
readonly name: string;
readonly value: string;
readonly span: PslSpan;
}
type PslAttributeArgument = PslAttributePositionalArgument | PslAttributeNamedArgument;
interface PslTypeConstructorCall {
readonly kind: 'typeConstructor';
readonly path: readonly string[];
readonly args: readonly PslAttributeArgument[];
readonly span: PslSpan;
}
interface PslAttribute {
readonly kind: 'attribute';
readonly target: PslAttributeTarget;
readonly name: string;
readonly args: readonly PslAttributeArgument[];
readonly span: PslSpan;
}
type PslReferentialAction = string;
type PslFieldAttribute = PslAttribute;
interface PslField {
readonly kind: 'field';
readonly name: string;
/** Unqualified type name, e.g. `"User"` for both `User`, `auth.User`, and `supabase:auth.User`. */
readonly typeName: string;
/** Namespace qualifier from a dot-qualified type reference, e.g. `"auth"` for `auth.User` or `supabase:auth.User`. Absent for unqualified types. */
readonly typeNamespaceId?: string;
/**
* Contract-space qualifier from a colon-prefix type reference, e.g. `"supabase"` for
* `supabase:auth.User` or `supabase:User`. Absent for local (same-space) type references.
*
* When present, the field references a model from a different contract space. The namespace
* (`typeNamespaceId`) and model name (`typeName`) identify the target within that space.
* Physical table resolution against the extension contract is deferred to the aggregate stage (M3).
*/
readonly typeContractSpaceId?: string;
readonly typeConstructor?: PslTypeConstructorCall;
readonly optional: boolean;
readonly list: boolean;
readonly typeRef?: string;
readonly attributes: readonly PslFieldAttribute[];
readonly span: PslSpan;
}
interface PslUniqueConstraint {
readonly kind: 'unique';
readonly fields: readonly string[];
readonly span: PslSpan;
}
interface PslIndexConstraint {
readonly kind: 'index';
readonly fields: readonly string[];
readonly span: PslSpan;
}
type PslModelAttribute = PslAttribute;
interface PslModel {
readonly kind: 'model';
readonly name: string;
readonly fields: readonly PslField[];
readonly attributes: readonly PslModelAttribute[];
readonly span: PslSpan;
/**
* Optional leading comment line emitted above the `model` keyword by the
* printer. Producers (e.g. `sqlSchemaIrToPslAst`) attach introspection
* advisories such as "// WARNING: This table has no primary key in the
* database" here. The parser leaves this field unset; round-tripping a
* parsed schema does not re-attach comments.
*/
readonly comment?: string;
}
interface PslEnumValue {
readonly kind: 'enumValue';
readonly name: string;
/**
* Optional storage label for the enum member, captured from a trailing
* `@map("...")` attribute on the member line. The parser populates this
* when the source PSL carries an explicit `@map`. Producers (e.g.
* `sqlSchemaIrToPslAst`) leave it unset; the printer emits `@map(...)`
* automatically when normalisation would change the printed member name
* (so an enum value `'in-progress'` becomes `inProgress @map("in-progress")`
* in PSL, preserving the round-trip).
*/
readonly mapName?: string;
readonly span: PslSpan;
}
interface PslEnum {
readonly kind: 'enum';
readonly name: string;
readonly values: readonly PslEnumValue[];
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
/**
* A reusable group of fields embedded in a model (a `type Name { … }` block) —
* e.g. a MongoDB embedded document or a Postgres composite type. Unlike
* {@link PslModel} it has no storage or identity of its own.
*/
interface PslCompositeType {
readonly kind: 'compositeType';
readonly name: string;
readonly fields: readonly PslField[];
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
interface PslNamedTypeDeclaration {
readonly kind: 'namedType';
readonly name: string;
/**
* Parser invariant: exactly one of `baseType` and `typeConstructor` is set.
* Expressing this as a discriminated union trips TypeScript narrowing when
* the declaration flows through helpers that accept the full union.
*/
readonly baseType?: string;
readonly typeConstructor?: PslTypeConstructorCall;
readonly attributes: readonly PslAttribute[];
readonly span: PslSpan;
}
interface PslTypesBlock {
readonly kind: 'types';
readonly declarations: readonly PslNamedTypeDeclaration[];
readonly span: PslSpan;
}
/**
* Name of the synthesised namespace bucket the framework parser uses for
* top-level declarations that appear outside any `namespace { … }` block.
* The double-underscore decoration signals that the identifier is parser-
* synthesised and never appears in user-authored PSL source — writing
* `namespace __unspecified__ { … }` is a parse error.
*
* Distinct from the IR sentinel `__unbound__`: the PSL bucket describes
* syntactic absence at the parser layer; the IR sentinel describes a late-
* bound storage slot at the IR layer. Per-target interpreters decide how
* (or whether) to map the PSL bucket to the IR sentinel.
*/
declare const UNSPECIFIED_PSL_NAMESPACE_ID = "__unspecified__";
/** A value in {@link PslNamespace.entries}: a built-in entity node or an extension-contributed {@link PslExtensionBlock}. */
type PslNamespaceEntry = PslModel | PslEnum | PslCompositeType | PslExtensionBlock;
/**
* A namespace block, or the parser's synthesised `__unspecified__` bucket for
* declarations outside any `namespace { … }`. Same-name blocks reopen-merge;
* `span` points at the first opening.
*
* Entities are stored canonically (ADR 224) in `entries[kind][name]`, where
* `kind` is the PSL keyword for built-ins or the block discriminator for
* extension kinds, e.g. `entries['policy_select']['ReadPosts']`.
*/
interface PslNamespace {
readonly kind: 'namespace';
readonly name: string;
/** Canonical store: a frozen container of frozen per-kind maps. The accessors below derive from it. */
readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
/** Built-in models, from `entries['model']`. Extension kinds: {@link namespacePslExtensionBlocks}. */
readonly models: readonly PslModel[];
/** Built-in enums, from `entries['enum']`. */
readonly enums: readonly PslEnum[];
/** Built-in composite types, from `entries['compositeType']`. */
readonly compositeTypes: readonly PslCompositeType[];
readonly span: PslSpan;
}
/** Constructs a {@link PslNamespace}. Use this, never a namespace literal — the accessors must derive from `entries`. */
declare function makePslNamespace(init: {
readonly kind: 'namespace';
readonly name: string;
readonly entries: Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
readonly span: PslSpan;
}): PslNamespace;
/**
* Builds the frozen `entries[kind][name]` container from per-kind arrays.
* Built-ins key on their PSL keyword; extension blocks key on their `kind`
* discriminator. Call this rather than hand-building the literal.
*/
declare function makePslNamespaceEntries(models: readonly PslModel[], enums: readonly PslEnum[], compositeTypes: readonly PslCompositeType[], extensionBlocks: readonly PslExtensionBlock[]): Readonly<Record<string, Readonly<Record<string, PslNamespaceEntry>>>>;
interface PslDocumentAst {
readonly kind: 'document';
readonly sourceId: string;
readonly namespaces: readonly PslNamespace[];
readonly types?: PslTypesBlock;
readonly span: PslSpan;
}
/**
* Returns all models from every namespace in document order. Convenience
* for consumers that don't (yet) need namespace-awareness.
*/
declare function flatPslModels(ast: PslDocumentAst): readonly PslModel[];
/**
* Returns all enums from every namespace in document order.
*/
declare function flatPslEnums(ast: PslDocumentAst): readonly PslEnum[];
/**
* Returns all composite types from every namespace in document order.
*/
declare function flatPslCompositeTypes(ast: PslDocumentAst): readonly PslCompositeType[];
/**
* The set of `entries` kind keys that the framework parser reserves for
* built-in PSL entity kinds. Any own-enumerable key on `PslNamespace.entries`
* that is **not** in this set was contributed by an extension-block descriptor.
*
* Built-in keys match the PSL keyword used on each block type:
* `'model'`, `'enum'`, `'compositeType'`.
*/
declare const BUILTIN_PSL_KIND_KEYS: ReadonlySet<string>;
/**
* Returns all extension-contributed blocks in the given namespace, in
* insertion order (the order the parser encountered them in the source).
*
* Reads from `namespace.entries`, skipping the three built-in kind keys
* (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain
* only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`).
*/
declare function namespacePslExtensionBlocks(ns: PslNamespace): readonly PslExtensionBlock[];
interface ParsePslDocumentInput {
readonly schema: string;
readonly sourceId: string;
/**
* Registry of declarative block descriptors, keyed by arbitrary path
* segments with {@link AuthoringPslBlockDescriptor} leaves. The registry
* teaches the parser which top-level keywords belong to extension
* contributions: when the parser encounters an unknown keyword, it looks
* it up here and, when found, reads the block generically into a
* {@link PslExtensionBlock} node. Absent or undefined means no extension
* blocks are registered and any unknown keyword yields
* `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK`.
*
* Contrast with the parsed block nodes themselves, which live in
* {@link PslNamespace.entries} under their discriminator key (read them with
* {@link namespacePslExtensionBlocks}); this field holds the registry of
* descriptors that teach the parser how to read those blocks.
*/
readonly pslBlockDescriptors?: AuthoringPslBlockDescriptorNamespace;
/**
* Codec lookup for validating `value`-kind extension block parameters.
* When provided alongside `pslBlockDescriptors`, the generic validator runs
* over every parsed extension block after the full AST is assembled,
* appending any diagnostics to the parse result. Absent or undefined means
* no codec validation runs; `ref` resolution still runs when namespace
* context is available (built from the assembled namespaces).
*/
readonly codecLookup?: CodecLookup;
}
interface ParsePslDocumentResult {
readonly ast: PslDocumentAst;
readonly diagnostics: readonly PslDiagnostic[];
readonly ok: boolean;
}
//#endregion
export { flatPslCompositeTypes as A, PslNamespace as C, PslTypesBlock as D, PslTypeConstructorCall as E, namespacePslExtensionBlocks as F, flatPslModels as M, makePslNamespace as N, PslUniqueConstraint as O, makePslNamespaceEntries as P, PslNamedTypeDeclaration as S, PslReferentialAction as T, PslField as _, PslAttributeArgument as a, PslModel as b, PslAttributeTarget as c, PslDefaultLiteralValue as d, PslDefaultValue as f, PslEnumValue as g, PslEnum as h, PslAttribute as i, flatPslEnums as j, UNSPECIFIED_PSL_NAMESPACE_ID as k, PslCompositeType as l, PslDocumentAst as m, ParsePslDocumentInput as n, PslAttributeNamedArgument as o, PslDiagnostic as p, ParsePslDocumentResult as r, PslAttributePositionalArgument as s, BUILTIN_PSL_KIND_KEYS as t, PslDefaultFunctionValue as u, PslFieldAttribute as v, PslNamespaceEntry as w, PslModelAttribute as x, PslIndexConstraint as y };
//# sourceMappingURL=psl-ast-Cn50B-UG.d.mts.map
{"version":3,"file":"psl-ast-Cn50B-UG.d.mts","names":[],"sources":["../src/control/psl-ast.ts"],"mappings":";;;;UAuBiB,aAAA;EAAA,SACN,IAAA,EAAM,iBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,uBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,UAGE,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAK;AAA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