🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@prisma-next/sql-contract

Package Overview
Dependencies
Maintainers
3
Versions
950
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma-next/sql-contract - npm Package Compare versions

Comparing version
0.14.0-dev.11
to
0.14.0-dev.12
+149
dist/sql-storage-BqbeAE6l.d.mts
import { o as SqlNode } from "./foreign-key-BATxB95l.mjs";
import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-WnYsIFM8.mjs";
import { Namespace, 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 SqlNamespaceTablesInput {
readonly id: string;
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
}
/**
* Target-supplied factory that materializes a `Namespace` from a SQL
* `SqlNamespaceTablesInput` (used to populate `SqlStorage.namespaces`).
*/
type SqlNamespaceFactory = (input: SqlNamespaceTablesInput) => 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, SqlNamespace>>;
}
/**
* 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>>;
};
/**
* SQL family namespace. `entries` is the open ADR 224 dictionary —
* `entries[entityKind][entityName]` addresses any entity. Emitted
* contract literals satisfy this structurally (no prototype getters
* needed). For typed access to specific kinds, use the class getters
* on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.
*/
type SqlNamespace = Namespace & {
readonly entries: SqlNamespaceEntries;
/**
* Render a dialect-qualified table reference for runtime SQL emission.
* Present on materialised target concretions (`PostgresSchema`,
* `SqliteDatabase`, …) and family placeholders; omitted on emitted
* contract structural namespace literals (methods are not serialised).
*/
qualifyTable?(tableName: string): string;
};
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 { SqlNamespaceTablesInput as a, SqlStorageTypeEntry as c, StorageTypeInstance as d, StorageTypeInstanceInput as f, SqlNamespaceFactory as i, isSqlAuthoringContributions as l, toStorageTypeInstance as m, SqlNamespace as n, SqlStorage as o, isStorageTypeInstance as p, SqlNamespaceEntries as r, SqlStorageInput as s, SqlAuthoringContributions as t, CODEC_INSTANCE_KIND as u };
//# sourceMappingURL=sql-storage-BqbeAE6l.d.mts.map
{"version":3,"file":"sql-storage-BqbeAE6l.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,KCWY,mBAAA,GAAsB,mBAAA,GAAsB,wBAAwB;AAAA,UAE/D,uBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;KAOzC,mBAAA,IAAuB,KAAA,EAAO,uBAAA,KAA4B,SAAS;;;;;ADRlD;AAU7B;;UCOiB,yBAAA,SAAkC,sBAAsB;EAAA,SAC9D,eAAA,GAAkB,mBAAA;AAAA;;;;;iBAOb,2BAAA,CACd,SAAA,EAAW,sBAAA,eACV,SAAA,IAAa,yBAAyB;AAAA,UAOxB,eAAA;EAAA,SACN,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,KAAA,GAAQ,MAAA,SAAe,mBAAA;EAAA,SACvB,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,YAAA;AAAA;;;;ADhB4C;AAc3F;;;;;;;;AAAmF;;;;ACtCnF;;;;AAAgF;AAEhF;;;;;;AAAA,KAoEY,mBAAA,GAAsB,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;EAAA,SACxD,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAChC,QAAA,GAAW,QAAA,CAAS,MAAA,SAAe,eAAA;AAAA;;;;;;;AApEa;KA8E/C,YAAA,GAAe,SAAA;EAAA,SAChB,OAAA,EAAS,mBAAmB;;;;;;;EAOrC,YAAA,EAAc,SAAA;AAAA;AAAA,cAGH,UAAA,wCAAkD,OAAA,YAAmB,OAAA;EAAA,SACvE,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,SAC5B,KAAA,GAAQ,QAAA,CAAS,MAAA,SAAe,mBAAA;cAErC,KAAA,EAAO,eAAA,CAAgB,KAAA;AAAA"}
import { r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
import { a as SqlNamespaceTablesInput, n as SqlNamespace, r as SqlNamespaceEntries } from "./sql-storage-BqbeAE6l.mjs";
import { Namespace, NamespaceBase } from "@prisma-next/framework-components/ir";
import { CodecTrait } from "@prisma-next/framework-components/codec";
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
//#region src/ir/build-sql-namespace.d.ts
declare function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace;
declare function buildSqlNamespaceMap(namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>): Readonly<Record<string, SqlNamespace>>;
//#endregion
//#region src/ir/sql-unbound-namespace.d.ts
/**
* Family-layer placeholder for the SQL unbound-namespace singleton —
* the late-bound slot whose binding the target resolves at connection
* time rather than at authoring time.
*
* SQL contracts honour the framework `Storage.namespaces` invariant from
* the moment they appear in the IR. Today `SqlStorage` is family-shared
* (Postgres + SQLite consume the same class); a per-target namespace
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
* earns its existence when each target's namespace shape lands. Until
* then the family ships a single placeholder singleton so the JSON
* envelope and runtime walk are honest at every layer.
*
* The `kind` discriminator is installed as a non-enumerable own property
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
* and bounded to the minimum data the framework `Namespace` interface
* promises.
*
* **Freeze-trap warning.** The leaf constructor calls
* `freezeNode(this)` after installing `kind`. The leaf-class shape
* works today only because `NamespaceBase` does NOT freeze in its
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
* `super()` succeeds because the instance is still mutable at that
* point. Subclasses that add instance fields will still hit the freeze
* trap once leaf-class `freezeNode(this)` runs; and if a future
* framework change lifts the freeze to `NamespaceBase`, even the
* `defineProperty` here would silently fail. To add subclass instance
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
* leaf calls explicitly at the end of its own constructor.
*/
declare class SqlUnboundNamespace extends NamespaceBase {
static readonly instance: SqlUnboundNamespace;
readonly id: "__unbound__";
readonly entries: SqlNamespaceEntries;
readonly kind: string;
private constructor();
get table(): Readonly<Record<string, StorageTable>>;
qualifyTable(tableName: string): string;
}
//#endregion
//#region src/types.d.ts
interface SqlControlDriverInstance<T extends string = string> extends ControlDriverInstance<'sql', T> {
query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<{
readonly rows: Row[];
}>;
}
type ForeignKeyOptions = {
readonly name?: string;
readonly onDelete?: ReferentialAction;
readonly onUpdate?: ReferentialAction;
};
type SqlModelFieldStorage = {
readonly column: string;
readonly codecId?: string;
readonly nullable?: boolean;
};
type SqlModelStorage = {
readonly table: string;
readonly namespaceId: string;
readonly fields: Record<string, SqlModelFieldStorage>;
};
declare const DEFAULT_FK_CONSTRAINT = true;
declare const DEFAULT_FK_INDEX = true;
declare function applyFkDefaults(fk: {
constraint?: boolean | undefined;
index?: boolean | undefined;
}, overrideDefaults?: {
constraint?: boolean | undefined;
index?: boolean | undefined;
}): {
constraint: boolean;
index: boolean;
};
type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;
type TypeMaps<TCodecTypes extends Record<string, {
output: unknown;
}> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>, TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>> = {
readonly codecTypes: TCodecTypes;
readonly queryOperationTypes: TQueryOperationTypes;
readonly fieldOutputTypes: TFieldOutputTypes;
readonly fieldInputTypes: TFieldInputTypes;
};
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly codecTypes: infer C;
} ? C extends Record<string, {
output: unknown;
}> ? C : Record<string, never> : Record<string, never>;
/**
* Dispatch hint identifying the first-argument target of an operation.
*
* Used by ORM column helpers to decide whether an operation is reachable on a
* field. Either names a concrete codec identity or a set of capability traits
* that the field's codec must carry.
*/
type QueryOperationSelfSpec = {
readonly codecId: string;
readonly traits?: never;
} | {
readonly traits: readonly CodecTrait[];
readonly codecId?: never;
};
/**
* Structural shape an operation's impl must return: any value carrying a
* codec-exact `returnType` descriptor. `Expression<T>` (from
* `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
* extends this. Trait-targeted returns are deliberately excluded — predicate
* detection and result decoding both depend on knowing the concrete return
* codec.
*/
type QueryOperationReturn = {
readonly returnType: {
readonly codecId: string;
readonly nullable: boolean;
};
};
type QueryOperationTypeEntry = {
readonly self?: QueryOperationSelfSpec;
readonly impl: (...args: never[]) => QueryOperationReturn;
};
type SqlQueryOperationTypes<_CT extends Record<string, {
readonly input: unknown;
readonly output: unknown;
}>, T extends Record<string, QueryOperationTypeEntry>> = T;
type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly queryOperationTypes: infer Q;
} ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly fieldOutputTypes: infer F;
} ? F extends NamespacedFieldTypeMap ? F : Record<string, never> : Record<string, never>;
type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly fieldInputTypes: infer F;
} ? F extends NamespacedFieldTypeMap ? F : Record<string, never> : Record<string, never>;
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
//#endregion
export { TypeMaps as C, buildSqlNamespace as D, SqlUnboundNamespace as E, buildSqlNamespaceMap as O, SqlQueryOperationTypes as S, applyFkDefaults as T, QueryOperationTypesOf as _, ExtractCodecTypes as a, SqlModelFieldStorage as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKeyOptions as f, QueryOperationTypesBase as g, QueryOperationTypeEntry as h, DEFAULT_FK_INDEX as i, ExtractTypeMapsFromContract as l, QueryOperationSelfSpec as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, QueryOperationReturn as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, ResolveCodecTypes as v, TypeMapsPhantomKey as w, SqlModelStorage as x, SqlControlDriverInstance as y };
//# sourceMappingURL=types-AtudkZcJ.d.mts.map
{"version":3,"file":"types-AtudkZcJ.d.mts","names":[],"sources":["../src/ir/build-sql-namespace.ts","../src/ir/sql-unbound-namespace.ts","../src/types.ts"],"mappings":";;;;;;;;iBAyFgB,iBAAA,CAAkB,KAAA,EAAO,uBAAA,GAA0B,YAAY;AAAA,iBAI/D,oBAAA,CACd,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,SAAA,GAAY,uBAAA,KAC/C,QAAA,CAAS,MAAA,SAAe,YAAA;;;;;;;;AAN3B;;;;;;;;AAA+E;AAI/E;;;;;;;;;;;;;;;;;cCrDa,mBAAA,SAA4B,aAAA;EAAA,gBACvB,QAAA,EAAU,mBAAA;EAAA,SAEjB,EAAA;EAAA,SACA,OAAA,EAAS,mBAAA;EAAA,SAMD,IAAA;EAAA,QAEV,WAAA;EAAA,IAWH,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAOrC,YAAA,CAAa,SAAA;AAAA;;;UClEE,wBAAA,oCACP,qBAAA,QAA6B,CAAA;EACrC,KAAA,OAAY,MAAA,mBACV,GAAA,UACA,MAAA,wBACC,OAAA;IAAA,SAAmB,IAAA,EAAM,GAAA;EAAA;AAAA;AAAA,KA4ClB,iBAAA;EAAA,SACD,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAiB;AAAA;AAAA,KAG3B,oBAAA;EAAA,SACD,MAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGC,eAAA;EAAA,SACD,KAAA;EAAA,SACA,WAAA;EAAA,SACA,MAAA,EAAQ,MAAM,SAAS,oBAAA;AAAA;AAAA,cAGrB,qBAAA;AAAA,cACA,gBAAA;AAAA,iBAEG,eAAA,CACd,EAAA;EAAM,UAAA;EAAkC,KAAA;AAAA,GACxC,gBAAA;EAAqB,UAAA;EAAkC,KAAA;AAAA;EACpD,UAAA;EAAqB,KAAA;AAAA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A,MAAiC,kBAAA,eAAiC,CAAA,GAC1E,WAAA,CAAY,CAAA,CAAE,kBAAA,SAA2B,CAAA;AAAA,KAGjC,kBAAA,OAAyB,CAAA,oBACjC,MAAA,kBACA,CAAA;EAAA,SAAqB,gBAAA;AAAA,IACnB,CAAA,SAAU,sBAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,OAAwB,CAAA,oBAChC,MAAA,kBACA,CAAA;EAAA,SAAqB,eAAA;AAAA,IACnB,CAAA,SAAU,sBAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,MAAuB,YAAA,CAAa,2BAAA,CAA4B,CAAA;AAAA,KAChE,0BAAA,MAAgC,qBAAA,CAAsB,2BAAA,CAA4B,CAAA;AAAA,KAClF,uBAAA,MAA6B,kBAAA,CAAmB,2BAAA,CAA4B,CAAA;AAAA,KAC5E,sBAAA,MAA4B,iBAAA,CAAkB,2BAAA,CAA4B,CAAA;AAAA,KAE1E,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
import { p as SqlNode, t as composeSqlEntityKinds } from "./entity-kinds-Cl36zL5j.mjs";
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
import { blindCast } from "@prisma-next/utils/casts";
//#region src/ir/sql-unbound-namespace.ts
/**
* Family-layer placeholder for the SQL unbound-namespace singleton —
* the late-bound slot whose binding the target resolves at connection
* time rather than at authoring time.
*
* SQL contracts honour the framework `Storage.namespaces` invariant from
* the moment they appear in the IR. Today `SqlStorage` is family-shared
* (Postgres + SQLite consume the same class); a per-target namespace
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
* earns its existence when each target's namespace shape lands. Until
* then the family ships a single placeholder singleton so the JSON
* envelope and runtime walk are honest at every layer.
*
* The `kind` discriminator is installed as a non-enumerable own property
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
* and bounded to the minimum data the framework `Namespace` interface
* promises.
*
* **Freeze-trap warning.** The leaf constructor calls
* `freezeNode(this)` after installing `kind`. The leaf-class shape
* works today only because `NamespaceBase` does NOT freeze in its
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
* `super()` succeeds because the instance is still mutable at that
* point. Subclasses that add instance fields will still hit the freeze
* trap once leaf-class `freezeNode(this)` runs; and if a future
* framework change lifts the freeze to `NamespaceBase`, even the
* `defineProperty` here would silently fail. To add subclass instance
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
* leaf calls explicitly at the end of its own constructor.
*/
var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
static instance = new SqlUnboundNamespace();
id = UNBOUND_NAMESPACE_ID;
entries = Object.freeze({ table: blindCast(Object.freeze({})) });
constructor() {
super();
Object.defineProperty(this, "kind", {
value: "sql-namespace",
writable: false,
enumerable: false,
configurable: true
});
freezeNode(this);
}
get table() {
return blindCast(this.entries["table"]);
}
qualifyTable(tableName) {
return `"${tableName}"`;
}
};
//#endregion
//#region src/ir/build-sql-namespace.ts
const SQL_NAMESPACE_KIND = "sql-namespace";
function isMaterializedSqlNamespace(ns) {
if (typeof ns !== "object" || ns === null) return false;
const proto = Object.getPrototypeOf(ns);
if (proto === Object.prototype || proto === null) return false;
return ns.kind === SQL_NAMESPACE_KIND;
}
var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
id;
entries;
static fromTablesInput(input) {
const tableKind = input.entries["table"];
const tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;
const valueSetKind = input.entries["valueSet"];
const hasValueSets = valueSetKind !== void 0 && Object.keys(valueSetKind).length > 0;
const hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== "table" && kind !== "valueSet");
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets && !hasUnknownKinds) return SqlUnboundNamespace.instance;
return new SqlBoundNamespace(input);
}
constructor(input) {
super();
this.id = input.id;
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
this.entries = Object.freeze(blindCast(dispatched));
Object.defineProperty(this, "kind", {
value: SQL_NAMESPACE_KIND,
writable: false,
enumerable: false,
configurable: true
});
freezeNode(this);
}
get table() {
return this.entries.table ?? Object.freeze({});
}
get valueSet() {
return this.entries.valueSet;
}
qualifyTable(tableName) {
if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
return `"${this.id}"."${tableName}"`;
}
};
function buildSqlNamespace(input) {
return SqlBoundNamespace.fromTablesInput(input);
}
function buildSqlNamespaceMap(namespaces) {
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? ns : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
}
//#endregion
//#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";
}
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 = entry.kind;
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 { isSqlAuthoringContributions as a, toStorageTypeInstance as c, SqlUnboundNamespace as d, SqlStorage as i, buildSqlNamespace as l, DEFAULT_FK_INDEX as n, CODEC_INSTANCE_KIND as o, applyFkDefaults as r, isStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, buildSqlNamespaceMap as u };
//# sourceMappingURL=types-CZ6MwpXG.mjs.map
{"version":3,"file":"types-CZ6MwpXG.mjs","names":[],"sources":["../src/ir/sql-unbound-namespace.ts","../src/ir/build-sql-namespace.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { SqlNamespaceEntries } from './sql-storage';\nimport type { StorageTable } from './storage-table';\n\n/**\n * Family-layer placeholder for the SQL unbound-namespace singleton —\n * the late-bound slot whose binding the target resolves at connection\n * time rather than at authoring time.\n *\n * SQL contracts honour the framework `Storage.namespaces` invariant from\n * the moment they appear in the IR. Today `SqlStorage` is family-shared\n * (Postgres + SQLite consume the same class); a per-target namespace\n * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)\n * earns its existence when each target's namespace shape lands. Until\n * then the family ships a single placeholder singleton so the JSON\n * envelope and runtime walk are honest at every layer.\n *\n * The `kind` discriminator is installed as a non-enumerable own property\n * so the JSON envelope reads `{ \"id\": \"__unbound__\", \"entries\": { … } }`\n * — symmetric with the family-level non-enumerable `kind` on `SqlNode`\n * and bounded to the minimum data the framework `Namespace` interface\n * promises.\n *\n * **Freeze-trap warning.** The leaf constructor calls\n * `freezeNode(this)` after installing `kind`. The leaf-class shape\n * works today only because `NamespaceBase` does NOT freeze in its\n * constructor — the `Object.defineProperty(this, 'kind', …)` call after\n * `super()` succeeds because the instance is still mutable at that\n * point. Subclasses that add instance fields will still hit the freeze\n * trap once leaf-class `freezeNode(this)` runs; and if a future\n * framework change lifts the freeze to `NamespaceBase`, even the\n * `defineProperty` here would silently fail. To add subclass instance\n * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each\n * leaf calls explicitly at the end of its own constructor.\n */\nexport class SqlUnboundNamespace extends NamespaceBase {\n static readonly instance: SqlUnboundNamespace = new SqlUnboundNamespace();\n\n readonly id = UNBOUND_NAMESPACE_ID;\n readonly entries: SqlNamespaceEntries = Object.freeze({\n table: blindCast<\n Readonly<Record<string, StorageTable>>,\n 'empty frozen map is a valid Readonly<Record<string, StorageTable>>'\n >(Object.freeze({})),\n });\n declare readonly kind: string;\n\n private constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql-namespace',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return blindCast<\n Readonly<Record<string, StorageTable>>,\n 'entries[table] holds only StorageTable by construction'\n >(this.entries['table']);\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { composeSqlEntityKinds } from '../entity-kinds';\nimport type { SqlNamespace, SqlNamespaceEntries, SqlNamespaceTablesInput } from './sql-storage';\nimport { SqlUnboundNamespace } from './sql-unbound-namespace';\nimport type { StorageTable } from './storage-table';\nimport type { StorageValueSet } from './storage-value-set';\n\nconst SQL_NAMESPACE_KIND = 'sql-namespace' as const;\n\nfunction isMaterializedSqlNamespace(ns: Namespace | SqlNamespaceTablesInput): ns is SqlNamespace {\n if (typeof ns !== 'object' || ns === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(ns);\n if (proto === Object.prototype || proto === null) {\n return false;\n }\n return (ns as Namespace).kind === SQL_NAMESPACE_KIND;\n}\n\nclass SqlBoundNamespace extends NamespaceBase {\n declare readonly kind: string;\n\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n\n static fromTablesInput(input: SqlNamespaceTablesInput): SqlNamespace {\n const tableKind = input.entries['table'];\n const tableCount = tableKind !== undefined ? Object.keys(tableKind).length : 0;\n const valueSetKind = input.entries['valueSet'];\n const hasValueSets = valueSetKind !== undefined && Object.keys(valueSetKind).length > 0;\n const hasUnknownKinds = Object.keys(input.entries).some(\n (kind) => kind !== 'table' && kind !== 'valueSet',\n );\n if (\n input.id === UNBOUND_NAMESPACE_ID &&\n tableCount === 0 &&\n !hasValueSets &&\n !hasUnknownKinds\n ) {\n return SqlUnboundNamespace.instance;\n }\n return new SqlBoundNamespace(input);\n }\n\n private constructor(input: SqlNamespaceTablesInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(dispatched),\n );\n Object.defineProperty(this, 'kind', {\n value: SQL_NAMESPACE_KIND,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\n }\n\n qualifyTable(tableName: string): string {\n if (this.id === UNBOUND_NAMESPACE_ID) {\n return `\"${tableName}\"`;\n }\n return `\"${this.id}\".\"${tableName}\"`;\n }\n}\n\nexport function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace {\n return SqlBoundNamespace.fromTablesInput(input);\n}\n\nexport function buildSqlNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>,\n): Readonly<Record<string, SqlNamespace>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsKey, ns]) => [\n nsKey,\n isMaterializedSqlNamespace(ns)\n ? ns\n : SqlBoundNamespace.fromTablesInput(\n blindCast<\n SqlNamespaceTablesInput,\n 'non-materialized SQL namespace map entry is a SqlNamespaceTablesInput'\n >(ns),\n ),\n ]),\n );\n}\n","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 { freezeNode, type Namespace, type Storage } 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 SqlNamespaceTablesInput {\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 * `SqlNamespaceTablesInput` (used to populate `SqlStorage.namespaces`).\n */\nexport type SqlNamespaceFactory = (input: SqlNamespaceTablesInput) => 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, SqlNamespace>>;\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 * SQL family namespace. `entries` is the open ADR 224 dictionary —\n * `entries[entityKind][entityName]` addresses any entity. Emitted\n * contract literals satisfy this structurally (no prototype getters\n * needed). For typed access to specific kinds, use the class getters\n * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.\n */\nexport type SqlNamespace = Namespace & {\n readonly entries: SqlNamespaceEntries;\n /**\n * Render a dialect-qualified table reference for runtime SQL emission.\n * Present on materialised target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) and family placeholders; omitted on emitted\n * contract structural namespace literals (methods are not serialised).\n */\n qualifyTable?(tableName: string): string;\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 = (entry as { kind?: unknown }).kind;\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 { buildSqlNamespace, buildSqlNamespaceMap } from './ir/build-sql-namespace';\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 isSqlAuthoringContributions,\n type SqlAuthoringContributions,\n type SqlNamespace,\n type SqlNamespaceEntries,\n type SqlNamespaceFactory,\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { SqlUnboundNamespace } from './ir/sql-unbound-namespace';\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 { StorageValueSet, type StorageValueSetInput } 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 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> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\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. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\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 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>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,sBAAb,MAAa,4BAA4B,cAAc;CACrD,OAAgB,WAAgC,IAAI,oBAAoB;CAExE,KAAc;CACd,UAAwC,OAAO,OAAO,EACpD,OAAO,UAGL,OAAO,OAAO,CAAC,CAAC,CAAC,EACrB,CAAC;CAGD,cAAsB;EACpB,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;EAChB,CAAC;EACD,WAAW,IAAI;CACjB;CAEA,IAAI,QAAgD;EAClD,OAAO,UAGL,KAAK,QAAQ,QAAQ;CACzB;CAEA,aAAa,WAA2B;EACtC,OAAO,IAAI,UAAU;CACvB;AACF;;;AC3DA,MAAM,qBAAqB;AAE3B,SAAS,2BAA2B,IAA6D;CAC/F,IAAI,OAAO,OAAO,YAAY,OAAO,MACnC,OAAO;CAET,MAAM,QAAQ,OAAO,eAAe,EAAE;CACtC,IAAI,UAAU,OAAO,aAAa,UAAU,MAC1C,OAAO;CAET,OAAQ,GAAiB,SAAS;AACpC;AAEA,IAAM,oBAAN,MAAM,0BAA0B,cAAc;CAG5C;CACA;CAEA,OAAO,gBAAgB,OAA8C;EACnE,MAAM,YAAY,MAAM,QAAQ;EAChC,MAAM,aAAa,cAAc,KAAA,IAAY,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS;EAC7E,MAAM,eAAe,MAAM,QAAQ;EACnC,MAAM,eAAe,iBAAiB,KAAA,KAAa,OAAO,KAAK,YAAY,CAAC,CAAC,SAAS;EACtF,MAAM,kBAAkB,OAAO,KAAK,MAAM,OAAO,CAAC,CAAC,MAChD,S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ACbA,SAAgB,4BACd,WACwC;CACxC,IAAI,cAAc,KAAA,KAAa,CAAC,OAAO,OAAO,WAAW,iBAAiB,GACxE,OAAO;CAET,OAAO,OAAO,QAAQ,IAAI,WAAW,iBAAiB,MAAM;AAC9D;AA0DA,IAAa,aAAb,cAA+D,QAA2B;CACxF;CACA;CAGA,YAAY,OAA+B;EACzC,MAAM;EACN,KAAK,cAAc,MAAM;EACzB,KAAK,aAAa,OAAO,OAAO,MAAM,UAAU;EAChD,IAAI,MAAM,UAAU,KAAA,GAClB,KAAK,QAAQ,OAAO,OAClB,OAAO,YACL,OAAO,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,MAAM,mBAAmB,MAAM,EAAE,CAAC,CAAC,CACtF,CACF;EAEF,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAS,mBAAmB,MAAc,OAAiD;CACzF,IAAI,sBAAsB,KAAK,GAAG;EAMhC,IAAI,gBAAgB,OAClB,OAAO;EAET,OAAO,sBAAsB,KAAK;CACpC;CACA,MAAM,UAAW,MAA6B;CAC9C,MAAM,kBACJ,YAAY,KAAA,IACR,iCACA,uCAAuC,KAAK,UAAU,OAAO;CACnE,MAAM,IAAI,MACR,iBAAiB,KAAK,UAAU,IAAI,EAAE,QAAQ,gBAAgB,aAAa,KAAK,UAAU,gBAAgB,EAAE,gGAC9G;AACF;;;AClGA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;CACvC;AACF"}
+1
-1
import { t as ForeignKey } from "./foreign-key-BATxB95l.mjs";
import { a as UniqueConstraint, c as StorageColumnInput, d as PrimaryKey, l as Index, r as StorageTable, s as StorageColumn } from "./storage-value-set-WnYsIFM8.mjs";
import { b as SqlModelFieldStorage, f as ForeignKeyOptions, x as SqlModelStorage } from "./types-B1N8w0I2.mjs";
import { b as SqlModelFieldStorage, f as ForeignKeyOptions, x as SqlModelStorage } from "./types-AtudkZcJ.mjs";
import { ScalarFieldType } from "@prisma-next/contract/types";

@@ -5,0 +5,0 @@

import { a as StorageTable, c as Index, l as PrimaryKey, o as UniqueConstraint, s as StorageColumn, u as ForeignKey } from "./entity-kinds-Cl36zL5j.mjs";
import { r as applyFkDefaults } from "./types-B-eiQXff.mjs";
import { r as applyFkDefaults } from "./types-CZ6MwpXG.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 { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
import { o as SqlStorage } from "./sql-storage-BqbeAE6l.mjs";
import { a as IndexTypeRegistry } from "./index-types-Czsyu7Iw.mjs";

@@ -3,0 +3,0 @@ import { Contract } from "@prisma-next/contract/types";

import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
import { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
import { o as SqlStorage } from "./sql-storage-BqbeAE6l.mjs";

@@ -4,0 +4,0 @@ //#region src/resolve-storage-table.d.ts

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 UniqueConstraint, c as StorageColumnInput, d as PrimaryKey, f as PrimaryKeyInput, i as StorageTableInput, l as Index, m as CheckConstraintInput, n as StorageValueSetInput, o as UniqueConstraintInput, p as CheckConstraint, r as StorageTable, s as StorageColumn, t as StorageValueSet, u as IndexInput } from "./storage-value-set-WnYsIFM8.mjs";
import { a as SqlStorageInput, c as StorageTypeInstance, d as toStorageTypeInstance, i as SqlStorage, l as StorageTypeInstanceInput, n as SqlNamespaceEntries, o as SqlStorageTypeEntry, r as SqlNamespaceTablesInput, s as CODEC_INSTANCE_KIND, t as SqlNamespace, u as isStorageTypeInstance } from "./sql-storage-Dga0jwP2.mjs";
import { C as TypeMaps, D as buildSqlNamespace, E as SqlUnboundNamespace, O as buildSqlNamespaceMap, S as SqlQueryOperationTypes, T as applyFkDefaults, _ as QueryOperationTypesOf, a as ExtractCodecTypes, b as SqlModelFieldStorage, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKeyOptions, g as QueryOperationTypesBase, h as QueryOperationTypeEntry, i as DEFAULT_FK_INDEX, l as ExtractTypeMapsFromContract, m as QueryOperationSelfSpec, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as QueryOperationReturn, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as ResolveCodecTypes, w as TypeMapsPhantomKey, x as SqlModelStorage, y as SqlControlDriverInstance } from "./types-B1N8w0I2.mjs";
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 ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReference, type ForeignKeyReferenceInput, Index, type IndexInput, PrimaryKey, type PrimaryKeyInput, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlControlDriverInstance, type SqlModelFieldStorage, type SqlModelStorage, type SqlNamespace, type SqlNamespaceEntries, type SqlNamespaceTablesInput, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, SqlUnboundNamespace, StorageColumn, type StorageColumnInput, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, StorageValueSet, type StorageValueSetInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, buildSqlNamespace, buildSqlNamespaceMap, isStorageTypeInstance, toStorageTypeInstance };
import { a as SqlNamespaceTablesInput, c as SqlStorageTypeEntry, d as StorageTypeInstance, f as StorageTypeInstanceInput, i as SqlNamespaceFactory, l as isSqlAuthoringContributions, m as toStorageTypeInstance, n as SqlNamespace, o as SqlStorage, p as isStorageTypeInstance, r as SqlNamespaceEntries, s as SqlStorageInput, t as SqlAuthoringContributions, u as CODEC_INSTANCE_KIND } from "./sql-storage-BqbeAE6l.mjs";
import { C as TypeMaps, D as buildSqlNamespace, E as SqlUnboundNamespace, O as buildSqlNamespaceMap, S as SqlQueryOperationTypes, T as applyFkDefaults, _ as QueryOperationTypesOf, a as ExtractCodecTypes, b as SqlModelFieldStorage, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKeyOptions, g as QueryOperationTypesBase, h as QueryOperationTypeEntry, i as DEFAULT_FK_INDEX, l as ExtractTypeMapsFromContract, m as QueryOperationSelfSpec, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as QueryOperationReturn, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as ResolveCodecTypes, w as TypeMapsPhantomKey, x as SqlModelStorage, y as SqlControlDriverInstance } from "./types-AtudkZcJ.mjs";
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 ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReference, type ForeignKeyReferenceInput, Index, type IndexInput, 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, type SqlNamespaceEntries, type SqlNamespaceFactory, type SqlNamespaceTablesInput, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, SqlUnboundNamespace, StorageColumn, type StorageColumnInput, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, StorageValueSet, type StorageValueSetInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, buildSqlNamespace, buildSqlNamespaceMap, isSqlAuthoringContributions, isStorageTypeInstance, toStorageTypeInstance };
import { a as StorageTable, c as Index, d as ForeignKeyReference, f as CheckConstraint, i as StorageValueSet, l as PrimaryKey, o as UniqueConstraint, p as SqlNode, s as StorageColumn, u as ForeignKey } from "./entity-kinds-Cl36zL5j.mjs";
import { a as CODEC_INSTANCE_KIND, c as buildSqlNamespace, i as SqlStorage, l as buildSqlNamespaceMap, n as DEFAULT_FK_INDEX, o as isStorageTypeInstance, r as applyFkDefaults, s as toStorageTypeInstance, t as DEFAULT_FK_CONSTRAINT, u as SqlUnboundNamespace } from "./types-B-eiQXff.mjs";
export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNode, SqlStorage, SqlUnboundNamespace, StorageColumn, StorageTable, StorageValueSet, UniqueConstraint, applyFkDefaults, buildSqlNamespace, buildSqlNamespaceMap, isStorageTypeInstance, toStorageTypeInstance };
import { a as isSqlAuthoringContributions, c as toStorageTypeInstance, d as SqlUnboundNamespace, i as SqlStorage, l as buildSqlNamespace, n as DEFAULT_FK_INDEX, o as CODEC_INSTANCE_KIND, r as applyFkDefaults, s as isStorageTypeInstance, t as DEFAULT_FK_CONSTRAINT, u as buildSqlNamespaceMap } from "./types-CZ6MwpXG.mjs";
export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNode, SqlStorage, SqlUnboundNamespace, StorageColumn, StorageTable, StorageValueSet, UniqueConstraint, applyFkDefaults, buildSqlNamespace, buildSqlNamespaceMap, isSqlAuthoringContributions, isStorageTypeInstance, toStorageTypeInstance };
import { n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
import { f as PrimaryKeyInput, o as UniqueConstraintInput } from "./storage-value-set-WnYsIFM8.mjs";
import { i as SqlStorage } from "./sql-storage-Dga0jwP2.mjs";
import { o as SqlStorage } from "./sql-storage-BqbeAE6l.mjs";
import { Type } from "arktype";

@@ -5,0 +5,0 @@ import { AnyEntityKindDescriptor } from "@prisma-next/framework-components/ir";

import { C as StorageTableSchema, S as ReferentialActionSchema, _ as ColumnDefaultSchema, b as ForeignKeySourceSchema, g as ColumnDefaultLiteralSchema, h as ColumnDefaultFunctionSchema, m as CheckConstraintSchema, t as composeSqlEntityKinds, v as ForeignKeyReferenceSchema, w as StorageValueSetSchema, x as IndexSchema, y as ForeignKeySchema } from "./entity-kinds-Cl36zL5j.mjs";
import { i as SqlStorage, l as buildSqlNamespaceMap, u as SqlUnboundNamespace } from "./types-B-eiQXff.mjs";
import { d as SqlUnboundNamespace, i as SqlStorage, u as buildSqlNamespaceMap } from "./types-CZ6MwpXG.mjs";
import { type } from "arktype";

@@ -4,0 +4,0 @@ import { UNBOUND_NAMESPACE_ID, isPlainRecord } from "@prisma-next/framework-components/ir";

{
"name": "@prisma-next/sql-contract",
"version": "0.14.0-dev.11",
"version": "0.14.0-dev.12",
"license": "Apache-2.0",

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

"dependencies": {
"@prisma-next/contract": "0.14.0-dev.11",
"@prisma-next/framework-components": "0.14.0-dev.11",
"@prisma-next/utils": "0.14.0-dev.11",
"@prisma-next/contract": "0.14.0-dev.12",
"@prisma-next/framework-components": "0.14.0-dev.12",
"@prisma-next/utils": "0.14.0-dev.12",
"arktype": "^2.2.0"
},
"devDependencies": {
"@prisma-next/test-utils": "0.14.0-dev.11",
"@prisma-next/tsconfig": "0.14.0-dev.11",
"@prisma-next/tsdown": "0.14.0-dev.11",
"@prisma-next/test-utils": "0.14.0-dev.12",
"@prisma-next/tsconfig": "0.14.0-dev.12",
"@prisma-next/tsdown": "0.14.0-dev.12",
"tsdown": "0.22.1",

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

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

ResolveCodecTypes,
SqlAuthoringContributions,
SqlControlDriverInstance,

@@ -30,2 +31,3 @@ SqlModelFieldStorage,

SqlNamespaceEntries,
SqlNamespaceFactory,
SqlNamespaceTablesInput,

@@ -55,2 +57,3 @@ SqlQueryOperationTypes,

Index,
isSqlAuthoringContributions,
isStorageTypeInstance,

@@ -57,0 +60,0 @@ PrimaryKey,

import type { StorageHashBase } from '@prisma-next/contract/types';
import type { AuthoringContributions } from '@prisma-next/framework-components/authoring';
import { freezeNode, type Namespace, type Storage } from '@prisma-next/framework-components/ir';

@@ -27,2 +28,32 @@ import { SqlNode } from './sql-node';

/**
* Target-supplied factory that materializes a `Namespace` from a SQL
* `SqlNamespaceTablesInput` (used to populate `SqlStorage.namespaces`).
*/
export type SqlNamespaceFactory = (input: SqlNamespaceTablesInput) => 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.
*/
export interface SqlAuthoringContributions extends AuthoringContributions {
readonly createNamespace?: SqlNamespaceFactory;
}
/**
* Narrows framework `AuthoringContributions` to the SQL-family shape by testing
* for the SQL-specific `createNamespace` capability.
*/
export function isSqlAuthoringContributions(
authoring: AuthoringContributions | undefined,
): authoring is SqlAuthoringContributions {
if (authoring === undefined || !Object.hasOwn(authoring, 'createNamespace')) {
return false;
}
return typeof Reflect.get(authoring, 'createNamespace') === 'function';
}
export interface SqlStorageInput<THash extends string = string> {

@@ -29,0 +60,0 @@ readonly storageHash: StorageHashBase<THash>;

@@ -28,4 +28,7 @@ import type { CodecTrait } from '@prisma-next/framework-components/codec';

export {
isSqlAuthoringContributions,
type SqlAuthoringContributions,
type SqlNamespace,
type SqlNamespaceEntries,
type SqlNamespaceFactory,
type SqlNamespaceTablesInput,

@@ -32,0 +35,0 @@ SqlStorage,

import { o as SqlNode } from "./foreign-key-BATxB95l.mjs";
import { r as StorageTable, t as StorageValueSet } from "./storage-value-set-WnYsIFM8.mjs";
import { Namespace, Storage, StorageType } from "@prisma-next/framework-components/ir";
import { StorageHashBase } from "@prisma-next/contract/types";
//#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 SqlNamespaceTablesInput {
readonly id: string;
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
}
interface SqlStorageInput<THash extends string = string> {
readonly storageHash: StorageHashBase<THash>;
readonly types?: Record<string, SqlStorageTypeEntry>;
readonly namespaces: Readonly<Record<string, SqlNamespace>>;
}
/**
* 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>>;
};
/**
* SQL family namespace. `entries` is the open ADR 224 dictionary —
* `entries[entityKind][entityName]` addresses any entity. Emitted
* contract literals satisfy this structurally (no prototype getters
* needed). For typed access to specific kinds, use the class getters
* on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.
*/
type SqlNamespace = Namespace & {
readonly entries: SqlNamespaceEntries;
/**
* Render a dialect-qualified table reference for runtime SQL emission.
* Present on materialised target concretions (`PostgresSchema`,
* `SqliteDatabase`, …) and family placeholders; omitted on emitted
* contract structural namespace literals (methods are not serialised).
*/
qualifyTable?(tableName: string): string;
};
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 { SqlStorageInput as a, StorageTypeInstance as c, toStorageTypeInstance as d, SqlStorage as i, StorageTypeInstanceInput as l, SqlNamespaceEntries as n, SqlStorageTypeEntry as o, SqlNamespaceTablesInput as r, CODEC_INSTANCE_KIND as s, SqlNamespace as t, isStorageTypeInstance as u };
//# sourceMappingURL=sql-storage-Dga0jwP2.d.mts.map
{"version":3,"file":"sql-storage-Dga0jwP2.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;;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"./entity-kinds-Cl36zL5j.mjs";
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
import { blindCast } from "@prisma-next/utils/casts";
//#region src/ir/sql-unbound-namespace.ts
/**
* Family-layer placeholder for the SQL unbound-namespace singleton —
* the late-bound slot whose binding the target resolves at connection
* time rather than at authoring time.
*
* SQL contracts honour the framework `Storage.namespaces` invariant from
* the moment they appear in the IR. Today `SqlStorage` is family-shared
* (Postgres + SQLite consume the same class); a per-target namespace
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
* earns its existence when each target's namespace shape lands. Until
* then the family ships a single placeholder singleton so the JSON
* envelope and runtime walk are honest at every layer.
*
* The `kind` discriminator is installed as a non-enumerable own property
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
* and bounded to the minimum data the framework `Namespace` interface
* promises.
*
* **Freeze-trap warning.** The leaf constructor calls
* `freezeNode(this)` after installing `kind`. The leaf-class shape
* works today only because `NamespaceBase` does NOT freeze in its
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
* `super()` succeeds because the instance is still mutable at that
* point. Subclasses that add instance fields will still hit the freeze
* trap once leaf-class `freezeNode(this)` runs; and if a future
* framework change lifts the freeze to `NamespaceBase`, even the
* `defineProperty` here would silently fail. To add subclass instance
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
* leaf calls explicitly at the end of its own constructor.
*/
var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
static instance = new SqlUnboundNamespace();
id = UNBOUND_NAMESPACE_ID;
entries = Object.freeze({ table: blindCast(Object.freeze({})) });
constructor() {
super();
Object.defineProperty(this, "kind", {
value: "sql-namespace",
writable: false,
enumerable: false,
configurable: true
});
freezeNode(this);
}
get table() {
return blindCast(this.entries["table"]);
}
qualifyTable(tableName) {
return `"${tableName}"`;
}
};
//#endregion
//#region src/ir/build-sql-namespace.ts
const SQL_NAMESPACE_KIND = "sql-namespace";
function isMaterializedSqlNamespace(ns) {
if (typeof ns !== "object" || ns === null) return false;
const proto = Object.getPrototypeOf(ns);
if (proto === Object.prototype || proto === null) return false;
return ns.kind === SQL_NAMESPACE_KIND;
}
var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
id;
entries;
static fromTablesInput(input) {
const tableKind = input.entries["table"];
const tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;
const valueSetKind = input.entries["valueSet"];
const hasValueSets = valueSetKind !== void 0 && Object.keys(valueSetKind).length > 0;
const hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== "table" && kind !== "valueSet");
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets && !hasUnknownKinds) return SqlUnboundNamespace.instance;
return new SqlBoundNamespace(input);
}
constructor(input) {
super();
this.id = input.id;
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
this.entries = Object.freeze(blindCast(dispatched));
Object.defineProperty(this, "kind", {
value: SQL_NAMESPACE_KIND,
writable: false,
enumerable: false,
configurable: true
});
freezeNode(this);
}
get table() {
return this.entries.table ?? Object.freeze({});
}
get valueSet() {
return this.entries.valueSet;
}
qualifyTable(tableName) {
if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
return `"${this.id}"."${tableName}"`;
}
};
function buildSqlNamespace(input) {
return SqlBoundNamespace.fromTablesInput(input);
}
function buildSqlNamespaceMap(namespaces) {
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? ns : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
}
//#endregion
//#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
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 = entry.kind;
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 { CODEC_INSTANCE_KIND as a, buildSqlNamespace as c, SqlStorage as i, buildSqlNamespaceMap as l, DEFAULT_FK_INDEX as n, isStorageTypeInstance as o, applyFkDefaults as r, toStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, SqlUnboundNamespace as u };
//# sourceMappingURL=types-B-eiQXff.mjs.map
{"version":3,"file":"types-B-eiQXff.mjs","names":[],"sources":["../src/ir/sql-unbound-namespace.ts","../src/ir/build-sql-namespace.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { SqlNamespaceEntries } from './sql-storage';\nimport type { StorageTable } from './storage-table';\n\n/**\n * Family-layer placeholder for the SQL unbound-namespace singleton —\n * the late-bound slot whose binding the target resolves at connection\n * time rather than at authoring time.\n *\n * SQL contracts honour the framework `Storage.namespaces` invariant from\n * the moment they appear in the IR. Today `SqlStorage` is family-shared\n * (Postgres + SQLite consume the same class); a per-target namespace\n * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)\n * earns its existence when each target's namespace shape lands. Until\n * then the family ships a single placeholder singleton so the JSON\n * envelope and runtime walk are honest at every layer.\n *\n * The `kind` discriminator is installed as a non-enumerable own property\n * so the JSON envelope reads `{ \"id\": \"__unbound__\", \"entries\": { … } }`\n * — symmetric with the family-level non-enumerable `kind` on `SqlNode`\n * and bounded to the minimum data the framework `Namespace` interface\n * promises.\n *\n * **Freeze-trap warning.** The leaf constructor calls\n * `freezeNode(this)` after installing `kind`. The leaf-class shape\n * works today only because `NamespaceBase` does NOT freeze in its\n * constructor — the `Object.defineProperty(this, 'kind', …)` call after\n * `super()` succeeds because the instance is still mutable at that\n * point. Subclasses that add instance fields will still hit the freeze\n * trap once leaf-class `freezeNode(this)` runs; and if a future\n * framework change lifts the freeze to `NamespaceBase`, even the\n * `defineProperty` here would silently fail. To add subclass instance\n * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each\n * leaf calls explicitly at the end of its own constructor.\n */\nexport class SqlUnboundNamespace extends NamespaceBase {\n static readonly instance: SqlUnboundNamespace = new SqlUnboundNamespace();\n\n readonly id = UNBOUND_NAMESPACE_ID;\n readonly entries: SqlNamespaceEntries = Object.freeze({\n table: blindCast<\n Readonly<Record<string, StorageTable>>,\n 'empty frozen map is a valid Readonly<Record<string, StorageTable>>'\n >(Object.freeze({})),\n });\n declare readonly kind: string;\n\n private constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql-namespace',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return blindCast<\n Readonly<Record<string, StorageTable>>,\n 'entries[table] holds only StorageTable by construction'\n >(this.entries['table']);\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { composeSqlEntityKinds } from '../entity-kinds';\nimport type { SqlNamespace, SqlNamespaceEntries, SqlNamespaceTablesInput } from './sql-storage';\nimport { SqlUnboundNamespace } from './sql-unbound-namespace';\nimport type { StorageTable } from './storage-table';\nimport type { StorageValueSet } from './storage-value-set';\n\nconst SQL_NAMESPACE_KIND = 'sql-namespace' as const;\n\nfunction isMaterializedSqlNamespace(ns: Namespace | SqlNamespaceTablesInput): ns is SqlNamespace {\n if (typeof ns !== 'object' || ns === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(ns);\n if (proto === Object.prototype || proto === null) {\n return false;\n }\n return (ns as Namespace).kind === SQL_NAMESPACE_KIND;\n}\n\nclass SqlBoundNamespace extends NamespaceBase {\n declare readonly kind: string;\n\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n\n static fromTablesInput(input: SqlNamespaceTablesInput): SqlNamespace {\n const tableKind = input.entries['table'];\n const tableCount = tableKind !== undefined ? Object.keys(tableKind).length : 0;\n const valueSetKind = input.entries['valueSet'];\n const hasValueSets = valueSetKind !== undefined && Object.keys(valueSetKind).length > 0;\n const hasUnknownKinds = Object.keys(input.entries).some(\n (kind) => kind !== 'table' && kind !== 'valueSet',\n );\n if (\n input.id === UNBOUND_NAMESPACE_ID &&\n tableCount === 0 &&\n !hasValueSets &&\n !hasUnknownKinds\n ) {\n return SqlUnboundNamespace.instance;\n }\n return new SqlBoundNamespace(input);\n }\n\n private constructor(input: SqlNamespaceTablesInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(dispatched),\n );\n Object.defineProperty(this, 'kind', {\n value: SQL_NAMESPACE_KIND,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\n }\n\n qualifyTable(tableName: string): string {\n if (this.id === UNBOUND_NAMESPACE_ID) {\n return `\"${tableName}\"`;\n }\n return `\"${this.id}\".\"${tableName}\"`;\n }\n}\n\nexport function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace {\n return SqlBoundNamespace.fromTablesInput(input);\n}\n\nexport function buildSqlNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>,\n): Readonly<Record<string, SqlNamespace>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsKey, ns]) => [\n nsKey,\n isMaterializedSqlNamespace(ns)\n ? ns\n : SqlBoundNamespace.fromTablesInput(\n blindCast<\n SqlNamespaceTablesInput,\n 'non-materialized SQL namespace map entry is a SqlNamespaceTablesInput'\n >(ns),\n ),\n ]),\n );\n}\n","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 { freezeNode, type Namespace, type Storage } 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 SqlNamespaceTablesInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\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, SqlNamespace>>;\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 * SQL family namespace. `entries` is the open ADR 224 dictionary —\n * `entries[entityKind][entityName]` addresses any entity. Emitted\n * contract literals satisfy this structurally (no prototype getters\n * needed). For typed access to specific kinds, use the class getters\n * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.\n */\nexport type SqlNamespace = Namespace & {\n readonly entries: SqlNamespaceEntries;\n /**\n * Render a dialect-qualified table reference for runtime SQL emission.\n * Present on materialised target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) and family placeholders; omitted on emitted\n * contract structural namespace literals (methods are not serialised).\n */\n qualifyTable?(tableName: string): string;\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 = (entry as { kind?: unknown }).kind;\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 { buildSqlNamespace, buildSqlNamespaceMap } from './ir/build-sql-namespace';\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 type SqlNamespace,\n type SqlNamespaceEntries,\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { SqlUnboundNamespace } from './ir/sql-unbound-namespace';\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 { StorageValueSet, type StorageValueSetInput } 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 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> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\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. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\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 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>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,sBAAb,MAAa,4BAA4B,cAAc;CACrD,OAAgB,WAAgC,IAAI,oBAAoB;CAExE,KAAc;CACd,UAAwC,OAAO,OAAO,EACpD,OAAO,UAGL,OAAO,OAAO,CAAC,CAAC,CAAC,EACr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AAc,OAAiD;CACzF,IAAI,sBAAsB,KAAK,GAAG;EAMhC,IAAI,gBAAgB,OAClB,OAAO;EAET,OAAO,sBAAsB,KAAK;CACpC;CACA,MAAM,UAAW,MAA6B;CAC9C,MAAM,kBACJ,YAAY,KAAA,IACR,iCACA,uCAAuC,KAAK,UAAU,OAAO;CACnE,MAAM,IAAI,MACR,iBAAiB,KAAK,UAAU,IAAI,EAAE,QAAQ,gBAAgB,aAAa,KAAK,UAAU,gBAAgB,EAAE,gGAC9G;AACF;;;ACtEA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;CACvC;AACF"}
import { r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
import { n as SqlNamespaceEntries, r as SqlNamespaceTablesInput, t as SqlNamespace } from "./sql-storage-Dga0jwP2.mjs";
import { Namespace, NamespaceBase } from "@prisma-next/framework-components/ir";
import { CodecTrait } from "@prisma-next/framework-components/codec";
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
//#region src/ir/build-sql-namespace.d.ts
declare function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace;
declare function buildSqlNamespaceMap(namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>): Readonly<Record<string, SqlNamespace>>;
//#endregion
//#region src/ir/sql-unbound-namespace.d.ts
/**
* Family-layer placeholder for the SQL unbound-namespace singleton —
* the late-bound slot whose binding the target resolves at connection
* time rather than at authoring time.
*
* SQL contracts honour the framework `Storage.namespaces` invariant from
* the moment they appear in the IR. Today `SqlStorage` is family-shared
* (Postgres + SQLite consume the same class); a per-target namespace
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
* earns its existence when each target's namespace shape lands. Until
* then the family ships a single placeholder singleton so the JSON
* envelope and runtime walk are honest at every layer.
*
* The `kind` discriminator is installed as a non-enumerable own property
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
* and bounded to the minimum data the framework `Namespace` interface
* promises.
*
* **Freeze-trap warning.** The leaf constructor calls
* `freezeNode(this)` after installing `kind`. The leaf-class shape
* works today only because `NamespaceBase` does NOT freeze in its
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
* `super()` succeeds because the instance is still mutable at that
* point. Subclasses that add instance fields will still hit the freeze
* trap once leaf-class `freezeNode(this)` runs; and if a future
* framework change lifts the freeze to `NamespaceBase`, even the
* `defineProperty` here would silently fail. To add subclass instance
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
* leaf calls explicitly at the end of its own constructor.
*/
declare class SqlUnboundNamespace extends NamespaceBase {
static readonly instance: SqlUnboundNamespace;
readonly id: "__unbound__";
readonly entries: SqlNamespaceEntries;
readonly kind: string;
private constructor();
get table(): Readonly<Record<string, StorageTable>>;
qualifyTable(tableName: string): string;
}
//#endregion
//#region src/types.d.ts
interface SqlControlDriverInstance<T extends string = string> extends ControlDriverInstance<'sql', T> {
query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<{
readonly rows: Row[];
}>;
}
type ForeignKeyOptions = {
readonly name?: string;
readonly onDelete?: ReferentialAction;
readonly onUpdate?: ReferentialAction;
};
type SqlModelFieldStorage = {
readonly column: string;
readonly codecId?: string;
readonly nullable?: boolean;
};
type SqlModelStorage = {
readonly table: string;
readonly namespaceId: string;
readonly fields: Record<string, SqlModelFieldStorage>;
};
declare const DEFAULT_FK_CONSTRAINT = true;
declare const DEFAULT_FK_INDEX = true;
declare function applyFkDefaults(fk: {
constraint?: boolean | undefined;
index?: boolean | undefined;
}, overrideDefaults?: {
constraint?: boolean | undefined;
index?: boolean | undefined;
}): {
constraint: boolean;
index: boolean;
};
type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;
type TypeMaps<TCodecTypes extends Record<string, {
output: unknown;
}> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>, TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>> = {
readonly codecTypes: TCodecTypes;
readonly queryOperationTypes: TQueryOperationTypes;
readonly fieldOutputTypes: TFieldOutputTypes;
readonly fieldInputTypes: TFieldInputTypes;
};
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly codecTypes: infer C;
} ? C extends Record<string, {
output: unknown;
}> ? C : Record<string, never> : Record<string, never>;
/**
* Dispatch hint identifying the first-argument target of an operation.
*
* Used by ORM column helpers to decide whether an operation is reachable on a
* field. Either names a concrete codec identity or a set of capability traits
* that the field's codec must carry.
*/
type QueryOperationSelfSpec = {
readonly codecId: string;
readonly traits?: never;
} | {
readonly traits: readonly CodecTrait[];
readonly codecId?: never;
};
/**
* Structural shape an operation's impl must return: any value carrying a
* codec-exact `returnType` descriptor. `Expression<T>` (from
* `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
* extends this. Trait-targeted returns are deliberately excluded — predicate
* detection and result decoding both depend on knowing the concrete return
* codec.
*/
type QueryOperationReturn = {
readonly returnType: {
readonly codecId: string;
readonly nullable: boolean;
};
};
type QueryOperationTypeEntry = {
readonly self?: QueryOperationSelfSpec;
readonly impl: (...args: never[]) => QueryOperationReturn;
};
type SqlQueryOperationTypes<_CT extends Record<string, {
readonly input: unknown;
readonly output: unknown;
}>, T extends Record<string, QueryOperationTypeEntry>> = T;
type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly queryOperationTypes: infer Q;
} ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly fieldOutputTypes: infer F;
} ? F extends NamespacedFieldTypeMap ? F : Record<string, never> : Record<string, never>;
type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
readonly fieldInputTypes: infer F;
} ? F extends NamespacedFieldTypeMap ? F : Record<string, never> : Record<string, never>;
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
//#endregion
export { TypeMaps as C, buildSqlNamespace as D, SqlUnboundNamespace as E, buildSqlNamespaceMap as O, SqlQueryOperationTypes as S, applyFkDefaults as T, QueryOperationTypesOf as _, ExtractCodecTypes as a, SqlModelFieldStorage as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKeyOptions as f, QueryOperationTypesBase as g, QueryOperationTypeEntry as h, DEFAULT_FK_INDEX as i, ExtractTypeMapsFromContract as l, QueryOperationSelfSpec as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, QueryOperationReturn as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, ResolveCodecTypes as v, TypeMapsPhantomKey as w, SqlModelStorage as x, SqlControlDriverInstance as y };
//# sourceMappingURL=types-B1N8w0I2.d.mts.map
{"version":3,"file":"types-B1N8w0I2.d.mts","names":[],"sources":["../src/ir/build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