@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.
Files changed (188) hide show
  1. package/README.md +31 -0
  2. package/dist/backend/postgres/index.cjs +31 -18
  3. package/dist/backend/postgres/index.d.cts +6 -6
  4. package/dist/backend/postgres/index.d.ts +6 -6
  5. package/dist/backend/postgres/index.js +9 -8
  6. package/dist/backend/postgres/pglite.cjs +13 -12
  7. package/dist/backend/postgres/pglite.cjs.map +1 -1
  8. package/dist/backend/postgres/pglite.d.cts +3 -3
  9. package/dist/backend/postgres/pglite.d.ts +3 -3
  10. package/dist/backend/postgres/pglite.js +9 -8
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +29 -16
  13. package/dist/backend/sqlite/index.d.cts +7 -7
  14. package/dist/backend/sqlite/index.d.ts +7 -7
  15. package/dist/backend/sqlite/index.js +8 -7
  16. package/dist/backend/sqlite/libsql.cjs +13 -12
  17. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  18. package/dist/backend/sqlite/libsql.d.cts +3 -3
  19. package/dist/backend/sqlite/libsql.d.ts +3 -3
  20. package/dist/backend/sqlite/libsql.js +9 -8
  21. package/dist/backend/sqlite/libsql.js.map +1 -1
  22. package/dist/backend/sqlite/local.cjs +14 -13
  23. package/dist/backend/sqlite/local.cjs.map +1 -1
  24. package/dist/backend/sqlite/local.d.cts +3 -3
  25. package/dist/backend/sqlite/local.d.ts +3 -3
  26. package/dist/backend/sqlite/local.js +9 -8
  27. package/dist/backend/sqlite/local.js.map +1 -1
  28. package/dist/{chunk-SFFJ2IKN.cjs → chunk-3642VBVC.cjs} +70 -68
  29. package/dist/chunk-3642VBVC.cjs.map +1 -0
  30. package/dist/chunk-3E7SNSIA.cjs +55 -0
  31. package/dist/chunk-3E7SNSIA.cjs.map +1 -0
  32. package/dist/{chunk-6RMLO5O4.cjs → chunk-3IR2GEMJ.cjs} +8 -7
  33. package/dist/chunk-3IR2GEMJ.cjs.map +1 -0
  34. package/dist/{chunk-6SA7UIQJ.cjs → chunk-3QRBXYT5.cjs} +6 -6
  35. package/dist/{chunk-6SA7UIQJ.cjs.map → chunk-3QRBXYT5.cjs.map} +1 -1
  36. package/dist/{chunk-54JVNOAQ.cjs → chunk-4RBAJVEC.cjs} +128 -6
  37. package/dist/chunk-4RBAJVEC.cjs.map +1 -0
  38. package/dist/{chunk-IJORSAC3.js → chunk-6NRFUHMS.js} +4 -3
  39. package/dist/chunk-6NRFUHMS.js.map +1 -0
  40. package/dist/{chunk-FLOI7QOT.cjs → chunk-BF3ZDEUE.cjs} +104 -72
  41. package/dist/chunk-BF3ZDEUE.cjs.map +1 -0
  42. package/dist/{chunk-2HZGWCB4.js → chunk-C4C4Q7A6.js} +3 -3
  43. package/dist/chunk-C4C4Q7A6.js.map +1 -0
  44. package/dist/{chunk-O4VUR6SI.js → chunk-CEF2QOTO.js} +3 -3
  45. package/dist/{chunk-O4VUR6SI.js.map → chunk-CEF2QOTO.js.map} +1 -1
  46. package/dist/{chunk-V4IQYOQ4.cjs → chunk-CFNT3ITG.cjs} +3 -3
  47. package/dist/chunk-CFNT3ITG.cjs.map +1 -0
  48. package/dist/{chunk-LJLMDDCW.js → chunk-CWFPJ3RC.js} +3 -3
  49. package/dist/{chunk-LJLMDDCW.js.map → chunk-CWFPJ3RC.js.map} +1 -1
  50. package/dist/{chunk-RZ4DH4E7.cjs → chunk-D3EWZ67S.cjs} +3348 -2030
  51. package/dist/chunk-D3EWZ67S.cjs.map +1 -0
  52. package/dist/{chunk-GKFWM3DS.js → chunk-DJYRRDHA.js} +124 -5
  53. package/dist/chunk-DJYRRDHA.js.map +1 -0
  54. package/dist/{chunk-YQGLVWB2.cjs → chunk-EF3Z645U.cjs} +2 -52
  55. package/dist/chunk-EF3Z645U.cjs.map +1 -0
  56. package/dist/{chunk-ASYQDPPU.cjs → chunk-FDN43KXV.cjs} +19 -19
  57. package/dist/{chunk-ASYQDPPU.cjs.map → chunk-FDN43KXV.cjs.map} +1 -1
  58. package/dist/chunk-GYVBEZAO.js +120 -0
  59. package/dist/chunk-GYVBEZAO.js.map +1 -0
  60. package/dist/chunk-I4W7MKVG.cjs +1526 -0
  61. package/dist/chunk-I4W7MKVG.cjs.map +1 -0
  62. package/dist/{chunk-MXE2U3EX.js → chunk-IZ4PCL47.js} +3 -52
  63. package/dist/chunk-IZ4PCL47.js.map +1 -0
  64. package/dist/{chunk-4A4GUZTQ.js → chunk-JHOBXD7O.js} +10 -8
  65. package/dist/chunk-JHOBXD7O.js.map +1 -0
  66. package/dist/{chunk-CIINW6PS.cjs → chunk-KY5SDVA7.cjs} +676 -635
  67. package/dist/chunk-KY5SDVA7.cjs.map +1 -0
  68. package/dist/{chunk-N2MBPTAF.cjs → chunk-LM2IC4ZJ.cjs} +14 -14
  69. package/dist/{chunk-N2MBPTAF.cjs.map → chunk-LM2IC4ZJ.cjs.map} +1 -1
  70. package/dist/{chunk-7JGLPAFV.cjs → chunk-MBLXCV2Y.cjs} +16 -16
  71. package/dist/chunk-MBLXCV2Y.cjs.map +1 -0
  72. package/dist/{chunk-5DTPBFX5.cjs → chunk-NG5N7R45.cjs} +28 -28
  73. package/dist/{chunk-5DTPBFX5.cjs.map → chunk-NG5N7R45.cjs.map} +1 -1
  74. package/dist/chunk-OIE2UPVG.cjs +126 -0
  75. package/dist/chunk-OIE2UPVG.cjs.map +1 -0
  76. package/dist/{chunk-STP7QVUB.js → chunk-OS6KS3HV.js} +43 -11
  77. package/dist/chunk-OS6KS3HV.js.map +1 -0
  78. package/dist/{chunk-2ZY4K43M.js → chunk-PIHXFF73.js} +3 -3
  79. package/dist/{chunk-2ZY4K43M.js.map → chunk-PIHXFF73.js.map} +1 -1
  80. package/dist/{chunk-ATTXBMAX.js → chunk-PRMKPFN5.js} +3 -3
  81. package/dist/{chunk-ATTXBMAX.js.map → chunk-PRMKPFN5.js.map} +1 -1
  82. package/dist/chunk-PYD3UCDU.js +1480 -0
  83. package/dist/chunk-PYD3UCDU.js.map +1 -0
  84. package/dist/{chunk-MAQJYNJR.js → chunk-QBYTJSAY.js} +14 -16
  85. package/dist/chunk-QBYTJSAY.js.map +1 -0
  86. package/dist/{chunk-THX25XW6.js → chunk-SPT5JMME.js} +27 -7
  87. package/dist/chunk-SPT5JMME.js.map +1 -0
  88. package/dist/{chunk-3JBJEYWE.cjs → chunk-SST7XDY6.cjs} +32 -12
  89. package/dist/chunk-SST7XDY6.cjs.map +1 -0
  90. package/dist/{chunk-VZX2KSY3.js → chunk-UPDMJEW6.js} +608 -563
  91. package/dist/chunk-UPDMJEW6.js.map +1 -0
  92. package/dist/{chunk-UIFEEPME.js → chunk-WLP6TKFB.js} +3141 -1823
  93. package/dist/chunk-WLP6TKFB.js.map +1 -0
  94. package/dist/{chunk-VMEWZU2N.cjs → chunk-WWVV44DY.cjs} +11 -11
  95. package/dist/{chunk-VMEWZU2N.cjs.map → chunk-WWVV44DY.cjs.map} +1 -1
  96. package/dist/{chunk-UJ4V3YUQ.js → chunk-XKNAK27R.js} +3 -3
  97. package/dist/{chunk-UJ4V3YUQ.js.map → chunk-XKNAK27R.js.map} +1 -1
  98. package/dist/chunk-XLUNB2TZ.js +53 -0
  99. package/dist/chunk-XLUNB2TZ.js.map +1 -0
  100. package/dist/{chunk-XKJQQQVR.js → chunk-XVUJY72M.js} +6 -6
  101. package/dist/{chunk-XKJQQQVR.js.map → chunk-XVUJY72M.js.map} +1 -1
  102. package/dist/{chunk-5CN7B4CZ.cjs → chunk-YW7GHMF4.cjs} +17 -17
  103. package/dist/{chunk-5CN7B4CZ.cjs.map → chunk-YW7GHMF4.cjs.map} +1 -1
  104. package/dist/{ddl-BJcPrB4L.d.ts → ddl-CVnHJcar.d.ts} +3 -3
  105. package/dist/{ddl-CPZ7mB7X.d.cts → ddl-Dxt_fBHr.d.cts} +3 -3
  106. package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
  107. package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
  108. package/dist/graph-extension/index.d.cts +4 -4
  109. package/dist/graph-extension/index.d.ts +4 -4
  110. package/dist/graph-merge/index.cjs +200 -55
  111. package/dist/graph-merge/index.cjs.map +1 -1
  112. package/dist/graph-merge/index.d.cts +6 -6
  113. package/dist/graph-merge/index.d.ts +6 -6
  114. package/dist/graph-merge/index.js +185 -40
  115. package/dist/graph-merge/index.js.map +1 -1
  116. package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
  117. package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
  118. package/dist/index.cjs +145 -116
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.cts +25 -55
  121. package/dist/index.d.ts +25 -55
  122. package/dist/index.js +19 -17
  123. package/dist/index.js.map +1 -1
  124. package/dist/indexes/index.cjs +15 -14
  125. package/dist/indexes/index.d.cts +5 -5
  126. package/dist/indexes/index.d.ts +5 -5
  127. package/dist/indexes/index.js +6 -5
  128. package/dist/interchange/index.cjs +15 -15
  129. package/dist/interchange/index.d.cts +9 -9
  130. package/dist/interchange/index.d.ts +9 -9
  131. package/dist/interchange/index.js +2 -2
  132. package/dist/{manager-Np7VVSlE.d.cts → manager-BYl_zyZR.d.cts} +2 -2
  133. package/dist/{manager-By-WEd8M.d.ts → manager-C0_r0ALf.d.ts} +2 -2
  134. package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
  135. package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
  136. package/dist/{postgres-4J2tmauh.d.cts → postgres-MzBPkYzq.d.ts} +2651 -596
  137. package/dist/{postgres-BdIb7tS_.d.ts → postgres-_9psmVGm.d.cts} +2651 -596
  138. package/dist/profiler/index.cjs +4 -3
  139. package/dist/profiler/index.cjs.map +1 -1
  140. package/dist/profiler/index.d.cts +7 -7
  141. package/dist/profiler/index.d.ts +7 -7
  142. package/dist/profiler/index.js +2 -1
  143. package/dist/profiler/index.js.map +1 -1
  144. package/dist/schema/index.cjs +30 -29
  145. package/dist/schema/index.cjs.map +1 -1
  146. package/dist/schema/index.d.cts +7 -7
  147. package/dist/schema/index.d.ts +7 -7
  148. package/dist/schema/index.js +7 -6
  149. package/dist/schema/index.js.map +1 -1
  150. package/dist/{sqlite-aM_PAz-O.d.ts → sqlite-BfksSb45.d.cts} +2726 -455
  151. package/dist/{sqlite-Gatk_iw_.d.cts → sqlite-gm44dShb.d.ts} +2726 -455
  152. package/dist/{store-DuCbdqsh.d.cts → store-view-9jQ2rPum.d.cts} +1101 -465
  153. package/dist/{store-MloRPwb9.d.ts → store-view-FfE5_7eo.d.ts} +1101 -465
  154. package/dist/{types-DoByHGyU.d.cts → types-B6mhrcLv.d.cts} +2 -2
  155. package/dist/{types-C1CYxWrL.d.cts → types-C_UnQOQp.d.cts} +154 -23
  156. package/dist/{types-K3vpaJAL.d.ts → types-CdWxK-nD.d.ts} +2 -2
  157. package/dist/{types-BKQljXom.d.ts → types-DGylBhWo.d.ts} +154 -23
  158. package/dist/{where-DydZjGOb.d.cts → where-Bpp2ul_z.d.cts} +2 -2
  159. package/dist/{where-Dt49bvo6.d.ts → where-BsEXraKW.d.ts} +2 -2
  160. package/package.json +2 -2
  161. package/dist/chunk-2HZGWCB4.js.map +0 -1
  162. package/dist/chunk-3JBJEYWE.cjs.map +0 -1
  163. package/dist/chunk-4A4GUZTQ.js.map +0 -1
  164. package/dist/chunk-54JVNOAQ.cjs.map +0 -1
  165. package/dist/chunk-6G35I3VW.cjs +0 -40
  166. package/dist/chunk-6G35I3VW.cjs.map +0 -1
  167. package/dist/chunk-6RMLO5O4.cjs.map +0 -1
  168. package/dist/chunk-7JGLPAFV.cjs.map +0 -1
  169. package/dist/chunk-CIINW6PS.cjs.map +0 -1
  170. package/dist/chunk-FLOI7QOT.cjs.map +0 -1
  171. package/dist/chunk-GKFWM3DS.js.map +0 -1
  172. package/dist/chunk-IJORSAC3.js.map +0 -1
  173. package/dist/chunk-M6OC455F.js +0 -65
  174. package/dist/chunk-M6OC455F.js.map +0 -1
  175. package/dist/chunk-MAQJYNJR.js.map +0 -1
  176. package/dist/chunk-MXE2U3EX.js.map +0 -1
  177. package/dist/chunk-RP7YITHX.cjs +0 -70
  178. package/dist/chunk-RP7YITHX.cjs.map +0 -1
  179. package/dist/chunk-RZ4DH4E7.cjs.map +0 -1
  180. package/dist/chunk-SAJSMR2B.js +0 -35
  181. package/dist/chunk-SAJSMR2B.js.map +0 -1
  182. package/dist/chunk-SFFJ2IKN.cjs.map +0 -1
  183. package/dist/chunk-STP7QVUB.js.map +0 -1
  184. package/dist/chunk-THX25XW6.js.map +0 -1
  185. package/dist/chunk-UIFEEPME.js.map +0 -1
  186. package/dist/chunk-V4IQYOQ4.cjs.map +0 -1
  187. package/dist/chunk-VZX2KSY3.js.map +0 -1
  188. package/dist/chunk-YQGLVWB2.cjs.map +0 -1
