@nicia-ai/typegraph 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/postgres/index.cjs +34 -28
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +5 -5
- package/dist/backend/postgres/index.d.ts +5 -5
- package/dist/backend/postgres/index.js +16 -10
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +14 -14
- package/dist/backend/sqlite/index.d.cts +5 -5
- package/dist/backend/sqlite/index.d.ts +5 -5
- package/dist/backend/sqlite/index.js +4 -4
- package/dist/backend/sqlite/local.cjs +7 -7
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +7 -7
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-7VITUTRA.cjs → chunk-3HQLOKS5.cjs} +163 -13
- package/dist/chunk-3HQLOKS5.cjs.map +1 -0
- package/dist/{chunk-NZMKJHE2.cjs → chunk-56RQFK7U.cjs} +22 -15
- package/dist/chunk-56RQFK7U.cjs.map +1 -0
- package/dist/{chunk-U3452TEU.js → chunk-6GWJH6AR.js} +15 -27
- package/dist/chunk-6GWJH6AR.js.map +1 -0
- package/dist/{chunk-2XPKLHHH.cjs → chunk-CRMN2NOM.cjs} +247 -208
- package/dist/chunk-CRMN2NOM.cjs.map +1 -0
- package/dist/{chunk-54WJF3DW.js → chunk-GNIYZKBI.js} +29 -3
- package/dist/chunk-GNIYZKBI.js.map +1 -0
- package/dist/{chunk-52WSY6G5.js → chunk-HWWF3FOP.js} +158 -119
- package/dist/chunk-HWWF3FOP.js.map +1 -0
- package/dist/{chunk-PYV4ADC6.js → chunk-L4ON6RJF.js} +164 -14
- package/dist/chunk-L4ON6RJF.js.map +1 -0
- package/dist/{chunk-JQDWEX6V.cjs → chunk-LELLOHJK.cjs} +22 -34
- package/dist/chunk-LELLOHJK.cjs.map +1 -0
- package/dist/{chunk-2WVFEIHR.cjs → chunk-MME3H4ZF.cjs} +40 -2
- package/dist/chunk-MME3H4ZF.cjs.map +1 -0
- package/dist/{chunk-J4SICP3X.js → chunk-XZBAGJJH.js} +15 -8
- package/dist/chunk-XZBAGJJH.js.map +1 -0
- package/dist/{ddl-BJg93HDN.d.cts → ddl-BBo2EcFc.d.cts} +2 -2
- package/dist/{ddl-CsfWcl_B.d.ts → ddl-D4jlcOH_.d.ts} +2 -2
- package/dist/index.cjs +473 -625
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -9
- package/dist/index.d.ts +12 -9
- package/dist/index.js +434 -586
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +16 -16
- package/dist/indexes/index.d.cts +2 -2
- package/dist/indexes/index.d.ts +2 -2
- package/dist/indexes/index.js +2 -2
- package/dist/interchange/index.d.cts +3 -3
- package/dist/interchange/index.d.ts +3 -3
- package/dist/{manager-DGSnJa1v.d.cts → manager-Bj1UEnhE.d.cts} +2 -2
- package/dist/{manager-BCLhWysp.d.ts → manager-Chhrq1vl.d.ts} +2 -2
- package/dist/profiler/index.cjs +6 -6
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +3 -3
- package/dist/profiler/index.d.ts +3 -3
- package/dist/profiler/index.js +6 -6
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +20 -20
- package/dist/schema/index.d.cts +4 -4
- package/dist/schema/index.d.ts +4 -4
- package/dist/schema/index.js +2 -2
- package/dist/{sqlite-H01wIXvB.d.ts → sqlite-Blq-AhmK.d.ts} +1 -1
- package/dist/{sqlite-DVca_IIy.d.cts → sqlite-DE-6NWtC.d.cts} +1 -1
- package/dist/{store-Bmdt_dS6.d.cts → store-BNercm8P.d.cts} +86 -31
- package/dist/{store-6-vH0ZIj.d.ts → store-CD_0yf2s.d.ts} +86 -31
- package/dist/{types-GLkwvQvS.d.cts → types-B3mmOMJV.d.cts} +20 -6
- package/dist/{types-C8Ra3ROE.d.cts → types-CZd2PEOc.d.cts} +8 -2
- package/dist/{types-CC8eB0PB.d.ts → types-Ceb01czq.d.ts} +8 -2
- package/dist/{types-1YJKodRv.d.ts → types-ThB4cFLp.d.ts} +20 -6
- package/package.json +1 -1
- package/dist/chunk-2WVFEIHR.cjs.map +0 -1
- package/dist/chunk-2XPKLHHH.cjs.map +0 -1
- package/dist/chunk-52WSY6G5.js.map +0 -1
- package/dist/chunk-54WJF3DW.js.map +0 -1
- package/dist/chunk-7VITUTRA.cjs.map +0 -1
- package/dist/chunk-J4SICP3X.js.map +0 -1
- package/dist/chunk-JQDWEX6V.cjs.map +0 -1
- package/dist/chunk-NZMKJHE2.cjs.map +0 -1
- package/dist/chunk-PYV4ADC6.js.map +0 -1
- 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
|
|
3
|
+
var chunk3HQLOKS5_cjs = require('./chunk-3HQLOKS5.cjs');
|
|
4
4
|
var chunkNI2GV74U_cjs = require('./chunk-NI2GV74U.cjs');
|
|
5
5
|
var chunk44SXEVF4_cjs = require('./chunk-44SXEVF4.cjs');
|
|
6
|
-
var
|
|
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
|
-
[
|
|
128
|
+
[chunk3HQLOKS5_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
|
-
[
|
|
164
|
+
[chunk3HQLOKS5_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(
|
|
176
|
+
var subClassOfMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
188
|
+
var broaderMetaEdge = createMetaEdge(chunk3HQLOKS5_cjs.META_EDGE_BROADER, {
|
|
148
189
|
transitive: true,
|
|
149
|
-
inverse:
|
|
190
|
+
inverse: chunk3HQLOKS5_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(
|
|
201
|
+
var narrowerMetaEdge = createMetaEdge(chunk3HQLOKS5_cjs.META_EDGE_NARROWER, {
|
|
161
202
|
transitive: true,
|
|
162
|
-
inverse:
|
|
203
|
+
inverse: chunk3HQLOKS5_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(
|
|
214
|
+
var relatedToMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
226
|
+
var equivalentToMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
239
|
+
var sameAsMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
252
|
+
var differentFromMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
264
|
+
var disjointWithMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
276
|
+
var partOfMetaEdge = createMetaEdge(chunk3HQLOKS5_cjs.META_EDGE_PART_OF, {
|
|
236
277
|
transitive: true,
|
|
237
|
-
inverse:
|
|
278
|
+
inverse: chunk3HQLOKS5_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(
|
|
289
|
+
var hasPartMetaEdge = createMetaEdge(chunk3HQLOKS5_cjs.META_EDGE_HAS_PART, {
|
|
249
290
|
transitive: true,
|
|
250
|
-
inverse:
|
|
291
|
+
inverse: chunk3HQLOKS5_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(
|
|
302
|
+
var inverseOfMetaEdge = createMetaEdge(chunk3HQLOKS5_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(
|
|
307
|
+
var impliesMetaEdge = createMetaEdge(chunk3HQLOKS5_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
|
|
1378
|
-
visit(
|
|
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
|
|
1384
|
-
visit(
|
|
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
|
-
|
|
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 =
|
|
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 >
|
|
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 ${
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
|
4304
|
-
const projected = matchFieldToProjection(
|
|
4285
|
+
for (const orderSpec of op.orderBy) {
|
|
4286
|
+
const projected = matchFieldToProjection(orderSpec.field, projection);
|
|
4305
4287
|
if (!projected) {
|
|
4306
|
-
const fieldDesc =
|
|
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(
|
|
4314
|
-
const nulls =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
|
5214
|
-
if (
|
|
5215
|
-
pathAliases.push(
|
|
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
|
|
5240
|
-
var
|
|
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,
|
|
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,
|
|
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 ??
|
|
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
|
|
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
|
|
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 =
|
|
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 ??
|
|
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
|
-
*
|
|
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 ?
|
|
8854
|
-
return new
|
|
8840
|
+
const closures = graph.ontology.length > 0 ? chunk3HQLOKS5_cjs.computeClosuresFromOntology(graph.ontology) : chunk3HQLOKS5_cjs.createEmptyClosures();
|
|
8841
|
+
return new chunk3HQLOKS5_cjs.KindRegistry(nodeTypes, edgeTypes, closures);
|
|
8855
8842
|
}
|
|
8856
8843
|
function extractNodeTypes(graph) {
|
|
8857
8844
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -9604,53 +9591,47 @@ function createNodeCollection(config) {
|
|
|
9604
9591
|
// src/store/collection-factory.ts
|
|
9605
9592
|
function createNodeCollectionsProxy(graph, graphId, registry, backend, operations) {
|
|
9606
9593
|
const collectionCache = /* @__PURE__ */ new Map();
|
|
9607
|
-
return new Proxy(
|
|
9608
|
-
{
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
if (!(kind in graph.nodes)) {
|
|
9612
|
-
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
|
|
9613
|
-
}
|
|
9614
|
-
const cached = collectionCache.get(kind);
|
|
9615
|
-
if (cached !== void 0) {
|
|
9616
|
-
return cached;
|
|
9617
|
-
}
|
|
9618
|
-
const collection = createNodeCollection({
|
|
9619
|
-
graphId,
|
|
9620
|
-
kind,
|
|
9621
|
-
backend,
|
|
9622
|
-
...operations
|
|
9623
|
-
});
|
|
9624
|
-
collectionCache.set(kind, collection);
|
|
9625
|
-
return collection;
|
|
9594
|
+
return new Proxy({}, {
|
|
9595
|
+
get: (_, kind) => {
|
|
9596
|
+
if (!(kind in graph.nodes)) {
|
|
9597
|
+
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
|
|
9626
9598
|
}
|
|
9599
|
+
const cached = collectionCache.get(kind);
|
|
9600
|
+
if (cached !== void 0) {
|
|
9601
|
+
return cached;
|
|
9602
|
+
}
|
|
9603
|
+
const collection = createNodeCollection({
|
|
9604
|
+
graphId,
|
|
9605
|
+
kind,
|
|
9606
|
+
backend,
|
|
9607
|
+
...operations
|
|
9608
|
+
});
|
|
9609
|
+
collectionCache.set(kind, collection);
|
|
9610
|
+
return collection;
|
|
9627
9611
|
}
|
|
9628
|
-
);
|
|
9612
|
+
});
|
|
9629
9613
|
}
|
|
9630
9614
|
function createEdgeCollectionsProxy(graph, graphId, registry, backend, operations) {
|
|
9631
9615
|
const collectionCache = /* @__PURE__ */ new Map();
|
|
9632
|
-
return new Proxy(
|
|
9633
|
-
{
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
if (!(kind in graph.edges)) {
|
|
9637
|
-
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "edge");
|
|
9638
|
-
}
|
|
9639
|
-
const cached = collectionCache.get(kind);
|
|
9640
|
-
if (cached !== void 0) {
|
|
9641
|
-
return cached;
|
|
9642
|
-
}
|
|
9643
|
-
const collection = createEdgeCollection({
|
|
9644
|
-
graphId,
|
|
9645
|
-
kind,
|
|
9646
|
-
backend,
|
|
9647
|
-
...operations
|
|
9648
|
-
});
|
|
9649
|
-
collectionCache.set(kind, collection);
|
|
9650
|
-
return collection;
|
|
9616
|
+
return new Proxy({}, {
|
|
9617
|
+
get: (_, kind) => {
|
|
9618
|
+
if (!(kind in graph.edges)) {
|
|
9619
|
+
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "edge");
|
|
9651
9620
|
}
|
|
9621
|
+
const cached = collectionCache.get(kind);
|
|
9622
|
+
if (cached !== void 0) {
|
|
9623
|
+
return cached;
|
|
9624
|
+
}
|
|
9625
|
+
const collection = createEdgeCollection({
|
|
9626
|
+
graphId,
|
|
9627
|
+
kind,
|
|
9628
|
+
backend,
|
|
9629
|
+
...operations
|
|
9630
|
+
});
|
|
9631
|
+
collectionCache.set(kind, collection);
|
|
9632
|
+
return collection;
|
|
9652
9633
|
}
|
|
9653
|
-
);
|
|
9634
|
+
});
|
|
9654
9635
|
}
|
|
9655
9636
|
|
|
9656
9637
|
// src/constraints/index.ts
|
|
@@ -10053,7 +10034,7 @@ async function validateAndPrepareEdgeCreate(ctx, input, id, backend) {
|
|
|
10053
10034
|
nodeId: input.toId
|
|
10054
10035
|
});
|
|
10055
10036
|
}
|
|
10056
|
-
const validatedProps =
|
|
10037
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateEdgeProps(edgeKind.schema, input.props, {
|
|
10057
10038
|
kind,
|
|
10058
10039
|
operation: "create"
|
|
10059
10040
|
});
|
|
@@ -10203,7 +10184,7 @@ async function executeEdgeUpdate(ctx, input, backend) {
|
|
|
10203
10184
|
const edgeKind = registration.type;
|
|
10204
10185
|
const existingProps = JSON.parse(existing.props);
|
|
10205
10186
|
const mergedProps = { ...existingProps, ...input.props };
|
|
10206
|
-
const validatedProps =
|
|
10187
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
|
|
10207
10188
|
kind: existing.kind,
|
|
10208
10189
|
operation: "update",
|
|
10209
10190
|
id
|
|
@@ -10229,7 +10210,7 @@ async function executeEdgeUpsertUpdate(ctx, input, backend, options) {
|
|
|
10229
10210
|
const edgeKind = registration.type;
|
|
10230
10211
|
const existingProps = JSON.parse(existing.props);
|
|
10231
10212
|
const mergedProps = { ...existingProps, ...input.props };
|
|
10232
|
-
const validatedProps =
|
|
10213
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
|
|
10233
10214
|
kind: existing.kind,
|
|
10234
10215
|
operation: "update",
|
|
10235
10216
|
id
|
|
@@ -10386,7 +10367,7 @@ async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, to
|
|
|
10386
10367
|
const matchOn = options?.matchOn ?? [];
|
|
10387
10368
|
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
10388
10369
|
const edgeKind = registration.type;
|
|
10389
|
-
const validatedProps =
|
|
10370
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateEdgeProps(edgeKind.schema, props, {
|
|
10390
10371
|
kind,
|
|
10391
10372
|
operation: "create"
|
|
10392
10373
|
});
|
|
@@ -10430,6 +10411,9 @@ async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, to
|
|
|
10430
10411
|
return { edge: edge2, action: "updated" };
|
|
10431
10412
|
}
|
|
10432
10413
|
const cardinality = registration.cardinality ?? "many";
|
|
10414
|
+
if (deletedRow === void 0) {
|
|
10415
|
+
throw new Error("Expected deletedRow to be defined");
|
|
10416
|
+
}
|
|
10433
10417
|
const matchedDeletedRow = deletedRow;
|
|
10434
10418
|
const effectiveValidTo = matchedDeletedRow.valid_to;
|
|
10435
10419
|
const constraintContext = {
|
|
@@ -10465,7 +10449,7 @@ async function executeEdgeBulkGetOrCreateByEndpoints(ctx, kind, items, backend,
|
|
|
10465
10449
|
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
10466
10450
|
const validated = [];
|
|
10467
10451
|
for (const item of items) {
|
|
10468
|
-
const validatedProps =
|
|
10452
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateEdgeProps(edgeKind.schema, item.props, {
|
|
10469
10453
|
kind,
|
|
10470
10454
|
operation: "create"
|
|
10471
10455
|
});
|
|
@@ -10549,6 +10533,9 @@ async function executeEdgeBulkGetOrCreateByEndpoints(ctx, kind, items, backend,
|
|
|
10549
10533
|
});
|
|
10550
10534
|
} else {
|
|
10551
10535
|
const bestRow = liveRow ?? deletedRow;
|
|
10536
|
+
if (bestRow === void 0) {
|
|
10537
|
+
throw new Error("Expected at least one of liveRow or deletedRow");
|
|
10538
|
+
}
|
|
10552
10539
|
toFetch.push({
|
|
10553
10540
|
index,
|
|
10554
10541
|
row: bestRow,
|
|
@@ -10849,11 +10836,12 @@ function getNodeRegistration(graph, kind) {
|
|
|
10849
10836
|
if (registration === void 0) throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
|
|
10850
10837
|
return registration;
|
|
10851
10838
|
}
|
|
10839
|
+
var CACHE_KEY_SEPARATOR = "\0";
|
|
10852
10840
|
function buildNodeCacheKey(graphId, kind, id) {
|
|
10853
|
-
return `${graphId}
|
|
10841
|
+
return `${graphId}${CACHE_KEY_SEPARATOR}${kind}${CACHE_KEY_SEPARATOR}${id}`;
|
|
10854
10842
|
}
|
|
10855
10843
|
function buildUniqueCacheKey(graphId, nodeKind, constraintName, key) {
|
|
10856
|
-
return `${graphId}
|
|
10844
|
+
return `${graphId}${CACHE_KEY_SEPARATOR}${nodeKind}${CACHE_KEY_SEPARATOR}${constraintName}${CACHE_KEY_SEPARATOR}${key}`;
|
|
10857
10845
|
}
|
|
10858
10846
|
function createNodeAlreadyExistsError(kind, id) {
|
|
10859
10847
|
return new chunk44SXEVF4_cjs.ValidationError(
|
|
@@ -10890,6 +10878,23 @@ function createPendingUniqueRow(graphId, nodeKind, constraintName, key, nodeId)
|
|
|
10890
10878
|
deleted_at: void 0
|
|
10891
10879
|
};
|
|
10892
10880
|
}
|
|
10881
|
+
function resolveConstraint(graph, kind, constraintName) {
|
|
10882
|
+
const registration = getNodeRegistration(graph, kind);
|
|
10883
|
+
const constraints = registration.unique ?? [];
|
|
10884
|
+
const constraint = constraints.find(
|
|
10885
|
+
(candidate) => candidate.name === constraintName
|
|
10886
|
+
);
|
|
10887
|
+
if (constraint === void 0) {
|
|
10888
|
+
throw new chunk44SXEVF4_cjs.NodeConstraintNotFoundError(constraintName, kind);
|
|
10889
|
+
}
|
|
10890
|
+
return constraint;
|
|
10891
|
+
}
|
|
10892
|
+
function createUniquenessContext(graphId, registry, backend) {
|
|
10893
|
+
return { graphId, registry, backend };
|
|
10894
|
+
}
|
|
10895
|
+
function createEmbeddingSyncContext(graphId, nodeKind, nodeId, backend) {
|
|
10896
|
+
return { graphId, nodeKind, nodeId, backend };
|
|
10897
|
+
}
|
|
10893
10898
|
function createNodeBatchValidationBackend(graphId, registry, backend) {
|
|
10894
10899
|
const nodeCache = /* @__PURE__ */ new Map();
|
|
10895
10900
|
const pendingNodes = /* @__PURE__ */ new Map();
|
|
@@ -10898,12 +10903,8 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
|
|
|
10898
10903
|
async function getNodeCached(lookupGraphId, kind, id) {
|
|
10899
10904
|
const cacheKey = buildNodeCacheKey(lookupGraphId, kind, id);
|
|
10900
10905
|
const pendingNode = pendingNodes.get(cacheKey);
|
|
10901
|
-
if (pendingNode !== void 0)
|
|
10902
|
-
|
|
10903
|
-
}
|
|
10904
|
-
if (nodeCache.has(cacheKey)) {
|
|
10905
|
-
return nodeCache.get(cacheKey);
|
|
10906
|
-
}
|
|
10906
|
+
if (pendingNode !== void 0) return pendingNode;
|
|
10907
|
+
if (nodeCache.has(cacheKey)) return nodeCache.get(cacheKey);
|
|
10907
10908
|
const existing = await backend.getNode(lookupGraphId, kind, id);
|
|
10908
10909
|
nodeCache.set(cacheKey, existing);
|
|
10909
10910
|
return existing;
|
|
@@ -10925,16 +10926,14 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
|
|
|
10925
10926
|
pendingOwner
|
|
10926
10927
|
);
|
|
10927
10928
|
}
|
|
10928
|
-
if (uniqueCache.has(cacheKey))
|
|
10929
|
-
return uniqueCache.get(cacheKey);
|
|
10930
|
-
}
|
|
10929
|
+
if (uniqueCache.has(cacheKey)) return uniqueCache.get(cacheKey);
|
|
10931
10930
|
const existing = await backend.checkUnique(params);
|
|
10932
10931
|
uniqueCache.set(cacheKey, existing);
|
|
10933
10932
|
return existing;
|
|
10934
10933
|
}
|
|
10935
10934
|
function registerPendingNode(params) {
|
|
10936
10935
|
const cacheKey = buildNodeCacheKey(params.graphId, params.kind, params.id);
|
|
10937
|
-
|
|
10936
|
+
pendingNodes.set(cacheKey, {
|
|
10938
10937
|
graph_id: params.graphId,
|
|
10939
10938
|
kind: params.kind,
|
|
10940
10939
|
id: params.id,
|
|
@@ -10945,14 +10944,11 @@ function createNodeBatchValidationBackend(graphId, registry, backend) {
|
|
|
10945
10944
|
created_at: "",
|
|
10946
10945
|
updated_at: "",
|
|
10947
10946
|
deleted_at: void 0
|
|
10948
|
-
};
|
|
10949
|
-
pendingNodes.set(cacheKey, pendingNode);
|
|
10947
|
+
});
|
|
10950
10948
|
}
|
|
10951
10949
|
function registerPendingUniqueEntries(kind, id, props, constraints) {
|
|
10952
10950
|
for (const constraint of constraints) {
|
|
10953
|
-
if (!checkWherePredicate(constraint, props))
|
|
10954
|
-
continue;
|
|
10955
|
-
}
|
|
10951
|
+
if (!checkWherePredicate(constraint, props)) continue;
|
|
10956
10952
|
const key = computeUniqueKey(
|
|
10957
10953
|
props,
|
|
10958
10954
|
constraint.fields,
|
|
@@ -10998,7 +10994,7 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
|
|
|
10998
10994
|
const kind = input.kind;
|
|
10999
10995
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11000
10996
|
const nodeKind = registration.type;
|
|
11001
|
-
const validatedProps =
|
|
10997
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateNodeProps(nodeKind.schema, input.props, {
|
|
11002
10998
|
kind,
|
|
11003
10999
|
operation: "create"
|
|
11004
11000
|
});
|
|
@@ -11014,14 +11010,9 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
|
|
|
11014
11010
|
backend
|
|
11015
11011
|
};
|
|
11016
11012
|
await checkDisjointnessConstraint(constraintContext, kind, id);
|
|
11017
|
-
const uniquenessContext = {
|
|
11018
|
-
graphId: ctx.graphId,
|
|
11019
|
-
registry: ctx.registry,
|
|
11020
|
-
backend
|
|
11021
|
-
};
|
|
11022
11013
|
const uniqueConstraints = registration.unique ?? [];
|
|
11023
11014
|
await checkUniquenessConstraints(
|
|
11024
|
-
|
|
11015
|
+
createUniquenessContext(ctx.graphId, ctx.registry, backend),
|
|
11025
11016
|
kind,
|
|
11026
11017
|
id,
|
|
11027
11018
|
validatedProps,
|
|
@@ -11044,77 +11035,112 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
|
|
|
11044
11035
|
};
|
|
11045
11036
|
}
|
|
11046
11037
|
async function finalizeNodeCreate(ctx, prepared, backend) {
|
|
11047
|
-
const uniquenessContext = {
|
|
11048
|
-
graphId: ctx.graphId,
|
|
11049
|
-
registry: ctx.registry,
|
|
11050
|
-
backend
|
|
11051
|
-
};
|
|
11052
11038
|
await insertUniquenessEntries(
|
|
11053
|
-
|
|
11039
|
+
createUniquenessContext(ctx.graphId, ctx.registry, backend),
|
|
11054
11040
|
prepared.kind,
|
|
11055
11041
|
prepared.id,
|
|
11056
11042
|
prepared.validatedProps,
|
|
11057
11043
|
prepared.uniqueConstraints
|
|
11058
11044
|
);
|
|
11059
|
-
const embeddingSyncContext = {
|
|
11060
|
-
graphId: ctx.graphId,
|
|
11061
|
-
nodeKind: prepared.kind,
|
|
11062
|
-
nodeId: prepared.id,
|
|
11063
|
-
backend
|
|
11064
|
-
};
|
|
11065
11045
|
await syncEmbeddings(
|
|
11066
|
-
|
|
11046
|
+
createEmbeddingSyncContext(
|
|
11047
|
+
ctx.graphId,
|
|
11048
|
+
prepared.kind,
|
|
11049
|
+
prepared.id,
|
|
11050
|
+
backend
|
|
11051
|
+
),
|
|
11067
11052
|
prepared.nodeKind.schema,
|
|
11068
11053
|
prepared.validatedProps
|
|
11069
11054
|
);
|
|
11070
11055
|
}
|
|
11071
|
-
async function
|
|
11072
|
-
const kind = input
|
|
11073
|
-
const
|
|
11074
|
-
const
|
|
11075
|
-
|
|
11056
|
+
async function performNodeUpdate(ctx, input, backend, options) {
|
|
11057
|
+
const { kind, id } = input;
|
|
11058
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11059
|
+
const existing = await backend.getNode(ctx.graphId, kind, id);
|
|
11060
|
+
if (!existing || existing.deleted_at && !options?.clearDeleted) {
|
|
11061
|
+
throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
|
|
11062
|
+
}
|
|
11063
|
+
const existingProps = JSON.parse(existing.props);
|
|
11064
|
+
const mergedProps = { ...existingProps, ...input.props };
|
|
11065
|
+
const nodeKind = registration.type;
|
|
11066
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
|
|
11067
|
+
kind,
|
|
11068
|
+
operation: "update",
|
|
11069
|
+
id
|
|
11070
|
+
});
|
|
11071
|
+
const validTo = chunkNI2GV74U_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
11072
|
+
await updateUniquenessEntries(
|
|
11073
|
+
createUniquenessContext(ctx.graphId, ctx.registry, backend),
|
|
11074
|
+
kind,
|
|
11075
|
+
id,
|
|
11076
|
+
existingProps,
|
|
11077
|
+
validatedProps,
|
|
11078
|
+
registration.unique ?? []
|
|
11079
|
+
);
|
|
11080
|
+
const updateParams = {
|
|
11081
|
+
graphId: ctx.graphId,
|
|
11082
|
+
kind,
|
|
11083
|
+
id,
|
|
11084
|
+
props: validatedProps,
|
|
11085
|
+
incrementVersion: true
|
|
11086
|
+
};
|
|
11087
|
+
if (validTo !== void 0) updateParams.validTo = validTo;
|
|
11088
|
+
if (options?.clearDeleted) updateParams.clearDeleted = true;
|
|
11089
|
+
const row = await backend.updateNode(updateParams);
|
|
11090
|
+
await syncEmbeddings(
|
|
11091
|
+
createEmbeddingSyncContext(ctx.graphId, kind, id, backend),
|
|
11092
|
+
nodeKind.schema,
|
|
11093
|
+
validatedProps
|
|
11094
|
+
);
|
|
11095
|
+
return rowToNode(row);
|
|
11096
|
+
}
|
|
11097
|
+
async function enforceDeleteBehavior(ctx, kind, id, mode, backend, registration) {
|
|
11098
|
+
const deleteBehavior = registration.onDelete ?? "restrict";
|
|
11099
|
+
const connectedEdges = await backend.findEdgesConnectedTo({
|
|
11100
|
+
graphId: ctx.graphId,
|
|
11101
|
+
nodeKind: kind,
|
|
11102
|
+
nodeId: id
|
|
11103
|
+
});
|
|
11104
|
+
if (connectedEdges.length === 0) return;
|
|
11105
|
+
switch (deleteBehavior) {
|
|
11106
|
+
case "restrict": {
|
|
11107
|
+
const edgeKinds = [...new Set(connectedEdges.map((edge) => edge.kind))];
|
|
11108
|
+
throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
|
|
11109
|
+
nodeKind: kind,
|
|
11110
|
+
nodeId: id,
|
|
11111
|
+
edgeCount: connectedEdges.length,
|
|
11112
|
+
edgeKinds
|
|
11113
|
+
});
|
|
11114
|
+
}
|
|
11115
|
+
case "cascade":
|
|
11116
|
+
case "disconnect": {
|
|
11117
|
+
for (const edge of connectedEdges) {
|
|
11118
|
+
await (mode === "hard" ? backend.hardDeleteEdge({
|
|
11119
|
+
graphId: ctx.graphId,
|
|
11120
|
+
id: edge.id
|
|
11121
|
+
}) : backend.deleteEdge({
|
|
11122
|
+
graphId: ctx.graphId,
|
|
11123
|
+
id: edge.id
|
|
11124
|
+
}));
|
|
11125
|
+
}
|
|
11126
|
+
break;
|
|
11127
|
+
}
|
|
11128
|
+
}
|
|
11129
|
+
}
|
|
11130
|
+
async function prepareBatchCreates(ctx, inputs, backend) {
|
|
11131
|
+
const {
|
|
11132
|
+
backend: validationBackend,
|
|
11133
|
+
registerPendingNode,
|
|
11134
|
+
registerPendingUniqueEntries
|
|
11135
|
+
} = createNodeBatchValidationBackend(ctx.graphId, ctx.registry, backend);
|
|
11136
|
+
const preparedCreates = [];
|
|
11137
|
+
for (const input of inputs) {
|
|
11138
|
+
const id = input.id ?? generateId();
|
|
11076
11139
|
const prepared = await validateAndPrepareNodeCreate(
|
|
11077
11140
|
ctx,
|
|
11078
11141
|
input,
|
|
11079
11142
|
id,
|
|
11080
|
-
|
|
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);
|
|
11089
|
-
});
|
|
11090
|
-
}
|
|
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
|
-
);
|
|
11098
|
-
}
|
|
11099
|
-
return result;
|
|
11100
|
-
}
|
|
11101
|
-
async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
|
|
11102
|
-
if (inputs.length === 0) {
|
|
11103
|
-
return;
|
|
11104
|
-
}
|
|
11105
|
-
const {
|
|
11106
|
-
backend: validationBackend,
|
|
11107
|
-
registerPendingNode,
|
|
11108
|
-
registerPendingUniqueEntries
|
|
11109
|
-
} = createNodeBatchValidationBackend(ctx.graphId, ctx.registry, backend);
|
|
11110
|
-
const preparedCreates = [];
|
|
11111
|
-
for (const input of inputs) {
|
|
11112
|
-
const id = input.id ?? generateId();
|
|
11113
|
-
const prepared = await validateAndPrepareNodeCreate(
|
|
11114
|
-
ctx,
|
|
11115
|
-
input,
|
|
11116
|
-
id,
|
|
11117
|
-
validationBackend
|
|
11143
|
+
validationBackend
|
|
11118
11144
|
);
|
|
11119
11145
|
preparedCreates.push(prepared);
|
|
11120
11146
|
registerPendingNode(prepared.insertParams);
|
|
@@ -11128,6 +11154,92 @@ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
|
|
|
11128
11154
|
const batchInsertParams = preparedCreates.map(
|
|
11129
11155
|
(prepared) => prepared.insertParams
|
|
11130
11156
|
);
|
|
11157
|
+
return { preparedCreates, batchInsertParams };
|
|
11158
|
+
}
|
|
11159
|
+
async function findUniqueRowAcrossKinds(backend, graphId, constraintName, key, kindsToCheck, includeDeleted) {
|
|
11160
|
+
for (const kindToCheck of kindsToCheck) {
|
|
11161
|
+
const row = await backend.checkUnique({
|
|
11162
|
+
graphId,
|
|
11163
|
+
nodeKind: kindToCheck,
|
|
11164
|
+
constraintName,
|
|
11165
|
+
key,
|
|
11166
|
+
includeDeleted
|
|
11167
|
+
});
|
|
11168
|
+
if (row !== void 0) return row;
|
|
11169
|
+
}
|
|
11170
|
+
return void 0;
|
|
11171
|
+
}
|
|
11172
|
+
async function batchCheckUniqueAcrossKinds(backend, graphId, constraintName, uniqueKeys, kindsToCheck, includeDeleted) {
|
|
11173
|
+
const existingByKey = /* @__PURE__ */ new Map();
|
|
11174
|
+
for (const kindToCheck of kindsToCheck) {
|
|
11175
|
+
if (backend.checkUniqueBatch === void 0) {
|
|
11176
|
+
for (const key of uniqueKeys) {
|
|
11177
|
+
if (existingByKey.has(key)) continue;
|
|
11178
|
+
const row = await backend.checkUnique({
|
|
11179
|
+
graphId,
|
|
11180
|
+
nodeKind: kindToCheck,
|
|
11181
|
+
constraintName,
|
|
11182
|
+
key,
|
|
11183
|
+
includeDeleted
|
|
11184
|
+
});
|
|
11185
|
+
if (row !== void 0) {
|
|
11186
|
+
existingByKey.set(row.key, row);
|
|
11187
|
+
}
|
|
11188
|
+
}
|
|
11189
|
+
} else {
|
|
11190
|
+
const rows = await backend.checkUniqueBatch({
|
|
11191
|
+
graphId,
|
|
11192
|
+
nodeKind: kindToCheck,
|
|
11193
|
+
constraintName,
|
|
11194
|
+
keys: uniqueKeys,
|
|
11195
|
+
includeDeleted
|
|
11196
|
+
});
|
|
11197
|
+
for (const row of rows) {
|
|
11198
|
+
if (!existingByKey.has(row.key)) {
|
|
11199
|
+
existingByKey.set(row.key, row);
|
|
11200
|
+
}
|
|
11201
|
+
}
|
|
11202
|
+
}
|
|
11203
|
+
}
|
|
11204
|
+
return existingByKey;
|
|
11205
|
+
}
|
|
11206
|
+
async function executeNodeCreateInternal(ctx, input, backend, options) {
|
|
11207
|
+
const kind = input.kind;
|
|
11208
|
+
const id = input.id ?? generateId();
|
|
11209
|
+
const opContext = ctx.createOperationContext("create", "node", kind, id);
|
|
11210
|
+
return ctx.withOperationHooks(opContext, async () => {
|
|
11211
|
+
const prepared = await validateAndPrepareNodeCreate(
|
|
11212
|
+
ctx,
|
|
11213
|
+
input,
|
|
11214
|
+
id,
|
|
11215
|
+
backend
|
|
11216
|
+
);
|
|
11217
|
+
let row;
|
|
11218
|
+
{
|
|
11219
|
+
row = await backend.insertNode(prepared.insertParams);
|
|
11220
|
+
}
|
|
11221
|
+
await finalizeNodeCreate(ctx, prepared, backend);
|
|
11222
|
+
if (row === void 0) return;
|
|
11223
|
+
return rowToNode(row);
|
|
11224
|
+
});
|
|
11225
|
+
}
|
|
11226
|
+
async function executeNodeCreate(ctx, input, backend) {
|
|
11227
|
+
const result = await executeNodeCreateInternal(ctx, input, backend);
|
|
11228
|
+
if (!result) {
|
|
11229
|
+
throw new chunk44SXEVF4_cjs.DatabaseOperationError(
|
|
11230
|
+
"Node create failed: expected created node row",
|
|
11231
|
+
{ operation: "insert", entity: "node" }
|
|
11232
|
+
);
|
|
11233
|
+
}
|
|
11234
|
+
return result;
|
|
11235
|
+
}
|
|
11236
|
+
async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
|
|
11237
|
+
if (inputs.length === 0) return;
|
|
11238
|
+
const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
|
|
11239
|
+
ctx,
|
|
11240
|
+
inputs,
|
|
11241
|
+
backend
|
|
11242
|
+
);
|
|
11131
11243
|
if (backend.insertNodesBatch === void 0) {
|
|
11132
11244
|
for (const insertParams of batchInsertParams) {
|
|
11133
11245
|
await (backend.insertNodeNoReturn?.(insertParams) ?? backend.insertNode(insertParams));
|
|
@@ -11140,34 +11252,11 @@ async function executeNodeCreateNoReturnBatch(ctx, inputs, backend) {
|
|
|
11140
11252
|
}
|
|
11141
11253
|
}
|
|
11142
11254
|
async function executeNodeCreateBatch(ctx, inputs, backend) {
|
|
11143
|
-
if (inputs.length === 0)
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
backend
|
|
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,
|
|
11157
|
-
id,
|
|
11158
|
-
validationBackend
|
|
11159
|
-
);
|
|
11160
|
-
preparedCreates.push(prepared);
|
|
11161
|
-
registerPendingNode(prepared.insertParams);
|
|
11162
|
-
registerPendingUniqueEntries(
|
|
11163
|
-
prepared.kind,
|
|
11164
|
-
prepared.id,
|
|
11165
|
-
prepared.validatedProps,
|
|
11166
|
-
prepared.uniqueConstraints
|
|
11167
|
-
);
|
|
11168
|
-
}
|
|
11169
|
-
const batchInsertParams = preparedCreates.map(
|
|
11170
|
-
(prepared) => prepared.insertParams
|
|
11255
|
+
if (inputs.length === 0) return [];
|
|
11256
|
+
const { preparedCreates, batchInsertParams } = await prepareBatchCreates(
|
|
11257
|
+
ctx,
|
|
11258
|
+
inputs,
|
|
11259
|
+
backend
|
|
11171
11260
|
);
|
|
11172
11261
|
let rows;
|
|
11173
11262
|
if (backend.insertNodesBatchReturning === void 0) {
|
|
@@ -11185,170 +11274,40 @@ async function executeNodeCreateBatch(ctx, inputs, backend) {
|
|
|
11185
11274
|
return rows.map((row) => rowToNode(row));
|
|
11186
11275
|
}
|
|
11187
11276
|
async function executeNodeUpdate(ctx, input, backend, options) {
|
|
11188
|
-
const
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
|
|
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
|
-
});
|
|
11277
|
+
const opContext = ctx.createOperationContext(
|
|
11278
|
+
"update",
|
|
11279
|
+
"node",
|
|
11280
|
+
input.kind,
|
|
11281
|
+
input.id
|
|
11282
|
+
);
|
|
11283
|
+
return ctx.withOperationHooks(
|
|
11284
|
+
opContext,
|
|
11285
|
+
() => performNodeUpdate(ctx, input, backend, options)
|
|
11286
|
+
);
|
|
11238
11287
|
}
|
|
11239
11288
|
async function executeNodeUpsertUpdate(ctx, input, backend, options) {
|
|
11240
|
-
|
|
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);
|
|
11289
|
+
return performNodeUpdate(ctx, input, backend, options);
|
|
11287
11290
|
}
|
|
11288
11291
|
async function executeNodeDelete(ctx, kind, id, backend) {
|
|
11289
11292
|
const opContext = ctx.createOperationContext("delete", "node", kind, id);
|
|
11290
11293
|
return ctx.withOperationHooks(opContext, async () => {
|
|
11291
11294
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11292
11295
|
const existing = await backend.getNode(ctx.graphId, kind, id);
|
|
11293
|
-
if (!existing || existing.deleted_at)
|
|
11294
|
-
return;
|
|
11295
|
-
}
|
|
11296
|
+
if (!existing || existing.deleted_at) return;
|
|
11296
11297
|
const existingProps = JSON.parse(existing.props);
|
|
11297
|
-
|
|
11298
|
-
|
|
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
|
-
};
|
|
11298
|
+
await enforceDeleteBehavior(ctx, kind, id, "soft", backend, registration);
|
|
11299
|
+
await backend.deleteNode({ graphId: ctx.graphId, kind, id });
|
|
11338
11300
|
await deleteUniquenessEntries(
|
|
11339
|
-
|
|
11301
|
+
createUniquenessContext(ctx.graphId, ctx.registry, backend),
|
|
11340
11302
|
kind,
|
|
11341
11303
|
existingProps,
|
|
11342
11304
|
registration.unique ?? []
|
|
11343
11305
|
);
|
|
11344
11306
|
const nodeKind = registration.type;
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
nodeKind
|
|
11348
|
-
|
|
11349
|
-
backend
|
|
11350
|
-
};
|
|
11351
|
-
await deleteNodeEmbeddings(embeddingSyncContext, nodeKind.schema);
|
|
11307
|
+
await deleteNodeEmbeddings(
|
|
11308
|
+
createEmbeddingSyncContext(ctx.graphId, kind, id, backend),
|
|
11309
|
+
nodeKind.schema
|
|
11310
|
+
);
|
|
11352
11311
|
});
|
|
11353
11312
|
}
|
|
11354
11313
|
async function executeNodeHardDelete(ctx, kind, id, backend) {
|
|
@@ -11356,71 +11315,29 @@ async function executeNodeHardDelete(ctx, kind, id, backend) {
|
|
|
11356
11315
|
return ctx.withOperationHooks(opContext, async () => {
|
|
11357
11316
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11358
11317
|
const existing = await backend.getNode(ctx.graphId, kind, id);
|
|
11359
|
-
if (!existing)
|
|
11360
|
-
|
|
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
|
-
}
|
|
11318
|
+
if (!existing) return;
|
|
11319
|
+
await enforceDeleteBehavior(ctx, kind, id, "hard", backend, registration);
|
|
11393
11320
|
const hardDelete = async (target) => {
|
|
11394
|
-
await target.hardDeleteNode({
|
|
11395
|
-
graphId: ctx.graphId,
|
|
11396
|
-
kind,
|
|
11397
|
-
id
|
|
11398
|
-
});
|
|
11321
|
+
await target.hardDeleteNode({ graphId: ctx.graphId, kind, id });
|
|
11399
11322
|
};
|
|
11400
11323
|
await ("transaction" in backend && backend.capabilities.transactions ? backend.transaction(async (tx) => hardDelete(tx)) : hardDelete(backend));
|
|
11401
11324
|
});
|
|
11402
11325
|
}
|
|
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
11326
|
async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, props, backend, options) {
|
|
11413
11327
|
const ifExists = options?.ifExists ?? "return";
|
|
11414
11328
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11415
11329
|
const nodeKind = registration.type;
|
|
11416
|
-
const validatedProps =
|
|
11330
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
11417
11331
|
kind,
|
|
11418
11332
|
operation: "create"
|
|
11419
11333
|
});
|
|
11420
11334
|
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
11421
11335
|
if (!checkWherePredicate(constraint, validatedProps)) {
|
|
11422
|
-
const
|
|
11423
|
-
|
|
11336
|
+
const node = await executeNodeCreate(
|
|
11337
|
+
ctx,
|
|
11338
|
+
{ kind, props: validatedProps },
|
|
11339
|
+
backend
|
|
11340
|
+
);
|
|
11424
11341
|
return { node, action: "created" };
|
|
11425
11342
|
}
|
|
11426
11343
|
const key = computeUniqueKey(
|
|
@@ -11433,23 +11350,20 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
|
|
|
11433
11350
|
constraint.scope,
|
|
11434
11351
|
ctx.registry
|
|
11435
11352
|
);
|
|
11436
|
-
|
|
11437
|
-
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
});
|
|
11445
|
-
if (row !== void 0) {
|
|
11446
|
-
existingUniqueRow = row;
|
|
11447
|
-
break;
|
|
11448
|
-
}
|
|
11449
|
-
}
|
|
11353
|
+
const existingUniqueRow = await findUniqueRowAcrossKinds(
|
|
11354
|
+
backend,
|
|
11355
|
+
ctx.graphId,
|
|
11356
|
+
constraint.name,
|
|
11357
|
+
key,
|
|
11358
|
+
kindsToCheck,
|
|
11359
|
+
true
|
|
11360
|
+
);
|
|
11450
11361
|
if (existingUniqueRow === void 0) {
|
|
11451
|
-
const
|
|
11452
|
-
|
|
11362
|
+
const node = await executeNodeCreate(
|
|
11363
|
+
ctx,
|
|
11364
|
+
{ kind, props: validatedProps },
|
|
11365
|
+
backend
|
|
11366
|
+
);
|
|
11453
11367
|
return { node, action: "created" };
|
|
11454
11368
|
}
|
|
11455
11369
|
const existingRow = await backend.getNode(
|
|
@@ -11458,8 +11372,11 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
|
|
|
11458
11372
|
existingUniqueRow.node_id
|
|
11459
11373
|
);
|
|
11460
11374
|
if (existingRow === void 0) {
|
|
11461
|
-
const
|
|
11462
|
-
|
|
11375
|
+
const node = await executeNodeCreate(
|
|
11376
|
+
ctx,
|
|
11377
|
+
{ kind, props: validatedProps },
|
|
11378
|
+
backend
|
|
11379
|
+
);
|
|
11463
11380
|
return { node, action: "created" };
|
|
11464
11381
|
}
|
|
11465
11382
|
const isSoftDeleted = existingRow.deleted_at !== void 0;
|
|
@@ -11482,7 +11399,7 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
|
|
|
11482
11399
|
async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
|
|
11483
11400
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11484
11401
|
const nodeKind = registration.type;
|
|
11485
|
-
const validatedProps =
|
|
11402
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
11486
11403
|
kind,
|
|
11487
11404
|
operation: "create"
|
|
11488
11405
|
});
|
|
@@ -11498,20 +11415,14 @@ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, bac
|
|
|
11498
11415
|
constraint.scope,
|
|
11499
11416
|
ctx.registry
|
|
11500
11417
|
);
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
});
|
|
11510
|
-
if (row !== void 0) {
|
|
11511
|
-
existingUniqueRow = row;
|
|
11512
|
-
break;
|
|
11513
|
-
}
|
|
11514
|
-
}
|
|
11418
|
+
const existingUniqueRow = await findUniqueRowAcrossKinds(
|
|
11419
|
+
backend,
|
|
11420
|
+
ctx.graphId,
|
|
11421
|
+
constraint.name,
|
|
11422
|
+
key,
|
|
11423
|
+
kindsToCheck,
|
|
11424
|
+
false
|
|
11425
|
+
);
|
|
11515
11426
|
if (existingUniqueRow === void 0) return void 0;
|
|
11516
11427
|
const existingRow = await backend.getNode(
|
|
11517
11428
|
ctx.graphId,
|
|
@@ -11522,14 +11433,10 @@ async function executeNodeFindByConstraint(ctx, kind, constraintName, props, bac
|
|
|
11522
11433
|
return void 0;
|
|
11523
11434
|
return rowToNode(existingRow);
|
|
11524
11435
|
}
|
|
11525
|
-
|
|
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);
|
|
11436
|
+
function validateAndComputeKeys(nodeKind, kind, constraint, items) {
|
|
11530
11437
|
const validated = [];
|
|
11531
11438
|
for (const item of items) {
|
|
11532
|
-
const validatedProps =
|
|
11439
|
+
const validatedProps = chunk3HQLOKS5_cjs.validateNodeProps(nodeKind.schema, item.props, {
|
|
11533
11440
|
kind,
|
|
11534
11441
|
operation: "create"
|
|
11535
11442
|
});
|
|
@@ -11541,49 +11448,35 @@ async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items,
|
|
|
11541
11448
|
) : void 0;
|
|
11542
11449
|
validated.push({ validatedProps, key });
|
|
11543
11450
|
}
|
|
11544
|
-
|
|
11451
|
+
return validated;
|
|
11452
|
+
}
|
|
11453
|
+
function collectUniqueKeys(validated) {
|
|
11454
|
+
return [
|
|
11545
11455
|
...new Set(
|
|
11546
|
-
validated.map((
|
|
11456
|
+
validated.map((entry) => entry.key).filter((key) => key !== void 0)
|
|
11547
11457
|
)
|
|
11548
11458
|
];
|
|
11459
|
+
}
|
|
11460
|
+
async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
|
|
11461
|
+
if (items.length === 0) return [];
|
|
11462
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11463
|
+
const nodeKind = registration.type;
|
|
11464
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
11465
|
+
const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
|
|
11466
|
+
const uniqueKeys = collectUniqueKeys(validated);
|
|
11549
11467
|
const kindsToCheck = getKindsForUniquenessCheck(
|
|
11550
11468
|
kind,
|
|
11551
11469
|
constraint.scope,
|
|
11552
11470
|
ctx.registry
|
|
11553
11471
|
);
|
|
11554
|
-
const existingByKey =
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
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
|
-
}
|
|
11472
|
+
const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
|
|
11473
|
+
backend,
|
|
11474
|
+
ctx.graphId,
|
|
11475
|
+
constraint.name,
|
|
11476
|
+
uniqueKeys,
|
|
11477
|
+
kindsToCheck,
|
|
11478
|
+
false
|
|
11479
|
+
) : /* @__PURE__ */ new Map();
|
|
11587
11480
|
const results = Array.from({ length: items.length });
|
|
11588
11481
|
const seenKeys = /* @__PURE__ */ new Map();
|
|
11589
11482
|
for (const [index, { key }] of validated.entries()) {
|
|
@@ -11621,73 +11514,28 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
|
|
|
11621
11514
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11622
11515
|
const nodeKind = registration.type;
|
|
11623
11516
|
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
11624
|
-
const validated =
|
|
11625
|
-
|
|
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
|
-
];
|
|
11517
|
+
const validated = validateAndComputeKeys(nodeKind, kind, constraint, items);
|
|
11518
|
+
const uniqueKeys = collectUniqueKeys(validated);
|
|
11643
11519
|
const kindsToCheck = getKindsForUniquenessCheck(
|
|
11644
11520
|
kind,
|
|
11645
11521
|
constraint.scope,
|
|
11646
11522
|
ctx.registry
|
|
11647
11523
|
);
|
|
11648
|
-
const existingByKey =
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
|
|
11654
|
-
|
|
11655
|
-
|
|
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
|
-
}
|
|
11524
|
+
const existingByKey = uniqueKeys.length > 0 ? await batchCheckUniqueAcrossKinds(
|
|
11525
|
+
backend,
|
|
11526
|
+
ctx.graphId,
|
|
11527
|
+
constraint.name,
|
|
11528
|
+
uniqueKeys,
|
|
11529
|
+
kindsToCheck,
|
|
11530
|
+
true
|
|
11531
|
+
) : /* @__PURE__ */ new Map();
|
|
11681
11532
|
const toCreate = [];
|
|
11682
11533
|
const toFetch = [];
|
|
11683
11534
|
const duplicateOf = [];
|
|
11684
11535
|
const seenKeys = /* @__PURE__ */ new Map();
|
|
11685
11536
|
for (const [index, { validatedProps, key }] of validated.entries()) {
|
|
11686
11537
|
if (key === void 0) {
|
|
11687
|
-
toCreate.push({
|
|
11688
|
-
index,
|
|
11689
|
-
input: { kind, props: validatedProps }
|
|
11690
|
-
});
|
|
11538
|
+
toCreate.push({ index, input: { kind, props: validatedProps } });
|
|
11691
11539
|
continue;
|
|
11692
11540
|
}
|
|
11693
11541
|
const previousIndex = seenKeys.get(key);
|
|
@@ -11698,10 +11546,7 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
|
|
|
11698
11546
|
seenKeys.set(key, index);
|
|
11699
11547
|
const existing = existingByKey.get(key);
|
|
11700
11548
|
if (existing === void 0) {
|
|
11701
|
-
toCreate.push({
|
|
11702
|
-
index,
|
|
11703
|
-
input: { kind, props: validatedProps }
|
|
11704
|
-
});
|
|
11549
|
+
toCreate.push({ index, input: { kind, props: validatedProps } });
|
|
11705
11550
|
} else {
|
|
11706
11551
|
toFetch.push({
|
|
11707
11552
|
index,
|
|
@@ -11735,8 +11580,11 @@ async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName,
|
|
|
11735
11580
|
nodeId
|
|
11736
11581
|
);
|
|
11737
11582
|
if (existingRow === void 0) {
|
|
11738
|
-
const
|
|
11739
|
-
|
|
11583
|
+
const node = await executeNodeCreate(
|
|
11584
|
+
ctx,
|
|
11585
|
+
{ kind, props: validatedProps },
|
|
11586
|
+
backend
|
|
11587
|
+
);
|
|
11740
11588
|
results[index] = { node, action: "created" };
|
|
11741
11589
|
continue;
|
|
11742
11590
|
}
|
|
@@ -12037,7 +11885,7 @@ var Store = class {
|
|
|
12037
11885
|
graphId: this.graphId,
|
|
12038
11886
|
rootId,
|
|
12039
11887
|
backend: this.#backend,
|
|
12040
|
-
dialect:
|
|
11888
|
+
dialect: chunkMME3H4ZF_cjs.getDialect(this.#backend.dialect),
|
|
12041
11889
|
schema: this.#schema,
|
|
12042
11890
|
options
|
|
12043
11891
|
});
|
|
@@ -12209,13 +12057,13 @@ function createStore(graph, backend, options) {
|
|
|
12209
12057
|
}
|
|
12210
12058
|
async function createStoreWithSchema(graph, backend, options) {
|
|
12211
12059
|
const store = createStore(graph, backend, options);
|
|
12212
|
-
const result = await
|
|
12060
|
+
const result = await chunk3HQLOKS5_cjs.ensureSchema(backend, graph, options);
|
|
12213
12061
|
return [store, result];
|
|
12214
12062
|
}
|
|
12215
12063
|
|
|
12216
12064
|
Object.defineProperty(exports, "isMetaEdge", {
|
|
12217
12065
|
enumerable: true,
|
|
12218
|
-
get: function () { return
|
|
12066
|
+
get: function () { return chunk3HQLOKS5_cjs.isMetaEdge; }
|
|
12219
12067
|
});
|
|
12220
12068
|
Object.defineProperty(exports, "defineGraph", {
|
|
12221
12069
|
enumerable: true,
|