@prisma-next/sql-contract 0.8.0 → 0.9.0-dev.2

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.
Files changed (52) hide show
  1. package/README.md +13 -11
  2. package/dist/factories.d.mts +2 -2
  3. package/dist/factories.d.mts.map +1 -1
  4. package/dist/factories.mjs +16 -14
  5. package/dist/factories.mjs.map +1 -1
  6. package/dist/index-type-validation.d.mts +2 -2
  7. package/dist/index-type-validation.mjs +1 -1
  8. package/dist/index-type-validation.mjs.map +1 -1
  9. package/dist/{index-types-DqVqGHwg.d.mts → index-types-B1cf5N0F.d.mts} +1 -1
  10. package/dist/{index-types-DqVqGHwg.d.mts.map → index-types-B1cf5N0F.d.mts.map} +1 -1
  11. package/dist/index-types.d.mts +1 -1
  12. package/dist/types-B0lbr9cb.d.mts +498 -0
  13. package/dist/types-B0lbr9cb.d.mts.map +1 -0
  14. package/dist/types-iqFGDcJp.mjs +389 -0
  15. package/dist/types-iqFGDcJp.mjs.map +1 -0
  16. package/dist/types.d.mts +2 -2
  17. package/dist/types.mjs +2 -2
  18. package/dist/validators.d.mts +27 -15
  19. package/dist/validators.d.mts.map +1 -1
  20. package/dist/validators.mjs +409 -2
  21. package/dist/validators.mjs.map +1 -0
  22. package/package.json +6 -7
  23. package/src/exports/types.ts +30 -9
  24. package/src/factories.ts +19 -32
  25. package/src/index-type-validation.ts +1 -1
  26. package/src/index.ts +0 -1
  27. package/src/ir/foreign-key-references.ts +26 -0
  28. package/src/ir/foreign-key.ts +50 -0
  29. package/src/ir/postgres-enum-storage-entry.ts +55 -0
  30. package/src/ir/primary-key.ts +22 -0
  31. package/src/ir/sql-index.ts +33 -0
  32. package/src/ir/sql-node.ts +52 -0
  33. package/src/ir/sql-storage.ts +154 -0
  34. package/src/ir/sql-unspecified-namespace.ts +51 -0
  35. package/src/ir/storage-column.ts +55 -0
  36. package/src/ir/storage-table.ts +63 -0
  37. package/src/ir/storage-type-instance.ts +60 -0
  38. package/src/ir/unique-constraint.ts +22 -0
  39. package/src/types.ts +38 -99
  40. package/src/validators.ts +268 -28
  41. package/dist/types-hgzy8ME1.mjs +0 -13
  42. package/dist/types-hgzy8ME1.mjs.map +0 -1
  43. package/dist/types-njsiV-Ck.d.mts +0 -186
  44. package/dist/types-njsiV-Ck.d.mts.map +0 -1
  45. package/dist/validate.d.mts +0 -9
  46. package/dist/validate.d.mts.map +0 -1
  47. package/dist/validate.mjs +0 -106
  48. package/dist/validate.mjs.map +0 -1
  49. package/dist/validators-Dm5X-Hvg.mjs +0 -294
  50. package/dist/validators-Dm5X-Hvg.mjs.map +0 -1
  51. package/src/exports/validate.ts +0 -1
  52. package/src/validate.ts +0 -227