@@ -1,29 +1,30 @@
1
1
  'use strict';
2
2
 
3
- var chunkRZ4DH4E7_cjs = require('../chunk-RZ4DH4E7.cjs');
3
+ var chunkD3EWZ67S_cjs = require('../chunk-D3EWZ67S.cjs');
4
4
  require('../chunk-HTGDWIDE.cjs');
5
- var chunk3JBJEYWE_cjs = require('../chunk-3JBJEYWE.cjs');
6
- var chunk5DTPBFX5_cjs = require('../chunk-5DTPBFX5.cjs');
7
- var chunk7JGLPAFV_cjs = require('../chunk-7JGLPAFV.cjs');
8
- require('../chunk-6SA7UIQJ.cjs');
9
- require('../chunk-6RMLO5O4.cjs');
10
- require('../chunk-YQGLVWB2.cjs');
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-6G35I3VW.cjs');
14
- var chunkRP7YITHX_cjs = require('../chunk-RP7YITHX.cjs');
15
- require('../chunk-V4IQYOQ4.cjs');
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, chunkRP7YITHX_cjs.sortedReplacer);
24
+ return JSON.stringify(props, chunkOIE2UPVG_cjs.sortedReplacer);
24
25
  }
25
26
  function canonicalValueKey(value) {
26
- return JSON.stringify(value, chunkRP7YITHX_cjs.sortedReplacer);
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 = chunk7JGLPAFV_cjs.getNodeKinds(graph);
232
- const edgeKinds = chunk7JGLPAFV_cjs.getEdgeKinds(graph);
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 chunk5DTPBFX5_cjs.computeSchemaHash(chunk5DTPBFX5_cjs.serializeSchema(store.graph, version));
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 computeContentFingerprint(store) {
322
- const backend = store.backend;
323
- const graphId = store.graphId;
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
- computeContentFingerprint(store)
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 chunk3JBJEYWE_cjs.exportGraph(baseStore, {
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 chunkRZ4DH4E7_cjs.createStoreWithSchema(
456
+ const [freshStore] = await chunkD3EWZ67S_cjs.createStoreWithSchema(
455
457
  baseStore.graph,
456
458
  backend
457
459
  );
458
- const result = await chunk3JBJEYWE_cjs.importGraph(freshStore, data, {
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(chunkRZ4DH4E7_cjs.generateId());
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}${chunkRZ4DH4E7_cjs.computeUniqueKey(
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 = chunk5DTPBFX5_cjs.defineNode("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 chunk7JGLPAFV_cjs.defineGraph({
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 chunkRZ4DH4E7_cjs.createStoreWithSchema(
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 target.transaction(
3237
- (tx) => applyMergePlan(
3238
- plan,
3239
- tx.nodes,
3240
- tx.edges
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(store, target, branches, options, false);
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 rows of perKind) {
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 commitIncrementalPlan(target, plan) {
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 target.transaction(async (tx) => {
3736
- const nodesApi = tx.nodes;
3737
- const edgesApi = tx.edges;
3738
- await validateIncrementalNodeWrites(target, nodesApi, plan);
3739
- await validateIncrementalEdgeWrites(target, edgesApi, plan);
3740
- return applyMergePlan(plan, nodesApi, edgesApi);
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;