prisma-generator-express 1.21.0 → 1.21.1
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 +48 -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 +48 -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 COUNT_PROJECTION_KEYS = new Set(['select', 'include'])
|
|
214
|
+
|
|
215
|
+
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
216
|
+
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
217
|
+
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
218
|
+
'_sum', '_min', '_max', 'by',
|
|
219
|
+
])
|
|
220
|
+
|
|
221
|
+
function stripProjectionKeys(obj: Record<string, any>): Record<string, any> {
|
|
222
|
+
const result: Record<string, any> = {}
|
|
223
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
224
|
+
if (COUNT_PROJECTION_KEYS.has(key)) continue
|
|
225
|
+
result[key] = value
|
|
226
|
+
}
|
|
227
|
+
return result
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function stripProjectionForCount(shape: Record<string, any>): Record<string, any> {
|
|
231
|
+
if (typeof shape === 'function') {
|
|
232
|
+
return (...args: any[]) => stripProjectionKeys((shape as Function)(...args))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const keys = Object.keys(shape)
|
|
236
|
+
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
237
|
+
|
|
238
|
+
if (isSingleShape) {
|
|
239
|
+
return stripProjectionKeys(shape)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const result: Record<string, any> = {}
|
|
243
|
+
for (const [key, variant] of Object.entries(shape)) {
|
|
244
|
+
if (typeof variant === 'function') {
|
|
245
|
+
result[key] = (...args: any[]) => stripProjectionKeys(variant(...args))
|
|
246
|
+
} else if (typeof variant === 'object' && variant !== null) {
|
|
247
|
+
result[key] = stripProjectionKeys(variant)
|
|
248
|
+
} else {
|
|
249
|
+
result[key] = variant
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return result
|
|
253
|
+
}
|
|
254
|
+
|
|
213
255
|
${generateReadHandlers(modelName, modelNameLower)}
|
|
214
256
|
|
|
215
257
|
${generateWriteHandlers(modelName, modelNameLower)}
|
|
@@ -349,6 +391,8 @@ async function countForPagination(
|
|
|
349
391
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
350
392
|
const hasDistinct = distinctFields.length > 0
|
|
351
393
|
|
|
394
|
+
const countShape = shape ? stripProjectionForCount(shape) : undefined
|
|
395
|
+
|
|
352
396
|
if (hasDistinct) {
|
|
353
397
|
const selectField = distinctFields[0]
|
|
354
398
|
const distinctArgs: Record<string, any> = {
|
|
@@ -366,8 +410,8 @@ async function countForPagination(
|
|
|
366
410
|
console.warn('[prisma-generator-express] Distinct count exceeds ' + DISTINCT_COUNT_LIMIT + ', falling back to approximate total')
|
|
367
411
|
const countArgs: Record<string, any> = {}
|
|
368
412
|
if (query.where) countArgs.where = query.where
|
|
369
|
-
return
|
|
370
|
-
? await delegate.guard(
|
|
413
|
+
return countShape
|
|
414
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
371
415
|
: await delegate.count(countArgs)
|
|
372
416
|
}
|
|
373
417
|
|
|
@@ -377,8 +421,8 @@ async function countForPagination(
|
|
|
377
421
|
const countArgs: Record<string, any> = {}
|
|
378
422
|
if (query.where) countArgs.where = query.where
|
|
379
423
|
|
|
380
|
-
return
|
|
381
|
-
? await delegate.guard(
|
|
424
|
+
return countShape
|
|
425
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
382
426
|
: await delegate.count(countArgs)
|
|
383
427
|
}
|
|
384
428
|
|
|
@@ -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,wDAiQC;AAjQD,SAAgB,sBAAsB,CAAC,OAA8B;IACnE,MAAM,EAAE,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AE,CAAC,cAAc,IAAI,EAAE,CAAC;aAC9C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,+BAA+B,KAAK,IAAI,CAAC;aACxD,IAAI,CAAC,IAAI,CAAC,CAAA;QAEb,OAAO;wBACS,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,48 @@ function assertGuard(delegate: any): void {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
const COUNT_PROJECTION_KEYS = new Set(['select', 'include'])
|
|
220
|
+
|
|
221
|
+
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
222
|
+
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
223
|
+
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
224
|
+
'_sum', '_min', '_max', 'by',
|
|
225
|
+
])
|
|
226
|
+
|
|
227
|
+
function stripProjectionKeys(obj: Record<string, any>): Record<string, any> {
|
|
228
|
+
const result: Record<string, any> = {}
|
|
229
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
230
|
+
if (COUNT_PROJECTION_KEYS.has(key)) continue
|
|
231
|
+
result[key] = value
|
|
232
|
+
}
|
|
233
|
+
return result
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function stripProjectionForCount(shape: Record<string, any>): Record<string, any> {
|
|
237
|
+
if (typeof shape === 'function') {
|
|
238
|
+
return (...args: any[]) => stripProjectionKeys((shape as Function)(...args))
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const keys = Object.keys(shape)
|
|
242
|
+
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
243
|
+
|
|
244
|
+
if (isSingleShape) {
|
|
245
|
+
return stripProjectionKeys(shape)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const result: Record<string, any> = {}
|
|
249
|
+
for (const [key, variant] of Object.entries(shape)) {
|
|
250
|
+
if (typeof variant === 'function') {
|
|
251
|
+
result[key] = (...args: any[]) => stripProjectionKeys(variant(...args))
|
|
252
|
+
} else if (typeof variant === 'object' && variant !== null) {
|
|
253
|
+
result[key] = stripProjectionKeys(variant)
|
|
254
|
+
} else {
|
|
255
|
+
result[key] = variant
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return result
|
|
259
|
+
}
|
|
260
|
+
|
|
219
261
|
${generateReadHandlers(modelName, modelNameLower)}
|
|
220
262
|
|
|
221
263
|
${generateWriteHandlers(modelName, modelNameLower)}
|
|
@@ -374,6 +416,8 @@ async function countForPagination(
|
|
|
374
416
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
375
417
|
const hasDistinct = distinctFields.length > 0
|
|
376
418
|
|
|
419
|
+
const countShape = shape ? stripProjectionForCount(shape) : undefined
|
|
420
|
+
|
|
377
421
|
if (hasDistinct) {
|
|
378
422
|
const selectField = distinctFields[0]
|
|
379
423
|
const distinctArgs: Record<string, any> = {
|
|
@@ -391,8 +435,8 @@ async function countForPagination(
|
|
|
391
435
|
console.warn('[prisma-generator-express] Distinct count exceeds ' + DISTINCT_COUNT_LIMIT + ', falling back to approximate total')
|
|
392
436
|
const countArgs: Record<string, any> = {}
|
|
393
437
|
if (query.where) countArgs.where = query.where
|
|
394
|
-
return
|
|
395
|
-
? await delegate.guard(
|
|
438
|
+
return countShape
|
|
439
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
396
440
|
: await delegate.count(countArgs)
|
|
397
441
|
}
|
|
398
442
|
|
|
@@ -402,8 +446,8 @@ async function countForPagination(
|
|
|
402
446
|
const countArgs: Record<string, any> = {}
|
|
403
447
|
if (query.where) countArgs.where = query.where
|
|
404
448
|
|
|
405
|
-
return
|
|
406
|
-
? await delegate.guard(
|
|
449
|
+
return countShape
|
|
450
|
+
? await delegate.guard(countShape, caller).count(countArgs)
|
|
407
451
|
: await delegate.count(countArgs)
|
|
408
452
|
}
|
|
409
453
|
|