@prisma/client-engine-runtime 6.6.0-dev.70 → 6.6.0-dev.72
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/QueryPlan.d.ts +9 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +114 -19
- package/dist/index.mjs +113 -19
- package/dist/interpreter/generators.d.ts +21 -0
- package/dist/interpreter/generators.test.d.ts +1 -0
- package/dist/interpreter/renderQuery.d.ts +2 -1
- package/package.json +8 -3
package/dist/QueryPlan.d.ts
CHANGED
|
@@ -6,7 +6,15 @@ export type PrismaValuePlaceholder = {
|
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
|
|
9
|
-
export type
|
|
9
|
+
export type PrismaValueGenerator = {
|
|
10
|
+
prisma__type: 'generatorCall';
|
|
11
|
+
prisma__value: {
|
|
12
|
+
name: string;
|
|
13
|
+
args: PrismaValue[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
|
|
17
|
+
export type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder | PrismaValueGenerator;
|
|
10
18
|
export type QueryPlanBinding = {
|
|
11
19
|
name: string;
|
|
12
20
|
expr: QueryPlanNode;
|
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,8 @@ export declare type Fragment = {
|
|
|
12
12
|
type: 'parameterTuple';
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
|
|
16
|
+
|
|
15
17
|
export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
|
|
16
18
|
|
|
17
19
|
export declare type JoinExpression = {
|
|
@@ -25,7 +27,15 @@ export declare interface PlaceholderFormat {
|
|
|
25
27
|
hasNumbering: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder;
|
|
30
|
+
export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder | PrismaValueGenerator;
|
|
31
|
+
|
|
32
|
+
export declare type PrismaValueGenerator = {
|
|
33
|
+
prisma__type: 'generatorCall';
|
|
34
|
+
prisma__value: {
|
|
35
|
+
name: string;
|
|
36
|
+
args: PrismaValue[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
29
39
|
|
|
30
40
|
export declare type PrismaValuePlaceholder = {
|
|
31
41
|
prisma__type: 'param';
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare type Fragment = {
|
|
|
12
12
|
type: 'parameterTuple';
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
|
|
16
|
+
|
|
15
17
|
export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
|
|
16
18
|
|
|
17
19
|
export declare type JoinExpression = {
|
|
@@ -25,7 +27,15 @@ export declare interface PlaceholderFormat {
|
|
|
25
27
|
hasNumbering: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder;
|
|
30
|
+
export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder | PrismaValueGenerator;
|
|
31
|
+
|
|
32
|
+
export declare type PrismaValueGenerator = {
|
|
33
|
+
prisma__type: 'generatorCall';
|
|
34
|
+
prisma__value: {
|
|
35
|
+
name: string;
|
|
36
|
+
args: PrismaValue[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
29
39
|
|
|
30
40
|
export declare type PrismaValuePlaceholder = {
|
|
31
41
|
prisma__type: 'param';
|
package/dist/index.js
CHANGED
|
@@ -33,14 +33,95 @@ __export(index_exports, {
|
|
|
33
33
|
QueryInterpreter: () => QueryInterpreter,
|
|
34
34
|
TransactionManager: () => TransactionManager,
|
|
35
35
|
TransactionManagerError: () => TransactionManagerError,
|
|
36
|
+
isPrismaValueGenerator: () => isPrismaValueGenerator,
|
|
36
37
|
isPrismaValuePlaceholder: () => isPrismaValuePlaceholder
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
40
|
|
|
41
|
+
// src/interpreter/generators.ts
|
|
42
|
+
var import_cuid = __toESM(require("@bugsnag/cuid"));
|
|
43
|
+
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
44
|
+
var import_nanoid = require("nanoid");
|
|
45
|
+
var import_ulid = require("ulid");
|
|
46
|
+
var import_uuid = require("uuid");
|
|
47
|
+
var GeneratorRegistry = class {
|
|
48
|
+
#generators = {};
|
|
49
|
+
constructor() {
|
|
50
|
+
this.register("now", new NowGenerator());
|
|
51
|
+
this.register("uuid", new UuidGenerator());
|
|
52
|
+
this.register("cuid", new CuidGenerator());
|
|
53
|
+
this.register("ulid", new UlidGenerator());
|
|
54
|
+
this.register("nanoid", new NanoIdGenerator());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns a snapshot of the generator registry. It's 'frozen' in time at the moment of this
|
|
58
|
+
* method being called, meaning that the built-in time-based generators will always return
|
|
59
|
+
* the same value on repeated calls as long as the same snapshot is used.
|
|
60
|
+
*/
|
|
61
|
+
snapshot() {
|
|
62
|
+
return Object.create(this.#generators, {
|
|
63
|
+
now: { value: new NowGenerator() }
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Registers a new generator with the given name.
|
|
68
|
+
*/
|
|
69
|
+
register(name, generator) {
|
|
70
|
+
this.#generators[name] = generator;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var NowGenerator = class {
|
|
74
|
+
#now = /* @__PURE__ */ new Date();
|
|
75
|
+
generate() {
|
|
76
|
+
return this.#now.toISOString();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var UuidGenerator = class {
|
|
80
|
+
generate(arg) {
|
|
81
|
+
if (arg === 4) {
|
|
82
|
+
return (0, import_uuid.v4)();
|
|
83
|
+
} else if (arg === 7) {
|
|
84
|
+
return (0, import_uuid.v7)();
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error("Invalid UUID generator arguments");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var CuidGenerator = class {
|
|
91
|
+
generate(arg) {
|
|
92
|
+
if (arg === 1) {
|
|
93
|
+
return (0, import_cuid.default)();
|
|
94
|
+
} else if (arg === 2) {
|
|
95
|
+
return (0, import_cuid2.createId)();
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error("Invalid CUID generator arguments");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var UlidGenerator = class {
|
|
102
|
+
generate() {
|
|
103
|
+
return (0, import_ulid.ulid)();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var NanoIdGenerator = class {
|
|
107
|
+
generate(arg) {
|
|
108
|
+
if (typeof arg === "number") {
|
|
109
|
+
return (0, import_nanoid.nanoid)(arg);
|
|
110
|
+
} else if (arg === void 0) {
|
|
111
|
+
return (0, import_nanoid.nanoid)();
|
|
112
|
+
} else {
|
|
113
|
+
throw new Error("Invalid Nanoid generator arguments");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
40
118
|
// src/QueryPlan.ts
|
|
41
119
|
function isPrismaValuePlaceholder(value) {
|
|
42
120
|
return typeof value === "object" && value !== null && value["prisma__type"] === "param";
|
|
43
121
|
}
|
|
122
|
+
function isPrismaValueGenerator(value) {
|
|
123
|
+
return typeof value === "object" && value !== null && value["prisma__type"] === "generatorCall";
|
|
124
|
+
}
|
|
44
125
|
|
|
45
126
|
// src/utils.ts
|
|
46
127
|
function assertNever(_, message) {
|
|
@@ -48,19 +129,31 @@ function assertNever(_, message) {
|
|
|
48
129
|
}
|
|
49
130
|
|
|
50
131
|
// src/interpreter/renderQuery.ts
|
|
51
|
-
function renderQuery(dbQuery, scope) {
|
|
132
|
+
function renderQuery(dbQuery, scope, generators) {
|
|
52
133
|
const queryType = dbQuery.type;
|
|
53
134
|
switch (queryType) {
|
|
54
135
|
case "rawSql":
|
|
55
|
-
return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope));
|
|
136
|
+
return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope, generators));
|
|
56
137
|
case "templateSql":
|
|
57
|
-
return renderTemplateSql(
|
|
138
|
+
return renderTemplateSql(
|
|
139
|
+
dbQuery.fragments,
|
|
140
|
+
dbQuery.placeholderFormat,
|
|
141
|
+
substituteParams(dbQuery.params, scope, generators)
|
|
142
|
+
);
|
|
58
143
|
default:
|
|
59
144
|
assertNever(queryType, `Invalid query type`);
|
|
60
145
|
}
|
|
61
146
|
}
|
|
62
|
-
function substituteParams(params, scope) {
|
|
147
|
+
function substituteParams(params, scope, generators) {
|
|
63
148
|
return params.map((param) => {
|
|
149
|
+
if (isPrismaValueGenerator(param)) {
|
|
150
|
+
const { name, args } = param.prisma__value;
|
|
151
|
+
const generator = generators[name];
|
|
152
|
+
if (!generator) {
|
|
153
|
+
throw new Error(`Encountered an unknown generator '${name}'`);
|
|
154
|
+
}
|
|
155
|
+
return generator.generate(...args);
|
|
156
|
+
}
|
|
64
157
|
if (!isPrismaValuePlaceholder(param)) {
|
|
65
158
|
return param;
|
|
66
159
|
}
|
|
@@ -184,18 +277,19 @@ var QueryInterpreter = class {
|
|
|
184
277
|
#queryable;
|
|
185
278
|
#placeholderValues;
|
|
186
279
|
#onQuery;
|
|
280
|
+
#generators = new GeneratorRegistry();
|
|
187
281
|
constructor({ queryable, placeholderValues, onQuery }) {
|
|
188
282
|
this.#queryable = queryable;
|
|
189
283
|
this.#placeholderValues = placeholderValues;
|
|
190
284
|
this.#onQuery = onQuery;
|
|
191
285
|
}
|
|
192
286
|
async run(queryPlan) {
|
|
193
|
-
return this.interpretNode(queryPlan, this.#placeholderValues);
|
|
287
|
+
return this.interpretNode(queryPlan, this.#placeholderValues, this.#generators.snapshot());
|
|
194
288
|
}
|
|
195
|
-
async interpretNode(node, scope) {
|
|
289
|
+
async interpretNode(node, scope, generators) {
|
|
196
290
|
switch (node.type) {
|
|
197
291
|
case "seq": {
|
|
198
|
-
const results = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
292
|
+
const results = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
199
293
|
return results[results.length - 1];
|
|
200
294
|
}
|
|
201
295
|
case "get": {
|
|
@@ -205,10 +299,10 @@ var QueryInterpreter = class {
|
|
|
205
299
|
const nestedScope = Object.create(scope);
|
|
206
300
|
await Promise.all(
|
|
207
301
|
node.args.bindings.map(async (binding) => {
|
|
208
|
-
nestedScope[binding.name] = await this.interpretNode(binding.expr, scope);
|
|
302
|
+
nestedScope[binding.name] = await this.interpretNode(binding.expr, scope, generators);
|
|
209
303
|
})
|
|
210
304
|
);
|
|
211
|
-
return this.interpretNode(node.args.expr, nestedScope);
|
|
305
|
+
return this.interpretNode(node.args.expr, nestedScope, generators);
|
|
212
306
|
}
|
|
213
307
|
case "getFirstNonEmpty": {
|
|
214
308
|
for (const name of node.args.names) {
|
|
@@ -220,31 +314,31 @@ var QueryInterpreter = class {
|
|
|
220
314
|
return [];
|
|
221
315
|
}
|
|
222
316
|
case "concat": {
|
|
223
|
-
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
317
|
+
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
224
318
|
return parts.reduce((acc, part) => acc.concat(asList(part)), []);
|
|
225
319
|
}
|
|
226
320
|
case "sum": {
|
|
227
|
-
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
321
|
+
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
228
322
|
return parts.reduce((acc, part) => asNumber(acc) + asNumber(part));
|
|
229
323
|
}
|
|
230
324
|
case "execute": {
|
|
231
|
-
const query = renderQuery(node.args, scope);
|
|
325
|
+
const query = renderQuery(node.args, scope, generators);
|
|
232
326
|
return this.#withQueryEvent(query, async () => {
|
|
233
327
|
return await this.#queryable.executeRaw(query);
|
|
234
328
|
});
|
|
235
329
|
}
|
|
236
330
|
case "query": {
|
|
237
|
-
const query = renderQuery(node.args, scope);
|
|
331
|
+
const query = renderQuery(node.args, scope, generators);
|
|
238
332
|
return this.#withQueryEvent(query, async () => {
|
|
239
333
|
return serialize(await this.#queryable.queryRaw(query));
|
|
240
334
|
});
|
|
241
335
|
}
|
|
242
336
|
case "reverse": {
|
|
243
|
-
const value = await this.interpretNode(node.args, scope);
|
|
337
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
244
338
|
return Array.isArray(value) ? value.reverse() : value;
|
|
245
339
|
}
|
|
246
340
|
case "unique": {
|
|
247
|
-
const value = await this.interpretNode(node.args, scope);
|
|
341
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
248
342
|
if (!Array.isArray(value)) {
|
|
249
343
|
return value;
|
|
250
344
|
}
|
|
@@ -254,22 +348,22 @@ var QueryInterpreter = class {
|
|
|
254
348
|
return value[0] ?? null;
|
|
255
349
|
}
|
|
256
350
|
case "required": {
|
|
257
|
-
const value = await this.interpretNode(node.args, scope);
|
|
351
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
258
352
|
if (isEmpty(value)) {
|
|
259
353
|
throw new Error("Required value is empty");
|
|
260
354
|
}
|
|
261
355
|
return value;
|
|
262
356
|
}
|
|
263
357
|
case "mapField": {
|
|
264
|
-
const value = await this.interpretNode(node.args.records, scope);
|
|
358
|
+
const value = await this.interpretNode(node.args.records, scope, generators);
|
|
265
359
|
return mapField(value, node.args.field);
|
|
266
360
|
}
|
|
267
361
|
case "join": {
|
|
268
|
-
const parent = await this.interpretNode(node.args.parent, scope);
|
|
362
|
+
const parent = await this.interpretNode(node.args.parent, scope, generators);
|
|
269
363
|
const children = await Promise.all(
|
|
270
364
|
node.args.children.map(async (joinExpr) => ({
|
|
271
365
|
joinExpr,
|
|
272
|
-
childRecords: await this.interpretNode(joinExpr.child, scope)
|
|
366
|
+
childRecords: await this.interpretNode(joinExpr.child, scope, generators)
|
|
273
367
|
}))
|
|
274
368
|
);
|
|
275
369
|
if (Array.isArray(parent)) {
|
|
@@ -585,5 +679,6 @@ var TransactionManager = class {
|
|
|
585
679
|
QueryInterpreter,
|
|
586
680
|
TransactionManager,
|
|
587
681
|
TransactionManagerError,
|
|
682
|
+
isPrismaValueGenerator,
|
|
588
683
|
isPrismaValuePlaceholder
|
|
589
684
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,87 @@
|
|
|
1
|
+
// src/interpreter/generators.ts
|
|
2
|
+
import cuid1 from "@bugsnag/cuid";
|
|
3
|
+
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
4
|
+
import { nanoid } from "nanoid";
|
|
5
|
+
import { ulid } from "ulid";
|
|
6
|
+
import { v4 as uuidv4, v7 as uuidv7 } from "uuid";
|
|
7
|
+
var GeneratorRegistry = class {
|
|
8
|
+
#generators = {};
|
|
9
|
+
constructor() {
|
|
10
|
+
this.register("now", new NowGenerator());
|
|
11
|
+
this.register("uuid", new UuidGenerator());
|
|
12
|
+
this.register("cuid", new CuidGenerator());
|
|
13
|
+
this.register("ulid", new UlidGenerator());
|
|
14
|
+
this.register("nanoid", new NanoIdGenerator());
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a snapshot of the generator registry. It's 'frozen' in time at the moment of this
|
|
18
|
+
* method being called, meaning that the built-in time-based generators will always return
|
|
19
|
+
* the same value on repeated calls as long as the same snapshot is used.
|
|
20
|
+
*/
|
|
21
|
+
snapshot() {
|
|
22
|
+
return Object.create(this.#generators, {
|
|
23
|
+
now: { value: new NowGenerator() }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Registers a new generator with the given name.
|
|
28
|
+
*/
|
|
29
|
+
register(name, generator) {
|
|
30
|
+
this.#generators[name] = generator;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var NowGenerator = class {
|
|
34
|
+
#now = /* @__PURE__ */ new Date();
|
|
35
|
+
generate() {
|
|
36
|
+
return this.#now.toISOString();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var UuidGenerator = class {
|
|
40
|
+
generate(arg) {
|
|
41
|
+
if (arg === 4) {
|
|
42
|
+
return uuidv4();
|
|
43
|
+
} else if (arg === 7) {
|
|
44
|
+
return uuidv7();
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error("Invalid UUID generator arguments");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var CuidGenerator = class {
|
|
51
|
+
generate(arg) {
|
|
52
|
+
if (arg === 1) {
|
|
53
|
+
return cuid1();
|
|
54
|
+
} else if (arg === 2) {
|
|
55
|
+
return cuid2();
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error("Invalid CUID generator arguments");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var UlidGenerator = class {
|
|
62
|
+
generate() {
|
|
63
|
+
return ulid();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var NanoIdGenerator = class {
|
|
67
|
+
generate(arg) {
|
|
68
|
+
if (typeof arg === "number") {
|
|
69
|
+
return nanoid(arg);
|
|
70
|
+
} else if (arg === void 0) {
|
|
71
|
+
return nanoid();
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error("Invalid Nanoid generator arguments");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
1
78
|
// src/QueryPlan.ts
|
|
2
79
|
function isPrismaValuePlaceholder(value) {
|
|
3
80
|
return typeof value === "object" && value !== null && value["prisma__type"] === "param";
|
|
4
81
|
}
|
|
82
|
+
function isPrismaValueGenerator(value) {
|
|
83
|
+
return typeof value === "object" && value !== null && value["prisma__type"] === "generatorCall";
|
|
84
|
+
}
|
|
5
85
|
|
|
6
86
|
// src/utils.ts
|
|
7
87
|
function assertNever(_, message) {
|
|
@@ -9,19 +89,31 @@ function assertNever(_, message) {
|
|
|
9
89
|
}
|
|
10
90
|
|
|
11
91
|
// src/interpreter/renderQuery.ts
|
|
12
|
-
function renderQuery(dbQuery, scope) {
|
|
92
|
+
function renderQuery(dbQuery, scope, generators) {
|
|
13
93
|
const queryType = dbQuery.type;
|
|
14
94
|
switch (queryType) {
|
|
15
95
|
case "rawSql":
|
|
16
|
-
return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope));
|
|
96
|
+
return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope, generators));
|
|
17
97
|
case "templateSql":
|
|
18
|
-
return renderTemplateSql(
|
|
98
|
+
return renderTemplateSql(
|
|
99
|
+
dbQuery.fragments,
|
|
100
|
+
dbQuery.placeholderFormat,
|
|
101
|
+
substituteParams(dbQuery.params, scope, generators)
|
|
102
|
+
);
|
|
19
103
|
default:
|
|
20
104
|
assertNever(queryType, `Invalid query type`);
|
|
21
105
|
}
|
|
22
106
|
}
|
|
23
|
-
function substituteParams(params, scope) {
|
|
107
|
+
function substituteParams(params, scope, generators) {
|
|
24
108
|
return params.map((param) => {
|
|
109
|
+
if (isPrismaValueGenerator(param)) {
|
|
110
|
+
const { name, args } = param.prisma__value;
|
|
111
|
+
const generator = generators[name];
|
|
112
|
+
if (!generator) {
|
|
113
|
+
throw new Error(`Encountered an unknown generator '${name}'`);
|
|
114
|
+
}
|
|
115
|
+
return generator.generate(...args);
|
|
116
|
+
}
|
|
25
117
|
if (!isPrismaValuePlaceholder(param)) {
|
|
26
118
|
return param;
|
|
27
119
|
}
|
|
@@ -145,18 +237,19 @@ var QueryInterpreter = class {
|
|
|
145
237
|
#queryable;
|
|
146
238
|
#placeholderValues;
|
|
147
239
|
#onQuery;
|
|
240
|
+
#generators = new GeneratorRegistry();
|
|
148
241
|
constructor({ queryable, placeholderValues, onQuery }) {
|
|
149
242
|
this.#queryable = queryable;
|
|
150
243
|
this.#placeholderValues = placeholderValues;
|
|
151
244
|
this.#onQuery = onQuery;
|
|
152
245
|
}
|
|
153
246
|
async run(queryPlan) {
|
|
154
|
-
return this.interpretNode(queryPlan, this.#placeholderValues);
|
|
247
|
+
return this.interpretNode(queryPlan, this.#placeholderValues, this.#generators.snapshot());
|
|
155
248
|
}
|
|
156
|
-
async interpretNode(node, scope) {
|
|
249
|
+
async interpretNode(node, scope, generators) {
|
|
157
250
|
switch (node.type) {
|
|
158
251
|
case "seq": {
|
|
159
|
-
const results = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
252
|
+
const results = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
160
253
|
return results[results.length - 1];
|
|
161
254
|
}
|
|
162
255
|
case "get": {
|
|
@@ -166,10 +259,10 @@ var QueryInterpreter = class {
|
|
|
166
259
|
const nestedScope = Object.create(scope);
|
|
167
260
|
await Promise.all(
|
|
168
261
|
node.args.bindings.map(async (binding) => {
|
|
169
|
-
nestedScope[binding.name] = await this.interpretNode(binding.expr, scope);
|
|
262
|
+
nestedScope[binding.name] = await this.interpretNode(binding.expr, scope, generators);
|
|
170
263
|
})
|
|
171
264
|
);
|
|
172
|
-
return this.interpretNode(node.args.expr, nestedScope);
|
|
265
|
+
return this.interpretNode(node.args.expr, nestedScope, generators);
|
|
173
266
|
}
|
|
174
267
|
case "getFirstNonEmpty": {
|
|
175
268
|
for (const name of node.args.names) {
|
|
@@ -181,31 +274,31 @@ var QueryInterpreter = class {
|
|
|
181
274
|
return [];
|
|
182
275
|
}
|
|
183
276
|
case "concat": {
|
|
184
|
-
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
277
|
+
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
185
278
|
return parts.reduce((acc, part) => acc.concat(asList(part)), []);
|
|
186
279
|
}
|
|
187
280
|
case "sum": {
|
|
188
|
-
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope)));
|
|
281
|
+
const parts = await Promise.all(node.args.map((arg) => this.interpretNode(arg, scope, generators)));
|
|
189
282
|
return parts.reduce((acc, part) => asNumber(acc) + asNumber(part));
|
|
190
283
|
}
|
|
191
284
|
case "execute": {
|
|
192
|
-
const query = renderQuery(node.args, scope);
|
|
285
|
+
const query = renderQuery(node.args, scope, generators);
|
|
193
286
|
return this.#withQueryEvent(query, async () => {
|
|
194
287
|
return await this.#queryable.executeRaw(query);
|
|
195
288
|
});
|
|
196
289
|
}
|
|
197
290
|
case "query": {
|
|
198
|
-
const query = renderQuery(node.args, scope);
|
|
291
|
+
const query = renderQuery(node.args, scope, generators);
|
|
199
292
|
return this.#withQueryEvent(query, async () => {
|
|
200
293
|
return serialize(await this.#queryable.queryRaw(query));
|
|
201
294
|
});
|
|
202
295
|
}
|
|
203
296
|
case "reverse": {
|
|
204
|
-
const value = await this.interpretNode(node.args, scope);
|
|
297
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
205
298
|
return Array.isArray(value) ? value.reverse() : value;
|
|
206
299
|
}
|
|
207
300
|
case "unique": {
|
|
208
|
-
const value = await this.interpretNode(node.args, scope);
|
|
301
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
209
302
|
if (!Array.isArray(value)) {
|
|
210
303
|
return value;
|
|
211
304
|
}
|
|
@@ -215,22 +308,22 @@ var QueryInterpreter = class {
|
|
|
215
308
|
return value[0] ?? null;
|
|
216
309
|
}
|
|
217
310
|
case "required": {
|
|
218
|
-
const value = await this.interpretNode(node.args, scope);
|
|
311
|
+
const value = await this.interpretNode(node.args, scope, generators);
|
|
219
312
|
if (isEmpty(value)) {
|
|
220
313
|
throw new Error("Required value is empty");
|
|
221
314
|
}
|
|
222
315
|
return value;
|
|
223
316
|
}
|
|
224
317
|
case "mapField": {
|
|
225
|
-
const value = await this.interpretNode(node.args.records, scope);
|
|
318
|
+
const value = await this.interpretNode(node.args.records, scope, generators);
|
|
226
319
|
return mapField(value, node.args.field);
|
|
227
320
|
}
|
|
228
321
|
case "join": {
|
|
229
|
-
const parent = await this.interpretNode(node.args.parent, scope);
|
|
322
|
+
const parent = await this.interpretNode(node.args.parent, scope, generators);
|
|
230
323
|
const children = await Promise.all(
|
|
231
324
|
node.args.children.map(async (joinExpr) => ({
|
|
232
325
|
joinExpr,
|
|
233
|
-
childRecords: await this.interpretNode(joinExpr.child, scope)
|
|
326
|
+
childRecords: await this.interpretNode(joinExpr.child, scope, generators)
|
|
234
327
|
}))
|
|
235
328
|
);
|
|
236
329
|
if (Array.isArray(parent)) {
|
|
@@ -545,5 +638,6 @@ export {
|
|
|
545
638
|
QueryInterpreter,
|
|
546
639
|
TransactionManager,
|
|
547
640
|
TransactionManagerError,
|
|
641
|
+
isPrismaValueGenerator,
|
|
548
642
|
isPrismaValuePlaceholder
|
|
549
643
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PrismaValue } from '../QueryPlan';
|
|
2
|
+
export declare class GeneratorRegistry {
|
|
3
|
+
#private;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Returns a snapshot of the generator registry. It's 'frozen' in time at the moment of this
|
|
7
|
+
* method being called, meaning that the built-in time-based generators will always return
|
|
8
|
+
* the same value on repeated calls as long as the same snapshot is used.
|
|
9
|
+
*/
|
|
10
|
+
snapshot(): Readonly<GeneratorRegistrySnapshot>;
|
|
11
|
+
/**
|
|
12
|
+
* Registers a new generator with the given name.
|
|
13
|
+
*/
|
|
14
|
+
register(name: string, generator: ValueGenerator): void;
|
|
15
|
+
}
|
|
16
|
+
export interface GeneratorRegistrySnapshot {
|
|
17
|
+
[key: string]: ValueGenerator;
|
|
18
|
+
}
|
|
19
|
+
export interface ValueGenerator {
|
|
20
|
+
generate(...args: PrismaValue[]): PrismaValue;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SqlQuery } from '@prisma/driver-adapter-utils';
|
|
2
2
|
import type { QueryPlanDbQuery } from '../QueryPlan';
|
|
3
|
+
import { GeneratorRegistrySnapshot } from './generators';
|
|
3
4
|
import { ScopeBindings } from './scope';
|
|
4
|
-
export declare function renderQuery(dbQuery: QueryPlanDbQuery, scope: ScopeBindings): SqlQuery;
|
|
5
|
+
export declare function renderQuery(dbQuery: QueryPlanDbQuery, scope: ScopeBindings, generators: GeneratorRegistrySnapshot): SqlQuery;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "6.6.0-dev.
|
|
3
|
+
"version": "6.6.0-dev.72",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -24,8 +24,13 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
27
|
+
"@bugsnag/cuid": "3.2.1",
|
|
28
|
+
"@paralleldrive/cuid2": "2.2.2",
|
|
29
|
+
"nanoid": "5.1.5",
|
|
30
|
+
"ulid": "3.0.0",
|
|
31
|
+
"uuid": "11.1.0",
|
|
32
|
+
"@prisma/debug": "6.6.0-dev.72",
|
|
33
|
+
"@prisma/driver-adapter-utils": "6.6.0-dev.72"
|
|
29
34
|
},
|
|
30
35
|
"devDependencies": {
|
|
31
36
|
"@types/jest": "29.5.14",
|