@nicia-ai/typegraph 0.13.0 → 0.14.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.
Files changed (67) hide show
  1. package/dist/backend/postgres/index.cjs +28 -28
  2. package/dist/backend/postgres/index.d.cts +1 -1
  3. package/dist/backend/postgres/index.d.ts +1 -1
  4. package/dist/backend/postgres/index.js +4 -4
  5. package/dist/backend/sqlite/index.cjs +14 -14
  6. package/dist/backend/sqlite/index.d.cts +1 -1
  7. package/dist/backend/sqlite/index.d.ts +1 -1
  8. package/dist/backend/sqlite/index.js +4 -4
  9. package/dist/backend/sqlite/local.cjs +7 -7
  10. package/dist/backend/sqlite/local.d.cts +1 -1
  11. package/dist/backend/sqlite/local.d.ts +1 -1
  12. package/dist/backend/sqlite/local.js +4 -4
  13. package/dist/{chunk-U3452TEU.js → chunk-6GWJH6AR.js} +15 -27
  14. package/dist/chunk-6GWJH6AR.js.map +1 -0
  15. package/dist/{chunk-52WSY6G5.js → chunk-BNIBR5U2.js} +70 -31
  16. package/dist/chunk-BNIBR5U2.js.map +1 -0
  17. package/dist/{chunk-54WJF3DW.js → chunk-GNIYZKBI.js} +29 -3
  18. package/dist/chunk-GNIYZKBI.js.map +1 -0
  19. package/dist/{chunk-2XPKLHHH.cjs → chunk-KE2BL3JZ.cjs} +74 -35
  20. package/dist/chunk-KE2BL3JZ.cjs.map +1 -0
  21. package/dist/{chunk-PYV4ADC6.js → chunk-KLOSTZDQ.js} +141 -13
  22. package/dist/chunk-KLOSTZDQ.js.map +1 -0
  23. package/dist/{chunk-JQDWEX6V.cjs → chunk-LELLOHJK.cjs} +22 -34
  24. package/dist/chunk-LELLOHJK.cjs.map +1 -0
  25. package/dist/{chunk-2WVFEIHR.cjs → chunk-MME3H4ZF.cjs} +40 -2
  26. package/dist/chunk-MME3H4ZF.cjs.map +1 -0
  27. package/dist/{chunk-NZMKJHE2.cjs → chunk-OEKH5PWL.cjs} +15 -15
  28. package/dist/{chunk-NZMKJHE2.cjs.map → chunk-OEKH5PWL.cjs.map} +1 -1
  29. package/dist/{chunk-7VITUTRA.cjs → chunk-QFZ5QB2J.cjs} +140 -12
  30. package/dist/chunk-QFZ5QB2J.cjs.map +1 -0
  31. package/dist/{chunk-J4SICP3X.js → chunk-RVUEBUBH.js} +3 -3
  32. package/dist/{chunk-J4SICP3X.js.map → chunk-RVUEBUBH.js.map} +1 -1
  33. package/dist/index.cjs +432 -578
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +12 -9
  36. package/dist/index.d.ts +12 -9
  37. package/dist/index.js +393 -539
  38. package/dist/index.js.map +1 -1
  39. package/dist/indexes/index.cjs +16 -16
  40. package/dist/indexes/index.js +2 -2
  41. package/dist/interchange/index.d.cts +3 -3
  42. package/dist/interchange/index.d.ts +3 -3
  43. package/dist/{manager-DGSnJa1v.d.cts → manager-oh2mTMvy.d.cts} +1 -1
  44. package/dist/{manager-BCLhWysp.d.ts → manager-qRSdnKEO.d.ts} +1 -1
  45. package/dist/profiler/index.cjs +6 -6
  46. package/dist/profiler/index.cjs.map +1 -1
  47. package/dist/profiler/index.d.cts +3 -3
  48. package/dist/profiler/index.d.ts +3 -3
  49. package/dist/profiler/index.js +6 -6
  50. package/dist/profiler/index.js.map +1 -1
  51. package/dist/schema/index.cjs +20 -20
  52. package/dist/schema/index.d.cts +4 -4
  53. package/dist/schema/index.d.ts +4 -4
  54. package/dist/schema/index.js +2 -2
  55. package/dist/{store-6-vH0ZIj.d.ts → store-B9ItxA-Q.d.ts} +37 -17
  56. package/dist/{store-Bmdt_dS6.d.cts → store-BJPIoe8u.d.cts} +37 -17
  57. package/dist/{types-1YJKodRv.d.ts → types-5t_MIcvv.d.ts} +12 -6
  58. package/dist/{types-GLkwvQvS.d.cts → types-Ckfwgv9l.d.cts} +12 -6
  59. package/package.json +1 -1
  60. package/dist/chunk-2WVFEIHR.cjs.map +0 -1
  61. package/dist/chunk-2XPKLHHH.cjs.map +0 -1
  62. package/dist/chunk-52WSY6G5.js.map +0 -1
  63. package/dist/chunk-54WJF3DW.js.map +0 -1
  64. package/dist/chunk-7VITUTRA.cjs.map +0 -1
  65. package/dist/chunk-JQDWEX6V.cjs.map +0 -1
  66. package/dist/chunk-PYV4ADC6.js.map +0 -1
  67. package/dist/chunk-U3452TEU.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,16 +1,66 @@
1
1
  'use strict';
2
2
 
3
- var chunk7VITUTRA_cjs = require('./chunk-7VITUTRA.cjs');
3
+ var chunkQFZ5QB2J_cjs = require('./chunk-QFZ5QB2J.cjs');
4
4
  var chunkNI2GV74U_cjs = require('./chunk-NI2GV74U.cjs');
5
5
  var chunk44SXEVF4_cjs = require('./chunk-44SXEVF4.cjs');
6
- var chunk2WVFEIHR_cjs = require('./chunk-2WVFEIHR.cjs');
6
+ var chunkMME3H4ZF_cjs = require('./chunk-MME3H4ZF.cjs');
7
7
  var chunkP5CNM325_cjs = require('./chunk-P5CNM325.cjs');
8
8
  var zod = require('zod');
9
9
  var drizzleOrm = require('drizzle-orm');
10
10
  var nanoid = require('nanoid');
11
11
 
12
+ // src/store/reserved-keys.ts
13
+ var RESERVED_NODE_KEYS = /* @__PURE__ */ new Set([
14
+ "id",
15
+ "kind",
16
+ "meta"
17
+ ]);
18
+ var RESERVED_EDGE_KEYS = /* @__PURE__ */ new Set([
19
+ "id",
20
+ "kind",
21
+ "meta",
22
+ "fromKind",
23
+ "fromId",
24
+ "toKind",
25
+ "toId"
26
+ ]);
27
+ var PROTOTYPE_POLLUTION_KEYS = /* @__PURE__ */ new Set([
28
+ "__proto__",
29
+ "constructor",
30
+ "prototype"
31
+ ]);
32
+ function validateProjectionField(field2, entityType, kind) {
33
+ const reserved = entityType === "node" ? RESERVED_NODE_KEYS : RESERVED_EDGE_KEYS;
34
+ if (reserved.has(field2)) {
35
+ throw new chunk44SXEVF4_cjs.ConfigurationError(
36
+ `Projection field "${field2}" on ${entityType} kind "${kind}" conflicts with a reserved structural key`,
37
+ { field: field2, kind, entityType, reservedKeys: [...reserved] },
38
+ {
39
+ suggestion: `Remove "${field2}" from the projection. Structural fields (${[...reserved].join(", ")}) are included automatically when relevant.`
40
+ }
41
+ );
42
+ }
43
+ if (PROTOTYPE_POLLUTION_KEYS.has(field2)) {
44
+ throw new chunk44SXEVF4_cjs.ConfigurationError(
45
+ `Projection field "${field2}" on ${entityType} kind "${kind}" is not allowed`,
46
+ { field: field2, kind, entityType },
47
+ {
48
+ suggestion: `"${field2}" cannot be used as a projection field name.`
49
+ }
50
+ );
51
+ }
52
+ }
53
+ function filterReservedKeys(props, reservedKeys) {
54
+ const filtered = {};
55
+ for (const [key, value] of Object.entries(props)) {
56
+ if (!reservedKeys.has(key)) {
57
+ filtered[key] = value;
58
+ }
59
+ }
60
+ return filtered;
61
+ }
62
+
12
63
  // src/core/node.ts
13
- var RESERVED_NODE_KEYS = /* @__PURE__ */ new Set(["id", "kind", "meta"]);
14
64
  function validateSchemaKeys(schema, name) {
15
65
  const shape = schema.shape;
16
66
  const conflicts = Object.keys(shape).filter(
@@ -35,15 +85,6 @@ function defineNode(name, options) {
35
85
  description: options.description
36
86
  });
37
87
  }
38
- var RESERVED_EDGE_KEYS = /* @__PURE__ */ new Set([
39
- "id",
40
- "kind",
41
- "meta",
42
- "fromKind",
43
- "fromId",
44
- "toKind",
45
- "toId"
46
- ]);
47
88
  var EMPTY_SCHEMA = zod.z.object({});
