prisma-sql 1.13.0 → 1.15.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.15.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",
@@ -116,7 +116,7 @@ var require_package = __commonJS({
116
116
  author: "multipliedtwice <multipliedtwice@gmail.com>",
117
117
  license: "MIT",
118
118
  dependencies: {
119
- "@dee-wan/schema-parser": "1.2.0",
119
+ "@dee-wan/schema-parser": "1.3.0",
120
120
  "@prisma/generator-helper": "^7.2.0",
121
121
  "@prisma/internals": "^7.2.0"
122
122
  },
@@ -4183,14 +4183,6 @@ function safeAlias(input) {
4183
4183
  }
4184
4184
  return base;
4185
4185
  }
4186
- function isPrismaMethod(v) {
4187
- return v === "findMany" || v === "findFirst" || v === "findUnique" || v === "aggregate" || v === "groupBy" || v === "count";
4188
- }
4189
- function getMethodFromProcessed(processed) {
4190
- const maybe = processed == null ? void 0 : processed.method;
4191
- if (isPrismaMethod(maybe)) return maybe;
4192
- return "findMany";
4193
- }
4194
4186
  function buildSqlResult(args) {
4195
4187
  const {
4196
4188
  method,
@@ -4303,6 +4295,7 @@ function buildMainWhere(args) {
4303
4295
  }
4304
4296
  function buildAndNormalizeSql(args) {
4305
4297
  const {
4298
+ method,
4306
4299
  processed,
4307
4300
  whereResult,
4308
4301
  tableName,
@@ -4311,7 +4304,6 @@ function buildAndNormalizeSql(args) {
4311
4304
  schemaModels,
4312
4305
  dialect
4313
4306
  } = args;
4314
- const method = getMethodFromProcessed(processed);
4315
4307
  const sqlResult = buildSqlResult({
4316
4308
  method,
4317
4309
  processed,
@@ -4333,7 +4325,7 @@ function finalizeDirective(args) {
4333
4325
  validateSqlPositions(normalizedSql, normalizedMappings, getGlobalDialect());
4334
4326
  const { staticParams, dynamicKeys } = buildParamsFromMappings(normalizedMappings);
4335
4327
  return {
4336
- header: directive.header,
4328
+ method: directive.method,
4337
4329
  sql: normalizedSql,
4338
4330
  staticParams,
4339
4331
  dynamicKeys,
@@ -4353,7 +4345,9 @@ function generateSQL(directive) {
4353
4345
  modelDef,
4354
4346
  dialect
4355
4347
  });
4348
+ const method = directive.method;
4356
4349
  const normalized = buildAndNormalizeSql({
4350
+ method,
4357
4351
  processed: query.processed,
4358
4352
  whereResult,
4359
4353
  tableName,
@@ -4394,7 +4388,7 @@ function generateClient(options) {
4394
4388
  const modelQueries = queries.get(modelName);
4395
4389
  for (const directive of result.directives) {
4396
4390
  try {
4397
- const method = directive.header;
4391
+ const method = directive.method;
4398
4392
  const sqlDirective = generateSQL2(directive);
4399
4393
  if (!modelQueries.has(method)) {
4400
4394
  modelQueries.set(method, /* @__PURE__ */ new Map());
@@ -4458,9 +4452,58 @@ const QUERIES: Record<string, Record<string, Record<string, {
4458
4452
 
4459
4453
  const DIALECT = ${JSON.stringify(dialect)}
4460
4454
 
4455
+ function isDynamicParam(key: string): boolean {
4456
+ // Common dynamic parameters that should be replaced with markers
4457
+ return key === 'skip' || key === 'take' || key === 'cursor'
4458
+ }
4459
+
4461
4460
  function normalizeQuery(args: any): string {
4462
4461
  if (!args) return '{}'
4463
- return JSON.stringify(args, (key, value) => {
4462
+
4463
+ // Clone and normalize the args
4464
+ const normalized = JSON.parse(JSON.stringify(args))
4465
+
4466
+ // Replace dynamic params with markers to match prebaked keys
4467
+ function replaceDynamicParams(obj: any): any {
4468
+ if (!obj || typeof obj !== 'object') return obj
4469
+
4470
+ if (Array.isArray(obj)) {
4471
+ return obj.map(replaceDynamicParams)
4472
+ }
4473
+
4474
+ const result: any = {}
4475
+ for (const [key, value] of Object.entries(obj)) {
4476
+ // Replace top-level dynamic params with markers
4477
+ if (isDynamicParam(key)) {
4478
+ result[key] = \`__DYNAMIC_\${key}__\`
4479
+ } else {
4480
+ result[key] = replaceDynamicParams(value)
4481
+ }
4482
+ }
4483
+ return result
4484
+ }
4485
+
4486
+ const withMarkers = replaceDynamicParams(normalized)
4487
+
4488
+ // Remove empty objects to match prebaked keys
4489
+ function removeEmptyObjects(obj: any): any {
4490
+ if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return obj
4491
+
4492
+ const result: any = {}
4493
+ for (const [key, value] of Object.entries(obj)) {
4494
+ // Skip empty objects (but keep empty arrays)
4495
+ if (value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0) {
4496
+ continue
4497
+ }
4498
+ result[key] = removeEmptyObjects(value)
4499
+ }
4500
+ return result
4501
+ }
4502
+
4503
+ const cleaned = removeEmptyObjects(withMarkers)
4504
+
4505
+ // Sort keys recursively for deterministic matching
4506
+ return JSON.stringify(cleaned, (key, value) => {
4464
4507
  if (value && typeof value === 'object' && !Array.isArray(value)) {
4465
4508
  const sorted: Record<string, unknown> = {}
4466
4509
  for (const k of Object.keys(value).sort()) {