@prisma-next/adapter-postgres 0.16.0-dev.10 → 0.16.0-dev.12
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/control.mjs +265 -30
- package/dist/control.mjs.map +1 -1
- package/package.json +23 -23
- package/src/core/control-mutation-defaults.ts +140 -34
- package/src/exports/control.ts +2 -2
package/dist/control.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { parsePostgresDefault } from "@prisma-next/target-postgres/default-norma
|
|
|
4
4
|
import { normalizeSchemaNativeType } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
5
5
|
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
6
6
|
import { timestampNowControlDescriptor } from "@prisma-next/family-sql/control";
|
|
7
|
-
import { builtinGeneratorRegistryMetadata
|
|
7
|
+
import { builtinGeneratorRegistryMetadata } from "@prisma-next/ids";
|
|
8
8
|
import { int, num, oneOf, optional, str } from "@prisma-next/psl-parser";
|
|
9
9
|
//#region src/core/control-mutation-defaults.ts
|
|
10
10
|
function invalidArgumentDiagnostic(input) {
|
|
@@ -149,47 +149,282 @@ const postgresDefaultFunctionRegistryEntries = [
|
|
|
149
149
|
usageSignatures: ["dbgenerated(\"...\")"]
|
|
150
150
|
}]
|
|
151
151
|
];
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The base PSL scalars as zero-arg type constructors in the unified authoring
|
|
154
|
+
* channel, with explicit `nativeType` values pinned to the codec manifests
|
|
155
|
+
* (`codecLookup.targetTypesFor(codecId)[0]`).
|
|
156
|
+
*
|
|
157
|
+
* The type position is the only storage decider: a mutation-default generator
|
|
158
|
+
* (`@default(uuid())`) never re-picks a column's storage.
|
|
159
|
+
*/
|
|
160
|
+
const postgresScalarAuthoringTypes = {
|
|
161
|
+
String: {
|
|
162
|
+
kind: "typeConstructor",
|
|
163
|
+
output: {
|
|
164
|
+
codecId: "pg/text@1",
|
|
165
|
+
nativeType: "text"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
Boolean: {
|
|
169
|
+
kind: "typeConstructor",
|
|
170
|
+
output: {
|
|
171
|
+
codecId: "pg/bool@1",
|
|
172
|
+
nativeType: "bool"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
Int: {
|
|
176
|
+
kind: "typeConstructor",
|
|
177
|
+
output: {
|
|
178
|
+
codecId: "pg/int4@1",
|
|
179
|
+
nativeType: "int4"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
BigInt: {
|
|
183
|
+
kind: "typeConstructor",
|
|
184
|
+
output: {
|
|
185
|
+
codecId: "pg/int8@1",
|
|
186
|
+
nativeType: "int8"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
Float: {
|
|
190
|
+
kind: "typeConstructor",
|
|
191
|
+
output: {
|
|
192
|
+
codecId: "pg/float8@1",
|
|
193
|
+
nativeType: "float8"
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
Decimal: {
|
|
197
|
+
kind: "typeConstructor",
|
|
198
|
+
output: {
|
|
199
|
+
codecId: "pg/numeric@1",
|
|
200
|
+
nativeType: "numeric"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
DateTime: {
|
|
204
|
+
kind: "typeConstructor",
|
|
205
|
+
output: {
|
|
206
|
+
codecId: "pg/timestamptz@1",
|
|
207
|
+
nativeType: "timestamptz"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
Json: {
|
|
211
|
+
kind: "typeConstructor",
|
|
212
|
+
output: {
|
|
213
|
+
codecId: "pg/json@1",
|
|
214
|
+
nativeType: "json"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
Jsonb: {
|
|
218
|
+
kind: "typeConstructor",
|
|
219
|
+
output: {
|
|
220
|
+
codecId: "pg/jsonb@1",
|
|
221
|
+
nativeType: "jsonb"
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
Bytes: {
|
|
225
|
+
kind: "typeConstructor",
|
|
226
|
+
output: {
|
|
227
|
+
codecId: "pg/bytea@1",
|
|
228
|
+
nativeType: "bytea"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* The former `@db.*` native types as first-class top-level type constructors
|
|
234
|
+
* (TML-2986). Codec ids, native types, and typeParams key shapes mirror the
|
|
235
|
+
* legacy `@db.*` attribute path (`NATIVE_TYPE_SPECS` in sql-contract-psl)
|
|
236
|
+
* exactly; every argument is optional, so each name is also authorable bare
|
|
237
|
+
* (`VarChar` ≡ `VarChar()`), and omitted arguments omit their typeParams keys.
|
|
238
|
+
*/
|
|
239
|
+
const postgresNativeAuthoringTypes = {
|
|
240
|
+
VarChar: {
|
|
241
|
+
kind: "typeConstructor",
|
|
242
|
+
args: [{
|
|
243
|
+
kind: "number",
|
|
244
|
+
name: "length",
|
|
245
|
+
integer: true,
|
|
246
|
+
minimum: 1,
|
|
247
|
+
optional: true
|
|
248
|
+
}],
|
|
249
|
+
output: {
|
|
250
|
+
codecId: "sql/varchar@1",
|
|
251
|
+
nativeType: "character varying",
|
|
252
|
+
typeParams: { length: {
|
|
253
|
+
kind: "arg",
|
|
254
|
+
index: 0
|
|
255
|
+
} }
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
Char: {
|
|
259
|
+
kind: "typeConstructor",
|
|
260
|
+
args: [{
|
|
261
|
+
kind: "number",
|
|
262
|
+
name: "length",
|
|
263
|
+
integer: true,
|
|
264
|
+
minimum: 1,
|
|
265
|
+
optional: true
|
|
266
|
+
}],
|
|
267
|
+
output: {
|
|
268
|
+
codecId: "sql/char@1",
|
|
269
|
+
nativeType: "character",
|
|
270
|
+
typeParams: { length: {
|
|
271
|
+
kind: "arg",
|
|
272
|
+
index: 0
|
|
273
|
+
} }
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
Numeric: {
|
|
277
|
+
kind: "typeConstructor",
|
|
278
|
+
args: [{
|
|
279
|
+
kind: "number",
|
|
280
|
+
name: "precision",
|
|
281
|
+
integer: true,
|
|
282
|
+
minimum: 1,
|
|
283
|
+
optional: true
|
|
284
|
+
}, {
|
|
285
|
+
kind: "number",
|
|
286
|
+
name: "scale",
|
|
287
|
+
integer: true,
|
|
288
|
+
minimum: 0,
|
|
289
|
+
optional: true
|
|
290
|
+
}],
|
|
291
|
+
output: {
|
|
292
|
+
codecId: "pg/numeric@1",
|
|
293
|
+
nativeType: "numeric",
|
|
294
|
+
typeParams: {
|
|
295
|
+
precision: {
|
|
296
|
+
kind: "arg",
|
|
297
|
+
index: 0
|
|
298
|
+
},
|
|
299
|
+
scale: {
|
|
300
|
+
kind: "arg",
|
|
301
|
+
index: 1
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
Timestamp: {
|
|
307
|
+
kind: "typeConstructor",
|
|
308
|
+
args: [{
|
|
309
|
+
kind: "number",
|
|
310
|
+
name: "precision",
|
|
311
|
+
integer: true,
|
|
312
|
+
minimum: 0,
|
|
313
|
+
optional: true
|
|
314
|
+
}],
|
|
315
|
+
output: {
|
|
316
|
+
codecId: "pg/timestamp@1",
|
|
317
|
+
nativeType: "timestamp",
|
|
318
|
+
typeParams: { precision: {
|
|
319
|
+
kind: "arg",
|
|
320
|
+
index: 0
|
|
321
|
+
} }
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
Timestamptz: {
|
|
325
|
+
kind: "typeConstructor",
|
|
326
|
+
args: [{
|
|
327
|
+
kind: "number",
|
|
328
|
+
name: "precision",
|
|
329
|
+
integer: true,
|
|
330
|
+
minimum: 0,
|
|
331
|
+
optional: true
|
|
332
|
+
}],
|
|
333
|
+
output: {
|
|
334
|
+
codecId: "pg/timestamptz@1",
|
|
335
|
+
nativeType: "timestamptz",
|
|
336
|
+
typeParams: { precision: {
|
|
337
|
+
kind: "arg",
|
|
338
|
+
index: 0
|
|
339
|
+
} }
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
Time: {
|
|
343
|
+
kind: "typeConstructor",
|
|
344
|
+
args: [{
|
|
345
|
+
kind: "number",
|
|
346
|
+
name: "precision",
|
|
347
|
+
integer: true,
|
|
348
|
+
minimum: 0,
|
|
349
|
+
optional: true
|
|
350
|
+
}],
|
|
351
|
+
output: {
|
|
352
|
+
codecId: "pg/time@1",
|
|
353
|
+
nativeType: "time",
|
|
354
|
+
typeParams: { precision: {
|
|
355
|
+
kind: "arg",
|
|
356
|
+
index: 0
|
|
357
|
+
} }
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
Timetz: {
|
|
361
|
+
kind: "typeConstructor",
|
|
362
|
+
args: [{
|
|
363
|
+
kind: "number",
|
|
364
|
+
name: "precision",
|
|
365
|
+
integer: true,
|
|
366
|
+
minimum: 0,
|
|
367
|
+
optional: true
|
|
368
|
+
}],
|
|
369
|
+
output: {
|
|
370
|
+
codecId: "pg/timetz@1",
|
|
371
|
+
nativeType: "timetz",
|
|
372
|
+
typeParams: { precision: {
|
|
373
|
+
kind: "arg",
|
|
374
|
+
index: 0
|
|
375
|
+
} }
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
Uuid: {
|
|
379
|
+
kind: "typeConstructor",
|
|
380
|
+
output: {
|
|
381
|
+
codecId: "pg/uuid@1",
|
|
382
|
+
nativeType: "uuid"
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
SmallInt: {
|
|
386
|
+
kind: "typeConstructor",
|
|
387
|
+
output: {
|
|
388
|
+
codecId: "pg/int2@1",
|
|
389
|
+
nativeType: "int2"
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
Real: {
|
|
393
|
+
kind: "typeConstructor",
|
|
394
|
+
output: {
|
|
395
|
+
codecId: "pg/float4@1",
|
|
396
|
+
nativeType: "float4"
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
Date: {
|
|
400
|
+
kind: "typeConstructor",
|
|
401
|
+
output: {
|
|
402
|
+
codecId: "pg/timestamptz@1",
|
|
403
|
+
nativeType: "date"
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
const postgresAuthoringTypes = {
|
|
408
|
+
...postgresScalarAuthoringTypes,
|
|
409
|
+
...postgresNativeAuthoringTypes
|
|
410
|
+
};
|
|
163
411
|
function createPostgresDefaultFunctionRegistry() {
|
|
164
412
|
return new Map(postgresDefaultFunctionRegistryEntries);
|
|
165
413
|
}
|
|
166
414
|
function createPostgresMutationDefaultGeneratorDescriptors() {
|
|
167
415
|
return [...builtinGeneratorRegistryMetadata.map(({ id, applicableCodecIds }) => ({
|
|
168
416
|
id,
|
|
169
|
-
applicableCodecIds
|
|
170
|
-
resolveGeneratedColumnDescriptor: ({ generated }) => {
|
|
171
|
-
if (generated.kind !== "generator" || generated.id !== id) return;
|
|
172
|
-
const descriptor = resolveBuiltinGeneratedColumnDescriptor({
|
|
173
|
-
id,
|
|
174
|
-
...generated.params ? { params: generated.params } : {}
|
|
175
|
-
});
|
|
176
|
-
return {
|
|
177
|
-
codecId: descriptor.type.codecId,
|
|
178
|
-
nativeType: descriptor.type.nativeType,
|
|
179
|
-
...descriptor.type.typeRef ? { typeRef: descriptor.type.typeRef } : {},
|
|
180
|
-
...descriptor.typeParams ? { typeParams: descriptor.typeParams } : {}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
417
|
+
applicableCodecIds
|
|
183
418
|
})), timestampNowControlDescriptor()];
|
|
184
419
|
}
|
|
185
|
-
function createPostgresScalarTypeDescriptors() {
|
|
186
|
-
return new Map(postgresScalarTypeDescriptors);
|
|
187
|
-
}
|
|
188
420
|
//#endregion
|
|
189
421
|
//#region src/exports/control.ts
|
|
190
422
|
const postgresAdapterDescriptor = {
|
|
191
423
|
...postgresAdapterDescriptorMeta,
|
|
192
|
-
|
|
424
|
+
authoring: {
|
|
425
|
+
type: postgresAuthoringTypes,
|
|
426
|
+
valueObjectStorageType: "Jsonb"
|
|
427
|
+
},
|
|
193
428
|
controlMutationDefaults: {
|
|
194
429
|
defaultFunctionRegistry: createPostgresDefaultFunctionRegistry(),
|
|
195
430
|
generatorDescriptors: createPostgresMutationDefaultGeneratorDescriptors()
|
package/dist/control.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.mjs","names":[],"sources":["../src/core/control-mutation-defaults.ts","../src/exports/control.ts"],"sourcesContent":["import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types';\nimport { timestampNowControlDescriptor } from '@prisma-next/family-sql/control';\nimport type {\n ControlMutationDefaultEntry,\n DefaultFunctionLoweringContext,\n LoweredDefaultResult,\n MutationDefaultGeneratorDescriptor,\n TypedDefaultFunctionCall,\n} from '@prisma-next/framework-components/control';\nimport {\n builtinGeneratorRegistryMetadata,\n resolveBuiltinGeneratedColumnDescriptor,\n} from '@prisma-next/ids';\nimport type { FuncCallSig } from '@prisma-next/psl-parser';\nimport { int, num, oneOf, optional, str } from '@prisma-next/psl-parser';\n\nfunction invalidArgumentDiagnostic(input: {\n readonly context: DefaultFunctionLoweringContext;\n readonly span: TypedDefaultFunctionCall['span'];\n readonly message: string;\n}): LoweredDefaultResult {\n return {\n ok: false,\n diagnostic: {\n code: 'PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT',\n message: input.message,\n sourceId: input.context.sourceId,\n span: input.span,\n },\n };\n}\n\nfunction executionGenerator(\n id: ExecutionMutationDefaultValue['id'],\n params?: Record<string, unknown>,\n): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'execution',\n generated: {\n kind: 'generator',\n id,\n ...(params ? { params } : {}),\n },\n },\n };\n}\n\nfunction lowerAutoincrement(): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression: 'autoincrement()' },\n },\n };\n}\n\nfunction lowerNow(): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression: 'now()' },\n },\n };\n}\n\nfunction lowerUlid(): LoweredDefaultResult {\n return executionGenerator('ulid');\n}\n\nfunction lowerUuid(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n return input.call.args['version'] === 7\n ? executionGenerator('uuidv7')\n : executionGenerator('uuidv4');\n}\n\nfunction lowerCuid(): LoweredDefaultResult {\n return executionGenerator('cuid2');\n}\n\nfunction lowerNanoid(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const size = input.call.args['size'];\n return typeof size === 'number'\n ? executionGenerator('nanoid', { size })\n : executionGenerator('nanoid');\n}\n\nfunction lowerDbgenerated(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const expression = input.call.args['expression'];\n if (typeof expression !== 'string' || expression.trim().length === 0) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message: 'Default function \"dbgenerated\" argument cannot be empty.',\n });\n }\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression },\n },\n };\n}\n\nconst nowSig: FuncCallSig = {};\nconst autoincrementSig: FuncCallSig = {};\nconst ulidSig: FuncCallSig = {};\nconst uuidSig: FuncCallSig = {\n positional: [{ key: 'version', type: optional(oneOf(num(4), num(7))) }],\n};\nconst cuidSig: FuncCallSig = { positional: [{ key: 'version', type: num(2) }] };\nconst nanoidSig: FuncCallSig = {\n positional: [{ key: 'size', type: optional(int({ min: 2, max: 255 })) }],\n};\nconst dbgeneratedSig: FuncCallSig = { positional: [{ key: 'expression', type: str() }] };\n\nconst postgresDefaultFunctionRegistryEntries = [\n [\n 'autoincrement',\n {\n signature: autoincrementSig,\n lower: lowerAutoincrement,\n usageSignatures: ['autoincrement()'],\n },\n ],\n ['now', { signature: nowSig, lower: lowerNow, usageSignatures: ['now()'] }],\n [\n 'uuid',\n { signature: uuidSig, lower: lowerUuid, usageSignatures: ['uuid()', 'uuid(4)', 'uuid(7)'] },\n ],\n ['cuid', { signature: cuidSig, lower: lowerCuid, usageSignatures: ['cuid(2)'] }],\n ['ulid', { signature: ulidSig, lower: lowerUlid, usageSignatures: ['ulid()'] }],\n [\n 'nanoid',\n { signature: nanoidSig, lower: lowerNanoid, usageSignatures: ['nanoid()', 'nanoid(<2-255>)'] },\n ],\n [\n 'dbgenerated',\n { signature: dbgeneratedSig, lower: lowerDbgenerated, usageSignatures: ['dbgenerated(\"...\")'] },\n ],\n] satisfies ReadonlyArray<readonly [string, ControlMutationDefaultEntry]>;\n\nconst postgresScalarTypeDescriptors = new Map<string, string>([\n ['String', 'pg/text@1'],\n ['Boolean', 'pg/bool@1'],\n ['Int', 'pg/int4@1'],\n ['BigInt', 'pg/int8@1'],\n ['Float', 'pg/float8@1'],\n ['Decimal', 'pg/numeric@1'],\n ['DateTime', 'pg/timestamptz@1'],\n ['Json', 'pg/jsonb@1'],\n ['Bytes', 'pg/bytea@1'],\n]);\n\nexport function createPostgresDefaultFunctionRegistry(): ReadonlyMap<\n string,\n ControlMutationDefaultEntry\n> {\n return new Map(postgresDefaultFunctionRegistryEntries);\n}\n\nexport function createPostgresMutationDefaultGeneratorDescriptors(): readonly MutationDefaultGeneratorDescriptor[] {\n return [\n ...builtinGeneratorRegistryMetadata.map(\n ({ id, applicableCodecIds }): MutationDefaultGeneratorDescriptor => ({\n id,\n applicableCodecIds,\n resolveGeneratedColumnDescriptor: ({ generated }) => {\n if (generated.kind !== 'generator' || generated.id !== id) {\n return undefined;\n }\n const descriptor = resolveBuiltinGeneratedColumnDescriptor({\n id,\n ...(generated.params ? { params: generated.params } : {}),\n });\n return {\n codecId: descriptor.type.codecId,\n nativeType: descriptor.type.nativeType,\n ...(descriptor.type.typeRef ? { typeRef: descriptor.type.typeRef } : {}),\n ...(descriptor.typeParams ? { typeParams: descriptor.typeParams } : {}),\n };\n },\n }),\n ),\n timestampNowControlDescriptor(),\n ];\n}\n\nexport function createPostgresScalarTypeDescriptors(): ReadonlyMap<string, string> {\n return new Map(postgresScalarTypeDescriptors);\n}\n","import type { SqlControlAdapterDescriptor } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport {\n escapeLiteral,\n qualifyName,\n quoteIdentifier,\n SqlEscapeError,\n} from '@prisma-next/target-postgres/sql-utils';\nimport { PostgresControlAdapter } from '../core/control-adapter';\nimport {\n createPostgresDefaultFunctionRegistry,\n createPostgresMutationDefaultGeneratorDescriptors,\n createPostgresScalarTypeDescriptors,\n} from '../core/control-mutation-defaults';\nimport { postgresAdapterDescriptorMeta } from '../core/descriptor-meta';\n\nconst postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'> = {\n ...postgresAdapterDescriptorMeta,\n scalarTypeDescriptors: createPostgresScalarTypeDescriptors(),\n controlMutationDefaults: {\n defaultFunctionRegistry: createPostgresDefaultFunctionRegistry(),\n generatorDescriptors: createPostgresMutationDefaultGeneratorDescriptors(),\n },\n create(stack): SqlControlAdapter<'postgres'> {\n return new PostgresControlAdapter(stack.codecLookup);\n },\n};\n\nexport default postgresAdapterDescriptor;\n\nexport { parsePostgresDefault } from '@prisma-next/target-postgres/default-normalizer';\nexport { normalizeSchemaNativeType } from '@prisma-next/target-postgres/native-type-normalizer';\nexport { createPostgresBuiltinCodecLookup } from '../core/codec-lookup';\nexport { PostgresControlAdapter } from '../core/control-adapter';\nexport { escapeLiteral, qualifyName, quoteIdentifier, SqlEscapeError };\n"],"mappings":";;;;;;;;;AAgBA,SAAS,0BAA0B,OAIV;CACvB,OAAO;EACL,IAAI;EACJ,YAAY;GACV,MAAM;GACN,SAAS,MAAM;GACf,UAAU,MAAM,QAAQ;GACxB,MAAM,MA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Q,YAAY;CACrB,CAAC,SAAS,YAAY;AACxB,CAAC;AAED,SAAgB,wCAGd;CACA,OAAO,IAAI,IAAI,sCAAsC;AACvD;AAEA,SAAgB,oDAAmG;CACjH,OAAO,CACL,GAAG,iCAAiC,KACjC,EAAE,IAAI,0BAA8D;EACnE;EACA;EACA,mCAAmC,EAAE,gBAAgB;GACnD,IAAI,UAAU,SAAS,eAAe,UAAU,OAAO,IACrD;GAEF,MAAM,aAAa,wCAAwC;IACzD;IACA,GAAI,UAAU,SAAS,EAAE,QAAQ,UAAU,OAAO,IAAI,CAAC;GACzD,CAAC;GACD,OAAO;IACL,SAAS,WAAW,KAAK;IACzB,YAAY,WAAW,KAAK;IAC5B,GAAI,WAAW,KAAK,UAAU,EAAE,SAAS,WAAW,KAAK,QAAQ,IAAI,CAAC;IACtE,GAAI,WAAW,aAAa,EAAE,YAAY,WAAW,WAAW,IAAI,CAAC;GACvE;EACF;CACF,EACF,GACA,8BAA8B,CAChC;AACF;AAEA,SAAgB,sCAAmE;CACjF,OAAO,IAAI,IAAI,6BAA6B;AAC9C;;;AC3LA,MAAM,4BAAqE;CACzE,GAAG;CACH,uBAAuB,oCAAoC;CAC3D,yBAAyB;EACvB,yBAAyB,sCAAsC;EAC/D,sBAAsB,kDAAkD;CAC1E;CACA,OAAO,OAAsC;EAC3C,OAAO,IAAI,uBAAuB,MAAM,WAAW;CACrD;AACF"}
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../src/core/control-mutation-defaults.ts","../src/exports/control.ts"],"sourcesContent":["import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types';\nimport { timestampNowControlDescriptor } from '@prisma-next/family-sql/control';\nimport type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport type {\n ControlMutationDefaultEntry,\n DefaultFunctionLoweringContext,\n LoweredDefaultResult,\n MutationDefaultGeneratorDescriptor,\n TypedDefaultFunctionCall,\n} from '@prisma-next/framework-components/control';\nimport { builtinGeneratorRegistryMetadata } from '@prisma-next/ids';\nimport type { FuncCallSig } from '@prisma-next/psl-parser';\nimport { int, num, oneOf, optional, str } from '@prisma-next/psl-parser';\n\nfunction invalidArgumentDiagnostic(input: {\n readonly context: DefaultFunctionLoweringContext;\n readonly span: TypedDefaultFunctionCall['span'];\n readonly message: string;\n}): LoweredDefaultResult {\n return {\n ok: false,\n diagnostic: {\n code: 'PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT',\n message: input.message,\n sourceId: input.context.sourceId,\n span: input.span,\n },\n };\n}\n\nfunction executionGenerator(\n id: ExecutionMutationDefaultValue['id'],\n params?: Record<string, unknown>,\n): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'execution',\n generated: {\n kind: 'generator',\n id,\n ...(params ? { params } : {}),\n },\n },\n };\n}\n\nfunction lowerAutoincrement(): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression: 'autoincrement()' },\n },\n };\n}\n\nfunction lowerNow(): LoweredDefaultResult {\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression: 'now()' },\n },\n };\n}\n\nfunction lowerUlid(): LoweredDefaultResult {\n return executionGenerator('ulid');\n}\n\nfunction lowerUuid(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n return input.call.args['version'] === 7\n ? executionGenerator('uuidv7')\n : executionGenerator('uuidv4');\n}\n\nfunction lowerCuid(): LoweredDefaultResult {\n return executionGenerator('cuid2');\n}\n\nfunction lowerNanoid(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const size = input.call.args['size'];\n return typeof size === 'number'\n ? executionGenerator('nanoid', { size })\n : executionGenerator('nanoid');\n}\n\nfunction lowerDbgenerated(input: {\n readonly call: TypedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const expression = input.call.args['expression'];\n if (typeof expression !== 'string' || expression.trim().length === 0) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message: 'Default function \"dbgenerated\" argument cannot be empty.',\n });\n }\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: { kind: 'function', expression },\n },\n };\n}\n\nconst nowSig: FuncCallSig = {};\nconst autoincrementSig: FuncCallSig = {};\nconst ulidSig: FuncCallSig = {};\nconst uuidSig: FuncCallSig = {\n positional: [{ key: 'version', type: optional(oneOf(num(4), num(7))) }],\n};\nconst cuidSig: FuncCallSig = { positional: [{ key: 'version', type: num(2) }] };\nconst nanoidSig: FuncCallSig = {\n positional: [{ key: 'size', type: optional(int({ min: 2, max: 255 })) }],\n};\nconst dbgeneratedSig: FuncCallSig = { positional: [{ key: 'expression', type: str() }] };\n\nconst postgresDefaultFunctionRegistryEntries = [\n [\n 'autoincrement',\n {\n signature: autoincrementSig,\n lower: lowerAutoincrement,\n usageSignatures: ['autoincrement()'],\n },\n ],\n ['now', { signature: nowSig, lower: lowerNow, usageSignatures: ['now()'] }],\n [\n 'uuid',\n { signature: uuidSig, lower: lowerUuid, usageSignatures: ['uuid()', 'uuid(4)', 'uuid(7)'] },\n ],\n ['cuid', { signature: cuidSig, lower: lowerCuid, usageSignatures: ['cuid(2)'] }],\n ['ulid', { signature: ulidSig, lower: lowerUlid, usageSignatures: ['ulid()'] }],\n [\n 'nanoid',\n { signature: nanoidSig, lower: lowerNanoid, usageSignatures: ['nanoid()', 'nanoid(<2-255>)'] },\n ],\n [\n 'dbgenerated',\n { signature: dbgeneratedSig, lower: lowerDbgenerated, usageSignatures: ['dbgenerated(\"...\")'] },\n ],\n] satisfies ReadonlyArray<readonly [string, ControlMutationDefaultEntry]>;\n\n/**\n * The base PSL scalars as zero-arg type constructors in the unified authoring\n * channel, with explicit `nativeType` values pinned to the codec manifests\n * (`codecLookup.targetTypesFor(codecId)[0]`).\n *\n * The type position is the only storage decider: a mutation-default generator\n * (`@default(uuid())`) never re-picks a column's storage.\n */\nexport const postgresScalarAuthoringTypes = {\n String: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/text@1', nativeType: 'text' },\n },\n Boolean: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/bool@1', nativeType: 'bool' },\n },\n Int: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/int4@1', nativeType: 'int4' },\n },\n BigInt: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/int8@1', nativeType: 'int8' },\n },\n Float: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/float8@1', nativeType: 'float8' },\n },\n Decimal: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/numeric@1', nativeType: 'numeric' },\n },\n DateTime: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/timestamptz@1', nativeType: 'timestamptz' },\n },\n Json: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/json@1', nativeType: 'json' },\n },\n Jsonb: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/jsonb@1', nativeType: 'jsonb' },\n },\n Bytes: {\n kind: 'typeConstructor',\n output: { codecId: 'pg/bytea@1', nativeType: 'bytea' },\n },\n} as const satisfies AuthoringTypeNamespace;\n\n/**\n * The former `@db.*` native types as first-class top-level type constructors\n * (TML-2986). Codec ids, native types, and typeParams key shapes mirror the\n * legacy `@db.*` attribute path (`NATIVE_TYPE_SPECS` in sql-contract-psl)\n * exactly; every argument is optional, so each name is also authorable bare\n * (`VarChar` ≡ `VarChar()`), and omitted arguments omit their typeParams keys.\n */\nexport const postgresNativeAuthoringTypes = {\n VarChar: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, optional: true }],\n output: {\n codecId: 'sql/varchar@1',\n nativeType: 'character varying',\n typeParams: { length: { kind: 'arg', index: 0 } },\n },\n },\n Char: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, optional: true }],\n output: {\n codecId: 'sql/char@1',\n nativeType: 'character',\n typeParams: { length: { kind: 'arg', index: 0 } },\n },\n },\n Numeric: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'precision', integer: true, minimum: 1, optional: true },\n { kind: 'number', name: 'scale', integer: true, minimum: 0, optional: true },\n ],\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n typeParams: {\n precision: { kind: 'arg', index: 0 },\n scale: { kind: 'arg', index: 1 },\n },\n },\n },\n Timestamp: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],\n output: {\n codecId: 'pg/timestamp@1',\n nativeType: 'timestamp',\n typeParams: { precision: { kind: 'arg', index: 0 } },\n },\n },\n Timestamptz: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n typeParams: { precision: { kind: 'arg', index: 0 } },\n },\n },\n Time: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],\n output: {\n codecId: 'pg/time@1',\n nativeType: 'time',\n typeParams: { precision: { kind: 'arg', index: 0 } },\n },\n },\n Timetz: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],\n output: {\n codecId: 'pg/timetz@1',\n nativeType: 'timetz',\n typeParams: { precision: { kind: 'arg', index: 0 } },\n },\n },\n Uuid: { kind: 'typeConstructor', output: { codecId: 'pg/uuid@1', nativeType: 'uuid' } },\n SmallInt: { kind: 'typeConstructor', output: { codecId: 'pg/int2@1', nativeType: 'int2' } },\n Real: { kind: 'typeConstructor', output: { codecId: 'pg/float4@1', nativeType: 'float4' } },\n Date: { kind: 'typeConstructor', output: { codecId: 'pg/timestamptz@1', nativeType: 'date' } },\n} as const satisfies AuthoringTypeNamespace;\n\nexport const postgresAuthoringTypes = {\n ...postgresScalarAuthoringTypes,\n ...postgresNativeAuthoringTypes,\n} as const satisfies AuthoringTypeNamespace;\n\nexport function createPostgresDefaultFunctionRegistry(): ReadonlyMap<\n string,\n ControlMutationDefaultEntry\n> {\n return new Map(postgresDefaultFunctionRegistryEntries);\n}\n\nexport function createPostgresMutationDefaultGeneratorDescriptors(): readonly MutationDefaultGeneratorDescriptor[] {\n return [\n ...builtinGeneratorRegistryMetadata.map(\n ({ id, applicableCodecIds }): MutationDefaultGeneratorDescriptor => ({\n id,\n applicableCodecIds,\n }),\n ),\n timestampNowControlDescriptor(),\n ];\n}\n","import type { SqlControlAdapterDescriptor } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport {\n escapeLiteral,\n qualifyName,\n quoteIdentifier,\n SqlEscapeError,\n} from '@prisma-next/target-postgres/sql-utils';\nimport { PostgresControlAdapter } from '../core/control-adapter';\nimport {\n createPostgresDefaultFunctionRegistry,\n createPostgresMutationDefaultGeneratorDescriptors,\n postgresAuthoringTypes,\n} from '../core/control-mutation-defaults';\nimport { postgresAdapterDescriptorMeta } from '../core/descriptor-meta';\n\nconst postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'> = {\n ...postgresAdapterDescriptorMeta,\n authoring: { type: postgresAuthoringTypes, valueObjectStorageType: 'Jsonb' },\n controlMutationDefaults: {\n defaultFunctionRegistry: createPostgresDefaultFunctionRegistry(),\n generatorDescriptors: createPostgresMutationDefaultGeneratorDescriptors(),\n },\n create(stack): SqlControlAdapter<'postgres'> {\n return new PostgresControlAdapter(stack.codecLookup);\n },\n};\n\nexport default postgresAdapterDescriptor;\n\nexport { parsePostgresDefault } from '@prisma-next/target-postgres/default-normalizer';\nexport { normalizeSchemaNativeType } from '@prisma-next/target-postgres/native-type-normalizer';\nexport { createPostgresBuiltinCodecLookup } from '../core/codec-lookup';\nexport { PostgresControlAdapter } from '../core/control-adapter';\nexport { escapeLiteral, qualifyName, quoteIdentifier, SqlEscapeError };\n"],"mappings":";;;;;;;;;AAcA,SAAS,0BAA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MAAM;EAAmB,QAAQ;GAAE,SAAS;GAAe,YAAY;EAAS;CAAE;CAC1F,MAAM;EAAE,MAAM;EAAmB,QAAQ;GAAE,SAAS;GAAoB,YAAY;EAAO;CAAE;AAC/F;AAEA,MAAa,yBAAyB;CACpC,GAAG;CACH,GAAG;AACL;AAEA,SAAgB,wCAGd;CACA,OAAO,IAAI,IAAI,sCAAsC;AACvD;AAEA,SAAgB,oDAAmG;CACjH,OAAO,CACL,GAAG,iCAAiC,KACjC,EAAE,IAAI,0BAA8D;EACnE;EACA;CACF,EACF,GACA,8BAA8B,CAChC;AACF;;;ACrSA,MAAM,4BAAqE;CACzE,GAAG;CACH,WAAW;EAAE,MAAM;EAAwB,wBAAwB;CAAQ;CAC3E,yBAAyB;EACvB,yBAAyB,sCAAsC;EAC/D,sBAAsB,kDAAkD;CAC1E;CACA,OAAO,OAAsC;EAC3C,OAAO,IAAI,uBAAuB,MAAM,WAAW;CACrD;AACF"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-postgres",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.12",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.16.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.16.0-dev.
|
|
10
|
-
"@prisma-next/errors": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/family-sql": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.16.0-dev.
|
|
13
|
-
"@prisma-next/ids": "0.16.0-dev.
|
|
14
|
-
"@prisma-next/psl-parser": "0.16.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract": "0.16.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract-psl": "0.16.0-dev.
|
|
17
|
-
"@prisma-next/sql-contract-ts": "0.16.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.16.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.16.0-dev.
|
|
20
|
-
"@prisma-next/sql-runtime": "0.16.0-dev.
|
|
21
|
-
"@prisma-next/sql-schema-ir": "0.16.0-dev.
|
|
22
|
-
"@prisma-next/target-postgres": "0.16.0-dev.
|
|
23
|
-
"@prisma-next/utils": "0.16.0-dev.
|
|
8
|
+
"@prisma-next/contract": "0.16.0-dev.12",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.16.0-dev.12",
|
|
10
|
+
"@prisma-next/errors": "0.16.0-dev.12",
|
|
11
|
+
"@prisma-next/family-sql": "0.16.0-dev.12",
|
|
12
|
+
"@prisma-next/framework-components": "0.16.0-dev.12",
|
|
13
|
+
"@prisma-next/ids": "0.16.0-dev.12",
|
|
14
|
+
"@prisma-next/psl-parser": "0.16.0-dev.12",
|
|
15
|
+
"@prisma-next/sql-contract": "0.16.0-dev.12",
|
|
16
|
+
"@prisma-next/sql-contract-psl": "0.16.0-dev.12",
|
|
17
|
+
"@prisma-next/sql-contract-ts": "0.16.0-dev.12",
|
|
18
|
+
"@prisma-next/sql-operations": "0.16.0-dev.12",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.16.0-dev.12",
|
|
20
|
+
"@prisma-next/sql-runtime": "0.16.0-dev.12",
|
|
21
|
+
"@prisma-next/sql-schema-ir": "0.16.0-dev.12",
|
|
22
|
+
"@prisma-next/target-postgres": "0.16.0-dev.12",
|
|
23
|
+
"@prisma-next/utils": "0.16.0-dev.12",
|
|
24
24
|
"arktype": "^2.2.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/cli": "0.16.0-dev.
|
|
28
|
-
"@prisma-next/driver-postgres": "0.16.0-dev.
|
|
29
|
-
"@prisma-next/migration-tools": "0.16.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.16.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.16.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.16.0-dev.
|
|
27
|
+
"@prisma-next/cli": "0.16.0-dev.12",
|
|
28
|
+
"@prisma-next/driver-postgres": "0.16.0-dev.12",
|
|
29
|
+
"@prisma-next/migration-tools": "0.16.0-dev.12",
|
|
30
|
+
"@prisma-next/test-utils": "0.16.0-dev.12",
|
|
31
|
+
"@prisma-next/tsconfig": "0.16.0-dev.12",
|
|
32
|
+
"@prisma-next/tsdown": "0.16.0-dev.12",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"tsdown": "0.22.8",
|
|
35
35
|
"typescript": "5.9.3",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
|
|
2
2
|
import { timestampNowControlDescriptor } from '@prisma-next/family-sql/control';
|
|
3
|
+
import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';
|
|
3
4
|
import type {
|
|
4
5
|
ControlMutationDefaultEntry,
|
|
5
6
|
DefaultFunctionLoweringContext,
|
|
@@ -7,10 +8,7 @@ import type {
|
|
|
7
8
|
MutationDefaultGeneratorDescriptor,
|
|
8
9
|
TypedDefaultFunctionCall,
|
|
9
10
|
} from '@prisma-next/framework-components/control';
|
|
10
|
-
import {
|
|
11
|
-
builtinGeneratorRegistryMetadata,
|
|
12
|
-
resolveBuiltinGeneratedColumnDescriptor,
|
|
13
|
-
} from '@prisma-next/ids';
|
|
11
|
+
import { builtinGeneratorRegistryMetadata } from '@prisma-next/ids';
|
|
14
12
|
import type { FuncCallSig } from '@prisma-next/psl-parser';
|
|
15
13
|
import { int, num, oneOf, optional, str } from '@prisma-next/psl-parser';
|
|
16
14
|
|
|
@@ -153,17 +151,144 @@ const postgresDefaultFunctionRegistryEntries = [
|
|
|
153
151
|
],
|
|
154
152
|
] satisfies ReadonlyArray<readonly [string, ControlMutationDefaultEntry]>;
|
|
155
153
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
154
|
+
/**
|
|
155
|
+
* The base PSL scalars as zero-arg type constructors in the unified authoring
|
|
156
|
+
* channel, with explicit `nativeType` values pinned to the codec manifests
|
|
157
|
+
* (`codecLookup.targetTypesFor(codecId)[0]`).
|
|
158
|
+
*
|
|
159
|
+
* The type position is the only storage decider: a mutation-default generator
|
|
160
|
+
* (`@default(uuid())`) never re-picks a column's storage.
|
|
161
|
+
*/
|
|
162
|
+
export const postgresScalarAuthoringTypes = {
|
|
163
|
+
String: {
|
|
164
|
+
kind: 'typeConstructor',
|
|
165
|
+
output: { codecId: 'pg/text@1', nativeType: 'text' },
|
|
166
|
+
},
|
|
167
|
+
Boolean: {
|
|
168
|
+
kind: 'typeConstructor',
|
|
169
|
+
output: { codecId: 'pg/bool@1', nativeType: 'bool' },
|
|
170
|
+
},
|
|
171
|
+
Int: {
|
|
172
|
+
kind: 'typeConstructor',
|
|
173
|
+
output: { codecId: 'pg/int4@1', nativeType: 'int4' },
|
|
174
|
+
},
|
|
175
|
+
BigInt: {
|
|
176
|
+
kind: 'typeConstructor',
|
|
177
|
+
output: { codecId: 'pg/int8@1', nativeType: 'int8' },
|
|
178
|
+
},
|
|
179
|
+
Float: {
|
|
180
|
+
kind: 'typeConstructor',
|
|
181
|
+
output: { codecId: 'pg/float8@1', nativeType: 'float8' },
|
|
182
|
+
},
|
|
183
|
+
Decimal: {
|
|
184
|
+
kind: 'typeConstructor',
|
|
185
|
+
output: { codecId: 'pg/numeric@1', nativeType: 'numeric' },
|
|
186
|
+
},
|
|
187
|
+
DateTime: {
|
|
188
|
+
kind: 'typeConstructor',
|
|
189
|
+
output: { codecId: 'pg/timestamptz@1', nativeType: 'timestamptz' },
|
|
190
|
+
},
|
|
191
|
+
Json: {
|
|
192
|
+
kind: 'typeConstructor',
|
|
193
|
+
output: { codecId: 'pg/json@1', nativeType: 'json' },
|
|
194
|
+
},
|
|
195
|
+
Jsonb: {
|
|
196
|
+
kind: 'typeConstructor',
|
|
197
|
+
output: { codecId: 'pg/jsonb@1', nativeType: 'jsonb' },
|
|
198
|
+
},
|
|
199
|
+
Bytes: {
|
|
200
|
+
kind: 'typeConstructor',
|
|
201
|
+
output: { codecId: 'pg/bytea@1', nativeType: 'bytea' },
|
|
202
|
+
},
|
|
203
|
+
} as const satisfies AuthoringTypeNamespace;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The former `@db.*` native types as first-class top-level type constructors
|
|
207
|
+
* (TML-2986). Codec ids, native types, and typeParams key shapes mirror the
|
|
208
|
+
* legacy `@db.*` attribute path (`NATIVE_TYPE_SPECS` in sql-contract-psl)
|
|
209
|
+
* exactly; every argument is optional, so each name is also authorable bare
|
|
210
|
+
* (`VarChar` ≡ `VarChar()`), and omitted arguments omit their typeParams keys.
|
|
211
|
+
*/
|
|
212
|
+
export const postgresNativeAuthoringTypes = {
|
|
213
|
+
VarChar: {
|
|
214
|
+
kind: 'typeConstructor',
|
|
215
|
+
args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, optional: true }],
|
|
216
|
+
output: {
|
|
217
|
+
codecId: 'sql/varchar@1',
|
|
218
|
+
nativeType: 'character varying',
|
|
219
|
+
typeParams: { length: { kind: 'arg', index: 0 } },
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
Char: {
|
|
223
|
+
kind: 'typeConstructor',
|
|
224
|
+
args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, optional: true }],
|
|
225
|
+
output: {
|
|
226
|
+
codecId: 'sql/char@1',
|
|
227
|
+
nativeType: 'character',
|
|
228
|
+
typeParams: { length: { kind: 'arg', index: 0 } },
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
Numeric: {
|
|
232
|
+
kind: 'typeConstructor',
|
|
233
|
+
args: [
|
|
234
|
+
{ kind: 'number', name: 'precision', integer: true, minimum: 1, optional: true },
|
|
235
|
+
{ kind: 'number', name: 'scale', integer: true, minimum: 0, optional: true },
|
|
236
|
+
],
|
|
237
|
+
output: {
|
|
238
|
+
codecId: 'pg/numeric@1',
|
|
239
|
+
nativeType: 'numeric',
|
|
240
|
+
typeParams: {
|
|
241
|
+
precision: { kind: 'arg', index: 0 },
|
|
242
|
+
scale: { kind: 'arg', index: 1 },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
Timestamp: {
|
|
247
|
+
kind: 'typeConstructor',
|
|
248
|
+
args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],
|
|
249
|
+
output: {
|
|
250
|
+
codecId: 'pg/timestamp@1',
|
|
251
|
+
nativeType: 'timestamp',
|
|
252
|
+
typeParams: { precision: { kind: 'arg', index: 0 } },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
Timestamptz: {
|
|
256
|
+
kind: 'typeConstructor',
|
|
257
|
+
args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],
|
|
258
|
+
output: {
|
|
259
|
+
codecId: 'pg/timestamptz@1',
|
|
260
|
+
nativeType: 'timestamptz',
|
|
261
|
+
typeParams: { precision: { kind: 'arg', index: 0 } },
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
Time: {
|
|
265
|
+
kind: 'typeConstructor',
|
|
266
|
+
args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],
|
|
267
|
+
output: {
|
|
268
|
+
codecId: 'pg/time@1',
|
|
269
|
+
nativeType: 'time',
|
|
270
|
+
typeParams: { precision: { kind: 'arg', index: 0 } },
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
Timetz: {
|
|
274
|
+
kind: 'typeConstructor',
|
|
275
|
+
args: [{ kind: 'number', name: 'precision', integer: true, minimum: 0, optional: true }],
|
|
276
|
+
output: {
|
|
277
|
+
codecId: 'pg/timetz@1',
|
|
278
|
+
nativeType: 'timetz',
|
|
279
|
+
typeParams: { precision: { kind: 'arg', index: 0 } },
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
Uuid: { kind: 'typeConstructor', output: { codecId: 'pg/uuid@1', nativeType: 'uuid' } },
|
|
283
|
+
SmallInt: { kind: 'typeConstructor', output: { codecId: 'pg/int2@1', nativeType: 'int2' } },
|
|
284
|
+
Real: { kind: 'typeConstructor', output: { codecId: 'pg/float4@1', nativeType: 'float4' } },
|
|
285
|
+
Date: { kind: 'typeConstructor', output: { codecId: 'pg/timestamptz@1', nativeType: 'date' } },
|
|
286
|
+
} as const satisfies AuthoringTypeNamespace;
|
|
287
|
+
|
|
288
|
+
export const postgresAuthoringTypes = {
|
|
289
|
+
...postgresScalarAuthoringTypes,
|
|
290
|
+
...postgresNativeAuthoringTypes,
|
|
291
|
+
} as const satisfies AuthoringTypeNamespace;
|
|
167
292
|
|
|
168
293
|
export function createPostgresDefaultFunctionRegistry(): ReadonlyMap<
|
|
169
294
|
string,
|
|
@@ -178,27 +303,8 @@ export function createPostgresMutationDefaultGeneratorDescriptors(): readonly Mu
|
|
|
178
303
|
({ id, applicableCodecIds }): MutationDefaultGeneratorDescriptor => ({
|
|
179
304
|
id,
|
|
180
305
|
applicableCodecIds,
|
|
181
|
-
resolveGeneratedColumnDescriptor: ({ generated }) => {
|
|
182
|
-
if (generated.kind !== 'generator' || generated.id !== id) {
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
|
-
const descriptor = resolveBuiltinGeneratedColumnDescriptor({
|
|
186
|
-
id,
|
|
187
|
-
...(generated.params ? { params: generated.params } : {}),
|
|
188
|
-
});
|
|
189
|
-
return {
|
|
190
|
-
codecId: descriptor.type.codecId,
|
|
191
|
-
nativeType: descriptor.type.nativeType,
|
|
192
|
-
...(descriptor.type.typeRef ? { typeRef: descriptor.type.typeRef } : {}),
|
|
193
|
-
...(descriptor.typeParams ? { typeParams: descriptor.typeParams } : {}),
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
306
|
}),
|
|
197
307
|
),
|
|
198
308
|
timestampNowControlDescriptor(),
|
|
199
309
|
];
|
|
200
310
|
}
|
|
201
|
-
|
|
202
|
-
export function createPostgresScalarTypeDescriptors(): ReadonlyMap<string, string> {
|
|
203
|
-
return new Map(postgresScalarTypeDescriptors);
|
|
204
|
-
}
|
package/src/exports/control.ts
CHANGED
|
@@ -10,13 +10,13 @@ import { PostgresControlAdapter } from '../core/control-adapter';
|
|
|
10
10
|
import {
|
|
11
11
|
createPostgresDefaultFunctionRegistry,
|
|
12
12
|
createPostgresMutationDefaultGeneratorDescriptors,
|
|
13
|
-
|
|
13
|
+
postgresAuthoringTypes,
|
|
14
14
|
} from '../core/control-mutation-defaults';
|
|
15
15
|
import { postgresAdapterDescriptorMeta } from '../core/descriptor-meta';
|
|
16
16
|
|
|
17
17
|
const postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'> = {
|
|
18
18
|
...postgresAdapterDescriptorMeta,
|
|
19
|
-
|
|
19
|
+
authoring: { type: postgresAuthoringTypes, valueObjectStorageType: 'Jsonb' },
|
|
20
20
|
controlMutationDefaults: {
|
|
21
21
|
defaultFunctionRegistry: createPostgresDefaultFunctionRegistry(),
|
|
22
22
|
generatorDescriptors: createPostgresMutationDefaultGeneratorDescriptors(),
|