48
89
  function validateSchemaKeys2(schema, name) {
49
90
  const shape = schema.shape;
@@ -84,7 +125,7 @@ function metaEdge(name, options = {}) {
84
125
  description: options.description
85
126
  };
86
127
  return Object.freeze({
87
- [chunk7VITUTRA_cjs.META_EDGE_BRAND]: true,
128
+ [chunkQFZ5QB2J_cjs.META_EDGE_BRAND]: true,
88
129
  name,
89
130
  properties
90
131
  });
@@ -120,7 +161,7 @@ function createExternalRef(table) {
120
161
  // src/ontology/core-meta-edges.ts
121
162
  function createMetaEdge(name, properties) {
122
163
  return Object.freeze({
123
- [chunk7VITUTRA_cjs.META_EDGE_BRAND]: true,
164
+ [chunkQFZ5QB2J_cjs.META_EDGE_BRAND]: true,
124
165
  name,
125
166
  properties: {
126
167
  transitive: properties.transitive ?? false,
@@ -132,7 +173,7 @@ function createMetaEdge(name, properties) {
132
173
  }
133
174
  });
134
175
  }
135
- var subClassOfMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_SUB_CLASS_OF, {
176
+ var subClassOfMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_SUB_CLASS_OF, {
136
177
  transitive: true,
137
178
  inference: "subsumption",
138
179
  description: "Type inheritance (Podcast subClassOf Media)"
@@ -144,9 +185,9 @@ function subClassOf(child, parent) {
144
185
  to: parent
145
186
  };
146
187
  }
147
- var broaderMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_BROADER, {
188
+ var broaderMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_BROADER, {
148
189
  transitive: true,
149
- inverse: chunk7VITUTRA_cjs.META_EDGE_NARROWER,
190
+ inverse: chunkQFZ5QB2J_cjs.META_EDGE_NARROWER,
150
191
  inference: "hierarchy",
151
192
  description: "Broader concept (ML broader AI)"
152
193
  });
@@ -157,9 +198,9 @@ function broader(narrowerConcept, broaderConcept) {
157
198
  to: broaderConcept
158
199
  };
159
200
  }
160
- var narrowerMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_NARROWER, {
201
+ var narrowerMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_NARROWER, {
161
202
  transitive: true,
162
- inverse: chunk7VITUTRA_cjs.META_EDGE_BROADER,
203
+ inverse: chunkQFZ5QB2J_cjs.META_EDGE_BROADER,
163
204
  inference: "hierarchy",
164
205
  description: "Narrower concept (AI narrower ML)"
165
206
  });
@@ -170,7 +211,7 @@ function narrower(broaderConcept, narrowerConcept) {
170
211
  to: narrowerConcept
171
212
  };
172
213
  }
173
- var relatedToMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_RELATED_TO, {
214
+ var relatedToMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_RELATED_TO, {
174
215
  symmetric: true,
175
216
  inference: "association",
176
217
  description: "Non-hierarchical association"
@@ -182,7 +223,7 @@ function relatedTo(conceptA, conceptB) {
182
223
  to: conceptB
183
224
  };
184
225
  }
185
- var equivalentToMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_EQUIVALENT_TO, {
226
+ var equivalentToMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_EQUIVALENT_TO, {
186
227
  symmetric: true,
187
228
  transitive: true,
188
229
  inference: "substitution",
@@ -195,7 +236,7 @@ function equivalentTo(kindA, kindBOrIri) {
195
236
  to: kindBOrIri
196
237
  };
197
238
  }
198
- var sameAsMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_SAME_AS, {
239
+ var sameAsMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_SAME_AS, {
199
240
  symmetric: true,
200
241
  transitive: true,
201
242
  inference: "substitution",
@@ -208,7 +249,7 @@ function sameAs(kindA, kindBOrIri) {
208
249
  to: kindBOrIri
209
250
  };
210
251
  }
211
- var differentFromMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_DIFFERENT_FROM, {
252
+ var differentFromMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_DIFFERENT_FROM, {
212
253
  symmetric: true,
213
254
  inference: "constraint",
214
255
  description: "Explicitly different individuals"
@@ -220,7 +261,7 @@ function differentFrom(kindA, kindB) {
220
261
  to: kindB
221
262
  };
222
263
  }
223
- var disjointWithMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_DISJOINT_WITH, {
264
+ var disjointWithMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_DISJOINT_WITH, {
224
265
  symmetric: true,
225
266
  inference: "constraint",
226
267
  description: "Mutually exclusive types"
@@ -232,9 +273,9 @@ function disjointWith(kindA, kindB) {
232
273
  to: kindB
233
274
  };
234
275
  }
235
- var partOfMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_PART_OF, {
276
+ var partOfMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_PART_OF, {
236
277
  transitive: true,
237
- inverse: chunk7VITUTRA_cjs.META_EDGE_HAS_PART,
278
+ inverse: chunkQFZ5QB2J_cjs.META_EDGE_HAS_PART,
238
279
  inference: "composition",
239
280
  description: "X is part of Y"
240
281
  });
@@ -245,9 +286,9 @@ function partOf(part, whole) {
245
286
  to: whole
246
287
  };
247
288
  }
248
- var hasPartMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_HAS_PART, {
289
+ var hasPartMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_HAS_PART, {
249
290
  transitive: true,
250
- inverse: chunk7VITUTRA_cjs.META_EDGE_PART_OF,
291
+ inverse: chunkQFZ5QB2J_cjs.META_EDGE_PART_OF,
251
292
  inference: "composition",
252
293
  description: "Y has part X"
253
294
  });
@@ -258,12 +299,12 @@ function hasPart(whole, part) {
258
299
  to: part
259
300
  };
260
301
  }
261
- var inverseOfMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_INVERSE_OF, {
302
+ var inverseOfMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_INVERSE_OF, {
262
303
  symmetric: true,
263
304
  inference: "none",
264
305
  description: "Edge A is inverse of edge B"
265
306
  });
266
- var impliesMetaEdge = createMetaEdge(chunk7VITUTRA_cjs.META_EDGE_IMPLIES, {
307
+ var impliesMetaEdge = createMetaEdge(chunkQFZ5QB2J_cjs.META_EDGE_IMPLIES, {
267
308
  transitive: true,
268
309
  inference: "none",
269
310
  description: "Edge A implies edge B exists"
@@ -1374,14 +1415,14 @@ function extractVectorSimilarityPredicates(predicates) {
1374
1415
  break;
1375
1416
  }
1376
1417
  case "and": {
1377
- for (const p of expr.predicates) {
1378
- visit(p, inDisallowedBranch);
1418
+ for (const predicate2 of expr.predicates) {
1419
+ visit(predicate2, inDisallowedBranch);
1379
1420
  }
1380
1421
  break;
1381
1422
  }
1382
1423
  case "or": {
1383
- for (const p of expr.predicates) {
1384
- visit(p, true);
1424
+ for (const predicate2 of expr.predicates) {
1425
+ visit(predicate2, true);
1385
1426
  }
1386
1427
  break;
1387
1428
  }
@@ -2404,6 +2445,9 @@ function compileTemporalFilter(options) {
2404
2445
  return drizzleOrm.sql`${deletedAt} IS NULL AND (${validFrom} IS NULL OR ${validFrom} <= ${now}) AND (${validTo} IS NULL OR ${validTo} > ${now})`;
2405
2446
  }
2406
2447
  case "asOf": {
2448
+ if (asOf === void 0) {
2449
+ throw new Error(`asOf timestamp is required for temporal mode "asOf"`);
2450
+ }
2407
2451
  const timestamp = asOf;
2408
2452
  return drizzleOrm.sql`${deletedAt} IS NULL AND (${validFrom} IS NULL OR ${validFrom} <= ${timestamp}) AND (${validTo} IS NULL OR ${validTo} > ${timestamp})`;
2409
2453
  }
@@ -2714,7 +2758,7 @@ function lowerComposableQueryToLogicalPlanNode(query, dialect, graphId, nextPlan
2714
2758
  }
2715
2759
  const vectorPredicate = runVectorPredicatePass(
2716
2760
  query,
2717
- chunk2WVFEIHR_cjs.getDialect(dialect)
2761
+ chunkMME3H4ZF_cjs.getDialect(dialect)
2718
2762
  ).vectorPredicate;
2719
2763
  const effectiveLimit = resolveVectorAwareLimit(query.limit, vectorPredicate);
2720
2764
  const loweringInput = {
@@ -2811,7 +2855,7 @@ function lowerSetOperationToLogicalPlan(input) {
2811
2855
  }
2812
2856
 
2813
2857
  // src/query/compiler/recursive.ts
2814
- var MAX_RECURSIVE_DEPTH = 100;
2858
+ var MAX_RECURSIVE_DEPTH = 10;
2815
2859
  var MAX_EXPLICIT_RECURSIVE_DEPTH = 1e3;
2816
2860
  var NO_ALWAYS_REQUIRED_COLUMNS = /* @__PURE__ */ new Set();
2817
2861
  function runRecursiveQueryPassPipeline(ast, graphId, ctx) {
@@ -3304,15 +3348,14 @@ var DEFAULT_TABLE_NAMES = {
3304
3348
  edges: "typegraph_edges",
3305
3349
  embeddings: "typegraph_node_embeddings"
3306
3350
  };
3307
- var MAX_IDENTIFIER_LENGTH = 63;
3308
3351
  var VALID_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/i;
3309
3352
  function validateTableName(name, label) {
3310
3353
  if (!name || name.length === 0) {
3311
3354
  throw new chunk44SXEVF4_cjs.ConfigurationError(`${label} table name cannot be empty`);
3312
3355
  }
3313
- if (name.length > MAX_IDENTIFIER_LENGTH) {
3356
+ if (name.length > chunkMME3H4ZF_cjs.MAX_PG_IDENTIFIER_LENGTH) {
3314
3357
  throw new chunk44SXEVF4_cjs.ConfigurationError(
3315
- `${label} table name exceeds maximum length of ${MAX_IDENTIFIER_LENGTH} characters`
3358
+ `${label} table name exceeds maximum length of ${chunkMME3H4ZF_cjs.MAX_PG_IDENTIFIER_LENGTH} characters`
3316
3359
  );
3317
3360
  }
3318
3361
  if (!VALID_IDENTIFIER_PATTERN.test(name)) {
@@ -3395,64 +3438,13 @@ function decodeByValueType(value, valueType) {
3395
3438
  }
3396
3439
  }
3397
3440
 
3398
- // src/store/reserved-keys.ts
3399
- var RESERVED_NODE_KEYS2 = /* @__PURE__ */ new Set([
3400
- "id",
3401
- "kind",
3402
- "meta"
3403
- ]);
3404
- var RESERVED_EDGE_KEYS2 = /* @__PURE__ */ new Set([
3405
- "id",
3406
- "kind",
3407
- "meta",
3408
- "fromKind",
3409
- "fromId",
3410
- "toKind",
3411
- "toId"
3412
- ]);
3413
- var PROTOTYPE_POLLUTION_KEYS = /* @__PURE__ */ new Set([
3414
- "__proto__",
3415
- "constructor",
3416
- "prototype"
3417
- ]);
3418
- function validateProjectionField(field2, entityType, kind) {
3419
- const reserved = entityType === "node" ? RESERVED_NODE_KEYS2 : RESERVED_EDGE_KEYS2;
3420
- if (reserved.has(field2)) {
3421
- throw new chunk44SXEVF4_cjs.ConfigurationError(
3422
- `Projection field "${field2}" on ${entityType} kind "${kind}" conflicts with a reserved structural key`,
3423
- { field: field2, kind, entityType, reservedKeys: [...reserved] },
3424
- {
3425
- suggestion: `Remove "${field2}" from the projection. Structural fields (${[...reserved].join(", ")}) are included automatically when relevant.`
3426
- }
3427
- );
3428
- }
3429
- if (PROTOTYPE_POLLUTION_KEYS.has(field2)) {
3430
- throw new chunk44SXEVF4_cjs.ConfigurationError(
3431
- `Projection field "${field2}" on ${entityType} kind "${kind}" is not allowed`,
3432
- { field: field2, kind, entityType },
3433
- {
3434
- suggestion: `"${field2}" cannot be used as a projection field name.`
3435
- }
3436
- );
3437
- }
3438
- }
3439
- function filterReservedKeys(props, reservedKeys) {
3440
- const filtered = {};
3441
- for (const [key, value] of Object.entries(props)) {
3442
- if (!reservedKeys.has(key)) {
3443
- filtered[key] = value;
3444
- }
3445
- }
3446
- return filtered;
3447
- }
3448
-
3449
3441
  // src/store/row-mappers.ts
3450
3442
  function nullToUndefined2(value) {
3451
3443
  return value === null ? void 0 : value;
3452
3444
  }
3453
3445
  function rowToNode(row) {
3454
3446
  const rawProps = JSON.parse(row.props);
3455
- const props = filterReservedKeys(rawProps, RESERVED_NODE_KEYS2);
3447
+ const props = filterReservedKeys(rawProps, RESERVED_NODE_KEYS);
3456
3448
  return {
3457
3449
  kind: row.kind,
3458
3450
  id: row.id,
@@ -3472,7 +3464,7 @@ function rowToNodeMeta(row) {
3472
3464
  }
3473
3465
  function rowToEdge(row) {
3474
3466
  const rawProps = JSON.parse(row.props);
3475
- const props = filterReservedKeys(rawProps, RESERVED_EDGE_KEYS2);
3467
+ const props = filterReservedKeys(rawProps, RESERVED_EDGE_KEYS);
3476
3468
  return {
3477
3469
  id: row.id,
3478
3470
  kind: row.kind,
@@ -3496,17 +3488,6 @@ function rowToEdgeMeta(row) {
3496
3488
 
3497
3489
  // src/store/subgraph.ts
3498
3490
  var DEFAULT_SUBGRAPH_MAX_DEPTH = 10;
3499
- var MAX_PG_IDENTIFIER_LENGTH = 63;
3500
- function fnv1aBase36(input) {
3501
- let hash = 2166136261;
3502
- for (const character of input) {
3503
- const codePoint = character.codePointAt(0);
3504
- if (codePoint === void 0) continue;
3505
- hash ^= codePoint;
3506
- hash = Math.imul(hash, 16777619);
3507
- }
3508
- return (hash >>> 0).toString(36);
3509
- }
3510
3491
  var TEXT_ENCODER = new TextEncoder();
3511
3492
  function truncateToBytes(value, maxBytes) {
3512
3493
  const encoded = TEXT_ENCODER.encode(value);
@@ -3519,9 +3500,9 @@ function truncateToBytes(value, maxBytes) {
3519
3500
  }
3520
3501
  function projectionAlias(entityPrefix, kind, field2) {
3521
3502
  const prefix = entityPrefix === "node" ? "sg_n" : "sg_e";
3522
- const hash = fnv1aBase36(`${kind}\0${field2}`);
3503
+ const hash = chunkMME3H4ZF_cjs.fnv1aBase36(`${kind}\0${field2}`);
3523
3504
  const fixedBytes = prefix.length + 1 + 1 + hash.length;
3524
- const maxKindBytes = MAX_PG_IDENTIFIER_LENGTH - fixedBytes;
3505
+ const maxKindBytes = chunkMME3H4ZF_cjs.MAX_PG_IDENTIFIER_LENGTH - fixedBytes;
3525
3506
  const truncatedKind = truncateToBytes(kind, maxKindBytes);
3526
3507
  return `${prefix}_${truncatedKind}_${hash}`;
3527
3508
  }
@@ -3538,7 +3519,7 @@ async function executeSubgraph(params) {
3538
3519
  }
3539
3520
  const maxDepth = Math.min(
3540
3521
  options.maxDepth ?? DEFAULT_SUBGRAPH_MAX_DEPTH,
3541
- MAX_RECURSIVE_DEPTH
3522
+ MAX_EXPLICIT_RECURSIVE_DEPTH
3542
3523
  );
3543
3524
  const ctx = {
3544
3525
  graphId: params.graphId,
@@ -4222,6 +4203,7 @@ function compileFieldColumnForSetOp(field2, prefix, dialect) {
4222
4203
  updated_at: "_updated_at",
4223
4204
  deleted_at: "_deleted_at"
4224
4205
  };
4206
+ if (columnName === void 0) return drizzleOrm.sql.raw(`${cteName}.${alias}_props`);
4225
4207
  const suffix = columnMap[columnName];
4226
4208
  if (suffix) {
4227
4209
  return drizzleOrm.sql.raw(`${cteName}.${alias}${suffix}`);
@@ -4300,18 +4282,18 @@ function buildSetOperationSuffixClauses(op, dialect) {
4300
4282
  );
4301
4283
  }
4302
4284
  const orderParts = [];
4303
- for (const o of op.orderBy) {
4304
- const projected = matchFieldToProjection(o.field, projection);
4285
+ for (const orderSpec of op.orderBy) {
4286
+ const projected = matchFieldToProjection(orderSpec.field, projection);
4305
4287
  if (!projected) {
4306
- const fieldDesc = o.field.jsonPointer ? `${o.field.alias}.props${o.field.jsonPointer}` : `${o.field.alias}.${o.field.path.join(".")}`;
4288
+ const fieldDesc = orderSpec.field.jsonPointer ? `${orderSpec.field.alias}.props${orderSpec.field.jsonPointer}` : `${orderSpec.field.alias}.${orderSpec.field.path.join(".")}`;
4307
4289
  const availableFields = projection.fields.map((f) => f.outputName).join(", ");
4308
4290
  throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
4309
4291
  `Set operation ORDER BY field "${fieldDesc}" is not in the projection. ORDER BY for UNION/INTERSECT/EXCEPT must reference projected columns. Available columns: ${availableFields}`
4310
4292
  );
4311
4293
  }
4312
4294
  const columnRef = drizzleOrm.sql.raw(dialect.quoteIdentifier(projected.outputName));
4313
- const dir = drizzleOrm.sql.raw(o.direction.toUpperCase());
4314
- const nulls = o.nulls ?? (o.direction === "asc" ? "last" : "first");
4295
+ const dir = drizzleOrm.sql.raw(orderSpec.direction.toUpperCase());
4296
+ const nulls = orderSpec.nulls ?? (orderSpec.direction === "asc" ? "last" : "first");
4315
4297
  const nullsDir = drizzleOrm.sql.raw(nulls === "first" ? "DESC" : "ASC");
4316
4298
  orderParts.push(
4317
4299
  drizzleOrm.sql`(${columnRef} IS NULL) ${nullsDir}`,
@@ -4663,7 +4645,7 @@ function compileQuery(ast, graphId, options = "sqlite") {
4663
4645
  const options_ = typeof options === "string" ? { dialect: options } : options;
4664
4646
  const dialect = options_.dialect ?? "sqlite";
4665
4647
  const schema = options_.schema ?? DEFAULT_SQL_SCHEMA;
4666
- const adapter = chunk2WVFEIHR_cjs.getDialect(dialect);
4648
+ const adapter = chunkMME3H4ZF_cjs.getDialect(dialect);
4667
4649
  const ctx = {
4668
4650
  dialect: adapter,
4669
4651
  schema,
@@ -4703,7 +4685,7 @@ function compileSetOperation2(op, graphId, options = "sqlite") {
4703
4685
  const options_ = typeof options === "string" ? { dialect: options } : options;
4704
4686
  const dialect = options_.dialect ?? "sqlite";
4705
4687
  const schema = options_.schema ?? DEFAULT_SQL_SCHEMA;
4706
- const adapter = chunk2WVFEIHR_cjs.getDialect(dialect);
4688
+ const adapter = chunkMME3H4ZF_cjs.getDialect(dialect);
4707
4689
  return compileSetOperation(
4708
4690
  op,
4709
4691
  graphId,
@@ -5178,13 +5160,14 @@ function generateId() {
5178
5160
 
5179
5161
  // src/utils/path.ts
5180
5162
  function parseSqlitePath(path) {
5181
- if (!path || path === "||") return [];
5163
+ const emptyPath = `${chunkMME3H4ZF_cjs.SQLITE_PATH_DELIMITER}${chunkMME3H4ZF_cjs.SQLITE_PATH_DELIMITER}`;
5164
+ if (!path || path === emptyPath) return [];
5182
5165
  const trimmed = path.slice(1, -1);
5183
5166
  if (trimmed === "") return [];
5184
- return trimmed.split("|");
5167
+ return trimmed.split(chunkMME3H4ZF_cjs.SQLITE_PATH_DELIMITER);
5185
5168
  }
5186
5169
  function isSqlitePath(value) {
5187
- return typeof value === "string" && value.startsWith("|") && value.endsWith("|");
5170
+ return typeof value === "string" && value.startsWith(chunkMME3H4ZF_cjs.SQLITE_PATH_DELIMITER) && value.endsWith(chunkMME3H4ZF_cjs.SQLITE_PATH_DELIMITER);
5188
5171
  }
5189
5172
  function normalizePath(value) {
5190
5173
  if (Array.isArray(value)) {
@@ -5199,20 +5182,20 @@ function normalizePath(value) {
5199
5182
  return [];
5200
5183
  }
5201
5184
  function isPostgresTextArray(value) {
5202
- return typeof value === "string" && value.startsWith("{") && value.endsWith("}");
5185
+ return typeof value === "string" && value.startsWith(chunkMME3H4ZF_cjs.PG_ARRAY_START) && value.endsWith(chunkMME3H4ZF_cjs.PG_ARRAY_END);
5203
5186
  }
5204
5187
  function parsePostgresTextArray(value) {
5205
5188
  const inner = value.slice(1, -1);
5206
5189
  if (inner === "") return [];
5207
- return inner.split(",");
5190
+ return inner.split(chunkMME3H4ZF_cjs.PG_PATH_ELEMENT_SEPARATOR);
5208
5191
  }
5209
5192
 
5210
5193
  // src/query/execution/result-mapper.ts
5211
5194
  function transformPathColumns(rows, state, _dialect) {
5212
5195
  const pathAliases = [];
5213
- for (const t of state.traversals) {
5214
- if (t.variableLength?.pathAlias !== void 0) {
5215
- pathAliases.push(t.variableLength.pathAlias);
5196
+ for (const traversal of state.traversals) {
5197
+ if (traversal.variableLength?.pathAlias !== void 0) {
5198
+ pathAliases.push(traversal.variableLength.pathAlias);
5216
5199
  }
5217
5200
  }
5218
5201
  if (pathAliases.length === 0) return rows;
@@ -5236,8 +5219,8 @@ function transformPathColumns(rows, state, _dialect) {
5236
5219
  }
5237
5220
  return changed ? result : rows;
5238
5221
  }
5239
- var RESERVED_NODE_KEYS3 = /* @__PURE__ */ new Set(["id", "kind", "meta"]);
5240
- var RESERVED_EDGE_KEYS3 = /* @__PURE__ */ new Set(["id", "kind", "fromId", "toId", "meta"]);
5222
+ var RESERVED_NODE_KEYS2 = /* @__PURE__ */ new Set(["id", "kind", "meta"]);
5223
+ var RESERVED_EDGE_KEYS2 = /* @__PURE__ */ new Set(["id", "kind", "fromId", "toId", "meta"]);
5241
5224
  function nullToUndefined3(value) {
5242
5225
  return value === null ? void 0 : value;
5243
5226
  }
@@ -5275,7 +5258,7 @@ function buildSelectableNode(row, alias) {
5275
5258
  deletedAt
5276
5259
  }
5277
5260
  };
5278
- assignPropsExcludingReserved(result, rawProps, RESERVED_NODE_KEYS3);
5261
+ assignPropsExcludingReserved(result, rawProps, RESERVED_NODE_KEYS2);
5279
5262
  return result;
5280
5263
  }
5281
5264
  function buildSelectableNodeOrUndefined(row, alias) {
@@ -5317,7 +5300,7 @@ function buildSelectableEdge(row, alias) {
5317
5300
  deletedAt
5318
5301
  }
5319
5302
  };
5320
- assignPropsExcludingReserved(result, rawProps, RESERVED_EDGE_KEYS3);
5303
+ assignPropsExcludingReserved(result, rawProps, RESERVED_EDGE_KEYS2);
5321
5304
  return result;
5322
5305
  }
5323
5306
  function buildSelectContext(row, startAlias, traversals) {
@@ -5445,7 +5428,7 @@ async function* createStreamIterable(batchSize, paginate) {
5445
5428
  }
5446
5429
  }
5447
5430
  function getStreamBatchSize(options) {
5448
- return options?.batchSize ?? 1e3;
5431
+ return options?.batchSize ?? chunkMME3H4ZF_cjs.DEFAULT_STREAM_BATCH_SIZE;
5449
5432
  }
5450
5433
 
5451
5434
  // src/query/ast.ts
@@ -5537,7 +5520,7 @@ function createNodeTrackingProxy(alias, kindNames, tracker, options) {
5537
5520
  return getPlaceholderForSystemField(property, options.mode);
5538
5521
  }
5539
5522
  if (property === "meta") {
5540
- for (const key of chunk2WVFEIHR_cjs.NODE_META_KEYS) {
5523
+ for (const key of chunkMME3H4ZF_cjs.NODE_META_KEYS) {
5541
5524
  tracker.record(alias, `meta.${key}`, true);
5542
5525
  }
5543
5526
  return buildNodeMetaPlaceholder(options.mode);
@@ -5570,7 +5553,7 @@ function createEdgeTrackingProxy(alias, edgeKindNames, tracker, options) {
5570
5553
  return getPlaceholderForSystemField(property, options.mode);
5571
5554
  }
5572
5555
  if (property === "meta") {
5573
- for (const key of chunk2WVFEIHR_cjs.EDGE_META_KEYS) {
5556
+ for (const key of chunkMME3H4ZF_cjs.EDGE_META_KEYS) {
5574
5557
  tracker.record(alias, `meta.${key}`, true);
5575
5558
  }
5576
5559
  return buildEdgeMetaPlaceholder(options.mode);
@@ -5857,6 +5840,9 @@ function buildSelectiveContext(row, plans, traversals) {
5857
5840
  return context;
5858
5841
  }
5859
5842
  function buildOptionalAliasValue(row, plan) {
5843
+ if (plan.idOutputName === void 0) {
5844
+ return void 0;
5845
+ }
5860
5846
  const idValue = row[plan.idOutputName];
5861
5847
  if (idValue === null || idValue === void 0) {
5862
5848
  return void 0;
@@ -6258,7 +6244,7 @@ function substituteParameters(ast, bindings) {
6258
6244
  };
6259
6245
  }
6260
6246
  function fillPlaceholders(params, bindings, dialect) {
6261
- const adapter = chunk2WVFEIHR_cjs.getDialect(dialect);
6247
+ const adapter = chunkMME3H4ZF_cjs.getDialect(dialect);
6262
6248
  return params.map((parameter) => {
6263
6249
  if (parameter instanceof drizzleOrm.Placeholder) {
6264
6250
  const name = parameter.name;
@@ -7333,7 +7319,7 @@ var ExecutableQuery = class _ExecutableQuery {
7333
7319
  );
7334
7320
  }
7335
7321
  const isBackward = options.last !== void 0 || options.before !== void 0;
7336
- const limit = options.first ?? options.last ?? 20;
7322
+ const limit = options.first ?? options.last ?? chunkMME3H4ZF_cjs.DEFAULT_PAGINATION_LIMIT;
7337
7323
  const cursor = options.after ?? options.before;
7338
7324
  let cursorData;
7339
7325
  if (cursor) {
@@ -7656,7 +7642,8 @@ var TraversalBuilder = class _TraversalBuilder {
7656
7642
  }
7657
7643
  /**
7658
7644
  * Enables variable-length (recursive) traversal.
7659
- * By default, traverses unlimited depth with cycle prevention.
7645
+ * Defaults to MAX_RECURSIVE_DEPTH (10) hops with cycle prevention.
7646
+ * Use `maxHops` to override (up to MAX_EXPLICIT_RECURSIVE_DEPTH).
7660
7647
  */
7661
7648
  recursive(options) {
7662
7649
  const minDepth = options?.minHops ?? this.#variableLength.minDepth;
@@ -8850,8 +8837,8 @@ function createQueryBuilder(graphId, registry, options) {
8850
8837
  function buildKindRegistry(graph) {
8851
8838
  const nodeTypes = extractNodeTypes(graph);
8852
8839
  const edgeTypes = extractEdgeTypes(graph);
8853
- const closures = graph.ontology.length > 0 ? chunk7VITUTRA_cjs.computeClosuresFromOntology(graph.ontology) : chunk7VITUTRA_cjs.createEmptyClosures();
8854
- return new chunk7VITUTRA_cjs.KindRegistry(nodeTypes, edgeTypes, closures);
8840
+ const closures = graph.ontology.length > 0 ? chunkQFZ5QB2J_cjs.computeClosuresFromOntology(graph.ontology) : chunkQFZ5QB2J_cjs.createEmptyClosures();
8841
+ return new chunkQFZ5QB2J_cjs.KindRegistry(nodeTypes, edgeTypes, closures);
8855
8842
  }
8856
8843
  function extractNodeTypes(graph) {
8857
8844
  const result = /* @__PURE__ */ new Map();
@@ -10053,7 +10040,7 @@ async function validateAndPrepareEdgeCreate(ctx, input, id, backend) {
10053
10040
  nodeId: input.toId
10054
10041
  });
10055
10042
  }
10056
- const validatedProps = chunk7VITUTRA_cjs.validateEdgeProps(edgeKind.schema, input.props, {
10043
+ const validatedProps = chunkQFZ5QB2J_cjs.validateEdgeProps(edgeKind.schema, input.props, {
10057
10044
  kind,
10058
10045
  operation: "create"
10059
10046
  });
@@ -10203,7 +10190,7 @@ async function executeEdgeUpdate(ctx, input, backend) {
10203
10190
  const edgeKind = registration.type;
10204
10191
  const existingProps = JSON.parse(existing.props);
10205
10192
  const mergedProps = { ...existingProps, ...input.props };
10206
- const validatedProps = chunk7VITUTRA_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
10193
+ const validatedProps = chunkQFZ5QB2J_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
10207
10194
  kind: existing.kind,
10208
10195
  operation: "update",
10209
10196
  id
@@ -10229,7 +10216,7 @@ async function executeEdgeUpsertUpdate(ctx, input, backend, options) {
10229
10216
  const edgeKind = registration.type;
10230
10217
  const existingProps = JSON.parse(existing.props);
10231
10218
  const mergedProps = { ...existingProps, ...input.props };
10232
- const validatedProps = chunk7VITUTRA_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
10219
+ const validatedProps = chunkQFZ5QB2J_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
10233
10220
  kind: existing.kind,
10234
10221
  operation: "update",
10235
10222
  id
@@ -10386,7 +10373,7 @@ async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, to
10386
10373
  const matchOn = options?.matchOn ?? [];
10387
10374
  const registration = getEdgeRegistration(ctx.graph, kind);
10388
10375
  const edgeKind = registration.type;
10389
- const validatedProps = chunk7VITUTRA_cjs.validateEdgeProps(edgeKind.schema, props, {
10376
+ const validatedProps = chunkQFZ5QB2J_cjs.validateEdgeProps(edgeKind.schema, props, {
10390
10377
  kind,
10391
10378
  operation: "create"
10392
10379
  });
@@ -10430,6 +10417,9 @@ async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, to
10430
10417
  return { edge: edge2, action: "updated" };
10431
10418
  }
10432
10419
  const cardinality = registration.cardinality ?? "many";
10420
+ if (deletedRow === void 0) {
10421
+ throw new Error("Expected deletedRow to be defined");
10422
+ }
10433
10423
  const matchedDeletedRow = deletedRow;
10434
10424
  const effectiveValidTo = matchedDeletedRow.valid_to;
10435
10425
  const constraintContext = {
@@ -10465,7 +10455,7 @@ async function executeEdgeBulkGetOrCreateByEndpoints(ctx, kind, items, backend,
10465
10455
  validateMatchOnFields(edgeKind.schema, matchOn, kind);
10466
10456
  const validated = [];
10467
10457
  for (const item of items) {
10468
- const validatedProps = chunk7VITUTRA_cjs.validateEdgeProps(edgeKind.schema, item.props, {
10458
+ const validatedProps = chunkQFZ5QB2J_cjs.validateEdgeProps(edgeKind.schema, item.props, {
10469
10459
  kind,
10470
10460
  operation: "create"
10471
10461
  });
@@ -10549,6 +10539,9 @@ async function executeEdgeBulkGetOrCreateByEndpoints(ctx, kind, items, backend,
10549
10539
  });
10550
10540
  } else {
10551
10541
  const bestRow = liveRow ?? deletedRow;
10542
+ if (bestRow === void 0) {
10543
+ throw new Error("Expected at least one of liveRow or deletedRow");
10544
+ }
10552
10545
  toFetch.push({
10553
10546
  index,
10554
10547
  row: bestRow,
@@ -10849,11 +10842,12 @@ function getNodeRegistration(graph, kind) {
10849
10842
  if (registration === void 0) throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
10850
10843
  return registration;
10851
10844
  }
10845
+ var CACHE_KEY_SEPARATOR = "\0";
10852
10846
  function buildNodeCacheKey(graphId, kind, id) {
10853
- return `${graphId}\0${kind}\0${id}`;
10847
+ return `${graphId}${CACHE_KEY_SEPARATOR}${kind}${CACHE_KEY_SEPARATOR}${id}`;
10854
10848
  }
10855
10849
  function buildUniqueCacheKey(graphId, nodeKind, constraintName, key) {
10856
- return `${graphId}\0${nodeKind}\0${constraintName}\0${key}`;
10850
+ return `${graphId}${CACHE_KEY_SEPARATOR}${nodeKind}${CACHE_KEY_SEPARATOR}${constraintName}${CACHE_KEY_SEPARATOR}${key}`;
10857
10851
  }
10858
10852
  function createNodeAlreadyExistsError(kind, id) {
10859
10853
  return new chunk44SXEVF4_cjs.ValidationError(
@@ -10890,6 +10884,23 @@ function createPendingUniqueRow(graphId, nodeKind, constraintName, key, nodeId)
10890
10884
  deleted_at: void 0
10891
10885
  };
10892
10886
  }
10887
+ function resolveConstraint(graph, kind, constraintName) {
10888
+ const registration = getNodeRegistration(graph, kind);
10889
+ const constraints = registration.unique ?? [];
10890
+ const constraint = constraints.find(
10891
+ (candidate) => candidate.name === constraintName
10892
+ );
10893
+ if (constraint === void 0) {
10894
+ throw new chunk44SXEVF4_cjs.NodeConstraintNotFoundError(constraintName, kind);
10895
+ }
10896
+ return constraint;
10897
+ }
10898
+ function createUniquenessContext(graphId, registry, backend) {
10899
+ return { graphId, registry, backend };
10900
+ }
10901
+ function createEmbeddingSyncContext(graphId, nodeKind, nodeId, backend) {
10902
+ return { graphId, nodeKind, nodeId, backend };
10903
+ }
10893
10904
  function createNodeBatchValidationBackend(graphId, registry, backend) {
10894
10905
  const nodeCache = /* @__PURE__ */ new Map();
10895
10906
  const pendingNodes = /* @__PURE__ */ new Map();
@@ -10898,12 +10909,8 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
10898
10909
  async function getNodeCached(lookupGraphId, kind, id) {
10899
10910
  const cacheKey = buildNodeCacheKey(lookupGraphId, kind, id);
10900
10911
  const pendingNode = pendingNodes.get(cacheKey);
10901
- if (pendingNode !== void 0) {
10902
- return pendingNode;
10903
- }
10904
- if (nodeCache.has(cacheKey)) {
10905
- return nodeCache.get(cacheKey);
10906
- }
10912
+ if (pendingNode !== void 0) return pendingNode;
10913
+ if (nodeCache.has(cacheKey)) return nodeCache.get(cacheKey);
10907
10914
  const existing = await backend.getNode(lookupGraphId, kind, id);
10908
10915
  nodeCache.set(cacheKey, existing);
10909
10916
  return existing;
@@ -10925,16 +10932,14 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
10925
10932
  pendingOwner
10926
10933
  );
10927
10934
  }
10928
- if (uniqueCache.has(cacheKey)) {
10929
- return uniqueCache.get(cacheKey);
10930
- }
10935
+ if (uniqueCache.has(cacheKey)) return uniqueCache.get(cacheKey);
10931
10936
  const existing = await backend.checkUnique(params);
10932
10937
  uniqueCache.set(cacheKey, existing);
10933
10938
  return existing;
10934
10939
  }
10935
10940
  function registerPendingNode(params) {
10936
10941
  const cacheKey = buildNodeCacheKey(params.graphId, params.kind, params.id);
10937
- const pendingNode = {
10942
+ pendingNodes.set(cacheKey, {
10938
10943
  graph_id: params.graphId,
10939
10944
  kind: params.kind,
10940
10945
  id: params.id,
@@ -10945,14 +10950,11 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
10945
10950
  created_at: "",
10946
10951
  updated_at: "",
10947
10952
  deleted_at: void 0
10948
- };
10949
- pendingNodes.set(cacheKey, pendingNode);
10953
+ });
10950
10954
  }
10951
10955
  function registerPendingUniqueEntries(kind, id, props, constraints) {
10952
10956
  for (const constraint of constraints) {
10953
- if (!checkWherePredicate(constraint, props)) {
10954
- continue;
10955
- }
10957
+ if (!checkWherePredicate(constraint, props)) continue;
10956
10958
  const key = computeUniqueKey(
10957
10959
  props,
10958
10960
  constraint.fields,
@@ -10998,7 +11000,7 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
10998
11000
  const kind = input.kind;
10999
11001
  const registration = getNodeRegistration(ctx.graph, kind);
11000
11002
  const nodeKind = registration.type;
11001
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, input.props, {
11003
+ const validatedProps = chunkQFZ5QB2J_cjs.validateNodeProps(nodeKind.schema, input.props, {
11002
11004
  kind,
11003
11005
  operation: "create"
11004
11006
  });
@@ -11014,14 +11016,9 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
11014
11016
  backend
11015
11017
  };
11016
11018
  await checkDisjointnessConstraint(constraintContext, kind, id);
11017
- const uniquenessContext = {
11018
- graphId: ctx.graphId,
11019
- registry: ctx.registry,
11020
- backend
11021
- };
11022
11019
  const uniqueConstraints = registration.unique ?? [];
11023
11020
  await checkUniquenessConstraints(
11024
- uniquenessContext,
11021
+ createUniquenessContext(ctx.graphId, ctx.registry, backend),
11025
11022
  kind,
11026
11023
  id,
11027
11024
  validatedProps,
@@ -11044,64 +11041,99 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
11044
11041
  };
11045
11042
  }
11046
11043
  async function finalizeNodeCreate(ctx, prepared, backend) {
11047
- const uniquenessContext = {
11048
- graphId: ctx.graphId,
11049
- registry: ctx.registry,
11050
- backend
11051
- };
11052
11044
  await insertUniquenessEntries(
11053
- uniquenessContext,
11045
+ createUniquenessContext(ctx.graphId, ctx.registry, backend),
11054
11046
  prepared.kind,
11055
11047
  prepared.id,
11056
11048
  prepared.validatedProps,
11057
11049
  prepared.uniqueConstraints
11058
11050
  );
11059
- const embeddingSyncContext = {
11060
- graphId: ctx.graphId,
11061
- nodeKind: prepared.kind,
11062
- nodeId: prepared.id,
11063
- backend
11064
- };
11065
11051
  await syncEmbeddings(
11066
- embeddingSyncContext,
11052
+ createEmbeddingSyncContext(
11053
+ ctx.graphId,
11054
+ prepared.kind,
11055
+ prepared.id,
11056
+ backend
11057
+ ),
11067
11058
  prepared.nodeKind.schema,
11068
11059
  prepared.validatedProps
11069
11060
  );
11070
11061
  }
11071
- async function executeNodeCreateInternal(ctx, input, backend, options) {
11072
- const kind = input.kind;
11073
- const id = input.id ?? generateId();
11074
- const opContext = ctx.createOperationContext("create", "node", kind, id);
11075
- return ctx.withOperationHooks(opContext, async () => {
11076
- const prepared = await validateAndPrepareNodeCreate(
11077
- ctx,
11078
- input,
11079
- id,
11080
- backend
11081
- );
11082
- let row;
11083
- {
11084
- row = await backend.insertNode(prepared.insertParams);
11085
- }
11086
- await finalizeNodeCreate(ctx, prepared, backend);
11087
- if (row === void 0) return;
11088
- return rowToNode(row);
11062
+ async function performNodeUpdate(ctx, input, backend, options) {
11063
+ const { kind, id } = input;
11064
+ const registration = getNodeRegistration(ctx.graph, kind);
11065
+ const existing = await backend.getNode(ctx.graphId, kind, id);
11066
+ if (!existing || existing.deleted_at && !options?.clearDeleted) {
11067
+ throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
11068
+ }
11069
+ const existingProps = JSON.parse(existing.props);
11070
+ const mergedProps = { ...existingProps, ...input.props };
11071
+ const nodeKind = registration.type;
11072
+ const validatedProps = chunkQFZ5QB2J_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
11073
+ kind,
11074
+ operation: "update",
11075
+ id
11089
11076
  });
11077
+ const validTo = chunkNI2GV74U_cjs.validateOptionalIsoDate(input.validTo, "validTo");
11078
+ await updateUniquenessEntries(
11079
+ createUniquenessContext(ctx.graphId, ctx.registry, backend),
11080
+ kind,
11081
+ id,
11082
+ existingProps,
11083
+ validatedProps,
11084
+ registration.unique ?? []
11085
+ );
11086
+ const updateParams = {
11087
+ graphId: ctx.graphId,
11088
+ kind,
11089
+ id,
11090
+ props: validatedProps,
11091
+ incrementVersion: true
11092
+ };
11093
+ if (validTo !== void 0) updateParams.validTo = validTo;
11094
+ if (options?.clearDeleted) updateParams.clearDeleted = true;
11095
+ const row = await backend.updateNode(updateParams);
11096
+ await syncEmbeddings(
11097
+ createEmbeddingSyncContext(ctx.graphId, kind, id, backend),
11098
+ nodeKind.schema,
11099
+ validatedProps
11100
+ );
11101
+ return rowToNode(row);
11090
11102
  }
11091
- async function executeNodeCreate(ctx, input, backend) {
11092
- const result = await executeNodeCreateInternal(ctx, input, backend);
11093
- if (!result) {
11094
- throw new chunk44SXEVF4_cjs.DatabaseOperationError(
11095
- "Node create failed: expected created node row",
11096
- { operation: "insert", entity: "node" }
11097
- );
11103
+ async function enforceDeleteBehavior(ctx, kind, id, mode, backend, registration) {
11104
+ const deleteBehavior = registration.onDelete ?? "restrict";
11105
+ const connectedEdges = await backend.findEdgesConnectedTo({
11106
+ graphId: ctx.graphId,
11107
+ nodeKind: kind,
11108
+ nodeId: id
11109
+ });
11110
+ if (connectedEdges.length === 0) return;
11111
+ switch (deleteBehavior) {
11112
+ case "restrict": {
11113
+ const edgeKinds = [...new Set(connectedEdges.map((edge) => edge.kind))];
11114
+ throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
11115
+ nodeKind: kind,
11116
+ nodeId: id,
11117
+ edgeCount: connectedEdges.length,
11118
+ edgeKinds
11119
+ });
11120
+ }
11121
+ case "cascade":
11122
+ case "disconnect": {
11123
+ for (const edge of connectedEdges) {
11124
+ await (mode === "hard" ? backend.hardDeleteEdge({
11125
+ graphId: ctx.graphId,
11126
+ id: edge.id
11127
+ }) : backend.deleteEdge({
11128
+ graphId: ctx.graphId,
11129
+ id: edge.id
11130
+ }));
11131
+ }
11132
+ break;
11133
+ }
11098
11134
  }
11099
- return result;
11100
11135
  }
11101
- async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
11102
- if (inputs.length === 0) {
11103
- return;
11104
- }
11136
+ async function prepareBatchCreates(ctx, inputs, backend) {
11105
11137
  const {
11106
11138
  backend: validationBackend,
11107
11139
  registerPendingNode,
@@ -11128,46 +11160,109 @@ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
11128
11160
  const batchInsertParams = preparedCreates.map(
11129
11161
  (prepared) => prepared.insertParams
11130
11162
  );
11131
- if (backend.insertNodesBatch === void 0) {
11132
- for (const insertParams of batchInsertParams) {
11133
- await (backend.insertNodeNoReturn?.(insertParams) ?? backend.insertNode(insertParams));
11134
- }
11135
- } else {
11136
- await backend.insertNodesBatch(batchInsertParams);
11137
- }
11138
- for (const prepared of preparedCreates) {
11139
- await finalizeNodeCreate(ctx, prepared, backend);
11140
- }
11163
+ return { preparedCreates, batchInsertParams };
11141
11164
  }
11142
- async function executeNodeCreateBatch(ctx, inputs, backend) {
11143
- if (inputs.length === 0) {
11144
- return [];
11165
+ async function findUniqueRowAcrossKinds(backend, graphId, constraintName, key, kindsToCheck, includeDeleted) {
11166
+ for (const kindToCheck of kindsToCheck) {
11167
+ const row = await backend.checkUnique({
11168
+ graphId,
11169
+ nodeKind: kindToCheck,
11170
+ constraintName,
11171
+ key,
11172
+ includeDeleted
11173
+ });
11174
+ if (row !== void 0) return row;
11145
11175
  }
11146
- const {
11147
- backend: validationBackend,
11148
- registerPendingNode,
11149
- registerPendingUniqueEntries
11150
- } = createNodeBatchValidationBackend(ctx.graphId, ctx.registry, backend);
11151
- const preparedCreates = [];
11152
- for (const input of inputs) {
11153
- const id = input.id ?? generateId();
11154
- const prepared = await validateAndPrepareNodeCreate(
11155
- ctx,
11156
- input,
11176
+ return void 0;
11177
+ }
11178
+ async function batchCheckUniqueAcrossKinds(backend, graphId, constraintName, uniqueKeys, kindsToCheck, includeDeleted) {
11179
+ const existingByKey = /* @__PURE__ */ new Map();
11180
+ for (const kindToCheck of kindsToCheck) {
11181
+ if (backend.checkUniqueBatch === void 0) {
11182
+ for (const key of uniqueKeys) {
11183
+ if (existingByKey.has(key)) continue;
11184
+ const row = await backend.checkUnique({
11185
+ graphId,
11186
+ nodeKind: kindToCheck,
11187
+ constraintName,
11188
+ key,
11189
+ includeDeleted
11190
+ });
11191
+ if (row !== void 0) {
11192
+ existingByKey.set(row.key, row);
11193
+ }
11194
+ }
11195
+ } else {
11196
+ const rows = await backend.checkUniqueBatch({
11197
+ graphId,
11198
+ nodeKind: kindToCheck,
11199
+ constraintName,
11200
+ keys: uniqueKeys,
11201
+ includeDeleted
11202
+ });
11203
+ for (const row of rows) {
11204
+ if (!existingByKey.has(row.key)) {
11205
+ existingByKey.set(row.key, row);
11206
+ }
11207
+ }
11208
+ }
11209
+ }
11210
+ return existingByKey;
11211
+ }
11212
+ async function executeNodeCreateInternal(ctx, input, backend, options) {
11213
+ const kind = input.kind;
11214
+ const id = input.id ?? generateId();
11215
+ const opContext = ctx.createOperationContext("create", "node", kind, id);
11216
+ return ctx.withOperationHooks(opContext, async () => {
11217
+ const prepared = await validateAndPrepareNodeCreate(
11218
+ ctx,
11219
+ input,
11157
11220
  id,
11158
- validationBackend
11221
+ backend
11159
11222
  );
11160
- preparedCreates.push(prepared);
11161
- registerPendingNode(prepared.insertParams);
11162
- registerPendingUniqueEntries(
11163
- prepared.kind,
11164
- prepared.id,
11165
- prepared.validatedProps,
11166
- prepared.uniqueConstraints
11223
+ let row;
11224
+ {
11225
+ row = await backend.insertNode(prepared.insertParams);
11226
+ }
11227
+ await finalizeNodeCreate(ctx, prepared, backend);
11228
+ if (row === void 0) return;
11229
+ return rowToNode(row);
11230
+ });
11231
+ }
11232
+ async function executeNodeCreate(ctx, input, backend) {
11233
+ const result = await executeNodeCreateInternal(ctx, input, backend);
11234
+ if (!result) {
11235
+ throw new chunk44SXEVF4_cjs.DatabaseOperationError(
11236
+ "Node create failed: expected created node row",
11237
+ { operation: "insert", entity: "node" }
11167
11238
  );
11168
11239
  }
11169
- const batchInsertParams = preparedCreates.map(
11170
- (prepared) => prepared.insertParams
11240
+ return result;
11241
+ }
11242
+ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
11243
+ if (inputs.length === 0) return;
11244
+ const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
11245
+ ctx,
11246
+ inputs,
11247
+ backend
11248
+ );
11249
+ if (backend.insertNodesBatch === void 0) {
11250
+ for (const insertParams of batchInsertParams) {
11251
+ await (backend.insertNodeNoReturn?.(insertParams) ?? backend.insertNode(insertParams));
11252
+ }
11253
+ } else {
11254
+ await backend.insertNodesBatch(batchInsertParams);
11255
+ }
11256
+ for (const prepared of preparedCreates) {
11257
+ await finalizeNodeCreate(ctx, prepared, backend);
11258
+ }
11259
+ }
11260
+ async function executeNodeCreateBatch(ctx, inputs, backend) {
11261
+ if (inputs.length === 0) return [];
11262
+ const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
11263
+ ctx,
11264
+ inputs,
11265
+ backend
11171
11266
  );
11172
11267
  let rows;
11173
11268
  if (backend.insertNodesBatchReturning === void 0) {
@@ -11185,170 +11280,40 @@ async function executeNodeCreateBatch(ctx, inputs, backend) {
11185
11280
  return rows.map((row) => rowToNode(row));
11186
11281
  }
11187
11282
  async function executeNodeUpdate(ctx, input, backend, options) {
11188
- const kind = input.kind;
11189
- const id = input.id;
11190
- const opContext = ctx.createOperationContext("update", "node", kind, id);
11191
- return ctx.withOperationHooks(opContext, async () => {
11192
- const registration = getNodeRegistration(ctx.graph, kind);
11193
- const existing = await backend.getNode(ctx.graphId, kind, id);
11194
- if (!existing || existing.deleted_at && !options?.clearDeleted) {
11195
- throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
11196
- }
11197
- const existingProps = JSON.parse(existing.props);
11198
- const mergedProps = { ...existingProps, ...input.props };
11199
- const nodeKind = registration.type;
11200
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
11201
- kind,
11202
- operation: "update",
11203
- id
11204
- });
11205
- const validTo = chunkNI2GV74U_cjs.validateOptionalIsoDate(input.validTo, "validTo");
11206
- const uniquenessContext = {
11207
- graphId: ctx.graphId,
11208
- registry: ctx.registry,
11209
- backend
11210
- };
11211
- await updateUniquenessEntries(
11212
- uniquenessContext,
11213
- kind,
11214
- id,
11215
- existingProps,
11216
- validatedProps,
11217
- registration.unique ?? []
11218
- );
11219
- const updateParams = {
11220
- graphId: ctx.graphId,
11221
- kind,
11222
- id,
11223
- props: validatedProps,
11224
- incrementVersion: true
11225
- };
11226
- if (validTo !== void 0) updateParams.validTo = validTo;
11227
- if (options?.clearDeleted) updateParams.clearDeleted = true;
11228
- const row = await backend.updateNode(updateParams);
11229
- const embeddingSyncContext = {
11230
- graphId: ctx.graphId,
11231
- nodeKind: kind,
11232
- nodeId: id,
11233
- backend
11234
- };
11235
- await syncEmbeddings(embeddingSyncContext, nodeKind.schema, validatedProps);
11236
- return rowToNode(row);
11237
- });
11283
+ const opContext = ctx.createOperationContext(
11284
+ "update",
11285
+ "node",
11286
+ input.kind,
11287
+ input.id
11288
+ );
11289
+ return ctx.withOperationHooks(
11290
+ opContext,
11291
+ () => performNodeUpdate(ctx, input, backend, options)
11292
+ );
11238
11293
  }
11239
11294
  async function executeNodeUpsertUpdate(ctx, input, backend, options) {
11240
- const kind = input.kind;
11241
- const id = input.id;
11242
- const registration = getNodeRegistration(ctx.graph, kind);
11243
- const existing = await backend.getNode(ctx.graphId, kind, id);
11244
- if (!existing || existing.deleted_at && !options?.clearDeleted) {
11245
- throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
11246
- }
11247
- const existingProps = JSON.parse(existing.props);
11248
- const mergedProps = { ...existingProps, ...input.props };
11249
- const nodeKind = registration.type;
11250
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
11251
- kind,
11252
- operation: "update",
11253
- id
11254
- });
11255
- const validTo = chunkNI2GV74U_cjs.validateOptionalIsoDate(input.validTo, "validTo");
11256
- const uniquenessContext = {
11257
- graphId: ctx.graphId,
11258
- registry: ctx.registry,
11259
- backend
11260
- };
11261
- await updateUniquenessEntries(
11262
- uniquenessContext,
11263
- kind,
11264
- id,
11265
- existingProps,
11266
- validatedProps,
11267
- registration.unique ?? []
11268
- );
11269
- const updateParams = {
11270
- graphId: ctx.graphId,
11271
- kind,
11272
- id,
11273
- props: validatedProps,
11274
- incrementVersion: true
11275
- };
11276
- if (validTo !== void 0) updateParams.validTo = validTo;
11277
- if (options?.clearDeleted) updateParams.clearDeleted = true;
11278
- const row = await backend.updateNode(updateParams);
11279
- const embeddingSyncContext = {
11280
- graphId: ctx.graphId,
11281
- nodeKind: kind,
11282
- nodeId: id,
11283
- backend
11284
- };
11285
- await syncEmbeddings(embeddingSyncContext, nodeKind.schema, validatedProps);
11286
- return rowToNode(row);
11295
+ return performNodeUpdate(ctx, input, backend, options);
11287
11296
  }
11288
11297
  async function executeNodeDelete(ctx, kind, id, backend) {
11289
11298
  const opContext = ctx.createOperationContext("delete", "node", kind, id);
11290
11299
  return ctx.withOperationHooks(opContext, async () => {
11291
11300
  const registration = getNodeRegistration(ctx.graph, kind);
11292
11301
  const existing = await backend.getNode(ctx.graphId, kind, id);
11293
- if (!existing || existing.deleted_at) {
11294
- return;
11295
- }
11302
+ if (!existing || existing.deleted_at) return;
11296
11303
  const existingProps = JSON.parse(existing.props);
11297
- const deleteBehavior = registration.onDelete ?? "restrict";
11298
- const connectedEdges = await backend.findEdgesConnectedTo({
11299
- graphId: ctx.graphId,
11300
- nodeKind: kind,
11301
- nodeId: id
11302
- });
11303
- if (connectedEdges.length > 0) {
11304
- switch (deleteBehavior) {
11305
- case "restrict": {
11306
- const edgeKinds = [
11307
- ...new Set(connectedEdges.map((edge) => edge.kind))
11308
- ];
11309
- throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
11310
- nodeKind: kind,
11311
- nodeId: id,
11312
- edgeCount: connectedEdges.length,
11313
- edgeKinds
11314
- });
11315
- }
11316
- case "cascade":
11317
- case "disconnect": {
11318
- for (const edge of connectedEdges) {
11319
- await backend.deleteEdge({
11320
- graphId: ctx.graphId,
11321
- id: edge.id
11322
- });
11323
- }
11324
- break;
11325
- }
11326
- }
11327
- }
11328
- await backend.deleteNode({
11329
- graphId: ctx.graphId,
11330
- kind,
11331
- id
11332
- });
11333
- const uniquenessContext = {
11334
- graphId: ctx.graphId,
11335
- registry: ctx.registry,
11336
- backend
11337
- };
11304
+ await enforceDeleteBehavior(ctx, kind, id, "soft", backend, registration);
11305
+ await backend.deleteNode({ graphId: ctx.graphId, kind, id });
11338
11306
  await deleteUniquenessEntries(
11339
- uniquenessContext,
11307
+ createUniquenessContext(ctx.graphId, ctx.registry, backend),
11340
11308
  kind,
11341
11309
  existingProps,
11342
11310
  registration.unique ?? []
11343
11311
  );
11344
11312
  const nodeKind = registration.type;
11345
- const embeddingSyncContext = {
11346
- graphId: ctx.graphId,
11347
- nodeKind: kind,
11348
- nodeId: id,
11349
- backend
11350
- };
11351
- await deleteNodeEmbeddings(embeddingSyncContext, nodeKind.schema);
11313
+ await deleteNodeEmbeddings(
11314
+ createEmbeddingSyncContext(ctx.graphId, kind, id, backend),
11315
+ nodeKind.schema
11316
+ );
11352
11317
  });
11353
11318
  }
11354
11319
  async function executeNodeHardDelete(ctx, kind, id, backend) {
@@ -11356,71 +11321,29 @@ async function executeNodeHardDelete(ctx, kind, id, backend) {
11356
11321
  return ctx.withOperationHooks(opContext, async () => {
11357
11322
  const registration = getNodeRegistration(ctx.graph, kind);
11358
11323
  const existing = await backend.getNode(ctx.graphId, kind, id);
11359
- if (!existing) {
11360
- return;
11361
- }
11362
- const deleteBehavior = registration.onDelete ?? "restrict";
11363
- const connectedEdges = await backend.findEdgesConnectedTo({
11364
- graphId: ctx.graphId,
11365
- nodeKind: kind,
11366
- nodeId: id
11367
- });
11368
- if (connectedEdges.length > 0) {
11369
- switch (deleteBehavior) {
11370
- case "restrict": {
11371
- const edgeKinds = [
11372
- ...new Set(connectedEdges.map((edge) => edge.kind))
11373
- ];
11374
- throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
11375
- nodeKind: kind,
11376
- nodeId: id,
11377
- edgeCount: connectedEdges.length,
11378
- edgeKinds
11379
- });
11380
- }
11381
- case "cascade":
11382
- case "disconnect": {
11383
- for (const edge of connectedEdges) {
11384
- await backend.hardDeleteEdge({
11385
- graphId: ctx.graphId,
11386
- id: edge.id
11387
- });
11388
- }
11389
- break;
11390
- }
11391
- }
11392
- }
11324
+ if (!existing) return;
11325
+ await enforceDeleteBehavior(ctx, kind, id, "hard", backend, registration);
11393
11326
  const hardDelete = async (target) => {
11394
- await target.hardDeleteNode({
11395
- graphId: ctx.graphId,
11396
- kind,
11397
- id
11398
- });
11327
+ await target.hardDeleteNode({ graphId: ctx.graphId, kind, id });
11399
11328
  };
11400
11329
  await ("transaction" in backend && backend.capabilities.transactions ? backend.transaction(async (tx) => hardDelete(tx)) : hardDelete(backend));
11401
11330
  });
11402
11331
  }
11403
- function resolveConstraint(graph, kind, constraintName) {
11404
- const registration = getNodeRegistration(graph, kind);
11405
- const constraints = registration.unique ?? [];
11406
- const constraint = constraints.find((c) => c.name === constraintName);
11407
- if (constraint === void 0) {
11408
- throw new chunk44SXEVF4_cjs.NodeConstraintNotFoundError(constraintName, kind);
11409
- }
11410
- return constraint;
11411
- }
11412
11332
  async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, props, backend, options) {
11413
11333
  const ifExists = options?.ifExists ?? "return";
11414
11334
  const registration = getNodeRegistration(ctx.graph, kind);
11415
11335
  const nodeKind = registration.type;
11416
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, props, {
11336
+ const validatedProps = chunkQFZ5QB2J_cjs.validateNodeProps(nodeKind.schema, props, {
11417
11337
  kind,
11418
11338
  operation: "create"
11419
11339
  });
11420
11340
  const constraint = resolveConstraint(ctx.graph, kind, constraintName);
11421
11341
  if (!checkWherePredicate(constraint, validatedProps)) {
11422
- const input = { kind, props: validatedProps };
11423
- const node = await executeNodeCreate(ctx, input, backend);
11342
+ const node = await executeNodeCreate(
11343
+ ctx,
11344
+ { kind, props: validatedProps },
11345
+ backend
11346
+ );
11424
11347
  return { node, action: "created" };
11425
11348
  }
11426
11349
  const key = computeUniqueKey(
@@ -11433,23 +11356,20 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
11433
11356
  constraint.scope,
11434
11357
  ctx.registry
11435
11358
  );
11436
- let existingUniqueRow;
11437
- for (const kindToCheck of kindsToCheck) {
11438
- const row = await backend.checkUnique({
11439
- graphId: ctx.graphId,
11440
- nodeKind: kindToCheck,
11441
- constraintName: constraint.name,
11442
- key,
11443
- includeDeleted: true
11444
- });
11445
- if (row !== void 0) {
11446
- existingUniqueRow = row;
11447
- break;
11448
- }
11449
- }
11359
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
11360
+ backend,
11361
+ ctx.graphId,
11362
+ constraint.name,
11363
+ key,
11364
+ kindsToCheck,
11365
+ true
11366
+ );
11450
11367
  if (existingUniqueRow === void 0) {
11451
- const input = { kind, props: validatedProps };
11452
- const node = await executeNodeCreate(ctx, input, backend);
11368
+ const node = await executeNodeCreate(
11369
+ ctx,
11370
+ { kind, props: validatedProps },
11371
+ backend
11372
+ );
11453
11373
  return { node, action: "created" };
11454
11374
  }
11455
11375
  const existingRow = await backend.getNode(
@@ -11458,8 +11378,11 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
11458
11378
  existingUniqueRow.node_id
11459
11379
  );
11460
11380
  if (existingRow === void 0) {
11461
- const input = { kind, props: validatedProps };
11462
- const node = await executeNodeCreate(ctx, input, backend);
11381
+ const node = await executeNodeCreate(
11382
+ ctx,
11383
+ { kind, props: validatedProps },
11384
+ backend
11385
+ );
11463
11386
  return { node, action: "created" };
11464
11387
  }
11465
11388
  const isSoftDeleted = existingRow.deleted_at !== void 0;
@@ -11482,7 +11405,7 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
11482
11405
  async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
11483
11406
  const registration = getNodeRegistration(ctx.graph, kind);
11484
11407
  const nodeKind = registration.type;
11485
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, props, {
11408
+ const validatedProps = chunkQFZ5QB2J_cjs.validateNodeProps(nodeKind.schema, props, {
11486
11409
  kind,
11487
11410
  operation: "create"
11488
11411
  });
@@ -11498,20 +11421,14 @@ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, bac
11498
11421
  constraint.scope,
11499
11422
  ctx.registry
11500
11423
  );
11501
- let existingUniqueRow;
11502
- for (const kindToCheck of kindsToCheck) {
11503
- const row = await backend.checkUnique({
11504
- graphId: ctx.graphId,
11505
- nodeKind: kindToCheck,
11506
- constraintName: constraint.name,
11507
- key,
11508
- includeDeleted: false
11509
- });
11510
- if (row !== void 0) {
11511
- existingUniqueRow = row;
11512
- break;
11513
- }
11514
- }
11424
+ const existingUniqueRow = await findUniqueRowAcrossKinds(
11425
+ backend,
11426
+ ctx.graphId,
11427
+ constraint.name,
11428
+ key,
11429
+ kindsToCheck,
11430
+ false
11431
+ );
11515
11432
  if (existingUniqueRow === void 0) return void 0;
11516
11433
  const existingRow = await backend.getNode(
11517
11434
  ctx.graphId,
@@ -11522,14 +11439,10 @@ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, bac
11522
11439
  return void 0;
11523
11440
  return rowToNode(existingRow);
11524
11441
  }
11525
- async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
11526
- if (items.length === 0) return [];
11527
- const registration = getNodeRegistration(ctx.graph, kind);
11528
- const nodeKind = registration.type;
11529
- const constraint = resolveConstraint(ctx.graph, kind, constraintName);
11442
+ function validateAndComputeKeys(nodeKind, kind, constraint, items) {
11530
11443
  const validated = [];
11531
11444
  for (const item of items) {
11532
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, item.props, {
11445
+ const validatedProps = chunkQFZ5QB2J_cjs.validateNodeProps(nodeKind.schema, item.props, {
11533
11446
  kind,
11534
11447
  operation: "create"
11535
11448
  });
@@ -11541,49 +11454,35 @@ async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items,
11541
11454
  ) : void 0;
11542
11455
  validated.push({ validatedProps, key });
11543
11456
  }
11544
- const uniqueKeys = [
11457
+ return validated;
11458
+ }
11459
+ function collectUniqueKeys(validated) {
11460
+ return [
11545
11461
  ...new Set(
11546
- validated.map((v) => v.key).filter((k) => k !== void 0)
11462
+ validated.map((entry) => entry.key).filter((key) => key !== void 0)
11547
11463
  )
11548
11464
  ];
11465
+ }
11466
+ async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
11467
+ if (items.length === 0) return [];
11468
+ const registration = getNodeRegistration(ctx.graph, kind);
11469
+ const nodeKind = registration.type;
11470
+ const constraint = resolveConstraint(ctx.graph, kind, constraintName);
11471
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
11472
+ const uniqueKeys = collectUniqueKeys(validated);
11549
11473
  const kindsToCheck = getKindsForUniquenessCheck(
11550
11474
  kind,
11551
11475
  constraint.scope,
11552
11476
  ctx.registry
11553
11477
  );
11554
- const existingByKey = /* @__PURE__ */ new Map();
11555
- if (uniqueKeys.length > 0) {
11556
- for (const kindToCheck of kindsToCheck) {
11557
- if (backend.checkUniqueBatch === void 0) {
11558
- for (const key of uniqueKeys) {
11559
- if (existingByKey.has(key)) continue;
11560
- const row = await backend.checkUnique({
11561
- graphId: ctx.graphId,
11562
- nodeKind: kindToCheck,
11563
- constraintName: constraint.name,
11564
- key,
11565
- includeDeleted: false
11566
- });
11567
- if (row !== void 0) {
11568
- existingByKey.set(row.key, row);
11569
- }
11570
- }
11571
- } else {
11572
- const rows = await backend.checkUniqueBatch({
11573
- graphId: ctx.graphId,
11574
- nodeKind: kindToCheck,
11575
- constraintName: constraint.name,
11576
- keys: uniqueKeys,
11577
- includeDeleted: false
11578
- });
11579
- for (const row of rows) {
11580
- if (!existingByKey.has(row.key)) {
11581
- existingByKey.set(row.key, row);
11582
- }
11583
- }
11584
- }
11585
- }
11586
- }
11478
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
11479
+ backend,
11480
+ ctx.graphId,
11481
+ constraint.name,
11482
+ uniqueKeys,
11483
+ kindsToCheck,
11484
+ false
11485
+ ) : /* @__PURE__ */ new Map();
11587
11486
  const results = Array.from({ length: items.length });
11588
11487
  const seenKeys = /* @__PURE__ */ new Map();
11589
11488
  for (const [index, { key }] of validated.entries()) {
@@ -11621,73 +11520,28 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
11621
11520
  const registration = getNodeRegistration(ctx.graph, kind);
11622
11521
  const nodeKind = registration.type;
11623
11522
  const constraint = resolveConstraint(ctx.graph, kind, constraintName);
11624
- const validated = [];
11625
- for (const item of items) {
11626
- const validatedProps = chunk7VITUTRA_cjs.validateNodeProps(nodeKind.schema, item.props, {
11627
- kind,
11628
- operation: "create"
11629
- });
11630
- const applies = checkWherePredicate(constraint, validatedProps);
11631
- const key = applies ? computeUniqueKey(
11632
- validatedProps,
11633
- constraint.fields,
11634
- constraint.collation
11635
- ) : void 0;
11636
- validated.push({ validatedProps, key });
11637
- }
11638
- const uniqueKeys = [
11639
- ...new Set(
11640
- validated.map((v) => v.key).filter((k) => k !== void 0)
11641
- )
11642
- ];
11523
+ const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
11524
+ const uniqueKeys = collectUniqueKeys(validated);
11643
11525
  const kindsToCheck = getKindsForUniquenessCheck(
11644
11526
  kind,
11645
11527
  constraint.scope,
11646
11528
  ctx.registry
11647
11529
  );
11648
- const existingByKey = /* @__PURE__ */ new Map();
11649
- if (uniqueKeys.length > 0) {
11650
- for (const kindToCheck of kindsToCheck) {
11651
- if (backend.checkUniqueBatch === void 0) {
11652
- for (const key of uniqueKeys) {
11653
- if (existingByKey.has(key)) continue;
11654
- const row = await backend.checkUnique({
11655
- graphId: ctx.graphId,
11656
- nodeKind: kindToCheck,
11657
- constraintName: constraint.name,
11658
- key,
11659
- includeDeleted: true
11660
- });
11661
- if (row !== void 0) {
11662
- existingByKey.set(row.key, row);
11663
- }
11664
- }
11665
- } else {
11666
- const rows = await backend.checkUniqueBatch({
11667
- graphId: ctx.graphId,
11668
- nodeKind: kindToCheck,
11669
- constraintName: constraint.name,
11670
- keys: uniqueKeys,
11671
- includeDeleted: true
11672
- });
11673
- for (const row of rows) {
11674
- if (!existingByKey.has(row.key)) {
11675
- existingByKey.set(row.key, row);
11676
- }
11677
- }
11678
- }
11679
- }
11680
- }
11530
+ const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
11531
+ backend,
11532
+ ctx.graphId,
11533
+ constraint.name,
11534
+ uniqueKeys,
11535
+ kindsToCheck,
11536
+ true
11537
+ ) : /* @__PURE__ */ new Map();
11681
11538
  const toCreate = [];
11682
11539
  const toFetch = [];
11683
11540
  const duplicateOf = [];
11684
11541
  const seenKeys = /* @__PURE__ */ new Map();
11685
11542
  for (const [index, { validatedProps, key }] of validated.entries()) {
11686
11543
  if (key === void 0) {
11687
- toCreate.push({
11688
- index,
11689
- input: { kind, props: validatedProps }
11690
- });
11544
+ toCreate.push({ index, input: { kind, props: validatedProps } });
11691
11545
  continue;
11692
11546
  }
11693
11547
  const previousIndex = seenKeys.get(key);
@@ -11698,10 +11552,7 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
11698
11552
  seenKeys.set(key, index);
11699
11553
  const existing = existingByKey.get(key);
11700
11554
  if (existing === void 0) {
11701
- toCreate.push({
11702
- index,
11703
- input: { kind, props: validatedProps }
11704
- });
11555
+ toCreate.push({ index, input: { kind, props: validatedProps } });
11705
11556
  } else {
11706
11557
  toFetch.push({
11707
11558
  index,
@@ -11735,8 +11586,11 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
11735
11586
  nodeId
11736
11587
  );
11737
11588
  if (existingRow === void 0) {
11738
- const input = { kind, props: validatedProps };
11739
- const node = await executeNodeCreate(ctx, input, backend);
11589
+ const node = await executeNodeCreate(
11590
+ ctx,
11591
+ { kind, props: validatedProps },
11592
+ backend
11593
+ );
11740
11594
  results[index] = { node, action: "created" };
11741
11595
  continue;
11742
11596
  }
@@ -12037,7 +11891,7 @@ var Store = class {
12037
11891
  graphId: this.graphId,
12038
11892
  rootId,
12039
11893
  backend: this.#backend,
12040
- dialect: chunk2WVFEIHR_cjs.getDialect(this.#backend.dialect),
11894
+ dialect: chunkMME3H4ZF_cjs.getDialect(this.#backend.dialect),
12041
11895
  schema: this.#schema,
12042
11896
  options
12043
11897
  });
@@ -12209,13 +12063,13 @@ function createStore(graph, backend, options) {
12209
12063
  }
12210
12064
  async function createStoreWithSchema(graph, backend, options) {
12211
12065
  const store = createStore(graph, backend, options);
12212
- const result = await chunk7VITUTRA_cjs.ensureSchema(backend, graph, options);
12066
+ const result = await chunkQFZ5QB2J_cjs.ensureSchema(backend, graph, options);
12213
12067
  return [store, result];
12214
12068
  }
12215
12069
 
12216
12070
  Object.defineProperty(exports, "isMetaEdge", {
12217
12071
  enumerable: true,
12218
- get: function () { return chunk7VITUTRA_cjs.isMetaEdge; }
12072
+ get: function () { return chunkQFZ5QB2J_cjs.isMetaEdge; }
12219
12073
  });
12220
12074
  Object.defineProperty(exports, "defineGraph", {
12221
12075
  enumerable: true,