@nicia-ai/typegraph 0.20.0 → 0.21.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/{ast-Bh2NDeaK.d.cts → ast-CSLbPIOC.d.ts} +56 -3
- package/dist/{ast-COMyNeMn.d.ts → ast-DogwbBqA.d.cts} +56 -3
- package/dist/backend/postgres/index.cjs +123 -45
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +15 -7
- package/dist/backend/postgres/index.d.ts +15 -7
- package/dist/backend/postgres/index.js +101 -23
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +15 -15
- package/dist/backend/sqlite/index.d.cts +11 -7
- package/dist/backend/sqlite/index.d.ts +11 -7
- package/dist/backend/sqlite/index.js +5 -5
- package/dist/backend/sqlite/libsql.cjs +8 -8
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +5 -5
- package/dist/backend/sqlite/local.cjs +9 -9
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +5 -5
- package/dist/{chunk-LELLOHJK.cjs → chunk-2X7P7AD5.cjs} +35 -35
- package/dist/{chunk-LELLOHJK.cjs.map → chunk-2X7P7AD5.cjs.map} +1 -1
- package/dist/{chunk-GNIYZKBI.js → chunk-4XNE2JG3.js} +376 -8
- package/dist/chunk-4XNE2JG3.js.map +1 -0
- package/dist/{chunk-HXJXTOXR.cjs → chunk-CQL6FOTT.cjs} +82 -21
- package/dist/chunk-CQL6FOTT.cjs.map +1 -0
- package/dist/{chunk-K7SQ3SWP.js → chunk-EYELZHKY.js} +120 -12
- package/dist/chunk-EYELZHKY.js.map +1 -0
- package/dist/{chunk-MME3H4ZF.cjs → chunk-FQCQM3KG.cjs} +385 -9
- package/dist/chunk-FQCQM3KG.cjs.map +1 -0
- package/dist/{chunk-X33WV2UF.cjs → chunk-HRNQ3DVJ.cjs} +24 -21
- package/dist/chunk-HRNQ3DVJ.cjs.map +1 -0
- package/dist/{chunk-W6M7XWKX.js → chunk-JYUQA77I.js} +21 -18
- package/dist/chunk-JYUQA77I.js.map +1 -0
- package/dist/{chunk-LLHFS53Q.js → chunk-NRNJ52AA.js} +72 -11
- package/dist/chunk-NRNJ52AA.js.map +1 -0
- package/dist/{chunk-IYWWXOVK.cjs → chunk-Q73OWTJY.cjs} +204 -89
- package/dist/chunk-Q73OWTJY.cjs.map +1 -0
- package/dist/{chunk-G5CYWKRF.js → chunk-RS5OLGEW.js} +2 -2
- package/dist/{chunk-G5CYWKRF.js.map → chunk-RS5OLGEW.js.map} +1 -1
- package/dist/{chunk-6GWJH6AR.js → chunk-SMMOAVJ5.js} +4 -4
- package/dist/{chunk-6GWJH6AR.js.map → chunk-SMMOAVJ5.js.map} +1 -1
- package/dist/{chunk-QFZQGEQ3.js → chunk-UQVBVBVG.js} +151 -36
- package/dist/chunk-UQVBVBVG.js.map +1 -0
- package/dist/{chunk-P5CNM325.cjs → chunk-UVZHTBZ5.cjs} +123 -11
- package/dist/chunk-UVZHTBZ5.cjs.map +1 -0
- package/dist/{chunk-5GZMPJOP.cjs → chunk-WRWVWKQL.cjs} +2 -2
- package/dist/{chunk-5GZMPJOP.cjs.map → chunk-WRWVWKQL.cjs.map} +1 -1
- package/dist/{ddl-BBo2EcFc.d.cts → ddl-BqkTShcR.d.ts} +28 -6
- package/dist/{ddl-D4jlcOH_.d.ts → ddl-Dk1NDN3M.d.cts} +28 -6
- package/dist/index.cjs +1705 -490
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +1552 -361
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +17 -17
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +3 -3
- package/dist/interchange/index.cjs +6 -6
- package/dist/interchange/index.d.cts +4 -5
- package/dist/interchange/index.d.ts +4 -5
- package/dist/interchange/index.js +1 -1
- package/dist/{manager-Chhrq1vl.d.ts → manager-0jVZtiE8.d.ts} +1 -2
- package/dist/{manager-Bj1UEnhE.d.cts → manager-BPK-2PUI.d.cts} +1 -2
- package/dist/profiler/index.cjs +15 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -8
- package/dist/profiler/index.d.ts +7 -8
- package/dist/profiler/index.js +8 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +21 -21
- package/dist/schema/index.d.cts +4 -5
- package/dist/schema/index.d.ts +4 -5
- package/dist/schema/index.js +3 -3
- package/dist/{sqlite-DE-6NWtC.d.cts → sqlite-D1rrwcir.d.cts} +14 -1
- package/dist/{sqlite-Blq-AhmK.d.ts → sqlite-W3rmJMlc.d.ts} +14 -1
- package/dist/{store-BMrRi_mY.d.ts → store-2QW2SIRk.d.cts} +404 -5
- package/dist/{store-DRRvALu8.d.cts → store-C0q13mtJ.d.ts} +404 -5
- package/dist/{types-B3mmOMJV.d.cts → types-CQF88McG.d.cts} +475 -2
- package/dist/{types-ThB4cFLp.d.ts → types-CQF88McG.d.ts} +475 -2
- package/dist/{types-COPePE8_.d.ts → types-CglvhPKz.d.ts} +1 -1
- package/dist/{types-CVtGFpB9.d.cts → types-D23slCOA.d.cts} +1 -1
- package/dist/{types-Ceb01czq.d.ts → types-IMQCuser.d.ts} +2 -2
- package/dist/{types-CZd2PEOc.d.cts → types-vgjar7Ch.d.cts} +2 -2
- package/package.json +9 -9
- package/dist/chunk-GNIYZKBI.js.map +0 -1
- package/dist/chunk-HXJXTOXR.cjs.map +0 -1
- package/dist/chunk-IYWWXOVK.cjs.map +0 -1
- package/dist/chunk-K7SQ3SWP.js.map +0 -1
- package/dist/chunk-LLHFS53Q.js.map +0 -1
- package/dist/chunk-MME3H4ZF.cjs.map +0 -1
- package/dist/chunk-P5CNM325.cjs.map +0 -1
- package/dist/chunk-QFZQGEQ3.js.map +0 -1
- package/dist/chunk-W6M7XWKX.js.map +0 -1
- package/dist/chunk-X33WV2UF.cjs.map +0 -1
- package/dist/types-DMzKq0d5.d.cts +0 -181
- package/dist/types-DMzKq0d5.d.ts +0 -181
|
@@ -37,6 +37,66 @@ function getEmbeddingDimensions(schema) {
|
|
|
37
37
|
}
|
|
38
38
|
return void 0;
|
|
39
39
|
}
|
|
40
|
+
var SEARCHABLE_FIELD_KEY = "_searchableField";
|
|
41
|
+
var DEFAULT_SEARCHABLE_LANGUAGE = "english";
|
|
42
|
+
var SEARCHABLE_WRAPPER_TYPES = /* @__PURE__ */ new Set([
|
|
43
|
+
"optional",
|
|
44
|
+
"nullable",
|
|
45
|
+
"default",
|
|
46
|
+
"prefault",
|
|
47
|
+
"catch",
|
|
48
|
+
"readonly",
|
|
49
|
+
"nonoptional",
|
|
50
|
+
"success"
|
|
51
|
+
]);
|
|
52
|
+
function readSearchableMetadata(value) {
|
|
53
|
+
if (typeof value !== "object" || value === null) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
const language = value.language;
|
|
57
|
+
return typeof language === "string" ? { language } : void 0;
|
|
58
|
+
}
|
|
59
|
+
function getSearchableMetadataFromSchemaMeta(schema) {
|
|
60
|
+
const meta = schema.meta();
|
|
61
|
+
return readSearchableMetadata(meta?.[SEARCHABLE_FIELD_KEY]);
|
|
62
|
+
}
|
|
63
|
+
function searchable(options = {}) {
|
|
64
|
+
const language = options.language ?? DEFAULT_SEARCHABLE_LANGUAGE;
|
|
65
|
+
if (language.length === 0) {
|
|
66
|
+
throw new Error("searchable() language must be a non-empty string");
|
|
67
|
+
}
|
|
68
|
+
const metadata = { language };
|
|
69
|
+
const schema = zod.z.string().meta({
|
|
70
|
+
[SEARCHABLE_FIELD_KEY]: metadata
|
|
71
|
+
});
|
|
72
|
+
return Object.assign(schema, {
|
|
73
|
+
[SEARCHABLE_FIELD_KEY]: metadata
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function isSearchableSchema(value) {
|
|
77
|
+
if (typeof value !== "object" || value === null) return false;
|
|
78
|
+
if (!(SEARCHABLE_FIELD_KEY in value)) return false;
|
|
79
|
+
return readSearchableMetadata(
|
|
80
|
+
value[SEARCHABLE_FIELD_KEY]
|
|
81
|
+
) !== void 0;
|
|
82
|
+
}
|
|
83
|
+
function getSearchableMetadata(schema) {
|
|
84
|
+
if (isSearchableSchema(schema)) {
|
|
85
|
+
return schema[SEARCHABLE_FIELD_KEY];
|
|
86
|
+
}
|
|
87
|
+
const directMetadata = getSearchableMetadataFromSchemaMeta(schema);
|
|
88
|
+
if (directMetadata !== void 0) {
|
|
89
|
+
return directMetadata;
|
|
90
|
+
}
|
|
91
|
+
const def = schema.def;
|
|
92
|
+
if (SEARCHABLE_WRAPPER_TYPES.has(schema.type) && def.innerType !== void 0) {
|
|
93
|
+
return getSearchableMetadata(def.innerType);
|
|
94
|
+
}
|
|
95
|
+
if (schema.type === "pipe") {
|
|
96
|
+
return (def.in === void 0 ? void 0 : getSearchableMetadata(def.in)) ?? (def.out === void 0 ? void 0 : getSearchableMetadata(def.out));
|
|
97
|
+
}
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
40
100
|
|
|
41
101
|
// src/query/json-pointer.ts
|
|
42
102
|
var MAX_JSON_POINTER_DEPTH = 5;
|
|
@@ -212,30 +272,42 @@ var SUPPORTED_SCHEMA_TYPE_SET = new Set(
|
|
|
212
272
|
function isSupportedSchemaType(type) {
|
|
213
273
|
return SUPPORTED_SCHEMA_TYPE_SET.has(type);
|
|
214
274
|
}
|
|
275
|
+
function sharedCacheKey(kindNames, fieldName) {
|
|
276
|
+
return `${[...kindNames].toSorted().join("|")}|${fieldName}`;
|
|
277
|
+
}
|
|
215
278
|
function createSchemaIntrospector(nodeKinds, edgeKinds) {
|
|
216
279
|
const nodeShapeCache = /* @__PURE__ */ new Map();
|
|
217
280
|
const edgeShapeCache = /* @__PURE__ */ new Map();
|
|
281
|
+
const sharedFieldTypeInfoCache = /* @__PURE__ */ new Map();
|
|
282
|
+
const sharedEdgeFieldTypeInfoCache = /* @__PURE__ */ new Map();
|
|
283
|
+
const searchableCache = /* @__PURE__ */ new Map();
|
|
218
284
|
function getFieldTypeInfo(kindName, fieldName) {
|
|
219
285
|
const shape = getShapeForKind(kindName);
|
|
220
286
|
return shape?.[fieldName];
|
|
221
287
|
}
|
|
222
288
|
function getSharedFieldTypeInfo(kindNames, fieldName) {
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
return
|
|
289
|
+
const cacheKey = sharedCacheKey(kindNames, fieldName);
|
|
290
|
+
if (sharedFieldTypeInfoCache.has(cacheKey)) {
|
|
291
|
+
return sharedFieldTypeInfoCache.get(cacheKey);
|
|
226
292
|
}
|
|
227
|
-
|
|
293
|
+
const infos = kindNames.map((kindName) => getFieldTypeInfo(kindName, fieldName)).filter((info) => info !== void 0);
|
|
294
|
+
const merged = infos.length !== kindNames.length || infos.length === 0 ? void 0 : mergeFieldTypeInfos(infos);
|
|
295
|
+
sharedFieldTypeInfoCache.set(cacheKey, merged);
|
|
296
|
+
return merged;
|
|
228
297
|
}
|
|
229
298
|
function getEdgeFieldTypeInfo(edgeKindName, fieldName) {
|
|
230
299
|
const shape = getShapeForEdgeKind(edgeKindName);
|
|
231
300
|
return shape?.[fieldName];
|
|
232
301
|
}
|
|
233
302
|
function getSharedEdgeFieldTypeInfo(edgeKindNames, fieldName) {
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
return
|
|
303
|
+
const cacheKey = sharedCacheKey(edgeKindNames, fieldName);
|
|
304
|
+
if (sharedEdgeFieldTypeInfoCache.has(cacheKey)) {
|
|
305
|
+
return sharedEdgeFieldTypeInfoCache.get(cacheKey);
|
|
237
306
|
}
|
|
238
|
-
|
|
307
|
+
const infos = edgeKindNames.map((kindName) => getEdgeFieldTypeInfo(kindName, fieldName)).filter((info) => info !== void 0);
|
|
308
|
+
const merged = infos.length !== edgeKindNames.length || infos.length === 0 ? void 0 : mergeFieldTypeInfos(infos);
|
|
309
|
+
sharedEdgeFieldTypeInfoCache.set(cacheKey, merged);
|
|
310
|
+
return merged;
|
|
239
311
|
}
|
|
240
312
|
function getShapeForKind(kindName) {
|
|
241
313
|
const cached = nodeShapeCache.get(kindName);
|
|
@@ -288,11 +360,26 @@ function createSchemaIntrospector(nodeKinds, edgeKinds) {
|
|
|
288
360
|
edgeShapeCache.set(edgeKindName, resolved);
|
|
289
361
|
return resolved;
|
|
290
362
|
}
|
|
363
|
+
function hasSearchableField(kindNames) {
|
|
364
|
+
const cacheKey = [...kindNames].toSorted().join("|");
|
|
365
|
+
const cached = searchableCache.get(cacheKey);
|
|
366
|
+
if (cached !== void 0) return cached;
|
|
367
|
+
const result = kindNames.length > 0 && kindNames.every((kindName) => {
|
|
368
|
+
const shape = getShapeForKind(kindName);
|
|
369
|
+
if (!shape) return false;
|
|
370
|
+
return Object.values(shape).some(
|
|
371
|
+
(info) => info.searchable !== void 0
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
searchableCache.set(cacheKey, result);
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
291
377
|
return {
|
|
292
378
|
getFieldTypeInfo,
|
|
293
379
|
getSharedFieldTypeInfo,
|
|
294
380
|
getEdgeFieldTypeInfo,
|
|
295
|
-
getSharedEdgeFieldTypeInfo
|
|
381
|
+
getSharedEdgeFieldTypeInfo,
|
|
382
|
+
hasSearchableField
|
|
296
383
|
};
|
|
297
384
|
}
|
|
298
385
|
function resolveFieldTypeInfo(schema) {
|
|
@@ -300,6 +387,11 @@ function resolveFieldTypeInfo(schema) {
|
|
|
300
387
|
if (embeddingDimensions !== void 0) {
|
|
301
388
|
return { valueType: "embedding", dimensions: embeddingDimensions };
|
|
302
389
|
}
|
|
390
|
+
const searchableMetadata = getSearchableMetadata(schema);
|
|
391
|
+
const searchableStringSchema = searchableMetadata === void 0 ? void 0 : unwrapSearchableStringSchema(schema);
|
|
392
|
+
if (searchableMetadata !== void 0 && searchableStringSchema !== void 0) {
|
|
393
|
+
return { valueType: "string", searchable: searchableMetadata };
|
|
394
|
+
}
|
|
303
395
|
const unwrapped = unwrapSchema(schema);
|
|
304
396
|
const unwrappedEmbeddingDimensions = getEmbeddingDimensions(unwrapped);
|
|
305
397
|
if (unwrappedEmbeddingDimensions !== void 0) {
|
|
@@ -460,6 +552,10 @@ function mergeFieldTypeInfos(infos) {
|
|
|
460
552
|
recordValueType
|
|
461
553
|
};
|
|
462
554
|
}
|
|
555
|
+
if (first.valueType === "string") {
|
|
556
|
+
const allSearchable = first.searchable !== void 0 && rest.every((info) => info.searchable !== void 0);
|
|
557
|
+
return allSearchable ? { valueType: "string", searchable: first.searchable } : { valueType: "string" };
|
|
558
|
+
}
|
|
463
559
|
return first;
|
|
464
560
|
}
|
|
465
561
|
function intersectShapes(shapes) {
|
|
@@ -482,6 +578,18 @@ function intersectShapes(shapes) {
|
|
|
482
578
|
);
|
|
483
579
|
return Object.freeze(Object.fromEntries(entries));
|
|
484
580
|
}
|
|
581
|
+
function unwrapSearchableStringSchema(schema) {
|
|
582
|
+
const type = schema.type;
|
|
583
|
+
const def = schema.def;
|
|
584
|
+
if ((type === "optional" || type === "nullable" || type === "default" || type === "prefault" || type === "catch" || type === "readonly" || type === "nonoptional" || type === "success") && def.innerType) {
|
|
585
|
+
return unwrapSearchableStringSchema(def.innerType);
|
|
586
|
+
}
|
|
587
|
+
if (type === "pipe") {
|
|
588
|
+
return (def.in === void 0 ? void 0 : unwrapSearchableStringSchema(def.in)) ?? (def.out === void 0 ? void 0 : unwrapSearchableStringSchema(def.out));
|
|
589
|
+
}
|
|
590
|
+
const unwrapped = unwrapSchema(schema);
|
|
591
|
+
return unwrapped.type === "string" ? unwrapped : void 0;
|
|
592
|
+
}
|
|
485
593
|
function unwrapSchema(schema) {
|
|
486
594
|
const type = schema.type;
|
|
487
595
|
const def = schema.def;
|
|
@@ -494,15 +602,19 @@ function unwrapSchema(schema) {
|
|
|
494
602
|
return schema;
|
|
495
603
|
}
|
|
496
604
|
|
|
605
|
+
exports.DEFAULT_SEARCHABLE_LANGUAGE = DEFAULT_SEARCHABLE_LANGUAGE;
|
|
497
606
|
exports.MAX_JSON_POINTER_DEPTH = MAX_JSON_POINTER_DEPTH;
|
|
498
607
|
exports.createSchemaIntrospector = createSchemaIntrospector;
|
|
499
608
|
exports.embedding = embedding;
|
|
500
609
|
exports.getEmbeddingDimensions = getEmbeddingDimensions;
|
|
610
|
+
exports.getSearchableMetadata = getSearchableMetadata;
|
|
501
611
|
exports.isEmbeddingSchema = isEmbeddingSchema;
|
|
612
|
+
exports.isSearchableSchema = isSearchableSchema;
|
|
502
613
|
exports.joinJsonPointers = joinJsonPointers;
|
|
503
614
|
exports.jsonPointer = jsonPointer;
|
|
504
615
|
exports.normalizeJsonPointer = normalizeJsonPointer;
|
|
505
616
|
exports.parseJsonPointer = parseJsonPointer;
|
|
506
617
|
exports.resolveFieldTypeInfoAtJsonPointer = resolveFieldTypeInfoAtJsonPointer;
|
|
507
|
-
|
|
508
|
-
//# sourceMappingURL=chunk-
|
|
618
|
+
exports.searchable = searchable;
|
|
619
|
+
//# sourceMappingURL=chunk-UVZHTBZ5.cjs.map
|
|
620
|
+
//# sourceMappingURL=chunk-UVZHTBZ5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/embedding.ts","../src/core/searchable.ts","../src/query/json-pointer.ts","../src/query/field-type-info.ts","../src/query/schema-introspector.ts"],"names":["z","shape"],"mappings":";;;;;AAqCO,IAAM,wBAAA,GAA2B,sBAAA;AAwDjC,SAAS,UAA4B,UAAA,EAAmC;AAC7E,EAAA,IAAI,CAAC,MAAA,CAAO,SAAA,CAAU,UAAU,CAAA,IAAK,cAAc,CAAA,EAAG;AACpD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,yDAAyD,UAAU,CAAA;AAAA,KACrE;AA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A,CAA6B,IAAI,SAAS,CAAA;AAAA,EACnD;AAEA,EAAA,IAAI,SAAS,MAAA,EAAQ;AACnB,IAAA,OAAA,CACG,GAAA,CAAI,EAAA,KAAO,MAAA,GACV,MAAA,GACA,6BAA6B,GAAA,CAAI,EAAE,CAAA,MACpC,GAAA,CAAI,GAAA,KAAQ,MAAA,GACX,MAAA,GACA,4BAAA,CAA6B,IAAI,GAAG,CAAA,CAAA;AAAA,EAE1C;AAEA,EAAA,MAAM,SAAA,GAAY,aAAa,MAAM,CAAA;AACrC,EAAA,OAAO,SAAA,CAAU,IAAA,KAAS,QAAA,GAAW,SAAA,GAAY,MAAA;AACnD;AAEA,SAAS,aAAa,MAAA,EAA8B;AAClD,EAAA,MAAM,OAAO,MAAA,CAAO,IAAA;AACpB,EAAA,MAAM,MAAM,MAAA,CAAO,GAAA;AAKnB,EAAA,IAAA,CACG,SAAS,UAAA,IACR,IAAA,KAAS,UAAA,IACT,IAAA,KAAS,aACT,IAAA,KAAS,UAAA,IACT,IAAA,KAAS,OAAA,IACT,SAAS,UAAA,IACT,IAAA,KAAS,iBACT,IAAA,KAAS,SAAA,KACX,IAAI,SAAA,EACJ;AACA,IAAA,OAAO,YAAA,CAAa,IAAI,SAAS,CAAA;AAAA,EACnC;AAEA,EAAA,IAAI,IAAA,KAAS,MAAA,IAAU,GAAA,CAAI,GAAA,EAAK;AAC9B,IAAA,OAAO,YAAA,CAAa,IAAI,GAAG,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,MAAA;AACT","file":"chunk-UVZHTBZ5.cjs","sourcesContent":["/**\n * Embedding type for vector search.\n *\n * Creates a Zod-compatible schema for vector embeddings with\n * dimension validation and metadata for query compilation.\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// Embedding Brand Symbol\n// ============================================================\n\n/**\n * Symbol used to brand embedding values at the type level.\n * This allows TypeScript to distinguish embedding arrays from regular\n * number arrays in the query builder type system.\n */\ndeclare const EMBEDDING_BRAND: unique symbol;\n\n/**\n * Branded embedding type for type-level distinction.\n * At runtime this is just `readonly number[]`, but TypeScript can\n * distinguish it from regular arrays for query builder typing.\n */\nexport type EmbeddingValue = readonly number[] & {\n readonly [EMBEDDING_BRAND]: true;\n};\n\n// ============================================================\n// Embedding Metadata Symbol\n// ============================================================\n\n/**\n * Symbol key for storing embedding dimensions on the schema.\n * This allows the schema introspector to detect embedding types\n * and extract dimension information.\n */\nexport const EMBEDDING_DIMENSIONS_KEY = \"_embeddingDimensions\" as const;\n\n// ============================================================\n// Embedding Schema Type\n// ============================================================\n\n/**\n * A Zod schema for vector embeddings with attached dimension metadata.\n * Uses the branded EmbeddingValue type for type-level distinction.\n */\nexport type EmbeddingSchema<D extends number = number> =\n z.ZodType<EmbeddingValue> &\n Readonly<{\n [EMBEDDING_DIMENSIONS_KEY]: D;\n }>;\n\n// ============================================================\n// Embedding Factory\n// ============================================================\n\n/**\n * Creates a Zod schema for vector embeddings.\n *\n * The dimension is validated at runtime and attached as metadata\n * for the schema introspector and query compiler.\n *\n * @param dimensions - The number of dimensions (e.g., 384, 512, 768, 1536, 3072)\n * @returns A Zod schema that validates embedding arrays\n *\n * @example\n * ```typescript\n * // OpenAI ada-002 embeddings\n * const Document = defineNode(\"Document\", {\n * schema: z.object({\n * title: z.string(),\n * embedding: embedding(1536),\n * }),\n * });\n *\n * // Sentence transformers\n * const Sentence = defineNode(\"Sentence\", {\n * schema: z.object({\n * text: z.string(),\n * embedding: embedding(384), // all-MiniLM-L6-v2\n * }),\n * });\n *\n * // Optional embeddings are supported\n * const Article = defineNode(\"Article\", {\n * schema: z.object({\n * content: z.string(),\n * embedding: embedding(1536).optional(),\n * }),\n * });\n * ```\n */\nexport function embedding<D extends number>(dimensions: D): EmbeddingSchema<D> {\n if (!Number.isInteger(dimensions) || dimensions <= 0) {\n throw new Error(\n `Embedding dimensions must be a positive integer, got: ${dimensions}`,\n );\n }\n\n // Use EmbeddingValue as the output type for proper type branding.\n // At runtime, validation accepts any number array with correct dimensions.\n const schema = z.custom<EmbeddingValue>(\n (value): value is EmbeddingValue => {\n if (!Array.isArray(value)) {\n return false;\n }\n if (value.length !== dimensions) {\n return false;\n }\n return value.every((n) => typeof n === \"number\" && Number.isFinite(n));\n },\n {\n message: `Expected an array of ${dimensions} finite numbers`,\n },\n );\n\n // Attach dimensions metadata for introspection\n return Object.assign(schema, {\n [EMBEDDING_DIMENSIONS_KEY]: dimensions,\n });\n}\n\n// ============================================================\n// Type Guards\n// ============================================================\n\n/**\n * Checks if a value is an embedding schema.\n */\nexport function isEmbeddingSchema(value: unknown): value is EmbeddingSchema {\n return (\n typeof value === \"object\" &&\n value !== null &&\n EMBEDDING_DIMENSIONS_KEY in value &&\n typeof (value as Record<string, unknown>)[EMBEDDING_DIMENSIONS_KEY] ===\n \"number\"\n );\n}\n\n/**\n * Gets the dimensions from an embedding schema.\n * Returns undefined if the schema is not an embedding schema.\n */\nexport function getEmbeddingDimensions(schema: z.ZodType): number | undefined {\n if (isEmbeddingSchema(schema)) {\n return schema[EMBEDDING_DIMENSIONS_KEY];\n }\n return undefined;\n}\n","/**\n * Searchable string type for fulltext search.\n *\n * `searchable()` attaches `SearchableMetadata` to a plain Zod string so\n * the schema introspector and fulltext-sync layer can keep the fulltext\n * index in sync with node data.\n *\n * The metadata is preserved by Zod's `.meta()` across refinements\n * (`.min(1)`, `.trim()`, `.regex(...)`) and wrapper types (`.optional()`,\n * `.nullable()`, `.default(...)`, pipes) — `getSearchableMetadata()` walks\n * these variants so runtime indexing works whether or not a user chains\n * additional modifiers.\n *\n * `$fulltext` is exposed on every `NodeAccessor` at the type level; a\n * runtime guard throws a clear error if you call `.matches()` on an\n * alias whose node kind has no `searchable()` fields. This is simpler\n * and more predictable than a type-level brand that silently disappears\n * behind `.min(1)`.\n *\n * @example\n * ```typescript\n * const Document = defineNode(\"Document\", {\n * schema: z.object({\n * title: searchable({ language: \"english\" }),\n * body: searchable().min(1),\n * authorId: z.string(),\n * }),\n * });\n * ```\n */\nimport { z } from \"zod\";\n\nexport const SEARCHABLE_FIELD_KEY = \"_searchableField\" as const;\n\nexport const DEFAULT_SEARCHABLE_LANGUAGE = \"english\" as const;\n\nconst SEARCHABLE_WRAPPER_TYPES = new Set([\n \"optional\",\n \"nullable\",\n \"default\",\n \"prefault\",\n \"catch\",\n \"readonly\",\n \"nonoptional\",\n \"success\",\n]);\n\n/**\n * Searchable field metadata attached to a Zod schema.\n */\nexport type SearchableMetadata = Readonly<{\n /**\n * Language for stemming / tokenization.\n * Postgres: passed to `to_tsvector(regconfig, ...)`.\n * SQLite FTS5: tokenizer is fixed at table-create time, so the\n * language is recorded but not applied per-row.\n */\n language: string;\n}>;\n\n/**\n * Branded Zod string schema. The `SEARCHABLE_FIELD_KEY` marker is\n * attached both as a direct property (fast runtime check) and via Zod's\n * `.meta()` (so it survives `.min()`, `.trim()`, etc.).\n */\nexport type SearchableSchema = z.ZodString &\n Readonly<{\n [SEARCHABLE_FIELD_KEY]: SearchableMetadata;\n }>;\n\nexport type SearchableOptions = Readonly<{\n language?: string;\n}>;\n\ntype SearchableMetaRecord = Readonly<\n Partial<Record<typeof SEARCHABLE_FIELD_KEY, unknown>>\n>;\n\ntype SearchableSchemaDef = Readonly<{\n innerType?: z.ZodType;\n in?: z.ZodType;\n out?: z.ZodType;\n}>;\n\nfunction readSearchableMetadata(\n value: unknown,\n): SearchableMetadata | undefined {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const language = (value as Partial<SearchableMetadata>).language;\n return typeof language === \"string\" ? { language } : undefined;\n}\n\nfunction getSearchableMetadataFromSchemaMeta(\n schema: z.ZodType,\n): SearchableMetadata | undefined {\n const meta = schema.meta() as SearchableMetaRecord | undefined;\n return readSearchableMetadata(meta?.[SEARCHABLE_FIELD_KEY]);\n}\n\n/**\n * Creates a Zod string schema tagged as fulltext-searchable.\n *\n * The returned schema passes runtime validation unchanged — the tag only\n * affects how TypeGraph treats the field for indexing and search. Pair\n * with `.optional()` / `.nullable()` / `.min()` / `.trim()` exactly like\n * any other Zod string; `getSearchableMetadata()` finds the metadata\n * through all of them.\n */\nexport function searchable(options: SearchableOptions = {}): SearchableSchema {\n const language = options.language ?? DEFAULT_SEARCHABLE_LANGUAGE;\n\n if (language.length === 0) {\n throw new Error(\"searchable() language must be a non-empty string\");\n }\n\n const metadata: SearchableMetadata = { language };\n const schema = z.string().meta({\n [SEARCHABLE_FIELD_KEY]: metadata,\n });\n\n return Object.assign(schema, {\n [SEARCHABLE_FIELD_KEY]: metadata,\n });\n}\n\nexport function isSearchableSchema(value: unknown): value is SearchableSchema {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(SEARCHABLE_FIELD_KEY in value)) return false;\n return (\n readSearchableMetadata(\n (value as Record<string, unknown>)[SEARCHABLE_FIELD_KEY],\n ) !== undefined\n );\n}\n\nexport function getSearchableMetadata(\n schema: z.ZodType,\n): SearchableMetadata | undefined {\n if (isSearchableSchema(schema)) {\n return schema[SEARCHABLE_FIELD_KEY];\n }\n\n const directMetadata = getSearchableMetadataFromSchemaMeta(schema);\n if (directMetadata !== undefined) {\n return directMetadata;\n }\n\n const def = schema.def as SearchableSchemaDef;\n if (\n SEARCHABLE_WRAPPER_TYPES.has(schema.type) &&\n def.innerType !== undefined\n ) {\n return getSearchableMetadata(def.innerType);\n }\n\n if (schema.type === \"pipe\") {\n return (\n (def.in === undefined ? undefined : getSearchableMetadata(def.in)) ??\n (def.out === undefined ? undefined : getSearchableMetadata(def.out))\n );\n }\n\n return undefined;\n}\n","// JSON Pointer utilities and types.\n\nexport const MAX_JSON_POINTER_DEPTH = 5 as const;\n\nexport type JsonPointer = string & { readonly __jsonPointer: unique symbol };\nexport type JsonPointerSegment = string | number;\nexport type JsonPointerSegments = readonly JsonPointerSegment[];\n\ntype Depth = 0 | 1 | 2 | 3 | 4 | 5;\n\ninterface DepthDecrementMap {\n 0: 0;\n 1: 0;\n 2: 1;\n 3: 2;\n 4: 3;\n 5: 4;\n}\n\ntype Decrement<Current extends Depth> = DepthDecrementMap[Current];\n\ntype NonNegativeIntegerString = Exclude<`${bigint}`, `-${string}`>;\ntype ObjectPointerKey<T> = Exclude<\n Extract<keyof T, string>,\n NonNegativeIntegerString\n>;\n\ntype EncodeTilde<S extends string> =\n S extends `${infer Head}~${infer Tail}` ?\n `${EncodeTilde<Head>}~0${EncodeTilde<Tail>}`\n : S;\n\ntype EncodeSlash<S extends string> =\n S extends `${infer Head}/${infer Tail}` ?\n `${EncodeSlash<Head>}~1${EncodeSlash<Tail>}`\n : S;\n\ntype EncodePointerSegment<S extends string> = EncodeSlash<EncodeTilde<S>>;\n\ntype DecodePointerSegment<S extends string> =\n S extends `${infer Head}~1${infer Tail}` ?\n `${DecodePointerSegment<Head>}/${DecodePointerSegment<Tail>}`\n : S extends `${infer Head}~0${infer Tail}` ?\n `${DecodePointerSegment<Head>}~${DecodePointerSegment<Tail>}`\n : S;\n\ntype PointerForArray<T, Current extends Depth> =\n | `/${NonNegativeIntegerString}`\n | (Current extends 1 ? never\n : `/${NonNegativeIntegerString}${JsonPointerFor<T, Decrement<Current>>}`);\n\ntype PointerForObject<T, Current extends Depth> = {\n [K in ObjectPointerKey<T>]:\n | `/${EncodePointerSegment<K>}`\n | (Current extends 1 ? never\n : `/${EncodePointerSegment<K>}${JsonPointerFor<T[K], Decrement<Current>>}`);\n}[ObjectPointerKey<T>];\n\nexport type JsonPointerFor<T, Current extends Depth = 5> =\n | \"\"\n | (Current extends 0 ? \"\"\n : T extends readonly (infer U)[] ? PointerForArray<U, Current>\n : never)\n | (Current extends 0 ? \"\"\n : T extends Record<string, unknown> ? PointerForObject<T, Current>\n : never);\n\ntype PointerSegmentsForArray<T, Current extends Depth> =\n | readonly [number]\n | (Current extends 1 ? readonly [number]\n : readonly [number, ...JsonPointerSegmentsFor<T, Decrement<Current>>]);\n\ntype PointerSegmentsForObject<T, Current extends Depth> = {\n [K in ObjectPointerKey<T>]:\n | readonly [K]\n | (Current extends 1 ? readonly [K]\n : readonly [K, ...JsonPointerSegmentsFor<T[K], Decrement<Current>>]);\n}[ObjectPointerKey<T>];\n\nexport type JsonPointerSegmentsFor<T, Current extends Depth = 5> =\n | readonly []\n | (Current extends 0 ? readonly []\n : T extends readonly (infer U)[] ? PointerSegmentsForArray<U, Current>\n : never)\n | (Current extends 0 ? readonly []\n : T extends Record<string, unknown> ? PointerSegmentsForObject<T, Current>\n : never);\n\nexport type JsonPointerInput<T> =\n | JsonPointerFor<T>\n | JsonPointerSegmentsFor<T>\n | JsonPointer;\n\nexport type ResolveJsonPointer<T, Pointer extends string> =\n Pointer extends \"\" ? T\n : Pointer extends `/${infer Head}/${infer Tail}` ?\n ResolveJsonPointer<\n ResolvePointerSegment<T, DecodePointerSegment<Head>>,\n `/${Tail}`\n >\n : Pointer extends `/${infer Head}` ?\n ResolvePointerSegment<T, DecodePointerSegment<Head>>\n : unknown;\n\ntype ResolvePointerSegment<T, Segment extends string> =\n T extends readonly (infer U)[] ?\n Segment extends NonNegativeIntegerString ?\n U\n : unknown\n : T extends Record<string, unknown> ?\n Segment extends keyof T ?\n Segment extends NonNegativeIntegerString ?\n unknown\n : T[Segment]\n : unknown\n : unknown;\n\nexport type ResolveJsonPointerSegments<\n T,\n Segments extends readonly JsonPointerSegment[],\n> =\n Segments extends readonly [] ? T\n : Segments extends readonly [infer Head, ...infer Tail] ?\n ResolveJsonPointerSegments<\n ResolvePointerSegment<T, SegmentToString<Head>>,\n Extract<Tail, readonly JsonPointerSegment[]>\n >\n : unknown;\n\ntype SegmentToString<Segment> =\n Segment extends number ? `${Segment}`\n : Segment extends string ? Segment\n : string;\n\nexport function jsonPointer(segments: JsonPointerSegments): JsonPointer {\n if (segments.length > MAX_JSON_POINTER_DEPTH) {\n throw new Error(\n `JSON Pointer exceeds max depth ${MAX_JSON_POINTER_DEPTH}: ${segments.length}`,\n );\n }\n\n if (segments.length === 0) {\n return \"\" as JsonPointer;\n }\n\n const encoded = segments.map((segment) => {\n if (segment === \"-\") {\n throw new Error(\n \"JSON Pointer '-' segment is not allowed for query access\",\n );\n }\n if (typeof segment === \"number\") {\n if (!Number.isInteger(segment) || segment < 0) {\n throw new Error(\n `JSON Pointer index must be a non-negative integer: ${segment}`,\n );\n }\n return segment.toString();\n }\n return encodeJsonPointerSegment(segment);\n });\n\n return `/${encoded.join(\"/\")}` as JsonPointer;\n}\n\nfunction isJsonPointerSegments(\n input: unknown,\n): input is readonly JsonPointerSegment[] {\n return Array.isArray(input);\n}\n\nexport function normalizeJsonPointer<T>(\n input: JsonPointerInput<T>,\n): JsonPointer {\n if (isJsonPointerSegments(input)) {\n return jsonPointer(input);\n }\n\n return assertJsonPointer(input);\n}\n\nexport function parseJsonPointer(pointer: JsonPointer): readonly string[] {\n if (pointer === \"\") {\n return [];\n }\n\n const rawSegments = pointer.slice(1).split(\"/\");\n return rawSegments.map((segment) => decodeJsonPointerSegment(segment));\n}\n\nexport function joinJsonPointers(\n base: JsonPointer | undefined,\n relative: JsonPointer,\n): JsonPointer {\n if (!base || base === \"\") {\n return relative;\n }\n if (relative === \"\") {\n return base;\n }\n\n const combinedSegments = [\n ...parseJsonPointer(base),\n ...parseJsonPointer(relative),\n ];\n return jsonPointer(combinedSegments);\n}\n\nfunction assertJsonPointer(pointer: string): JsonPointer {\n if (pointer !== \"\" && !pointer.startsWith(\"/\")) {\n throw new Error(\"JSON Pointer must be empty or start with '/'\");\n }\n\n const segments = pointer === \"\" ? [] : pointer.slice(1).split(\"/\");\n if (segments.length > MAX_JSON_POINTER_DEPTH) {\n throw new Error(\n `JSON Pointer exceeds max depth ${MAX_JSON_POINTER_DEPTH}: ${segments.length}`,\n );\n }\n\n for (const segment of segments) {\n if (segment === \"-\") {\n throw new Error(\n \"JSON Pointer '-' segment is not allowed for query access\",\n );\n }\n if (!isValidPointerEncoding(segment)) {\n throw new Error(\n `Invalid JSON Pointer escape sequence in segment: ${segment}`,\n );\n }\n }\n\n return pointer as JsonPointer;\n}\n\nfunction encodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction decodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\nfunction isValidPointerEncoding(segment: string): boolean {\n for (let index = 0; index < segment.length; index += 1) {\n if (segment[index] !== \"~\") {\n continue;\n }\n const next = segment[index + 1];\n if (next !== \"0\" && next !== \"1\") {\n return false;\n }\n index += 1;\n }\n return true;\n}\n","import { type JsonPointer, parseJsonPointer } from \"./json-pointer\";\nimport { type FieldTypeInfo } from \"./schema-introspector\";\n\nfunction isJsonPointerIndex(segment: string): boolean {\n return /^\\d+$/.test(segment);\n}\n\nexport function resolveFieldTypeInfoAtJsonPointer(\n typeInfo: FieldTypeInfo | undefined,\n pointer: JsonPointer,\n): FieldTypeInfo | undefined {\n if (!typeInfo) {\n return undefined;\n }\n\n const segments = parseJsonPointer(pointer);\n\n let current: FieldTypeInfo | undefined = typeInfo;\n for (const segment of segments) {\n if (!current) {\n return undefined;\n }\n\n if (current.valueType === \"array\") {\n if (!isJsonPointerIndex(segment)) {\n throw new Error(\n `JSON Pointer segment \"${segment}\" is not a valid array index`,\n );\n }\n current = current.elementTypeInfo;\n continue;\n }\n\n if (current.valueType === \"object\") {\n if (isJsonPointerIndex(segment)) {\n throw new Error(\n \"JSON Pointer numeric segments are only valid for arrays\",\n );\n }\n if (current.shape && segment in current.shape) {\n current = current.shape[segment];\n continue;\n }\n if (current.recordValueType) {\n current = current.recordValueType;\n continue;\n }\n throw new Error(\n `JSON Pointer segment \"${segment}\" is not defined on object schema`,\n );\n }\n\n throw new Error(\n `JSON Pointer segment \"${segment}\" cannot traverse ${current.valueType}`,\n );\n }\n\n return current;\n}\n","import { type z } from \"zod\";\n\nimport { getEmbeddingDimensions } from \"../core/embedding\";\nimport {\n getSearchableMetadata,\n type SearchableMetadata,\n} from \"../core/searchable\";\nimport { type ValueType } from \"./ast\";\n\nconst SUPPORTED_SCHEMA_TYPES = [\n \"string\",\n \"number\",\n \"nan\",\n \"boolean\",\n \"date\",\n \"literal\",\n \"enum\",\n \"nativeEnum\",\n \"array\",\n \"tuple\",\n \"object\",\n \"record\",\n \"union\",\n \"discriminatedUnion\",\n \"intersection\",\n] as const;\n\ntype SupportedSchemaType = (typeof SUPPORTED_SCHEMA_TYPES)[number];\n\n// Use Set<string> to allow checking arbitrary strings while maintaining type safety\nconst SUPPORTED_SCHEMA_TYPE_SET: ReadonlySet<string> = new Set(\n SUPPORTED_SCHEMA_TYPES,\n);\n\nfunction isSupportedSchemaType(type: string): type is SupportedSchemaType {\n return SUPPORTED_SCHEMA_TYPE_SET.has(type);\n}\n\nexport type FieldTypeInfo = Readonly<{\n valueType: ValueType;\n elementType?: ValueType | undefined;\n elementTypeInfo?: FieldTypeInfo | undefined;\n shape?: Readonly<Record<string, FieldTypeInfo>> | undefined;\n recordValueType?: FieldTypeInfo | undefined;\n /** For embedding types: the number of dimensions */\n dimensions?: number | undefined;\n /** For fulltext-searchable string types: field-level metadata */\n searchable?: SearchableMetadata | undefined;\n}>;\n\nexport type SchemaIntrospector = Readonly<{\n getFieldTypeInfo: (\n kindName: string,\n fieldName: string,\n ) => FieldTypeInfo | undefined;\n getSharedFieldTypeInfo: (\n kindNames: readonly string[],\n fieldName: string,\n ) => FieldTypeInfo | undefined;\n getEdgeFieldTypeInfo: (\n edgeKindName: string,\n fieldName: string,\n ) => FieldTypeInfo | undefined;\n getSharedEdgeFieldTypeInfo: (\n edgeKindNames: readonly string[],\n fieldName: string,\n ) => FieldTypeInfo | undefined;\n /**\n * True iff every kind in `kindNames` has at least one `searchable()`\n * field. For polymorphic aliases, `$fulltext` is available only when\n * every resolved kind has searchable content — otherwise `.matches()`\n * would silently miss some kinds.\n */\n hasSearchableField: (kindNames: readonly string[]) => boolean;\n}>;\n\nfunction sharedCacheKey(\n kindNames: readonly string[],\n fieldName: string,\n): string {\n return `${[...kindNames].toSorted().join(\"|\")}|${fieldName}`;\n}\n\nexport function createSchemaIntrospector(\n nodeKinds: ReadonlyMap<string, { schema: z.ZodType }>,\n edgeKinds?: ReadonlyMap<string, { schema: z.ZodType }>,\n): SchemaIntrospector {\n const nodeShapeCache = new Map<\n string,\n Readonly<Record<string, FieldTypeInfo>>\n >();\n const edgeShapeCache = new Map<\n string,\n Readonly<Record<string, FieldTypeInfo>>\n >();\n // Proxy-based field accessors trigger a fresh merge on every property\n // read during a `whereNode(n => ...)` callback. For polymorphic\n // aliases with N kinds and M field accesses, that is O(N*M) per\n // compile; caching collapses it to O(1) after the first access.\n const sharedFieldTypeInfoCache = new Map<string, FieldTypeInfo | undefined>();\n const sharedEdgeFieldTypeInfoCache = new Map<\n string,\n FieldTypeInfo | undefined\n >();\n const searchableCache = new Map<string, boolean>();\n\n function getFieldTypeInfo(\n kindName: string,\n fieldName: string,\n ): FieldTypeInfo | undefined {\n const shape = getShapeForKind(kindName);\n return shape?.[fieldName];\n }\n\n function getSharedFieldTypeInfo(\n kindNames: readonly string[],\n fieldName: string,\n ): FieldTypeInfo | undefined {\n const cacheKey = sharedCacheKey(kindNames, fieldName);\n if (sharedFieldTypeInfoCache.has(cacheKey)) {\n return sharedFieldTypeInfoCache.get(cacheKey);\n }\n\n const infos = kindNames\n .map((kindName) => getFieldTypeInfo(kindName, fieldName))\n .filter((info): info is FieldTypeInfo => info !== undefined);\n\n const merged =\n infos.length !== kindNames.length || infos.length === 0 ?\n undefined\n : mergeFieldTypeInfos(infos);\n sharedFieldTypeInfoCache.set(cacheKey, merged);\n return merged;\n }\n\n function getEdgeFieldTypeInfo(\n edgeKindName: string,\n fieldName: string,\n ): FieldTypeInfo | undefined {\n const shape = getShapeForEdgeKind(edgeKindName);\n return shape?.[fieldName];\n }\n\n function getSharedEdgeFieldTypeInfo(\n edgeKindNames: readonly string[],\n fieldName: string,\n ): FieldTypeInfo | undefined {\n const cacheKey = sharedCacheKey(edgeKindNames, fieldName);\n if (sharedEdgeFieldTypeInfoCache.has(cacheKey)) {\n return sharedEdgeFieldTypeInfoCache.get(cacheKey);\n }\n\n const infos = edgeKindNames\n .map((kindName) => getEdgeFieldTypeInfo(kindName, fieldName))\n .filter((info): info is FieldTypeInfo => info !== undefined);\n\n const merged =\n infos.length !== edgeKindNames.length || infos.length === 0 ?\n undefined\n : mergeFieldTypeInfos(infos);\n sharedEdgeFieldTypeInfoCache.set(cacheKey, merged);\n return merged;\n }\n\n function getShapeForKind(\n kindName: string,\n ): Readonly<Record<string, FieldTypeInfo>> | undefined {\n const cached = nodeShapeCache.get(kindName);\n if (cached) {\n return cached;\n }\n\n const kind = nodeKinds.get(kindName);\n if (!kind) {\n return undefined;\n }\n\n const schema = kind.schema;\n if (schema.type !== \"object\") {\n return undefined;\n }\n\n const shape = (schema.def as { shape?: Record<string, z.ZodType> }).shape;\n if (!shape) {\n return undefined;\n }\n\n const entries = Object.entries(shape).map(\n ([key, value]) => [key, resolveFieldTypeInfo(value)] as const,\n );\n const resolved = Object.freeze(Object.fromEntries(entries));\n nodeShapeCache.set(kindName, resolved);\n return resolved;\n }\n\n function getShapeForEdgeKind(\n edgeKindName: string,\n ): Readonly<Record<string, FieldTypeInfo>> | undefined {\n if (!edgeKinds) {\n return undefined;\n }\n\n const cached = edgeShapeCache.get(edgeKindName);\n if (cached) {\n return cached;\n }\n\n const kind = edgeKinds.get(edgeKindName);\n if (!kind) {\n return undefined;\n }\n\n const schema = kind.schema;\n if (schema.type !== \"object\") {\n return undefined;\n }\n\n const shape = (schema.def as { shape?: Record<string, z.ZodType> }).shape;\n if (!shape) {\n return undefined;\n }\n\n const entries = Object.entries(shape).map(\n ([key, value]) => [key, resolveFieldTypeInfo(value)] as const,\n );\n const resolved = Object.freeze(Object.fromEntries(entries));\n edgeShapeCache.set(edgeKindName, resolved);\n return resolved;\n }\n\n function hasSearchableField(kindNames: readonly string[]): boolean {\n const cacheKey = [...kindNames].toSorted().join(\"|\");\n const cached = searchableCache.get(cacheKey);\n if (cached !== undefined) return cached;\n\n const result =\n kindNames.length > 0 &&\n kindNames.every((kindName) => {\n const shape = getShapeForKind(kindName);\n if (!shape) return false;\n return Object.values(shape).some(\n (info) => info.searchable !== undefined,\n );\n });\n searchableCache.set(cacheKey, result);\n return result;\n }\n\n return {\n getFieldTypeInfo,\n getSharedFieldTypeInfo,\n getEdgeFieldTypeInfo,\n getSharedEdgeFieldTypeInfo,\n hasSearchableField,\n };\n}\n\nfunction resolveFieldTypeInfo(schema: z.ZodType): FieldTypeInfo {\n // Check for embedding type before unwrapping\n // (embedding metadata is attached to the outer schema)\n const embeddingDimensions = getEmbeddingDimensions(schema);\n if (embeddingDimensions !== undefined) {\n return { valueType: \"embedding\", dimensions: embeddingDimensions };\n }\n\n const searchableMetadata = getSearchableMetadata(schema);\n const searchableStringSchema =\n searchableMetadata === undefined ? undefined : (\n unwrapSearchableStringSchema(schema)\n );\n if (\n searchableMetadata !== undefined &&\n searchableStringSchema !== undefined\n ) {\n return { valueType: \"string\", searchable: searchableMetadata };\n }\n\n const unwrapped = unwrapSchema(schema);\n\n // Check embedding on unwrapped schema too (for z.optional(embedding(...)))\n const unwrappedEmbeddingDimensions = getEmbeddingDimensions(unwrapped);\n if (unwrappedEmbeddingDimensions !== undefined) {\n return { valueType: \"embedding\", dimensions: unwrappedEmbeddingDimensions };\n }\n\n // Cast to string to detach from Zod's internal type union,\n // then let the type guard narrow to our SupportedSchemaType.\n const rawType = unwrapped.type as string;\n\n if (!isSupportedSchemaType(rawType)) {\n return { valueType: \"unknown\" };\n }\n\n // After the type guard, rawType is SupportedSchemaType.\n const schemaType = rawType;\n\n // Handle each schema type individually\n if (schemaType === \"string\") {\n return { valueType: \"string\" };\n }\n if (schemaType === \"number\" || schemaType === \"nan\") {\n return { valueType: \"number\" };\n }\n if (schemaType === \"boolean\") {\n return { valueType: \"boolean\" };\n }\n if (schemaType === \"date\") {\n return { valueType: \"date\" };\n }\n if (schemaType === \"literal\") {\n const literalValue = (unwrapped.def as { value?: unknown }).value;\n return resolveLiteralTypeInfo(literalValue);\n }\n if (schemaType === \"enum\") {\n return { valueType: \"string\" };\n }\n if (schemaType === \"nativeEnum\") {\n const values = Object.values(\n (unwrapped.def as { values?: Record<string, unknown> }).values ?? {},\n );\n const valueType = resolveEnumValueType(values);\n return { valueType };\n }\n if (schemaType === \"array\") {\n const elementSchema = (unwrapped.def as { element?: z.ZodType }).element;\n const elementInfo =\n elementSchema ? resolveFieldTypeInfo(elementSchema) : undefined;\n return {\n valueType: \"array\",\n elementType: elementInfo?.valueType,\n elementTypeInfo: elementInfo,\n };\n }\n if (schemaType === \"tuple\") {\n return {\n valueType: \"array\",\n elementType: \"unknown\",\n };\n }\n if (schemaType === \"object\") {\n const shape = (unwrapped.def as { shape?: Record<string, z.ZodType> })\n .shape;\n if (!shape) {\n return { valueType: \"object\" };\n }\n const entries = Object.entries(shape).map(\n ([key, value]) => [key, resolveFieldTypeInfo(value)] as const,\n );\n const resolved = Object.freeze(Object.fromEntries(entries));\n return {\n valueType: \"object\",\n shape: resolved,\n };\n }\n if (schemaType === \"record\") {\n const valueSchema = (unwrapped.def as { valueType?: z.ZodType }).valueType;\n const valueInfo =\n valueSchema ? resolveFieldTypeInfo(valueSchema) : undefined;\n return {\n valueType: \"object\",\n recordValueType: valueInfo,\n };\n }\n if (schemaType === \"union\" || schemaType === \"discriminatedUnion\") {\n const unionOptions = (unwrapped.def as { options?: readonly z.ZodType[] })\n .options;\n if (!unionOptions || unionOptions.length === 0) {\n return { valueType: \"unknown\" };\n }\n const optionInfos = unionOptions.map((option) =>\n resolveFieldTypeInfo(option),\n );\n return mergeFieldTypeInfos(optionInfos) ?? { valueType: \"unknown\" };\n }\n\n // Only \"intersection\" remains after all other cases\n const left = (unwrapped.def as { left?: z.ZodType }).left;\n const right = (unwrapped.def as { right?: z.ZodType }).right;\n if (!left || !right) {\n return { valueType: \"unknown\" };\n }\n const leftInfo = resolveFieldTypeInfo(left);\n const rightInfo = resolveFieldTypeInfo(right);\n return mergeFieldTypeInfos([leftInfo, rightInfo]) ?? { valueType: \"unknown\" };\n}\n\nfunction resolveLiteralTypeInfo(value: unknown): FieldTypeInfo {\n if (value instanceof Date) {\n return { valueType: \"date\" };\n }\n if (typeof value === \"string\") {\n return { valueType: \"string\" };\n }\n if (typeof value === \"number\") {\n return { valueType: \"number\" };\n }\n if (typeof value === \"boolean\") {\n return { valueType: \"boolean\" };\n }\n return { valueType: \"unknown\" };\n}\n\nfunction resolveEnumValueType(values: readonly unknown[]): ValueType {\n const uniqueTypes = new Set(values.map((value) => typeof value));\n if (uniqueTypes.size !== 1) {\n return \"unknown\";\n }\n\n const type = uniqueTypes.values().next().value;\n if (type === \"string\") {\n return \"string\";\n }\n if (type === \"number\") {\n return \"number\";\n }\n if (type === \"boolean\") {\n return \"boolean\";\n }\n return \"unknown\";\n}\n\nfunction mergeFieldTypeInfos(\n infos: readonly FieldTypeInfo[],\n): FieldTypeInfo | undefined {\n const [first, ...rest] = infos;\n if (!first) {\n return undefined;\n }\n\n const sameValueType = rest.every(\n (info) => info.valueType === first.valueType,\n );\n if (!sameValueType) {\n return undefined;\n }\n\n if (first.valueType === \"array\") {\n const elementType =\n rest.every((info) => info.elementType === first.elementType) ?\n first.elementType\n : \"unknown\";\n const elementTypeInfo =\n (\n rest.every(\n (info) =>\n info.elementTypeInfo?.valueType ===\n first.elementTypeInfo?.valueType,\n )\n ) ?\n first.elementTypeInfo\n : undefined;\n return {\n valueType: \"array\",\n elementType,\n elementTypeInfo,\n };\n }\n\n if (first.valueType === \"object\") {\n const shapes = infos\n .map((info) => info.shape)\n .filter(\n (shape): shape is Readonly<Record<string, FieldTypeInfo>> =>\n shape !== undefined,\n );\n\n const shape =\n shapes.length === infos.length ? intersectShapes(shapes) : undefined;\n\n const recordValueType =\n (\n rest.every(\n (info) =>\n info.recordValueType?.valueType ===\n first.recordValueType?.valueType,\n )\n ) ?\n first.recordValueType\n : undefined;\n\n return {\n valueType: \"object\",\n shape,\n recordValueType,\n };\n }\n\n // Strings: only mark the merged result as searchable if every kind\n // in the polymorphic alias declares the field as searchable. A field\n // that isn't uniformly searchable would silently search only some\n // kinds via `.matches()`.\n if (first.valueType === \"string\") {\n const allSearchable =\n first.searchable !== undefined &&\n rest.every((info) => info.searchable !== undefined);\n return allSearchable ?\n { valueType: \"string\", searchable: first.searchable }\n : { valueType: \"string\" };\n }\n\n return first;\n}\n\nfunction intersectShapes(\n shapes: readonly Readonly<Record<string, FieldTypeInfo>>[],\n): Readonly<Record<string, FieldTypeInfo>> {\n const [first, ...rest] = shapes;\n if (!first) {\n return Object.freeze({});\n }\n\n const keys = Object.keys(first).filter((key) =>\n rest.every((shape) => key in shape),\n );\n\n const entries = keys\n .map((key) => {\n const infos = shapes.map((shape) => shape[key]!);\n const merged = mergeFieldTypeInfos(infos);\n if (!merged) {\n return;\n }\n return [key, merged] as const;\n })\n .filter(\n (entry): entry is readonly [string, FieldTypeInfo] => entry !== undefined,\n );\n\n return Object.freeze(Object.fromEntries(entries));\n}\n\nfunction unwrapSearchableStringSchema(\n schema: z.ZodType,\n): z.ZodType | undefined {\n const type = schema.type;\n const def = schema.def as {\n innerType?: z.ZodType;\n in?: z.ZodType;\n out?: z.ZodType;\n };\n\n if (\n (type === \"optional\" ||\n type === \"nullable\" ||\n type === \"default\" ||\n type === \"prefault\" ||\n type === \"catch\" ||\n type === \"readonly\" ||\n type === \"nonoptional\" ||\n type === \"success\") &&\n def.innerType\n ) {\n return unwrapSearchableStringSchema(def.innerType);\n }\n\n if (type === \"pipe\") {\n return (\n (def.in === undefined ?\n undefined\n : unwrapSearchableStringSchema(def.in)) ??\n (def.out === undefined ?\n undefined\n : unwrapSearchableStringSchema(def.out))\n );\n }\n\n const unwrapped = unwrapSchema(schema);\n return unwrapped.type === \"string\" ? unwrapped : undefined;\n}\n\nfunction unwrapSchema(schema: z.ZodType): z.ZodType {\n const type = schema.type;\n const def = schema.def as {\n innerType?: z.ZodType;\n out?: z.ZodType;\n };\n\n if (\n (type === \"optional\" ||\n type === \"nullable\" ||\n type === \"default\" ||\n type === \"prefault\" ||\n type === \"catch\" ||\n type === \"readonly\" ||\n type === \"nonoptional\" ||\n type === \"success\") &&\n def.innerType\n ) {\n return unwrapSchema(def.innerType);\n }\n\n if (type === \"pipe\" && def.out) {\n return unwrapSchema(def.out);\n }\n\n return schema;\n}\n"]}
|
|
@@ -143,5 +143,5 @@ exports.isGraphDef = isGraphDef;
|
|
|
143
143
|
exports.isNodeType = isNodeType;
|
|
144
144
|
exports.nowIso = nowIso;
|
|
145
145
|
exports.validateOptionalIsoDate = validateOptionalIsoDate;
|
|
146
|
-
//# sourceMappingURL=chunk-
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
146
|
+
//# sourceMappingURL=chunk-WRWVWKQL.cjs.map
|
|
147
|
+
//# sourceMappingURL=chunk-WRWVWKQL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/types.ts","../src/core/define-graph.ts","../src/utils/date.ts"],"names":["ConfigurationError","ValidationError"],"mappings":";;;;;AAOO,IAAM,eAAA,GAAkB;AAGxB,IAAM,eAAA,GAAkB;AA0PxB,SAAS,WAAW,KAAA,EAAmC;AAC5D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAKO,SAAS,WAAW,KAAA,EAAsC;AAC/D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAMO,SAAS,wBACd,KAAA,EACgC;AAChC,EAAA,OACE,WAAW,KAAK,CAAA,IAChB,MAAM,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,IACxB,KAAA,CAAM,KAAK,MAAA,GAAS,CAAA,IACpB,MAAM,OAAA,CAAQ,KAAA,CAAM,EAAE,CAAA,IACtB,KAAA,CAAM,GAAG,MAAA,GAAS,CAAA;AAEtB;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ACxE,EAAA,IAAI,CAAC,cAAA,CAAe,KAAK,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAIC,iCAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,IAAA,EAAO,KAAK,CAAA,4CAAA,CAAA;AAAA,MAEvD;AAAA,QACE,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,IAAA,EAAM,SAAA;AAAA,YACN,OAAA,EAAS,+EAA+E,KAAK,CAAA,CAAA;AAAA;AAC/F;AACF,OACF;AAAA,MACA;AAAA,QACE,UAAA,EAAY,CAAA,iEAAA;AAAA;AACd,KACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAMO,SAAS,uBAAA,CACd,OACA,SAAA,EACoB;AACpB,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,MAAA;AAChC,EAAA,OAAO,eAAA,CAAgB,OAAO,SAAS,CAAA;AACzC;AAuBO,SAAS,MAAA,GAAiB;AAC/B,EAAA,OAAA,iBAAO,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAChC","file":"chunk-5GZMPJOP.cjs","sourcesContent":["import { type z } from \"zod\";\n\n// ============================================================\n// Brand Keys for Nominal Typing\n// ============================================================\n\n/** Brand key for NodeType */\nexport const NODE_TYPE_BRAND = \"__nodeType\" as const;\n\n/** Brand key for EdgeType */\nexport const EDGE_TYPE_BRAND = \"__edgeType\" as const;\n\n/** Brand symbol for NodeId */\ndeclare const __nodeId: unique symbol;\n\n/** Brand symbol for EdgeId */\ndeclare const __edgeId: unique symbol;\n\n// ============================================================\n// Node Type\n// ============================================================\n\n/**\n * A node type definition.\n *\n * Created via `defineNode()`. Represents a type of node in the graph\n * with an associated Zod schema for properties.\n */\nexport type NodeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [NODE_TYPE_BRAND]: true;\n kind: K;\n schema: S;\n description: string | undefined;\n}>;\n\n/**\n * Branded node ID type.\n *\n * Prevents mixing IDs from different node types at compile time.\n */\nexport type NodeId<N extends NodeType> = string &\n Readonly<{\n [__nodeId]: N;\n }>;\n\n/**\n * Infer the props type from a NodeType.\n */\nexport type NodeProps<N extends NodeType> = z.infer<N[\"schema\"]>;\n\n// ============================================================\n// Edge Type\n// ============================================================\n\n/**\n * An edge type definition.\n *\n * Created via `defineEdge()`. Represents a type of edge in the graph\n * with an optional Zod schema for properties.\n *\n * Optionally includes `from` and `to` arrays that define the allowed\n * source and target node types (domain and range constraints).\n */\nexport type EdgeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n From extends readonly NodeType[] | undefined = undefined,\n To extends readonly NodeType[] | undefined = undefined,\n> = Readonly<{\n [EDGE_TYPE_BRAND]: true;\n kind: K;\n schema: S;\n description: string | undefined;\n from: From;\n to: To;\n}>;\n\n/**\n * Base edge type for use in constraints - accepts any from/to configuration.\n */\nexport type AnyEdgeType = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[] | undefined,\n readonly NodeType[] | undefined\n>;\n\n/**\n * An edge type that has both from and to constraints defined.\n * Can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport type EdgeTypeWithEndpoints = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[],\n readonly NodeType[]\n>;\n\n/**\n * Branded edge ID type.\n *\n * Prevents mixing IDs from different edge types at compile time.\n */\nexport type EdgeId<E extends AnyEdgeType = AnyEdgeType> = string &\n Readonly<{\n [__edgeId]: E;\n }>;\n\n/**\n * Infer the props type from an EdgeType.\n */\nexport type EdgeProps<E extends AnyEdgeType> = z.infer<E[\"schema\"]>;\n\n// ============================================================\n// Configuration Types\n// ============================================================\n\n/**\n * Delete behaviors for nodes.\n */\nexport type DeleteBehavior = \"restrict\" | \"cascade\" | \"disconnect\";\n\n/**\n * Edge cardinality constraints.\n */\nexport type Cardinality =\n | \"many\" // No constraint (default)\n | \"one\" // At most one edge of this kind from any source node\n | \"unique\" // At most one edge of this kind between any (source, target) pair\n | \"oneActive\"; // At most one edge with valid_to IS NULL from any source\n\n/**\n * Endpoint existence modes for edge validation.\n */\nexport type EndpointExistence =\n | \"notDeleted\" // Endpoint deleted_at IS NULL (default)\n | \"currentlyValid\" // Endpoint not deleted AND temporally valid\n | \"ever\"; // Endpoint exists in any state\n\n/**\n * Temporal query modes.\n */\nexport type TemporalMode =\n | \"current\" // Valid now AND not deleted\n | \"asOf\" // Valid at specific date AND not deleted\n | \"includeEnded\" // All validity periods AND not deleted\n | \"includeTombstones\"; // Everything including soft-deleted\n\n/**\n * Uniqueness constraint scope.\n */\nexport type UniquenessScope =\n | \"kind\" // Unique within this exact kind only\n | \"kindWithSubClasses\"; // Unique across this kind and all subclasses\n\n/**\n * Collation for uniqueness constraints.\n */\nexport type Collation = \"binary\" | \"caseInsensitive\";\n\n// ============================================================\n// Uniqueness Constraint\n// ============================================================\n\n/**\n * Uniqueness constraint definition.\n */\nexport type UniqueConstraint<\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n name: string;\n fields: readonly (keyof z.infer<S> & string)[];\n where?: (\n props: UniqueConstraintPredicateBuilder<S>,\n ) => UniqueConstraintPredicate;\n scope: UniquenessScope;\n collation: Collation;\n}>;\n\n/**\n * Predicate builder for uniqueness constraint where clause.\n * Uses -? to make all fields required in the builder, even if optional in the schema.\n */\nexport type UniqueConstraintPredicateBuilder<\n S extends z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [K in keyof z.infer<S>]-?: UniqueConstraintField;\n}>;\n\n/**\n * Field operations for uniqueness constraint predicates.\n */\ntype UniqueConstraintField = Readonly<{\n isNull: () => UniqueConstraintPredicate;\n isNotNull: () => UniqueConstraintPredicate;\n}>;\n\n/**\n * A uniqueness constraint predicate (internal representation).\n */\nexport type UniqueConstraintPredicate = Readonly<{\n __type: \"unique_predicate\";\n field: string;\n op: \"isNull\" | \"isNotNull\";\n}>;\n\n// ============================================================\n// Node Registration\n// ============================================================\n\n/**\n * Node registration in a graph definition.\n */\nexport type NodeRegistration<N extends NodeType = NodeType> = Readonly<{\n type: N;\n unique?: readonly UniqueConstraint<N[\"schema\"]>[];\n onDelete?: DeleteBehavior;\n}>;\n\n// ============================================================\n// Edge Registration\n// ============================================================\n\n/**\n * Edge registration in a graph definition.\n */\nexport type EdgeRegistration<\n E extends AnyEdgeType = AnyEdgeType,\n FromTypes extends NodeType = NodeType,\n ToTypes extends NodeType = NodeType,\n> = Readonly<{\n type: E;\n from: readonly FromTypes[];\n to: readonly ToTypes[];\n cardinality?: Cardinality;\n endpointExistence?: EndpointExistence;\n}>;\n\n// ============================================================\n// Graph Defaults\n// ============================================================\n\n/**\n * Default settings for a graph.\n */\nexport type GraphDefaults = Readonly<{\n onNodeDelete?: DeleteBehavior;\n temporalMode?: TemporalMode;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Checks if a value is a NodeType.\n */\nexport function isNodeType(value: unknown): value is NodeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n NODE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[NODE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType.\n */\nexport function isEdgeType(value: unknown): value is AnyEdgeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n EDGE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[EDGE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType with both from and to constraints defined.\n * Such edges can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport function isEdgeTypeWithEndpoints(\n value: unknown,\n): value is EdgeTypeWithEndpoints {\n return (\n isEdgeType(value) &&\n Array.isArray(value.from) &&\n value.from.length > 0 &&\n Array.isArray(value.to) &&\n value.to.length > 0\n );\n}\n","import { ConfigurationError } from \"../errors/index\";\nimport { type OntologyRelation } from \"../ontology/types\";\nimport {\n type AnyEdgeType,\n type DeleteBehavior,\n type EdgeRegistration,\n type EdgeTypeWithEndpoints,\n type GraphDefaults,\n isEdgeType,\n isEdgeTypeWithEndpoints,\n type NodeRegistration,\n type NodeType,\n type TemporalMode,\n} from \"./types\";\n\n// ============================================================\n// Graph Definition Brand Symbol\n// ============================================================\n\n/** Brand key for GraphDef */\nconst GRAPH_DEF_BRAND = \"__graphDef\" as const;\n\n// ============================================================\n// Edge Entry Types\n// ============================================================\n\n/**\n * An edge entry in the graph definition.\n * Can be:\n * - EdgeType directly (constrained or unconstrained)\n * - EdgeRegistration object (always works, can override/narrow defaults)\n */\ntype EdgeEntry = EdgeRegistration | AnyEdgeType;\n\n/**\n * Normalized edge map type - all entries become EdgeRegistration.\n * For bare EdgeTypes, constrained endpoints are extracted from the type;\n * unconstrained edges fall back to all node types in the graph.\n */\ntype NormalizedEdges<\n TNodes extends Record<string, NodeRegistration>,\n TEdges extends Record<string, EdgeEntry>,\n> = {\n [K in keyof TEdges]: TEdges[K] extends EdgeRegistration ? TEdges[K]\n : TEdges[K] extends AnyEdgeType ?\n EdgeRegistration<\n TEdges[K],\n TEdges[K][\"from\"] extends readonly (infer N extends NodeType)[] ? N\n : TNodes[keyof TNodes][\"type\"],\n TEdges[K][\"to\"] extends readonly (infer N extends NodeType)[] ? N\n : TNodes[keyof TNodes][\"type\"]\n >\n : never;\n};\n\n// ============================================================\n// Edge Normalization Functions\n// ============================================================\n\n/**\n * Validates that an EdgeRegistration's constraints don't widen beyond\n * the edge type's built-in domain/range constraints.\n */\nfunction validateConstraintNarrowing(\n name: string,\n edgeType: EdgeTypeWithEndpoints,\n registration: EdgeRegistration,\n): void {\n const builtInFromNames = new Set(edgeType.from.map((n) => n.kind));\n for (const fromNode of registration.from) {\n if (!builtInFromNames.has(fromNode.kind)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'from' kind \"${fromNode.kind}\" ` +\n `not in edge's built-in domain: [${[...builtInFromNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidFrom: fromNode.kind,\n allowedFrom: [...builtInFromNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n\n const builtInToNames = new Set(edgeType.to.map((n) => n.kind));\n for (const toNode of registration.to) {\n if (!builtInToNames.has(toNode.kind)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'to' kind \"${toNode.kind}\" ` +\n `not in edge's built-in range: [${[...builtInToNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidTo: toNode.kind,\n allowedTo: [...builtInToNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n}\n\n/**\n * Normalizes a single edge entry to EdgeRegistration.\n */\nfunction normalizeEdgeEntry(\n name: string,\n entry: EdgeEntry,\n allNodeTypes: readonly NodeType[],\n): EdgeRegistration {\n if (isEdgeType(entry)) {\n if (isEdgeTypeWithEndpoints(entry)) {\n // EdgeType with from/to — convert to EdgeRegistration\n return { type: entry, from: entry.from, to: entry.to };\n }\n // Unconstrained EdgeType — allow any→any\n return { type: entry, from: allNodeTypes, to: allNodeTypes };\n }\n\n // Already EdgeRegistration — validate narrowing if edge has built-in constraints\n if (isEdgeTypeWithEndpoints(entry.type)) {\n validateConstraintNarrowing(name, entry.type, entry);\n }\n\n return entry;\n}\n\n/**\n * Normalizes all edge entries to EdgeRegistration.\n */\nfunction normalizeEdges(\n edges: Record<string, EdgeEntry>,\n allNodeTypes: readonly NodeType[],\n): Record<string, EdgeRegistration> {\n const result: Record<string, EdgeRegistration> = {};\n for (const [name, entry] of Object.entries(edges)) {\n result[name] = normalizeEdgeEntry(name, entry, allNodeTypes);\n }\n return result;\n}\n\n// ============================================================\n// Graph Definition Configuration\n// ============================================================\n\n/**\n * Configuration for defineGraph.\n */\ntype GraphDefConfig<\n TNodes extends Record<string, NodeRegistration>,\n TEdges extends Record<string, EdgeEntry>,\n TOntology extends readonly OntologyRelation[],\n> = Readonly<{\n /** Unique identifier for this graph */\n id: string;\n /** Node registrations */\n nodes: TNodes;\n /** Edge registrations or EdgeTypes with built-in domain/range */\n edges: TEdges;\n /** Ontology relations */\n ontology?: TOntology;\n /** Graph-wide defaults */\n defaults?: GraphDefaults;\n}>;\n\n// ============================================================\n// Graph Definition Type\n// ============================================================\n\n/**\n * A graph definition.\n *\n * This is a compile-time artifact that describes the structure of a graph.\n * Use `createStore()` to create a runtime store from this definition.\n */\nexport type GraphDef<\n TNodes extends Record<string, NodeRegistration> = Record<\n string,\n NodeRegistration\n >,\n TEdges extends Record<string, EdgeRegistration> = Record<\n string,\n EdgeRegistration\n >,\n TOntology extends readonly OntologyRelation[] = readonly OntologyRelation[],\n> = Readonly<{\n [GRAPH_DEF_BRAND]: true;\n id: string;\n nodes: TNodes;\n edges: TEdges;\n ontology: TOntology;\n defaults: Readonly<{\n onNodeDelete: DeleteBehavior;\n temporalMode: TemporalMode;\n }>;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Extract node kind names from a GraphDef.\n */\nexport type NodeKinds<G extends GraphDef> = keyof G[\"nodes\"] & string;\n\n/**\n * Extract edge kind names from a GraphDef.\n */\nexport type EdgeKinds<G extends GraphDef> = keyof G[\"edges\"] & string;\n\n/**\n * Get a NodeType from a GraphDef by kind name.\n */\nexport type GetNodeType<\n G extends GraphDef,\n K extends NodeKinds<G>,\n> = G[\"nodes\"][K][\"type\"];\n\n/**\n * Get an EdgeType from a GraphDef by kind name.\n */\nexport type GetEdgeType<\n G extends GraphDef,\n K extends EdgeKinds<G>,\n> = G[\"edges\"][K][\"type\"];\n\n/**\n * Get all NodeTypes from a GraphDef.\n */\nexport type AllNodeTypes<G extends GraphDef> = {\n [K in NodeKinds<G>]: G[\"nodes\"][K][\"type\"];\n}[NodeKinds<G>];\n\n/**\n * Get all EdgeTypes from a GraphDef.\n */\nexport type AllEdgeTypes<G extends GraphDef> = {\n [K in EdgeKinds<G>]: G[\"edges\"][K][\"type\"];\n}[EdgeKinds<G>];\n\n// ============================================================\n// Define Graph Function\n// ============================================================\n\n/**\n * Creates a graph definition.\n *\n * @example\n * ```typescript\n * const graph = defineGraph({\n * id: \"my_graph\",\n * nodes: {\n * Person: { type: Person },\n * Company: { type: Company },\n * },\n * edges: {\n * // Traditional EdgeRegistration syntax\n * worksAt: {\n * type: worksAt,\n * from: [Person],\n * to: [Company],\n * cardinality: \"many\",\n * },\n * // Or use EdgeType directly if it has from/to defined\n * knows, // EdgeType with built-in domain/range\n * },\n * ontology: [\n * subClassOf(Company, Organization),\n * disjointWith(Person, Organization),\n * ],\n * defaults: {\n * onNodeDelete: \"restrict\",\n * temporalMode: \"current\",\n * },\n * });\n * ```\n */\nexport function defineGraph<\n const TNodes extends Record<string, NodeRegistration<NodeType>>,\n const TEdges extends Record<string, EdgeEntry>,\n const TOntology extends readonly OntologyRelation[],\n>(\n config: GraphDefConfig<TNodes, TEdges, TOntology>,\n): GraphDef<TNodes, NormalizedEdges<TNodes, TEdges>, TOntology> {\n const defaults = {\n onNodeDelete: config.defaults?.onNodeDelete ?? \"restrict\",\n temporalMode: config.defaults?.temporalMode ?? \"current\",\n } as const;\n\n const allNodeTypes = Object.values(config.nodes).map((reg) => reg.type);\n const normalizedEdges = normalizeEdges(config.edges, allNodeTypes);\n\n return Object.freeze({\n [GRAPH_DEF_BRAND]: true as const,\n id: config.id,\n nodes: config.nodes,\n edges: normalizedEdges,\n ontology: config.ontology ?? ([] as unknown as TOntology),\n defaults,\n }) as GraphDef<TNodes, NormalizedEdges<TNodes, TEdges>, TOntology>;\n}\n\n// ============================================================\n// Graph Definition Utilities\n// ============================================================\n\n/**\n * Checks if a value is a GraphDef.\n */\nexport function isGraphDef(value: unknown): value is GraphDef {\n return (\n typeof value === \"object\" &&\n value !== null &&\n GRAPH_DEF_BRAND in value &&\n (value as Record<string, unknown>)[GRAPH_DEF_BRAND] === true\n );\n}\n\n/**\n * Gets all node kind names from a GraphDef.\n */\nexport function getNodeKinds<G extends GraphDef>(\n graph: G,\n): readonly (keyof G[\"nodes\"] & string)[] {\n return Object.keys(graph.nodes) as (keyof G[\"nodes\"] & string)[];\n}\n\n/**\n * Gets all edge kind names from a GraphDef.\n */\nexport function getEdgeKinds<G extends GraphDef>(\n graph: G,\n): readonly (keyof G[\"edges\"] & string)[] {\n return Object.keys(graph.edges) as (keyof G[\"edges\"] & string)[];\n}\n","/**\n * Date encoding utilities for consistent storage.\n *\n * Contract: All dates are stored as ISO 8601 strings in UTC.\n * - Always includes milliseconds\n * - Always UTC (Z suffix)\n * - Sorts correctly as strings\n */\n\nimport { ValidationError } from \"../errors\";\n\n/**\n * ISO 8601 datetime pattern.\n * Matches formats like:\n * - 2024-01-15T10:30:00.000Z\n * - 2024-01-15T10:30:00Z\n * - 2024-01-15T10:30:00.123Z\n */\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?Z$/;\n\n/**\n * Checks if a string is a valid ISO 8601 datetime.\n *\n * @param value - String to validate\n * @returns True if valid ISO 8601 datetime\n */\nexport function isValidIsoDate(value: string): boolean {\n if (!ISO_DATE_PATTERN.test(value)) {\n return false;\n }\n // Also check that Date parsing produces a valid date\n const date = new Date(value);\n return !Number.isNaN(date.getTime());\n}\n\n/**\n * Validates that a string is a valid ISO 8601 datetime.\n * Throws ValidationError if invalid.\n *\n * @param value - String to validate\n * @param fieldName - Name of field for error message\n * @returns The validated string\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function validateIsoDate(value: string, fieldName: string): string {\n if (!isValidIsoDate(value)) {\n throw new ValidationError(\n `Invalid ISO 8601 datetime for \"${fieldName}\": \"${value}\". ` +\n `Expected format: YYYY-MM-DDTHH:mm:ss.sssZ`,\n {\n issues: [\n {\n path: fieldName,\n message: `Invalid ISO 8601 datetime format. Expected: YYYY-MM-DDTHH:mm:ss.sssZ, got: \"${value}\"`,\n },\n ],\n },\n {\n suggestion: `Use a valid ISO 8601 UTC datetime like \"2024-01-15T10:30:00.000Z\"`,\n },\n );\n }\n return value;\n}\n\n/**\n * Validates an optional ISO date string.\n * Returns undefined if value is undefined, otherwise validates.\n */\nexport function validateOptionalIsoDate(\n value: string | undefined,\n fieldName: string,\n): string | undefined {\n if (value === undefined) return undefined;\n return validateIsoDate(value, fieldName);\n}\n\n/**\n * Encodes a Date to an ISO 8601 string for storage.\n */\nexport function encodeDate(date: Date): string {\n return date.toISOString();\n}\n\n/**\n * Decodes an ISO 8601 string to a Date.\n * Validates the string format first.\n *\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function decodeDate(isoString: string): Date {\n validateIsoDate(isoString, \"date\");\n return new Date(isoString);\n}\n\n/**\n * Returns the current timestamp as an ISO string.\n */\nexport function nowIso(): string {\n return new Date().toISOString();\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/types.ts","../src/core/define-graph.ts","../src/utils/date.ts"],"names":["ConfigurationError","ValidationError"],"mappings":";;;;;AAOO,IAAM,eAAA,GAAkB;AAGxB,IAAM,eAAA,GAAkB;AA0PxB,SAAS,WAAW,KAAA,EAAmC;AAC5D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAKO,SAAS,WAAW,KAAA,EAAsC;AAC/D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAMO,SAAS,wBACd,KAAA,EACgC;AAChC,EAAA,OACE,WAAW,KAAK,CAAA,IAChB,MAAM,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,IACxB,KAAA,CAAM,KAAK,MAAA,GAAS,CAAA,IACpB,MAAM,OAAA,CAAQ,KAAA,CAAM,EAAE,CAAA,IACtB,KAAA,CAAM,GAAG,MAAA,GAAS,CAAA;AAEtB;;;ACnRA,IAAM,eAAA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C,cAAA,CAAe,KAAK,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAIC,iCAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,IAAA,EAAO,KAAK,CAAA,4CAAA,CAAA;AAAA,MAEvD;AAAA,QACE,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,IAAA,EAAM,SAAA;AAAA,YACN,OAAA,EAAS,+EAA+E,KAAK,CAAA,CAAA;AAAA;AAC/F;AACF,OACF;AAAA,MACA;AAAA,QACE,UAAA,EAAY,CAAA,iEAAA;AAAA;AACd,KACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAMO,SAAS,uBAAA,CACd,OACA,SAAA,EACoB;AACpB,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,MAAA;AAChC,EAAA,OAAO,eAAA,CAAgB,OAAO,SAAS,CAAA;AACzC;AAuBO,SAAS,MAAA,GAAiB;AAC/B,EAAA,OAAA,iBAAO,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAChC","file":"chunk-WRWVWKQL.cjs","sourcesContent":["import { type z } from \"zod\";\n\n// ============================================================\n// Brand Keys for Nominal Typing\n// ============================================================\n\n/** Brand key for NodeType */\nexport const NODE_TYPE_BRAND = \"__nodeType\" as const;\n\n/** Brand key for EdgeType */\nexport const EDGE_TYPE_BRAND = \"__edgeType\" as const;\n\n/** Brand symbol for NodeId */\ndeclare const __nodeId: unique symbol;\n\n/** Brand symbol for EdgeId */\ndeclare const __edgeId: unique symbol;\n\n// ============================================================\n// Node Type\n// ============================================================\n\n/**\n * A node type definition.\n *\n * Created via `defineNode()`. Represents a type of node in the graph\n * with an associated Zod schema for properties.\n */\nexport type NodeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [NODE_TYPE_BRAND]: true;\n kind: K;\n schema: S;\n description: string | undefined;\n}>;\n\n/**\n * Branded node ID type.\n *\n * Prevents mixing IDs from different node types at compile time.\n */\nexport type NodeId<N extends NodeType> = string &\n Readonly<{\n [__nodeId]: N;\n }>;\n\n/**\n * Infer the props type from a NodeType.\n */\nexport type NodeProps<N extends NodeType> = z.infer<N[\"schema\"]>;\n\n// ============================================================\n// Edge Type\n// ============================================================\n\n/**\n * An edge type definition.\n *\n * Created via `defineEdge()`. Represents a type of edge in the graph\n * with an optional Zod schema for properties.\n *\n * Optionally includes `from` and `to` arrays that define the allowed\n * source and target node types (domain and range constraints).\n */\nexport type EdgeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n From extends readonly NodeType[] | undefined = undefined,\n To extends readonly NodeType[] | undefined = undefined,\n> = Readonly<{\n [EDGE_TYPE_BRAND]: true;\n kind: K;\n schema: S;\n description: string | undefined;\n from: From;\n to: To;\n}>;\n\n/**\n * Base edge type for use in constraints - accepts any from/to configuration.\n */\nexport type AnyEdgeType = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[] | undefined,\n readonly NodeType[] | undefined\n>;\n\n/**\n * An edge type that has both from and to constraints defined.\n * Can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport type EdgeTypeWithEndpoints = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[],\n readonly NodeType[]\n>;\n\n/**\n * Branded edge ID type.\n *\n * Prevents mixing IDs from different edge types at compile time.\n */\nexport type EdgeId<E extends AnyEdgeType = AnyEdgeType> = string &\n Readonly<{\n [__edgeId]: E;\n }>;\n\n/**\n * Infer the props type from an EdgeType.\n */\nexport type EdgeProps<E extends AnyEdgeType> = z.infer<E[\"schema\"]>;\n\n// ============================================================\n// Configuration Types\n// ============================================================\n\n/**\n * Delete behaviors for nodes.\n */\nexport type DeleteBehavior = \"restrict\" | \"cascade\" | \"disconnect\";\n\n/**\n * Edge cardinality constraints.\n */\nexport type Cardinality =\n | \"many\" // No constraint (default)\n | \"one\" // At most one edge of this kind from any source node\n | \"unique\" // At most one edge of this kind between any (source, target) pair\n | \"oneActive\"; // At most one edge with valid_to IS NULL from any source\n\n/**\n * Endpoint existence modes for edge validation.\n */\nexport type EndpointExistence =\n | \"notDeleted\" // Endpoint deleted_at IS NULL (default)\n | \"currentlyValid\" // Endpoint not deleted AND temporally valid\n | \"ever\"; // Endpoint exists in any state\n\n/**\n * Temporal query modes.\n */\nexport type TemporalMode =\n | \"current\" // Valid now AND not deleted\n | \"asOf\" // Valid at specific date AND not deleted\n | \"includeEnded\" // All validity periods AND not deleted\n | \"includeTombstones\"; // Everything including soft-deleted\n\n/**\n * Uniqueness constraint scope.\n */\nexport type UniquenessScope =\n | \"kind\" // Unique within this exact kind only\n | \"kindWithSubClasses\"; // Unique across this kind and all subclasses\n\n/**\n * Collation for uniqueness constraints.\n */\nexport type Collation = \"binary\" | \"caseInsensitive\";\n\n// ============================================================\n// Uniqueness Constraint\n// ============================================================\n\n/**\n * Uniqueness constraint definition.\n */\nexport type UniqueConstraint<\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n name: string;\n fields: readonly (keyof z.infer<S> & string)[];\n where?: (\n props: UniqueConstraintPredicateBuilder<S>,\n ) => UniqueConstraintPredicate;\n scope: UniquenessScope;\n collation: Collation;\n}>;\n\n/**\n * Predicate builder for uniqueness constraint where clause.\n * Uses -? to make all fields required in the builder, even if optional in the schema.\n */\nexport type UniqueConstraintPredicateBuilder<\n S extends z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [K in keyof z.infer<S>]-?: UniqueConstraintField;\n}>;\n\n/**\n * Field operations for uniqueness constraint predicates.\n */\ntype UniqueConstraintField = Readonly<{\n isNull: () => UniqueConstraintPredicate;\n isNotNull: () => UniqueConstraintPredicate;\n}>;\n\n/**\n * A uniqueness constraint predicate (internal representation).\n */\nexport type UniqueConstraintPredicate = Readonly<{\n __type: \"unique_predicate\";\n field: string;\n op: \"isNull\" | \"isNotNull\";\n}>;\n\n// ============================================================\n// Node Registration\n// ============================================================\n\n/**\n * Node registration in a graph definition.\n */\nexport type NodeRegistration<N extends NodeType = NodeType> = Readonly<{\n type: N;\n unique?: readonly UniqueConstraint<N[\"schema\"]>[];\n onDelete?: DeleteBehavior;\n}>;\n\n// ============================================================\n// Edge Registration\n// ============================================================\n\n/**\n * Edge registration in a graph definition.\n */\nexport type EdgeRegistration<\n E extends AnyEdgeType = AnyEdgeType,\n FromTypes extends NodeType = NodeType,\n ToTypes extends NodeType = NodeType,\n> = Readonly<{\n type: E;\n from: readonly FromTypes[];\n to: readonly ToTypes[];\n cardinality?: Cardinality;\n endpointExistence?: EndpointExistence;\n}>;\n\n// ============================================================\n// Graph Defaults\n// ============================================================\n\n/**\n * Default settings for a graph.\n */\nexport type GraphDefaults = Readonly<{\n onNodeDelete?: DeleteBehavior;\n temporalMode?: TemporalMode;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Checks if a value is a NodeType.\n */\nexport function isNodeType(value: unknown): value is NodeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n NODE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[NODE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType.\n */\nexport function isEdgeType(value: unknown): value is AnyEdgeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n EDGE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[EDGE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType with both from and to constraints defined.\n * Such edges can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport function isEdgeTypeWithEndpoints(\n value: unknown,\n): value is EdgeTypeWithEndpoints {\n return (\n isEdgeType(value) &&\n Array.isArray(value.from) &&\n value.from.length > 0 &&\n Array.isArray(value.to) &&\n value.to.length > 0\n );\n}\n","import { ConfigurationError } from \"../errors/index\";\nimport { type OntologyRelation } from \"../ontology/types\";\nimport {\n type AnyEdgeType,\n type DeleteBehavior,\n type EdgeRegistration,\n type EdgeTypeWithEndpoints,\n type GraphDefaults,\n isEdgeType,\n isEdgeTypeWithEndpoints,\n type NodeRegistration,\n type NodeType,\n type TemporalMode,\n} from \"./types\";\n\n// ============================================================\n// Graph Definition Brand Symbol\n// ============================================================\n\n/** Brand key for GraphDef */\nconst GRAPH_DEF_BRAND = \"__graphDef\" as const;\n\n// ============================================================\n// Edge Entry Types\n// ============================================================\n\n/**\n * An edge entry in the graph definition.\n * Can be:\n * - EdgeType directly (constrained or unconstrained)\n * - EdgeRegistration object (always works, can override/narrow defaults)\n */\ntype EdgeEntry = EdgeRegistration | AnyEdgeType;\n\n/**\n * Normalized edge map type - all entries become EdgeRegistration.\n * For bare EdgeTypes, constrained endpoints are extracted from the type;\n * unconstrained edges fall back to all node types in the graph.\n */\ntype NormalizedEdges<\n TNodes extends Record<string, NodeRegistration>,\n TEdges extends Record<string, EdgeEntry>,\n> = {\n [K in keyof TEdges]: TEdges[K] extends EdgeRegistration ? TEdges[K]\n : TEdges[K] extends AnyEdgeType ?\n EdgeRegistration<\n TEdges[K],\n TEdges[K][\"from\"] extends readonly (infer N extends NodeType)[] ? N\n : TNodes[keyof TNodes][\"type\"],\n TEdges[K][\"to\"] extends readonly (infer N extends NodeType)[] ? N\n : TNodes[keyof TNodes][\"type\"]\n >\n : never;\n};\n\n// ============================================================\n// Edge Normalization Functions\n// ============================================================\n\n/**\n * Validates that an EdgeRegistration's constraints don't widen beyond\n * the edge type's built-in domain/range constraints.\n */\nfunction validateConstraintNarrowing(\n name: string,\n edgeType: EdgeTypeWithEndpoints,\n registration: EdgeRegistration,\n): void {\n const builtInFromNames = new Set(edgeType.from.map((n) => n.kind));\n for (const fromNode of registration.from) {\n if (!builtInFromNames.has(fromNode.kind)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'from' kind \"${fromNode.kind}\" ` +\n `not in edge's built-in domain: [${[...builtInFromNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidFrom: fromNode.kind,\n allowedFrom: [...builtInFromNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n\n const builtInToNames = new Set(edgeType.to.map((n) => n.kind));\n for (const toNode of registration.to) {\n if (!builtInToNames.has(toNode.kind)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'to' kind \"${toNode.kind}\" ` +\n `not in edge's built-in range: [${[...builtInToNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidTo: toNode.kind,\n allowedTo: [...builtInToNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n}\n\n/**\n * Normalizes a single edge entry to EdgeRegistration.\n */\nfunction normalizeEdgeEntry(\n name: string,\n entry: EdgeEntry,\n allNodeTypes: readonly NodeType[],\n): EdgeRegistration {\n if (isEdgeType(entry)) {\n if (isEdgeTypeWithEndpoints(entry)) {\n // EdgeType with from/to — convert to EdgeRegistration\n return { type: entry, from: entry.from, to: entry.to };\n }\n // Unconstrained EdgeType — allow any→any\n return { type: entry, from: allNodeTypes, to: allNodeTypes };\n }\n\n // Already EdgeRegistration — validate narrowing if edge has built-in constraints\n if (isEdgeTypeWithEndpoints(entry.type)) {\n validateConstraintNarrowing(name, entry.type, entry);\n }\n\n return entry;\n}\n\n/**\n * Normalizes all edge entries to EdgeRegistration.\n */\nfunction normalizeEdges(\n edges: Record<string, EdgeEntry>,\n allNodeTypes: readonly NodeType[],\n): Record<string, EdgeRegistration> {\n const result: Record<string, EdgeRegistration> = {};\n for (const [name, entry] of Object.entries(edges)) {\n result[name] = normalizeEdgeEntry(name, entry, allNodeTypes);\n }\n return result;\n}\n\n// ============================================================\n// Graph Definition Configuration\n// ============================================================\n\n/**\n * Configuration for defineGraph.\n */\ntype GraphDefConfig<\n TNodes extends Record<string, NodeRegistration>,\n TEdges extends Record<string, EdgeEntry>,\n TOntology extends readonly OntologyRelation[],\n> = Readonly<{\n /** Unique identifier for this graph */\n id: string;\n /** Node registrations */\n nodes: TNodes;\n /** Edge registrations or EdgeTypes with built-in domain/range */\n edges: TEdges;\n /** Ontology relations */\n ontology?: TOntology;\n /** Graph-wide defaults */\n defaults?: GraphDefaults;\n}>;\n\n// ============================================================\n// Graph Definition Type\n// ============================================================\n\n/**\n * A graph definition.\n *\n * This is a compile-time artifact that describes the structure of a graph.\n * Use `createStore()` to create a runtime store from this definition.\n */\nexport type GraphDef<\n TNodes extends Record<string, NodeRegistration> = Record<\n string,\n NodeRegistration\n >,\n TEdges extends Record<string, EdgeRegistration> = Record<\n string,\n EdgeRegistration\n >,\n TOntology extends readonly OntologyRelation[] = readonly OntologyRelation[],\n> = Readonly<{\n [GRAPH_DEF_BRAND]: true;\n id: string;\n nodes: TNodes;\n edges: TEdges;\n ontology: TOntology;\n defaults: Readonly<{\n onNodeDelete: DeleteBehavior;\n temporalMode: TemporalMode;\n }>;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Extract node kind names from a GraphDef.\n */\nexport type NodeKinds<G extends GraphDef> = keyof G[\"nodes\"] & string;\n\n/**\n * Extract edge kind names from a GraphDef.\n */\nexport type EdgeKinds<G extends GraphDef> = keyof G[\"edges\"] & string;\n\n/**\n * Get a NodeType from a GraphDef by kind name.\n */\nexport type GetNodeType<\n G extends GraphDef,\n K extends NodeKinds<G>,\n> = G[\"nodes\"][K][\"type\"];\n\n/**\n * Get an EdgeType from a GraphDef by kind name.\n */\nexport type GetEdgeType<\n G extends GraphDef,\n K extends EdgeKinds<G>,\n> = G[\"edges\"][K][\"type\"];\n\n/**\n * Get all NodeTypes from a GraphDef.\n */\nexport type AllNodeTypes<G extends GraphDef> = {\n [K in NodeKinds<G>]: G[\"nodes\"][K][\"type\"];\n}[NodeKinds<G>];\n\n/**\n * Get all EdgeTypes from a GraphDef.\n */\nexport type AllEdgeTypes<G extends GraphDef> = {\n [K in EdgeKinds<G>]: G[\"edges\"][K][\"type\"];\n}[EdgeKinds<G>];\n\n// ============================================================\n// Define Graph Function\n// ============================================================\n\n/**\n * Creates a graph definition.\n *\n * @example\n * ```typescript\n * const graph = defineGraph({\n * id: \"my_graph\",\n * nodes: {\n * Person: { type: Person },\n * Company: { type: Company },\n * },\n * edges: {\n * // Traditional EdgeRegistration syntax\n * worksAt: {\n * type: worksAt,\n * from: [Person],\n * to: [Company],\n * cardinality: \"many\",\n * },\n * // Or use EdgeType directly if it has from/to defined\n * knows, // EdgeType with built-in domain/range\n * },\n * ontology: [\n * subClassOf(Company, Organization),\n * disjointWith(Person, Organization),\n * ],\n * defaults: {\n * onNodeDelete: \"restrict\",\n * temporalMode: \"current\",\n * },\n * });\n * ```\n */\nexport function defineGraph<\n const TNodes extends Record<string, NodeRegistration<NodeType>>,\n const TEdges extends Record<string, EdgeEntry>,\n const TOntology extends readonly OntologyRelation[],\n>(\n config: GraphDefConfig<TNodes, TEdges, TOntology>,\n): GraphDef<TNodes, NormalizedEdges<TNodes, TEdges>, TOntology> {\n const defaults = {\n onNodeDelete: config.defaults?.onNodeDelete ?? \"restrict\",\n temporalMode: config.defaults?.temporalMode ?? \"current\",\n } as const;\n\n const allNodeTypes = Object.values(config.nodes).map((reg) => reg.type);\n const normalizedEdges = normalizeEdges(config.edges, allNodeTypes);\n\n return Object.freeze({\n [GRAPH_DEF_BRAND]: true as const,\n id: config.id,\n nodes: config.nodes,\n edges: normalizedEdges,\n ontology: config.ontology ?? ([] as unknown as TOntology),\n defaults,\n }) as GraphDef<TNodes, NormalizedEdges<TNodes, TEdges>, TOntology>;\n}\n\n// ============================================================\n// Graph Definition Utilities\n// ============================================================\n\n/**\n * Checks if a value is a GraphDef.\n */\nexport function isGraphDef(value: unknown): value is GraphDef {\n return (\n typeof value === \"object\" &&\n value !== null &&\n GRAPH_DEF_BRAND in value &&\n (value as Record<string, unknown>)[GRAPH_DEF_BRAND] === true\n );\n}\n\n/**\n * Gets all node kind names from a GraphDef.\n */\nexport function getNodeKinds<G extends GraphDef>(\n graph: G,\n): readonly (keyof G[\"nodes\"] & string)[] {\n return Object.keys(graph.nodes);\n}\n\n/**\n * Gets all edge kind names from a GraphDef.\n */\nexport function getEdgeKinds<G extends GraphDef>(\n graph: G,\n): readonly (keyof G[\"edges\"] & string)[] {\n return Object.keys(graph.edges);\n}\n","/**\n * Date encoding utilities for consistent storage.\n *\n * Contract: All dates are stored as ISO 8601 strings in UTC.\n * - Always includes milliseconds\n * - Always UTC (Z suffix)\n * - Sorts correctly as strings\n */\n\nimport { ValidationError } from \"../errors\";\n\n/**\n * ISO 8601 datetime pattern.\n * Matches formats like:\n * - 2024-01-15T10:30:00.000Z\n * - 2024-01-15T10:30:00Z\n * - 2024-01-15T10:30:00.123Z\n */\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?Z$/;\n\n/**\n * Checks if a string is a valid ISO 8601 datetime.\n *\n * @param value - String to validate\n * @returns True if valid ISO 8601 datetime\n */\nexport function isValidIsoDate(value: string): boolean {\n if (!ISO_DATE_PATTERN.test(value)) {\n return false;\n }\n // Also check that Date parsing produces a valid date\n const date = new Date(value);\n return !Number.isNaN(date.getTime());\n}\n\n/**\n * Validates that a string is a valid ISO 8601 datetime.\n * Throws ValidationError if invalid.\n *\n * @param value - String to validate\n * @param fieldName - Name of field for error message\n * @returns The validated string\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function validateIsoDate(value: string, fieldName: string): string {\n if (!isValidIsoDate(value)) {\n throw new ValidationError(\n `Invalid ISO 8601 datetime for \"${fieldName}\": \"${value}\". ` +\n `Expected format: YYYY-MM-DDTHH:mm:ss.sssZ`,\n {\n issues: [\n {\n path: fieldName,\n message: `Invalid ISO 8601 datetime format. Expected: YYYY-MM-DDTHH:mm:ss.sssZ, got: \"${value}\"`,\n },\n ],\n },\n {\n suggestion: `Use a valid ISO 8601 UTC datetime like \"2024-01-15T10:30:00.000Z\"`,\n },\n );\n }\n return value;\n}\n\n/**\n * Validates an optional ISO date string.\n * Returns undefined if value is undefined, otherwise validates.\n */\nexport function validateOptionalIsoDate(\n value: string | undefined,\n fieldName: string,\n): string | undefined {\n if (value === undefined) return undefined;\n return validateIsoDate(value, fieldName);\n}\n\n/**\n * Encodes a Date to an ISO 8601 string for storage.\n */\nexport function encodeDate(date: Date): string {\n return date.toISOString();\n}\n\n/**\n * Decodes an ISO 8601 string to a Date.\n * Validates the string format first.\n *\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function decodeDate(isoString: string): Date {\n validateIsoDate(isoString, \"date\");\n return new Date(isoString);\n}\n\n/**\n * Returns the current timestamp as an ISO string.\n */\nexport function nowIso(): string {\n return new Date().toISOString();\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { m as FulltextStrategy } from './types-CQF88McG.js';
|
|
1
2
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
import { T as TypeGraphIndex } from './types-
|
|
3
|
-
import { S as SqliteTables } from './sqlite-
|
|
3
|
+
import { T as TypeGraphIndex } from './types-IMQCuser.js';
|
|
4
|
+
import { S as SqliteTables } from './sqlite-W3rmJMlc.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Table name configuration.
|
|
@@ -11,6 +12,7 @@ type PostgresTableNames = Readonly<{
|
|
|
11
12
|
uniques: string;
|
|
12
13
|
schemaVersions: string;
|
|
13
14
|
embeddings: string;
|
|
15
|
+
fulltext: string;
|
|
14
16
|
}>;
|
|
15
17
|
type CreatePostgresTablesOptions = Readonly<{
|
|
16
18
|
/**
|
|
@@ -811,6 +813,16 @@ declare function createPostgresTables(names?: Partial<PostgresTableNames>, optio
|
|
|
811
813
|
};
|
|
812
814
|
dialect: "pg";
|
|
813
815
|
}>;
|
|
816
|
+
/**
|
|
817
|
+
* The fulltext storage table is owned by the active `FulltextStrategy`,
|
|
818
|
+
* not Drizzle. Shapes vary across strategies — the default `tsvectorStrategy`
|
|
819
|
+
* uses a `regconfig` language column, a GENERATED STORED `tsv` column,
|
|
820
|
+
* and a GIN index; alternate strategies (ParadeDB, pg_trgm, pgroonga)
|
|
821
|
+
* pick their own column types and index methods. DDL is emitted as
|
|
822
|
+
* raw SQL via `strategy.generateDdl()`; reads and writes are composed
|
|
823
|
+
* from the strategy's fragment helpers.
|
|
824
|
+
*/
|
|
825
|
+
readonly fulltextTableName: string;
|
|
814
826
|
};
|
|
815
827
|
/**
|
|
816
828
|
* Default tables with standard TypeGraph table names.
|
|
@@ -1601,6 +1613,16 @@ declare const tables: {
|
|
|
1601
1613
|
};
|
|
1602
1614
|
dialect: "pg";
|
|
1603
1615
|
}>;
|
|
1616
|
+
/**
|
|
1617
|
+
* The fulltext storage table is owned by the active `FulltextStrategy`,
|
|
1618
|
+
* not Drizzle. Shapes vary across strategies — the default `tsvectorStrategy`
|
|
1619
|
+
* uses a `regconfig` language column, a GENERATED STORED `tsv` column,
|
|
1620
|
+
* and a GIN index; alternate strategies (ParadeDB, pg_trgm, pgroonga)
|
|
1621
|
+
* pick their own column types and index methods. DDL is emitted as
|
|
1622
|
+
* raw SQL via `strategy.generateDdl()`; reads and writes are composed
|
|
1623
|
+
* from the strategy's fragment helpers.
|
|
1624
|
+
*/
|
|
1625
|
+
readonly fulltextTableName: string;
|
|
1604
1626
|
};
|
|
1605
1627
|
/**
|
|
1606
1628
|
* Convenience exports for default tables.
|
|
@@ -2398,16 +2420,16 @@ type PostgresTables = ReturnType<typeof createPostgresTables>;
|
|
|
2398
2420
|
/**
|
|
2399
2421
|
* Generates all DDL statements for the given SQLite tables.
|
|
2400
2422
|
*/
|
|
2401
|
-
declare function generateSqliteDDL(tables?: SqliteTables): string[];
|
|
2423
|
+
declare function generateSqliteDDL(tables?: SqliteTables, fulltextStrategy?: FulltextStrategy): string[];
|
|
2402
2424
|
/**
|
|
2403
2425
|
* Generates a single SQL string for SQLite migrations.
|
|
2404
2426
|
* Convenience function that joins all DDL statements.
|
|
2405
2427
|
*/
|
|
2406
|
-
declare function generateSqliteMigrationSQL(tables?: SqliteTables): string;
|
|
2428
|
+
declare function generateSqliteMigrationSQL(tables?: SqliteTables, fulltextStrategy?: FulltextStrategy): string;
|
|
2407
2429
|
/**
|
|
2408
2430
|
* Generates all DDL statements for the given PostgreSQL tables.
|
|
2409
2431
|
*/
|
|
2410
|
-
declare function generatePostgresDDL(tables?: PostgresTables): string[];
|
|
2432
|
+
declare function generatePostgresDDL(tables?: PostgresTables, fulltextStrategy?: FulltextStrategy): string[];
|
|
2411
2433
|
/**
|
|
2412
2434
|
* Generates a single SQL string for PostgreSQL migrations.
|
|
2413
2435
|
* Convenience function that joins all DDL statements.
|
|
@@ -2415,6 +2437,6 @@ declare function generatePostgresDDL(tables?: PostgresTables): string[];
|
|
|
2415
2437
|
* Includes CREATE EXTENSION for pgvector since the embeddings table
|
|
2416
2438
|
* uses the native VECTOR type.
|
|
2417
2439
|
*/
|
|
2418
|
-
declare function generatePostgresMigrationSQL(tables?: PostgresTables): string;
|
|
2440
|
+
declare function generatePostgresMigrationSQL(tables?: PostgresTables, fulltextStrategy?: FulltextStrategy): string;
|
|
2419
2441
|
|
|
2420
2442
|
export { type CreatePostgresTablesOptions as C, type PostgresTables as P, generateSqliteMigrationSQL as a, type PostgresTableNames as b, createPostgresTables as c, embeddings as d, edges as e, generatePostgresDDL as f, generateSqliteDDL as g, generatePostgresMigrationSQL as h, nodes as n, schemaVersions as s, tables as t, uniques as u };
|