prisma-sql 1.13.0 → 1.14.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/generator.cjs +51 -2
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +51 -2
- package/dist/generator.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -56,7 +56,7 @@ var require_package = __commonJS({
|
|
|
56
56
|
"package.json"(exports$1, module) {
|
|
57
57
|
module.exports = {
|
|
58
58
|
name: "prisma-sql",
|
|
59
|
-
version: "1.
|
|
59
|
+
version: "1.14.0",
|
|
60
60
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
61
61
|
main: "dist/index.cjs",
|
|
62
62
|
module: "dist/index.js",
|
|
@@ -4460,9 +4460,58 @@ const QUERIES: Record<string, Record<string, Record<string, {
|
|
|
4460
4460
|
|
|
4461
4461
|
const DIALECT = ${JSON.stringify(dialect)}
|
|
4462
4462
|
|
|
4463
|
+
function isDynamicParam(key: string): boolean {
|
|
4464
|
+
// Common dynamic parameters that should be replaced with markers
|
|
4465
|
+
return key === 'skip' || key === 'take' || key === 'cursor'
|
|
4466
|
+
}
|
|
4467
|
+
|
|
4463
4468
|
function normalizeQuery(args: any): string {
|
|
4464
4469
|
if (!args) return '{}'
|
|
4465
|
-
|
|
4470
|
+
|
|
4471
|
+
// Clone and normalize the args
|
|
4472
|
+
const normalized = JSON.parse(JSON.stringify(args))
|
|
4473
|
+
|
|
4474
|
+
// Replace dynamic params with markers to match prebaked keys
|
|
4475
|
+
function replaceDynamicParams(obj: any): any {
|
|
4476
|
+
if (!obj || typeof obj !== 'object') return obj
|
|
4477
|
+
|
|
4478
|
+
if (Array.isArray(obj)) {
|
|
4479
|
+
return obj.map(replaceDynamicParams)
|
|
4480
|
+
}
|
|
4481
|
+
|
|
4482
|
+
const result: any = {}
|
|
4483
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
4484
|
+
// Replace top-level dynamic params with markers
|
|
4485
|
+
if (isDynamicParam(key)) {
|
|
4486
|
+
result[key] = \`__DYNAMIC_\${key}__\`
|
|
4487
|
+
} else {
|
|
4488
|
+
result[key] = replaceDynamicParams(value)
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
return result
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
const withMarkers = replaceDynamicParams(normalized)
|
|
4495
|
+
|
|
4496
|
+
// Remove empty objects to match prebaked keys
|
|
4497
|
+
function removeEmptyObjects(obj: any): any {
|
|
4498
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return obj
|
|
4499
|
+
|
|
4500
|
+
const result: any = {}
|
|
4501
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
4502
|
+
// Skip empty objects (but keep empty arrays)
|
|
4503
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0) {
|
|
4504
|
+
continue
|
|
4505
|
+
}
|
|
4506
|
+
result[key] = removeEmptyObjects(value)
|
|
4507
|
+
}
|
|
4508
|
+
return result
|
|
4509
|
+
}
|
|
4510
|
+
|
|
4511
|
+
const cleaned = removeEmptyObjects(withMarkers)
|
|
4512
|
+
|
|
4513
|
+
// Sort keys recursively for deterministic matching
|
|
4514
|
+
return JSON.stringify(cleaned, (key, value) => {
|
|
4466
4515
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
4467
4516
|
const sorted: Record<string, unknown> = {}
|
|
4468
4517
|
for (const k of Object.keys(value).sort()) {
|