@prisma-next/adapter-postgres 0.14.0-dev.74 → 0.14.0-dev.76
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 +43 -104
- package/dist/control.mjs.map +1 -1
- package/package.json +23 -23
- package/src/core/control-mutation-defaults.ts +61 -190
package/dist/control.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { normalizeSchemaNativeType } from "@prisma-next/target-postgres/native-t
|
|
|
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
7
|
import { builtinGeneratorRegistryMetadata, resolveBuiltinGeneratedColumnDescriptor } from "@prisma-next/ids";
|
|
8
|
+
import { int, num, oneOf, optional, str } from "@prisma-next/psl-parser";
|
|
8
9
|
//#region src/core/control-mutation-defaults.ts
|
|
9
10
|
function invalidArgumentDiagnostic(input) {
|
|
10
11
|
return {
|
|
@@ -30,33 +31,7 @@ function executionGenerator(id, params) {
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
-
if (input.call.args.length === 0) return;
|
|
35
|
-
return invalidArgumentDiagnostic({
|
|
36
|
-
context: input.context,
|
|
37
|
-
span: input.call.span,
|
|
38
|
-
message: `Default function "${input.call.name}" does not accept arguments. Use ${input.usage}.`
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function parseIntegerArgument(raw) {
|
|
42
|
-
const trimmed = raw.trim();
|
|
43
|
-
if (!/^-?\d+$/.test(trimmed)) return;
|
|
44
|
-
const value = Number(trimmed);
|
|
45
|
-
if (!Number.isInteger(value)) return;
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
function parseStringLiteral(raw) {
|
|
49
|
-
const match = raw.trim().match(/^(['"])(.*)\1$/s);
|
|
50
|
-
if (!match) return;
|
|
51
|
-
return match[2] ?? "";
|
|
52
|
-
}
|
|
53
|
-
function lowerAutoincrement(input) {
|
|
54
|
-
const maybeNoArgs = expectNoArgs({
|
|
55
|
-
call: input.call,
|
|
56
|
-
context: input.context,
|
|
57
|
-
usage: "`autoincrement()`"
|
|
58
|
-
});
|
|
59
|
-
if (maybeNoArgs) return maybeNoArgs;
|
|
34
|
+
function lowerAutoincrement() {
|
|
60
35
|
return {
|
|
61
36
|
ok: true,
|
|
62
37
|
value: {
|
|
@@ -68,13 +43,7 @@ function lowerAutoincrement(input) {
|
|
|
68
43
|
}
|
|
69
44
|
};
|
|
70
45
|
}
|
|
71
|
-
function lowerNow(
|
|
72
|
-
const maybeNoArgs = expectNoArgs({
|
|
73
|
-
call: input.call,
|
|
74
|
-
context: input.context,
|
|
75
|
-
usage: "`now()`"
|
|
76
|
-
});
|
|
77
|
-
if (maybeNoArgs) return maybeNoArgs;
|
|
46
|
+
function lowerNow() {
|
|
78
47
|
return {
|
|
79
48
|
ok: true,
|
|
80
49
|
value: {
|
|
@@ -86,83 +55,24 @@ function lowerNow(input) {
|
|
|
86
55
|
}
|
|
87
56
|
};
|
|
88
57
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
if (input.call.args.length !== 1) return invalidArgumentDiagnostic({
|
|
92
|
-
context: input.context,
|
|
93
|
-
span: input.call.span,
|
|
94
|
-
message: "Default function \"uuid\" accepts at most one version argument: `uuid()`, `uuid(4)`, or `uuid(7)`."
|
|
95
|
-
});
|
|
96
|
-
const version = parseIntegerArgument(input.call.args[0]?.raw ?? "");
|
|
97
|
-
if (version === 4) return executionGenerator("uuidv4");
|
|
98
|
-
if (version === 7) return executionGenerator("uuidv7");
|
|
99
|
-
return invalidArgumentDiagnostic({
|
|
100
|
-
context: input.context,
|
|
101
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
102
|
-
message: "Default function \"uuid\" supports only `uuid()`, `uuid(4)`, or `uuid(7)` in SQL PSL provider v1."
|
|
103
|
-
});
|
|
58
|
+
function lowerUlid() {
|
|
59
|
+
return executionGenerator("ulid");
|
|
104
60
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
107
|
-
ok: false,
|
|
108
|
-
diagnostic: {
|
|
109
|
-
code: "PSL_UNKNOWN_DEFAULT_FUNCTION",
|
|
110
|
-
message: "Default function \"cuid()\" is not supported in SQL PSL provider v1. Use `cuid(2)` instead.",
|
|
111
|
-
sourceId: input.context.sourceId,
|
|
112
|
-
span: input.call.span
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
if (input.call.args.length !== 1) return invalidArgumentDiagnostic({
|
|
116
|
-
context: input.context,
|
|
117
|
-
span: input.call.span,
|
|
118
|
-
message: "Default function \"cuid\" accepts exactly one version argument: `cuid(2)`."
|
|
119
|
-
});
|
|
120
|
-
if (parseIntegerArgument(input.call.args[0]?.raw ?? "") === 2) return executionGenerator("cuid2");
|
|
121
|
-
return invalidArgumentDiagnostic({
|
|
122
|
-
context: input.context,
|
|
123
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
124
|
-
message: "Default function \"cuid\" supports only `cuid(2)` in SQL PSL provider v1."
|
|
125
|
-
});
|
|
61
|
+
function lowerUuid(input) {
|
|
62
|
+
return input.call.args["version"] === 7 ? executionGenerator("uuidv7") : executionGenerator("uuidv4");
|
|
126
63
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
call: input.call,
|
|
130
|
-
context: input.context,
|
|
131
|
-
usage: "`ulid()`"
|
|
132
|
-
});
|
|
133
|
-
if (maybeNoArgs) return maybeNoArgs;
|
|
134
|
-
return executionGenerator("ulid");
|
|
64
|
+
function lowerCuid() {
|
|
65
|
+
return executionGenerator("cuid2");
|
|
135
66
|
}
|
|
136
67
|
function lowerNanoid(input) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
context: input.context,
|
|
140
|
-
span: input.call.span,
|
|
141
|
-
message: "Default function \"nanoid\" accepts at most one size argument: `nanoid()` or `nanoid(<2-255>)`."
|
|
142
|
-
});
|
|
143
|
-
const size = parseIntegerArgument(input.call.args[0]?.raw ?? "");
|
|
144
|
-
if (size !== void 0 && size >= 2 && size <= 255) return executionGenerator("nanoid", { size });
|
|
145
|
-
return invalidArgumentDiagnostic({
|
|
146
|
-
context: input.context,
|
|
147
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
148
|
-
message: "Default function \"nanoid\" size argument must be an integer between 2 and 255."
|
|
149
|
-
});
|
|
68
|
+
const size = input.call.args["size"];
|
|
69
|
+
return typeof size === "number" ? executionGenerator("nanoid", { size }) : executionGenerator("nanoid");
|
|
150
70
|
}
|
|
151
71
|
function lowerDbgenerated(input) {
|
|
152
|
-
|
|
72
|
+
const expression = input.call.args["expression"];
|
|
73
|
+
if (typeof expression !== "string" || expression.trim().length === 0) return invalidArgumentDiagnostic({
|
|
153
74
|
context: input.context,
|
|
154
75
|
span: input.call.span,
|
|
155
|
-
message: "Default function \"dbgenerated\" requires exactly one string argument: `dbgenerated(\"...\")`."
|
|
156
|
-
});
|
|
157
|
-
const rawExpression = parseStringLiteral(input.call.args[0]?.raw ?? "");
|
|
158
|
-
if (rawExpression === void 0) return invalidArgumentDiagnostic({
|
|
159
|
-
context: input.context,
|
|
160
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
161
|
-
message: "Default function \"dbgenerated\" argument must be a string literal."
|
|
162
|
-
});
|
|
163
|
-
if (rawExpression.trim().length === 0) return invalidArgumentDiagnostic({
|
|
164
|
-
context: input.context,
|
|
165
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
166
76
|
message: "Default function \"dbgenerated\" argument cannot be empty."
|
|
167
77
|
});
|
|
168
78
|
return {
|
|
@@ -171,21 +81,46 @@ function lowerDbgenerated(input) {
|
|
|
171
81
|
kind: "storage",
|
|
172
82
|
defaultValue: {
|
|
173
83
|
kind: "function",
|
|
174
|
-
expression
|
|
84
|
+
expression
|
|
175
85
|
}
|
|
176
86
|
}
|
|
177
87
|
};
|
|
178
88
|
}
|
|
89
|
+
const nowSig = {};
|
|
90
|
+
const autoincrementSig = {};
|
|
91
|
+
const ulidSig = {};
|
|
92
|
+
const uuidSig = { positional: [{
|
|
93
|
+
key: "version",
|
|
94
|
+
type: optional(oneOf(num(4), num(7)))
|
|
95
|
+
}] };
|
|
96
|
+
const cuidSig = { positional: [{
|
|
97
|
+
key: "version",
|
|
98
|
+
type: num(2)
|
|
99
|
+
}] };
|
|
100
|
+
const nanoidSig = { positional: [{
|
|
101
|
+
key: "size",
|
|
102
|
+
type: optional(int({
|
|
103
|
+
min: 2,
|
|
104
|
+
max: 255
|
|
105
|
+
}))
|
|
106
|
+
}] };
|
|
107
|
+
const dbgeneratedSig = { positional: [{
|
|
108
|
+
key: "expression",
|
|
109
|
+
type: str()
|
|
110
|
+
}] };
|
|
179
111
|
const postgresDefaultFunctionRegistryEntries = [
|
|
180
112
|
["autoincrement", {
|
|
113
|
+
signature: autoincrementSig,
|
|
181
114
|
lower: lowerAutoincrement,
|
|
182
115
|
usageSignatures: ["autoincrement()"]
|
|
183
116
|
}],
|
|
184
117
|
["now", {
|
|
118
|
+
signature: nowSig,
|
|
185
119
|
lower: lowerNow,
|
|
186
120
|
usageSignatures: ["now()"]
|
|
187
121
|
}],
|
|
188
122
|
["uuid", {
|
|
123
|
+
signature: uuidSig,
|
|
189
124
|
lower: lowerUuid,
|
|
190
125
|
usageSignatures: [
|
|
191
126
|
"uuid()",
|
|
@@ -194,18 +129,22 @@ const postgresDefaultFunctionRegistryEntries = [
|
|
|
194
129
|
]
|
|
195
130
|
}],
|
|
196
131
|
["cuid", {
|
|
132
|
+
signature: cuidSig,
|
|
197
133
|
lower: lowerCuid,
|
|
198
134
|
usageSignatures: ["cuid(2)"]
|
|
199
135
|
}],
|
|
200
136
|
["ulid", {
|
|
137
|
+
signature: ulidSig,
|
|
201
138
|
lower: lowerUlid,
|
|
202
139
|
usageSignatures: ["ulid()"]
|
|
203
140
|
}],
|
|
204
141
|
["nanoid", {
|
|
142
|
+
signature: nanoidSig,
|
|
205
143
|
lower: lowerNanoid,
|
|
206
144
|
usageSignatures: ["nanoid()", "nanoid(<2-255>)"]
|
|
207
145
|
}],
|
|
208
146
|
["dbgenerated", {
|
|
147
|
+
signature: dbgeneratedSig,
|
|
209
148
|
lower: lowerDbgenerated,
|
|
210
149
|
usageSignatures: ["dbgenerated(\"...\")"]
|
|
211
150
|
}]
|
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 ParsedDefaultFunctionCall,\n} from '@prisma-next/framework-components/control';\nimport {\n builtinGeneratorRegistryMetadata,\n resolveBuiltinGeneratedColumnDescriptor,\n} from '@prisma-next/ids';\n\nfunction invalidArgumentDiagnostic(input: {\n readonly context: DefaultFunctionLoweringContext;\n readonly span: ParsedDefaultFunctionCall['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 expectNoArgs(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n readonly usage: string;\n}): LoweredDefaultResult | undefined {\n if (input.call.args.length === 0) {\n return undefined;\n }\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message: `Default function \"${input.call.name}\" does not accept arguments. Use ${input.usage}.`,\n });\n}\n\nfunction parseIntegerArgument(raw: string): number | undefined {\n const trimmed = raw.trim();\n if (!/^-?\\d+$/.test(trimmed)) {\n return undefined;\n }\n const value = Number(trimmed);\n if (!Number.isInteger(value)) {\n return undefined;\n }\n return value;\n}\n\nfunction parseStringLiteral(raw: string): string | undefined {\n const match = raw.trim().match(/^(['\"])(.*)\\1$/s);\n if (!match) {\n return undefined;\n }\n return match[2] ?? '';\n}\n\nfunction lowerAutoincrement(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const maybeNoArgs = expectNoArgs({\n call: input.call,\n context: input.context,\n usage: '`autoincrement()`',\n });\n if (maybeNoArgs) {\n return maybeNoArgs;\n }\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: {\n kind: 'function',\n expression: 'autoincrement()',\n },\n },\n };\n}\n\nfunction lowerNow(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const maybeNoArgs = expectNoArgs({\n call: input.call,\n context: input.context,\n usage: '`now()`',\n });\n if (maybeNoArgs) {\n return maybeNoArgs;\n }\n return {\n ok: true,\n value: {\n kind: 'storage',\n defaultValue: {\n kind: 'function',\n expression: 'now()',\n },\n },\n };\n}\n\nfunction lowerUuid(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n if (input.call.args.length === 0) {\n return executionGenerator('uuidv4');\n }\n if (input.call.args.length !== 1) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message:\n 'Default function \"uuid\" accepts at most one version argument: `uuid()`, `uuid(4)`, or `uuid(7)`.',\n });\n }\n const version = parseIntegerArgument(input.call.args[0]?.raw ?? '');\n if (version === 4) {\n return executionGenerator('uuidv4');\n }\n if (version === 7) {\n return executionGenerator('uuidv7');\n }\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.args[0]?.span ?? input.call.span,\n message:\n 'Default function \"uuid\" supports only `uuid()`, `uuid(4)`, or `uuid(7)` in SQL PSL provider v1.',\n });\n}\n\nfunction lowerCuid(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n if (input.call.args.length === 0) {\n return {\n ok: false,\n diagnostic: {\n code: 'PSL_UNKNOWN_DEFAULT_FUNCTION',\n message:\n 'Default function \"cuid()\" is not supported in SQL PSL provider v1. Use `cuid(2)` instead.',\n sourceId: input.context.sourceId,\n span: input.call.span,\n },\n };\n }\n if (input.call.args.length !== 1) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message: 'Default function \"cuid\" accepts exactly one version argument: `cuid(2)`.',\n });\n }\n const version = parseIntegerArgument(input.call.args[0]?.raw ?? '');\n if (version === 2) {\n return executionGenerator('cuid2');\n }\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.args[0]?.span ?? input.call.span,\n message: 'Default function \"cuid\" supports only `cuid(2)` in SQL PSL provider v1.',\n });\n}\n\nfunction lowerUlid(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n const maybeNoArgs = expectNoArgs({\n call: input.call,\n context: input.context,\n usage: '`ulid()`',\n });\n if (maybeNoArgs) {\n return maybeNoArgs;\n }\n return executionGenerator('ulid');\n}\n\nfunction lowerNanoid(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n if (input.call.args.length === 0) {\n return executionGenerator('nanoid');\n }\n if (input.call.args.length !== 1) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message:\n 'Default function \"nanoid\" accepts at most one size argument: `nanoid()` or `nanoid(<2-255>)`.',\n });\n }\n const size = parseIntegerArgument(input.call.args[0]?.raw ?? '');\n if (size !== undefined && size >= 2 && size <= 255) {\n return executionGenerator('nanoid', { size });\n }\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.args[0]?.span ?? input.call.span,\n message: 'Default function \"nanoid\" size argument must be an integer between 2 and 255.',\n });\n}\n\nfunction lowerDbgenerated(input: {\n readonly call: ParsedDefaultFunctionCall;\n readonly context: DefaultFunctionLoweringContext;\n}): LoweredDefaultResult {\n if (input.call.args.length !== 1) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.span,\n message:\n 'Default function \"dbgenerated\" requires exactly one string argument: `dbgenerated(\"...\")`.',\n });\n }\n const rawExpression = parseStringLiteral(input.call.args[0]?.raw ?? '');\n if (rawExpression === undefined) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.args[0]?.span ?? input.call.span,\n message: 'Default function \"dbgenerated\" argument must be a string literal.',\n });\n }\n if (rawExpression.trim().length === 0) {\n return invalidArgumentDiagnostic({\n context: input.context,\n span: input.call.args[0]?.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: {\n kind: 'function',\n expression: rawExpression,\n },\n },\n };\n}\n\nconst postgresDefaultFunctionRegistryEntries = [\n ['autoincrement', { lower: lowerAutoincrement, usageSignatures: ['autoincrement()'] }],\n ['now', { lower: lowerNow, usageSignatures: ['now()'] }],\n ['uuid', { lower: lowerUuid, usageSignatures: ['uuid()', 'uuid(4)', 'uuid(7)'] }],\n ['cuid', { lower: lowerCuid, usageSignatures: ['cuid(2)'] }],\n ['ulid', { lower: lowerUlid, usageSignatures: ['ulid()'] }],\n ['nanoid', { lower: lowerNanoid, usageSignatures: ['nanoid()', 'nanoid(<2-255>)'] }],\n ['dbgenerated', { lower: lowerDbgenerated, usageSignatures: ['dbgenerated(\"...\")'] }],\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":";;;;;;;;AAcA,SAAS,0BAA0B,OAIV;CACvB,OAAO;EACL,IAAI;EACJ,YAAY;GACV,MAAM;GACN,SAAS,MAAM;GACf,UAAU,MAAM,QAAQ;GACxB,MAAM,MAAM;EACd;CACF;AACF;AAEA,SAAS,mBACP,IACA,QACsB;CACtB,OAAO;EACL,IAAI;EACJ,OAAO;GACL,MAAM;GACN,WAAW;IACT,MAAM;IACN;IACA,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;GAC7B;EACF;CACF;AACF;AAEA,SAAS,aAAa,OAIe;CACnC,IAAI,MAAM,KAAK,KAAK,WAAW,GAC7B;CAEF,OAAO,0BAA0B;EAC/B,SAAS,MAAM;EACf,MAAM,MAAM,KAAK;EACjB,SAAS,qBAAqB,MAAM,KAAK,KAAK,mCAAmC,MAAM,MAAM;CAC/F,CAAC;AACH;AAEA,SAAS,qBAAqB,KAAiC;CAC7D,MAAM,UAAU,IAAI,KAAK;CACzB,IAAI,CAAC,UAAU,KAAK,OAAO,GACzB;CAEF,MAAM,QAAQ,OAAO,OAAO;CAC5B,IAAI,CAAC,OAAO,UAAU,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BAAkB;CAC/B,CAAC,QAAQ,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;;;AC5TA,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 {\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,MAAM;EACd;CACF;AACF;AAEA,SAAS,mBACP,IACA,QACsB;CACtB,OAAO;EACL,IAAI;EACJ,OAAO;GACL,MAAM;GACN,WAAW;IACT,MAAM;IACN;IACA,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;GAC7B;EACF;CACF;AACF;AAEA,SAAS,qBAA2C;CAClD,OAAO;EACL,IAAI;EACJ,OAAO;GACL,MAAM;GACN,cAAc;IAAE,MAAM;IAAY,YAAY;GAAkB;EAClE;CACF;AACF;AAEA,SAAS,WAAiC;CACxC,OAAO;EACL,IAAI;EACJ,OAAO;GACL,MAAM;GACN,cAAc;IAAE,MAAM;IAAY,YAAY;GAAQ;EACxD;CACF;AACF;AAEA,SAAS,YAAkC;CACzC,OAAO,mBAAmB,MAAM;AAClC;AAEA,SAAS,UAAU,OAGM;CACvB,OAAO,MAAM,KAAK,KAAK,eAAe,IAClC,mBAAmB,QAAQ,IAC3B,mBAAmB,QAAQ;AACjC;AAEA,SAAS,YAAkC;CACzC,OAAO,mBAAmB,OAAO;AACnC;AAEA,S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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"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-postgres",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.76",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.14.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.14.0-dev.
|
|
10
|
-
"@prisma-next/errors": "0.14.0-dev.
|
|
11
|
-
"@prisma-next/family-sql": "0.14.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.14.0-dev.
|
|
13
|
-
"@prisma-next/ids": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/sql-contract
|
|
16
|
-
"@prisma-next/sql-contract-
|
|
17
|
-
"@prisma-next/sql-
|
|
18
|
-
"@prisma-next/sql-
|
|
19
|
-
"@prisma-next/sql-
|
|
20
|
-
"@prisma-next/sql-
|
|
21
|
-
"@prisma-next/
|
|
22
|
-
"@prisma-next/
|
|
8
|
+
"@prisma-next/contract": "0.14.0-dev.76",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.14.0-dev.76",
|
|
10
|
+
"@prisma-next/errors": "0.14.0-dev.76",
|
|
11
|
+
"@prisma-next/family-sql": "0.14.0-dev.76",
|
|
12
|
+
"@prisma-next/framework-components": "0.14.0-dev.76",
|
|
13
|
+
"@prisma-next/ids": "0.14.0-dev.76",
|
|
14
|
+
"@prisma-next/psl-parser": "0.14.0-dev.76",
|
|
15
|
+
"@prisma-next/sql-contract": "0.14.0-dev.76",
|
|
16
|
+
"@prisma-next/sql-contract-psl": "0.14.0-dev.76",
|
|
17
|
+
"@prisma-next/sql-contract-ts": "0.14.0-dev.76",
|
|
18
|
+
"@prisma-next/sql-operations": "0.14.0-dev.76",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.76",
|
|
20
|
+
"@prisma-next/sql-runtime": "0.14.0-dev.76",
|
|
21
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.76",
|
|
22
|
+
"@prisma-next/target-postgres": "0.14.0-dev.76",
|
|
23
|
+
"@prisma-next/utils": "0.14.0-dev.76",
|
|
23
24
|
"arktype": "^2.2.2"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@prisma-next/cli": "0.14.0-dev.
|
|
27
|
-
"@prisma-next/driver-postgres": "0.14.0-dev.
|
|
28
|
-
"@prisma-next/migration-tools": "0.14.0-dev.
|
|
29
|
-
"@prisma-next/
|
|
30
|
-
"@prisma-next/
|
|
31
|
-
"@prisma-next/
|
|
32
|
-
"@prisma-next/tsdown": "0.14.0-dev.74",
|
|
27
|
+
"@prisma-next/cli": "0.14.0-dev.76",
|
|
28
|
+
"@prisma-next/driver-postgres": "0.14.0-dev.76",
|
|
29
|
+
"@prisma-next/migration-tools": "0.14.0-dev.76",
|
|
30
|
+
"@prisma-next/test-utils": "0.14.0-dev.76",
|
|
31
|
+
"@prisma-next/tsconfig": "0.14.0-dev.76",
|
|
32
|
+
"@prisma-next/tsdown": "0.14.0-dev.76",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"tsdown": "0.22.3",
|
|
35
35
|
"typescript": "5.9.3",
|
|
@@ -5,16 +5,18 @@ import type {
|
|
|
5
5
|
DefaultFunctionLoweringContext,
|
|
6
6
|
LoweredDefaultResult,
|
|
7
7
|
MutationDefaultGeneratorDescriptor,
|
|
8
|
-
|
|
8
|
+
TypedDefaultFunctionCall,
|
|
9
9
|
} from '@prisma-next/framework-components/control';
|
|
10
10
|
import {
|
|
11
11
|
builtinGeneratorRegistryMetadata,
|
|
12
12
|
resolveBuiltinGeneratedColumnDescriptor,
|
|
13
13
|
} from '@prisma-next/ids';
|
|
14
|
+
import type { FuncCallSig } from '@prisma-next/psl-parser';
|
|
15
|
+
import { int, num, oneOf, optional, str } from '@prisma-next/psl-parser';
|
|
14
16
|
|
|
15
17
|
function invalidArgumentDiagnostic(input: {
|
|
16
18
|
readonly context: DefaultFunctionLoweringContext;
|
|
17
|
-
readonly span:
|
|
19
|
+
readonly span: TypedDefaultFunctionCall['span'];
|
|
18
20
|
readonly message: string;
|
|
19
21
|
}): LoweredDefaultResult {
|
|
20
22
|
return {
|
|
@@ -45,218 +47,62 @@ function executionGenerator(
|
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
function
|
|
49
|
-
readonly call: ParsedDefaultFunctionCall;
|
|
50
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
51
|
-
readonly usage: string;
|
|
52
|
-
}): LoweredDefaultResult | undefined {
|
|
53
|
-
if (input.call.args.length === 0) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return invalidArgumentDiagnostic({
|
|
57
|
-
context: input.context,
|
|
58
|
-
span: input.call.span,
|
|
59
|
-
message: `Default function "${input.call.name}" does not accept arguments. Use ${input.usage}.`,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function parseIntegerArgument(raw: string): number | undefined {
|
|
64
|
-
const trimmed = raw.trim();
|
|
65
|
-
if (!/^-?\d+$/.test(trimmed)) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
const value = Number(trimmed);
|
|
69
|
-
if (!Number.isInteger(value)) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function parseStringLiteral(raw: string): string | undefined {
|
|
76
|
-
const match = raw.trim().match(/^(['"])(.*)\1$/s);
|
|
77
|
-
if (!match) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
return match[2] ?? '';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function lowerAutoincrement(input: {
|
|
84
|
-
readonly call: ParsedDefaultFunctionCall;
|
|
85
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
86
|
-
}): LoweredDefaultResult {
|
|
87
|
-
const maybeNoArgs = expectNoArgs({
|
|
88
|
-
call: input.call,
|
|
89
|
-
context: input.context,
|
|
90
|
-
usage: '`autoincrement()`',
|
|
91
|
-
});
|
|
92
|
-
if (maybeNoArgs) {
|
|
93
|
-
return maybeNoArgs;
|
|
94
|
-
}
|
|
50
|
+
function lowerAutoincrement(): LoweredDefaultResult {
|
|
95
51
|
return {
|
|
96
52
|
ok: true,
|
|
97
53
|
value: {
|
|
98
54
|
kind: 'storage',
|
|
99
|
-
defaultValue: {
|
|
100
|
-
kind: 'function',
|
|
101
|
-
expression: 'autoincrement()',
|
|
102
|
-
},
|
|
55
|
+
defaultValue: { kind: 'function', expression: 'autoincrement()' },
|
|
103
56
|
},
|
|
104
57
|
};
|
|
105
58
|
}
|
|
106
59
|
|
|
107
|
-
function lowerNow(
|
|
108
|
-
readonly call: ParsedDefaultFunctionCall;
|
|
109
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
110
|
-
}): LoweredDefaultResult {
|
|
111
|
-
const maybeNoArgs = expectNoArgs({
|
|
112
|
-
call: input.call,
|
|
113
|
-
context: input.context,
|
|
114
|
-
usage: '`now()`',
|
|
115
|
-
});
|
|
116
|
-
if (maybeNoArgs) {
|
|
117
|
-
return maybeNoArgs;
|
|
118
|
-
}
|
|
60
|
+
function lowerNow(): LoweredDefaultResult {
|
|
119
61
|
return {
|
|
120
62
|
ok: true,
|
|
121
63
|
value: {
|
|
122
64
|
kind: 'storage',
|
|
123
|
-
defaultValue: {
|
|
124
|
-
kind: 'function',
|
|
125
|
-
expression: 'now()',
|
|
126
|
-
},
|
|
65
|
+
defaultValue: { kind: 'function', expression: 'now()' },
|
|
127
66
|
},
|
|
128
67
|
};
|
|
129
68
|
}
|
|
130
69
|
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
134
|
-
}): LoweredDefaultResult {
|
|
135
|
-
if (input.call.args.length === 0) {
|
|
136
|
-
return executionGenerator('uuidv4');
|
|
137
|
-
}
|
|
138
|
-
if (input.call.args.length !== 1) {
|
|
139
|
-
return invalidArgumentDiagnostic({
|
|
140
|
-
context: input.context,
|
|
141
|
-
span: input.call.span,
|
|
142
|
-
message:
|
|
143
|
-
'Default function "uuid" accepts at most one version argument: `uuid()`, `uuid(4)`, or `uuid(7)`.',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const version = parseIntegerArgument(input.call.args[0]?.raw ?? '');
|
|
147
|
-
if (version === 4) {
|
|
148
|
-
return executionGenerator('uuidv4');
|
|
149
|
-
}
|
|
150
|
-
if (version === 7) {
|
|
151
|
-
return executionGenerator('uuidv7');
|
|
152
|
-
}
|
|
153
|
-
return invalidArgumentDiagnostic({
|
|
154
|
-
context: input.context,
|
|
155
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
156
|
-
message:
|
|
157
|
-
'Default function "uuid" supports only `uuid()`, `uuid(4)`, or `uuid(7)` in SQL PSL provider v1.',
|
|
158
|
-
});
|
|
70
|
+
function lowerUlid(): LoweredDefaultResult {
|
|
71
|
+
return executionGenerator('ulid');
|
|
159
72
|
}
|
|
160
73
|
|
|
161
|
-
function
|
|
162
|
-
readonly call:
|
|
74
|
+
function lowerUuid(input: {
|
|
75
|
+
readonly call: TypedDefaultFunctionCall;
|
|
163
76
|
readonly context: DefaultFunctionLoweringContext;
|
|
164
77
|
}): LoweredDefaultResult {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
diagnostic: {
|
|
169
|
-
code: 'PSL_UNKNOWN_DEFAULT_FUNCTION',
|
|
170
|
-
message:
|
|
171
|
-
'Default function "cuid()" is not supported in SQL PSL provider v1. Use `cuid(2)` instead.',
|
|
172
|
-
sourceId: input.context.sourceId,
|
|
173
|
-
span: input.call.span,
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
if (input.call.args.length !== 1) {
|
|
178
|
-
return invalidArgumentDiagnostic({
|
|
179
|
-
context: input.context,
|
|
180
|
-
span: input.call.span,
|
|
181
|
-
message: 'Default function "cuid" accepts exactly one version argument: `cuid(2)`.',
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
const version = parseIntegerArgument(input.call.args[0]?.raw ?? '');
|
|
185
|
-
if (version === 2) {
|
|
186
|
-
return executionGenerator('cuid2');
|
|
187
|
-
}
|
|
188
|
-
return invalidArgumentDiagnostic({
|
|
189
|
-
context: input.context,
|
|
190
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
191
|
-
message: 'Default function "cuid" supports only `cuid(2)` in SQL PSL provider v1.',
|
|
192
|
-
});
|
|
78
|
+
return input.call.args['version'] === 7
|
|
79
|
+
? executionGenerator('uuidv7')
|
|
80
|
+
: executionGenerator('uuidv4');
|
|
193
81
|
}
|
|
194
82
|
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
readonly context: DefaultFunctionLoweringContext;
|
|
198
|
-
}): LoweredDefaultResult {
|
|
199
|
-
const maybeNoArgs = expectNoArgs({
|
|
200
|
-
call: input.call,
|
|
201
|
-
context: input.context,
|
|
202
|
-
usage: '`ulid()`',
|
|
203
|
-
});
|
|
204
|
-
if (maybeNoArgs) {
|
|
205
|
-
return maybeNoArgs;
|
|
206
|
-
}
|
|
207
|
-
return executionGenerator('ulid');
|
|
83
|
+
function lowerCuid(): LoweredDefaultResult {
|
|
84
|
+
return executionGenerator('cuid2');
|
|
208
85
|
}
|
|
209
86
|
|
|
210
87
|
function lowerNanoid(input: {
|
|
211
|
-
readonly call:
|
|
88
|
+
readonly call: TypedDefaultFunctionCall;
|
|
212
89
|
readonly context: DefaultFunctionLoweringContext;
|
|
213
90
|
}): LoweredDefaultResult {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return invalidArgumentDiagnostic({
|
|
219
|
-
context: input.context,
|
|
220
|
-
span: input.call.span,
|
|
221
|
-
message:
|
|
222
|
-
'Default function "nanoid" accepts at most one size argument: `nanoid()` or `nanoid(<2-255>)`.',
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
const size = parseIntegerArgument(input.call.args[0]?.raw ?? '');
|
|
226
|
-
if (size !== undefined && size >= 2 && size <= 255) {
|
|
227
|
-
return executionGenerator('nanoid', { size });
|
|
228
|
-
}
|
|
229
|
-
return invalidArgumentDiagnostic({
|
|
230
|
-
context: input.context,
|
|
231
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
232
|
-
message: 'Default function "nanoid" size argument must be an integer between 2 and 255.',
|
|
233
|
-
});
|
|
91
|
+
const size = input.call.args['size'];
|
|
92
|
+
return typeof size === 'number'
|
|
93
|
+
? executionGenerator('nanoid', { size })
|
|
94
|
+
: executionGenerator('nanoid');
|
|
234
95
|
}
|
|
235
96
|
|
|
236
97
|
function lowerDbgenerated(input: {
|
|
237
|
-
readonly call:
|
|
98
|
+
readonly call: TypedDefaultFunctionCall;
|
|
238
99
|
readonly context: DefaultFunctionLoweringContext;
|
|
239
100
|
}): LoweredDefaultResult {
|
|
240
|
-
|
|
101
|
+
const expression = input.call.args['expression'];
|
|
102
|
+
if (typeof expression !== 'string' || expression.trim().length === 0) {
|
|
241
103
|
return invalidArgumentDiagnostic({
|
|
242
104
|
context: input.context,
|
|
243
105
|
span: input.call.span,
|
|
244
|
-
message:
|
|
245
|
-
'Default function "dbgenerated" requires exactly one string argument: `dbgenerated("...")`.',
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const rawExpression = parseStringLiteral(input.call.args[0]?.raw ?? '');
|
|
249
|
-
if (rawExpression === undefined) {
|
|
250
|
-
return invalidArgumentDiagnostic({
|
|
251
|
-
context: input.context,
|
|
252
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
253
|
-
message: 'Default function "dbgenerated" argument must be a string literal.',
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (rawExpression.trim().length === 0) {
|
|
257
|
-
return invalidArgumentDiagnostic({
|
|
258
|
-
context: input.context,
|
|
259
|
-
span: input.call.args[0]?.span ?? input.call.span,
|
|
260
106
|
message: 'Default function "dbgenerated" argument cannot be empty.',
|
|
261
107
|
});
|
|
262
108
|
}
|
|
@@ -264,22 +110,47 @@ function lowerDbgenerated(input: {
|
|
|
264
110
|
ok: true,
|
|
265
111
|
value: {
|
|
266
112
|
kind: 'storage',
|
|
267
|
-
defaultValue: {
|
|
268
|
-
kind: 'function',
|
|
269
|
-
expression: rawExpression,
|
|
270
|
-
},
|
|
113
|
+
defaultValue: { kind: 'function', expression },
|
|
271
114
|
},
|
|
272
115
|
};
|
|
273
116
|
}
|
|
274
117
|
|
|
118
|
+
const nowSig: FuncCallSig = {};
|
|
119
|
+
const autoincrementSig: FuncCallSig = {};
|
|
120
|
+
const ulidSig: FuncCallSig = {};
|
|
121
|
+
const uuidSig: FuncCallSig = {
|
|
122
|
+
positional: [{ key: 'version', type: optional(oneOf(num(4), num(7))) }],
|
|
123
|
+
};
|
|
124
|
+
const cuidSig: FuncCallSig = { positional: [{ key: 'version', type: num(2) }] };
|
|
125
|
+
const nanoidSig: FuncCallSig = {
|
|
126
|
+
positional: [{ key: 'size', type: optional(int({ min: 2, max: 255 })) }],
|
|
127
|
+
};
|
|
128
|
+
const dbgeneratedSig: FuncCallSig = { positional: [{ key: 'expression', type: str() }] };
|
|
129
|
+
|
|
275
130
|
const postgresDefaultFunctionRegistryEntries = [
|
|
276
|
-
[
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
131
|
+
[
|
|
132
|
+
'autoincrement',
|
|
133
|
+
{
|
|
134
|
+
signature: autoincrementSig,
|
|
135
|
+
lower: lowerAutoincrement,
|
|
136
|
+
usageSignatures: ['autoincrement()'],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
['now', { signature: nowSig, lower: lowerNow, usageSignatures: ['now()'] }],
|
|
140
|
+
[
|
|
141
|
+
'uuid',
|
|
142
|
+
{ signature: uuidSig, lower: lowerUuid, usageSignatures: ['uuid()', 'uuid(4)', 'uuid(7)'] },
|
|
143
|
+
],
|
|
144
|
+
['cuid', { signature: cuidSig, lower: lowerCuid, usageSignatures: ['cuid(2)'] }],
|
|
145
|
+
['ulid', { signature: ulidSig, lower: lowerUlid, usageSignatures: ['ulid()'] }],
|
|
146
|
+
[
|
|
147
|
+
'nanoid',
|
|
148
|
+
{ signature: nanoidSig, lower: lowerNanoid, usageSignatures: ['nanoid()', 'nanoid(<2-255>)'] },
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
'dbgenerated',
|
|
152
|
+
{ signature: dbgeneratedSig, lower: lowerDbgenerated, usageSignatures: ['dbgenerated("...")'] },
|
|
153
|
+
],
|
|
283
154
|
] satisfies ReadonlyArray<readonly [string, ControlMutationDefaultEntry]>;
|
|
284
155
|
|
|
285
156
|
const postgresScalarTypeDescriptors = new Map<string, string>([
|