@vibeorm/runtime 2.3.0 → 2.4.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
@@ -165,8 +165,8 @@ function compileAdvisoryLock(params) {
165
165
  }
166
166
  const mode = readMode({ value: request.mode, method });
167
167
  if (hasSingle) {
168
- const key2 = { key: readInt64({ value: request.key, method }) };
169
- return statementFor({ method, mode, key: key2 });
168
+ const key = { key: readInt64({ value: request.key, method }) };
169
+ return statementFor({ method, mode, key });
170
170
  }
171
171
  if (!("classId" in request) || !("objectId" in request)) {
172
172
  throw validationError({
@@ -611,20 +611,20 @@ function wirePlanKey(wire) {
611
611
  }
612
612
  function fieldDecoder(params) {
613
613
  const { dialect, field, wire } = params;
614
- const decode2 = fieldCodec({ dialect, field }).decode;
614
+ const decode = fieldCodec({ dialect, field }).decode;
615
615
  if (isPostgresEnumList({ dialect, field })) {
616
616
  return (value) => decodeValue({ dialect, field, value });
617
617
  }
618
- if (decode2 === IDENTITY_DECODE)
618
+ if (decode === IDENTITY_DECODE)
619
619
  return null;
620
620
  if (field.isList) {
621
621
  if (field.scalarType === "Json" && decodeIsNoop({ scalarType: "Json", wire }))
622
622
  return null;
623
- return (value) => Array.isArray(value) ? value.map((element) => element === null || element === undefined ? element : decode2(element)) : decode2(value);
623
+ return (value) => Array.isArray(value) ? value.map((element) => element === null || element === undefined ? element : decode(element)) : decode(value);
624
624
  }
625
625
  if (field.scalarType !== null && decodeIsNoop({ scalarType: field.scalarType, wire }))
626
626
  return null;
627
- return decode2;
627
+ return decode;
628
628
  }
629
629
  function buildDecodePlan(params) {
630
630
  const { dialect, model, wire } = params;
@@ -632,12 +632,12 @@ function buildDecodePlan(params) {
632
632
  const inPlace = [];
633
633
  const renamedColumns = [];
634
634
  for (const field of model.fields) {
635
- const decode2 = fieldDecoder({ dialect, field, ...wire === undefined ? {} : { wire } });
636
- byColumn.set(field.columnName, { name: field.name, decode: decode2 });
635
+ const decode = fieldDecoder({ dialect, field, ...wire === undefined ? {} : { wire } });
636
+ byColumn.set(field.columnName, { name: field.name, decode });
637
637
  if (field.columnName !== field.name)
638
638
  renamedColumns.push(field.columnName);
639
- if (decode2 !== null)
640
- inPlace.push({ column: field.columnName, decode: decode2 });
639
+ if (decode !== null)
640
+ inPlace.push({ column: field.columnName, decode });
641
641
  }
642
642
  return { byColumn, renamedColumns, decoders: inPlace, inPlace: renamedColumns.length > 0 ? null : inPlace };
643
643
  }
@@ -764,12 +764,12 @@ function getJsonDecodePlan(model) {
764
764
  const inPlace = [];
765
765
  const renamedColumns = [];
766
766
  for (const field of model.fields) {
767
- const decode2 = field.scalarType === "Json" ? null : field.scalarType === "Bytes" && !field.isList ? decodeBase64Bytes : fieldDecoder({ dialect: "postgres", field });
768
- byColumn.set(field.columnName, { name: field.name, decode: decode2 });
767
+ const decode = field.scalarType === "Json" ? null : field.scalarType === "Bytes" && !field.isList ? decodeBase64Bytes : fieldDecoder({ dialect: "postgres", field });
768
+ byColumn.set(field.columnName, { name: field.name, decode });
769
769
  if (field.columnName !== field.name)
770
770
  renamedColumns.push(field.columnName);
771
- if (decode2 !== null)
772
- inPlace.push({ column: field.columnName, decode: decode2 });
771
+ if (decode !== null)
772
+ inPlace.push({ column: field.columnName, decode });
773
773
  }
774
774
  plan = { byColumn, renamedColumns, decoders: inPlace, inPlace: renamedColumns.length > 0 ? null : inPlace };
775
775
  jsonDecodePlanCache.set(model, plan);
@@ -2616,7 +2616,7 @@ function compileOperatorFilter(params) {
2616
2616
  }
2617
2617
  const insensitive = mode === "insensitive";
2618
2618
  const strict = mode === "strict";
2619
- const ciCollated = (params2) => params2.dialect.name === "mysql" && params2.field.collation?.toLowerCase().endsWith("_ci") === true;
2619
+ const ciCollated = (params) => params.dialect.name === "mysql" && params.field.collation?.toLowerCase().endsWith("_ci") === true;
2620
2620
  const requireStringOperand = (operator, operand) => {
2621
2621
  if (typeof operand !== "string") {
2622
2622
  throw validationError4({
@@ -2903,13 +2903,13 @@ function compileRelationFilter(params) {
2903
2903
  meta: { model: model.name, relation: relation.name }
2904
2904
  });
2905
2905
  }
2906
- const conditions2 = [];
2906
+ const conditions = [];
2907
2907
  for (const [operator, operand] of Object.entries(value)) {
2908
2908
  if (operand === undefined)
2909
2909
  continue;
2910
2910
  switch (operator) {
2911
2911
  case "some":
2912
- conditions2.push(buildRelationExists({
2912
+ conditions.push(buildRelationExists({
2913
2913
  ctx,
2914
2914
  link,
2915
2915
  outer,
@@ -2917,7 +2917,7 @@ function compileRelationFilter(params) {
2917
2917
  }));
2918
2918
  break;
2919
2919
  case "none":
2920
- conditions2.push(buildRelationExists({
2920
+ conditions.push(buildRelationExists({
2921
2921
  ctx,
2922
2922
  link,
2923
2923
  outer,
@@ -2926,7 +2926,7 @@ function compileRelationFilter(params) {
2926
2926
  }));
2927
2927
  break;
2928
2928
  case "every":
2929
- conditions2.push(buildRelationExists({
2929
+ conditions.push(buildRelationExists({
2930
2930
  ctx,
2931
2931
  link,
2932
2932
  outer,
@@ -2942,15 +2942,15 @@ function compileRelationFilter(params) {
2942
2942
  });
2943
2943
  }
2944
2944
  }
2945
- if (conditions2.length === 0) {
2945
+ if (conditions.length === 0) {
2946
2946
  throw validationError4({
2947
2947
  message: `filter on relation ${model.name}.${relation.name} must contain some, every or none`,
2948
2948
  meta: { model: model.name, relation: relation.name }
2949
2949
  });
2950
2950
  }
2951
- if (conditions2.length === 1)
2952
- return conditions2[0];
2953
- return { kind: "and", operands: conditions2 };
2951
+ if (conditions.length === 1)
2952
+ return conditions[0];
2953
+ return { kind: "and", operands: conditions };
2954
2954
  }
2955
2955
  let isArm;
2956
2956
  let hasIs = false;
@@ -3145,17 +3145,17 @@ function compileRelationOrderTerms(params) {
3145
3145
  meta: { model: model.name, relation: relation.name }
3146
3146
  });
3147
3147
  }
3148
- const direction2 = requireDirection(value, `orderBy.${relation.name}._count`);
3149
- const alias2 = `__ord${++aliasSeq.n}`;
3148
+ const direction = requireDirection(value, `orderBy.${relation.name}._count`);
3149
+ const alias = `__ord${++aliasSeq.n}`;
3150
3150
  const select = link.kind === "manyToMany" ? {
3151
3151
  kind: "select",
3152
- table: { name: link.join.tableName, alias: alias2 },
3152
+ table: { name: link.join.tableName, alias },
3153
3153
  columns: [],
3154
3154
  selectExpr: { kind: "countAll" },
3155
3155
  where: {
3156
3156
  kind: "cmpCol",
3157
3157
  op: "eq",
3158
- left: { table: alias2, name: link.join.parentColumn },
3158
+ left: { table: alias, name: link.join.parentColumn },
3159
3159
  right: {
3160
3160
  table: outer,
3161
3161
  name: singleKeyPair({ link, what: "implicit many-to-many ordering" }).parent.columnName
@@ -3163,12 +3163,12 @@ function compileRelationOrderTerms(params) {
3163
3163
  }
3164
3164
  } : {
3165
3165
  kind: "select",
3166
- table: { name: link.target.tableName, alias: alias2 },
3166
+ table: { name: link.target.tableName, alias },
3167
3167
  columns: [],
3168
3168
  selectExpr: { kind: "countAll" },
3169
- where: correlateLink({ link, childTable: alias2, outerTable: outer })
3169
+ where: correlateLink({ link, childTable: alias, outerTable: outer })
3170
3170
  };
3171
- terms.push({ select, direction: direction2 });
3171
+ terms.push({ select, direction });
3172
3172
  continue;
3173
3173
  }
3174
3174
  if (isList) {
@@ -3576,7 +3576,7 @@ function compileUpdateSet(params) {
3576
3576
  });
3577
3577
  }
3578
3578
  if (isPlainObject3(value) && field.scalarType !== "Json") {
3579
- const entries = Object.entries(value).filter(([, operand2]) => operand2 !== undefined);
3579
+ const entries = Object.entries(value).filter(([, operand]) => operand !== undefined);
3580
3580
  if (entries.length !== 1) {
3581
3581
  throw validationError4({
3582
3582
  message: `update of ${model.name}.${field.name} must use exactly one operation`,
@@ -4134,7 +4134,7 @@ function buildFindShape(params) {
4134
4134
  },
4135
4135
  ...where === undefined ? {} : { where }
4136
4136
  };
4137
- const statement2 = {
4137
+ const statement = {
4138
4138
  kind: "select",
4139
4139
  table: { name: DISTINCT_TABLE_ALIAS },
4140
4140
  columns: projectionColumns({ model, selectedFields }),
@@ -4144,7 +4144,7 @@ function buildFindShape(params) {
4144
4144
  ...limit === undefined ? {} : { limit },
4145
4145
  ...offset === undefined ? {} : { offset }
4146
4146
  };
4147
- return { statement: statement2, reverseRows: backward, resortBy };
4147
+ return { statement, reverseRows: backward, resortBy };
4148
4148
  }
4149
4149
  if (distinctOuterOrder !== null) {
4150
4150
  const inner = {
@@ -4160,7 +4160,7 @@ function buildFindShape(params) {
4160
4160
  ...projectionColumns({ model, selectedFields }),
4161
4161
  ...lateralJoins.map((join) => ({ name: join.columnAlias }))
4162
4162
  ];
4163
- const statement2 = {
4163
+ const statement = {
4164
4164
  kind: "select",
4165
4165
  table: { name: DISTINCT_TABLE_ALIAS },
4166
4166
  columns: outerColumns,
@@ -4169,7 +4169,7 @@ function buildFindShape(params) {
4169
4169
  ...limit === undefined ? {} : { limit },
4170
4170
  ...offset === undefined ? {} : { offset }
4171
4171
  };
4172
- return { statement: statement2, reverseRows: backward, resortBy };
4172
+ return { statement, reverseRows: backward, resortBy };
4173
4173
  }
4174
4174
  const pageFirst = lateralJoins.length > 0 && (limit !== undefined || offset !== undefined) && orderTerms.every((term) => ("column" in term));
4175
4175
  if (pageFirst && selection !== undefined) {
@@ -4185,7 +4185,7 @@ function buildFindShape(params) {
4185
4185
  ...limit === undefined ? {} : { limit },
4186
4186
  ...offset === undefined ? {} : { offset }
4187
4187
  };
4188
- const statement2 = {
4188
+ const statement = {
4189
4189
  kind: "select",
4190
4190
  table: { name: model.tableName },
4191
4191
  columns,
@@ -4193,7 +4193,7 @@ function buildFindShape(params) {
4193
4193
  lateralJoins,
4194
4194
  ...orderTerms.length === 0 ? {} : { orderBy: orderTerms }
4195
4195
  };
4196
- return { statement: statement2, reverseRows: backward, resortBy };
4196
+ return { statement, reverseRows: backward, resortBy };
4197
4197
  }
4198
4198
  const statement = {
4199
4199
  kind: "select",
@@ -4618,9 +4618,9 @@ function compileGroupByOrder(params) {
4618
4618
  }
4619
4619
  agg = { fn: "countAll" };
4620
4620
  } else {
4621
- const field2 = getFieldMeta({ model, field: selector, context: `orderBy ${name}` });
4622
- validateAggregatedField({ model, field: field2, key });
4623
- const aggColumn = key === "_count" ? { name: field2.columnName } : compareColumnRef({ dialect, field: field2 });
4621
+ const field = getFieldMeta({ model, field: selector, context: `orderBy ${name}` });
4622
+ validateAggregatedField({ model, field, key });
4623
+ const aggColumn = key === "_count" ? { name: field.columnName } : compareColumnRef({ dialect, field });
4624
4624
  agg = { fn: AGG_FN_BY_KEY[key], column: aggColumn };
4625
4625
  }
4626
4626
  terms.push({ agg, direction });
@@ -5070,7 +5070,7 @@ function buildQuery(params) {
5070
5070
  throw validationError4({ message: "A conflict update requires an explicit target" });
5071
5071
  const updates = requireObject({ value: spec.update, what: "onConflict.update", model });
5072
5072
  const fields = resolveUpsertUpdateFields({ model, update: Object.keys(updates), targetColumns: new Set(compiled.columns ?? []), skipUpdatedAt: true });
5073
- const columns2 = Object.fromEntries(model.fields.map((field) => [field.name, field.columnName]));
5073
+ const columns = Object.fromEntries(model.fields.map((field) => [field.name, field.columnName]));
5074
5074
  conflictClause = {
5075
5075
  columns: compiled.columns ?? [],
5076
5076
  ...compiled.constraint === undefined ? {} : { constraint: compiled.constraint },
@@ -5079,7 +5079,7 @@ function buildQuery(params) {
5079
5079
  const fragment = updates[field.name];
5080
5080
  if (!isSqlFragment(fragment))
5081
5081
  throw validationError4({ message: "Conflict update expressions must be constructed SQL fragments" });
5082
- return [field.columnName, mapConflictColumns({ fragment, columns: columns2 })];
5082
+ return [field.columnName, mapConflictColumns({ fragment, columns })];
5083
5083
  }))
5084
5084
  };
5085
5085
  } else
@@ -6981,7 +6981,7 @@ function requirePostgres(params) {
6981
6981
  return getSqlDialect2({ dialect: params.dialect });
6982
6982
  }
6983
6983
  async function explainSql(params) {
6984
- const { executor, sql: sql2, rlsContext } = params;
6984
+ const { executor, sql, rlsContext } = params;
6985
6985
  const mode = params.mode ?? "estimate";
6986
6986
  const dialect = requirePostgres({ dialect: params.dialect });
6987
6987
  const warnings = [];
@@ -6998,7 +6998,7 @@ async function explainSql(params) {
6998
6998
  meta: { mode }
6999
6999
  });
7000
7000
  }
7001
- assertExecutableRead({ text: sql2.text });
7001
+ assertExecutableRead({ text: sql.text });
7002
7002
  warnings.push("this statement was EXECUTED to produce observed rows and milliseconds; a read-only transaction and a keyword check are not a proof of safety, because a SELECT can call a function with side effects");
7003
7003
  }
7004
7004
  const contextKeys = rlsContext === undefined ? [] : Object.keys(rlsContext);
@@ -7014,7 +7014,7 @@ async function explainSql(params) {
7014
7014
  const report = await explainOnSession({
7015
7015
  executor,
7016
7016
  dialect: params.dialect,
7017
- sql: sql2,
7017
+ sql,
7018
7018
  mode,
7019
7019
  warnings,
7020
7020
  ...rlsContext === undefined ? {} : { rlsContext },
@@ -7033,7 +7033,7 @@ async function explainSql(params) {
7033
7033
  }
7034
7034
  }
7035
7035
  async function explainOnSession(params) {
7036
- const { executor, sql: sql2, mode, rlsContext } = params;
7036
+ const { executor, sql, mode, rlsContext } = params;
7037
7037
  const dialect = requirePostgres({ dialect: params.dialect });
7038
7038
  const warnings = params.warnings ?? [];
7039
7039
  const contextKeys = rlsContext === undefined ? [] : Object.keys(rlsContext);
@@ -7061,7 +7061,7 @@ async function explainOnSession(params) {
7061
7061
  }
7062
7062
  const explain = renderPostgresExplain({
7063
7063
  dialect,
7064
- query: { text: sql2.text, values: [...sql2.values], returning: "none" },
7064
+ query: { text: sql.text, values: [...sql.values], returning: "none" },
7065
7065
  options: mode === "analyze" ? { analyze: true, buffers: true } : {}
7066
7066
  });
7067
7067
  const rows = await run(explain);
@@ -7288,7 +7288,7 @@ function createStatementDiagnostics(params) {
7288
7288
  text: query.text,
7289
7289
  values: (query.values ?? []).map((value) => Array.isArray(value) ? tx.formatArrayParam(value) : value)
7290
7290
  });
7291
- const report2 = await explainOnSession({
7291
+ const report = await explainOnSession({
7292
7292
  executor,
7293
7293
  dialect: dialect.name,
7294
7294
  sql: { text: statement.text, values: statement.values },
@@ -7297,11 +7297,11 @@ function createStatementDiagnostics(params) {
7297
7297
  });
7298
7298
  return summarizePlan({
7299
7299
  plan: {
7300
- root: report2.root,
7301
- nodeCount: report2.nodeCount,
7302
- truncated: report2.truncated,
7303
- ...report2.planningTimeMs === undefined ? {} : { planningTimeMs: report2.planningTimeMs },
7304
- ...report2.executionTimeMs === undefined ? {} : { executionTimeMs: report2.executionTimeMs }
7300
+ root: report.root,
7301
+ nodeCount: report.nodeCount,
7302
+ truncated: report.truncated,
7303
+ ...report.planningTimeMs === undefined ? {} : { planningTimeMs: report.planningTimeMs },
7304
+ ...report.executionTimeMs === undefined ? {} : { executionTimeMs: report.executionTimeMs }
7305
7305
  },
7306
7306
  mode
7307
7307
  });
@@ -7650,13 +7650,13 @@ function recommendFromPlan(params) {
7650
7650
  candidate: false
7651
7651
  });
7652
7652
  } else {
7653
- const removed2 = node.rowsRemovedByFilter;
7653
+ const removed = node.rowsRemovedByFilter;
7654
7654
  findings.push({
7655
7655
  code: "sequential-scan-on-large-table",
7656
7656
  severity: "warn",
7657
7657
  node: node.nodeType,
7658
7658
  relation,
7659
- evidence: `sequential scan over "${relation}" (about ${facts.estimatedRows} rows, planner cost ${node.estimatedTotalCost} cost units)` + (removed2 === undefined ? "" : `, discarding ${removed2} rows by filter`) + (node.actualRows === undefined ? "" : `, returning ${node.actualRows}`),
7659
+ evidence: `sequential scan over "${relation}" (about ${facts.estimatedRows} rows, planner cost ${node.estimatedTotalCost} cost units)` + (removed === undefined ? "" : `, discarding ${removed} rows by filter`) + (node.actualRows === undefined ? "" : `, returning ${node.actualRows}`),
7660
7660
  candidate: true,
7661
7661
  indexCandidate: {
7662
7662
  table: relation,
@@ -8207,8 +8207,8 @@ async function loadManyToMany(params) {
8207
8207
  for (const pair of pairs) {
8208
8208
  const rawParent = pair[M2M_PARENT_ALIAS];
8209
8209
  delete pair[M2M_PARENT_ALIAS];
8210
- const parentKey2 = decodeParent === null || rawParent === null || rawParent === undefined ? rawParent : decodeParent(rawParent);
8211
- const key = relationValueKey({ value: parentKey2 });
8210
+ const parentKey = decodeParent === null || rawParent === null || rawParent === undefined ? rawParent : decodeParent(rawParent);
8211
+ const key = relationValueKey({ value: parentKey });
8212
8212
  const group = groups.get(key);
8213
8213
  if (group === undefined)
8214
8214
  groups.set(key, [pair]);
@@ -8403,10 +8403,10 @@ async function attachLateralRelations(params) {
8403
8403
  for (const row of rows) {
8404
8404
  const raw = row[column];
8405
8405
  delete row[column];
8406
- let parsed2 = raw;
8406
+ let parsed = raw;
8407
8407
  if (typeof raw === "string") {
8408
8408
  try {
8409
- parsed2 = JSON.parse(raw);
8409
+ parsed = JSON.parse(raw);
8410
8410
  } catch (cause) {
8411
8411
  throw new VibeError19({
8412
8412
  code: "VIBE_INTERNAL",
@@ -8417,10 +8417,10 @@ async function attachLateralRelations(params) {
8417
8417
  }
8418
8418
  }
8419
8419
  if (isList) {
8420
- if (!Array.isArray(parsed2)) {
8420
+ if (!Array.isArray(parsed)) {
8421
8421
  throw new VibeError19({ code: "VIBE_INTERNAL", message: "to-many relation payload must be an array", meta: { relation: node.name } });
8422
8422
  }
8423
- const children = parsed2.map(decodePosition);
8423
+ const children = parsed.map(decodePosition);
8424
8424
  for (const child of children) {
8425
8425
  for (const name of hiddenOrder)
8426
8426
  delete child[name];
@@ -8428,11 +8428,11 @@ async function attachLateralRelations(params) {
8428
8428
  row[node.name] = children;
8429
8429
  pushAll(kept, children);
8430
8430
  } else {
8431
- if (parsed2 === null) {
8431
+ if (parsed === null) {
8432
8432
  row[node.name] = null;
8433
8433
  continue;
8434
8434
  }
8435
- const child = decodePosition(parsed2);
8435
+ const child = decodePosition(parsed);
8436
8436
  for (const name of hiddenOrder)
8437
8437
  delete child[name];
8438
8438
  row[node.name] = child;
@@ -8497,13 +8497,13 @@ function containsSqlFragment(value, seen = new Set) {
8497
8497
  return false;
8498
8498
  }
8499
8499
  function restrictedSqlArgs(params) {
8500
- const refuse2 = () => params.refusal?.() ?? new VibeError20({ code: "VIBE_VALIDATION", message: `SQL fragments are unavailable through ${params.path}; use the unrestricted client`, meta: { path: params.path } });
8500
+ const refuse = () => params.refusal?.() ?? new VibeError20({ code: "VIBE_VALIDATION", message: `SQL fragments are unavailable through ${params.path}; use the unrestricted client`, meta: { path: params.path } });
8501
8501
  if (containsSqlFragment(params.value))
8502
- throw refuse2();
8502
+ throw refuse();
8503
8503
  const seen = new Map;
8504
8504
  const copy = (value) => {
8505
8505
  if (isSqlFragment2(value))
8506
- throw refuse2();
8506
+ throw refuse();
8507
8507
  if (typeof value !== "object" || value === null)
8508
8508
  return value;
8509
8509
  if (seen.has(value))
@@ -8796,9 +8796,9 @@ function mergeLevel(params) {
8796
8796
  continue;
8797
8797
  }
8798
8798
  if (spec === true) {
8799
- const child2 = mergeLevel({ meta, name, definition, mask: targetMask, args: {} });
8800
- select[relationName] = child2.merged;
8801
- relationPlans.set(relationName, child2.plan);
8799
+ const child = mergeLevel({ meta, name, definition, mask: targetMask, args: {} });
8800
+ select[relationName] = child.merged;
8801
+ relationPlans.set(relationName, child.plan);
8802
8802
  continue;
8803
8803
  }
8804
8804
  if (!isPlainObject5(spec)) {
@@ -9014,12 +9014,12 @@ function validateNestedVerbs(params) {
9014
9014
  return value;
9015
9015
  if (!arms.some((arm) => value[arm] !== undefined))
9016
9016
  return one(value);
9017
- const next2 = { ...value };
9017
+ const next = { ...value };
9018
9018
  for (const arm of arms) {
9019
9019
  if (value[arm] !== undefined)
9020
- next2[arm] = many(value[arm]);
9020
+ next[arm] = many(value[arm]);
9021
9021
  }
9022
- return next2;
9022
+ return next;
9023
9023
  };
9024
9024
  const eachBody = (value, arms) => Array.isArray(value) ? value.map((item) => body(item, arms)) : body(value, arms);
9025
9025
  const next = { ...verbs };
@@ -9521,20 +9521,20 @@ function scopeSelection(params) {
9521
9521
  if (spec === undefined || spec === false)
9522
9522
  continue;
9523
9523
  if (name === "_count") {
9524
- const names = spec === true ? model.relations.filter((relation2) => relation2.isList).map((relation2) => relation2.name) : isPlainObject7(spec) && isPlainObject7(spec.select) ? Object.keys(spec.select).filter((key2) => {
9525
- const entry = spec.select[key2];
9524
+ const names = spec === true ? model.relations.filter((relation) => relation.isList).map((relation) => relation.name) : isPlainObject7(spec) && isPlainObject7(spec.select) ? Object.keys(spec.select).filter((key) => {
9525
+ const entry = spec.select[key];
9526
9526
  return entry === true || isPlainObject7(entry);
9527
9527
  }) : [];
9528
9528
  const countSelect = isPlainObject7(spec) && isPlainObject7(spec.select) ? { ...spec.select } : undefined;
9529
9529
  for (const counted of names) {
9530
- const relation2 = model.relationByName.get(counted);
9531
- const target2 = relation2 === undefined ? undefined : meta.modelByName.get(relation2.targetModel);
9532
- if (target2?.policy !== undefined) {
9530
+ const relation = model.relationByName.get(counted);
9531
+ const target = relation === undefined ? undefined : meta.modelByName.get(relation.targetModel);
9532
+ if (target?.policy !== undefined) {
9533
9533
  throw policyError(`_count of ${model.name}.${counted} cannot enforce @@policy because relation counts take no filter \u2014 use a scoped child count query instead`, { model: model.name, relation: counted });
9534
9534
  }
9535
9535
  const entry = countSelect?.[counted];
9536
- if (target2 !== undefined && countSelect !== undefined && isPlainObject7(entry) && entry.where !== undefined) {
9537
- countSelect[counted] = { ...entry, where: scopeWhere({ meta, model: target2, where: entry.where, context }) };
9536
+ if (target !== undefined && countSelect !== undefined && isPlainObject7(entry) && entry.where !== undefined) {
9537
+ countSelect[counted] = { ...entry, where: scopeWhere({ meta, model: target, where: entry.where, context }) };
9538
9538
  }
9539
9539
  }
9540
9540
  if (countSelect !== undefined)
@@ -9627,8 +9627,8 @@ function forceWriteData(params) {
9627
9627
  }
9628
9628
  function forceNestedVerbs(params) {
9629
9629
  const { meta, target, verbs, context } = params;
9630
- const walk2 = (row, phase) => isPlainObject7(row) ? forceWriteData({ meta, model: target, data: row, context, phase }) : row;
9631
- const each = (value, phase) => Array.isArray(value) ? value.map((row) => walk2(row, phase)) : walk2(value, phase);
9630
+ const walk = (row, phase) => isPlainObject7(row) ? forceWriteData({ meta, model: target, data: row, context, phase }) : row;
9631
+ const each = (value, phase) => Array.isArray(value) ? value.map((row) => walk(row, phase)) : walk(value, phase);
9632
9632
  const body = (value, keys) => {
9633
9633
  if (!isPlainObject7(value))
9634
9634
  return value;
@@ -9705,7 +9705,7 @@ function scopedDelegate(params) {
9705
9705
  const pkWhere = pk.length === 1 ? { [pk[0]]: target[pk[0]] } : { [pkClientKey()]: Object.fromEntries(pk.map((name) => [name, target[name]])) };
9706
9706
  return write(raw, pkWhere);
9707
9707
  };
9708
- const notFound2 = (method) => new VibeError24({ code: "VIBE_NOT_FOUND", message: `${method} on ${model.name}: no row matches the unique where inside the bound policy context`, meta: { model: model.name, method } });
9708
+ const notFound = (method) => new VibeError24({ code: "VIBE_NOT_FOUND", message: `${method} on ${model.name}: no row matches the unique where inside the bound policy context`, meta: { model: model.name, method } });
9709
9709
  return {
9710
9710
  findMany: (args) => base.findMany(scopeFind(args)),
9711
9711
  findFirst: (args) => base.findFirst(scopeFind(args)),
@@ -9724,9 +9724,9 @@ function scopedDelegate(params) {
9724
9724
  update: (args) => defer(async (tx) => {
9725
9725
  const raw = tx.$bypassPolicy === undefined ? tx : tx.$bypassPolicy();
9726
9726
  const data = writeData(args.data, "update");
9727
- const row = await lockThen(raw, args, (raw2, pkWhere) => raw2.$models[model.name].update({ ...scopeWrite(args), data, where: pkWhere }));
9727
+ const row = await lockThen(raw, args, (raw, pkWhere) => raw.$models[model.name].update({ ...scopeWrite(args), data, where: pkWhere }));
9728
9728
  if (row === null)
9729
- throw notFound2("update");
9729
+ throw notFound("update");
9730
9730
  return row;
9731
9731
  }),
9732
9732
  updateMany: (args) => deferred(() => base.updateMany({
@@ -9769,16 +9769,16 @@ function scopedDelegate(params) {
9769
9769
  const update = writeData(args.update, "update");
9770
9770
  const create = writeData(args.create, "create");
9771
9771
  const projection = scopeWrite(Object.fromEntries(["select", "include"].flatMap((key) => args[key] === undefined ? [] : [[key, args[key]]])));
9772
- const row = await lockThen(raw, args, (raw2, pkWhere) => raw2.$models[model.name].update({ ...projection, where: pkWhere, data: update }));
9772
+ const row = await lockThen(raw, args, (raw, pkWhere) => raw.$models[model.name].update({ ...projection, where: pkWhere, data: update }));
9773
9773
  if (row !== null)
9774
9774
  return row;
9775
9775
  return await raw.$models[model.name].create({ ...projection, data: create });
9776
9776
  }),
9777
9777
  delete: (args) => defer(async (tx) => {
9778
9778
  const raw = tx.$bypassPolicy === undefined ? tx : tx.$bypassPolicy();
9779
- const row = await lockThen(raw, args, (raw2, pkWhere) => raw2.$models[model.name].delete({ ...scopeWrite(args), where: pkWhere }));
9779
+ const row = await lockThen(raw, args, (raw, pkWhere) => raw.$models[model.name].delete({ ...scopeWrite(args), where: pkWhere }));
9780
9780
  if (row === null)
9781
- throw notFound2("delete");
9781
+ throw notFound("delete");
9782
9782
  return row;
9783
9783
  }),
9784
9784
  deleteMany: (args) => deferred(() => base.deleteMany({
@@ -10589,7 +10589,7 @@ function walkNestedVerbs(params) {
10589
10589
  const mode = nestedModeFor(targetEntry);
10590
10590
  const out = { ...verbs };
10591
10591
  const pred = (verbPath) => requirePred({ ctx, model: target, path: verbPath });
10592
- const refuse2 = (verb, why) => {
10592
+ const refuse = (verb, why) => {
10593
10593
  throw refusal({
10594
10594
  model: target.name,
10595
10595
  path: `${path}.${verb}`,
@@ -10618,7 +10618,7 @@ function walkNestedVerbs(params) {
10618
10618
  continue;
10619
10619
  }
10620
10620
  if (scoped && mode === "refuse" && REFERENCE_VERBS2.includes(verb)) {
10621
- refuse2(verb, `is disabled \u2014 ${target.name} is configured nested: "refuse"; go through the base client or its own delegate`);
10621
+ refuse(verb, `is disabled \u2014 ${target.name} is configured nested: "refuse"; go through the base client or its own delegate`);
10622
10622
  }
10623
10623
  switch (verb) {
10624
10624
  case "connect":
@@ -10633,9 +10633,9 @@ function walkNestedVerbs(params) {
10633
10633
  if (scoped) {
10634
10634
  const kind = link().kind;
10635
10635
  if (kind === "manyToMany")
10636
- refuse2(verb, "clears the whole join set \u2014 unlinking other tenants' rows cannot be verified; disconnect explicit rows instead");
10636
+ refuse(verb, "clears the whole join set \u2014 unlinking other tenants' rows cannot be verified; disconnect explicit rows instead");
10637
10637
  if (!implicitSafe)
10638
- refuse2(verb, "first detaches EVERY current child, which cannot be tenant-filtered on this edge; disconnect explicit rows instead");
10638
+ refuse(verb, "first detaches EVERY current child, which cannot be tenant-filtered on this edge; disconnect explicit rows instead");
10639
10639
  }
10640
10640
  out[verb] = mapItems(operand ?? [], (item) => isPlainObject8(item) ? uniqueWhere(item, verbPath) : item);
10641
10641
  break;
@@ -10646,10 +10646,10 @@ function walkNestedVerbs(params) {
10646
10646
  const kind = link().kind;
10647
10647
  if (kind === "toOneOwner") {
10648
10648
  if (tenancyEdge) {
10649
- refuse2(verb, "would orphan the row out of its tenant (through-parent set to null) \u2014 delete it or connect a replacement");
10649
+ refuse(verb, "would orphan the row out of its tenant (through-parent set to null) \u2014 delete it or connect a replacement");
10650
10650
  }
10651
10651
  } else if (!implicitSafe) {
10652
- refuse2(verb, "targets whatever row currently points here \u2014 not tenant-verifiable on this edge");
10652
+ refuse(verb, "targets whatever row currently points here \u2014 not tenant-verifiable on this edge");
10653
10653
  }
10654
10654
  }
10655
10655
  break;
@@ -10660,7 +10660,7 @@ function walkNestedVerbs(params) {
10660
10660
  case "delete": {
10661
10661
  if (!relation.isList) {
10662
10662
  if (scoped && !implicitSafe) {
10663
- refuse2(verb, "targets whatever row is currently connected \u2014 not tenant-verifiable on this edge");
10663
+ refuse(verb, "targets whatever row is currently connected \u2014 not tenant-verifiable on this edge");
10664
10664
  }
10665
10665
  break;
10666
10666
  }
@@ -10670,7 +10670,7 @@ function walkNestedVerbs(params) {
10670
10670
  case "update": {
10671
10671
  if (!relation.isList) {
10672
10672
  if (scoped && !implicitSafe) {
10673
- refuse2(verb, "targets whatever row is currently connected \u2014 not tenant-verifiable on this edge; update it through its own delegate");
10673
+ refuse(verb, "targets whatever row is currently connected \u2014 not tenant-verifiable on this edge; update it through its own delegate");
10674
10674
  }
10675
10675
  out[verb] = isPlainObject8(operand) ? "data" in operand && isPlainObject8(operand.data) ? { ...operand, data: walkChildUpdate(operand.data, verbPath) } : walkChildUpdate(operand, verbPath) : operand;
10676
10676
  break;
@@ -10687,7 +10687,7 @@ function walkNestedVerbs(params) {
10687
10687
  case "upsert": {
10688
10688
  if (!relation.isList) {
10689
10689
  if (scoped && !implicitSafe) {
10690
- refuse2(verb, "updates whatever row is currently connected \u2014 not tenant-verifiable on this edge");
10690
+ refuse(verb, "updates whatever row is currently connected \u2014 not tenant-verifiable on this edge");
10691
10691
  }
10692
10692
  out[verb] = isPlainObject8(operand) ? {
10693
10693
  ...operand,
@@ -10756,9 +10756,9 @@ function rewriteScopedCall(params) {
10756
10756
  case "findUniqueOrThrow": {
10757
10757
  walkSelection({ ctx, model, args, path: root });
10758
10758
  if (!scoped) {
10759
- const walked2 = walkOwnWhere(args.where, `${root}.where`);
10760
- if (walked2 !== undefined)
10761
- args.where = walked2;
10759
+ const walked = walkOwnWhere(args.where, `${root}.where`);
10760
+ if (walked !== undefined)
10761
+ args.where = walked;
10762
10762
  return { model: model.name, method, args };
10763
10763
  }
10764
10764
  const flat = isPlainObject8(args.where) ? flattenUniqueWhere({ model, where: args.where }) : args.where;
@@ -11570,186 +11570,186 @@ class StatementRenderCache {
11570
11570
  this.entries.set(key, slot);
11571
11571
  }
11572
11572
  }
11573
- function addIdent(walk2, name) {
11574
- walk2.key += `\xA7${name.length}~${name}`;
11573
+ function addIdent(walk, name) {
11574
+ walk.key += `\xA7${name.length}~${name}`;
11575
11575
  }
11576
- function addCol(walk2, column) {
11576
+ function addCol(walk, column) {
11577
11577
  if (column.table !== undefined)
11578
- addIdent(walk2, column.table);
11579
- walk2.key += ".";
11580
- addIdent(walk2, column.name);
11578
+ addIdent(walk, column.table);
11579
+ walk.key += ".";
11580
+ addIdent(walk, column.name);
11581
11581
  if (column.transform !== undefined)
11582
- walk2.key += column.transform === "castText" ? "^t" : "^b";
11582
+ walk.key += column.transform === "castText" ? "^t" : "^b";
11583
11583
  if (column.castReal === true)
11584
- walk2.key += "^r";
11584
+ walk.key += "^r";
11585
11585
  if (column.alias !== undefined) {
11586
- walk2.key += "^a";
11587
- addIdent(walk2, column.alias);
11586
+ walk.key += "^a";
11587
+ addIdent(walk, column.alias);
11588
11588
  }
11589
11589
  }
11590
- function addTable(walk2, table) {
11591
- addIdent(walk2, table.name);
11590
+ function addTable(walk, table) {
11591
+ addIdent(walk, table.name);
11592
11592
  if (table.alias !== undefined) {
11593
- walk2.key += "@";
11594
- addIdent(walk2, table.alias);
11593
+ walk.key += "@";
11594
+ addIdent(walk, table.alias);
11595
11595
  }
11596
11596
  }
11597
- function addAgg(walk2, agg) {
11598
- walk2.key += agg.fn;
11597
+ function addAgg(walk, agg) {
11598
+ walk.key += agg.fn;
11599
11599
  if (agg.fn !== "countAll")
11600
- addCol(walk2, agg.column);
11600
+ addCol(walk, agg.column);
11601
11601
  }
11602
- function addSetEntry(walk2, name, value) {
11602
+ function addSetEntry(walk, name, value) {
11603
11603
  if (isJsonParamCell(value)) {
11604
- walk2.key += "=j";
11605
- addIdent(walk2, name);
11606
- walk2.values.push(value.text);
11604
+ walk.key += "=j";
11605
+ addIdent(walk, name);
11606
+ walk.values.push(value.text);
11607
11607
  return;
11608
11608
  }
11609
11609
  if (isSetOperation(value)) {
11610
- walk2.key += `=o${value.__op}`;
11611
- addIdent(walk2, name);
11612
- walk2.values.push(value.value);
11610
+ walk.key += `=o${value.__op}`;
11611
+ addIdent(walk, name);
11612
+ walk.values.push(value.value);
11613
11613
  return;
11614
11614
  }
11615
11615
  if (isDbNowMarker(value)) {
11616
- walk2.key += value.offsetSeconds === 0 ? "=N0" : "=N1";
11617
- addIdent(walk2, name);
11616
+ walk.key += value.offsetSeconds === 0 ? "=N0" : "=N1";
11617
+ addIdent(walk, name);
11618
11618
  if (value.offsetSeconds !== 0)
11619
- walk2.values.push(value.offsetSeconds);
11619
+ walk.values.push(value.offsetSeconds);
11620
11620
  return;
11621
11621
  }
11622
11622
  if (isListSetOperation(value)) {
11623
- walk2.key += `=l${value.__listOp}`;
11624
- addIdent(walk2, name);
11625
- walk2.values.push(value.value);
11623
+ walk.key += `=l${value.__listOp}`;
11624
+ addIdent(walk, name);
11625
+ walk.values.push(value.value);
11626
11626
  return;
11627
11627
  }
11628
- walk2.key += "=v";
11629
- addIdent(walk2, name);
11630
- walk2.values.push(value);
11628
+ walk.key += "=v";
11629
+ addIdent(walk, name);
11630
+ walk.values.push(value);
11631
11631
  }
11632
- function addReturning(walk2, returning) {
11632
+ function addReturning(walk, returning) {
11633
11633
  if (returning === undefined || returning.length === 0) {
11634
- walk2.key += "r0";
11634
+ walk.key += "r0";
11635
11635
  return;
11636
11636
  }
11637
- walk2.key += "r(";
11637
+ walk.key += "r(";
11638
11638
  for (const name of returning)
11639
- addIdent(walk2, name);
11640
- walk2.key += ")";
11639
+ addIdent(walk, name);
11640
+ walk.key += ")";
11641
11641
  }
11642
- function walkExpr(walk2, dialect, expr) {
11642
+ function walkExpr(walk, dialect, expr) {
11643
11643
  switch (expr.kind) {
11644
11644
  case "cmp":
11645
11645
  if (isDbNowMarker(expr.value)) {
11646
- walk2.key += `cN${expr.op}${expr.value.offsetSeconds === 0 ? "0" : "1"}`;
11647
- addCol(walk2, expr.column);
11646
+ walk.key += `cN${expr.op}${expr.value.offsetSeconds === 0 ? "0" : "1"}`;
11647
+ addCol(walk, expr.column);
11648
11648
  if (expr.value.offsetSeconds !== 0)
11649
- walk2.values.push(expr.value.offsetSeconds);
11649
+ walk.values.push(expr.value.offsetSeconds);
11650
11650
  return true;
11651
11651
  }
11652
- walk2.key += `c${expr.op}`;
11653
- addCol(walk2, expr.column);
11654
- walk2.values.push(expr.value);
11652
+ walk.key += `c${expr.op}`;
11653
+ addCol(walk, expr.column);
11654
+ walk.values.push(expr.value);
11655
11655
  return true;
11656
11656
  case "cmpCol":
11657
- walk2.key += `k${expr.op}`;
11658
- addCol(walk2, expr.left);
11659
- addCol(walk2, expr.right);
11657
+ walk.key += `k${expr.op}`;
11658
+ addCol(walk, expr.left);
11659
+ addCol(walk, expr.right);
11660
11660
  return true;
11661
11661
  case "isNull":
11662
- walk2.key += expr.negate === true ? "n1" : "n0";
11663
- addCol(walk2, expr.column);
11662
+ walk.key += expr.negate === true ? "n1" : "n0";
11663
+ addCol(walk, expr.column);
11664
11664
  return true;
11665
11665
  case "inArray": {
11666
11666
  if (expr.values.length === 0) {
11667
- walk2.key += expr.negate === true ? "z1" : "z0";
11667
+ walk.key += expr.negate === true ? "z1" : "z0";
11668
11668
  return true;
11669
11669
  }
11670
- walk2.key += expr.negate === true ? "i1" : "i0";
11671
- addCol(walk2, expr.column);
11670
+ walk.key += expr.negate === true ? "i1" : "i0";
11671
+ addCol(walk, expr.column);
11672
11672
  if (dialect.inArrayStrategy === "any") {
11673
- walk2.values.push([...expr.values]);
11673
+ walk.values.push([...expr.values]);
11674
11674
  } else {
11675
- walk2.key += `#${expr.values.length}`;
11675
+ walk.key += `#${expr.values.length}`;
11676
11676
  for (const value of expr.values)
11677
- walk2.values.push(value);
11677
+ walk.values.push(value);
11678
11678
  }
11679
11679
  return true;
11680
11680
  }
11681
11681
  case "tupleIn": {
11682
11682
  if (expr.columns.length === 0)
11683
11683
  return false;
11684
- walk2.key += `Tu${expr.negate === true ? "1" : "0"}${expr.columns.length}#${expr.rows.length}(`;
11684
+ walk.key += `Tu${expr.negate === true ? "1" : "0"}${expr.columns.length}#${expr.rows.length}(`;
11685
11685
  for (const column of expr.columns)
11686
- addCol(walk2, column);
11687
- walk2.key += ")";
11686
+ addCol(walk, column);
11687
+ walk.key += ")";
11688
11688
  if (expr.rows.length === 0)
11689
11689
  return true;
11690
11690
  for (const row of expr.rows) {
11691
11691
  if (row.length !== expr.columns.length)
11692
11692
  return false;
11693
11693
  for (const value of row)
11694
- walk2.values.push(value);
11694
+ walk.values.push(value);
11695
11695
  }
11696
11696
  return true;
11697
11697
  }
11698
11698
  case "like":
11699
- walk2.key += `L${expr.insensitive === true ? "i" : "s"}${expr.negate === true ? "n" : "p"}`;
11700
- addCol(walk2, expr.column);
11701
- walk2.values.push(expr.pattern);
11699
+ walk.key += `L${expr.insensitive === true ? "i" : "s"}${expr.negate === true ? "n" : "p"}`;
11700
+ addCol(walk, expr.column);
11701
+ walk.values.push(expr.pattern);
11702
11702
  return true;
11703
11703
  case "strictMatch":
11704
- walk2.key += `S${expr.op}${expr.negate === true ? "n" : "p"}`;
11705
- addCol(walk2, expr.column);
11706
- walk2.values.push(expr.op === "equals" ? expr.value : strictMatchPattern({ strategy: dialect.strictMatchStrategy, op: expr.op, value: expr.value }));
11704
+ walk.key += `S${expr.op}${expr.negate === true ? "n" : "p"}`;
11705
+ addCol(walk, expr.column);
11706
+ walk.values.push(expr.op === "equals" ? expr.value : strictMatchPattern({ strategy: dialect.strictMatchStrategy, op: expr.op, value: expr.value }));
11707
11707
  return true;
11708
11708
  case "and":
11709
11709
  case "or": {
11710
- walk2.key += `${expr.kind === "and" ? "A" : "O"}${expr.operands.length}(`;
11710
+ walk.key += `${expr.kind === "and" ? "A" : "O"}${expr.operands.length}(`;
11711
11711
  for (const operand of expr.operands) {
11712
- if (!walkExpr(walk2, dialect, operand))
11712
+ if (!walkExpr(walk, dialect, operand))
11713
11713
  return false;
11714
11714
  }
11715
- walk2.key += ")";
11715
+ walk.key += ")";
11716
11716
  return true;
11717
11717
  }
11718
11718
  case "not":
11719
- walk2.key += "!(";
11720
- if (!walkExpr(walk2, dialect, expr.operand))
11719
+ walk.key += "!(";
11720
+ if (!walkExpr(walk, dialect, expr.operand))
11721
11721
  return false;
11722
- walk2.key += ")";
11722
+ walk.key += ")";
11723
11723
  return true;
11724
11724
  case "exists":
11725
- walk2.key += expr.negate === true ? "E1(" : "E0(";
11726
- if (!walkSelect(walk2, dialect, expr.select))
11725
+ walk.key += expr.negate === true ? "E1(" : "E0(";
11726
+ if (!walkSelect(walk, dialect, expr.select))
11727
11727
  return false;
11728
- walk2.key += ")";
11728
+ walk.key += ")";
11729
11729
  return true;
11730
11730
  case "aggCmp":
11731
- walk2.key += `g${expr.op}`;
11732
- addAgg(walk2, expr.agg);
11733
- walk2.values.push(expr.value);
11731
+ walk.key += `g${expr.op}`;
11732
+ addAgg(walk, expr.agg);
11733
+ walk.values.push(expr.value);
11734
11734
  return true;
11735
11735
  case "arrayHas":
11736
- walk2.key += expr.negate === true ? "h1" : "h0";
11737
- addCol(walk2, expr.column);
11738
- walk2.values.push(expr.value);
11736
+ walk.key += expr.negate === true ? "h1" : "h0";
11737
+ addCol(walk, expr.column);
11738
+ walk.values.push(expr.value);
11739
11739
  return true;
11740
11740
  case "arrayContainsAll":
11741
- walk2.key += "H";
11742
- addCol(walk2, expr.column);
11743
- walk2.values.push([...expr.values]);
11741
+ walk.key += "H";
11742
+ addCol(walk, expr.column);
11743
+ walk.values.push([...expr.values]);
11744
11744
  return true;
11745
11745
  case "arrayOverlaps":
11746
- walk2.key += "V";
11747
- addCol(walk2, expr.column);
11748
- walk2.values.push([...expr.values]);
11746
+ walk.key += "V";
11747
+ addCol(walk, expr.column);
11748
+ walk.values.push([...expr.values]);
11749
11749
  return true;
11750
11750
  case "arrayIsEmpty":
11751
- walk2.key += expr.empty ? "e1" : "e0";
11752
- addCol(walk2, expr.column);
11751
+ walk.key += expr.empty ? "e1" : "e0";
11752
+ addCol(walk, expr.column);
11753
11753
  return true;
11754
11754
  case "jsonFilter":
11755
11755
  return false;
@@ -11757,140 +11757,140 @@ function walkExpr(walk2, dialect, expr) {
11757
11757
  case "fragment":
11758
11758
  return false;
11759
11759
  case "raw":
11760
- walk2.key += "R(";
11761
- addIdent(walk2, expr.text);
11762
- walk2.key += ")";
11760
+ walk.key += "R(";
11761
+ addIdent(walk, expr.text);
11762
+ walk.key += ")";
11763
11763
  return true;
11764
11764
  }
11765
11765
  }
11766
- function walkOrderTerm2(walk2, dialect, term) {
11766
+ function walkOrderTerm2(walk, dialect, term) {
11767
11767
  if ("agg" in term) {
11768
- walk2.key += "a";
11769
- addAgg(walk2, term.agg);
11768
+ walk.key += "a";
11769
+ addAgg(walk, term.agg);
11770
11770
  } else if ("select" in term) {
11771
- walk2.key += "q(";
11772
- if (!walkSelect(walk2, dialect, term.select))
11771
+ walk.key += "q(";
11772
+ if (!walkSelect(walk, dialect, term.select))
11773
11773
  return false;
11774
- walk2.key += ")";
11774
+ walk.key += ")";
11775
11775
  } else {
11776
- addCol(walk2, term.column);
11777
- walk2.key += term.nulls === undefined ? "-" : term.nulls === "first" ? "^" : "$";
11776
+ addCol(walk, term.column);
11777
+ walk.key += term.nulls === undefined ? "-" : term.nulls === "first" ? "^" : "$";
11778
11778
  }
11779
- walk2.key += term.direction === "asc" ? "+" : "~";
11779
+ walk.key += term.direction === "asc" ? "+" : "~";
11780
11780
  return true;
11781
11781
  }
11782
- function walkSelect(walk2, dialect, statement) {
11783
- walk2.key += "S{";
11782
+ function walkSelect(walk, dialect, statement) {
11783
+ walk.key += "S{";
11784
11784
  if (statement.distinctOn !== undefined && statement.distinctOn.length > 0) {
11785
- walk2.key += "d(";
11785
+ walk.key += "d(";
11786
11786
  for (const column of statement.distinctOn)
11787
- addCol(walk2, column);
11788
- walk2.key += ")";
11787
+ addCol(walk, column);
11788
+ walk.key += ")";
11789
11789
  }
11790
- walk2.key += "p(";
11790
+ walk.key += "p(";
11791
11791
  for (const column of statement.columns)
11792
- addCol(walk2, column);
11793
- walk2.key += ")";
11792
+ addCol(walk, column);
11793
+ walk.key += ")";
11794
11794
  if (statement.selectExpr !== undefined) {
11795
11795
  if (statement.selectExpr.kind === "one") {
11796
- walk2.key += "x1";
11796
+ walk.key += "x1";
11797
11797
  } else {
11798
- walk2.key += "xc";
11798
+ walk.key += "xc";
11799
11799
  if (statement.selectExpr.alias !== undefined)
11800
- addIdent(walk2, statement.selectExpr.alias);
11800
+ addIdent(walk, statement.selectExpr.alias);
11801
11801
  }
11802
11802
  }
11803
11803
  if (statement.aggregates !== undefined) {
11804
11804
  for (const selection of statement.aggregates) {
11805
- walk2.key += "a";
11806
- addAgg(walk2, selection.agg);
11807
- addIdent(walk2, selection.alias);
11805
+ walk.key += "a";
11806
+ addAgg(walk, selection.agg);
11807
+ addIdent(walk, selection.alias);
11808
11808
  }
11809
11809
  }
11810
11810
  if (statement.rowNumber !== undefined) {
11811
- walk2.key += "W(";
11811
+ walk.key += "W(";
11812
11812
  for (const column of statement.rowNumber.partitionBy)
11813
- addCol(walk2, column);
11814
- walk2.key += ":";
11813
+ addCol(walk, column);
11814
+ walk.key += ":";
11815
11815
  for (const term of statement.rowNumber.orderBy) {
11816
- if (!walkOrderTerm2(walk2, dialect, term))
11816
+ if (!walkOrderTerm2(walk, dialect, term))
11817
11817
  return false;
11818
11818
  }
11819
- addIdent(walk2, statement.rowNumber.alias);
11820
- walk2.key += ")";
11819
+ addIdent(walk, statement.rowNumber.alias);
11820
+ walk.key += ")";
11821
11821
  }
11822
- walk2.key += "f";
11823
- addTable(walk2, statement.table);
11822
+ walk.key += "f";
11823
+ addTable(walk, statement.table);
11824
11824
  if (statement.fromSelect !== undefined) {
11825
- walk2.key += "F(";
11826
- if (!walkSelect(walk2, dialect, statement.fromSelect))
11825
+ walk.key += "F(";
11826
+ if (!walkSelect(walk, dialect, statement.fromSelect))
11827
11827
  return false;
11828
- walk2.key += ")";
11828
+ walk.key += ")";
11829
11829
  }
11830
11830
  if (statement.innerJoins !== undefined && statement.innerJoins.length > 0) {
11831
11831
  for (const join of statement.innerJoins) {
11832
- walk2.key += "J(";
11833
- addTable(walk2, join.table);
11832
+ walk.key += "J(";
11833
+ addTable(walk, join.table);
11834
11834
  for (const pair of join.on) {
11835
- addCol(walk2, pair.left);
11836
- walk2.key += "=";
11837
- addCol(walk2, pair.right);
11835
+ addCol(walk, pair.left);
11836
+ walk.key += "=";
11837
+ addCol(walk, pair.right);
11838
11838
  }
11839
- walk2.key += ")";
11839
+ walk.key += ")";
11840
11840
  }
11841
11841
  }
11842
11842
  if (statement.lateralJoins !== undefined && statement.lateralJoins.length > 0) {
11843
11843
  for (const join of statement.lateralJoins) {
11844
- walk2.key += join.agg === "count" ? "Jc(" : join.agg === "jsonArray" ? "Ja(" : "Jo(";
11845
- walk2.key += join.rowFormat === "positional" ? "pos;" : "obj;";
11846
- if (!walkSelect(walk2, dialect, join.select))
11844
+ walk.key += join.agg === "count" ? "Jc(" : join.agg === "jsonArray" ? "Ja(" : "Jo(";
11845
+ walk.key += join.rowFormat === "positional" ? "pos;" : "obj;";
11846
+ if (!walkSelect(walk, dialect, join.select))
11847
11847
  return false;
11848
- addIdent(walk2, join.columnAlias);
11849
- addIdent(walk2, join.alias);
11850
- walk2.key += ")";
11848
+ addIdent(walk, join.columnAlias);
11849
+ addIdent(walk, join.alias);
11850
+ walk.key += ")";
11851
11851
  }
11852
11852
  }
11853
11853
  if (statement.where !== undefined) {
11854
- walk2.key += "w";
11855
- if (!walkExpr(walk2, dialect, statement.where))
11854
+ walk.key += "w";
11855
+ if (!walkExpr(walk, dialect, statement.where))
11856
11856
  return false;
11857
11857
  }
11858
11858
  if (statement.groupBy !== undefined && statement.groupBy.length > 0) {
11859
- walk2.key += "b(";
11859
+ walk.key += "b(";
11860
11860
  for (const column of statement.groupBy)
11861
- addCol(walk2, column);
11862
- walk2.key += ")";
11861
+ addCol(walk, column);
11862
+ walk.key += ")";
11863
11863
  }
11864
11864
  if (statement.having !== undefined) {
11865
- walk2.key += "v";
11866
- if (!walkExpr(walk2, dialect, statement.having))
11865
+ walk.key += "v";
11866
+ if (!walkExpr(walk, dialect, statement.having))
11867
11867
  return false;
11868
11868
  }
11869
11869
  if (statement.orderBy !== undefined && statement.orderBy.length > 0) {
11870
- walk2.key += "o(";
11870
+ walk.key += "o(";
11871
11871
  for (const term of statement.orderBy) {
11872
- if (!walkOrderTerm2(walk2, dialect, term))
11872
+ if (!walkOrderTerm2(walk, dialect, term))
11873
11873
  return false;
11874
11874
  }
11875
- walk2.key += ")";
11875
+ walk.key += ")";
11876
11876
  }
11877
11877
  if (statement.limit !== undefined)
11878
- walk2.key += `t${statement.limit}`;
11878
+ walk.key += `t${statement.limit}`;
11879
11879
  if (statement.offset !== undefined)
11880
- walk2.key += `s${statement.offset}`;
11880
+ walk.key += `s${statement.offset}`;
11881
11881
  if (statement.rowLock !== undefined) {
11882
- walk2.key += `u:${statement.rowLock.strength}/${statement.rowLock.wait}`;
11882
+ walk.key += `u:${statement.rowLock.strength}/${statement.rowLock.wait}`;
11883
11883
  }
11884
- walk2.key += "}";
11884
+ walk.key += "}";
11885
11885
  return true;
11886
11886
  }
11887
- function walkInsert(walk2, dialect, statement) {
11888
- walk2.key += "I{";
11889
- addTable(walk2, statement.table);
11890
- walk2.key += "c(";
11887
+ function walkInsert(walk, dialect, statement) {
11888
+ walk.key += "I{";
11889
+ addTable(walk, statement.table);
11890
+ walk.key += "c(";
11891
11891
  for (const name of statement.columns)
11892
- addIdent(walk2, name);
11893
- walk2.key += `)r${statement.rows.length}`;
11892
+ addIdent(walk, name);
11893
+ walk.key += `)r${statement.rows.length}`;
11894
11894
  const arity = statement.columns.length;
11895
11895
  for (let rowIndex = 0;rowIndex < statement.rows.length; rowIndex++) {
11896
11896
  const row = statement.rows[rowIndex];
@@ -11899,95 +11899,95 @@ function walkInsert(walk2, dialect, statement) {
11899
11899
  for (let cell = 0;cell < row.length; cell++) {
11900
11900
  const value = row[cell];
11901
11901
  if (isSqlDefaultCell(value))
11902
- walk2.key += `D${rowIndex}:${cell};`;
11902
+ walk.key += `D${rowIndex}:${cell};`;
11903
11903
  else if (isJsonParamCell(value)) {
11904
- walk2.key += `J${rowIndex}:${cell};`;
11905
- walk2.values.push(value.text);
11904
+ walk.key += `J${rowIndex}:${cell};`;
11905
+ walk.values.push(value.text);
11906
11906
  } else if (isDbNowMarker(value)) {
11907
- walk2.key += `T${rowIndex}:${cell}:${value.offsetSeconds === 0 ? "0" : "1"};`;
11907
+ walk.key += `T${rowIndex}:${cell}:${value.offsetSeconds === 0 ? "0" : "1"};`;
11908
11908
  if (value.offsetSeconds !== 0)
11909
- walk2.values.push(value.offsetSeconds);
11909
+ walk.values.push(value.offsetSeconds);
11910
11910
  } else
11911
- walk2.values.push(value);
11911
+ walk.values.push(value);
11912
11912
  }
11913
11913
  }
11914
11914
  const onConflict = statement.onConflict;
11915
11915
  if (onConflict !== undefined) {
11916
11916
  if ("doNothing" in onConflict) {
11917
- walk2.key += "N(";
11917
+ walk.key += "N(";
11918
11918
  if (onConflict.constraint !== undefined) {
11919
- walk2.key += "K";
11920
- addIdent(walk2, onConflict.constraint);
11919
+ walk.key += "K";
11920
+ addIdent(walk, onConflict.constraint);
11921
11921
  }
11922
11922
  if (onConflict.columns !== undefined) {
11923
11923
  for (const name of onConflict.columns)
11924
- addIdent(walk2, name);
11924
+ addIdent(walk, name);
11925
11925
  }
11926
11926
  if (onConflict.conflictWhere !== undefined) {
11927
- walk2.key += "w";
11928
- addIdent(walk2, onConflict.conflictWhere);
11927
+ walk.key += "w";
11928
+ addIdent(walk, onConflict.conflictWhere);
11929
11929
  }
11930
- walk2.key += ")";
11930
+ walk.key += ")";
11931
11931
  } else {
11932
11932
  if (Object.values(onConflict.update).some(isSqlFragment3))
11933
11933
  return false;
11934
- walk2.key += "U(";
11934
+ walk.key += "U(";
11935
11935
  if (onConflict.constraint !== undefined) {
11936
- walk2.key += "K";
11937
- addIdent(walk2, onConflict.constraint);
11936
+ walk.key += "K";
11937
+ addIdent(walk, onConflict.constraint);
11938
11938
  }
11939
11939
  for (const name of onConflict.columns)
11940
- addIdent(walk2, name);
11941
- walk2.key += ":";
11940
+ addIdent(walk, name);
11941
+ walk.key += ":";
11942
11942
  for (const [name, value] of Object.entries(onConflict.update))
11943
- addSetEntry(walk2, name, value);
11943
+ addSetEntry(walk, name, value);
11944
11944
  if (onConflict.lastInsertIdColumn !== undefined) {
11945
- walk2.key += "@";
11946
- addIdent(walk2, onConflict.lastInsertIdColumn);
11945
+ walk.key += "@";
11946
+ addIdent(walk, onConflict.lastInsertIdColumn);
11947
11947
  }
11948
- walk2.key += ")";
11948
+ walk.key += ")";
11949
11949
  }
11950
11950
  }
11951
- addReturning(walk2, statement.returning);
11952
- walk2.key += "}";
11951
+ addReturning(walk, statement.returning);
11952
+ walk.key += "}";
11953
11953
  return true;
11954
11954
  }
11955
- function walkUpdate(walk2, dialect, statement) {
11956
- walk2.key += "U{";
11957
- addTable(walk2, statement.table);
11955
+ function walkUpdate(walk, dialect, statement) {
11956
+ walk.key += "U{";
11957
+ addTable(walk, statement.table);
11958
11958
  for (const [name, value] of Object.entries(statement.set))
11959
- addSetEntry(walk2, name, value);
11959
+ addSetEntry(walk, name, value);
11960
11960
  if (statement.where !== undefined) {
11961
- walk2.key += "w";
11962
- if (!walkExpr(walk2, dialect, statement.where))
11961
+ walk.key += "w";
11962
+ if (!walkExpr(walk, dialect, statement.where))
11963
11963
  return false;
11964
11964
  }
11965
- addReturning(walk2, statement.returning);
11966
- walk2.key += "}";
11965
+ addReturning(walk, statement.returning);
11966
+ walk.key += "}";
11967
11967
  return true;
11968
11968
  }
11969
- function walkDelete(walk2, dialect, statement) {
11970
- walk2.key += "D{";
11971
- addTable(walk2, statement.table);
11969
+ function walkDelete(walk, dialect, statement) {
11970
+ walk.key += "D{";
11971
+ addTable(walk, statement.table);
11972
11972
  if (statement.where !== undefined) {
11973
- walk2.key += "w";
11974
- if (!walkExpr(walk2, dialect, statement.where))
11973
+ walk.key += "w";
11974
+ if (!walkExpr(walk, dialect, statement.where))
11975
11975
  return false;
11976
11976
  }
11977
- addReturning(walk2, statement.returning);
11978
- walk2.key += "}";
11977
+ addReturning(walk, statement.returning);
11978
+ walk.key += "}";
11979
11979
  return true;
11980
11980
  }
11981
- function walkStatement(walk2, dialect, statement) {
11981
+ function walkStatement(walk, dialect, statement) {
11982
11982
  switch (statement.kind) {
11983
11983
  case "select":
11984
- return walkSelect(walk2, dialect, statement);
11984
+ return walkSelect(walk, dialect, statement);
11985
11985
  case "insert":
11986
- return walkInsert(walk2, dialect, statement);
11986
+ return walkInsert(walk, dialect, statement);
11987
11987
  case "update":
11988
- return walkUpdate(walk2, dialect, statement);
11988
+ return walkUpdate(walk, dialect, statement);
11989
11989
  case "delete":
11990
- return walkDelete(walk2, dialect, statement);
11990
+ return walkDelete(walk, dialect, statement);
11991
11991
  case "rlsEnable":
11992
11992
  case "rlsForce":
11993
11993
  case "rlsDisable":
@@ -12025,18 +12025,18 @@ function sameValues(walked, rendered) {
12025
12025
  }
12026
12026
  function renderStatementCached(params) {
12027
12027
  const { dialect, statement, cache } = params;
12028
- const walk2 = { key: "", values: [] };
12029
- if (!walkStatement(walk2, dialect, statement)) {
12028
+ const walk = { key: "", values: [] };
12029
+ if (!walkStatement(walk, dialect, statement)) {
12030
12030
  return renderStatement4({ dialect, statement });
12031
12031
  }
12032
- const slot = cache.get(walk2.key);
12032
+ const slot = cache.get(walk.key);
12033
12033
  if (slot !== undefined) {
12034
12034
  if (slot === null)
12035
12035
  return renderStatement4({ dialect, statement });
12036
- return { text: slot.text, values: walk2.values, returning: slot.returning };
12036
+ return { text: slot.text, values: walk.values, returning: slot.returning };
12037
12037
  }
12038
12038
  const rendered = renderStatement4({ dialect, statement });
12039
- cache.set(walk2.key, sameValues(walk2.values, rendered.values) ? { text: rendered.text, returning: rendered.returning } : null);
12039
+ cache.set(walk.key, sameValues(walk.values, rendered.values) ? { text: rendered.text, returning: rendered.returning } : null);
12040
12040
  return rendered;
12041
12041
  }
12042
12042
 
@@ -12057,32 +12057,63 @@ function isPlainObject9(value) {
12057
12057
  const proto = Object.getPrototypeOf(value);
12058
12058
  return proto === Object.prototype || proto === null;
12059
12059
  }
12060
- function descend(params) {
12061
- const { ctx, model, key } = params;
12062
- const field = model.fieldByName.get(key);
12063
- if (field !== undefined)
12064
- return field.scalarType === "Json" ? "json" : model;
12065
- const relation = model.relationByName.get(key);
12066
- if (relation === undefined)
12067
- return model;
12068
- return ctx.meta.modelByName.get(relation.targetModel) ?? model;
12069
- }
12060
+ var STRUCTURAL_KEYWORDS = Object.freeze({
12061
+ where: { level: "fields", filter: true },
12062
+ having: { level: "fields", filter: true },
12063
+ some: { level: "fields", filter: true },
12064
+ every: { level: "fields", filter: true },
12065
+ none: { level: "fields", filter: true },
12066
+ is: { level: "fields", filter: true },
12067
+ isNot: { level: "fields", filter: true },
12068
+ deleteMany: { level: "fields", filter: true },
12069
+ data: { level: "fields", filter: false },
12070
+ create: { level: "fields", filter: false },
12071
+ set: { level: "fields", filter: false },
12072
+ connect: { level: "fields", filter: false },
12073
+ disconnect: { level: "fields", filter: false },
12074
+ delete: { level: "fields", filter: false },
12075
+ cursor: { level: "fields", filter: false },
12076
+ select: { level: "fields", filter: "inherit" },
12077
+ include: { level: "fields", filter: "inherit" },
12078
+ omit: { level: "fields", filter: "inherit" },
12079
+ orderBy: { level: "fields", filter: "inherit" },
12080
+ connectOrCreate: { level: "structural", filter: "inherit" },
12081
+ upsert: { level: "structural", filter: "inherit" },
12082
+ createMany: { level: "structural", filter: "inherit" },
12083
+ updateMany: { level: "structural", filter: "inherit" },
12084
+ _count: { level: "structural", filter: "inherit" },
12085
+ update: { level: "structural", filter: false }
12086
+ });
12087
+ var LOGICAL_KEYS = new Set(["AND", "OR", "NOT"]);
12070
12088
  function walkArray(params) {
12071
- const { ctx, model, value, path, filter } = params;
12089
+ const { ctx, model, value, path, level, filter } = params;
12072
12090
  let changed = false;
12073
12091
  const out = value.map((item, index) => {
12074
- const next = walkNode({ ctx, model, value: item, path: `${path}[${index}]`, filter });
12092
+ const next = walkNode({ ctx, model, value: item, path: `${path}[${index}]`, level, filter });
12075
12093
  if (next !== item)
12076
12094
  changed = true;
12077
12095
  return next;
12078
12096
  });
12079
12097
  return changed ? out : value;
12080
12098
  }
12099
+ function walkJsonOperators(params) {
12100
+ const { ctx, value, path } = params;
12101
+ let filtered = null;
12102
+ for (const operator of Object.keys(value)) {
12103
+ if (value[operator] === undefined) {
12104
+ throw explicitUndefined({ model: ctx.model, method: ctx.method, path: `${path}.${operator}` });
12105
+ }
12106
+ if (value[operator] === SKIP) {
12107
+ filtered ??= { ...value };
12108
+ delete filtered[operator];
12109
+ }
12110
+ }
12111
+ return filtered ?? value;
12112
+ }
12081
12113
  function walkNode(params) {
12082
- const { ctx, model, value, path } = params;
12083
- const filter = params.filter === true;
12114
+ const { ctx, model, value, path, level, filter } = params;
12084
12115
  if (Array.isArray(value))
12085
- return walkArray({ ctx, model, value, path, filter });
12116
+ return walkArray({ ctx, model, value, path, level, filter });
12086
12117
  if (!isPlainObject9(value))
12087
12118
  return value;
12088
12119
  let out = null;
@@ -12097,33 +12128,31 @@ function walkNode(params) {
12097
12128
  delete out[key];
12098
12129
  continue;
12099
12130
  }
12100
- const target = descend({ ctx, model, key });
12101
- if (target === "json") {
12102
- if (filter && isPlainObject9(child)) {
12103
- let filtered = null;
12104
- for (const operator of Object.keys(child)) {
12105
- if (child[operator] === undefined) {
12106
- throw explicitUndefined({ model: ctx.model, method: ctx.method, path: `${childPath}.${operator}` });
12107
- }
12108
- if (child[operator] === SKIP) {
12109
- filtered ??= { ...child };
12110
- delete filtered[operator];
12111
- }
12112
- }
12113
- if (filtered !== null) {
12114
- out ??= { ...value };
12115
- out[key] = filtered;
12116
- }
12131
+ let next;
12132
+ const keyword = level === "structural" ? STRUCTURAL_KEYWORDS[key] : undefined;
12133
+ if (keyword !== undefined) {
12134
+ next = walkNode({
12135
+ ctx,
12136
+ model,
12137
+ value: child,
12138
+ path: childPath,
12139
+ level: keyword.level,
12140
+ filter: keyword.filter === "inherit" ? filter : keyword.filter
12141
+ });
12142
+ } else if (LOGICAL_KEYS.has(key)) {
12143
+ next = walkNode({ ctx, model, value: child, path: childPath, level: "fields", filter });
12144
+ } else {
12145
+ const field = model.fieldByName.get(key);
12146
+ if (field !== undefined && field.scalarType === "Json") {
12147
+ next = filter && isPlainObject9(child) ? walkJsonOperators({ ctx, value: child, path: childPath }) : child;
12148
+ } else if (field !== undefined) {
12149
+ next = walkNode({ ctx, model, value: child, path: childPath, level: "fields", filter });
12150
+ } else {
12151
+ const relation = model.relationByName.get(key);
12152
+ const target = relation === undefined ? undefined : ctx.meta.modelByName.get(relation.targetModel);
12153
+ next = target === undefined ? walkNode({ ctx, model, value: child, path: childPath, level: "fields", filter }) : walkNode({ ctx, model: target, value: child, path: childPath, level: "structural", filter });
12117
12154
  }
12118
- continue;
12119
12155
  }
12120
- const next = walkNode({
12121
- ctx,
12122
- model: target,
12123
- value: child,
12124
- path: childPath,
12125
- filter: key === "where" || key === "having" ? true : key === "data" || key === "create" || key === "update" ? false : filter
12126
- });
12127
12156
  if (next !== child) {
12128
12157
  out ??= { ...value };
12129
12158
  out[key] = next;
@@ -12136,7 +12165,7 @@ function checkStrictArguments(params) {
12136
12165
  if (args === undefined)
12137
12166
  return;
12138
12167
  const ctx = { meta, model: model.clientName, method };
12139
- const walked = walkNode({ ctx, model, value: args, path: "args" });
12168
+ const walked = walkNode({ ctx, model, value: args, path: "args", level: "structural", filter: false });
12140
12169
  return walked;
12141
12170
  }
12142
12171
 
@@ -13093,11 +13122,11 @@ async function runRows(params) {
13093
13122
  return materializeRows({ dialect: engine.dialect.name, model: plan.model, rows, wire: engine.adapter.wire });
13094
13123
  }
13095
13124
  async function runBoundAffected(params) {
13096
- const { adapter, text: text2, values } = params;
13097
- const bound2 = adapter.executeAffected;
13098
- if (bound2 !== undefined)
13099
- return await bound2.call(adapter, { text: text2, values });
13100
- return await adapter.executeUnsafe({ text: text2, values });
13125
+ const { adapter, text, values } = params;
13126
+ const bound = adapter.executeAffected;
13127
+ if (bound !== undefined)
13128
+ return await bound.call(adapter, { text, values });
13129
+ return await adapter.executeUnsafe({ text, values });
13101
13130
  }
13102
13131
  async function runAffected(params) {
13103
13132
  const { engine, plan } = params;
@@ -13314,22 +13343,22 @@ async function runSingleMutation(params) {
13314
13343
  if (!hasIdTrick)
13315
13344
  throw notFound2({ model: source.model.name, method: source.method });
13316
13345
  const where = await insertedKeyWhere({ engine: txEngine, source: { ...source, refetchWhere: null } });
13317
- const after2 = await refetch({ engine: txEngine, source, where });
13318
- if (after2 === null)
13346
+ const after = await refetch({ engine: txEngine, source, where });
13347
+ if (after === null)
13319
13348
  throw notFound2({ model: source.model.name, method: source.method });
13320
- return after2;
13349
+ return after;
13321
13350
  });
13322
13351
  }
13323
13352
  if (source.method === "update") {
13324
13353
  return await engine.adapter.transaction(async (txAdapter) => {
13325
13354
  const txEngine = { ...engine, adapter: txAdapter, inTransaction: true };
13326
- const { affectedRows: affected2 } = await executeWrite(txEngine);
13327
- if (affected2 === 0)
13355
+ const { affectedRows: affected } = await executeWrite(txEngine);
13356
+ if (affected === 0)
13328
13357
  throw notFound2({ model: source.model.name, method: source.method });
13329
- const after2 = await refetch({ engine: txEngine, source, where: knownWhere });
13330
- if (after2 === null)
13358
+ const after = await refetch({ engine: txEngine, source, where: knownWhere });
13359
+ if (after === null)
13331
13360
  throw notFound2({ model: source.model.name, method: source.method });
13332
- return after2;
13361
+ return after;
13333
13362
  });
13334
13363
  }
13335
13364
  const { affectedRows: affected } = await executeWrite(engine);
@@ -13509,21 +13538,21 @@ function makeWriteContext(params) {
13509
13538
  }
13510
13539
  function readOnlyDelegate2(params) {
13511
13540
  const { delegate, model } = params;
13512
- const refuse2 = (method) => async () => {
13541
+ const refuse = (method) => async () => {
13513
13542
  throw viewIsReadOnly({ model, method });
13514
13543
  };
13515
13544
  return {
13516
13545
  ...delegate,
13517
- create: refuse2("create"),
13518
- createMany: refuse2("createMany"),
13519
- createManyAndReturn: refuse2("createManyAndReturn"),
13520
- update: refuse2("update"),
13521
- updateMany: refuse2("updateMany"),
13522
- updateManyAndReturn: refuse2("updateManyAndReturn"),
13523
- upsert: refuse2("upsert"),
13524
- upsertMany: refuse2("upsertMany"),
13525
- delete: refuse2("delete"),
13526
- deleteMany: refuse2("deleteMany")
13546
+ create: refuse("create"),
13547
+ createMany: refuse("createMany"),
13548
+ createManyAndReturn: refuse("createManyAndReturn"),
13549
+ update: refuse("update"),
13550
+ updateMany: refuse("updateMany"),
13551
+ updateManyAndReturn: refuse("updateManyAndReturn"),
13552
+ upsert: refuse("upsert"),
13553
+ upsertMany: refuse("upsertMany"),
13554
+ delete: refuse("delete"),
13555
+ deleteMany: refuse("deleteMany")
13527
13556
  };
13528
13557
  }
13529
13558
  function isEffectivelyEmptyData(value) {
@@ -13574,7 +13603,7 @@ function createDelegate(params) {
13574
13603
  });
13575
13604
  }
13576
13605
  const shape = resolveResultShape({ meta: target.meta, model: modelMeta, method: "create", args });
13577
- const row2 = await createWithNested({
13606
+ const row = await createWithNested({
13578
13607
  ctx: makeWriteContext({ engine: target }),
13579
13608
  model: modelMeta,
13580
13609
  data: args.data
@@ -13583,7 +13612,7 @@ function createDelegate(params) {
13583
13612
  engine: target,
13584
13613
  model: modelMeta,
13585
13614
  shape: { ...shape, relationStrategy: "query" },
13586
- row: row2
13615
+ row
13587
13616
  });
13588
13617
  }
13589
13618
  const built = plan({ engine: target, model, method: "create", args });
@@ -13601,7 +13630,7 @@ function createDelegate(params) {
13601
13630
  const modelMeta = getModelMeta({ meta: target.meta, model });
13602
13631
  if (hasNestedWrites({ model: modelMeta, data: args.data })) {
13603
13632
  const shape = resolveResultShape({ meta: target.meta, model: modelMeta, method: "update", args });
13604
- const row2 = await updateWithNested({
13633
+ const row = await updateWithNested({
13605
13634
  ctx: makeWriteContext({ engine: target }),
13606
13635
  model: modelMeta,
13607
13636
  where: args.where,
@@ -13611,7 +13640,7 @@ function createDelegate(params) {
13611
13640
  engine: target,
13612
13641
  model: modelMeta,
13613
13642
  shape: { ...shape, relationStrategy: "query" },
13614
- row: row2
13643
+ row
13615
13644
  });
13616
13645
  }
13617
13646
  const built = plan({ engine: target, model, method: "update", args });
@@ -13688,12 +13717,12 @@ function createDelegate(params) {
13688
13717
  method: "upsert",
13689
13718
  args
13690
13719
  });
13691
- const row2 = await runUpsertFallback({ engine: target, model: modelMeta, args });
13720
+ const row = await runUpsertFallback({ engine: target, model: modelMeta, args });
13692
13721
  return await finalizeRow({
13693
13722
  engine: target,
13694
13723
  model: modelMeta,
13695
13724
  shape: { ...shape, relationStrategy: "query" },
13696
- row: row2
13725
+ row
13697
13726
  });
13698
13727
  }
13699
13728
  const built = plan({ engine: target, model, method: "upsert", args });
@@ -13848,11 +13877,11 @@ function withStrictArguments(params) {
13848
13877
  function buildRawStatement(params) {
13849
13878
  const { dialect, strings, values } = params;
13850
13879
  const collector = new ParamCollector(dialect);
13851
- let text2 = strings[0] ?? "";
13880
+ let text = strings[0] ?? "";
13852
13881
  for (let index = 0;index < values.length; index++) {
13853
- text2 += collector.add(values[index]) + (strings[index + 1] ?? "");
13882
+ text += collector.add(values[index]) + (strings[index + 1] ?? "");
13854
13883
  }
13855
- return { text: text2, values: collector.values };
13884
+ return { text, values: collector.values };
13856
13885
  }
13857
13886
  function buildClient(params) {
13858
13887
  const { engine } = params;
@@ -13869,7 +13898,7 @@ function buildClient(params) {
13869
13898
  models[model.name] = delegate;
13870
13899
  models[model.clientName] = delegate;
13871
13900
  }
13872
- const runRaw = async (method, statement, decodeRows2) => {
13901
+ const runRaw = async (method, statement, decodeRows) => {
13873
13902
  const scope = beginOperation({ engine, kind: "raw", model: null, method });
13874
13903
  scope?.dispatch();
13875
13904
  const running = executeOperation({
@@ -13885,7 +13914,7 @@ function buildClient(params) {
13885
13914
  rowCount: (value) => method.startsWith("$query") ? value.rows.length : value.affectedRows,
13886
13915
  run: () => statement.values.length > 0 ? target.adapter.executeRawBound !== undefined ? target.adapter.executeRawBound(statement) : runBoundAffected({ adapter: target.adapter, text: statement.text, values: statement.values }) : target.adapter.executeUnsafe(statement)
13887
13916
  });
13888
- decodeRows2?.(result.rows);
13917
+ decodeRows?.(result.rows);
13889
13918
  return result;
13890
13919
  }
13891
13920
  });
@@ -13901,8 +13930,8 @@ function buildClient(params) {
13901
13930
  });
13902
13931
  return await running;
13903
13932
  };
13904
- const runAdvisoryLock = async (params2) => {
13905
- const { method, options } = params2;
13933
+ const runAdvisoryLock = async (params) => {
13934
+ const { method, options } = params;
13906
13935
  assertEngineActive({ engine });
13907
13936
  const statement = compileAdvisoryLock({
13908
13937
  dialect: engine.dialect,
@@ -14048,8 +14077,8 @@ function buildClient(params) {
14048
14077
  },
14049
14078
  $queryRaw: async (strings, ...values) => (await runRaw("$queryRaw", buildRawStatement({ dialect: engine.dialect, strings, values }))).rows,
14050
14079
  $executeRaw: async (strings, ...values) => (await runRaw("$executeRaw", buildRawStatement({ dialect: engine.dialect, strings, values }))).affectedRows,
14051
- $queryRawUnsafe: async (text2, ...values) => (await runRaw("$queryRawUnsafe", { text: text2, values })).rows,
14052
- $executeRawUnsafe: async (text2, ...values) => (await runRaw("$executeRawUnsafe", { text: text2, values })).affectedRows,
14080
+ $queryRawUnsafe: async (text, ...values) => (await runRaw("$queryRawUnsafe", { text, values })).rows,
14081
+ $executeRawUnsafe: async (text, ...values) => (await runRaw("$executeRawUnsafe", { text, values })).affectedRows,
14053
14082
  $advisoryLock: async (options) => {
14054
14083
  await runAdvisoryLock({ method: "$advisoryLock", options });
14055
14084
  },
@@ -14095,7 +14124,7 @@ function buildClient(params) {
14095
14124
  }
14096
14125
  attachExtensionMounts({ engine, client, models });
14097
14126
  attachDefineView({ client, meta: engine.meta, models });
14098
- const wrapDelegate = engine.options?.strictArguments !== false ? (params2) => withStrictArguments({ engine, ...params2 }) : undefined;
14127
+ const wrapDelegate = engine.options?.strictArguments !== false ? (params) => withStrictArguments({ engine, ...params }) : undefined;
14099
14128
  if (engine.rlsSchema === undefined)
14100
14129
  attachScoped({ client, meta: engine.meta, ...wrapDelegate === undefined ? {} : { wrapDelegate } });
14101
14130
  if (engine.rlsSchema === undefined) {
@@ -14170,7 +14199,7 @@ function makeMountContext(params) {
14170
14199
  provider: engine.adapter.provider,
14171
14200
  meta: engine.meta,
14172
14201
  model,
14173
- executeRows: async ({ text: text2, values, method }) => {
14202
+ executeRows: async ({ text, values, method }) => {
14174
14203
  const scope = beginOperation({
14175
14204
  engine,
14176
14205
  kind: "extension",
@@ -14186,11 +14215,11 @@ function makeMountContext(params) {
14186
14215
  kind: "extension",
14187
14216
  model: model?.name ?? null,
14188
14217
  method: method ?? extension,
14189
- text: text2,
14218
+ text,
14190
14219
  values,
14191
14220
  rowCount: (value) => value.length,
14192
14221
  run: () => target.adapter.execute({
14193
- text: text2,
14222
+ text,
14194
14223
  values: bindValues({ adapter: target.adapter, values: [...values] })
14195
14224
  })
14196
14225
  });
@@ -14210,11 +14239,12 @@ function makeMountContext(params) {
14210
14239
  meta: { extension }
14211
14240
  });
14212
14241
  }
14242
+ const checked = engine.options?.strictArguments !== false ? checkStrictArguments({ meta: engine.meta, model: target, method: `${extension}.compileWhere`, args: { where } }) : undefined;
14213
14243
  return compileWhere({
14214
14244
  dialect: engine.dialect,
14215
14245
  meta: engine.meta,
14216
14246
  model: target,
14217
- where,
14247
+ where: checked === undefined ? where : checked.where,
14218
14248
  ...qualify === undefined ? {} : { qualify }
14219
14249
  });
14220
14250
  }
@@ -14273,8 +14303,8 @@ function attachExtensionMounts(params) {
14273
14303
  meta: { extension: mount.extension, model: model.name, property: mount.property }
14274
14304
  });
14275
14305
  }
14276
- const value2 = createMountSurface({ engine, mount, model });
14277
- Object.defineProperty(delegate, mount.property, { value: value2, enumerable: true, configurable: true });
14306
+ const value = createMountSurface({ engine, mount, model });
14307
+ Object.defineProperty(delegate, mount.property, { value, enumerable: true, configurable: true });
14278
14308
  continue;
14279
14309
  }
14280
14310
  if (!mount.property.startsWith("$") || mount.property in client) {
@@ -14414,8 +14444,8 @@ function validation(params) {
14414
14444
  return new VibeError32({ code: "VIBE_VALIDATION", message: params.message, meta: params.meta });
14415
14445
  }
14416
14446
  function projectionFor(params) {
14417
- const { plan: plan2, select, omit } = params;
14418
- const names = plan2.keys.map((key) => key.field.name);
14447
+ const { plan, select, omit } = params;
14448
+ const names = plan.keys.map((key) => key.field.name);
14419
14449
  if (select !== undefined) {
14420
14450
  const hidden = names.filter((name) => select[name] !== true);
14421
14451
  if (hidden.length === 0)
@@ -14445,13 +14475,13 @@ function iterateKeyset(options) {
14445
14475
  });
14446
14476
  }
14447
14477
  const model = getModelMeta({ meta, model: options.model });
14448
- const plan2 = compileKeysetOrderPlan({
14478
+ const plan = compileKeysetOrderPlan({
14449
14479
  model,
14450
14480
  dialect,
14451
14481
  terms: compileKeysetOrderInputs({ dialect, meta, model, orderBy }),
14452
14482
  ...options.timestampPrecision === undefined ? {} : { timestampPrecision: options.timestampPrecision }
14453
14483
  });
14454
- const projection = projectionFor({ plan: plan2, select: options.select, omit: options.omit });
14484
+ const projection = projectionFor({ plan, select: options.select, omit: options.omit });
14455
14485
  const keysetArg = options.timestampPrecision === undefined ? {} : { keyset: { timestampPrecision: options.timestampPrecision } };
14456
14486
  let buffer = [];
14457
14487
  let position = options.after ?? null;
@@ -14482,16 +14512,16 @@ function iterateKeyset(options) {
14482
14512
  const first = rows[0];
14483
14513
  if (position !== null && first !== undefined) {
14484
14514
  const advanced = keysetRowIsAfter({
14485
- keys: plan2.keys,
14486
- row: keysetRowValues({ plan: plan2, row: first }),
14487
- position: decodeKeysetToken({ plan: plan2, token: position })
14515
+ keys: plan.keys,
14516
+ row: keysetRowValues({ plan, row: first }),
14517
+ position: decodeKeysetToken({ plan, token: position })
14488
14518
  });
14489
14519
  if (advanced === false) {
14490
14520
  stop();
14491
14521
  throw new VibeError32({
14492
14522
  code: "VIBE_DATA_INVALID",
14493
14523
  message: `keyset traversal of "${options.model}" is not advancing: the engine returned a row that does not sort after the previous position. ` + "The ordering is not total, or a cursor value lost precision \u2014 a DateTime column finer than milliseconds asserted as millisecond-exact does this.",
14494
- meta: { model: options.model, order: plan2.signature, reason: "keyset-position-not-advancing" }
14524
+ meta: { model: options.model, order: plan.signature, reason: "keyset-position-not-advancing" }
14495
14525
  });
14496
14526
  }
14497
14527
  }
@@ -14523,7 +14553,7 @@ function iterateKeyset(options) {
14523
14553
  }
14524
14554
  }
14525
14555
  const raw = buffer.shift();
14526
- pending = encodeKeysetToken({ plan: plan2, row: raw });
14556
+ pending = encodeKeysetToken({ plan, row: raw });
14527
14557
  position = pending;
14528
14558
  if (projection.hidden.length === 0)
14529
14559
  return { done: false, value: raw };
@@ -14643,115 +14673,115 @@ function createTelemetryCollector(params) {
14643
14673
  };
14644
14674
  }
14645
14675
  export {
14646
- validateWriteData,
14647
- updateWithNested,
14648
- toSqlExecutor,
14649
- toClientName,
14650
- summarizePlan,
14651
- sqlProjection,
14652
- sql2 as sql,
14653
- rewriteScopedCall,
14654
- resolveTelemetryConfig,
14655
- resolveStatementDiagnostics,
14656
- resolveScopedModels,
14657
- resolveResultShape,
14658
- resolveRelationSelection,
14659
- resolveRelationLink,
14660
- recommendFromPlan,
14661
- readWorkloadStatistics,
14662
- readOnlyRefusal,
14663
- queryFingerprint,
14664
- previewOperation,
14665
- parsePostgresPlan,
14666
- parseDiagnosticsEnv,
14667
- parameterTypeTag,
14668
- normalizeSql,
14669
- lateralColumnAlias,
14670
- keysetRowValues,
14671
- keysetRowIsAfter,
14672
- iterateKeyset,
14673
- isExecutableRead,
14674
- isDbNow,
14675
- inspectNativeRlsTransaction,
14676
- inspectNativeRls,
14677
- inheritReadOnly,
14678
- hasNestedWrites,
14679
- getModelMeta,
14680
- getFieldMeta,
14681
- getCodec,
14682
- generateUuid,
14683
- generateUlid,
14684
- generateNanoid,
14685
- generateDefaultValue,
14686
- generateCuid,
14687
- formatStatementDiagnostic,
14688
- formatNativeRlsReport,
14689
- explainSql,
14690
- explainOperation,
14691
- explainOnSession,
14692
- encodeValue,
14693
- encodeKeysetToken,
14694
- delegateMethodAccess,
14695
- defineDatabaseModule,
14696
- decodeValue,
14697
- decodeRows,
14698
- decodeRow,
14699
- decodeKeysetToken,
14700
- decodeIsNoop2 as decodeIsNoop,
14701
- decodeAggregateValue,
14702
- decode2 as decode,
14703
- dbNow,
14704
- createWithNested,
14705
- createView,
14706
- createTelemetryRecorder,
14707
- createTelemetryCollector,
14708
- createStatementDiagnostics,
14709
- createSqlModel,
14710
- createScopeRewriter,
14711
- createClient,
14712
- compileWhere,
14713
- compileSelect,
14714
- compileOrderBy,
14715
- compileKeysetOrderPlan,
14716
- compileKeysetOrderInputs,
14717
- compileAdvisoryLock,
14718
- clientMemberAccess,
14719
- checkStrictArguments,
14720
- buildRuntimeMeta,
14721
- buildQuery,
14722
- buildExtensionOperatorMap,
14723
- buildConnectHooks,
14724
- attachScoped,
14725
- attachRelations,
14726
- attachReadOnly,
14727
- attachPolicy,
14728
- attachLateralRelations,
14729
- attachDefineView,
14730
- assertNativeRlsReady,
14731
- assertExtensionManifest,
14732
- assertComputedManifest,
14733
- applyWriteValidators,
14734
- applyComputedFields,
14735
- analyzeOperationTelemetry,
14736
- affectedRowsAreRowCounts,
14737
- WRITE_DELEGATE_METHODS,
14738
- ViewResult,
14739
- TELEMETRY_DEFAULTS,
14740
- STATEMENT_DIAGNOSTICS_DEFAULTS,
14741
- SQLITE_CODECS,
14742
- SKIP,
14743
- READ_DELEGATE_METHODS,
14744
- POSTGRES_CODECS,
14745
- PLAN_DEFAULTS,
14746
- MYSQL_CODECS,
14747
- KEYSET_TOKEN_VERSION,
14748
- KEYSET_TOKEN_PREFIX,
14749
- KEYSET_MAX_PAGE_SIZE,
14750
- DIALECT_CODECS2 as DIALECT_CODECS,
14751
- DIAGNOSTIC_THRESHOLDS,
14752
- DELEGATE_METHOD_ACCESS,
14676
+ CLIENT_MEMBER_ACCESS,
14753
14677
  COUNT_ALIAS,
14754
- CLIENT_MEMBER_ACCESS
14678
+ DELEGATE_METHOD_ACCESS,
14679
+ DIAGNOSTIC_THRESHOLDS,
14680
+ DIALECT_CODECS2 as DIALECT_CODECS,
14681
+ KEYSET_MAX_PAGE_SIZE,
14682
+ KEYSET_TOKEN_PREFIX,
14683
+ KEYSET_TOKEN_VERSION,
14684
+ MYSQL_CODECS,
14685
+ PLAN_DEFAULTS,
14686
+ POSTGRES_CODECS,
14687
+ READ_DELEGATE_METHODS,
14688
+ SKIP,
14689
+ SQLITE_CODECS,
14690
+ STATEMENT_DIAGNOSTICS_DEFAULTS,
14691
+ TELEMETRY_DEFAULTS,
14692
+ ViewResult,
14693
+ WRITE_DELEGATE_METHODS,
14694
+ affectedRowsAreRowCounts,
14695
+ analyzeOperationTelemetry,
14696
+ applyComputedFields,
14697
+ applyWriteValidators,
14698
+ assertComputedManifest,
14699
+ assertExtensionManifest,
14700
+ assertNativeRlsReady,
14701
+ attachDefineView,
14702
+ attachLateralRelations,
14703
+ attachPolicy,
14704
+ attachReadOnly,
14705
+ attachRelations,
14706
+ attachScoped,
14707
+ buildConnectHooks,
14708
+ buildExtensionOperatorMap,
14709
+ buildQuery,
14710
+ buildRuntimeMeta,
14711
+ checkStrictArguments,
14712
+ clientMemberAccess,
14713
+ compileAdvisoryLock,
14714
+ compileKeysetOrderInputs,
14715
+ compileKeysetOrderPlan,
14716
+ compileOrderBy,
14717
+ compileSelect,
14718
+ compileWhere,
14719
+ createClient,
14720
+ createScopeRewriter,
14721
+ createSqlModel,
14722
+ createStatementDiagnostics,
14723
+ createTelemetryCollector,
14724
+ createTelemetryRecorder,
14725
+ createView,
14726
+ createWithNested,
14727
+ dbNow,
14728
+ decode2 as decode,
14729
+ decodeAggregateValue,
14730
+ decodeIsNoop2 as decodeIsNoop,
14731
+ decodeKeysetToken,
14732
+ decodeRow,
14733
+ decodeRows,
14734
+ decodeValue,
14735
+ defineDatabaseModule,
14736
+ delegateMethodAccess,
14737
+ encodeKeysetToken,
14738
+ encodeValue,
14739
+ explainOnSession,
14740
+ explainOperation,
14741
+ explainSql,
14742
+ formatNativeRlsReport,
14743
+ formatStatementDiagnostic,
14744
+ generateCuid,
14745
+ generateDefaultValue,
14746
+ generateNanoid,
14747
+ generateUlid,
14748
+ generateUuid,
14749
+ getCodec,
14750
+ getFieldMeta,
14751
+ getModelMeta,
14752
+ hasNestedWrites,
14753
+ inheritReadOnly,
14754
+ inspectNativeRls,
14755
+ inspectNativeRlsTransaction,
14756
+ isDbNow,
14757
+ isExecutableRead,
14758
+ iterateKeyset,
14759
+ keysetRowIsAfter,
14760
+ keysetRowValues,
14761
+ lateralColumnAlias,
14762
+ normalizeSql,
14763
+ parameterTypeTag,
14764
+ parseDiagnosticsEnv,
14765
+ parsePostgresPlan,
14766
+ previewOperation,
14767
+ queryFingerprint,
14768
+ readOnlyRefusal,
14769
+ readWorkloadStatistics,
14770
+ recommendFromPlan,
14771
+ resolveRelationLink,
14772
+ resolveRelationSelection,
14773
+ resolveResultShape,
14774
+ resolveScopedModels,
14775
+ resolveStatementDiagnostics,
14776
+ resolveTelemetryConfig,
14777
+ rewriteScopedCall,
14778
+ sql2 as sql,
14779
+ sqlProjection,
14780
+ summarizePlan,
14781
+ toClientName,
14782
+ toSqlExecutor,
14783
+ updateWithNested,
14784
+ validateWriteData
14755
14785
  };
14756
14786
 
14757
- //# debugId=22841846B558EACA64756E2164756E21
14787
+ //# debugId=BC9380E497613E8D64756E2164756E21