@dialecte/core 0.6.0 → 0.6.1

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.
@@ -1,4 +1,4 @@
1
- import { C as e, I as t, L as n, M as r, N as i, S as a, T as o, b as s, c, g as l, k as u, m as d, n as f, p, s as m, t as h, v as g, w as _, y as v } from "./utils-CZ12wsuC.js";
1
+ import { A as e, C as t, E as n, L as r, N as i, P as a, R as o, T as s, _ as c, b as l, c as u, h as d, l as f, m as p, n as m, t as h, w as g, x as _, y as v } from "./utils-CTBHUFs9.js";
2
2
  import { assertNoFixedViolation as y, assertXsiTypeAdmitted as b, assertXsiTypeChangeLeavesNothing as x, isRecordOf as S, mergeExtensions as C, standardizeRecord as ee, toFullAttributeArray as w, toRawRecord as te, toRef as T, toTreeRecord as ne } from "./helpers.js";
3
3
  //#region \0rolldown/runtime.js
4
4
  var re = Object.create, ie = Object.defineProperty, ae = Object.getOwnPropertyDescriptor, E = Object.getOwnPropertyNames, D = Object.getPrototypeOf, oe = Object.prototype.hasOwnProperty, O = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), se = (e, t, n, r) => {
@@ -119,12 +119,12 @@ function pe(e) {
119
119
  status: "deleted"
120
120
  };
121
121
  }
