@nicia-ai/typegraph 0.32.0 → 0.34.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/README.md +51 -0
- package/dist/backend/postgres/index.cjs +36 -19
- package/dist/backend/postgres/index.d.cts +6 -6
- package/dist/backend/postgres/index.d.ts +6 -6
- package/dist/backend/postgres/index.js +14 -9
- package/dist/backend/postgres/pglite.cjs +18 -13
- package/dist/backend/postgres/pglite.cjs.map +1 -1
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +14 -9
- package/dist/backend/postgres/pglite.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +34 -17
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +13 -8
- package/dist/backend/sqlite/libsql.cjs +19 -14
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +12 -5
- package/dist/backend/sqlite/libsql.d.ts +12 -5
- package/dist/backend/sqlite/libsql.js +15 -10
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +19 -14
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +14 -9
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/chunk-2EBMPJBO.js +16 -0
- package/dist/chunk-2EBMPJBO.js.map +1 -0
- package/dist/{chunk-CFNT3ITG.cjs → chunk-2JXB3NYJ.cjs} +15 -35
- package/dist/chunk-2JXB3NYJ.cjs.map +1 -0
- package/dist/chunk-2MRAX3UE.js +105 -0
- package/dist/chunk-2MRAX3UE.js.map +1 -0
- package/dist/{chunk-2LAT5BIK.cjs → chunk-3BRVBQQD.cjs} +2328 -3131
- package/dist/chunk-3BRVBQQD.cjs.map +1 -0
- package/dist/chunk-3E7SNSIA.cjs +55 -0
- package/dist/chunk-3E7SNSIA.cjs.map +1 -0
- package/dist/{chunk-FDN43KXV.cjs → chunk-3Z6TW3CT.cjs} +20 -19
- package/dist/chunk-3Z6TW3CT.cjs.map +1 -0
- package/dist/{chunk-IJORSAC3.js → chunk-4DIBPQNJ.js} +6 -4
- package/dist/chunk-4DIBPQNJ.js.map +1 -0
- package/dist/chunk-4S2FXGBJ.js +9 -0
- package/dist/chunk-4S2FXGBJ.js.map +1 -0
- package/dist/chunk-5IQIX7LU.cjs +2070 -0
- package/dist/chunk-5IQIX7LU.cjs.map +1 -0
- package/dist/{chunk-CWFPJ3RC.js → chunk-6GNSY7AV.js} +3 -3
- package/dist/{chunk-CWFPJ3RC.js.map → chunk-6GNSY7AV.js.map} +1 -1
- package/dist/{chunk-LAZGHOZW.cjs → chunk-6HVOHZHS.cjs} +184 -117
- package/dist/chunk-6HVOHZHS.cjs.map +1 -0
- package/dist/chunk-6SCVW4AS.js +20 -0
- package/dist/chunk-6SCVW4AS.js.map +1 -0
- package/dist/chunk-A7SZZFAG.js +2010 -0
- package/dist/chunk-A7SZZFAG.js.map +1 -0
- package/dist/chunk-ACSVZPK7.cjs +21 -0
- package/dist/chunk-ACSVZPK7.cjs.map +1 -0
- package/dist/{chunk-MXE2U3EX.js → chunk-BVTWD66D.js} +4 -115
- package/dist/chunk-BVTWD66D.js.map +1 -0
- package/dist/{chunk-W4ZX2GCP.js → chunk-CHXTTSC6.js} +5 -39
- package/dist/chunk-CHXTTSC6.js.map +1 -0
- package/dist/{chunk-XQFAJVYW.js → chunk-CYX2JTDG.js} +124 -5
- package/dist/chunk-CYX2JTDG.js.map +1 -0
- package/dist/{chunk-PRMKPFN5.js → chunk-DEQFL35G.js} +4 -3
- package/dist/chunk-DEQFL35G.js.map +1 -0
- package/dist/chunk-DI74SMXS.cjs +29 -0
- package/dist/chunk-DI74SMXS.cjs.map +1 -0
- package/dist/{chunk-WWVV44DY.cjs → chunk-G6SOJEDI.cjs} +11 -11
- package/dist/{chunk-WWVV44DY.cjs.map → chunk-G6SOJEDI.cjs.map} +1 -1
- package/dist/{chunk-LM2IC4ZJ.cjs → chunk-GQANNXXT.cjs} +15 -14
- package/dist/chunk-GQANNXXT.cjs.map +1 -0
- package/dist/chunk-GZCNZ7QW.js +24 -0
- package/dist/chunk-GZCNZ7QW.js.map +1 -0
- package/dist/{chunk-KTIEB7VH.cjs → chunk-HK5SATYM.cjs} +35 -58
- package/dist/chunk-HK5SATYM.cjs.map +1 -0
- package/dist/chunk-HMFK4BXR.cjs +12 -0
- package/dist/{chunk-6ZR4QC3O.cjs.map → chunk-HMFK4BXR.cjs.map} +1 -1
- package/dist/chunk-ITE4IXAK.js +25 -0
- package/dist/chunk-ITE4IXAK.js.map +1 -0
- package/dist/chunk-JJRCLAUN.cjs +155 -0
- package/dist/chunk-JJRCLAUN.cjs.map +1 -0
- package/dist/{chunk-ZFWNO3GE.cjs → chunk-JQGIPGVL.cjs} +66 -2
- package/dist/chunk-JQGIPGVL.cjs.map +1 -0
- package/dist/{chunk-2BVHPOIG.js → chunk-K2TGS3EN.js} +105 -38
- package/dist/chunk-K2TGS3EN.js.map +1 -0
- package/dist/chunk-K34OPSJK.js +29 -0
- package/dist/chunk-K34OPSJK.js.map +1 -0
- package/dist/{chunk-YW7GHMF4.cjs → chunk-KGC4LY5T.cjs} +18 -17
- package/dist/chunk-KGC4LY5T.cjs.map +1 -0
- package/dist/{chunk-SB65GJNY.cjs → chunk-KNHYNQQ3.cjs} +111 -72
- package/dist/chunk-KNHYNQQ3.cjs.map +1 -0
- package/dist/{chunk-C4C4Q7A6.js → chunk-KUTNI6SI.js} +6 -21
- package/dist/chunk-KUTNI6SI.js.map +1 -0
- package/dist/{chunk-NDM5PXEH.js → chunk-LANHCOXB.js} +44 -11
- package/dist/chunk-LANHCOXB.js.map +1 -0
- package/dist/chunk-N6WTUSBV.cjs +23 -0
- package/dist/chunk-N6WTUSBV.cjs.map +1 -0
- package/dist/{chunk-73KASJGO.cjs → chunk-NAUA4PW5.cjs} +4 -28
- package/dist/chunk-NAUA4PW5.cjs.map +1 -0
- package/dist/chunk-QV245VMN.js +145 -0
- package/dist/chunk-QV245VMN.js.map +1 -0
- package/dist/{chunk-CEF2QOTO.js → chunk-RBV7YCQD.js} +4 -3
- package/dist/chunk-RBV7YCQD.js.map +1 -0
- package/dist/chunk-RHZWOJVA.cjs +109 -0
- package/dist/chunk-RHZWOJVA.cjs.map +1 -0
- package/dist/{chunk-6RMLO5O4.cjs → chunk-RRKQAKD6.cjs} +13 -11
- package/dist/chunk-RRKQAKD6.cjs.map +1 -0
- package/dist/{chunk-TUA3MEJJ.js → chunk-RY2VIWAM.js} +612 -564
- package/dist/chunk-RY2VIWAM.js.map +1 -0
- package/dist/{chunk-PIHXFF73.js → chunk-SHLY4MCM.js} +3 -3
- package/dist/{chunk-PIHXFF73.js.map → chunk-SHLY4MCM.js.map} +1 -1
- package/dist/{chunk-HFBRAOF7.js → chunk-T2DWPQNE.js} +103 -64
- package/dist/chunk-T2DWPQNE.js.map +1 -0
- package/dist/{chunk-WYTUF3QO.js → chunk-T46GR2VY.js} +3 -3
- package/dist/{chunk-WYTUF3QO.js.map → chunk-T46GR2VY.js.map} +1 -1
- package/dist/{chunk-EEYV6UOE.cjs → chunk-T6SPUYLX.cjs} +5 -43
- package/dist/chunk-T6SPUYLX.cjs.map +1 -0
- package/dist/{chunk-3QRBXYT5.cjs → chunk-TGJE22RM.cjs} +6 -6
- package/dist/{chunk-3QRBXYT5.cjs.map → chunk-TGJE22RM.cjs.map} +1 -1
- package/dist/{chunk-YL4F3CMD.cjs → chunk-TOTPVGOG.cjs} +105 -72
- package/dist/chunk-TOTPVGOG.cjs.map +1 -0
- package/dist/{chunk-3HQDMOBK.cjs → chunk-UJLOZYKT.cjs} +680 -636
- package/dist/chunk-UJLOZYKT.cjs.map +1 -0
- package/dist/chunk-UNNPKQUG.cjs +1390 -0
- package/dist/chunk-UNNPKQUG.cjs.map +1 -0
- package/dist/chunk-UR7W5YQK.js +18 -0
- package/dist/chunk-UR7W5YQK.js.map +1 -0
- package/dist/chunk-V3QNTB7Z.js +1351 -0
- package/dist/chunk-V3QNTB7Z.js.map +1 -0
- package/dist/{chunk-XKNAK27R.js → chunk-VCGO4V26.js} +4 -3
- package/dist/chunk-VCGO4V26.js.map +1 -0
- package/dist/{chunk-YQGLVWB2.cjs → chunk-WL2SG7ZV.cjs} +6 -122
- package/dist/chunk-WL2SG7ZV.cjs.map +1 -0
- package/dist/{chunk-WNORITK6.js → chunk-WLRIWYHQ.js} +2041 -2834
- package/dist/chunk-WLRIWYHQ.js.map +1 -0
- package/dist/{chunk-JKRKIEVA.cjs → chunk-WVC2Q2FD.cjs} +128 -6
- package/dist/chunk-WVC2Q2FD.cjs.map +1 -0
- package/dist/chunk-XLUNB2TZ.js +53 -0
- package/dist/chunk-XLUNB2TZ.js.map +1 -0
- package/dist/chunk-XXVEULWX.js +39 -0
- package/dist/chunk-XXVEULWX.js.map +1 -0
- package/dist/chunk-YAZE7QZR.cjs +32 -0
- package/dist/chunk-YAZE7QZR.cjs.map +1 -0
- package/dist/chunk-YC6PWTHY.cjs +44 -0
- package/dist/chunk-YC6PWTHY.cjs.map +1 -0
- package/dist/chunk-Z5HBYM7U.cjs +11 -0
- package/dist/chunk-Z5HBYM7U.cjs.map +1 -0
- package/dist/{chunk-454I6GDF.js → chunk-Z5XBMDXU.js} +63 -3
- package/dist/chunk-Z5XBMDXU.js.map +1 -0
- package/dist/{chunk-CAMMC3E4.cjs → chunk-ZP5WHI4C.cjs} +109 -81
- package/dist/chunk-ZP5WHI4C.cjs.map +1 -0
- package/dist/{chunk-YCV72E6L.js → chunk-ZURTTSCM.js} +4 -25
- package/dist/chunk-ZURTTSCM.js.map +1 -0
- package/dist/{chunk-7WW3WL6E.js → chunk-ZV5N4DBG.js} +49 -21
- package/dist/chunk-ZV5N4DBG.js.map +1 -0
- package/dist/chunk-ZY4GXIVN.cjs +32 -0
- package/dist/chunk-ZY4GXIVN.cjs.map +1 -0
- package/dist/{ddl-C8e8zDAE.d.ts → ddl-BrmPg61z.d.ts} +3 -3
- package/dist/{ddl-CwyG4HoQ.d.cts → ddl-j1-sH6lE.d.cts} +3 -3
- package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
- package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
- package/dist/graph-extension/index.cjs +18 -17
- package/dist/graph-extension/index.d.cts +4 -4
- package/dist/graph-extension/index.d.ts +4 -4
- package/dist/graph-extension/index.js +3 -2
- package/dist/graph-merge/index.cjs +295 -146
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +6 -6
- package/dist/graph-merge/index.d.ts +6 -6
- package/dist/graph-merge/index.js +173 -24
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
- package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
- package/dist/index.cjs +206 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -55
- package/dist/index.d.ts +25 -55
- package/dist/index.js +32 -22
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +28 -25
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +10 -7
- package/dist/interchange/index.cjs +25 -16
- package/dist/interchange/index.d.cts +5 -5
- package/dist/interchange/index.d.ts +5 -5
- package/dist/interchange/index.js +12 -3
- package/dist/{manager-8htmuGr-.d.ts → manager-BZUeN_BU.d.ts} +2 -2
- package/dist/{manager-aVgxbGt-.d.cts → manager-ms9cKdc6.d.cts} +2 -2
- package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
- package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
- package/dist/{postgres-Dhom7iiX.d.ts → postgres-BhpxGMC5.d.cts} +2651 -596
- package/dist/{postgres-jgXmD45C.d.cts → postgres-CWHLwNl1.d.ts} +2651 -596
- package/dist/profiler/index.cjs +5 -4
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/profiler/index.js +3 -2
- package/dist/profiler/index.js.map +1 -1
- package/dist/provenance/index.cjs +591 -0
- package/dist/provenance/index.cjs.map +1 -0
- package/dist/provenance/index.d.cts +73 -0
- package/dist/provenance/index.d.ts +73 -0
- package/dist/provenance/index.js +589 -0
- package/dist/provenance/index.js.map +1 -0
- package/dist/schema/index.cjs +37 -32
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +14 -9
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-DcQ_BCUW.d.cts → sqlite-CGu5SLsw.d.ts} +2726 -455
- package/dist/{sqlite-BfLsCEqO.d.ts → sqlite-XrDxNaa7.d.cts} +2726 -455
- package/dist/{store-view-pBOUrQte.d.ts → store-view-BlgnhEYf.d.ts} +467 -131
- package/dist/{store-view-lTcb_cnp.d.cts → store-view-D09po4H6.d.cts} +467 -131
- package/dist/{types-DGDiXAYc.d.ts → types-B1TbZJYS.d.ts} +2 -2
- package/dist/{types-Dk8r09KY.d.ts → types-D1Sqeyxy.d.ts} +161 -26
- package/dist/{types-5RQwzWXx.d.cts → types-DiE1AO7p.d.cts} +2 -2
- package/dist/{types-Dvmn-eal.d.cts → types-DkNnF-7K.d.cts} +161 -26
- package/dist/{where-Cx_glEEB.d.cts → where-DKjuofPr.d.cts} +2 -2
- package/dist/{where-CHZFELX0.d.ts → where-DrUIIWHb.d.ts} +2 -2
- package/package.json +8 -2
- package/dist/chunk-2BVHPOIG.js.map +0 -1
- package/dist/chunk-2LAT5BIK.cjs.map +0 -1
- package/dist/chunk-2YMGNYXY.js +0 -40
- package/dist/chunk-2YMGNYXY.js.map +0 -1
- package/dist/chunk-3HQDMOBK.cjs.map +0 -1
- package/dist/chunk-454I6GDF.js.map +0 -1
- package/dist/chunk-6G35I3VW.cjs +0 -40
- package/dist/chunk-6G35I3VW.cjs.map +0 -1
- package/dist/chunk-6RMLO5O4.cjs.map +0 -1
- package/dist/chunk-6ZR4QC3O.cjs +0 -12
- package/dist/chunk-73KASJGO.cjs.map +0 -1
- package/dist/chunk-7WW3WL6E.js.map +0 -1
- package/dist/chunk-C4C4Q7A6.js.map +0 -1
- package/dist/chunk-CAMMC3E4.cjs.map +0 -1
- package/dist/chunk-CEF2QOTO.js.map +0 -1
- package/dist/chunk-CFNT3ITG.cjs.map +0 -1
- package/dist/chunk-EEYV6UOE.cjs.map +0 -1
- package/dist/chunk-FDN43KXV.cjs.map +0 -1
- package/dist/chunk-HFBRAOF7.js.map +0 -1
- package/dist/chunk-IJORSAC3.js.map +0 -1
- package/dist/chunk-JKRKIEVA.cjs.map +0 -1
- package/dist/chunk-KTIEB7VH.cjs.map +0 -1
- package/dist/chunk-LAZGHOZW.cjs.map +0 -1
- package/dist/chunk-LM2IC4ZJ.cjs.map +0 -1
- package/dist/chunk-M6OC455F.js +0 -65
- package/dist/chunk-M6OC455F.js.map +0 -1
- package/dist/chunk-MXE2U3EX.js.map +0 -1
- package/dist/chunk-NDM5PXEH.js.map +0 -1
- package/dist/chunk-PRMKPFN5.js.map +0 -1
- package/dist/chunk-RP7YITHX.cjs +0 -70
- package/dist/chunk-RP7YITHX.cjs.map +0 -1
- package/dist/chunk-SAJSMR2B.js +0 -35
- package/dist/chunk-SAJSMR2B.js.map +0 -1
- package/dist/chunk-SB65GJNY.cjs.map +0 -1
- package/dist/chunk-TUA3MEJJ.js.map +0 -1
- package/dist/chunk-W4ZX2GCP.js.map +0 -1
- package/dist/chunk-WNORITK6.js.map +0 -1
- package/dist/chunk-XKNAK27R.js.map +0 -1
- package/dist/chunk-XQFAJVYW.js.map +0 -1
- package/dist/chunk-YCV72E6L.js.map +0 -1
- package/dist/chunk-YL4F3CMD.cjs.map +0 -1
- package/dist/chunk-YQGLVWB2.cjs.map +0 -1
- package/dist/chunk-YW7GHMF4.cjs.map +0 -1
- package/dist/chunk-ZFWNO3GE.cjs.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FNV1A_OFFSET_BASIS, FNV1A_PRIME } from './chunk-2EBMPJBO.js';
|
|
2
|
+
|
|
3
|
+
// src/utils/hash.ts
|
|
4
|
+
function fnv1aBase36(input) {
|
|
5
|
+
let hash = FNV1A_OFFSET_BASIS;
|
|
6
|
+
for (const character of input) {
|
|
7
|
+
const codePoint = character.codePointAt(0);
|
|
8
|
+
if (codePoint === void 0) continue;
|
|
9
|
+
hash ^= codePoint;
|
|
10
|
+
hash = Math.imul(hash, FNV1A_PRIME);
|
|
11
|
+
}
|
|
12
|
+
return (hash >>> 0).toString(36);
|
|
13
|
+
}
|
|
14
|
+
async function sha256Hex(input, byteLength = 8) {
|
|
15
|
+
const encoded = new TextEncoder().encode(input);
|
|
16
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", encoded);
|
|
17
|
+
const bytes = new Uint8Array(digest);
|
|
18
|
+
let hex = "";
|
|
19
|
+
for (let index = 0; index < byteLength; index++) {
|
|
20
|
+
const byte = bytes[index];
|
|
21
|
+
if (byte === void 0) break;
|
|
22
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
23
|
+
}
|
|
24
|
+
return hex;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { fnv1aBase36, sha256Hex };
|
|
28
|
+
//# sourceMappingURL=chunk-K34OPSJK.js.map
|
|
29
|
+
//# sourceMappingURL=chunk-K34OPSJK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/hash.ts"],"names":[],"mappings":";;;AAWO,SAAS,YAAY,KAAA,EAAuB;AACjD,EAAA,IAAI,IAAA,GAAO,kBAAA;AACX,EAAA,KAAA,MAAW,aAAa,KAAA,EAAO;AAC7B,IAAA,MAAM,SAAA,GAAY,SAAA,CAAU,WAAA,CAAY,CAAC,CAAA;AACzC,IAAA,IAAI,cAAc,MAAA,EAAW;AAC7B,IAAA,IAAA,IAAQ,SAAA;AACR,IAAA,IAAA,GAAO,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,WAAW,CAAA;AAAA,EACpC;AACA,EAAA,OAAA,CAAQ,IAAA,KAAS,CAAA,EAAG,QAAA,CAAS,EAAE,CAAA;AACjC;AAWA,eAAsB,SAAA,CACpB,KAAA,EACA,UAAA,GAAa,CAAA,EACI;AACjB,EAAA,MAAM,OAAA,GAAU,IAAI,WAAA,EAAY,CAAE,OAAO,KAAK,CAAA;AAC9C,EAAA,MAAM,SAAS,MAAM,UAAA,CAAW,OAAO,MAAA,CAAO,MAAA,CAAO,WAAW,OAAO,CAAA;AACvE,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,MAAM,CAAA;AACnC,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,UAAA,EAAY,KAAA,EAAA,EAAS;AAC/C,IAAA,MAAM,IAAA,GAAO,MAAM,KAAK,CAAA;AACxB,IAAA,IAAI,SAAS,MAAA,EAAW;AACxB,IAAA,GAAA,IAAO,KAAK,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAA;AAAA,EAC1C;AACA,EAAA,OAAO,GAAA;AACT","file":"chunk-K34OPSJK.js","sourcesContent":["/**\n * Hash utilities — FNV-1a for fast non-cryptographic identifier\n * generation, SHA-256 (truncated) for collision-resistant signatures.\n */\nimport { FNV1A_OFFSET_BASIS, FNV1A_PRIME } from \"../constants\";\n\n/**\n * FNV-1a hash of `input`, returned as a base-36 encoded string. Used for\n * generating short, deterministic identifiers (column aliases, index\n * name suffixes, etc.).\n */\nexport function fnv1aBase36(input: string): string {\n let hash = FNV1A_OFFSET_BASIS;\n for (const character of input) {\n const codePoint = character.codePointAt(0);\n if (codePoint === undefined) continue;\n hash ^= codePoint;\n hash = Math.imul(hash, FNV1A_PRIME);\n }\n return (hash >>> 0).toString(36);\n}\n\n/**\n * Hex-truncated SHA-256 of `input` via the Web Crypto API. Works in\n * Node.js 16+, Cloudflare Workers, Deno, and browsers.\n *\n * `byteLength` controls how many bytes of the digest are emitted —\n * default 8 (16 hex chars, ~64 bits, sufficient for schema-version and\n * per-graph index signatures). Pass 16 (32 hex chars) when hashes are\n * compared against externally-stored signatures.\n */\nexport async function sha256Hex(\n input: string,\n byteLength = 8,\n): Promise<string> {\n const encoded = new TextEncoder().encode(input);\n const digest = await globalThis.crypto.subtle.digest(\"SHA-256\", encoded);\n const bytes = new Uint8Array(digest);\n let hex = \"\";\n for (let index = 0; index < byteLength; index++) {\n const byte = bytes[index];\n if (byte === undefined) break;\n hex += byte.toString(16).padStart(2, \"0\");\n }\n return hex;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk2JXB3NYJ_cjs = require('./chunk-2JXB3NYJ.cjs');
|
|
4
|
+
var chunkYAZE7QZR_cjs = require('./chunk-YAZE7QZR.cjs');
|
|
4
5
|
var drizzleOrm = require('drizzle-orm');
|
|
5
6
|
var pgCore = require('drizzle-orm/pg-core');
|
|
6
7
|
|
|
@@ -72,7 +73,7 @@ function operatorClass(metric) {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
function vectorLiteral(embedding, name) {
|
|
75
|
-
|
|
76
|
+
chunk2JXB3NYJ_cjs.assertFiniteEmbedding(embedding, name);
|
|
76
77
|
return drizzleOrm.sql`${formatVector(embedding)}::vector`;
|
|
77
78
|
}
|
|
78
79
|
function distanceExpression(embeddingColumn, queryEmbedding, metric) {
|
|
@@ -97,11 +98,11 @@ var pgvectorStrategy = {
|
|
|
97
98
|
name: "pgvector",
|
|
98
99
|
capabilities: PGVECTOR_CAPABILITIES,
|
|
99
100
|
tableName(graphId, nodeKind, fieldPath) {
|
|
100
|
-
return
|
|
101
|
+
return chunk2JXB3NYJ_cjs.vectorPhysicalName(TABLE_PREFIX, graphId, nodeKind, fieldPath);
|
|
101
102
|
},
|
|
102
103
|
ownedTables(slot) {
|
|
103
104
|
const table = this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath);
|
|
104
|
-
const name =
|
|
105
|
+
const name = chunk2JXB3NYJ_cjs.quoteIdentifier(table);
|
|
105
106
|
const createDdl = [
|
|
106
107
|
`CREATE TABLE IF NOT EXISTS ${name} (
|
|
107
108
|
"graph_id" TEXT NOT NULL,
|
|
@@ -114,7 +115,7 @@ var pgvectorStrategy = {
|
|
|
114
115
|
];
|
|
115
116
|
return [
|
|
116
117
|
{
|
|
117
|
-
logicalName: `${
|
|
118
|
+
logicalName: `${chunk2JXB3NYJ_cjs.VECTOR_CONTRIBUTION_PREFIX}:${slot.nodeKind}.${slot.fieldPath}`,
|
|
118
119
|
owner: "pgvector",
|
|
119
120
|
tableName: table,
|
|
120
121
|
createDdl,
|
|
@@ -123,7 +124,7 @@ var pgvectorStrategy = {
|
|
|
123
124
|
];
|
|
124
125
|
},
|
|
125
126
|
buildUpsert(slot, params, timestamp) {
|
|
126
|
-
const table =
|
|
127
|
+
const table = chunkYAZE7QZR_cjs.quotedTableName(
|
|
127
128
|
this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath)
|
|
128
129
|
);
|
|
129
130
|
const value = vectorLiteral(params.embedding, "embedding");
|
|
@@ -137,7 +138,7 @@ var pgvectorStrategy = {
|
|
|
137
138
|
];
|
|
138
139
|
},
|
|
139
140
|
buildDelete(slot, params) {
|
|
140
|
-
const table =
|
|
141
|
+
const table = chunkYAZE7QZR_cjs.quotedTableName(
|
|
141
142
|
this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath)
|
|
142
143
|
);
|
|
143
144
|
return [
|
|
@@ -148,7 +149,7 @@ var pgvectorStrategy = {
|
|
|
148
149
|
];
|
|
149
150
|
},
|
|
150
151
|
buildSearch(slot, params) {
|
|
151
|
-
const table =
|
|
152
|
+
const table = chunkYAZE7QZR_cjs.quotedTableName(
|
|
152
153
|
this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath)
|
|
153
154
|
);
|
|
154
155
|
const embeddingColumn = drizzleOrm.sql`${table}."embedding"`;
|
|
@@ -157,11 +158,11 @@ var pgvectorStrategy = {
|
|
|
157
158
|
params.queryEmbedding,
|
|
158
159
|
params.metric
|
|
159
160
|
);
|
|
160
|
-
const score =
|
|
161
|
+
const score = chunk2JXB3NYJ_cjs.vectorScoreExpression(distance, params.metric);
|
|
161
162
|
const conditions = [drizzleOrm.sql`${table}."graph_id" = ${params.graphId}`];
|
|
162
163
|
if (params.minScore !== void 0) {
|
|
163
164
|
conditions.push(
|
|
164
|
-
|
|
165
|
+
chunk2JXB3NYJ_cjs.vectorMinScoreCondition(distance, params.metric, params.minScore)
|
|
165
166
|
);
|
|
166
167
|
}
|
|
167
168
|
return drizzleOrm.sql`
|
|
@@ -188,17 +189,17 @@ var pgvectorStrategy = {
|
|
|
188
189
|
buildDropIndex(slot) {
|
|
189
190
|
if (!usesAnnIndex(slot)) return void 0;
|
|
190
191
|
const indexName = pgvectorIndexName(slot);
|
|
191
|
-
return drizzleOrm.sql.raw(`DROP INDEX IF EXISTS ${
|
|
192
|
+
return drizzleOrm.sql.raw(`DROP INDEX IF EXISTS ${chunk2JXB3NYJ_cjs.quoteIdentifier(indexName)}`);
|
|
192
193
|
},
|
|
193
194
|
buildDropStorage(slot) {
|
|
194
|
-
const table =
|
|
195
|
+
const table = chunk2JXB3NYJ_cjs.quoteIdentifier(
|
|
195
196
|
this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath)
|
|
196
197
|
);
|
|
197
198
|
return [`DROP TABLE IF EXISTS ${table} CASCADE`];
|
|
198
199
|
}
|
|
199
200
|
};
|
|
200
201
|
function pgvectorIndexName(slot) {
|
|
201
|
-
return
|
|
202
|
+
return chunk2JXB3NYJ_cjs.vectorPhysicalName(
|
|
202
203
|
INDEX_PREFIX,
|
|
203
204
|
slot.graphId,
|
|
204
205
|
slot.nodeKind,
|
|
@@ -206,8 +207,8 @@ function pgvectorIndexName(slot) {
|
|
|
206
207
|
);
|
|
207
208
|
}
|
|
208
209
|
function pgvectorIndexDdl(table, slot, concurrent) {
|
|
209
|
-
const indexName =
|
|
210
|
-
const quotedTable =
|
|
210
|
+
const indexName = chunk2JXB3NYJ_cjs.quoteIdentifier(pgvectorIndexName(slot));
|
|
211
|
+
const quotedTable = chunk2JXB3NYJ_cjs.quoteIdentifier(table);
|
|
211
212
|
const opClass = operatorClass(slot.metric);
|
|
212
213
|
const m = slot.indexParams?.m ?? DEFAULT_HNSW_M;
|
|
213
214
|
const efConstruction = slot.indexParams?.efConstruction ?? DEFAULT_HNSW_EF_CONSTRUCTION;
|
|
@@ -234,5 +235,5 @@ function pgvectorIndexDdl(table, slot, concurrent) {
|
|
|
234
235
|
|
|
235
236
|
exports.assertPgvectorEfSearch = assertPgvectorEfSearch;
|
|
236
237
|
exports.pgvectorStrategy = pgvectorStrategy;
|
|
237
|
-
//# sourceMappingURL=chunk-
|
|
238
|
-
//# sourceMappingURL=chunk-
|
|
238
|
+
//# sourceMappingURL=chunk-KGC4LY5T.cjs.map
|
|
239
|
+
//# sourceMappingURL=chunk-KGC4LY5T.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/drizzle/columns/vector.ts","../src/query/dialect/vector/pgvector-strategy.ts"],"names":["customType","assertFiniteEmbedding","sql","vectorPhysicalName","quoteIdentifier","VECTOR_CONTRIBUTION_PREFIX","quotedTableName","vectorScoreExpression","vectorMinScoreCondition"],"mappings":";;;;;;;AA0CsBA,iBAAA,CAInB;AAAA,EACD,SAAS,MAAA,EAAQ;AAEf,I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,IAAA,CAAK,MAAM,CAAA;AAEzC,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,WAAA,EAAa,CAAA,IAAK,cAAA;AACjC,EAAA,MAAM,cAAA,GACJ,IAAA,CAAK,WAAA,EAAa,cAAA,IAAkB,4BAAA;AACtC,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,WAAA,EAAa,KAAA,IAAS,qBAAA;AAGzC,EAAA,MAAM,MAAA,GAAS,CAAA,YAAA,EAAe,UAAA,GAAa,eAAA,GAAkB,EAAE,CAAA,cAAA,CAAA;AAE/D,EAAA,QAAQ,KAAK,SAAA;AAAW,IACtB,KAAK,MAAA,EAAQ;AACX,MAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,SAAS,CAAA,IAAA,EAAO,WAAW,CAAA,yBAAA,EAA4B,OAAO,CAAA,YAAA,EAAe,CAAC,CAAA,oBAAA,EAAuB,cAAc,CAAA,EAAA,CAAA;AAAA,IACzI;AAAA,IACA,KAAK,SAAA,EAAW;AACd,MAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,SAAS,OAAO,WAAW,CAAA,4BAAA,EAA+B,OAAO,CAAA,gBAAA,EAAmB,KAAK,CAAA,EAAA,CAAA;AAAA,IAC/G;AAAA,IACA,KAAK,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,MAAA,MAAM,cAAqB,IAAA,CAAK,SAAA;AAChC,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,+BAAA,EAAkC,MAAA,CAAO,WAAW,CAAC,CAAA,CAAE,CAAA;AAAA,IACzE;AAAA;AAEJ","file":"chunk-KGC4LY5T.cjs","sourcesContent":["/**\n * Custom Drizzle column type for pgvector's VECTOR type.\n *\n * Provides native support for PostgreSQL vector embeddings without\n * requiring runtime casts in queries.\n *\n * @example\n * ```typescript\n * import { pgTable, text, integer } from \"drizzle-orm/pg-core\";\n * import { vector } from \"./columns/vector\";\n *\n * const embeddings = pgTable(\"embeddings\", {\n * id: text(\"id\").primaryKey(),\n * embedding: vector(\"embedding\"),\n * dimensions: integer(\"dimensions\"),\n * });\n * ```\n */\nimport { customType } from \"drizzle-orm/pg-core\";\n\n/**\n * PostgreSQL vector column type for pgvector extension.\n *\n * Stores embeddings as native VECTOR type, enabling efficient\n * similarity search without runtime casts.\n *\n * The column type is unparameterized (`VECTOR` not `VECTOR(N)`)\n * to support multiple embedding dimensions in a single table.\n * Dimension validation is handled at the application level.\n *\n * @example\n * ```typescript\n * // In table definition\n * embedding: vector(\"embedding\").notNull(),\n *\n * // In queries - no cast needed\n * db.execute(sql`\n * SELECT * FROM embeddings\n * WHERE embedding <=> ${formatVector([0.1, 0.2, 0.3])} < 0.5\n * `);\n * ```\n */\nexport const vector = customType<{\n data: number[];\n driverData: string;\n config: { dimensions?: number };\n}>({\n dataType(config) {\n // Use parameterized type if dimensions specified, otherwise unparameterized\n return config?.dimensions ? `vector(${config.dimensions})` : \"vector\";\n },\n\n toDriver(value: number[]): string {\n // Format as pgvector literal: [1.0,2.0,3.0]\n return `[${value.join(\",\")}]`;\n },\n\n fromDriver(value: string): number[] {\n // pgvector returns '[1,2,3]' format\n // Handle both string and already-parsed array (some drivers differ)\n if (Array.isArray(value)) {\n return value as number[];\n }\n // Parse the string representation\n const content = value.slice(1, -1); // Remove [ and ]\n if (content === \"\") {\n return [];\n }\n return content.split(\",\").map((s) => Number.parseFloat(s.trim()));\n },\n});\n\n/**\n * Formats a number array as a pgvector literal string.\n *\n * Use this when building raw SQL queries with embeddings.\n *\n * @example\n * ```typescript\n * const embedding = [0.1, 0.2, 0.3];\n * db.execute(sql`\n * SELECT * FROM embeddings\n * WHERE embedding <=> ${formatVector(embedding)}::vector < 0.5\n * `);\n * ```\n */\nexport function formatVector(embedding: readonly number[]): string {\n return `[${embedding.join(\",\")}]`;\n}\n","/**\n * pgvector strategy.\n *\n * Postgres' pgvector extension is the one engine where the *same* SQL serves\n * brute-force and ANN: `ORDER BY embedding <=> q LIMIT k` scans sequentially\n * with no index and is rewritten to an HNSW/IVFFlat scan the moment a matching\n * index exists — the planner picks it up automatically. So `buildSearch` never\n * branches on `slot.indexType`; it emits one relevance scan and lets Postgres\n * decide. (Contrast libSQL/sqlite-vec, whose ANN needs distinct syntax.)\n *\n * Storage is per-`(nodeKind, fieldPath)`: a `vector(N)` column carrying the\n * field's fixed dimension `N`, with the operator-class-typed ANN index folded\n * into the same table contribution so materialization builds table + index\n * together. The typed column means the index does not need the legacy\n * `::vector(N)` cast-in-index escape hatch the old shared table relied on.\n *\n * Metric support is the full pgvector set — `cosine`, `l2`, `inner_product` —\n * advertised as data on `capabilities`, mirroring `vector_cosine_ops` /\n * `vector_l2_ops` / `vector_ip_ops` and the `<=>` / `<->` / `<#>` operators.\n *\n * Mirrors the `libsqlVectorStrategy` / `sqliteVecStrategy` structure while\n * letting Postgres' planner pick the ANN index when one exists.\n */\nimport { type SQL, sql } from \"drizzle-orm\";\n\nimport { formatVector } from \"../../../backend/drizzle/columns/vector\";\nimport { quotedTableName } from \"../../../backend/drizzle/operations/shared\";\nimport { type StrategyTableContribution } from \"../../../backend/table-contribution\";\nimport {\n type DeleteEmbeddingParams,\n type UpsertEmbeddingParams,\n type VectorCapabilities,\n type VectorMetric,\n type VectorSearchParams,\n} from \"../../../backend/types\";\nimport {\n assertFiniteEmbedding,\n quoteIdentifier,\n VECTOR_CONTRIBUTION_PREFIX,\n vectorMinScoreCondition,\n vectorPhysicalName,\n vectorScoreExpression,\n type VectorSlot,\n type VectorStrategy,\n} from \"../vector-strategy\";\n\n/** Physical-name prefixes for the per-field table and its ANN index. */\nconst TABLE_PREFIX = \"tg_vec\";\nconst INDEX_PREFIX = \"tg_vecidx\";\n\n/**\n * pgvector defines `hnsw.ef_search` as an integer GUC with a valid range\n * of 1..1000; `SET hnsw.ef_search = 1001` errors at the server. The\n * backend validates a per-search `efSearch` against this ceiling before\n * inlining it into `SET LOCAL`, surfacing a clear message instead of a raw\n * pgvector error.\n */\nexport const MAX_HNSW_EF_SEARCH = 1000;\n\n/**\n * Validates a per-search `efSearch` override against pgvector's\n * `hnsw.ef_search` valid range. `undefined` (no override) is accepted.\n */\nexport function assertPgvectorEfSearch(efSearch?: number): void {\n if (efSearch === undefined) return;\n if (!Number.isInteger(efSearch) || efSearch <= 0) {\n throw new Error(`efSearch must be a positive integer, got: ${efSearch}`);\n }\n if (efSearch > MAX_HNSW_EF_SEARCH) {\n throw new RangeError(\n `efSearch must be ≤ ${MAX_HNSW_EF_SEARCH} (pgvector's hnsw.ef_search ` +\n `valid range is 1..${MAX_HNSW_EF_SEARCH}), got: ${efSearch}`,\n );\n }\n}\n\n/**\n * pgvector's `vector` type caps at 16,000 dimensions for a stored column\n * (2,000 for an indexed column, but the column-type ceiling is what governs\n * storage; recall degradation beyond 2,000 is a tuning concern, not a hard\n * limit advertised here).\n */\nconst PGVECTOR_MAX_DIMENSIONS = 16_000;\n\n/** Default HNSW `m` (max connections per layer) — pgvector's own default. */\nconst DEFAULT_HNSW_M = 16;\n/** Default HNSW `ef_construction` (build candidate list) — pgvector's own default. */\nconst DEFAULT_HNSW_EF_CONSTRUCTION = 64;\n/** Default IVFFlat `lists` (inverted lists) — pgvector's own default. */\nconst DEFAULT_IVFFLAT_LISTS = 100;\n\nconst PGVECTOR_CAPABILITIES: VectorCapabilities = {\n supported: true,\n metrics: [\"cosine\", \"l2\", \"inner_product\"],\n indexTypes: [\"hnsw\", \"ivfflat\", \"none\"],\n maxDimensions: PGVECTOR_MAX_DIMENSIONS,\n};\n\n/** Whether a slot's declared index type materializes a real pgvector ANN index. */\nfunction usesAnnIndex(slot: VectorSlot): boolean {\n return slot.indexType === \"hnsw\" || slot.indexType === \"ivfflat\";\n}\n\n/**\n * pgvector operator class for a metric's ANN index — `vector_cosine_ops` /\n * `vector_l2_ops` / `vector_ip_ops`, mirroring the `<=>` / `<->` / `<#>`\n * distance operators this strategy emits.\n */\nfunction operatorClass(metric: VectorMetric): string {\n switch (metric) {\n case \"cosine\": {\n return \"vector_cosine_ops\";\n }\n case \"l2\": {\n return \"vector_l2_ops\";\n }\n case \"inner_product\": {\n return \"vector_ip_ops\";\n }\n default: {\n const _exhaustive: never = metric;\n throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);\n }\n }\n}\n\n/**\n * Formats an embedding as a `::vector` literal. The value is bound as a\n * parameter (not interpolated) — Postgres parses the `[a,b,c]` text and the\n * cast types it. Finiteness is validated first so a NaN names its index.\n */\nfunction vectorLiteral(embedding: readonly number[], name: string): SQL {\n assertFiniteEmbedding(embedding, name);\n return sql`${formatVector(embedding)}::vector`;\n}\n\nfunction distanceExpression(\n embeddingColumn: SQL,\n queryEmbedding: readonly number[],\n metric: VectorMetric,\n): SQL {\n const query = vectorLiteral(queryEmbedding, \"queryEmbedding\");\n switch (metric) {\n case \"cosine\": {\n return sql`(${embeddingColumn} <=> ${query})`;\n }\n case \"l2\": {\n return sql`(${embeddingColumn} <-> ${query})`;\n }\n case \"inner_product\": {\n return sql`(${embeddingColumn} <#> ${query})`;\n }\n default: {\n const _exhaustive: never = metric;\n throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);\n }\n }\n}\n\nexport const pgvectorStrategy: VectorStrategy = {\n name: \"pgvector\",\n capabilities: PGVECTOR_CAPABILITIES,\n\n tableName(graphId, nodeKind, fieldPath) {\n return vectorPhysicalName(TABLE_PREFIX, graphId, nodeKind, fieldPath);\n },\n\n ownedTables(slot): readonly StrategyTableContribution[] {\n const table = this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath);\n const name = quoteIdentifier(table);\n\n // No standalone graph_id index: the PRIMARY KEY (graph_id, node_id) already\n // covers `WHERE graph_id = ?` via its leading column, so a separate index\n // would be pure write amplification.\n const createDdl = [\n `CREATE TABLE IF NOT EXISTS ${name} (\n \"graph_id\" TEXT NOT NULL,\n \"node_id\" TEXT NOT NULL,\n \"embedding\" vector(${slot.dimensions}) NOT NULL,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ NOT NULL,\n PRIMARY KEY (\"graph_id\", \"node_id\")\n);`,\n ];\n\n // The HNSW/IVFFlat index is intentionally NOT created here. pgvector\n // similarity SQL is planner-driven (`ORDER BY embedding <=> q LIMIT k`\n // uses the index when present, sequential-scans when not), so the index\n // is a pure materialization concern: `buildCreateIndex` builds it through\n // `materializeIndexes()` with the field's declared `m`/`ef_construction`/\n // `lists`. Building it eagerly here would bake in default tuning (the\n // write-ensure slot has no `indexParams`) and `CREATE INDEX IF NOT EXISTS`\n // would then mask the tuned index materialization would emit.\n\n return [\n {\n logicalName: `${VECTOR_CONTRIBUTION_PREFIX}:${slot.nodeKind}.${slot.fieldPath}`,\n owner: \"pgvector\",\n tableName: table,\n createDdl,\n runtimeEnsure: true,\n },\n ];\n },\n\n buildUpsert(slot, params: UpsertEmbeddingParams, timestamp): readonly SQL[] {\n const table = quotedTableName(\n this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath),\n );\n const value = vectorLiteral(params.embedding, \"embedding\");\n return [\n sql`\n INSERT INTO ${table} (\"graph_id\", \"node_id\", \"embedding\", \"created_at\", \"updated_at\")\n VALUES (${params.graphId}, ${params.nodeId}, ${value}, ${timestamp}, ${timestamp})\n ON CONFLICT (\"graph_id\", \"node_id\")\n DO UPDATE SET \"embedding\" = EXCLUDED.\"embedding\", \"updated_at\" = EXCLUDED.\"updated_at\"\n `,\n ];\n },\n\n buildDelete(slot, params: DeleteEmbeddingParams): readonly SQL[] {\n const table = quotedTableName(\n this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath),\n );\n return [\n sql`\n DELETE FROM ${table}\n WHERE \"graph_id\" = ${params.graphId} AND \"node_id\" = ${params.nodeId}\n `,\n ];\n },\n\n buildSearch(slot, params: VectorSearchParams): SQL {\n const table = quotedTableName(\n this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath),\n );\n const embeddingColumn = sql`${table}.\"embedding\"`;\n const distance = distanceExpression(\n embeddingColumn,\n params.queryEmbedding,\n params.metric,\n );\n const score = vectorScoreExpression(distance, params.metric);\n\n // Same SQL for brute-force and ANN: with a matching HNSW/IVFFlat index the\n // Postgres planner rewrites this `ORDER BY distance LIMIT k` into an index\n // scan automatically, so the strategy never branches on `slot.indexType`.\n const conditions: SQL[] = [sql`${table}.\"graph_id\" = ${params.graphId}`];\n if (params.minScore !== undefined) {\n conditions.push(\n vectorMinScoreCondition(distance, params.metric, params.minScore),\n );\n }\n return sql`\n SELECT ${table}.\"node_id\" AS node_id, ${score} AS score\n FROM ${table}\n WHERE ${sql.join(conditions, sql` AND `)}\n ORDER BY ${distance} ASC\n LIMIT ${params.limit}\n `;\n },\n\n distanceExpression(embeddingColumn, queryEmbedding, metric) {\n return distanceExpression(embeddingColumn, queryEmbedding, metric);\n },\n\n buildCreateIndex(slot, options): SQL | undefined {\n if (!usesAnnIndex(slot)) return undefined;\n return sql.raw(\n pgvectorIndexDdl(\n this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath),\n slot,\n options?.concurrent === true,\n ),\n );\n },\n\n buildDropIndex(slot): SQL | undefined {\n if (!usesAnnIndex(slot)) return undefined;\n const indexName = pgvectorIndexName(slot);\n return sql.raw(`DROP INDEX IF EXISTS ${quoteIdentifier(indexName)}`);\n },\n\n buildDropStorage(slot): readonly string[] {\n const table = quoteIdentifier(\n this.tableName(slot.graphId, slot.nodeKind, slot.fieldPath),\n );\n // CASCADE drops the ANN index along with the table.\n return [`DROP TABLE IF EXISTS ${table} CASCADE`];\n },\n};\n\nfunction pgvectorIndexName(slot: VectorSlot): string {\n return vectorPhysicalName(\n INDEX_PREFIX,\n slot.graphId,\n slot.nodeKind,\n slot.fieldPath,\n );\n}\n\nfunction pgvectorIndexDdl(\n table: string,\n slot: VectorSlot,\n concurrent: boolean,\n): string {\n const indexName = quoteIdentifier(pgvectorIndexName(slot));\n const quotedTable = quoteIdentifier(table);\n const opClass = operatorClass(slot.metric);\n // Honor the field's declared tuning; fall back to pgvector defaults.\n const m = slot.indexParams?.m ?? DEFAULT_HNSW_M;\n const efConstruction =\n slot.indexParams?.efConstruction ?? DEFAULT_HNSW_EF_CONSTRUCTION;\n const lists = slot.indexParams?.lists ?? DEFAULT_IVFFLAT_LISTS;\n // CONCURRENTLY builds without taking a write-blocking lock on the live table\n // (materializeIndexes passes concurrent on Postgres). Run outside a tx.\n const create = `CREATE INDEX${concurrent ? \" CONCURRENTLY\" : \"\"} IF NOT EXISTS`;\n\n switch (slot.indexType) {\n case \"hnsw\": {\n return `${create} ${indexName} ON ${quotedTable} USING hnsw (\"embedding\" ${opClass}) WITH (m = ${m}, ef_construction = ${efConstruction});`;\n }\n case \"ivfflat\": {\n return `${create} ${indexName} ON ${quotedTable} USING ivfflat (\"embedding\" ${opClass}) WITH (lists = ${lists});`;\n }\n case \"none\": {\n throw new Error(\n \"pgvectorIndexDdl called for a brute-force-only slot (indexType 'none').\",\n );\n }\n default: {\n const _exhaustive: never = slot.indexType;\n throw new Error(`Unsupported vector index type: ${String(_exhaustive)}`);\n }\n }\n}\n"]}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN6WTUSBV_cjs = require('./chunk-N6WTUSBV.cjs');
|
|
4
|
+
var chunkT6SPUYLX_cjs = require('./chunk-T6SPUYLX.cjs');
|
|
5
|
+
var chunk5IQIX7LU_cjs = require('./chunk-5IQIX7LU.cjs');
|
|
6
|
+
var chunkUNNPKQUG_cjs = require('./chunk-UNNPKQUG.cjs');
|
|
7
|
+
var chunkYC6PWTHY_cjs = require('./chunk-YC6PWTHY.cjs');
|
|
8
|
+
var chunkJIEJCTDS_cjs = require('./chunk-JIEJCTDS.cjs');
|
|
4
9
|
var zod = require('zod');
|
|
5
10
|
|
|
6
11
|
var FORMAT_VERSION = "1.0";
|
|
7
|
-
var ValidityTimestampSchema = zod.z.iso.datetime().refine((value) =>
|
|
12
|
+
var ValidityTimestampSchema = zod.z.iso.datetime().refine((value) => chunkYC6PWTHY_cjs.isCanonicalIsoDate(value), {
|
|
8
13
|
message: "Expected canonical UTC ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ); convert with new Date(value).toISOString()."
|
|
9
14
|
});
|
|
10
15
|
var InterchangeNodeSchema = zod.z.object({
|
|
@@ -117,8 +122,8 @@ async function exportGraph(store, options) {
|
|
|
117
122
|
const graph = store.graph;
|
|
118
123
|
const graphId = store.graphId;
|
|
119
124
|
const backend = store.backend;
|
|
120
|
-
const nodeKindsToExport = options_.nodeKinds ??
|
|
121
|
-
const edgeKindsToExport = options_.edgeKinds ??
|
|
125
|
+
const nodeKindsToExport = options_.nodeKinds ?? chunkT6SPUYLX_cjs.getNodeKinds(graph);
|
|
126
|
+
const edgeKindsToExport = options_.edgeKinds ?? chunkT6SPUYLX_cjs.getEdgeKinds(graph);
|
|
122
127
|
const nodes = [];
|
|
123
128
|
for (const kind of nodeKindsToExport) {
|
|
124
129
|
const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);
|
|
@@ -132,7 +137,7 @@ async function exportGraph(store, options) {
|
|
|
132
137
|
const schemaVersion = await backend.getActiveSchema(graphId);
|
|
133
138
|
return {
|
|
134
139
|
formatVersion: FORMAT_VERSION,
|
|
135
|
-
exportedAt:
|
|
140
|
+
exportedAt: chunkYC6PWTHY_cjs.nowIso(),
|
|
136
141
|
source: {
|
|
137
142
|
type: "typegraph-export",
|
|
138
143
|
graphId,
|
|
@@ -222,47 +227,27 @@ async function importGraph(store, data, options) {
|
|
|
222
227
|
const graph = store.graph;
|
|
223
228
|
const graphId = store.graphId;
|
|
224
229
|
const backend = store.backend;
|
|
230
|
+
const registry = store.registry;
|
|
225
231
|
const nodeSchemas = buildNodeSchemaMap(graph);
|
|
226
232
|
const edgeSchemas = buildEdgeSchemaMap(graph);
|
|
227
233
|
const importedNodeIds = /* @__PURE__ */ new Set();
|
|
228
|
-
|
|
229
|
-
await backend.transaction(async (tx) => {
|
|
230
|
-
await processNodes(
|
|
231
|
-
tx,
|
|
232
|
-
graphId,
|
|
233
|
-
data.nodes,
|
|
234
|
-
nodeSchemas,
|
|
235
|
-
options,
|
|
236
|
-
result,
|
|
237
|
-
errors,
|
|
238
|
-
importedNodeIds
|
|
239
|
-
);
|
|
240
|
-
await processEdges(
|
|
241
|
-
tx,
|
|
242
|
-
graphId,
|
|
243
|
-
data.edges,
|
|
244
|
-
edgeSchemas,
|
|
245
|
-
nodeSchemas,
|
|
246
|
-
options,
|
|
247
|
-
result,
|
|
248
|
-
errors,
|
|
249
|
-
importedNodeIds
|
|
250
|
-
);
|
|
251
|
-
});
|
|
252
|
-
} else {
|
|
234
|
+
await chunkN6WTUSBV_cjs.runInWriteTransaction(store, backend, async (target, lock) => {
|
|
253
235
|
await processNodes(
|
|
254
|
-
|
|
236
|
+
target,
|
|
255
237
|
graphId,
|
|
238
|
+
registry,
|
|
256
239
|
data.nodes,
|
|
257
240
|
nodeSchemas,
|
|
258
241
|
options,
|
|
259
242
|
result,
|
|
260
243
|
errors,
|
|
261
|
-
importedNodeIds
|
|
244
|
+
importedNodeIds,
|
|
245
|
+
lock
|
|
262
246
|
);
|
|
263
247
|
await processEdges(
|
|
264
|
-
|
|
248
|
+
target,
|
|
265
249
|
graphId,
|
|
250
|
+
registry,
|
|
266
251
|
data.edges,
|
|
267
252
|
edgeSchemas,
|
|
268
253
|
nodeSchemas,
|
|
@@ -271,7 +256,7 @@ async function importGraph(store, data, options) {
|
|
|
271
256
|
errors,
|
|
272
257
|
importedNodeIds
|
|
273
258
|
);
|
|
274
|
-
}
|
|
259
|
+
});
|
|
275
260
|
return {
|
|
276
261
|
...result,
|
|
277
262
|
success: errors.length === 0,
|
|
@@ -280,7 +265,7 @@ async function importGraph(store, data, options) {
|
|
|
280
265
|
}
|
|
281
266
|
function buildNodeSchemaMap(graph) {
|
|
282
267
|
const map = /* @__PURE__ */ new Map();
|
|
283
|
-
for (const kindName of
|
|
268
|
+
for (const kindName of chunkT6SPUYLX_cjs.getNodeKinds(graph)) {
|
|
284
269
|
const registration = graph.nodes[kindName];
|
|
285
270
|
map.set(kindName, {
|
|
286
271
|
registration,
|
|
@@ -291,18 +276,16 @@ function buildNodeSchemaMap(graph) {
|
|
|
291
276
|
}
|
|
292
277
|
function buildEdgeSchemaMap(graph) {
|
|
293
278
|
const map = /* @__PURE__ */ new Map();
|
|
294
|
-
for (const kindName of
|
|
279
|
+
for (const kindName of chunkT6SPUYLX_cjs.getEdgeKinds(graph)) {
|
|
295
280
|
const registration = graph.edges[kindName];
|
|
296
281
|
map.set(kindName, {
|
|
297
282
|
registration,
|
|
298
|
-
schema: registration.type.schema
|
|
299
|
-
fromKinds: new Set(registration.from.map((node) => node.kind)),
|
|
300
|
-
toKinds: new Set(registration.to.map((node) => node.kind))
|
|
283
|
+
schema: registration.type.schema
|
|
301
284
|
});
|
|
302
285
|
}
|
|
303
286
|
return map;
|
|
304
287
|
}
|
|
305
|
-
async function processNodes(backend, graphId, nodes, schemas, options, result, errors, importedNodeIds) {
|
|
288
|
+
async function processNodes(backend, graphId, registry, nodes, schemas, options, result, errors, importedNodeIds, lock) {
|
|
306
289
|
const batchSize = options.batchSize;
|
|
307
290
|
for (let index = 0; index < nodes.length; index += batchSize) {
|
|
308
291
|
const batch = nodes.slice(index, index + batchSize);
|
|
@@ -310,9 +293,11 @@ async function processNodes(backend, graphId, nodes, schemas, options, result, e
|
|
|
310
293
|
const importResult = await processNode(
|
|
311
294
|
backend,
|
|
312
295
|
graphId,
|
|
296
|
+
registry,
|
|
313
297
|
node,
|
|
314
298
|
schemas,
|
|
315
|
-
options
|
|
299
|
+
options,
|
|
300
|
+
lock
|
|
316
301
|
);
|
|
317
302
|
switch (importResult.status) {
|
|
318
303
|
case "created": {
|
|
@@ -327,7 +312,9 @@ async function processNodes(backend, graphId, nodes, schemas, options, result, e
|
|
|
327
312
|
}
|
|
328
313
|
case "skipped": {
|
|
329
314
|
result.nodes.skipped++;
|
|
330
|
-
|
|
315
|
+
if (importResult.liveTarget) {
|
|
316
|
+
importedNodeIds.add(makeNodeKey(node.kind, node.id));
|
|
317
|
+
}
|
|
331
318
|
break;
|
|
332
319
|
}
|
|
333
320
|
case "error": {
|
|
@@ -343,16 +330,26 @@ async function processNodes(backend, graphId, nodes, schemas, options, result, e
|
|
|
343
330
|
}
|
|
344
331
|
}
|
|
345
332
|
}
|
|
333
|
+
async function catchUniquenessError(fn) {
|
|
334
|
+
try {
|
|
335
|
+
return { ok: true, value: await fn() };
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (error instanceof chunkJIEJCTDS_cjs.UniquenessError) {
|
|
338
|
+
return { ok: false, error: error.message };
|
|
339
|
+
}
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
346
343
|
function validateValidityWindow(entity) {
|
|
347
344
|
try {
|
|
348
|
-
|
|
349
|
-
|
|
345
|
+
chunkYC6PWTHY_cjs.validateOptionalCanonicalIsoDate(entity.validFrom, "validFrom");
|
|
346
|
+
chunkYC6PWTHY_cjs.validateOptionalCanonicalIsoDate(entity.validTo, "validTo");
|
|
350
347
|
return void 0;
|
|
351
348
|
} catch (error) {
|
|
352
349
|
return error instanceof Error ? error.message : String(error);
|
|
353
350
|
}
|
|
354
351
|
}
|
|
355
|
-
async function processNode(backend, graphId, node, schemas, options) {
|
|
352
|
+
async function processNode(backend, graphId, registry, node, schemas, options, lock) {
|
|
356
353
|
const schemaEntry = schemas.get(node.kind);
|
|
357
354
|
if (!schemaEntry) {
|
|
358
355
|
return { status: "error", error: `Unknown node kind: ${node.kind}` };
|
|
@@ -369,11 +366,14 @@ async function processNode(backend, graphId, node, schemas, options) {
|
|
|
369
366
|
if (validityError !== void 0) {
|
|
370
367
|
return { status: "error", error: validityError };
|
|
371
368
|
}
|
|
369
|
+
const { registration } = schemaEntry;
|
|
370
|
+
const uniqueConstraints = registration.unique ?? [];
|
|
371
|
+
const writeContext = { graphId, registry, lock };
|
|
372
372
|
const existing = await backend.getNode(graphId, node.kind, node.id);
|
|
373
373
|
if (existing) {
|
|
374
374
|
switch (options.onConflict) {
|
|
375
375
|
case "skip": {
|
|
376
|
-
return { status: "skipped" };
|
|
376
|
+
return { status: "skipped", liveTarget: chunkUNNPKQUG_cjs.isLiveNodeRow(existing) };
|
|
377
377
|
}
|
|
378
378
|
case "error": {
|
|
379
379
|
return {
|
|
@@ -382,18 +382,41 @@ async function processNode(backend, graphId, node, schemas, options) {
|
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
384
|
case "update": {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
385
|
+
if (!chunkUNNPKQUG_cjs.isLiveNodeRow(existing)) {
|
|
386
|
+
return { status: "skipped", liveTarget: false };
|
|
387
|
+
}
|
|
388
|
+
const updateResult = await catchUniquenessError(
|
|
389
|
+
() => chunk5IQIX7LU_cjs.applyNodeUpdate(
|
|
390
|
+
writeContext,
|
|
391
|
+
{
|
|
392
|
+
existing,
|
|
393
|
+
schema: registration.type.schema,
|
|
394
|
+
validatedProps: propsResult.data,
|
|
395
|
+
uniqueConstraints,
|
|
396
|
+
...node.validTo !== void 0 && { validTo: node.validTo }
|
|
397
|
+
},
|
|
398
|
+
backend
|
|
399
|
+
)
|
|
400
|
+
);
|
|
401
|
+
if (!updateResult.ok) {
|
|
402
|
+
return { status: "error", error: updateResult.error };
|
|
403
|
+
}
|
|
393
404
|
return { status: "updated" };
|
|
394
405
|
}
|
|
395
406
|
}
|
|
396
407
|
}
|
|
408
|
+
const uniquenessResult = await catchUniquenessError(
|
|
409
|
+
() => chunk5IQIX7LU_cjs.checkUniquenessConstraints(
|
|
410
|
+
{ graphId, registry, backend },
|
|
411
|
+
node.kind,
|
|
412
|
+
node.id,
|
|
413
|
+
propsResult.data,
|
|
414
|
+
uniqueConstraints
|
|
415
|
+
)
|
|
416
|
+
);
|
|
417
|
+
if (!uniquenessResult.ok) {
|
|
418
|
+
return { status: "error", error: uniquenessResult.error };
|
|
419
|
+
}
|
|
397
420
|
await backend.insertNode({
|
|
398
421
|
graphId,
|
|
399
422
|
kind: node.kind,
|
|
@@ -402,9 +425,20 @@ async function processNode(backend, graphId, node, schemas, options) {
|
|
|
402
425
|
...node.validFrom !== void 0 && { validFrom: node.validFrom },
|
|
403
426
|
...node.validTo !== void 0 && { validTo: node.validTo }
|
|
404
427
|
});
|
|
428
|
+
await chunk5IQIX7LU_cjs.applyNodeInsertSideEffects(
|
|
429
|
+
writeContext,
|
|
430
|
+
{
|
|
431
|
+
kind: node.kind,
|
|
432
|
+
id: node.id,
|
|
433
|
+
schema: registration.type.schema,
|
|
434
|
+
props: propsResult.data,
|
|
435
|
+
uniqueConstraints
|
|
436
|
+
},
|
|
437
|
+
backend
|
|
438
|
+
);
|
|
405
439
|
return { status: "created" };
|
|
406
440
|
}
|
|
407
|
-
async function processEdges(backend, graphId, edges, edgeSchemas, nodeSchemas, options, result, errors, importedNodeIds) {
|
|
441
|
+
async function processEdges(backend, graphId, registry, edges, edgeSchemas, nodeSchemas, options, result, errors, importedNodeIds) {
|
|
408
442
|
const batchSize = options.batchSize;
|
|
409
443
|
for (let index = 0; index < edges.length; index += batchSize) {
|
|
410
444
|
const batch = edges.slice(index, index + batchSize);
|
|
@@ -412,6 +446,7 @@ async function processEdges(backend, graphId, edges, edgeSchemas, nodeSchemas, o
|
|
|
412
446
|
const importResult = await processEdge(
|
|
413
447
|
backend,
|
|
414
448
|
graphId,
|
|
449
|
+
registry,
|
|
415
450
|
edge,
|
|
416
451
|
edgeSchemas,
|
|
417
452
|
nodeSchemas,
|
|
@@ -444,7 +479,7 @@ async function processEdges(backend, graphId, edges, edgeSchemas, nodeSchemas, o
|
|
|
444
479
|
}
|
|
445
480
|
}
|
|
446
481
|
}
|
|
447
|
-
async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, options, importedNodeIds) {
|
|
482
|
+
async function processEdge(backend, graphId, registry, edge, edgeSchemas, nodeSchemas, options, importedNodeIds) {
|
|
448
483
|
const schemaEntry = edgeSchemas.get(edge.kind);
|
|
449
484
|
if (!schemaEntry) {
|
|
450
485
|
return { status: "error", error: `Unknown edge kind: ${edge.kind}` };
|
|
@@ -458,17 +493,15 @@ async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, opt
|
|
|
458
493
|
if (!nodeSchemas.has(edge.to.kind)) {
|
|
459
494
|
return { status: "error", error: `Unknown to node kind: ${edge.to.kind}` };
|
|
460
495
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`
|
|
471
|
-
};
|
|
496
|
+
const endpointError = chunk5IQIX7LU_cjs.validateEdgeEndpoints(
|
|
497
|
+
edge.kind,
|
|
498
|
+
edge.from.kind,
|
|
499
|
+
edge.to.kind,
|
|
500
|
+
schemaEntry.registration,
|
|
501
|
+
registry
|
|
502
|
+
);
|
|
503
|
+
if (endpointError !== void 0) {
|
|
504
|
+
return { status: "error", error: endpointError.message };
|
|
472
505
|
}
|
|
473
506
|
if (options.validateReferences) {
|
|
474
507
|
const fromKey = makeNodeKey(edge.from.kind, edge.from.id);
|
|
@@ -479,7 +512,7 @@ async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, opt
|
|
|
479
512
|
edge.from.kind,
|
|
480
513
|
edge.from.id
|
|
481
514
|
);
|
|
482
|
-
if (!fromExists) {
|
|
515
|
+
if (fromExists === void 0 || !chunkUNNPKQUG_cjs.isLiveNodeRow(fromExists)) {
|
|
483
516
|
return {
|
|
484
517
|
status: "error",
|
|
485
518
|
error: `From node not found: ${edge.from.kind}:${edge.from.id}`
|
|
@@ -488,7 +521,7 @@ async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, opt
|
|
|
488
521
|
}
|
|
489
522
|
if (!importedNodeIds.has(toKey)) {
|
|
490
523
|
const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);
|
|
491
|
-
if (!toExists) {
|
|
524
|
+
if (toExists === void 0 || !chunkUNNPKQUG_cjs.isLiveNodeRow(toExists)) {
|
|
492
525
|
return {
|
|
493
526
|
status: "error",
|
|
494
527
|
error: `To node not found: ${edge.to.kind}:${edge.to.id}`
|
|
@@ -512,12 +545,18 @@ async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, opt
|
|
|
512
545
|
if (existing) {
|
|
513
546
|
switch (options.onConflict) {
|
|
514
547
|
case "skip": {
|
|
515
|
-
return {
|
|
548
|
+
return {
|
|
549
|
+
status: "skipped",
|
|
550
|
+
liveTarget: existing.deleted_at === void 0
|
|
551
|
+
};
|
|
516
552
|
}
|
|
517
553
|
case "error": {
|
|
518
554
|
return { status: "error", error: `Edge already exists: ${edge.id}` };
|
|
519
555
|
}
|
|
520
556
|
case "update": {
|
|
557
|
+
if (existing.deleted_at !== void 0) {
|
|
558
|
+
return { status: "skipped", liveTarget: false };
|
|
559
|
+
}
|
|
521
560
|
await backend.updateEdge({
|
|
522
561
|
graphId,
|
|
523
562
|
id: edge.id,
|
|
@@ -620,5 +659,5 @@ exports.InterchangeNodeSchema = InterchangeNodeSchema;
|
|
|
620
659
|
exports.UnknownPropertyStrategySchema = UnknownPropertyStrategySchema;
|
|
621
660
|
exports.exportGraph = exportGraph;
|
|
622
661
|
exports.importGraph = importGraph;
|
|
623
|
-
//# sourceMappingURL=chunk-
|
|
624
|
-
//# sourceMappingURL=chunk-
|
|
662
|
+
//# sourceMappingURL=chunk-KNHYNQQ3.cjs.map
|
|
663
|
+
//# sourceMappingURL=chunk-KNHYNQQ3.cjs.map
|