@nicia-ai/typegraph 0.65.0 → 0.66.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/CHANGELOG.md +17 -0
- package/dist/{atomic-mutation-program-BznZQ06C.d.ts → atomic-mutation-program-BhP75Qn0.d.ts} +1 -1
- package/dist/{atomic-mutation-program-Bfu5z-je.d.cts → atomic-mutation-program-DMdmc4s0.d.cts} +1 -1
- package/dist/backend/drizzle/engine/index.cjs +13 -13
- package/dist/backend/drizzle/engine/index.d.cts +9 -9
- package/dist/backend/drizzle/engine/index.d.ts +9 -9
- package/dist/backend/drizzle/engine/index.js +8 -8
- package/dist/backend/drizzle/indexes.d.cts +1 -1
- package/dist/backend/drizzle/indexes.d.ts +1 -1
- package/dist/backend/index.cjs +91 -91
- package/dist/backend/index.d.cts +7 -7
- package/dist/backend/index.d.ts +7 -7
- package/dist/backend/index.js +8 -8
- package/dist/backend/postgres/index.cjs +23 -23
- package/dist/backend/postgres/index.d.cts +8 -8
- package/dist/backend/postgres/index.d.ts +8 -8
- package/dist/backend/postgres/index.js +8 -8
- package/dist/backend/postgres/pglite-store.cjs +1 -1
- package/dist/backend/postgres/pglite-store.d.cts +6 -6
- package/dist/backend/postgres/pglite-store.d.ts +6 -6
- package/dist/backend/postgres/pglite-store.js +1 -1
- package/dist/backend/postgres/pglite.cjs +10 -10
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +9 -9
- package/dist/backend/sqlite/index.cjs +21 -21
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +8 -8
- package/dist/backend/sqlite/libsql.cjs +14 -14
- package/dist/backend/sqlite/libsql.d.cts +3 -3
- package/dist/backend/sqlite/libsql.d.ts +3 -3
- package/dist/backend/sqlite/libsql.js +8 -8
- package/dist/backend/sqlite/local-store.cjs +1 -1
- package/dist/backend/sqlite/local-store.d.cts +6 -6
- package/dist/backend/sqlite/local-store.d.ts +6 -6
- package/dist/backend/sqlite/local-store.js +1 -1
- package/dist/backend/sqlite/local.cjs +10 -10
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +9 -9
- package/dist/{chunk-337ONI2I.js → chunk-3SUZXB5X.js} +146 -80
- package/dist/chunk-3SUZXB5X.js.map +1 -0
- package/dist/{chunk-4VTCIEK3.js → chunk-4TQOIBWH.js} +3 -3
- package/dist/{chunk-4VTCIEK3.js.map → chunk-4TQOIBWH.js.map} +1 -1
- package/dist/{chunk-JRWKRBI5.cjs → chunk-5JOCIMQ3.cjs} +6 -6
- package/dist/{chunk-JRWKRBI5.cjs.map → chunk-5JOCIMQ3.cjs.map} +1 -1
- package/dist/{chunk-BWQA3POT.cjs → chunk-6B3LQUYG.cjs} +206 -138
- package/dist/chunk-6B3LQUYG.cjs.map +1 -0
- package/dist/{chunk-RQPCUHIH.js → chunk-6ECNYQDW.js} +3 -3
- package/dist/{chunk-RQPCUHIH.js.map → chunk-6ECNYQDW.js.map} +1 -1
- package/dist/{chunk-OLB75LRQ.js → chunk-6GKKAQMW.js} +5 -5
- package/dist/{chunk-OLB75LRQ.js.map → chunk-6GKKAQMW.js.map} +1 -1
- package/dist/{chunk-OC5ROP7V.cjs → chunk-6JRVV2SS.cjs} +8 -2
- package/dist/chunk-6JRVV2SS.cjs.map +1 -0
- package/dist/{chunk-JERQGJKG.cjs → chunk-732VS5PW.cjs} +18 -18
- package/dist/{chunk-JERQGJKG.cjs.map → chunk-732VS5PW.cjs.map} +1 -1
- package/dist/{chunk-DSX3P4S5.cjs → chunk-76OB5RSH.cjs} +6 -6
- package/dist/{chunk-DSX3P4S5.cjs.map → chunk-76OB5RSH.cjs.map} +1 -1
- package/dist/{chunk-DHRLOQLQ.cjs → chunk-7LQTDGV5.cjs} +11 -11
- package/dist/{chunk-DHRLOQLQ.cjs.map → chunk-7LQTDGV5.cjs.map} +1 -1
- package/dist/{chunk-Q25QYSOH.js → chunk-7YJHUY4T.js} +9 -9
- package/dist/{chunk-Q25QYSOH.js.map → chunk-7YJHUY4T.js.map} +1 -1
- package/dist/{chunk-BBOMNH44.js → chunk-BABP4D5B.js} +3 -3
- package/dist/{chunk-BBOMNH44.js.map → chunk-BABP4D5B.js.map} +1 -1
- package/dist/{chunk-EVGZ2TRQ.js → chunk-BE75G3M5.js} +3 -3
- package/dist/{chunk-EVGZ2TRQ.js.map → chunk-BE75G3M5.js.map} +1 -1
- package/dist/{chunk-FXGZT3WO.cjs → chunk-BX42F7IJ.cjs} +41 -41
- package/dist/{chunk-FXGZT3WO.cjs.map → chunk-BX42F7IJ.cjs.map} +1 -1
- package/dist/{chunk-VROJKWZ7.js → chunk-C3HNC3S6.js} +5 -5
- package/dist/{chunk-VROJKWZ7.js.map → chunk-C3HNC3S6.js.map} +1 -1
- package/dist/{chunk-G6T23JU7.js → chunk-CDKNGCE7.js} +3 -3
- package/dist/{chunk-G6T23JU7.js.map → chunk-CDKNGCE7.js.map} +1 -1
- package/dist/{chunk-BNTJ5YFO.cjs → chunk-EACDHXJL.cjs} +4 -4
- package/dist/{chunk-BNTJ5YFO.cjs.map → chunk-EACDHXJL.cjs.map} +1 -1
- package/dist/{chunk-SNDJUTMB.cjs → chunk-EBQX7MYL.cjs} +72 -72
- package/dist/{chunk-SNDJUTMB.cjs.map → chunk-EBQX7MYL.cjs.map} +1 -1
- package/dist/{chunk-GKSAEUX6.js → chunk-FXOFJ4FS.js} +7 -7
- package/dist/{chunk-GKSAEUX6.js.map → chunk-FXOFJ4FS.js.map} +1 -1
- package/dist/{chunk-ZOWRACZQ.cjs → chunk-G7OKJDMG.cjs} +5 -5
- package/dist/{chunk-ZOWRACZQ.cjs.map → chunk-G7OKJDMG.cjs.map} +1 -1
- package/dist/{chunk-VZRXXABW.js → chunk-HSLP6CVG.js} +5 -5
- package/dist/{chunk-VZRXXABW.js.map → chunk-HSLP6CVG.js.map} +1 -1
- package/dist/{chunk-MKJPBSID.cjs → chunk-I7SBZJI2.cjs} +4 -4
- package/dist/{chunk-MKJPBSID.cjs.map → chunk-I7SBZJI2.cjs.map} +1 -1
- package/dist/{chunk-H346QK3V.cjs → chunk-K7YACILO.cjs} +9 -9
- package/dist/{chunk-H346QK3V.cjs.map → chunk-K7YACILO.cjs.map} +1 -1
- package/dist/{chunk-L2GBVYRU.cjs → chunk-MGCPSR4C.cjs} +11 -11
- package/dist/{chunk-L2GBVYRU.cjs.map → chunk-MGCPSR4C.cjs.map} +1 -1
- package/dist/{chunk-KDNRACRG.cjs → chunk-MRUOOAIQ.cjs} +4 -4
- package/dist/{chunk-KDNRACRG.cjs.map → chunk-MRUOOAIQ.cjs.map} +1 -1
- package/dist/{chunk-PFXNQFFY.js → chunk-MUEPEWMQ.js} +67 -8
- package/dist/chunk-MUEPEWMQ.js.map +1 -0
- package/dist/{chunk-HTSJTWUT.js → chunk-OF63ZHSD.js} +4 -4
- package/dist/{chunk-HTSJTWUT.js.map → chunk-OF63ZHSD.js.map} +1 -1
- package/dist/{chunk-NGA3THGU.cjs → chunk-QR7W37HG.cjs} +14 -14
- package/dist/{chunk-NGA3THGU.cjs.map → chunk-QR7W37HG.cjs.map} +1 -1
- package/dist/{chunk-QFEO4M5W.js → chunk-RTPMG6LQ.js} +11 -11
- package/dist/{chunk-QFEO4M5W.js.map → chunk-RTPMG6LQ.js.map} +1 -1
- package/dist/{chunk-PFD4NUYV.js → chunk-SSDHR2C2.js} +3 -3
- package/dist/{chunk-PFD4NUYV.js.map → chunk-SSDHR2C2.js.map} +1 -1
- package/dist/{chunk-THK3SCQA.js → chunk-SYXTWPX6.js} +5 -5
- package/dist/{chunk-THK3SCQA.js.map → chunk-SYXTWPX6.js.map} +1 -1
- package/dist/{chunk-XSLQYGNR.cjs → chunk-T3VU3YRQ.cjs} +69 -69
- package/dist/{chunk-XSLQYGNR.cjs.map → chunk-T3VU3YRQ.cjs.map} +1 -1
- package/dist/{chunk-MIBWA6HX.js → chunk-TR7QTODF.js} +213 -33
- package/dist/chunk-TR7QTODF.js.map +1 -0
- package/dist/{chunk-AD3NLSV5.js → chunk-TU22BFMP.js} +8 -2
- package/dist/chunk-TU22BFMP.js.map +1 -0
- package/dist/{chunk-WTMSUIRO.js → chunk-UFKYMQJ5.js} +3 -3
- package/dist/{chunk-WTMSUIRO.js.map → chunk-UFKYMQJ5.js.map} +1 -1
- package/dist/{chunk-35LDKSMM.cjs → chunk-VNJMM2QQ.cjs} +30 -30
- package/dist/{chunk-35LDKSMM.cjs.map → chunk-VNJMM2QQ.cjs.map} +1 -1
- package/dist/{chunk-53ZEBIMD.js → chunk-WB55URNM.js} +6 -6
- package/dist/{chunk-53ZEBIMD.js.map → chunk-WB55URNM.js.map} +1 -1
- package/dist/{chunk-D2JPOFRZ.cjs → chunk-WY3IFEKV.cjs} +191 -191
- package/dist/{chunk-D2JPOFRZ.cjs.map → chunk-WY3IFEKV.cjs.map} +1 -1
- package/dist/{chunk-3KWF25MF.cjs → chunk-XQNKN3UF.cjs} +305 -246
- package/dist/chunk-XQNKN3UF.cjs.map +1 -0
- package/dist/{chunk-3RSFLZ7A.cjs → chunk-Y4X6ODVY.cjs} +943 -763
- package/dist/chunk-Y4X6ODVY.cjs.map +1 -0
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/{ddl-DvW9aobX.d.ts → ddl-2q7xLM1X.d.ts} +3 -3
- package/dist/{ddl-BjuXbPfw.d.cts → ddl-D_09BfbN.d.cts} +3 -3
- package/dist/graph-extension/index.d.cts +2 -2
- package/dist/graph-extension/index.d.ts +2 -2
- package/dist/graph-merge/index.cjs +156 -156
- package/dist/graph-merge/index.d.cts +7 -7
- package/dist/graph-merge/index.d.ts +7 -7
- package/dist/graph-merge/index.js +14 -14
- package/dist/{graph-templates-1vMqlPsu.d.cts → graph-templates-B5Q7oYAA.d.cts} +2 -2
- package/dist/{graph-templates-Y52w16dH.d.ts → graph-templates-D9N-Z9kw.d.ts} +2 -2
- package/dist/index.cjs +99 -99
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +18 -18
- package/dist/indexes/index.d.cts +4 -4
- package/dist/indexes/index.d.ts +4 -4
- package/dist/{ingestion-import-target-CCKeXZbW.d.ts → ingestion-import-target-B8EU6ug2.d.ts} +1 -1
- package/dist/{ingestion-import-target-774QRgkF.d.cts → ingestion-import-target-C5sHNFJF.d.cts} +1 -1
- package/dist/interchange/index.cjs +34 -34
- package/dist/interchange/index.d.cts +7 -7
- package/dist/interchange/index.d.ts +7 -7
- package/dist/interchange/index.js +11 -11
- package/dist/{local-store-impl-3E4VLFCI.cjs → local-store-impl-J6TJG45N.cjs} +22 -22
- package/dist/{local-store-impl-3E4VLFCI.cjs.map → local-store-impl-J6TJG45N.cjs.map} +1 -1
- package/dist/{local-store-impl-DFKS7QTV.js → local-store-impl-XKWR46WQ.js} +18 -18
- package/dist/{local-store-impl-DFKS7QTV.js.map → local-store-impl-XKWR46WQ.js.map} +1 -1
- package/dist/{pglite-store-impl-T75O3LVQ.cjs → pglite-store-impl-KXD5VWC5.cjs} +22 -22
- package/dist/{pglite-store-impl-T75O3LVQ.cjs.map → pglite-store-impl-KXD5VWC5.cjs.map} +1 -1
- package/dist/{pglite-store-impl-N63GGBU2.js → pglite-store-impl-LRZ4TO3H.js} +18 -18
- package/dist/{pglite-store-impl-N63GGBU2.js.map → pglite-store-impl-LRZ4TO3H.js.map} +1 -1
- package/dist/{postgres-2FYdVYCm.d.cts → postgres-BIm6TDfF.d.cts} +3 -3
- package/dist/{postgres-C9gitL71.d.ts → postgres-CRRB2qzy.d.ts} +3 -3
- package/dist/{postgres-BONrXHb4.d.cts → postgres-DOBXcZVg.d.cts} +1 -1
- package/dist/{postgres-DAFRdnTr.d.ts → postgres-DhZixg92.d.ts} +1 -1
- package/dist/{profile-Bmcg07Ki.d.cts → profile-CjAffcQt.d.cts} +2 -2
- package/dist/{profile-CAD65CqS.d.ts → profile-DVd70NA-.d.ts} +2 -2
- package/dist/profiler/index.d.cts +8 -8
- package/dist/profiler/index.d.ts +8 -8
- package/dist/provenance/index.cjs +22 -22
- package/dist/provenance/index.d.cts +6 -6
- package/dist/provenance/index.d.ts +6 -6
- package/dist/provenance/index.js +6 -6
- package/dist/{repair-validity-windows-CinP91t7.d.cts → repair-validity-windows-CpP_GpIx.d.cts} +1 -1
- package/dist/{repair-validity-windows-BJz4nffP.d.ts → repair-validity-windows-lfe275bY.d.ts} +1 -1
- package/dist/{resolve-DgOSlXx_.d.ts → resolve-CoYqHqno.d.cts} +7 -2
- package/dist/{resolve-DQXSEN_A.d.cts → resolve-DV0Iposp.d.ts} +7 -2
- package/dist/schema/index.cjs +37 -37
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +7 -7
- package/dist/{searchable-DMdCwkXO.d.cts → searchable-C7Xt6g45.d.cts} +1 -1
- package/dist/{searchable-BPRF0Bah.d.ts → searchable-KKXrPet3.d.ts} +1 -1
- package/dist/{sqlite-DcDAAYow.d.ts → sqlite-BNwQ5pd7.d.ts} +3 -3
- package/dist/{sqlite-DgbYa-1Y.d.cts → sqlite-BkQM9ZeI.d.cts} +1 -1
- package/dist/{sqlite-UlG5prJQ.d.ts → sqlite-CcCSeXGg.d.ts} +1 -1
- package/dist/{sqlite-Co_uIpfs.d.cts → sqlite-DX9H3L7z.d.cts} +3 -3
- package/dist/{store-HxoFyQMu.d.cts → store-3nfPQK5j.d.cts} +30 -7
- package/dist/{store-C9T1c9Az.d.ts → store-C8ZPl7OW.d.ts} +30 -7
- package/dist/{types-CRCyg1fJ.d.cts → types-BynPp5kU.d.cts} +18 -2
- package/dist/{types-CRCyg1fJ.d.ts → types-BynPp5kU.d.ts} +18 -2
- package/dist/{types-Dg_prBqC.d.ts → types-C9YwrkSe.d.ts} +1 -1
- package/dist/{types-B5AUesS1.d.cts → types-JG-4CG6P.d.cts} +1 -1
- package/dist/{where-gRyc3jj_.d.cts → where-D1gBDqQ_.d.cts} +1 -1
- package/dist/{where-D-NDKMPw.d.ts → where-D2GqMFp-.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-337ONI2I.js.map +0 -1
- package/dist/chunk-3KWF25MF.cjs.map +0 -1
- package/dist/chunk-3RSFLZ7A.cjs.map +0 -1
- package/dist/chunk-AD3NLSV5.js.map +0 -1
- package/dist/chunk-BWQA3POT.cjs.map +0 -1
- package/dist/chunk-MIBWA6HX.js.map +0 -1
- package/dist/chunk-OC5ROP7V.cjs.map +0 -1
- package/dist/chunk-PFXNQFFY.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk6JRVV2SS_cjs = require('./chunk-6JRVV2SS.cjs');
|
|
4
4
|
var chunk5ICDVLI3_cjs = require('./chunk-5ICDVLI3.cjs');
|
|
5
5
|
var chunk7XYPLAPL_cjs = require('./chunk-7XYPLAPL.cjs');
|
|
6
6
|
|
|
7
7
|
// src/store/claims/backing.ts
|
|
8
8
|
function claimSupport(target, verdict) {
|
|
9
9
|
if (!verdict.supported) return { supported: false };
|
|
10
|
-
return { supported: true, claims:
|
|
10
|
+
return { supported: true, claims: chunk6JRVV2SS_cjs.claimsMembers(target, verdict) };
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// src/store/claims/edge-claims.ts
|
|
@@ -97,7 +97,7 @@ async function withEdgeClaimRelationPrecondition(graphId, issue) {
|
|
|
97
97
|
try {
|
|
98
98
|
return await issue();
|
|
99
99
|
} catch (error) {
|
|
100
|
-
if (!
|
|
100
|
+
if (!chunk6JRVV2SS_cjs.isMissingTableError(error)) throw error;
|
|
101
101
|
throw edgeClaimRelationMissing(graphId, error);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -165,5 +165,5 @@ exports.edgeCardinalityClaimRefusal = edgeCardinalityClaimRefusal;
|
|
|
165
165
|
exports.edgeCardinalityClaimTarget = edgeCardinalityClaimTarget;
|
|
166
166
|
exports.edgeClaimRelationMissing = edgeClaimRelationMissing;
|
|
167
167
|
exports.purgeEdgeClaims = purgeEdgeClaims;
|
|
168
|
-
//# sourceMappingURL=chunk-
|
|
169
|
-
//# sourceMappingURL=chunk-
|
|
168
|
+
//# sourceMappingURL=chunk-G7OKJDMG.cjs.map
|
|
169
|
+
//# sourceMappingURL=chunk-G7OKJDMG.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store/claims/backing.ts","../src/store/claims/edge-claims.ts"],"names":["claimsMembers","edgeCardinalityAxis","encodeTupleKey","checkUniqueEdge","checkCardinality","CardinalityError","ConfigurationError","isMissingTableError","outcome","compareClaimTargets"],"mappings":";;;;;;;AAiHO,SAAS,YAAA,CACd,QAGA,OAAA,EACc;AACd,EAAA,IAAI,CAAC,OAAA,CAAQ,SAAA,EAAW,OAAO,EAAE,WAAW,KAAA,EAAM;AAClD,EAAA,OAAO,EAAE,SAAA,EAAW,IAAA,EAAM,QAAQA,+BAAA,CAAc,MAAA,EAAQ,OAAO,CAAA,EAAE;AACnE;;;AC1DO,IAAM,sBAAA,GAAyB;AAAA,EACpC,KAAK,EAAE,QAAA,EAAU,QAAQ,mBAAA,EAAqB,IAAA,EAAM,gBAAgB,MAAA,EAAO;AAAA,EAC3E,MAAA,EAAQ;AAAA,IACN,QAAA,EAAU,WAAA;AAAA,IACV,mBAAA,EAAqB,IAAA;AAAA,IACrB,cAAA,EAAgB;AAAA,GAClB;AAAA,EACA,SAAA,EAAW;AAAA,IACT,QAAA,EAAU,MAAA;AAAA,IACV,mBAAA,EAAqB,KAAA;AAAA,IACrB,cAAA,EAAgB;AAAA;AAEpB;AAGO,SAAS,2BACd,QAAA,EACmB;AACnB,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,sBAAsB,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC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0BAAA,CAA2B,KAAK,CAAA,GAAI,CAAA,CACrE,QAAA,CAAS,CAAC,IAAA,EAAM,KAAA,KAAUC,sCAAoB,IAAA,CAAK,MAAA,EAAQ,KAAA,CAAM,MAAM,CAAC,CAAA;AAC3E,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,CAAC,CAAA,EAAG,MAAM,OAAA,IAAW,EAAA;AAC7C,EAAA,MAAM,WAAW,MAAM,iCAAA;AAAA,IAAkC,OAAA;AAAA,IAAS,MAChE,QAAQ,MAAA,CAAO,yBAAA;AAAA,MACb,OAAA,CAAQ,GAAA,CAAI,CAAC,KAAA,KAAU,MAAM,KAAK;AAAA;AACpC,GACF;AACA,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,OAAO,CAAA,IAAK,QAAA,CAAS,SAAQ,EAAG;AACjD,IAAA,MAAM,KAAA,GAAQ,QAAQ,KAAK,CAAA;AAC3B,IAAA,IAAI,KAAA,KAAU,MAAA,IAAa,OAAA,CAAQ,MAAA,KAAW,SAAA,EAAW;AACvD,MAAA,MAAM,2BAAA,CAA4B,MAAM,KAAK,CAAA;AAAA,IAC/C;AAAA,EACF;AACF;AAUA,eAAsB,eAAA,CACpB,OAAA,EACA,OAAA,EACA,OAAA,EACA,OAAA,EACe;AACf,EAAA,IAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC1B,EAAA,MAAM,OAAA,GAAU,YAAA,CAAa,OAAA,EAAS,OAAO,CAAA;AAC7C,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AACxB,EAAA,MAAM,iCAAA;AAAA,IAAkC,OAAA;AAAA,IAAS,MAC/C,OAAA,CAAQ,MAAA,CAAO,gBAAgB,EAAE,OAAA,EAAS,SAAS;AAAA,GACrD;AACF","file":"chunk-ZOWRACZQ.cjs","sourcesContent":["/**\n * What backs each constraint fence class.\n *\n * A constrained write is fenced by one of two things: a per-graph lock that\n * serializes the probe with the write it guards, or a CLAIM row whose primary\n * key refuses a second claimant outright. The second is strictly stronger — it\n * holds without a lock, which is what an import needs — and this module records\n * which class has reached it, so \"is this fence a lock or a key?\" is answered\n * from one table rather than inferred from whichever module a reader lands in.\n *\n * It also owns the runtime half of the same question — {@link claimSupport},\n * the one reader of \"can THIS object hold a claim?\" — so the declaration and\n * the surface are reconciled in one place rather than at each claim site.\n * `claimSupport` is now a thin binder over the `claims` capability bundle\n * (`backend/capabilities`): the bidirectional declaration/surface cross-check\n * lives once in `resolve.ts`'s `assertClaimsBidirectionalAgreement`, reached\n * through the verdict every caller threads in, and this module owns only the\n * per-write port bind (`claimsMembers`) and this decision's shape.\n */\nimport {\n type BundleBinding,\n claimsMembers,\n} from \"../../backend/capabilities/bind\";\nimport type { CLAIMS } from \"../../backend/capabilities/bundle-registry\";\nimport { type BundleVerdictOf } from \"../../backend/capabilities/resolve\";\nimport { type GraphBackend } from \"../../backend/types\";\n\n/**\n * The runtime extent of the fence classes. {@link ConstraintFenceReason} is\n * DERIVED from it rather than declared beside it: a union type has no runtime\n * extent, so a totality test over a map keyed by the union could only iterate\n * that map's own keys and would be trivially true.\n */\nexport const CONSTRAINT_FENCE_REASONS = [\n \"edgeCardinality\",\n \"edgeMatchKeyConvergence\",\n \"nodeDisjointness\",\n \"nodeUniquenessClaim\",\n \"nodeUniquenessScope\",\n] as const;\n\n/**\n * WHICH declared constraint makes a write constrained.\n *\n * The classification names the reason rather than answering yes/no, because\n * the reason is load-bearing twice over: it is what the fence is taken FOR, and\n * — on a backend that cannot hold the fence — it is what the refusal has to\n * tell the caller. \"This backend cannot fence constrained writes\" is unusable\n * advice; \"your `cardinality: 'one'` edge cannot be enforced here\" is\n * actionable, and only the classifier knows which it was.\n */\nexport type ConstraintFenceReason = (typeof CONSTRAINT_FENCE_REASONS)[number];\n\n/** The relation whose key fences a class, or `lockOnly` when nothing does yet. */\ntype ConstraintFenceBacking = \"uniques\" | \"edgeClaims\" | \"lockOnly\";\n\n/**\n * Which claim relation backs each fence class. The `satisfies` forces totality:\n * a new reason cannot be added without stating what backs it.\n *\n * `nodeUniquenessScope` is `\"uniques\"` because a shared-scope claim is now\n * written at the scope's axis, so two writers of two kinds in one hierarchy\n * contend for one row. `nodeUniquenessClaim` is the same relation seen from the\n * other side: the claim row is the fence, and the class exists because a write\n * that must issue it BEFORE the row it gates needs a transaction to undo the\n * pair together — which is what its refusal names. `nodeDisjointness` is the\n * same relation again, at a third kind of axis: a claim keyed on the declared\n * PAIR and on the node's id, which is the axis disjointness actually declares\n * and the one the nodes primary key `(graph_id, kind, id)` cannot fence.\n * `edgeCardinality` is the other relation: a claim keyed on\n * `(<cardinality>:<edgeKind>, endpoint identity)`, which is the axis the\n * declaration actually spans and the one the edges primary key `(graph_id, id)`\n * cannot fence. The classes still marked `lockOnly` are fenced by the per-graph\n * write lock alone, which is why they are also the classes a non-transactional\n * backend refuses.\n */\nexport const CONSTRAINT_FENCE_BACKING = {\n edgeCardinality: \"edgeClaims\",\n edgeMatchKeyConvergence: \"lockOnly\",\n nodeDisjointness: \"uniques\",\n nodeUniquenessClaim: \"uniques\",\n nodeUniquenessScope: \"uniques\",\n} as const satisfies Record<ConstraintFenceReason, ConstraintFenceBacking>;\n\n/** The decision {@link claimSupport} returns — never a flag a caller re-derives. */\nexport type ClaimSupport =\n /** Capability declared AND every claim member present: the members, bound off the port. */\n | Readonly<{\n supported: true;\n claims: BundleBinding<(typeof CLAIMS)[\"core\"][number]>;\n }>\n /** Capability absent or false AND no claim member present: the declared gap. */\n | Readonly<{ supported: false }>;\n\n/**\n * THE one reader of \"can this object hold a claim?\", asked about the object the\n * claim is about to be written to.\n *\n * Takes the bundle's VERDICT — resolved once, against `GraphBackend`, by the\n * caller's `ClaimsVerdictThunk` (ruling B1/B7) — rather than resolving it\n * itself: the declaration/surface cross-check\n * (`resolve.ts`'s `assertClaimsBidirectionalAgreement`) runs exactly once,\n * inside that resolution, and this function never re-derives it. What this\n * function still owns is the PER-WRITE bind: `claimsMembers` (`bind.ts`) binds\n * the verdict's named members off `target` — the object the write actually\n * executes on, which may be a `TransactionBackend` the verdict was never\n * resolved against — and throws the bundle's port-surface code\n * (`CONSTRAINT_CLAIM_SURFACE_MISMATCH`) if `target` disagrees with what the\n * verdict says is present.\n *\n * @throws ConfigurationError (`CONSTRAINT_CLAIM_SURFACE_MISMATCH`) when\n * `target` is missing a member the verdict says is present.\n */\nexport function claimSupport(\n target: Readonly<\n Partial<Pick<GraphBackend, (typeof CLAIMS)[\"core\"][number]>>\n >,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n): ClaimSupport {\n if (!verdict.supported) return { supported: false };\n return { supported: true, claims: claimsMembers(target, verdict) };\n}\n","/**\n * Edge claims — what an edge write reserves on a declared cardinality axis.\n *\n * A declared cardinality is a predicate over `(kind, from)` or\n * `(kind, from, to)`, and the edges relation's only uniqueness is its\n * `(graph_id, id)` primary key, so nothing in the schema re-decides at write\n * time what the probe decided at read time. This module is the reservation that\n * does: one row per `(graph_id, axis, key)` in `typegraph_edge_claims`, whose\n * primary key refuses a second concurrent claimant.\n *\n * The claim needs no release path. A claim whose holder is no longer live (or,\n * for `oneActive`, no longer active) fails the liveness predicate the takeover\n * statement carries and is taken over in place, so the fence never depends on\n * any delete path having run. `purgeEdgeClaims` exists to bound table growth,\n * not to make the fence correct.\n */\nimport type { CLAIMS } from \"../../backend/capabilities/bundle-registry\";\nimport { type BundleVerdictOf } from \"../../backend/capabilities/resolve\";\nimport {\n type ClaimEdgeCardinalityParams,\n type GraphBackend,\n type InsertEdgeParams,\n} from \"../../backend/types\";\nimport { checkCardinality, checkUniqueEdge } from \"../../constraints\";\nimport { type Cardinality } from \"../../core/types\";\nimport { CardinalityError, ConfigurationError } from \"../../errors\";\nimport { isMissingTableError } from \"../../utils/sql-errors\";\nimport { encodeTupleKey } from \"../../utils/tuple-key\";\nimport {\n type ClaimTarget,\n compareClaimTargets,\n edgeCardinalityAxis,\n} from \"./axis\";\nimport { claimSupport } from \"./backing\";\n\n/** A cardinality that declares something — `many` declares nothing. */\nexport type ConstrainedCardinality = Exclude<Cardinality, \"many\">;\n\n/**\n * What one declared cardinality means to every layer that has to agree about\n * it: which endpoints its axis key covers, whether an edge born already ended\n * claims at all, and what a holder must still BE for its claim to stand.\n */\nexport type EdgeCardinalitySpec = Readonly<{\n /** Which endpoints the axis key covers. */\n keyShape: \"from\" | \"fromAndTo\";\n /** Whether a new edge that is born ENDED makes a claim at all. */\n claimsWhenBornEnded: boolean;\n /** What a holder must still be for its claim to stand. */\n holderLiveness: \"live\" | \"liveAndActive\";\n}>;\n\n/**\n * THE table both renderers of the cardinality predicate read: the TypeScript\n * probe ({@link file://../constraints.ts checkCardinalityConstraint}) and the\n * SQL takeover statement\n * ({@link file://../../backend/drizzle/operations/edge-claims.ts}).\n *\n * Two renderers, one table, exhaustive by type: a new cardinality cannot be\n * added without stating all three facts, and the probe and the fence cannot\n * disagree about any of them — a disagreement is exactly the shape where the\n * probe accepts a write the fence then refuses forever (or the reverse).\n */\nexport const EDGE_CARDINALITY_SPECS = {\n one: { keyShape: \"from\", claimsWhenBornEnded: true, holderLiveness: \"live\" },\n unique: {\n keyShape: \"fromAndTo\",\n claimsWhenBornEnded: true,\n holderLiveness: \"live\",\n },\n oneActive: {\n keyShape: \"from\",\n claimsWhenBornEnded: false,\n holderLiveness: \"liveAndActive\",\n },\n} as const satisfies Record<ConstrainedCardinality, EdgeCardinalitySpec>;\n\n/** Every axis an edge kind's claims can sit on, for housekeeping reaps. */\nexport function edgeCardinalityAxesForKind(\n edgeKind: string,\n): readonly string[] {\n return Object.keys(EDGE_CARDINALITY_SPECS).map((cardinality) =>\n edgeCardinalityAxis(cardinality, edgeKind),\n );\n}\n\n/**\n * THE claim row one edge write reserves: its axis, and the endpoint identity\n * the axis is keyed by.\n *\n * The key is {@link encodeTupleKey}, not a delimiter join: node ids are\n * arbitrary caller data (only kind names pass `assertClaimAxisSafe`), and a\n * delimiter that a value may contain makes two different endpoint tuples\n * collapse onto one key — which would refuse a write no constraint forbids.\n */\nexport function edgeCardinalityClaimTarget(\n params: ClaimEdgeCardinalityParams,\n): ClaimTarget {\n const spec = EDGE_CARDINALITY_SPECS[params.cardinality];\n return {\n relation: \"edgeClaims\",\n graphId: params.graphId,\n axis: edgeCardinalityAxis(params.cardinality, params.edgeKind),\n key:\n spec.keyShape === \"from\" ?\n encodeTupleKey([params.fromKind, params.fromId])\n : encodeTupleKey([\n params.fromKind,\n params.fromId,\n params.toKind,\n params.toId,\n ]),\n };\n}\n\n/**\n * The fields a claim is decided from: the row's identity and the upper bound\n * that decides whether it joins an active-only population. Narrower than\n * {@link InsertEdgeParams} on purpose — a resurrect has no insert params to\n * hand over, and passing an invented `props` to satisfy a type would be a\n * fabricated value a reader has to check is unread.\n */\nexport type EdgeClaimSubject = Pick<\n InsertEdgeParams,\n \"graphId\" | \"id\" | \"kind\" | \"fromKind\" | \"fromId\" | \"toKind\" | \"toId\"\n> &\n Readonly<{ validTo?: string }>;\n\n/**\n * THE claim an edge insert owes, or `undefined` when it owes none.\n *\n * `many` declares no constraint, and an `oneActive` edge born already ended\n * joins no active population — `claimsWhenBornEnded` is the one place that\n * second exemption is written down, and the probe reads the same field, so the\n * two cannot drift into \"probed but unclaimed\" (a silent hole) or \"claimed but\n * unprobed\" (a refusal with no matching error).\n */\nexport function edgeCardinalityClaim(\n cardinality: Cardinality,\n subject: EdgeClaimSubject,\n): ClaimEdgeCardinalityParams | undefined {\n if (cardinality === \"many\") return undefined;\n if (\n !EDGE_CARDINALITY_SPECS[cardinality].claimsWhenBornEnded &&\n subject.validTo !== undefined\n ) {\n return undefined;\n }\n return {\n graphId: subject.graphId,\n cardinality,\n edgeKind: subject.kind,\n edgeId: subject.id,\n fromKind: subject.fromKind,\n fromId: subject.fromId,\n toKind: subject.toKind,\n toId: subject.toId,\n };\n}\n\n/**\n * The refusal a lost claim raises — built by the SAME owners the probe calls,\n * so the fence's error is `instanceof` the same class and carries the same\n * payload as the probe's for the same violation (I3).\n */\n/**\n * Builds the public cardinality refusal for a claim decision.\n *\n * Both the ordinary claim path and the fused claim-plus-edge path call this\n * owner. Keeping the translation here prevents a backend result discriminator\n * from growing a second spelling of the same typed error.\n */\nexport function edgeCardinalityClaimRefusal(\n params: ClaimEdgeCardinalityParams,\n): CardinalityError {\n const error =\n params.cardinality === \"unique\" ?\n checkUniqueEdge(\n params.edgeKind,\n params.fromKind,\n params.fromId,\n params.toKind,\n params.toId,\n 1,\n )\n : checkCardinality(\n params.edgeKind,\n params.fromKind,\n params.fromId,\n params.cardinality,\n 1,\n true,\n );\n // Both owners refuse for an incumbent count of one on every constrained\n // cardinality; the fallback keeps the return type honest without inventing a\n // second spelling of the message.\n return (\n error ??\n new CardinalityError({\n edgeKind: params.edgeKind,\n fromKind: params.fromKind,\n fromId: params.fromId,\n cardinality: params.cardinality,\n existingCount: 1,\n })\n );\n}\n\n/**\n * Converts the engine's \"relation does not exist\" into a typed precondition\n * error naming the relation and the way to create it.\n *\n * Checked at FIRST USE rather than at store construction: a graph with no\n * constrained edge kind never issues a claim and must not pay a catalog read\n * for a relation it will never touch. A database bootstrapped before this\n * relation existed reaches it here, on the first constrained edge write, with\n * an error that says what to run instead of an opaque driver failure.\n */\nexport function edgeClaimRelationMissing(\n graphId: string,\n cause: unknown,\n): ConfigurationError {\n return new ConfigurationError(\n \"Enforcing a declared edge cardinality needs the edge claim relation \" +\n \"(typegraph_edge_claims), and this database does not have it. \" +\n \"Databases initialized before this relation existed were never sent \" +\n \"its CREATE TABLE, because the bootstrap DDL runs only on first boot.\",\n { code: \"EDGE_CLAIM_RELATION_MISSING\", graphId },\n {\n cause,\n suggestion:\n \"Run the generated migration SQL (generatePostgresMigrationSQL / \" +\n \"generateSqliteMigrationSQL) against this database, or declare the \" +\n 'edge kind `cardinality: \"many\"` and enforce the limit in ' +\n \"application code.\",\n },\n );\n}\n\nasync function withEdgeClaimRelationPrecondition<T>(\n graphId: string,\n issue: () => Promise<T>,\n): Promise<T> {\n try {\n return await issue();\n } catch (error) {\n if (!isMissingTableError(error)) throw error;\n throw edgeClaimRelationMissing(graphId, error);\n }\n}\n\ntype ClaimModeTarget = Readonly<\n Partial<\n Pick<\n GraphBackend,\n (typeof CLAIMS)[\"core\"][number] | \"claimEdgeCardinalityGuarded\"\n >\n >\n>;\n\n/** The narrow backend facet an edge claim is written through. */\ntype ClaimTargetMembers = ClaimModeTarget;\n\n/**\n * The one owner of whether a single write may replace its entity probe with a\n * guarded claim. Both claim-bundle support and the optional strong member are\n * required: the member is the backend's explicit opt-in contract, while the\n * bundle verdict proves the target can actually persist claims. Either absence\n * deliberately preserves the legacy probe-then-claim protocol.\n */\nexport function edgeCardinalityClaimMode(\n backend: ClaimModeTarget,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n):\n | Readonly<{\n kind: \"guarded\";\n claim: NonNullable<GraphBackend[\"claimEdgeCardinalityGuarded\"]>;\n }>\n | Readonly<{\n kind: \"probeThenClaim\";\n support: ReturnType<typeof claimSupport>;\n }> {\n const support = claimSupport(backend, verdict);\n const guardedClaim = backend.claimEdgeCardinalityGuarded;\n return !support.supported || guardedClaim === undefined ?\n { kind: \"probeThenClaim\", support }\n : { kind: \"guarded\", claim: guardedClaim };\n}\n\n/**\n * Issues ONE edge cardinality claim against the object the row write goes to,\n * refusing with the declared error when a live incumbent holds the axis.\n *\n * A backend that declares no claim support writes no claim and keeps exactly\n * the fence it has today (the per-graph write lock around the probe) — a\n * declared gap with a parity-matrix row, never a silent unfencing and never a\n * new refusal.\n */\nexport async function claimEdgeCardinality(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n claim: ClaimEdgeCardinalityParams,\n): Promise<void> {\n const mode = edgeCardinalityClaimMode(backend, verdict);\n if (mode.kind === \"guarded\") {\n const outcome = await withEdgeClaimRelationPrecondition(claim.graphId, () =>\n mode.claim(claim),\n );\n if (outcome.status === \"refused\") {\n throw edgeCardinalityClaimRefusal(claim);\n }\n return;\n }\n const support = mode.support;\n if (!support.supported) return;\n const outcome = await withEdgeClaimRelationPrecondition(claim.graphId, () =>\n support.claims.claimEdgeCardinality(claim),\n );\n if (outcome.status === \"refused\") throw edgeCardinalityClaimRefusal(claim);\n}\n\n/**\n * Issues a batch's claims as ONE statement, entries sorted by\n * {@link compareClaimTargets}.\n *\n * One statement takes its row locks in a fixed order, so a batch cannot\n * deadlock against itself; sorting is what stops two writers of the same two\n * axes from taking them in opposite orders. In-batch duplicates are refused\n * before this by the batch validation wrapper's pending-cardinality state, so\n * the backend's duplicate-conflict-target guard stays a defensive invariant.\n */\nexport async function claimEdgeCardinalityBatch(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n claims: readonly ClaimEdgeCardinalityParams[],\n): Promise<void> {\n if (claims.length === 0) return;\n const support = claimSupport(backend, verdict);\n if (!support.supported) return;\n const ordered = claims\n .map((claim) => ({ claim, target: edgeCardinalityClaimTarget(claim) }))\n .toSorted((left, right) => compareClaimTargets(left.target, right.target));\n const graphId = ordered[0]?.claim.graphId ?? \"\";\n const outcomes = await withEdgeClaimRelationPrecondition(graphId, () =>\n support.claims.claimEdgeCardinalityBatch(\n ordered.map((entry) => entry.claim),\n ),\n );\n for (const [index, outcome] of outcomes.entries()) {\n const entry = ordered[index];\n if (entry !== undefined && outcome.status === \"refused\") {\n throw edgeCardinalityClaimRefusal(entry.claim);\n }\n }\n}\n\n/**\n * Housekeeping: drops the claim rows named edges held.\n *\n * Never a fence and never load-bearing — a claim whose holder is gone already\n * fails the takeover statement's liveness predicate, so the axis is reusable\n * whether or not this ran. It exists so a hard delete does not leave a row\n * behind forever. A backend without claim support has nothing to purge.\n */\nexport async function purgeEdgeClaims(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n graphId: string,\n edgeIds: readonly string[],\n): Promise<void> {\n if (edgeIds.length === 0) return;\n const support = claimSupport(backend, verdict);\n if (!support.supported) return;\n await withEdgeClaimRelationPrecondition(graphId, () =>\n support.claims.purgeEdgeClaims({ graphId, edgeIds }),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/store/claims/backing.ts","../src/store/claims/edge-claims.ts"],"names":["claimsMembers","edgeCardinalityAxis","encodeTupleKey","checkUniqueEdge","checkCardinality","CardinalityError","ConfigurationError","isMissingTableError","outcome","compareClaimTargets"],"mappings":";;;;;;;AAiHO,SAAS,YAAA,CACd,QAGA,OAAA,EACc;AACd,EAAA,IAAI,CAAC,OAAA,CAAQ,SAAA,EAAW,OAAO,EAAE,WAAW,KAAA,EAAM;AAClD,EAAA,OAAO,EAAE,SAAA,EAAW,IAAA,EAAM,QAAQA,+BAAA,CAAc,MAAA,EAAQ,OAAO,CAAA,EAAE;AACnE;;;AC1DO,IAAM,sBAAA,GAAyB;AAAA,EACpC,KAAK,EAAE,QAAA,EAAU,QAAQ,mBAAA,EAAqB,IAAA,EAAM,gBAAgB,MAAA,EAAO;AAAA,EAC3E,MAAA,EAAQ;AAAA,IACN,QAAA,EAAU,WAAA;AAAA,IACV,mBAAA,EAAqB,IAAA;AAAA,IACrB,cAAA,EAAgB;AAAA,GAClB;AAAA,EACA,SAAA,EAAW;AAAA,IACT,QAAA,EAAU,MAAA;AAAA,IACV,mBAAA,EAAqB,KAAA;AAAA,IACrB,cAAA,EAAgB;AAAA;AAEpB;AAGO,SAAS,2BACd,QAAA,EACmB;AACnB,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,sBAAsB,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,WAAA,KAC9CC,qCAAA,CAAoB,WAAA,EAAa,QAAQ;AAAA,GAC3C;AACF;AAWO,SAAS,2BACd,MAAA,EACa;AACb,EAAA,MAAM,IAAA,GAAO,sBAAA,CAAuB,MAAA,CAAO,WAAW,CAAA;AACtD,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,YAAA;AAAA,IACV,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,IAAA,EAAMA,qCAAA,CAAoB,MAAA,CAAO,WAAA,EAAa,OAAO,QAAQ,CAAA;AAAA,IAC7D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AAAA,MACb,OAAA,CAAQ,GAAA,CAAI,CAAC,KAAA,KAAU,MAAM,KAAK;AAAA;AACpC,GACF;AACA,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,OAAO,CAAA,IAAK,QAAA,CAAS,SAAQ,EAAG;AACjD,IAAA,MAAM,KAAA,GAAQ,QAAQ,KAAK,CAAA;AAC3B,IAAA,IAAI,KAAA,KAAU,MAAA,IAAa,OAAA,CAAQ,MAAA,KAAW,SAAA,EAAW;AACvD,MAAA,MAAM,2BAAA,CAA4B,MAAM,KAAK,CAAA;AAAA,IAC/C;AAAA,EACF;AACF;AAUA,eAAsB,eAAA,CACpB,OAAA,EACA,OAAA,EACA,OAAA,EACA,OAAA,EACe;AACf,EAAA,IAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC1B,EAAA,MAAM,OAAA,GAAU,YAAA,CAAa,OAAA,EAAS,OAAO,CAAA;AAC7C,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AACxB,EAAA,MAAM,iCAAA;AAAA,IAAkC,OAAA;AAAA,IAAS,MAC/C,OAAA,CAAQ,MAAA,CAAO,gBAAgB,EAAE,OAAA,EAAS,SAAS;AAAA,GACrD;AACF","file":"chunk-G7OKJDMG.cjs","sourcesContent":["/**\n * What backs each constraint fence class.\n *\n * A constrained write is fenced by one of two things: a per-graph lock that\n * serializes the probe with the write it guards, or a CLAIM row whose primary\n * key refuses a second claimant outright. The second is strictly stronger — it\n * holds without a lock, which is what an import needs — and this module records\n * which class has reached it, so \"is this fence a lock or a key?\" is answered\n * from one table rather than inferred from whichever module a reader lands in.\n *\n * It also owns the runtime half of the same question — {@link claimSupport},\n * the one reader of \"can THIS object hold a claim?\" — so the declaration and\n * the surface are reconciled in one place rather than at each claim site.\n * `claimSupport` is now a thin binder over the `claims` capability bundle\n * (`backend/capabilities`): the bidirectional declaration/surface cross-check\n * lives once in `resolve.ts`'s `assertClaimsBidirectionalAgreement`, reached\n * through the verdict every caller threads in, and this module owns only the\n * per-write port bind (`claimsMembers`) and this decision's shape.\n */\nimport {\n type BundleBinding,\n claimsMembers,\n} from \"../../backend/capabilities/bind\";\nimport type { CLAIMS } from \"../../backend/capabilities/bundle-registry\";\nimport { type BundleVerdictOf } from \"../../backend/capabilities/resolve\";\nimport { type GraphBackend } from \"../../backend/types\";\n\n/**\n * The runtime extent of the fence classes. {@link ConstraintFenceReason} is\n * DERIVED from it rather than declared beside it: a union type has no runtime\n * extent, so a totality test over a map keyed by the union could only iterate\n * that map's own keys and would be trivially true.\n */\nexport const CONSTRAINT_FENCE_REASONS = [\n \"edgeCardinality\",\n \"edgeMatchKeyConvergence\",\n \"nodeDisjointness\",\n \"nodeUniquenessClaim\",\n \"nodeUniquenessScope\",\n] as const;\n\n/**\n * WHICH declared constraint makes a write constrained.\n *\n * The classification names the reason rather than answering yes/no, because\n * the reason is load-bearing twice over: it is what the fence is taken FOR, and\n * — on a backend that cannot hold the fence — it is what the refusal has to\n * tell the caller. \"This backend cannot fence constrained writes\" is unusable\n * advice; \"your `cardinality: 'one'` edge cannot be enforced here\" is\n * actionable, and only the classifier knows which it was.\n */\nexport type ConstraintFenceReason = (typeof CONSTRAINT_FENCE_REASONS)[number];\n\n/** The relation whose key fences a class, or `lockOnly` when nothing does yet. */\ntype ConstraintFenceBacking = \"uniques\" | \"edgeClaims\" | \"lockOnly\";\n\n/**\n * Which claim relation backs each fence class. The `satisfies` forces totality:\n * a new reason cannot be added without stating what backs it.\n *\n * `nodeUniquenessScope` is `\"uniques\"` because a shared-scope claim is now\n * written at the scope's axis, so two writers of two kinds in one hierarchy\n * contend for one row. `nodeUniquenessClaim` is the same relation seen from the\n * other side: the claim row is the fence, and the class exists because a write\n * that must issue it BEFORE the row it gates needs a transaction to undo the\n * pair together — which is what its refusal names. `nodeDisjointness` is the\n * same relation again, at a third kind of axis: a claim keyed on the declared\n * PAIR and on the node's id, which is the axis disjointness actually declares\n * and the one the nodes primary key `(graph_id, kind, id)` cannot fence.\n * `edgeCardinality` is the other relation: a claim keyed on\n * `(<cardinality>:<edgeKind>, endpoint identity)`, which is the axis the\n * declaration actually spans and the one the edges primary key `(graph_id, id)`\n * cannot fence. The classes still marked `lockOnly` are fenced by the per-graph\n * write lock alone, which is why they are also the classes a non-transactional\n * backend refuses.\n */\nexport const CONSTRAINT_FENCE_BACKING = {\n edgeCardinality: \"edgeClaims\",\n edgeMatchKeyConvergence: \"lockOnly\",\n nodeDisjointness: \"uniques\",\n nodeUniquenessClaim: \"uniques\",\n nodeUniquenessScope: \"uniques\",\n} as const satisfies Record<ConstraintFenceReason, ConstraintFenceBacking>;\n\n/** The decision {@link claimSupport} returns — never a flag a caller re-derives. */\nexport type ClaimSupport =\n /** Capability declared AND every claim member present: the members, bound off the port. */\n | Readonly<{\n supported: true;\n claims: BundleBinding<(typeof CLAIMS)[\"core\"][number]>;\n }>\n /** Capability absent or false AND no claim member present: the declared gap. */\n | Readonly<{ supported: false }>;\n\n/**\n * THE one reader of \"can this object hold a claim?\", asked about the object the\n * claim is about to be written to.\n *\n * Takes the bundle's VERDICT — resolved once, against `GraphBackend`, by the\n * caller's `ClaimsVerdictThunk` (ruling B1/B7) — rather than resolving it\n * itself: the declaration/surface cross-check\n * (`resolve.ts`'s `assertClaimsBidirectionalAgreement`) runs exactly once,\n * inside that resolution, and this function never re-derives it. What this\n * function still owns is the PER-WRITE bind: `claimsMembers` (`bind.ts`) binds\n * the verdict's named members off `target` — the object the write actually\n * executes on, which may be a `TransactionBackend` the verdict was never\n * resolved against — and throws the bundle's port-surface code\n * (`CONSTRAINT_CLAIM_SURFACE_MISMATCH`) if `target` disagrees with what the\n * verdict says is present.\n *\n * @throws ConfigurationError (`CONSTRAINT_CLAIM_SURFACE_MISMATCH`) when\n * `target` is missing a member the verdict says is present.\n */\nexport function claimSupport(\n target: Readonly<\n Partial<Pick<GraphBackend, (typeof CLAIMS)[\"core\"][number]>>\n >,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n): ClaimSupport {\n if (!verdict.supported) return { supported: false };\n return { supported: true, claims: claimsMembers(target, verdict) };\n}\n","/**\n * Edge claims — what an edge write reserves on a declared cardinality axis.\n *\n * A declared cardinality is a predicate over `(kind, from)` or\n * `(kind, from, to)`, and the edges relation's only uniqueness is its\n * `(graph_id, id)` primary key, so nothing in the schema re-decides at write\n * time what the probe decided at read time. This module is the reservation that\n * does: one row per `(graph_id, axis, key)` in `typegraph_edge_claims`, whose\n * primary key refuses a second concurrent claimant.\n *\n * The claim needs no release path. A claim whose holder is no longer live (or,\n * for `oneActive`, no longer active) fails the liveness predicate the takeover\n * statement carries and is taken over in place, so the fence never depends on\n * any delete path having run. `purgeEdgeClaims` exists to bound table growth,\n * not to make the fence correct.\n */\nimport type { CLAIMS } from \"../../backend/capabilities/bundle-registry\";\nimport { type BundleVerdictOf } from \"../../backend/capabilities/resolve\";\nimport {\n type ClaimEdgeCardinalityParams,\n type GraphBackend,\n type InsertEdgeParams,\n} from \"../../backend/types\";\nimport { checkCardinality, checkUniqueEdge } from \"../../constraints\";\nimport { type Cardinality } from \"../../core/types\";\nimport { CardinalityError, ConfigurationError } from \"../../errors\";\nimport { isMissingTableError } from \"../../utils/sql-errors\";\nimport { encodeTupleKey } from \"../../utils/tuple-key\";\nimport {\n type ClaimTarget,\n compareClaimTargets,\n edgeCardinalityAxis,\n} from \"./axis\";\nimport { claimSupport } from \"./backing\";\n\n/** A cardinality that declares something — `many` declares nothing. */\nexport type ConstrainedCardinality = Exclude<Cardinality, \"many\">;\n\n/**\n * What one declared cardinality means to every layer that has to agree about\n * it: which endpoints its axis key covers, whether an edge born already ended\n * claims at all, and what a holder must still BE for its claim to stand.\n */\nexport type EdgeCardinalitySpec = Readonly<{\n /** Which endpoints the axis key covers. */\n keyShape: \"from\" | \"fromAndTo\";\n /** Whether a new edge that is born ENDED makes a claim at all. */\n claimsWhenBornEnded: boolean;\n /** What a holder must still be for its claim to stand. */\n holderLiveness: \"live\" | \"liveAndActive\";\n}>;\n\n/**\n * THE table both renderers of the cardinality predicate read: the TypeScript\n * probe ({@link file://../constraints.ts checkCardinalityConstraint}) and the\n * SQL takeover statement\n * ({@link file://../../backend/drizzle/operations/edge-claims.ts}).\n *\n * Two renderers, one table, exhaustive by type: a new cardinality cannot be\n * added without stating all three facts, and the probe and the fence cannot\n * disagree about any of them — a disagreement is exactly the shape where the\n * probe accepts a write the fence then refuses forever (or the reverse).\n */\nexport const EDGE_CARDINALITY_SPECS = {\n one: { keyShape: \"from\", claimsWhenBornEnded: true, holderLiveness: \"live\" },\n unique: {\n keyShape: \"fromAndTo\",\n claimsWhenBornEnded: true,\n holderLiveness: \"live\",\n },\n oneActive: {\n keyShape: \"from\",\n claimsWhenBornEnded: false,\n holderLiveness: \"liveAndActive\",\n },\n} as const satisfies Record<ConstrainedCardinality, EdgeCardinalitySpec>;\n\n/** Every axis an edge kind's claims can sit on, for housekeeping reaps. */\nexport function edgeCardinalityAxesForKind(\n edgeKind: string,\n): readonly string[] {\n return Object.keys(EDGE_CARDINALITY_SPECS).map((cardinality) =>\n edgeCardinalityAxis(cardinality, edgeKind),\n );\n}\n\n/**\n * THE claim row one edge write reserves: its axis, and the endpoint identity\n * the axis is keyed by.\n *\n * The key is {@link encodeTupleKey}, not a delimiter join: node ids are\n * arbitrary caller data (only kind names pass `assertClaimAxisSafe`), and a\n * delimiter that a value may contain makes two different endpoint tuples\n * collapse onto one key — which would refuse a write no constraint forbids.\n */\nexport function edgeCardinalityClaimTarget(\n params: ClaimEdgeCardinalityParams,\n): ClaimTarget {\n const spec = EDGE_CARDINALITY_SPECS[params.cardinality];\n return {\n relation: \"edgeClaims\",\n graphId: params.graphId,\n axis: edgeCardinalityAxis(params.cardinality, params.edgeKind),\n key:\n spec.keyShape === \"from\" ?\n encodeTupleKey([params.fromKind, params.fromId])\n : encodeTupleKey([\n params.fromKind,\n params.fromId,\n params.toKind,\n params.toId,\n ]),\n };\n}\n\n/**\n * The fields a claim is decided from: the row's identity and the upper bound\n * that decides whether it joins an active-only population. Narrower than\n * {@link InsertEdgeParams} on purpose — a resurrect has no insert params to\n * hand over, and passing an invented `props` to satisfy a type would be a\n * fabricated value a reader has to check is unread.\n */\nexport type EdgeClaimSubject = Pick<\n InsertEdgeParams,\n \"graphId\" | \"id\" | \"kind\" | \"fromKind\" | \"fromId\" | \"toKind\" | \"toId\"\n> &\n Readonly<{ validTo?: string }>;\n\n/**\n * THE claim an edge insert owes, or `undefined` when it owes none.\n *\n * `many` declares no constraint, and an `oneActive` edge born already ended\n * joins no active population — `claimsWhenBornEnded` is the one place that\n * second exemption is written down, and the probe reads the same field, so the\n * two cannot drift into \"probed but unclaimed\" (a silent hole) or \"claimed but\n * unprobed\" (a refusal with no matching error).\n */\nexport function edgeCardinalityClaim(\n cardinality: Cardinality,\n subject: EdgeClaimSubject,\n): ClaimEdgeCardinalityParams | undefined {\n if (cardinality === \"many\") return undefined;\n if (\n !EDGE_CARDINALITY_SPECS[cardinality].claimsWhenBornEnded &&\n subject.validTo !== undefined\n ) {\n return undefined;\n }\n return {\n graphId: subject.graphId,\n cardinality,\n edgeKind: subject.kind,\n edgeId: subject.id,\n fromKind: subject.fromKind,\n fromId: subject.fromId,\n toKind: subject.toKind,\n toId: subject.toId,\n };\n}\n\n/**\n * The refusal a lost claim raises — built by the SAME owners the probe calls,\n * so the fence's error is `instanceof` the same class and carries the same\n * payload as the probe's for the same violation (I3).\n */\n/**\n * Builds the public cardinality refusal for a claim decision.\n *\n * Both the ordinary claim path and the fused claim-plus-edge path call this\n * owner. Keeping the translation here prevents a backend result discriminator\n * from growing a second spelling of the same typed error.\n */\nexport function edgeCardinalityClaimRefusal(\n params: ClaimEdgeCardinalityParams,\n): CardinalityError {\n const error =\n params.cardinality === \"unique\" ?\n checkUniqueEdge(\n params.edgeKind,\n params.fromKind,\n params.fromId,\n params.toKind,\n params.toId,\n 1,\n )\n : checkCardinality(\n params.edgeKind,\n params.fromKind,\n params.fromId,\n params.cardinality,\n 1,\n true,\n );\n // Both owners refuse for an incumbent count of one on every constrained\n // cardinality; the fallback keeps the return type honest without inventing a\n // second spelling of the message.\n return (\n error ??\n new CardinalityError({\n edgeKind: params.edgeKind,\n fromKind: params.fromKind,\n fromId: params.fromId,\n cardinality: params.cardinality,\n existingCount: 1,\n })\n );\n}\n\n/**\n * Converts the engine's \"relation does not exist\" into a typed precondition\n * error naming the relation and the way to create it.\n *\n * Checked at FIRST USE rather than at store construction: a graph with no\n * constrained edge kind never issues a claim and must not pay a catalog read\n * for a relation it will never touch. A database bootstrapped before this\n * relation existed reaches it here, on the first constrained edge write, with\n * an error that says what to run instead of an opaque driver failure.\n */\nexport function edgeClaimRelationMissing(\n graphId: string,\n cause: unknown,\n): ConfigurationError {\n return new ConfigurationError(\n \"Enforcing a declared edge cardinality needs the edge claim relation \" +\n \"(typegraph_edge_claims), and this database does not have it. \" +\n \"Databases initialized before this relation existed were never sent \" +\n \"its CREATE TABLE, because the bootstrap DDL runs only on first boot.\",\n { code: \"EDGE_CLAIM_RELATION_MISSING\", graphId },\n {\n cause,\n suggestion:\n \"Run the generated migration SQL (generatePostgresMigrationSQL / \" +\n \"generateSqliteMigrationSQL) against this database, or declare the \" +\n 'edge kind `cardinality: \"many\"` and enforce the limit in ' +\n \"application code.\",\n },\n );\n}\n\nasync function withEdgeClaimRelationPrecondition<T>(\n graphId: string,\n issue: () => Promise<T>,\n): Promise<T> {\n try {\n return await issue();\n } catch (error) {\n if (!isMissingTableError(error)) throw error;\n throw edgeClaimRelationMissing(graphId, error);\n }\n}\n\ntype ClaimModeTarget = Readonly<\n Partial<\n Pick<\n GraphBackend,\n (typeof CLAIMS)[\"core\"][number] | \"claimEdgeCardinalityGuarded\"\n >\n >\n>;\n\n/** The narrow backend facet an edge claim is written through. */\ntype ClaimTargetMembers = ClaimModeTarget;\n\n/**\n * The one owner of whether a single write may replace its entity probe with a\n * guarded claim. Both claim-bundle support and the optional strong member are\n * required: the member is the backend's explicit opt-in contract, while the\n * bundle verdict proves the target can actually persist claims. Either absence\n * deliberately preserves the legacy probe-then-claim protocol.\n */\nexport function edgeCardinalityClaimMode(\n backend: ClaimModeTarget,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n):\n | Readonly<{\n kind: \"guarded\";\n claim: NonNullable<GraphBackend[\"claimEdgeCardinalityGuarded\"]>;\n }>\n | Readonly<{\n kind: \"probeThenClaim\";\n support: ReturnType<typeof claimSupport>;\n }> {\n const support = claimSupport(backend, verdict);\n const guardedClaim = backend.claimEdgeCardinalityGuarded;\n return !support.supported || guardedClaim === undefined ?\n { kind: \"probeThenClaim\", support }\n : { kind: \"guarded\", claim: guardedClaim };\n}\n\n/**\n * Issues ONE edge cardinality claim against the object the row write goes to,\n * refusing with the declared error when a live incumbent holds the axis.\n *\n * A backend that declares no claim support writes no claim and keeps exactly\n * the fence it has today (the per-graph write lock around the probe) — a\n * declared gap with a parity-matrix row, never a silent unfencing and never a\n * new refusal.\n */\nexport async function claimEdgeCardinality(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n claim: ClaimEdgeCardinalityParams,\n): Promise<void> {\n const mode = edgeCardinalityClaimMode(backend, verdict);\n if (mode.kind === \"guarded\") {\n const outcome = await withEdgeClaimRelationPrecondition(claim.graphId, () =>\n mode.claim(claim),\n );\n if (outcome.status === \"refused\") {\n throw edgeCardinalityClaimRefusal(claim);\n }\n return;\n }\n const support = mode.support;\n if (!support.supported) return;\n const outcome = await withEdgeClaimRelationPrecondition(claim.graphId, () =>\n support.claims.claimEdgeCardinality(claim),\n );\n if (outcome.status === \"refused\") throw edgeCardinalityClaimRefusal(claim);\n}\n\n/**\n * Issues a batch's claims as ONE statement, entries sorted by\n * {@link compareClaimTargets}.\n *\n * One statement takes its row locks in a fixed order, so a batch cannot\n * deadlock against itself; sorting is what stops two writers of the same two\n * axes from taking them in opposite orders. In-batch duplicates are refused\n * before this by the batch validation wrapper's pending-cardinality state, so\n * the backend's duplicate-conflict-target guard stays a defensive invariant.\n */\nexport async function claimEdgeCardinalityBatch(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n claims: readonly ClaimEdgeCardinalityParams[],\n): Promise<void> {\n if (claims.length === 0) return;\n const support = claimSupport(backend, verdict);\n if (!support.supported) return;\n const ordered = claims\n .map((claim) => ({ claim, target: edgeCardinalityClaimTarget(claim) }))\n .toSorted((left, right) => compareClaimTargets(left.target, right.target));\n const graphId = ordered[0]?.claim.graphId ?? \"\";\n const outcomes = await withEdgeClaimRelationPrecondition(graphId, () =>\n support.claims.claimEdgeCardinalityBatch(\n ordered.map((entry) => entry.claim),\n ),\n );\n for (const [index, outcome] of outcomes.entries()) {\n const entry = ordered[index];\n if (entry !== undefined && outcome.status === \"refused\") {\n throw edgeCardinalityClaimRefusal(entry.claim);\n }\n }\n}\n\n/**\n * Housekeeping: drops the claim rows named edges held.\n *\n * Never a fence and never load-bearing — a claim whose holder is gone already\n * fails the takeover statement's liveness predicate, so the axis is reusable\n * whether or not this ran. It exists so a hard delete does not leave a row\n * behind forever. A backend without claim support has nothing to purge.\n */\nexport async function purgeEdgeClaims(\n backend: ClaimTargetMembers,\n verdict: BundleVerdictOf<typeof CLAIMS>,\n graphId: string,\n edgeIds: readonly string[],\n): Promise<void> {\n if (edgeIds.length === 0) return;\n const support = claimSupport(backend, verdict);\n if (!support.supported) return;\n await withEdgeClaimRelationPrecondition(graphId, () =>\n support.claims.purgeEdgeClaims({ graphId, edgeIds }),\n );\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_LOCAL_SQLITE_PRAGMAS } from './chunk-H4FY6OZK.js';
|
|
2
|
-
import { assertNoLegacyTransactionCapability, tables2, createSqliteBackend, CURRENT_BASE_SCHEMA_VERSION, generateSqliteMigrationSQL, quoteDdlIdentifier, planSqliteEdgeMatchIdentityAdoption } from './chunk-
|
|
2
|
+
import { assertNoLegacyTransactionCapability, tables2, createSqliteBackend, CURRENT_BASE_SCHEMA_VERSION, generateSqliteMigrationSQL, quoteDdlIdentifier, planSqliteEdgeMatchIdentityAdoption } from './chunk-MUEPEWMQ.js';
|
|
3
3
|
import { sqliteVecStrategy } from './chunk-JVWXWAV5.js';
|
|
4
|
-
import { markBundledRootAutocommitEligible } from './chunk-
|
|
5
|
-
import { wrapWithManagedClose, isSqliteMissingEdgeMatchIdentityColumnError, isSqliteDuplicateEdgeMatchIdentityColumnError } from './chunk-
|
|
4
|
+
import { markBundledRootAutocommitEligible } from './chunk-6ECNYQDW.js';
|
|
5
|
+
import { wrapWithManagedClose, isSqliteMissingEdgeMatchIdentityColumnError, isSqliteDuplicateEdgeMatchIdentityColumnError } from './chunk-TU22BFMP.js';
|
|
6
6
|
import { ConfigurationError, CompilerInvariantError } from './chunk-GMKPIYHY.js';
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import Database from 'better-sqlite3';
|
|
@@ -206,5 +206,5 @@ function tryLoadSqliteVec(sqlite) {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
export { createLocalSqliteBackend };
|
|
209
|
-
//# sourceMappingURL=chunk-
|
|
210
|
-
//# sourceMappingURL=chunk-
|
|
209
|
+
//# sourceMappingURL=chunk-HSLP6CVG.js.map
|
|
210
|
+
//# sourceMappingURL=chunk-HSLP6CVG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/backend/sqlite/local.ts"],"names":["tables"],"mappings":";;;;;;;;;;;AAiFA,IAAM,WAAA,GAAc,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAEjD,SAAS,4BAAA,CACP,MAAA,EACAA,OAAAA,EACA,gBAAA,EACM;AAUN,EAAA,IAAI,gCAAgC,CAAA,EAAG;AACrC,IAAA,MAAM,IAAI,sBAAA;AAAA,MACR,sGAAA;AAAA,MACA,EAAE,gBAAgB,2BAAA;AAA4B,KAChD;AAAA,EACF;AACA,EAAA,MAAM,eAAA,GAAkB,0BAAA,CAA2BA,OAAAA,EAAQ,gBAAgB,CAAA;AAC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,IAAA,IACZ,UAAU,OAAA,IACV,OAAO,OAAA,CAAQ,IAAA,KAAS,UAAA,EACxB;AACA,MAAC,OAAA,CAAsD,KAAK,MAAM,CAAA;AAClE,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF","file":"chunk-VZRXXABW.js","sourcesContent":["/**\n * Local SQLite backend using better-sqlite3.\n *\n * This module depends on the `better-sqlite3` native addon and should only\n * be imported in Node.js environments. For bundler-friendly SQLite DDL\n * generation and Drizzle backend creation, import from `@nicia-ai/typegraph/adapters/drizzle/sqlite`.\n *\n * @example In-memory database (default)\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/sqlite/local\";\n *\n * const { backend, db } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database for persistent local development\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/sqlite/local\";\n *\n * const { backend, db } = createLocalSqliteBackend({ path: \"./dev.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nimport { createRequire } from \"node:module\";\n\nimport Database from \"better-sqlite3\";\nimport { getTableName } from \"drizzle-orm\";\nimport {\n type BetterSQLite3Database,\n drizzle,\n} from \"drizzle-orm/better-sqlite3\";\n\nimport { CompilerInvariantError, ConfigurationError } from \"../../errors\";\nimport { type FulltextStrategy } from \"../../query/dialect/fulltext-strategy\";\nimport { sqliteVecStrategy } from \"../../query/dialect/vector/sqlite-vec-strategy\";\nimport {\n isSqliteDuplicateEdgeMatchIdentityColumnError,\n isSqliteMissingEdgeMatchIdentityColumnError,\n} from \"../../utils/sql-errors\";\nimport { markBundledRootAutocommitEligible } from \"../capabilities/autocommit-single-statement\";\nimport { wrapWithManagedClose } from \"../derive-backend\";\nimport { CURRENT_BASE_SCHEMA_VERSION } from \"../drizzle/base-schema\";\nimport {\n generateSqliteMigrationSQL,\n planSqliteEdgeMatchIdentityAdoption,\n quoteDdlIdentifier,\n} from \"../drizzle/ddl\";\nimport { type AnySqliteDatabase } from \"../drizzle/execution\";\nexport type { AnySqliteDatabase } from \"../drizzle/execution\";\nimport { assertNoLegacyTransactionCapability } from \"../capabilities/declarations\";\nimport {\n createSqliteBackend,\n type SqliteTables,\n tables as defaultTables,\n} from \"../drizzle/sqlite\";\nimport {\n DEFAULT_LOCAL_SQLITE_PRAGMAS,\n type LocalSqliteJournalMode,\n type LocalSqlitePragmaOptions,\n type LocalSqliteSynchronousMode,\n} from \"./local-options\";\n\nexport {\n DEFAULT_LOCAL_SQLITE_PRAGMAS,\n type LocalSqliteJournalMode,\n type LocalSqlitePragmaOptions,\n type LocalSqliteSynchronousMode,\n} from \"./local-options\";\nimport {\n type AdapterBackend,\n type BundledBackendCapabilityOverrides,\n type SchemaProvisioning,\n} from \"../types\";\nexport type { BundledBackendCapabilityOverrides } from \"../types\";\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../types\";\n\nconst nodeRequire = createRequire(import.meta.url);\n\nfunction installLocalSqliteBaseSchema(\n sqlite: Database.Database,\n tables: SqliteTables,\n fulltextStrategy: FulltextStrategy | false | undefined,\n): void {\n // v2 (the fences relation) and v3 (the recorded-relations' and recorded\n // identity-assertions relation's `since_idx` indexes) need no adoption\n // logic beyond what `generateSqliteMigrationSQL` already emits: a\n // brand-new relation or index is fully covered by its own `CREATE TABLE\n // IF NOT EXISTS` / `CREATE INDEX IF NOT EXISTS`, on both a fresh database\n // and one that already has every OTHER base table or index. Only v1's\n // edge-match-identity `ADD COLUMN` migration — handled by the catch block\n // below — needed runtime introspection this synchronous path writes by\n // hand instead of running `BaseSchemaLifecycle`'s async state machine.\n if (CURRENT_BASE_SCHEMA_VERSION !== 3) {\n throw new CompilerInvariantError(\n \"The synchronous managed SQLite installation path only implements base-schema v1 through v3 adoption.\",\n { currentVersion: CURRENT_BASE_SCHEMA_VERSION },\n );\n }\n const installationSql = generateSqliteMigrationSQL(tables, fulltextStrategy);\n try {\n sqlite.exec(installationSql);\n } catch (error) {\n if (!isSqliteMissingEdgeMatchIdentityColumnError(error)) throw error;\n const edgeTableName = getTableName(tables.edges);\n for (let attempt = 0; attempt < 3; attempt += 1) {\n const rows = sqlite\n .prepare(`PRAGMA table_info(${quoteDdlIdentifier(edgeTableName)})`)\n .all() as readonly Readonly<{ name?: unknown }>[];\n const columns = new Set(\n rows.flatMap((row) => (typeof row.name === \"string\" ? [row.name] : [])),\n );\n const adoptionSql = planSqliteEdgeMatchIdentityAdoption(\n edgeTableName,\n columns,\n );\n try {\n sqlite.exec([...adoptionSql, installationSql].join(\"\\n\"));\n return;\n } catch (repairError) {\n if (\n attempt === 2 ||\n !isSqliteDuplicateEdgeMatchIdentityColumnError(repairError)\n ) {\n throw repairError;\n }\n }\n }\n throw new CompilerInvariantError(\n \"Local SQLite match-identity adoption exhausted its retry loop without returning or throwing.\",\n );\n }\n}\n\n// ============================================================\n// Native Addon Helpers\n// ============================================================\n\ntype NodeModuleVersionMismatch = Readonly<{\n compiled: number;\n required: number;\n}>;\n\nfunction getUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nfunction parseNodeModuleVersionMismatchMessage(\n message: string,\n): NodeModuleVersionMismatch | undefined {\n const regexp =\n /NODE_MODULE_VERSION (?<compiled>\\d+)[\\s\\S]*?NODE_MODULE_VERSION (?<required>\\d+)/;\n const match = regexp.exec(message);\n if (!match?.groups) return undefined;\n\n const compiled = Number(match.groups[\"compiled\"]);\n const required = Number(match.groups[\"required\"]);\n\n if (!Number.isFinite(compiled) || !Number.isFinite(required))\n return undefined;\n\n return { compiled, required };\n}\n\nfunction createDatabase(path: string): Database.Database {\n try {\n return new Database(path);\n } catch (error) {\n const message = getUnknownErrorMessage(error);\n const mismatch = parseNodeModuleVersionMismatchMessage(message);\n if (!mismatch) throw error;\n\n throw new ConfigurationError(\n [\n \"Failed to load better-sqlite3 native addon.\",\n `It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,\n \"This usually happens after switching Node versions without rebuilding native dependencies.\",\n \"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3).\",\n ].join(\" \"),\n {\n nodeVersion: process.version,\n nodeModuleVersion: process.versions.modules,\n compiledNodeModuleVersion: mismatch.compiled,\n requiredNodeModuleVersion: mismatch.required,\n },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Types\n// ============================================================\n\nconst LOCAL_SQLITE_JOURNAL_MODES: readonly LocalSqliteJournalMode[] = [\n \"wal\",\n \"delete\",\n \"truncate\",\n \"persist\",\n \"memory\",\n \"off\",\n];\n\nconst LOCAL_SQLITE_SYNCHRONOUS_MODES: readonly LocalSqliteSynchronousMode[] = [\n \"off\",\n \"normal\",\n \"full\",\n \"extra\",\n];\n\nconst SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES = 2_147_483_647;\n\nfunction applyConnectionPragmas(\n sqlite: Database.Database,\n pragmas: LocalSqlitePragmaOptions | false | undefined,\n): void {\n if (pragmas === false) return;\n const resolved: Required<LocalSqlitePragmaOptions> = {\n ...DEFAULT_LOCAL_SQLITE_PRAGMAS,\n ...pragmas,\n };\n\n // Runtime guards mirror the compile-time unions: pragma values are spliced\n // into pragma statements, so reject anything outside the allowlists rather\n // than forwarding it to SQLite.\n if (!LOCAL_SQLITE_JOURNAL_MODES.includes(resolved.journalMode)) {\n throw new ConfigurationError(\n `Invalid journalMode pragma: ${resolved.journalMode}. ` +\n `Expected one of: ${LOCAL_SQLITE_JOURNAL_MODES.join(\", \")}.`,\n { journalMode: resolved.journalMode },\n );\n }\n if (!LOCAL_SQLITE_SYNCHRONOUS_MODES.includes(resolved.synchronous)) {\n throw new ConfigurationError(\n `Invalid synchronous pragma: ${resolved.synchronous}. ` +\n `Expected one of: ${LOCAL_SQLITE_SYNCHRONOUS_MODES.join(\", \")}.`,\n { synchronous: resolved.synchronous },\n );\n }\n if (\n !Number.isSafeInteger(resolved.busyTimeoutMs) ||\n resolved.busyTimeoutMs < 0\n ) {\n throw new ConfigurationError(\n `Invalid busyTimeoutMs pragma: ${String(resolved.busyTimeoutMs)}. ` +\n \"Expected a non-negative integer number of milliseconds.\",\n { busyTimeoutMs: resolved.busyTimeoutMs },\n );\n }\n if (\n resolved.cacheSizeKib !== undefined &&\n (!Number.isSafeInteger(resolved.cacheSizeKib) || resolved.cacheSizeKib >= 0)\n ) {\n throw new ConfigurationError(\n `Invalid cacheSizeKib pragma: ${String(resolved.cacheSizeKib)}. ` +\n \"Expected a negative safe integer — SQLite's own cache_size pragma \" +\n \"interprets a positive value as a page count, not KiB, so a caller \" +\n 'who passes e.g. 131072 meaning \"131072 KiB\" silently gets ' +\n \"131072 pages (~512MiB at the default 4KiB page size) instead.\",\n { cacheSizeKib: resolved.cacheSizeKib },\n );\n }\n if (\n resolved.mmapSizeBytes !== undefined &&\n (!Number.isSafeInteger(resolved.mmapSizeBytes) ||\n resolved.mmapSizeBytes < 0)\n ) {\n throw new ConfigurationError(\n `Invalid mmapSizeBytes pragma: ${String(resolved.mmapSizeBytes)}. ` +\n \"Expected a non-negative safe integer number of bytes.\",\n { mmapSizeBytes: resolved.mmapSizeBytes },\n );\n }\n if (\n resolved.walAutocheckpointPages !== undefined &&\n (!Number.isSafeInteger(resolved.walAutocheckpointPages) ||\n resolved.walAutocheckpointPages < 0 ||\n resolved.walAutocheckpointPages > SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES)\n ) {\n throw new ConfigurationError(\n `Invalid walAutocheckpointPages pragma: ${String(resolved.walAutocheckpointPages)}. ` +\n `Expected an integer between 0 and ${SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES} ` +\n \"WAL pages (0 disables automatic checkpointing entirely).\",\n { walAutocheckpointPages: resolved.walAutocheckpointPages },\n );\n }\n\n // \":memory:\" databases always journal in memory; SQLite answers the WAL\n // request with \"memory\" instead of erroring, so no special-casing needed.\n sqlite.pragma(`journal_mode = ${resolved.journalMode}`);\n sqlite.pragma(`synchronous = ${resolved.synchronous}`);\n sqlite.pragma(`busy_timeout = ${resolved.busyTimeoutMs}`);\n if (resolved.cacheSizeKib !== undefined) {\n sqlite.pragma(`cache_size = ${resolved.cacheSizeKib}`);\n }\n if (resolved.mmapSizeBytes !== undefined) {\n sqlite.pragma(`mmap_size = ${resolved.mmapSizeBytes}`);\n }\n if (resolved.walAutocheckpointPages !== undefined) {\n sqlite.pragma(`wal_autocheckpoint = ${resolved.walAutocheckpointPages}`);\n }\n}\n\n/**\n * Options for creating a local SQLite backend.\n */\nexport type LocalSqliteBackendOptions = Readonly<{\n schemaProvisioning?: SchemaProvisioning;\n /**\n * Path to the SQLite database file.\n * Defaults to \":memory:\" for an in-memory database.\n */\n path?: string;\n\n /**\n * Connection pragmas applied at open. Defaults to\n * {@link DEFAULT_LOCAL_SQLITE_PRAGMAS} (WAL, `synchronous=NORMAL`, 5s busy\n * timeout, and SQLite's own tiny built-in page cache / disabled mmap\n * left untouched). Individual values merge over the defaults; pass\n * `false` to skip pragma configuration entirely and keep the driver\n * defaults (rollback journal, `synchronous=FULL`, and better-sqlite3's\n * own 5s busy timeout from its `timeout` constructor option). Set\n * `cacheSizeKib`/`mmapSizeBytes` explicitly once a database's working\n * set is known to exceed SQLite's 2MiB default cache — otherwise every\n * query pays a fresh disk read per page past that tiny working set. Set\n * `walAutocheckpointPages` explicitly for a bulk-insert-heavy workload —\n * SQLite's own default checkpoints every ~4MiB of WAL growth, which gets\n * more expensive as the database file grows over a large load.\n */\n pragmas?: LocalSqlitePragmaOptions | false;\n\n /**\n * Custom table definitions.\n * Defaults to standard TypeGraph table names.\n */\n tables?: SqliteTables;\n\n /**\n * Override the fulltext strategy. Defaults to `fts5Strategy` (SQLite's\n * built-in FTS5 virtual table). Pass `false` to disable fulltext support\n * entirely — the backend then advertises no `capabilities.fulltext` and\n * omits the fulltext CRUD/search methods, and the managed installation\n * never creates the fulltext table. Forwarded to both the installation\n * DDL and `createSqliteBackend`.\n */\n fulltext?: FulltextStrategy | false;\n\n /**\n * Override specific backend capabilities — e.g. to simulate an engine-level\n * gap like missing SQL window functions in tests. Forwarded to\n * createSqliteBackend.\n */\n capabilities?: BundledBackendCapabilityOverrides;\n}>;\n\n/**\n * Result of creating a local SQLite backend.\n */\nexport type LocalSqliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore.\n */\n backend: AdapterBackend<AnySqliteDatabase>;\n\n /**\n * The underlying Drizzle database instance.\n * Useful for direct SQL access or cleanup.\n */\n db: BetterSQLite3Database;\n}>;\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a SQLite backend with minimal configuration.\n *\n * This is a convenience function for local development and testing.\n * It handles database creation, schema migration, and backend setup.\n *\n * For production deployments or custom configurations, use createSqliteBackend\n * directly with your own Drizzle database instance.\n *\n * @param options - Configuration options\n * @returns Backend and database instances\n *\n * @example In-memory database (default)\n * ```typescript\n * const { backend } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database\n * ```typescript\n * const { backend, db } = createLocalSqliteBackend({ path: \"./data.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nexport function createLocalSqliteBackend(\n options: LocalSqliteBackendOptions = {},\n): LocalSqliteBackendResult {\n assertNoLegacyTransactionCapability(options.capabilities);\n const path = options.path ?? \":memory:\";\n const tables = options.tables ?? defaultTables;\n\n const sqlite = createDatabase(path);\n try {\n applyConnectionPragmas(sqlite, options.pragmas);\n\n // Best-effort: load sqlite-vec so embedding fields are persisted to\n // per-`(kind, field)` `vec0` storage. Without it, nodes with\n // `embedding()` fields validate and insert but their vectors are silently\n // dropped. When the user has installed sqlite-vec as a peer dep we load\n // it and wire the strategy; otherwise we proceed without vector support.\n const hasSqliteVec = tryLoadSqliteVec(sqlite);\n\n const db = drizzle(sqlite);\n\n // The managed factory owns a complete fresh installation, including the\n // deployment-wide base-schema marker consumed by verified/runtime-only\n // entrypoints. Raw generateSqliteDDL intentionally omits that marker.\n installLocalSqliteBaseSchema(sqlite, tables, options.fulltext);\n\n const backend = createSqliteBackend(db, {\n ...(options.schemaProvisioning === undefined ?\n {}\n : { schemaProvisioning: options.schemaProvisioning }),\n executionProfile: {\n isSync: true,\n },\n tables,\n ...(hasSqliteVec ? { vector: sqliteVecStrategy } : {}),\n ...(options.fulltext === undefined ? {} : { fulltext: options.fulltext }),\n capabilities: {\n ...options.capabilities,\n graphAnalytics: {\n supported:\n options.capabilities?.graphAnalytics?.supported ??\n options.capabilities?.execution?.interactiveTransactions !== false,\n mathFunctions:\n options.capabilities?.graphAnalytics?.mathFunctions ?? true,\n },\n },\n });\n const managedBackend = wrapWithManagedClose(backend, () => {\n sqlite.close();\n });\n\n return { backend: markBundledRootAutocommitEligible(managedBackend), db };\n } catch (error) {\n try {\n sqlite.close();\n } catch {\n // Preserve the provisioning error; a cleanup failure is secondary.\n }\n throw error;\n }\n}\n\nfunction tryLoadSqliteVec(sqlite: Database.Database): boolean {\n try {\n // `sqlite-vec` is an optional peer dep; resolved via createRequire so\n // bundlers don't mark it as a hard import. Node resolves the package\n // only when it's actually installed.\n const module_: unknown = nodeRequire(\"sqlite-vec\");\n if (\n typeof module_ === \"object\" &&\n module_ !== null &&\n \"load\" in module_ &&\n typeof module_.load === \"function\"\n ) {\n (module_ as { load: (db: Database.Database) => void }).load(sqlite);\n return true;\n }\n return false;\n } catch {\n return false;\n }\n}\nexport type { GraphIdentityConfig } from \"../../core/define-graph\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/backend/sqlite/local.ts"],"names":["tables"],"mappings":";;;;;;;;;;;AAiFA,IAAM,WAAA,GAAc,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAEjD,SAAS,4BAAA,CACP,MAAA,EACAA,OAAAA,EACA,gBAAA,EACM;AAUN,EAAA,IAAI,gCAAgC,CAAA,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A,MAAM,KAAA;AAAA,EACR;AACF;AAEA,SAAS,iBAAiB,MAAA,EAAoC;AAC5D,EAAA,IAAI;AAIF,IAAA,MAAM,OAAA,GAAmB,YAAY,YAAY,CAAA;AACjD,IAAA,IACE,OAAO,OAAA,KAAY,QAAA,IACnB,OAAA,KAAY,IAAA,IACZ,UAAU,OAAA,IACV,OAAO,OAAA,CAAQ,IAAA,KAAS,UAAA,EACxB;AACA,MAAC,OAAA,CAAsD,KAAK,MAAM,CAAA;AAClE,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF","file":"chunk-HSLP6CVG.js","sourcesContent":["/**\n * Local SQLite backend using better-sqlite3.\n *\n * This module depends on the `better-sqlite3` native addon and should only\n * be imported in Node.js environments. For bundler-friendly SQLite DDL\n * generation and Drizzle backend creation, import from `@nicia-ai/typegraph/adapters/drizzle/sqlite`.\n *\n * @example In-memory database (default)\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/sqlite/local\";\n *\n * const { backend, db } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database for persistent local development\n * ```typescript\n * import { createLocalSqliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/sqlite/local\";\n *\n * const { backend, db } = createLocalSqliteBackend({ path: \"./dev.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nimport { createRequire } from \"node:module\";\n\nimport Database from \"better-sqlite3\";\nimport { getTableName } from \"drizzle-orm\";\nimport {\n type BetterSQLite3Database,\n drizzle,\n} from \"drizzle-orm/better-sqlite3\";\n\nimport { CompilerInvariantError, ConfigurationError } from \"../../errors\";\nimport { type FulltextStrategy } from \"../../query/dialect/fulltext-strategy\";\nimport { sqliteVecStrategy } from \"../../query/dialect/vector/sqlite-vec-strategy\";\nimport {\n isSqliteDuplicateEdgeMatchIdentityColumnError,\n isSqliteMissingEdgeMatchIdentityColumnError,\n} from \"../../utils/sql-errors\";\nimport { markBundledRootAutocommitEligible } from \"../capabilities/autocommit-single-statement\";\nimport { wrapWithManagedClose } from \"../derive-backend\";\nimport { CURRENT_BASE_SCHEMA_VERSION } from \"../drizzle/base-schema\";\nimport {\n generateSqliteMigrationSQL,\n planSqliteEdgeMatchIdentityAdoption,\n quoteDdlIdentifier,\n} from \"../drizzle/ddl\";\nimport { type AnySqliteDatabase } from \"../drizzle/execution\";\nexport type { AnySqliteDatabase } from \"../drizzle/execution\";\nimport { assertNoLegacyTransactionCapability } from \"../capabilities/declarations\";\nimport {\n createSqliteBackend,\n type SqliteTables,\n tables as defaultTables,\n} from \"../drizzle/sqlite\";\nimport {\n DEFAULT_LOCAL_SQLITE_PRAGMAS,\n type LocalSqliteJournalMode,\n type LocalSqlitePragmaOptions,\n type LocalSqliteSynchronousMode,\n} from \"./local-options\";\n\nexport {\n DEFAULT_LOCAL_SQLITE_PRAGMAS,\n type LocalSqliteJournalMode,\n type LocalSqlitePragmaOptions,\n type LocalSqliteSynchronousMode,\n} from \"./local-options\";\nimport {\n type AdapterBackend,\n type BundledBackendCapabilityOverrides,\n type SchemaProvisioning,\n} from \"../types\";\nexport type { BundledBackendCapabilityOverrides } from \"../types\";\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../types\";\n\nconst nodeRequire = createRequire(import.meta.url);\n\nfunction installLocalSqliteBaseSchema(\n sqlite: Database.Database,\n tables: SqliteTables,\n fulltextStrategy: FulltextStrategy | false | undefined,\n): void {\n // v2 (the fences relation) and v3 (the recorded-relations' and recorded\n // identity-assertions relation's `since_idx` indexes) need no adoption\n // logic beyond what `generateSqliteMigrationSQL` already emits: a\n // brand-new relation or index is fully covered by its own `CREATE TABLE\n // IF NOT EXISTS` / `CREATE INDEX IF NOT EXISTS`, on both a fresh database\n // and one that already has every OTHER base table or index. Only v1's\n // edge-match-identity `ADD COLUMN` migration — handled by the catch block\n // below — needed runtime introspection this synchronous path writes by\n // hand instead of running `BaseSchemaLifecycle`'s async state machine.\n if (CURRENT_BASE_SCHEMA_VERSION !== 3) {\n throw new CompilerInvariantError(\n \"The synchronous managed SQLite installation path only implements base-schema v1 through v3 adoption.\",\n { currentVersion: CURRENT_BASE_SCHEMA_VERSION },\n );\n }\n const installationSql = generateSqliteMigrationSQL(tables, fulltextStrategy);\n try {\n sqlite.exec(installationSql);\n } catch (error) {\n if (!isSqliteMissingEdgeMatchIdentityColumnError(error)) throw error;\n const edgeTableName = getTableName(tables.edges);\n for (let attempt = 0; attempt < 3; attempt += 1) {\n const rows = sqlite\n .prepare(`PRAGMA table_info(${quoteDdlIdentifier(edgeTableName)})`)\n .all() as readonly Readonly<{ name?: unknown }>[];\n const columns = new Set(\n rows.flatMap((row) => (typeof row.name === \"string\" ? [row.name] : [])),\n );\n const adoptionSql = planSqliteEdgeMatchIdentityAdoption(\n edgeTableName,\n columns,\n );\n try {\n sqlite.exec([...adoptionSql, installationSql].join(\"\\n\"));\n return;\n } catch (repairError) {\n if (\n attempt === 2 ||\n !isSqliteDuplicateEdgeMatchIdentityColumnError(repairError)\n ) {\n throw repairError;\n }\n }\n }\n throw new CompilerInvariantError(\n \"Local SQLite match-identity adoption exhausted its retry loop without returning or throwing.\",\n );\n }\n}\n\n// ============================================================\n// Native Addon Helpers\n// ============================================================\n\ntype NodeModuleVersionMismatch = Readonly<{\n compiled: number;\n required: number;\n}>;\n\nfunction getUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\nfunction parseNodeModuleVersionMismatchMessage(\n message: string,\n): NodeModuleVersionMismatch | undefined {\n const regexp =\n /NODE_MODULE_VERSION (?<compiled>\\d+)[\\s\\S]*?NODE_MODULE_VERSION (?<required>\\d+)/;\n const match = regexp.exec(message);\n if (!match?.groups) return undefined;\n\n const compiled = Number(match.groups[\"compiled\"]);\n const required = Number(match.groups[\"required\"]);\n\n if (!Number.isFinite(compiled) || !Number.isFinite(required))\n return undefined;\n\n return { compiled, required };\n}\n\nfunction createDatabase(path: string): Database.Database {\n try {\n return new Database(path);\n } catch (error) {\n const message = getUnknownErrorMessage(error);\n const mismatch = parseNodeModuleVersionMismatchMessage(message);\n if (!mismatch) throw error;\n\n throw new ConfigurationError(\n [\n \"Failed to load better-sqlite3 native addon.\",\n `It was compiled for NODE_MODULE_VERSION ${mismatch.compiled}, but this Node.js runtime requires ${mismatch.required}.`,\n \"This usually happens after switching Node versions without rebuilding native dependencies.\",\n \"Rebuild with: pnpm rebuild better-sqlite3 (or npm rebuild better-sqlite3).\",\n ].join(\" \"),\n {\n nodeVersion: process.version,\n nodeModuleVersion: process.versions.modules,\n compiledNodeModuleVersion: mismatch.compiled,\n requiredNodeModuleVersion: mismatch.required,\n },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Types\n// ============================================================\n\nconst LOCAL_SQLITE_JOURNAL_MODES: readonly LocalSqliteJournalMode[] = [\n \"wal\",\n \"delete\",\n \"truncate\",\n \"persist\",\n \"memory\",\n \"off\",\n];\n\nconst LOCAL_SQLITE_SYNCHRONOUS_MODES: readonly LocalSqliteSynchronousMode[] = [\n \"off\",\n \"normal\",\n \"full\",\n \"extra\",\n];\n\nconst SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES = 2_147_483_647;\n\nfunction applyConnectionPragmas(\n sqlite: Database.Database,\n pragmas: LocalSqlitePragmaOptions | false | undefined,\n): void {\n if (pragmas === false) return;\n const resolved: Required<LocalSqlitePragmaOptions> = {\n ...DEFAULT_LOCAL_SQLITE_PRAGMAS,\n ...pragmas,\n };\n\n // Runtime guards mirror the compile-time unions: pragma values are spliced\n // into pragma statements, so reject anything outside the allowlists rather\n // than forwarding it to SQLite.\n if (!LOCAL_SQLITE_JOURNAL_MODES.includes(resolved.journalMode)) {\n throw new ConfigurationError(\n `Invalid journalMode pragma: ${resolved.journalMode}. ` +\n `Expected one of: ${LOCAL_SQLITE_JOURNAL_MODES.join(\", \")}.`,\n { journalMode: resolved.journalMode },\n );\n }\n if (!LOCAL_SQLITE_SYNCHRONOUS_MODES.includes(resolved.synchronous)) {\n throw new ConfigurationError(\n `Invalid synchronous pragma: ${resolved.synchronous}. ` +\n `Expected one of: ${LOCAL_SQLITE_SYNCHRONOUS_MODES.join(\", \")}.`,\n { synchronous: resolved.synchronous },\n );\n }\n if (\n !Number.isSafeInteger(resolved.busyTimeoutMs) ||\n resolved.busyTimeoutMs < 0\n ) {\n throw new ConfigurationError(\n `Invalid busyTimeoutMs pragma: ${String(resolved.busyTimeoutMs)}. ` +\n \"Expected a non-negative integer number of milliseconds.\",\n { busyTimeoutMs: resolved.busyTimeoutMs },\n );\n }\n if (\n resolved.cacheSizeKib !== undefined &&\n (!Number.isSafeInteger(resolved.cacheSizeKib) || resolved.cacheSizeKib >= 0)\n ) {\n throw new ConfigurationError(\n `Invalid cacheSizeKib pragma: ${String(resolved.cacheSizeKib)}. ` +\n \"Expected a negative safe integer — SQLite's own cache_size pragma \" +\n \"interprets a positive value as a page count, not KiB, so a caller \" +\n 'who passes e.g. 131072 meaning \"131072 KiB\" silently gets ' +\n \"131072 pages (~512MiB at the default 4KiB page size) instead.\",\n { cacheSizeKib: resolved.cacheSizeKib },\n );\n }\n if (\n resolved.mmapSizeBytes !== undefined &&\n (!Number.isSafeInteger(resolved.mmapSizeBytes) ||\n resolved.mmapSizeBytes < 0)\n ) {\n throw new ConfigurationError(\n `Invalid mmapSizeBytes pragma: ${String(resolved.mmapSizeBytes)}. ` +\n \"Expected a non-negative safe integer number of bytes.\",\n { mmapSizeBytes: resolved.mmapSizeBytes },\n );\n }\n if (\n resolved.walAutocheckpointPages !== undefined &&\n (!Number.isSafeInteger(resolved.walAutocheckpointPages) ||\n resolved.walAutocheckpointPages < 0 ||\n resolved.walAutocheckpointPages > SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES)\n ) {\n throw new ConfigurationError(\n `Invalid walAutocheckpointPages pragma: ${String(resolved.walAutocheckpointPages)}. ` +\n `Expected an integer between 0 and ${SQLITE_MAX_WAL_AUTOCHECKPOINT_PAGES} ` +\n \"WAL pages (0 disables automatic checkpointing entirely).\",\n { walAutocheckpointPages: resolved.walAutocheckpointPages },\n );\n }\n\n // \":memory:\" databases always journal in memory; SQLite answers the WAL\n // request with \"memory\" instead of erroring, so no special-casing needed.\n sqlite.pragma(`journal_mode = ${resolved.journalMode}`);\n sqlite.pragma(`synchronous = ${resolved.synchronous}`);\n sqlite.pragma(`busy_timeout = ${resolved.busyTimeoutMs}`);\n if (resolved.cacheSizeKib !== undefined) {\n sqlite.pragma(`cache_size = ${resolved.cacheSizeKib}`);\n }\n if (resolved.mmapSizeBytes !== undefined) {\n sqlite.pragma(`mmap_size = ${resolved.mmapSizeBytes}`);\n }\n if (resolved.walAutocheckpointPages !== undefined) {\n sqlite.pragma(`wal_autocheckpoint = ${resolved.walAutocheckpointPages}`);\n }\n}\n\n/**\n * Options for creating a local SQLite backend.\n */\nexport type LocalSqliteBackendOptions = Readonly<{\n schemaProvisioning?: SchemaProvisioning;\n /**\n * Path to the SQLite database file.\n * Defaults to \":memory:\" for an in-memory database.\n */\n path?: string;\n\n /**\n * Connection pragmas applied at open. Defaults to\n * {@link DEFAULT_LOCAL_SQLITE_PRAGMAS} (WAL, `synchronous=NORMAL`, 5s busy\n * timeout, and SQLite's own tiny built-in page cache / disabled mmap\n * left untouched). Individual values merge over the defaults; pass\n * `false` to skip pragma configuration entirely and keep the driver\n * defaults (rollback journal, `synchronous=FULL`, and better-sqlite3's\n * own 5s busy timeout from its `timeout` constructor option). Set\n * `cacheSizeKib`/`mmapSizeBytes` explicitly once a database's working\n * set is known to exceed SQLite's 2MiB default cache — otherwise every\n * query pays a fresh disk read per page past that tiny working set. Set\n * `walAutocheckpointPages` explicitly for a bulk-insert-heavy workload —\n * SQLite's own default checkpoints every ~4MiB of WAL growth, which gets\n * more expensive as the database file grows over a large load.\n */\n pragmas?: LocalSqlitePragmaOptions | false;\n\n /**\n * Custom table definitions.\n * Defaults to standard TypeGraph table names.\n */\n tables?: SqliteTables;\n\n /**\n * Override the fulltext strategy. Defaults to `fts5Strategy` (SQLite's\n * built-in FTS5 virtual table). Pass `false` to disable fulltext support\n * entirely — the backend then advertises no `capabilities.fulltext` and\n * omits the fulltext CRUD/search methods, and the managed installation\n * never creates the fulltext table. Forwarded to both the installation\n * DDL and `createSqliteBackend`.\n */\n fulltext?: FulltextStrategy | false;\n\n /**\n * Override specific backend capabilities — e.g. to simulate an engine-level\n * gap like missing SQL window functions in tests. Forwarded to\n * createSqliteBackend.\n */\n capabilities?: BundledBackendCapabilityOverrides;\n}>;\n\n/**\n * Result of creating a local SQLite backend.\n */\nexport type LocalSqliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore.\n */\n backend: AdapterBackend<AnySqliteDatabase>;\n\n /**\n * The underlying Drizzle database instance.\n * Useful for direct SQL access or cleanup.\n */\n db: BetterSQLite3Database;\n}>;\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a SQLite backend with minimal configuration.\n *\n * This is a convenience function for local development and testing.\n * It handles database creation, schema migration, and backend setup.\n *\n * For production deployments or custom configurations, use createSqliteBackend\n * directly with your own Drizzle database instance.\n *\n * @param options - Configuration options\n * @returns Backend and database instances\n *\n * @example In-memory database (default)\n * ```typescript\n * const { backend } = createLocalSqliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example File-based database\n * ```typescript\n * const { backend, db } = createLocalSqliteBackend({ path: \"./data.db\" });\n * const store = createStore(graph, backend);\n * ```\n */\nexport function createLocalSqliteBackend(\n options: LocalSqliteBackendOptions = {},\n): LocalSqliteBackendResult {\n assertNoLegacyTransactionCapability(options.capabilities);\n const path = options.path ?? \":memory:\";\n const tables = options.tables ?? defaultTables;\n\n const sqlite = createDatabase(path);\n try {\n applyConnectionPragmas(sqlite, options.pragmas);\n\n // Best-effort: load sqlite-vec so embedding fields are persisted to\n // per-`(kind, field)` `vec0` storage. Without it, nodes with\n // `embedding()` fields validate and insert but their vectors are silently\n // dropped. When the user has installed sqlite-vec as a peer dep we load\n // it and wire the strategy; otherwise we proceed without vector support.\n const hasSqliteVec = tryLoadSqliteVec(sqlite);\n\n const db = drizzle(sqlite);\n\n // The managed factory owns a complete fresh installation, including the\n // deployment-wide base-schema marker consumed by verified/runtime-only\n // entrypoints. Raw generateSqliteDDL intentionally omits that marker.\n installLocalSqliteBaseSchema(sqlite, tables, options.fulltext);\n\n const backend = createSqliteBackend(db, {\n ...(options.schemaProvisioning === undefined ?\n {}\n : { schemaProvisioning: options.schemaProvisioning }),\n executionProfile: {\n isSync: true,\n },\n tables,\n ...(hasSqliteVec ? { vector: sqliteVecStrategy } : {}),\n ...(options.fulltext === undefined ? {} : { fulltext: options.fulltext }),\n capabilities: {\n ...options.capabilities,\n graphAnalytics: {\n supported:\n options.capabilities?.graphAnalytics?.supported ??\n options.capabilities?.execution?.interactiveTransactions !== false,\n mathFunctions:\n options.capabilities?.graphAnalytics?.mathFunctions ?? true,\n },\n },\n });\n const managedBackend = wrapWithManagedClose(backend, () => {\n sqlite.close();\n });\n\n return { backend: markBundledRootAutocommitEligible(managedBackend), db };\n } catch (error) {\n try {\n sqlite.close();\n } catch {\n // Preserve the provisioning error; a cleanup failure is secondary.\n }\n throw error;\n }\n}\n\nfunction tryLoadSqliteVec(sqlite: Database.Database): boolean {\n try {\n // `sqlite-vec` is an optional peer dep; resolved via createRequire so\n // bundlers don't mark it as a hard import. Node resolves the package\n // only when it's actually installed.\n const module_: unknown = nodeRequire(\"sqlite-vec\");\n if (\n typeof module_ === \"object\" &&\n module_ !== null &&\n \"load\" in module_ &&\n typeof module_.load === \"function\"\n ) {\n (module_ as { load: (db: Database.Database) => void }).load(sqlite);\n return true;\n }\n return false;\n } catch {\n return false;\n }\n}\nexport type { GraphIdentityConfig } from \"../../core/define-graph\";\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMRUOOAIQ_cjs = require('./chunk-MRUOOAIQ.cjs');
|
|
4
4
|
|
|
5
5
|
// src/backend/capabilities/autocommit-single-statement.ts
|
|
6
6
|
var BUNDLED_ROOT_AUTOCOMMIT_BACKENDS = /* @__PURE__ */ new WeakSet();
|
|
@@ -44,7 +44,7 @@ function rephaseNonTransactionalNodeClaimPlan(plan) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
function rephaseAtomicNodeClaimPlan(plan, support) {
|
|
47
|
-
if (plan.mode.kind !== "ordinary" || plan.claims.length === 0 || !
|
|
47
|
+
if (plan.mode.kind !== "ordinary" || plan.claims.length === 0 || !chunkMRUOOAIQ_cjs.supportsAtomicNodeClaims(support, plan.claims)) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
const supported = plan.claims.every((claim) => {
|
|
@@ -101,5 +101,5 @@ exports.resolvedNodeUpdateBatchFitsBindBudget = resolvedNodeUpdateBatchFitsBindB
|
|
|
101
101
|
exports.supportsNodeCreatePlan = supportsNodeCreatePlan;
|
|
102
102
|
exports.supportsNodeInsertProjectionRequirements = supportsNodeInsertProjectionRequirements;
|
|
103
103
|
exports.supportsNodeInsertProjections = supportsNodeInsertProjections;
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-I7SBZJI2.cjs.map
|
|
105
|
+
//# sourceMappingURL=chunk-I7SBZJI2.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/backend/capabilities/autocommit-single-statement.ts","../src/backend/capabilities/node-insert-projections.ts","../src/backend/resolved-node-update-batch.ts"],"names":["supportsAtomicNodeClaims"],"mappings":";;;;;AAaA,IAAM,gCAAA,uBAAuC,OAAA,EAAgB;AAGtD,SAAS,kCACd,MAAA,EACG;AACH,EAAA,gCAAA,CAAiC,IAAI,MAAM,CAAA;AA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B,CAAC,UAAA,KAAe,UAAA,CAAW,IAAA,KAAS;AAAA;AACtC,GACD,CAAA;AAEL;;;AC7MA,IAAM,2CAAA,GAA8C,CAAA;AAGpD,IAAM,2CAAA,GAA8C,CAAA;AAO7C,SAAS,qCAAA,CACd,YACA,iBAAA,EACS;AACT,EAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,UAAU,CAAA,IAAK,UAAA,GAAa,GAAG,OAAO,KAAA;AAChE,EAAA,IAAI,iBAAA,KAAsB,QAAW,OAAO,IAAA;AAC5C,EAAA,OACE,2CAAA,GACE,aAAa,2CAAA,IACf,iBAAA;AAEJ","file":"chunk-MKJPBSID.cjs","sourcesContent":["/**\n * Origin evidence for the managed single-statement autocommit fast path.\n *\n * This is intentionally narrower than schema-fenced-insert eligibility. The\n * latter follows bundled transaction targets and derived wrappers because its\n * statement still runs inside an explicit transaction. Here, omitting that\n * transaction is the optimization, so only the literal root objects produced\n * by the bundled factories may opt in. In particular, this evidence is never\n * carried through `deriveBackend`, an owned transaction, or adoption of a\n * caller-owned transaction.\n */\nimport type { GraphBackend, TransactionBackend } from \"../types\";\n\nconst BUNDLED_ROOT_AUTOCOMMIT_BACKENDS = new WeakSet<object>();\n\n/** @internal Called only by bundled factories after their root backend exists. */\nexport function markBundledRootAutocommitEligible<T extends object>(\n target: T,\n): T {\n BUNDLED_ROOT_AUTOCOMMIT_BACKENDS.add(target);\n return target;\n}\n\n/** Whether this is the exact root backend a bundled factory created. */\nexport function isBundledRootAutocommitEligible(\n target: GraphBackend | TransactionBackend,\n): target is GraphBackend {\n return BUNDLED_ROOT_AUTOCOMMIT_BACKENDS.has(target);\n}\n","import type {\n BackendIdentity,\n GraphBackend,\n ManagedNodeCreatePlan,\n NodeInsertClaim,\n NodeInsertProjection,\n} from \"../types\";\nimport {\n type AtomicNodeClaimSupport,\n supportsAtomicNodeClaims,\n} from \"./atomic-mutation-program\";\n\nexport type NodeProjectionInsertTarget = BackendIdentity &\n Pick<GraphBackend, \"commands\">;\n\nexport type NodeInsertProjectionRequirements = Readonly<{\n fulltext: boolean;\n embedding: boolean;\n}>;\n\nexport function supportsNodeInsertProjectionRequirements(\n target: NodeProjectionInsertTarget,\n requirements: NodeInsertProjectionRequirements,\n): boolean {\n return (\n (!requirements.fulltext ||\n target.fulltextStrategy?.buildSyncFromInsertedNode !== undefined) &&\n (!requirements.embedding ||\n target.vectorStrategy?.buildUpsertFromInsertedNode !== undefined)\n );\n}\n\n/**\n * The single owner of projection-fusion eligibility.\n *\n * A projection plan is all-or-nothing: every requested projection must have\n * an inserted-node builder on the active strategy, and the receiver must\n * expose the atomic executor. Callers use this same predicate before choosing\n * root autocommit and again on the actual transaction callback target.\n */\nexport function supportsNodeInsertProjections(\n target: NodeProjectionInsertTarget,\n projections: readonly NodeInsertProjection[],\n): boolean {\n if (projections.length === 0) return false;\n return supportsNodeInsertProjectionRequirements(target, {\n fulltext: projections.some((projection) => projection.kind === \"fulltext\"),\n embedding: projections.some(\n (projection) => projection.kind === \"embedding\",\n ),\n });\n}\n\n/**\n * Whether the receiver can make uniqueness/disjointness claims authoritative\n * inside the planned node statement.\n *\n * Claims are reported by the statement as a verdict, so the caller must have a\n * transaction boundary around the statement before it can safely defer the\n * application probes. A root backend is deliberately excluded: its\n * command port is also used for projection-only\n * autocommit writes, but a claim refusal must roll back the node and any\n * claims it touched together.\n */\nfunction supportsNodeInsertClaims(target: NodeProjectionInsertTarget): boolean {\n return (\n !(\"transaction\" in target) &&\n target.capabilities.atomicNodeInsertClaims === true\n );\n}\n\n/**\n * The only claim shape that is safe to execute on a root backend without a\n * rollback boundary. A generated id cannot collide with a different node, so\n * the claim is the sole conflict source; same-kind uniqueness has no legacy\n * axis or cross-kind/disjoint probe to consult. Rephasing it before the node\n * insert makes a conflict prevent the node row from being written at all.\n */\nfunction supportsNonTransactionalNodeClaimPlan(\n plan: Pick<\n ManagedNodeCreatePlan,\n \"idGenerated\" | \"mode\" | \"params\" | \"claims\" | \"projections\"\n >,\n): boolean {\n return (\n plan.idGenerated &&\n plan.mode.kind === \"ordinary\" &&\n plan.projections.length === 0 &&\n plan.claims.length === 1 &&\n plan.claims.every(\n (claim) =>\n claim.verdict.kind === \"uniqueness\" &&\n claim.axis === plan.params.kind &&\n claim.verdict.probeAxes.length === 1 &&\n claim.verdict.probeAxes[0] === claim.axis,\n )\n );\n}\n\n/** Rephases the safe root claim shape so a conflict gates the node insert. */\nexport function rephaseNonTransactionalNodeClaimPlan(\n plan: ManagedNodeCreatePlan,\n): ManagedNodeCreatePlan | undefined {\n if (!supportsNonTransactionalNodeClaimPlan(plan)) return;\n return {\n ...plan,\n claims: plan.claims.map((claim) => ({\n ...claim,\n placement: \"pre-insert\",\n })),\n };\n}\n\n/**\n * Normalizes the complete claim envelope accepted by an atomic node program.\n *\n * Unlike the ordinary root insert seam, a closed program can also prove a\n * disjoint claim because it carries the legacy live-node probe and cleanup in\n * the same atomic transport submission. The executor's advertised support is\n * authoritative; an omitted family remains on the portable path.\n */\nexport function rephaseAtomicNodeClaimPlan(\n plan: ManagedNodeCreatePlan,\n support: AtomicNodeClaimSupport | undefined,\n): ManagedNodeCreatePlan | undefined {\n if (\n plan.mode.kind !== \"ordinary\" ||\n plan.claims.length === 0 ||\n !supportsAtomicNodeClaims(support, plan.claims)\n ) {\n return;\n }\n const supported = plan.claims.every((claim) => {\n if (claim.verdict.kind === \"uniqueness\") {\n return (\n claim.verdict.probeAxes.length > 0 &&\n claim.verdict.probeAxes[0] === claim.axis &&\n new Set(claim.verdict.probeAxes).size === claim.verdict.probeAxes.length\n );\n }\n return (\n claim.key === plan.params.id &&\n claim.verdict.conflictingKinds.length > 0 &&\n new Set(claim.verdict.conflictingKinds).size ===\n claim.verdict.conflictingKinds.length\n );\n });\n if (!supported) return;\n return {\n ...plan,\n claims: plan.claims.map((claim) => ({\n ...claim,\n placement: \"pre-insert\",\n })),\n };\n}\n\n/** Whether the receiver can lower this complete insert plan atomically. */\nexport function supportsNodeCreatePlan(\n target: NodeProjectionInsertTarget,\n input: Readonly<{\n params?: ManagedNodeCreatePlan[\"params\"];\n idGenerated?: ManagedNodeCreatePlan[\"idGenerated\"];\n mode?: ManagedNodeCreatePlan[\"mode\"];\n claims: readonly NodeInsertClaim[];\n projections: readonly NodeInsertProjection[];\n /** Store-side proof that no identity/history/revision side effect exists. */\n allowNonTransactionalClaims?: boolean | undefined;\n }>,\n): boolean {\n if (input.claims.length === 0) {\n return supportsNodeInsertProjections(target, input.projections);\n }\n // A claim refusal is discovered from the data-modifying statement's result,\n // so the caller-owned transaction is the rollback boundary. Root graph\n // backends expose `transaction`; transaction-scoped operation backends do\n // not. Keep this exported predicate aligned with the execution contract.\n const ordinaryPlan =\n (\n input.params === undefined ||\n input.mode === undefined ||\n input.idGenerated === undefined\n ) ?\n undefined\n : {\n entity: \"node\" as const,\n params: input.params,\n idGenerated: input.idGenerated,\n mode: input.mode,\n claims: input.claims,\n projections: input.projections,\n };\n const rootClaimFusion =\n input.allowNonTransactionalClaims === true &&\n target.capabilities.atomicNodeInsertClaims === true &&\n ordinaryPlan !== undefined &&\n supportsNonTransactionalNodeClaimPlan(ordinaryPlan);\n return (\n (supportsNodeInsertClaims(target) ||\n (\"transaction\" in target && rootClaimFusion)) &&\n supportsNodeInsertProjectionRequirements(target, {\n fulltext: input.projections.some(\n (projection) => projection.kind === \"fulltext\",\n ),\n embedding: input.projections.some(\n (projection) => projection.kind === \"embedding\",\n ),\n })\n );\n}\n","/**\n * Bind parameters in one resolved node replacement statement, excluding its\n * entries: two graph/kind predicates, the update timestamp, and the count gate.\n */\nconst RESOLVED_NODE_UPDATE_BATCH_FIXED_BIND_COUNT = 6;\n\n/** Each entry contributes one relational id/props/version row. */\nconst RESOLVED_NODE_UPDATE_BATCH_ENTRY_BIND_COUNT = 3;\n\n/**\n * The one owner of whether the portable resolved-update statement fits the\n * target's advertised bind budget. An absent budget is an explicit admission\n * that this backend has no known ceiling.\n */\nexport function resolvedNodeUpdateBatchFitsBindBudget(\n entryCount: number,\n maxBindParameters: number | undefined,\n): boolean {\n if (!Number.isSafeInteger(entryCount) || entryCount < 1) return false;\n if (maxBindParameters === undefined) return true;\n return (\n RESOLVED_NODE_UPDATE_BATCH_FIXED_BIND_COUNT +\n entryCount * RESOLVED_NODE_UPDATE_BATCH_ENTRY_BIND_COUNT <=\n maxBindParameters\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/backend/capabilities/autocommit-single-statement.ts","../src/backend/capabilities/node-insert-projections.ts","../src/backend/resolved-node-update-batch.ts"],"names":["supportsAtomicNodeClaims"],"mappings":";;;;;AAaA,IAAM,gCAAA,uBAAuC,OAAA,EAAgB;AAGtD,SAAS,kCACd,MAAA,EACG;AACH,EAAA,gCAAA,CAAiC,IAAI,MAAM,CAAA;AAC3C,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,gCACd,MAAA,EACwB;AACxB,EAAA,OAAO,gCAAA,CAAiC,IAAI,MAAM,CAAA;AACpD;;;ACRO,SAAS,wCAAA,CACd,QACA,YAAA,EACS;AACT,EAAA,OAAA,CACG,CAAC,YAAA,CAAa,QAAA,IACb,MAAA,CAAO,gBAAA,EAAkB,yBAAA,KAA8B,MAAA,MACxD,CAAC,YAAA,CAAa,SAAA,IACb,MAAA,CAAO,cAAA,EAAgB,2BAAA,KAAgC,MAAA,CAAA;AAE7D;AAUO,SAAS,6BAAA,CACd,QACA,WAAA,EACS;AACT,EAAA,IAAI,WAAA,CAAY,MAAA,KAAW,CAAA,EAAG,OAAO,KAAA;AACrC,EAAA,OAAO,yCAAyC,MAAA,EAAQ;AAAA,IACtD,UAAU,WAAA,CAAY,IAAA,CAAK,CAAC,UAAA,KAAe,UAAA,CAAW,SAAS,UAAU,CAAA;AAAA,IACzE,WAAW,WAAA,CAAY,IAAA;AAAA,MACrB,CAAC,UAAA,KAAe,UAAA,CAAW,IAAA,KAAS;AAAA;AACtC,GACD,CAAA;AACH;AAaA,SAAS,yBAAyB,MAAA,EAA6C;AAC7E,EAAA,OACE,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Aa,KAAA,CAAM;AAAA,GACrB;AACJ,EAAA,MAAM,eAAA,GACJ,KAAA,CAAM,2BAAA,KAAgC,IAAA,IACtC,MAAA,CAAO,YAAA,CAAa,sBAAA,KAA2B,IAAA,IAC/C,YAAA,KAAiB,MAAA,IACjB,qCAAA,CAAsC,YAAY,CAAA;AACpD,EAAA,OAAA,CACG,yBAAyB,MAAM,CAAA,IAC7B,iBAAiB,MAAA,IAAU,eAAA,KAC9B,yCAAyC,MAAA,EAAQ;AAAA,IAC/C,QAAA,EAAU,MAAM,WAAA,CAAY,IAAA;AAAA,MAC1B,CAAC,UAAA,KAAe,UAAA,CAAW,IAAA,KAAS;AAAA,KACtC;AAAA,IACA,SAAA,EAAW,MAAM,WAAA,CAAY,IAAA;AAAA,MAC3B,CAAC,UAAA,KAAe,UAAA,CAAW,IAAA,KAAS;AAAA;AACtC,GACD,CAAA;AAEL;;;AC7MA,IAAM,2CAAA,GAA8C,CAAA;AAGpD,IAAM,2CAAA,GAA8C,CAAA;AAO7C,SAAS,qCAAA,CACd,YACA,iBAAA,EACS;AACT,EAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,UAAU,CAAA,IAAK,UAAA,GAAa,GAAG,OAAO,KAAA;AAChE,EAAA,IAAI,iBAAA,KAAsB,QAAW,OAAO,IAAA;AAC5C,EAAA,OACE,2CAAA,GACE,aAAa,2CAAA,IACf,iBAAA;AAEJ","file":"chunk-I7SBZJI2.cjs","sourcesContent":["/**\n * Origin evidence for the managed single-statement autocommit fast path.\n *\n * This is intentionally narrower than schema-fenced-insert eligibility. The\n * latter follows bundled transaction targets and derived wrappers because its\n * statement still runs inside an explicit transaction. Here, omitting that\n * transaction is the optimization, so only the literal root objects produced\n * by the bundled factories may opt in. In particular, this evidence is never\n * carried through `deriveBackend`, an owned transaction, or adoption of a\n * caller-owned transaction.\n */\nimport type { GraphBackend, TransactionBackend } from \"../types\";\n\nconst BUNDLED_ROOT_AUTOCOMMIT_BACKENDS = new WeakSet<object>();\n\n/** @internal Called only by bundled factories after their root backend exists. */\nexport function markBundledRootAutocommitEligible<T extends object>(\n target: T,\n): T {\n BUNDLED_ROOT_AUTOCOMMIT_BACKENDS.add(target);\n return target;\n}\n\n/** Whether this is the exact root backend a bundled factory created. */\nexport function isBundledRootAutocommitEligible(\n target: GraphBackend | TransactionBackend,\n): target is GraphBackend {\n return BUNDLED_ROOT_AUTOCOMMIT_BACKENDS.has(target);\n}\n","import type {\n BackendIdentity,\n GraphBackend,\n ManagedNodeCreatePlan,\n NodeInsertClaim,\n NodeInsertProjection,\n} from \"../types\";\nimport {\n type AtomicNodeClaimSupport,\n supportsAtomicNodeClaims,\n} from \"./atomic-mutation-program\";\n\nexport type NodeProjectionInsertTarget = BackendIdentity &\n Pick<GraphBackend, \"commands\">;\n\nexport type NodeInsertProjectionRequirements = Readonly<{\n fulltext: boolean;\n embedding: boolean;\n}>;\n\nexport function supportsNodeInsertProjectionRequirements(\n target: NodeProjectionInsertTarget,\n requirements: NodeInsertProjectionRequirements,\n): boolean {\n return (\n (!requirements.fulltext ||\n target.fulltextStrategy?.buildSyncFromInsertedNode !== undefined) &&\n (!requirements.embedding ||\n target.vectorStrategy?.buildUpsertFromInsertedNode !== undefined)\n );\n}\n\n/**\n * The single owner of projection-fusion eligibility.\n *\n * A projection plan is all-or-nothing: every requested projection must have\n * an inserted-node builder on the active strategy, and the receiver must\n * expose the atomic executor. Callers use this same predicate before choosing\n * root autocommit and again on the actual transaction callback target.\n */\nexport function supportsNodeInsertProjections(\n target: NodeProjectionInsertTarget,\n projections: readonly NodeInsertProjection[],\n): boolean {\n if (projections.length === 0) return false;\n return supportsNodeInsertProjectionRequirements(target, {\n fulltext: projections.some((projection) => projection.kind === \"fulltext\"),\n embedding: projections.some(\n (projection) => projection.kind === \"embedding\",\n ),\n });\n}\n\n/**\n * Whether the receiver can make uniqueness/disjointness claims authoritative\n * inside the planned node statement.\n *\n * Claims are reported by the statement as a verdict, so the caller must have a\n * transaction boundary around the statement before it can safely defer the\n * application probes. A root backend is deliberately excluded: its\n * command port is also used for projection-only\n * autocommit writes, but a claim refusal must roll back the node and any\n * claims it touched together.\n */\nfunction supportsNodeInsertClaims(target: NodeProjectionInsertTarget): boolean {\n return (\n !(\"transaction\" in target) &&\n target.capabilities.atomicNodeInsertClaims === true\n );\n}\n\n/**\n * The only claim shape that is safe to execute on a root backend without a\n * rollback boundary. A generated id cannot collide with a different node, so\n * the claim is the sole conflict source; same-kind uniqueness has no legacy\n * axis or cross-kind/disjoint probe to consult. Rephasing it before the node\n * insert makes a conflict prevent the node row from being written at all.\n */\nfunction supportsNonTransactionalNodeClaimPlan(\n plan: Pick<\n ManagedNodeCreatePlan,\n \"idGenerated\" | \"mode\" | \"params\" | \"claims\" | \"projections\"\n >,\n): boolean {\n return (\n plan.idGenerated &&\n plan.mode.kind === \"ordinary\" &&\n plan.projections.length === 0 &&\n plan.claims.length === 1 &&\n plan.claims.every(\n (claim) =>\n claim.verdict.kind === \"uniqueness\" &&\n claim.axis === plan.params.kind &&\n claim.verdict.probeAxes.length === 1 &&\n claim.verdict.probeAxes[0] === claim.axis,\n )\n );\n}\n\n/** Rephases the safe root claim shape so a conflict gates the node insert. */\nexport function rephaseNonTransactionalNodeClaimPlan(\n plan: ManagedNodeCreatePlan,\n): ManagedNodeCreatePlan | undefined {\n if (!supportsNonTransactionalNodeClaimPlan(plan)) return;\n return {\n ...plan,\n claims: plan.claims.map((claim) => ({\n ...claim,\n placement: \"pre-insert\",\n })),\n };\n}\n\n/**\n * Normalizes the complete claim envelope accepted by an atomic node program.\n *\n * Unlike the ordinary root insert seam, a closed program can also prove a\n * disjoint claim because it carries the legacy live-node probe and cleanup in\n * the same atomic transport submission. The executor's advertised support is\n * authoritative; an omitted family remains on the portable path.\n */\nexport function rephaseAtomicNodeClaimPlan(\n plan: ManagedNodeCreatePlan,\n support: AtomicNodeClaimSupport | undefined,\n): ManagedNodeCreatePlan | undefined {\n if (\n plan.mode.kind !== \"ordinary\" ||\n plan.claims.length === 0 ||\n !supportsAtomicNodeClaims(support, plan.claims)\n ) {\n return;\n }\n const supported = plan.claims.every((claim) => {\n if (claim.verdict.kind === \"uniqueness\") {\n return (\n claim.verdict.probeAxes.length > 0 &&\n claim.verdict.probeAxes[0] === claim.axis &&\n new Set(claim.verdict.probeAxes).size === claim.verdict.probeAxes.length\n );\n }\n return (\n claim.key === plan.params.id &&\n claim.verdict.conflictingKinds.length > 0 &&\n new Set(claim.verdict.conflictingKinds).size ===\n claim.verdict.conflictingKinds.length\n );\n });\n if (!supported) return;\n return {\n ...plan,\n claims: plan.claims.map((claim) => ({\n ...claim,\n placement: \"pre-insert\",\n })),\n };\n}\n\n/** Whether the receiver can lower this complete insert plan atomically. */\nexport function supportsNodeCreatePlan(\n target: NodeProjectionInsertTarget,\n input: Readonly<{\n params?: ManagedNodeCreatePlan[\"params\"];\n idGenerated?: ManagedNodeCreatePlan[\"idGenerated\"];\n mode?: ManagedNodeCreatePlan[\"mode\"];\n claims: readonly NodeInsertClaim[];\n projections: readonly NodeInsertProjection[];\n /** Store-side proof that no identity/history/revision side effect exists. */\n allowNonTransactionalClaims?: boolean | undefined;\n }>,\n): boolean {\n if (input.claims.length === 0) {\n return supportsNodeInsertProjections(target, input.projections);\n }\n // A claim refusal is discovered from the data-modifying statement's result,\n // so the caller-owned transaction is the rollback boundary. Root graph\n // backends expose `transaction`; transaction-scoped operation backends do\n // not. Keep this exported predicate aligned with the execution contract.\n const ordinaryPlan =\n (\n input.params === undefined ||\n input.mode === undefined ||\n input.idGenerated === undefined\n ) ?\n undefined\n : {\n entity: \"node\" as const,\n params: input.params,\n idGenerated: input.idGenerated,\n mode: input.mode,\n claims: input.claims,\n projections: input.projections,\n };\n const rootClaimFusion =\n input.allowNonTransactionalClaims === true &&\n target.capabilities.atomicNodeInsertClaims === true &&\n ordinaryPlan !== undefined &&\n supportsNonTransactionalNodeClaimPlan(ordinaryPlan);\n return (\n (supportsNodeInsertClaims(target) ||\n (\"transaction\" in target && rootClaimFusion)) &&\n supportsNodeInsertProjectionRequirements(target, {\n fulltext: input.projections.some(\n (projection) => projection.kind === \"fulltext\",\n ),\n embedding: input.projections.some(\n (projection) => projection.kind === \"embedding\",\n ),\n })\n );\n}\n","/**\n * Bind parameters in one resolved node replacement statement, excluding its\n * entries: two graph/kind predicates, the update timestamp, and the count gate.\n */\nconst RESOLVED_NODE_UPDATE_BATCH_FIXED_BIND_COUNT = 6;\n\n/** Each entry contributes one relational id/props/version row. */\nconst RESOLVED_NODE_UPDATE_BATCH_ENTRY_BIND_COUNT = 3;\n\n/**\n * The one owner of whether the portable resolved-update statement fits the\n * target's advertised bind budget. An absent budget is an explicit admission\n * that this backend has no known ceiling.\n */\nexport function resolvedNodeUpdateBatchFitsBindBudget(\n entryCount: number,\n maxBindParameters: number | undefined,\n): boolean {\n if (!Number.isSafeInteger(entryCount) || entryCount < 1) return false;\n if (maxBindParameters === undefined) return true;\n return (\n RESOLVED_NODE_UPDATE_BATCH_FIXED_BIND_COUNT +\n entryCount * RESOLVED_NODE_UPDATE_BATCH_ENTRY_BIND_COUNT <=\n maxBindParameters\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkBX42F7IJ_cjs = require('./chunk-BX42F7IJ.cjs');
|
|
4
4
|
var chunkHAHNRASW_cjs = require('./chunk-HAHNRASW.cjs');
|
|
5
5
|
var chunkBXHAPCQG_cjs = require('./chunk-BXHAPCQG.cjs');
|
|
6
6
|
var chunk7XYPLAPL_cjs = require('./chunk-7XYPLAPL.cjs');
|
|
@@ -35,7 +35,7 @@ function deserializeSchema(schema) {
|
|
|
35
35
|
function buildRegistryFromRelations(schema) {
|
|
36
36
|
const nodeKinds = /* @__PURE__ */ new Map();
|
|
37
37
|
const edgeKinds = /* @__PURE__ */ new Map();
|
|
38
|
-
return
|
|
38
|
+
return chunkBX42F7IJ_cjs.buildValidatedKindRegistry({
|
|
39
39
|
nodeKinds,
|
|
40
40
|
edgeKinds,
|
|
41
41
|
ontology: schema.ontology.relations.map(
|
|
@@ -101,8 +101,8 @@ async function registerGraphTemplate(backend, params) {
|
|
|
101
101
|
}
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
|
-
const schemaDocument =
|
|
105
|
-
const schemaHash = await
|
|
104
|
+
const schemaDocument = chunkBX42F7IJ_cjs.serializeSchema(reconciled.graph, reconciled.version);
|
|
105
|
+
const schemaHash = await chunkBX42F7IJ_cjs.computeSchemaHash(schemaDocument);
|
|
106
106
|
if (schemaHash !== reconciled.hash) {
|
|
107
107
|
throw new chunk7XYPLAPL_cjs.ConfigurationError(
|
|
108
108
|
"Reconciled schema hash does not match its graph snapshot.",
|
|
@@ -129,8 +129,8 @@ async function instantiateGraphTemplate(backend, params) {
|
|
|
129
129
|
if (sourceVersion === void 0 || reconciledHash === void 0) {
|
|
130
130
|
throw graphTemplateHandleMismatchError(params.template.id);
|
|
131
131
|
}
|
|
132
|
-
const sourceHash = await
|
|
133
|
-
|
|
132
|
+
const sourceHash = await chunkBX42F7IJ_cjs.computeSchemaHash(
|
|
133
|
+
chunkBX42F7IJ_cjs.serializeSchema(params.template.reconciled.graph, sourceVersion)
|
|
134
134
|
);
|
|
135
135
|
if (sourceHash !== params.template.schemaHash || reconciledHash !== params.template.schemaHash) {
|
|
136
136
|
throw graphTemplateHandleMismatchError(params.template.id);
|
|
@@ -139,7 +139,7 @@ async function instantiateGraphTemplate(backend, params) {
|
|
|
139
139
|
...params.template.reconciled.graph,
|
|
140
140
|
id: params.graphId
|
|
141
141
|
});
|
|
142
|
-
const targetHash = await
|
|
142
|
+
const targetHash = await chunkBX42F7IJ_cjs.computeSchemaHash(chunkBX42F7IJ_cjs.serializeSchema(targetGraph, 1));
|
|
143
143
|
const result = await instantiate({
|
|
144
144
|
templateId: params.template.id,
|
|
145
145
|
templateSchemaHash: params.template.schemaHash,
|
|
@@ -192,5 +192,5 @@ exports.deserializeSchema = deserializeSchema;
|
|
|
192
192
|
exports.instantiateGraph = instantiateGraph;
|
|
193
193
|
exports.instantiateGraphTemplate = instantiateGraphTemplate;
|
|
194
194
|
exports.registerGraphTemplate = registerGraphTemplate;
|
|
195
|
-
//# sourceMappingURL=chunk-
|
|
196
|
-
//# sourceMappingURL=chunk-
|
|
195
|
+
//# sourceMappingURL=chunk-K7YACILO.cjs.map
|
|
196
|
+
//# sourceMappingURL=chunk-K7YACILO.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema/deserializer.ts","../src/schema/graph-templates.ts"],"names":["hasOwnKey","buildValidatedKindRegistry","ConfigurationError","resolveGraphVectorSlots","serializeSchema","computeSchemaHash"],"mappings":";;;;;;;;AAqFO,SAAS,kBACd,MAAA,EACoB;AACpB,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,SAAS,SAAS,CAAA;AAE3D,EAAA,OAAO;AAAA,IACL,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,aAAa,MAAA,CAAO,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAAM,SAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAA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time objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { type AnyEdgeType, type NodeType } from \"../core/types\";\nimport { type NamedOntologyRelation } from \"../ontology/validation\";\nimport { buildValidatedKindRegistry } from \"../registry/build-validated\";\nimport type { KindRegistry } from \"../registry/kind-registry\";\nimport { type EdgeEndpointKinds } from \"../registry/validate-implies\";\nimport { hasOwnKey } from \"../utils/object\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the durable TypeGraph Identity Profile configuration. */\n getIdentity: () => SerializedSchema[\"identity\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a validated KindRegistry by recomputing closures from relations */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n // Own-key reads, for the same reason {@link buildEdgeEndpointKinds} below\n // uses a `Map`: `schema` is parsed out of a stored JSON document and the\n // caller supplies the name, so a raw read hands back an `Object.prototype`\n // member typed as a definition for any name no kind is registered under.\n getNode: (name) =>\n hasOwnKey(schema.nodes, name) ? schema.nodes[name] : undefined,\n getNodeNames: () => nodeNames,\n\n getEdge: (name) =>\n hasOwnKey(schema.edges, name) ? schema.edges[name] : undefined,\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) =>\n hasOwnKey(schema.ontology.metaEdges, name) ?\n schema.ontology.metaEdges[name]\n : undefined,\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getIdentity: () => schema.identity,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromRelations(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized relations.\n *\n * Persisted closures are a legacy inspection artifact. Relations are validated\n * and closures are recomputed so old schemas gain current hardening rules.\n */\nfunction buildRegistryFromRelations(schema: SerializedSchema): KindRegistry {\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map<string, NodeType>();\n const edgeKinds = new Map<string, AnyEdgeType>();\n return buildValidatedKindRegistry({\n nodeKinds,\n edgeKinds,\n ontology: schema.ontology.relations.map(\n (relation): NamedOntologyRelation => ({\n metaEdge: relation.metaEdge,\n from: relation.from,\n to: relation.to,\n }),\n ),\n edgeEndpoints: buildEdgeEndpointKinds(schema.edges),\n ...(schema.identity === undefined ? {} : { identity: schema.identity }),\n });\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n const pairs: { from: string; to: string }[] = [];\n if (def.targetKindsBySource === undefined) {\n for (const fromKind of def.fromKinds) {\n for (const toKind of def.toKinds) {\n pairs.push({ from: fromKind, to: toKind });\n }\n }\n } else {\n for (const [sourceKind, targetKinds] of Object.entries(\n def.targetKindsBySource,\n )) {\n for (const targetKind of targetKinds) {\n pairs.push({ from: sourceKind, to: targetKind });\n }\n }\n }\n result.set(kind, {\n from: def.fromKinds,\n to: def.toKinds,\n pairs,\n });\n }\n return result;\n}\n","import type { GraphBackend, SchemaVersionRow } from \"../backend/types\";\nimport { type GraphDef } from \"../core/define-graph\";\nimport { resolveGraphVectorSlots } from \"../core/embedding\";\nimport { ConfigurationError } from \"../errors\";\nimport { type ReconciledSchema } from \"../store/store\";\nimport { computeSchemaHash, serializeSchema } from \"./serializer\";\n\n/** A locally held handle for a durable server-side graph template. */\nexport type GraphTemplate<G extends GraphDef> = Readonly<{\n id: string;\n reconciled: ReconciledSchema<G>;\n schemaHash: string;\n}>;\n\nexport type InstantiateGraphTemplateResult<G extends GraphDef> = Readonly<{\n status: \"ready\";\n reconciled: ReconciledSchema<G>;\n schema: SchemaVersionRow;\n}>;\n\n/**\n * Registers the fully materialized shape of a verified store as a durable\n * template. The original schema version is retained only as snapshot\n * provenance: every instantiated graph starts at v1 with that final shape.\n */\nexport async function registerGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ templateId: string; reconciled: ReconciledSchema<G> }>,\n): Promise<GraphTemplate<G>> {\n const register = backend.registerGraphTemplate;\n if (register === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const { reconciled } = params;\n if (reconciled.version === undefined || reconciled.hash === undefined) {\n throw new ConfigurationError(\n \"A graph template requires a reconciled schema from a managed or verified Store.\",\n { code: \"GRAPH_TEMPLATE_REQUIRES_RECONCILED_SCHEMA\" },\n );\n }\n if (\n resolveGraphVectorSlots(reconciled.graph).length > 0 &&\n backend.capabilities.vector?.supported === true\n ) {\n throw new ConfigurationError(\n \"Graph templates do not support embedding fields because vector storage is graph-scoped and cannot be instantiated schema-only.\",\n {\n code: \"GRAPH_TEMPLATE_VECTOR_UNSUPPORTED\",\n graphId: reconciled.graph.id,\n },\n {\n suggestion:\n \"Provision the graph through createStoreWithSchema until template instantiation can atomically materialize vector contributions.\",\n },\n );\n }\n const schemaDocument = serializeSchema(reconciled.graph, reconciled.version);\n const schemaHash = await computeSchemaHash(schemaDocument);\n if (schemaHash !== reconciled.hash) {\n throw new ConfigurationError(\n \"Reconciled schema hash does not match its graph snapshot.\",\n { code: \"GRAPH_TEMPLATE_RECONCILED_HASH_MISMATCH\" },\n );\n }\n await register({\n templateId: params.templateId,\n schemaHash,\n schemaDoc: schemaDocument,\n });\n return Object.freeze({\n id: params.templateId,\n reconciled,\n schemaHash,\n });\n}\n\n/**\n * Instantiates the template's final graph shape as target schema v1. Only the\n * target hash crosses the wire; the durable source document stays in the\n * backend template registry and is rebound to `graphId` by one SQL statement.\n */\nexport async function instantiateGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n const instantiate = backend.instantiateGraphTemplate;\n if (instantiate === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const sourceVersion = params.template.reconciled.version;\n const reconciledHash = params.template.reconciled.hash;\n if (sourceVersion === undefined || reconciledHash === undefined) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const sourceHash = await computeSchemaHash(\n serializeSchema(params.template.reconciled.graph, sourceVersion),\n );\n if (\n sourceHash !== params.template.schemaHash ||\n reconciledHash !== params.template.schemaHash\n ) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const targetGraph: G = Object.freeze({\n ...params.template.reconciled.graph,\n id: params.graphId,\n });\n const targetHash = await computeSchemaHash(serializeSchema(targetGraph, 1));\n const result = await instantiate({\n templateId: params.template.id,\n templateSchemaHash: params.template.schemaHash,\n graphId: params.graphId,\n schemaHash: targetHash,\n });\n if (result.status === \"refused\") {\n throw new ConfigurationError(\n `Graph template instantiation was refused for graph \"${params.graphId}\". The template may be absent, or the graph already has a different schema.`,\n {\n code: \"GRAPH_TEMPLATE_INSTANTIATION_REFUSED\",\n graphId: params.graphId,\n templateId: params.template.id,\n },\n );\n }\n if (\n result.row.graph_id !== params.graphId ||\n result.row.version !== 1 ||\n result.row.schema_hash !== targetHash\n ) {\n throw new ConfigurationError(\n \"Graph template backend returned a schema row that does not match the requested target.\",\n { code: \"GRAPH_TEMPLATE_INVALID_RESULT\", graphId: params.graphId },\n );\n }\n return Object.freeze({\n status: \"ready\",\n reconciled: Object.freeze({\n graph: targetGraph,\n version: result.row.version,\n hash: result.row.schema_hash,\n }),\n schema: result.row,\n });\n}\n\nfunction graphTemplateHandleMismatchError(\n templateId: string,\n): ConfigurationError {\n return new ConfigurationError(\n `Graph template handle \"${templateId}\" does not match its reconciled schema snapshot.`,\n { code: \"GRAPH_TEMPLATE_HANDLE_MISMATCH\", templateId },\n );\n}\n\n/** Short public name for {@link instantiateGraphTemplate}. */\nexport function instantiateGraph<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n return instantiateGraphTemplate(backend, params);\n}\n\nfunction graphTemplatesUnsupportedError(\n backend: GraphBackend,\n): ConfigurationError {\n return new ConfigurationError(\n `The ${backend.dialect} backend does not support durable graph templates.`,\n { code: \"GRAPH_TEMPLATES_UNSUPPORTED\", dialect: backend.dialect },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/schema/deserializer.ts","../src/schema/graph-templates.ts"],"names":["hasOwnKey","buildValidatedKindRegistry","ConfigurationError","resolveGraphVectorSlots","serializeSchema","computeSchemaHash"],"mappings":";;;;;;;;AAqFO,SAAS,kBACd,MAAA,EACoB;AACpB,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAC1C,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,SAAS,SAAS,CAAA;AAE3D,EAAA,OAAO;AAAA,IACL,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,aAAa,MAAA,CAAO,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAAM,SAAA;AAAA,IAEpB,OAAA,EAAS,CAAC,IAAA,KACRA,2BAAA,CAAU,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA,GAAI,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACvD,cAAc,MAAM,SAAA;AAAA,IAEpB,WAAA,EAAa,CAAC,IAAA,KACZA,2BAAA,CAAU,MAAA,CAAO,QAAA,CAAS,SAAA,EAAW,IAAI,CAAA,GACvC,MAAA,CAAO,QAAA,CAAS,SAAA,CAAU,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CAAI,OAAA,KAAY,CAAA,IACvB,MAAA,CAAO,GAAA,CAAI,WAAA,KAAgB,UAAA,EAC3B;AACA,IAAA,MAAM,IAAIA,oCAAA;AAAA,MACR,wFAAA;AAAA,MACA,EAAE,IAAA,EAAM,+BAAA,EAAiC,OAAA,EAAS,OAAO,OAAA;AAAQ,KACnE;AAAA,EACF;AACA,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAA,EAAQ,OAAA;AAAA,IACR,UAAA,EAAY,OAAO,MAAA,CAAO;AAAA,MACxB,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS,OAAO,GAAA,CAAI,OAAA;AAAA,MACpB,IAAA,EAAM,OAAO,GAAA,CAAI;AAAA,KAClB,CAAA;AAAA,IACD,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAEA,SAAS,iCACP,UAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,0BAA0B,UAAU,CAAA,gDAAA,CAAA;AAAA,IACpC,EAAE,IAAA,EAAM,gCAAA,EAAkC,UAAA;AAAW,GACvD;AACF;AAGO,SAAS,gBAAA,CACd,SACA,MAAA,EAC4C;AAC5C,EAAA,OAAO,wBAAA,CAAyB,SAAS,MAAM,CAAA;AACjD;AAEA,SAAS,+BACP,OAAA,EACoB;AACpB,EAAA,OAAO,IAAIA,oCAAA;AAAA,IACT,CAAA,IAAA,EAAO,QAAQ,OAAO,CAAA,kDAAA,CAAA;AAAA,IACtB,EAAE,IAAA,EAAM,6BAAA,EAA+B,OAAA,EAAS,QAAQ,OAAA;AAAQ,GAClE;AACF","file":"chunk-K7YACILO.cjs","sourcesContent":["/**\n * Schema deserializer for loading stored schemas.\n *\n * Reconstructs runtime objects from SerializedSchema.\n * Note: Zod schemas cannot be fully reconstructed from JSON Schema,\n * so this provides access to the serialized data for introspection.\n */\nimport { type AnyEdgeType, type NodeType } from \"../core/types\";\nimport { type NamedOntologyRelation } from \"../ontology/validation\";\nimport { buildValidatedKindRegistry } from \"../registry/build-validated\";\nimport type { KindRegistry } from \"../registry/kind-registry\";\nimport { type EdgeEndpointKinds } from \"../registry/validate-implies\";\nimport { hasOwnKey } from \"../utils/object\";\nimport {\n type SerializedClosures,\n type SerializedEdgeDef,\n type SerializedMetaEdge,\n type SerializedNodeDef,\n type SerializedOntologyRelation,\n type SerializedSchema,\n} from \"./types\";\n\n// ============================================================\n// Deserialized Schema\n// ============================================================\n\n/**\n * A deserialized schema provides read-only access to schema metadata.\n *\n * Note: Unlike the original GraphDef, this does not include Zod schemas\n * since those cannot be reconstructed from JSON Schema. Use this for\n * introspection and metadata access only.\n */\nexport type DeserializedSchema = Readonly<{\n graphId: string;\n version: number;\n generatedAt: string;\n\n /** Get node definition by name */\n getNode: (name: string) => SerializedNodeDef | undefined;\n\n /** Get all node names */\n getNodeNames: () => readonly string[];\n\n /** Get edge definition by name */\n getEdge: (name: string) => SerializedEdgeDef | undefined;\n\n /** Get all edge names */\n getEdgeNames: () => readonly string[];\n\n /** Get meta-edge definition by name */\n getMetaEdge: (name: string) => SerializedMetaEdge | undefined;\n\n /** Get all meta-edge names */\n getMetaEdgeNames: () => readonly string[];\n\n /** Get all ontology relations */\n getRelations: () => readonly SerializedOntologyRelation[];\n\n /** Get precomputed closures */\n getClosures: () => SerializedClosures;\n\n /** Get graph defaults */\n getDefaults: () => SerializedSchema[\"defaults\"];\n\n /** Get the durable TypeGraph Identity Profile configuration. */\n getIdentity: () => SerializedSchema[\"identity\"];\n\n /** Get the raw serialized schema */\n getRaw: () => SerializedSchema;\n\n /** Build a validated KindRegistry by recomputing closures from relations */\n buildRegistry: () => KindRegistry;\n}>;\n\n// ============================================================\n// Deserialization\n// ============================================================\n\n/**\n * Deserializes a SerializedSchema into a DeserializedSchema.\n *\n * @param schema - The serialized schema to deserialize\n * @returns A deserialized schema with accessor methods\n */\nexport function deserializeSchema(\n schema: SerializedSchema,\n): DeserializedSchema {\n const nodeNames = Object.keys(schema.nodes);\n const edgeNames = Object.keys(schema.edges);\n const metaEdgeNames = Object.keys(schema.ontology.metaEdges);\n\n return {\n graphId: schema.graphId,\n version: schema.version,\n generatedAt: schema.generatedAt,\n\n // Own-key reads, for the same reason {@link buildEdgeEndpointKinds} below\n // uses a `Map`: `schema` is parsed out of a stored JSON document and the\n // caller supplies the name, so a raw read hands back an `Object.prototype`\n // member typed as a definition for any name no kind is registered under.\n getNode: (name) =>\n hasOwnKey(schema.nodes, name) ? schema.nodes[name] : undefined,\n getNodeNames: () => nodeNames,\n\n getEdge: (name) =>\n hasOwnKey(schema.edges, name) ? schema.edges[name] : undefined,\n getEdgeNames: () => edgeNames,\n\n getMetaEdge: (name) =>\n hasOwnKey(schema.ontology.metaEdges, name) ?\n schema.ontology.metaEdges[name]\n : undefined,\n getMetaEdgeNames: () => metaEdgeNames,\n\n getRelations: () => schema.ontology.relations,\n getClosures: () => schema.ontology.closures,\n\n getDefaults: () => schema.defaults,\n getIdentity: () => schema.identity,\n getRaw: () => schema,\n\n buildRegistry: () => buildRegistryFromRelations(schema),\n };\n}\n\n// ============================================================\n// Registry Building\n// ============================================================\n\n/**\n * Builds a KindRegistry from serialized relations.\n *\n * Persisted closures are a legacy inspection artifact. Relations are validated\n * and closures are recomputed so old schemas gain current hardening rules.\n */\nfunction buildRegistryFromRelations(schema: SerializedSchema): KindRegistry {\n // Build empty node/edge kind maps (we don't have the actual Zod schemas)\n const nodeKinds = new Map<string, NodeType>();\n const edgeKinds = new Map<string, AnyEdgeType>();\n return buildValidatedKindRegistry({\n nodeKinds,\n edgeKinds,\n ontology: schema.ontology.relations.map(\n (relation): NamedOntologyRelation => ({\n metaEdge: relation.metaEdge,\n from: relation.from,\n to: relation.to,\n }),\n ),\n edgeEndpoints: buildEdgeEndpointKinds(schema.edges),\n ...(schema.identity === undefined ? {} : { identity: schema.identity }),\n });\n}\n\n/**\n * Maps each edge kind's serialized definition to its domain/range kind\n * names, for `validateImpliesEndpointCompatibility`. A `Map` (rather than\n * the plain `schema.edges` object) so a lookup for an edge kind literally\n * named \"toString\" or another `Object.prototype` member can't resolve to\n * an inherited member instead of `undefined`.\n */\nfunction buildEdgeEndpointKinds(\n edges: Record<string, SerializedEdgeDef>,\n): ReadonlyMap<string, EdgeEndpointKinds> {\n const result = new Map<string, EdgeEndpointKinds>();\n for (const [kind, def] of Object.entries(edges)) {\n const pairs: { from: string; to: string }[] = [];\n if (def.targetKindsBySource === undefined) {\n for (const fromKind of def.fromKinds) {\n for (const toKind of def.toKinds) {\n pairs.push({ from: fromKind, to: toKind });\n }\n }\n } else {\n for (const [sourceKind, targetKinds] of Object.entries(\n def.targetKindsBySource,\n )) {\n for (const targetKind of targetKinds) {\n pairs.push({ from: sourceKind, to: targetKind });\n }\n }\n }\n result.set(kind, {\n from: def.fromKinds,\n to: def.toKinds,\n pairs,\n });\n }\n return result;\n}\n","import type { GraphBackend, SchemaVersionRow } from \"../backend/types\";\nimport { type GraphDef } from \"../core/define-graph\";\nimport { resolveGraphVectorSlots } from \"../core/embedding\";\nimport { ConfigurationError } from \"../errors\";\nimport { type ReconciledSchema } from \"../store/store\";\nimport { computeSchemaHash, serializeSchema } from \"./serializer\";\n\n/** A locally held handle for a durable server-side graph template. */\nexport type GraphTemplate<G extends GraphDef> = Readonly<{\n id: string;\n reconciled: ReconciledSchema<G>;\n schemaHash: string;\n}>;\n\nexport type InstantiateGraphTemplateResult<G extends GraphDef> = Readonly<{\n status: \"ready\";\n reconciled: ReconciledSchema<G>;\n schema: SchemaVersionRow;\n}>;\n\n/**\n * Registers the fully materialized shape of a verified store as a durable\n * template. The original schema version is retained only as snapshot\n * provenance: every instantiated graph starts at v1 with that final shape.\n */\nexport async function registerGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ templateId: string; reconciled: ReconciledSchema<G> }>,\n): Promise<GraphTemplate<G>> {\n const register = backend.registerGraphTemplate;\n if (register === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const { reconciled } = params;\n if (reconciled.version === undefined || reconciled.hash === undefined) {\n throw new ConfigurationError(\n \"A graph template requires a reconciled schema from a managed or verified Store.\",\n { code: \"GRAPH_TEMPLATE_REQUIRES_RECONCILED_SCHEMA\" },\n );\n }\n if (\n resolveGraphVectorSlots(reconciled.graph).length > 0 &&\n backend.capabilities.vector?.supported === true\n ) {\n throw new ConfigurationError(\n \"Graph templates do not support embedding fields because vector storage is graph-scoped and cannot be instantiated schema-only.\",\n {\n code: \"GRAPH_TEMPLATE_VECTOR_UNSUPPORTED\",\n graphId: reconciled.graph.id,\n },\n {\n suggestion:\n \"Provision the graph through createStoreWithSchema until template instantiation can atomically materialize vector contributions.\",\n },\n );\n }\n const schemaDocument = serializeSchema(reconciled.graph, reconciled.version);\n const schemaHash = await computeSchemaHash(schemaDocument);\n if (schemaHash !== reconciled.hash) {\n throw new ConfigurationError(\n \"Reconciled schema hash does not match its graph snapshot.\",\n { code: \"GRAPH_TEMPLATE_RECONCILED_HASH_MISMATCH\" },\n );\n }\n await register({\n templateId: params.templateId,\n schemaHash,\n schemaDoc: schemaDocument,\n });\n return Object.freeze({\n id: params.templateId,\n reconciled,\n schemaHash,\n });\n}\n\n/**\n * Instantiates the template's final graph shape as target schema v1. Only the\n * target hash crosses the wire; the durable source document stays in the\n * backend template registry and is rebound to `graphId` by one SQL statement.\n */\nexport async function instantiateGraphTemplate<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n const instantiate = backend.instantiateGraphTemplate;\n if (instantiate === undefined) throw graphTemplatesUnsupportedError(backend);\n await backend.assertBaseSchemaCurrent?.();\n const sourceVersion = params.template.reconciled.version;\n const reconciledHash = params.template.reconciled.hash;\n if (sourceVersion === undefined || reconciledHash === undefined) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const sourceHash = await computeSchemaHash(\n serializeSchema(params.template.reconciled.graph, sourceVersion),\n );\n if (\n sourceHash !== params.template.schemaHash ||\n reconciledHash !== params.template.schemaHash\n ) {\n throw graphTemplateHandleMismatchError(params.template.id);\n }\n const targetGraph: G = Object.freeze({\n ...params.template.reconciled.graph,\n id: params.graphId,\n });\n const targetHash = await computeSchemaHash(serializeSchema(targetGraph, 1));\n const result = await instantiate({\n templateId: params.template.id,\n templateSchemaHash: params.template.schemaHash,\n graphId: params.graphId,\n schemaHash: targetHash,\n });\n if (result.status === \"refused\") {\n throw new ConfigurationError(\n `Graph template instantiation was refused for graph \"${params.graphId}\". The template may be absent, or the graph already has a different schema.`,\n {\n code: \"GRAPH_TEMPLATE_INSTANTIATION_REFUSED\",\n graphId: params.graphId,\n templateId: params.template.id,\n },\n );\n }\n if (\n result.row.graph_id !== params.graphId ||\n result.row.version !== 1 ||\n result.row.schema_hash !== targetHash\n ) {\n throw new ConfigurationError(\n \"Graph template backend returned a schema row that does not match the requested target.\",\n { code: \"GRAPH_TEMPLATE_INVALID_RESULT\", graphId: params.graphId },\n );\n }\n return Object.freeze({\n status: \"ready\",\n reconciled: Object.freeze({\n graph: targetGraph,\n version: result.row.version,\n hash: result.row.schema_hash,\n }),\n schema: result.row,\n });\n}\n\nfunction graphTemplateHandleMismatchError(\n templateId: string,\n): ConfigurationError {\n return new ConfigurationError(\n `Graph template handle \"${templateId}\" does not match its reconciled schema snapshot.`,\n { code: \"GRAPH_TEMPLATE_HANDLE_MISMATCH\", templateId },\n );\n}\n\n/** Short public name for {@link instantiateGraphTemplate}. */\nexport function instantiateGraph<G extends GraphDef>(\n backend: GraphBackend,\n params: Readonly<{ template: GraphTemplate<G>; graphId: string }>,\n): Promise<InstantiateGraphTemplateResult<G>> {\n return instantiateGraphTemplate(backend, params);\n}\n\nfunction graphTemplatesUnsupportedError(\n backend: GraphBackend,\n): ConfigurationError {\n return new ConfigurationError(\n `The ${backend.dialect} backend does not support durable graph templates.`,\n { code: \"GRAPH_TEMPLATES_UNSUPPORTED\", dialect: backend.dialect },\n );\n}\n"]}
|