122
- function j(e, n, r) {
123
- e !== n && t("ELEMENT_TAGNAME_MISMATCH", {
124
- detail: `Expected tagName '${n}', got '${e}' for id '${r}'`,
122
+ function j(e, t, n) {
123
+ e !== t && r("ELEMENT_TAGNAME_MISMATCH", {
124
+ detail: `Expected tagName '${t}', got '${e}' for id '${n}'`,
125
125
  ref: {
126
- tagName: n,
127
- id: r
126
+ tagName: t,
127
+ id: n
128
128
  }
129
129
  });
130
130
  }
@@ -197,27 +197,27 @@ function he(e) {
197
197
  //#endregion
198
198
  //#region src/document/query/get/record/get-record.ts
199
199
  async function N(e) {
200
- let { context: n, ref: r } = e;
201
- if (n.stagedOperations.log.length > 0) {
200
+ let { context: t, ref: n } = e;
201
+ if (t.stagedOperations.log.length > 0) {
202
202
  let e = fe({
203
- stagedOperations: n.stagedOperations,
204
- tagName: r.tagName,
205
- id: r.id
203
+ stagedOperations: t.stagedOperations,
204
+ tagName: n.tagName,
205
+ id: n.id
206
206
  });
207
207
  if (e?.status === "deleted") return;
208
208
  if (e) return e;
209
209
  }
210
210
  let i;
211
- if (r.id === void 0) {
212
- let e = `__singleton_${r.tagName}`, t = vn(n) ? n.recordCache.get(e) : void 0;
213
- t ? (n.perf.count("core::query::getRecord.cacheHit"), i = t) : (n.perf.count("core::query::getRecord.miss"), n.perf.count("core::store::getByTagName"), i = (await n.store.getByTagNameInDocument(r.tagName, n.documentId))[0], i && vn(n) && (n.recordCache.set(i.id, i), n.recordCache.set(e, i)));
211
+ if (n.id === void 0) {
212
+ let e = `__singleton_${n.tagName}`, r = vn(t) ? t.recordCache.get(e) : void 0;
213
+ r ? (t.perf.count("core::query::getRecord.cacheHit"), i = r) : (t.perf.count("core::query::getRecord.miss"), t.perf.count("core::store::getByTagName"), i = (await t.store.getByTagNameInDocument(n.tagName, t.documentId))[0], i && vn(t) && (t.recordCache.set(i.id, i), t.recordCache.set(e, i)));
214
214
  } else {
215
- let e = vn(n) ? n.recordCache.get(r.id) : void 0;
216
- e ? (n.perf.count("core::query::getRecord.cacheHit"), i = e) : (n.perf.count("core::query::getRecord.miss"), n.perf.count("core::store::get"), i = await n.store.get(r.id, n.documentId), i && vn(n) && n.recordCache.set(r.id, i));
215
+ let e = vn(t) ? t.recordCache.get(n.id) : void 0;
216
+ e ? (t.perf.count("core::query::getRecord.cacheHit"), i = e) : (t.perf.count("core::query::getRecord.miss"), t.perf.count("core::store::get"), i = await t.store.get(n.id, t.documentId), i && vn(t) && t.recordCache.set(n.id, i));
217
217
  }
218
- if (i) return i.tagName !== r.tagName && t("ELEMENT_TAGNAME_MISMATCH", {
219
- detail: `Expected tagName '${r.tagName}', got '${i.tagName}' for id '${r.id}'`,
220
- ref: r
218
+ if (i) return i.tagName !== n.tagName && r("ELEMENT_TAGNAME_MISMATCH", {
219
+ detail: `Expected tagName '${n.tagName}', got '${i.tagName}' for id '${n.id}'`,
220
+ ref: n
221
221
  }), {
222
222
  ...i,
223
223
  status: "unchanged"
@@ -359,23 +359,23 @@ function F(e) {
359
359
  return !0;
360
360
  }
361
361
  function xe(e) {
362
- let { dialecteConfig: t, record: n, expected: r } = e, i = n.attributes.find(s);
363
- if (i === void 0 || i.value === "") return !1;
364
- let o = v({
365
- dialecteConfig: t,
366
- value: i.value,
367
- namespaceOf: a({
368
- dialecteConfig: t,
369
- attributes: n.attributes
362
+ let { dialecteConfig: n, record: r, expected: i } = e, a = r.attributes.find(_);
363
+ if (a === void 0 || a.value === "") return !1;
364
+ let o = l({
365
+ dialecteConfig: n,
366
+ value: a.value,
367
+ namespaceOf: t({
368
+ dialecteConfig: n,
369
+ attributes: r.attributes
370
370
  })
371
- }), c = a({
372
- dialecteConfig: t,
371
+ }), s = t({
372
+ dialecteConfig: n,
373
373
  attributes: []
374
374
  });
375
- return (Array.isArray(r) ? r : [r]).filter((e) => typeof e == "string").some((e) => v({
376
- dialecteConfig: t,
375
+ return (Array.isArray(i) ? i : [i]).filter((e) => typeof e == "string").some((e) => l({
376
+ dialecteConfig: n,
377
377
  value: e,
378
- namespaceOf: c
378
+ namespaceOf: s
379
379
  }) === o);
380
380
  }
381
381
  //#endregion
@@ -624,11 +624,11 @@ async function I(e) {
624
624
  let { context: t, ref: n, name: r, namespace: i, defaults: a = "optional" } = e, o = await N({
625
625
  context: t,
626
626
  ref: n
627
- }), s = o?.attributes ?? [], c = Ie(t.dialecteConfig, r, i), u = s.find((e) => e.name === c);
628
- return u ? u.value : (o ? l({
627
+ }), s = o?.attributes ?? [], l = Ie(t.dialecteConfig, r, i), u = s.find((e) => e.name === l);
628
+ return u ? u.value : (o ? c({
629
629
  dialecteConfig: t.dialecteConfig,
630
630
  record: o,
631
- attributeName: c,
631
+ attributeName: l,
632
632
  defaults: a
633
633
  }) : void 0) ?? "";
634
634
  }
@@ -636,10 +636,10 @@ async function Fe(e) {
636
636
  let { context: t, ref: n, name: r, namespace: i, defaults: a = "optional" } = e, { dialecteConfig: o } = t, s = await N({
637
637
  context: t,
638
638
  ref: n
639
- }), c = s?.attributes ?? [], u = Ie(o, r, i), f = c.find((e) => e.name === u);
639
+ }), l = s?.attributes ?? [], u = Ie(o, r, i), f = l.find((e) => e.name === u);
640
640
  if (f) return f;
641
641
  if (!s || a === "none") return;
642
- let p = l({
642
+ let p = c({
643
643
  dialecteConfig: o,
644
644
  record: s,
645
645
  attributeName: u,
@@ -659,7 +659,7 @@ async function Fe(e) {
659
659
  }
660
660
  function Ie(e, t, n) {
661
661
  if (n === void 0) return t;
662
- let r = m(e, n);
662
+ let r = u(e, n);
663
663
  return r ? `${r}:${t}` : t;
664
664
  }
665
665
  //#endregion
@@ -668,35 +668,35 @@ async function Le(e) {
668
668
  let { context: t, ref: n, namespace: r, defaults: i = "optional" } = e, { dialecteConfig: a } = t, o = await N({
669
669
  context: t,
670
670
  ref: n
671
- }), s = o?.attributes ?? [], c = r === void 0 ? void 0 : m(a, r), u = s.reduce((e, t) => {
671
+ }), s = o?.attributes ?? [], l = r === void 0 ? void 0 : u(a, r), d = s.reduce((e, t) => {
672
672
  let n = L({
673
673
  name: t.name,
674
674
  namespace: t.namespace,
675
- targetPrefix: c
675
+ targetPrefix: l
676
676
  });
677
677
  return n !== void 0 && (e[n] = t.value ?? ""), e;
678
678
  }, {});
679
679
  if (o && i !== "none") {
680
- let e = g({
680
+ let e = v({
681
681
  dialecteConfig: a,
682
682
  record: o
683
683
  })?.attributes.sequence ?? [];
684
684
  for (let t of e) {
685
685
  let e = L({
686
686
  name: t,
687
- targetPrefix: c
687
+ targetPrefix: l
688
688
  });
689
- if (e === void 0 || e in u) continue;
690
- let n = l({
689
+ if (e === void 0 || e in d) continue;
690
+ let n = c({
691
691
  dialecteConfig: a,
692
692
  record: o,
693
693
  attributeName: t,
694
694
  defaults: i
695
695
  });
696
- n !== void 0 && (u[e] = n);
696
+ n !== void 0 && (d[e] = n);
697
697
  }
698
698
  }
699
- return u;
699
+ return d;
700
700
  }
701
701
  function L(e) {
702
702
  let { name: t, namespace: n, targetPrefix: r } = e, { prefix: i, local: a, isXmlns: o } = ze(t);
@@ -708,13 +708,13 @@ async function Re(e) {
708
708
  ref: n
709
709
  }), o = [...a?.attributes ?? []];
710
710
  if (a && r !== "none") {
711
- let e = new Set(o.map((e) => e.name)), t = g({
711
+ let e = new Set(o.map((e) => e.name)), t = v({
712
712
  dialecteConfig: i,
713
713
  record: a
714
714
  })?.attributes.sequence ?? [];
715
715
  for (let n of t) {
716
716
  if (e.has(n)) continue;
717
- let t = l({
717
+ let t = c({
718
718
  dialecteConfig: i,
719
719
  record: a,
720
720
  attributeName: n,
@@ -759,7 +759,7 @@ async function Be(e) {
759
759
  context: t,
760
760
  ref: n
761
761
  });
762
- if (r) return g({
762
+ if (r) return v({
763
763
  dialecteConfig: t.dialecteConfig,
764
764
  record: r
765
765
  });
@@ -858,7 +858,7 @@ function Ke(e) {
858
858
  let { tree: t, childrenConfig: n } = e;
859
859
  function r(e) {
860
860
  if (e.tree.length === 0) return e;
861
- let t = f({
861
+ let t = m({
862
862
  parentTagName: e.tagName,
863
863
  children: e.tree.map(r),
864
864
  childrenConfig: n
@@ -873,24 +873,24 @@ function Ke(e) {
873
873
  //#endregion
874
874
  //#region src/document/query/get/tree/get-tree.ts
875
875
  async function qe(e) {
876
- let { context: t, ref: n, options: r = {}, dialecteConfig: i } = e, { select: a, omit: o, unwrap: s, depth: l } = r, u = l !== void 0 && n.id !== void 0 && t.stagedOperations.log.length === 0 ? await R(t, n, l) : await Je(t), d = z(u, n);
877
- c(d, {
876
+ let { context: t, ref: n, options: r = {}, dialecteConfig: i } = e, { select: a, omit: o, unwrap: s, depth: c } = r, l = c !== void 0 && n.id !== void 0 && t.stagedOperations.log.length === 0 ? await R(t, n, c) : await Je(t), u = z(l, n);
877
+ f(u, {
878
878
  detail: "No record found for provided ref",
879
879
  key: "ELEMENT_NOT_FOUND"
880
880
  });
881
- let f = He({
881
+ let d = He({
882
882
  omit: o,
883
883
  dialecteConfig: t.dialecteConfig
884
884
  }), p = t.dialecteConfig.transparentElements, m = Ye({
885
- recordsById: u,
886
- record: d,
885
+ recordsById: l,
886
+ record: u,
887
887
  select: a,
888
- compiledOmit: f,
888
+ compiledOmit: d,
889
889
  dialecteConfig: i,
890
890
  transparentElements: p,
891
- remainingDepth: l ?? Infinity
891
+ remainingDepth: c ?? Infinity
892
892
  });
893
- if (!m) return ne({ record: d });
893
+ if (!m) return ne({ record: u });
894
894
  let h = s ?? (p?.length ? p : void 0);
895
895
  return Ke({
896
896
  tree: h ? Ve({
@@ -1102,12 +1102,12 @@ async function it(e) {
1102
1102
  context: t,
1103
1103
  includeDeleted: a
1104
1104
  });
1105
- let o = e.siblings ?? !1, s = o === !0 || typeof o == "object" && !!o, l = typeof o == "object" && !!o && o.expand === !0, u = n ?? { tagName: t.dialecteConfig.rootElementName }, d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = a ? he(t.stagedOperations.log) : void 0;
1105
+ let o = e.siblings ?? !1, s = o === !0 || typeof o == "object" && !!o, c = typeof o == "object" && !!o && o.expand === !0, l = n ?? { tagName: t.dialecteConfig.rootElementName }, u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), p = a ? he(t.stagedOperations.log) : void 0;
1106
1106
  function m(e) {
1107
- if (p) for (let t of p.get(e) ?? []) f.has(t.id) || (f.set(t.id, t), m(t.id));
1107
+ if (p) for (let t of p.get(e) ?? []) d.has(t.id) || (d.set(t.id, t), m(t.id));
1108
1108
  }
1109
1109
  async function h(e, n) {
1110
- if (d.set(e.id, e), m(e.id), !(i !== void 0 && n >= i)) for (let r of e.children) {
1110
+ if (u.set(e.id, e), m(e.id), !(i !== void 0 && n >= i)) for (let r of e.children) {
1111
1111
  let e = await N({
1112
1112
  context: t,
1113
1113
  ref: T(r)
@@ -1117,9 +1117,9 @@ async function it(e) {
1117
1117
  }
1118
1118
  let g = await N({
1119
1119
  context: t,
1120
- ref: u
1120
+ ref: l
1121
1121
  });
1122
- c(g, {
1122
+ f(g, {
1123
1123
  key: "ELEMENT_NOT_FOUND",
1124
1124
  detail: "No record found for the provided ref"
1125
1125
  });
@@ -1129,13 +1129,13 @@ async function it(e) {
1129
1129
  if (v > 0) {
1130
1130
  let e = await ye({
1131
1131
  context: t,
1132
- ref: u,
1132
+ ref: l,
1133
1133
  options: {
1134
1134
  depth: v,
1135
1135
  order: "bottom-up"
1136
1136
  }
1137
1137
  });
1138
- for (let t of e) d.set(t.id, t), _ = t.id;
1138
+ for (let t of e) u.set(t.id, t), _ = t.id;
1139
1139
  if (s) {
1140
1140
  let n = [g, ...e];
1141
1141
  for (let e = 0; e < n.length - 1; e++) {
@@ -1146,14 +1146,14 @@ async function it(e) {
1146
1146
  context: t,
1147
1147
  ref: T(e)
1148
1148
  });
1149
- n && (l ? await h(n, 0) : d.set(n.id, n));
1149
+ n && (c ? await h(n, 0) : u.set(n.id, n));
1150
1150
  }
1151
1151
  }
1152
1152
  }
1153
1153
  }
1154
1154
  return ot({
1155
- live: d,
1156
- deletedById: f,
1155
+ live: u,
1156
+ deletedById: d,
1157
1157
  rootId: _
1158
1158
  });
1159
1159
  }
@@ -1167,7 +1167,7 @@ async function at(e) {
1167
1167
  a = e.id;
1168
1168
  break;
1169
1169
  }
1170
- return c(a, {
1170
+ return f(a, {
1171
1171
  key: "ROOT_NOT_FOUND",
1172
1172
  detail: `No ${t.dialecteConfig.rootElementName} root element found in document`
1173
1173
  }), ot({
@@ -1201,18 +1201,18 @@ function st(e) {
1201
1201
  n.push(e), o.set(t, n);
1202
1202
  }
1203
1203
  let s = i.get(r);
1204
- c(s, {
1204
+ f(s, {
1205
1205
  key: "ROOT_NOT_FOUND",
1206
1206
  detail: `No record found for rootId "${r}"`
1207
1207
  });
1208
- function l(e, t) {
1209
- let n = t === "live" ? i : a, r = e.children.filter((e) => n.has(e.id)).map((e) => l(n.get(e.id), t)), s = t === "live" ? (o.get(e.id) ?? []).map((e) => l(e, "deleted")) : [];
1208
+ function c(e, t) {
1209
+ let n = t === "live" ? i : a, r = e.children.filter((e) => n.has(e.id)).map((e) => c(n.get(e.id), t)), s = t === "live" ? (o.get(e.id) ?? []).map((e) => c(e, "deleted")) : [];
1210
1210
  return ne({
1211
1211
  record: e,
1212
1212
  tree: [...r, ...s]
1213
1213
  });
1214
1214
  }
1215
- return l(s, "live");
1215
+ return c(s, "live");
1216
1216
  }
1217
1217
  //#endregion
1218
1218
  //#region node_modules/xml-parser-xo/dist/cjs/index.js
@@ -1505,67 +1505,67 @@ async function ft(e) {
1505
1505
  function pt(e) {
1506
1506
  let { records: t, config: n, withDatabaseIds: r = !1, rootId: i, declareNamespaces: a = !0 } = e, o = /* @__PURE__ */ new Map(), s;
1507
1507
  for (let e of t) o.set(e.id, e), e.tagName === n.rootElementName && (s = e);
1508
- let l = i ? o.get(i) : s;
1509
- c(l, {
1508
+ let c = i ? o.get(i) : s;
1509
+ f(c, {
1510
1510
  detail: i ? `No record found for rootId "${i}"` : `No ${n.rootElementName} root element found in records`,
1511
1511
  key: "EXPORT_ROOT_NOT_FOUND"
1512
1512
  });
1513
- let u = l.tagName === n.rootElementName ? l : void 0, d = n.namespaces.default, f = document.implementation.createDocument(d.uri, null, null), p = ht({
1514
- document: f,
1515
- record: l,
1516
- defaultNamespace: d,
1513
+ let l = c.tagName === n.rootElementName ? c : void 0, u = n.namespaces.default, d = document.implementation.createDocument(u.uri, null, null), p = ht({
1514
+ document: d,
1515
+ record: c,
1516
+ defaultNamespace: u,
1517
1517
  declareNamespaces: a
1518
1518
  });
1519
- return a && p.setAttribute("xmlns", l.namespace.uri), l.attributes && _t({
1519
+ return a && p.setAttribute("xmlns", c.namespace.uri), c.attributes && _t({
1520
1520
  config: n,
1521
- document: f,
1521
+ document: d,
1522
1522
  element: p,
1523
- attributes: l.attributes,
1523
+ attributes: c.attributes,
1524
1524
  isRoot: !0,
1525
- documentRoot: u,
1525
+ documentRoot: l,
1526
1526
  declareNamespaces: a
1527
- }), u && bt({
1527
+ }), l && bt({
1528
1528
  config: n,
1529
1529
  rootElement: p,
1530
- namespace: l.namespace,
1531
- rootRecord: u
1532
- }), l.value && (p.textContent = l.value.trim()), r && p.setAttribute(V, l.id), f.appendChild(p), a && vt({
1530
+ namespace: c.namespace,
1531
+ rootRecord: l
1532
+ }), c.value && (p.textContent = c.value.trim()), r && p.setAttribute(V, c.id), d.appendChild(p), a && vt({
1533
1533
  config: n,
1534
1534
  element: p,
1535
- record: l,
1536
- documentRoot: u
1535
+ record: c,
1536
+ documentRoot: l
1537
1537
  }), mt({
1538
1538
  index: o,
1539
1539
  config: n,
1540
1540
  withDatabaseIds: r,
1541
- xmlDocument: f,
1542
- parentRecord: l,
1541
+ xmlDocument: d,
1542
+ parentRecord: c,
1543
1543
  parentElement: p,
1544
- documentRoot: u,
1544
+ documentRoot: l,
1545
1545
  declareNamespaces: a
1546
- }), f;
1546
+ }), d;
1547
1547
  }
1548
1548
  function mt(e) {
1549
- let { index: t, config: n, withDatabaseIds: r, xmlDocument: i, parentRecord: a, parentElement: o, documentRoot: s, declareNamespaces: l } = e;
1549
+ let { index: t, config: n, withDatabaseIds: r, xmlDocument: i, parentRecord: a, parentElement: o, documentRoot: s, declareNamespaces: c } = e;
1550
1550
  if (!a.children || a.children.length === 0) return;
1551
- let u = [];
1551
+ let l = [];
1552
1552
  for (let e of a.children) {
1553
1553
  let n = t.get(e.id);
1554
- c(n, {
1554
+ f(n, {
1555
1555
  detail: `Parent '${a.tagName}' references non-existent child '${e.tagName}' (id: ${e.id})`,
1556
1556
  key: "EXPORT_ORPHAN_CHILD_REF",
1557
1557
  ref: {
1558
1558
  tagName: a.tagName,
1559
1559
  id: a.id
1560
1560
  }
1561
- }), u.push(n);
1561
+ }), l.push(n);
1562
1562
  }
1563
- let d = f({
1563
+ let u = m({
1564
1564
  parentTagName: a.tagName,
1565
- children: u,
1565
+ children: l,
1566
1566
  childrenConfig: n.children
1567
1567
  });
1568
- for (let e of d) {
1568
+ for (let e of u) {
1569
1569
  let a = gt({
1570
1570
  config: n,
1571
1571
  document: i,
@@ -1573,9 +1573,9 @@ function mt(e) {
1573
1573
  defaultNamespace: n.namespaces.default,
1574
1574
  withDatabaseIds: r,
1575
1575
  documentRoot: s,
1576
- declareNamespaces: l
1576
+ declareNamespaces: c
1577
1577
  });
1578
- o.appendChild(a), l && vt({
1578
+ o.appendChild(a), c && vt({
1579
1579
  config: n,
1580
1580
  element: a,
1581
1581
  record: e,
@@ -1588,7 +1588,7 @@ function mt(e) {
1588
1588
  parentRecord: e,
1589
1589
  parentElement: a,
1590
1590
  documentRoot: s,
1591
- declareNamespaces: l
1591
+ declareNamespaces: c
1592
1592
  });
1593
1593
  }
1594
1594
  }
@@ -1646,29 +1646,29 @@ function _t(e) {
1646
1646
  }), r.setAttributeNS(e.namespace.uri, `${e.namespace.prefix}:${i}`, String(e.value));
1647
1647
  }
1648
1648
  }
1649
- function vt(e) {
1650
- let { config: t, element: n, record: i, documentRoot: o } = e, s = n.getAttributeNS(r.uri, "type");
1651
- if (s === null) return;
1652
- let c = _({
1653
- value: s,
1654
- namespaceOf: a({
1655
- dialecteConfig: t,
1656
- attributes: i.attributes
1649
+ function vt(n) {
1650
+ let { config: r, element: a, record: o, documentRoot: c } = n, l = a.getAttributeNS(i.uri, "type");
1651
+ if (l === null) return;
1652
+ let u = s({
1653
+ value: l,
1654
+ namespaceOf: t({
1655
+ dialecteConfig: r,
1656
+ attributes: o.attributes
1657
1657
  })
1658
1658
  });
1659
- if (c === void 0 || c.namespace === "") return;
1660
- let l = s.indexOf(":"), d = l === -1 ? "" : s.slice(0, l), f = Object.values(t.namespaces).some((e) => e.prefix === d && e.uri === c.namespace);
1661
- if (d && f && yt({
1662
- config: t,
1663
- document: n.ownerDocument,
1659
+ if (u === void 0 || u.namespace === "") return;
1660
+ let d = l.indexOf(":"), f = d === -1 ? "" : l.slice(0, d), p = Object.values(r.namespaces).some((e) => e.prefix === f && e.uri === u.namespace);
1661
+ if (f && p && yt({
1662
+ config: r,
1663
+ document: a.ownerDocument,
1664
1664
  namespace: {
1665
- prefix: d,
1666
- uri: c.namespace
1665
+ prefix: f,
1666
+ uri: u.namespace
1667
1667
  },
1668
- documentRoot: o
1669
- }), n.lookupNamespaceURI(d || null) === c.namespace) return;
1670
- let p = n.lookupPrefix(c.namespace), m = p !== null && n.lookupNamespaceURI(p) === c.namespace ? p : null, h = m ?? H({ element: n });
1671
- m === null && n.setAttributeNS(u, `xmlns:${h}`, c.namespace), n.setAttributeNS(r.uri, `${n.lookupPrefix(r.uri) ?? "xsi"}:type`, `${h}:${c.local}`);
1668
+ documentRoot: c
1669
+ }), a.lookupNamespaceURI(f || null) === u.namespace) return;
1670
+ let m = a.lookupPrefix(u.namespace), h = m !== null && a.lookupNamespaceURI(m) === u.namespace ? m : null, g = h ?? H({ element: a });
1671
+ h === null && a.setAttributeNS(e, `xmlns:${g}`, u.namespace), a.setAttributeNS(i.uri, `${a.lookupPrefix(i.uri) ?? "xsi"}:type`, `${g}:${u.local}`);
1672
1672
  }
1673
1673
  function H(e) {
1674
1674
  let { element: t } = e;
@@ -1677,29 +1677,29 @@ function H(e) {
1677
1677
  if (t.lookupNamespaceURI(n) === null) return n;
1678
1678
  }
1679
1679
  }
1680
- function yt(e) {
1681
- let { config: t, document: n, namespace: r, documentRoot: i } = e, a = n.documentElement;
1682
- if (!a || !r.prefix || r.prefix === "xmlns") return;
1683
- let o = u;
1684
- a.getAttributeNS(o, r.prefix) === null && (a.setAttributeNS(o, `xmlns:${r.prefix}`, r.uri), i && bt({
1685
- config: t,
1686
- rootElement: a,
1687
- namespace: r,
1688
- rootRecord: i
1680
+ function yt(t) {
1681
+ let { config: n, document: r, namespace: i, documentRoot: a } = t, o = r.documentElement;
1682
+ if (!o || !i.prefix || i.prefix === "xmlns") return;
1683
+ let s = e;
1684
+ o.getAttributeNS(s, i.prefix) === null && (o.setAttributeNS(s, `xmlns:${i.prefix}`, i.uri), a && bt({
1685
+ config: n,
1686
+ rootElement: o,
1687
+ namespace: i,
1688
+ rootRecord: a
1689
1689
  }));
1690
1690
  }
1691
1691
  function bt(e) {
1692
- let { config: t, rootElement: n, namespace: r, rootRecord: i } = e, a = g({
1692
+ let { config: t, rootElement: n, namespace: r, rootRecord: i } = e, a = v({
1693
1693
  dialecteConfig: t,
1694
1694
  record: i
1695
- })?.attributes.details ?? {}, o = Object.entries(a).filter(([e, n]) => l({
1695
+ })?.attributes.details ?? {}, o = Object.entries(a).filter(([e, n]) => c({
1696
1696
  dialecteConfig: t,
1697
1697
  record: i,
1698
1698
  attributeName: e,
1699
1699
  defaults: "required"
1700
1700
  }) === void 0 ? !1 : r.uri === t.namespaces.default.uri ? !n.namespace : n.namespace?.prefix === r.prefix && n.namespace?.uri === r.uri);
1701
1701
  if (o.length > 0) for (let [e, r] of o) {
1702
- let a = p(e), o = l({
1702
+ let a = p(e), o = c({
1703
1703
  dialecteConfig: t,
1704
1704
  record: i,
1705
1705
  attributeName: e,
@@ -1714,12 +1714,12 @@ function bt(e) {
1714
1714
  function xt(e) {
1715
1715
  let { config: t, document: n, element: r, record: i, documentRoot: a, declareNamespaces: o } = e;
1716
1716
  if (!o) return;
1717
- let s = g({
1717
+ let s = v({
1718
1718
  dialecteConfig: t,
1719
1719
  record: i
1720
1720
  })?.attributes.details;
1721
- if (s) for (let [e, c] of Object.entries(s)) {
1722
- let s = l({
1721
+ if (s) for (let [e, l] of Object.entries(s)) {
1722
+ let s = c({
1723
1723
  dialecteConfig: t,
1724
1724
  record: i,
1725
1725
  attributeName: e,
@@ -1727,12 +1727,12 @@ function xt(e) {
1727
1727
  });
1728
1728
  if (s === void 0) continue;
1729
1729
  let u = p(e);
1730
- (c.namespace ? r.hasAttributeNS(c.namespace.uri, u) : r.hasAttribute(u)) || (c.namespace && c.namespace.prefix && c.namespace.prefix !== "xmlns" ? (o && yt({
1730
+ (l.namespace ? r.hasAttributeNS(l.namespace.uri, u) : r.hasAttribute(u)) || (l.namespace && l.namespace.prefix && l.namespace.prefix !== "xmlns" ? (o && yt({
1731
1731
  config: t,
1732
1732
  document: n,
1733
- namespace: c.namespace,
1733
+ namespace: l.namespace,
1734
1734
  documentRoot: a
1735
- }), r.setAttributeNS(c.namespace.uri, `${c.namespace.prefix}:${u}`, s)) : r.setAttribute(u, s));
1735
+ }), r.setAttributeNS(l.namespace.uri, `${l.namespace.prefix}:${u}`, s)) : r.setAttribute(u, s));
1736
1736
  }
1737
1737
  }
1738
1738
  function St(e) {
@@ -2572,36 +2572,36 @@ var wt = /* @__PURE__ */ O(((e, t) => {
2572
2572
  })();
2573
2573
  })(e === void 0 ? e.sax = {} : e);
2574
2574
  })))(), 1);
2575
- function U(e, n) {
2576
- let r = new Set(n.elements), i = {};
2577
- for (let e of n.elements) i[e] = void 0;
2575
+ function U(e, t) {
2576
+ let n = new Set(t.elements), i = {};
2577
+ for (let e of t.elements) i[e] = void 0;
2578
2578
  let a = Tt.parser(!0, {
2579
2579
  xmlns: !0,
2580
2580
  position: !1
2581
2581
  }), o = null;
2582
2582
  a.onopentag = (e) => {
2583
- let t = e, n = t.local;
2584
- if (!r.has(n)) return;
2583
+ let t = e, r = t.local;
2584
+ if (!n.has(r)) return;
2585
2585
  let a = {};
2586
2586
  for (let e of Object.values(t.attributes)) {
2587
2587
  let t = e.prefix === "xmlns" && e.local === "" ? "xmlns" : e.prefix ? e.local : e.name;
2588
2588
  a[t] = e.value;
2589
2589
  }
2590
- i[n] = {
2590
+ i[r] = {
2591
2591
  namespace: t.uri,
2592
2592
  attributes: a,
2593
2593
  value: "",
2594
2594
  children: []
2595
- }, r.delete(n), o = n;
2595
+ }, n.delete(r), o = r;
2596
2596
  }, a.ontext = (e) => {
2597
2597
  o && i[o] && (i[o].value += e);
2598
2598
  }, a.oncdata = a.ontext, a.onclosetag = (e) => {
2599
- if (o === e && (o = null), r.size === 0) throw Et;
2599
+ if (o === e && (o = null), n.size === 0) throw Et;
2600
2600
  };
2601
2601
  try {
2602
2602
  a.write(e).close();
2603
2603
  } catch (e) {
2604
- e !== Et && t("PARSE_ERROR", {
2604
+ e !== Et && r("PARSE_ERROR", {
2605
2605
  detail: String(e),
2606
2606
  cause: e instanceof Error ? e : void 0
2607
2607
  });
@@ -2771,33 +2771,33 @@ function jt(e) {
2771
2771
  getSize: l
2772
2772
  };
2773
2773
  }
2774
- function Mt(t) {
2775
- let { node: n, state: r, dialecteConfig: i, useCustomRecordsIds: a } = t, o = Ft(n);
2776
- r.defaultNamespace ||= It({
2777
- element: n,
2778
- defaultNamespace: i.namespaces.default,
2779
- rootElementName: i.rootElementName
2774
+ function Mt(e) {
2775
+ let { node: t, state: n, dialecteConfig: r, useCustomRecordsIds: i } = e, a = Ft(t);
2776
+ n.defaultNamespace ||= It({
2777
+ element: t,
2778
+ defaultNamespace: r.namespaces.default,
2779
+ rootElementName: r.rootElementName
2780
2780
  });
2781
- let s = Lt(n, r.defaultNamespace), c = {
2781
+ let o = Lt(t, n.defaultNamespace), s = {
2782
2782
  id: zt({
2783
- attributes: n.attributes,
2784
- useCustomRecordsIds: a
2783
+ attributes: t.attributes,
2784
+ useCustomRecordsIds: i
2785
2785
  }),
2786
- tagName: o,
2787
- namespace: s,
2788
- attributes: e({
2789
- dialecteConfig: i,
2786
+ tagName: a,
2787
+ namespace: o,
2788
+ attributes: g({
2789
+ dialecteConfig: r,
2790
2790
  attributes: K(Bt({
2791
- attributes: n.attributes,
2792
- useCustomRecordsIds: a
2791
+ attributes: t.attributes,
2792
+ useCustomRecordsIds: i
2793
2793
  })),
2794
- namespaceOf: (e) => n.ns[e]
2794
+ namespaceOf: (e) => t.ns[e]
2795
2795
  }),
2796
2796
  value: "",
2797
- parent: Rt(r.stack),
2797
+ parent: Rt(n.stack),
2798
2798
  children: []
2799
2799
  };
2800
- r.stack.push(c);
2800
+ n.stack.push(s);
2801
2801
  }
2802
2802
  function Nt(e) {
2803
2803
  let { text: t, state: n } = e;
@@ -2833,7 +2833,7 @@ function Ft(e) {
2833
2833
  }
2834
2834
  function It(e) {
2835
2835
  let { element: t, defaultNamespace: n, rootElementName: r } = e;
2836
- return c(t.name === r, { detail: `Expected root element <${r}>, got <${t.name}>` }), t.attributes?.xmlns?.value ? {
2836
+ return f(t.name === r, { detail: `Expected root element <${r}>, got <${t.name}>` }), t.attributes?.xmlns?.value ? {
2837
2837
  prefix: "",
2838
2838
  uri: t.attributes.xmlns.value
2839
2839
  } : n;
@@ -2866,31 +2866,31 @@ function Rt(e) {
2866
2866
  } : null;
2867
2867
  }
2868
2868
  function zt(e) {
2869
- let { attributes: t, useCustomRecordsIds: n } = e, r = t[o];
2870
- return n && r && r.value ? r.value : crypto.randomUUID();
2869
+ let { attributes: t, useCustomRecordsIds: r } = e, i = t[n];
2870
+ return r && i && i.value ? i.value : crypto.randomUUID();
2871
2871
  }
2872
2872
  function Bt(e) {
2873
- let { attributes: t, useCustomRecordsIds: n } = e;
2874
- return n ? Object.values(t).filter((e) => e.name !== o) : Object.values(t);
2873
+ let { attributes: t, useCustomRecordsIds: r } = e;
2874
+ return r ? Object.values(t).filter((e) => e.name !== n) : Object.values(t);
2875
2875
  }
2876
2876
  //#endregion
2877
2877
  //#region src/xml/parse/parse-xml-document.ts
2878
2878
  var Vt = 32 * 1024, Ht = 2e3;
2879
2879
  async function q(e) {
2880
- let { documentId: t, store: n, config: r, useCustomRecordsIds: i = !1, chunkOptions: a, hooks: o, perf: s = W } = e, { file: l } = e, { supportedFileExtensions: u } = r.io;
2881
- if (c(u.some((e) => l.name.toLowerCase().endsWith(e)), {
2880
+ let { documentId: t, store: n, config: r, useCustomRecordsIds: i = !1, chunkOptions: a, hooks: o, perf: s = W } = e, { file: c } = e, { supportedFileExtensions: l } = r.io;
2881
+ if (f(l.some((e) => c.name.toLowerCase().endsWith(e)), {
2882
2882
  key: "ASSERTION_FAILED",
2883
- detail: `Unsupported file type: ${l.name}`
2884
- }), l.size === 0) return {
2883
+ detail: `Unsupported file type: ${c.name}`
2884
+ }), c.size === 0) return {
2885
2885
  documentId: t,
2886
2886
  recordCount: 0
2887
2887
  };
2888
- let d = o?.beforeImport;
2889
- if (d) {
2890
- let e = d(await l.text());
2891
- l = new File([e], l.name, { type: l.type });
2888
+ let u = o?.beforeImport;
2889
+ if (u) {
2890
+ let e = u(await c.text());
2891
+ c = new File([e], c.name, { type: c.type });
2892
2892
  }
2893
- let f = a?.chunkSize ?? Vt, p = a?.batchSize ?? Ht, m = new Dt(), h = jt({
2893
+ let d = a?.chunkSize ?? Vt, p = a?.batchSize ?? Ht, m = new Dt(), h = jt({
2894
2894
  dialecteConfig: r,
2895
2895
  useCustomRecordsIds: i,
2896
2896
  session: m,
@@ -2899,12 +2899,12 @@ async function q(e) {
2899
2899
  });
2900
2900
  s.start("core::import");
2901
2901
  let g = await Ut({
2902
- file: l,
2902
+ file: c,
2903
2903
  sax: h,
2904
2904
  session: m,
2905
2905
  store: n,
2906
2906
  documentId: t,
2907
- chunkSize: f,
2907
+ chunkSize: d,
2908
2908
  batchSize: p,
2909
2909
  perf: s
2910
2910
  });
@@ -3155,7 +3155,7 @@ var Xt = class {
3155
3155
  }
3156
3156
  async getDocumentInfo() {
3157
3157
  let e = await this.store.getDocument(this.documentId);
3158
- return c(e, {
3158
+ return f(e, {
3159
3159
  key: "DOCUMENT_NOT_REGISTERED",
3160
3160
  detail: `Expected document id: ${this.documentId}`
3161
3161
  }), e;
@@ -3165,7 +3165,7 @@ var Xt = class {
3165
3165
  context: this.context,
3166
3166
  ref: { tagName: this.dialecteConfig.rootElementName }
3167
3167
  });
3168
- return c(e, {
3168
+ return f(e, {
3169
3169
  key: "ROOT_NOT_FOUND",
3170
3170
  detail: `Expected tag name: ${this.dialecteConfig.rootElementName}`
3171
3171
  }), e;
@@ -3280,9 +3280,9 @@ var Xt = class {
3280
3280
  //#endregion
3281
3281
  //#region src/document/transaction/stage-operations.ts
3282
3282
  function Qt(e) {
3283
- let { context: t, status: n, record: r, oldRecord: i, newRecord: a } = e, o, s, l;
3284
- if (r && (o = te(r)), i && (s = te(i)), a && (l = te(a)), n === "created") {
3285
- c(o, {
3283
+ let { context: t, status: n, record: r, oldRecord: i, newRecord: a } = e, o, s, c;
3284
+ if (r && (o = te(r)), i && (s = te(i)), a && (c = te(a)), n === "created") {
3285
+ f(o, {
3286
3286
  detail: "Record is required for created",
3287
3287
  key: "ELEMENT_NOT_FOUND"
3288
3288
  });
@@ -3293,18 +3293,18 @@ function Qt(e) {
3293
3293
  };
3294
3294
  t.stagedOperations.log.push(e), t.stagedOperations.byId.set(o.id, e);
3295
3295
  } else if (n === "updated") {
3296
- c(s && l, {
3296
+ f(s && c, {
3297
3297
  detail: "Old record and new record are required for updated",
3298
3298
  key: "ELEMENT_NOT_FOUND"
3299
3299
  });
3300
3300
  let e = {
3301
3301
  status: n,
3302
3302
  oldRecord: s,
3303
- newRecord: l
3303
+ newRecord: c
3304
3304
  };
3305
- t.stagedOperations.log.push(e), t.stagedOperations.byId.set(l.id, e);
3305
+ t.stagedOperations.log.push(e), t.stagedOperations.byId.set(c.id, e);
3306
3306
  } else if (n === "deleted" && o) {
3307
- c(o, {
3307
+ f(o, {
3308
3308
  detail: "Record is required for deleted",
3309
3309
  key: "ELEMENT_NOT_FOUND"
3310
3310
  });
@@ -3346,16 +3346,16 @@ function $t(e) {
3346
3346
  //#endregion
3347
3347
  //#region src/document/transaction/create/create.ts
3348
3348
  async function en(e) {
3349
- let { dialecteConfig: t, hooks: n, context: r, query: i, parentRef: a, params: o } = e, { id: s, tagName: l, attributes: u, namespace: d, value: f } = o;
3349
+ let { dialecteConfig: t, hooks: n, context: r, query: i, parentRef: a, params: o } = e, { id: s, tagName: c, attributes: l, namespace: u, value: d } = o;
3350
3350
  tn({
3351
- attributes: u,
3352
- tagName: l
3351
+ attributes: l,
3352
+ tagName: c
3353
3353
  });
3354
3354
  let p = await N({
3355
3355
  context: r,
3356
3356
  ref: a
3357
3357
  });
3358
- c(p, {
3358
+ f(p, {
3359
3359
  detail: "Parent record not found",
3360
3360
  key: "ELEMENT_NOT_FOUND",
3361
3361
  ref: a
@@ -3365,10 +3365,10 @@ async function en(e) {
3365
3365
  hooks: n,
3366
3366
  record: {
3367
3367
  id: s ?? crypto.randomUUID(),
3368
- tagName: l,
3369
- attributes: u,
3370
- namespace: d,
3371
- value: f,
3368
+ tagName: c,
3369
+ attributes: l,
3370
+ namespace: u,
3371
+ value: d,
3372
3372
  parent: {
3373
3373
  id: p.id,
3374
3374
  tagName: p.tagName
@@ -3410,12 +3410,12 @@ async function en(e) {
3410
3410
  }), m;
3411
3411
  }
3412
3412
  function tn(e) {
3413
- let { attributes: n, tagName: r } = e;
3414
- if (!(!n || !Array.isArray(n))) for (let e of n) {
3415
- let { name: n, namespace: i } = e;
3416
- n === "xmlns" || n.startsWith("xmlns:") || !n.includes(":") || typeof i == "object" && i?.prefix === n.slice(0, n.indexOf(":")) || t("PREFIXED_ATTRIBUTE_NAME", {
3417
- detail: `Attribute '${n}' on '${r}' is prefixed — pass a local name plus its namespace instead: { name: '${p(n)}', namespace }.`,
3418
- ref: { tagName: r }
3413
+ let { attributes: t, tagName: n } = e;
3414
+ if (!(!t || !Array.isArray(t))) for (let e of t) {
3415
+ let { name: t, namespace: i } = e;
3416
+ t === "xmlns" || t.startsWith("xmlns:") || !t.includes(":") || typeof i == "object" && i?.prefix === t.slice(0, t.indexOf(":")) || r("PREFIXED_ATTRIBUTE_NAME", {
3417
+ detail: `Attribute '${t}' on '${n}' is prefixed — pass a local name plus its namespace instead: { name: '${p(t)}', namespace }.`,
3418
+ ref: { tagName: n }
3419
3419
  });
3420
3420
  }
3421
3421
  }
@@ -3487,11 +3487,11 @@ async function on(e) {
3487
3487
  context: n,
3488
3488
  ref: i
3489
3489
  });
3490
- c(a, {
3490
+ f(a, {
3491
3491
  detail: `Record not found (tagName=${i.tagName}, id=${i.id})`,
3492
3492
  key: "ELEMENT_NOT_FOUND",
3493
3493
  ref: i
3494
- }), c(a.parent, {
3494
+ }), f(a.parent, {
3495
3495
  detail: "Cannot delete root element",
3496
3496
  key: "PROTECTED_ROOT"
3497
3497
  }), t?.beforeDelete && $t({
@@ -3512,7 +3512,7 @@ async function on(e) {
3512
3512
  context: n,
3513
3513
  ref: T(a.parent)
3514
3514
  });
3515
- c(o, {
3515
+ f(o, {
3516
3516
  detail: `Parent record not found (tagName=${a.parent.tagName}, id=${a.parent.id})`,
3517
3517
  key: "ELEMENT_NOT_FOUND"
3518
3518
  });
@@ -3580,58 +3580,58 @@ function ln(e) {
3580
3580
  //#endregion
3581
3581
  //#region src/document/transaction/update/update.ts
3582
3582
  async function un(e) {
3583
- let { dialecteConfig: t, hooks: n, context: r, query: i, ref: a, params: o } = e, { attributes: l, value: u } = o, d = await N({
3583
+ let { dialecteConfig: t, hooks: n, context: r, query: i, ref: a, params: o } = e, { attributes: s, value: c } = o, l = await N({
3584
3584
  context: r,
3585
3585
  ref: a
3586
3586
  });
3587
- c(d, {
3587
+ f(l, {
3588
3588
  detail: `Record not found (tagName=${a.tagName}, id=${a.id})`,
3589
3589
  key: "ELEMENT_NOT_FOUND",
3590
3590
  ref: a
3591
3591
  });
3592
- let f = l ? w({
3592
+ let u = s ? w({
3593
3593
  dialecteConfig: t,
3594
- tagName: d.tagName,
3595
- attributes: l,
3596
- stored: d.attributes
3597
- }) : [], p = d.attributes;
3598
- l && (p = [...d.attributes.filter((e) => !f.some((t) => t.name === e.name)), ...f].filter((e) => e.value !== void 0 && e.value !== null), y({
3594
+ tagName: l.tagName,
3595
+ attributes: s,
3596
+ stored: l.attributes
3597
+ }) : [], d = l.attributes;
3598
+ s && (d = [...l.attributes.filter((e) => !u.some((t) => t.name === e.name)), ...u].filter((e) => e.value !== void 0 && e.value !== null), y({
3599
3599
  dialecteConfig: t,
3600
3600
  record: {
3601
- ...d,
3602
- attributes: p
3601
+ ...l,
3602
+ attributes: d
3603
3603
  },
3604
- attributes: f
3604
+ attributes: u
3605
3605
  }));
3606
- let m = f.some(s), h = ee({
3606
+ let p = u.some(_), m = ee({
3607
3607
  dialecteConfig: t,
3608
3608
  hooks: n,
3609
3609
  record: {
3610
- ...d,
3611
- attributes: p,
3612
- value: u === void 0 ? d.value : u
3610
+ ...l,
3611
+ attributes: d,
3612
+ value: c === void 0 ? l.value : c
3613
3613
  }
3614
3614
  });
3615
- return m && (b({
3615
+ return p && (b({
3616
3616
  dialecteConfig: t,
3617
- record: h
3617
+ record: m
3618
3618
  }), x({
3619
3619
  dialecteConfig: t,
3620
- merged: p,
3621
- record: h
3622
- })), dn(d, h) ? h : (Qt({
3620
+ merged: d,
3621
+ record: m
3622
+ })), dn(l, m) ? m : (Qt({
3623
3623
  context: r,
3624
3624
  status: "updated",
3625
- oldRecord: d,
3626
- newRecord: h
3625
+ oldRecord: l,
3626
+ newRecord: m
3627
3627
  }), n?.afterUpdated && $t({
3628
3628
  context: r,
3629
3629
  operations: await n.afterUpdated({
3630
- oldRecord: d,
3631
- newRecord: h,
3630
+ oldRecord: l,
3631
+ newRecord: m,
3632
3632
  query: i
3633
3633
  })
3634
- }), h);
3634
+ }), m);
3635
3635
  }
3636
3636
  function dn(e, t) {
3637
3637
  return e.value !== t.value || e.attributes.length !== t.attributes.length ? !1 : e.attributes.every((e, n) => fn(e, t.attributes[n]));
@@ -3917,24 +3917,24 @@ var yn = class {
3917
3917
  createTransaction() {
3918
3918
  return new _n(this.store, this.config, this.documentId, this.state, this.hooks, this.perf, this.signalStateChange);
3919
3919
  }
3920
- async transaction(e, n) {
3921
- this.activeTransactions > 0 && t("CONCURRENT_TRANSACTION", { detail: `${this.activeTransactions} transaction(s) already active. Concurrent transactions risk lost updates — serialize them or implement a transaction queue.` }), this.activeTransactions++, this.state.loading = !0, this.state.error = null, this.signalStateChange(!1);
3922
- let r = this.withAllExtensions(this.createTransaction());
3920
+ async transaction(e, t) {
3921
+ this.activeTransactions > 0 && r("CONCURRENT_TRANSACTION", { detail: `${this.activeTransactions} transaction(s) already active. Concurrent transactions risk lost updates — serialize them or implement a transaction queue.` }), this.activeTransactions++, this.state.loading = !0, this.state.error = null, this.signalStateChange(!1);
3922
+ let n = this.withAllExtensions(this.createTransaction());
3923
3923
  try {
3924
- let t = await e(r);
3925
- return await r.finishStaging(), await r.commit(), await this.refreshHistoryStatus(), this.broadcast({
3924
+ let r = await e(n);
3925
+ return await n.finishStaging(), await n.commit(), await this.refreshHistoryStatus(), this.broadcast({
3926
3926
  type: "commit",
3927
3927
  documentId: this.documentId,
3928
3928
  timestamp: this.state.lastUpdate ?? Date.now()
3929
- }), r.clearStagedOperations(), r.clearRecordCache(), this.state.history.push({
3929
+ }), n.clearStagedOperations(), n.clearRecordCache(), this.state.history.push({
3930
3930
  method: "commit",
3931
- message: n?.label ?? "Changes committed",
3931
+ message: t?.label ?? "Changes committed",
3932
3932
  timestamp: Date.now()
3933
- }), t;
3933
+ }), r;
3934
3934
  } catch (e) {
3935
3935
  throw this.reportFailure(e);
3936
3936
  } finally {
3937
- r.progress.forceClear(), this.activeTransactions--, this.state.loading = !1, this.signalStateChange(!0);
3937
+ n.progress.forceClear(), this.activeTransactions--, this.state.loading = !1, this.signalStateChange(!0);
3938
3938
  }
3939
3939
  }
3940
3940
  async prepare(e, t) {
@@ -3981,13 +3981,13 @@ var yn = class {
3981
3981
  };
3982
3982
  }
3983
3983
  reportFailure(e) {
3984
- let t = n(e);
3984
+ let t = o(e);
3985
3985
  if (e instanceof Error && t) return this.state.error = t, e;
3986
- let r = i("UNKNOWN", {
3986
+ let n = a("UNKNOWN", {
3987
3987
  detail: e instanceof Error ? e.message : String(e),
3988
3988
  cause: e instanceof Error ? e : void 0
3989
3989
  });
3990
- return this.state.error = n(r) ?? null, r;
3990
+ return this.state.error = o(n) ?? null, n;
3991
3991
  }
3992
3992
  close() {
3993
3993
  this.store.close();
@@ -7905,14 +7905,14 @@ var Un = {
7905
7905
  }
7906
7906
  async commit(e) {
7907
7907
  await this.ensureCurrentSchema();
7908
- let { documentId: n, creates: r, updates: i, deletes: a, onProgress: o } = e, s = this.db.table(this.resolveTableName(n)), c = r.length + i.length + a.length, l = 0;
7908
+ let { documentId: t, creates: n, updates: i, deletes: a, onProgress: o } = e, s = this.db.table(this.resolveTableName(t)), c = n.length + i.length + a.length, l = 0;
7909
7909
  try {
7910
7910
  await this.db.transaction("rw", s, this.db.table(J), this.db.table(Y), async () => {
7911
7911
  let e = i.length > 0 ? await s.bulkGet(i.map((e) => e.id)) : [], u = a.length > 0 ? await s.bulkGet(a) : [];
7912
- if (r.length > 0) try {
7913
- await s.bulkAdd(r), l += r.length, o(l, c);
7912
+ if (n.length > 0) try {
7913
+ await s.bulkAdd(n), l += n.length, o(l, c);
7914
7914
  } catch (e) {
7915
- t("STORE_BULK_ADD_FAILED", {
7915
+ r("STORE_BULK_ADD_FAILED", {
7916
7916
  detail: e instanceof Error ? e.message : String(e),
7917
7917
  cause: e instanceof Error ? e : void 0
7918
7918
  });
@@ -7920,7 +7920,7 @@ var Un = {
7920
7920
  if (i.length > 0) try {
7921
7921
  await s.bulkPut(i), l += i.length, o(l, c);
7922
7922
  } catch (e) {
7923
- t("STORE_BULK_UPDATE_FAILED", {
7923
+ r("STORE_BULK_UPDATE_FAILED", {
7924
7924
  detail: e instanceof Error ? e.message : String(e),
7925
7925
  cause: e instanceof Error ? e : void 0
7926
7926
  });
@@ -7928,19 +7928,19 @@ var Un = {
7928
7928
  if (a.length > 0) try {
7929
7929
  await s.bulkDelete(a), l += a.length, o(l, c);
7930
7930
  } catch (e) {
7931
- t("STORE_DELETE_FAILED", {
7931
+ r("STORE_DELETE_FAILED", {
7932
7932
  detail: e instanceof Error ? e.message : String(e),
7933
7933
  cause: e instanceof Error ? e : void 0
7934
7934
  });
7935
7935
  }
7936
- let d = await this.getHead(n), f = await this.db.table(J).where({ documentId: n }).filter((e) => e.sequenceNumber > d).toArray();
7936
+ let d = await this.getHead(t), f = await this.db.table(J).where({ documentId: t }).filter((e) => e.sequenceNumber > d).toArray();
7937
7937
  f.length > 0 && await this.db.table(J).bulkDelete(f.map((e) => e.id));
7938
7938
  let p = d + 1, m = {
7939
- documentId: n,
7939
+ documentId: t,
7940
7940
  sequenceNumber: p,
7941
7941
  timestamp: Date.now(),
7942
7942
  operations: {
7943
- creates: r,
7943
+ creates: n,
7944
7944
  updates: i.map((t, n) => ({
7945
7945
  before: e[n],
7946
7946
  after: t
@@ -7948,11 +7948,11 @@ var Un = {
7948
7948
  deletes: u.filter(Boolean)
7949
7949
  }
7950
7950
  };
7951
- await this.db.table(J).add(m), await this.setHead(n, p);
7951
+ await this.db.table(J).add(m), await this.setHead(t, p);
7952
7952
  });
7953
7953
  } catch (e) {
7954
7954
  if (e instanceof Error && e.message.includes("dialecte")) throw e;
7955
- t("STORE_COMMIT_FAILED", {
7955
+ r("STORE_COMMIT_FAILED", {
7956
7956
  detail: e instanceof Error ? e.message : String(e),
7957
7957
  cause: e instanceof Error ? e : void 0
7958
7958
  });
@@ -8029,18 +8029,18 @@ var Un = {
8029
8029
  async getStandaloneBlobs() {
8030
8030
  return await this.ensureCurrentSchema(), (await this.db.table(X).toArray()).filter((e) => e.attachedTo.length === 0);
8031
8031
  }
8032
- async attachBlob(e, n) {
8032
+ async attachBlob(e, t) {
8033
8033
  await this.ensureCurrentSchema();
8034
- let r = await this.db.table(X).get(e);
8035
- if (r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` }), r.attachedTo.some((e) => e.documentId === n.documentId && e.recordRef === n.recordRef && e.attribute === n.attribute)) return;
8036
- let i = [...r.attachedTo, n];
8034
+ let n = await this.db.table(X).get(e);
8035
+ if (n || r("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` }), n.attachedTo.some((e) => e.documentId === t.documentId && e.recordRef === t.recordRef && e.attribute === t.attribute)) return;
8036
+ let i = [...n.attachedTo, t];
8037
8037
  await this.db.table(X).update(e, { attachedTo: i });
8038
8038
  }
8039
- async detachBlob(e, n) {
8039
+ async detachBlob(e, t) {
8040
8040
  await this.ensureCurrentSchema();
8041
- let r = await this.db.table(X).get(e);
8042
- r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8043
- let i = r.attachedTo.filter((e) => !(e.documentId === n.documentId && e.recordRef === n.recordRef));
8041
+ let n = await this.db.table(X).get(e);
8042
+ n || r("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8043
+ let i = n.attachedTo.filter((e) => !(e.documentId === t.documentId && e.recordRef === t.recordRef));
8044
8044
  await this.db.table(X).update(e, { attachedTo: i });
8045
8045
  }
8046
8046
  async removeBlob(e) {
@@ -8123,8 +8123,8 @@ var Un = {
8123
8123
  function Gn() {
8124
8124
  return new Promise((e) => setTimeout(e, 0));
8125
8125
  }
8126
- function Kn(e, n) {
8127
- e.has(n) || t("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${n}" is not registered` });
8126
+ function Kn(e, t) {
8127
+ e.has(t) || r("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${t}" is not registered` });
8128
8128
  }
8129
8129
  //#endregion
8130
8130
  //#region src/store/in-memory/in-memory-store.ts
@@ -8274,8 +8274,8 @@ var qn = class e {
8274
8274
  getDatabaseInstance() {
8275
8275
  return null;
8276
8276
  }
8277
- async addBlob(e, n) {
8278
- this.guardWritable(), this.documents.has(e.documentId) || t("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${e.documentId}" is not registered` }), this.blobs.set(e.id, e), this.getBlobTable(e.documentId).set(e.id, n);
8277
+ async addBlob(e, t) {
8278
+ this.guardWritable(), this.documents.has(e.documentId) || r("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${e.documentId}" is not registered` }), this.blobs.set(e.id, e), this.getBlobTable(e.documentId).set(e.id, t);
8279
8279
  }
8280
8280
  async getBlob(e) {
8281
8281
  let t = this.blobs.get(e);
@@ -8295,21 +8295,21 @@ var qn = class e {
8295
8295
  async getStandaloneBlobs() {
8296
8296
  return [...this.blobs.values()].filter((e) => e.attachedTo.length === 0);
8297
8297
  }
8298
- async attachBlob(e, n) {
8298
+ async attachBlob(e, t) {
8299
8299
  this.guardWritable();
8300
- let r = this.blobs.get(e);
8301
- r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` }), !r.attachedTo.some((e) => e.documentId === n.documentId && e.recordRef === n.recordRef && e.attribute === n.attribute) && this.blobs.set(e, {
8302
- ...r,
8303
- attachedTo: [...r.attachedTo, n]
8300
+ let n = this.blobs.get(e);
8301
+ n || r("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` }), !n.attachedTo.some((e) => e.documentId === t.documentId && e.recordRef === t.recordRef && e.attribute === t.attribute) && this.blobs.set(e, {
8302
+ ...n,
8303
+ attachedTo: [...n.attachedTo, t]
8304
8304
  });
8305
8305
  }
8306
- async detachBlob(e, n) {
8306
+ async detachBlob(e, t) {
8307
8307
  this.guardWritable();
8308
- let r = this.blobs.get(e);
8309
- r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8310
- let i = r.attachedTo.filter((e) => !(e.documentId === n.documentId && e.recordRef === n.recordRef));
8308
+ let n = this.blobs.get(e);
8309
+ n || r("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8310
+ let i = n.attachedTo.filter((e) => !(e.documentId === t.documentId && e.recordRef === t.recordRef));
8311
8311
  this.blobs.set(e, {
8312
- ...r,
8312
+ ...n,
8313
8313
  attachedTo: i
8314
8314
  });
8315
8315
  }
@@ -8327,7 +8327,7 @@ var qn = class e {
8327
8327
  return n || (n = /* @__PURE__ */ new Map(), this.records.set(t, n)), n;
8328
8328
  }
8329
8329
  guardWritable() {
8330
- this.writable || t("STORE_NOT_WRITABLE", { detail: "In-memory store is read-only. Hydrate with a real document before writing." });
8330
+ this.writable || r("STORE_NOT_WRITABLE", { detail: "In-memory store is read-only. Hydrate with a real document before writing." });
8331
8331
  }
8332
8332
  };
8333
8333
  //#endregion
@@ -8342,29 +8342,29 @@ function Jn(e, t, n, r) {
8342
8342
  //#region src/project/io/export-document.ts
8343
8343
  async function Yn(e) {
8344
8344
  let { documentId: t, state: n, configs: r, store: i, projectName: a, options: o } = e, s = n.documents.get(t);
8345
- c(s, {
8345
+ f(s, {
8346
8346
  key: "DOCUMENT_NOT_REGISTERED",
8347
8347
  detail: `Document "${t}" not registered in project "${a}"`
8348
8348
  });
8349
- let l = r[s.record.configKey], u = pt({
8349
+ let c = r[s.record.configKey], l = pt({
8350
8350
  records: await i.getByDocumentId(t),
8351
- config: l,
8351
+ config: c,
8352
8352
  withDatabaseIds: o?.withDatabaseIds
8353
- }), d = `${s.record.name}${s.record.extension}`;
8353
+ }), u = `${s.record.name}${s.record.extension}`;
8354
8354
  return o?.withDownload && await ft({
8355
8355
  extension: s.record.extension,
8356
- xmlDocument: u,
8357
- filename: d
8356
+ xmlDocument: l,
8357
+ filename: u
8358
8358
  }), {
8359
- xmlDocument: u,
8360
- filename: d
8359
+ xmlDocument: l,
8360
+ filename: u
8361
8361
  };
8362
8362
  }
8363
8363
  //#endregion
8364
8364
  //#region src/project/io/export-blob.ts
8365
8365
  async function Xn(e) {
8366
8366
  let { blobId: t, store: n, options: r } = e, i = await n.getBlob(t);
8367
- c(i, {
8367
+ f(i, {
8368
8368
  key: "BLOB_NOT_FOUND",
8369
8369
  detail: `Blob "${t}" not found in store`
8370
8370
  });
@@ -8401,32 +8401,32 @@ function Qn(e, t) {
8401
8401
  //#endregion
8402
8402
  //#region src/project/io/import-document.ts
8403
8403
  async function $n(e) {
8404
- let { file: t, store: n, configs: r, defaultConfigKey: i, options: a, hooks: o, perf: s } = e, l = a?.configKey ?? i, u = r[l];
8405
- c(u, {
8404
+ let { file: t, store: n, configs: r, defaultConfigKey: i, options: a, hooks: o, perf: s } = e, c = a?.configKey ?? i, l = r[c];
8405
+ f(l, {
8406
8406
  key: "UNKNOWN_CONFIG_KEY",
8407
- detail: `Unknown configKey: "${l}". Available: ${Object.keys(r).join(", ")}`
8407
+ detail: `Unknown configKey: "${c}". Available: ${Object.keys(r).join(", ")}`
8408
8408
  });
8409
- let d = crypto.randomUUID(), f = t.name.includes(".") ? `.${t.name.split(".").pop()}` : u.io.supportedFileExtensions[0], p = {
8410
- id: d,
8409
+ let u = crypto.randomUUID(), d = t.name.includes(".") ? `.${t.name.split(".").pop()}` : l.io.supportedFileExtensions[0], p = {
8410
+ id: u,
8411
8411
  name: t.name.replace(/\.[^.]+$/, "") || "untitled",
8412
- extension: f,
8413
- configKey: l,
8412
+ extension: d,
8413
+ configKey: c,
8414
8414
  createdAt: Date.now(),
8415
8415
  metadata: a?.metadata
8416
8416
  };
8417
8417
  await h(n, p);
8418
8418
  let { recordCount: m } = await q({
8419
8419
  file: t,
8420
- documentId: d,
8420
+ documentId: u,
8421
8421
  store: n,
8422
- config: u,
8422
+ config: l,
8423
8423
  useCustomRecordsIds: a?.useCustomRecordsIds,
8424
8424
  chunkOptions: a?.chunkOptions,
8425
8425
  hooks: o,
8426
8426
  perf: s
8427
8427
  });
8428
8428
  return {
8429
- documentId: d,
8429
+ documentId: u,
8430
8430
  record: p,
8431
8431
  documentState: Zn(p),
8432
8432
  recordCount: m
@@ -8444,19 +8444,19 @@ async function $n(e) {
8444
8444
  //#region src/project/io/init-empty-document.ts
8445
8445
  async function er(e) {
8446
8446
  let { store: t, configs: n, defaultConfigKey: r, options: i, hooks: a } = e, o = i?.configKey ?? r, s = n[o];
8447
- c(s, {
8447
+ f(s, {
8448
8448
  key: "UNKNOWN_CONFIG_KEY",
8449
8449
  detail: `Unknown configKey: "${o}". Available: ${Object.keys(n).join(", ")}`
8450
8450
  });
8451
- let l = i?.extension ?? s.io.supportedFileExtensions[0], u = i?.name ?? "untitled", d = crypto.randomUUID(), f = {
8452
- id: d,
8453
- name: u,
8454
- extension: l,
8451
+ let c = i?.extension ?? s.io.supportedFileExtensions[0], l = i?.name ?? "untitled", u = crypto.randomUUID(), d = {
8452
+ id: u,
8453
+ name: l,
8454
+ extension: c,
8455
8455
  configKey: o,
8456
8456
  createdAt: Date.now(),
8457
8457
  metadata: i?.metadata
8458
8458
  };
8459
- await t.registerDocument(f);
8459
+ await t.registerDocument(d);
8460
8460
  let p = ee({
8461
8461
  dialecteConfig: s,
8462
8462
  hooks: a,
@@ -8468,29 +8468,29 @@ async function er(e) {
8468
8468
  children: []
8469
8469
  }
8470
8470
  });
8471
- return await t.bulkWrite(d, { creates: [p] }), {
8472
- documentId: d,
8473
- record: f,
8474
- documentState: Zn(f)
8471
+ return await t.bulkWrite(u, { creates: [p] }), {
8472
+ documentId: u,
8473
+ record: d,
8474
+ documentState: Zn(d)
8475
8475
  };
8476
8476
  }
8477
8477
  //#endregion
8478
8478
  //#region src/project/project.ts
8479
8479
  var tr = class {
8480
8480
  get name() {
8481
- return c(this._name !== void 0, {
8481
+ return f(this._name !== void 0, {
8482
8482
  key: "PROJECT_NOT_OPENED",
8483
8483
  detail: "Call project.open(name) before accessing project properties."
8484
8484
  }), this._name;
8485
8485
  }
8486
8486
  get store() {
8487
- return c(this._store !== void 0, {
8487
+ return f(this._store !== void 0, {
8488
8488
  key: "PROJECT_NOT_OPENED",
8489
8489
  detail: "Call project.open(name) before accessing project properties."
8490
8490
  }), this._store;
8491
8491
  }
8492
8492
  get channel() {
8493
- return c(this._channel !== void 0, {
8493
+ return f(this._channel !== void 0, {
8494
8494
  key: "PROJECT_NOT_OPENED",
8495
8495
  detail: "Call project.open(name) before accessing project properties."
8496
8496
  }), this._channel;
@@ -8625,7 +8625,7 @@ var tr = class {
8625
8625
  }
8626
8626
  openDocument(e) {
8627
8627
  let t = this.state.documents.get(e);
8628
- c(t, {
8628
+ f(t, {
8629
8629
  key: "DOCUMENT_NOT_REGISTERED",
8630
8630
  detail: `Document "${e}" not registered in project "${this.name}"`
8631
8631
  });
@@ -8654,7 +8654,7 @@ var tr = class {
8654
8654
  }
8655
8655
  async undo(e) {
8656
8656
  let t = this.state.documents.get(e);
8657
- c(t, {
8657
+ f(t, {
8658
8658
  key: "DOCUMENT_NOT_REGISTERED",
8659
8659
  detail: `Document "${e}" not registered in project "${this.name}"`
8660
8660
  }), await this.store.undo(e);
@@ -8667,7 +8667,7 @@ var tr = class {
8667
8667
  }
8668
8668
  async redo(e) {
8669
8669
  let t = this.state.documents.get(e);
8670
- c(t, {
8670
+ f(t, {
8671
8671
  key: "DOCUMENT_NOT_REGISTERED",
8672
8672
  detail: `Document "${e}" not registered in project "${this.name}"`
8673
8673
  }), await this.store.redo(e);