@nicia-ai/typegraph 0.3.1 → 0.5.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/drizzle/index.cjs +6 -6
- package/dist/backend/drizzle/index.d.cts +1 -1
- package/dist/backend/drizzle/index.d.ts +1 -1
- package/dist/backend/drizzle/index.js +4 -4
- package/dist/backend/drizzle/postgres.cjs +4 -4
- package/dist/backend/drizzle/postgres.d.cts +1 -1
- package/dist/backend/drizzle/postgres.d.ts +1 -1
- package/dist/backend/drizzle/postgres.js +3 -3
- package/dist/backend/drizzle/sqlite.cjs +4 -4
- package/dist/backend/drizzle/sqlite.d.cts +1 -1
- package/dist/backend/drizzle/sqlite.d.ts +1 -1
- package/dist/backend/drizzle/sqlite.js +3 -3
- package/dist/backend/postgres/index.cjs +4 -4
- package/dist/backend/postgres/index.d.cts +1 -1
- package/dist/backend/postgres/index.d.ts +1 -1
- package/dist/backend/postgres/index.js +3 -3
- package/dist/backend/sqlite/index.cjs +6 -6
- package/dist/backend/sqlite/index.d.cts +1 -1
- package/dist/backend/sqlite/index.d.ts +1 -1
- package/dist/backend/sqlite/index.js +4 -4
- package/dist/{chunk-OYL2SGBD.cjs → chunk-44SXEVF4.cjs} +18 -2
- package/dist/chunk-44SXEVF4.cjs.map +1 -0
- package/dist/{chunk-F2BZSEFE.js → chunk-4MTYE6CF.js} +4 -4
- package/dist/{chunk-F2BZSEFE.js.map → chunk-4MTYE6CF.js.map} +1 -1
- package/dist/{chunk-4HARSV2G.js → chunk-6HFWKZU5.js} +61 -3
- package/dist/chunk-6HFWKZU5.js.map +1 -0
- package/dist/{chunk-F23W4W3A.cjs → chunk-ENXM4W4M.cjs} +18 -18
- package/dist/{chunk-F23W4W3A.cjs.map → chunk-ENXM4W4M.cjs.map} +1 -1
- package/dist/{chunk-ZJHQZZT2.cjs → chunk-K2ROKOK3.cjs} +6 -6
- package/dist/{chunk-ZJHQZZT2.cjs.map → chunk-K2ROKOK3.cjs.map} +1 -1
- package/dist/{chunk-46YY2FRV.js → chunk-KKFJJYCP.js} +3 -3
- package/dist/{chunk-46YY2FRV.js.map → chunk-KKFJJYCP.js.map} +1 -1
- package/dist/{chunk-CMHFS34N.cjs → chunk-KPU6TLUV.cjs} +16 -16
- package/dist/{chunk-CMHFS34N.cjs.map → chunk-KPU6TLUV.cjs.map} +1 -1
- package/dist/{chunk-DD6ONEBN.cjs → chunk-LDM2AFKZ.cjs} +12 -12
- package/dist/{chunk-DD6ONEBN.cjs.map → chunk-LDM2AFKZ.cjs.map} +1 -1
- package/dist/{chunk-NP4G4ZKM.js → chunk-M5SOQ7UV.js} +4 -4
- package/dist/{chunk-NP4G4ZKM.js.map → chunk-M5SOQ7UV.js.map} +1 -1
- package/dist/{chunk-SFY2PPOY.cjs → chunk-PW5BSBZV.cjs} +68 -10
- package/dist/chunk-PW5BSBZV.cjs.map +1 -0
- package/dist/{chunk-O5XPCJLF.js → chunk-SJ2QMDXY.js} +18 -3
- package/dist/chunk-SJ2QMDXY.js.map +1 -0
- package/dist/{chunk-XDTYTNYL.js → chunk-TGDFBLGS.js} +3 -3
- package/dist/{chunk-XDTYTNYL.js.map → chunk-TGDFBLGS.js.map} +1 -1
- package/dist/{index-Dkicw49A.d.ts → index-DyrR_d-H.d.cts} +9 -1
- package/dist/{index-Dkicw49A.d.cts → index-DyrR_d-H.d.ts} +9 -1
- package/dist/index.cjs +1130 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +924 -16
- package/dist/index.js.map +1 -1
- package/dist/interchange/index.cjs +7 -7
- package/dist/interchange/index.d.cts +3 -3
- package/dist/interchange/index.d.ts +3 -3
- package/dist/interchange/index.js +2 -2
- package/dist/{manager-e9LXthrx.d.ts → manager-DXC7CqKG.d.ts} +1 -1
- package/dist/{manager-Jc5Btay9.d.cts → manager-DiPf-0GG.d.cts} +1 -1
- package/dist/profiler/index.d.cts +3 -3
- package/dist/profiler/index.d.ts +3 -3
- package/dist/schema/index.cjs +22 -22
- package/dist/schema/index.d.cts +5 -5
- package/dist/schema/index.d.ts +5 -5
- package/dist/schema/index.js +4 -4
- package/dist/{store-DM3Tk3Pw.d.ts → store-DODIWZxC.d.ts} +145 -7
- package/dist/{store-nbBybLWP.d.cts → store-nDW3GOFb.d.cts} +145 -7
- package/dist/{types-Cdbi4hcx.d.ts → types-DpIoePMI.d.ts} +19 -0
- package/dist/{types-DDP0MGBF.d.cts → types-WX8V9dqn.d.cts} +19 -0
- package/package.json +2 -2
- package/dist/chunk-4HARSV2G.js.map +0 -1
- package/dist/chunk-O5XPCJLF.js.map +0 -1
- package/dist/chunk-OYL2SGBD.cjs.map +0 -1
- package/dist/chunk-SFY2PPOY.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkLDM2AFKZ_cjs = require('./chunk-LDM2AFKZ.cjs');
|
|
4
|
+
var chunkK2ROKOK3_cjs = require('./chunk-K2ROKOK3.cjs');
|
|
5
|
+
var chunk44SXEVF4_cjs = require('./chunk-44SXEVF4.cjs');
|
|
6
6
|
var chunk2WVFEIHR_cjs = require('./chunk-2WVFEIHR.cjs');
|
|
7
7
|
var chunkP5CNM325_cjs = require('./chunk-P5CNM325.cjs');
|
|
8
8
|
var zod = require('zod');
|
|
@@ -17,7 +17,7 @@ function validateSchemaKeys(schema, name) {
|
|
|
17
17
|
(key) => RESERVED_NODE_KEYS.has(key)
|
|
18
18
|
);
|
|
19
19
|
if (conflicts.length > 0) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
21
21
|
`Node "${name}" schema contains reserved property names: ${conflicts.join(", ")}`,
|
|
22
22
|
{ nodeType: name, conflicts, reservedKeys: [...RESERVED_NODE_KEYS] },
|
|
23
23
|
{
|
|
@@ -29,7 +29,7 @@ function validateSchemaKeys(schema, name) {
|
|
|
29
29
|
function defineNode(name, options) {
|
|
30
30
|
validateSchemaKeys(options.schema, name);
|
|
31
31
|
return Object.freeze({
|
|
32
|
-
[
|
|
32
|
+
[chunkK2ROKOK3_cjs.NODE_TYPE_BRAND]: true,
|
|
33
33
|
kind: name,
|
|
34
34
|
schema: options.schema,
|
|
35
35
|
description: options.description
|
|
@@ -51,7 +51,7 @@ function validateSchemaKeys2(schema, name) {
|
|
|
51
51
|
(key) => RESERVED_EDGE_KEYS.has(key)
|
|
52
52
|
);
|
|
53
53
|
if (conflicts.length > 0) {
|
|
54
|
-
throw new
|
|
54
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
55
55
|
`Edge "${name}" schema contains reserved property names: ${conflicts.join(", ")}`,
|
|
56
56
|
{ edgeType: name, conflicts, reservedKeys: [...RESERVED_EDGE_KEYS] },
|
|
57
57
|
{
|
|
@@ -64,7 +64,7 @@ function defineEdge(name, options) {
|
|
|
64
64
|
const schema = options?.schema ?? EMPTY_SCHEMA;
|
|
65
65
|
validateSchemaKeys2(schema, name);
|
|
66
66
|
return Object.freeze({
|
|
67
|
-
[
|
|
67
|
+
[chunkK2ROKOK3_cjs.EDGE_TYPE_BRAND]: true,
|
|
68
68
|
kind: name,
|
|
69
69
|
schema,
|
|
70
70
|
description: options?.description,
|
|
@@ -84,7 +84,7 @@ function metaEdge(name, options = {}) {
|
|
|
84
84
|
description: options.description
|
|
85
85
|
};
|
|
86
86
|
return Object.freeze({
|
|
87
|
-
[
|
|
87
|
+
[chunkLDM2AFKZ_cjs.META_EDGE_BRAND]: true,
|
|
88
88
|
name,
|
|
89
89
|
properties
|
|
90
90
|
});
|
|
@@ -120,7 +120,7 @@ function createExternalRef(table) {
|
|
|
120
120
|
// src/ontology/core-meta-edges.ts
|
|
121
121
|
function createMetaEdge(name, properties) {
|
|
122
122
|
return Object.freeze({
|
|
123
|
-
[
|
|
123
|
+
[chunkLDM2AFKZ_cjs.META_EDGE_BRAND]: true,
|
|
124
124
|
name,
|
|
125
125
|
properties: {
|
|
126
126
|
transitive: properties.transitive ?? false,
|
|
@@ -132,7 +132,7 @@ function createMetaEdge(name, properties) {
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
var subClassOfMetaEdge = createMetaEdge(
|
|
135
|
+
var subClassOfMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_SUB_CLASS_OF, {
|
|
136
136
|
transitive: true,
|
|
137
137
|
inference: "subsumption",
|
|
138
138
|
description: "Type inheritance (Podcast subClassOf Media)"
|
|
@@ -144,9 +144,9 @@ function subClassOf(child, parent) {
|
|
|
144
144
|
to: parent
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
var broaderMetaEdge = createMetaEdge(
|
|
147
|
+
var broaderMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_BROADER, {
|
|
148
148
|
transitive: true,
|
|
149
|
-
inverse:
|
|
149
|
+
inverse: chunkLDM2AFKZ_cjs.META_EDGE_NARROWER,
|
|
150
150
|
inference: "hierarchy",
|
|
151
151
|
description: "Broader concept (ML broader AI)"
|
|
152
152
|
});
|
|
@@ -157,9 +157,9 @@ function broader(narrowerConcept, broaderConcept) {
|
|
|
157
157
|
to: broaderConcept
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
var narrowerMetaEdge = createMetaEdge(
|
|
160
|
+
var narrowerMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_NARROWER, {
|
|
161
161
|
transitive: true,
|
|
162
|
-
inverse:
|
|
162
|
+
inverse: chunkLDM2AFKZ_cjs.META_EDGE_BROADER,
|
|
163
163
|
inference: "hierarchy",
|
|
164
164
|
description: "Narrower concept (AI narrower ML)"
|
|
165
165
|
});
|
|
@@ -170,7 +170,7 @@ function narrower(broaderConcept, narrowerConcept) {
|
|
|
170
170
|
to: narrowerConcept
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
var relatedToMetaEdge = createMetaEdge(
|
|
173
|
+
var relatedToMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_RELATED_TO, {
|
|
174
174
|
symmetric: true,
|
|
175
175
|
inference: "association",
|
|
176
176
|
description: "Non-hierarchical association"
|
|
@@ -182,7 +182,7 @@ function relatedTo(conceptA, conceptB) {
|
|
|
182
182
|
to: conceptB
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
|
-
var equivalentToMetaEdge = createMetaEdge(
|
|
185
|
+
var equivalentToMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_EQUIVALENT_TO, {
|
|
186
186
|
symmetric: true,
|
|
187
187
|
transitive: true,
|
|
188
188
|
inference: "substitution",
|
|
@@ -195,7 +195,7 @@ function equivalentTo(kindA, kindBOrIri) {
|
|
|
195
195
|
to: kindBOrIri
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
var sameAsMetaEdge = createMetaEdge(
|
|
198
|
+
var sameAsMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_SAME_AS, {
|
|
199
199
|
symmetric: true,
|
|
200
200
|
transitive: true,
|
|
201
201
|
inference: "substitution",
|
|
@@ -208,7 +208,7 @@ function sameAs(kindA, kindBOrIri) {
|
|
|
208
208
|
to: kindBOrIri
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
var differentFromMetaEdge = createMetaEdge(
|
|
211
|
+
var differentFromMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_DIFFERENT_FROM, {
|
|
212
212
|
symmetric: true,
|
|
213
213
|
inference: "constraint",
|
|
214
214
|
description: "Explicitly different individuals"
|
|
@@ -220,7 +220,7 @@ function differentFrom(kindA, kindB) {
|
|
|
220
220
|
to: kindB
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
|
-
var disjointWithMetaEdge = createMetaEdge(
|
|
223
|
+
var disjointWithMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_DISJOINT_WITH, {
|
|
224
224
|
symmetric: true,
|
|
225
225
|
inference: "constraint",
|
|
226
226
|
description: "Mutually exclusive types"
|
|
@@ -232,9 +232,9 @@ function disjointWith(kindA, kindB) {
|
|
|
232
232
|
to: kindB
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
var partOfMetaEdge = createMetaEdge(
|
|
235
|
+
var partOfMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_PART_OF, {
|
|
236
236
|
transitive: true,
|
|
237
|
-
inverse:
|
|
237
|
+
inverse: chunkLDM2AFKZ_cjs.META_EDGE_HAS_PART,
|
|
238
238
|
inference: "composition",
|
|
239
239
|
description: "X is part of Y"
|
|
240
240
|
});
|
|
@@ -245,9 +245,9 @@ function partOf(part, whole) {
|
|
|
245
245
|
to: whole
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
|
-
var hasPartMetaEdge = createMetaEdge(
|
|
248
|
+
var hasPartMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_HAS_PART, {
|
|
249
249
|
transitive: true,
|
|
250
|
-
inverse:
|
|
250
|
+
inverse: chunkLDM2AFKZ_cjs.META_EDGE_PART_OF,
|
|
251
251
|
inference: "composition",
|
|
252
252
|
description: "Y has part X"
|
|
253
253
|
});
|
|
@@ -258,12 +258,12 @@ function hasPart(whole, part) {
|
|
|
258
258
|
to: part
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
|
-
var inverseOfMetaEdge = createMetaEdge(
|
|
261
|
+
var inverseOfMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_INVERSE_OF, {
|
|
262
262
|
symmetric: true,
|
|
263
263
|
inference: "none",
|
|
264
264
|
description: "Edge A is inverse of edge B"
|
|
265
265
|
});
|
|
266
|
-
var impliesMetaEdge = createMetaEdge(
|
|
266
|
+
var impliesMetaEdge = createMetaEdge(chunkLDM2AFKZ_cjs.META_EDGE_IMPLIES, {
|
|
267
267
|
transitive: true,
|
|
268
268
|
inference: "none",
|
|
269
269
|
description: "Edge A implies edge B exists"
|
|
@@ -317,10 +317,10 @@ function runRecursiveTraversalSelectionPass(ast) {
|
|
|
317
317
|
(traversal) => traversal.variableLength !== void 0
|
|
318
318
|
);
|
|
319
319
|
if (variableLengthTraversal === void 0) {
|
|
320
|
-
throw new
|
|
320
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError("No variable-length traversal found");
|
|
321
321
|
}
|
|
322
322
|
if (ast.traversals.length > 1) {
|
|
323
|
-
throw new
|
|
323
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
324
324
|
"Variable-length traversals with multiple traversals are not yet supported. Please use a single variable-length traversal."
|
|
325
325
|
);
|
|
326
326
|
}
|
|
@@ -838,7 +838,7 @@ function notInSubquery(field2, subquery) {
|
|
|
838
838
|
function assertSingleColumnSubquery(subquery) {
|
|
839
839
|
const columnCount = getSubqueryColumnCount(subquery);
|
|
840
840
|
if (columnCount === 1) return;
|
|
841
|
-
throw new
|
|
841
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
842
842
|
`IN/NOT IN subquery must project exactly 1 column, but got ${columnCount}`,
|
|
843
843
|
{ subqueryColumnCount: columnCount },
|
|
844
844
|
{
|
|
@@ -851,7 +851,7 @@ function assertCompatibleSubqueryValueTypes(field2, subquery) {
|
|
|
851
851
|
const subqueryValueType = getSingleSubqueryColumnValueType(subquery);
|
|
852
852
|
const resolvedValueType = fieldValueType ?? subqueryValueType;
|
|
853
853
|
if (isUnsupportedInSubqueryValueType(resolvedValueType)) {
|
|
854
|
-
throw new
|
|
854
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
855
855
|
`IN/NOT IN subquery does not support ${String(resolvedValueType)} values`,
|
|
856
856
|
{ valueType: resolvedValueType },
|
|
857
857
|
{
|
|
@@ -862,7 +862,7 @@ function assertCompatibleSubqueryValueTypes(field2, subquery) {
|
|
|
862
862
|
if (isInSubqueryTypeCompatible(fieldValueType, subqueryValueType)) {
|
|
863
863
|
return;
|
|
864
864
|
}
|
|
865
|
-
throw new
|
|
865
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
866
866
|
`IN/NOT IN type mismatch: field type "${String(fieldValueType)}" does not match subquery column type "${String(subqueryValueType)}"`,
|
|
867
867
|
{
|
|
868
868
|
fieldValueType,
|
|
@@ -988,7 +988,7 @@ function resolveLiteralValueTypes(literals) {
|
|
|
988
988
|
}
|
|
989
989
|
}
|
|
990
990
|
if (resolved.size > 1) {
|
|
991
|
-
throw new
|
|
991
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
992
992
|
"Mixed literal value types are not supported in predicates",
|
|
993
993
|
{ valueTypes: [...resolved] }
|
|
994
994
|
);
|
|
@@ -1114,7 +1114,7 @@ function compilePredicateExpression(expr, ctx) {
|
|
|
1114
1114
|
if (!upperIsParam) boundsForType.push(expr.upper);
|
|
1115
1115
|
const valueType = boundsForType.length > 0 ? resolveComparisonValueType(expr.field, boundsForType) : normalizeValueType2(expr.field.valueType);
|
|
1116
1116
|
if (valueType === "array" || valueType === "object") {
|
|
1117
|
-
throw new
|
|
1117
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1118
1118
|
"Between comparisons are not supported for JSON arrays or objects"
|
|
1119
1119
|
);
|
|
1120
1120
|
}
|
|
@@ -1179,7 +1179,7 @@ function compileComparisonPredicate(expr, dialect, cteColumnPrefix) {
|
|
|
1179
1179
|
);
|
|
1180
1180
|
const opSql2 = COMPARISON_OP_SQL[expr.op];
|
|
1181
1181
|
if (!opSql2) {
|
|
1182
|
-
throw new
|
|
1182
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1183
1183
|
`Comparison operation "${expr.op}" is not supported for parameterized predicates`
|
|
1184
1184
|
);
|
|
1185
1185
|
}
|
|
@@ -1187,7 +1187,7 @@ function compileComparisonPredicate(expr, dialect, cteColumnPrefix) {
|
|
|
1187
1187
|
}
|
|
1188
1188
|
const valueType = resolveComparisonValueType(expr.left, expr.right);
|
|
1189
1189
|
if (valueType === "array" || valueType === "object") {
|
|
1190
|
-
throw new
|
|
1190
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1191
1191
|
`Comparison operation "${expr.op}" is not supported for ${valueType} values`
|
|
1192
1192
|
);
|
|
1193
1193
|
}
|
|
@@ -1215,7 +1215,7 @@ function compileComparisonPredicate(expr, dialect, cteColumnPrefix) {
|
|
|
1215
1215
|
const convertedRight = convertValueForSql(rightValue.value, dialect);
|
|
1216
1216
|
const opSql = COMPARISON_OP_SQL[expr.op];
|
|
1217
1217
|
if (!opSql) {
|
|
1218
|
-
throw new
|
|
1218
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1219
1219
|
`Comparison operation "${expr.op}" is not supported`
|
|
1220
1220
|
);
|
|
1221
1221
|
}
|
|
@@ -1278,13 +1278,13 @@ function compileObjectPredicate(expr, dialect, cteColumnPrefix) {
|
|
|
1278
1278
|
}
|
|
1279
1279
|
case "pathEquals": {
|
|
1280
1280
|
if (!expr.value) {
|
|
1281
|
-
throw new
|
|
1281
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1282
1282
|
"pathEquals requires a comparison value"
|
|
1283
1283
|
);
|
|
1284
1284
|
}
|
|
1285
1285
|
const valueType = resolvePredicateValueType(expr.valueType, expr.value);
|
|
1286
1286
|
if (valueType === "array" || valueType === "object") {
|
|
1287
|
-
throw new
|
|
1287
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1288
1288
|
"pathEquals is not supported for JSON arrays or objects"
|
|
1289
1289
|
);
|
|
1290
1290
|
}
|
|
@@ -1300,7 +1300,7 @@ function compileObjectPredicate(expr, dialect, cteColumnPrefix) {
|
|
|
1300
1300
|
}
|
|
1301
1301
|
case "pathContains": {
|
|
1302
1302
|
if (!expr.value) {
|
|
1303
|
-
throw new
|
|
1303
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1304
1304
|
"pathContains requires a comparison value"
|
|
1305
1305
|
);
|
|
1306
1306
|
}
|
|
@@ -1328,7 +1328,7 @@ function compileAggregatePredicate(expr, dialect) {
|
|
|
1328
1328
|
const aggregate = compileAggregateExpr(expr.aggregate, dialect);
|
|
1329
1329
|
const op = COMPARISON_OP_SQL[expr.op];
|
|
1330
1330
|
if (!op) {
|
|
1331
|
-
throw new
|
|
1331
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1332
1332
|
`Comparison operation "${expr.op}" is not supported for aggregate predicates`
|
|
1333
1333
|
);
|
|
1334
1334
|
}
|
|
@@ -1363,7 +1363,7 @@ function compileAggregateExpr(expr, dialect) {
|
|
|
1363
1363
|
return drizzleOrm.sql`MAX(${field2})`;
|
|
1364
1364
|
}
|
|
1365
1365
|
default: {
|
|
1366
|
-
throw new
|
|
1366
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1367
1367
|
`Unknown aggregate function: ${expr.function}`
|
|
1368
1368
|
);
|
|
1369
1369
|
}
|
|
@@ -1371,7 +1371,7 @@ function compileAggregateExpr(expr, dialect) {
|
|
|
1371
1371
|
}
|
|
1372
1372
|
function compileExistsSubquery(expr, ctx) {
|
|
1373
1373
|
if (expr.subquery.graphId === void 0) {
|
|
1374
|
-
throw new
|
|
1374
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError("EXISTS subquery must have a graphId");
|
|
1375
1375
|
}
|
|
1376
1376
|
const subSql = ctx.compileQuery(expr.subquery, expr.subquery.graphId);
|
|
1377
1377
|
return expr.negated ? drizzleOrm.sql`NOT EXISTS (${subSql})` : drizzleOrm.sql`EXISTS (${subSql})`;
|
|
@@ -1379,7 +1379,7 @@ function compileExistsSubquery(expr, ctx) {
|
|
|
1379
1379
|
function compileInSubquery(expr, ctx) {
|
|
1380
1380
|
const subqueryColumnCount = getSubqueryColumnCount(expr.subquery);
|
|
1381
1381
|
if (subqueryColumnCount !== 1) {
|
|
1382
|
-
throw new
|
|
1382
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1383
1383
|
`IN/NOT IN subquery must project exactly 1 column, but got ${subqueryColumnCount}`,
|
|
1384
1384
|
{ subqueryColumnCount }
|
|
1385
1385
|
);
|
|
@@ -1388,13 +1388,13 @@ function compileInSubquery(expr, ctx) {
|
|
|
1388
1388
|
const subqueryValueType = getSingleSubqueryColumnValueType(expr.subquery);
|
|
1389
1389
|
const resolvedValueType = fieldValueType ?? subqueryValueType;
|
|
1390
1390
|
if (isUnsupportedInSubqueryValueType(resolvedValueType)) {
|
|
1391
|
-
throw new
|
|
1391
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1392
1392
|
`IN/NOT IN subquery does not support ${String(resolvedValueType)} values`,
|
|
1393
1393
|
{ valueType: resolvedValueType }
|
|
1394
1394
|
);
|
|
1395
1395
|
}
|
|
1396
1396
|
if (!isInSubqueryTypeCompatible(fieldValueType, subqueryValueType)) {
|
|
1397
|
-
throw new
|
|
1397
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1398
1398
|
`IN/NOT IN type mismatch: field type "${String(fieldValueType)}" does not match subquery column type "${String(subqueryValueType)}"`,
|
|
1399
1399
|
{
|
|
1400
1400
|
fieldValueType,
|
|
@@ -1404,7 +1404,7 @@ function compileInSubquery(expr, ctx) {
|
|
|
1404
1404
|
}
|
|
1405
1405
|
const valueType = fieldValueType ?? subqueryValueType;
|
|
1406
1406
|
if (expr.subquery.graphId === void 0) {
|
|
1407
|
-
throw new
|
|
1407
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1408
1408
|
"IN/NOT IN subquery must have a graphId"
|
|
1409
1409
|
);
|
|
1410
1410
|
}
|
|
@@ -1428,7 +1428,7 @@ function extractVectorSimilarityPredicates(predicates) {
|
|
|
1428
1428
|
switch (expr.__type) {
|
|
1429
1429
|
case "vector_similarity": {
|
|
1430
1430
|
if (inDisallowedBranch) {
|
|
1431
|
-
throw new
|
|
1431
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1432
1432
|
"Vector similarity predicates cannot be nested under OR or NOT. Use top-level AND combinations instead."
|
|
1433
1433
|
);
|
|
1434
1434
|
}
|
|
@@ -1463,7 +1463,7 @@ function extractVectorSimilarityPredicates(predicates) {
|
|
|
1463
1463
|
function runVectorPredicatePass(ast, dialect) {
|
|
1464
1464
|
const vectorPredicates = extractVectorSimilarityPredicates(ast.predicates);
|
|
1465
1465
|
if (vectorPredicates.length > 1) {
|
|
1466
|
-
throw new
|
|
1466
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1467
1467
|
"Multiple vector similarity predicates in a single query are not supported"
|
|
1468
1468
|
);
|
|
1469
1469
|
}
|
|
@@ -1473,29 +1473,29 @@ function runVectorPredicatePass(ast, dialect) {
|
|
|
1473
1473
|
}
|
|
1474
1474
|
const vectorStrategy = dialect.capabilities.vectorPredicateStrategy;
|
|
1475
1475
|
if (vectorStrategy === "unsupported" || !dialect.supportsVectors) {
|
|
1476
|
-
throw new
|
|
1476
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1477
1477
|
`Vector similarity predicates are not supported for dialect "${dialect.name}"`
|
|
1478
1478
|
);
|
|
1479
1479
|
}
|
|
1480
1480
|
if (!dialect.capabilities.vectorMetrics.includes(vectorPredicate.metric)) {
|
|
1481
|
-
throw new
|
|
1481
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1482
1482
|
`Vector metric "${vectorPredicate.metric}" is not supported for dialect "${dialect.name}"`
|
|
1483
1483
|
);
|
|
1484
1484
|
}
|
|
1485
1485
|
if (!Number.isFinite(vectorPredicate.limit) || vectorPredicate.limit <= 0) {
|
|
1486
|
-
throw new
|
|
1486
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1487
1487
|
`Vector predicate limit must be a positive finite number, got ${String(vectorPredicate.limit)}`
|
|
1488
1488
|
);
|
|
1489
1489
|
}
|
|
1490
1490
|
const { minScore } = vectorPredicate;
|
|
1491
1491
|
if (minScore !== void 0) {
|
|
1492
1492
|
if (!Number.isFinite(minScore)) {
|
|
1493
|
-
throw new
|
|
1493
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1494
1494
|
`Vector minScore must be a finite number, got ${String(minScore)}`
|
|
1495
1495
|
);
|
|
1496
1496
|
}
|
|
1497
1497
|
if (vectorPredicate.metric === "cosine" && (minScore < -1 || minScore > 1)) {
|
|
1498
|
-
throw new
|
|
1498
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
1499
1499
|
`Cosine minScore must be between -1 and 1, got ${String(minScore)}`
|
|
1500
1500
|
);
|
|
1501
1501
|
}
|
|
@@ -1589,7 +1589,7 @@ function appendAggregateSortLimitAndProjectNodes(currentNode, ast, nextPlanNodeI
|
|
|
1589
1589
|
} else if (hasOffset) {
|
|
1590
1590
|
node = { ...limitOffsetNodeBase, offset: ast.offset };
|
|
1591
1591
|
} else {
|
|
1592
|
-
throw new
|
|
1592
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1593
1593
|
"limit_offset node requires limit or offset to be present"
|
|
1594
1594
|
);
|
|
1595
1595
|
}
|
|
@@ -1886,7 +1886,7 @@ function findUnaryNodeInProjectChain(rootNode, op) {
|
|
|
1886
1886
|
}
|
|
1887
1887
|
function inspectProjectPlan(logicalPlan) {
|
|
1888
1888
|
if (logicalPlan.root.op !== "project") {
|
|
1889
|
-
throw new
|
|
1889
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1890
1890
|
`SQL emitter expected logical plan root to be "project", got "${logicalPlan.root.op}"`,
|
|
1891
1891
|
{ component: "plan-inspector" }
|
|
1892
1892
|
);
|
|
@@ -1916,13 +1916,13 @@ function inspectProjectPlan(logicalPlan) {
|
|
|
1916
1916
|
function inspectStandardProjectPlan(logicalPlan) {
|
|
1917
1917
|
const shape = inspectProjectPlan(logicalPlan);
|
|
1918
1918
|
if (shape.hasSetOperation) {
|
|
1919
|
-
throw new
|
|
1919
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1920
1920
|
'Standard SQL emitter does not support plans containing "set_op" nodes',
|
|
1921
1921
|
{ component: "plan-inspector" }
|
|
1922
1922
|
);
|
|
1923
1923
|
}
|
|
1924
1924
|
if (shape.hasRecursiveExpand) {
|
|
1925
|
-
throw new
|
|
1925
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1926
1926
|
'Standard SQL emitter does not support plans containing "recursive_expand" nodes',
|
|
1927
1927
|
{ component: "plan-inspector" }
|
|
1928
1928
|
);
|
|
@@ -1932,13 +1932,13 @@ function inspectStandardProjectPlan(logicalPlan) {
|
|
|
1932
1932
|
function inspectRecursiveProjectPlan(logicalPlan) {
|
|
1933
1933
|
const shape = inspectProjectPlan(logicalPlan);
|
|
1934
1934
|
if (!shape.hasRecursiveExpand) {
|
|
1935
|
-
throw new
|
|
1935
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1936
1936
|
'Recursive SQL emitter expected logical plan to contain a "recursive_expand" node',
|
|
1937
1937
|
{ component: "plan-inspector" }
|
|
1938
1938
|
);
|
|
1939
1939
|
}
|
|
1940
1940
|
if (shape.hasSetOperation) {
|
|
1941
|
-
throw new
|
|
1941
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
1942
1942
|
'Recursive SQL emitter does not support plans containing "set_op" nodes',
|
|
1943
1943
|
{ component: "plan-inspector" }
|
|
1944
1944
|
);
|
|
@@ -1997,7 +1997,7 @@ function inspectSetOperationPlan(logicalPlan) {
|
|
|
1997
1997
|
const operations = /* @__PURE__ */ new Set();
|
|
1998
1998
|
collectPlanOperations(logicalPlan.root, operations);
|
|
1999
1999
|
if (!operations.has("set_op")) {
|
|
2000
|
-
throw new
|
|
2000
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2001
2001
|
'Set-operation SQL emitter expected logical plan to contain a "set_op" node',
|
|
2002
2002
|
{ component: "plan-inspector" }
|
|
2003
2003
|
);
|
|
@@ -2015,25 +2015,25 @@ function inspectSetOperationPlan(logicalPlan) {
|
|
|
2015
2015
|
function assertRecursiveEmitterClauseAlignment(logicalPlan, input) {
|
|
2016
2016
|
const planShape = inspectRecursiveProjectPlan(logicalPlan);
|
|
2017
2017
|
if (planShape.hasSort && input.orderBy === void 0) {
|
|
2018
|
-
throw new
|
|
2018
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2019
2019
|
"Recursive SQL emitter expected ORDER BY clause for plan containing a sort node",
|
|
2020
2020
|
{ component: "recursive-emitter" }
|
|
2021
2021
|
);
|
|
2022
2022
|
}
|
|
2023
2023
|
if (!planShape.hasSort && input.orderBy !== void 0) {
|
|
2024
|
-
throw new
|
|
2024
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2025
2025
|
"Recursive SQL emitter received ORDER BY clause for a plan without sort nodes",
|
|
2026
2026
|
{ component: "recursive-emitter" }
|
|
2027
2027
|
);
|
|
2028
2028
|
}
|
|
2029
2029
|
if (planShape.hasLimitOffset && input.limitOffset === void 0) {
|
|
2030
|
-
throw new
|
|
2030
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2031
2031
|
"Recursive SQL emitter expected LIMIT/OFFSET clause for plan containing a limit_offset node",
|
|
2032
2032
|
{ component: "recursive-emitter" }
|
|
2033
2033
|
);
|
|
2034
2034
|
}
|
|
2035
2035
|
if (!planShape.hasLimitOffset && input.limitOffset !== void 0) {
|
|
2036
|
-
throw new
|
|
2036
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2037
2037
|
"Recursive SQL emitter received LIMIT/OFFSET clause for a plan without limit_offset nodes",
|
|
2038
2038
|
{ component: "recursive-emitter" }
|
|
2039
2039
|
);
|
|
@@ -2060,14 +2060,14 @@ function assertSetOperationEmitterClauseAlignment(logicalPlan, suffixClauses) {
|
|
|
2060
2060
|
const shape = inspectSetOperationPlan(logicalPlan);
|
|
2061
2061
|
const hasSuffixClauses = suffixClauses !== void 0 && suffixClauses.length > 0;
|
|
2062
2062
|
if (!shape.hasSort && !shape.hasLimitOffset && hasSuffixClauses) {
|
|
2063
|
-
throw new
|
|
2063
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2064
2064
|
"Set-operation SQL emitter received suffix clauses for a plan without top-level sort or limit_offset nodes",
|
|
2065
2065
|
{ component: "set-operation-emitter" }
|
|
2066
2066
|
);
|
|
2067
2067
|
}
|
|
2068
2068
|
if (!hasSuffixClauses) {
|
|
2069
2069
|
if (shape.hasSort || shape.hasLimitOffset) {
|
|
2070
|
-
throw new
|
|
2070
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2071
2071
|
"Set-operation SQL emitter expected suffix clauses for plan containing top-level sort or limit_offset nodes",
|
|
2072
2072
|
{ component: "set-operation-emitter" }
|
|
2073
2073
|
);
|
|
@@ -2077,7 +2077,7 @@ function assertSetOperationEmitterClauseAlignment(logicalPlan, suffixClauses) {
|
|
|
2077
2077
|
const limitOffsetClauseCount = shape.limitOffsetNode === void 0 ? 0 : (shape.limitOffsetNode.limit === void 0 ? 0 : 1) + (shape.limitOffsetNode.offset === void 0 ? 0 : 1);
|
|
2078
2078
|
const expectedClauseCount = (shape.sortNode === void 0 ? 0 : 1) + limitOffsetClauseCount;
|
|
2079
2079
|
if (suffixClauses.length !== expectedClauseCount) {
|
|
2080
|
-
throw new
|
|
2080
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2081
2081
|
`Set-operation SQL emitter expected ${String(expectedClauseCount)} top-level suffix clause(s) from logical plan, got ${String(suffixClauses.length)}`,
|
|
2082
2082
|
{ component: "set-operation-emitter" }
|
|
2083
2083
|
);
|
|
@@ -2101,38 +2101,38 @@ function emitSetOperationQuerySql(input) {
|
|
|
2101
2101
|
function assertStandardEmitterClauseAlignment(logicalPlan, input) {
|
|
2102
2102
|
const planShape = inspectStandardProjectPlan(logicalPlan);
|
|
2103
2103
|
if (input.groupBy !== void 0 && !planShape.hasAggregate) {
|
|
2104
|
-
throw new
|
|
2104
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2105
2105
|
"Standard SQL emitter received GROUP BY clause for a plan without aggregate nodes",
|
|
2106
2106
|
{ component: "standard-emitter" }
|
|
2107
2107
|
);
|
|
2108
2108
|
}
|
|
2109
2109
|
if (input.having !== void 0 && !planShape.hasAggregate) {
|
|
2110
|
-
throw new
|
|
2110
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2111
2111
|
"Standard SQL emitter received HAVING clause for a plan without aggregate nodes",
|
|
2112
2112
|
{ component: "standard-emitter" }
|
|
2113
2113
|
);
|
|
2114
2114
|
}
|
|
2115
2115
|
const expectsOrderBy = planShape.hasSort || planShape.hasVectorKnn;
|
|
2116
2116
|
if (expectsOrderBy && input.orderBy === void 0) {
|
|
2117
|
-
throw new
|
|
2117
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2118
2118
|
"Standard SQL emitter expected ORDER BY clause for plan containing a sort or vector_knn node",
|
|
2119
2119
|
{ component: "standard-emitter" }
|
|
2120
2120
|
);
|
|
2121
2121
|
}
|
|
2122
2122
|
if (!expectsOrderBy && input.orderBy !== void 0) {
|
|
2123
|
-
throw new
|
|
2123
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2124
2124
|
"Standard SQL emitter received ORDER BY clause for a plan without sort or vector_knn nodes",
|
|
2125
2125
|
{ component: "standard-emitter" }
|
|
2126
2126
|
);
|
|
2127
2127
|
}
|
|
2128
2128
|
if (planShape.hasLimitOffset && input.limitOffset === void 0) {
|
|
2129
|
-
throw new
|
|
2129
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2130
2130
|
"Standard SQL emitter expected LIMIT/OFFSET clause for plan containing a limit_offset node",
|
|
2131
2131
|
{ component: "standard-emitter" }
|
|
2132
2132
|
);
|
|
2133
2133
|
}
|
|
2134
2134
|
if (!planShape.hasLimitOffset && input.limitOffset !== void 0) {
|
|
2135
|
-
throw new
|
|
2135
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2136
2136
|
"Standard SQL emitter received LIMIT/OFFSET clause for a plan without limit_offset nodes",
|
|
2137
2137
|
{ component: "standard-emitter" }
|
|
2138
2138
|
);
|
|
@@ -2213,7 +2213,7 @@ function getNodeKindsForAlias(ast, alias) {
|
|
|
2213
2213
|
return traversal.nodeKinds;
|
|
2214
2214
|
}
|
|
2215
2215
|
}
|
|
2216
|
-
throw new
|
|
2216
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(`Unknown traversal source alias: ${alias}`);
|
|
2217
2217
|
}
|
|
2218
2218
|
|
|
2219
2219
|
// src/query/compiler/typed-json-extract.ts
|
|
@@ -2544,7 +2544,7 @@ function compileAggregateExprFromSource(expr, dialect) {
|
|
|
2544
2544
|
return drizzleOrm.sql`${drizzleOrm.sql.raw(fn.toUpperCase())}(${column})`;
|
|
2545
2545
|
}
|
|
2546
2546
|
default: {
|
|
2547
|
-
throw new
|
|
2547
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
2548
2548
|
`Unknown aggregate function: ${String(fn)}`
|
|
2549
2549
|
);
|
|
2550
2550
|
}
|
|
@@ -2642,7 +2642,7 @@ function buildStandardOrderBy(input) {
|
|
|
2642
2642
|
for (const orderSpec of ast.orderBy) {
|
|
2643
2643
|
const valueType = orderSpec.field.valueType;
|
|
2644
2644
|
if (valueType === "array" || valueType === "object") {
|
|
2645
|
-
throw new
|
|
2645
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
2646
2646
|
"Ordering by JSON arrays or objects is not supported"
|
|
2647
2647
|
);
|
|
2648
2648
|
}
|
|
@@ -2772,7 +2772,7 @@ function buildStandardVectorOrderBy(input) {
|
|
|
2772
2772
|
for (const orderSpec of ast.orderBy) {
|
|
2773
2773
|
const valueType = orderSpec.field.valueType;
|
|
2774
2774
|
if (valueType === "array" || valueType === "object") {
|
|
2775
|
-
throw new
|
|
2775
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
2776
2776
|
"Ordering by JSON arrays or objects is not supported"
|
|
2777
2777
|
);
|
|
2778
2778
|
}
|
|
@@ -2855,7 +2855,7 @@ function runRecursiveQueryPassPipeline(ast, graphId, ctx) {
|
|
|
2855
2855
|
execute(currentState) {
|
|
2856
2856
|
const traversal = currentState.traversal;
|
|
2857
2857
|
if (traversal === void 0) {
|
|
2858
|
-
throw new
|
|
2858
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2859
2859
|
"Recursive traversal pass did not select traversal"
|
|
2860
2860
|
);
|
|
2861
2861
|
}
|
|
@@ -2908,17 +2908,17 @@ function compileVariableLengthQueryWithRecursiveCteStrategy(ast, graphId, ctx) {
|
|
|
2908
2908
|
traversal: vlTraversal
|
|
2909
2909
|
} = passState;
|
|
2910
2910
|
if (temporalFilterPass === void 0) {
|
|
2911
|
-
throw new
|
|
2911
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2912
2912
|
"Temporal filter pass did not initialize temporal state"
|
|
2913
2913
|
);
|
|
2914
2914
|
}
|
|
2915
2915
|
if (logicalPlan === void 0) {
|
|
2916
|
-
throw new
|
|
2916
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2917
2917
|
"Logical plan pass did not initialize plan state"
|
|
2918
2918
|
);
|
|
2919
2919
|
}
|
|
2920
2920
|
if (vlTraversal === void 0) {
|
|
2921
|
-
throw new
|
|
2921
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
2922
2922
|
"Recursive traversal pass did not select traversal"
|
|
2923
2923
|
);
|
|
2924
2924
|
}
|
|
@@ -3010,7 +3010,7 @@ function compileRecursiveCte(ast, traversal, graphId, ctx, requiredColumnsByAlia
|
|
|
3010
3010
|
targetContext
|
|
3011
3011
|
);
|
|
3012
3012
|
if (vl.maxDepth > MAX_EXPLICIT_RECURSIVE_DEPTH) {
|
|
3013
|
-
throw new
|
|
3013
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3014
3014
|
`Recursive traversal maxHops(${vl.maxDepth}) exceeds maximum explicit depth of ${MAX_EXPLICIT_RECURSIVE_DEPTH}`
|
|
3015
3015
|
);
|
|
3016
3016
|
}
|
|
@@ -3237,7 +3237,7 @@ function compileRecursiveSelectiveProjection(fields, ast, traversal, dialect) {
|
|
|
3237
3237
|
const allowedAliases = /* @__PURE__ */ new Set([ast.start.alias, traversal.nodeAlias]);
|
|
3238
3238
|
const columns = fields.map((field2) => {
|
|
3239
3239
|
if (!allowedAliases.has(field2.alias)) {
|
|
3240
|
-
throw new
|
|
3240
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3241
3241
|
`Selective projection for recursive traversals does not support alias "${field2.alias}"`
|
|
3242
3242
|
);
|
|
3243
3243
|
}
|
|
@@ -3271,7 +3271,7 @@ function compileRecursiveOrderBy(ast, dialect) {
|
|
|
3271
3271
|
for (const orderSpec of ast.orderBy) {
|
|
3272
3272
|
const valueType = orderSpec.field.valueType;
|
|
3273
3273
|
if (valueType === "array" || valueType === "object") {
|
|
3274
|
-
throw new
|
|
3274
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3275
3275
|
"Ordering by JSON arrays or objects is not supported"
|
|
3276
3276
|
);
|
|
3277
3277
|
}
|
|
@@ -3305,15 +3305,15 @@ var MAX_IDENTIFIER_LENGTH = 63;
|
|
|
3305
3305
|
var VALID_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/i;
|
|
3306
3306
|
function validateTableName(name, label) {
|
|
3307
3307
|
if (!name || name.length === 0) {
|
|
3308
|
-
throw new
|
|
3308
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(`${label} table name cannot be empty`);
|
|
3309
3309
|
}
|
|
3310
3310
|
if (name.length > MAX_IDENTIFIER_LENGTH) {
|
|
3311
|
-
throw new
|
|
3311
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
3312
3312
|
`${label} table name exceeds maximum length of ${MAX_IDENTIFIER_LENGTH} characters`
|
|
3313
3313
|
);
|
|
3314
3314
|
}
|
|
3315
3315
|
if (!VALID_IDENTIFIER_PATTERN.test(name)) {
|
|
3316
|
-
throw new
|
|
3316
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
3317
3317
|
`${label} table name "${name}" is not a valid SQL identifier. Table names must start with a letter or underscore and contain only letters, digits, underscores, or dollar signs.`
|
|
3318
3318
|
);
|
|
3319
3319
|
}
|
|
@@ -3392,7 +3392,7 @@ function compileSetOperation(op, graphId, dialect, schema, compileQuery2) {
|
|
|
3392
3392
|
const passState = runSetOperationPassPipeline(op, graphId, dialect);
|
|
3393
3393
|
const { logicalPlan } = passState;
|
|
3394
3394
|
if (logicalPlan === void 0) {
|
|
3395
|
-
throw new
|
|
3395
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
3396
3396
|
"Logical plan pass did not initialize plan state"
|
|
3397
3397
|
);
|
|
3398
3398
|
}
|
|
@@ -3456,7 +3456,7 @@ function compileSetOperationForSqlite(op, graphId, dialect, logicalPlan, schema)
|
|
|
3456
3456
|
dialect,
|
|
3457
3457
|
schema,
|
|
3458
3458
|
compileQuery: () => {
|
|
3459
|
-
throw new
|
|
3459
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
3460
3460
|
"compileQuery is not available in set-operation CTE compilation"
|
|
3461
3461
|
);
|
|
3462
3462
|
}
|
|
@@ -3508,7 +3508,7 @@ function validateSqliteSetOpLeaf(ast) {
|
|
|
3508
3508
|
unsupported.push("per-query OFFSET (use set operation's offset instead)");
|
|
3509
3509
|
}
|
|
3510
3510
|
if (unsupported.length > 0) {
|
|
3511
|
-
throw new
|
|
3511
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3512
3512
|
`SQLite set operations (UNION/INTERSECT/EXCEPT) do not support: ${unsupported.join(", ")}. Use PostgreSQL for complex set operations, or refactor to separate queries.`
|
|
3513
3513
|
);
|
|
3514
3514
|
}
|
|
@@ -3666,7 +3666,7 @@ function compileFieldValueForSetOp(source, prefix, alias, dialect) {
|
|
|
3666
3666
|
return drizzleOrm.sql`${drizzleOrm.sql.raw(fn.toUpperCase())}(${column})`;
|
|
3667
3667
|
}
|
|
3668
3668
|
default: {
|
|
3669
|
-
throw new
|
|
3669
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
3670
3670
|
`Unknown aggregate function: ${String(fn)}`
|
|
3671
3671
|
);
|
|
3672
3672
|
}
|
|
@@ -3719,7 +3719,7 @@ function buildCompoundSelectRecursive(query, leaves, prefixToSelect) {
|
|
|
3719
3719
|
if (!("__type" in query)) {
|
|
3720
3720
|
const leaf = leaves.find((l) => l.ast === query);
|
|
3721
3721
|
if (!leaf) {
|
|
3722
|
-
throw new
|
|
3722
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError("Leaf query not found in leaves array");
|
|
3723
3723
|
}
|
|
3724
3724
|
return prefixToSelect.get(leaf.prefix);
|
|
3725
3725
|
}
|
|
@@ -3763,7 +3763,7 @@ function buildSetOperationSuffixClauses(op, dialect) {
|
|
|
3763
3763
|
if (op.orderBy && op.orderBy.length > 0) {
|
|
3764
3764
|
const projection = getLeftmostProjection(op);
|
|
3765
3765
|
if (projection.fields.length === 0) {
|
|
3766
|
-
throw new
|
|
3766
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3767
3767
|
"Set operation ORDER BY requires explicit field projection. SELECT * does not provide stable output column names for ordering. Use .select() to specify which fields to project."
|
|
3768
3768
|
);
|
|
3769
3769
|
}
|
|
@@ -3773,7 +3773,7 @@ function buildSetOperationSuffixClauses(op, dialect) {
|
|
|
3773
3773
|
if (!projected) {
|
|
3774
3774
|
const fieldDesc = o.field.jsonPointer ? `${o.field.alias}.props${o.field.jsonPointer}` : `${o.field.alias}.${o.field.path.join(".")}`;
|
|
3775
3775
|
const availableFields = projection.fields.map((f) => f.outputName).join(", ");
|
|
3776
|
-
throw new
|
|
3776
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
3777
3777
|
`Set operation ORDER BY field "${fieldDesc}" is not in the projection. ORDER BY for UNION/INTERSECT/EXCEPT must reference projected columns. Available columns: ${availableFields}`
|
|
3778
3778
|
);
|
|
3779
3779
|
}
|
|
@@ -4382,13 +4382,13 @@ function compileStandardQueryWithCteStrategy(ast, graphId, ctx) {
|
|
|
4382
4382
|
vectorPredicate
|
|
4383
4383
|
} = runStandardQueryPassPipeline(ast, graphId, ctx);
|
|
4384
4384
|
if (temporalFilterPass === void 0) {
|
|
4385
|
-
throw new
|
|
4385
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
4386
4386
|
"Temporal filter pass did not initialize temporal state",
|
|
4387
4387
|
{ phase: "standard-pass-pipeline" }
|
|
4388
4388
|
);
|
|
4389
4389
|
}
|
|
4390
4390
|
if (logicalPlan === void 0) {
|
|
4391
|
-
throw new
|
|
4391
|
+
throw new chunk44SXEVF4_cjs.CompilerInvariantError(
|
|
4392
4392
|
"Logical plan pass did not initialize plan state",
|
|
4393
4393
|
{ phase: "standard-pass-pipeline" }
|
|
4394
4394
|
);
|
|
@@ -4489,7 +4489,7 @@ function decodeCursor(cursor) {
|
|
|
4489
4489
|
const json = atob(base64);
|
|
4490
4490
|
const raw = JSON.parse(json);
|
|
4491
4491
|
if (typeof raw.v !== "number" || raw.v > CURSOR_VERSION) {
|
|
4492
|
-
throw new
|
|
4492
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
4493
4493
|
`Unsupported cursor version: ${String(raw.v)}. Maximum supported: ${CURSOR_VERSION}`,
|
|
4494
4494
|
{
|
|
4495
4495
|
issues: [
|
|
@@ -4505,7 +4505,7 @@ function decodeCursor(cursor) {
|
|
|
4505
4505
|
);
|
|
4506
4506
|
}
|
|
4507
4507
|
if (raw.d !== "f" && raw.d !== "b") {
|
|
4508
|
-
throw new
|
|
4508
|
+
throw new chunk44SXEVF4_cjs.ValidationError(`Invalid cursor direction: ${String(raw.d)}`, {
|
|
4509
4509
|
issues: [
|
|
4510
4510
|
{
|
|
4511
4511
|
path: "cursor",
|
|
@@ -4515,7 +4515,7 @@ function decodeCursor(cursor) {
|
|
|
4515
4515
|
});
|
|
4516
4516
|
}
|
|
4517
4517
|
if (!Array.isArray(raw.vals) || !Array.isArray(raw.cols)) {
|
|
4518
|
-
throw new
|
|
4518
|
+
throw new chunk44SXEVF4_cjs.ValidationError("Invalid cursor structure", {
|
|
4519
4519
|
issues: [
|
|
4520
4520
|
{
|
|
4521
4521
|
path: "cursor",
|
|
@@ -4525,7 +4525,7 @@ function decodeCursor(cursor) {
|
|
|
4525
4525
|
});
|
|
4526
4526
|
}
|
|
4527
4527
|
if (raw.vals.length !== raw.cols.length) {
|
|
4528
|
-
throw new
|
|
4528
|
+
throw new chunk44SXEVF4_cjs.ValidationError("Cursor column count mismatch", {
|
|
4529
4529
|
issues: [
|
|
4530
4530
|
{
|
|
4531
4531
|
path: "cursor",
|
|
@@ -4541,10 +4541,10 @@ function decodeCursor(cursor) {
|
|
|
4541
4541
|
cols: raw.cols
|
|
4542
4542
|
};
|
|
4543
4543
|
} catch (error) {
|
|
4544
|
-
if (error instanceof
|
|
4544
|
+
if (error instanceof chunk44SXEVF4_cjs.ValidationError) {
|
|
4545
4545
|
throw error;
|
|
4546
4546
|
}
|
|
4547
|
-
throw new
|
|
4547
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
4548
4548
|
"Invalid cursor format",
|
|
4549
4549
|
{
|
|
4550
4550
|
issues: [{ path: "cursor", message: "Failed to decode cursor" }]
|
|
@@ -4608,7 +4608,7 @@ function buildCursorFromRow(row, orderSpecs, direction) {
|
|
|
4608
4608
|
function validateCursorColumns(cursorData, orderSpecs) {
|
|
4609
4609
|
const expectedCols = orderSpecs.map((spec) => buildColumnId(spec));
|
|
4610
4610
|
if (cursorData.cols.length !== expectedCols.length) {
|
|
4611
|
-
throw new
|
|
4611
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
4612
4612
|
`Cursor has ${cursorData.cols.length} columns but query has ${expectedCols.length} ORDER BY columns`,
|
|
4613
4613
|
{
|
|
4614
4614
|
issues: [
|
|
@@ -4625,7 +4625,7 @@ function validateCursorColumns(cursorData, orderSpecs) {
|
|
|
4625
4625
|
}
|
|
4626
4626
|
for (const [index, expectedCol] of expectedCols.entries()) {
|
|
4627
4627
|
if (cursorData.cols[index] !== expectedCol) {
|
|
4628
|
-
throw new
|
|
4628
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
4629
4629
|
`Cursor column mismatch at position ${index}: expected "${expectedCol}", got "${cursorData.cols[index]}"`,
|
|
4630
4630
|
{
|
|
4631
4631
|
issues: [
|
|
@@ -5488,7 +5488,7 @@ var SQL_RESERVED_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
5488
5488
|
]);
|
|
5489
5489
|
function validateSqlIdentifier(alias) {
|
|
5490
5490
|
if (!SQL_IDENTIFIER_PATTERN.test(alias)) {
|
|
5491
|
-
throw new
|
|
5491
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
5492
5492
|
`Invalid alias "${alias}": must start with a letter or underscore, contain only letters, digits, and underscores, and be at most 63 characters`,
|
|
5493
5493
|
{
|
|
5494
5494
|
issues: [
|
|
@@ -5504,7 +5504,7 @@ function validateSqlIdentifier(alias) {
|
|
|
5504
5504
|
);
|
|
5505
5505
|
}
|
|
5506
5506
|
if (alias.toLowerCase().startsWith("cte_")) {
|
|
5507
|
-
throw new
|
|
5507
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
5508
5508
|
`Invalid alias "${alias}": aliases starting with "cte_" are reserved for internal use`,
|
|
5509
5509
|
{
|
|
5510
5510
|
issues: [
|
|
@@ -5520,7 +5520,7 @@ function validateSqlIdentifier(alias) {
|
|
|
5520
5520
|
);
|
|
5521
5521
|
}
|
|
5522
5522
|
if (SQL_RESERVED_KEYWORDS.has(alias.toLowerCase())) {
|
|
5523
|
-
throw new
|
|
5523
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
5524
5524
|
`Invalid alias "${alias}": "${alias}" is a reserved SQL keyword`,
|
|
5525
5525
|
{
|
|
5526
5526
|
issues: [
|
|
@@ -5534,7 +5534,7 @@ function validateSqlIdentifier(alias) {
|
|
|
5534
5534
|
}
|
|
5535
5535
|
}
|
|
5536
5536
|
function throwInvalidVectorPredicatePlacement(path) {
|
|
5537
|
-
throw new
|
|
5537
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
5538
5538
|
"Vector similarity predicates cannot be nested under OR or NOT. Use top-level AND combinations instead.",
|
|
5539
5539
|
{
|
|
5540
5540
|
issues: [
|
|
@@ -5645,7 +5645,7 @@ function buildQueryAst(config, state) {
|
|
|
5645
5645
|
}
|
|
5646
5646
|
function toLiteral(value) {
|
|
5647
5647
|
if (value === null) {
|
|
5648
|
-
throw new
|
|
5648
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5649
5649
|
"Parameter value must not be null (use undefined-based patterns instead)",
|
|
5650
5650
|
{ parameterName: "value", valueType: "null" }
|
|
5651
5651
|
);
|
|
@@ -5662,7 +5662,7 @@ function toLiteral(value) {
|
|
|
5662
5662
|
if (typeof value === "boolean") {
|
|
5663
5663
|
return { __type: "literal", value, valueType: "boolean" };
|
|
5664
5664
|
}
|
|
5665
|
-
throw new
|
|
5665
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5666
5666
|
`Unsupported parameter value type: ${typeof value}`,
|
|
5667
5667
|
{ parameterName: "value", actualType: typeof value }
|
|
5668
5668
|
);
|
|
@@ -5673,7 +5673,7 @@ function substitutePredicateExpression(expr, bindings) {
|
|
|
5673
5673
|
if (isParameterRef(expr.right)) {
|
|
5674
5674
|
const value = bindings[expr.right.name];
|
|
5675
5675
|
if (value === void 0) {
|
|
5676
|
-
throw new
|
|
5676
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5677
5677
|
`Missing binding for parameter "${expr.right.name}"`,
|
|
5678
5678
|
{ parameterName: expr.right.name }
|
|
5679
5679
|
);
|
|
@@ -5689,13 +5689,13 @@ function substitutePredicateExpression(expr, bindings) {
|
|
|
5689
5689
|
if (isParameterRef(expr.pattern)) {
|
|
5690
5690
|
const value = bindings[expr.pattern.name];
|
|
5691
5691
|
if (value === void 0) {
|
|
5692
|
-
throw new
|
|
5692
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5693
5693
|
`Missing binding for parameter "${expr.pattern.name}"`,
|
|
5694
5694
|
{ parameterName: expr.pattern.name }
|
|
5695
5695
|
);
|
|
5696
5696
|
}
|
|
5697
5697
|
if (typeof value !== "string") {
|
|
5698
|
-
throw new
|
|
5698
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5699
5699
|
`Parameter "${expr.pattern.name}" must be a string for string operations`,
|
|
5700
5700
|
{ parameterName: expr.pattern.name, actualType: typeof value }
|
|
5701
5701
|
);
|
|
@@ -5762,7 +5762,7 @@ function substitutePredicateExpression(expr, bindings) {
|
|
|
5762
5762
|
function resolveBinding(bindings, name) {
|
|
5763
5763
|
const value = bindings[name];
|
|
5764
5764
|
if (value === void 0) {
|
|
5765
|
-
throw new
|
|
5765
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(`Missing binding for parameter "${name}"`, {
|
|
5766
5766
|
parameterName: name
|
|
5767
5767
|
});
|
|
5768
5768
|
}
|
|
@@ -5787,7 +5787,7 @@ function fillPlaceholders(params, bindings, dialect) {
|
|
|
5787
5787
|
const name = parameter.name;
|
|
5788
5788
|
const value = bindings[name];
|
|
5789
5789
|
if (value === void 0) {
|
|
5790
|
-
throw new
|
|
5790
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
5791
5791
|
`Missing binding for parameter "${name}"`,
|
|
5792
5792
|
{ parameterName: name }
|
|
5793
5793
|
);
|
|
@@ -5854,7 +5854,7 @@ var PreparedQuery = class {
|
|
|
5854
5854
|
this.#selectFn
|
|
5855
5855
|
);
|
|
5856
5856
|
} catch (error) {
|
|
5857
|
-
if (error instanceof MissingSelectiveFieldError || error instanceof
|
|
5857
|
+
if (error instanceof MissingSelectiveFieldError || error instanceof chunk44SXEVF4_cjs.UnsupportedPredicateError) {
|
|
5858
5858
|
return this.#executeUnoptimized(bindings);
|
|
5859
5859
|
}
|
|
5860
5860
|
throw error;
|
|
@@ -6024,7 +6024,7 @@ function validateBindings(bindings, metadata) {
|
|
|
6024
6024
|
}
|
|
6025
6025
|
}
|
|
6026
6026
|
if (missing.length > 0) {
|
|
6027
|
-
throw new
|
|
6027
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
6028
6028
|
`Missing bindings for parameter${missing.length === 1 ? "" : "s"}: ${missing.map((name) => `"${name}"`).join(", ")}`,
|
|
6029
6029
|
{ missingParameters: missing }
|
|
6030
6030
|
);
|
|
@@ -6033,7 +6033,7 @@ function validateBindings(bindings, metadata) {
|
|
|
6033
6033
|
(name) => !expectedNames.has(name)
|
|
6034
6034
|
);
|
|
6035
6035
|
if (unexpected.length > 0) {
|
|
6036
|
-
throw new
|
|
6036
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
6037
6037
|
`Unexpected bindings provided: ${unexpected.map((name) => `"${name}"`).join(", ")}`,
|
|
6038
6038
|
{ unexpectedParameters: unexpected }
|
|
6039
6039
|
);
|
|
@@ -6045,14 +6045,14 @@ function validateBindings(bindings, metadata) {
|
|
|
6045
6045
|
}
|
|
6046
6046
|
function validateBindingValue(name, value, isStringOp) {
|
|
6047
6047
|
if (value === null) {
|
|
6048
|
-
throw new
|
|
6048
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
6049
6049
|
"Parameter value must not be null (use undefined-based patterns instead)",
|
|
6050
6050
|
{ parameterName: name, valueType: "null" }
|
|
6051
6051
|
);
|
|
6052
6052
|
}
|
|
6053
6053
|
if (isStringOp) {
|
|
6054
6054
|
if (typeof value !== "string") {
|
|
6055
|
-
throw new
|
|
6055
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
6056
6056
|
`Parameter "${name}" must be a string for string operations`,
|
|
6057
6057
|
{ parameterName: name, actualType: typeof value }
|
|
6058
6058
|
);
|
|
@@ -6062,7 +6062,7 @@ function validateBindingValue(name, value, isStringOp) {
|
|
|
6062
6062
|
if (value instanceof Date || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
6063
6063
|
return;
|
|
6064
6064
|
}
|
|
6065
|
-
throw new
|
|
6065
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
6066
6066
|
`Unsupported parameter value type: ${typeof value}`,
|
|
6067
6067
|
{ parameterName: name, actualType: typeof value }
|
|
6068
6068
|
);
|
|
@@ -6421,7 +6421,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6421
6421
|
this.#cachedOptimizedCompiled = NOT_COMPUTED;
|
|
6422
6422
|
return void 0;
|
|
6423
6423
|
}
|
|
6424
|
-
if (error instanceof
|
|
6424
|
+
if (error instanceof chunk44SXEVF4_cjs.UnsupportedPredicateError) {
|
|
6425
6425
|
this.#cachedSelectiveFieldsForExecute = void 0;
|
|
6426
6426
|
this.#cachedOptimizedCompiled = NOT_COMPUTED;
|
|
6427
6427
|
return void 0;
|
|
@@ -6555,7 +6555,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6555
6555
|
selectiveFields
|
|
6556
6556
|
});
|
|
6557
6557
|
} catch (error) {
|
|
6558
|
-
if (error instanceof
|
|
6558
|
+
if (error instanceof chunk44SXEVF4_cjs.UnsupportedPredicateError) {
|
|
6559
6559
|
this.#cachedSelectiveFieldsForPagination = void 0;
|
|
6560
6560
|
return void 0;
|
|
6561
6561
|
}
|
|
@@ -6581,7 +6581,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6581
6581
|
this.#cachedSelectiveFieldsForPagination = void 0;
|
|
6582
6582
|
return void 0;
|
|
6583
6583
|
}
|
|
6584
|
-
if (error instanceof
|
|
6584
|
+
if (error instanceof chunk44SXEVF4_cjs.UnsupportedPredicateError) {
|
|
6585
6585
|
this.#cachedSelectiveFieldsForPagination = void 0;
|
|
6586
6586
|
return void 0;
|
|
6587
6587
|
}
|
|
@@ -6606,7 +6606,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6606
6606
|
this.#cachedSelectiveFieldsForPagination = void 0;
|
|
6607
6607
|
return void 0;
|
|
6608
6608
|
}
|
|
6609
|
-
if (error instanceof
|
|
6609
|
+
if (error instanceof chunk44SXEVF4_cjs.UnsupportedPredicateError) {
|
|
6610
6610
|
this.#cachedSelectiveFieldsForPagination = void 0;
|
|
6611
6611
|
return void 0;
|
|
6612
6612
|
}
|
|
@@ -6744,7 +6744,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6744
6744
|
);
|
|
6745
6745
|
}
|
|
6746
6746
|
if (this.#state.orderBy.length === 0) {
|
|
6747
|
-
throw new
|
|
6747
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
6748
6748
|
"Cursor pagination requires ORDER BY. Add .orderBy() before .paginate()",
|
|
6749
6749
|
{
|
|
6750
6750
|
issues: [
|
|
@@ -6820,7 +6820,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6820
6820
|
*/
|
|
6821
6821
|
stream(options) {
|
|
6822
6822
|
if (this.#state.orderBy.length === 0) {
|
|
6823
|
-
throw new
|
|
6823
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
6824
6824
|
"Streaming requires ORDER BY. Add .orderBy() before .stream()",
|
|
6825
6825
|
{
|
|
6826
6826
|
issues: [
|
|
@@ -7591,7 +7591,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
7591
7591
|
*/
|
|
7592
7592
|
temporal(mode, asOf) {
|
|
7593
7593
|
if (mode === "asOf" && asOf === void 0) {
|
|
7594
|
-
throw new
|
|
7594
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
7595
7595
|
'Temporal mode "asOf" requires a timestamp',
|
|
7596
7596
|
{
|
|
7597
7597
|
issues: [
|
|
@@ -8247,12 +8247,12 @@ function createQueryBuilder(graphId, registry, options) {
|
|
|
8247
8247
|
function buildKindRegistry(graph) {
|
|
8248
8248
|
const nodeTypes = extractNodeTypes(graph);
|
|
8249
8249
|
const edgeTypes = extractEdgeTypes(graph);
|
|
8250
|
-
const closures = graph.ontology.length > 0 ?
|
|
8251
|
-
return new
|
|
8250
|
+
const closures = graph.ontology.length > 0 ? chunkLDM2AFKZ_cjs.computeClosuresFromOntology(graph.ontology) : chunkLDM2AFKZ_cjs.createEmptyClosures();
|
|
8251
|
+
return new chunkLDM2AFKZ_cjs.KindRegistry(nodeTypes, edgeTypes, closures);
|
|
8252
8252
|
}
|
|
8253
8253
|
function extractNodeTypes(graph) {
|
|
8254
8254
|
const result = /* @__PURE__ */ new Map();
|
|
8255
|
-
for (const typeName of
|
|
8255
|
+
for (const typeName of chunkK2ROKOK3_cjs.getNodeKinds(graph)) {
|
|
8256
8256
|
const registration = graph.nodes[typeName];
|
|
8257
8257
|
result.set(typeName, registration.type);
|
|
8258
8258
|
}
|
|
@@ -8260,7 +8260,7 @@ function extractNodeTypes(graph) {
|
|
|
8260
8260
|
}
|
|
8261
8261
|
function extractEdgeTypes(graph) {
|
|
8262
8262
|
const result = /* @__PURE__ */ new Map();
|
|
8263
|
-
for (const typeName of
|
|
8263
|
+
for (const typeName of chunkK2ROKOK3_cjs.getEdgeKinds(graph)) {
|
|
8264
8264
|
const registration = graph.edges[typeName];
|
|
8265
8265
|
result.set(typeName, registration.type);
|
|
8266
8266
|
}
|
|
@@ -8393,7 +8393,7 @@ function createEdgeCollection(config) {
|
|
|
8393
8393
|
async find(options) {
|
|
8394
8394
|
const untypedOptions = options;
|
|
8395
8395
|
if (untypedOptions?.where !== void 0) {
|
|
8396
|
-
throw new
|
|
8396
|
+
throw new chunk44SXEVF4_cjs.UnsupportedPredicateError(
|
|
8397
8397
|
`store.edges.${kind}.find({ where }) is not supported. Use store.query().traverse(...).whereEdge(...) for edge property filters.`,
|
|
8398
8398
|
{ kind, operation: "find" }
|
|
8399
8399
|
);
|
|
@@ -8406,7 +8406,7 @@ function createEdgeCollection(config) {
|
|
|
8406
8406
|
temporalMode: mode
|
|
8407
8407
|
};
|
|
8408
8408
|
if (mode === "current" || mode === "asOf") {
|
|
8409
|
-
params.asOf = options?.asOf ??
|
|
8409
|
+
params.asOf = options?.asOf ?? chunkK2ROKOK3_cjs.nowIso();
|
|
8410
8410
|
}
|
|
8411
8411
|
if (options?.from?.kind !== void 0)
|
|
8412
8412
|
params.fromKind = options.from.kind;
|
|
@@ -8427,7 +8427,7 @@ function createEdgeCollection(config) {
|
|
|
8427
8427
|
temporalMode: mode
|
|
8428
8428
|
};
|
|
8429
8429
|
if (mode === "current" || mode === "asOf") {
|
|
8430
|
-
params.asOf = options?.asOf ??
|
|
8430
|
+
params.asOf = options?.asOf ?? chunkK2ROKOK3_cjs.nowIso();
|
|
8431
8431
|
}
|
|
8432
8432
|
if (options?.from?.kind !== void 0)
|
|
8433
8433
|
params.fromKind = options.from.kind;
|
|
@@ -8450,7 +8450,7 @@ function createEdgeCollection(config) {
|
|
|
8450
8450
|
const results = await executeEdgeCreateBatch2(batchInputs, backend);
|
|
8451
8451
|
return narrowEdges(results);
|
|
8452
8452
|
},
|
|
8453
|
-
async
|
|
8453
|
+
async bulkUpsertById(items) {
|
|
8454
8454
|
if (items.length === 0) return [];
|
|
8455
8455
|
const upsertAll = async (target) => {
|
|
8456
8456
|
const ids = items.map((item) => item.id);
|
|
@@ -8476,7 +8476,7 @@ function createEdgeCollection(config) {
|
|
|
8476
8476
|
if (existing) {
|
|
8477
8477
|
const input = {
|
|
8478
8478
|
id: item.id,
|
|
8479
|
-
props: item.props
|
|
8479
|
+
props: item.props
|
|
8480
8480
|
};
|
|
8481
8481
|
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8482
8482
|
toUpdate.push({
|
|
@@ -8492,7 +8492,7 @@ function createEdgeCollection(config) {
|
|
|
8492
8492
|
fromId: item.from.id,
|
|
8493
8493
|
toKind: item.to.kind,
|
|
8494
8494
|
toId: item.to.id,
|
|
8495
|
-
props: item.props
|
|
8495
|
+
props: item.props
|
|
8496
8496
|
};
|
|
8497
8497
|
if (item.validFrom !== void 0) input.validFrom = item.validFrom;
|
|
8498
8498
|
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
@@ -8546,6 +8546,74 @@ function createEdgeCollection(config) {
|
|
|
8546
8546
|
return;
|
|
8547
8547
|
}
|
|
8548
8548
|
await deleteAll(backend);
|
|
8549
|
+
},
|
|
8550
|
+
async findByEndpoints(from, to, options) {
|
|
8551
|
+
const findOptions = {};
|
|
8552
|
+
if (options?.matchOn !== void 0)
|
|
8553
|
+
findOptions.matchOn = options.matchOn;
|
|
8554
|
+
if (options?.props !== void 0)
|
|
8555
|
+
findOptions.props = options.props;
|
|
8556
|
+
const result = await config.executeFindByEndpoints(
|
|
8557
|
+
kind,
|
|
8558
|
+
from.kind,
|
|
8559
|
+
from.id,
|
|
8560
|
+
to.kind,
|
|
8561
|
+
to.id,
|
|
8562
|
+
backend,
|
|
8563
|
+
findOptions
|
|
8564
|
+
);
|
|
8565
|
+
return result === void 0 ? void 0 : narrowEdge(result);
|
|
8566
|
+
},
|
|
8567
|
+
async getOrCreateByEndpoints(from, to, props, options) {
|
|
8568
|
+
const getOrCreateOptions = {};
|
|
8569
|
+
if (options?.matchOn !== void 0)
|
|
8570
|
+
getOrCreateOptions.matchOn = options.matchOn;
|
|
8571
|
+
if (options?.ifExists !== void 0)
|
|
8572
|
+
getOrCreateOptions.ifExists = options.ifExists;
|
|
8573
|
+
const result = await config.executeGetOrCreateByEndpoints(
|
|
8574
|
+
kind,
|
|
8575
|
+
from.kind,
|
|
8576
|
+
from.id,
|
|
8577
|
+
to.kind,
|
|
8578
|
+
to.id,
|
|
8579
|
+
props,
|
|
8580
|
+
backend,
|
|
8581
|
+
getOrCreateOptions
|
|
8582
|
+
);
|
|
8583
|
+
return { edge: narrowEdge(result.edge), action: result.action };
|
|
8584
|
+
},
|
|
8585
|
+
async bulkGetOrCreateByEndpoints(items, options) {
|
|
8586
|
+
if (items.length === 0) return [];
|
|
8587
|
+
const mappedItems = items.map((item) => ({
|
|
8588
|
+
fromKind: item.from.kind,
|
|
8589
|
+
fromId: item.from.id,
|
|
8590
|
+
toKind: item.to.kind,
|
|
8591
|
+
toId: item.to.id,
|
|
8592
|
+
props: item.props
|
|
8593
|
+
}));
|
|
8594
|
+
const getOrCreateOptions = {};
|
|
8595
|
+
if (options?.matchOn !== void 0)
|
|
8596
|
+
getOrCreateOptions.matchOn = options.matchOn;
|
|
8597
|
+
if (options?.ifExists !== void 0)
|
|
8598
|
+
getOrCreateOptions.ifExists = options.ifExists;
|
|
8599
|
+
const getOrCreateAll = async (target) => {
|
|
8600
|
+
const results = await config.executeBulkGetOrCreateByEndpoints(
|
|
8601
|
+
kind,
|
|
8602
|
+
mappedItems,
|
|
8603
|
+
target,
|
|
8604
|
+
getOrCreateOptions
|
|
8605
|
+
);
|
|
8606
|
+
return results.map((result) => ({
|
|
8607
|
+
edge: narrowEdge(result.edge),
|
|
8608
|
+
action: result.action
|
|
8609
|
+
}));
|
|
8610
|
+
};
|
|
8611
|
+
if (backend.capabilities.transactions && "transaction" in backend) {
|
|
8612
|
+
return backend.transaction(
|
|
8613
|
+
async (txBackend) => getOrCreateAll(txBackend)
|
|
8614
|
+
);
|
|
8615
|
+
}
|
|
8616
|
+
return getOrCreateAll(backend);
|
|
8549
8617
|
}
|
|
8550
8618
|
};
|
|
8551
8619
|
}
|
|
@@ -8584,7 +8652,11 @@ function createNodeCollection(config) {
|
|
|
8584
8652
|
executeDelete: executeNodeDelete2,
|
|
8585
8653
|
executeHardDelete: executeNodeHardDelete2,
|
|
8586
8654
|
matchesTemporalMode,
|
|
8587
|
-
createQuery
|
|
8655
|
+
createQuery,
|
|
8656
|
+
executeGetOrCreateByConstraint,
|
|
8657
|
+
executeBulkGetOrCreateByConstraint,
|
|
8658
|
+
executeFindByConstraint,
|
|
8659
|
+
executeBulkFindByConstraint
|
|
8588
8660
|
} = config;
|
|
8589
8661
|
return {
|
|
8590
8662
|
async create(props, options) {
|
|
@@ -8650,7 +8722,7 @@ function createNodeCollection(config) {
|
|
|
8650
8722
|
},
|
|
8651
8723
|
async find(options) {
|
|
8652
8724
|
if (options?.where !== void 0 && createQuery === void 0) {
|
|
8653
|
-
throw new
|
|
8725
|
+
throw new chunk44SXEVF4_cjs.ConfigurationError(
|
|
8654
8726
|
`store.nodes.${kind}.find({ where }) requires a query-capable store`,
|
|
8655
8727
|
{ kind, operation: "find" }
|
|
8656
8728
|
);
|
|
@@ -8659,7 +8731,7 @@ function createNodeCollection(config) {
|
|
|
8659
8731
|
const mode2 = options.temporalMode ?? defaultTemporalMode;
|
|
8660
8732
|
let query = createQuery().from(kind, "_n").temporal(
|
|
8661
8733
|
mode2,
|
|
8662
|
-
mode2 === "asOf" ? options.asOf ??
|
|
8734
|
+
mode2 === "asOf" ? options.asOf ?? chunkK2ROKOK3_cjs.nowIso() : void 0
|
|
8663
8735
|
).whereNode("_n", options.where).select((ctx) => ctx._n);
|
|
8664
8736
|
if (options.limit !== void 0) query = query.limit(options.limit);
|
|
8665
8737
|
if (options.offset !== void 0) query = query.offset(options.offset);
|
|
@@ -8674,7 +8746,7 @@ function createNodeCollection(config) {
|
|
|
8674
8746
|
temporalMode: mode
|
|
8675
8747
|
};
|
|
8676
8748
|
if (mode === "current" || mode === "asOf") {
|
|
8677
|
-
params.asOf = options?.asOf ??
|
|
8749
|
+
params.asOf = options?.asOf ?? chunkK2ROKOK3_cjs.nowIso();
|
|
8678
8750
|
}
|
|
8679
8751
|
if (options?.limit !== void 0) params.limit = options.limit;
|
|
8680
8752
|
if (options?.offset !== void 0) params.offset = options.offset;
|
|
@@ -8690,11 +8762,11 @@ function createNodeCollection(config) {
|
|
|
8690
8762
|
temporalMode: mode
|
|
8691
8763
|
};
|
|
8692
8764
|
if (mode === "current" || mode === "asOf") {
|
|
8693
|
-
params.asOf = options?.asOf ??
|
|
8765
|
+
params.asOf = options?.asOf ?? chunkK2ROKOK3_cjs.nowIso();
|
|
8694
8766
|
}
|
|
8695
8767
|
return backend.countNodesByKind(params);
|
|
8696
8768
|
},
|
|
8697
|
-
async
|
|
8769
|
+
async upsertById(id, props, options) {
|
|
8698
8770
|
const existing = await backend.getNode(graphId, kind, id);
|
|
8699
8771
|
if (existing) {
|
|
8700
8772
|
const input = {
|
|
@@ -8735,7 +8807,7 @@ function createNodeCollection(config) {
|
|
|
8735
8807
|
const results = await executeNodeCreateBatch2(batchInputs, backend);
|
|
8736
8808
|
return narrowNodes(results);
|
|
8737
8809
|
},
|
|
8738
|
-
async
|
|
8810
|
+
async bulkUpsertById(items) {
|
|
8739
8811
|
if (items.length === 0) return [];
|
|
8740
8812
|
const upsertAll = async (target) => {
|
|
8741
8813
|
const ids = items.map((item) => item.id);
|
|
@@ -8832,6 +8904,68 @@ function createNodeCollection(config) {
|
|
|
8832
8904
|
return;
|
|
8833
8905
|
}
|
|
8834
8906
|
await deleteAll(backend);
|
|
8907
|
+
},
|
|
8908
|
+
async findByConstraint(constraintName, props) {
|
|
8909
|
+
const result = await executeFindByConstraint(
|
|
8910
|
+
kind,
|
|
8911
|
+
constraintName,
|
|
8912
|
+
props,
|
|
8913
|
+
backend
|
|
8914
|
+
);
|
|
8915
|
+
return result === void 0 ? void 0 : narrowNode(result);
|
|
8916
|
+
},
|
|
8917
|
+
async bulkFindByConstraint(constraintName, items) {
|
|
8918
|
+
if (items.length === 0) return [];
|
|
8919
|
+
const mappedItems = items.map((item) => ({
|
|
8920
|
+
props: item.props
|
|
8921
|
+
}));
|
|
8922
|
+
const results = await executeBulkFindByConstraint(
|
|
8923
|
+
kind,
|
|
8924
|
+
constraintName,
|
|
8925
|
+
mappedItems,
|
|
8926
|
+
backend
|
|
8927
|
+
);
|
|
8928
|
+
return results.map(
|
|
8929
|
+
(result) => result === void 0 ? void 0 : narrowNode(result)
|
|
8930
|
+
);
|
|
8931
|
+
},
|
|
8932
|
+
async getOrCreateByConstraint(constraintName, props, options) {
|
|
8933
|
+
const execute = async (target) => {
|
|
8934
|
+
const result = await executeGetOrCreateByConstraint(
|
|
8935
|
+
kind,
|
|
8936
|
+
constraintName,
|
|
8937
|
+
props,
|
|
8938
|
+
target,
|
|
8939
|
+
options
|
|
8940
|
+
);
|
|
8941
|
+
return result;
|
|
8942
|
+
};
|
|
8943
|
+
if (backend.capabilities.transactions && "transaction" in backend) {
|
|
8944
|
+
return backend.transaction(async (txBackend) => execute(txBackend));
|
|
8945
|
+
}
|
|
8946
|
+
return execute(backend);
|
|
8947
|
+
},
|
|
8948
|
+
async bulkGetOrCreateByConstraint(constraintName, items, options) {
|
|
8949
|
+
if (items.length === 0) return [];
|
|
8950
|
+
const mappedItems = items.map((item) => ({
|
|
8951
|
+
props: item.props
|
|
8952
|
+
}));
|
|
8953
|
+
const getOrCreateAll = async (target) => {
|
|
8954
|
+
const results = await executeBulkGetOrCreateByConstraint(
|
|
8955
|
+
kind,
|
|
8956
|
+
constraintName,
|
|
8957
|
+
mappedItems,
|
|
8958
|
+
target,
|
|
8959
|
+
options
|
|
8960
|
+
);
|
|
8961
|
+
return results;
|
|
8962
|
+
};
|
|
8963
|
+
if (backend.capabilities.transactions && "transaction" in backend) {
|
|
8964
|
+
return backend.transaction(
|
|
8965
|
+
async (txBackend) => getOrCreateAll(txBackend)
|
|
8966
|
+
);
|
|
8967
|
+
}
|
|
8968
|
+
return getOrCreateAll(backend);
|
|
8835
8969
|
}
|
|
8836
8970
|
};
|
|
8837
8971
|
}
|
|
@@ -8844,7 +8978,7 @@ function createNodeCollectionsProxy(graph, graphId, registry, backend, operation
|
|
|
8844
8978
|
{
|
|
8845
8979
|
get: (_, kind) => {
|
|
8846
8980
|
if (!(kind in graph.nodes)) {
|
|
8847
|
-
throw new
|
|
8981
|
+
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
|
|
8848
8982
|
}
|
|
8849
8983
|
const cached = collectionCache.get(kind);
|
|
8850
8984
|
if (cached !== void 0) {
|
|
@@ -8869,7 +9003,7 @@ function createEdgeCollectionsProxy(graph, graphId, registry, backend, operation
|
|
|
8869
9003
|
{
|
|
8870
9004
|
get: (_, kind) => {
|
|
8871
9005
|
if (!(kind in graph.edges)) {
|
|
8872
|
-
throw new
|
|
9006
|
+
throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "edge");
|
|
8873
9007
|
}
|
|
8874
9008
|
const cached = collectionCache.get(kind);
|
|
8875
9009
|
if (cached !== void 0) {
|
|
@@ -8889,16 +9023,18 @@ function createEdgeCollectionsProxy(graph, graphId, registry, backend, operation
|
|
|
8889
9023
|
}
|
|
8890
9024
|
|
|
8891
9025
|
// src/constraints/index.ts
|
|
9026
|
+
var UNIQUE_KEY_SEPARATOR = "";
|
|
9027
|
+
var UNIQUE_KEY_NULL_MARKER = "";
|
|
8892
9028
|
function computeUniqueKey(props, fields, collation) {
|
|
8893
9029
|
const values = fields.map((field2) => {
|
|
8894
9030
|
const value = props[field2];
|
|
8895
9031
|
if (value === void 0 || value === null) {
|
|
8896
|
-
return
|
|
9032
|
+
return UNIQUE_KEY_NULL_MARKER;
|
|
8897
9033
|
}
|
|
8898
9034
|
const stringValue = typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value);
|
|
8899
9035
|
return collation === "caseInsensitive" ? stringValue.toLowerCase() : stringValue;
|
|
8900
9036
|
});
|
|
8901
|
-
return values.join(
|
|
9037
|
+
return values.join(UNIQUE_KEY_SEPARATOR);
|
|
8902
9038
|
}
|
|
8903
9039
|
function checkWherePredicate(constraint, props) {
|
|
8904
9040
|
if (!constraint.where) {
|
|
@@ -8967,7 +9103,7 @@ function checkCardinality(edgeKind, fromKind, fromId, cardinality, existingEdgeC
|
|
|
8967
9103
|
}
|
|
8968
9104
|
case "one": {
|
|
8969
9105
|
if (existingEdgeCount > 0) {
|
|
8970
|
-
return new
|
|
9106
|
+
return new chunk44SXEVF4_cjs.CardinalityError({
|
|
8971
9107
|
edgeKind,
|
|
8972
9108
|
fromKind,
|
|
8973
9109
|
fromId,
|
|
@@ -8982,7 +9118,7 @@ function checkCardinality(edgeKind, fromKind, fromId, cardinality, existingEdgeC
|
|
|
8982
9118
|
}
|
|
8983
9119
|
case "oneActive": {
|
|
8984
9120
|
if (hasActiveEdge) {
|
|
8985
|
-
return new
|
|
9121
|
+
return new chunk44SXEVF4_cjs.CardinalityError({
|
|
8986
9122
|
edgeKind,
|
|
8987
9123
|
fromKind,
|
|
8988
9124
|
fromId,
|
|
@@ -8996,7 +9132,7 @@ function checkCardinality(edgeKind, fromKind, fromId, cardinality, existingEdgeC
|
|
|
8996
9132
|
}
|
|
8997
9133
|
function checkUniqueEdge(edgeKind, fromKind, fromId, _toKind, _toId, existingCount) {
|
|
8998
9134
|
if (existingCount > 0) {
|
|
8999
|
-
return new
|
|
9135
|
+
return new chunk44SXEVF4_cjs.CardinalityError({
|
|
9000
9136
|
edgeKind,
|
|
9001
9137
|
fromKind,
|
|
9002
9138
|
fromId,
|
|
@@ -9012,7 +9148,7 @@ function validateEdgeEndpoints(edgeKind, fromKind, toKind, registration, registr
|
|
|
9012
9148
|
(validKind) => registry.isAssignableTo(fromKind, validKind)
|
|
9013
9149
|
);
|
|
9014
9150
|
if (!fromValid) {
|
|
9015
|
-
return new
|
|
9151
|
+
return new chunk44SXEVF4_cjs.EndpointError({
|
|
9016
9152
|
edgeKind,
|
|
9017
9153
|
endpoint: "from",
|
|
9018
9154
|
actualKind: fromKind,
|
|
@@ -9024,7 +9160,7 @@ function validateEdgeEndpoints(edgeKind, fromKind, toKind, registration, registr
|
|
|
9024
9160
|
(validKind) => registry.isAssignableTo(toKind, validKind)
|
|
9025
9161
|
);
|
|
9026
9162
|
if (!toValid) {
|
|
9027
|
-
return new
|
|
9163
|
+
return new chunk44SXEVF4_cjs.EndpointError({
|
|
9028
9164
|
edgeKind,
|
|
9029
9165
|
endpoint: "to",
|
|
9030
9166
|
actualKind: toKind,
|
|
@@ -9036,7 +9172,7 @@ function validateEdgeEndpoints(edgeKind, fromKind, toKind, registration, registr
|
|
|
9036
9172
|
function checkDisjointness(nodeId, nodeKind, existingKinds, registry) {
|
|
9037
9173
|
for (const existingKind of existingKinds) {
|
|
9038
9174
|
if (registry.areDisjoint(nodeKind, existingKind)) {
|
|
9039
|
-
return new
|
|
9175
|
+
return new chunk44SXEVF4_cjs.DisjointError({
|
|
9040
9176
|
nodeId,
|
|
9041
9177
|
attemptedKind: nodeKind,
|
|
9042
9178
|
conflictingKind: existingKind
|
|
@@ -9189,7 +9325,7 @@ function rowToEdge(row) {
|
|
|
9189
9325
|
// src/store/operations/edge-operations.ts
|
|
9190
9326
|
function getEdgeRegistration(graph, kind) {
|
|
9191
9327
|
const registration = graph.edges[kind];
|
|
9192
|
-
if (registration === void 0) throw new
|
|
9328
|
+
if (registration === void 0) throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "edge");
|
|
9193
9329
|
return registration;
|
|
9194
9330
|
}
|
|
9195
9331
|
function buildEdgeEndpointCacheKey(graphId, kind, id) {
|
|
@@ -9331,7 +9467,7 @@ async function validateAndPrepareEdgeCreate(ctx, input, id, backend) {
|
|
|
9331
9467
|
if (endpointError) throw endpointError;
|
|
9332
9468
|
const fromNode = await backend.getNode(ctx.graphId, fromKind, input.fromId);
|
|
9333
9469
|
if (!fromNode || fromNode.deleted_at) {
|
|
9334
|
-
throw new
|
|
9470
|
+
throw new chunk44SXEVF4_cjs.EndpointNotFoundError({
|
|
9335
9471
|
edgeKind: kind,
|
|
9336
9472
|
endpoint: "from",
|
|
9337
9473
|
nodeKind: fromKind,
|
|
@@ -9340,19 +9476,19 @@ async function validateAndPrepareEdgeCreate(ctx, input, id, backend) {
|
|
|
9340
9476
|
}
|
|
9341
9477
|
const toNode = await backend.getNode(ctx.graphId, toKind, input.toId);
|
|
9342
9478
|
if (!toNode || toNode.deleted_at) {
|
|
9343
|
-
throw new
|
|
9479
|
+
throw new chunk44SXEVF4_cjs.EndpointNotFoundError({
|
|
9344
9480
|
edgeKind: kind,
|
|
9345
9481
|
endpoint: "to",
|
|
9346
9482
|
nodeKind: toKind,
|
|
9347
9483
|
nodeId: input.toId
|
|
9348
9484
|
});
|
|
9349
9485
|
}
|
|
9350
|
-
const validatedProps =
|
|
9486
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateEdgeProps(edgeKind.schema, input.props, {
|
|
9351
9487
|
kind,
|
|
9352
9488
|
operation: "create"
|
|
9353
9489
|
});
|
|
9354
|
-
const validFrom =
|
|
9355
|
-
const validTo =
|
|
9490
|
+
const validFrom = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validFrom, "validFrom");
|
|
9491
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
9356
9492
|
const cardinality = registration.cardinality ?? "many";
|
|
9357
9493
|
const constraintContext = {
|
|
9358
9494
|
graphId: ctx.graphId,
|
|
@@ -9407,7 +9543,7 @@ async function executeEdgeCreateInternal(ctx, input, backend, options) {
|
|
|
9407
9543
|
async function executeEdgeCreate(ctx, input, backend) {
|
|
9408
9544
|
const result = await executeEdgeCreateInternal(ctx, input, backend);
|
|
9409
9545
|
if (!result) {
|
|
9410
|
-
throw new
|
|
9546
|
+
throw new chunk44SXEVF4_cjs.DatabaseOperationError(
|
|
9411
9547
|
"Edge create failed: expected created edge row",
|
|
9412
9548
|
{ operation: "insert", entity: "edge" }
|
|
9413
9549
|
);
|
|
@@ -9484,7 +9620,7 @@ async function executeEdgeUpdate(ctx, input, backend) {
|
|
|
9484
9620
|
const id = input.id;
|
|
9485
9621
|
const existing = await backend.getEdge(ctx.graphId, id);
|
|
9486
9622
|
if (!existing || existing.deleted_at) {
|
|
9487
|
-
throw new
|
|
9623
|
+
throw new chunk44SXEVF4_cjs.EdgeNotFoundError("unknown", id);
|
|
9488
9624
|
}
|
|
9489
9625
|
const opContext = ctx.createOperationContext(
|
|
9490
9626
|
"update",
|
|
@@ -9497,12 +9633,12 @@ async function executeEdgeUpdate(ctx, input, backend) {
|
|
|
9497
9633
|
const edgeKind = registration.type;
|
|
9498
9634
|
const existingProps = JSON.parse(existing.props);
|
|
9499
9635
|
const mergedProps = { ...existingProps, ...input.props };
|
|
9500
|
-
const validatedProps =
|
|
9636
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
|
|
9501
9637
|
kind: existing.kind,
|
|
9502
9638
|
operation: "update",
|
|
9503
9639
|
id
|
|
9504
9640
|
});
|
|
9505
|
-
const validTo =
|
|
9641
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
9506
9642
|
const updateParams = {
|
|
9507
9643
|
graphId: ctx.graphId,
|
|
9508
9644
|
id,
|
|
@@ -9517,18 +9653,18 @@ async function executeEdgeUpsertUpdate(ctx, input, backend, options) {
|
|
|
9517
9653
|
const id = input.id;
|
|
9518
9654
|
const existing = await backend.getEdge(ctx.graphId, id);
|
|
9519
9655
|
if (!existing) {
|
|
9520
|
-
throw new
|
|
9656
|
+
throw new chunk44SXEVF4_cjs.EdgeNotFoundError("unknown", id);
|
|
9521
9657
|
}
|
|
9522
9658
|
const registration = getEdgeRegistration(ctx.graph, existing.kind);
|
|
9523
9659
|
const edgeKind = registration.type;
|
|
9524
9660
|
const existingProps = JSON.parse(existing.props);
|
|
9525
9661
|
const mergedProps = { ...existingProps, ...input.props };
|
|
9526
|
-
const validatedProps =
|
|
9662
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateEdgeProps(edgeKind.schema, mergedProps, {
|
|
9527
9663
|
kind: existing.kind,
|
|
9528
9664
|
operation: "update",
|
|
9529
9665
|
id
|
|
9530
9666
|
});
|
|
9531
|
-
const validTo =
|
|
9667
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
9532
9668
|
const updateParams = {
|
|
9533
9669
|
graphId: ctx.graphId,
|
|
9534
9670
|
id,
|
|
@@ -9575,6 +9711,343 @@ async function executeEdgeHardDelete(ctx, id, backend) {
|
|
|
9575
9711
|
});
|
|
9576
9712
|
});
|
|
9577
9713
|
}
|
|
9714
|
+
var RECORD_SEP = "";
|
|
9715
|
+
var UNIT_SEP = "";
|
|
9716
|
+
var UNDEFINED_SENTINEL = "";
|
|
9717
|
+
function validateMatchOnFields(schema, matchOn, edgeKind) {
|
|
9718
|
+
if (matchOn.length === 0) return;
|
|
9719
|
+
const shape = schema.shape;
|
|
9720
|
+
if (shape === void 0) {
|
|
9721
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
9722
|
+
`Edge kind "${edgeKind}" has no schema shape to validate matchOn fields against`,
|
|
9723
|
+
{
|
|
9724
|
+
kind: edgeKind,
|
|
9725
|
+
operation: "create",
|
|
9726
|
+
issues: matchOn.map((field2) => ({
|
|
9727
|
+
path: field2,
|
|
9728
|
+
message: `Field "${field2}" does not exist in edge schema`
|
|
9729
|
+
}))
|
|
9730
|
+
}
|
|
9731
|
+
);
|
|
9732
|
+
}
|
|
9733
|
+
const invalidFields = matchOn.filter((field2) => !(field2 in shape));
|
|
9734
|
+
if (invalidFields.length > 0) {
|
|
9735
|
+
throw new chunk44SXEVF4_cjs.ValidationError(
|
|
9736
|
+
`Invalid matchOn fields for edge kind "${edgeKind}": ${invalidFields.join(", ")}`,
|
|
9737
|
+
{
|
|
9738
|
+
kind: edgeKind,
|
|
9739
|
+
operation: "create",
|
|
9740
|
+
issues: invalidFields.map((field2) => ({
|
|
9741
|
+
path: field2,
|
|
9742
|
+
message: `Field "${field2}" does not exist in edge schema`
|
|
9743
|
+
}))
|
|
9744
|
+
}
|
|
9745
|
+
);
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9748
|
+
function stableStringify(value) {
|
|
9749
|
+
if (value === void 0) return UNDEFINED_SENTINEL;
|
|
9750
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
9751
|
+
if (Array.isArray(value)) {
|
|
9752
|
+
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
9753
|
+
}
|
|
9754
|
+
const sorted = Object.keys(value).toSorted();
|
|
9755
|
+
const entries = sorted.map(
|
|
9756
|
+
(key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`
|
|
9757
|
+
);
|
|
9758
|
+
return `{${entries.join(",")}}`;
|
|
9759
|
+
}
|
|
9760
|
+
function buildEdgeCompositeKey(fromKind, fromId, toKind, toId, props, matchOn) {
|
|
9761
|
+
const endpointPart = `${fromKind}${RECORD_SEP}${fromId}${RECORD_SEP}${toKind}${RECORD_SEP}${toId}`;
|
|
9762
|
+
if (matchOn.length === 0) return endpointPart;
|
|
9763
|
+
const sortedFields = [...matchOn].toSorted();
|
|
9764
|
+
const propertyParts = sortedFields.map(
|
|
9765
|
+
(field2) => `${RECORD_SEP}${field2}${UNIT_SEP}${stableStringify(props[field2])}`
|
|
9766
|
+
);
|
|
9767
|
+
return endpointPart + propertyParts.join("");
|
|
9768
|
+
}
|
|
9769
|
+
function buildEndpointPairKey(fromKind, fromId, toKind, toId) {
|
|
9770
|
+
return `${fromKind}${RECORD_SEP}${fromId}${RECORD_SEP}${toKind}${RECORD_SEP}${toId}`;
|
|
9771
|
+
}
|
|
9772
|
+
function findMatchingEdge(rows, matchOn, inputProps) {
|
|
9773
|
+
let liveRow;
|
|
9774
|
+
let deletedRow;
|
|
9775
|
+
for (const row of rows) {
|
|
9776
|
+
if (matchOn.length > 0) {
|
|
9777
|
+
const rowProps = JSON.parse(row.props);
|
|
9778
|
+
const matches = matchOn.every(
|
|
9779
|
+
(field2) => stableStringify(rowProps[field2]) === stableStringify(inputProps[field2])
|
|
9780
|
+
);
|
|
9781
|
+
if (!matches) continue;
|
|
9782
|
+
}
|
|
9783
|
+
if (row.deleted_at === void 0) {
|
|
9784
|
+
liveRow ??= row;
|
|
9785
|
+
} else {
|
|
9786
|
+
deletedRow ??= row;
|
|
9787
|
+
}
|
|
9788
|
+
if (liveRow !== void 0) break;
|
|
9789
|
+
}
|
|
9790
|
+
return { liveRow, deletedRow };
|
|
9791
|
+
}
|
|
9792
|
+
async function executeEdgeFindByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, backend, options) {
|
|
9793
|
+
const matchOn = options?.matchOn ?? [];
|
|
9794
|
+
const props = options?.props ?? {};
|
|
9795
|
+
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
9796
|
+
const edgeKind = registration.type;
|
|
9797
|
+
if (matchOn.length > 0) {
|
|
9798
|
+
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
9799
|
+
}
|
|
9800
|
+
const candidateRows = await backend.findEdgesByKind({
|
|
9801
|
+
graphId: ctx.graphId,
|
|
9802
|
+
kind,
|
|
9803
|
+
fromKind,
|
|
9804
|
+
fromId,
|
|
9805
|
+
toKind,
|
|
9806
|
+
toId,
|
|
9807
|
+
excludeDeleted: true
|
|
9808
|
+
});
|
|
9809
|
+
if (candidateRows.length === 0) return void 0;
|
|
9810
|
+
if (matchOn.length === 0) return rowToEdge(candidateRows[0]);
|
|
9811
|
+
const { liveRow } = findMatchingEdge(candidateRows, matchOn, props);
|
|
9812
|
+
return liveRow === void 0 ? void 0 : rowToEdge(liveRow);
|
|
9813
|
+
}
|
|
9814
|
+
async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, props, backend, options) {
|
|
9815
|
+
const ifExists = options?.ifExists ?? "return";
|
|
9816
|
+
const matchOn = options?.matchOn ?? [];
|
|
9817
|
+
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
9818
|
+
const edgeKind = registration.type;
|
|
9819
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateEdgeProps(edgeKind.schema, props, {
|
|
9820
|
+
kind,
|
|
9821
|
+
operation: "create"
|
|
9822
|
+
});
|
|
9823
|
+
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
9824
|
+
const candidateRows = await backend.findEdgesByKind({
|
|
9825
|
+
graphId: ctx.graphId,
|
|
9826
|
+
kind,
|
|
9827
|
+
fromKind,
|
|
9828
|
+
fromId,
|
|
9829
|
+
toKind,
|
|
9830
|
+
toId,
|
|
9831
|
+
excludeDeleted: false,
|
|
9832
|
+
temporalMode: "includeTombstones"
|
|
9833
|
+
});
|
|
9834
|
+
const { liveRow, deletedRow } = findMatchingEdge(
|
|
9835
|
+
candidateRows,
|
|
9836
|
+
matchOn,
|
|
9837
|
+
validatedProps
|
|
9838
|
+
);
|
|
9839
|
+
if (liveRow === void 0 && deletedRow === void 0) {
|
|
9840
|
+
const input = {
|
|
9841
|
+
kind,
|
|
9842
|
+
fromKind,
|
|
9843
|
+
fromId,
|
|
9844
|
+
toKind,
|
|
9845
|
+
toId,
|
|
9846
|
+
props: validatedProps
|
|
9847
|
+
};
|
|
9848
|
+
const edge2 = await executeEdgeCreate(ctx, input, backend);
|
|
9849
|
+
return { edge: edge2, action: "created" };
|
|
9850
|
+
}
|
|
9851
|
+
if (liveRow !== void 0) {
|
|
9852
|
+
if (ifExists === "return") {
|
|
9853
|
+
return { edge: rowToEdge(liveRow), action: "found" };
|
|
9854
|
+
}
|
|
9855
|
+
const edge2 = await executeEdgeUpsertUpdate(
|
|
9856
|
+
ctx,
|
|
9857
|
+
{ id: liveRow.id, props: validatedProps },
|
|
9858
|
+
backend
|
|
9859
|
+
);
|
|
9860
|
+
return { edge: edge2, action: "updated" };
|
|
9861
|
+
}
|
|
9862
|
+
const cardinality = registration.cardinality ?? "many";
|
|
9863
|
+
const matchedDeletedRow = deletedRow;
|
|
9864
|
+
const effectiveValidTo = matchedDeletedRow.valid_to;
|
|
9865
|
+
const constraintContext = {
|
|
9866
|
+
graphId: ctx.graphId,
|
|
9867
|
+
registry: ctx.registry,
|
|
9868
|
+
backend
|
|
9869
|
+
};
|
|
9870
|
+
await checkCardinalityConstraint(
|
|
9871
|
+
constraintContext,
|
|
9872
|
+
kind,
|
|
9873
|
+
cardinality,
|
|
9874
|
+
fromKind,
|
|
9875
|
+
fromId,
|
|
9876
|
+
toKind,
|
|
9877
|
+
toId,
|
|
9878
|
+
effectiveValidTo
|
|
9879
|
+
);
|
|
9880
|
+
const edge = await executeEdgeUpsertUpdate(
|
|
9881
|
+
ctx,
|
|
9882
|
+
{ id: matchedDeletedRow.id, props: validatedProps },
|
|
9883
|
+
backend,
|
|
9884
|
+
{ clearDeleted: true }
|
|
9885
|
+
);
|
|
9886
|
+
return { edge, action: "resurrected" };
|
|
9887
|
+
}
|
|
9888
|
+
async function executeEdgeBulkGetOrCreateByEndpoints(ctx, kind, items, backend, options) {
|
|
9889
|
+
if (items.length === 0) return [];
|
|
9890
|
+
const ifExists = options?.ifExists ?? "return";
|
|
9891
|
+
const matchOn = options?.matchOn ?? [];
|
|
9892
|
+
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
9893
|
+
const edgeKind = registration.type;
|
|
9894
|
+
const cardinality = registration.cardinality ?? "many";
|
|
9895
|
+
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
9896
|
+
const validated = [];
|
|
9897
|
+
for (const item of items) {
|
|
9898
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateEdgeProps(edgeKind.schema, item.props, {
|
|
9899
|
+
kind,
|
|
9900
|
+
operation: "create"
|
|
9901
|
+
});
|
|
9902
|
+
const compositeKey = buildEdgeCompositeKey(
|
|
9903
|
+
item.fromKind,
|
|
9904
|
+
item.fromId,
|
|
9905
|
+
item.toKind,
|
|
9906
|
+
item.toId,
|
|
9907
|
+
validatedProps,
|
|
9908
|
+
matchOn
|
|
9909
|
+
);
|
|
9910
|
+
const endpointKey = buildEndpointPairKey(
|
|
9911
|
+
item.fromKind,
|
|
9912
|
+
item.fromId,
|
|
9913
|
+
item.toKind,
|
|
9914
|
+
item.toId
|
|
9915
|
+
);
|
|
9916
|
+
validated.push({
|
|
9917
|
+
fromKind: item.fromKind,
|
|
9918
|
+
fromId: item.fromId,
|
|
9919
|
+
toKind: item.toKind,
|
|
9920
|
+
toId: item.toId,
|
|
9921
|
+
validatedProps,
|
|
9922
|
+
compositeKey,
|
|
9923
|
+
endpointKey
|
|
9924
|
+
});
|
|
9925
|
+
}
|
|
9926
|
+
const uniqueEndpoints = /* @__PURE__ */ new Map();
|
|
9927
|
+
for (const entry of validated) {
|
|
9928
|
+
if (!uniqueEndpoints.has(entry.endpointKey)) {
|
|
9929
|
+
uniqueEndpoints.set(entry.endpointKey, {
|
|
9930
|
+
fromKind: entry.fromKind,
|
|
9931
|
+
fromId: entry.fromId,
|
|
9932
|
+
toKind: entry.toKind,
|
|
9933
|
+
toId: entry.toId
|
|
9934
|
+
});
|
|
9935
|
+
}
|
|
9936
|
+
}
|
|
9937
|
+
const rowsByEndpoint = /* @__PURE__ */ new Map();
|
|
9938
|
+
for (const [endpointKey, endpoint] of uniqueEndpoints) {
|
|
9939
|
+
const rows = await backend.findEdgesByKind({
|
|
9940
|
+
graphId: ctx.graphId,
|
|
9941
|
+
kind,
|
|
9942
|
+
fromKind: endpoint.fromKind,
|
|
9943
|
+
fromId: endpoint.fromId,
|
|
9944
|
+
toKind: endpoint.toKind,
|
|
9945
|
+
toId: endpoint.toId,
|
|
9946
|
+
excludeDeleted: false,
|
|
9947
|
+
temporalMode: "includeTombstones"
|
|
9948
|
+
});
|
|
9949
|
+
rowsByEndpoint.set(endpointKey, rows);
|
|
9950
|
+
}
|
|
9951
|
+
const toCreate = [];
|
|
9952
|
+
const toFetch = [];
|
|
9953
|
+
const duplicateOf = [];
|
|
9954
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
9955
|
+
for (const [index, entry] of validated.entries()) {
|
|
9956
|
+
const previousIndex = seenKeys.get(entry.compositeKey);
|
|
9957
|
+
if (previousIndex !== void 0) {
|
|
9958
|
+
duplicateOf.push({ index, sourceIndex: previousIndex });
|
|
9959
|
+
continue;
|
|
9960
|
+
}
|
|
9961
|
+
seenKeys.set(entry.compositeKey, index);
|
|
9962
|
+
const candidateRows = rowsByEndpoint.get(entry.endpointKey) ?? [];
|
|
9963
|
+
const { liveRow, deletedRow } = findMatchingEdge(
|
|
9964
|
+
candidateRows,
|
|
9965
|
+
matchOn,
|
|
9966
|
+
entry.validatedProps
|
|
9967
|
+
);
|
|
9968
|
+
if (liveRow === void 0 && deletedRow === void 0) {
|
|
9969
|
+
toCreate.push({
|
|
9970
|
+
index,
|
|
9971
|
+
input: {
|
|
9972
|
+
kind,
|
|
9973
|
+
fromKind: entry.fromKind,
|
|
9974
|
+
fromId: entry.fromId,
|
|
9975
|
+
toKind: entry.toKind,
|
|
9976
|
+
toId: entry.toId,
|
|
9977
|
+
props: entry.validatedProps
|
|
9978
|
+
}
|
|
9979
|
+
});
|
|
9980
|
+
} else {
|
|
9981
|
+
const bestRow = liveRow ?? deletedRow;
|
|
9982
|
+
toFetch.push({
|
|
9983
|
+
index,
|
|
9984
|
+
row: bestRow,
|
|
9985
|
+
isDeleted: liveRow === void 0,
|
|
9986
|
+
validatedProps: entry.validatedProps,
|
|
9987
|
+
fromKind: entry.fromKind,
|
|
9988
|
+
fromId: entry.fromId,
|
|
9989
|
+
toKind: entry.toKind,
|
|
9990
|
+
toId: entry.toId
|
|
9991
|
+
});
|
|
9992
|
+
}
|
|
9993
|
+
}
|
|
9994
|
+
const results = Array.from({ length: items.length });
|
|
9995
|
+
if (toCreate.length > 0) {
|
|
9996
|
+
const createInputs = toCreate.map((entry) => entry.input);
|
|
9997
|
+
const createdEdges = await executeEdgeCreateBatch(
|
|
9998
|
+
ctx,
|
|
9999
|
+
createInputs,
|
|
10000
|
+
backend
|
|
10001
|
+
);
|
|
10002
|
+
for (const [batchIndex, entry] of toCreate.entries()) {
|
|
10003
|
+
results[entry.index] = {
|
|
10004
|
+
edge: createdEdges[batchIndex],
|
|
10005
|
+
action: "created"
|
|
10006
|
+
};
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
for (const entry of toFetch) {
|
|
10010
|
+
if (entry.isDeleted) {
|
|
10011
|
+
const effectiveValidTo = entry.row.valid_to;
|
|
10012
|
+
const constraintContext = {
|
|
10013
|
+
graphId: ctx.graphId,
|
|
10014
|
+
registry: ctx.registry,
|
|
10015
|
+
backend
|
|
10016
|
+
};
|
|
10017
|
+
await checkCardinalityConstraint(
|
|
10018
|
+
constraintContext,
|
|
10019
|
+
kind,
|
|
10020
|
+
cardinality,
|
|
10021
|
+
entry.fromKind,
|
|
10022
|
+
entry.fromId,
|
|
10023
|
+
entry.toKind,
|
|
10024
|
+
entry.toId,
|
|
10025
|
+
effectiveValidTo
|
|
10026
|
+
);
|
|
10027
|
+
const edge = await executeEdgeUpsertUpdate(
|
|
10028
|
+
ctx,
|
|
10029
|
+
{ id: entry.row.id, props: entry.validatedProps },
|
|
10030
|
+
backend,
|
|
10031
|
+
{ clearDeleted: true }
|
|
10032
|
+
);
|
|
10033
|
+
results[entry.index] = { edge, action: "resurrected" };
|
|
10034
|
+
} else if (ifExists === "update") {
|
|
10035
|
+
const edge = await executeEdgeUpsertUpdate(
|
|
10036
|
+
ctx,
|
|
10037
|
+
{ id: entry.row.id, props: entry.validatedProps },
|
|
10038
|
+
backend
|
|
10039
|
+
);
|
|
10040
|
+
results[entry.index] = { edge, action: "updated" };
|
|
10041
|
+
} else {
|
|
10042
|
+
results[entry.index] = { edge: rowToEdge(entry.row), action: "found" };
|
|
10043
|
+
}
|
|
10044
|
+
}
|
|
10045
|
+
for (const { index, sourceIndex } of duplicateOf) {
|
|
10046
|
+
const sourceResult = results[sourceIndex];
|
|
10047
|
+
results[index] = { edge: sourceResult.edge, action: "found" };
|
|
10048
|
+
}
|
|
10049
|
+
return results;
|
|
10050
|
+
}
|
|
9578
10051
|
|
|
9579
10052
|
// src/store/embedding-sync.ts
|
|
9580
10053
|
function getEmbeddingFields(schema) {
|
|
@@ -9696,7 +10169,7 @@ async function checkUniquenessConstraints(ctx, kind, id, props, constraints) {
|
|
|
9696
10169
|
key
|
|
9697
10170
|
});
|
|
9698
10171
|
if (existing && existing.node_id !== id) {
|
|
9699
|
-
throw new
|
|
10172
|
+
throw new chunk44SXEVF4_cjs.UniquenessError({
|
|
9700
10173
|
constraintName: constraint.name,
|
|
9701
10174
|
kind: kindToCheck,
|
|
9702
10175
|
existingId: existing.node_id,
|
|
@@ -9779,7 +10252,7 @@ async function updateUniquenessEntries(ctx, kind, id, oldProps, newProps, constr
|
|
|
9779
10252
|
key: newKey
|
|
9780
10253
|
});
|
|
9781
10254
|
if (existing && existing.node_id !== id) {
|
|
9782
|
-
throw new
|
|
10255
|
+
throw new chunk44SXEVF4_cjs.UniquenessError({
|
|
9783
10256
|
constraintName: constraint.name,
|
|
9784
10257
|
kind: kindToCheck,
|
|
9785
10258
|
existingId: existing.node_id,
|
|
@@ -9803,7 +10276,7 @@ async function updateUniquenessEntries(ctx, kind, id, oldProps, newProps, constr
|
|
|
9803
10276
|
// src/store/operations/node-operations.ts
|
|
9804
10277
|
function getNodeRegistration(graph, kind) {
|
|
9805
10278
|
const registration = graph.nodes[kind];
|
|
9806
|
-
if (registration === void 0) throw new
|
|
10279
|
+
if (registration === void 0) throw new chunk44SXEVF4_cjs.KindNotFoundError(kind, "node");
|
|
9807
10280
|
return registration;
|
|
9808
10281
|
}
|
|
9809
10282
|
function buildNodeCacheKey(graphId, kind, id) {
|
|
@@ -9813,7 +10286,7 @@ function buildUniqueCacheKey(graphId, nodeKind, constraintName, key) {
|
|
|
9813
10286
|
return `${graphId}\0${nodeKind}\0${constraintName}\0${key}`;
|
|
9814
10287
|
}
|
|
9815
10288
|
function createNodeAlreadyExistsError(kind, id) {
|
|
9816
|
-
return new
|
|
10289
|
+
return new chunk44SXEVF4_cjs.ValidationError(
|
|
9817
10290
|
`Node already exists: ${kind}/${id}`,
|
|
9818
10291
|
{
|
|
9819
10292
|
entityType: "node",
|
|
@@ -9955,12 +10428,12 @@ async function validateAndPrepareNodeCreate(ctx, input, id, backend) {
|
|
|
9955
10428
|
const kind = input.kind;
|
|
9956
10429
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
9957
10430
|
const nodeKind = registration.type;
|
|
9958
|
-
const validatedProps =
|
|
10431
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, input.props, {
|
|
9959
10432
|
kind,
|
|
9960
10433
|
operation: "create"
|
|
9961
10434
|
});
|
|
9962
|
-
const validFrom =
|
|
9963
|
-
const validTo =
|
|
10435
|
+
const validFrom = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validFrom, "validFrom");
|
|
10436
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
9964
10437
|
const existingNode = await backend.getNode(ctx.graphId, kind, id);
|
|
9965
10438
|
if (existingNode && !existingNode.deleted_at) {
|
|
9966
10439
|
throw createNodeAlreadyExistsError(kind, id);
|
|
@@ -10048,7 +10521,7 @@ async function executeNodeCreateInternal(ctx, input, backend, options) {
|
|
|
10048
10521
|
async function executeNodeCreate(ctx, input, backend) {
|
|
10049
10522
|
const result = await executeNodeCreateInternal(ctx, input, backend);
|
|
10050
10523
|
if (!result) {
|
|
10051
|
-
throw new
|
|
10524
|
+
throw new chunk44SXEVF4_cjs.DatabaseOperationError(
|
|
10052
10525
|
"Node create failed: expected created node row",
|
|
10053
10526
|
{ operation: "insert", entity: "node" }
|
|
10054
10527
|
);
|
|
@@ -10149,17 +10622,17 @@ async function executeNodeUpdate(ctx, input, backend, options) {
|
|
|
10149
10622
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10150
10623
|
const existing = await backend.getNode(ctx.graphId, kind, id);
|
|
10151
10624
|
if (!existing || existing.deleted_at && !options?.clearDeleted) {
|
|
10152
|
-
throw new
|
|
10625
|
+
throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
|
|
10153
10626
|
}
|
|
10154
10627
|
const existingProps = JSON.parse(existing.props);
|
|
10155
10628
|
const mergedProps = { ...existingProps, ...input.props };
|
|
10156
10629
|
const nodeKind = registration.type;
|
|
10157
|
-
const validatedProps =
|
|
10630
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
|
|
10158
10631
|
kind,
|
|
10159
10632
|
operation: "update",
|
|
10160
10633
|
id
|
|
10161
10634
|
});
|
|
10162
|
-
const validTo =
|
|
10635
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
10163
10636
|
const uniquenessContext = {
|
|
10164
10637
|
graphId: ctx.graphId,
|
|
10165
10638
|
registry: ctx.registry,
|
|
@@ -10199,17 +10672,17 @@ async function executeNodeUpsertUpdate(ctx, input, backend, options) {
|
|
|
10199
10672
|
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10200
10673
|
const existing = await backend.getNode(ctx.graphId, kind, id);
|
|
10201
10674
|
if (!existing || existing.deleted_at && !options?.clearDeleted) {
|
|
10202
|
-
throw new
|
|
10675
|
+
throw new chunk44SXEVF4_cjs.NodeNotFoundError(kind, id);
|
|
10203
10676
|
}
|
|
10204
10677
|
const existingProps = JSON.parse(existing.props);
|
|
10205
10678
|
const mergedProps = { ...existingProps, ...input.props };
|
|
10206
10679
|
const nodeKind = registration.type;
|
|
10207
|
-
const validatedProps =
|
|
10680
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, mergedProps, {
|
|
10208
10681
|
kind,
|
|
10209
10682
|
operation: "update",
|
|
10210
10683
|
id
|
|
10211
10684
|
});
|
|
10212
|
-
const validTo =
|
|
10685
|
+
const validTo = chunkK2ROKOK3_cjs.validateOptionalIsoDate(input.validTo, "validTo");
|
|
10213
10686
|
const uniquenessContext = {
|
|
10214
10687
|
graphId: ctx.graphId,
|
|
10215
10688
|
registry: ctx.registry,
|
|
@@ -10263,7 +10736,7 @@ async function executeNodeDelete(ctx, kind, id, backend) {
|
|
|
10263
10736
|
const edgeKinds = [
|
|
10264
10737
|
...new Set(connectedEdges.map((edge) => edge.kind))
|
|
10265
10738
|
];
|
|
10266
|
-
throw new
|
|
10739
|
+
throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
|
|
10267
10740
|
nodeKind: kind,
|
|
10268
10741
|
nodeId: id,
|
|
10269
10742
|
edgeCount: connectedEdges.length,
|
|
@@ -10328,7 +10801,7 @@ async function executeNodeHardDelete(ctx, kind, id, backend) {
|
|
|
10328
10801
|
const edgeKinds = [
|
|
10329
10802
|
...new Set(connectedEdges.map((edge) => edge.kind))
|
|
10330
10803
|
];
|
|
10331
|
-
throw new
|
|
10804
|
+
throw new chunk44SXEVF4_cjs.RestrictedDeleteError({
|
|
10332
10805
|
nodeKind: kind,
|
|
10333
10806
|
nodeId: id,
|
|
10334
10807
|
edgeCount: connectedEdges.length,
|
|
@@ -10357,6 +10830,371 @@ async function executeNodeHardDelete(ctx, kind, id, backend) {
|
|
|
10357
10830
|
await ("transaction" in backend && backend.capabilities.transactions ? backend.transaction(async (tx) => hardDelete(tx)) : hardDelete(backend));
|
|
10358
10831
|
});
|
|
10359
10832
|
}
|
|
10833
|
+
function resolveConstraint(graph, kind, constraintName) {
|
|
10834
|
+
const registration = getNodeRegistration(graph, kind);
|
|
10835
|
+
const constraints = registration.unique ?? [];
|
|
10836
|
+
const constraint = constraints.find((c) => c.name === constraintName);
|
|
10837
|
+
if (constraint === void 0) {
|
|
10838
|
+
throw new chunk44SXEVF4_cjs.NodeConstraintNotFoundError(constraintName, kind);
|
|
10839
|
+
}
|
|
10840
|
+
return constraint;
|
|
10841
|
+
}
|
|
10842
|
+
async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, props, backend, options) {
|
|
10843
|
+
const ifExists = options?.ifExists ?? "return";
|
|
10844
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10845
|
+
const nodeKind = registration.type;
|
|
10846
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
10847
|
+
kind,
|
|
10848
|
+
operation: "create"
|
|
10849
|
+
});
|
|
10850
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10851
|
+
if (!checkWherePredicate(constraint, validatedProps)) {
|
|
10852
|
+
const input = { kind, props: validatedProps };
|
|
10853
|
+
const node = await executeNodeCreate(ctx, input, backend);
|
|
10854
|
+
return { node, action: "created" };
|
|
10855
|
+
}
|
|
10856
|
+
const key = computeUniqueKey(
|
|
10857
|
+
validatedProps,
|
|
10858
|
+
constraint.fields,
|
|
10859
|
+
constraint.collation
|
|
10860
|
+
);
|
|
10861
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10862
|
+
kind,
|
|
10863
|
+
constraint.scope,
|
|
10864
|
+
ctx.registry
|
|
10865
|
+
);
|
|
10866
|
+
let existingUniqueRow;
|
|
10867
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10868
|
+
const row = await backend.checkUnique({
|
|
10869
|
+
graphId: ctx.graphId,
|
|
10870
|
+
nodeKind: kindToCheck,
|
|
10871
|
+
constraintName: constraint.name,
|
|
10872
|
+
key,
|
|
10873
|
+
includeDeleted: true
|
|
10874
|
+
});
|
|
10875
|
+
if (row !== void 0) {
|
|
10876
|
+
existingUniqueRow = row;
|
|
10877
|
+
break;
|
|
10878
|
+
}
|
|
10879
|
+
}
|
|
10880
|
+
if (existingUniqueRow === void 0) {
|
|
10881
|
+
const input = { kind, props: validatedProps };
|
|
10882
|
+
const node = await executeNodeCreate(ctx, input, backend);
|
|
10883
|
+
return { node, action: "created" };
|
|
10884
|
+
}
|
|
10885
|
+
const existingRow = await backend.getNode(
|
|
10886
|
+
ctx.graphId,
|
|
10887
|
+
existingUniqueRow.concrete_kind,
|
|
10888
|
+
existingUniqueRow.node_id
|
|
10889
|
+
);
|
|
10890
|
+
if (existingRow === void 0) {
|
|
10891
|
+
const input = { kind, props: validatedProps };
|
|
10892
|
+
const node = await executeNodeCreate(ctx, input, backend);
|
|
10893
|
+
return { node, action: "created" };
|
|
10894
|
+
}
|
|
10895
|
+
const isSoftDeleted = existingRow.deleted_at !== void 0;
|
|
10896
|
+
if (isSoftDeleted || ifExists === "update") {
|
|
10897
|
+
const concreteKind = existingUniqueRow.concrete_kind;
|
|
10898
|
+
const node = await executeNodeUpsertUpdate(
|
|
10899
|
+
ctx,
|
|
10900
|
+
{
|
|
10901
|
+
kind: concreteKind,
|
|
10902
|
+
id: existingRow.id,
|
|
10903
|
+
props: validatedProps
|
|
10904
|
+
},
|
|
10905
|
+
backend,
|
|
10906
|
+
{ clearDeleted: isSoftDeleted }
|
|
10907
|
+
);
|
|
10908
|
+
return { node, action: isSoftDeleted ? "resurrected" : "updated" };
|
|
10909
|
+
}
|
|
10910
|
+
return { node: rowToNode(existingRow), action: "found" };
|
|
10911
|
+
}
|
|
10912
|
+
async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
|
|
10913
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10914
|
+
const nodeKind = registration.type;
|
|
10915
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
10916
|
+
kind,
|
|
10917
|
+
operation: "create"
|
|
10918
|
+
});
|
|
10919
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10920
|
+
if (!checkWherePredicate(constraint, validatedProps)) return void 0;
|
|
10921
|
+
const key = computeUniqueKey(
|
|
10922
|
+
validatedProps,
|
|
10923
|
+
constraint.fields,
|
|
10924
|
+
constraint.collation
|
|
10925
|
+
);
|
|
10926
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10927
|
+
kind,
|
|
10928
|
+
constraint.scope,
|
|
10929
|
+
ctx.registry
|
|
10930
|
+
);
|
|
10931
|
+
let existingUniqueRow;
|
|
10932
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10933
|
+
const row = await backend.checkUnique({
|
|
10934
|
+
graphId: ctx.graphId,
|
|
10935
|
+
nodeKind: kindToCheck,
|
|
10936
|
+
constraintName: constraint.name,
|
|
10937
|
+
key,
|
|
10938
|
+
includeDeleted: false
|
|
10939
|
+
});
|
|
10940
|
+
if (row !== void 0) {
|
|
10941
|
+
existingUniqueRow = row;
|
|
10942
|
+
break;
|
|
10943
|
+
}
|
|
10944
|
+
}
|
|
10945
|
+
if (existingUniqueRow === void 0) return void 0;
|
|
10946
|
+
const existingRow = await backend.getNode(
|
|
10947
|
+
ctx.graphId,
|
|
10948
|
+
existingUniqueRow.concrete_kind,
|
|
10949
|
+
existingUniqueRow.node_id
|
|
10950
|
+
);
|
|
10951
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0)
|
|
10952
|
+
return void 0;
|
|
10953
|
+
return rowToNode(existingRow);
|
|
10954
|
+
}
|
|
10955
|
+
async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
|
|
10956
|
+
if (items.length === 0) return [];
|
|
10957
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10958
|
+
const nodeKind = registration.type;
|
|
10959
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10960
|
+
const validated = [];
|
|
10961
|
+
for (const item of items) {
|
|
10962
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, item.props, {
|
|
10963
|
+
kind,
|
|
10964
|
+
operation: "create"
|
|
10965
|
+
});
|
|
10966
|
+
const applies = checkWherePredicate(constraint, validatedProps);
|
|
10967
|
+
const key = applies ? computeUniqueKey(
|
|
10968
|
+
validatedProps,
|
|
10969
|
+
constraint.fields,
|
|
10970
|
+
constraint.collation
|
|
10971
|
+
) : void 0;
|
|
10972
|
+
validated.push({ validatedProps, key });
|
|
10973
|
+
}
|
|
10974
|
+
const uniqueKeys = [
|
|
10975
|
+
...new Set(
|
|
10976
|
+
validated.map((v) => v.key).filter((k) => k !== void 0)
|
|
10977
|
+
)
|
|
10978
|
+
];
|
|
10979
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10980
|
+
kind,
|
|
10981
|
+
constraint.scope,
|
|
10982
|
+
ctx.registry
|
|
10983
|
+
);
|
|
10984
|
+
const existingByKey = /* @__PURE__ */ new Map();
|
|
10985
|
+
if (uniqueKeys.length > 0) {
|
|
10986
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10987
|
+
if (backend.checkUniqueBatch === void 0) {
|
|
10988
|
+
for (const key of uniqueKeys) {
|
|
10989
|
+
if (existingByKey.has(key)) continue;
|
|
10990
|
+
const row = await backend.checkUnique({
|
|
10991
|
+
graphId: ctx.graphId,
|
|
10992
|
+
nodeKind: kindToCheck,
|
|
10993
|
+
constraintName: constraint.name,
|
|
10994
|
+
key,
|
|
10995
|
+
includeDeleted: false
|
|
10996
|
+
});
|
|
10997
|
+
if (row !== void 0) {
|
|
10998
|
+
existingByKey.set(row.key, row);
|
|
10999
|
+
}
|
|
11000
|
+
}
|
|
11001
|
+
} else {
|
|
11002
|
+
const rows = await backend.checkUniqueBatch({
|
|
11003
|
+
graphId: ctx.graphId,
|
|
11004
|
+
nodeKind: kindToCheck,
|
|
11005
|
+
constraintName: constraint.name,
|
|
11006
|
+
keys: uniqueKeys,
|
|
11007
|
+
includeDeleted: false
|
|
11008
|
+
});
|
|
11009
|
+
for (const row of rows) {
|
|
11010
|
+
if (!existingByKey.has(row.key)) {
|
|
11011
|
+
existingByKey.set(row.key, row);
|
|
11012
|
+
}
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
const results = Array.from({ length: items.length });
|
|
11018
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
11019
|
+
for (const [index, { key }] of validated.entries()) {
|
|
11020
|
+
if (key === void 0) {
|
|
11021
|
+
results[index] = void 0;
|
|
11022
|
+
continue;
|
|
11023
|
+
}
|
|
11024
|
+
const previousIndex = seenKeys.get(key);
|
|
11025
|
+
if (previousIndex !== void 0) {
|
|
11026
|
+
results[index] = results[previousIndex];
|
|
11027
|
+
continue;
|
|
11028
|
+
}
|
|
11029
|
+
seenKeys.set(key, index);
|
|
11030
|
+
const existing = existingByKey.get(key);
|
|
11031
|
+
if (existing === void 0) {
|
|
11032
|
+
results[index] = void 0;
|
|
11033
|
+
continue;
|
|
11034
|
+
}
|
|
11035
|
+
const existingRow = await backend.getNode(
|
|
11036
|
+
ctx.graphId,
|
|
11037
|
+
existing.concrete_kind,
|
|
11038
|
+
existing.node_id
|
|
11039
|
+
);
|
|
11040
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0) {
|
|
11041
|
+
results[index] = void 0;
|
|
11042
|
+
continue;
|
|
11043
|
+
}
|
|
11044
|
+
results[index] = rowToNode(existingRow);
|
|
11045
|
+
}
|
|
11046
|
+
return results;
|
|
11047
|
+
}
|
|
11048
|
+
async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName, items, backend, options) {
|
|
11049
|
+
if (items.length === 0) return [];
|
|
11050
|
+
const ifExists = options?.ifExists ?? "return";
|
|
11051
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
11052
|
+
const nodeKind = registration.type;
|
|
11053
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
11054
|
+
const validated = [];
|
|
11055
|
+
for (const item of items) {
|
|
11056
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, item.props, {
|
|
11057
|
+
kind,
|
|
11058
|
+
operation: "create"
|
|
11059
|
+
});
|
|
11060
|
+
const applies = checkWherePredicate(constraint, validatedProps);
|
|
11061
|
+
const key = applies ? computeUniqueKey(
|
|
11062
|
+
validatedProps,
|
|
11063
|
+
constraint.fields,
|
|
11064
|
+
constraint.collation
|
|
11065
|
+
) : void 0;
|
|
11066
|
+
validated.push({ validatedProps, key });
|
|
11067
|
+
}
|
|
11068
|
+
const uniqueKeys = [
|
|
11069
|
+
...new Set(
|
|
11070
|
+
validated.map((v) => v.key).filter((k) => k !== void 0)
|
|
11071
|
+
)
|
|
11072
|
+
];
|
|
11073
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
11074
|
+
kind,
|
|
11075
|
+
constraint.scope,
|
|
11076
|
+
ctx.registry
|
|
11077
|
+
);
|
|
11078
|
+
const existingByKey = /* @__PURE__ */ new Map();
|
|
11079
|
+
if (uniqueKeys.length > 0) {
|
|
11080
|
+
for (const kindToCheck of kindsToCheck) {
|
|
11081
|
+
if (backend.checkUniqueBatch === void 0) {
|
|
11082
|
+
for (const key of uniqueKeys) {
|
|
11083
|
+
if (existingByKey.has(key)) continue;
|
|
11084
|
+
const row = await backend.checkUnique({
|
|
11085
|
+
graphId: ctx.graphId,
|
|
11086
|
+
nodeKind: kindToCheck,
|
|
11087
|
+
constraintName: constraint.name,
|
|
11088
|
+
key,
|
|
11089
|
+
includeDeleted: true
|
|
11090
|
+
});
|
|
11091
|
+
if (row !== void 0) {
|
|
11092
|
+
existingByKey.set(row.key, row);
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
} else {
|
|
11096
|
+
const rows = await backend.checkUniqueBatch({
|
|
11097
|
+
graphId: ctx.graphId,
|
|
11098
|
+
nodeKind: kindToCheck,
|
|
11099
|
+
constraintName: constraint.name,
|
|
11100
|
+
keys: uniqueKeys,
|
|
11101
|
+
includeDeleted: true
|
|
11102
|
+
});
|
|
11103
|
+
for (const row of rows) {
|
|
11104
|
+
if (!existingByKey.has(row.key)) {
|
|
11105
|
+
existingByKey.set(row.key, row);
|
|
11106
|
+
}
|
|
11107
|
+
}
|
|
11108
|
+
}
|
|
11109
|
+
}
|
|
11110
|
+
}
|
|
11111
|
+
const toCreate = [];
|
|
11112
|
+
const toFetch = [];
|
|
11113
|
+
const duplicateOf = [];
|
|
11114
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
11115
|
+
for (const [index, { validatedProps, key }] of validated.entries()) {
|
|
11116
|
+
if (key === void 0) {
|
|
11117
|
+
toCreate.push({
|
|
11118
|
+
index,
|
|
11119
|
+
input: { kind, props: validatedProps }
|
|
11120
|
+
});
|
|
11121
|
+
continue;
|
|
11122
|
+
}
|
|
11123
|
+
const previousIndex = seenKeys.get(key);
|
|
11124
|
+
if (previousIndex !== void 0) {
|
|
11125
|
+
duplicateOf.push({ index, sourceIndex: previousIndex });
|
|
11126
|
+
continue;
|
|
11127
|
+
}
|
|
11128
|
+
seenKeys.set(key, index);
|
|
11129
|
+
const existing = existingByKey.get(key);
|
|
11130
|
+
if (existing === void 0) {
|
|
11131
|
+
toCreate.push({
|
|
11132
|
+
index,
|
|
11133
|
+
input: { kind, props: validatedProps }
|
|
11134
|
+
});
|
|
11135
|
+
} else {
|
|
11136
|
+
toFetch.push({
|
|
11137
|
+
index,
|
|
11138
|
+
nodeId: existing.node_id,
|
|
11139
|
+
concreteKind: existing.concrete_kind,
|
|
11140
|
+
validatedProps,
|
|
11141
|
+
isSoftDeleted: existing.deleted_at !== void 0
|
|
11142
|
+
});
|
|
11143
|
+
}
|
|
11144
|
+
}
|
|
11145
|
+
const results = Array.from({ length: items.length });
|
|
11146
|
+
if (toCreate.length > 0) {
|
|
11147
|
+
const createInputs = toCreate.map((entry) => entry.input);
|
|
11148
|
+
const createdNodes = await executeNodeCreateBatch(
|
|
11149
|
+
ctx,
|
|
11150
|
+
createInputs,
|
|
11151
|
+
backend
|
|
11152
|
+
);
|
|
11153
|
+
for (const [batchIndex, entry] of toCreate.entries()) {
|
|
11154
|
+
results[entry.index] = {
|
|
11155
|
+
node: createdNodes[batchIndex],
|
|
11156
|
+
action: "created"
|
|
11157
|
+
};
|
|
11158
|
+
}
|
|
11159
|
+
}
|
|
11160
|
+
for (const entry of toFetch) {
|
|
11161
|
+
const { index, concreteKind, validatedProps, isSoftDeleted, nodeId } = entry;
|
|
11162
|
+
const existingRow = await backend.getNode(
|
|
11163
|
+
ctx.graphId,
|
|
11164
|
+
concreteKind,
|
|
11165
|
+
nodeId
|
|
11166
|
+
);
|
|
11167
|
+
if (existingRow === void 0) {
|
|
11168
|
+
const input = { kind, props: validatedProps };
|
|
11169
|
+
const node = await executeNodeCreate(ctx, input, backend);
|
|
11170
|
+
results[index] = { node, action: "created" };
|
|
11171
|
+
continue;
|
|
11172
|
+
}
|
|
11173
|
+
if (isSoftDeleted || ifExists === "update") {
|
|
11174
|
+
const node = await executeNodeUpsertUpdate(
|
|
11175
|
+
ctx,
|
|
11176
|
+
{
|
|
11177
|
+
kind: concreteKind,
|
|
11178
|
+
id: existingRow.id,
|
|
11179
|
+
props: validatedProps
|
|
11180
|
+
},
|
|
11181
|
+
backend,
|
|
11182
|
+
{ clearDeleted: isSoftDeleted }
|
|
11183
|
+
);
|
|
11184
|
+
results[index] = {
|
|
11185
|
+
node,
|
|
11186
|
+
action: isSoftDeleted ? "resurrected" : "updated"
|
|
11187
|
+
};
|
|
11188
|
+
} else {
|
|
11189
|
+
results[index] = { node: rowToNode(existingRow), action: "found" };
|
|
11190
|
+
}
|
|
11191
|
+
}
|
|
11192
|
+
for (const { index, sourceIndex } of duplicateOf) {
|
|
11193
|
+
const sourceResult = results[sourceIndex];
|
|
11194
|
+
results[index] = { node: sourceResult.node, action: "found" };
|
|
11195
|
+
}
|
|
11196
|
+
return results;
|
|
11197
|
+
}
|
|
10360
11198
|
|
|
10361
11199
|
// src/store/store.ts
|
|
10362
11200
|
var Store = class {
|
|
@@ -10470,7 +11308,31 @@ var Store = class {
|
|
|
10470
11308
|
executeDelete: (kind, id, backend) => executeNodeDelete(ctx, kind, id, backend),
|
|
10471
11309
|
executeHardDelete: (kind, id, backend) => executeNodeHardDelete(ctx, kind, id, backend),
|
|
10472
11310
|
matchesTemporalMode: (row, options) => this.#matchesTemporalMode(row, options),
|
|
10473
|
-
createQuery: () => this.query()
|
|
11311
|
+
createQuery: () => this.query(),
|
|
11312
|
+
executeGetOrCreateByConstraint: (kind, constraintName, props, backend, options) => executeNodeGetOrCreateByConstraint(
|
|
11313
|
+
ctx,
|
|
11314
|
+
kind,
|
|
11315
|
+
constraintName,
|
|
11316
|
+
props,
|
|
11317
|
+
backend,
|
|
11318
|
+
options
|
|
11319
|
+
),
|
|
11320
|
+
executeBulkGetOrCreateByConstraint: (kind, constraintName, items, backend, options) => executeNodeBulkGetOrCreateByConstraint(
|
|
11321
|
+
ctx,
|
|
11322
|
+
kind,
|
|
11323
|
+
constraintName,
|
|
11324
|
+
items,
|
|
11325
|
+
backend,
|
|
11326
|
+
options
|
|
11327
|
+
),
|
|
11328
|
+
executeFindByConstraint: (kind, constraintName, props, backend) => executeNodeFindByConstraint(ctx, kind, constraintName, props, backend),
|
|
11329
|
+
executeBulkFindByConstraint: (kind, constraintName, items, backend) => executeNodeBulkFindByConstraint(
|
|
11330
|
+
ctx,
|
|
11331
|
+
kind,
|
|
11332
|
+
constraintName,
|
|
11333
|
+
items,
|
|
11334
|
+
backend
|
|
11335
|
+
)
|
|
10474
11336
|
};
|
|
10475
11337
|
}
|
|
10476
11338
|
/**
|
|
@@ -10489,7 +11351,35 @@ var Store = class {
|
|
|
10489
11351
|
executeDelete: (id, backend) => executeEdgeDelete(ctx, id, backend),
|
|
10490
11352
|
executeHardDelete: (id, backend) => executeEdgeHardDelete(ctx, id, backend),
|
|
10491
11353
|
matchesTemporalMode: (row, options) => this.#matchesTemporalMode(row, options),
|
|
10492
|
-
createQuery: () => this.query()
|
|
11354
|
+
createQuery: () => this.query(),
|
|
11355
|
+
executeGetOrCreateByEndpoints: (kind, fromKind, fromId, toKind, toId, props, backend, options) => executeEdgeGetOrCreateByEndpoints(
|
|
11356
|
+
ctx,
|
|
11357
|
+
kind,
|
|
11358
|
+
fromKind,
|
|
11359
|
+
fromId,
|
|
11360
|
+
toKind,
|
|
11361
|
+
toId,
|
|
11362
|
+
props,
|
|
11363
|
+
backend,
|
|
11364
|
+
options
|
|
11365
|
+
),
|
|
11366
|
+
executeBulkGetOrCreateByEndpoints: (kind, items, backend, options) => executeEdgeBulkGetOrCreateByEndpoints(
|
|
11367
|
+
ctx,
|
|
11368
|
+
kind,
|
|
11369
|
+
items,
|
|
11370
|
+
backend,
|
|
11371
|
+
options
|
|
11372
|
+
),
|
|
11373
|
+
executeFindByEndpoints: (kind, fromKind, fromId, toKind, toId, backend, options) => executeEdgeFindByEndpoints(
|
|
11374
|
+
ctx,
|
|
11375
|
+
kind,
|
|
11376
|
+
fromKind,
|
|
11377
|
+
fromId,
|
|
11378
|
+
toKind,
|
|
11379
|
+
toId,
|
|
11380
|
+
backend,
|
|
11381
|
+
options
|
|
11382
|
+
)
|
|
10493
11383
|
};
|
|
10494
11384
|
}
|
|
10495
11385
|
// === Query Builder ===
|
|
@@ -10556,6 +11446,24 @@ var Store = class {
|
|
|
10556
11446
|
return fn({ nodes, edges });
|
|
10557
11447
|
});
|
|
10558
11448
|
}
|
|
11449
|
+
// === Graph Lifecycle ===
|
|
11450
|
+
/**
|
|
11451
|
+
* Hard-deletes all data for this graph from the database.
|
|
11452
|
+
*
|
|
11453
|
+
* Removes all nodes, edges, uniqueness entries, embeddings, and schema versions
|
|
11454
|
+
* for this graph's ID. No hooks, no per-row logic. Wrapped in a transaction
|
|
11455
|
+
* when the backend supports it.
|
|
11456
|
+
*
|
|
11457
|
+
* The store is usable after clearing — new data can be created immediately.
|
|
11458
|
+
*/
|
|
11459
|
+
async clear() {
|
|
11460
|
+
const doClear = async (target) => {
|
|
11461
|
+
await target.clearGraph(this.graphId);
|
|
11462
|
+
};
|
|
11463
|
+
await (this.#backend.capabilities.transactions ? this.#backend.transaction(async (tx) => doClear(tx)) : doClear(this.#backend));
|
|
11464
|
+
this.#nodeCollections = void 0;
|
|
11465
|
+
this.#edgeCollections = void 0;
|
|
11466
|
+
}
|
|
10559
11467
|
// === Lifecycle ===
|
|
10560
11468
|
/**
|
|
10561
11469
|
* Closes the store and releases underlying resources.
|
|
@@ -10624,7 +11532,7 @@ var Store = class {
|
|
|
10624
11532
|
// === Internal: Temporal Filtering ===
|
|
10625
11533
|
#matchesTemporalMode(row, options) {
|
|
10626
11534
|
const mode = options?.temporalMode ?? this.#graph.defaults.temporalMode;
|
|
10627
|
-
const asOf = options?.asOf ??
|
|
11535
|
+
const asOf = options?.asOf ?? chunkK2ROKOK3_cjs.nowIso();
|
|
10628
11536
|
switch (mode) {
|
|
10629
11537
|
case "current":
|
|
10630
11538
|
case "asOf": {
|
|
@@ -10657,133 +11565,137 @@ function createStore(graph, backend, options) {
|
|
|
10657
11565
|
}
|
|
10658
11566
|
async function createStoreWithSchema(graph, backend, options) {
|
|
10659
11567
|
const store = createStore(graph, backend, options);
|
|
10660
|
-
const result = await
|
|
11568
|
+
const result = await chunkLDM2AFKZ_cjs.ensureSchema(backend, graph, options);
|
|
10661
11569
|
return [store, result];
|
|
10662
11570
|
}
|
|
10663
11571
|
|
|
10664
11572
|
Object.defineProperty(exports, "isMetaEdge", {
|
|
10665
11573
|
enumerable: true,
|
|
10666
|
-
get: function () { return
|
|
11574
|
+
get: function () { return chunkLDM2AFKZ_cjs.isMetaEdge; }
|
|
10667
11575
|
});
|
|
10668
11576
|
Object.defineProperty(exports, "defineGraph", {
|
|
10669
11577
|
enumerable: true,
|
|
10670
|
-
get: function () { return
|
|
11578
|
+
get: function () { return chunkK2ROKOK3_cjs.defineGraph; }
|
|
10671
11579
|
});
|
|
10672
11580
|
Object.defineProperty(exports, "getEdgeKinds", {
|
|
10673
11581
|
enumerable: true,
|
|
10674
|
-
get: function () { return
|
|
11582
|
+
get: function () { return chunkK2ROKOK3_cjs.getEdgeKinds; }
|
|
10675
11583
|
});
|
|
10676
11584
|
Object.defineProperty(exports, "getNodeKinds", {
|
|
10677
11585
|
enumerable: true,
|
|
10678
|
-
get: function () { return
|
|
11586
|
+
get: function () { return chunkK2ROKOK3_cjs.getNodeKinds; }
|
|
10679
11587
|
});
|
|
10680
11588
|
Object.defineProperty(exports, "isEdgeType", {
|
|
10681
11589
|
enumerable: true,
|
|
10682
|
-
get: function () { return
|
|
11590
|
+
get: function () { return chunkK2ROKOK3_cjs.isEdgeType; }
|
|
10683
11591
|
});
|
|
10684
11592
|
Object.defineProperty(exports, "isEdgeTypeWithEndpoints", {
|
|
10685
11593
|
enumerable: true,
|
|
10686
|
-
get: function () { return
|
|
11594
|
+
get: function () { return chunkK2ROKOK3_cjs.isEdgeTypeWithEndpoints; }
|
|
10687
11595
|
});
|
|
10688
11596
|
Object.defineProperty(exports, "isGraphDef", {
|
|
10689
11597
|
enumerable: true,
|
|
10690
|
-
get: function () { return
|
|
11598
|
+
get: function () { return chunkK2ROKOK3_cjs.isGraphDef; }
|
|
10691
11599
|
});
|
|
10692
11600
|
Object.defineProperty(exports, "isNodeType", {
|
|
10693
11601
|
enumerable: true,
|
|
10694
|
-
get: function () { return
|
|
11602
|
+
get: function () { return chunkK2ROKOK3_cjs.isNodeType; }
|
|
10695
11603
|
});
|
|
10696
11604
|
Object.defineProperty(exports, "CardinalityError", {
|
|
10697
11605
|
enumerable: true,
|
|
10698
|
-
get: function () { return
|
|
11606
|
+
get: function () { return chunk44SXEVF4_cjs.CardinalityError; }
|
|
10699
11607
|
});
|
|
10700
11608
|
Object.defineProperty(exports, "CompilerInvariantError", {
|
|
10701
11609
|
enumerable: true,
|
|
10702
|
-
get: function () { return
|
|
11610
|
+
get: function () { return chunk44SXEVF4_cjs.CompilerInvariantError; }
|
|
10703
11611
|
});
|
|
10704
11612
|
Object.defineProperty(exports, "ConfigurationError", {
|
|
10705
11613
|
enumerable: true,
|
|
10706
|
-
get: function () { return
|
|
11614
|
+
get: function () { return chunk44SXEVF4_cjs.ConfigurationError; }
|
|
10707
11615
|
});
|
|
10708
11616
|
Object.defineProperty(exports, "DatabaseOperationError", {
|
|
10709
11617
|
enumerable: true,
|
|
10710
|
-
get: function () { return
|
|
11618
|
+
get: function () { return chunk44SXEVF4_cjs.DatabaseOperationError; }
|
|
10711
11619
|
});
|
|
10712
11620
|
Object.defineProperty(exports, "DisjointError", {
|
|
10713
11621
|
enumerable: true,
|
|
10714
|
-
get: function () { return
|
|
11622
|
+
get: function () { return chunk44SXEVF4_cjs.DisjointError; }
|
|
10715
11623
|
});
|
|
10716
11624
|
Object.defineProperty(exports, "EdgeNotFoundError", {
|
|
10717
11625
|
enumerable: true,
|
|
10718
|
-
get: function () { return
|
|
11626
|
+
get: function () { return chunk44SXEVF4_cjs.EdgeNotFoundError; }
|
|
10719
11627
|
});
|
|
10720
11628
|
Object.defineProperty(exports, "EndpointError", {
|
|
10721
11629
|
enumerable: true,
|
|
10722
|
-
get: function () { return
|
|
11630
|
+
get: function () { return chunk44SXEVF4_cjs.EndpointError; }
|
|
10723
11631
|
});
|
|
10724
11632
|
Object.defineProperty(exports, "EndpointNotFoundError", {
|
|
10725
11633
|
enumerable: true,
|
|
10726
|
-
get: function () { return
|
|
11634
|
+
get: function () { return chunk44SXEVF4_cjs.EndpointNotFoundError; }
|
|
10727
11635
|
});
|
|
10728
11636
|
Object.defineProperty(exports, "KindNotFoundError", {
|
|
10729
11637
|
enumerable: true,
|
|
10730
|
-
get: function () { return
|
|
11638
|
+
get: function () { return chunk44SXEVF4_cjs.KindNotFoundError; }
|
|
10731
11639
|
});
|
|
10732
11640
|
Object.defineProperty(exports, "MigrationError", {
|
|
10733
11641
|
enumerable: true,
|
|
10734
|
-
get: function () { return
|
|
11642
|
+
get: function () { return chunk44SXEVF4_cjs.MigrationError; }
|
|
11643
|
+
});
|
|
11644
|
+
Object.defineProperty(exports, "NodeConstraintNotFoundError", {
|
|
11645
|
+
enumerable: true,
|
|
11646
|
+
get: function () { return chunk44SXEVF4_cjs.NodeConstraintNotFoundError; }
|
|
10735
11647
|
});
|
|
10736
11648
|
Object.defineProperty(exports, "NodeNotFoundError", {
|
|
10737
11649
|
enumerable: true,
|
|
10738
|
-
get: function () { return
|
|
11650
|
+
get: function () { return chunk44SXEVF4_cjs.NodeNotFoundError; }
|
|
10739
11651
|
});
|
|
10740
11652
|
Object.defineProperty(exports, "RestrictedDeleteError", {
|
|
10741
11653
|
enumerable: true,
|
|
10742
|
-
get: function () { return
|
|
11654
|
+
get: function () { return chunk44SXEVF4_cjs.RestrictedDeleteError; }
|
|
10743
11655
|
});
|
|
10744
11656
|
Object.defineProperty(exports, "SchemaMismatchError", {
|
|
10745
11657
|
enumerable: true,
|
|
10746
|
-
get: function () { return
|
|
11658
|
+
get: function () { return chunk44SXEVF4_cjs.SchemaMismatchError; }
|
|
10747
11659
|
});
|
|
10748
11660
|
Object.defineProperty(exports, "TypeGraphError", {
|
|
10749
11661
|
enumerable: true,
|
|
10750
|
-
get: function () { return
|
|
11662
|
+
get: function () { return chunk44SXEVF4_cjs.TypeGraphError; }
|
|
10751
11663
|
});
|
|
10752
11664
|
Object.defineProperty(exports, "UniquenessError", {
|
|
10753
11665
|
enumerable: true,
|
|
10754
|
-
get: function () { return
|
|
11666
|
+
get: function () { return chunk44SXEVF4_cjs.UniquenessError; }
|
|
10755
11667
|
});
|
|
10756
11668
|
Object.defineProperty(exports, "UnsupportedPredicateError", {
|
|
10757
11669
|
enumerable: true,
|
|
10758
|
-
get: function () { return
|
|
11670
|
+
get: function () { return chunk44SXEVF4_cjs.UnsupportedPredicateError; }
|
|
10759
11671
|
});
|
|
10760
11672
|
Object.defineProperty(exports, "ValidationError", {
|
|
10761
11673
|
enumerable: true,
|
|
10762
|
-
get: function () { return
|
|
11674
|
+
get: function () { return chunk44SXEVF4_cjs.ValidationError; }
|
|
10763
11675
|
});
|
|
10764
11676
|
Object.defineProperty(exports, "VersionConflictError", {
|
|
10765
11677
|
enumerable: true,
|
|
10766
|
-
get: function () { return
|
|
11678
|
+
get: function () { return chunk44SXEVF4_cjs.VersionConflictError; }
|
|
10767
11679
|
});
|
|
10768
11680
|
Object.defineProperty(exports, "getErrorSuggestion", {
|
|
10769
11681
|
enumerable: true,
|
|
10770
|
-
get: function () { return
|
|
11682
|
+
get: function () { return chunk44SXEVF4_cjs.getErrorSuggestion; }
|
|
10771
11683
|
});
|
|
10772
11684
|
Object.defineProperty(exports, "isConstraintError", {
|
|
10773
11685
|
enumerable: true,
|
|
10774
|
-
get: function () { return
|
|
11686
|
+
get: function () { return chunk44SXEVF4_cjs.isConstraintError; }
|
|
10775
11687
|
});
|
|
10776
11688
|
Object.defineProperty(exports, "isSystemError", {
|
|
10777
11689
|
enumerable: true,
|
|
10778
|
-
get: function () { return
|
|
11690
|
+
get: function () { return chunk44SXEVF4_cjs.isSystemError; }
|
|
10779
11691
|
});
|
|
10780
11692
|
Object.defineProperty(exports, "isTypeGraphError", {
|
|
10781
11693
|
enumerable: true,
|
|
10782
|
-
get: function () { return
|
|
11694
|
+
get: function () { return chunk44SXEVF4_cjs.isTypeGraphError; }
|
|
10783
11695
|
});
|
|
10784
11696
|
Object.defineProperty(exports, "isUserRecoverable", {
|
|
10785
11697
|
enumerable: true,
|
|
10786
|
-
get: function () { return
|
|
11698
|
+
get: function () { return chunk44SXEVF4_cjs.isUserRecoverable; }
|
|
10787
11699
|
});
|
|
10788
11700
|
Object.defineProperty(exports, "MAX_JSON_POINTER_DEPTH", {
|
|
10789
11701
|
enumerable: true,
|