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