@@ -0,0 +1,498 @@
1
+ import { IRNodeBase, Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir";
2
+ import { ColumnDefault, StorageHashBase } from "@prisma-next/contract/types";
3
+ import { CodecTrait } from "@prisma-next/framework-components/codec";
4
+
5
+ //#region src/ir/sql-node.d.ts
6
+ /**
7
+ * SQL family IR node base. Carries the family-level `kind` discriminator
8
+ * `'sql'` and inherits the framework's `freezeNode` affordance.
9
+ *
10
+ * Single family-level discriminator (not per-leaf) reflects the fact that
11
+ * SQL IR has no polymorphic dispatch today — verifiers and serializers
12
+ * walk by structural position (`storage.tables[name].columns[name]`),
13
+ * not by inspecting `kind`. The abstract bar for per-leaf discriminators
14
+ * isn't earned until a future polymorphic consumer arrives.
15
+ *
16
+ * `kind` is installed as a non-enumerable own property on every instance,
17
+ * which keeps three things clean simultaneously:
18
+ *
19
+ * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope
20
+ * shape (no `kind` field), so emitted contract.json files and the
21
+ * `validateSqlContractFully` arktype schemas stay unchanged.
22
+ * - Test assertions that use `toEqual({...})` against the pre-lift flat
23
+ * shape continue to pass — only enumerable own properties are
24
+ * compared.
25
+ * - Direct access (`node.kind`) and runtime narrowing
26
+ * (`if (node.kind === 'sql')`) still work, so future polymorphic
27
+ * dispatch can begin reading `kind` without a runtime change.
28
+ *
29
+ * Future per-leaf overrides land cleanly: a class that gains a
30
+ * polymorphic-dispatch consumer (e.g. an enum type instance walked
31
+ * alongside other types) overrides `kind` with its narrower literal
32
+ * at that leaf level. Per-leaf overrides will use enumerable kind
33
+ * (matching the Mongo per-class-discriminator precedent) because they
34
+ * encode dispatch-relevant information that callers need to see in
35
+ * JSON envelopes; the family-level `'sql'` is uniform across all SQL
36
+ * IR and carries no dispatch-relevant information.
37
+ */
38
+ declare abstract class SqlNode extends IRNodeBase {
39
+ readonly kind?: string;
40
+ constructor();
41
+ }
42
+ //#endregion
43
+ //#region src/ir/foreign-key-references.d.ts
44
+ interface ForeignKeyReferencesInput {
45
+ readonly table: string;
46
+ readonly columns: readonly string[];
47
+ }
48
+ /**
49
+ * SQL Contract IR node for the referenced side of a foreign key.
50
+ *
51
+ * The class is shaped around single-namespace references today; a
52
+ * future milestone introduces a cross-namespace coordinate on top of
53
+ * `(table, columns)` when namespace-keyed storage lands.
54
+ */
55
+ declare class ForeignKeyReferences extends SqlNode {
56
+ readonly table: string;
57
+ readonly columns: readonly string[];
58
+ constructor(input: ForeignKeyReferencesInput);
59
+ }
60
+ //#endregion
61
+ //#region src/ir/foreign-key.d.ts
62
+ type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
63
+ interface ForeignKeyInput {
64
+ readonly columns: readonly string[];
65
+ readonly references: ForeignKeyReferences | ForeignKeyReferencesInput;
66
+ readonly name?: string;
67
+ readonly onDelete?: ReferentialAction;
68
+ readonly onUpdate?: ReferentialAction;
69
+ /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
70
+ readonly constraint: boolean;
71
+ /** Whether to emit a backing index for the FK columns. */
72
+ readonly index: boolean;
73
+ }
74
+ /**
75
+ * SQL Contract IR node for a table-level foreign-key declaration.
76
+ *
77
+ * The nested `references` field is normalised to a
78
+ * {@link ForeignKeyReferences} instance inside the constructor so
79
+ * downstream walks see a uniform AST regardless of whether the input
80
+ * was a JSON literal or an already-constructed class instance.
81
+ */
82
+ declare class ForeignKey extends SqlNode {
83
+ readonly columns: readonly string[];
84
+ readonly references: ForeignKeyReferences;
85
+ readonly constraint: boolean;
86
+ readonly index: boolean;
87
+ readonly name?: string;
88
+ readonly onDelete?: ReferentialAction;
89
+ readonly onUpdate?: ReferentialAction;
90
+ constructor(input: ForeignKeyInput);
91
+ }
92
+ //#endregion
93
+ //#region src/ir/postgres-enum-storage-entry.d.ts
94
+ /**
95
+ * Discriminator literal for the Postgres-enum variant on the polymorphic
96
+ * `SqlStorage.types` slot.
97
+ *
98
+ * Enums are a target-level concept: Postgres ships native
99
+ * `CREATE TYPE … AS ENUM` while other SQL targets approximate enums via
100
+ * constraints. The literal lives at the SQL family layer because every
101
+ * SQL-family consumer (verifier, planner, lowering, …) needs to
102
+ * discriminate enum-typed slot entries from codec-typed ones. The
103
+ * concrete IR class (`PostgresEnumType`) lives in the target-postgres
104
+ * package and implements this structural contract; cross-domain
105
+ * layering rules forbid the SQL family from importing the concrete
106
+ * target class directly, so the discriminator and structural interface
107
+ * carry the dispatch.
108
+ */
109
+ declare const POSTGRES_ENUM_KIND: "postgres-enum";
110
+ /**
111
+ * Structural contract every Postgres-enum slot entry honours — both
112
+ * the live `PostgresEnumType` IR-class instance and the raw JSON
113
+ * envelope shape that survives `JSON.stringify` round-trips. SQL
114
+ * family-layer dispatch narrows polymorphic `StorageType` slot
115
+ * entries to this shape via `isPostgresEnumStorageEntry`.
116
+ *
117
+ * The `codecBinding` field is accessor-shaped (live class instance) on
118
+ * the IR class and undefined on the raw JSON envelope; consumers that
119
+ * need it must guard for its presence (the JSON path synthesises an
120
+ * equivalent shape from `codecId` + `values`).
121
+ */
122
+ interface PostgresEnumStorageEntry extends StorageType {
123
+ readonly kind: typeof POSTGRES_ENUM_KIND;
124
+ readonly name: string;
125
+ readonly nativeType: string;
126
+ readonly values: readonly string[];
127
+ /**
128
+ * Enumerable own property on the persisted JSON envelope; the live
129
+ * IR-class instance carries it too. Family-shared dispatch sites
130
+ * read `codecId` directly rather than going through the IR-class
131
+ * `codecBinding` accessor (which lives on the prototype and isn't
132
+ * present on raw JSON envelopes).
133
+ */
134
+ readonly codecId: string;
135
+ }
136
+ /**
137
+ * Narrow a polymorphic `StorageType` entry to the Postgres-enum shape
138
+ * via its enumerable `kind` discriminator. Type guard returns true for
139
+ * both live `PostgresEnumType` instances and raw JSON envelopes.
140
+ */
141
+ declare function isPostgresEnumStorageEntry(value: unknown): value is PostgresEnumStorageEntry;
142
+ //#endregion
143
+ //#region src/ir/primary-key.d.ts
144
+ interface PrimaryKeyInput {
145
+ readonly columns: readonly string[];
146
+ readonly name?: string;
147
+ }
148
+ /**
149
+ * SQL Contract IR node for a table's primary-key constraint.
150
+ */
151
+ declare class PrimaryKey extends SqlNode {
152
+ readonly columns: readonly string[];
153
+ readonly name?: string;
154
+ constructor(input: PrimaryKeyInput);
155
+ }
156
+ //#endregion
157
+ //#region src/ir/sql-index.d.ts
158
+ interface IndexInput {
159
+ readonly columns: readonly string[];
160
+ readonly name?: string;
161
+ readonly type?: string;
162
+ readonly options?: Record<string, unknown>;
163
+ }
164
+ /**
165
+ * SQL Contract IR node for a table-level secondary index.
166
+ *
167
+ * Note that this class shadows the global TypeScript `Index` lib type
168
+ * at the family-shared name; consumer files that need both should
169
+ * alias one (e.g.
170
+ * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
171
+ */
172
+ declare class Index extends SqlNode {
173
+ readonly columns: readonly string[];
174
+ readonly name?: string;
175
+ readonly type?: string;
176
+ readonly options?: Record<string, unknown>;
177
+ constructor(input: IndexInput);
178
+ }
179
+ //#endregion
180
+ //#region src/ir/storage-column.d.ts
181
+ /**
182
+ * Hydration / construction input shape for {@link StorageColumn}. Mirrors
183
+ * the on-disk storage JSON envelope exactly so the family-base
184
+ * serializer's hydration walker can hand an arktype-validated literal
185
+ * straight to `new`.
186
+ *
187
+ * `typeParams` and `typeRef` remain mutually exclusive (one or the
188
+ * other, not both); the constructor preserves whichever caller-side
189
+ * choice the input encodes.
190
+ */
191
+ interface StorageColumnInput {
192
+ readonly nativeType: string;
193
+ readonly codecId: string;
194
+ readonly nullable: boolean;
195
+ readonly typeParams?: Record<string, unknown>;
196
+ readonly typeRef?: string;
197
+ readonly default?: ColumnDefault;
198
+ }
199
+ /**
200
+ * SQL Contract IR node for a single column entry in `StorageTable.columns`.
201
+ *
202
+ * Single concrete family-shared class — every SQL target reads the
203
+ * same column shape today, so there is no per-target subclass. The
204
+ * class type accepts any caller that constructs via
205
+ * `new StorageColumn(input)`; literal construction sites must pass
206
+ * through the constructor or the family-base hydration walker.
207
+ *
208
+ * The column's `name` is not on the class — columns are keyed by name
209
+ * in the parent `StorageTable.columns: Record<string, StorageColumn>`
210
+ * map, so a `name` field would be redundant with the key.
211
+ */
212
+ declare class StorageColumn extends SqlNode {
213
+ readonly nativeType: string;
214
+ readonly codecId: string;
215
+ readonly nullable: boolean;
216
+ readonly typeParams?: Record<string, unknown>;
217
+ readonly typeRef?: string;
218
+ readonly default?: ColumnDefault;
219
+ constructor(input: StorageColumnInput);
220
+ }
221
+ //#endregion
222
+ //#region src/ir/unique-constraint.d.ts
223
+ interface UniqueConstraintInput {
224
+ readonly columns: readonly string[];
225
+ readonly name?: string;
226
+ }
227
+ /**
228
+ * SQL Contract IR node for a table-level unique constraint.
229
+ */
230
+ declare class UniqueConstraint extends SqlNode {
231
+ readonly columns: readonly string[];
232
+ readonly name?: string;
233
+ constructor(input: UniqueConstraintInput);
234
+ }
235
+ //#endregion
236
+ //#region src/ir/storage-table.d.ts
237
+ interface StorageTableInput {
238
+ readonly columns: Record<string, StorageColumn | StorageColumnInput>;
239
+ readonly primaryKey?: PrimaryKey | PrimaryKeyInput;
240
+ readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;
241
+ readonly indexes: ReadonlyArray<Index | IndexInput>;
242
+ readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;
243
+ }
244
+ /**
245
+ * SQL Contract IR node for a single table entry in `SqlStorage.tables`.
246
+ *
247
+ * The constructor normalises nested IR-class fields (columns, primary
248
+ * key, uniques, indexes, foreign keys) into the appropriate class
249
+ * instances so downstream walks see a uniform AST regardless of whether
250
+ * the input was a JSON literal or an already-constructed class.
251
+ *
252
+ * The table's `name` is not on the class — tables are keyed by name in
253
+ * the parent `SqlStorage.tables: Record<string, StorageTable>` map.
254
+ * A future namespace-aware milestone will add a `namespaceId` field
255
+ * when namespace-keyed storage lands; today's single-namespace shape
256
+ * needs neither field.
257
+ */
258
+ declare class StorageTable extends SqlNode {
259
+ readonly columns: Readonly<Record<string, StorageColumn>>;
260
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
261
+ readonly indexes: ReadonlyArray<Index>;
262
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
263
+ readonly primaryKey?: PrimaryKey;
264
+ constructor(input: StorageTableInput);
265
+ }
266
+ //#endregion
267
+ //#region src/ir/storage-type-instance.d.ts
268
+ /**
269
+ * Sentinel kind for the legacy codec-triple shape persisted under
270
+ * `SqlStorage.types`. Plain JSON-clean object literals carry this
271
+ * discriminator so the polymorphic slot dispatch can route them down
272
+ * the codec path while target-specific IR class instances (e.g. the
273
+ * Postgres enum class) keep their own narrower `kind` literal.
274
+ */
275
+ declare const CODEC_INSTANCE_KIND: "codec-instance";
276
+ /**
277
+ * Structural sub-interface of {@link StorageType} for codec-typed entries
278
+ * in `SqlStorage.types`. These are plain object literals — there is no
279
+ * runtime IR class, the JSON envelope round-trips through the slot
280
+ * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch
281
+ * key that distinguishes codec-typed entries from class-instance entries
282
+ * (e.g. `PostgresEnumType`) sharing the polymorphic slot.
283
+ */
284
+ interface StorageTypeInstance extends StorageType {
285
+ readonly kind: typeof CODEC_INSTANCE_KIND;
286
+ readonly codecId: string;
287
+ readonly nativeType: string;
288
+ readonly typeParams: Record<string, unknown>;
289
+ }
290
+ /**
291
+ * Construction-time input for a codec-triple entry. Symmetric with the
292
+ * structural runtime shape minus the `kind` discriminator — callers may
293
+ * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.
294
+ */
295
+ interface StorageTypeInstanceInput {
296
+ readonly codecId: string;
297
+ readonly nativeType: string;
298
+ readonly typeParams: Record<string, unknown>;
299
+ }
300
+ /**
301
+ * Stamp the codec-instance `kind` discriminator on a caller-supplied
302
+ * codec triple. Idempotent: input that already carries the discriminator
303
+ * passes through unchanged.
304
+ */
305
+ declare function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance;
306
+ /**
307
+ * Type-guard for codec-typed entries on the polymorphic
308
+ * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
309
+ * class-instance kinds (e.g. `PostgresEnumType`).
310
+ */
311
+ declare function isStorageTypeInstance(value: unknown): value is StorageTypeInstance;
312
+ //#endregion
313
+ //#region src/ir/sql-storage.d.ts
314
+ /**
315
+ * Polymorphic value type for `SqlStorage.types` entries (Decision 18,
316
+ * Option B). The slot's framework alphabet is `StorageType` — codec
317
+ * triples (`StorageTypeInstance` with `kind: 'codec-instance'`) and
318
+ * target-specific IR class instances structurally satisfying
319
+ * `PostgresEnumStorageEntry` (with `kind: 'postgres-enum'`) are the
320
+ * two variants the SQL family ships today. The construction side also
321
+ * accepts {@link StorageTypeInstanceInput} so callers can pass raw
322
+ * codec triples; the constructor stamps the discriminator.
323
+ */
324
+ type SqlStorageTypeEntry = StorageTypeInstance | PostgresEnumStorageEntry | StorageTypeInstanceInput;
325
+ interface SqlStorageInput<THash extends string = string> {
326
+ readonly storageHash: StorageHashBase<THash>;
327
+ readonly tables: Record<string, StorageTable | StorageTableInput>;
328
+ readonly types?: Record<string, SqlStorageTypeEntry>;
329
+ readonly namespaces?: Readonly<Record<string, Namespace>>;
330
+ }
331
+ /**
332
+ * SQL Contract IR root node for the `storage` field.
333
+ *
334
+ * Single concrete family-shared class — both Postgres and SQLite
335
+ * consume this same class today. Per-target storage subclasses are
336
+ * introduced when each target's namespace shape earns its
337
+ * target-specific concretion (target-specific derived fields,
338
+ * target-specific storage extensions).
339
+ *
340
+ * Honours the framework `Storage` interface: every SQL IR carries a
341
+ * `namespaces` map keyed by namespace id. The default singleton
342
+ * (`{ [UNSPECIFIED_NAMESPACE_ID]: SqlUnspecifiedNamespace.instance }`)
343
+ * binds every contract authored before per-target namespace concretions
344
+ * land; per-target namespace classes (`PostgresSchema.unspecified`,
345
+ * `SqliteUnspecifiedDatabase.instance`) earn their slots when each
346
+ * target's namespace shape lands.
347
+ *
348
+ * The constructor normalises nested IR-class fields (`tables`, optional
349
+ * `types`) into class instances so downstream walks see a uniform AST.
350
+ * `types` is polymorphic per Decision 18 Option B: codec-triple inputs
351
+ * are stamped with `kind: 'codec-instance'`; class-instance kinds
352
+ * (e.g. Postgres-enum entries satisfying `PostgresEnumStorageEntry`)
353
+ * pass through; hydration of raw JSON class-instance entries (carrying
354
+ * their narrower `kind` literal) is the per-target serializer's
355
+ * responsibility (so the family base does not import target-specific
356
+ * subclasses).
357
+ */
358
+ declare class SqlStorage<THash extends string = string> extends SqlNode implements Storage {
359
+ readonly storageHash: StorageHashBase<THash>;
360
+ readonly tables: Readonly<Record<string, StorageTable>>;
361
+ readonly namespaces: Readonly<Record<string, Namespace>>;
362
+ readonly types?: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>;
363
+ constructor(input: SqlStorageInput<THash>);
364
+ }
365
+ //#endregion
366
+ //#region src/ir/sql-unspecified-namespace.d.ts
367
+ /**
368
+ * Family-layer placeholder for the SQL unspecified-namespace singleton.
369
+ *
370
+ * SQL contracts honour the framework `Storage.namespaces` invariant from
371
+ * the moment they appear in the IR. Today `SqlStorage` is family-shared
372
+ * (Postgres + SQLite consume the same class); a per-target namespace
373
+ * concretion (`PostgresSchema.unspecified`, `SqliteUnspecifiedDatabase.instance`)
374
+ * earns its existence when each target's namespace shape lands. Until
375
+ * then the family ships a single placeholder singleton so the JSON
376
+ * envelope and runtime walk are honest at every layer.
377
+ *
378
+ * The `kind` discriminator is installed as a non-enumerable own property
379
+ * so the JSON envelope reads `{ "id": "__unspecified__" }` — symmetric
380
+ * with the family-level non-enumerable `kind` on `SqlNode` and bounded
381
+ * to the minimum data the framework `Namespace` interface promises.
382
+ *
383
+ * **Freeze-trap warning.** The leaf constructor calls
384
+ * `freezeNode(this)` after installing `kind`. The leaf-class shape
385
+ * works today only because `NamespaceBase` does NOT freeze in its
386
+ * constructor — the `Object.defineProperty(this, 'kind', …)` call after
387
+ * `super()` succeeds because the instance is still mutable at that
388
+ * point. Subclasses that add instance fields will still hit the freeze
389
+ * trap once leaf-class `freezeNode(this)` runs; and if a future
390
+ * framework change lifts the freeze to `NamespaceBase`, even the
391
+ * `defineProperty` here would silently fail. To add subclass instance
392
+ * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
393
+ * leaf calls explicitly at the end of its own constructor.
394
+ */
395
+ declare class SqlUnspecifiedNamespace extends NamespaceBase {
396
+ static readonly instance: SqlUnspecifiedNamespace;
397
+ readonly id: "__unspecified__";
398
+ readonly kind?: string;
399
+ private constructor();
400
+ }
401
+ //#endregion
402
+ //#region src/types.d.ts
403
+ type ForeignKeyOptions = {
404
+ readonly name?: string;
405
+ readonly onDelete?: ReferentialAction;
406
+ readonly onUpdate?: ReferentialAction;
407
+ };
408
+ type SqlModelFieldStorage = {
409
+ readonly column: string;
410
+ readonly codecId?: string;
411
+ readonly nullable?: boolean;
412
+ };
413
+ type SqlModelStorage = {
414
+ readonly table: string;
415
+ readonly fields: Record<string, SqlModelFieldStorage>;
416
+ };
417
+ declare const DEFAULT_FK_CONSTRAINT = true;
418
+ declare const DEFAULT_FK_INDEX = true;
419
+ declare function applyFkDefaults(fk: {
420
+ constraint?: boolean | undefined;
421
+ index?: boolean | undefined;
422
+ }, overrideDefaults?: {
423
+ constraint?: boolean | undefined;
424
+ index?: boolean | undefined;
425
+ }): {
426
+ constraint: boolean;
427
+ index: boolean;
428
+ };
429
+ type TypeMaps<TCodecTypes extends Record<string, {
430
+ output: unknown;
431
+ }> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
432
+ readonly codecTypes: TCodecTypes;
433
+ readonly queryOperationTypes: TQueryOperationTypes;
434
+ readonly fieldOutputTypes: TFieldOutputTypes;
435
+ readonly fieldInputTypes: TFieldInputTypes;
436
+ };
437
+ type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
438
+ readonly codecTypes: infer C;
439
+ } ? C extends Record<string, {
440
+ output: unknown;
441
+ }> ? C : Record<string, never> : Record<string, never>;
442
+ /**
443
+ * Dispatch hint identifying the first-argument target of an operation.
444
+ *
445
+ * Used by ORM column helpers to decide whether an operation is reachable on a
446
+ * field. Either names a concrete codec identity or a set of capability traits
447
+ * that the field's codec must carry.
448
+ */
449
+ type QueryOperationSelfSpec = {
450
+ readonly codecId: string;
451
+ readonly traits?: never;
452
+ } | {
453
+ readonly traits: readonly CodecTrait[];
454
+ readonly codecId?: never;
455
+ };
456
+ /**
457
+ * Structural shape an operation's impl must return: any value carrying a
458
+ * codec-exact `returnType` descriptor. `Expression<T>` (from
459
+ * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
460
+ * extends this. Trait-targeted returns are deliberately excluded — predicate
461
+ * detection and result decoding both depend on knowing the concrete return
462
+ * codec.
463
+ */
464
+ type QueryOperationReturn = {
465
+ readonly returnType: {
466
+ readonly codecId: string;
467
+ readonly nullable: boolean;
468
+ };
469
+ };
470
+ type QueryOperationTypeEntry = {
471
+ readonly self?: QueryOperationSelfSpec;
472
+ readonly impl: (...args: never[]) => QueryOperationReturn;
473
+ };
474
+ type SqlQueryOperationTypes<_CT extends Record<string, {
475
+ readonly input: unknown;
476
+ readonly output: unknown;
477
+ }>, T extends Record<string, QueryOperationTypeEntry>> = T;
478
+ type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
479
+ type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
480
+ readonly queryOperationTypes: infer Q;
481
+ } ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
482
+ type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
483
+ type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
484
+ type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
485
+ type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
486
+ readonly fieldOutputTypes: infer F;
487
+ } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
488
+ type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
489
+ readonly fieldInputTypes: infer F;
490
+ } ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
491
+ type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
492
+ type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
493
+ type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
494
+ type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
495
+ type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
496
+ //#endregion
497
+ export { StorageTypeInstance as A, Index as B, TypeMapsPhantomKey as C, SqlStorageInput as D, SqlStorage as E, StorageTableInput as F, PostgresEnumStorageEntry as G, PrimaryKey as H, UniqueConstraint as I, ForeignKeyInput as J, isPostgresEnumStorageEntry as K, UniqueConstraintInput as L, isStorageTypeInstance as M, toStorageTypeInstance as N, SqlStorageTypeEntry as O, StorageTable as P, SqlNode as Q, StorageColumn as R, TypeMaps as S, SqlUnspecifiedNamespace as T, PrimaryKeyInput as U, IndexInput as V, POSTGRES_ENUM_KIND as W, ForeignKeyReferences as X, ReferentialAction as Y, ForeignKeyReferencesInput as Z, QueryOperationTypesOf as _, ExtractCodecTypes as a, SqlModelStorage as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKeyOptions as f, QueryOperationTypesBase as g, QueryOperationTypeEntry as h, DEFAULT_FK_INDEX as i, StorageTypeInstanceInput as j, CODEC_INSTANCE_KIND as k, ExtractTypeMapsFromContract as l, QueryOperationSelfSpec as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, QueryOperationReturn as p, ForeignKey as q, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, ResolveCodecTypes as v, applyFkDefaults as w, SqlQueryOperationTypes as x, SqlModelFieldStorage as y, StorageColumnInput as z };
498
+ //# sourceMappingURL=types-B0lbr9cb.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-B0lbr9cb.d.mts","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/foreign-key-references.ts","../src/ir/foreign-key.ts","../src/ir/postgres-enum-storage-entry.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/ir/sql-unspecified-namespace.ts","../src/types.ts"],"mappings":";;;;;;;;;AAkCA;;;;;;;;;;;;AC/BA;;;;;AAYA;;;;;;;;;;;uBDmBsB,OAAA,SAAgB,UAAA;EAAA,SAC3B,IAAA;;;;;UChCM,yBAAA;EAAA,SACN,KAAA;EAAA,SACA,OAAA;AAAA;AD6BX;;;;;;;AAAA,cCnBa,oBAAA,SAA6B,OAAA;EAAA,SAC/B,KAAA;EAAA,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