@nicia-ai/typegraph 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/postgres/index.cjs +29 -29
- package/dist/backend/postgres/index.d.cts +39 -7
- package/dist/backend/postgres/index.d.ts +39 -7
- package/dist/backend/postgres/index.js +16 -16
- package/dist/backend/postgres/pglite.cjs +21 -21
- package/dist/backend/postgres/pglite.d.cts +4 -4
- package/dist/backend/postgres/pglite.d.ts +4 -4
- package/dist/backend/postgres/pglite.js +16 -16
- package/dist/backend/sqlite/index.cjs +25 -26
- package/dist/backend/sqlite/index.d.cts +8 -8
- package/dist/backend/sqlite/index.d.ts +8 -8
- package/dist/backend/sqlite/index.js +13 -14
- package/dist/backend/sqlite/libsql.cjs +19 -19
- package/dist/backend/sqlite/libsql.d.cts +4 -4
- package/dist/backend/sqlite/libsql.d.ts +4 -4
- package/dist/backend/sqlite/libsql.js +15 -15
- package/dist/backend/sqlite/local.cjs +101 -21
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +95 -5
- package/dist/backend/sqlite/local.d.ts +95 -5
- package/dist/backend/sqlite/local.js +95 -16
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-ZV5N4DBG.js → chunk-3TWF3SH4.js} +300 -58
- package/dist/chunk-3TWF3SH4.js.map +1 -0
- package/dist/chunk-4JEZZJ6S.cjs +1271 -0
- package/dist/chunk-4JEZZJ6S.cjs.map +1 -0
- package/dist/{chunk-UNNPKQUG.cjs → chunk-4TOD4LBZ.cjs} +246 -155
- package/dist/chunk-4TOD4LBZ.cjs.map +1 -0
- package/dist/{chunk-QV245VMN.js → chunk-55MZDDZV.js} +100 -6
- package/dist/chunk-55MZDDZV.js.map +1 -0
- package/dist/{chunk-GQANNXXT.cjs → chunk-5A6FNS6N.cjs} +75 -20
- package/dist/chunk-5A6FNS6N.cjs.map +1 -0
- package/dist/{chunk-3Z6TW3CT.cjs → chunk-5AQIKK56.cjs} +65 -25
- package/dist/chunk-5AQIKK56.cjs.map +1 -0
- package/dist/{chunk-BVTWD66D.js → chunk-5SEGFTZX.js} +3 -3
- package/dist/{chunk-BVTWD66D.js.map → chunk-5SEGFTZX.js.map} +1 -1
- package/dist/{chunk-6GNSY7AV.js → chunk-6FR2MMS6.js} +7 -7
- package/dist/chunk-6FR2MMS6.js.map +1 -0
- package/dist/chunk-7YSP4V4R.cjs +69 -0
- package/dist/chunk-7YSP4V4R.cjs.map +1 -0
- package/dist/chunk-A42GCBGX.cjs +28 -0
- package/dist/chunk-A42GCBGX.cjs.map +1 -0
- package/dist/{chunk-RHZWOJVA.cjs → chunk-BLZDPRXT.cjs} +52 -4
- package/dist/chunk-BLZDPRXT.cjs.map +1 -0
- package/dist/chunk-BYPOGQWK.js +25 -0
- package/dist/chunk-BYPOGQWK.js.map +1 -0
- package/dist/{chunk-6HVOHZHS.cjs → chunk-CK5BVQOW.cjs} +213 -168
- package/dist/chunk-CK5BVQOW.cjs.map +1 -0
- package/dist/{chunk-JJRCLAUN.cjs → chunk-CTTSDJLY.cjs} +116 -10
- package/dist/chunk-CTTSDJLY.cjs.map +1 -0
- package/dist/chunk-CUHM5CWJ.cjs +12 -0
- package/dist/chunk-CUHM5CWJ.cjs.map +1 -0
- package/dist/{chunk-A7SZZFAG.js → chunk-CZQ3FO2Q.js} +409 -99
- package/dist/chunk-CZQ3FO2Q.js.map +1 -0
- package/dist/{chunk-2JXB3NYJ.cjs → chunk-D7ZEOS56.cjs} +25 -32
- package/dist/chunk-D7ZEOS56.cjs.map +1 -0
- package/dist/chunk-DFVLCOP6.js +10 -0
- package/dist/chunk-DFVLCOP6.js.map +1 -0
- package/dist/{chunk-UJLOZYKT.cjs → chunk-EM3CWPND.cjs} +441 -115
- package/dist/chunk-EM3CWPND.cjs.map +1 -0
- package/dist/chunk-EMF62TZG.cjs +1176 -0
- package/dist/chunk-EMF62TZG.cjs.map +1 -0
- package/dist/chunk-EOLERH7Y.cjs +40 -0
- package/dist/chunk-EOLERH7Y.cjs.map +1 -0
- package/dist/{chunk-TGJE22RM.cjs → chunk-FACJJWGF.cjs} +24 -6
- package/dist/chunk-FACJJWGF.cjs.map +1 -0
- package/dist/{chunk-HK5SATYM.cjs → chunk-FL472AMI.cjs} +16 -109
- package/dist/chunk-FL472AMI.cjs.map +1 -0
- package/dist/{chunk-WVC2Q2FD.cjs → chunk-FN35DLCN.cjs} +31 -9
- package/dist/chunk-FN35DLCN.cjs.map +1 -0
- package/dist/{chunk-KUTNI6SI.js → chunk-FPIZFYHE.js} +10 -18
- package/dist/chunk-FPIZFYHE.js.map +1 -0
- package/dist/{chunk-VCGO4V26.js → chunk-FRV5Q5IO.js} +64 -9
- package/dist/chunk-FRV5Q5IO.js.map +1 -0
- package/dist/{chunk-K5P5OZXS.js → chunk-G6Q5UM7U.js} +2 -2
- package/dist/{chunk-K5P5OZXS.js.map → chunk-G6Q5UM7U.js.map} +1 -1
- package/dist/chunk-GSQ6NPH6.cjs +100 -0
- package/dist/chunk-GSQ6NPH6.cjs.map +1 -0
- package/dist/chunk-GUR2FNB5.cjs +12 -0
- package/dist/{chunk-HMFK4BXR.cjs.map → chunk-GUR2FNB5.cjs.map} +1 -1
- package/dist/{chunk-JQGIPGVL.cjs → chunk-H7YNSMA7.cjs} +43 -2
- package/dist/chunk-H7YNSMA7.cjs.map +1 -0
- package/dist/{chunk-2MRAX3UE.js → chunk-I7ZUZKFD.js} +47 -4
- package/dist/chunk-I7ZUZKFD.js.map +1 -0
- package/dist/{chunk-3BRVBQQD.cjs → chunk-J7WFGBJR.cjs} +2445 -2367
- package/dist/chunk-J7WFGBJR.cjs.map +1 -0
- package/dist/{chunk-V3QNTB7Z.js → chunk-JBTOYDMN.js} +194 -114
- package/dist/chunk-JBTOYDMN.js.map +1 -0
- package/dist/{chunk-K2TGS3EN.js → chunk-K3PPLHY7.js} +138 -89
- package/dist/chunk-K3PPLHY7.js.map +1 -0
- package/dist/{chunk-Z5XBMDXU.js → chunk-KBGQIPRQ.js} +42 -3
- package/dist/chunk-KBGQIPRQ.js.map +1 -0
- package/dist/chunk-KMI7LYAF.js +1252 -0
- package/dist/chunk-KMI7LYAF.js.map +1 -0
- package/dist/{chunk-JIEJCTDS.cjs → chunk-LGEALRC6.cjs} +21 -4
- package/dist/chunk-LGEALRC6.cjs.map +1 -0
- package/dist/{chunk-TQOYM4LN.js → chunk-MP2JQKSG.js} +21 -5
- package/dist/chunk-MP2JQKSG.js.map +1 -0
- package/dist/{chunk-ZP5WHI4C.cjs → chunk-O7UN7OXA.cjs} +358 -116
- package/dist/chunk-O7UN7OXA.cjs.map +1 -0
- package/dist/chunk-OHMP6N2J.js +47 -0
- package/dist/chunk-OHMP6N2J.js.map +1 -0
- package/dist/{chunk-4DIBPQNJ.js → chunk-OR5ZA5WP.js} +135 -25
- package/dist/chunk-OR5ZA5WP.js.map +1 -0
- package/dist/{chunk-DEQFL35G.js → chunk-Q5TEXCTB.js} +61 -7
- package/dist/chunk-Q5TEXCTB.js.map +1 -0
- package/dist/chunk-QNKSQTKQ.js +1312 -0
- package/dist/chunk-QNKSQTKQ.js.map +1 -0
- package/dist/{chunk-ZURTTSCM.js → chunk-QOTI55H7.js} +6 -94
- package/dist/chunk-QOTI55H7.js.map +1 -0
- package/dist/{chunk-CHXTTSC6.js → chunk-QWEUYILR.js} +104 -5
- package/dist/chunk-QWEUYILR.js.map +1 -0
- package/dist/{chunk-LANHCOXB.js → chunk-RGP33ZJ5.js} +485 -83
- package/dist/chunk-RGP33ZJ5.js.map +1 -0
- package/dist/chunk-RGPG7EOJ.js +94 -0
- package/dist/chunk-RGPG7EOJ.js.map +1 -0
- package/dist/{chunk-G6SOJEDI.cjs → chunk-S55OV6PW.cjs} +15 -15
- package/dist/chunk-S55OV6PW.cjs.map +1 -0
- package/dist/{chunk-3E7SNSIA.cjs → chunk-SJDMVITW.cjs} +4 -4
- package/dist/{chunk-3E7SNSIA.cjs.map → chunk-SJDMVITW.cjs.map} +1 -1
- package/dist/{chunk-XLUNB2TZ.js → chunk-SNXVDZAJ.js} +3 -3
- package/dist/{chunk-XLUNB2TZ.js.map → chunk-SNXVDZAJ.js.map} +1 -1
- package/dist/{chunk-RBV7YCQD.js → chunk-T2WUSPDA.js} +49 -9
- package/dist/chunk-T2WUSPDA.js.map +1 -0
- package/dist/{chunk-KGC4LY5T.cjs → chunk-TCOCYN2P.cjs} +75 -21
- package/dist/chunk-TCOCYN2P.cjs.map +1 -0
- package/dist/{chunk-FLRCVI2G.cjs → chunk-TDXIBCGY.cjs} +2 -2
- package/dist/{chunk-FLRCVI2G.cjs.map → chunk-TDXIBCGY.cjs.map} +1 -1
- package/dist/{chunk-ZY4GXIVN.cjs → chunk-TEDRJXOG.cjs} +5 -5
- package/dist/{chunk-ZY4GXIVN.cjs.map → chunk-TEDRJXOG.cjs.map} +1 -1
- package/dist/{chunk-WLRIWYHQ.js → chunk-UES55P7G.js} +1863 -1785
- package/dist/chunk-UES55P7G.js.map +1 -0
- package/dist/{chunk-WL2SG7ZV.cjs → chunk-UMDVATGY.cjs} +6 -6
- package/dist/{chunk-WL2SG7ZV.cjs.map → chunk-UMDVATGY.cjs.map} +1 -1
- package/dist/chunk-UT3S4SEN.js +31 -0
- package/dist/chunk-UT3S4SEN.js.map +1 -0
- package/dist/{chunk-RRKQAKD6.cjs → chunk-UUT7UN2N.cjs} +149 -39
- package/dist/chunk-UUT7UN2N.cjs.map +1 -0
- package/dist/{chunk-SHLY4MCM.js → chunk-UZV3AZKF.js} +21 -3
- package/dist/chunk-UZV3AZKF.js.map +1 -0
- package/dist/{chunk-CYX2JTDG.js → chunk-VHMPG6UL.js} +29 -7
- package/dist/chunk-VHMPG6UL.js.map +1 -0
- package/dist/{chunk-T6SPUYLX.cjs → chunk-VPYHY3LJ.cjs} +116 -10
- package/dist/chunk-VPYHY3LJ.cjs.map +1 -0
- package/dist/{chunk-T46GR2VY.js → chunk-VSPCZAXF.js} +3 -3
- package/dist/{chunk-T46GR2VY.js.map → chunk-VSPCZAXF.js.map} +1 -1
- package/dist/{chunk-K34OPSJK.js → chunk-W63OVYY4.js} +3 -3
- package/dist/{chunk-K34OPSJK.js.map → chunk-W63OVYY4.js.map} +1 -1
- package/dist/{chunk-RY2VIWAM.js → chunk-WDBCBWC4.js} +355 -32
- package/dist/chunk-WDBCBWC4.js.map +1 -0
- package/dist/chunk-WJT7OU7E.cjs +1334 -0
- package/dist/chunk-WJT7OU7E.cjs.map +1 -0
- package/dist/{chunk-5IQIX7LU.cjs → chunk-XOX22WHL.cjs} +476 -163
- package/dist/chunk-XOX22WHL.cjs.map +1 -0
- package/dist/{ddl-BrmPg61z.d.ts → ddl-C2rZ-Aen.d.ts} +4 -4
- package/dist/{ddl-j1-sH6lE.d.cts → ddl-CZz7a0E8.d.cts} +4 -4
- package/dist/{extension-types-YGFJPrzK.d.cts → extension-types-ixRpJVUp.d.cts} +24 -1
- package/dist/{extension-types-YGFJPrzK.d.ts → extension-types-ixRpJVUp.d.ts} +24 -1
- package/dist/{types-DkNnF-7K.d.cts → fulltext-strategy-B57yvC5Q.d.ts} +2562 -2133
- package/dist/{types-D1Sqeyxy.d.ts → fulltext-strategy-CDkSSYhq.d.cts} +2562 -2133
- package/dist/graph-extension/index.cjs +20 -19
- package/dist/graph-extension/index.d.cts +4 -4
- package/dist/graph-extension/index.d.ts +4 -4
- package/dist/graph-extension/index.js +5 -4
- package/dist/graph-merge/index.cjs +255 -164
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +63 -33
- package/dist/graph-merge/index.d.ts +63 -33
- package/dist/graph-merge/index.js +135 -44
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/{index-DGX6D9j1.d.ts → index-6CSUAq-x.d.ts} +234 -93
- package/dist/{index-SEvUHDA6.d.cts → index-Bks_3HHK.d.cts} +234 -93
- package/dist/index.cjs +208 -188
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +33 -33
- package/dist/indexes/index.cjs +19 -20
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +10 -11
- package/dist/interchange/index.cjs +47 -26
- package/dist/interchange/index.d.cts +126 -12
- package/dist/interchange/index.d.ts +126 -12
- package/dist/interchange/index.js +14 -13
- package/dist/{manager-ms9cKdc6.d.cts → manager-DwQi8eV0.d.cts} +9 -2
- package/dist/{manager-BZUeN_BU.d.ts → manager-ejUCB52T.d.ts} +9 -2
- package/dist/{materialize-indexes-D20xNluI.d.cts → materialize-indexes-B4e9360H.d.cts} +20 -4
- package/dist/{materialize-indexes-CAkIYFV-.d.ts → materialize-indexes-te9TPMMJ.d.ts} +20 -4
- package/dist/{postgres-BhpxGMC5.d.cts → postgres-CfEqsRMp.d.cts} +152 -1
- package/dist/{postgres-CWHLwNl1.d.ts → postgres-DQ5R6rzV.d.ts} +152 -1
- package/dist/profiler/index.cjs +11 -11
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/profiler/index.js +4 -4
- package/dist/provenance/index.cjs +40 -41
- package/dist/provenance/index.cjs.map +1 -1
- package/dist/provenance/index.d.cts +5 -5
- package/dist/provenance/index.d.ts +5 -5
- package/dist/provenance/index.js +11 -12
- package/dist/provenance/index.js.map +1 -1
- package/dist/schema/index.cjs +53 -40
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +57 -57
- package/dist/schema/index.d.ts +57 -57
- package/dist/schema/index.js +28 -15
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-XrDxNaa7.d.cts → sqlite-D7zBinNR.d.cts} +92 -1
- package/dist/{sqlite-CGu5SLsw.d.ts → sqlite-DvQndLky.d.ts} +92 -1
- package/dist/{store-view-D09po4H6.d.cts → store-view-BSpqvAxK.d.cts} +415 -44
- package/dist/{store-view-BlgnhEYf.d.ts → store-view-CKbHFRnn.d.ts} +415 -44
- package/dist/{types-DiE1AO7p.d.cts → types-Bv9DcS_E.d.cts} +2 -2
- package/dist/{types-B1TbZJYS.d.ts → types-CoxuV7EJ.d.ts} +2 -2
- package/dist/{where-DKjuofPr.d.cts → where-7RKFOsXt.d.ts} +2 -2
- package/dist/{where-DrUIIWHb.d.ts → where-DdMIXOtH.d.cts} +2 -2
- package/package.json +14 -13
- package/dist/chunk-2EBMPJBO.js +0 -16
- package/dist/chunk-2EBMPJBO.js.map +0 -1
- package/dist/chunk-2JXB3NYJ.cjs.map +0 -1
- package/dist/chunk-2MRAX3UE.js.map +0 -1
- package/dist/chunk-3BRVBQQD.cjs.map +0 -1
- package/dist/chunk-3EUKJEQ3.js +0 -77
- package/dist/chunk-3EUKJEQ3.js.map +0 -1
- package/dist/chunk-3Z6TW3CT.cjs.map +0 -1
- package/dist/chunk-4DIBPQNJ.js.map +0 -1
- package/dist/chunk-4S2FXGBJ.js +0 -9
- package/dist/chunk-4S2FXGBJ.js.map +0 -1
- package/dist/chunk-5IQIX7LU.cjs.map +0 -1
- package/dist/chunk-6GNSY7AV.js.map +0 -1
- package/dist/chunk-6HVOHZHS.cjs.map +0 -1
- package/dist/chunk-6SCVW4AS.js +0 -20
- package/dist/chunk-6SCVW4AS.js.map +0 -1
- package/dist/chunk-A7SZZFAG.js.map +0 -1
- package/dist/chunk-CHXTTSC6.js.map +0 -1
- package/dist/chunk-CYX2JTDG.js.map +0 -1
- package/dist/chunk-DEQFL35G.js.map +0 -1
- package/dist/chunk-G6SOJEDI.cjs.map +0 -1
- package/dist/chunk-GQANNXXT.cjs.map +0 -1
- package/dist/chunk-GZCNZ7QW.js +0 -24
- package/dist/chunk-GZCNZ7QW.js.map +0 -1
- package/dist/chunk-HK5SATYM.cjs.map +0 -1
- package/dist/chunk-HMFK4BXR.cjs +0 -12
- package/dist/chunk-HTGDWIDE.cjs +0 -89
- package/dist/chunk-HTGDWIDE.cjs.map +0 -1
- package/dist/chunk-JIEJCTDS.cjs.map +0 -1
- package/dist/chunk-JJRCLAUN.cjs.map +0 -1
- package/dist/chunk-JQGIPGVL.cjs.map +0 -1
- package/dist/chunk-K2TGS3EN.js.map +0 -1
- package/dist/chunk-KGC4LY5T.cjs.map +0 -1
- package/dist/chunk-KNHYNQQ3.cjs +0 -663
- package/dist/chunk-KNHYNQQ3.cjs.map +0 -1
- package/dist/chunk-KUTNI6SI.js.map +0 -1
- package/dist/chunk-LANHCOXB.js.map +0 -1
- package/dist/chunk-N6WTUSBV.cjs +0 -23
- package/dist/chunk-N6WTUSBV.cjs.map +0 -1
- package/dist/chunk-NAUA4PW5.cjs +0 -28
- package/dist/chunk-NAUA4PW5.cjs.map +0 -1
- package/dist/chunk-QV245VMN.js.map +0 -1
- package/dist/chunk-RBV7YCQD.js.map +0 -1
- package/dist/chunk-RHZWOJVA.cjs.map +0 -1
- package/dist/chunk-RRKQAKD6.cjs.map +0 -1
- package/dist/chunk-RY2VIWAM.js.map +0 -1
- package/dist/chunk-SHLY4MCM.js.map +0 -1
- package/dist/chunk-T2DWPQNE.js +0 -649
- package/dist/chunk-T2DWPQNE.js.map +0 -1
- package/dist/chunk-T6SPUYLX.cjs.map +0 -1
- package/dist/chunk-TGJE22RM.cjs.map +0 -1
- package/dist/chunk-TOTPVGOG.cjs +0 -774
- package/dist/chunk-TOTPVGOG.cjs.map +0 -1
- package/dist/chunk-TQOYM4LN.js.map +0 -1
- package/dist/chunk-UJLOZYKT.cjs.map +0 -1
- package/dist/chunk-UNNPKQUG.cjs.map +0 -1
- package/dist/chunk-V3QNTB7Z.js.map +0 -1
- package/dist/chunk-VCGO4V26.js.map +0 -1
- package/dist/chunk-WLRIWYHQ.js.map +0 -1
- package/dist/chunk-WVC2Q2FD.cjs.map +0 -1
- package/dist/chunk-XXVEULWX.js +0 -39
- package/dist/chunk-XXVEULWX.js.map +0 -1
- package/dist/chunk-YAZE7QZR.cjs +0 -32
- package/dist/chunk-YAZE7QZR.cjs.map +0 -1
- package/dist/chunk-YC6PWTHY.cjs +0 -44
- package/dist/chunk-YC6PWTHY.cjs.map +0 -1
- package/dist/chunk-Z5HBYM7U.cjs +0 -11
- package/dist/chunk-Z5HBYM7U.cjs.map +0 -1
- package/dist/chunk-Z5XBMDXU.js.map +0 -1
- package/dist/chunk-ZP5WHI4C.cjs.map +0 -1
- package/dist/chunk-ZURTTSCM.js.map +0 -1
- package/dist/chunk-ZV5N4DBG.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLGEALRC6_cjs = require('./chunk-LGEALRC6.cjs');
|
|
4
|
+
|
|
5
|
+
// src/store/reserved-keys.ts
|
|
6
|
+
var RESERVED_NODE_KEYS = /* @__PURE__ */ new Set([
|
|
7
|
+
"id",
|
|
8
|
+
"kind",
|
|
9
|
+
"meta"
|
|
10
|
+
]);
|
|
11
|
+
var RESERVED_EDGE_KEYS = /* @__PURE__ */ new Set([
|
|
12
|
+
"id",
|
|
13
|
+
"kind",
|
|
14
|
+
"meta",
|
|
15
|
+
"fromKind",
|
|
16
|
+
"fromId",
|
|
17
|
+
"toKind",
|
|
18
|
+
"toId"
|
|
19
|
+
]);
|
|
20
|
+
var PROTOTYPE_POLLUTION_KEYS = /* @__PURE__ */ new Set([
|
|
21
|
+
"__proto__",
|
|
22
|
+
"constructor",
|
|
23
|
+
"prototype"
|
|
24
|
+
]);
|
|
25
|
+
var RESERVED_PROPERTY_PREFIX = "$";
|
|
26
|
+
function isReservedPropertyName(name) {
|
|
27
|
+
return name.startsWith(RESERVED_PROPERTY_PREFIX);
|
|
28
|
+
}
|
|
29
|
+
function assertSchemaKeysAreFree(entityKind, name, keys, reservedStructuralKeys) {
|
|
30
|
+
const structuralConflicts = keys.filter(
|
|
31
|
+
(key) => reservedStructuralKeys.has(key)
|
|
32
|
+
);
|
|
33
|
+
if (structuralConflicts.length > 0) {
|
|
34
|
+
const label = entityKind.toLowerCase();
|
|
35
|
+
throw new chunkLGEALRC6_cjs.ConfigurationError(
|
|
36
|
+
`${entityKind} "${name}" schema contains reserved property names: ${structuralConflicts.join(", ")}`,
|
|
37
|
+
{
|
|
38
|
+
[`${label}Type`]: name,
|
|
39
|
+
conflicts: structuralConflicts,
|
|
40
|
+
reservedKeys: [...reservedStructuralKeys]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
suggestion: `Rename the conflicting properties. Reserved names (${[...reservedStructuralKeys].join(", ")}) are added automatically to all ${label}s.`
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const prefixConflicts = keys.filter((key) => isReservedPropertyName(key));
|
|
48
|
+
if (prefixConflicts.length > 0) {
|
|
49
|
+
const label = entityKind.toLowerCase();
|
|
50
|
+
throw new chunkLGEALRC6_cjs.ConfigurationError(
|
|
51
|
+
`${entityKind} "${name}" schema uses the reserved "${RESERVED_PROPERTY_PREFIX}" prefix on: ${prefixConflicts.join(", ")}`,
|
|
52
|
+
{
|
|
53
|
+
[`${label}Type`]: name,
|
|
54
|
+
conflicts: prefixConflicts,
|
|
55
|
+
reservedPrefix: RESERVED_PROPERTY_PREFIX
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
suggestion: `Property names starting with "${RESERVED_PROPERTY_PREFIX}" are reserved for TypeGraph accessors (e.g. $fulltext). Rename each field.`
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function validateProjectionField(field, entityType, kind) {
|
|
64
|
+
const reserved = entityType === "node" ? RESERVED_NODE_KEYS : RESERVED_EDGE_KEYS;
|
|
65
|
+
if (reserved.has(field)) {
|
|
66
|
+
throw new chunkLGEALRC6_cjs.ConfigurationError(
|
|
67
|
+
`Projection field "${field}" on ${entityType} kind "${kind}" conflicts with a reserved structural key`,
|
|
68
|
+
{ field, kind, entityType, reservedKeys: [...reserved] },
|
|
69
|
+
{
|
|
70
|
+
suggestion: `Remove "${field}" from the projection. Structural fields (${[...reserved].join(", ")}) are included automatically when relevant.`
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (PROTOTYPE_POLLUTION_KEYS.has(field)) {
|
|
75
|
+
throw new chunkLGEALRC6_cjs.ConfigurationError(
|
|
76
|
+
`Projection field "${field}" on ${entityType} kind "${kind}" is not allowed`,
|
|
77
|
+
{ field, kind, entityType },
|
|
78
|
+
{
|
|
79
|
+
suggestion: `"${field}" cannot be used as a projection field name.`
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function filterReservedKeys(props, reservedKeys) {
|
|
85
|
+
const filtered = {};
|
|
86
|
+
for (const [key, value] of Object.entries(props)) {
|
|
87
|
+
if (!reservedKeys.has(key)) {
|
|
88
|
+
filtered[key] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return filtered;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.RESERVED_EDGE_KEYS = RESERVED_EDGE_KEYS;
|
|
95
|
+
exports.RESERVED_NODE_KEYS = RESERVED_NODE_KEYS;
|
|
96
|
+
exports.assertSchemaKeysAreFree = assertSchemaKeysAreFree;
|
|
97
|
+
exports.filterReservedKeys = filterReservedKeys;
|
|
98
|
+
exports.validateProjectionField = validateProjectionField;
|
|
99
|
+
//# sourceMappingURL=chunk-GSQ6NPH6.cjs.map
|
|
100
|
+
//# sourceMappingURL=chunk-GSQ6NPH6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store/reserved-keys.ts"],"names":["ConfigurationError"],"mappings":";;;;;AASO,IAAM,kBAAA,uBAA8C,GAAA,CAAI;AAAA,EAC7D,IAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,kBAAA,uBAA8C,GAAA,CAAI;AAAA,EAC7D,IAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAA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QACE,UAAA,EAAY,IAAI,KAAK,CAAA,4CAAA;AAAA;AACvB,KACF;AAAA,EACF;AACF;AAKO,SAAS,kBAAA,CACd,OACA,YAAA,EACyB;AACzB,EAAA,MAAM,WAAoC,EAAC;AAC3C,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,CAAC,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA,EAAG;AAC1B,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,KAAA;AAAA,IAClB;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT","file":"chunk-GSQ6NPH6.cjs","sourcesContent":["/**\n * Reserved Keys for Store Entities\n *\n * Structural keys that cannot be overwritten by user-defined properties.\n * Shared across row-mappers, subgraph projection, and schema validation.\n */\nimport type { KindEntity } from \"../core/types\";\nimport { ConfigurationError } from \"../errors\";\n\nexport const RESERVED_NODE_KEYS: ReadonlySet<string> = new Set([\n \"id\",\n \"kind\",\n \"meta\",\n]);\n\nexport const RESERVED_EDGE_KEYS: ReadonlySet<string> = new Set([\n \"id\",\n \"kind\",\n \"meta\",\n \"fromKind\",\n \"fromId\",\n \"toKind\",\n \"toId\",\n]);\n\nconst PROTOTYPE_POLLUTION_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n]);\n\n/**\n * Properties starting with `$` are reserved for TypeGraph-owned accessors\n * on the query-builder node/edge proxies (today: `$fulltext`). Reserving\n * the whole prefix — not just the currently-used names — keeps future\n * accessors (e.g. `$vector`, `$json`) from colliding with user fields.\n */\nconst RESERVED_PROPERTY_PREFIX = \"$\";\n\n/**\n * True if a user-defined field name is reserved by TypeGraph's accessor\n * namespace. `defineNode` / `defineEdge` call this against schema keys so\n * the collision fails fast at graph-definition time rather than silently\n * at query time.\n */\nfunction isReservedPropertyName(name: string): boolean {\n return name.startsWith(RESERVED_PROPERTY_PREFIX);\n}\n\n/**\n * Validates that a node or edge schema does not use any reserved property\n * name. Covers both the structural keys (`id`, `kind`, etc.) and the\n * `$`-prefix accessor namespace. Throws a single `ConfigurationError`\n * per conflict class so the user sees all collisions in one pass.\n */\nexport function assertSchemaKeysAreFree(\n entityKind: \"Node\" | \"Edge\",\n name: string,\n keys: readonly string[],\n reservedStructuralKeys: ReadonlySet<string>,\n): void {\n const structuralConflicts = keys.filter((key) =>\n reservedStructuralKeys.has(key),\n );\n if (structuralConflicts.length > 0) {\n const label = entityKind.toLowerCase();\n throw new ConfigurationError(\n `${entityKind} \"${name}\" schema contains reserved property names: ${structuralConflicts.join(\", \")}`,\n {\n [`${label}Type`]: name,\n conflicts: structuralConflicts,\n reservedKeys: [...reservedStructuralKeys],\n },\n {\n suggestion: `Rename the conflicting properties. Reserved names (${[...reservedStructuralKeys].join(\", \")}) are added automatically to all ${label}s.`,\n },\n );\n }\n\n const prefixConflicts = keys.filter((key) => isReservedPropertyName(key));\n if (prefixConflicts.length > 0) {\n const label = entityKind.toLowerCase();\n throw new ConfigurationError(\n `${entityKind} \"${name}\" schema uses the reserved \"${RESERVED_PROPERTY_PREFIX}\" prefix on: ${prefixConflicts.join(\", \")}`,\n {\n [`${label}Type`]: name,\n conflicts: prefixConflicts,\n reservedPrefix: RESERVED_PROPERTY_PREFIX,\n },\n {\n suggestion: `Property names starting with \"${RESERVED_PROPERTY_PREFIX}\" are reserved for TypeGraph accessors (e.g. $fulltext). Rename each field.`,\n },\n );\n }\n}\n\n/**\n * Validates that a projection field name is safe to assign onto a result object.\n * Rejects reserved structural keys and prototype-pollution vectors.\n *\n * @throws ConfigurationError if the field is reserved or dangerous\n */\nexport function validateProjectionField(\n field: string,\n entityType: KindEntity,\n kind: string,\n): void {\n const reserved =\n entityType === \"node\" ? RESERVED_NODE_KEYS : RESERVED_EDGE_KEYS;\n\n if (reserved.has(field)) {\n throw new ConfigurationError(\n `Projection field \"${field}\" on ${entityType} kind \"${kind}\" conflicts with a reserved structural key`,\n { field, kind, entityType, reservedKeys: [...reserved] },\n {\n suggestion: `Remove \"${field}\" from the projection. Structural fields (${[...reserved].join(\", \")}) are included automatically when relevant.`,\n },\n );\n }\n\n if (PROTOTYPE_POLLUTION_KEYS.has(field)) {\n throw new ConfigurationError(\n `Projection field \"${field}\" on ${entityType} kind \"${kind}\" is not allowed`,\n { field, kind, entityType },\n {\n suggestion: `\"${field}\" cannot be used as a projection field name.`,\n },\n );\n }\n}\n\n/**\n * Filters out reserved keys from a props object to prevent runtime collisions.\n */\nexport function filterReservedKeys(\n props: Record<string, unknown>,\n reservedKeys: ReadonlySet<string>,\n): Record<string, unknown> {\n const filtered: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n if (!reservedKeys.has(key)) {\n filtered[key] = value;\n }\n }\n return filtered;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFL472AMI_cjs = require('./chunk-FL472AMI.cjs');
|
|
4
|
+
|
|
5
|
+
// src/graph-extension/define-graph-extension.ts
|
|
6
|
+
function defineGraphExtension(input) {
|
|
7
|
+
return chunkFL472AMI_cjs.unwrap(chunkFL472AMI_cjs.validateGraphExtension(input, { strict: true }));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.defineGraphExtension = defineGraphExtension;
|
|
11
|
+
//# sourceMappingURL=chunk-GUR2FNB5.cjs.map
|
|
12
|
+
//# sourceMappingURL=chunk-GUR2FNB5.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph-extension/define-graph-extension.ts"],"names":["unwrap","validateGraphExtension"],"mappings":";;;;;AAyDO,SAAS,qBAAqB,KAAA,EAAuC;AAC1E,EAAA,OAAOA,yBAAOC,wCAAA,CAAuB,KAAA,EAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAC,CAAA;AAC/D","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../src/graph-extension/define-graph-extension.ts"],"names":["unwrap","validateGraphExtension"],"mappings":";;;;;AAyDO,SAAS,qBAAqB,KAAA,EAAuC;AAC1E,EAAA,OAAOA,yBAAOC,wCAAA,CAAuB,KAAA,EAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAC,CAAA;AAC/D","file":"chunk-GUR2FNB5.cjs","sourcesContent":["/**\n * Public entry for declaring a graph extension.\n *\n * Pure value: validates the input, deeply freezes the result, and returns\n * a `GraphExtension`. Invalid documents throw\n * `GraphExtensionValidationError` carrying every issue with a\n * JSON-pointer `path` to the offending field.\n */\nimport { unwrap } from \"../utils/result\";\nimport { type GraphExtension } from \"./extension-types\";\nimport { validateGraphExtension } from \"./validation\";\n\n/**\n * Validates and freezes a graph-extension document.\n *\n * Authoring entry point — runs validation in **strict** mode: unknown\n * top-level keys (e.g. `node` instead of `nodes`) and unsupported\n * string formats (e.g. `\"date-time\"` with a hyphen instead of\n * `\"datetime\"`) fail loudly with `UNKNOWN_DOCUMENT_KEY` /\n * `UNSUPPORTED_STRING_FORMAT`. The persistence-load path leaves both\n * checks off so a document committed by a future v1.x writer with\n * additive fields still parses on an older v1 reader. Callers\n * accepting raw JSON from an untyped source (e.g. an LLM proposal)\n * should validate first via `validateGraphExtension` and surface\n * the structured issues, then pass the validated document here.\n *\n * @param input - Document describing additional node kinds, edge\n * kinds, and ontology relations. Must satisfy the v1 property-type\n * subset documented in `ExtensionPropertyType`.\n *\n * @returns The same document, deeply frozen and shape-checked.\n *\n * @throws {GraphExtensionValidationError} when the document violates\n * the v1 property-type subset, references undeclared kinds, contains\n * ontology cycles, etc. The thrown error's `details.issues` array\n * carries every failure with a JSON-pointer path.\n * @throws {GraphExtensionVersionUnsupportedError} when the document\n * declares a future major version this library cannot safely decode.\n *\n * @example\n * ```typescript\n * const extension = defineGraphExtension({\n * nodes: {\n * Paper: {\n * properties: {\n * doi: { type: \"string\" },\n * title: { type: \"string\", searchable: { language: \"english\" } },\n * },\n * unique: [{ name: \"paper_doi\", fields: [\"doi\"] }],\n * },\n * },\n * });\n *\n * const evolved = await store.evolve(extension);\n * const papers = evolved.getNodeCollectionOrThrow(\"Paper\");\n * ```\n */\nexport function defineGraphExtension(input: GraphExtension): GraphExtension {\n return unwrap(validateGraphExtension(input, { strict: true }));\n}\n"]}
|
|
@@ -176,6 +176,45 @@ function getSearchableMetadata(schema) {
|
|
|
176
176
|
}
|
|
177
177
|
return void 0;
|
|
178
178
|
}
|
|
179
|
+
var searchableFieldsCache = /* @__PURE__ */ new WeakMap();
|
|
180
|
+
function getSearchableFields(schema) {
|
|
181
|
+
const cached = searchableFieldsCache.get(schema);
|
|
182
|
+
if (cached) return cached;
|
|
183
|
+
const fields = computeSearchableFields(schema);
|
|
184
|
+
searchableFieldsCache.set(schema, fields);
|
|
185
|
+
return fields;
|
|
186
|
+
}
|
|
187
|
+
function computeSearchableFields(schema) {
|
|
188
|
+
if (schema.type !== "object") return [];
|
|
189
|
+
const def = schema.def;
|
|
190
|
+
const shape = def.shape;
|
|
191
|
+
if (!shape) return [];
|
|
192
|
+
const fields = [];
|
|
193
|
+
for (const [fieldPath, fieldSchema] of Object.entries(shape)) {
|
|
194
|
+
const metadata = getSearchableMetadata(fieldSchema);
|
|
195
|
+
if (metadata !== void 0) {
|
|
196
|
+
fields.push({ fieldPath, metadata });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
warnIfConflictingLanguages(fields);
|
|
200
|
+
return fields;
|
|
201
|
+
}
|
|
202
|
+
function warnIfConflictingLanguages(fields) {
|
|
203
|
+
if (fields.length < 2) return;
|
|
204
|
+
const languages = new Set(fields.map((field) => field.metadata.language));
|
|
205
|
+
if (languages.size < 2) return;
|
|
206
|
+
if (typeof console === "undefined" || typeof console.warn !== "function") {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const fieldSummary = fields.map((field) => `${field.fieldPath}=${field.metadata.language}`).join(", ");
|
|
210
|
+
const winning = fields[0]?.metadata.language ?? DEFAULT_SEARCHABLE_LANGUAGE;
|
|
211
|
+
console.warn(
|
|
212
|
+
`[typegraph] searchable() fields declare conflicting languages (${fieldSummary}). The first field's language ("${winning}") is used for the combined fulltext row.`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function resolveDeclaredFulltextLanguage(schema) {
|
|
216
|
+
return getSearchableFields(schema)[0]?.metadata.language;
|
|
217
|
+
}
|
|
179
218
|
|
|
180
219
|
exports.DEFAULT_EMBEDDING_INDEX_TYPE = DEFAULT_EMBEDDING_INDEX_TYPE;
|
|
181
220
|
exports.DEFAULT_EMBEDDING_METRIC = DEFAULT_EMBEDDING_METRIC;
|
|
@@ -183,10 +222,12 @@ exports.DEFAULT_SEARCHABLE_LANGUAGE = DEFAULT_SEARCHABLE_LANGUAGE;
|
|
|
183
222
|
exports.embedding = embedding;
|
|
184
223
|
exports.getEmbeddingDimensions = getEmbeddingDimensions;
|
|
185
224
|
exports.getEmbeddingIndex = getEmbeddingIndex;
|
|
225
|
+
exports.getSearchableFields = getSearchableFields;
|
|
186
226
|
exports.getSearchableMetadata = getSearchableMetadata;
|
|
187
227
|
exports.isEmbeddingSchema = isEmbeddingSchema;
|
|
188
228
|
exports.isSearchableSchema = isSearchableSchema;
|
|
229
|
+
exports.resolveDeclaredFulltextLanguage = resolveDeclaredFulltextLanguage;
|
|
189
230
|
exports.resolveEmbeddingFields = resolveEmbeddingFields;
|
|
190
231
|
exports.searchable = searchable;
|
|
191
|
-
//# sourceMappingURL=chunk-
|
|
192
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-H7YNSMA7.cjs.map
|
|
233
|
+
//# sourceMappingURL=chunk-H7YNSMA7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/embedding.ts","../src/core/searchable.ts"],"names":["z"],"mappings":";;;;;AAqCO,IAAM,wBAAA,GAA2B,sBAAA;AAOjC,IAAM,mBAAA,GAAsB,iBAAA;AA4DnC,IAAM,cAAA,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A,CAAI,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,KAAU,KAAA,CAAM,QAAA,CAAS,QAAQ,CAAC,CAAA;AACxE,EAAA,IAAI,SAAA,CAAU,OAAO,CAAA,EAAG;AACxB,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,OAAO,OAAA,CAAQ,SAAS,UAAA,EAAY;AACxE,IAAA;AAAA,EACF;AACA,EAAA,MAAM,YAAA,GAAe,MAAA,CAClB,GAAA,CAAI,CAAC,UAAU,CAAA,EAAG,KAAA,CAAM,SAAS,CAAA,CAAA,EAAI,MAAM,QAAA,CAAS,QAAQ,CAAA,CAAE,CAAA,CAC9D,KAAK,IAAI,CAAA;AACZ,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,CAAC,CAAA,EAAG,SAAS,QAAA,IAAY,2BAAA;AAChD,EAAA,OAAA,CAAQ,IAAA;AAAA,IACN,CAAA,+DAAA,EACM,YAAY,CAAA,gCAAA,EAAmC,OAAO,CAAA,yCAAA;AAAA,GAE9D;AACF;AAaO,SAAS,gCACd,MAAA,EACoB;AACpB,EAAA,OAAO,mBAAA,CAAoB,MAAM,CAAA,CAAE,CAAC,GAAG,QAAA,CAAS,QAAA;AAClD","file":"chunk-H7YNSMA7.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 * Symbol key for storing the embedding's preferred index configuration\n * on the schema. The schema introspector reads this when auto-deriving\n * `VectorIndexDeclaration` entries at `defineGraph()` time.\n */\nexport const EMBEDDING_INDEX_KEY = \"_embeddingIndex\" as const;\n\n/**\n * Distance metric used for vector similarity. Pinned at the embedding\n * brand because changing the metric usually means generating different\n * model output (e.g. cosine-normalized vs. raw inner-product), and the\n * stored index needs the same metric to score correctly.\n *\n * - `cosine`: cosine similarity. The default — works for most\n * sentence-transformer / OpenAI-style embeddings that are already\n * length-normalized.\n * - `l2`: Euclidean distance. Use when your model outputs vectors\n * trained for L2 (e.g. some image embedding models).\n * - `inner_product`: dot-product distance. Use when your model outputs\n * pre-normalized vectors AND you want to skip the cosine\n * normalization step at query time.\n */\nexport type EmbeddingMetric = \"cosine\" | \"l2\" | \"inner_product\";\n\n/**\n * Vector index implementation. `hnsw` is the default and what pgvector\n * recommends for most workloads. `ivfflat` is the alternative for\n * larger datasets where memory is the bottleneck. `none` disables\n * automatic index creation for this embedding (the operator can still\n * call `backend.createVectorIndex` manually).\n */\nexport type EmbeddingIndexType = \"hnsw\" | \"ivfflat\" | \"none\";\n\n/**\n * Per-embedding configuration for the auto-derived\n * `VectorIndexDeclaration`. All fields are optional with sensible\n * defaults (`cosine` / `hnsw` / pgvector defaults: `m=16`,\n * `ef_construction=64`). Override only when your model or dataset has\n * a known reason to.\n */\nexport type EmbeddingIndexOptions = Readonly<{\n /** Distance metric. Default `\"cosine\"`. */\n metric?: EmbeddingMetric;\n /** Vector index implementation. Default `\"hnsw\"`. */\n indexType?: EmbeddingIndexType;\n /** HNSW `m` parameter — max connections per layer. Default `16`. */\n m?: number;\n /** HNSW `ef_construction` parameter — build-time search depth. Default `64`. */\n efConstruction?: number;\n /** IVFFlat `lists` parameter — number of inverted-list partitions. */\n lists?: number;\n}>;\n\n/**\n * Resolved embedding index configuration with all defaults applied.\n * What gets attached to the brand and read by the auto-derivation pass.\n */\nexport type ResolvedEmbeddingIndex = Readonly<{\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n m: number;\n efConstruction: number;\n lists: number | undefined;\n}>;\n\nconst DEFAULT_HNSW_M = 16;\nconst DEFAULT_HNSW_EF_CONSTRUCTION = 64;\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 [EMBEDDING_INDEX_KEY]: ResolvedEmbeddingIndex;\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>(\n dimensions: D,\n options: EmbeddingIndexOptions = {},\n): 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 const indexConfig = resolveEmbeddingIndex(options);\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 return Object.assign(schema, {\n [EMBEDDING_DIMENSIONS_KEY]: dimensions,\n [EMBEDDING_INDEX_KEY]: indexConfig,\n });\n}\n\nfunction resolveEmbeddingIndex(\n options: EmbeddingIndexOptions,\n): ResolvedEmbeddingIndex {\n const indexType = options.indexType ?? DEFAULT_EMBEDDING_INDEX_TYPE;\n const m = options.m ?? DEFAULT_HNSW_M;\n const efConstruction = options.efConstruction ?? DEFAULT_HNSW_EF_CONSTRUCTION;\n\n if (m <= 0 || !Number.isInteger(m)) {\n throw new Error(\n `embedding() index option 'm' must be a positive integer, got: ${m}`,\n );\n }\n if (efConstruction <= 0 || !Number.isInteger(efConstruction)) {\n throw new Error(\n `embedding() index option 'efConstruction' must be a positive integer, got: ${efConstruction}`,\n );\n }\n if (\n options.lists !== undefined &&\n (options.lists <= 0 || !Number.isInteger(options.lists))\n ) {\n throw new Error(\n `embedding() index option 'lists' must be a positive integer, got: ${options.lists}`,\n );\n }\n\n return Object.freeze({\n metric: options.metric ?? DEFAULT_EMBEDDING_METRIC,\n indexType,\n m,\n efConstruction,\n lists: options.lists,\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/**\n * Gets the resolved index configuration from an embedding schema.\n * Returns undefined if the schema is not an embedding schema. Used by\n * the auto-derivation pass at `defineGraph()` time to build vector\n * `IndexDeclaration` entries.\n */\nexport function getEmbeddingIndex(\n schema: z.ZodType,\n): ResolvedEmbeddingIndex | undefined {\n if (!isEmbeddingSchema(schema)) return undefined;\n const candidate = (schema as unknown as Record<string, unknown>)[\n EMBEDDING_INDEX_KEY\n ];\n if (candidate === undefined) return undefined;\n return candidate as ResolvedEmbeddingIndex;\n}\n\n// ============================================================\n// Embedding Field Resolution\n// ============================================================\n\n/**\n * One resolved embedding field on a node schema — its dot-path plus the\n * fixed `dimensions` and the resolved index `(metric, indexType)`.\n * Sourced from the field's `embedding()` brand, unwrapping `.optional()`\n * / `.nullable()` / `.default()` / `.readonly()` wrappers. The single\n * source of truth shared by embedding sync (write path), the query\n * compiler's `field.similarTo(...)` slot resolution, and search.\n */\nexport type ResolvedEmbeddingField = Readonly<{\n fieldPath: string;\n dimensions: number;\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n}>;\n\n/**\n * The single source of truth for an embedding field's default metric / index\n * type when unspecified — used by `embedding()` declaration resolution, the\n * field-fallback below, and the legacy-migration slot defaults\n * (`migrate-vectors.ts`) so the three never drift.\n */\nexport const DEFAULT_EMBEDDING_METRIC: EmbeddingMetric = \"cosine\";\nexport const DEFAULT_EMBEDDING_INDEX_TYPE: EmbeddingIndexType = \"hnsw\";\n\n/**\n * Extracts every top-level embedding field from a node's object schema.\n * Returns `[]` for non-object schemas or schemas with no embedding\n * fields. Embeddings nested inside object properties are out of scope by\n * design (storage keys at the top-level `(kind, fieldPath)` grain).\n */\nexport function resolveEmbeddingFields(\n schema: z.ZodType,\n): readonly ResolvedEmbeddingField[] {\n if (schema.type !== \"object\") return [];\n const shape = (schema.def as { shape?: Record<string, z.ZodType> }).shape;\n if (!shape) return [];\n\n const fields: ResolvedEmbeddingField[] = [];\n for (const [fieldPath, fieldSchema] of Object.entries(shape)) {\n const dimensions = resolveEmbeddingDimensions(fieldSchema);\n if (dimensions === undefined) continue;\n const index = resolveEmbeddingIndexConfig(fieldSchema);\n fields.push({\n fieldPath,\n dimensions,\n metric: index?.metric ?? DEFAULT_EMBEDDING_METRIC,\n indexType: index?.indexType ?? DEFAULT_EMBEDDING_INDEX_TYPE,\n });\n }\n return fields;\n}\n\nfunction resolveEmbeddingDimensions(schema: z.ZodType): number | undefined {\n const direct = getEmbeddingDimensions(schema);\n if (direct !== undefined) return direct;\n const unwrapped = unwrapToEmbedding(schema);\n return unwrapped === undefined ? undefined : (\n getEmbeddingDimensions(unwrapped)\n );\n}\n\nfunction resolveEmbeddingIndexConfig(\n schema: z.ZodType,\n): ResolvedEmbeddingIndex | undefined {\n const direct = getEmbeddingIndex(schema);\n if (direct !== undefined) return direct;\n const unwrapped = unwrapToEmbedding(schema);\n return unwrapped === undefined ? undefined : getEmbeddingIndex(unwrapped);\n}\n\n/**\n * Unwraps optional / nullable / default / readonly wrappers to find the\n * inner embedding schema, recursing through chained wrappers. Returns\n * `undefined` when no embedding schema is reachable.\n */\nfunction unwrapToEmbedding(schema: z.ZodType): z.ZodType | undefined {\n const type = schema.type;\n const innerType = (schema.def as { innerType?: z.ZodType }).innerType;\n if (\n (type === \"optional\" ||\n type === \"nullable\" ||\n type === \"default\" ||\n type === \"readonly\") &&\n innerType\n ) {\n if (isEmbeddingSchema(innerType)) return innerType;\n return unwrapToEmbedding(innerType);\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\n// ============================================================\n// Schema-level searchable-field resolution\n// ============================================================\n\n/** One searchable field discovered on a node schema. */\nexport type SearchableFieldInfo = Readonly<{\n fieldPath: string;\n metadata: SearchableMetadata;\n}>;\n\n/**\n * Cache keyed by the Zod schema *instance*. Schemas are immutable at\n * runtime and the same `nodeKind.schema` reference is reused across\n * every CRUD call, so this collapses the per-use introspection cost to\n * one walk per schema for the lifetime of the process.\n */\nconst searchableFieldsCache = new WeakMap<\n z.ZodType,\n readonly SearchableFieldInfo[]\n>();\n\n/**\n * Extracts searchable field information from a Zod schema.\n *\n * Handles top-level searchable() strings as well as wrapped variants\n * (optional / nullable / default / readonly / pipe).\n */\nexport function getSearchableFields(\n schema: z.ZodType,\n): readonly SearchableFieldInfo[] {\n const cached = searchableFieldsCache.get(schema);\n if (cached) return cached;\n\n const fields = computeSearchableFields(schema);\n searchableFieldsCache.set(schema, fields);\n return fields;\n}\n\nfunction computeSearchableFields(\n schema: z.ZodType,\n): readonly SearchableFieldInfo[] {\n if (schema.type !== \"object\") return [];\n\n const def = schema.def as { shape?: Record<string, z.ZodType> };\n const shape = def.shape;\n if (!shape) return [];\n\n const fields: SearchableFieldInfo[] = [];\n for (const [fieldPath, fieldSchema] of Object.entries(shape)) {\n const metadata = getSearchableMetadata(fieldSchema);\n if (metadata !== undefined) {\n fields.push({ fieldPath, metadata });\n }\n }\n warnIfConflictingLanguages(fields);\n return fields;\n}\n\n/**\n * Warns (once per schema, via the WeakMap memo above) when a schema's\n * searchable fields declare different `language` values. The first\n * field's language wins on the stored row; true per-field multilingual\n * indexing is not supported today.\n */\nfunction warnIfConflictingLanguages(\n fields: readonly SearchableFieldInfo[],\n): void {\n if (fields.length < 2) return;\n const languages = new Set(fields.map((field) => field.metadata.language));\n if (languages.size < 2) return;\n if (typeof console === \"undefined\" || typeof console.warn !== \"function\") {\n return;\n }\n const fieldSummary = fields\n .map((field) => `${field.fieldPath}=${field.metadata.language}`)\n .join(\", \");\n const winning = fields[0]?.metadata.language ?? DEFAULT_SEARCHABLE_LANGUAGE;\n console.warn(\n `[typegraph] searchable() fields declare conflicting languages ` +\n `(${fieldSummary}). The first field's language (\"${winning}\") is ` +\n `used for the combined fulltext row.`,\n );\n}\n\n/**\n * The one language a kind's fulltext rows are written with — the first\n * searchable field's declared language (the winning-language rule the\n * write path applies). `undefined` when the schema has no searchable\n * fields.\n *\n * Search paths use this to parse queries with a CONSTANT regconfig: the\n * per-row `websearch_to_tsquery(\"language\", ...)` form makes the tsquery\n * non-constant, so PostgreSQL's GIN index on `tsv` can never serve the\n * match and every search scans the kind's rows.\n */\nexport function resolveDeclaredFulltextLanguage(\n schema: z.ZodType,\n): string | undefined {\n return getSearchableFields(schema)[0]?.metadata.language;\n}\n"]}
|
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
import { ConfigurationError } from './chunk-
|
|
1
|
+
import { ValidationError, ConfigurationError } from './chunk-MP2JQKSG.js';
|
|
2
|
+
|
|
3
|
+
// src/utils/date.ts
|
|
4
|
+
var CANONICAL_ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
5
|
+
function isCanonicalIsoDate(value) {
|
|
6
|
+
if (!CANONICAL_ISO_DATE_PATTERN.test(value)) return false;
|
|
7
|
+
const date = new Date(value);
|
|
8
|
+
return !Number.isNaN(date.getTime()) && date.toISOString() === value;
|
|
9
|
+
}
|
|
10
|
+
function validateCanonicalIsoDate(value, fieldName) {
|
|
11
|
+
if (!isCanonicalIsoDate(value)) {
|
|
12
|
+
throw new ValidationError(
|
|
13
|
+
`Invalid canonical ISO 8601 datetime for "${fieldName}": "${value}". Expected fixed-width UTC: YYYY-MM-DDTHH:mm:ss.sssZ`,
|
|
14
|
+
{
|
|
15
|
+
issues: [
|
|
16
|
+
{
|
|
17
|
+
path: fieldName,
|
|
18
|
+
message: `Expected canonical UTC ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ), got: "${value}"`
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
suggestion: `Use a fixed-width UTC datetime like "2024-01-15T10:30:00.000Z" (e.g. new Date(value).toISOString()).`
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function validateOptionalCanonicalIsoDate(value, fieldName) {
|
|
30
|
+
if (value === void 0) return void 0;
|
|
31
|
+
return validateCanonicalIsoDate(value, fieldName);
|
|
32
|
+
}
|
|
33
|
+
function nowIso() {
|
|
34
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
35
|
+
}
|
|
2
36
|
|
|
3
37
|
// src/utils/sql-errors.ts
|
|
4
38
|
var SQLITE_MISSING_TABLE_PATTERN = "no such table";
|
|
@@ -48,6 +82,15 @@ function isPostgresUndefinedRelationMessage(link) {
|
|
|
48
82
|
if (message.startsWith(DRIZZLE_QUERY_ERROR_PREFIX)) return false;
|
|
49
83
|
return POSTGRES_UNDEFINED_RELATION_PATTERN.test(message);
|
|
50
84
|
}
|
|
85
|
+
function isInsufficientResourcesError(error) {
|
|
86
|
+
for (const link of errorChain(error)) {
|
|
87
|
+
if (!canReadProperty(link)) continue;
|
|
88
|
+
const code = Reflect.get(link, "code");
|
|
89
|
+
if (typeof code === "string" && code.length === 5 && code.startsWith("53"))
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
51
94
|
function isMissingTableError(error) {
|
|
52
95
|
let everyPriorLinkWasError = true;
|
|
53
96
|
for (const link of errorChain(error)) {
|
|
@@ -100,6 +143,6 @@ function parseDimensionMismatch(error) {
|
|
|
100
143
|
return void 0;
|
|
101
144
|
}
|
|
102
145
|
|
|
103
|
-
export { isMissingTableError, parseDimensionMismatch, withRecordedRelationsPrecondition };
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
146
|
+
export { isCanonicalIsoDate, isInsufficientResourcesError, isMissingTableError, nowIso, parseDimensionMismatch, validateCanonicalIsoDate, validateOptionalCanonicalIsoDate, withRecordedRelationsPrecondition };
|
|
147
|
+
//# sourceMappingURL=chunk-I7ZUZKFD.js.map
|
|
148
|
+
//# sourceMappingURL=chunk-I7ZUZKFD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/date.ts","../src/utils/sql-errors.ts"],"names":[],"mappings":";;;AAyEA,IAAM,0BAAA,GACJ,+CAAA;AAMK,SAAS,mBAAmB,KAAA,EAAwB;AACzD,EAAA,IAAI,CAAC,0BAAA,CAA2B,IAAA,CAAK,KAAK,GAAG,OAAO,KAAA;AACpD,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,KAAK,CAAA;AAC3B,EAAA,OAAO,CAAC,OAAO,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,IAAK,IAAA,CAAK,WAAA,EAAY,KAAM,KAAA;AACjE;AAgBO,SAAS,wBAAA,CACd,OACA,SAAA,EACQ;AACR,EAAA,IAAI,CAAC,kBAAA,CAAmB,KAAK,CAAA,EAAG;AAC9B,IAAA,MAAM,IAAI,eAAA;AAAA,MACR,CAAA,yCAAA,EAA4C,SAAS,CAAA,IAAA,EAAO,KAAK,CAAA,qDAAA,CAAA;AAAA,MAEjE;AAAA,QACE,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,IAAA,EAAM,SAAA;AAAA,YACN,OAAA,EAAS,qEAAqE,KAAK,CAAA,CAAA;AAAA;AACrF;AACF,OACF;AAAA,MACA;AAAA,QACE,UAAA,EAAY,CAAA,oGAAA;AAAA;AACd,KACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAUO,SAAS,gCAAA,CACd,OACA,SAAA,EACoB;AACpB,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,MAAA;AAChC,EAAA,OAAO,wBAAA,CAAyB,OAAO,SAAS,CAAA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A,MAAM,oCAAA;AAAA,MACJ,EAAE,GAAG,OAAA,EAAS,IAAA,EAAM,4BAAA,EAA6B;AAAA,MACjD;AAAA,KACF;AAAA,EACF;AACF;AAQA,IAAM,0BAAA,GACJ,sEAAA;AAQK,SAAS,uBACd,KAAA,EAC8D;AAC9D,EAAA,KAAA,MAAW,IAAA,IAAQ,UAAA,CAAW,KAAK,CAAA,EAAG;AACpC,IAAA,MAAM,OAAA,GAAU,aAAa,IAAI,CAAA;AACjC,IAAA,MAAM,KAAA,GAAQ,0BAAA,CAA2B,IAAA,CAAK,OAAO,CAAA;AACrD,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,OAAO;AAAA,QACL,QAAA,EAAU,MAAA,CAAO,KAAA,CAAM,CAAC,CAAC,CAAA;AAAA,QACzB,MAAA,EAAQ,MAAM,CAAC,CAAA,KAAM,SAAY,MAAA,GAAY,MAAA,CAAO,KAAA,CAAM,CAAC,CAAC;AAAA,OAC9D;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"chunk-I7ZUZKFD.js","sourcesContent":["/**\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 * Strict canonical ISO 8601 pattern: fixed-width UTC with exactly\n * millisecond precision (`YYYY-MM-DDTHH:mm:ss.sssZ`). Unlike\n * {@link ISO_DATE_PATTERN}, which tolerates a missing or variable-width\n * fractional part, this is the only shape whose lexicographic text order\n * matches chronological order — avoiding cases like `\"...:00.1Z\"` (= `.100`)\n * sorting *after* `\"...:00.101Z\"`.\n */\nconst CANONICAL_ISO_DATE_PATTERN =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n\n/**\n * Checks if a string is a canonical UTC ISO 8601 datetime with fixed\n * millisecond width (`YYYY-MM-DDTHH:mm:ss.sssZ`).\n */\nexport function isCanonicalIsoDate(value: string): boolean {\n if (!CANONICAL_ISO_DATE_PATTERN.test(value)) return false;\n const date = new Date(value);\n return !Number.isNaN(date.getTime()) && date.toISOString() === value;\n}\n\n/**\n * Validates that a string is a canonical UTC ISO 8601 datetime with fixed\n * millisecond width. Stricter than {@link validateIsoDate} (which also\n * accepts missing or 1–2 digit milliseconds): required wherever the value\n * is compared **as text** against stored timestamps and must sort\n * chronologically — e.g. a temporal `asOf` coordinate, where a\n * variable-width value would mis-order and silently include or exclude the\n * wrong rows. Produce one with `new Date(value).toISOString()`.\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 canonical UTC ISO datetime\n */\nexport function validateCanonicalIsoDate(\n value: string,\n fieldName: string,\n): string {\n if (!isCanonicalIsoDate(value)) {\n throw new ValidationError(\n `Invalid canonical ISO 8601 datetime for \"${fieldName}\": \"${value}\". ` +\n `Expected fixed-width UTC: YYYY-MM-DDTHH:mm:ss.sssZ`,\n {\n issues: [\n {\n path: fieldName,\n message: `Expected canonical UTC ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ), got: \"${value}\"`,\n },\n ],\n },\n {\n suggestion: `Use a fixed-width UTC datetime like \"2024-01-15T10:30:00.000Z\" (e.g. new Date(value).toISOString()).`,\n },\n );\n }\n return value;\n}\n\n/**\n * Validates an optional canonical ISO date string. Returns `undefined` for an\n * absent value; otherwise enforces canonical fixed-width UTC ISO 8601 via\n * {@link validateCanonicalIsoDate}. Used for stored validity-window inputs\n * (`validFrom` / `validTo`) so every timestamp the temporal filters compare as\n * text is canonical and sorts chronologically — the same contract the `asOf`\n * read coordinate already enforces.\n */\nexport function validateOptionalCanonicalIsoDate(\n value: string | undefined,\n fieldName: string,\n): string | undefined {\n if (value === undefined) return undefined;\n return validateCanonicalIsoDate(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","/**\n * Cross-dialect detection of \"this relation does not exist yet\" errors.\n *\n * Shared so the schema bootstrap (`loadActiveSchemaWithBootstrap`) and\n * the durable contribution-materialization gate (#135) agree on what a\n * missing-table failure looks like, and — critically — so neither one\n * swallows a genuine system fault (connection/permission/driver error)\n * as a benign \"not bootstrapped yet\".\n *\n * Detection walks the error's `cause` chain because Drizzle (>= the\n * `DrizzleQueryError` era, drizzle-orm ≥ 0.36) wraps every failure from a\n * query-builder call (`db.select()`, `db.insert()`, …): the wrapper's\n * `.message` becomes the failed query text and the real driver error —\n * which carries both the missing-relation text and the SQLSTATE — is\n * preserved on `.cause`. node-postgres / postgres-js nest the pg error\n * one link deep; better-sqlite3 throws it unwrapped; raw `client.query()`\n * fast paths surface it directly. Walking the chain makes the check\n * wrapper- and driver-agnostic instead of only matching the outermost\n * `.message`, which on Postgres is just the SQL string.\n */\n\nimport { ConfigurationError } from \"../errors\";\n\nconst SQLITE_MISSING_TABLE_PATTERN = \"no such table\";\nconst SQLITE_GENERIC_ERROR_CODE = \"SQLITE_ERROR\";\nconst DRIZZLE_QUERY_ERROR_PREFIX = \"Failed query:\";\nconst POSTGRES_UNDEFINED_RELATION_PATTERN =\n /\\b(?:relation|table)\\s+\"[^\"]+\"\\s+does not exist\\b/i;\n\n/**\n * SQLSTATE for PostgreSQL `undefined_table`. Preferred over the\n * human-readable message: it is locale-independent (the \"... does not\n * exist\" text is translated under a non-English `lc_messages`) and is\n * preserved on the underlying driver error even when Drizzle overwrites\n * `.message` with the query text.\n */\nconst POSTGRES_UNDEFINED_TABLE_CODE = \"42P01\";\n\n/**\n * Yields an error and each error reachable by following `.cause`,\n * outermost first. `seen` guards the pathological cyclic-cause case so a\n * self-referential chain can't spin forever.\n *\n * The walk intentionally follows `.cause` through *non-`Error`* links, not just\n * `Error` instances: postgres-js surfaces its driver error as a plain object\n * (message + SQLSTATE `code`) on a Drizzle wrapper's `.cause`, so stopping at\n * the first non-`Error` link would miss it (see the postgres-js test). A plain\n * object is classified by its locale-independent SQLSTATE alone\n * ({@link isPostgresUndefinedTable}); the looser SQLite message substring is\n * consulted only for `Error` instances and raw strings\n * ({@link missingTableMessage}), so an unrelated object in a cause chain that\n * merely mentions one of those phrases is not mistaken for a missing table.\n */\nfunction* errorChain(error: unknown): Generator<unknown, void, void> {\n const seen = new Set<unknown>();\n let current: unknown = error;\n while (current !== undefined && current !== null && !seen.has(current)) {\n seen.add(current);\n yield current;\n current =\n canReadProperty(current) ? Reflect.get(current, \"cause\") : undefined;\n }\n}\n\nfunction canReadProperty(value: unknown): value is object {\n return (\n (typeof value === \"object\" && value !== null) || typeof value === \"function\"\n );\n}\n\n/**\n * Whether a single chain link is a PostgreSQL `undefined_table` failure,\n * identified by its SQLSTATE rather than a message substring.\n */\nfunction isPostgresUndefinedTable(link: unknown): boolean {\n return (\n canReadProperty(link) &&\n Reflect.get(link, \"code\") === POSTGRES_UNDEFINED_TABLE_CODE\n );\n}\n\nfunction messageProperty(link: unknown): string | undefined {\n if (typeof link === \"string\") return link;\n if (link instanceof Error) return link.message;\n const message =\n canReadProperty(link) ?\n (Reflect.get(link, \"message\") as unknown)\n : undefined;\n return typeof message === \"string\" ? message : undefined;\n}\n\nfunction errorMessage(link: unknown): string {\n return messageProperty(link) ?? String(link);\n}\n\n/**\n * The message a SQLite missing-table substring match may be tested against — but\n * only for `Error` instances and raw `string` links, never an arbitrary plain\n * object.\n *\n * Generic \"does not exist\" is deliberately not substring-matched: PostgreSQL uses\n * that phrase for undefined columns, functions, types, and relations. PostgreSQL\n * missing tables are classified by SQLSTATE 42P01 when available, or by the\n * narrower driver-message shape `relation/table \"...\" does not exist` when a\n * bring-your-own driver omits SQLSTATE. SQLite does not expose a portable\n * SQLSTATE here, so the narrow \"no such table\" engine message is still accepted.\n */\nfunction missingTableMessage(link: unknown): string | undefined {\n return typeof link === \"string\" || link instanceof Error ?\n messageProperty(link)\n : undefined;\n}\n\nfunction sqliteErrorCode(link: unknown): unknown {\n if (!canReadProperty(link)) return undefined;\n return Reflect.get(link, \"code\");\n}\n\n/**\n * Cloudflare D1 / Durable Objects may surface a missing-table failure as the\n * generic SQLite code with no detail. Accept the bare marker, but do not\n * substring-match detailed `SQLITE_ERROR: ...` failures: those include syntax\n * errors and bind-limit faults that must stay loud.\n */\nfunction isBareSqliteErrorMarker(link: unknown): boolean {\n const message = messageProperty(link);\n if (message === SQLITE_GENERIC_ERROR_CODE) return true;\n if (sqliteErrorCode(link) !== SQLITE_GENERIC_ERROR_CODE) return false;\n return (\n message === undefined ||\n message === SQLITE_GENERIC_ERROR_CODE ||\n message.includes(SQLITE_MISSING_TABLE_PATTERN)\n );\n}\n\nfunction isPostgresUndefinedRelationMessage(link: unknown): boolean {\n const message = errorMessage(link);\n if (message.startsWith(DRIZZLE_QUERY_ERROR_PREFIX)) return false;\n return POSTGRES_UNDEFINED_RELATION_PATTERN.test(message);\n}\n\n/**\n * Whether any link in the cause chain is a PostgreSQL \"insufficient\n * resources\" failure (SQLSTATE class 53: disk_full, out_of_memory,\n * configuration_limit_exceeded, ...). Parallel index builds surface\n * shared-memory exhaustion this way (53100 from dsm_impl_posix on hosts\n * with a small /dev/shm); callers retry such work with parallelism\n * disabled. Identified by the locale-independent 5-character SQLSTATE\n * prefix only — never by message text.\n */\nexport function isInsufficientResourcesError(error: unknown): boolean {\n for (const link of errorChain(error)) {\n if (!canReadProperty(link)) continue;\n const code: unknown = Reflect.get(link, \"code\");\n if (typeof code === \"string\" && code.length === 5 && code.startsWith(\"53\"))\n return true;\n }\n return false;\n}\n\nexport function isMissingTableError(error: unknown): boolean {\n // SQLSTATE 42P01 is locale-independent and structural, so it is honored on\n // *every* link — including a plain driver-error object reached only by walking\n // through a non-`Error` `.cause` (postgres-js).\n //\n // The SQLite message substring is honored only while every prior link in the\n // chain was an `Error` (or the top-level string) — the reach of the\n // pre-broadening walk, which stopped at the first non-`Error` `.cause`.\n let everyPriorLinkWasError = true;\n for (const link of errorChain(error)) {\n if (isPostgresUndefinedTable(link)) return true;\n if (isPostgresUndefinedRelationMessage(link)) return true;\n if (isBareSqliteErrorMarker(link)) return true;\n if (everyPriorLinkWasError) {\n const message = missingTableMessage(link);\n if (message?.includes(SQLITE_MISSING_TABLE_PATTERN) === true) {\n return true;\n }\n }\n if (!(link instanceof Error)) everyPriorLinkWasError = false;\n }\n return false;\n}\n\nfunction historyMissingRecordedRelationsError(\n details: Record<string, unknown>,\n cause: unknown,\n): ConfigurationError {\n return new ConfigurationError(\n \"history: true requires the recorded-time relations to exist, but a recorded relation is missing.\",\n details,\n {\n cause,\n suggestion:\n \"Create the recorded-time relations (typegraph_recorded_nodes, typegraph_recorded_edges, typegraph_recorded_clock) — e.g. re-run the generated migration SQL — on this database before enabling history capture.\",\n },\n );\n}\n\n/**\n * Converts missing recorded-relation failures into the actionable precondition\n * error used by construction-time history checks. Capture paths use this after\n * the live write has already succeeded inside the same transaction; recorded\n * read paths use it when query/schema swapping reaches a recorded table that\n * has not been materialized yet.\n */\nexport async function withRecordedRelationsPrecondition<T>(\n promise: Promise<T>,\n details: Record<string, unknown>,\n): Promise<T> {\n try {\n return await promise;\n } catch (error) {\n if (!isMissingTableError(error)) throw error;\n throw historyMissingRecordedRelationsError(\n { ...details, code: \"RECORDED_RELATIONS_MISSING\" },\n error,\n );\n }\n}\n\n/**\n * Engine \"vector dimension mismatch\" message shapes. pgvector:\n * `expected 384 dimensions, not 512`; libSQL / sqlite-vec surface a similar\n * `expected N … got/not M`. The first capture is the dimension the *stored*\n * column expects; the optional second is the dimension that was *attempted*.\n */\nconst DIMENSION_MISMATCH_PATTERN =\n /expected (\\d+) dimensions(?:[,\\s]+(?:not|got|but got|but)\\s*(\\d+))?/i;\n\n/**\n * Parses an engine vector-dimension-mismatch error into `{ expected, actual }`\n * by walking the `.cause` chain (drivers wrap the real error). `expected` is\n * the stored column's dimension; `actual` (when the message includes it) is the\n * attempted vector's dimension. Returns `undefined` for unrelated errors.\n */\nexport function parseDimensionMismatch(\n error: unknown,\n): { expected: number; actual: number | undefined } | undefined {\n for (const link of errorChain(error)) {\n const message = errorMessage(link);\n const match = DIMENSION_MISMATCH_PATTERN.exec(message);\n if (match) {\n return {\n expected: Number(match[1]),\n actual: match[2] === undefined ? undefined : Number(match[2]),\n };\n }\n }\n return undefined;\n}\n"]}
|