@prisma-next/framework-components
Advanced tools
| 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; | ||
| /** 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 | ||
| //#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 | ||
| export { CodecRef as a, voidParamsSchema as c, AnyCodecDescriptor as d, CodecDescriptor as f, CodecMeta as i, Codec as l, CodecInstanceContext as n, CodecTrait as o, CodecDescriptorImpl as p, CodecLookup as r, emptyCodecLookup as s, CodecCallContext as t, CodecImpl as u }; | ||
| //# sourceMappingURL=codec-types-7Qng7VFc.d.mts.map |
| {"version":3,"file":"codec-types-7Qng7VFc.d.mts","names":[],"sources":["../src/shared/codec-descriptor.ts","../src/shared/codec.ts","../src/shared/codec-types.ts"],"mappings":";;;;;;;;;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AY,MAAA;AAAA;;;;;;uBAQT,SAAA,sDAEK,UAAA,cAAwB,UAAA,kDAGtC,KAAA,CAAM,EAAA,EAAI,OAAA,EAAS,KAAA,EAAO,MAAA;EAAA,SAMT,UAAA,EAAY,eAAA;EDSd;;;cCTE,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;;;KC1E5B,UAAA;AF0BZ;;;;;;;;;AAAA,UEfiB,QAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA,GAAa,SAAS;AAAA;;;;;;;;;;;;UAchB,gBAAA;EAAA,SACN,MAAA,GAAS,WAAW;AAAA;;;;;;;;AFcwC;UEHtD,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;;;;;;;;UASgB,oBAAA;EAAA,SACN,IAAI;AAAA;;;;UAME,SAAA;EAAA,SACN,EAAA,GAAK,MAAM;AAAA;;;;cAMT,gBAAA,EAAkB,gBAAgB"} |
| 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 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-CLCzDm3Y.mjs.map |
| {"version":3,"file":"framework-authoring-CLCzDm3Y.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 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 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,OAA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OT,IAAI,aAAa,WAAW,QAAQ;EAClC,MAAM,QAAQ,KAAK;EAOnB,MAAM,UAAU,WAAW,OAAO;EAIlC,OAAO,QAAQ,OAAO,GAAG;CAC3B;CACA,iCAAiC,YAAY,WAAW,MAAM,IAAI;CAClE,OAAO,8BAA8B,WAAW,OAAO,UAAU,IAAI;AACvE;AAEA,SAAgB,gCACd,YACA,MAYA;CACA,OAAO;EACL,YAAY,oCAAoC,WAAW,QAAQ,IAAI;EACvE,UAAU,WAAW,OAAO,YAAY;EACxC,GAAG,UACD,WACA,WAAW,OAAO,YAAY,KAAA,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 { r as CodecLookup } from "./codec-types-7Qng7VFc.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 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' | ||
| /** | ||
| * 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 enum2 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. `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 { 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-DMAwH52s.d.mts.map |
| {"version":3,"file":"framework-authoring-DMAwH52s.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;AAwE7B;;;;;;;;;;;;;;AAIqB;AAErB;;;;;;;;;AAImB;AAGnB;;;;;;;;AAGmB;AAGnB;;AAHmB;;;;;;AAMA;AAGnB;;;;;;KAzBY,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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BAAA;EAAA,SACpB,EAAA;EAAA,SACA,MAAA;AAAA"} |
| import { d as AnyCodecDescriptor } from "./codec-types-7Qng7VFc.mjs"; | ||
| import { i as AuthoringContributions } from "./framework-authoring-DMAwH52s.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-DXqiWAJX.d.mts.map |
| {"version":3,"file":"framework-components-DXqiWAJX.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,M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;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 { r as CodecLookup } from "./codec-types-7Qng7VFc.mjs"; | ||
| import { R as PslDiagnosticCode, Y as PslSpan, h as AuthoringPslBlockDescriptorNamespace, z as PslExtensionBlock } from "./framework-authoring-DMAwH52s.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 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-Mq7MlfKe.d.mts.map |
| {"version":3,"file":"psl-ast-Mq7MlfKe.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,uBAAA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AuthoringPslBlockDescriptor, 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-DMAwH52s.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-CLCzDm3Y.mjs"; | ||
| export { assertNoCrossRegistryCollisions, hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringArgRef, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, resolveAuthoringTemplateValue, validateAuthoringHelperArguments }; |
+1
-1
@@ -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 voidParamsSchema, d as AnyCodecDescriptor, f as CodecDescriptor, i as CodecMeta, l as Codec, n as CodecInstanceContext, o as CodecTrait, p as CodecDescriptorImpl, r as CodecLookup, s as emptyCodecLookup, t as CodecCallContext, u as CodecImpl } from "./codec-types-7Qng7VFc.mjs"; | ||
@@ -3,0 +3,0 @@ //#region src/shared/column-spec.d.ts |
@@ -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-DXqiWAJX.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 { r as CodecLookup } from "./codec-types-7Qng7VFc.mjs"; | ||
| import { d as AuthoringFieldNamespace, h as AuthoringPslBlockDescriptorNamespace, i as AuthoringContributions, l as AuthoringEntityTypeNamespace, y as AuthoringTypeNamespace } from "./framework-authoring-DMAwH52s.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-DXqiWAJX.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 { m as PslDocumentAst } from "./psl-ast-Mq7MlfKe.mjs"; | ||
| import { Contract, ContractMarkerRecord, ControlPolicy, LedgerEntryRecord } from "@prisma-next/contract/types"; | ||
@@ -8,0 +8,0 @@ import { ImportRequirement, ImportRequirement as ImportRequirement$1 } from "@prisma-next/ts-render"; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| 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 { c as isAuthoringFieldPresetDescriptor, d as mergeAuthoringNamespaces, l as isAuthoringPslBlockDescriptor, s as isAuthoringEntityTypeDescriptor, t as assertNoCrossRegistryCollisions, u as isAuthoringTypeConstructorDescriptor } from "./framework-authoring-CLCzDm3Y.mjs"; | ||
| import { blindCast } from "@prisma-next/utils/casts"; | ||
@@ -3,0 +3,0 @@ //#region src/control/control-capabilities.ts |
@@ -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-DXqiWAJX.mjs"; | ||
@@ -3,0 +3,0 @@ //#region src/execution/execution-instances.d.ts |
@@ -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-7Qng7VFc.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-DMAwH52s.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-Mq7MlfKe.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, PslEnum, PslEnumValue, 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, flatPslEnums, flatPslModels, makePslNamespace, makePslNamespaceEntries, namespacePslExtensionBlocks, validateExtensionBlock }; | ||
| //# sourceMappingURL=psl-ast.d.mts.map |
+11
-9
@@ -112,3 +112,3 @@ import { blindCast } from "@prisma-next/utils/casts"; | ||
| * | ||
| * Reads from `namespace.entries`, skipping the three built-in kind keys | ||
| * Reads from `namespace.entries`, skipping the built-in kind keys | ||
| * (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain | ||
@@ -147,10 +147,12 @@ * only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`). | ||
| 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 | ||
| }); | ||
| } | ||
| } | ||
@@ -157,0 +159,0 @@ for (const [key, param] of Object.entries(descriptor.parameters)) if (param.required === true && !nodeKeys.has(key)) diagnostics.push({ |
@@ -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,IAAI;AAClC;;;;;;AAOA,SAAgB,wBACd,QACA,OACA,gBACA,iBACuE;CACvE,MAAM,YAAyE,CAAC;CAEhF,IAAI,OAAO,SAAS,GAAG;EACrB,MAAM,MAAgC,CAAC;EACvC,KAAK,MAAM,KAAK,QACd,IAAI,EAAE,QAAQ;EAEhB,UAAU,WAAW,OAAO,OAAO,GAAG;CACxC;CAE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,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\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 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 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":";;;;;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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-7Qng7VFc.mjs"; | ||
| import { PlanMeta } from "@prisma-next/contract/types"; | ||
@@ -3,0 +3,0 @@ |
+7
-7
| { | ||
| "name": "@prisma-next/framework-components", | ||
| "version": "0.13.0-dev.16", | ||
| "version": "0.13.0-dev.17", | ||
| "license": "Apache-2.0", | ||
@@ -9,6 +9,6 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/contract": "0.13.0-dev.16", | ||
| "@prisma-next/operations": "0.13.0-dev.16", | ||
| "@prisma-next/ts-render": "0.13.0-dev.16", | ||
| "@prisma-next/utils": "0.13.0-dev.16", | ||
| "@prisma-next/contract": "0.13.0-dev.17", | ||
| "@prisma-next/operations": "0.13.0-dev.17", | ||
| "@prisma-next/ts-render": "0.13.0-dev.17", | ||
| "@prisma-next/utils": "0.13.0-dev.17", | ||
| "@standard-schema/spec": "^1.1.0", | ||
@@ -18,4 +18,4 @@ "arktype": "^2.2.0" | ||
| "devDependencies": { | ||
| "@prisma-next/tsconfig": "0.13.0-dev.16", | ||
| "@prisma-next/tsdown": "0.13.0-dev.16", | ||
| "@prisma-next/tsconfig": "0.13.0-dev.17", | ||
| "@prisma-next/tsdown": "0.13.0-dev.17", | ||
| "tsdown": "0.22.1", | ||
@@ -22,0 +22,0 @@ "typescript": "5.9.3", |
@@ -10,2 +10,5 @@ export type { AuthoringPslBlockDescriptorNamespace } from '../shared/framework-authoring'; | ||
| PslExtensionBlock, | ||
| PslExtensionBlockAttribute, | ||
| PslExtensionBlockAttributeArg, | ||
| PslExtensionBlockParamBare, | ||
| PslExtensionBlockParamList, | ||
@@ -395,3 +398,3 @@ PslExtensionBlockParamOption, | ||
| * | ||
| * Reads from `namespace.entries`, skipping the three built-in kind keys | ||
| * Reads from `namespace.entries`, skipping the built-in kind keys | ||
| * (`'model'`, `'enum'`, `'compositeType'`). All remaining kind maps contain | ||
@@ -398,0 +401,0 @@ * only `PslExtensionBlock` nodes by construction (see `makePslNamespaceEntries`). |
@@ -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 @@ } |
@@ -6,2 +6,3 @@ export type { | ||
| AuthoringContributions, | ||
| AuthoringDiagnosticSink, | ||
| AuthoringEntityContext, | ||
@@ -8,0 +9,0 @@ AuthoringEntityTypeDescriptor, |
@@ -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; | ||
| } | ||
@@ -405,3 +442,3 @@ | ||
| function collectAuthoringLeafPaths( | ||
| function collectDescriptorPaths( | ||
| namespace: Readonly<Record<string, unknown>>, | ||
@@ -420,7 +457,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), | ||
| ); | ||
@@ -432,3 +465,3 @@ } | ||
| interface AuthoringLeafEntry { | ||
| interface DescriptorEntry { | ||
| readonly path: string; | ||
@@ -438,3 +471,3 @@ readonly discriminator: string; | ||
| function collectAuthoringLeafDiscriminators( | ||
| function collectDescriptorEntries( | ||
| namespace: Readonly<Record<string, unknown>>, | ||
@@ -444,4 +477,4 @@ isLeaf: (value: unknown) => boolean, | ||
| path: readonly string[] = [], | ||
| ): AuthoringLeafEntry[] { | ||
| const entries: AuthoringLeafEntry[] = []; | ||
| ): DescriptorEntry[] { | ||
| const entries: DescriptorEntry[] = []; | ||
| for (const [key, value] of Object.entries(namespace)) { | ||
@@ -490,3 +523,3 @@ const currentPath = [...path, key]; | ||
| } | ||
| entries.push(...collectAuthoringLeafDiscriminators(record, isLeaf, label, currentPath)); | ||
| entries.push(...collectDescriptorEntries(record, isLeaf, label, currentPath)); | ||
| } | ||
@@ -503,3 +536,3 @@ } | ||
| */ | ||
| function assertUniqueDiscriminators(entries: readonly AuthoringLeafEntry[], label: string): void { | ||
| function assertUniqueDiscriminators(entries: readonly DescriptorEntry[], label: string): void { | ||
| const seen = new Map<string, string>(); | ||
@@ -517,8 +550,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). | ||
| */ | ||
@@ -529,8 +593,4 @@ function assertPslBlocksHaveFactories( | ||
| ): void { | ||
| const blockEntries = collectAuthoringLeafDiscriminators( | ||
| pslBlockNamespace, | ||
| isAuthoringPslBlockDescriptor, | ||
| 'pslBlock', | ||
| ); | ||
| const entityEntries = collectAuthoringLeafDiscriminators( | ||
| const blockEntries = collectPslBlockDescriptorEntries(pslBlockNamespace); | ||
| const entityEntries = collectDescriptorEntries( | ||
| entityTypeNamespace, | ||
@@ -562,9 +622,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), | ||
| ); | ||
@@ -571,0 +631,0 @@ // Within-registry duplicate detection is handled upstream by the merge |
@@ -73,3 +73,12 @@ /** | ||
| */ | ||
| | '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'; | ||
@@ -122,10 +131,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 enum2 block). The name is the key in | ||
| * `parameters`; the interpreting consumer decides the default value. | ||
| * | ||
@@ -139,3 +151,4 @@ * These shapes are intentionally minimal. The validator and lowering refine | ||
| | PslExtensionBlockParamOption | ||
| | PslExtensionBlockParamList; | ||
| | PslExtensionBlockParamList | ||
| | PslExtensionBlockParamBare; | ||
@@ -167,2 +180,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 | ||
@@ -180,3 +225,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. | ||
@@ -188,3 +238,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;;;;;;;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,sDAEU,UAAA,cAAwB,UAAA;EFS7C;EAAA,SEJK,EAAA,EAAI,EAAA;EFKb;EAAA,SEHS,aAAA,GAAgB,OAAA;EFIzB;EEFA,MAAA,CAAO,KAAA,EAAO,MAAA,EAAQ,GAAA,EAAK,gBAAA,GAAmB,OAAA,CAAQ,KAAA;EFEjC;EEArB,MAAA,CAAO,IAAA,EAAM,KAAA,EAAO,GAAA,EAAK,gBAAA,GAAmB,OAAA,CAAQ,MAAA;EFChC;EECpB,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 { 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,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,UA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AO,QAAQ,OAAO,GAAG;CAC3B;CACA,iCAAiC,YAAY,WAAW,MAAM,IAAI;CAClE,OAAO,8BAA8B,WAAW,OAAO,UAAU,IAAI;AACvE;AAEA,SAAgB,gCACd,YACA,MAYA;CACA,OAAO;EACL,YAAY,oCAAoC,WAAW,QAAQ,IAAI;EACvE,UAAU,WAAW,OAAO,YAAY;EACxC,GAAG,UACD,WACA,WAAW,OAAO,YAAY,KAAA,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 { 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;;;;;;;;;AAImB;AAGnB;;;AAHmB;;;;;AAMA;AAGnB;;;;;;;KAnBY,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,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,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,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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AA,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;AAAA;AAAA,KAGJ,eAAA,GAAkB,uBAAA,GAA0B,sBAAsB;AAAA,KAElE,kBAAA;AAAA,UAEK,8BAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,yBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA;EAAA,SACA,IAAA,EAAM,OAAO;AAAA;AAAA,KAGZ,oBAAA,GAAuB,8BAAA,GAAiC,yBAAyB;AAAA,UAE5E,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA,WAAe,oBAAA;EAAA,SACf,IAAA,EAAM,OAAO;AAAA;AAAA,UAGP,YAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA,EAAQ,kBAAA;EAAA,SACR,IAAA;EAAA,SACA,IAAA,WAAe,oBAAA;EAAA,SACf,IAAA,E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