@prisma-next/sql-contract-ts 0.3.0-dev.9 → 0.3.0-dev.90

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.
@@ -24,10 +24,15 @@
24
24
  "enum": ["sql"],
25
25
  "description": "Target family classification"
26
26
  },
27
- "coreHash": {
27
+ "storageHash": {
28
28
  "type": "string",
29
29
  "pattern": "^sha256:[a-f0-9]{64}$",
30
- "description": "SHA-256 hash of the core schema structure (models, fields, relations, storage layout)"
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",
@@ -79,12 +84,38 @@
79
84
  "additionalProperties": {
80
85
  "$ref": "#/$defs/StorageTable"
81
86
  }
87
+ },
88
+ "types": {
89
+ "type": "object",
90
+ "description": "Named type instances for parameterized/custom types (e.g., vectors, enums)",
91
+ "additionalProperties": {
92
+ "$ref": "#/$defs/StorageTypeInstance"
93
+ }
82
94
  }
83
95
  },
84
96
  "required": ["tables"]
97
+ },
98
+ "execution": {
99
+ "type": "object",
100
+ "description": "Execution-only behavior not satisfied by the database",
101
+ "additionalProperties": false,
102
+ "properties": {
103
+ "mutations": {
104
+ "type": "object",
105
+ "additionalProperties": false,
106
+ "properties": {
107
+ "defaults": {
108
+ "type": "array",
109
+ "items": { "$ref": "#/$defs/ExecutionMutationDefault" }
110
+ }
111
+ },
112
+ "required": ["defaults"]
113
+ }
114
+ },
115
+ "required": ["mutations"]
85
116
  }
86
117
  },
87
- "required": ["schemaVersion", "target", "targetFamily", "coreHash", "models", "storage"],
118
+ "required": ["schemaVersion", "target", "targetFamily", "storageHash", "models", "storage"],
88
119
  "$defs": {
89
120
  "StorageTable": {
90
121
  "type": "object",
@@ -126,21 +157,142 @@
126
157
  },
127
158
  "required": ["columns"]
128
159
  },
160
+ "ColumnDefault": {
161
+ "description": "Column default value. Can be a literal value or a database function expression.",
162
+ "oneOf": [
163
+ {
164
+ "type": "object",
165
+ "description": "Static literal value",
166
+ "additionalProperties": false,
167
+ "properties": {
168
+ "kind": {
169
+ "type": "string",
170
+ "enum": ["literal"]
171
+ },
172
+ "value": {
173
+ "description": "JSON literal value (or tagged bigint) for the default value",
174
+ "oneOf": [
175
+ { "type": "string" },
176
+ { "type": "number" },
177
+ { "type": "boolean" },
178
+ { "type": "null" },
179
+ { "type": "array" },
180
+ { "type": "object" }
181
+ ]
182
+ }
183
+ },
184
+ "required": ["kind", "value"]
185
+ },
186
+ {
187
+ "type": "object",
188
+ "description": "Database function expression (e.g., 'autoincrement()', 'now()', 'gen_random_uuid()')",
189
+ "additionalProperties": false,
190
+ "properties": {
191
+ "kind": {
192
+ "type": "string",
193
+ "enum": ["function"]
194
+ },
195
+ "expression": {
196
+ "type": "string",
197
+ "description": "The function expression (e.g., 'autoincrement()', 'now()', 'gen_random_uuid()')"
198
+ }
199
+ },
200
+ "required": ["kind", "expression"]
201
+ }
202
+ ]
203
+ },
204
+ "ExecutionMutationDefaultValue": {
205
+ "type": "object",
206
+ "description": "Execution-time default value applied before a write",
207
+ "additionalProperties": false,
208
+ "properties": {
209
+ "kind": {
210
+ "type": "string",
211
+ "enum": ["generator"]
212
+ },
213
+ "id": {
214
+ "type": "string",
215
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"
216
+ },
217
+ "params": {
218
+ "type": "object",
219
+ "additionalProperties": true
220
+ }
221
+ },
222
+ "required": ["kind", "id"]
223
+ },
224
+ "ExecutionMutationDefault": {
225
+ "type": "object",
226
+ "additionalProperties": false,
227
+ "properties": {
228
+ "ref": {
229
+ "type": "object",
230
+ "additionalProperties": false,
231
+ "properties": {
232
+ "table": { "type": "string" },
233
+ "column": { "type": "string" }
234
+ },
235
+ "required": ["table", "column"]
236
+ },
237
+ "onCreate": { "$ref": "#/$defs/ExecutionMutationDefaultValue" },
238
+ "onUpdate": { "$ref": "#/$defs/ExecutionMutationDefaultValue" }
239
+ },
240
+ "required": ["ref"]
241
+ },
129
242
  "StorageColumn": {
130
243
  "type": "object",
131
- "description": "Column definition with type and nullability",
244
+ "description": "Column definition with type, nullability, and optional parameterized type info",
132
245
  "additionalProperties": false,
133
246
  "properties": {
134
- "type": {
247
+ "nativeType": {
135
248
  "type": "string",
136
- "description": "Column type (e.g., 'text', 'int4', 'timestamptz', 'bool')"
249
+ "description": "Database-native type (e.g., 'text', 'int4', 'timestamptz', 'vector(1536)')"
250
+ },
251
+ "codecId": {
252
+ "type": "string",
253
+ "description": "Codec identifier for encoding/decoding (e.g., 'pg/text@1', 'pg/vector@1')"
137
254
  },
138
255
  "nullable": {
139
256
  "type": "boolean",
140
257
  "default": false,
141
258
  "description": "Whether the column allows NULL values"
259
+ },
260
+ "typeParams": {
261
+ "type": "object",
262
+ "description": "Opaque, codec-owned JS/type parameters (e.g., { length: 1536 } for vectors)",
263
+ "additionalProperties": true
264
+ },
265
+ "typeRef": {
266
+ "type": "string",
267
+ "description": "Reference to a named type instance in storage.types"
268
+ },
269
+ "default": {
270
+ "$ref": "#/$defs/ColumnDefault",
271
+ "description": "Default value for the column"
142
272
  }
143
- }
273
+ },
274
+ "required": ["nativeType", "codecId", "nullable"]
275
+ },
276
+ "StorageTypeInstance": {
277
+ "type": "object",
278
+ "description": "Named, parameterized type instance for reuse across columns",
279
+ "additionalProperties": false,
280
+ "properties": {
281
+ "codecId": {
282
+ "type": "string",
283
+ "description": "Codec identifier for encoding/decoding"
284
+ },
285
+ "nativeType": {
286
+ "type": "string",
287
+ "description": "Database-native type"
288
+ },
289
+ "typeParams": {
290
+ "type": "object",
291
+ "description": "Codec-owned type parameters",
292
+ "additionalProperties": true
293
+ }
294
+ },
295
+ "required": ["codecId", "nativeType", "typeParams"]
144
296
  },
145
297
  "PrimaryKey": {
146
298
  "type": "object",
@@ -234,9 +386,17 @@
234
386
  "name": {
235
387
  "type": "string",
236
388
  "description": "Foreign key constraint name"
389
+ },
390
+ "constraint": {
391
+ "type": "boolean",
392
+ "description": "Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY)"
393
+ },
394
+ "index": {
395
+ "type": "boolean",
396
+ "description": "Whether to emit a backing index for the FK columns"
237
397
  }
238
398
  },
239
- "required": ["columns", "references"]
399
+ "required": ["columns", "references", "constraint", "index"]
240
400
  },
241
401
  "FieldType": {
242
402
  "type": "object",
@@ -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
+ }