prisma-generator-express 1.34.3 → 1.35.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.
|
@@ -115,27 +115,45 @@ export function mapError(error: unknown): HttpError {
|
|
|
115
115
|
const code = (error as any).code as string
|
|
116
116
|
const mapped = PRISMA_ERROR_MAP[code]
|
|
117
117
|
if (mapped) {
|
|
118
|
-
|
|
118
|
+
const detail = (error as any).message
|
|
119
|
+
const message = detail
|
|
120
|
+
? mapped.message + ': ' + detail
|
|
121
|
+
: mapped.message
|
|
122
|
+
return new HttpError(mapped.status, message)
|
|
119
123
|
}
|
|
120
124
|
if (typeof code === 'string' && code.startsWith('P')) {
|
|
125
|
+
const msg = (error as any).message || 'Database operation failed'
|
|
121
126
|
console.warn(
|
|
122
127
|
'[prisma-generator-express] Unmapped Prisma error code:',
|
|
123
128
|
code,
|
|
124
|
-
|
|
129
|
+
msg,
|
|
125
130
|
)
|
|
126
|
-
return new HttpError(500,
|
|
131
|
+
return new HttpError(500, msg)
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
if (error && typeof error === 'object' && 'name' in error) {
|
|
131
136
|
const name = (error as any).name
|
|
132
137
|
if (name === 'PrismaClientValidationError') {
|
|
133
|
-
return new HttpError(400, 'Invalid query parameters')
|
|
138
|
+
return new HttpError(400, (error as any).message || 'Invalid query parameters')
|
|
139
|
+
}
|
|
140
|
+
if (name === 'PrismaClientKnownRequestError') {
|
|
141
|
+
return new HttpError(400, (error as any).message || 'Database request error')
|
|
142
|
+
}
|
|
143
|
+
if (name === 'PrismaClientInitializationError') {
|
|
144
|
+
return new HttpError(503, (error as any).message || 'Database connection failed')
|
|
145
|
+
}
|
|
146
|
+
if (name === 'PrismaClientRustPanicError') {
|
|
147
|
+
return new HttpError(500, (error as any).message || 'Internal database engine error')
|
|
148
|
+
}
|
|
149
|
+
if (name === 'PrismaClientUnknownRequestError') {
|
|
150
|
+
return new HttpError(500, (error as any).message || 'Unknown database error')
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
153
|
|
|
154
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
137
155
|
console.error('[prisma-generator-express] Unhandled error:', error)
|
|
138
|
-
return new HttpError(500, 'Internal server error')
|
|
156
|
+
return new HttpError(500, msg || 'Internal server error')
|
|
139
157
|
}
|
|
140
158
|
|
|
141
159
|
let _speedExtension: ((opts: any) => any) | null = null
|
|
@@ -469,21 +487,29 @@ export async function findManyPaginated(
|
|
|
469
487
|
const shape = ctx.guardShape
|
|
470
488
|
const caller = ctx.guardCaller
|
|
471
489
|
const distinctCountLimit = ctx.paginationConfig?.distinctCountLimit
|
|
490
|
+
const delegate = (extended as any).${modelNameLower}
|
|
472
491
|
|
|
473
492
|
if (shape) {
|
|
474
|
-
assertGuard(
|
|
493
|
+
assertGuard(delegate)
|
|
475
494
|
}
|
|
476
495
|
|
|
477
496
|
let items: any[]
|
|
478
497
|
let total: number
|
|
479
498
|
|
|
480
|
-
if (typeof extended.$transaction
|
|
499
|
+
if (shape || typeof extended.$transaction !== 'function') {
|
|
500
|
+
const [data, count] = await Promise.all([
|
|
501
|
+
shape
|
|
502
|
+
? delegate.guard(shape, caller).findMany(query)
|
|
503
|
+
: delegate.findMany(query),
|
|
504
|
+
countForPagination(delegate, query, shape, caller, distinctCountLimit),
|
|
505
|
+
])
|
|
506
|
+
items = data
|
|
507
|
+
total = count
|
|
508
|
+
} else {
|
|
481
509
|
try {
|
|
482
510
|
const txResult = await extended.$transaction(async (tx: any) => {
|
|
483
|
-
const d =
|
|
484
|
-
|
|
485
|
-
: await tx.${modelNameLower}.findMany(query)
|
|
486
|
-
const t = await countForPagination(tx.${modelNameLower}, query, shape, caller, distinctCountLimit)
|
|
511
|
+
const d = await tx.${modelNameLower}.findMany(query)
|
|
512
|
+
const t = await countForPagination(tx.${modelNameLower}, query, undefined, undefined, distinctCountLimit)
|
|
487
513
|
return { d, t }
|
|
488
514
|
})
|
|
489
515
|
items = txResult.d
|
|
@@ -496,31 +522,12 @@ export async function findManyPaginated(
|
|
|
496
522
|
console.warn(
|
|
497
523
|
'[prisma-generator-express] Interactive transactions not available, pagination queries are non-atomic',
|
|
498
524
|
)
|
|
499
|
-
items =
|
|
500
|
-
|
|
501
|
-
: await (extended as any).${modelNameLower}.findMany(query)
|
|
502
|
-
total = await countForPagination(
|
|
503
|
-
(extended as any).${modelNameLower},
|
|
504
|
-
query,
|
|
505
|
-
shape,
|
|
506
|
-
caller,
|
|
507
|
-
distinctCountLimit,
|
|
508
|
-
)
|
|
525
|
+
items = await delegate.findMany(query)
|
|
526
|
+
total = await countForPagination(delegate, query, undefined, undefined, distinctCountLimit)
|
|
509
527
|
} else {
|
|
510
528
|
throw txError
|
|
511
529
|
}
|
|
512
530
|
}
|
|
513
|
-
} else {
|
|
514
|
-
items = shape
|
|
515
|
-
? await (extended as any).${modelNameLower}.guard(shape, caller).findMany(query)
|
|
516
|
-
: await (extended as any).${modelNameLower}.findMany(query)
|
|
517
|
-
total = await countForPagination(
|
|
518
|
-
(extended as any).${modelNameLower},
|
|
519
|
-
query,
|
|
520
|
-
shape,
|
|
521
|
-
caller,
|
|
522
|
-
distinctCountLimit,
|
|
523
|
-
)
|
|
524
531
|
}
|
|
525
532
|
|
|
526
533
|
const skip = (query.skip as number) ?? 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateOperationCore.js","sourceRoot":"","sources":["../../src/generators/generateOperationCore.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"generateOperationCore.js","sourceRoot":"","sources":["../../src/generators/generateOperationCore.ts"],"names":[],"mappings":";;AAEA,4DAuXC;AAMD,8CAwKC;AAriBD,SAAgB,wBAAwB;IACtC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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gDACK,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B7D,CAAA;AACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -113,27 +113,45 @@ export function mapError(error: unknown): HttpError {
|
|
|
113
113
|
const code = (error as any).code as string
|
|
114
114
|
const mapped = PRISMA_ERROR_MAP[code]
|
|
115
115
|
if (mapped) {
|
|
116
|
-
|
|
116
|
+
const detail = (error as any).message
|
|
117
|
+
const message = detail
|
|
118
|
+
? mapped.message + ': ' + detail
|
|
119
|
+
: mapped.message
|
|
120
|
+
return new HttpError(mapped.status, message)
|
|
117
121
|
}
|
|
118
122
|
if (typeof code === 'string' && code.startsWith('P')) {
|
|
123
|
+
const msg = (error as any).message || 'Database operation failed'
|
|
119
124
|
console.warn(
|
|
120
125
|
'[prisma-generator-express] Unmapped Prisma error code:',
|
|
121
126
|
code,
|
|
122
|
-
|
|
127
|
+
msg,
|
|
123
128
|
)
|
|
124
|
-
return new HttpError(500,
|
|
129
|
+
return new HttpError(500, msg)
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
if (error && typeof error === 'object' && 'name' in error) {
|
|
129
134
|
const name = (error as any).name
|
|
130
135
|
if (name === 'PrismaClientValidationError') {
|
|
131
|
-
return new HttpError(400, 'Invalid query parameters')
|
|
136
|
+
return new HttpError(400, (error as any).message || 'Invalid query parameters')
|
|
137
|
+
}
|
|
138
|
+
if (name === 'PrismaClientKnownRequestError') {
|
|
139
|
+
return new HttpError(400, (error as any).message || 'Database request error')
|
|
140
|
+
}
|
|
141
|
+
if (name === 'PrismaClientInitializationError') {
|
|
142
|
+
return new HttpError(503, (error as any).message || 'Database connection failed')
|
|
143
|
+
}
|
|
144
|
+
if (name === 'PrismaClientRustPanicError') {
|
|
145
|
+
return new HttpError(500, (error as any).message || 'Internal database engine error')
|
|
146
|
+
}
|
|
147
|
+
if (name === 'PrismaClientUnknownRequestError') {
|
|
148
|
+
return new HttpError(500, (error as any).message || 'Unknown database error')
|
|
132
149
|
}
|
|
133
150
|
}
|
|
134
151
|
|
|
152
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
135
153
|
console.error('[prisma-generator-express] Unhandled error:', error)
|
|
136
|
-
return new HttpError(500, 'Internal server error')
|
|
154
|
+
return new HttpError(500, msg || 'Internal server error')
|
|
137
155
|
}
|
|
138
156
|
|
|
139
157
|
let _speedExtension: ((opts: any) => any) | null = null
|
|
@@ -481,21 +499,29 @@ export async function findManyPaginated(
|
|
|
481
499
|
const shape = ctx.guardShape
|
|
482
500
|
const caller = ctx.guardCaller
|
|
483
501
|
const distinctCountLimit = ctx.paginationConfig?.distinctCountLimit
|
|
502
|
+
const delegate = (extended as any).${modelNameLower}
|
|
484
503
|
|
|
485
504
|
if (shape) {
|
|
486
|
-
assertGuard(
|
|
505
|
+
assertGuard(delegate)
|
|
487
506
|
}
|
|
488
507
|
|
|
489
508
|
let items: any[]
|
|
490
509
|
let total: number
|
|
491
510
|
|
|
492
|
-
if (typeof extended.$transaction
|
|
511
|
+
if (shape || typeof extended.$transaction !== 'function') {
|
|
512
|
+
const [data, count] = await Promise.all([
|
|
513
|
+
shape
|
|
514
|
+
? delegate.guard(shape, caller).findMany(query)
|
|
515
|
+
: delegate.findMany(query),
|
|
516
|
+
countForPagination(delegate, query, shape, caller, distinctCountLimit),
|
|
517
|
+
])
|
|
518
|
+
items = data
|
|
519
|
+
total = count
|
|
520
|
+
} else {
|
|
493
521
|
try {
|
|
494
522
|
const txResult = await extended.$transaction(async (tx: any) => {
|
|
495
|
-
const d =
|
|
496
|
-
|
|
497
|
-
: await tx.${modelNameLower}.findMany(query)
|
|
498
|
-
const t = await countForPagination(tx.${modelNameLower}, query, shape, caller, distinctCountLimit)
|
|
523
|
+
const d = await tx.${modelNameLower}.findMany(query)
|
|
524
|
+
const t = await countForPagination(tx.${modelNameLower}, query, undefined, undefined, distinctCountLimit)
|
|
499
525
|
return { d, t }
|
|
500
526
|
})
|
|
501
527
|
items = txResult.d
|
|
@@ -508,31 +534,12 @@ export async function findManyPaginated(
|
|
|
508
534
|
console.warn(
|
|
509
535
|
'[prisma-generator-express] Interactive transactions not available, pagination queries are non-atomic',
|
|
510
536
|
)
|
|
511
|
-
items =
|
|
512
|
-
|
|
513
|
-
: await (extended as any).${modelNameLower}.findMany(query)
|
|
514
|
-
total = await countForPagination(
|
|
515
|
-
(extended as any).${modelNameLower},
|
|
516
|
-
query,
|
|
517
|
-
shape,
|
|
518
|
-
caller,
|
|
519
|
-
distinctCountLimit,
|
|
520
|
-
)
|
|
537
|
+
items = await delegate.findMany(query)
|
|
538
|
+
total = await countForPagination(delegate, query, undefined, undefined, distinctCountLimit)
|
|
521
539
|
} else {
|
|
522
540
|
throw txError
|
|
523
541
|
}
|
|
524
542
|
}
|
|
525
|
-
} else {
|
|
526
|
-
items = shape
|
|
527
|
-
? await (extended as any).${modelNameLower}.guard(shape, caller).findMany(query)
|
|
528
|
-
: await (extended as any).${modelNameLower}.findMany(query)
|
|
529
|
-
total = await countForPagination(
|
|
530
|
-
(extended as any).${modelNameLower},
|
|
531
|
-
query,
|
|
532
|
-
shape,
|
|
533
|
-
caller,
|
|
534
|
-
distinctCountLimit,
|
|
535
|
-
)
|
|
536
543
|
}
|
|
537
544
|
|
|
538
545
|
const skip = (query.skip as number) ?? 0
|