prisma-generator-express 1.21.1 → 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.
|
@@ -210,41 +210,36 @@ function assertGuard(delegate: any): void {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
const COUNT_PROJECTION_KEYS = new Set(['select', 'include'])
|
|
214
|
-
|
|
215
213
|
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
216
214
|
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
217
215
|
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
218
216
|
'_sum', '_min', '_max', 'by',
|
|
219
217
|
])
|
|
220
218
|
|
|
221
|
-
function
|
|
219
|
+
function keepWhereOnly(obj: Record<string, any>): Record<string, any> {
|
|
222
220
|
const result: Record<string, any> = {}
|
|
223
|
-
|
|
224
|
-
if (COUNT_PROJECTION_KEYS.has(key)) continue
|
|
225
|
-
result[key] = value
|
|
226
|
-
}
|
|
221
|
+
if ('where' in obj) result.where = obj.where
|
|
227
222
|
return result
|
|
228
223
|
}
|
|
229
224
|
|
|
230
|
-
function
|
|
225
|
+
function buildCountShape(shape: Record<string, any>): Record<string, any> {
|
|
231
226
|
if (typeof shape === 'function') {
|
|
232
|
-
return (...args: any[]) =>
|
|
227
|
+
return (...args: any[]) => keepWhereOnly((shape as Function)(...args))
|
|
233
228
|
}
|
|
234
229
|
|
|
235
230
|
const keys = Object.keys(shape)
|
|
236
231
|
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
237
232
|
|
|
238
233
|
if (isSingleShape) {
|
|
239
|
-
return
|
|
234
|
+
return keepWhereOnly(shape)
|
|
240
235
|
}
|
|
241
236
|
|
|
242
237
|
const result: Record<string, any> = {}
|
|
243
238
|
for (const [key, variant] of Object.entries(shape)) {
|
|
244
239
|
if (typeof variant === 'function') {
|
|
245
|
-
result[key] = (...args: any[]) =>
|
|
240
|
+
result[key] = (...args: any[]) => keepWhereOnly(variant(...args))
|
|
246
241
|
} else if (typeof variant === 'object' && variant !== null) {
|
|
247
|
-
result[key] =
|
|
242
|
+
result[key] = keepWhereOnly(variant)
|
|
248
243
|
} else {
|
|
249
244
|
result[key] = variant
|
|
250
245
|
}
|
|
@@ -391,7 +386,7 @@ async function countForPagination(
|
|
|
391
386
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
392
387
|
const hasDistinct = distinctFields.length > 0
|
|
393
388
|
|
|
394
|
-
const countShape = shape ?
|
|
389
|
+
const countShape = shape ? buildCountShape(shape) : undefined
|
|
395
390
|
|
|
396
391
|
if (hasDistinct) {
|
|
397
392
|
const selectField = distinctFields[0]
|
|
@@ -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,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7E,MAAM,UAAU,GACd,qBAAqB,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAE9D,OAAO;wCAC+B,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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,41 +216,36 @@ function assertGuard(delegate: any): void {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
const COUNT_PROJECTION_KEYS = new Set(['select', 'include'])
|
|
220
|
-
|
|
221
219
|
const GUARD_SHAPE_CONFIG_KEYS = new Set([
|
|
222
220
|
'data', 'create', 'update', 'where', 'include', 'select', 'orderBy',
|
|
223
221
|
'cursor', 'take', 'skip', 'distinct', 'having', '_count', '_avg',
|
|
224
222
|
'_sum', '_min', '_max', 'by',
|
|
225
223
|
])
|
|
226
224
|
|
|
227
|
-
function
|
|
225
|
+
function keepWhereOnly(obj: Record<string, any>): Record<string, any> {
|
|
228
226
|
const result: Record<string, any> = {}
|
|
229
|
-
|
|
230
|
-
if (COUNT_PROJECTION_KEYS.has(key)) continue
|
|
231
|
-
result[key] = value
|
|
232
|
-
}
|
|
227
|
+
if ('where' in obj) result.where = obj.where
|
|
233
228
|
return result
|
|
234
229
|
}
|
|
235
230
|
|
|
236
|
-
function
|
|
231
|
+
function buildCountShape(shape: Record<string, any>): Record<string, any> {
|
|
237
232
|
if (typeof shape === 'function') {
|
|
238
|
-
return (...args: any[]) =>
|
|
233
|
+
return (...args: any[]) => keepWhereOnly((shape as Function)(...args))
|
|
239
234
|
}
|
|
240
235
|
|
|
241
236
|
const keys = Object.keys(shape)
|
|
242
237
|
const isSingleShape = keys.length === 0 || keys.every(k => GUARD_SHAPE_CONFIG_KEYS.has(k))
|
|
243
238
|
|
|
244
239
|
if (isSingleShape) {
|
|
245
|
-
return
|
|
240
|
+
return keepWhereOnly(shape)
|
|
246
241
|
}
|
|
247
242
|
|
|
248
243
|
const result: Record<string, any> = {}
|
|
249
244
|
for (const [key, variant] of Object.entries(shape)) {
|
|
250
245
|
if (typeof variant === 'function') {
|
|
251
|
-
result[key] = (...args: any[]) =>
|
|
246
|
+
result[key] = (...args: any[]) => keepWhereOnly(variant(...args))
|
|
252
247
|
} else if (typeof variant === 'object' && variant !== null) {
|
|
253
|
-
result[key] =
|
|
248
|
+
result[key] = keepWhereOnly(variant)
|
|
254
249
|
} else {
|
|
255
250
|
result[key] = variant
|
|
256
251
|
}
|
|
@@ -416,7 +411,7 @@ async function countForPagination(
|
|
|
416
411
|
const distinctFields = normalizeDistinct(query.distinct)
|
|
417
412
|
const hasDistinct = distinctFields.length > 0
|
|
418
413
|
|
|
419
|
-
const countShape = shape ?
|
|
414
|
+
const countShape = shape ? buildCountShape(shape) : undefined
|
|
420
415
|
|
|
421
416
|
if (hasDistinct) {
|
|
422
417
|
const selectField = distinctFields[0]
|