@prisma-next/sql-contract
Advanced tools
| import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-C4XInPlX.mjs"; | ||
| import { type } from "arktype"; | ||
| //#region src/ir/storage-entry-schemas.ts | ||
| const literalKindSchema = type("'literal'"); | ||
| const functionKindSchema = type("'function'"); | ||
| const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'"); | ||
| const ColumnDefaultLiteralSchema = type.declare().type({ | ||
| kind: literalKindSchema, | ||
| value: "string | number | boolean | null | unknown[] | Record<string, unknown>" | ||
| }); | ||
| const ColumnDefaultFunctionSchema = type.declare().type({ | ||
| kind: functionKindSchema, | ||
| expression: "string" | ||
| }); | ||
| const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema); | ||
| const StorageValueSetRefSchema = type({ | ||
| plane: "'storage'", | ||
| namespaceId: "string", | ||
| entityKind: "'valueSet'", | ||
| entityName: "string", | ||
| "spaceId?": "string" | ||
| }); | ||
| const StorageColumnSchema = type({ | ||
| "+": "reject", | ||
| nativeType: "string", | ||
| codecId: "string", | ||
| nullable: "boolean", | ||
| "many?": "boolean", | ||
| "typeParams?": "Record<string, unknown>", | ||
| "typeRef?": "string", | ||
| "default?": ColumnDefaultSchema, | ||
| "control?": ControlPolicySchema, | ||
| "valueSet?": StorageValueSetRefSchema | ||
| }).narrow((col, ctx) => { | ||
| if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both"); | ||
| return true; | ||
| }); | ||
| /** | ||
| * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`. | ||
| * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an | ||
| * ordered `values` array of codec-encoded permitted values. | ||
| */ | ||
| const StorageValueSetSchema = type({ | ||
| kind: "'valueSet'", | ||
| values: type("string | number | boolean | null | unknown[] | Record<string, unknown>").array().readonly() | ||
| }); | ||
| const PrimaryKeySchema = type.declare().type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string" | ||
| }); | ||
| const UniqueConstraintSchema = type.declare().type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string" | ||
| }); | ||
| const IndexSchema = type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string", | ||
| "type?": "string", | ||
| "options?": "Record<string, unknown>" | ||
| }); | ||
| const ForeignKeyReferenceSchema = type({ | ||
| "+": "reject", | ||
| namespaceId: "string", | ||
| tableName: "string", | ||
| columns: type.string.array().readonly(), | ||
| "spaceId?": "string" | ||
| }); | ||
| const ForeignKeySourceSchema = type({ | ||
| "+": "reject", | ||
| namespaceId: "string", | ||
| tableName: "string", | ||
| columns: type.string.array().readonly() | ||
| }); | ||
| const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'"); | ||
| const ForeignKeySchema = type.declare().type({ | ||
| source: ForeignKeySourceSchema, | ||
| target: ForeignKeyReferenceSchema, | ||
| "name?": "string", | ||
| "onDelete?": ReferentialActionSchema, | ||
| "onUpdate?": ReferentialActionSchema, | ||
| constraint: "boolean", | ||
| index: "boolean" | ||
| }); | ||
| const CheckConstraintSchema = type({ | ||
| "+": "reject", | ||
| name: "string", | ||
| column: "string", | ||
| valueSet: StorageValueSetRefSchema | ||
| }); | ||
| const StorageTableSchema = type({ | ||
| "+": "reject", | ||
| columns: type({ "[string]": StorageColumnSchema }), | ||
| "primaryKey?": PrimaryKeySchema, | ||
| uniques: UniqueConstraintSchema.array().readonly(), | ||
| indexes: IndexSchema.array().readonly(), | ||
| foreignKeys: ForeignKeySchema.array().readonly(), | ||
| "control?": ControlPolicySchema, | ||
| "checks?": CheckConstraintSchema.array().readonly() | ||
| }); | ||
| //#endregion | ||
| //#region src/entity-kinds.ts | ||
| const tableEntityKind = { | ||
| kind: "table", | ||
| schema: StorageTableSchema, | ||
| construct: (input) => new StorageTable(input) | ||
| }; | ||
| const valueSetEntityKind = { | ||
| kind: "valueSet", | ||
| schema: StorageValueSetSchema, | ||
| construct: (input) => new StorageValueSet(input) | ||
| }; | ||
| /** | ||
| * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in | ||
| * `table` and `valueSet` kinds plus any target `packKinds`. This builds the | ||
| * lookup table — it does not touch contract data. `hydrateNamespaceEntities` | ||
| * later consumes this registry to turn a namespace's raw entries into IR | ||
| * instances, and `createSqlContractSchema` derives validation from the same | ||
| * registry. Throws on a duplicate kind. | ||
| */ | ||
| function composeSqlEntityKinds(packKinds = []) { | ||
| const kinds = new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]); | ||
| for (const descriptor of packKinds) { | ||
| if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`); | ||
| kinds.set(descriptor.kind, descriptor); | ||
| } | ||
| return kinds; | ||
| } | ||
| //#endregion | ||
| export { ColumnDefaultFunctionSchema as a, ForeignKeyReferenceSchema as c, IndexSchema as d, ReferentialActionSchema as f, CheckConstraintSchema as i, ForeignKeySchema as l, StorageValueSetSchema as m, tableEntityKind as n, ColumnDefaultLiteralSchema as o, StorageTableSchema as p, valueSetEntityKind as r, ColumnDefaultSchema as s, composeSqlEntityKinds as t, ForeignKeySourceSchema as u }; | ||
| //# sourceMappingURL=entity-kinds-CHiydmat.mjs.map |
| {"version":3,"file":"entity-kinds-CHiydmat.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'many?': 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw new Error(\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC5C,MAAM,sBAAsB,KAAK,mDAAmD;AAEpF,MAAa,6BAA6B,KAAK,QAA8B,CAAC,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;AACT,CAAC;AAED,MAAa,8BAA8B,KAAK,QAA+B,CAAC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;AACd,CAAC;AAED,MAAa,sBAAsB,2BAA2B,GAAG,2BAA2B;AAE5F,MAAM,2BAA2B,KAAK;CACpC,OAAO;CACP,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,YAAY;AACd,CAAC;AAED,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,SAAS;CACT,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,aAAa;AACf,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ;CACtB,IAAI,IAAI,eAAe,KAAA,KAAa,IAAI,YAAY,KAAA,GAClD,OAAO,IAAI,OAAO,sDAAsD;CAE1E,OAAO;AACT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AC,SAAS;CAC/C,YAAY;CACZ,WAAW,sBAAsB,MAAM,CAAC,CAAC,SAAS;AACpD,CAAC;;;ACxHD,MAAa,kBAAyE;CACpF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;AAEA,MAAa,qBAAkF;CAC7F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,gBAAgB,KAAK;AACjD;;;;;;;;;AAUA,SAAgB,sBACd,YAAgD,CAAC,GACH;CAC9C,MAAM,QAAQ,IAAI,IAAqC,CACrD,CAAC,SAAS,eAAe,GACzB,CAAC,YAAY,kBAAkB,CACjC,CAAC;CACD,KAAK,MAAM,cAAc,WAAW;EAClC,IAAI,MAAM,IAAI,WAAW,IAAI,GAC3B,MAAM,IAAI,MACR,iDAAiD,WAAW,KAAK,0CACnE;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"} |
| import { o as SqlNode } from "./foreign-key-BATxB95l.mjs"; | ||
| import { i as StorageTable, t as StorageValueSet } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir"; | ||
| import { StorageHashBase } from "@prisma-next/contract/types"; | ||
| import { AuthoringContributions } from "@prisma-next/framework-components/authoring"; | ||
| //#region src/ir/storage-type-instance.d.ts | ||
| /** | ||
| * Sentinel kind for the legacy codec-triple shape persisted under | ||
| * `SqlStorage.types`. Plain JSON-clean object literals carry this | ||
| * discriminator so the polymorphic slot dispatch can route them down | ||
| * the codec path while target-specific IR class instances (e.g. the | ||
| * Postgres enum class) keep their own narrower `kind` literal. | ||
| */ | ||
| declare const CODEC_INSTANCE_KIND: "codec-instance"; | ||
| /** | ||
| * Structural sub-interface of {@link StorageType} for codec-typed entries | ||
| * in `SqlStorage.types`. These are plain object literals — there is no | ||
| * runtime IR class, the JSON envelope round-trips through the slot | ||
| * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch | ||
| * key that distinguishes codec-typed entries from any class-instance | ||
| * kinds a target pack contributes to the polymorphic slot. | ||
| */ | ||
| interface StorageTypeInstance extends StorageType { | ||
| readonly kind: typeof CODEC_INSTANCE_KIND; | ||
| readonly codecId: string; | ||
| readonly nativeType: string; | ||
| readonly typeParams: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Construction-time input for a codec-triple entry. Symmetric with the | ||
| * structural runtime shape minus the `kind` discriminator — callers may | ||
| * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on. | ||
| * `typeParams` may be omitted on input; the constructor normalises a | ||
| * missing value to `{}` so the in-memory shape is always present. | ||
| */ | ||
| interface StorageTypeInstanceInput { | ||
| readonly codecId: string; | ||
| readonly nativeType: string; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Stamp the codec-instance `kind` discriminator on a caller-supplied | ||
| * codec triple. Idempotent: input that already carries the discriminator | ||
| * passes through unchanged. Missing `typeParams` is normalised to `{}`. | ||
| */ | ||
| declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance; | ||
| /** | ||
| * Type-guard for codec-typed entries on the polymorphic | ||
| * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from | ||
| * any class-instance kinds a target pack contributes. | ||
| */ | ||
| declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance; | ||
| //#endregion | ||
| //#region src/ir/sql-storage.d.ts | ||
| /** | ||
| * Polymorphic value type for document-scoped `SqlStorage.types` entries | ||
| * (codec aliases / parameterised native type registrations). | ||
| * | ||
| * Postgres native enum registrations live under the postgres-specific | ||
| * `entries.type` slot on `PostgresSchema` (target layer), not here. | ||
| */ | ||
| type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput; | ||
| interface SqlNamespaceInput { | ||
| readonly id: string; | ||
| readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>; | ||
| } | ||
| /** | ||
| * Target-supplied factory that materializes a `Namespace` from a SQL | ||
| * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`). | ||
| */ | ||
| type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace; | ||
| /** | ||
| * SQL-family extension of the framework `AuthoringContributions`. SQL target | ||
| * packs add a `createNamespace` factory so the PSL/TS authoring paths can | ||
| * materialize namespaces (and merge lowered extension-block entities) without | ||
| * each consumer re-specifying it. The factory is SQL-specific, so it lives here | ||
| * rather than on the framework `AuthoringContributions` base. | ||
| */ | ||
| interface SqlAuthoringContributions extends AuthoringContributions { | ||
| readonly createNamespace?: SqlNamespaceFactory; | ||
| } | ||
| /** | ||
| * Narrows framework `AuthoringContributions` to the SQL-family shape by testing | ||
| * for the SQL-specific `createNamespace` capability. | ||
| */ | ||
| declare function isSqlAuthoringContributions(authoring: AuthoringContributions | undefined): authoring is SqlAuthoringContributions; | ||
| interface SqlStorageInput<THash extends string = string> { | ||
| readonly storageHash: StorageHashBase<THash>; | ||
| readonly types?: Record<string, SqlStorageTypeEntry>; | ||
| readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>; | ||
| } | ||
| /** | ||
| * SQL Contract IR root node for the `storage` field. | ||
| * | ||
| * Single concrete family-shared class — both Postgres and SQLite | ||
| * consume this class today. Per-target storage subclasses are | ||
| * introduced when each target's namespace shape earns its | ||
| * target-specific concretion (target-specific derived fields, | ||
| * target-specific storage extensions). | ||
| * | ||
| * Honours the framework `Storage` interface: every SQL IR carries a | ||
| * `namespaces` map keyed by namespace id. Callers must supply fully | ||
| * constructed `Namespace` instances — construction discipline lives | ||
| * in the authoring builders and deserializer hydration paths. | ||
| * | ||
| * The constructor normalises optional `types` into class instances. | ||
| * `types` is polymorphic per Decision 18 Option B: codec-triple inputs | ||
| * are stamped with `kind: 'codec-instance'`; hydration of raw JSON | ||
| * class-instance entries (carrying their narrower `kind` literal) is | ||
| * the per-target serializer's responsibility (so the family base does | ||
| * not import target-specific subclasses). | ||
| */ | ||
| /** | ||
| * The typed `entries` shape for SQL family namespaces. The open dictionary | ||
| * is intersected with optional known-kind maps so that `ns.entries.table` | ||
| * and `ns.entries.valueSet` resolve without a cast, while unknown pack- | ||
| * contributed kinds remain valid (the `Record` part allows any string key). | ||
| */ | ||
| type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & { | ||
| readonly table?: Readonly<Record<string, StorageTable>>; | ||
| readonly valueSet?: Readonly<Record<string, StorageValueSet>>; | ||
| }; | ||
| /** | ||
| * Structural interface for SQL family namespaces. Generated `.d.ts` contract | ||
| * types satisfy this structurally (no prototype methods). The runtime | ||
| * abstract class `SqlNamespaceBase` extends this. | ||
| * | ||
| * `qualifyTable` is optional so JSON-shaped contract types (which carry no | ||
| * methods) are accepted where `SqlNamespace` is required. Hydrated | ||
| * `SqlNamespaceBase` instances always have it. | ||
| */ | ||
| interface SqlNamespace { | ||
| readonly kind: string; | ||
| readonly id: string; | ||
| readonly entries: SqlNamespaceEntries; | ||
| qualifyTable?(tableName: string): string; | ||
| } | ||
| /** | ||
| * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`, | ||
| * `SqliteDatabase`, …) extend this — it is never instantiated directly. | ||
| * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]` | ||
| * addresses any entity. | ||
| */ | ||
| declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace { | ||
| abstract readonly id: string; | ||
| abstract readonly entries: SqlNamespaceEntries; | ||
| abstract qualifyTable(tableName: string): string; | ||
| } | ||
| /** | ||
| * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks | ||
| * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it | ||
| * survives duplicate-module boundaries (e.g. dist e2e where the target and | ||
| * the family carry separate copies of `@prisma-next/framework-components`). | ||
| * | ||
| * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`, | ||
| * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput` | ||
| * objects (`{ id, entries }`) do not. | ||
| */ | ||
| declare function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase; | ||
| declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage { | ||
| readonly storageHash: StorageHashBase<THash>; | ||
| readonly namespaces: Readonly<Record<string, SqlNamespace>>; | ||
| readonly types?: Readonly<Record<string, StorageTypeInstance>>; | ||
| constructor(input: SqlStorageInput<THash>); | ||
| } | ||
| //#endregion | ||
| export { SqlNamespaceFactory as a, SqlStorageInput as c, isSqlAuthoringContributions as d, CODEC_INSTANCE_KIND as f, toStorageTypeInstance as g, isStorageTypeInstance as h, SqlNamespaceEntries as i, SqlStorageTypeEntry as l, StorageTypeInstanceInput as m, SqlNamespace as n, SqlNamespaceInput as o, StorageTypeInstance as p, SqlNamespaceBase as r, SqlStorage as s, SqlAuthoringContributions as t, isMaterializedSqlNamespace as u }; | ||
| //# sourceMappingURL=sql-storage-Dc1Dy3Vb.d.mts.map |
| {"version":3,"file":"sql-storage-Dc1Dy3Vb.d.mts","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;;;;;;;AASA;cAAa,mBAAA;;;AAA+C;AAU5D;;;;;UAAiB,mBAAA,SAA4B,WAAA;EAAA,SAClC,IAAA,SAAa,mBAAA;EAAA,SACb,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,EAAY,MAAA;AAAA;;;;;;AAAM;AAU7B;UAAiB,wBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;;AAAA;AAQ9B;iBAAgB,qBAAA,CAAsB,KAAA,EAAO,wBAAA,GAA2B,mBAAmB;;;;;;iBAc3E,qBAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,mBAAmB;;;AAjDnF;;;;AAA4D;AAU5D;;AAVA,KCiBY,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,iBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe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,mBAAA;cAErC,KAAA,EAAO,eAAA,CAAgB,KAAA;AAAA"} |
| import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir"; | ||
| import { asNamespaceId } from "@prisma-next/contract/types"; | ||
| //#region src/ir/sql-node.ts | ||
| /** | ||
| * SQL family IR node base. Carries the family-level `kind` discriminator | ||
| * `'sql'` and inherits the framework's `freezeNode` affordance. | ||
| * | ||
| * Single family-level discriminator (not per-leaf) reflects the fact that | ||
| * SQL IR has no polymorphic dispatch today — verifiers and serializers | ||
| * walk by structural position (`storage.tables[name].columns[name]`), | ||
| * not by inspecting `kind`. The abstract bar for per-leaf discriminators | ||
| * isn't earned until a future polymorphic consumer arrives. | ||
| * | ||
| * `kind` is installed as a non-enumerable own property on every instance, | ||
| * which keeps three things clean simultaneously: | ||
| * | ||
| * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope | ||
| * shape (no `kind` field), so emitted contract.json files and the | ||
| * `validateSqlContractFully` arktype schemas stay unchanged. | ||
| * - Test assertions that use `toEqual({...})` against the pre-lift flat | ||
| * shape continue to pass — only enumerable own properties are | ||
| * compared. | ||
| * - Direct access (`node.kind`) and runtime narrowing | ||
| * (`if (node.kind === 'sql')`) still work, so future polymorphic | ||
| * dispatch can begin reading `kind` without a runtime change. | ||
| * | ||
| * Future per-leaf overrides land cleanly: a class that gains a | ||
| * polymorphic-dispatch consumer (e.g. an enum type instance walked | ||
| * alongside other types) overrides `kind` with its narrower literal | ||
| * at that leaf level. Per-leaf overrides will use enumerable kind | ||
| * (matching the Mongo per-class-discriminator precedent) because they | ||
| * encode dispatch-relevant information that callers need to see in | ||
| * JSON envelopes; the family-level `'sql'` is uniform across all SQL | ||
| * IR and carries no dispatch-relevant information. | ||
| */ | ||
| var SqlNode = class extends IRNodeBase { | ||
| kind; | ||
| constructor() { | ||
| super(); | ||
| Object.defineProperty(this, "kind", { | ||
| value: "sql", | ||
| writable: false, | ||
| enumerable: false, | ||
| configurable: true | ||
| }); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/check-constraint.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level check constraint that restricts | ||
| * a column to the permitted values of a value-set. | ||
| * | ||
| * The constraint is **structured** (names a column and a value-set | ||
| * reference), not a raw SQL expression. Each target renders its own DDL | ||
| * from the structured form, keeping the contract target-agnostic. | ||
| * | ||
| * Construction is idempotent: passing an existing `CheckConstraint` | ||
| * instance as input produces a new instance with identical fields. | ||
| * The constructor does not use `instanceof` for input discrimination — | ||
| * it reads plain named properties, which is sufficient since | ||
| * `CheckConstraintInput` is a structural type. | ||
| */ | ||
| var CheckConstraint = class extends SqlNode { | ||
| name; | ||
| column; | ||
| valueSet; | ||
| constructor(input) { | ||
| super(); | ||
| this.name = input.name; | ||
| this.column = input.column; | ||
| this.valueSet = input.valueSet; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/foreign-key-reference.ts | ||
| /** | ||
| * SQL Contract IR node for one side (source or target) of a foreign-key | ||
| * declaration. Carries the full coordinate: namespace, table, and columns. | ||
| * | ||
| * Cross-space discrimination is based on `spaceId` presence: absent means | ||
| * local (same contract-space); present means cross-space (the referenced | ||
| * table lives in the contract-space identified by `spaceId`). | ||
| * | ||
| * For local references `spaceId` is absent from JSON, keeping the serialized | ||
| * shape byte-identical to contracts authored before cross-space support was | ||
| * added. For cross-space references `spaceId` appears in JSON so round-trips | ||
| * are lossless. | ||
| * | ||
| * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir` | ||
| * as the sentinel `namespaceId` for single-namespace (unbound) references. | ||
| */ | ||
| var ForeignKeyReference = class extends SqlNode { | ||
| namespaceId; | ||
| tableName; | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.namespaceId = asNamespaceId(input.namespaceId); | ||
| this.tableName = input.tableName; | ||
| this.columns = input.columns; | ||
| if (input.spaceId !== void 0) this.spaceId = input.spaceId; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/foreign-key.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level foreign-key declaration. | ||
| * | ||
| * Each FK carries explicit `source` and `target` {@link ForeignKeyReference} | ||
| * coordinates (namespace, table, columns). For single-namespace contracts the | ||
| * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides. | ||
| * | ||
| * The nested references are normalised to {@link ForeignKeyReference} | ||
| * instances inside the constructor so downstream walks see a uniform AST | ||
| * regardless of whether the input was a JSON literal or an already-constructed | ||
| * class instance. | ||
| */ | ||
| var ForeignKey = class extends SqlNode { | ||
| source; | ||
| target; | ||
| constraint; | ||
| index; | ||
| constructor(input) { | ||
| super(); | ||
| this.source = input.source instanceof ForeignKeyReference ? input.source : new ForeignKeyReference(input.source); | ||
| this.target = input.target instanceof ForeignKeyReference ? input.target : new ForeignKeyReference(input.target); | ||
| this.constraint = input.constraint; | ||
| this.index = input.index; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| if (input.onDelete !== void 0) this.onDelete = input.onDelete; | ||
| if (input.onUpdate !== void 0) this.onUpdate = input.onUpdate; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/primary-key.ts | ||
| /** | ||
| * SQL Contract IR node for a table's primary-key constraint. | ||
| */ | ||
| var PrimaryKey = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/sql-index.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level secondary index. | ||
| * | ||
| * Note that this class shadows the global TypeScript `Index` lib type | ||
| * at the family-shared name; consumer files that need both should | ||
| * alias one (e.g. | ||
| * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`). | ||
| */ | ||
| var Index = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| if (input.type !== void 0) this.type = input.type; | ||
| if (input.options !== void 0) this.options = input.options; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/storage-column.ts | ||
| /** | ||
| * SQL Contract IR node for a single column entry in `StorageTable.columns`. | ||
| * | ||
| * Single concrete family-shared class — every SQL target reads the | ||
| * same column shape today, so there is no per-target subclass. The | ||
| * class type accepts any caller that constructs via | ||
| * `new StorageColumn(input)`; literal construction sites must pass | ||
| * through the constructor or the family-base hydration walker. | ||
| * | ||
| * The column's `name` is not on the class — columns are keyed by name | ||
| * in the parent `StorageTable.columns: Record<string, StorageColumn>` | ||
| * map, so a `name` field would be redundant with the key. | ||
| */ | ||
| var StorageColumn = class extends SqlNode { | ||
| nativeType; | ||
| codecId; | ||
| nullable; | ||
| constructor(input) { | ||
| super(); | ||
| this.nativeType = input.nativeType; | ||
| this.codecId = input.codecId; | ||
| this.nullable = input.nullable; | ||
| if (input.many !== void 0) this.many = input.many; | ||
| if (input.typeParams !== void 0) this.typeParams = input.typeParams; | ||
| if (input.typeRef !== void 0) this.typeRef = input.typeRef; | ||
| if (input.default !== void 0) this.default = input.default; | ||
| if (input.control !== void 0) this.control = input.control; | ||
| if (input.valueSet !== void 0) this.valueSet = input.valueSet; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/unique-constraint.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level unique constraint. | ||
| */ | ||
| var UniqueConstraint = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/storage-table.ts | ||
| /** | ||
| * SQL Contract IR node for a single table entry in a namespace's | ||
| * `tables` map. | ||
| * | ||
| * The constructor normalises nested IR-class fields (columns, primary | ||
| * key, uniques, indexes, foreign keys) into the appropriate class | ||
| * instances so downstream walks see a uniform AST regardless of whether | ||
| * the input was a JSON literal or an already-constructed class. | ||
| * | ||
| * The table's `name` is not on the class — tables are keyed by name in | ||
| * the parent namespace's `tables: Record<string, StorageTable>` map. | ||
| */ | ||
| var StorageTable = class StorageTable extends SqlNode { | ||
| columns; | ||
| uniques; | ||
| indexes; | ||
| foreignKeys; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([name, col]) => [name, col instanceof StorageColumn ? col : new StorageColumn(col)]))); | ||
| if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey); | ||
| this.uniques = Object.freeze(input.uniques.map((u) => u instanceof UniqueConstraint ? u : new UniqueConstraint(u))); | ||
| this.indexes = Object.freeze(input.indexes.map((i) => i instanceof Index ? i : new Index(i))); | ||
| this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof ForeignKey ? fk : new ForeignKey(fk))); | ||
| if (input.control !== void 0) this.control = input.control; | ||
| if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc))); | ||
| freezeNode(this); | ||
| } | ||
| /** | ||
| * Runtime guard that a namespace `table` entry is really a `StorageTable`. | ||
| * The compiler already types the entry as `StorageTable`, but a | ||
| * freshly-deserialized contract may carry plain JSON at that slot until | ||
| * hydration; this duck-types the structural shape. Accepts `undefined` so | ||
| * optional-chained entry lookups pass straight through. | ||
| */ | ||
| static is(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return "columns" in value && "uniques" in value && "indexes" in value && "foreignKeys" in value; | ||
| } | ||
| static assert(value, coordinate) { | ||
| if (!StorageTable.is(value)) throw new Error(`Expected a StorageTable at ${coordinate}`); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/storage-value-set.ts | ||
| /** | ||
| * SQL Contract IR node for a value-set entry in a namespace's `valueSet` | ||
| * map (`SqlNamespace.entries.valueSet`). | ||
| * | ||
| * A value-set records the ordered set of permitted codec-encoded values for | ||
| * an enum-like column restriction. It does not carry a `codecId` — the | ||
| * column that references it already holds the codec; the value-set holds | ||
| * only the permitted values. | ||
| * | ||
| * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope | ||
| * carries the discriminator and the serializer hydration walker can | ||
| * dispatch on it. This follows the per-leaf enumerable-kind convention | ||
| * established in the SQL-node comment (future polymorphic dispatch on | ||
| * namespace entries needs the discriminator in JSON). | ||
| * | ||
| * The entry's name is not on the class — value-sets are keyed by name in | ||
| * the parent namespace's `valueSet: Record<string, StorageValueSet>` map. | ||
| */ | ||
| var StorageValueSet = class extends SqlNode { | ||
| kind = "valueSet"; | ||
| values; | ||
| constructor(input) { | ||
| super(); | ||
| this.values = Object.freeze([...input.values]); | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| function isStorageValueSet(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return "kind" in value && value.kind === "valueSet" && "values" in value; | ||
| } | ||
| //#endregion | ||
| export { StorageColumn as a, ForeignKey as c, SqlNode as d, UniqueConstraint as i, ForeignKeyReference as l, isStorageValueSet as n, Index as o, StorageTable as r, PrimaryKey as s, StorageValueSet as t, CheckConstraint as u }; | ||
| //# sourceMappingURL=storage-value-set-C4XInPlX.mjs.map |
| {"version":3,"file":"storage-value-set-C4XInPlX.mjs","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. StorageValueSet)\n // can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly many?: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly many?: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.many !== undefined) this.many = input.many;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n\n /**\n * Runtime guard that a namespace `table` entry is really a `StorageTable`.\n * The compiler already types the entry as `StorageTable`, but a\n * freshly-deserialized contract may carry plain JSON at that slot until\n * hydration; this duck-types the structural shape. Accepts `undefined` so\n * optional-chained entry lookups pass straight through.\n */\n static is(value: StorageTable | undefined): value is StorageTable {\n if (typeof value !== 'object' || value === null) return false;\n return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value;\n }\n\n static assert(\n value: StorageTable | undefined,\n coordinate: string,\n ): asserts value is StorageTable {\n if (!StorageTable.is(value)) {\n throw new Error(`Expected a StorageTable at ${coordinate}`);\n }\n }\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'valueSet';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly JsonValue[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'valueSet' as const;\n readonly values: readonly JsonValue[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n\nexport function isStorageValueSet(value: unknown): value is StorageValueSet {\n if (typeof value !== 'object' || value === null) return false;\n return 'kind' in value && value.kind === 'valueSet' && 'values' in value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAsB,UAAtB,cAAsC,WAAW;CAC/C;CAEA,cAAc;EACZ,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GAMZ,cAAc;EAChB,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;ACtBA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C;CACA;CACA;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,SAAS,MAAM;EACpB,KAAK,WAAW,MAAM;EACtB,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;;;;ACHA,IAAa,sBAAb,cAAyC,QAAQ;CAC/C;CACA;CACA;CAGA,YAAY,OAAiC;EAC3C,MAAM;EACN,KAAK,cAAc,cAAc,MAAM,WAAW;EAClD,KAAK,YAAY,MAAM;EACvB,KAAK,UAAU,MAAM;EACrB,IAAI,MAAM,YAAY,KAAA,GAAW,KAAK,UAAU,MAAM;EACtD,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;ACtBA,IAAa,aAAb,cAAgC,QAAQ;CACtC;CACA;CACA;CACA;CAKA,YAAY,OAAwB;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BAAgB,EAAE,CAAC,CAAC;EAE/E,WAAW,IAAI;CACjB;;;;;;;;CASA,OAAO,GAAG,OAAwD;EAChE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,OAAO,aAAa,SAAS,aAAa,SAAS,aAAa,SAAS,iBAAiB;CAC5F;CAEA,OAAO,OACL,OACA,YAC+B;EAC/B,IAAI,CAAC,aAAa,GAAG,KAAK,GACxB,MAAM,IAAI,MAAM,8BAA8B,YAAY;CAE9D;AACF;;;;;;;;;;;;;;;;;;;;;AC1DA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C,OAAyB;CACzB;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;EAC7C,WAAW,IAAI;CACjB;AACF;AAEA,SAAgB,kBAAkB,OAA0C;CAC1E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,OAAO,UAAU,SAAS,MAAM,SAAS,cAAc,YAAY;AACrE"} |
| import { n as ForeignKeyInput, o as SqlNode, t as ForeignKey } from "./foreign-key-BATxB95l.mjs"; | ||
| import { ColumnDefault, ControlPolicy, JsonValue, ValueSetRef } from "@prisma-next/contract/types"; | ||
| //#region src/ir/check-constraint.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link CheckConstraint}. | ||
| * Mirrors the on-disk storage JSON envelope so the serializer hydration | ||
| * walker can hand a validated literal straight to `new`. | ||
| */ | ||
| interface CheckConstraintInput { | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly valueSet: ValueSetRef; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level check constraint that restricts | ||
| * a column to the permitted values of a value-set. | ||
| * | ||
| * The constraint is **structured** (names a column and a value-set | ||
| * reference), not a raw SQL expression. Each target renders its own DDL | ||
| * from the structured form, keeping the contract target-agnostic. | ||
| * | ||
| * Construction is idempotent: passing an existing `CheckConstraint` | ||
| * instance as input produces a new instance with identical fields. | ||
| * The constructor does not use `instanceof` for input discrimination — | ||
| * it reads plain named properties, which is sufficient since | ||
| * `CheckConstraintInput` is a structural type. | ||
| */ | ||
| declare class CheckConstraint extends SqlNode { | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly valueSet: ValueSetRef; | ||
| constructor(input: CheckConstraintInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/primary-key.d.ts | ||
| interface PrimaryKeyInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table's primary-key constraint. | ||
| */ | ||
| declare class PrimaryKey extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| constructor(input: PrimaryKeyInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-index.d.ts | ||
| interface IndexInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level secondary index. | ||
| * | ||
| * Note that this class shadows the global TypeScript `Index` lib type | ||
| * at the family-shared name; consumer files that need both should | ||
| * alias one (e.g. | ||
| * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`). | ||
| */ | ||
| declare class Index extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| constructor(input: IndexInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-column.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link StorageColumn}. Mirrors | ||
| * the on-disk storage JSON envelope exactly so the family-base | ||
| * serializer's hydration walker can hand an arktype-validated literal | ||
| * straight to `new`. | ||
| * | ||
| * `typeParams` and `typeRef` remain mutually exclusive (one or the | ||
| * other, not both); the constructor preserves whichever caller-side | ||
| * choice the input encodes. | ||
| */ | ||
| interface StorageColumnInput { | ||
| readonly nativeType: string; | ||
| readonly codecId: string; | ||
| readonly nullable: boolean; | ||
| readonly many?: boolean; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| readonly typeRef?: string; | ||
| readonly default?: ColumnDefault; | ||
| readonly control?: ControlPolicy; | ||
| readonly valueSet?: ValueSetRef; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a single column entry in `StorageTable.columns`. | ||
| * | ||
| * Single concrete family-shared class — every SQL target reads the | ||
| * same column shape today, so there is no per-target subclass. The | ||
| * class type accepts any caller that constructs via | ||
| * `new StorageColumn(input)`; literal construction sites must pass | ||
| * through the constructor or the family-base hydration walker. | ||
| * | ||
| * The column's `name` is not on the class — columns are keyed by name | ||
| * in the parent `StorageTable.columns: Record<string, StorageColumn>` | ||
| * map, so a `name` field would be redundant with the key. | ||
| */ | ||
| declare class StorageColumn extends SqlNode { | ||
| readonly nativeType: string; | ||
| readonly codecId: string; | ||
| readonly nullable: boolean; | ||
| readonly many?: boolean; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| readonly typeRef?: string; | ||
| readonly default?: ColumnDefault; | ||
| readonly control?: ControlPolicy; | ||
| readonly valueSet?: ValueSetRef; | ||
| constructor(input: StorageColumnInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/unique-constraint.d.ts | ||
| interface UniqueConstraintInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level unique constraint. | ||
| */ | ||
| declare class UniqueConstraint extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| constructor(input: UniqueConstraintInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-table.d.ts | ||
| interface StorageTableInput { | ||
| readonly columns: Record<string, StorageColumn | StorageColumnInput>; | ||
| readonly primaryKey?: PrimaryKey | PrimaryKeyInput; | ||
| readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>; | ||
| readonly indexes: ReadonlyArray<Index | IndexInput>; | ||
| readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>; | ||
| readonly control?: ControlPolicy; | ||
| readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a single table entry in a namespace's | ||
| * `tables` map. | ||
| * | ||
| * The constructor normalises nested IR-class fields (columns, primary | ||
| * key, uniques, indexes, foreign keys) into the appropriate class | ||
| * instances so downstream walks see a uniform AST regardless of whether | ||
| * the input was a JSON literal or an already-constructed class. | ||
| * | ||
| * The table's `name` is not on the class — tables are keyed by name in | ||
| * the parent namespace's `tables: Record<string, StorageTable>` map. | ||
| */ | ||
| declare class StorageTable extends SqlNode { | ||
| readonly columns: Readonly<Record<string, StorageColumn>>; | ||
| readonly uniques: ReadonlyArray<UniqueConstraint>; | ||
| readonly indexes: ReadonlyArray<Index>; | ||
| readonly foreignKeys: ReadonlyArray<ForeignKey>; | ||
| readonly primaryKey?: PrimaryKey; | ||
| readonly control?: ControlPolicy; | ||
| readonly checks?: ReadonlyArray<CheckConstraint>; | ||
| constructor(input: StorageTableInput); | ||
| /** | ||
| * Runtime guard that a namespace `table` entry is really a `StorageTable`. | ||
| * The compiler already types the entry as `StorageTable`, but a | ||
| * freshly-deserialized contract may carry plain JSON at that slot until | ||
| * hydration; this duck-types the structural shape. Accepts `undefined` so | ||
| * optional-chained entry lookups pass straight through. | ||
| */ | ||
| static is(value: StorageTable | undefined): value is StorageTable; | ||
| static assert(value: StorageTable | undefined, coordinate: string): asserts value is StorageTable; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-value-set.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link StorageValueSet}. | ||
| * Mirrors the on-disk storage JSON envelope so the serializer hydration | ||
| * walker can hand a validated literal straight to `new`. | ||
| */ | ||
| interface StorageValueSetInput { | ||
| readonly kind: 'valueSet'; | ||
| /** Ordered permitted values, codec-encoded. Declaration order is preserved. */ | ||
| readonly values: readonly JsonValue[]; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a value-set entry in a namespace's `valueSet` | ||
| * map (`SqlNamespace.entries.valueSet`). | ||
| * | ||
| * A value-set records the ordered set of permitted codec-encoded values for | ||
| * an enum-like column restriction. It does not carry a `codecId` — the | ||
| * column that references it already holds the codec; the value-set holds | ||
| * only the permitted values. | ||
| * | ||
| * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope | ||
| * carries the discriminator and the serializer hydration walker can | ||
| * dispatch on it. This follows the per-leaf enumerable-kind convention | ||
| * established in the SQL-node comment (future polymorphic dispatch on | ||
| * namespace entries needs the discriminator in JSON). | ||
| * | ||
| * The entry's name is not on the class — value-sets are keyed by name in | ||
| * the parent namespace's `valueSet: Record<string, StorageValueSet>` map. | ||
| */ | ||
| declare class StorageValueSet extends SqlNode { | ||
| readonly kind: "valueSet"; | ||
| readonly values: readonly JsonValue[]; | ||
| constructor(input: StorageValueSetInput); | ||
| } | ||
| declare function isStorageValueSet(value: unknown): value is StorageValueSet; | ||
| //#endregion | ||
| export { StorageTableInput as a, StorageColumn as c, IndexInput as d, PrimaryKey as f, CheckConstraintInput as h, StorageTable as i, StorageColumnInput as l, CheckConstraint as m, StorageValueSetInput as n, UniqueConstraint as o, PrimaryKeyInput as p, isStorageValueSet as r, UniqueConstraintInput as s, StorageValueSet as t, Index as u }; | ||
| //# sourceMappingURL=storage-value-set-DXL-7PYo.d.mts.map |
| {"version":3,"file":"storage-value-set-DXL-7PYo.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts"],"mappings":";;;;;;AASA;;;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;AAAA;AAiBhC;;;;;;;;;;;;cAAa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA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GAAa,UAAA,GAAa,eAAA;EAAA,SAC1B,OAAA,EAAS,aAAA,CAAc,gBAAA,GAAmB,qBAAA;EAAA,SAC1C,OAAA,EAAS,aAAA,CAAc,KAAA,GAAQ,UAAA;EAAA,SAC/B,WAAA,EAAa,aAAA,CAAc,UAAA,GAAa,eAAA;EAAA,SACxC,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA,GAAkB,oBAAA;AAAA;;;;;;;;;;;;;cAevC,YAAA,SAAqB,OAAA;EAAA,SACvB,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,aAAA;EAAA,SACjC,OAAA,EAAS,aAAA,CAAc,gBAAA;EAAA,SACvB,OAAA,EAAS,aAAA,CAAc,KAAA;EAAA,SACvB,WAAA,EAAa,aAAA,CAAc,UAAA;EAAA,SACnB,UAAA,GAAa,UAAA;EAAA,SACb,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA;cAE5B,KAAA,EAAO,iBAAA;EJrCV;AACI;AAMf;;;;;EAPW,OI0EF,EAAA,CAAG,KAAA,EAAO,YAAA,eAA2B,KAAA,IAAS,YAAA;EAAA,OAK9C,MAAA,CACL,KAAA,EAAO,YAAA,cACP,UAAA,mBACS,KAAA,IAAS,YAAA;AAAA;;;;;AL7EtB;;;UMAiB,oBAAA;EAAA,SACN,IAAA;ENCA;EAAA,SMCA,MAAA,WAAiB,SAAS;AAAA;;ANAL;AAiBhC;;;;;;;;;;;;;;;;cMIa,eAAA,SAAwB,OAAA;EAAA,SACjB,IAAA;EAAA,SACT,MAAA,WAAiB,SAAA;cAEd,KAAA,EAAO,oBAAA;AAAA;AAAA,iBAOL,iBAAA,CAAkB,KAAA,YAAiB,KAAA,IAAS,eAAe"} |
| import { d as SqlNode } from "./storage-value-set-C4XInPlX.mjs"; | ||
| import { NamespaceBase, freezeNode, isPlainRecord } from "@prisma-next/framework-components/ir"; | ||
| //#region src/ir/storage-type-instance.ts | ||
| /** | ||
| * Sentinel kind for the legacy codec-triple shape persisted under | ||
| * `SqlStorage.types`. Plain JSON-clean object literals carry this | ||
| * discriminator so the polymorphic slot dispatch can route them down | ||
| * the codec path while target-specific IR class instances (e.g. the | ||
| * Postgres enum class) keep their own narrower `kind` literal. | ||
| */ | ||
| const CODEC_INSTANCE_KIND = "codec-instance"; | ||
| /** | ||
| * Stamp the codec-instance `kind` discriminator on a caller-supplied | ||
| * codec triple. Idempotent: input that already carries the discriminator | ||
| * passes through unchanged. Missing `typeParams` is normalised to `{}`. | ||
| */ | ||
| function toStorageTypeInstance(input) { | ||
| return { | ||
| kind: CODEC_INSTANCE_KIND, | ||
| codecId: input.codecId, | ||
| nativeType: input.nativeType, | ||
| typeParams: input.typeParams ?? {} | ||
| }; | ||
| } | ||
| /** | ||
| * Type-guard for codec-typed entries on the polymorphic | ||
| * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from | ||
| * any class-instance kinds a target pack contributes. | ||
| */ | ||
| function isStorageTypeInstance(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return value.kind === CODEC_INSTANCE_KIND; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-storage.ts | ||
| /** | ||
| * Narrows framework `AuthoringContributions` to the SQL-family shape by testing | ||
| * for the SQL-specific `createNamespace` capability. | ||
| */ | ||
| function isSqlAuthoringContributions(authoring) { | ||
| if (authoring === void 0 || !Object.hasOwn(authoring, "createNamespace")) return false; | ||
| return typeof Reflect.get(authoring, "createNamespace") === "function"; | ||
| } | ||
| /** | ||
| * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`, | ||
| * `SqliteDatabase`, …) extend this — it is never instantiated directly. | ||
| * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]` | ||
| * addresses any entity. | ||
| */ | ||
| var SqlNamespaceBase = class extends NamespaceBase {}; | ||
| /** | ||
| * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks | ||
| * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it | ||
| * survives duplicate-module boundaries (e.g. dist e2e where the target and | ||
| * the family carry separate copies of `@prisma-next/framework-components`). | ||
| * | ||
| * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`, | ||
| * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput` | ||
| * objects (`{ id, entries }`) do not. | ||
| */ | ||
| function isMaterializedSqlNamespace(x) { | ||
| if (typeof x !== "object" || x === null || !("qualifyTable" in x)) return false; | ||
| return typeof x.qualifyTable === "function"; | ||
| } | ||
| var SqlStorage = class extends SqlNode { | ||
| storageHash; | ||
| namespaces; | ||
| constructor(input) { | ||
| super(); | ||
| this.storageHash = input.storageHash; | ||
| this.namespaces = Object.freeze(input.namespaces); | ||
| if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]))); | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| /** | ||
| * Strict polymorphic-slot dispatch for `SqlStorage.types` entries. | ||
| * Every entry must carry a `kind: 'codec-instance'` discriminator or | ||
| * be an already-constructed `StorageTypeInstance`. Untagged or | ||
| * unrecognised inputs throw a diagnostic naming the entry and its | ||
| * `kind`, so format drift surfaces loudly at the deserializer | ||
| * boundary instead of slipping past the seam and corrupting | ||
| * downstream IR walks. | ||
| * | ||
| * Codec-triple authors that have an untagged shape on hand can call | ||
| * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'` | ||
| * discriminator) before constructing `SqlStorage`. On-disk reads | ||
| * cross `familyInstance.deserializeContract` first; the structural | ||
| * arktype schema rejects untagged entries earlier, so this throw | ||
| * only fires for in-memory authoring bugs. | ||
| */ | ||
| function normaliseTypeEntry(name, entry) { | ||
| if (isStorageTypeInstance(entry)) { | ||
| if ("typeParams" in entry) return entry; | ||
| return toStorageTypeInstance(entry); | ||
| } | ||
| const rawKind = isPlainRecord(entry) ? entry["kind"] : void 0; | ||
| const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`; | ||
| throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`); | ||
| } | ||
| //#endregion | ||
| //#region src/types.ts | ||
| const DEFAULT_FK_CONSTRAINT = true; | ||
| const DEFAULT_FK_INDEX = true; | ||
| function applyFkDefaults(fk, overrideDefaults) { | ||
| return { | ||
| constraint: fk.constraint ?? overrideDefaults?.constraint ?? true, | ||
| index: fk.index ?? overrideDefaults?.index ?? true | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { SqlStorage as a, CODEC_INSTANCE_KIND as c, SqlNamespaceBase as i, isStorageTypeInstance as l, DEFAULT_FK_INDEX as n, isMaterializedSqlNamespace as o, applyFkDefaults as r, isSqlAuthoringContributions as s, DEFAULT_FK_CONSTRAINT as t, toStorageTypeInstance as u }; | ||
| //# sourceMappingURL=types-KiOT4SAV.mjs.map |
| {"version":3,"file":"types-KiOT4SAV.mjs","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Sentinel kind for the legacy codec-triple shape persisted under\n * `SqlStorage.types`. Plain JSON-clean object literals carry this\n * discriminator so the polymorphic slot dispatch can route them down\n * the codec path while target-specific IR class instances (e.g. the\n * Postgres enum class) keep their own narrower `kind` literal.\n */\nexport const CODEC_INSTANCE_KIND = 'codec-instance' as const;\n\n/**\n * Structural sub-interface of {@link StorageType} for codec-typed entries\n * in `SqlStorage.types`. These are plain object literals — there is no\n * runtime IR class, the JSON envelope round-trips through the slot\n * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch\n * key that distinguishes codec-typed entries from any class-instance\n * kinds a target pack contributes to the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n * `typeParams` may be omitted on input; the constructor normalises a\n * missing value to `{}` so the in-memory shape is always present.\n */\nexport interface StorageTypeInstanceInput {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n}\n\n/**\n * Stamp the codec-instance `kind` discriminator on a caller-supplied\n * codec triple. Idempotent: input that already carries the discriminator\n * passes through unchanged. Missing `typeParams` is normalised to `{}`.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams ?? {},\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * any class-instance kinds a target pack contributes.\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport type { AuthoringContributions } from '@prisma-next/framework-components/authoring';\nimport {\n freezeNode,\n isPlainRecord,\n type Namespace,\n NamespaceBase,\n type Storage,\n} from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\nimport type { StorageTable } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet } from './storage-value-set';\n\n/**\n * Polymorphic value type for document-scoped `SqlStorage.types` entries\n * (codec aliases / parameterised native type registrations).\n *\n * Postgres native enum registrations live under the postgres-specific\n * `entries.type` slot on `PostgresSchema` (target layer), not here.\n */\nexport type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;\n\nexport interface SqlNamespaceInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Target-supplied factory that materializes a `Namespace` from a SQL\n * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`).\n */\nexport type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace;\n\n/**\n * SQL-family extension of the framework `AuthoringContributions`. SQL target\n * packs add a `createNamespace` factory so the PSL/TS authoring paths can\n * materialize namespaces (and merge lowered extension-block entities) without\n * each consumer re-specifying it. The factory is SQL-specific, so it lives here\n * rather than on the framework `AuthoringContributions` base.\n */\nexport interface SqlAuthoringContributions extends AuthoringContributions {\n readonly createNamespace?: SqlNamespaceFactory;\n}\n\n/**\n * Narrows framework `AuthoringContributions` to the SQL-family shape by testing\n * for the SQL-specific `createNamespace` capability.\n */\nexport function isSqlAuthoringContributions(\n authoring: AuthoringContributions | undefined,\n): authoring is SqlAuthoringContributions {\n if (authoring === undefined || !Object.hasOwn(authoring, 'createNamespace')) {\n return false;\n }\n return typeof Reflect.get(authoring, 'createNamespace') === 'function';\n}\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>;\n}\n\n/**\n * SQL Contract IR root node for the `storage` field.\n *\n * Single concrete family-shared class — both Postgres and SQLite\n * consume this class today. Per-target storage subclasses are\n * introduced when each target's namespace shape earns its\n * target-specific concretion (target-specific derived fields,\n * target-specific storage extensions).\n *\n * Honours the framework `Storage` interface: every SQL IR carries a\n * `namespaces` map keyed by namespace id. Callers must supply fully\n * constructed `Namespace` instances — construction discipline lives\n * in the authoring builders and deserializer hydration paths.\n *\n * The constructor normalises optional `types` into class instances.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; hydration of raw JSON\n * class-instance entries (carrying their narrower `kind` literal) is\n * the per-target serializer's responsibility (so the family base does\n * not import target-specific subclasses).\n */\n/**\n * The typed `entries` shape for SQL family namespaces. The open dictionary\n * is intersected with optional known-kind maps so that `ns.entries.table`\n * and `ns.entries.valueSet` resolve without a cast, while unknown pack-\n * contributed kinds remain valid (the `Record` part allows any string key).\n */\nexport type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {\n readonly table?: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n};\n\n/**\n * Structural interface for SQL family namespaces. Generated `.d.ts` contract\n * types satisfy this structurally (no prototype methods). The runtime\n * abstract class `SqlNamespaceBase` extends this.\n *\n * `qualifyTable` is optional so JSON-shaped contract types (which carry no\n * methods) are accepted where `SqlNamespace` is required. Hydrated\n * `SqlNamespaceBase` instances always have it.\n */\nexport interface SqlNamespace {\n readonly kind: string;\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n qualifyTable?(tableName: string): string;\n}\n\n/**\n * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) extend this — it is never instantiated directly.\n * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`\n * addresses any entity.\n */\nexport abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {\n abstract override readonly id: string;\n abstract override readonly entries: SqlNamespaceEntries;\n\n abstract qualifyTable(tableName: string): string;\n}\n\n/**\n * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks\n * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it\n * survives duplicate-module boundaries (e.g. dist e2e where the target and\n * the family carry separate copies of `@prisma-next/framework-components`).\n *\n * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,\n * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`\n * objects (`{ id, entries }`) do not.\n */\nexport function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase {\n if (typeof x !== 'object' || x === null || !('qualifyTable' in x)) return false;\n return typeof x.qualifyTable === 'function';\n}\n\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n declare readonly types?: Readonly<Record<string, StorageTypeInstance>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.namespaces = Object.freeze(input.namespaces);\n if (input.types !== undefined) {\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]),\n ),\n );\n }\n freezeNode(this);\n }\n}\n\n/**\n * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.\n * Every entry must carry a `kind: 'codec-instance'` discriminator or\n * be an already-constructed `StorageTypeInstance`. Untagged or\n * unrecognised inputs throw a diagnostic naming the entry and its\n * `kind`, so format drift surfaces loudly at the deserializer\n * boundary instead of slipping past the seam and corrupting\n * downstream IR walks.\n *\n * Codec-triple authors that have an untagged shape on hand can call\n * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`\n * discriminator) before constructing `SqlStorage`. On-disk reads\n * cross `familyInstance.deserializeContract` first; the structural\n * arktype schema rejects untagged entries earlier, so this throw\n * only fires for in-memory authoring bugs.\n */\nfunction normaliseTypeEntry(name: string, entry: SqlStorageTypeEntry): StorageTypeInstance {\n if (isStorageTypeInstance(entry)) {\n // Normalise on-disk objects that omit `typeParams` (the canonical on-disk\n // form strips empty typeParams to keep JSON compact). The in-memory invariant\n // is always `typeParams: {}` when empty — never `undefined`. Only create a\n // new object when necessary to preserve identity-equality for callers that\n // hold a reference to an already-correct in-memory entry.\n if ('typeParams' in entry) {\n return entry;\n }\n return toStorageTypeInstance(entry);\n }\n const rawKind = isPlainRecord(entry) ? entry['kind'] : undefined;\n const kindDescription =\n rawKind === undefined\n ? 'missing `kind` discriminator'\n : `unrecognised \\`kind\\` discriminator ${JSON.stringify(rawKind)}`;\n throw new Error(\n `storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify('codec-instance')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport interface SqlControlDriverInstance<T extends string = string>\n extends ControlDriverInstance<'sql', T> {\n query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }>;\n}\n\nexport { CheckConstraint, type CheckConstraintInput } from './ir/check-constraint';\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReference,\n type ForeignKeyReferenceInput,\n} from './ir/foreign-key-reference';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n isMaterializedSqlNamespace,\n isSqlAuthoringContributions,\n type SqlAuthoringContributions,\n type SqlNamespace,\n SqlNamespaceBase,\n type SqlNamespaceEntries,\n type SqlNamespaceFactory,\n type SqlNamespaceInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { StorageColumn, type StorageColumnInput } from './ir/storage-column';\nexport { StorageTable, type StorageTableInput } from './ir/storage-table';\nexport {\n CODEC_INSTANCE_KIND,\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './ir/storage-type-instance';\nexport {\n isStorageValueSet,\n StorageValueSet,\n type StorageValueSetInput,\n} from './ir/storage-value-set';\nexport {\n UniqueConstraint,\n type UniqueConstraintInput,\n} from './ir/unique-constraint';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly namespaceId: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\n// Field-type maps nested by namespace coordinate: `[namespaceId][model][field]`.\n// Shared by the output and input field-type maps and their extractors.\nexport type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;\n\nexport type NamespacedStorageColumnTypeMap = Record<\n string,\n Record<string, Record<string, unknown>>\n>;\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TStorageColumnTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n TStorageColumnInputTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n readonly storageColumnTypes: TStorageColumnTypes;\n readonly storageColumnInputTypes: TStorageColumnInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Names a concrete codec identity, a set of capability traits the\n * field's codec must carry, or targets list-typed (`many`) fields. Element\n * capability gating for list ops travels in `elementTraits`.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never; readonly many?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never; readonly many?: never }\n | {\n readonly many: true;\n readonly elementTraits?: readonly CodecTrait[];\n readonly codecId?: never;\n readonly traits?: never;\n };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnInputTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnTypes<T> = StorageColumnTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnInputTypes<T> = StorageColumnInputTypesOf<\n ExtractTypeMapsFromContract<T>\n>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;AASA,MAAa,sBAAsB;;;;;;AAmCnC,SAAgB,sBAAsB,OAAsD;CAC1F,OAAO;EACL,MAAM;EACN,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,YAAY,MAAM,cAAc,CAAC;CACnC;AACF;;;;;;AAOA,SAAgB,sBAAsB,OAA8C;CAClF,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD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;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;CACvC;AACF"} |
@@ -1,2 +0,2 @@ | ||
| import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-Dc1Dy3Vb.mjs"; | ||
| import { DefaultNamespaceEntries, NamespacedEntities, SingleNamespaceView } from "@prisma-next/framework-components/ir"; | ||
@@ -3,0 +3,0 @@ import { Contract } from "@prisma-next/contract/types"; |
@@ -1,2 +0,2 @@ | ||
| import { a as StorageTableInput, i as StorageTable, n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { a as StorageTableInput, i as StorageTable, n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { AnyEntityKindDescriptor, EntityKindDescriptor } from "@prisma-next/framework-components/ir"; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
| import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-BSGvSPI8.mjs"; | ||
| import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-CHiydmat.mjs"; | ||
| export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind }; |
| import { t as ForeignKey } from "./foreign-key-BATxB95l.mjs"; | ||
| import { d as Index, i as StorageTable, l as StorageColumn, p as PrimaryKey, s as UniqueConstraint, u as StorageColumnInput } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { c as StorageColumn, f as PrimaryKey, i as StorageTable, l as StorageColumnInput, o as UniqueConstraint, u as Index } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-ChH7hULD.mjs"; | ||
@@ -4,0 +4,0 @@ import { ScalarFieldType } from "@prisma-next/contract/types"; |
@@ -1,3 +0,3 @@ | ||
| import { a as UniqueConstraint, c as PrimaryKey, l as ForeignKey, o as StorageColumn, r as StorageTable, s as Index } from "./storage-value-set-Cp7h3D59.mjs"; | ||
| import { r as applyFkDefaults } from "./types-B4sPkjNO.mjs"; | ||
| import { a as StorageColumn, c as ForeignKey, i as UniqueConstraint, o as Index, r as StorageTable, s as PrimaryKey } from "./storage-value-set-C4XInPlX.mjs"; | ||
| import { r as applyFkDefaults } from "./types-KiOT4SAV.mjs"; | ||
| import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir"; | ||
@@ -4,0 +4,0 @@ import { asNamespaceId } from "@prisma-next/contract/types"; |
@@ -1,2 +0,2 @@ | ||
| import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-Dc1Dy3Vb.mjs"; | ||
| import { a as IndexTypeRegistry } from "./index-types-Czsyu7Iw.mjs"; | ||
@@ -3,0 +3,0 @@ import { Contract } from "@prisma-next/contract/types"; |
@@ -1,3 +0,3 @@ | ||
| import { i as StorageTable } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs"; | ||
| import { i as StorageTable } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-Dc1Dy3Vb.mjs"; | ||
@@ -4,0 +4,0 @@ //#region src/resolve-storage-table.d.ts |
+3
-3
| import { a as ForeignKeyReferenceInput, i as ForeignKeyReference, n as ForeignKeyInput, o as SqlNode, r as ReferentialAction, t as ForeignKey } from "./foreign-key-BATxB95l.mjs"; | ||
| import { a as StorageTableInput, c as UniqueConstraintInput, d as Index, f as IndexInput, g as CheckConstraintInput, h as CheckConstraint, i as StorageTable, l as StorageColumn, m as PrimaryKeyInput, n as StorageValueSetInput, o as isStorageTable, p as PrimaryKey, r as isStorageValueSet, s as UniqueConstraint, t as StorageValueSet, u as StorageColumnInput } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { a as SqlNamespaceFactory, c as SqlStorageInput, d as isSqlAuthoringContributions, f as CODEC_INSTANCE_KIND, g as toStorageTypeInstance, h as isStorageTypeInstance, i as SqlNamespaceEntries, l as SqlStorageTypeEntry, m as StorageTypeInstanceInput, n as SqlNamespace, o as SqlNamespaceInput, p as StorageTypeInstance, r as SqlNamespaceBase, s as SqlStorage, t as SqlAuthoringContributions, u as isMaterializedSqlNamespace } from "./sql-storage-CUP3mD3c.mjs"; | ||
| import { a as StorageTableInput, c as StorageColumn, d as IndexInput, f as PrimaryKey, h as CheckConstraintInput, i as StorageTable, l as StorageColumnInput, m as CheckConstraint, n as StorageValueSetInput, o as UniqueConstraint, p as PrimaryKeyInput, r as isStorageValueSet, s as UniqueConstraintInput, t as StorageValueSet, u as Index } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { a as SqlNamespaceFactory, c as SqlStorageInput, d as isSqlAuthoringContributions, f as CODEC_INSTANCE_KIND, g as toStorageTypeInstance, h as isStorageTypeInstance, i as SqlNamespaceEntries, l as SqlStorageTypeEntry, m as StorageTypeInstanceInput, n as SqlNamespace, o as SqlNamespaceInput, p as StorageTypeInstance, r as SqlNamespaceBase, s as SqlStorage, t as SqlAuthoringContributions, u as isMaterializedSqlNamespace } from "./sql-storage-Dc1Dy3Vb.mjs"; | ||
| import { A as TypeMapsPhantomKey, C as SqlControlDriverInstance, D as StorageColumnInputTypesOf, E as SqlQueryOperationTypes, O as StorageColumnTypesOf, S as ResolveCodecTypes, T as SqlModelStorage, _ as QueryOperationReturn, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as ExtractTypeMapsFromContract, f as FieldInputTypesOf, g as NamespacedStorageColumnTypeMap, h as NamespacedFieldTypeMap, i as DEFAULT_FK_INDEX, j as applyFkDefaults, k as TypeMaps, l as ExtractStorageColumnInputTypes, m as ForeignKeyOptions, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as FieldOutputTypesOf, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as ExtractStorageColumnTypes, v as QueryOperationSelfSpec, w as SqlModelFieldStorage, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-ChH7hULD.mjs"; | ||
@@ -10,3 +10,3 @@ | ||
| //#endregion | ||
| export { CODEC_INSTANCE_KIND, CheckConstraint, type CheckConstraintInput, type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractStorageColumnInputTypes, type ExtractStorageColumnTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReference, type ForeignKeyReferenceInput, Index, type IndexInput, type NamespacedFieldTypeMap, type NamespacedStorageColumnTypeMap, PrimaryKey, type PrimaryKeyInput, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlAuthoringContributions, type SqlControlDriverInstance, type SqlModelFieldStorage, type SqlModelStorage, type SqlNamespace, SqlNamespaceBase, type SqlNamespaceEntries, type SqlNamespaceFactory, type SqlNamespaceInput, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, StorageColumn, type StorageColumnInput, type StorageColumnInputTypesOf, type StorageColumnMapAt, type StorageColumnTypeAcrossNamespaces, type StorageColumnTypesOf, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, StorageValueSet, type StorageValueSetInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTable, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance }; | ||
| export { CODEC_INSTANCE_KIND, CheckConstraint, type CheckConstraintInput, type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractStorageColumnInputTypes, type ExtractStorageColumnTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReference, type ForeignKeyReferenceInput, Index, type IndexInput, type NamespacedFieldTypeMap, type NamespacedStorageColumnTypeMap, PrimaryKey, type PrimaryKeyInput, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlAuthoringContributions, type SqlControlDriverInstance, type SqlModelFieldStorage, type SqlModelStorage, type SqlNamespace, SqlNamespaceBase, type SqlNamespaceEntries, type SqlNamespaceFactory, type SqlNamespaceInput, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, StorageColumn, type StorageColumnInput, type StorageColumnInputTypesOf, type StorageColumnMapAt, type StorageColumnTypeAcrossNamespaces, type StorageColumnTypesOf, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, StorageValueSet, type StorageValueSetInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance }; | ||
| //# sourceMappingURL=types.d.mts.map |
+3
-3
@@ -1,3 +0,3 @@ | ||
| import { a as UniqueConstraint, c as PrimaryKey, d as CheckConstraint, f as SqlNode, i as isStorageTable, l as ForeignKey, n as isStorageValueSet, o as StorageColumn, r as StorageTable, s as Index, t as StorageValueSet, u as ForeignKeyReference } from "./storage-value-set-Cp7h3D59.mjs"; | ||
| import { a as SqlStorage, c as CODEC_INSTANCE_KIND, i as SqlNamespaceBase, l as isStorageTypeInstance, n as DEFAULT_FK_INDEX, o as isMaterializedSqlNamespace, r as applyFkDefaults, s as isSqlAuthoringContributions, t as DEFAULT_FK_CONSTRAINT, u as toStorageTypeInstance } from "./types-B4sPkjNO.mjs"; | ||
| export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNamespaceBase, SqlNode, SqlStorage, StorageColumn, StorageTable, StorageValueSet, UniqueConstraint, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTable, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance }; | ||
| import { a as StorageColumn, c as ForeignKey, d as SqlNode, i as UniqueConstraint, l as ForeignKeyReference, n as isStorageValueSet, o as Index, r as StorageTable, s as PrimaryKey, t as StorageValueSet, u as CheckConstraint } from "./storage-value-set-C4XInPlX.mjs"; | ||
| import { a as SqlStorage, c as CODEC_INSTANCE_KIND, i as SqlNamespaceBase, l as isStorageTypeInstance, n as DEFAULT_FK_INDEX, o as isMaterializedSqlNamespace, r as applyFkDefaults, s as isSqlAuthoringContributions, t as DEFAULT_FK_CONSTRAINT, u as toStorageTypeInstance } from "./types-KiOT4SAV.mjs"; | ||
| export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNamespaceBase, SqlNode, SqlStorage, StorageColumn, StorageTable, StorageValueSet, UniqueConstraint, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance }; |
| import { n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-BATxB95l.mjs"; | ||
| import { c as UniqueConstraintInput, m as PrimaryKeyInput } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs"; | ||
| import { p as PrimaryKeyInput, s as UniqueConstraintInput } from "./storage-value-set-DXL-7PYo.mjs"; | ||
| import { s as SqlStorage } from "./sql-storage-Dc1Dy3Vb.mjs"; | ||
| import { AnyEntityKindDescriptor } from "@prisma-next/framework-components/ir"; | ||
@@ -5,0 +5,0 @@ import { Type } from "arktype"; |
@@ -1,2 +0,2 @@ | ||
| import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-BSGvSPI8.mjs"; | ||
| import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-CHiydmat.mjs"; | ||
| import { isPlainRecord } from "@prisma-next/framework-components/ir"; | ||
@@ -3,0 +3,0 @@ import { type } from "arktype"; |
+7
-7
| { | ||
| "name": "@prisma-next/sql-contract", | ||
| "version": "0.14.0-dev.39", | ||
| "version": "0.14.0-dev.40", | ||
| "license": "Apache-2.0", | ||
@@ -9,11 +9,11 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/contract": "0.14.0-dev.39", | ||
| "@prisma-next/framework-components": "0.14.0-dev.39", | ||
| "@prisma-next/utils": "0.14.0-dev.39", | ||
| "@prisma-next/contract": "0.14.0-dev.40", | ||
| "@prisma-next/framework-components": "0.14.0-dev.40", | ||
| "@prisma-next/utils": "0.14.0-dev.40", | ||
| "arktype": "^2.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@prisma-next/test-utils": "0.14.0-dev.39", | ||
| "@prisma-next/tsconfig": "0.14.0-dev.39", | ||
| "@prisma-next/tsdown": "0.14.0-dev.39", | ||
| "@prisma-next/test-utils": "0.14.0-dev.40", | ||
| "@prisma-next/tsconfig": "0.14.0-dev.40", | ||
| "@prisma-next/tsdown": "0.14.0-dev.40", | ||
| "tsdown": "0.22.1", | ||
@@ -20,0 +20,0 @@ "typescript": "5.9.3", |
@@ -65,3 +65,2 @@ export type { | ||
| isSqlAuthoringContributions, | ||
| isStorageTable, | ||
| isStorageTypeInstance, | ||
@@ -68,0 +67,0 @@ isStorageValueSet, |
@@ -71,7 +71,23 @@ import type { ControlPolicy } from '@prisma-next/contract/types'; | ||
| } | ||
| } | ||
| export function isStorageTable(value: unknown): value is StorageTable { | ||
| if (typeof value !== 'object' || value === null) return false; | ||
| return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value; | ||
| /** | ||
| * Runtime guard that a namespace `table` entry is really a `StorageTable`. | ||
| * The compiler already types the entry as `StorageTable`, but a | ||
| * freshly-deserialized contract may carry plain JSON at that slot until | ||
| * hydration; this duck-types the structural shape. Accepts `undefined` so | ||
| * optional-chained entry lookups pass straight through. | ||
| */ | ||
| static is(value: StorageTable | undefined): value is StorageTable { | ||
| if (typeof value !== 'object' || value === null) return false; | ||
| return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value; | ||
| } | ||
| static assert( | ||
| value: StorageTable | undefined, | ||
| coordinate: string, | ||
| ): asserts value is StorageTable { | ||
| if (!StorageTable.is(value)) { | ||
| throw new Error(`Expected a StorageTable at ${coordinate}`); | ||
| } | ||
| } | ||
| } |
+1
-1
@@ -40,3 +40,3 @@ import type { CodecTrait } from '@prisma-next/framework-components/codec'; | ||
| export { StorageColumn, type StorageColumnInput } from './ir/storage-column'; | ||
| export { isStorageTable, StorageTable, type StorageTableInput } from './ir/storage-table'; | ||
| export { StorageTable, type StorageTableInput } from './ir/storage-table'; | ||
| export { | ||
@@ -43,0 +43,0 @@ CODEC_INSTANCE_KIND, |
| import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-Cp7h3D59.mjs"; | ||
| import { type } from "arktype"; | ||
| //#region src/ir/storage-entry-schemas.ts | ||
| const literalKindSchema = type("'literal'"); | ||
| const functionKindSchema = type("'function'"); | ||
| const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'"); | ||
| const ColumnDefaultLiteralSchema = type.declare().type({ | ||
| kind: literalKindSchema, | ||
| value: "string | number | boolean | null | unknown[] | Record<string, unknown>" | ||
| }); | ||
| const ColumnDefaultFunctionSchema = type.declare().type({ | ||
| kind: functionKindSchema, | ||
| expression: "string" | ||
| }); | ||
| const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema); | ||
| const StorageValueSetRefSchema = type({ | ||
| plane: "'storage'", | ||
| namespaceId: "string", | ||
| entityKind: "'valueSet'", | ||
| entityName: "string", | ||
| "spaceId?": "string" | ||
| }); | ||
| const StorageColumnSchema = type({ | ||
| "+": "reject", | ||
| nativeType: "string", | ||
| codecId: "string", | ||
| nullable: "boolean", | ||
| "many?": "boolean", | ||
| "typeParams?": "Record<string, unknown>", | ||
| "typeRef?": "string", | ||
| "default?": ColumnDefaultSchema, | ||
| "control?": ControlPolicySchema, | ||
| "valueSet?": StorageValueSetRefSchema | ||
| }).narrow((col, ctx) => { | ||
| if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both"); | ||
| return true; | ||
| }); | ||
| /** | ||
| * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`. | ||
| * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an | ||
| * ordered `values` array of codec-encoded permitted values. | ||
| */ | ||
| const StorageValueSetSchema = type({ | ||
| kind: "'valueSet'", | ||
| values: type("string | number | boolean | null | unknown[] | Record<string, unknown>").array().readonly() | ||
| }); | ||
| const PrimaryKeySchema = type.declare().type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string" | ||
| }); | ||
| const UniqueConstraintSchema = type.declare().type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string" | ||
| }); | ||
| const IndexSchema = type({ | ||
| columns: type.string.array().readonly(), | ||
| "name?": "string", | ||
| "type?": "string", | ||
| "options?": "Record<string, unknown>" | ||
| }); | ||
| const ForeignKeyReferenceSchema = type({ | ||
| "+": "reject", | ||
| namespaceId: "string", | ||
| tableName: "string", | ||
| columns: type.string.array().readonly(), | ||
| "spaceId?": "string" | ||
| }); | ||
| const ForeignKeySourceSchema = type({ | ||
| "+": "reject", | ||
| namespaceId: "string", | ||
| tableName: "string", | ||
| columns: type.string.array().readonly() | ||
| }); | ||
| const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'"); | ||
| const ForeignKeySchema = type.declare().type({ | ||
| source: ForeignKeySourceSchema, | ||
| target: ForeignKeyReferenceSchema, | ||
| "name?": "string", | ||
| "onDelete?": ReferentialActionSchema, | ||
| "onUpdate?": ReferentialActionSchema, | ||
| constraint: "boolean", | ||
| index: "boolean" | ||
| }); | ||
| const CheckConstraintSchema = type({ | ||
| "+": "reject", | ||
| name: "string", | ||
| column: "string", | ||
| valueSet: StorageValueSetRefSchema | ||
| }); | ||
| const StorageTableSchema = type({ | ||
| "+": "reject", | ||
| columns: type({ "[string]": StorageColumnSchema }), | ||
| "primaryKey?": PrimaryKeySchema, | ||
| uniques: UniqueConstraintSchema.array().readonly(), | ||
| indexes: IndexSchema.array().readonly(), | ||
| foreignKeys: ForeignKeySchema.array().readonly(), | ||
| "control?": ControlPolicySchema, | ||
| "checks?": CheckConstraintSchema.array().readonly() | ||
| }); | ||
| //#endregion | ||
| //#region src/entity-kinds.ts | ||
| const tableEntityKind = { | ||
| kind: "table", | ||
| schema: StorageTableSchema, | ||
| construct: (input) => new StorageTable(input) | ||
| }; | ||
| const valueSetEntityKind = { | ||
| kind: "valueSet", | ||
| schema: StorageValueSetSchema, | ||
| construct: (input) => new StorageValueSet(input) | ||
| }; | ||
| /** | ||
| * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in | ||
| * `table` and `valueSet` kinds plus any target `packKinds`. This builds the | ||
| * lookup table — it does not touch contract data. `hydrateNamespaceEntities` | ||
| * later consumes this registry to turn a namespace's raw entries into IR | ||
| * instances, and `createSqlContractSchema` derives validation from the same | ||
| * registry. Throws on a duplicate kind. | ||
| */ | ||
| function composeSqlEntityKinds(packKinds = []) { | ||
| const kinds = new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]); | ||
| for (const descriptor of packKinds) { | ||
| if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`); | ||
| kinds.set(descriptor.kind, descriptor); | ||
| } | ||
| return kinds; | ||
| } | ||
| //#endregion | ||
| export { ColumnDefaultFunctionSchema as a, ForeignKeyReferenceSchema as c, IndexSchema as d, ReferentialActionSchema as f, CheckConstraintSchema as i, ForeignKeySchema as l, StorageValueSetSchema as m, tableEntityKind as n, ColumnDefaultLiteralSchema as o, StorageTableSchema as p, valueSetEntityKind as r, ColumnDefaultSchema as s, composeSqlEntityKinds as t, ForeignKeySourceSchema as u }; | ||
| //# sourceMappingURL=entity-kinds-BSGvSPI8.mjs.map |
| {"version":3,"file":"entity-kinds-BSGvSPI8.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'many?': 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw new Error(\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC5C,MAAM,sBAAsB,KAAK,mDAAmD;AAEpF,MAAa,6BAA6B,KAAK,QAA8B,CAAC,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;AACT,CAAC;AAED,MAAa,8BAA8B,KAAK,QAA+B,CAAC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;AACd,CAAC;AAED,MAAa,sBAAsB,2BAA2B,GAAG,2BAA2B;AAE5F,MAAM,2BAA2B,KAAK;CACpC,OAAO;CACP,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,YAAY;AACd,CAAC;AAED,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,SAAS;CACT,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,aAAa;AACf,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ;CACtB,IAAI,IAAI,eAAe,KAAA,KAAa,IAAI,YAAY,KAAA,GAClD,OAAO,IAAI,OAAO,sDAAsD;CAE1E,OAAO;A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CAAC,SAAS;CAC/C,YAAY;CACZ,WAAW,sBAAsB,MAAM,CAAC,CAAC,SAAS;AACpD,CAAC;;;ACxHD,MAAa,kBAAyE;CACpF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;AAEA,MAAa,qBAAkF;CAC7F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,gBAAgB,KAAK;AACjD;;;;;;;;;AAUA,SAAgB,sBACd,YAAgD,CAAC,GACH;CAC9C,MAAM,QAAQ,IAAI,IAAqC,CACrD,CAAC,SAAS,eAAe,GACzB,CAAC,YAAY,kBAAkB,CACjC,CAAC;CACD,KAAK,MAAM,cAAc,WAAW;EAClC,IAAI,MAAM,IAAI,WAAW,IAAI,GAC3B,MAAM,IAAI,MACR,iDAAiD,WAAW,KAAK,0CACnE;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"} |
| import { o as SqlNode } from "./foreign-key-BATxB95l.mjs"; | ||
| import { i as StorageTable, t as StorageValueSet } from "./storage-value-set-B1Xmb6D2.mjs"; | ||
| import { Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir"; | ||
| import { StorageHashBase } from "@prisma-next/contract/types"; | ||
| import { AuthoringContributions } from "@prisma-next/framework-components/authoring"; | ||
| //#region src/ir/storage-type-instance.d.ts | ||
| /** | ||
| * Sentinel kind for the legacy codec-triple shape persisted under | ||
| * `SqlStorage.types`. Plain JSON-clean object literals carry this | ||
| * discriminator so the polymorphic slot dispatch can route them down | ||
| * the codec path while target-specific IR class instances (e.g. the | ||
| * Postgres enum class) keep their own narrower `kind` literal. | ||
| */ | ||
| declare const CODEC_INSTANCE_KIND: "codec-instance"; | ||
| /** | ||
| * Structural sub-interface of {@link StorageType} for codec-typed entries | ||
| * in `SqlStorage.types`. These are plain object literals — there is no | ||
| * runtime IR class, the JSON envelope round-trips through the slot | ||
| * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch | ||
| * key that distinguishes codec-typed entries from any class-instance | ||
| * kinds a target pack contributes to the polymorphic slot. | ||
| */ | ||
| interface StorageTypeInstance extends StorageType { | ||
| readonly kind: typeof CODEC_INSTANCE_KIND; | ||
| readonly codecId: string; | ||
| readonly nativeType: string; | ||
| readonly typeParams: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Construction-time input for a codec-triple entry. Symmetric with the | ||
| * structural runtime shape minus the `kind` discriminator — callers may | ||
| * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on. | ||
| * `typeParams` may be omitted on input; the constructor normalises a | ||
| * missing value to `{}` so the in-memory shape is always present. | ||
| */ | ||
| interface StorageTypeInstanceInput { | ||
| readonly codecId: string; | ||
| readonly nativeType: string; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Stamp the codec-instance `kind` discriminator on a caller-supplied | ||
| * codec triple. Idempotent: input that already carries the discriminator | ||
| * passes through unchanged. Missing `typeParams` is normalised to `{}`. | ||
| */ | ||
| declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance; | ||
| /** | ||
| * Type-guard for codec-typed entries on the polymorphic | ||
| * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from | ||
| * any class-instance kinds a target pack contributes. | ||
| */ | ||
| declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance; | ||
| //#endregion | ||
| //#region src/ir/sql-storage.d.ts | ||
| /** | ||
| * Polymorphic value type for document-scoped `SqlStorage.types` entries | ||
| * (codec aliases / parameterised native type registrations). | ||
| * | ||
| * Postgres native enum registrations live under the postgres-specific | ||
| * `entries.type` slot on `PostgresSchema` (target layer), not here. | ||
| */ | ||
| type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput; | ||
| interface SqlNamespaceInput { | ||
| readonly id: string; | ||
| readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>; | ||
| } | ||
| /** | ||
| * Target-supplied factory that materializes a `Namespace` from a SQL | ||
| * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`). | ||
| */ | ||
| type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace; | ||
| /** | ||
| * SQL-family extension of the framework `AuthoringContributions`. SQL target | ||
| * packs add a `createNamespace` factory so the PSL/TS authoring paths can | ||
| * materialize namespaces (and merge lowered extension-block entities) without | ||
| * each consumer re-specifying it. The factory is SQL-specific, so it lives here | ||
| * rather than on the framework `AuthoringContributions` base. | ||
| */ | ||
| interface SqlAuthoringContributions extends AuthoringContributions { | ||
| readonly createNamespace?: SqlNamespaceFactory; | ||
| } | ||
| /** | ||
| * Narrows framework `AuthoringContributions` to the SQL-family shape by testing | ||
| * for the SQL-specific `createNamespace` capability. | ||
| */ | ||
| declare function isSqlAuthoringContributions(authoring: AuthoringContributions | undefined): authoring is SqlAuthoringContributions; | ||
| interface SqlStorageInput<THash extends string = string> { | ||
| readonly storageHash: StorageHashBase<THash>; | ||
| readonly types?: Record<string, SqlStorageTypeEntry>; | ||
| readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>; | ||
| } | ||
| /** | ||
| * SQL Contract IR root node for the `storage` field. | ||
| * | ||
| * Single concrete family-shared class — both Postgres and SQLite | ||
| * consume this class today. Per-target storage subclasses are | ||
| * introduced when each target's namespace shape earns its | ||
| * target-specific concretion (target-specific derived fields, | ||
| * target-specific storage extensions). | ||
| * | ||
| * Honours the framework `Storage` interface: every SQL IR carries a | ||
| * `namespaces` map keyed by namespace id. Callers must supply fully | ||
| * constructed `Namespace` instances — construction discipline lives | ||
| * in the authoring builders and deserializer hydration paths. | ||
| * | ||
| * The constructor normalises optional `types` into class instances. | ||
| * `types` is polymorphic per Decision 18 Option B: codec-triple inputs | ||
| * are stamped with `kind: 'codec-instance'`; hydration of raw JSON | ||
| * class-instance entries (carrying their narrower `kind` literal) is | ||
| * the per-target serializer's responsibility (so the family base does | ||
| * not import target-specific subclasses). | ||
| */ | ||
| /** | ||
| * The typed `entries` shape for SQL family namespaces. The open dictionary | ||
| * is intersected with optional known-kind maps so that `ns.entries.table` | ||
| * and `ns.entries.valueSet` resolve without a cast, while unknown pack- | ||
| * contributed kinds remain valid (the `Record` part allows any string key). | ||
| */ | ||
| type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & { | ||
| readonly table?: Readonly<Record<string, StorageTable>>; | ||
| readonly valueSet?: Readonly<Record<string, StorageValueSet>>; | ||
| }; | ||
| /** | ||
| * Structural interface for SQL family namespaces. Generated `.d.ts` contract | ||
| * types satisfy this structurally (no prototype methods). The runtime | ||
| * abstract class `SqlNamespaceBase` extends this. | ||
| * | ||
| * `qualifyTable` is optional so JSON-shaped contract types (which carry no | ||
| * methods) are accepted where `SqlNamespace` is required. Hydrated | ||
| * `SqlNamespaceBase` instances always have it. | ||
| */ | ||
| interface SqlNamespace { | ||
| readonly kind: string; | ||
| readonly id: string; | ||
| readonly entries: SqlNamespaceEntries; | ||
| qualifyTable?(tableName: string): string; | ||
| } | ||
| /** | ||
| * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`, | ||
| * `SqliteDatabase`, …) extend this — it is never instantiated directly. | ||
| * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]` | ||
| * addresses any entity. | ||
| */ | ||
| declare abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace { | ||
| abstract readonly id: string; | ||
| abstract readonly entries: SqlNamespaceEntries; | ||
| abstract qualifyTable(tableName: string): string; | ||
| } | ||
| /** | ||
| * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks | ||
| * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it | ||
| * survives duplicate-module boundaries (e.g. dist e2e where the target and | ||
| * the family carry separate copies of `@prisma-next/framework-components`). | ||
| * | ||
| * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`, | ||
| * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput` | ||
| * objects (`{ id, entries }`) do not. | ||
| */ | ||
| declare function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase; | ||
| declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage { | ||
| readonly storageHash: StorageHashBase<THash>; | ||
| readonly namespaces: Readonly<Record<string, SqlNamespace>>; | ||
| readonly types?: Readonly<Record<string, StorageTypeInstance>>; | ||
| constructor(input: SqlStorageInput<THash>); | ||
| } | ||
| //#endregion | ||
| export { SqlNamespaceFactory as a, SqlStorageInput as c, isSqlAuthoringContributions as d, CODEC_INSTANCE_KIND as f, toStorageTypeInstance as g, isStorageTypeInstance as h, SqlNamespaceEntries as i, SqlStorageTypeEntry as l, StorageTypeInstanceInput as m, SqlNamespace as n, SqlNamespaceInput as o, StorageTypeInstance as p, SqlNamespaceBase as r, SqlStorage as s, SqlAuthoringContributions as t, isMaterializedSqlNamespace as u }; | ||
| //# sourceMappingURL=sql-storage-CUP3mD3c.d.mts.map |
| {"version":3,"file":"sql-storage-CUP3mD3c.d.mts","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;;;;;;;AASA;cAAa,mBAAA;;;AAA+C;AAU5D;;;;;UAAiB,mBAAA,SAA4B,WAAA;EAAA,SAClC,IAAA,SAAa,mBAAA;EAAA,SACb,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,EAAY,MAAA;AAAA;;;;;;AAAM;AAU7B;UAAiB,wBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;;AAAA;AAQ9B;iBAAgB,qBAAA,CAAsB,KAAA,EAAO,wBAAA,GAA2B,mBAAmB;;;;;;iBAc3E,qBAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,mBAAmB;;;AAjDnF;;;;AAA4D;AAU5D;;AAVA,KCiBY,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,iBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QA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AAA;cAErC,KAAA,EAAO,eAAA,CAAgB,KAAA;AAAA"} |
| import { n as ForeignKeyInput, o as SqlNode, t as ForeignKey } from "./foreign-key-BATxB95l.mjs"; | ||
| import { ColumnDefault, ControlPolicy, JsonValue, ValueSetRef } from "@prisma-next/contract/types"; | ||
| //#region src/ir/check-constraint.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link CheckConstraint}. | ||
| * Mirrors the on-disk storage JSON envelope so the serializer hydration | ||
| * walker can hand a validated literal straight to `new`. | ||
| */ | ||
| interface CheckConstraintInput { | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly valueSet: ValueSetRef; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level check constraint that restricts | ||
| * a column to the permitted values of a value-set. | ||
| * | ||
| * The constraint is **structured** (names a column and a value-set | ||
| * reference), not a raw SQL expression. Each target renders its own DDL | ||
| * from the structured form, keeping the contract target-agnostic. | ||
| * | ||
| * Construction is idempotent: passing an existing `CheckConstraint` | ||
| * instance as input produces a new instance with identical fields. | ||
| * The constructor does not use `instanceof` for input discrimination — | ||
| * it reads plain named properties, which is sufficient since | ||
| * `CheckConstraintInput` is a structural type. | ||
| */ | ||
| declare class CheckConstraint extends SqlNode { | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly valueSet: ValueSetRef; | ||
| constructor(input: CheckConstraintInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/primary-key.d.ts | ||
| interface PrimaryKeyInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table's primary-key constraint. | ||
| */ | ||
| declare class PrimaryKey extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| constructor(input: PrimaryKeyInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-index.d.ts | ||
| interface IndexInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level secondary index. | ||
| * | ||
| * Note that this class shadows the global TypeScript `Index` lib type | ||
| * at the family-shared name; consumer files that need both should | ||
| * alias one (e.g. | ||
| * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`). | ||
| */ | ||
| declare class Index extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| constructor(input: IndexInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-column.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link StorageColumn}. Mirrors | ||
| * the on-disk storage JSON envelope exactly so the family-base | ||
| * serializer's hydration walker can hand an arktype-validated literal | ||
| * straight to `new`. | ||
| * | ||
| * `typeParams` and `typeRef` remain mutually exclusive (one or the | ||
| * other, not both); the constructor preserves whichever caller-side | ||
| * choice the input encodes. | ||
| */ | ||
| interface StorageColumnInput { | ||
| readonly nativeType: string; | ||
| readonly codecId: string; | ||
| readonly nullable: boolean; | ||
| readonly many?: boolean; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| readonly typeRef?: string; | ||
| readonly default?: ColumnDefault; | ||
| readonly control?: ControlPolicy; | ||
| readonly valueSet?: ValueSetRef; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a single column entry in `StorageTable.columns`. | ||
| * | ||
| * Single concrete family-shared class — every SQL target reads the | ||
| * same column shape today, so there is no per-target subclass. The | ||
| * class type accepts any caller that constructs via | ||
| * `new StorageColumn(input)`; literal construction sites must pass | ||
| * through the constructor or the family-base hydration walker. | ||
| * | ||
| * The column's `name` is not on the class — columns are keyed by name | ||
| * in the parent `StorageTable.columns: Record<string, StorageColumn>` | ||
| * map, so a `name` field would be redundant with the key. | ||
| */ | ||
| declare class StorageColumn extends SqlNode { | ||
| readonly nativeType: string; | ||
| readonly codecId: string; | ||
| readonly nullable: boolean; | ||
| readonly many?: boolean; | ||
| readonly typeParams?: Record<string, unknown>; | ||
| readonly typeRef?: string; | ||
| readonly default?: ColumnDefault; | ||
| readonly control?: ControlPolicy; | ||
| readonly valueSet?: ValueSetRef; | ||
| constructor(input: StorageColumnInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/unique-constraint.d.ts | ||
| interface UniqueConstraintInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a table-level unique constraint. | ||
| */ | ||
| declare class UniqueConstraint extends SqlNode { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| constructor(input: UniqueConstraintInput); | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-table.d.ts | ||
| interface StorageTableInput { | ||
| readonly columns: Record<string, StorageColumn | StorageColumnInput>; | ||
| readonly primaryKey?: PrimaryKey | PrimaryKeyInput; | ||
| readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>; | ||
| readonly indexes: ReadonlyArray<Index | IndexInput>; | ||
| readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>; | ||
| readonly control?: ControlPolicy; | ||
| readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a single table entry in a namespace's | ||
| * `tables` map. | ||
| * | ||
| * The constructor normalises nested IR-class fields (columns, primary | ||
| * key, uniques, indexes, foreign keys) into the appropriate class | ||
| * instances so downstream walks see a uniform AST regardless of whether | ||
| * the input was a JSON literal or an already-constructed class. | ||
| * | ||
| * The table's `name` is not on the class — tables are keyed by name in | ||
| * the parent namespace's `tables: Record<string, StorageTable>` map. | ||
| */ | ||
| declare class StorageTable extends SqlNode { | ||
| readonly columns: Readonly<Record<string, StorageColumn>>; | ||
| readonly uniques: ReadonlyArray<UniqueConstraint>; | ||
| readonly indexes: ReadonlyArray<Index>; | ||
| readonly foreignKeys: ReadonlyArray<ForeignKey>; | ||
| readonly primaryKey?: PrimaryKey; | ||
| readonly control?: ControlPolicy; | ||
| readonly checks?: ReadonlyArray<CheckConstraint>; | ||
| constructor(input: StorageTableInput); | ||
| } | ||
| declare function isStorageTable(value: unknown): value is StorageTable; | ||
| //#endregion | ||
| //#region src/ir/storage-value-set.d.ts | ||
| /** | ||
| * Hydration / construction input shape for {@link StorageValueSet}. | ||
| * Mirrors the on-disk storage JSON envelope so the serializer hydration | ||
| * walker can hand a validated literal straight to `new`. | ||
| */ | ||
| interface StorageValueSetInput { | ||
| readonly kind: 'valueSet'; | ||
| /** Ordered permitted values, codec-encoded. Declaration order is preserved. */ | ||
| readonly values: readonly JsonValue[]; | ||
| } | ||
| /** | ||
| * SQL Contract IR node for a value-set entry in a namespace's `valueSet` | ||
| * map (`SqlNamespace.entries.valueSet`). | ||
| * | ||
| * A value-set records the ordered set of permitted codec-encoded values for | ||
| * an enum-like column restriction. It does not carry a `codecId` — the | ||
| * column that references it already holds the codec; the value-set holds | ||
| * only the permitted values. | ||
| * | ||
| * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope | ||
| * carries the discriminator and the serializer hydration walker can | ||
| * dispatch on it. This follows the per-leaf enumerable-kind convention | ||
| * established in the SQL-node comment (future polymorphic dispatch on | ||
| * namespace entries needs the discriminator in JSON). | ||
| * | ||
| * The entry's name is not on the class — value-sets are keyed by name in | ||
| * the parent namespace's `valueSet: Record<string, StorageValueSet>` map. | ||
| */ | ||
| declare class StorageValueSet extends SqlNode { | ||
| readonly kind: "valueSet"; | ||
| readonly values: readonly JsonValue[]; | ||
| constructor(input: StorageValueSetInput); | ||
| } | ||
| declare function isStorageValueSet(value: unknown): value is StorageValueSet; | ||
| //#endregion | ||
| export { StorageTableInput as a, UniqueConstraintInput as c, Index as d, IndexInput as f, CheckConstraintInput as g, CheckConstraint as h, StorageTable as i, StorageColumn as l, PrimaryKeyInput as m, StorageValueSetInput as n, isStorageTable as o, PrimaryKey as p, isStorageValueSet as r, UniqueConstraint as s, StorageValueSet as t, StorageColumnInput as u }; | ||
| //# sourceMappingURL=storage-value-set-B1Xmb6D2.d.mts.map |
| {"version":3,"file":"storage-value-set-B1Xmb6D2.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts"],"mappings":";;;;;;AASA;;;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;AAAA;AAiBhC;;;;;;;;;;;;cAAa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAA;cAEP,KAAA,EAAO,oBAAA;AAAA;;;UC/BJ,eAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAI;AAAA;;;;cAMF,UAAA,SAAmB,OAAO;EAAA,SAC5B,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,eAAA;AAAA;;;UCZJ,UAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;;;;;AFKK;AAiBhC;cEXa,KAAA,SAAc,OAAA;EAAA,SAChB,OAAA;EAAA,SACQ,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;cAEf,KAAA,EAAO,UAAA;AAAA;;;;;AFfrB;;;;;;;;UGKiB,kBAAA;EAAA,SACN,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,IAAA;EAAA,SACA,UAAA,GAAa,MAAA;EAAA,SACb,OAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,OAAA,GAAU,aAAA;EAAA,SACV,QAAA,GAAW,WAAA;AAAA;;;;;;;;;AHWmB;;;;AC/BzC;cEoCa,aAAA,SAAsB,OAAA;EAAA,SACxB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACQ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;;;;;;cMIa,eAAA,SAAwB,OAAA;EAAA,SACjB,IAAA;EAAA,SACT,MAAA,WAAiB,SAAA;cAEd,KAAA,EAAO,oBAAA;AAAA;AAAA,iBAOL,iBAAA,CAAkB,KAAA,YAAiB,KAAA,IAAS,eAAe"} |
| import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir"; | ||
| import { asNamespaceId } from "@prisma-next/contract/types"; | ||
| //#region src/ir/sql-node.ts | ||
| /** | ||
| * SQL family IR node base. Carries the family-level `kind` discriminator | ||
| * `'sql'` and inherits the framework's `freezeNode` affordance. | ||
| * | ||
| * Single family-level discriminator (not per-leaf) reflects the fact that | ||
| * SQL IR has no polymorphic dispatch today — verifiers and serializers | ||
| * walk by structural position (`storage.tables[name].columns[name]`), | ||
| * not by inspecting `kind`. The abstract bar for per-leaf discriminators | ||
| * isn't earned until a future polymorphic consumer arrives. | ||
| * | ||
| * `kind` is installed as a non-enumerable own property on every instance, | ||
| * which keeps three things clean simultaneously: | ||
| * | ||
| * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope | ||
| * shape (no `kind` field), so emitted contract.json files and the | ||
| * `validateSqlContractFully` arktype schemas stay unchanged. | ||
| * - Test assertions that use `toEqual({...})` against the pre-lift flat | ||
| * shape continue to pass — only enumerable own properties are | ||
| * compared. | ||
| * - Direct access (`node.kind`) and runtime narrowing | ||
| * (`if (node.kind === 'sql')`) still work, so future polymorphic | ||
| * dispatch can begin reading `kind` without a runtime change. | ||
| * | ||
| * Future per-leaf overrides land cleanly: a class that gains a | ||
| * polymorphic-dispatch consumer (e.g. an enum type instance walked | ||
| * alongside other types) overrides `kind` with its narrower literal | ||
| * at that leaf level. Per-leaf overrides will use enumerable kind | ||
| * (matching the Mongo per-class-discriminator precedent) because they | ||
| * encode dispatch-relevant information that callers need to see in | ||
| * JSON envelopes; the family-level `'sql'` is uniform across all SQL | ||
| * IR and carries no dispatch-relevant information. | ||
| */ | ||
| var SqlNode = class extends IRNodeBase { | ||
| kind; | ||
| constructor() { | ||
| super(); | ||
| Object.defineProperty(this, "kind", { | ||
| value: "sql", | ||
| writable: false, | ||
| enumerable: false, | ||
| configurable: true | ||
| }); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/check-constraint.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level check constraint that restricts | ||
| * a column to the permitted values of a value-set. | ||
| * | ||
| * The constraint is **structured** (names a column and a value-set | ||
| * reference), not a raw SQL expression. Each target renders its own DDL | ||
| * from the structured form, keeping the contract target-agnostic. | ||
| * | ||
| * Construction is idempotent: passing an existing `CheckConstraint` | ||
| * instance as input produces a new instance with identical fields. | ||
| * The constructor does not use `instanceof` for input discrimination — | ||
| * it reads plain named properties, which is sufficient since | ||
| * `CheckConstraintInput` is a structural type. | ||
| */ | ||
| var CheckConstraint = class extends SqlNode { | ||
| name; | ||
| column; | ||
| valueSet; | ||
| constructor(input) { | ||
| super(); | ||
| this.name = input.name; | ||
| this.column = input.column; | ||
| this.valueSet = input.valueSet; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/foreign-key-reference.ts | ||
| /** | ||
| * SQL Contract IR node for one side (source or target) of a foreign-key | ||
| * declaration. Carries the full coordinate: namespace, table, and columns. | ||
| * | ||
| * Cross-space discrimination is based on `spaceId` presence: absent means | ||
| * local (same contract-space); present means cross-space (the referenced | ||
| * table lives in the contract-space identified by `spaceId`). | ||
| * | ||
| * For local references `spaceId` is absent from JSON, keeping the serialized | ||
| * shape byte-identical to contracts authored before cross-space support was | ||
| * added. For cross-space references `spaceId` appears in JSON so round-trips | ||
| * are lossless. | ||
| * | ||
| * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir` | ||
| * as the sentinel `namespaceId` for single-namespace (unbound) references. | ||
| */ | ||
| var ForeignKeyReference = class extends SqlNode { | ||
| namespaceId; | ||
| tableName; | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.namespaceId = asNamespaceId(input.namespaceId); | ||
| this.tableName = input.tableName; | ||
| this.columns = input.columns; | ||
| if (input.spaceId !== void 0) this.spaceId = input.spaceId; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/foreign-key.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level foreign-key declaration. | ||
| * | ||
| * Each FK carries explicit `source` and `target` {@link ForeignKeyReference} | ||
| * coordinates (namespace, table, columns). For single-namespace contracts the | ||
| * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides. | ||
| * | ||
| * The nested references are normalised to {@link ForeignKeyReference} | ||
| * instances inside the constructor so downstream walks see a uniform AST | ||
| * regardless of whether the input was a JSON literal or an already-constructed | ||
| * class instance. | ||
| */ | ||
| var ForeignKey = class extends SqlNode { | ||
| source; | ||
| target; | ||
| constraint; | ||
| index; | ||
| constructor(input) { | ||
| super(); | ||
| this.source = input.source instanceof ForeignKeyReference ? input.source : new ForeignKeyReference(input.source); | ||
| this.target = input.target instanceof ForeignKeyReference ? input.target : new ForeignKeyReference(input.target); | ||
| this.constraint = input.constraint; | ||
| this.index = input.index; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| if (input.onDelete !== void 0) this.onDelete = input.onDelete; | ||
| if (input.onUpdate !== void 0) this.onUpdate = input.onUpdate; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/primary-key.ts | ||
| /** | ||
| * SQL Contract IR node for a table's primary-key constraint. | ||
| */ | ||
| var PrimaryKey = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/sql-index.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level secondary index. | ||
| * | ||
| * Note that this class shadows the global TypeScript `Index` lib type | ||
| * at the family-shared name; consumer files that need both should | ||
| * alias one (e.g. | ||
| * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`). | ||
| */ | ||
| var Index = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| if (input.type !== void 0) this.type = input.type; | ||
| if (input.options !== void 0) this.options = input.options; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/storage-column.ts | ||
| /** | ||
| * SQL Contract IR node for a single column entry in `StorageTable.columns`. | ||
| * | ||
| * Single concrete family-shared class — every SQL target reads the | ||
| * same column shape today, so there is no per-target subclass. The | ||
| * class type accepts any caller that constructs via | ||
| * `new StorageColumn(input)`; literal construction sites must pass | ||
| * through the constructor or the family-base hydration walker. | ||
| * | ||
| * The column's `name` is not on the class — columns are keyed by name | ||
| * in the parent `StorageTable.columns: Record<string, StorageColumn>` | ||
| * map, so a `name` field would be redundant with the key. | ||
| */ | ||
| var StorageColumn = class extends SqlNode { | ||
| nativeType; | ||
| codecId; | ||
| nullable; | ||
| constructor(input) { | ||
| super(); | ||
| this.nativeType = input.nativeType; | ||
| this.codecId = input.codecId; | ||
| this.nullable = input.nullable; | ||
| if (input.many !== void 0) this.many = input.many; | ||
| if (input.typeParams !== void 0) this.typeParams = input.typeParams; | ||
| if (input.typeRef !== void 0) this.typeRef = input.typeRef; | ||
| if (input.default !== void 0) this.default = input.default; | ||
| if (input.control !== void 0) this.control = input.control; | ||
| if (input.valueSet !== void 0) this.valueSet = input.valueSet; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/unique-constraint.ts | ||
| /** | ||
| * SQL Contract IR node for a table-level unique constraint. | ||
| */ | ||
| var UniqueConstraint = class extends SqlNode { | ||
| columns; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = input.columns; | ||
| if (input.name !== void 0) this.name = input.name; | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ir/storage-table.ts | ||
| /** | ||
| * SQL Contract IR node for a single table entry in a namespace's | ||
| * `tables` map. | ||
| * | ||
| * The constructor normalises nested IR-class fields (columns, primary | ||
| * key, uniques, indexes, foreign keys) into the appropriate class | ||
| * instances so downstream walks see a uniform AST regardless of whether | ||
| * the input was a JSON literal or an already-constructed class. | ||
| * | ||
| * The table's `name` is not on the class — tables are keyed by name in | ||
| * the parent namespace's `tables: Record<string, StorageTable>` map. | ||
| */ | ||
| var StorageTable = class extends SqlNode { | ||
| columns; | ||
| uniques; | ||
| indexes; | ||
| foreignKeys; | ||
| constructor(input) { | ||
| super(); | ||
| this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([name, col]) => [name, col instanceof StorageColumn ? col : new StorageColumn(col)]))); | ||
| if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey); | ||
| this.uniques = Object.freeze(input.uniques.map((u) => u instanceof UniqueConstraint ? u : new UniqueConstraint(u))); | ||
| this.indexes = Object.freeze(input.indexes.map((i) => i instanceof Index ? i : new Index(i))); | ||
| this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof ForeignKey ? fk : new ForeignKey(fk))); | ||
| if (input.control !== void 0) this.control = input.control; | ||
| if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc))); | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| function isStorageTable(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return "columns" in value && "uniques" in value && "indexes" in value && "foreignKeys" in value; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/storage-value-set.ts | ||
| /** | ||
| * SQL Contract IR node for a value-set entry in a namespace's `valueSet` | ||
| * map (`SqlNamespace.entries.valueSet`). | ||
| * | ||
| * A value-set records the ordered set of permitted codec-encoded values for | ||
| * an enum-like column restriction. It does not carry a `codecId` — the | ||
| * column that references it already holds the codec; the value-set holds | ||
| * only the permitted values. | ||
| * | ||
| * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope | ||
| * carries the discriminator and the serializer hydration walker can | ||
| * dispatch on it. This follows the per-leaf enumerable-kind convention | ||
| * established in the SQL-node comment (future polymorphic dispatch on | ||
| * namespace entries needs the discriminator in JSON). | ||
| * | ||
| * The entry's name is not on the class — value-sets are keyed by name in | ||
| * the parent namespace's `valueSet: Record<string, StorageValueSet>` map. | ||
| */ | ||
| var StorageValueSet = class extends SqlNode { | ||
| kind = "valueSet"; | ||
| values; | ||
| constructor(input) { | ||
| super(); | ||
| this.values = Object.freeze([...input.values]); | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| function isStorageValueSet(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return "kind" in value && value.kind === "valueSet" && "values" in value; | ||
| } | ||
| //#endregion | ||
| export { UniqueConstraint as a, PrimaryKey as c, CheckConstraint as d, SqlNode as f, isStorageTable as i, ForeignKey as l, isStorageValueSet as n, StorageColumn as o, StorageTable as r, Index as s, StorageValueSet as t, ForeignKeyReference as u }; | ||
| //# sourceMappingURL=storage-value-set-Cp7h3D59.mjs.map |
| {"version":3,"file":"storage-value-set-Cp7h3D59.mjs","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. StorageValueSet)\n // can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly many?: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly many?: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.many !== undefined) this.many = input.many;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n}\n\nexport function isStorageTable(value: unknown): value is StorageTable {\n if (typeof value !== 'object' || value === null) return false;\n return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value;\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'valueSet';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly JsonValue[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'valueSet' as const;\n readonly values: readonly JsonValue[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n\nexport function isStorageValueSet(value: unknown): value is StorageValueSet {\n if (typeof value !== 'object' || value === null) return false;\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0C;CAC1E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,OAAO,UAAU,SAAS,MAAM,SAAS,cAAc,YAAY;AACrE"} |
| import { f as SqlNode } from "./storage-value-set-Cp7h3D59.mjs"; | ||
| import { NamespaceBase, freezeNode, isPlainRecord } from "@prisma-next/framework-components/ir"; | ||
| //#region src/ir/storage-type-instance.ts | ||
| /** | ||
| * Sentinel kind for the legacy codec-triple shape persisted under | ||
| * `SqlStorage.types`. Plain JSON-clean object literals carry this | ||
| * discriminator so the polymorphic slot dispatch can route them down | ||
| * the codec path while target-specific IR class instances (e.g. the | ||
| * Postgres enum class) keep their own narrower `kind` literal. | ||
| */ | ||
| const CODEC_INSTANCE_KIND = "codec-instance"; | ||
| /** | ||
| * Stamp the codec-instance `kind` discriminator on a caller-supplied | ||
| * codec triple. Idempotent: input that already carries the discriminator | ||
| * passes through unchanged. Missing `typeParams` is normalised to `{}`. | ||
| */ | ||
| function toStorageTypeInstance(input) { | ||
| return { | ||
| kind: CODEC_INSTANCE_KIND, | ||
| codecId: input.codecId, | ||
| nativeType: input.nativeType, | ||
| typeParams: input.typeParams ?? {} | ||
| }; | ||
| } | ||
| /** | ||
| * Type-guard for codec-typed entries on the polymorphic | ||
| * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from | ||
| * any class-instance kinds a target pack contributes. | ||
| */ | ||
| function isStorageTypeInstance(value) { | ||
| if (typeof value !== "object" || value === null) return false; | ||
| return value.kind === CODEC_INSTANCE_KIND; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-storage.ts | ||
| /** | ||
| * Narrows framework `AuthoringContributions` to the SQL-family shape by testing | ||
| * for the SQL-specific `createNamespace` capability. | ||
| */ | ||
| function isSqlAuthoringContributions(authoring) { | ||
| if (authoring === void 0 || !Object.hasOwn(authoring, "createNamespace")) return false; | ||
| return typeof Reflect.get(authoring, "createNamespace") === "function"; | ||
| } | ||
| /** | ||
| * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`, | ||
| * `SqliteDatabase`, …) extend this — it is never instantiated directly. | ||
| * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]` | ||
| * addresses any entity. | ||
| */ | ||
| var SqlNamespaceBase = class extends NamespaceBase {}; | ||
| /** | ||
| * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks | ||
| * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it | ||
| * survives duplicate-module boundaries (e.g. dist e2e where the target and | ||
| * the family carry separate copies of `@prisma-next/framework-components`). | ||
| * | ||
| * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`, | ||
| * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput` | ||
| * objects (`{ id, entries }`) do not. | ||
| */ | ||
| function isMaterializedSqlNamespace(x) { | ||
| if (typeof x !== "object" || x === null || !("qualifyTable" in x)) return false; | ||
| return typeof x.qualifyTable === "function"; | ||
| } | ||
| var SqlStorage = class extends SqlNode { | ||
| storageHash; | ||
| namespaces; | ||
| constructor(input) { | ||
| super(); | ||
| this.storageHash = input.storageHash; | ||
| this.namespaces = Object.freeze(input.namespaces); | ||
| if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]))); | ||
| freezeNode(this); | ||
| } | ||
| }; | ||
| /** | ||
| * Strict polymorphic-slot dispatch for `SqlStorage.types` entries. | ||
| * Every entry must carry a `kind: 'codec-instance'` discriminator or | ||
| * be an already-constructed `StorageTypeInstance`. Untagged or | ||
| * unrecognised inputs throw a diagnostic naming the entry and its | ||
| * `kind`, so format drift surfaces loudly at the deserializer | ||
| * boundary instead of slipping past the seam and corrupting | ||
| * downstream IR walks. | ||
| * | ||
| * Codec-triple authors that have an untagged shape on hand can call | ||
| * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'` | ||
| * discriminator) before constructing `SqlStorage`. On-disk reads | ||
| * cross `familyInstance.deserializeContract` first; the structural | ||
| * arktype schema rejects untagged entries earlier, so this throw | ||
| * only fires for in-memory authoring bugs. | ||
| */ | ||
| function normaliseTypeEntry(name, entry) { | ||
| if (isStorageTypeInstance(entry)) { | ||
| if ("typeParams" in entry) return entry; | ||
| return toStorageTypeInstance(entry); | ||
| } | ||
| const rawKind = isPlainRecord(entry) ? entry["kind"] : void 0; | ||
| const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`; | ||
| throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`); | ||
| } | ||
| //#endregion | ||
| //#region src/types.ts | ||
| const DEFAULT_FK_CONSTRAINT = true; | ||
| const DEFAULT_FK_INDEX = true; | ||
| function applyFkDefaults(fk, overrideDefaults) { | ||
| return { | ||
| constraint: fk.constraint ?? overrideDefaults?.constraint ?? true, | ||
| index: fk.index ?? overrideDefaults?.index ?? true | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { SqlStorage as a, CODEC_INSTANCE_KIND as c, SqlNamespaceBase as i, isStorageTypeInstance as l, DEFAULT_FK_INDEX as n, isMaterializedSqlNamespace as o, applyFkDefaults as r, isSqlAuthoringContributions as s, DEFAULT_FK_CONSTRAINT as t, toStorageTypeInstance as u }; | ||
| //# sourceMappingURL=types-B4sPkjNO.mjs.map |
| {"version":3,"file":"types-B4sPkjNO.mjs","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Sentinel kind for the legacy codec-triple shape persisted under\n * `SqlStorage.types`. Plain JSON-clean object literals carry this\n * discriminator so the polymorphic slot dispatch can route them down\n * the codec path while target-specific IR class instances (e.g. the\n * Postgres enum class) keep their own narrower `kind` literal.\n */\nexport const CODEC_INSTANCE_KIND = 'codec-instance' as const;\n\n/**\n * Structural sub-interface of {@link StorageType} for codec-typed entries\n * in `SqlStorage.types`. These are plain object literals — there is no\n * runtime IR class, the JSON envelope round-trips through the slot\n * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch\n * key that distinguishes codec-typed entries from any class-instance\n * kinds a target pack contributes to the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n * `typeParams` may be omitted on input; the constructor normalises a\n * missing value to `{}` so the in-memory shape is always present.\n */\nexport interface StorageTypeInstanceInput {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n}\n\n/**\n * Stamp the codec-instance `kind` discriminator on a caller-supplied\n * codec triple. Idempotent: input that already carries the discriminator\n * passes through unchanged. Missing `typeParams` is normalised to `{}`.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams ?? {},\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * any class-instance kinds a target pack contributes.\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport type { AuthoringContributions } from '@prisma-next/framework-components/authoring';\nimport {\n freezeNode,\n isPlainRecord,\n type Namespace,\n NamespaceBase,\n type Storage,\n} from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\nimport type { StorageTable } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet } from './storage-value-set';\n\n/**\n * Polymorphic value type for document-scoped `SqlStorage.types` entries\n * (codec aliases / parameterised native type registrations).\n *\n * Postgres native enum registrations live under the postgres-specific\n * `entries.type` slot on `PostgresSchema` (target layer), not here.\n */\nexport type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;\n\nexport interface SqlNamespaceInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Target-supplied factory that materializes a `Namespace` from a SQL\n * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`).\n */\nexport type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace;\n\n/**\n * SQL-family extension of the framework `AuthoringContributions`. SQL target\n * packs add a `createNamespace` factory so the PSL/TS authoring paths can\n * materialize namespaces (and merge lowered extension-block entities) without\n * each consumer re-specifying it. The factory is SQL-specific, so it lives here\n * rather than on the framework `AuthoringContributions` base.\n */\nexport interface SqlAuthoringContributions extends AuthoringContributions {\n readonly createNamespace?: SqlNamespaceFactory;\n}\n\n/**\n * Narrows framework `AuthoringContributions` to the SQL-family shape by testing\n * for the SQL-specific `createNamespace` capability.\n */\nexport function isSqlAuthoringContributions(\n authoring: AuthoringContributions | undefined,\n): authoring is SqlAuthoringContributions {\n if (authoring === undefined || !Object.hasOwn(authoring, 'createNamespace')) {\n return false;\n }\n return typeof Reflect.get(authoring, 'createNamespace') === 'function';\n}\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>;\n}\n\n/**\n * SQL Contract IR root node for the `storage` field.\n *\n * Single concrete family-shared class — both Postgres and SQLite\n * consume this class today. Per-target storage subclasses are\n * introduced when each target's namespace shape earns its\n * target-specific concretion (target-specific derived fields,\n * target-specific storage extensions).\n *\n * Honours the framework `Storage` interface: every SQL IR carries a\n * `namespaces` map keyed by namespace id. Callers must supply fully\n * constructed `Namespace` instances — construction discipline lives\n * in the authoring builders and deserializer hydration paths.\n *\n * The constructor normalises optional `types` into class instances.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; hydration of raw JSON\n * class-instance entries (carrying their narrower `kind` literal) is\n * the per-target serializer's responsibility (so the family base does\n * not import target-specific subclasses).\n */\n/**\n * The typed `entries` shape for SQL family namespaces. The open dictionary\n * is intersected with optional known-kind maps so that `ns.entries.table`\n * and `ns.entries.valueSet` resolve without a cast, while unknown pack-\n * contributed kinds remain valid (the `Record` part allows any string key).\n */\nexport type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {\n readonly table?: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n};\n\n/**\n * Structural interface for SQL family namespaces. Generated `.d.ts` contract\n * types satisfy this structurally (no prototype methods). The runtime\n * abstract class `SqlNamespaceBase` extends this.\n *\n * `qualifyTable` is optional so JSON-shaped contract types (which carry no\n * methods) are accepted where `SqlNamespace` is required. Hydrated\n * `SqlNamespaceBase` instances always have it.\n */\nexport interface SqlNamespace {\n readonly kind: string;\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n qualifyTable?(tableName: string): string;\n}\n\n/**\n * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) extend this — it is never instantiated directly.\n * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`\n * addresses any entity.\n */\nexport abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {\n abstract override readonly id: string;\n abstract override readonly entries: SqlNamespaceEntries;\n\n abstract qualifyTable(tableName: string): string;\n}\n\n/**\n * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks\n * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it\n * survives duplicate-module boundaries (e.g. dist e2e where the target and\n * the family carry separate copies of `@prisma-next/framework-components`).\n *\n * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,\n * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`\n * objects (`{ id, entries }`) do not.\n */\nexport function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase {\n if (typeof x !== 'object' || x === null || !('qualifyTable' in x)) return false;\n return typeof x.qualifyTable === 'function';\n}\n\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n declare readonly types?: Readonly<Record<string, StorageTypeInstance>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.namespaces = Object.freeze(input.namespaces);\n if (input.types !== undefined) {\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]),\n ),\n );\n }\n freezeNode(this);\n }\n}\n\n/**\n * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.\n * Every entry must carry a `kind: 'codec-instance'` discriminator or\n * be an already-constructed `StorageTypeInstance`. Untagged or\n * unrecognised inputs throw a diagnostic naming the entry and its\n * `kind`, so format drift surfaces loudly at the deserializer\n * boundary instead of slipping past the seam and corrupting\n * downstream IR walks.\n *\n * Codec-triple authors that have an untagged shape on hand can call\n * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`\n * discriminator) before constructing `SqlStorage`. On-disk reads\n * cross `familyInstance.deserializeContract` first; the structural\n * arktype schema rejects untagged entries earlier, so this throw\n * only fires for in-memory authoring bugs.\n */\nfunction normaliseTypeEntry(name: string, entry: SqlStorageTypeEntry): StorageTypeInstance {\n if (isStorageTypeInstance(entry)) {\n // Normalise on-disk objects that omit `typeParams` (the canonical on-disk\n // form strips empty typeParams to keep JSON compact). The in-memory invariant\n // is always `typeParams: {}` when empty — never `undefined`. Only create a\n // new object when necessary to preserve identity-equality for callers that\n // hold a reference to an already-correct in-memory entry.\n if ('typeParams' in entry) {\n return entry;\n }\n return toStorageTypeInstance(entry);\n }\n const rawKind = isPlainRecord(entry) ? entry['kind'] : undefined;\n const kindDescription =\n rawKind === undefined\n ? 'missing `kind` discriminator'\n : `unrecognised \\`kind\\` discriminator ${JSON.stringify(rawKind)}`;\n throw new Error(\n `storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify('codec-instance')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport interface SqlControlDriverInstance<T extends string = string>\n extends ControlDriverInstance<'sql', T> {\n query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }>;\n}\n\nexport { CheckConstraint, type CheckConstraintInput } from './ir/check-constraint';\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReference,\n type ForeignKeyReferenceInput,\n} from './ir/foreign-key-reference';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n isMaterializedSqlNamespace,\n isSqlAuthoringContributions,\n type SqlAuthoringContributions,\n type SqlNamespace,\n SqlNamespaceBase,\n type SqlNamespaceEntries,\n type SqlNamespaceFactory,\n type SqlNamespaceInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { StorageColumn, type StorageColumnInput } from './ir/storage-column';\nexport { isStorageTable, StorageTable, type StorageTableInput } from './ir/storage-table';\nexport {\n CODEC_INSTANCE_KIND,\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './ir/storage-type-instance';\nexport {\n isStorageValueSet,\n StorageValueSet,\n type StorageValueSetInput,\n} from './ir/storage-value-set';\nexport {\n UniqueConstraint,\n type UniqueConstraintInput,\n} from './ir/unique-constraint';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly namespaceId: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\n// Field-type maps nested by namespace coordinate: `[namespaceId][model][field]`.\n// Shared by the output and input field-type maps and their extractors.\nexport type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;\n\nexport type NamespacedStorageColumnTypeMap = Record<\n string,\n Record<string, Record<string, unknown>>\n>;\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TStorageColumnTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n TStorageColumnInputTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n readonly storageColumnTypes: TStorageColumnTypes;\n readonly storageColumnInputTypes: TStorageColumnInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Names a concrete codec identity, a set of capability traits the\n * field's codec must carry, or targets list-typed (`many`) fields. Element\n * capability gating for list ops travels in `elementTraits`.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never; readonly many?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never; readonly many?: never }\n | {\n readonly many: true;\n readonly elementTraits?: readonly CodecTrait[];\n readonly codecId?: never;\n readonly traits?: never;\n };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnInputTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnTypes<T> = StorageColumnTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnInputTypes<T> = StorageColumnInputTypesOf<\n ExtractTypeMapsFromContract<T>\n>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;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