prisma-generator-express 1.21.0 → 1.22.0
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/client/encodeQueryParams.js +2 -2
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +43 -4
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/package.json +1 -1
- package/src/client/encodeQueryParams.ts +1 -1
- package/src/generators/generateUnifiedHandler.ts +43 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.encodeQueryParams = void 0;
|
|
4
|
-
const
|
|
4
|
+
const misc_js_1 = require("../copy/misc.js");
|
|
5
5
|
function replacer(_key, value) {
|
|
6
6
|
if (typeof value === 'bigint') {
|
|
7
7
|
return value.toString();
|
|
@@ -21,7 +21,7 @@ const encodeQueryParams = (params) => {
|
|
|
21
21
|
entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`);
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
-
if (Array.isArray(value) || (0,
|
|
24
|
+
if (Array.isArray(value) || (0, misc_js_1.isObject)(value)) {
|
|
25
25
|
entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value, replacer))}`);
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodeQueryParams.js","sourceRoot":"","sources":["../../src/client/encodeQueryParams.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"encodeQueryParams.js","sourceRoot":"","sources":["../../src/client/encodeQueryParams.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAiB1C,SAAS,QAAQ,CAAC,IAAY,EAAE,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,QAAQ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|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
214
|
+
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
215
|
+
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
216
|
+
'_sum', '_min', '_max', 'by',
|
|
217
|
+
])
|
|
218
|
+
|
|
219
|
+
function keepWhereOnly(obj: Record<string, any>): Record<string, any> {
|
|
220
|
+
const result: Record<string, any> = {}
|
|
221
|
+
if ('where' in obj) result.where = obj.where
|
|
222
|
+
return result
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function buildCountShape(shape: Record<string, any>): Record<string, any> {
|
|
226
|
+
if (typeof shape === 'function') {
|
|
227
|
+
return (...args: any[]) => keepWhereOnly((shape as Function)(...args))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const keys = Object.keys(shape)
|
|
231
|
+
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
232
|
+
|
|
233
|
+
if (isSingleShape) {
|
|
234
|
+
return keepWhereOnly(shape)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const result: Record<string, any> = {}
|
|
238
|
+
for (const [key, variant] of Object.entries(shape)) {
|
|
239
|
+
if (typeof variant === 'function') {
|
|
240
|
+
result[key] = (...args: any[]) => keepWhereOnly(variant(...args))
|
|
241
|
+
} else if (typeof variant === 'object' && variant !== null) {
|
|
242
|
+
result[key] = keepWhereOnly(variant)
|
|
243
|
+
} else {
|
|
244
|
+
result[key] = variant
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result
|
|
248
|
+
}
|
|
249
|
+
|
|
213
250
|
${generateReadHandlers(modelName, modelNameLower)}
|
|
214
251
|
|
|
215
252
|
${generateWriteHandlers(modelName, modelNameLower)}
|
|
@@ -349,6 +386,8 @@ async function countForPagination(
|
|
|
349
386
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
350
387
|
const hasDistinct = distinctFields.length > 0
|
|
351
388
|
|
|
389
|
+
const countShape = shape ? buildCountShape(shape) : undefined
|
|
390
|
+
|
|
352
391
|
if (hasDistinct) {
|
|
353
392
|
const selectField = distinctFields[0]
|
|
354
393
|
const distinctArgs: Record<string, any> = {
|
|
@@ -366,8 +405,8 @@ async function countForPagination(
|
|
|
366
405
|
console.warn('[prisma-generator-express] Distinct count exceeds ' + DISTINCT_COUNT_LIMIT + ', falling back to approximate total')
|
|
367
406
|
const countArgs: Record<string, any> = {}
|
|
368
407
|
if (query.where) countArgs.where = query.where
|
|
369
|
-
return
|
|
370
|
-
? await delegate.guard(
|
|
408
|
+
return countShape
|
|
409
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
371
410
|
: await delegate.count(countArgs)
|
|
372
411
|
}
|
|
373
412
|
|
|
@@ -377,8 +416,8 @@ async function countForPagination(
|
|
|
377
416
|
const countArgs: Record<string, any> = {}
|
|
378
417
|
if (query.where) countArgs.where = query.where
|
|
379
418
|
|
|
380
|
-
return
|
|
381
|
-
? await delegate.guard(
|
|
419
|
+
return countShape
|
|
420
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
382
421
|
: await delegate.count(countArgs)
|
|
383
422
|
}
|
|
384
423
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAOA,
|
|
1
|
+
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAOA,wDA4PC;AA5PD,SAAgB,sBAAsB,CAAC,OAA8B;IACnE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAA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YAAY;;;EAGlC,eAAe,CAAC,CAAC,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE;;;;;6BAKlB,cAAc;;8BAEb,cAAc,yBAAyB,EAAE,CAAC,MAAM;;8BAEhD,cAAc,IAAI,EAAE,CAAC,MAAM;;;;;;;;;CASxD,CAAA;IACK,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC;QACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8CoB,SAAS;;;;;;;;;6BASJ,cAAc;;;;;;;;;;yBAUlB,cAAc;yBACd,cAAc;kDACW,cAAc;;;;;;;;;;;;+BAYjC,cAAc;+BACd,cAAc;sDACS,cAAc;;;;;;;2BAOzC,cAAc;2BACd,cAAc;kDACS,cAAc;;;;;;;;;;;;;CAa/D,CACE,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -216,6 +216,43 @@ function assertGuard(delegate: any): void {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
220
|
+
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
221
|
+
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
222
|
+
'_sum', '_min', '_max', 'by',
|
|
223
|
+
])
|
|
224
|
+
|
|
225
|
+
function keepWhereOnly(obj: Record<string, any>): Record<string, any> {
|
|
226
|
+
const result: Record<string, any> = {}
|
|
227
|
+
if ('where' in obj) result.where = obj.where
|
|
228
|
+
return result
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function buildCountShape(shape: Record<string, any>): Record<string, any> {
|
|
232
|
+
if (typeof shape === 'function') {
|
|
233
|
+
return (...args: any[]) => keepWhereOnly((shape as Function)(...args))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const keys = Object.keys(shape)
|
|
237
|
+
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
238
|
+
|
|
239
|
+
if (isSingleShape) {
|
|
240
|
+
return keepWhereOnly(shape)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const result: Record<string, any> = {}
|
|
244
|
+
for (const [key, variant] of Object.entries(shape)) {
|
|
245
|
+
if (typeof variant === 'function') {
|
|
246
|
+
result[key] = (...args: any[]) => keepWhereOnly(variant(...args))
|
|
247
|
+
} else if (typeof variant === 'object' && variant !== null) {
|
|
248
|
+
result[key] = keepWhereOnly(variant)
|
|
249
|
+
} else {
|
|
250
|
+
result[key] = variant
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return result
|
|
254
|
+
}
|
|
255
|
+
|
|
219
256
|
${generateReadHandlers(modelName, modelNameLower)}
|
|
220
257
|
|
|
221
258
|
${generateWriteHandlers(modelName, modelNameLower)}
|
|
@@ -374,6 +411,8 @@ async function countForPagination(
|
|
|
374
411
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
375
412
|
const hasDistinct = distinctFields.length > 0
|
|
376
413
|
|
|
414
|
+
const countShape = shape ? buildCountShape(shape) : undefined
|
|
415
|
+
|
|
377
416
|
if (hasDistinct) {
|
|
378
417
|
const selectField = distinctFields[0]
|
|
379
418
|
const distinctArgs: Record<string, any> = {
|
|
@@ -391,8 +430,8 @@ async function countForPagination(
|
|
|
391
430
|
console.warn('[prisma-generator-express] Distinct count exceeds ' + DISTINCT_COUNT_LIMIT + ', falling back to approximate total')
|
|
392
431
|
const countArgs: Record<string, any> = {}
|
|
393
432
|
if (query.where) countArgs.where = query.where
|
|
394
|
-
return
|
|
395
|
-
? await delegate.guard(
|
|
433
|
+
return countShape
|
|
434
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
396
435
|
: await delegate.count(countArgs)
|
|
397
436
|
}
|
|
398
437
|
|
|
@@ -402,8 +441,8 @@ async function countForPagination(
|
|
|
402
441
|
const countArgs: Record<string, any> = {}
|
|
403
442
|
if (query.where) countArgs.where = query.where
|
|
404
443
|
|
|
405
|
-
return
|
|
406
|
-
? await delegate.guard(
|
|
444
|
+
return countShape
|
|
445
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
407
446
|
: await delegate.count(countArgs)
|
|
408
447
|
}
|
|
409
448
|
|