@prisma-next/sql-contract-ts 0.3.0-dev.13 → 0.3.0-dev.131
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/LICENSE +201 -0
- package/README.md +78 -13
- package/dist/config-types.d.mts +8 -0
- package/dist/config-types.d.mts.map +1 -0
- package/dist/config-types.mjs +14 -0
- package/dist/config-types.mjs.map +1 -0
- package/dist/contract-builder.d.mts +97 -0
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +381 -0
- package/dist/contract-builder.mjs.map +1 -0
- package/package.json +21 -19
- package/schemas/data-contract-sql-v1.json +244 -23
- package/src/config-types.ts +11 -0
- package/src/contract-builder.ts +444 -90
- package/src/contract.ts +119 -106
- package/src/exports/config-types.ts +2 -0
- package/dist/chunk-SEOX3AAQ.js +0 -309
- package/dist/chunk-SEOX3AAQ.js.map +0 -1
- package/dist/contract-builder.d.ts +0 -87
- package/dist/contract-builder.d.ts.map +0 -1
- package/dist/contract.d.ts +0 -50
- package/dist/contract.d.ts.map +0 -1
- package/dist/exports/contract-builder.d.ts +0 -3
- package/dist/exports/contract-builder.d.ts.map +0 -1
- package/dist/exports/contract-builder.js +0 -216
- package/dist/exports/contract-builder.js.map +0 -1
- package/dist/exports/contract.d.ts +0 -2
- package/dist/exports/contract.d.ts.map +0 -1
- package/dist/exports/contract.js +0 -9
- package/dist/exports/contract.js.map +0 -1
- package/src/exports/contract.ts +0 -1
|
@@ -24,10 +24,15 @@
|
|
|
24
24
|
"enum": ["sql"],
|
|
25
25
|
"description": "Target family classification"
|
|
26
26
|
},
|
|
27
|
-
"
|
|
27
|
+
"storageHash": {
|
|
28
28
|
"type": "string",
|
|
29
29
|
"pattern": "^sha256:[a-f0-9]{64}$",
|
|
30
|
-
"description": "SHA-256 hash of the
|
|
30
|
+
"description": "SHA-256 hash of the storage section (DB-satisfied expectations)"
|
|
31
|
+
},
|
|
32
|
+
"executionHash": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"pattern": "^sha256:[a-f0-9]{64}$",
|
|
35
|
+
"description": "SHA-256 hash of the execution section (client-side behavior)"
|
|
31
36
|
},
|
|
32
37
|
"profileHash": {
|
|
33
38
|
"type": "string",
|
|
@@ -61,6 +66,13 @@
|
|
|
61
66
|
"$ref": "#/$defs/Source"
|
|
62
67
|
}
|
|
63
68
|
},
|
|
69
|
+
"roots": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"description": "Mapping of root model names to their identifiers",
|
|
72
|
+
"additionalProperties": {
|
|
73
|
+
"type": "string"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
64
76
|
"models": {
|
|
65
77
|
"type": "object",
|
|
66
78
|
"description": "Model definitions mapping application-level models to storage tables",
|
|
@@ -79,12 +91,46 @@
|
|
|
79
91
|
"additionalProperties": {
|
|
80
92
|
"$ref": "#/$defs/StorageTable"
|
|
81
93
|
}
|
|
94
|
+
},
|
|
95
|
+
"types": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"description": "Named type instances for parameterized/custom types (e.g., vectors, enums)",
|
|
98
|
+
"additionalProperties": {
|
|
99
|
+
"$ref": "#/$defs/StorageTypeInstance"
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
},
|
|
84
103
|
"required": ["tables"]
|
|
104
|
+
},
|
|
105
|
+
"execution": {
|
|
106
|
+
"type": "object",
|
|
107
|
+
"description": "Execution-only behavior not satisfied by the database",
|
|
108
|
+
"additionalProperties": false,
|
|
109
|
+
"properties": {
|
|
110
|
+
"mutations": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"additionalProperties": false,
|
|
113
|
+
"properties": {
|
|
114
|
+
"defaults": {
|
|
115
|
+
"type": "array",
|
|
116
|
+
"items": { "$ref": "#/$defs/ExecutionMutationDefault" }
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"required": ["defaults"]
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"required": ["mutations"]
|
|
85
123
|
}
|
|
86
124
|
},
|
|
87
|
-
"required": [
|
|
125
|
+
"required": [
|
|
126
|
+
"schemaVersion",
|
|
127
|
+
"target",
|
|
128
|
+
"targetFamily",
|
|
129
|
+
"storageHash",
|
|
130
|
+
"models",
|
|
131
|
+
"storage",
|
|
132
|
+
"roots"
|
|
133
|
+
],
|
|
88
134
|
"$defs": {
|
|
89
135
|
"StorageTable": {
|
|
90
136
|
"type": "object",
|
|
@@ -126,21 +172,142 @@
|
|
|
126
172
|
},
|
|
127
173
|
"required": ["columns"]
|
|
128
174
|
},
|
|
175
|
+
"ColumnDefault": {
|
|
176
|
+
"description": "Column default value. Can be a literal value or a database function expression.",
|
|
177
|
+
"oneOf": [
|
|
178
|
+
{
|
|
179
|
+
"type": "object",
|
|
180
|
+
"description": "Static literal value",
|
|
181
|
+
"additionalProperties": false,
|
|
182
|
+
"properties": {
|
|
183
|
+
"kind": {
|
|
184
|
+
"type": "string",
|
|
185
|
+
"enum": ["literal"]
|
|
186
|
+
},
|
|
187
|
+
"value": {
|
|
188
|
+
"description": "JSON literal value (or tagged bigint) for the default value",
|
|
189
|
+
"oneOf": [
|
|
190
|
+
{ "type": "string" },
|
|
191
|
+
{ "type": "number" },
|
|
192
|
+
{ "type": "boolean" },
|
|
193
|
+
{ "type": "null" },
|
|
194
|
+
{ "type": "array" },
|
|
195
|
+
{ "type": "object" }
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"required": ["kind", "value"]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"type": "object",
|
|
203
|
+
"description": "Database function expression (e.g., 'autoincrement()', 'now()', 'gen_random_uuid()')",
|
|
204
|
+
"additionalProperties": false,
|
|
205
|
+
"properties": {
|
|
206
|
+
"kind": {
|
|
207
|
+
"type": "string",
|
|
208
|
+
"enum": ["function"]
|
|
209
|
+
},
|
|
210
|
+
"expression": {
|
|
211
|
+
"type": "string",
|
|
212
|
+
"description": "The function expression (e.g., 'autoincrement()', 'now()', 'gen_random_uuid()')"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"required": ["kind", "expression"]
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
"ExecutionMutationDefaultValue": {
|
|
220
|
+
"type": "object",
|
|
221
|
+
"description": "Execution-time default value applied before a write",
|
|
222
|
+
"additionalProperties": false,
|
|
223
|
+
"properties": {
|
|
224
|
+
"kind": {
|
|
225
|
+
"type": "string",
|
|
226
|
+
"enum": ["generator"]
|
|
227
|
+
},
|
|
228
|
+
"id": {
|
|
229
|
+
"type": "string",
|
|
230
|
+
"pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"
|
|
231
|
+
},
|
|
232
|
+
"params": {
|
|
233
|
+
"type": "object",
|
|
234
|
+
"additionalProperties": true
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
"required": ["kind", "id"]
|
|
238
|
+
},
|
|
239
|
+
"ExecutionMutationDefault": {
|
|
240
|
+
"type": "object",
|
|
241
|
+
"additionalProperties": false,
|
|
242
|
+
"properties": {
|
|
243
|
+
"ref": {
|
|
244
|
+
"type": "object",
|
|
245
|
+
"additionalProperties": false,
|
|
246
|
+
"properties": {
|
|
247
|
+
"table": { "type": "string" },
|
|
248
|
+
"column": { "type": "string" }
|
|
249
|
+
},
|
|
250
|
+
"required": ["table", "column"]
|
|
251
|
+
},
|
|
252
|
+
"onCreate": { "$ref": "#/$defs/ExecutionMutationDefaultValue" },
|
|
253
|
+
"onUpdate": { "$ref": "#/$defs/ExecutionMutationDefaultValue" }
|
|
254
|
+
},
|
|
255
|
+
"required": ["ref"]
|
|
256
|
+
},
|
|
129
257
|
"StorageColumn": {
|
|
130
258
|
"type": "object",
|
|
131
|
-
"description": "Column definition with type and
|
|
259
|
+
"description": "Column definition with type, nullability, and optional parameterized type info",
|
|
132
260
|
"additionalProperties": false,
|
|
133
261
|
"properties": {
|
|
134
|
-
"
|
|
262
|
+
"nativeType": {
|
|
135
263
|
"type": "string",
|
|
136
|
-
"description": "
|
|
264
|
+
"description": "Database-native type (e.g., 'text', 'int4', 'timestamptz', 'vector(1536)')"
|
|
265
|
+
},
|
|
266
|
+
"codecId": {
|
|
267
|
+
"type": "string",
|
|
268
|
+
"description": "Codec identifier for encoding/decoding (e.g., 'pg/text@1', 'pg/vector@1')"
|
|
137
269
|
},
|
|
138
270
|
"nullable": {
|
|
139
271
|
"type": "boolean",
|
|
140
272
|
"default": false,
|
|
141
273
|
"description": "Whether the column allows NULL values"
|
|
274
|
+
},
|
|
275
|
+
"typeParams": {
|
|
276
|
+
"type": "object",
|
|
277
|
+
"description": "Opaque, codec-owned JS/type parameters (e.g., { length: 1536 } for vectors)",
|
|
278
|
+
"additionalProperties": true
|
|
279
|
+
},
|
|
280
|
+
"typeRef": {
|
|
281
|
+
"type": "string",
|
|
282
|
+
"description": "Reference to a named type instance in storage.types"
|
|
283
|
+
},
|
|
284
|
+
"default": {
|
|
285
|
+
"$ref": "#/$defs/ColumnDefault",
|
|
286
|
+
"description": "Default value for the column"
|
|
142
287
|
}
|
|
143
|
-
}
|
|
288
|
+
},
|
|
289
|
+
"required": ["nativeType", "codecId", "nullable"]
|
|
290
|
+
},
|
|
291
|
+
"StorageTypeInstance": {
|
|
292
|
+
"type": "object",
|
|
293
|
+
"description": "Named, parameterized type instance for reuse across columns",
|
|
294
|
+
"additionalProperties": false,
|
|
295
|
+
"properties": {
|
|
296
|
+
"codecId": {
|
|
297
|
+
"type": "string",
|
|
298
|
+
"description": "Codec identifier for encoding/decoding"
|
|
299
|
+
},
|
|
300
|
+
"nativeType": {
|
|
301
|
+
"type": "string",
|
|
302
|
+
"description": "Database-native type"
|
|
303
|
+
},
|
|
304
|
+
"typeParams": {
|
|
305
|
+
"type": "object",
|
|
306
|
+
"description": "Codec-owned type parameters",
|
|
307
|
+
"additionalProperties": true
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
"required": ["codecId", "nativeType", "typeParams"]
|
|
144
311
|
},
|
|
145
312
|
"PrimaryKey": {
|
|
146
313
|
"type": "object",
|
|
@@ -234,9 +401,17 @@
|
|
|
234
401
|
"name": {
|
|
235
402
|
"type": "string",
|
|
236
403
|
"description": "Foreign key constraint name"
|
|
404
|
+
},
|
|
405
|
+
"constraint": {
|
|
406
|
+
"type": "boolean",
|
|
407
|
+
"description": "Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY)"
|
|
408
|
+
},
|
|
409
|
+
"index": {
|
|
410
|
+
"type": "boolean",
|
|
411
|
+
"description": "Whether to emit a backing index for the FK columns"
|
|
237
412
|
}
|
|
238
413
|
},
|
|
239
|
-
"required": ["columns", "references"]
|
|
414
|
+
"required": ["columns", "references", "constraint", "index"]
|
|
240
415
|
},
|
|
241
416
|
"FieldType": {
|
|
242
417
|
"type": "object",
|
|
@@ -310,6 +485,13 @@
|
|
|
310
485
|
"table": {
|
|
311
486
|
"type": "string",
|
|
312
487
|
"description": "Table name in storage.tables"
|
|
488
|
+
},
|
|
489
|
+
"fields": {
|
|
490
|
+
"type": "object",
|
|
491
|
+
"description": "Per-field storage mappings",
|
|
492
|
+
"additionalProperties": {
|
|
493
|
+
"$ref": "#/$defs/ModelStorageField"
|
|
494
|
+
}
|
|
313
495
|
}
|
|
314
496
|
},
|
|
315
497
|
"required": ["table"]
|
|
@@ -327,26 +509,56 @@
|
|
|
327
509
|
"additionalProperties": {
|
|
328
510
|
"$ref": "#/$defs/ModelRelation"
|
|
329
511
|
}
|
|
512
|
+
},
|
|
513
|
+
"owner": {
|
|
514
|
+
"type": "string",
|
|
515
|
+
"description": "Owner model name — declares this model belongs to another model's aggregate (per ADR 177)"
|
|
330
516
|
}
|
|
331
517
|
},
|
|
332
518
|
"required": ["storage", "fields"]
|
|
333
519
|
},
|
|
334
520
|
"ModelField": {
|
|
335
521
|
"type": "object",
|
|
336
|
-
"description": "
|
|
522
|
+
"description": "Domain field definition. New format has codecId + nullable (column lives in model.storage.fields). Old format has column only.",
|
|
523
|
+
"additionalProperties": false,
|
|
524
|
+
"properties": {
|
|
525
|
+
"column": {
|
|
526
|
+
"type": "string",
|
|
527
|
+
"description": "Column name in the model's backing table (old format; new format uses model.storage.fields)"
|
|
528
|
+
},
|
|
529
|
+
"codecId": {
|
|
530
|
+
"type": "string",
|
|
531
|
+
"description": "Codec identifier for the field"
|
|
532
|
+
},
|
|
533
|
+
"nullable": {
|
|
534
|
+
"type": "boolean",
|
|
535
|
+
"description": "Whether the field allows NULL values"
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
"ModelStorageField": {
|
|
540
|
+
"type": "object",
|
|
541
|
+
"description": "Per-field storage mapping",
|
|
337
542
|
"additionalProperties": false,
|
|
338
543
|
"properties": {
|
|
339
544
|
"column": {
|
|
340
545
|
"type": "string",
|
|
341
546
|
"description": "Column name in the model's backing table"
|
|
547
|
+
},
|
|
548
|
+
"codecId": {
|
|
549
|
+
"type": "string",
|
|
550
|
+
"description": "Codec identifier for the field (derived from storage column)"
|
|
551
|
+
},
|
|
552
|
+
"nullable": {
|
|
553
|
+
"type": "boolean",
|
|
554
|
+
"description": "Whether the field allows NULL values (derived from storage column)"
|
|
342
555
|
}
|
|
343
556
|
},
|
|
344
557
|
"required": ["column"]
|
|
345
558
|
},
|
|
346
559
|
"ModelRelation": {
|
|
347
560
|
"type": "object",
|
|
348
|
-
"description": "Model relation definition",
|
|
349
|
-
"additionalProperties": false,
|
|
561
|
+
"description": "Model relation definition (domain format with localFields/targetFields, or storage format with parentCols/childCols)",
|
|
350
562
|
"properties": {
|
|
351
563
|
"to": {
|
|
352
564
|
"type": "string",
|
|
@@ -357,30 +569,39 @@
|
|
|
357
569
|
"enum": ["1:1", "1:N", "N:1", "N:M"],
|
|
358
570
|
"description": "Relation cardinality"
|
|
359
571
|
},
|
|
572
|
+
"strategy": {
|
|
573
|
+
"type": "string",
|
|
574
|
+
"enum": ["reference", "embed"],
|
|
575
|
+
"description": "Relation strategy"
|
|
576
|
+
},
|
|
360
577
|
"on": {
|
|
361
578
|
"type": "object",
|
|
362
579
|
"description": "Relation field mappings",
|
|
363
|
-
"additionalProperties": false,
|
|
364
580
|
"properties": {
|
|
365
581
|
"parentCols": {
|
|
366
582
|
"type": "array",
|
|
367
|
-
"description": "Parent table columns",
|
|
368
|
-
"items": {
|
|
369
|
-
"type": "string"
|
|
370
|
-
}
|
|
583
|
+
"description": "Parent table columns (storage format)",
|
|
584
|
+
"items": { "type": "string" }
|
|
371
585
|
},
|
|
372
586
|
"childCols": {
|
|
373
587
|
"type": "array",
|
|
374
|
-
"description": "Child table columns",
|
|
375
|
-
"items": {
|
|
376
|
-
|
|
377
|
-
|
|
588
|
+
"description": "Child table columns (storage format)",
|
|
589
|
+
"items": { "type": "string" }
|
|
590
|
+
},
|
|
591
|
+
"localFields": {
|
|
592
|
+
"type": "array",
|
|
593
|
+
"description": "Local model fields (domain format)",
|
|
594
|
+
"items": { "type": "string" }
|
|
595
|
+
},
|
|
596
|
+
"targetFields": {
|
|
597
|
+
"type": "array",
|
|
598
|
+
"description": "Target model fields (domain format)",
|
|
599
|
+
"items": { "type": "string" }
|
|
378
600
|
}
|
|
379
|
-
}
|
|
380
|
-
"required": ["parentCols", "childCols"]
|
|
601
|
+
}
|
|
381
602
|
}
|
|
382
603
|
},
|
|
383
|
-
"required": ["to", "cardinality"
|
|
604
|
+
"required": ["to", "cardinality"]
|
|
384
605
|
}
|
|
385
606
|
}
|
|
386
607
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContractConfig } from '@prisma-next/config/config-types';
|
|
2
|
+
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
3
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
4
|
+
import { ok } from '@prisma-next/utils/result';
|
|
5
|
+
|
|
6
|
+
export function typescriptContract(contractIR: ContractIR, output?: string): ContractConfig {
|
|
7
|
+
return {
|
|
8
|
+
source: async (_context) => ok(contractIR),
|
|
9
|
+
...ifDefined('output', output),
|
|
10
|
+
};
|
|
11
|
+
}
|