@prisma-next/sql-contract 0.14.0-dev.3 → 0.14.0-dev.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entity-kinds-BSGvSPI8.mjs +131 -0
- package/dist/entity-kinds-BSGvSPI8.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +5 -3
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +5 -4
- package/dist/factories.mjs.map +1 -1
- package/dist/index-type-validation.d.mts +1 -1
- package/dist/resolve-storage-table.d.mts +2 -2
- package/dist/{sql-storage-Dga0jwP2.d.mts → sql-storage-CUP3mD3c.d.mts} +60 -19
- package/dist/sql-storage-CUP3mD3c.d.mts.map +1 -0
- package/dist/{storage-value-set-WnYsIFM8.d.mts → storage-value-set-B1Xmb6D2.d.mts} +6 -2
- package/dist/storage-value-set-B1Xmb6D2.d.mts.map +1 -0
- package/dist/{entity-kinds-Cl36zL5j.mjs → storage-value-set-Cp7h3D59.mjs} +10 -127
- package/dist/storage-value-set-Cp7h3D59.mjs.map +1 -0
- package/dist/types-B4sPkjNO.mjs +114 -0
- package/dist/types-B4sPkjNO.mjs.map +1 -0
- package/dist/{types-B1N8w0I2.d.mts → types-ChH7hULD.d.mts} +24 -54
- package/dist/types-ChH7hULD.d.mts.map +1 -0
- package/dist/types.d.mts +10 -4
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +3 -3
- package/dist/validators.d.mts +8 -5
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +109 -17
- package/dist/validators.mjs.map +1 -1
- package/package.json +7 -7
- package/src/column-type-resolution.ts +26 -0
- package/src/exports/types.ts +18 -4
- package/src/factories.ts +12 -2
- package/src/ir/sql-storage.ts +80 -17
- package/src/ir/storage-column.ts +3 -0
- package/src/ir/storage-entry-schemas.ts +1 -0
- package/src/ir/storage-table.ts +5 -0
- package/src/ir/storage-value-set.ts +5 -0
- package/src/types.ts +52 -9
- package/src/validators.ts +215 -40
- package/dist/entity-kinds-Cl36zL5j.mjs.map +0 -1
- package/dist/sql-storage-Dga0jwP2.d.mts.map +0 -1
- package/dist/storage-value-set-WnYsIFM8.d.mts.map +0 -1
- package/dist/types-B-eiQXff.mjs +0 -191
- package/dist/types-B-eiQXff.mjs.map +0 -1
- package/dist/types-B1N8w0I2.d.mts.map +0 -1
- package/src/ir/build-sql-namespace.ts +0 -110
- package/src/ir/sql-unbound-namespace.ts +0 -74
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { f as SqlNode } from "./storage-value-set-Cp7h3D59.mjs";
|
|
2
|
+
import { NamespaceBase, freezeNode, isPlainRecord } from "@prisma-next/framework-components/ir";
|
|
3
|
+
//#region src/ir/storage-type-instance.ts
|
|
4
|
+
/**
|
|
5
|
+
* Sentinel kind for the legacy codec-triple shape persisted under
|
|
6
|
+
* `SqlStorage.types`. Plain JSON-clean object literals carry this
|
|
7
|
+
* discriminator so the polymorphic slot dispatch can route them down
|
|
8
|
+
* the codec path while target-specific IR class instances (e.g. the
|
|
9
|
+
* Postgres enum class) keep their own narrower `kind` literal.
|
|
10
|
+
*/
|
|
11
|
+
const CODEC_INSTANCE_KIND = "codec-instance";
|
|
12
|
+
/**
|
|
13
|
+
* Stamp the codec-instance `kind` discriminator on a caller-supplied
|
|
14
|
+
* codec triple. Idempotent: input that already carries the discriminator
|
|
15
|
+
* passes through unchanged. Missing `typeParams` is normalised to `{}`.
|
|
16
|
+
*/
|
|
17
|
+
function toStorageTypeInstance(input) {
|
|
18
|
+
return {
|
|
19
|
+
kind: CODEC_INSTANCE_KIND,
|
|
20
|
+
codecId: input.codecId,
|
|
21
|
+
nativeType: input.nativeType,
|
|
22
|
+
typeParams: input.typeParams ?? {}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type-guard for codec-typed entries on the polymorphic
|
|
27
|
+
* `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
|
|
28
|
+
* any class-instance kinds a target pack contributes.
|
|
29
|
+
*/
|
|
30
|
+
function isStorageTypeInstance(value) {
|
|
31
|
+
if (typeof value !== "object" || value === null) return false;
|
|
32
|
+
return value.kind === CODEC_INSTANCE_KIND;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/ir/sql-storage.ts
|
|
36
|
+
/**
|
|
37
|
+
* Narrows framework `AuthoringContributions` to the SQL-family shape by testing
|
|
38
|
+
* for the SQL-specific `createNamespace` capability.
|
|
39
|
+
*/
|
|
40
|
+
function isSqlAuthoringContributions(authoring) {
|
|
41
|
+
if (authoring === void 0 || !Object.hasOwn(authoring, "createNamespace")) return false;
|
|
42
|
+
return typeof Reflect.get(authoring, "createNamespace") === "function";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,
|
|
46
|
+
* `SqliteDatabase`, …) extend this — it is never instantiated directly.
|
|
47
|
+
* `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`
|
|
48
|
+
* addresses any entity.
|
|
49
|
+
*/
|
|
50
|
+
var SqlNamespaceBase = class extends NamespaceBase {};
|
|
51
|
+
/**
|
|
52
|
+
* Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks
|
|
53
|
+
* `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it
|
|
54
|
+
* survives duplicate-module boundaries (e.g. dist e2e where the target and
|
|
55
|
+
* the family carry separate copies of `@prisma-next/framework-components`).
|
|
56
|
+
*
|
|
57
|
+
* Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,
|
|
58
|
+
* `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`
|
|
59
|
+
* objects (`{ id, entries }`) do not.
|
|
60
|
+
*/
|
|
61
|
+
function isMaterializedSqlNamespace(x) {
|
|
62
|
+
if (typeof x !== "object" || x === null || !("qualifyTable" in x)) return false;
|
|
63
|
+
return typeof x.qualifyTable === "function";
|
|
64
|
+
}
|
|
65
|
+
var SqlStorage = class extends SqlNode {
|
|
66
|
+
storageHash;
|
|
67
|
+
namespaces;
|
|
68
|
+
constructor(input) {
|
|
69
|
+
super();
|
|
70
|
+
this.storageHash = input.storageHash;
|
|
71
|
+
this.namespaces = Object.freeze(input.namespaces);
|
|
72
|
+
if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)])));
|
|
73
|
+
freezeNode(this);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Strict polymorphic-slot dispatch for `SqlStorage.types` entries.
|
|
78
|
+
* Every entry must carry a `kind: 'codec-instance'` discriminator or
|
|
79
|
+
* be an already-constructed `StorageTypeInstance`. Untagged or
|
|
80
|
+
* unrecognised inputs throw a diagnostic naming the entry and its
|
|
81
|
+
* `kind`, so format drift surfaces loudly at the deserializer
|
|
82
|
+
* boundary instead of slipping past the seam and corrupting
|
|
83
|
+
* downstream IR walks.
|
|
84
|
+
*
|
|
85
|
+
* Codec-triple authors that have an untagged shape on hand can call
|
|
86
|
+
* `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`
|
|
87
|
+
* discriminator) before constructing `SqlStorage`. On-disk reads
|
|
88
|
+
* cross `familyInstance.deserializeContract` first; the structural
|
|
89
|
+
* arktype schema rejects untagged entries earlier, so this throw
|
|
90
|
+
* only fires for in-memory authoring bugs.
|
|
91
|
+
*/
|
|
92
|
+
function normaliseTypeEntry(name, entry) {
|
|
93
|
+
if (isStorageTypeInstance(entry)) {
|
|
94
|
+
if ("typeParams" in entry) return entry;
|
|
95
|
+
return toStorageTypeInstance(entry);
|
|
96
|
+
}
|
|
97
|
+
const rawKind = isPlainRecord(entry) ? entry["kind"] : void 0;
|
|
98
|
+
const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
|
|
99
|
+
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.`);
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/types.ts
|
|
103
|
+
const DEFAULT_FK_CONSTRAINT = true;
|
|
104
|
+
const DEFAULT_FK_INDEX = true;
|
|
105
|
+
function applyFkDefaults(fk, overrideDefaults) {
|
|
106
|
+
return {
|
|
107
|
+
constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
|
|
108
|
+
index: fk.index ?? overrideDefaults?.index ?? true
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { SqlStorage as a, CODEC_INSTANCE_KIND as c, SqlNamespaceBase as i, isStorageTypeInstance as l, DEFAULT_FK_INDEX as n, isMaterializedSqlNamespace as o, applyFkDefaults as r, isSqlAuthoringContributions as s, DEFAULT_FK_CONSTRAINT as t, toStorageTypeInstance as u };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=types-B4sPkjNO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-B4sPkjNO.mjs","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Sentinel kind for the legacy codec-triple shape persisted under\n * `SqlStorage.types`. Plain JSON-clean object literals carry this\n * discriminator so the polymorphic slot dispatch can route them down\n * the codec path while target-specific IR class instances (e.g. the\n * Postgres enum class) keep their own narrower `kind` literal.\n */\nexport const CODEC_INSTANCE_KIND = 'codec-instance' as const;\n\n/**\n * Structural sub-interface of {@link StorageType} for codec-typed entries\n * in `SqlStorage.types`. These are plain object literals — there is no\n * runtime IR class, the JSON envelope round-trips through the slot\n * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch\n * key that distinguishes codec-typed entries from any class-instance\n * kinds a target pack contributes to the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n * `typeParams` may be omitted on input; the constructor normalises a\n * missing value to `{}` so the in-memory shape is always present.\n */\nexport interface StorageTypeInstanceInput {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n}\n\n/**\n * Stamp the codec-instance `kind` discriminator on a caller-supplied\n * codec triple. Idempotent: input that already carries the discriminator\n * passes through unchanged. Missing `typeParams` is normalised to `{}`.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams ?? {},\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * any class-instance kinds a target pack contributes.\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport type { AuthoringContributions } from '@prisma-next/framework-components/authoring';\nimport {\n freezeNode,\n isPlainRecord,\n type Namespace,\n NamespaceBase,\n type Storage,\n} from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\nimport type { StorageTable } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet } from './storage-value-set';\n\n/**\n * Polymorphic value type for document-scoped `SqlStorage.types` entries\n * (codec aliases / parameterised native type registrations).\n *\n * Postgres native enum registrations live under the postgres-specific\n * `entries.type` slot on `PostgresSchema` (target layer), not here.\n */\nexport type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;\n\nexport interface SqlNamespaceInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Target-supplied factory that materializes a `Namespace` from a SQL\n * `SqlNamespaceInput` (used to populate `SqlStorage.namespaces`).\n */\nexport type SqlNamespaceFactory = (input: SqlNamespaceInput) => Namespace;\n\n/**\n * SQL-family extension of the framework `AuthoringContributions`. SQL target\n * packs add a `createNamespace` factory so the PSL/TS authoring paths can\n * materialize namespaces (and merge lowered extension-block entities) without\n * each consumer re-specifying it. The factory is SQL-specific, so it lives here\n * rather than on the framework `AuthoringContributions` base.\n */\nexport interface SqlAuthoringContributions extends AuthoringContributions {\n readonly createNamespace?: SqlNamespaceFactory;\n}\n\n/**\n * Narrows framework `AuthoringContributions` to the SQL-family shape by testing\n * for the SQL-specific `createNamespace` capability.\n */\nexport function isSqlAuthoringContributions(\n authoring: AuthoringContributions | undefined,\n): authoring is SqlAuthoringContributions {\n if (authoring === undefined || !Object.hasOwn(authoring, 'createNamespace')) {\n return false;\n }\n return typeof Reflect.get(authoring, 'createNamespace') === 'function';\n}\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces: Readonly<Record<string, SqlNamespaceBase>>;\n}\n\n/**\n * SQL Contract IR root node for the `storage` field.\n *\n * Single concrete family-shared class — both Postgres and SQLite\n * consume this class today. Per-target storage subclasses are\n * introduced when each target's namespace shape earns its\n * target-specific concretion (target-specific derived fields,\n * target-specific storage extensions).\n *\n * Honours the framework `Storage` interface: every SQL IR carries a\n * `namespaces` map keyed by namespace id. Callers must supply fully\n * constructed `Namespace` instances — construction discipline lives\n * in the authoring builders and deserializer hydration paths.\n *\n * The constructor normalises optional `types` into class instances.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; hydration of raw JSON\n * class-instance entries (carrying their narrower `kind` literal) is\n * the per-target serializer's responsibility (so the family base does\n * not import target-specific subclasses).\n */\n/**\n * The typed `entries` shape for SQL family namespaces. The open dictionary\n * is intersected with optional known-kind maps so that `ns.entries.table`\n * and `ns.entries.valueSet` resolve without a cast, while unknown pack-\n * contributed kinds remain valid (the `Record` part allows any string key).\n */\nexport type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {\n readonly table?: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n};\n\n/**\n * Structural interface for SQL family namespaces. Generated `.d.ts` contract\n * types satisfy this structurally (no prototype methods). The runtime\n * abstract class `SqlNamespaceBase` extends this.\n *\n * `qualifyTable` is optional so JSON-shaped contract types (which carry no\n * methods) are accepted where `SqlNamespace` is required. Hydrated\n * `SqlNamespaceBase` instances always have it.\n */\nexport interface SqlNamespace {\n readonly kind: string;\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n qualifyTable?(tableName: string): string;\n}\n\n/**\n * Abstract SQL family namespace base class. Target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) extend this — it is never instantiated directly.\n * `entries` is the open ADR 224 dictionary: `entries[entityKind][entityName]`\n * addresses any entity.\n */\nexport abstract class SqlNamespaceBase extends NamespaceBase implements SqlNamespace {\n abstract override readonly id: string;\n abstract override readonly entries: SqlNamespaceEntries;\n\n abstract qualifyTable(tableName: string): string;\n}\n\n/**\n * Realm-safe guard for hydrated `SqlNamespaceBase` concretions. Checks\n * `qualifyTable` structurally instead of `instanceof NamespaceBase`, so it\n * survives duplicate-module boundaries (e.g. dist e2e where the target and\n * the family carry separate copies of `@prisma-next/framework-components`).\n *\n * Every concrete `SqlNamespaceBase` subclass (`PostgresSchema`, `SqliteDatabase`,\n * `TestSqlNamespace`, …) implements `qualifyTable`. Raw `SqlNamespaceInput`\n * objects (`{ id, entries }`) do not.\n */\nexport function isMaterializedSqlNamespace(x: unknown): x is SqlNamespaceBase {\n if (typeof x !== 'object' || x === null || !('qualifyTable' in x)) return false;\n return typeof x.qualifyTable === 'function';\n}\n\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n declare readonly types?: Readonly<Record<string, StorageTypeInstance>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.namespaces = Object.freeze(input.namespaces);\n if (input.types !== undefined) {\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]),\n ),\n );\n }\n freezeNode(this);\n }\n}\n\n/**\n * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.\n * Every entry must carry a `kind: 'codec-instance'` discriminator or\n * be an already-constructed `StorageTypeInstance`. Untagged or\n * unrecognised inputs throw a diagnostic naming the entry and its\n * `kind`, so format drift surfaces loudly at the deserializer\n * boundary instead of slipping past the seam and corrupting\n * downstream IR walks.\n *\n * Codec-triple authors that have an untagged shape on hand can call\n * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`\n * discriminator) before constructing `SqlStorage`. On-disk reads\n * cross `familyInstance.deserializeContract` first; the structural\n * arktype schema rejects untagged entries earlier, so this throw\n * only fires for in-memory authoring bugs.\n */\nfunction normaliseTypeEntry(name: string, entry: SqlStorageTypeEntry): StorageTypeInstance {\n if (isStorageTypeInstance(entry)) {\n // Normalise on-disk objects that omit `typeParams` (the canonical on-disk\n // form strips empty typeParams to keep JSON compact). The in-memory invariant\n // is always `typeParams: {}` when empty — never `undefined`. Only create a\n // new object when necessary to preserve identity-equality for callers that\n // hold a reference to an already-correct in-memory entry.\n if ('typeParams' in entry) {\n return entry;\n }\n return toStorageTypeInstance(entry);\n }\n const rawKind = isPlainRecord(entry) ? entry['kind'] : undefined;\n const kindDescription =\n rawKind === undefined\n ? 'missing `kind` discriminator'\n : `unrecognised \\`kind\\` discriminator ${JSON.stringify(rawKind)}`;\n throw new Error(\n `storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify('codec-instance')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport interface SqlControlDriverInstance<T extends string = string>\n extends ControlDriverInstance<'sql', T> {\n query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }>;\n}\n\nexport { CheckConstraint, type CheckConstraintInput } from './ir/check-constraint';\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReference,\n type ForeignKeyReferenceInput,\n} from './ir/foreign-key-reference';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n isMaterializedSqlNamespace,\n isSqlAuthoringContributions,\n type SqlAuthoringContributions,\n type SqlNamespace,\n SqlNamespaceBase,\n type SqlNamespaceEntries,\n type SqlNamespaceFactory,\n type SqlNamespaceInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { StorageColumn, type StorageColumnInput } from './ir/storage-column';\nexport { isStorageTable, StorageTable, type StorageTableInput } from './ir/storage-table';\nexport {\n CODEC_INSTANCE_KIND,\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './ir/storage-type-instance';\nexport {\n isStorageValueSet,\n StorageValueSet,\n type StorageValueSetInput,\n} from './ir/storage-value-set';\nexport {\n UniqueConstraint,\n type UniqueConstraintInput,\n} from './ir/unique-constraint';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly namespaceId: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\n// Field-type maps nested by namespace coordinate: `[namespaceId][model][field]`.\n// Shared by the output and input field-type maps and their extractors.\nexport type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;\n\nexport type NamespacedStorageColumnTypeMap = Record<\n string,\n Record<string, Record<string, unknown>>\n>;\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TStorageColumnTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n TStorageColumnInputTypes extends NamespacedStorageColumnTypeMap = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n readonly storageColumnTypes: TStorageColumnTypes;\n readonly storageColumnInputTypes: TStorageColumnInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Names a concrete codec identity, a set of capability traits the\n * field's codec must carry, or targets list-typed (`many`) fields. Element\n * capability gating for list ops travels in `elementTraits`.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never; readonly many?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never; readonly many?: never }\n | {\n readonly many: true;\n readonly elementTraits?: readonly CodecTrait[];\n readonly codecId?: never;\n readonly traits?: never;\n };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type StorageColumnInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly storageColumnInputTypes: infer F }\n ? F extends NamespacedStorageColumnTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnTypes<T> = StorageColumnTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractStorageColumnInputTypes<T> = StorageColumnInputTypesOf<\n ExtractTypeMapsFromContract<T>\n>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;AASA,MAAa,sBAAsB;;;;;;AAmCnC,SAAgB,sBAAsB,OAAsD;CAC1F,OAAO;EACL,MAAM;EACN,SAAS,MAAM;EACf,YAAY,MAAM;EACl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AK,UAAU,gBAAgB,EAAE,gGAC9G;AACF;;;AC9HA,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,56 +1,7 @@
|
|
|
1
1
|
import { r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
|
|
2
|
-
import { r as StorageTable } from "./storage-value-set-WnYsIFM8.mjs";
|
|
3
|
-
import { n as SqlNamespaceEntries, r as SqlNamespaceTablesInput, t as SqlNamespace } from "./sql-storage-Dga0jwP2.mjs";
|
|
4
|
-
import { Namespace, NamespaceBase } from "@prisma-next/framework-components/ir";
|
|
5
2
|
import { CodecTrait } from "@prisma-next/framework-components/codec";
|
|
6
3
|
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
7
4
|
|
|
8
|
-
//#region src/ir/build-sql-namespace.d.ts
|
|
9
|
-
declare function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace;
|
|
10
|
-
declare function buildSqlNamespaceMap(namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>): Readonly<Record<string, SqlNamespace>>;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/ir/sql-unbound-namespace.d.ts
|
|
13
|
-
/**
|
|
14
|
-
* Family-layer placeholder for the SQL unbound-namespace singleton —
|
|
15
|
-
* the late-bound slot whose binding the target resolves at connection
|
|
16
|
-
* time rather than at authoring time.
|
|
17
|
-
*
|
|
18
|
-
* SQL contracts honour the framework `Storage.namespaces` invariant from
|
|
19
|
-
* the moment they appear in the IR. Today `SqlStorage` is family-shared
|
|
20
|
-
* (Postgres + SQLite consume the same class); a per-target namespace
|
|
21
|
-
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
|
|
22
|
-
* earns its existence when each target's namespace shape lands. Until
|
|
23
|
-
* then the family ships a single placeholder singleton so the JSON
|
|
24
|
-
* envelope and runtime walk are honest at every layer.
|
|
25
|
-
*
|
|
26
|
-
* The `kind` discriminator is installed as a non-enumerable own property
|
|
27
|
-
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
|
|
28
|
-
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
|
|
29
|
-
* and bounded to the minimum data the framework `Namespace` interface
|
|
30
|
-
* promises.
|
|
31
|
-
*
|
|
32
|
-
* **Freeze-trap warning.** The leaf constructor calls
|
|
33
|
-
* `freezeNode(this)` after installing `kind`. The leaf-class shape
|
|
34
|
-
* works today only because `NamespaceBase` does NOT freeze in its
|
|
35
|
-
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
|
|
36
|
-
* `super()` succeeds because the instance is still mutable at that
|
|
37
|
-
* point. Subclasses that add instance fields will still hit the freeze
|
|
38
|
-
* trap once leaf-class `freezeNode(this)` runs; and if a future
|
|
39
|
-
* framework change lifts the freeze to `NamespaceBase`, even the
|
|
40
|
-
* `defineProperty` here would silently fail. To add subclass instance
|
|
41
|
-
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
|
|
42
|
-
* leaf calls explicitly at the end of its own constructor.
|
|
43
|
-
*/
|
|
44
|
-
declare class SqlUnboundNamespace extends NamespaceBase {
|
|
45
|
-
static readonly instance: SqlUnboundNamespace;
|
|
46
|
-
readonly id: "__unbound__";
|
|
47
|
-
readonly entries: SqlNamespaceEntries;
|
|
48
|
-
readonly kind: string;
|
|
49
|
-
private constructor();
|
|
50
|
-
get table(): Readonly<Record<string, StorageTable>>;
|
|
51
|
-
qualifyTable(tableName: string): string;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
5
|
//#region src/types.d.ts
|
|
55
6
|
interface SqlControlDriverInstance<T extends string = string> extends ControlDriverInstance<'sql', T> {
|
|
56
7
|
query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<{
|
|
@@ -85,13 +36,16 @@ declare function applyFkDefaults(fk: {
|
|
|
85
36
|
index: boolean;
|
|
86
37
|
};
|
|
87
38
|
type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;
|
|
39
|
+
type NamespacedStorageColumnTypeMap = Record<string, Record<string, Record<string, unknown>>>;
|
|
88
40
|
type TypeMaps<TCodecTypes extends Record<string, {
|
|
89
41
|
output: unknown;
|
|
90
|
-
}> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>, TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>> = {
|
|
42
|
+
}> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>, TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>, TStorageColumnTypes extends NamespacedStorageColumnTypeMap = Record<string, never>, TStorageColumnInputTypes extends NamespacedStorageColumnTypeMap = Record<string, never>> = {
|
|
91
43
|
readonly codecTypes: TCodecTypes;
|
|
92
44
|
readonly queryOperationTypes: TQueryOperationTypes;
|
|
93
45
|
readonly fieldOutputTypes: TFieldOutputTypes;
|
|
94
46
|
readonly fieldInputTypes: TFieldInputTypes;
|
|
47
|
+
readonly storageColumnTypes: TStorageColumnTypes;
|
|
48
|
+
readonly storageColumnInputTypes: TStorageColumnInputTypes;
|
|
95
49
|
};
|
|
96
50
|
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
97
51
|
readonly codecTypes: infer C;
|
|
@@ -102,15 +56,23 @@ type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
|
102
56
|
* Dispatch hint identifying the first-argument target of an operation.
|
|
103
57
|
*
|
|
104
58
|
* Used by ORM column helpers to decide whether an operation is reachable on a
|
|
105
|
-
* field.
|
|
106
|
-
*
|
|
59
|
+
* field. Names a concrete codec identity, a set of capability traits the
|
|
60
|
+
* field's codec must carry, or targets list-typed (`many`) fields. Element
|
|
61
|
+
* capability gating for list ops travels in `elementTraits`.
|
|
107
62
|
*/
|
|
108
63
|
type QueryOperationSelfSpec = {
|
|
109
64
|
readonly codecId: string;
|
|
110
65
|
readonly traits?: never;
|
|
66
|
+
readonly many?: never;
|
|
111
67
|
} | {
|
|
112
68
|
readonly traits: readonly CodecTrait[];
|
|
113
69
|
readonly codecId?: never;
|
|
70
|
+
readonly many?: never;
|
|
71
|
+
} | {
|
|
72
|
+
readonly many: true;
|
|
73
|
+
readonly elementTraits?: readonly CodecTrait[];
|
|
74
|
+
readonly codecId?: never;
|
|
75
|
+
readonly traits?: never;
|
|
114
76
|
};
|
|
115
77
|
/**
|
|
116
78
|
* Structural shape an operation's impl must return: any value carrying a
|
|
@@ -147,11 +109,19 @@ type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T ext
|
|
|
147
109
|
type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
148
110
|
readonly fieldInputTypes: infer F;
|
|
149
111
|
} ? F extends NamespacedFieldTypeMap ? F : Record<string, never> : Record<string, never>;
|
|
112
|
+
type StorageColumnTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
113
|
+
readonly storageColumnTypes: infer F;
|
|
114
|
+
} ? F extends NamespacedStorageColumnTypeMap ? F : Record<string, never> : Record<string, never>;
|
|
115
|
+
type StorageColumnInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
116
|
+
readonly storageColumnInputTypes: infer F;
|
|
117
|
+
} ? F extends NamespacedStorageColumnTypeMap ? F : Record<string, never> : Record<string, never>;
|
|
150
118
|
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
151
119
|
type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
152
120
|
type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
153
121
|
type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
122
|
+
type ExtractStorageColumnTypes<T> = StorageColumnTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
123
|
+
type ExtractStorageColumnInputTypes<T> = StorageColumnInputTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
154
124
|
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
155
125
|
//#endregion
|
|
156
|
-
export {
|
|
157
|
-
//# sourceMappingURL=types-
|
|
126
|
+
export { TypeMapsPhantomKey as A, SqlControlDriverInstance as C, StorageColumnInputTypesOf as D, SqlQueryOperationTypes as E, StorageColumnTypesOf as O, ResolveCodecTypes as S, SqlModelStorage as T, QueryOperationReturn as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, ExtractTypeMapsFromContract as d, FieldInputTypesOf as f, NamespacedStorageColumnTypeMap as g, NamespacedFieldTypeMap as h, DEFAULT_FK_INDEX as i, applyFkDefaults as j, TypeMaps as k, ExtractStorageColumnInputTypes as l, ForeignKeyOptions as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, FieldOutputTypesOf as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, ExtractStorageColumnTypes as u, QueryOperationSelfSpec as v, SqlModelFieldStorage as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
|
|
127
|
+
//# sourceMappingURL=types-ChH7hULD.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-ChH7hULD.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;UAIiB,wBAAA,oCACP,qBAAA,QAA6B,CAAA;EACrC,KAAA,OAAY,MAAA,mBACV,GAAA,UACA,MAAA,wBACC,OAAA;IAAA,SAAmB,IAAA,EAAM,GAAA;EAAA;AAAA;AAAA,KAgDlB,iBAAA;EAAA,SACD,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R,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,yBAAA,OAAgC,CAAA,oBACxC,MAAA,kBACA,CAAA;EAAA,SAAqB,uBAAA;AAAA,IACnB,CAAA,SAAU,8BAAA,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,KAC1E,yBAAA,MAA+B,oBAAA,CAAqB,2BAAA,CAA4B,CAAA;AAAA,KAChF,8BAAA,MAAoC,yBAAA,CAC9C,2BAAA,CAA4B,CAAA;AAAA,KAGlB,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { a as ForeignKeyReferenceInput, i as ForeignKeyReference, n as ForeignKeyInput, o as SqlNode, r as ReferentialAction, t as ForeignKey } from "./foreign-key-BATxB95l.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import { C as
|
|
5
|
-
|
|
2
|
+
import { a as StorageTableInput, c as UniqueConstraintInput, d as Index, f as IndexInput, g as CheckConstraintInput, h as CheckConstraint, i as StorageTable, l as StorageColumn, m as PrimaryKeyInput, n as StorageValueSetInput, o as isStorageTable, p as PrimaryKey, r as isStorageValueSet, s as UniqueConstraint, t as StorageValueSet, u as StorageColumnInput } from "./storage-value-set-B1Xmb6D2.mjs";
|
|
3
|
+
import { a as SqlNamespaceFactory, c as SqlStorageInput, d as isSqlAuthoringContributions, f as CODEC_INSTANCE_KIND, g as toStorageTypeInstance, h as isStorageTypeInstance, i as SqlNamespaceEntries, l as SqlStorageTypeEntry, m as StorageTypeInstanceInput, n as SqlNamespace, o as SqlNamespaceInput, p as StorageTypeInstance, r as SqlNamespaceBase, s as SqlStorage, t as SqlAuthoringContributions, u as isMaterializedSqlNamespace } from "./sql-storage-CUP3mD3c.mjs";
|
|
4
|
+
import { A as TypeMapsPhantomKey, C as SqlControlDriverInstance, D as StorageColumnInputTypesOf, E as SqlQueryOperationTypes, O as StorageColumnTypesOf, S as ResolveCodecTypes, T as SqlModelStorage, _ as QueryOperationReturn, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as ExtractTypeMapsFromContract, f as FieldInputTypesOf, g as NamespacedStorageColumnTypeMap, h as NamespacedFieldTypeMap, i as DEFAULT_FK_INDEX, j as applyFkDefaults, k as TypeMaps, l as ExtractStorageColumnInputTypes, m as ForeignKeyOptions, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as FieldOutputTypesOf, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as ExtractStorageColumnTypes, v as QueryOperationSelfSpec, w as SqlModelFieldStorage, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-ChH7hULD.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/column-type-resolution.d.ts
|
|
7
|
+
type StorageColumnMapAt<SCT, NsId extends string, TableName extends string> = string extends keyof SCT ? never : NsId extends keyof SCT ? string extends keyof SCT[NsId] ? never : TableName extends keyof SCT[NsId] ? SCT[NsId][TableName] : never : never;
|
|
8
|
+
type StorageColumnTypeAcrossNamespaces<SCT, TableName extends string, ColumnName extends string> = { [Ns in keyof SCT]: TableName extends keyof SCT[Ns] ? ColumnName extends keyof SCT[Ns][TableName] ? SCT[Ns][TableName][ColumnName] : never : never }[keyof SCT];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CODEC_INSTANCE_KIND, CheckConstraint, type CheckConstraintInput, type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractStorageColumnInputTypes, type ExtractStorageColumnTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, ForeignKey, type ForeignKeyInput, type ForeignKeyOptions, ForeignKeyReference, type ForeignKeyReferenceInput, Index, type IndexInput, type NamespacedFieldTypeMap, type NamespacedStorageColumnTypeMap, PrimaryKey, type PrimaryKeyInput, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlAuthoringContributions, type SqlControlDriverInstance, type SqlModelFieldStorage, type SqlModelStorage, type SqlNamespace, SqlNamespaceBase, type SqlNamespaceEntries, type SqlNamespaceFactory, type SqlNamespaceInput, SqlNode, type SqlQueryOperationTypes, SqlStorage, type SqlStorageInput, type SqlStorageTypeEntry, StorageColumn, type StorageColumnInput, type StorageColumnInputTypesOf, type StorageColumnMapAt, type StorageColumnTypeAcrossNamespaces, type StorageColumnTypesOf, StorageTable, type StorageTableInput, type StorageTypeInstance, type StorageTypeInstanceInput, StorageValueSet, type StorageValueSetInput, type TypeMaps, type TypeMapsPhantomKey, UniqueConstraint, type UniqueConstraintInput, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTable, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance };
|
|
11
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/column-type-resolution.ts"],"mappings":";;;;;;KACY,kBAAA,4EAIa,GAAA,WAErB,IAAA,eAAmB,GAAA,wBACI,GAAA,CAAI,IAAA,YAEvB,SAAA,eAAwB,GAAA,CAAI,IAAA,IAC1B,GAAA,CAAI,IAAA,EAAM,SAAA;AAAA,KAIR,iCAAA,4EAKG,GAAA,GAAM,SAAA,eAAwB,GAAA,CAAI,EAAA,IAC3C,UAAA,eAAyB,GAAA,CAAI,EAAA,EAAI,SAAA,IAC/B,GAAA,CAAI,EAAA,EAAI,SAAA,EAAW,UAAA,0BAGnB,GAAA"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as
|
|
3
|
-
export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNode, SqlStorage,
|
|
1
|
+
import { a as UniqueConstraint, c as PrimaryKey, d as CheckConstraint, f as SqlNode, i as isStorageTable, l as ForeignKey, n as isStorageValueSet, o as StorageColumn, r as StorageTable, s as Index, t as StorageValueSet, u as ForeignKeyReference } from "./storage-value-set-Cp7h3D59.mjs";
|
|
2
|
+
import { a as SqlStorage, c as CODEC_INSTANCE_KIND, i as SqlNamespaceBase, l as isStorageTypeInstance, n as DEFAULT_FK_INDEX, o as isMaterializedSqlNamespace, r as applyFkDefaults, s as isSqlAuthoringContributions, t as DEFAULT_FK_CONSTRAINT, u as toStorageTypeInstance } from "./types-B4sPkjNO.mjs";
|
|
3
|
+
export { CODEC_INSTANCE_KIND, CheckConstraint, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, ForeignKey, ForeignKeyReference, Index, PrimaryKey, SqlNamespaceBase, SqlNode, SqlStorage, StorageColumn, StorageTable, StorageValueSet, UniqueConstraint, applyFkDefaults, isMaterializedSqlNamespace, isSqlAuthoringContributions, isStorageTable, isStorageTypeInstance, isStorageValueSet, toStorageTypeInstance };
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-BATxB95l.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { c as UniqueConstraintInput, m as PrimaryKeyInput } from "./storage-value-set-B1Xmb6D2.mjs";
|
|
3
|
+
import { s as SqlStorage } from "./sql-storage-CUP3mD3c.mjs";
|
|
4
4
|
import { Type } from "arktype";
|
|
5
5
|
import { AnyEntityKindDescriptor } from "@prisma-next/framework-components/ir";
|
|
6
6
|
import { Contract } from "@prisma-next/contract/types";
|
|
@@ -62,6 +62,7 @@ declare const StorageTableSchema: import("arktype/internal/variants/object.ts").
|
|
|
62
62
|
nativeType: string;
|
|
63
63
|
codecId: string;
|
|
64
64
|
nullable: boolean;
|
|
65
|
+
many?: boolean;
|
|
65
66
|
typeParams?: Record<string, unknown>;
|
|
66
67
|
typeRef?: string;
|
|
67
68
|
default?: ColumnDefaultLiteral | ColumnDefaultFunction;
|
|
@@ -133,13 +134,15 @@ declare function createSqlStorageSchema(kinds: ReadonlyMap<string, AnyEntityKind
|
|
|
133
134
|
*/
|
|
134
135
|
declare function createSqlContractSchema(kinds: ReadonlyMap<string, AnyEntityKindDescriptor>): Type<unknown>;
|
|
135
136
|
/**
|
|
136
|
-
* Validates the structural shape of SqlStorage using Arktype.
|
|
137
|
+
* Validates the structural shape of SqlStorage using Arktype. Pure
|
|
138
|
+
* structural check: namespace IR is never materialized here (that needs
|
|
139
|
+
* a target concretion via the serializer hydration path), so this throws
|
|
140
|
+
* on invalid input and constructs nothing.
|
|
137
141
|
*
|
|
138
142
|
* @param value - The storage value to validate
|
|
139
|
-
* @returns The validated storage if structure is valid
|
|
140
143
|
* @throws Error if the storage structure is invalid
|
|
141
144
|
*/
|
|
142
|
-
declare function validateStorage(value: unknown):
|
|
145
|
+
declare function validateStorage(value: unknown): void;
|
|
143
146
|
declare function validateModel(value: unknown): unknown;
|
|
144
147
|
/**
|
|
145
148
|
* Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/validators.ts"],"mappings":";;;;;;;;KAM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O,WAAA,SAAoB,uBAAA,IAC1B,IAAA;;;ADzHoC;AAKvC;;;iBCgKgB,sBAAA,CACd,KAAA,EAAO,WAAA,SAAoB,uBAAA,IAC1B,IAAA;ADlKqC;AAKxC;;;;AALwC,iBC0TxB,uBAAA,CACd,KAAA,EAAO,WAAA,SAAoB,uBAAA,IAC1B,IAAA;;;;ADvT6B;AAiChC;;;;;iBC4TgB,eAAA,CAAgB,KAAc;AAAA,iBAQ9B,aAAA,CAAc,KAAc;;;;ADnT5C;;;;;;;;;;iBCiXgB,wBAAA,CAAyB,OAAmB,EAAV,UAAU;;AD1W5D;;;;;iBC+gBgB,8BAAA,CAA+B,QAAA,EAAU,QAAQ,CAAC,UAAA;;;;;;ADvgBlE;iBCmkBgB,6BAAA,CAA8B,QAAA,EAAU,QAAQ,CAAC,UAAA;AAAA,UAwGhD,+BAAA;EDtqB0B;;;;;;;AAE3C;EAF2C,SC+qBhC,cAAA,GAAiB,IAAI;AAAA;;AD7qBI;AAIpC;;;;AAA6B;AAU7B;iBC0qBgB,wBAAA,WAAmC,QAAA,CAAS,UAAA,GAC1D,KAAA,WACA,OAAA,GAAU,+BAAA,GACT,CAAA"}
|
package/dist/validators.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as SqlStorage, l as buildSqlNamespaceMap, u as SqlUnboundNamespace } from "./types-B-eiQXff.mjs";
|
|
1
|
+
import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-BSGvSPI8.mjs";
|
|
3
2
|
import { type } from "arktype";
|
|
4
|
-
import {
|
|
3
|
+
import { isPlainRecord } from "@prisma-next/framework-components/ir";
|
|
5
4
|
import { CrossReferenceSchema } from "@prisma-next/contract/types";
|
|
6
|
-
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
5
|
import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
|
|
8
6
|
import { validateContractDomain } from "@prisma-next/contract/validate-domain";
|
|
7
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
9
8
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
9
|
//#region src/validators.ts
|
|
11
10
|
const generatorKindSchema = type("'generator'");
|
|
@@ -236,10 +235,12 @@ function createSqlContractSchema(kinds) {
|
|
|
236
235
|
}
|
|
237
236
|
const SqlContractSchema = createSqlContractSchema(DEFAULT_SQL_KINDS);
|
|
238
237
|
/**
|
|
239
|
-
* Validates the structural shape of SqlStorage using Arktype.
|
|
238
|
+
* Validates the structural shape of SqlStorage using Arktype. Pure
|
|
239
|
+
* structural check: namespace IR is never materialized here (that needs
|
|
240
|
+
* a target concretion via the serializer hydration path), so this throws
|
|
241
|
+
* on invalid input and constructs nothing.
|
|
240
242
|
*
|
|
241
243
|
* @param value - The storage value to validate
|
|
242
|
-
* @returns The validated storage if structure is valid
|
|
243
244
|
* @throws Error if the storage structure is invalid
|
|
244
245
|
*/
|
|
245
246
|
function validateStorage(value) {
|
|
@@ -248,17 +249,6 @@ function validateStorage(value) {
|
|
|
248
249
|
const messages = result.map((p) => p.message).join("; ");
|
|
249
250
|
throw new Error(`Storage validation failed: ${messages}`);
|
|
250
251
|
}
|
|
251
|
-
const validated = blindCast(result);
|
|
252
|
-
const namespaces = buildSqlNamespaceMap(validated.namespaces ?? {});
|
|
253
|
-
const unbound = namespaces[UNBOUND_NAMESPACE_ID] ?? SqlUnboundNamespace.instance;
|
|
254
|
-
return new SqlStorage({
|
|
255
|
-
storageHash: validated.storageHash,
|
|
256
|
-
...ifDefined("types", validated.types),
|
|
257
|
-
namespaces: {
|
|
258
|
-
...namespaces,
|
|
259
|
-
[UNBOUND_NAMESPACE_ID]: unbound
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
252
|
}
|
|
263
253
|
function validateModel(value) {
|
|
264
254
|
const result = ModelSchema(value);
|
|
@@ -463,8 +453,110 @@ function validateSqlContractFully(value, options) {
|
|
|
463
453
|
const semanticErrors = validateStorageSemantics(validated.storage);
|
|
464
454
|
if (semanticErrors.length > 0) throw new ContractValidationError(`Contract semantic validation failed: ${semanticErrors.join("; ")}`, "storage");
|
|
465
455
|
validateModelStorageReferences(validated);
|
|
456
|
+
validateRelationThroughConsistency(validated);
|
|
466
457
|
return validated;
|
|
467
458
|
}
|
|
459
|
+
/** Storage column lookup for through-consistency validation. */
|
|
460
|
+
function lookupStorageColumn(contract, namespaceId, tableName, columnName) {
|
|
461
|
+
const rawTable = contract.storage.namespaces[namespaceId]?.entries.table?.[tableName];
|
|
462
|
+
if (rawTable === void 0) return;
|
|
463
|
+
return blindCast(rawTable).columns[columnName];
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Two storage columns share a type when their `nativeType` and `typeParams`
|
|
467
|
+
* match. The contract is canonicalized, so `typeParams` key order is stable and
|
|
468
|
+
* a JSON comparison is exact. `codecId` and `nullable` are intentionally not
|
|
469
|
+
* compared: they do not change the database-level type that governs a join.
|
|
470
|
+
*/
|
|
471
|
+
function sameStorageType(a, b) {
|
|
472
|
+
return a.nativeType === b.nativeType && JSON.stringify(a.typeParams ?? null) === JSON.stringify(b.typeParams ?? null);
|
|
473
|
+
}
|
|
474
|
+
function describeColumnType(column) {
|
|
475
|
+
return column.typeParams === void 0 ? column.nativeType : `${column.nativeType} ${JSON.stringify(column.typeParams)}`;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Validates one side of an N:M join: the junction columns and the model
|
|
479
|
+
* columns they pair against positionally must be equal in number, exist in
|
|
480
|
+
* their tables, and share the same storage type (`nativeType` + `typeParams`).
|
|
481
|
+
* The junction's storage foreign keys already guarantee this for user-declared
|
|
482
|
+
* FK constraints, but `through` is a logical descriptor never tied to them by
|
|
483
|
+
* the rest of validation — and the TS builder accepts explicit join columns
|
|
484
|
+
* without requiring a junction FK at all — so this checks the columns directly
|
|
485
|
+
* against storage, one path regardless of how the junction was authored.
|
|
486
|
+
*
|
|
487
|
+
* Joined columns must be the *same* storage type, not merely compatible:
|
|
488
|
+
* relying on implicit conversion (e.g. `text`↔`character`) is unsafe on writes
|
|
489
|
+
* — `character(n)` space-padding makes such coercions non-associative — and no
|
|
490
|
+
* ADR sanctions heterogeneous junction columns. Equality is the conservative
|
|
491
|
+
* default; it can be relaxed deliberately if a real use case ever appears.
|
|
492
|
+
*/
|
|
493
|
+
function validateThroughJoinSide(input) {
|
|
494
|
+
const fail = (detail) => new ContractValidationError(`Many-to-many relation "${input.qualifiedName}" ${detail}`, "storage");
|
|
495
|
+
if (input.junctionColumns.length !== input.modelColumns.length) throw fail(`pairs ${input.junctionColumnsLabel} (${input.junctionColumns.length}) with ${input.modelColumnsLabel} (${input.modelColumns.length}) of differing length; they join positionally and must match.`);
|
|
496
|
+
for (const [index, junctionColumnName] of input.junctionColumns.entries()) {
|
|
497
|
+
const modelColumnRef = input.modelColumns[index];
|
|
498
|
+
if (modelColumnRef === void 0) continue;
|
|
499
|
+
const junctionColumn = lookupStorageColumn(input.contract, input.junctionNamespaceId, input.junctionTable, junctionColumnName);
|
|
500
|
+
if (junctionColumn === void 0) throw fail(`${input.junctionColumnsLabel} references column "${junctionColumnName}" absent from junction table "${input.junctionNamespaceId}.${input.junctionTable}".`);
|
|
501
|
+
const model = input.model;
|
|
502
|
+
if (model === void 0) continue;
|
|
503
|
+
let modelColumnName = modelColumnRef;
|
|
504
|
+
if (model.fieldToColumn !== void 0) {
|
|
505
|
+
const mapped = model.fieldToColumn[modelColumnRef];
|
|
506
|
+
if (mapped === void 0) throw fail(`${input.modelColumnsLabel} references field "${modelColumnRef}" absent from model on table "${model.namespaceId}.${model.table}".`);
|
|
507
|
+
modelColumnName = mapped.column;
|
|
508
|
+
}
|
|
509
|
+
const modelColumn = lookupStorageColumn(input.contract, model.namespaceId, model.table, modelColumnName);
|
|
510
|
+
if (modelColumn === void 0) throw fail(`${input.modelColumnsLabel} references column "${modelColumnName}" absent from table "${model.namespaceId}.${model.table}".`);
|
|
511
|
+
if (!sameStorageType(junctionColumn, modelColumn)) throw fail(`joins "${input.junctionTable}.${junctionColumnName}" (${describeColumnType(junctionColumn)}) with "${model.table}.${modelColumnName}" (${describeColumnType(modelColumn)}) of differing storage type; junction columns must match the type of the column they reference.`);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Validates that every N:M relation's `through` descriptor is consistent with
|
|
516
|
+
* the storage columns it joins: both join sides match in column count,
|
|
517
|
+
* reference columns that exist in their tables, and pair columns of the same
|
|
518
|
+
* storage type. Without this, a `through` that disagrees with storage surfaces
|
|
519
|
+
* as a silently wrong JOIN at query time rather than a validation error here.
|
|
520
|
+
*/
|
|
521
|
+
function validateRelationThroughConsistency(contract) {
|
|
522
|
+
for (const [namespaceId, namespace] of Object.entries(contract.domain.namespaces)) for (const [modelName, model] of Object.entries(namespace.models)) for (const [relationName, relation] of Object.entries(model.relations)) {
|
|
523
|
+
if (relation.cardinality !== "N:M") continue;
|
|
524
|
+
const qualifiedName = `${namespaceId}.${modelName}.${relationName}`;
|
|
525
|
+
const { on, through } = relation;
|
|
526
|
+
const modelStorage = blindCast(model.storage);
|
|
527
|
+
validateThroughJoinSide({
|
|
528
|
+
contract,
|
|
529
|
+
qualifiedName,
|
|
530
|
+
modelColumns: on.localFields,
|
|
531
|
+
modelColumnsLabel: "on.localFields",
|
|
532
|
+
model: {
|
|
533
|
+
namespaceId,
|
|
534
|
+
table: modelStorage.table,
|
|
535
|
+
fieldToColumn: modelStorage.fields
|
|
536
|
+
},
|
|
537
|
+
junctionColumns: through.parentColumns,
|
|
538
|
+
junctionColumnsLabel: "through.parentColumns",
|
|
539
|
+
junctionNamespaceId: through.namespaceId,
|
|
540
|
+
junctionTable: through.table
|
|
541
|
+
});
|
|
542
|
+
const targetModel = relation.to.space === void 0 ? contract.domain.namespaces[relation.to.namespace]?.models[relation.to.model] : void 0;
|
|
543
|
+
const targetModelSide = targetModel === void 0 ? void 0 : {
|
|
544
|
+
namespaceId: relation.to.namespace,
|
|
545
|
+
table: blindCast(targetModel.storage).table
|
|
546
|
+
};
|
|
547
|
+
validateThroughJoinSide({
|
|
548
|
+
contract,
|
|
549
|
+
qualifiedName,
|
|
550
|
+
modelColumns: through.targetColumns,
|
|
551
|
+
modelColumnsLabel: "through.targetColumns",
|
|
552
|
+
...ifDefined("model", targetModelSide),
|
|
553
|
+
junctionColumns: through.childColumns,
|
|
554
|
+
junctionColumnsLabel: "through.childColumns",
|
|
555
|
+
junctionNamespaceId: through.namespaceId,
|
|
556
|
+
junctionTable: through.table
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
468
560
|
//#endregion
|
|
469
561
|
export { CheckConstraintSchema, ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ContractEnumSchema, ForeignKeyReferenceSchema, ForeignKeySchema, ForeignKeySourceSchema, IndexSchema, ReferentialActionSchema, StorageTableSchema, StorageValueSetSchema, createNamespaceEntrySchema, createSqlContractSchema, createSqlStorageSchema, validateModel, validateModelStorageReferences, validateSqlContractFully, validateSqlStorageConsistency, validateStorage, validateStorageSemantics };
|
|
470
562
|
|