metal-orm 1.1.19 → 1.1.21

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.cjs CHANGED
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __esm = (fn8, res) => function __init() {
6
- return fn8 && (res = (0, fn8[__getOwnPropNames(fn8)[0]])(fn8 = 0)), res;
5
+ var __esm = (fn9, res) => function __init() {
6
+ return fn9 && (res = (0, fn9[__getOwnPropNames(fn9)[0]])(fn9 = 0)), res;
7
7
  };
8
8
  var __export = (target, all) => {
9
9
  for (var name in all)
@@ -182,6 +182,7 @@ __export(index_exports, {
182
182
  concatWs: () => concatWs,
183
183
  correlateBy: () => correlateBy,
184
184
  cos: () => cos,
185
+ cosineDistance: () => cosineDistance,
185
186
  cot: () => cot,
186
187
  count: () => count,
187
188
  countAll: () => countAll,
@@ -218,12 +219,14 @@ __export(index_exports, {
218
219
  denseRank: () => denseRank,
219
220
  diffSchema: () => diffSchema,
220
221
  div: () => div,
222
+ dotProduct: () => dotProduct,
221
223
  dtoToOpenApiSchema: () => dtoToOpenApiSchema,
222
224
  endOfMonth: () => endOfMonth,
223
225
  entityRef: () => entityRef,
224
226
  entityRefs: () => entityRefs,
225
227
  eq: () => eq,
226
228
  esel: () => esel,
229
+ euclideanDistance: () => euclideanDistance,
227
230
  exclude: () => exclude,
228
231
  executeFilteredPaged: () => executeFilteredPaged,
229
232
  executeHydrated: () => executeHydrated,
@@ -281,6 +284,7 @@ __export(index_exports, {
281
284
  inList: () => inList,
282
285
  inSubquery: () => inSubquery,
283
286
  initcap: () => initcap,
287
+ innerProduct: () => innerProduct,
284
288
  insertInto: () => insertInto,
285
289
  instr: () => instr,
286
290
  introspectSchema: () => introspectSchema,
@@ -309,6 +313,8 @@ __export(index_exports, {
309
313
  jsonPath: () => jsonPath,
310
314
  jsonSet: () => jsonSet,
311
315
  jsonify: () => jsonify,
316
+ l1Distance: () => l1Distance,
317
+ l2Distance: () => l2Distance,
312
318
  lag: () => lag,
313
319
  lastValue: () => lastValue,
314
320
  lead: () => lead,
@@ -336,6 +342,7 @@ __export(index_exports, {
336
342
  lt: () => lt,
337
343
  lte: () => lte,
338
344
  ltrim: () => ltrim,
345
+ manhattanDistance: () => manhattanDistance,
339
346
  mapFields: () => mapFields,
340
347
  materializeAs: () => materializeAs,
341
348
  max: () => max,
@@ -455,6 +462,8 @@ __export(index_exports, {
455
462
  validateTreeTable: () => validateTreeTable,
456
463
  valueToOperand: () => valueToOperand,
457
464
  variance: () => variance,
465
+ vectorDistance: () => vectorDistance,
466
+ vectorMatch: () => vectorMatch,
458
467
  visitExpression: () => visitExpression,
459
468
  visitOperand: () => visitOperand,
460
469
  weekOfYear: () => weekOfYear,
@@ -575,7 +584,9 @@ var STANDARD_COLUMN_TYPES = [
575
584
  "DATETIME",
576
585
  "TIMESTAMP",
577
586
  "TIMESTAMPTZ",
578
- "BOOLEAN"
587
+ "BOOLEAN",
588
+ "VECTOR",
589
+ "HALFVEC"
579
590
  ];
580
591
  var STANDARD_TYPE_SET = new Set(STANDARD_COLUMN_TYPES.map((t) => t.toLowerCase()));
581
592
  var normalizeColumnType = (type) => {
@@ -685,6 +696,27 @@ var col = {
685
696
  * @param values - Enum values
686
697
  */
687
698
  enum: (values) => ({ name: "", type: "ENUM", args: values }),
699
+ /**
700
+ * Creates a vector column definition
701
+ * @param dimensions - Vector dimensions
702
+ * @param options - Vector options (e.g. elementType: 'float16' | 'float32')
703
+ */
704
+ vector: (dimensions, options) => ({
705
+ name: "",
706
+ type: "VECTOR",
707
+ args: [dimensions],
708
+ vectorOptions: { dimensions, ...options }
709
+ }),
710
+ /**
711
+ * Creates a half-precision (float16) vector column definition (pgvector halfvec / SQL Server float16 vector / sqlite-vec float16)
712
+ * @param dimensions - Vector dimensions
713
+ */
714
+ halfvec: (dimensions) => ({
715
+ name: "",
716
+ type: "HALFVEC",
717
+ args: [dimensions],
718
+ vectorOptions: { dimensions, elementType: "float16" }
719
+ }),
688
720
  /**
689
721
  * Creates a column definition with a custom SQL type.
690
722
  * Useful for dialect-specific types without polluting the standard set.
@@ -2158,13 +2190,13 @@ var FunctionTableFormatter = class {
2158
2190
  * @param dialect - The dialect instance for compiling operands.
2159
2191
  * @returns SQL function table expression (e.g., "LATERAL schema.func(args) WITH ORDINALITY AS alias(col1, col2)").
2160
2192
  */
2161
- static format(fn8, ctx, dialect) {
2162
- const schemaPart = this.formatSchema(fn8, dialect);
2163
- const args = this.formatArgs(fn8, ctx, dialect);
2164
- const base = this.formatBase(fn8, schemaPart, args);
2165
- const lateral = this.formatLateral(fn8);
2166
- const alias = this.formatAlias(fn8, dialect);
2167
- const colAliases = this.formatColumnAliases(fn8, dialect);
2193
+ static format(fn9, ctx, dialect) {
2194
+ const schemaPart = this.formatSchema(fn9, dialect);
2195
+ const args = this.formatArgs(fn9, ctx, dialect);
2196
+ const base = this.formatBase(fn9, schemaPart, args);
2197
+ const lateral = this.formatLateral(fn9);
2198
+ const alias = this.formatAlias(fn9, dialect);
2199
+ const colAliases = this.formatColumnAliases(fn9, dialect);
2168
2200
  return `${lateral}${base}${alias}${colAliases}`;
2169
2201
  }
2170
2202
  /**
@@ -2174,9 +2206,9 @@ var FunctionTableFormatter = class {
2174
2206
  * @returns Schema prefix (e.g., "schema.") or empty string.
2175
2207
  * @internal
2176
2208
  */
2177
- static formatSchema(fn8, dialect) {
2178
- if (!fn8.schema) return "";
2179
- const quoted = dialect ? dialect.quoteIdentifier(fn8.schema) : fn8.schema;
2209
+ static formatSchema(fn9, dialect) {
2210
+ if (!fn9.schema) return "";
2211
+ const quoted = dialect ? dialect.quoteIdentifier(fn9.schema) : fn9.schema;
2180
2212
  return `${quoted}.`;
2181
2213
  }
2182
2214
  /**
@@ -2187,8 +2219,8 @@ var FunctionTableFormatter = class {
2187
2219
  * @returns Comma-separated function arguments.
2188
2220
  * @internal
2189
2221
  */
2190
- static formatArgs(fn8, ctx, dialect) {
2191
- return (fn8.args || []).map((a) => {
2222
+ static formatArgs(fn9, ctx, dialect) {
2223
+ return (fn9.args || []).map((a) => {
2192
2224
  if (ctx && dialect) {
2193
2225
  return dialect.compileOperand(a, ctx);
2194
2226
  }
@@ -2204,9 +2236,9 @@ var FunctionTableFormatter = class {
2204
2236
  * @returns Base function call expression (e.g., "schema.func(args) WITH ORDINALITY").
2205
2237
  * @internal
2206
2238
  */
2207
- static formatBase(fn8, schemaPart, args) {
2208
- const ordinality = fn8.withOrdinality ? " WITH ORDINALITY" : "";
2209
- return `${schemaPart}${fn8.name}(${args})${ordinality}`;
2239
+ static formatBase(fn9, schemaPart, args) {
2240
+ const ordinality = fn9.withOrdinality ? " WITH ORDINALITY" : "";
2241
+ return `${schemaPart}${fn9.name}(${args})${ordinality}`;
2210
2242
  }
2211
2243
  /**
2212
2244
  * Formats the LATERAL keyword if present.
@@ -2214,8 +2246,8 @@ var FunctionTableFormatter = class {
2214
2246
  * @returns "LATERAL " or empty string.
2215
2247
  * @internal
2216
2248
  */
2217
- static formatLateral(fn8) {
2218
- return fn8.lateral ? "LATERAL " : "";
2249
+ static formatLateral(fn9) {
2250
+ return fn9.lateral ? "LATERAL " : "";
2219
2251
  }
2220
2252
  /**
2221
2253
  * Formats the table alias for the function table.
@@ -2224,9 +2256,9 @@ var FunctionTableFormatter = class {
2224
2256
  * @returns " AS alias" or empty string.
2225
2257
  * @internal
2226
2258
  */
2227
- static formatAlias(fn8, dialect) {
2228
- if (!fn8.alias) return "";
2229
- const quoted = dialect ? dialect.quoteIdentifier(fn8.alias) : fn8.alias;
2259
+ static formatAlias(fn9, dialect) {
2260
+ if (!fn9.alias) return "";
2261
+ const quoted = dialect ? dialect.quoteIdentifier(fn9.alias) : fn9.alias;
2230
2262
  return ` AS ${quoted}`;
2231
2263
  }
2232
2264
  /**
@@ -2236,9 +2268,9 @@ var FunctionTableFormatter = class {
2236
2268
  * @returns "(col1, col2, ...)" or empty string.
2237
2269
  * @internal
2238
2270
  */
2239
- static formatColumnAliases(fn8, dialect) {
2240
- if (!fn8.columnAliases || !fn8.columnAliases.length) return "";
2241
- const aliases = fn8.columnAliases.map((col2) => dialect ? dialect.quoteIdentifier(col2) : col2).join(", ");
2271
+ static formatColumnAliases(fn9, dialect) {
2272
+ if (!fn9.columnAliases || !fn9.columnAliases.length) return "";
2273
+ const aliases = fn9.columnAliases.map((col2) => dialect ? dialect.quoteIdentifier(col2) : col2).join(", ");
2242
2274
  return `(${aliases})`;
2243
2275
  }
2244
2276
  };
@@ -2520,24 +2552,24 @@ var SqlDialectBase = class extends Dialect {
2520
2552
  }
2521
2553
  return this.compileTableSource(tableSource);
2522
2554
  }
2523
- compileFunctionTable(fn8, ctx) {
2524
- const key = fn8.key ?? fn8.name;
2555
+ compileFunctionTable(fn9, ctx) {
2556
+ const key = fn9.key ?? fn9.name;
2525
2557
  if (ctx) {
2526
2558
  const renderer = this.tableFunctionStrategy.getRenderer(key);
2527
2559
  if (renderer) {
2528
- const compiledArgs = (fn8.args ?? []).map((arg) => this.compileOperand(arg, ctx));
2560
+ const compiledArgs = (fn9.args ?? []).map((arg) => this.compileOperand(arg, ctx));
2529
2561
  return renderer({
2530
- node: fn8,
2562
+ node: fn9,
2531
2563
  compiledArgs,
2532
2564
  compileOperand: (operand) => this.compileOperand(operand, ctx),
2533
2565
  quoteIdentifier: this.quoteIdentifier.bind(this)
2534
2566
  });
2535
2567
  }
2536
- if (fn8.key) {
2568
+ if (fn9.key) {
2537
2569
  throw new Error(`Table function "${key}" is not supported by dialect "${this.dialect}".`);
2538
2570
  }
2539
2571
  }
2540
- return FunctionTableFormatter.format(fn8, ctx, this);
2572
+ return FunctionTableFormatter.format(fn9, ctx, this);
2541
2573
  }
2542
2574
  compileDerivedTable(table, ctx) {
2543
2575
  if (!table.alias) {
@@ -2726,6 +2758,26 @@ var PostgresFunctionStrategy = class extends StandardFunctionStrategy {
2726
2758
  const pathArray = this.formatJsonbPathArray(pathNode);
2727
2759
  return `jsonb_set(${compiledArgs[0]}, ${pathArray}, ${compiledArgs[2]}::jsonb, true)`;
2728
2760
  });
2761
+ this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
2762
+ if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
2763
+ const metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
2764
+ const [, v1, v2] = compiledArgs;
2765
+ switch (metric) {
2766
+ case "cosine":
2767
+ return `(${v1} <=> ${v2})`;
2768
+ case "euclidean":
2769
+ case "l2":
2770
+ return `(${v1} <-> ${v2})`;
2771
+ case "dot":
2772
+ case "inner_product":
2773
+ return `(${v1} <#> ${v2})`;
2774
+ case "manhattan":
2775
+ case "l1":
2776
+ return `(${v1} <~> ${v2})`;
2777
+ default:
2778
+ return `(${v1} <=> ${v2})`;
2779
+ }
2780
+ });
2729
2781
  }
2730
2782
  formatJsonbPathArray(pathNode) {
2731
2783
  const rawPath = String(pathNode.value ?? "");
@@ -2957,6 +3009,14 @@ var MysqlFunctionStrategy = class extends StandardFunctionStrategy {
2957
3009
  if (compiledArgs.length !== 2) throw new Error("ARRAY_APPEND expects 2 arguments (array, value)");
2958
3010
  return `JSON_ARRAY_APPEND(${compiledArgs[0]}, '$', ${compiledArgs[1]})`;
2959
3011
  });
3012
+ this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
3013
+ if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
3014
+ let metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toUpperCase() : compiledArgs[0].replace(/['"]/g, "").toUpperCase();
3015
+ if (metric === "L2") metric = "EUCLIDEAN";
3016
+ if (metric === "INNER_PRODUCT") metric = "DOT";
3017
+ const [, v1, v2] = compiledArgs;
3018
+ return `DISTANCE(${v1}, ${v2}, '${metric}')`;
3019
+ });
2960
3020
  }
2961
3021
  };
2962
3022
 
@@ -3193,6 +3253,15 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
3193
3253
  return `json_array_append(${compiledArgs[0]}, '$', ${compiledArgs[1]})`;
3194
3254
  });
3195
3255
  this.add("CHR", ({ compiledArgs }) => `CHAR(${compiledArgs[0]})`);
3256
+ this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
3257
+ if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
3258
+ const metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
3259
+ const [, v1, v2] = compiledArgs;
3260
+ if (metric === "euclidean" || metric === "l2") {
3261
+ return `vec_distance_L2(${v1}, ${v2})`;
3262
+ }
3263
+ return `vec_distance_cosine(${v1}, ${v2})`;
3264
+ });
3196
3265
  }
3197
3266
  };
3198
3267
 
@@ -3394,6 +3463,15 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
3394
3463
  this.add("ARRAY_APPEND", () => {
3395
3464
  throw new Error("ARRAY_APPEND is not supported on SQL Server");
3396
3465
  });
3466
+ this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
3467
+ if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
3468
+ let metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
3469
+ if (metric === "l2") metric = "euclidean";
3470
+ if (metric === "l1") metric = "manhattan";
3471
+ if (metric === "inner_product") metric = "dot";
3472
+ const [, v1, v2] = compiledArgs;
3473
+ return `VECTOR_DISTANCE('${metric}', ${v1}, ${v2})`;
3474
+ });
3397
3475
  }
3398
3476
  };
3399
3477
 
@@ -13843,6 +13921,50 @@ var fn7 = (key, args) => ({
13843
13921
  var afn3 = (key, args) => asType(fn7(key, args));
13844
13922
  var arrayAppend = (array, value) => afn3("ARRAY_APPEND", [array, value]);
13845
13923
 
13924
+ // src/core/functions/vector.ts
13925
+ var isColumnDef7 = (val) => !!val && typeof val === "object" && "type" in val && "name" in val;
13926
+ var toOperand8 = (input) => {
13927
+ if (isOperandNode(input)) return input;
13928
+ if (isColumnDef7(input)) return columnOperand(input);
13929
+ if (Array.isArray(input) || input instanceof Float32Array) {
13930
+ const formatted = `[${Array.from(input).join(", ")}]`;
13931
+ return valueToOperand(formatted);
13932
+ }
13933
+ return valueToOperand(input);
13934
+ };
13935
+ var fn8 = (key, args) => ({
13936
+ type: "Function",
13937
+ name: key,
13938
+ fn: key,
13939
+ args
13940
+ });
13941
+ var vectorDistance = (metric, v1, v2) => {
13942
+ const metricOp = valueToOperand(metric.toLowerCase());
13943
+ return asType(fn8("VECTOR_DISTANCE", [metricOp, toOperand8(v1), toOperand8(v2)]));
13944
+ };
13945
+ var cosineDistance = (v1, v2) => vectorDistance("cosine", v1, v2);
13946
+ var l2Distance = (v1, v2) => vectorDistance("euclidean", v1, v2);
13947
+ var euclideanDistance = (v1, v2) => vectorDistance("euclidean", v1, v2);
13948
+ var innerProduct = (v1, v2) => vectorDistance("dot", v1, v2);
13949
+ var dotProduct = (v1, v2) => vectorDistance("dot", v1, v2);
13950
+ var l1Distance = (v1, v2) => vectorDistance("manhattan", v1, v2);
13951
+ var manhattanDistance = (v1, v2) => vectorDistance("manhattan", v1, v2);
13952
+ var vectorMatch = (column, vector, k) => {
13953
+ const match = {
13954
+ type: "BinaryExpression",
13955
+ left: toOperand8(column),
13956
+ operator: "MATCH",
13957
+ right: toOperand8(vector)
13958
+ };
13959
+ const kNode = {
13960
+ type: "BinaryExpression",
13961
+ left: valueToOperand("k"),
13962
+ operator: "=",
13963
+ right: valueToOperand(k)
13964
+ };
13965
+ return { type: "LogicalExpression", operator: "AND", operands: [match, kNode] };
13966
+ };
13967
+
13846
13968
  // src/orm/als.ts
13847
13969
  var AsyncLocalStorage = class {
13848
13970
  store;
@@ -14158,12 +14280,12 @@ var TypeScriptGenerator = class {
14158
14280
  printBinaryExpression(binary) {
14159
14281
  const left2 = this.printOperand(binary.left);
14160
14282
  const right2 = this.printOperand(binary.right);
14161
- const fn8 = this.mapOp(binary.operator);
14283
+ const fn9 = this.mapOp(binary.operator);
14162
14284
  const args = [left2, right2];
14163
14285
  if (binary.escape) {
14164
14286
  args.push(this.printOperand(binary.escape));
14165
14287
  }
14166
- return `${fn8}(${args.join(", ")})`;
14288
+ return `${fn9}(${args.join(", ")})`;
14167
14289
  }
14168
14290
  /**
14169
14291
  * Prints a logical expression to TypeScript code
@@ -14195,13 +14317,13 @@ var TypeScriptGenerator = class {
14195
14317
  */
14196
14318
  printInExpression(inExpr) {
14197
14319
  const left2 = this.printOperand(inExpr.left);
14198
- const fn8 = this.mapOp(inExpr.operator);
14320
+ const fn9 = this.mapOp(inExpr.operator);
14199
14321
  if (Array.isArray(inExpr.right)) {
14200
14322
  const values = inExpr.right.map((v) => this.printOperand(v)).join(", ");
14201
- return `${fn8}(${left2}, [${values}])`;
14323
+ return `${fn9}(${left2}, [${values}])`;
14202
14324
  }
14203
14325
  const subquery = this.inlineChain(this.buildSelectLines(inExpr.right.query));
14204
- return `${fn8}(${left2}, (${subquery}))`;
14326
+ return `${fn9}(${left2}, (${subquery}))`;
14205
14327
  }
14206
14328
  /**
14207
14329
  * Prints a null expression to TypeScript code
@@ -14210,8 +14332,8 @@ var TypeScriptGenerator = class {
14210
14332
  */
14211
14333
  printNullExpression(nullExpr) {
14212
14334
  const left2 = this.printOperand(nullExpr.left);
14213
- const fn8 = this.mapOp(nullExpr.operator);
14214
- return `${fn8}(${left2})`;
14335
+ const fn9 = this.mapOp(nullExpr.operator);
14336
+ return `${fn9}(${left2})`;
14215
14337
  }
14216
14338
  /**
14217
14339
  * Prints a BETWEEN expression to TypeScript code
@@ -14255,9 +14377,9 @@ var TypeScriptGenerator = class {
14255
14377
  * @param fn - Function node
14256
14378
  * @returns TypeScript code representation
14257
14379
  */
14258
- printFunctionOperand(fn8) {
14259
- const args = fn8.args.map((a) => this.printOperand(a)).join(", ");
14260
- return `${fn8.name.toLowerCase()}(${args})`;
14380
+ printFunctionOperand(fn9) {
14381
+ const args = fn9.args.map((a) => this.printOperand(a)).join(", ");
14382
+ return `${fn9.name.toLowerCase()}(${args})`;
14261
14383
  }
14262
14384
  /**
14263
14385
  * Prints a JSON path operand to TypeScript code
@@ -14948,7 +15070,10 @@ var RelationChangeProcessor = class {
14948
15070
  const rootKey = relation.localKey || findPrimaryKey(entry.rootTable);
14949
15071
  const rootId = entry.root[rootKey];
14950
15072
  if (rootId === void 0 || rootId === null) return;
14951
- const targetId = this.resolvePrimaryKeyValue(entry.change.entity, relation.target);
15073
+ const targetId = this.resolveBelongsToManyTargetValue(
15074
+ entry.change.entity,
15075
+ relation
15076
+ );
14952
15077
  if (targetId === null) return;
14953
15078
  const pivotPayload = this.buildPivotPayload(relation, entry.change.pivot);
14954
15079
  if (entry.change.kind === "update") {
@@ -15020,7 +15145,7 @@ var RelationChangeProcessor = class {
15020
15145
  * Inserts a pivot row for belongs-to-many relations.
15021
15146
  * @param relation - The belongs-to-many relation
15022
15147
  * @param rootId - The root entity's primary key value
15023
- * @param targetId - The target entity's primary key value
15148
+ * @param targetId - The target entity's relation key value
15024
15149
  */
15025
15150
  async insertPivotRow(relation, rootId, targetId, pivotPayload) {
15026
15151
  const payload = {
@@ -15036,7 +15161,7 @@ var RelationChangeProcessor = class {
15036
15161
  * Updates a pivot row for belongs-to-many relations.
15037
15162
  * @param relation - The belongs-to-many relation
15038
15163
  * @param rootId - The root entity's primary key value
15039
- * @param targetId - The target entity's primary key value
15164
+ * @param targetId - The target entity's relation key value
15040
15165
  * @param pivotPayload - The pivot columns to update
15041
15166
  */
15042
15167
  async updatePivotRow(relation, rootId, targetId, pivotPayload) {
@@ -15051,7 +15176,7 @@ var RelationChangeProcessor = class {
15051
15176
  * Deletes a pivot row for belongs-to-many relations.
15052
15177
  * @param relation - The belongs-to-many relation
15053
15178
  * @param rootId - The root entity's primary key value
15054
- * @param targetId - The target entity's primary key value
15179
+ * @param targetId - The target entity's relation key value
15055
15180
  */
15056
15181
  async deletePivotRow(relation, rootId, targetId) {
15057
15182
  const rootCol = relation.pivotTable.columns[relation.pivotForeignKeyToRoot];
@@ -15064,14 +15189,13 @@ var RelationChangeProcessor = class {
15064
15189
  await this.executor.executeSql(compiled.sql, compiled.params);
15065
15190
  }
15066
15191
  /**
15067
- * Resolves the primary key value from an entity.
15068
- * @param entity - The entity
15069
- * @param table - The table definition
15070
- * @returns The primary key value or null
15192
+ * Resolves the target-side key value used by a belongs-to-many relation.
15193
+ * The declared targetKey is part of the relation contract and takes
15194
+ * precedence over the target table primary key.
15071
15195
  */
15072
- resolvePrimaryKeyValue(entity, table) {
15196
+ resolveBelongsToManyTargetValue(entity, relation) {
15073
15197
  if (!entity) return null;
15074
- const key = findPrimaryKey(table);
15198
+ const key = relation.targetKey || findPrimaryKey(relation.target);
15075
15199
  const value = entity[key];
15076
15200
  if (value === void 0 || value === null) return null;
15077
15201
  return value ?? null;
@@ -15872,9 +15996,9 @@ var OrmSession = class {
15872
15996
  * @returns The result of the function
15873
15997
  * @throws If the transaction fails
15874
15998
  */
15875
- async transaction(fn8) {
15999
+ async transaction(fn9) {
15876
16000
  if (!this.executor.capabilities.transactions) {
15877
- const result = await fn8(this);
16001
+ const result = await fn9(this);
15878
16002
  await this.commit();
15879
16003
  return result;
15880
16004
  }
@@ -15890,7 +16014,7 @@ var OrmSession = class {
15890
16014
  }
15891
16015
  this.transactionDepth += 1;
15892
16016
  try {
15893
- const result = await fn8(this);
16017
+ const result = await fn9(this);
15894
16018
  this.throwIfRollbackOnly();
15895
16019
  await this.flushWithHooks();
15896
16020
  this.throwIfRollbackOnly();
@@ -16404,7 +16528,7 @@ var Orm = class {
16404
16528
  * @returns The result of the function
16405
16529
  * @throws If the transaction fails
16406
16530
  */
16407
- async transaction(fn8) {
16531
+ async transaction(fn9) {
16408
16532
  const executor = this.executorFactory.createTransactionalExecutor();
16409
16533
  const session = new OrmSession({
16410
16534
  orm: this,
@@ -16412,7 +16536,7 @@ var Orm = class {
16412
16536
  cacheManager: this.cacheManager
16413
16537
  });
16414
16538
  try {
16415
- return await session.transaction(() => fn8(session));
16539
+ return await session.transaction(() => fn9(session));
16416
16540
  } finally {
16417
16541
  await session.dispose();
16418
16542
  }
@@ -21701,10 +21825,10 @@ async function runChunk(task, chunkIndex, totalChunks, rowsInChunk, timing, onCh
21701
21825
  }
21702
21826
  return result;
21703
21827
  }
21704
- async function maybeTransaction(session, transactional, fn8) {
21705
- if (!transactional) return fn8();
21828
+ async function maybeTransaction(session, transactional, fn9) {
21829
+ if (!transactional) return fn9();
21706
21830
  const ormSession = session;
21707
- return ormSession.transaction(fn8);
21831
+ return ormSession.transaction(fn9);
21708
21832
  }
21709
21833
  function aggregateOutcomes(outcomes) {
21710
21834
  const result = {
@@ -22171,6 +22295,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
22171
22295
  concatWs,
22172
22296
  correlateBy,
22173
22297
  cos,
22298
+ cosineDistance,
22174
22299
  cot,
22175
22300
  count,
22176
22301
  countAll,
@@ -22207,12 +22332,14 @@ async function bulkUpsert(session, table, rows, options = {}) {
22207
22332
  denseRank,
22208
22333
  diffSchema,
22209
22334
  div,
22335
+ dotProduct,
22210
22336
  dtoToOpenApiSchema,
22211
22337
  endOfMonth,
22212
22338
  entityRef,
22213
22339
  entityRefs,
22214
22340
  eq,
22215
22341
  esel,
22342
+ euclideanDistance,
22216
22343
  exclude,
22217
22344
  executeFilteredPaged,
22218
22345
  executeHydrated,
@@ -22270,6 +22397,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
22270
22397
  inList,
22271
22398
  inSubquery,
22272
22399
  initcap,
22400
+ innerProduct,
22273
22401
  insertInto,
22274
22402
  instr,
22275
22403
  introspectSchema,
@@ -22298,6 +22426,8 @@ async function bulkUpsert(session, table, rows, options = {}) {
22298
22426
  jsonPath,
22299
22427
  jsonSet,
22300
22428
  jsonify,
22429
+ l1Distance,
22430
+ l2Distance,
22301
22431
  lag,
22302
22432
  lastValue,
22303
22433
  lead,
@@ -22325,6 +22455,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
22325
22455
  lt,
22326
22456
  lte,
22327
22457
  ltrim,
22458
+ manhattanDistance,
22328
22459
  mapFields,
22329
22460
  materializeAs,
22330
22461
  max,
@@ -22444,6 +22575,8 @@ async function bulkUpsert(session, table, rows, options = {}) {
22444
22575
  validateTreeTable,
22445
22576
  valueToOperand,
22446
22577
  variance,
22578
+ vectorDistance,
22579
+ vectorMatch,
22447
22580
  visitExpression,
22448
22581
  visitOperand,
22449
22582
  weekOfYear,