prisma-sql 1.76.2 → 1.78.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/index.js CHANGED
@@ -6311,6 +6311,31 @@ function normalizeArgsForDialect(dialect, args) {
6311
6311
  if (dialect !== "postgres") return args;
6312
6312
  return applyPostgresDistinctOrderBy(args);
6313
6313
  }
6314
+ function normalizeCompoundCursor(cursor, model) {
6315
+ const keys = Object.keys(cursor);
6316
+ if (keys.length !== 1) return cursor;
6317
+ const key = keys[0];
6318
+ const value = cursor[key];
6319
+ const scalarSet = getScalarFieldSet(model);
6320
+ if (scalarSet.has(key)) return cursor;
6321
+ if (!isPlainObject(value)) return cursor;
6322
+ const nested = value;
6323
+ const nestedKeys = Object.keys(nested);
6324
+ if (nestedKeys.length === 0) return cursor;
6325
+ for (const nk of nestedKeys) {
6326
+ if (!scalarSet.has(nk)) return cursor;
6327
+ }
6328
+ return nested;
6329
+ }
6330
+ function normalizeArgsCompoundCursor(args, model) {
6331
+ if (!isNotNullish(args.cursor) || !isPlainObject(args.cursor)) return args;
6332
+ const flat = normalizeCompoundCursor(
6333
+ args.cursor,
6334
+ model
6335
+ );
6336
+ if (flat === args.cursor) return args;
6337
+ return __spreadProps(__spreadValues({}, args), { cursor: flat });
6338
+ }
6314
6339
  function buildCursorClauseIfAny(input) {
6315
6340
  const { cursor, orderBy, tableName, alias, params, skip, dialect, model } = input;
6316
6341
  if (!isNotNullish(cursor)) return {};
@@ -6408,7 +6433,8 @@ function buildSelectSql(input) {
6408
6433
  assertSafeTableRef(from.tableName);
6409
6434
  const dialectToUse = resolveDialect(dialect);
6410
6435
  const argsForSql = normalizeArgsForNegativeTake(method, args);
6411
- const normalizedArgs = normalizeArgsForDialect(dialectToUse, argsForSql);
6436
+ const argsWithDialect = normalizeArgsForDialect(dialectToUse, argsForSql);
6437
+ const normalizedArgs = normalizeArgsCompoundCursor(argsWithDialect, model);
6412
6438
  validateDistinct(model, normalizedArgs.distinct);
6413
6439
  validateOrderBy(model, normalizedArgs.orderBy);
6414
6440
  validateCursor(model, normalizedArgs.cursor, normalizedArgs.distinct);
@@ -8073,6 +8099,14 @@ function buildKey(row, fields) {
8073
8099
  }
8074
8100
 
8075
8101
  // src/builder/select/reducer.ts
8102
+ var UNSAFE_PROPERTY_NAMES = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
8103
+ function assertSafePropertyName(name) {
8104
+ if (UNSAFE_PROPERTY_NAMES.has(name)) {
8105
+ throw new Error(
8106
+ `Unsafe property name '${name}' rejected to prevent prototype pollution`
8107
+ );
8108
+ }
8109
+ }
8076
8110
  function buildRelationScalarCols(relModel, relPath, includeAllScalars, selectedScalarFields) {
8077
8111
  const jsonSet = getJsonFieldSet(relModel);
8078
8112
  const scalarFields = includeAllScalars ? getScalarFieldNames(relModel) : selectedScalarFields;
@@ -8104,6 +8138,7 @@ function buildReducerConfig(parentModel, includeSpec, allModels, prefix = "", de
8104
8138
  const modelMap = new Map(allModels.map((m) => [m.name, m]));
8105
8139
  for (const [incName, incValue] of Object.entries(includeSpec)) {
8106
8140
  if (incValue === false) continue;
8141
+ assertSafePropertyName(incName);
8107
8142
  const field = parentModel.fields.find((f) => f.name === incName);
8108
8143
  if (!field || !field.isRelation) {
8109
8144
  throw new Error(
@@ -8181,7 +8216,7 @@ function initNestedPlaceholders(obj, nested) {
8181
8216
  function materializeRelationObject(row, rel) {
8182
8217
  const relKey = buildKey(row, rel.keyCols);
8183
8218
  if (relKey == null) return null;
8184
- const obj = {};
8219
+ const obj = /* @__PURE__ */ Object.create(null);
8185
8220
  for (const c of rel.scalarCols) {
8186
8221
  obj[c.fieldName] = parseJsonIfNeeded(c.isJson, row[c.colName]);
8187
8222
  }
@@ -8249,7 +8284,7 @@ function reduceFlatRows(rows, config) {
8249
8284
  if (parentKey == null) continue;
8250
8285
  let record = resultMap.get(parentKey);
8251
8286
  if (!record) {
8252
- record = {};
8287
+ record = /* @__PURE__ */ Object.create(null);
8253
8288
  for (const fieldName of parentScalarFields) {
8254
8289
  record[fieldName] = maybeParseJson(
8255
8290
  row[fieldName],