prisma-sql 1.77.0 → 1.79.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.
@@ -70,7 +70,7 @@ var require_package = __commonJS({
70
70
  "package.json"(exports$1, module) {
71
71
  module.exports = {
72
72
  name: "prisma-sql",
73
- version: "1.77.0",
73
+ version: "1.79.0",
74
74
  description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
75
75
  main: "dist/index.cjs",
76
76
  module: "dist/index.js",
@@ -6287,6 +6287,31 @@ function normalizeArgsForDialect(dialect, args) {
6287
6287
  if (dialect !== "postgres") return args;
6288
6288
  return applyPostgresDistinctOrderBy(args);
6289
6289
  }
6290
+ function normalizeCompoundCursor(cursor, model) {
6291
+ const keys = Object.keys(cursor);
6292
+ if (keys.length !== 1) return cursor;
6293
+ const key = keys[0];
6294
+ const value = cursor[key];
6295
+ const scalarSet = getScalarFieldSet(model);
6296
+ if (scalarSet.has(key)) return cursor;
6297
+ if (!isPlainObject(value)) return cursor;
6298
+ const nested = value;
6299
+ const nestedKeys = Object.keys(nested);
6300
+ if (nestedKeys.length === 0) return cursor;
6301
+ for (const nk of nestedKeys) {
6302
+ if (!scalarSet.has(nk)) return cursor;
6303
+ }
6304
+ return nested;
6305
+ }
6306
+ function normalizeArgsCompoundCursor(args, model) {
6307
+ if (!isNotNullish(args.cursor) || !isPlainObject(args.cursor)) return args;
6308
+ const flat = normalizeCompoundCursor(
6309
+ args.cursor,
6310
+ model
6311
+ );
6312
+ if (flat === args.cursor) return args;
6313
+ return __spreadProps(__spreadValues({}, args), { cursor: flat });
6314
+ }
6290
6315
  function buildCursorClauseIfAny(input) {
6291
6316
  const { cursor, orderBy, tableName, alias, params, skip, dialect, model } = input;
6292
6317
  if (!isNotNullish(cursor)) return {};
@@ -6384,7 +6409,8 @@ function buildSelectSql(input) {
6384
6409
  assertSafeTableRef(from.tableName);
6385
6410
  const dialectToUse = resolveDialect(dialect);
6386
6411
  const argsForSql = normalizeArgsForNegativeTake(method, args);
6387
- const normalizedArgs = normalizeArgsForDialect(dialectToUse, argsForSql);
6412
+ const argsWithDialect = normalizeArgsForDialect(dialectToUse, argsForSql);
6413
+ const normalizedArgs = normalizeArgsCompoundCursor(argsWithDialect, model);
6388
6414
  validateDistinct(model, normalizedArgs.distinct);
6389
6415
  validateOrderBy(model, normalizedArgs.orderBy);
6390
6416
  validateCursor(model, normalizedArgs.cursor, normalizedArgs.distinct);
@@ -7835,6 +7861,23 @@ function resolveParamsFromMappings(args: any, paramMappings: any[]): unknown[] {
7835
7861
  params.push(normalizeValue(value))
7836
7862
  }
7837
7863
  return params
7864
+ }
7865
+
7866
+ function normalizeCompoundCursor(cursor: any, model: any): any {
7867
+ if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || cursor instanceof Date) return cursor
7868
+ const keys = Object.keys(cursor)
7869
+ if (keys.length !== 1) return cursor
7870
+ const key = keys[0]
7871
+ const value = cursor[key]
7872
+ if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) return cursor
7873
+ const scalarSet = new Set(model.fields.filter((f: any) => !f.isRelation).map((f: any) => f.name))
7874
+ if (scalarSet.has(key)) return cursor
7875
+ const nestedKeys = Object.keys(value)
7876
+ if (nestedKeys.length === 0) return cursor
7877
+ for (const nk of nestedKeys) {
7878
+ if (!scalarSet.has(nk)) return cursor
7879
+ }
7880
+ return value
7838
7881
  }`;
7839
7882
  }
7840
7883
  function generateDataConstants(cleanModels, mappings, fieldTypes, queries, dialect) {
@@ -8139,7 +8182,7 @@ function generateExtension(runtimeImportPath) {
8139
8182
  $parent?: any
8140
8183
  }
8141
8184
 
8142
- async function handleMethod(
8185
+ async function handleMethod(
8143
8186
  this: ModelContext,
8144
8187
  method: PrismaMethod,
8145
8188
  args: unknown
@@ -8151,6 +8194,7 @@ function generateExtension(runtimeImportPath) {
8151
8194
  }
8152
8195
 
8153
8196
  const startTime = Date.now()
8197
+ let sql: string | undefined
8154
8198
 
8155
8199
  try {
8156
8200
  if (args !== undefined && args !== null && typeof args !== 'object') {
@@ -8159,7 +8203,7 @@ function generateExtension(runtimeImportPath) {
8159
8203
  )
8160
8204
  }
8161
8205
 
8162
- const transformedArgs = transformEnumValuesByModel(modelName, args || {})
8206
+ let transformedArgs = transformEnumValuesByModel(modelName, args || {})
8163
8207
 
8164
8208
  const model = MODEL_MAP.get(modelName)
8165
8209
  if (!model) {
@@ -8169,6 +8213,13 @@ function generateExtension(runtimeImportPath) {
8169
8213
  return this.$parent[modelName][method](args)
8170
8214
  }
8171
8215
 
8216
+ if (transformedArgs.cursor) {
8217
+ const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
8218
+ if (flatCursor !== transformedArgs.cursor) {
8219
+ transformedArgs = { ...transformedArgs, cursor: flatCursor }
8220
+ }
8221
+ }
8222
+
8172
8223
  const plan = planQueryStrategy({
8173
8224
  model,
8174
8225
  method,
@@ -8179,7 +8230,6 @@ function generateExtension(runtimeImportPath) {
8179
8230
 
8180
8231
  const queryKey = normalizeQuery(plan.filteredArgs)
8181
8232
  const prebakedQuery = QUERIES[modelName]?.[method]?.[queryKey]
8182
- let sql: string
8183
8233
  let params: unknown[]
8184
8234
  let prebaked = false
8185
8235
  let requiresReduction = false
@@ -8332,12 +8382,19 @@ function generateExtension(runtimeImportPath) {
8332
8382
  throw new Error('Streaming requires postgres.js client')
8333
8383
  }
8334
8384
 
8335
- const transformedArgs = transformEnumValuesByModel(modelName, args || {})
8385
+ let transformedArgs = transformEnumValuesByModel(modelName, args || {})
8336
8386
  const model = MODEL_MAP.get(modelName)
8337
8387
  if (!model) {
8338
8388
  throw new Error(\`Model '\${modelName}' not found\`)
8339
8389
  }
8340
8390
 
8391
+ if (transformedArgs.cursor) {
8392
+ const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
8393
+ if (flatCursor !== transformedArgs.cursor) {
8394
+ transformedArgs = { ...transformedArgs, cursor: flatCursor }
8395
+ }
8396
+ }
8397
+
8341
8398
  const plan = planQueryStrategy({
8342
8399
  model,
8343
8400
  method: 'findMany',