@nicia-ai/typegraph 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/backend/postgres/index.cjs +31 -18
- package/dist/backend/postgres/index.d.cts +6 -6
- package/dist/backend/postgres/index.d.ts +6 -6
- package/dist/backend/postgres/index.js +9 -8
- package/dist/backend/postgres/pglite.cjs +13 -12
- package/dist/backend/postgres/pglite.cjs.map +1 -1
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +9 -8
- package/dist/backend/postgres/pglite.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +29 -16
- 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 -7
- package/dist/backend/sqlite/libsql.cjs +13 -12
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +3 -3
- package/dist/backend/sqlite/libsql.d.ts +3 -3
- package/dist/backend/sqlite/libsql.js +9 -8
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +14 -13
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +9 -8
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-SFFJ2IKN.cjs → chunk-3642VBVC.cjs} +70 -68
- package/dist/chunk-3642VBVC.cjs.map +1 -0
- package/dist/chunk-3E7SNSIA.cjs +55 -0
- package/dist/chunk-3E7SNSIA.cjs.map +1 -0
- package/dist/{chunk-6RMLO5O4.cjs → chunk-3IR2GEMJ.cjs} +8 -7
- package/dist/chunk-3IR2GEMJ.cjs.map +1 -0
- package/dist/{chunk-6SA7UIQJ.cjs → chunk-3QRBXYT5.cjs} +6 -6
- package/dist/{chunk-6SA7UIQJ.cjs.map → chunk-3QRBXYT5.cjs.map} +1 -1
- package/dist/{chunk-54JVNOAQ.cjs → chunk-4RBAJVEC.cjs} +128 -6
- package/dist/chunk-4RBAJVEC.cjs.map +1 -0
- package/dist/{chunk-IJORSAC3.js → chunk-6NRFUHMS.js} +4 -3
- package/dist/chunk-6NRFUHMS.js.map +1 -0
- package/dist/{chunk-FLOI7QOT.cjs → chunk-BF3ZDEUE.cjs} +104 -72
- package/dist/chunk-BF3ZDEUE.cjs.map +1 -0
- package/dist/{chunk-2HZGWCB4.js → chunk-C4C4Q7A6.js} +3 -3
- package/dist/chunk-C4C4Q7A6.js.map +1 -0
- package/dist/{chunk-O4VUR6SI.js → chunk-CEF2QOTO.js} +3 -3
- package/dist/{chunk-O4VUR6SI.js.map → chunk-CEF2QOTO.js.map} +1 -1
- package/dist/{chunk-V4IQYOQ4.cjs → chunk-CFNT3ITG.cjs} +3 -3
- package/dist/chunk-CFNT3ITG.cjs.map +1 -0
- package/dist/{chunk-LJLMDDCW.js → chunk-CWFPJ3RC.js} +3 -3
- package/dist/{chunk-LJLMDDCW.js.map → chunk-CWFPJ3RC.js.map} +1 -1
- package/dist/{chunk-RZ4DH4E7.cjs → chunk-D3EWZ67S.cjs} +3348 -2030
- package/dist/chunk-D3EWZ67S.cjs.map +1 -0
- package/dist/{chunk-GKFWM3DS.js → chunk-DJYRRDHA.js} +124 -5
- package/dist/chunk-DJYRRDHA.js.map +1 -0
- package/dist/{chunk-YQGLVWB2.cjs → chunk-EF3Z645U.cjs} +2 -52
- package/dist/chunk-EF3Z645U.cjs.map +1 -0
- package/dist/{chunk-ASYQDPPU.cjs → chunk-FDN43KXV.cjs} +19 -19
- package/dist/{chunk-ASYQDPPU.cjs.map → chunk-FDN43KXV.cjs.map} +1 -1
- package/dist/chunk-GYVBEZAO.js +120 -0
- package/dist/chunk-GYVBEZAO.js.map +1 -0
- package/dist/chunk-I4W7MKVG.cjs +1526 -0
- package/dist/chunk-I4W7MKVG.cjs.map +1 -0
- package/dist/{chunk-MXE2U3EX.js → chunk-IZ4PCL47.js} +3 -52
- package/dist/chunk-IZ4PCL47.js.map +1 -0
- package/dist/{chunk-4A4GUZTQ.js → chunk-JHOBXD7O.js} +10 -8
- package/dist/chunk-JHOBXD7O.js.map +1 -0
- package/dist/{chunk-CIINW6PS.cjs → chunk-KY5SDVA7.cjs} +676 -635
- package/dist/chunk-KY5SDVA7.cjs.map +1 -0
- package/dist/{chunk-N2MBPTAF.cjs → chunk-LM2IC4ZJ.cjs} +14 -14
- package/dist/{chunk-N2MBPTAF.cjs.map → chunk-LM2IC4ZJ.cjs.map} +1 -1
- package/dist/{chunk-7JGLPAFV.cjs → chunk-MBLXCV2Y.cjs} +16 -16
- package/dist/chunk-MBLXCV2Y.cjs.map +1 -0
- package/dist/{chunk-5DTPBFX5.cjs → chunk-NG5N7R45.cjs} +28 -28
- package/dist/{chunk-5DTPBFX5.cjs.map → chunk-NG5N7R45.cjs.map} +1 -1
- package/dist/chunk-OIE2UPVG.cjs +126 -0
- package/dist/chunk-OIE2UPVG.cjs.map +1 -0
- package/dist/{chunk-STP7QVUB.js → chunk-OS6KS3HV.js} +43 -11
- package/dist/chunk-OS6KS3HV.js.map +1 -0
- package/dist/{chunk-2ZY4K43M.js → chunk-PIHXFF73.js} +3 -3
- package/dist/{chunk-2ZY4K43M.js.map → chunk-PIHXFF73.js.map} +1 -1
- package/dist/{chunk-ATTXBMAX.js → chunk-PRMKPFN5.js} +3 -3
- package/dist/{chunk-ATTXBMAX.js.map → chunk-PRMKPFN5.js.map} +1 -1
- package/dist/chunk-PYD3UCDU.js +1480 -0
- package/dist/chunk-PYD3UCDU.js.map +1 -0
- package/dist/{chunk-MAQJYNJR.js → chunk-QBYTJSAY.js} +14 -16
- package/dist/chunk-QBYTJSAY.js.map +1 -0
- package/dist/{chunk-THX25XW6.js → chunk-SPT5JMME.js} +27 -7
- package/dist/chunk-SPT5JMME.js.map +1 -0
- package/dist/{chunk-3JBJEYWE.cjs → chunk-SST7XDY6.cjs} +32 -12
- package/dist/chunk-SST7XDY6.cjs.map +1 -0
- package/dist/{chunk-VZX2KSY3.js → chunk-UPDMJEW6.js} +608 -563
- package/dist/chunk-UPDMJEW6.js.map +1 -0
- package/dist/{chunk-UIFEEPME.js → chunk-WLP6TKFB.js} +3141 -1823
- package/dist/chunk-WLP6TKFB.js.map +1 -0
- package/dist/{chunk-VMEWZU2N.cjs → chunk-WWVV44DY.cjs} +11 -11
- package/dist/{chunk-VMEWZU2N.cjs.map → chunk-WWVV44DY.cjs.map} +1 -1
- package/dist/{chunk-UJ4V3YUQ.js → chunk-XKNAK27R.js} +3 -3
- package/dist/{chunk-UJ4V3YUQ.js.map → chunk-XKNAK27R.js.map} +1 -1
- package/dist/chunk-XLUNB2TZ.js +53 -0
- package/dist/chunk-XLUNB2TZ.js.map +1 -0
- package/dist/{chunk-XKJQQQVR.js → chunk-XVUJY72M.js} +6 -6
- package/dist/{chunk-XKJQQQVR.js.map → chunk-XVUJY72M.js.map} +1 -1
- package/dist/{chunk-5CN7B4CZ.cjs → chunk-YW7GHMF4.cjs} +17 -17
- package/dist/{chunk-5CN7B4CZ.cjs.map → chunk-YW7GHMF4.cjs.map} +1 -1
- package/dist/{ddl-BJcPrB4L.d.ts → ddl-CVnHJcar.d.ts} +3 -3
- package/dist/{ddl-CPZ7mB7X.d.cts → ddl-Dxt_fBHr.d.cts} +3 -3
- package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
- package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
- package/dist/graph-extension/index.d.cts +4 -4
- package/dist/graph-extension/index.d.ts +4 -4
- package/dist/graph-merge/index.cjs +200 -55
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +6 -6
- package/dist/graph-merge/index.d.ts +6 -6
- package/dist/graph-merge/index.js +185 -40
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
- package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
- package/dist/index.cjs +145 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -55
- package/dist/index.d.ts +25 -55
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +15 -14
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +6 -5
- package/dist/interchange/index.cjs +15 -15
- package/dist/interchange/index.d.cts +9 -9
- package/dist/interchange/index.d.ts +9 -9
- package/dist/interchange/index.js +2 -2
- package/dist/{manager-Np7VVSlE.d.cts → manager-BYl_zyZR.d.cts} +2 -2
- package/dist/{manager-By-WEd8M.d.ts → manager-C0_r0ALf.d.ts} +2 -2
- package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
- package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
- package/dist/{postgres-4J2tmauh.d.cts → postgres-MzBPkYzq.d.ts} +2651 -596
- package/dist/{postgres-BdIb7tS_.d.ts → postgres-_9psmVGm.d.cts} +2651 -596
- package/dist/profiler/index.cjs +4 -3
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/profiler/index.js +2 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +30 -29
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +7 -6
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-aM_PAz-O.d.ts → sqlite-BfksSb45.d.cts} +2726 -455
- package/dist/{sqlite-Gatk_iw_.d.cts → sqlite-gm44dShb.d.ts} +2726 -455
- package/dist/{store-DuCbdqsh.d.cts → store-view-9jQ2rPum.d.cts} +1101 -465
- package/dist/{store-MloRPwb9.d.ts → store-view-FfE5_7eo.d.ts} +1101 -465
- package/dist/{types-DoByHGyU.d.cts → types-B6mhrcLv.d.cts} +2 -2
- package/dist/{types-C1CYxWrL.d.cts → types-C_UnQOQp.d.cts} +154 -23
- package/dist/{types-K3vpaJAL.d.ts → types-CdWxK-nD.d.ts} +2 -2
- package/dist/{types-BKQljXom.d.ts → types-DGylBhWo.d.ts} +154 -23
- package/dist/{where-DydZjGOb.d.cts → where-Bpp2ul_z.d.cts} +2 -2
- package/dist/{where-Dt49bvo6.d.ts → where-BsEXraKW.d.ts} +2 -2
- package/package.json +2 -2
- package/dist/chunk-2HZGWCB4.js.map +0 -1
- package/dist/chunk-3JBJEYWE.cjs.map +0 -1
- package/dist/chunk-4A4GUZTQ.js.map +0 -1
- package/dist/chunk-54JVNOAQ.cjs.map +0 -1
- package/dist/chunk-6G35I3VW.cjs +0 -40
- package/dist/chunk-6G35I3VW.cjs.map +0 -1
- package/dist/chunk-6RMLO5O4.cjs.map +0 -1
- package/dist/chunk-7JGLPAFV.cjs.map +0 -1
- package/dist/chunk-CIINW6PS.cjs.map +0 -1
- package/dist/chunk-FLOI7QOT.cjs.map +0 -1
- package/dist/chunk-GKFWM3DS.js.map +0 -1
- package/dist/chunk-IJORSAC3.js.map +0 -1
- package/dist/chunk-M6OC455F.js +0 -65
- package/dist/chunk-M6OC455F.js.map +0 -1
- package/dist/chunk-MAQJYNJR.js.map +0 -1
- package/dist/chunk-MXE2U3EX.js.map +0 -1
- package/dist/chunk-RP7YITHX.cjs +0 -70
- package/dist/chunk-RP7YITHX.cjs.map +0 -1
- package/dist/chunk-RZ4DH4E7.cjs.map +0 -1
- package/dist/chunk-SAJSMR2B.js +0 -35
- package/dist/chunk-SAJSMR2B.js.map +0 -1
- package/dist/chunk-SFFJ2IKN.cjs.map +0 -1
- package/dist/chunk-STP7QVUB.js.map +0 -1
- package/dist/chunk-THX25XW6.js.map +0 -1
- package/dist/chunk-UIFEEPME.js.map +0 -1
- package/dist/chunk-V4IQYOQ4.cjs.map +0 -1
- package/dist/chunk-VZX2KSY3.js.map +0 -1
- package/dist/chunk-YQGLVWB2.cjs.map +0 -1
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD3EWZ67S_cjs = require('../chunk-D3EWZ67S.cjs');
|
|
4
4
|
require('../chunk-HTGDWIDE.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
require('../chunk-
|
|
9
|
-
require('../chunk-
|
|
10
|
-
require('../chunk-
|
|
5
|
+
var chunkSST7XDY6_cjs = require('../chunk-SST7XDY6.cjs');
|
|
6
|
+
var chunkNG5N7R45_cjs = require('../chunk-NG5N7R45.cjs');
|
|
7
|
+
var chunkMBLXCV2Y_cjs = require('../chunk-MBLXCV2Y.cjs');
|
|
8
|
+
require('../chunk-3QRBXYT5.cjs');
|
|
9
|
+
require('../chunk-3IR2GEMJ.cjs');
|
|
10
|
+
require('../chunk-EF3Z645U.cjs');
|
|
11
11
|
require('../chunk-ZFWNO3GE.cjs');
|
|
12
12
|
var chunkKTIEB7VH_cjs = require('../chunk-KTIEB7VH.cjs');
|
|
13
|
-
require('../chunk-
|
|
14
|
-
var
|
|
15
|
-
require('../chunk-
|
|
13
|
+
require('../chunk-I4W7MKVG.cjs');
|
|
14
|
+
var chunkOIE2UPVG_cjs = require('../chunk-OIE2UPVG.cjs');
|
|
15
|
+
require('../chunk-CFNT3ITG.cjs');
|
|
16
16
|
var chunk73KASJGO_cjs = require('../chunk-73KASJGO.cjs');
|
|
17
|
+
require('../chunk-3E7SNSIA.cjs');
|
|
17
18
|
var chunkJIEJCTDS_cjs = require('../chunk-JIEJCTDS.cjs');
|
|
18
19
|
require('../chunk-FLRCVI2G.cjs');
|
|
19
20
|
var zod = require('zod');
|
|
20
21
|
|
|
21
22
|
// src/graph-merge/canonical-props.ts
|
|
22
23
|
function canonicalizeProps(props) {
|
|
23
|
-
return JSON.stringify(props,
|
|
24
|
+
return JSON.stringify(props, chunkOIE2UPVG_cjs.sortedReplacer);
|
|
24
25
|
}
|
|
25
26
|
function canonicalValueKey(value) {
|
|
26
|
-
return JSON.stringify(value,
|
|
27
|
+
return JSON.stringify(value, chunkOIE2UPVG_cjs.sortedReplacer);
|
|
27
28
|
}
|
|
28
29
|
function parseRowProps(props) {
|
|
29
30
|
let parsed;
|
|
@@ -228,8 +229,8 @@ function byId(left, right) {
|
|
|
228
229
|
}
|
|
229
230
|
async function diffAgainstBase(baseStore, forkStore) {
|
|
230
231
|
const graph = baseStore.graph;
|
|
231
|
-
const nodeKinds =
|
|
232
|
-
const edgeKinds =
|
|
232
|
+
const nodeKinds = chunkMBLXCV2Y_cjs.getNodeKinds(graph);
|
|
233
|
+
const edgeKinds = chunkMBLXCV2Y_cjs.getEdgeKinds(graph);
|
|
233
234
|
const newNodes = [];
|
|
234
235
|
const modifiedNodes = [];
|
|
235
236
|
const deletedNodes = [];
|
|
@@ -311,19 +312,16 @@ async function readActiveSchemaVersion(backend, graphId) {
|
|
|
311
312
|
}
|
|
312
313
|
async function computeSchemaComponent(store) {
|
|
313
314
|
const version = await readActiveSchemaVersion(store.backend, store.graphId);
|
|
314
|
-
return
|
|
315
|
+
return chunkNG5N7R45_cjs.computeSchemaHash(chunkNG5N7R45_cjs.serializeSchema(store.graph, version));
|
|
315
316
|
}
|
|
316
317
|
function byDigestEntry(left, right) {
|
|
317
318
|
const byKind = compareStrings(left.kind, right.kind);
|
|
318
319
|
return byKind === 0 ? compareStrings(left.id, right.id) : byKind;
|
|
319
320
|
}
|
|
320
321
|
var CONTENT_FINGERPRINT_BYTES = 16;
|
|
321
|
-
async function
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
const graph = store.graph;
|
|
325
|
-
const nodeKinds = chunk7JGLPAFV_cjs.getNodeKinds(graph);
|
|
326
|
-
const edgeKinds = chunk7JGLPAFV_cjs.getEdgeKinds(graph);
|
|
322
|
+
async function computeContentComponent(backend, graphId, graph) {
|
|
323
|
+
const nodeKinds = chunkMBLXCV2Y_cjs.getNodeKinds(graph);
|
|
324
|
+
const edgeKinds = chunkMBLXCV2Y_cjs.getEdgeKinds(graph);
|
|
327
325
|
const nodeDigest = [];
|
|
328
326
|
for (const kind of nodeKinds) {
|
|
329
327
|
const rows = await enumerateAllNodes(backend, graphId, kind);
|
|
@@ -369,12 +367,16 @@ async function computeContentFingerprint(store) {
|
|
|
369
367
|
async function computeBaseVersion(store) {
|
|
370
368
|
const [schemaComponent, contentComponent] = await Promise.all([
|
|
371
369
|
computeSchemaComponent(store),
|
|
372
|
-
|
|
370
|
+
computeContentComponent(store.backend, store.graphId, store.graph)
|
|
373
371
|
]);
|
|
374
372
|
return asBaseVersion(
|
|
375
373
|
`${schemaComponent}${TOKEN_SEPARATOR}${contentComponent}`
|
|
376
374
|
);
|
|
377
375
|
}
|
|
376
|
+
function contentComponentOf(version) {
|
|
377
|
+
const separatorIndex = version.indexOf(TOKEN_SEPARATOR);
|
|
378
|
+
return separatorIndex === -1 ? version : version.slice(separatorIndex + 1);
|
|
379
|
+
}
|
|
378
380
|
|
|
379
381
|
// src/graph-merge/errors.ts
|
|
380
382
|
var MERGE_ERROR_CODES = {
|
|
@@ -445,17 +447,17 @@ var CLONE_IMPORT_BATCH_SIZE = 1e3;
|
|
|
445
447
|
function cloneWorkingCopyStrategy(makeBackend) {
|
|
446
448
|
return {
|
|
447
449
|
create: async (baseStore) => {
|
|
448
|
-
const data = await
|
|
450
|
+
const data = await chunkSST7XDY6_cjs.exportGraph(baseStore, {
|
|
449
451
|
includeMeta: true,
|
|
450
452
|
includeDeleted: false
|
|
451
453
|
});
|
|
452
454
|
const backend = await makeBackend();
|
|
453
455
|
try {
|
|
454
|
-
const [freshStore] = await
|
|
456
|
+
const [freshStore] = await chunkD3EWZ67S_cjs.createStoreWithSchema(
|
|
455
457
|
baseStore.graph,
|
|
456
458
|
backend
|
|
457
459
|
);
|
|
458
|
-
const result = await
|
|
460
|
+
const result = await chunkSST7XDY6_cjs.importGraph(freshStore, data, {
|
|
459
461
|
onConflict: "error",
|
|
460
462
|
onUnknownProperty: "error",
|
|
461
463
|
validateReferences: true,
|
|
@@ -483,7 +485,7 @@ function cloneWorkingCopyStrategy(makeBackend) {
|
|
|
483
485
|
async function branch(baseStore, makeBackend, options, strategy) {
|
|
484
486
|
try {
|
|
485
487
|
const base = await computeBaseVersion(baseStore);
|
|
486
|
-
const id = options?.id ?? asBranchId(
|
|
488
|
+
const id = options?.id ?? asBranchId(chunkD3EWZ67S_cjs.generateId());
|
|
487
489
|
const workingCopyStrategy = strategy ?? cloneWorkingCopyStrategy(makeBackend);
|
|
488
490
|
const store = await workingCopyStrategy.create(baseStore);
|
|
489
491
|
return chunkKTIEB7VH_cjs.ok({ id, base, store });
|
|
@@ -512,7 +514,7 @@ function constraintSignature(node, constraint) {
|
|
|
512
514
|
return void 0;
|
|
513
515
|
}
|
|
514
516
|
}
|
|
515
|
-
return `${constraint.name}${KEY_PART_SEPARATOR}${
|
|
517
|
+
return `${constraint.name}${KEY_PART_SEPARATOR}${chunkD3EWZ67S_cjs.computeUniqueKey(
|
|
516
518
|
props,
|
|
517
519
|
constraint.fields,
|
|
518
520
|
constraint.collation
|
|
@@ -2055,7 +2057,7 @@ function normalizeMergeOptions(options = {}) {
|
|
|
2055
2057
|
...provenanceWeights === void 0 ? {} : { provenanceWeights }
|
|
2056
2058
|
};
|
|
2057
2059
|
}
|
|
2058
|
-
var Provenance =
|
|
2060
|
+
var Provenance = chunkNG5N7R45_cjs.defineNode("Provenance", {
|
|
2059
2061
|
schema: zod.z.object({
|
|
2060
2062
|
targetGraphId: zod.z.string(),
|
|
2061
2063
|
role: zod.z.enum(["node", "edge"]),
|
|
@@ -2069,14 +2071,14 @@ function provenanceGraphId(targetGraphId) {
|
|
|
2069
2071
|
return `${targetGraphId}::merge-provenance`;
|
|
2070
2072
|
}
|
|
2071
2073
|
function buildProvenanceGraph(targetGraphId) {
|
|
2072
|
-
return
|
|
2074
|
+
return chunkMBLXCV2Y_cjs.defineGraph({
|
|
2073
2075
|
id: provenanceGraphId(targetGraphId),
|
|
2074
2076
|
nodes: { Provenance: { type: Provenance } },
|
|
2075
2077
|
edges: {}
|
|
2076
2078
|
});
|
|
2077
2079
|
}
|
|
2078
2080
|
async function openProvenanceStore(backend, targetGraphId) {
|
|
2079
|
-
const [store] = await
|
|
2081
|
+
const [store] = await chunkD3EWZ67S_cjs.createStoreWithSchema(
|
|
2080
2082
|
buildProvenanceGraph(targetGraphId),
|
|
2081
2083
|
backend
|
|
2082
2084
|
);
|
|
@@ -2507,6 +2509,48 @@ async function stageBranches(baseStore, branches) {
|
|
|
2507
2509
|
};
|
|
2508
2510
|
}
|
|
2509
2511
|
|
|
2512
|
+
// src/graph-merge/tx-retry.ts
|
|
2513
|
+
var RETRYABLE_SQLSTATES = /* @__PURE__ */ new Set(["40001", "40P01"]);
|
|
2514
|
+
var RETRYABLE_MESSAGE_PATTERN = /could not serialize access|deadlock detected/i;
|
|
2515
|
+
var MAX_COMMIT_ATTEMPTS = 3;
|
|
2516
|
+
function isRetryableTxConflict(error) {
|
|
2517
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2518
|
+
let current = error;
|
|
2519
|
+
while (current !== void 0 && current !== null && typeof current === "object" && !seen.has(current)) {
|
|
2520
|
+
seen.add(current);
|
|
2521
|
+
const candidate = current;
|
|
2522
|
+
if (typeof candidate.code === "string" && RETRYABLE_SQLSTATES.has(candidate.code)) {
|
|
2523
|
+
return true;
|
|
2524
|
+
}
|
|
2525
|
+
if (typeof candidate.message === "string" && RETRYABLE_MESSAGE_PATTERN.test(candidate.message)) {
|
|
2526
|
+
return true;
|
|
2527
|
+
}
|
|
2528
|
+
current = candidate.cause;
|
|
2529
|
+
}
|
|
2530
|
+
return false;
|
|
2531
|
+
}
|
|
2532
|
+
async function withTxConflictRetry(commit) {
|
|
2533
|
+
let lastConflict;
|
|
2534
|
+
for (let attempt = 1; attempt <= MAX_COMMIT_ATTEMPTS; attempt += 1) {
|
|
2535
|
+
try {
|
|
2536
|
+
return await commit();
|
|
2537
|
+
} catch (error) {
|
|
2538
|
+
if (!isRetryableTxConflict(error)) {
|
|
2539
|
+
throw error;
|
|
2540
|
+
}
|
|
2541
|
+
lastConflict = error;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
throw new MergeError(
|
|
2545
|
+
`Merge commit aborted by transaction conflicts (serialization failure or deadlock) on ${MAX_COMMIT_ATTEMPTS} consecutive attempts; giving up.`,
|
|
2546
|
+
{
|
|
2547
|
+
cause: lastConflict,
|
|
2548
|
+
details: { attempts: MAX_COMMIT_ATTEMPTS },
|
|
2549
|
+
suggestion: "Reduce concurrent writes to the merge target, or serialize merges against it."
|
|
2550
|
+
}
|
|
2551
|
+
);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2510
2554
|
// src/graph-merge/type-reconcile.ts
|
|
2511
2555
|
var INCOMPATIBLE_TYPES_FLAG_REASON = "type-reconcile:incompatible-kinds";
|
|
2512
2556
|
function distinctKinds(kinds) {
|
|
@@ -3226,20 +3270,48 @@ async function applyMergePlan(plan, nodesApi, edgesApi) {
|
|
|
3226
3270
|
}
|
|
3227
3271
|
return { nodes: committedNodeIds.size, edges: committedEdges };
|
|
3228
3272
|
}
|
|
3229
|
-
async function commitPlan(target, plan) {
|
|
3273
|
+
async function commitPlan(target, plan, expectedBaseVersion) {
|
|
3230
3274
|
if (!target.backend.capabilities.transactions) {
|
|
3231
3275
|
throw new MergeError(
|
|
3232
3276
|
"merge() requires a transaction-capable target backend. The merged plan (canonical upserts, soft-deletes, edge upserts) must commit atomically; a non-transactional fallback would leave a partially-merged graph on a mid-commit failure. (mergeIncremental() enforces the same requirement.)",
|
|
3233
3277
|
{ details: { capability: "transactions" } }
|
|
3234
3278
|
);
|
|
3235
3279
|
}
|
|
3236
|
-
return
|
|
3237
|
-
(tx) =>
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3280
|
+
return withTxConflictRetry(
|
|
3281
|
+
() => target.transaction(async (tx) => {
|
|
3282
|
+
if (expectedBaseVersion !== void 0) {
|
|
3283
|
+
await assertTargetUnchanged(tx.backend, target, expectedBaseVersion);
|
|
3284
|
+
}
|
|
3285
|
+
return applyMergePlan(
|
|
3286
|
+
plan,
|
|
3287
|
+
tx.nodes,
|
|
3288
|
+
tx.edges
|
|
3289
|
+
);
|
|
3290
|
+
}, MERGE_COMMIT_TX_OPTIONS)
|
|
3291
|
+
);
|
|
3292
|
+
}
|
|
3293
|
+
var MERGE_COMMIT_TX_OPTIONS = {
|
|
3294
|
+
isolationLevel: "serializable"
|
|
3295
|
+
};
|
|
3296
|
+
async function assertTargetUnchanged(txBackend, target, expectedBaseVersion) {
|
|
3297
|
+
const liveContent = await computeContentComponent(
|
|
3298
|
+
txBackend,
|
|
3299
|
+
target.graphId,
|
|
3300
|
+
target.graph
|
|
3242
3301
|
);
|
|
3302
|
+
const expectedContent = contentComponentOf(expectedBaseVersion);
|
|
3303
|
+
if (liveContent !== expectedContent) {
|
|
3304
|
+
throw new BaseVersionMismatchError(
|
|
3305
|
+
"The merge target was modified between the base@V check and the commit transaction; the resolved plan no longer describes the live target and was not applied.",
|
|
3306
|
+
{
|
|
3307
|
+
details: {
|
|
3308
|
+
expectedContentFingerprint: expectedContent,
|
|
3309
|
+
liveContentFingerprint: liveContent
|
|
3310
|
+
},
|
|
3311
|
+
suggestion: "Re-run the merge (and re-branch if the divergence is real), or serialize writers against merges on this target."
|
|
3312
|
+
}
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3243
3315
|
}
|
|
3244
3316
|
function nodeCollection(nodes, kind) {
|
|
3245
3317
|
const collection = nodes[kind];
|
|
@@ -3277,7 +3349,7 @@ async function validateBaseVersions(target, branches) {
|
|
|
3277
3349
|
);
|
|
3278
3350
|
}
|
|
3279
3351
|
}
|
|
3280
|
-
return chunkKTIEB7VH_cjs.ok();
|
|
3352
|
+
return chunkKTIEB7VH_cjs.ok(targetVersion);
|
|
3281
3353
|
}
|
|
3282
3354
|
function tryNormalize(optionsInput) {
|
|
3283
3355
|
try {
|
|
@@ -3286,7 +3358,7 @@ function tryNormalize(optionsInput) {
|
|
|
3286
3358
|
return chunkKTIEB7VH_cjs.err(new MergeError("Invalid merge options.", { cause: error }));
|
|
3287
3359
|
}
|
|
3288
3360
|
}
|
|
3289
|
-
async function resolveMerge(store, target, branches, options, useBaseSources, incremental) {
|
|
3361
|
+
async function resolveMerge(store, target, branches, options, useBaseSources, incremental, expectedBaseVersion) {
|
|
3290
3362
|
let targetBranchSeen = false;
|
|
3291
3363
|
for (const branch2 of branches) {
|
|
3292
3364
|
if (branch2.id === BASE_PROVENANCE_BRANCH) {
|
|
@@ -3357,7 +3429,16 @@ async function resolveMerge(store, target, branches, options, useBaseSources, in
|
|
|
3357
3429
|
subClassClosure,
|
|
3358
3430
|
preferredBranchId
|
|
3359
3431
|
);
|
|
3360
|
-
const merged = incremental === void 0 ? await commitPlan(target, plan) : await commitIncrementalPlan(target, plan
|
|
3432
|
+
const merged = incremental === void 0 ? await commitPlan(target, plan, expectedBaseVersion) : await commitIncrementalPlan(target, plan, {
|
|
3433
|
+
stagedNewByKind: newNodesByKind(staging),
|
|
3434
|
+
options,
|
|
3435
|
+
introspectionKinds,
|
|
3436
|
+
// The committed (kind, id) keys the base sources matched at PLAN time;
|
|
3437
|
+
// anything NEW the in-tx re-probe surfaces is a window write.
|
|
3438
|
+
plannedBaseMatchKeys: new Set(
|
|
3439
|
+
candidates.data.baseMembers.map((member) => mergeKeyOf(member))
|
|
3440
|
+
)
|
|
3441
|
+
});
|
|
3361
3442
|
const provenance = options.provenance ? buildProvenanceIndex(plan.provenanceRecords) : { byBranch: () => ({ nodeIds: [], edgeIds: [] }) };
|
|
3362
3443
|
const warnings = [...plan.warnings];
|
|
3363
3444
|
let provenancePersisted;
|
|
@@ -3418,7 +3499,15 @@ async function merge(store, branches, optionsInput = {}) {
|
|
|
3418
3499
|
if (chunkKTIEB7VH_cjs.isErr(precondition)) {
|
|
3419
3500
|
return chunkKTIEB7VH_cjs.err(precondition.error);
|
|
3420
3501
|
}
|
|
3421
|
-
return resolveMerge(
|
|
3502
|
+
return resolveMerge(
|
|
3503
|
+
store,
|
|
3504
|
+
target,
|
|
3505
|
+
branches,
|
|
3506
|
+
options,
|
|
3507
|
+
false,
|
|
3508
|
+
void 0,
|
|
3509
|
+
precondition.data
|
|
3510
|
+
);
|
|
3422
3511
|
}
|
|
3423
3512
|
async function validateForkPointVersions(forkPoint, branches) {
|
|
3424
3513
|
const forkVersion = await computeBaseVersion(forkPoint);
|
|
@@ -3651,13 +3740,12 @@ async function validateIncrementalEdgeWrites(target, edgesApi, plan) {
|
|
|
3651
3740
|
}
|
|
3652
3741
|
const notFound = [...plannedKindById.keys()].filter((id) => !existingById.has(id)).sort((left, right) => compareStrings(left, right));
|
|
3653
3742
|
if (notFound.length > 0) {
|
|
3654
|
-
const perKind = await Promise.all(
|
|
3655
|
-
Object.keys(target.graph.edges).map(
|
|
3656
|
-
(kind) => edgeCollection(edgesApi, kind).getByIds(notFound, INCLUDE_TOMBSTONES)
|
|
3657
|
-
)
|
|
3658
|
-
);
|
|
3659
3743
|
const crossKindById = /* @__PURE__ */ new Map();
|
|
3660
|
-
for (const
|
|
3744
|
+
for (const kind of Object.keys(target.graph.edges)) {
|
|
3745
|
+
const rows = await edgeCollection(edgesApi, kind).getByIds(
|
|
3746
|
+
notFound,
|
|
3747
|
+
INCLUDE_TOMBSTONES
|
|
3748
|
+
);
|
|
3661
3749
|
for (const [index, id] of notFound.entries()) {
|
|
3662
3750
|
const row = rows[index];
|
|
3663
3751
|
if (row !== void 0 && !crossKindById.has(id)) {
|
|
@@ -3725,20 +3813,77 @@ async function validateIncrementalEdgeWrites(target, edgesApi, plan) {
|
|
|
3725
3813
|
}
|
|
3726
3814
|
}
|
|
3727
3815
|
}
|
|
3728
|
-
async function
|
|
3816
|
+
async function collectBaseMatchKeys(lookupStore, guard) {
|
|
3817
|
+
const matched = /* @__PURE__ */ new Set();
|
|
3818
|
+
for (const [kind, stagedNodes] of guard.stagedNewByKind) {
|
|
3819
|
+
const resolveConfig = guard.options.resolve[kind];
|
|
3820
|
+
if (resolveConfig === void 0) {
|
|
3821
|
+
continue;
|
|
3822
|
+
}
|
|
3823
|
+
const collection = lookupStore.nodes[kind];
|
|
3824
|
+
if (collection === void 0 || stagedNodes.length === 0) {
|
|
3825
|
+
continue;
|
|
3826
|
+
}
|
|
3827
|
+
const items = stagedNodes.map((staged) => ({ props: staged.node.props }));
|
|
3828
|
+
for (const constraint of uniqueConstraintsFor(
|
|
3829
|
+
guard.introspectionKinds,
|
|
3830
|
+
kind
|
|
3831
|
+
)) {
|
|
3832
|
+
const matches = await collection.bulkFindByConstraint(
|
|
3833
|
+
constraint.name,
|
|
3834
|
+
items
|
|
3835
|
+
);
|
|
3836
|
+
for (const base of matches) {
|
|
3837
|
+
if (base !== void 0) {
|
|
3838
|
+
matched.add(mergeKeyOf(base));
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
if (resolveConfig.blockIndex !== void 0) {
|
|
3843
|
+
const matchesByItem = await collection.bulkFindByIndex(
|
|
3844
|
+
resolveConfig.blockIndex,
|
|
3845
|
+
items
|
|
3846
|
+
);
|
|
3847
|
+
for (const perItem of matchesByItem) {
|
|
3848
|
+
for (const base of perItem) {
|
|
3849
|
+
matched.add(mergeKeyOf(base));
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
return matched;
|
|
3855
|
+
}
|
|
3856
|
+
async function assertBaseResolutionStable(lookupStore, guard) {
|
|
3857
|
+
const liveKeys = await collectBaseMatchKeys(lookupStore, guard);
|
|
3858
|
+
const appeared = [...liveKeys].filter((key) => !guard.plannedBaseMatchKeys.has(key)).sort((left, right) => compareMergeKeys(left, right));
|
|
3859
|
+
if (appeared.length === 0) {
|
|
3860
|
+
return;
|
|
3861
|
+
}
|
|
3862
|
+
throw new BaseVersionMismatchError(
|
|
3863
|
+
`mergeIncremental() resolved its branch additions against the target as of planning, but ${appeared.length} committed row(s) matching a branch addition's identity key (a unique constraint or block index) were inserted before the commit transaction. Committing the plan would create duplicate entities the base-source resolution would otherwise have collapsed.`,
|
|
3864
|
+
{
|
|
3865
|
+
details: { appeared },
|
|
3866
|
+
suggestion: "Re-run mergeIncremental(); the re-planned merge resolves the branch additions against the now-committed rows."
|
|
3867
|
+
}
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3870
|
+
async function commitIncrementalPlan(target, plan, guard) {
|
|
3729
3871
|
if (!target.backend.capabilities.transactions) {
|
|
3730
3872
|
throw new MergeError(
|
|
3731
3873
|
"mergeIncremental() requires a transaction-capable target backend. Incremental writes must preflight existing rows and commit atomically; non-transactional fallback would allow partial graph writes.",
|
|
3732
3874
|
{ details: { capability: "transactions" } }
|
|
3733
3875
|
);
|
|
3734
3876
|
}
|
|
3735
|
-
return
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3877
|
+
return withTxConflictRetry(
|
|
3878
|
+
() => target.transaction(async (tx) => {
|
|
3879
|
+
const nodesApi = tx.nodes;
|
|
3880
|
+
const edgesApi = tx.edges;
|
|
3881
|
+
await assertBaseResolutionStable(tx, guard);
|
|
3882
|
+
await validateIncrementalNodeWrites(target, nodesApi, plan);
|
|
3883
|
+
await validateIncrementalEdgeWrites(target, edgesApi, plan);
|
|
3884
|
+
return applyMergePlan(plan, nodesApi, edgesApi);
|
|
3885
|
+
}, MERGE_COMMIT_TX_OPTIONS)
|
|
3886
|
+
);
|
|
3742
3887
|
}
|
|
3743
3888
|
async function mergeIncremental(args) {
|
|
3744
3889
|
const { forkPoint, target, branches } = args;
|