@dialecte/core 0.4.14 → 0.4.16

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 { a as e, d as t, f as n, n as r, o as i, p as a, r as o, t as s } from "./utils-C5_11hqg.js";
1
+ import { c as e, h as t, m as n, n as r, p as i, r as a, s as o, t as s } from "./utils-BiEx1x59.js";
2
2
  import { CUSTOM_RECORD_ID_ATTRIBUTE as c, assertNoFixedViolation as l, isRecordOf as u, mergeExtensions as d, standardizeRecord as f, toFullAttributeArray as p, toRawRecord as m, toRef as h, toTreeRecord as g } from "./helpers.js";
3
3
  //#region \0rolldown/runtime.js
4
4
  var _ = Object.create, v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.getOwnPropertyNames, x = Object.getPrototypeOf, S = Object.prototype.hasOwnProperty, C = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), ee = (e, t, n, r) => {
@@ -118,12 +118,12 @@ function T(e) {
118
118
  status: "deleted"
119
119
  };
120
120
  }
121
- function E(e, t, n) {
122
- e !== t && a("ELEMENT_TAGNAME_MISMATCH", {
123
- detail: `Expected tagName '${t}', got '${e}' for id '${n}'`,
121
+ function E(e, n, r) {
122
+ e !== n && t("ELEMENT_TAGNAME_MISMATCH", {
123
+ detail: `Expected tagName '${n}', got '${e}' for id '${r}'`,
124
124
  ref: {
125
- tagName: t,
126
- id: n
125
+ tagName: n,
126
+ id: r
127
127
  }
128
128
  });
129
129
  }
@@ -196,29 +196,29 @@ function ce(e) {
196
196
  //#endregion
197
197
  //#region src/document/query/get/record/get-record.ts
198
198
  async function O(e) {
199
- let { context: t, ref: n } = e;
200
- if (t.stagedOperations.log.length > 0) {
199
+ let { context: n, ref: r } = e;
200
+ if (n.stagedOperations.log.length > 0) {
201
201
  let e = oe({
202
- stagedOperations: t.stagedOperations,
203
- tagName: n.tagName,
204
- id: n.id
202
+ stagedOperations: n.stagedOperations,
203
+ tagName: r.tagName,
204
+ id: r.id
205
205
  });
206
206
  if (e?.status === "deleted") return;
207
207
  if (e) return e;
208
208
  }
209
- let r;
210
- if (n.id === void 0) {
211
- let e = `__singleton_${n.tagName}`, i = Qt(t) ? t.recordCache.get(e) : void 0;
212
- i ? (t.perf.count("core::query::getRecord.cacheHit"), r = i) : (t.perf.count("core::query::getRecord.miss"), t.perf.count("core::store::getByTagName"), r = (await t.store.getByTagNameInDocument(n.tagName, t.documentId))[0], r && Qt(t) && (t.recordCache.set(r.id, r), t.recordCache.set(e, r)));
209
+ let i;
210
+ if (r.id === void 0) {
211
+ let e = `__singleton_${r.tagName}`, t = Qt(n) ? n.recordCache.get(e) : void 0;
212
+ 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 && Qt(n) && (n.recordCache.set(i.id, i), n.recordCache.set(e, i)));
213
213
  } else {
214
- let e = Qt(t) ? t.recordCache.get(n.id) : void 0;
215
- e ? (t.perf.count("core::query::getRecord.cacheHit"), r = e) : (t.perf.count("core::query::getRecord.miss"), t.perf.count("core::store::get"), r = await t.store.get(n.id, t.documentId), r && Qt(t) && t.recordCache.set(n.id, r));
214
+ let e = Qt(n) ? n.recordCache.get(r.id) : void 0;
215
+ 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 && Qt(n) && n.recordCache.set(r.id, i));
216
216
  }
217
- if (r) return r.tagName !== n.tagName && a("ELEMENT_TAGNAME_MISMATCH", {
218
- detail: `Expected tagName '${n.tagName}', got '${r.tagName}' for id '${n.id}'`,
219
- ref: n
217
+ if (i) return i.tagName !== r.tagName && t("ELEMENT_TAGNAME_MISMATCH", {
218
+ detail: `Expected tagName '${r.tagName}', got '${i.tagName}' for id '${r.id}'`,
219
+ ref: r
220
220
  }), {
221
- ...r,
221
+ ...i,
222
222
  status: "unchanged"
223
223
  };
224
224
  }
@@ -593,10 +593,10 @@ async function F(e) {
593
593
  defaults: o
594
594
  }) : void 0) ?? "";
595
595
  }
596
- async function Ce(e) {
597
- let { context: t, ref: r, name: a, namespace: o, defaults: s = "optional" } = e, { dialecteConfig: c } = t, l = await O({
598
- context: t,
599
- ref: r
596
+ async function Ce(t) {
597
+ let { context: r, ref: i, name: a, namespace: o, defaults: s = "optional" } = t, { dialecteConfig: c } = r, l = await O({
598
+ context: r,
599
+ ref: i
600
600
  }), u = l?.attributes ?? [], d = we(c, a, o), f = u.find((e) => e.name === d);
601
601
  if (f) return f;
602
602
  if (!l || s === "none") return;
@@ -607,7 +607,7 @@ async function Ce(e) {
607
607
  defaults: s
608
608
  });
609
609
  if (p === void 0) return;
610
- let { namespace: m } = i({
610
+ let { namespace: m } = e({
611
611
  dialecteConfig: c,
612
612
  tagName: l.tagName,
613
613
  attributeName: d
@@ -618,18 +618,18 @@ async function Ce(e) {
618
618
  namespace: m
619
619
  };
620
620
  }
621
- function we(e, n, r) {
622
- if (r === void 0) return n;
623
- let i = t(e, r);
624
- return i ? `${i}:${n}` : n;
621
+ function we(e, t, n) {
622
+ if (n === void 0) return t;
623
+ let r = i(e, n);
624
+ return r ? `${r}:${t}` : t;
625
625
  }
626
626
  //#endregion
627
627
  //#region src/document/query/get/attribute/get-attributes.ts
628
628
  async function Te(e) {
629
- let { context: r, ref: i, namespace: a, defaults: o = "optional" } = e, { dialecteConfig: s } = r, c = await O({
630
- context: r,
631
- ref: i
632
- }), l = c?.attributes ?? [], u = a === void 0 ? "" : t(s, a), d = l.reduce((e, t) => {
629
+ let { context: t, ref: r, namespace: a, defaults: o = "optional" } = e, { dialecteConfig: s } = t, c = await O({
630
+ context: t,
631
+ ref: r
632
+ }), l = c?.attributes ?? [], u = a === void 0 ? "" : i(s, a), d = l.reduce((e, t) => {
633
633
  let { prefix: n, local: r, isXmlns: i } = De(t.name);
634
634
  return i || n !== u || (e[r] = t.value ?? ""), e;
635
635
  }, {});
@@ -649,30 +649,30 @@ async function Te(e) {
649
649
  }
650
650
  return d;
651
651
  }
652
- async function Ee(e) {
653
- let { context: t, ref: r, defaults: a = "optional" } = e, { dialecteConfig: o } = t, s = await O({
654
- context: t,
655
- ref: r
652
+ async function Ee(t) {
653
+ let { context: r, ref: i, defaults: a = "optional" } = t, { dialecteConfig: o } = r, s = await O({
654
+ context: r,
655
+ ref: i
656
656
  }), c = [...s?.attributes ?? []];
657
657
  if (s && a !== "none") {
658
- let e = new Set(c.map((e) => e.name)), t = o.definition[s.tagName]?.attributes.sequence ?? [];
659
- for (let r of t) {
660
- if (e.has(r)) continue;
661
- let t = n({
658
+ let t = new Set(c.map((e) => e.name)), r = o.definition[s.tagName]?.attributes.sequence ?? [];
659
+ for (let i of r) {
660
+ if (t.has(i)) continue;
661
+ let r = n({
662
662
  dialecteConfig: o,
663
663
  tagName: s.tagName,
664
- attributeName: r,
664
+ attributeName: i,
665
665
  defaults: a
666
666
  });
667
- if (t === void 0) continue;
668
- let { namespace: l } = i({
667
+ if (r === void 0) continue;
668
+ let { namespace: l } = e({
669
669
  dialecteConfig: o,
670
670
  tagName: s.tagName,
671
- attributeName: r
671
+ attributeName: i
672
672
  });
673
673
  c.push({
674
- name: r,
675
- value: t,
674
+ name: i,
675
+ value: r,
676
676
  namespace: l
677
677
  });
678
678
  }
@@ -796,15 +796,15 @@ function Ne(e) {
796
796
  //#endregion
797
797
  //#region src/document/query/get/tree/get-tree.ts
798
798
  async function Pe(e) {
799
- let { context: t, ref: n, options: r = {}, dialecteConfig: i } = e, { select: a, omit: s, unwrap: c, depth: l } = r, u = l !== void 0 && n.id !== void 0 && t.stagedOperations.log.length === 0 ? await Fe(t, n, l) : await I(t), d = Ie(u, n);
800
- o(d, {
799
+ let { context: t, ref: n, options: r = {}, dialecteConfig: i } = e, { select: o, omit: s, unwrap: c, depth: l } = r, u = l !== void 0 && n.id !== void 0 && t.stagedOperations.log.length === 0 ? await Fe(t, n, l) : await I(t), d = Ie(u, n);
800
+ a(d, {
801
801
  detail: "No record found for provided ref",
802
802
  key: "ELEMENT_NOT_FOUND"
803
803
  });
804
804
  let f = ke(s), p = t.dialecteConfig.transparentElements, m = Le({
805
805
  recordsById: u,
806
806
  record: d,
807
- select: a,
807
+ select: o,
808
808
  compiledOmit: f,
809
809
  dialecteConfig: i,
810
810
  transparentElements: p,
@@ -1010,12 +1010,12 @@ function We(e, t) {
1010
1010
  //#endregion
1011
1011
  //#region src/document/query/snapshot/collect-snapshot.ts
1012
1012
  async function Ge(e) {
1013
- let { context: t, ref: n, ancestors: r = 0, depth: i, includeDeleted: a = !1 } = e;
1013
+ let { context: t, ref: n, ancestors: r = 0, depth: i, includeDeleted: o = !1 } = e;
1014
1014
  if (!n && i === void 0) return Ke({
1015
1015
  context: t,
1016
- includeDeleted: a
1016
+ includeDeleted: o
1017
1017
  });
1018
- let s = e.siblings ?? !1, c = s === !0 || typeof s == "object" && !!s, l = typeof s == "object" && !!s && s.expand === !0, u = n ?? { tagName: t.dialecteConfig.rootElementName }, d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = a ? ce(t.stagedOperations.log) : void 0, m = (e) => {
1018
+ let s = e.siblings ?? !1, c = s === !0 || typeof s == "object" && !!s, l = typeof s == "object" && !!s && s.expand === !0, u = n ?? { tagName: t.dialecteConfig.rootElementName }, d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = o ? ce(t.stagedOperations.log) : void 0, m = (e) => {
1019
1019
  if (p) for (let t of p.get(e) ?? []) f.has(t.id) || (f.set(t.id, t), m(t.id));
1020
1020
  }, g = async (e, n) => {
1021
1021
  if (d.set(e.id, e), m(e.id), !(i !== void 0 && n >= i)) for (let r of e.children) {
@@ -1029,7 +1029,7 @@ async function Ge(e) {
1029
1029
  context: t,
1030
1030
  ref: u
1031
1031
  });
1032
- o(_, {
1032
+ a(_, {
1033
1033
  key: "ELEMENT_NOT_FOUND",
1034
1034
  detail: "No record found for the provided ref"
1035
1035
  });
@@ -1072,18 +1072,18 @@ async function Ke(e) {
1072
1072
  rawRecords: await t.store.getByDocumentId(t.documentId),
1073
1073
  stagedOperations: t.stagedOperations,
1074
1074
  includeDeleted: n
1075
- }), a;
1075
+ }), o;
1076
1076
  for (let e of r.values()) if (e.tagName === t.dialecteConfig.rootElementName) {
1077
- a = e.id;
1077
+ o = e.id;
1078
1078
  break;
1079
1079
  }
1080
- return o(a, {
1080
+ return a(o, {
1081
1081
  key: "ROOT_NOT_FOUND",
1082
1082
  detail: `No ${t.dialecteConfig.rootElementName} root element found in document`
1083
1083
  }), qe({
1084
1084
  live: r,
1085
1085
  deletedById: new Map(i.map((e) => [e.id, e])),
1086
- rootId: a
1086
+ rootId: o
1087
1087
  });
1088
1088
  }
1089
1089
  function qe(e) {
@@ -1103,7 +1103,7 @@ function qe(e) {
1103
1103
  //#endregion
1104
1104
  //#region src/document/query/snapshot/records-to-tree.ts
1105
1105
  function Je(e) {
1106
- let { liveRecords: t, deletedRecords: n, rootId: r } = e, i = new Map(t.map((e) => [e.id, e])), a = new Map(n.map((e) => [e.id, e])), s = /* @__PURE__ */ new Map();
1106
+ let { liveRecords: t, deletedRecords: n, rootId: r } = e, i = new Map(t.map((e) => [e.id, e])), o = new Map(n.map((e) => [e.id, e])), s = /* @__PURE__ */ new Map();
1107
1107
  for (let e of n) {
1108
1108
  let t = e.parent?.id;
1109
1109
  if (!t) continue;
@@ -1111,15 +1111,15 @@ function Je(e) {
1111
1111
  n.push(e), s.set(t, n);
1112
1112
  }
1113
1113
  let c = i.get(r);
1114
- o(c, {
1114
+ a(c, {
1115
1115
  key: "ROOT_NOT_FOUND",
1116
1116
  detail: `No record found for rootId "${r}"`
1117
1117
  });
1118
1118
  let l = (e, t) => {
1119
- let n = t === "live" ? i : a, r = e.children.filter((e) => n.has(e.id)).map((e) => l(n.get(e.id), t)), o = t === "live" ? (s.get(e.id) ?? []).map((e) => l(e, "deleted")) : [];
1119
+ let n = t === "live" ? i : o, r = e.children.filter((e) => n.has(e.id)).map((e) => l(n.get(e.id), t)), a = t === "live" ? (s.get(e.id) ?? []).map((e) => l(e, "deleted")) : [];
1120
1120
  return g({
1121
1121
  record: e,
1122
- tree: [...r, ...o]
1122
+ tree: [...r, ...a]
1123
1123
  });
1124
1124
  };
1125
1125
  return l(c, "live");
@@ -1413,10 +1413,10 @@ async function $e(e) {
1413
1413
  //#endregion
1414
1414
  //#region src/xml/build/build-xml-document.ts
1415
1415
  function et(e) {
1416
- let { records: t, config: n, withDatabaseIds: r = !1, rootId: i, declareNamespaces: a = !0 } = e, s = /* @__PURE__ */ new Map(), c;
1416
+ let { records: t, config: n, withDatabaseIds: r = !1, rootId: i, declareNamespaces: o = !0 } = e, s = /* @__PURE__ */ new Map(), c;
1417
1417
  for (let e of t) s.set(e.id, e), e.tagName === n.rootElementName && (c = e);
1418
1418
  let l = i ? s.get(i) : c;
1419
- o(l, {
1419
+ a(l, {
1420
1420
  detail: i ? `No record found for rootId "${i}"` : `No ${n.rootElementName} root element found in records`,
1421
1421
  key: "EXPORT_ROOT_NOT_FOUND"
1422
1422
  });
@@ -1424,16 +1424,16 @@ function et(e) {
1424
1424
  document: f,
1425
1425
  record: l,
1426
1426
  defaultNamespace: d,
1427
- declareNamespaces: a
1427
+ declareNamespaces: o
1428
1428
  });
1429
- return a && p.setAttribute("xmlns", l.namespace.uri), l.attributes && it({
1429
+ return o && p.setAttribute("xmlns", l.namespace.uri), l.attributes && it({
1430
1430
  config: n,
1431
1431
  document: f,
1432
1432
  element: p,
1433
1433
  attributes: l.attributes,
1434
1434
  isRoot: !0,
1435
1435
  isFragment: u,
1436
- declareNamespaces: a
1436
+ declareNamespaces: o
1437
1437
  }), u || ot({
1438
1438
  config: n,
1439
1439
  rootElement: p,
@@ -1446,16 +1446,16 @@ function et(e) {
1446
1446
  parentRecord: l,
1447
1447
  parentElement: p,
1448
1448
  isFragment: u,
1449
- declareNamespaces: a
1449
+ declareNamespaces: o
1450
1450
  }), f;
1451
1451
  }
1452
1452
  function tt(e) {
1453
- let { index: t, config: n, withDatabaseIds: i, xmlDocument: a, parentRecord: s, parentElement: c, isFragment: l, declareNamespaces: u } = e;
1453
+ let { index: t, config: n, withDatabaseIds: i, xmlDocument: o, parentRecord: s, parentElement: c, isFragment: l, declareNamespaces: u } = e;
1454
1454
  if (!s.children || s.children.length === 0) return;
1455
1455
  let d = [];
1456
1456
  for (let e of s.children) {
1457
1457
  let n = t.get(e.id);
1458
- o(n, {
1458
+ a(n, {
1459
1459
  detail: `Parent '${s.tagName}' references non-existent child '${e.tagName}' (id: ${e.id})`,
1460
1460
  key: "EXPORT_ORPHAN_CHILD_REF",
1461
1461
  ref: {
@@ -1472,7 +1472,7 @@ function tt(e) {
1472
1472
  for (let e of f) {
1473
1473
  let r = rt({
1474
1474
  config: n,
1475
- document: a,
1475
+ document: o,
1476
1476
  record: e,
1477
1477
  defaultNamespace: n.namespaces.default,
1478
1478
  withDatabaseIds: i,
@@ -1483,7 +1483,7 @@ function tt(e) {
1483
1483
  index: t,
1484
1484
  config: n,
1485
1485
  withDatabaseIds: i,
1486
- xmlDocument: a,
1486
+ xmlDocument: o,
1487
1487
  parentRecord: e,
1488
1488
  parentElement: r,
1489
1489
  isFragment: l,
@@ -1524,25 +1524,25 @@ function rt(e) {
1524
1524
  declareNamespaces: s
1525
1525
  }), r.value && (l.textContent = r.value.trim()), a && l.setAttribute(Ze, r.id), l;
1526
1526
  }
1527
- function it(t) {
1528
- let { config: n, document: r, element: i, attributes: a, isRoot: o, isFragment: s, declareNamespaces: c } = t;
1529
- for (let t of a) {
1530
- if (lt(t)) continue;
1531
- if (!ct(t) || !t.namespace.prefix) {
1532
- i.setAttribute(t.name, String(t.value));
1527
+ function it(e) {
1528
+ let { config: t, document: n, element: r, attributes: i, isRoot: a, isFragment: s, declareNamespaces: c } = e;
1529
+ for (let e of i) {
1530
+ if (lt(e)) continue;
1531
+ if (!ct(e) || !e.namespace.prefix) {
1532
+ r.setAttribute(e.name, String(e.value));
1533
1533
  continue;
1534
1534
  }
1535
- let a = e(t.name);
1535
+ let i = o(e.name);
1536
1536
  if (!c) {
1537
- i.setAttribute(`${t.namespace.prefix}:${a}`, String(t.value));
1537
+ r.setAttribute(`${e.namespace.prefix}:${i}`, String(e.value));
1538
1538
  continue;
1539
1539
  }
1540
- o || at({
1541
- config: n,
1542
- document: r,
1543
- namespace: t.namespace,
1540
+ a || at({
1541
+ config: t,
1542
+ document: n,
1543
+ namespace: e.namespace,
1544
1544
  isFragment: s
1545
- }), i.setAttributeNS(t.namespace.uri, `${t.namespace.prefix}:${a}`, String(t.value));
1545
+ }), r.setAttributeNS(e.namespace.uri, `${e.namespace.prefix}:${i}`, String(e.value));
1546
1546
  }
1547
1547
  }
1548
1548
  function at(e) {
@@ -1555,45 +1555,45 @@ function at(e) {
1555
1555
  namespace: r
1556
1556
  }));
1557
1557
  }
1558
- function ot(t) {
1559
- let { config: r, rootElement: i, namespace: a } = t, o = Object.entries(r.definition[r.rootElementName].attributes.details).filter(([e, t]) => n({
1560
- dialecteConfig: r,
1561
- tagName: r.rootElementName,
1558
+ function ot(e) {
1559
+ let { config: t, rootElement: r, namespace: i } = e, a = Object.entries(t.definition[t.rootElementName].attributes.details).filter(([e, r]) => n({
1560
+ dialecteConfig: t,
1561
+ tagName: t.rootElementName,
1562
1562
  attributeName: e,
1563
1563
  defaults: "required"
1564
- }) === void 0 ? !1 : a.uri === r.namespaces.default.uri ? !t.namespace : t.namespace?.prefix === a.prefix && t.namespace?.uri === a.uri);
1565
- if (o.length > 0) for (let [t, a] of o) {
1566
- let o = e(t), s = n({
1567
- dialecteConfig: r,
1568
- tagName: r.rootElementName,
1569
- attributeName: t,
1564
+ }) === void 0 ? !1 : i.uri === t.namespaces.default.uri ? !r.namespace : r.namespace?.prefix === i.prefix && r.namespace?.uri === i.uri);
1565
+ if (a.length > 0) for (let [e, i] of a) {
1566
+ let a = o(e), s = n({
1567
+ dialecteConfig: t,
1568
+ tagName: t.rootElementName,
1569
+ attributeName: e,
1570
1570
  defaults: "required"
1571
1571
  }) ?? "";
1572
- if (!(a.namespace ? i.hasAttributeNS(a.namespace.uri, o) : i.hasAttribute(o))) if (a.namespace) {
1573
- let e = `${a.namespace.prefix}:${o}`;
1574
- i.setAttributeNS(a.namespace.uri, e, s);
1575
- } else i.setAttribute(o, s);
1572
+ if (!(i.namespace ? r.hasAttributeNS(i.namespace.uri, a) : r.hasAttribute(a))) if (i.namespace) {
1573
+ let e = `${i.namespace.prefix}:${a}`;
1574
+ r.setAttributeNS(i.namespace.uri, e, s);
1575
+ } else r.setAttribute(a, s);
1576
1576
  }
1577
1577
  }
1578
- function st(t) {
1579
- let { config: r, document: i, element: a, tagName: o, isFragment: s, declareNamespaces: c } = t;
1578
+ function st(e) {
1579
+ let { config: t, document: r, element: i, tagName: a, isFragment: s, declareNamespaces: c } = e;
1580
1580
  if (!c) return;
1581
- let l = r.definition[o]?.attributes.details;
1582
- if (l) for (let [t, u] of Object.entries(l)) {
1581
+ let l = t.definition[a]?.attributes.details;
1582
+ if (l) for (let [e, u] of Object.entries(l)) {
1583
1583
  let l = n({
1584
- dialecteConfig: r,
1585
- tagName: o,
1586
- attributeName: t,
1584
+ dialecteConfig: t,
1585
+ tagName: a,
1586
+ attributeName: e,
1587
1587
  defaults: "required"
1588
1588
  });
1589
1589
  if (l === void 0) continue;
1590
- let d = e(t);
1591
- (u.namespace ? a.hasAttributeNS(u.namespace.uri, d) : a.hasAttribute(d)) || (u.namespace && u.namespace.prefix && u.namespace.prefix !== "xmlns" ? (c && at({
1592
- config: r,
1593
- document: i,
1590
+ let d = o(e);
1591
+ (u.namespace ? i.hasAttributeNS(u.namespace.uri, d) : i.hasAttribute(d)) || (u.namespace && u.namespace.prefix && u.namespace.prefix !== "xmlns" ? (c && at({
1592
+ config: t,
1593
+ document: r,
1594
1594
  namespace: u.namespace,
1595
1595
  isFragment: s
1596
- }), a.setAttributeNS(u.namespace.uri, `${u.namespace.prefix}:${d}`, l)) : a.setAttribute(d, l));
1596
+ }), i.setAttributeNS(u.namespace.uri, `${u.namespace.prefix}:${d}`, l)) : i.setAttribute(d, l));
1597
1597
  }
1598
1598
  }
1599
1599
  function ct(e) {
@@ -2433,41 +2433,41 @@ var B = /* @__PURE__ */ C(((e, t) => {
2433
2433
  })();
2434
2434
  })(e === void 0 ? e.sax = {} : e);
2435
2435
  })))(), 1);
2436
- function dt(e, t) {
2437
- let n = new Set(t.elements), r = {};
2438
- for (let e of t.elements) r[e] = void 0;
2439
- let i = ut.parser(!0, {
2436
+ function dt(e, n) {
2437
+ let r = new Set(n.elements), i = {};
2438
+ for (let e of n.elements) i[e] = void 0;
2439
+ let a = ut.parser(!0, {
2440
2440
  xmlns: !0,
2441
2441
  position: !1
2442
2442
  }), o = null;
2443
- i.onopentag = (e) => {
2444
- let t = e, i = t.local;
2445
- if (!n.has(i)) return;
2443
+ a.onopentag = (e) => {
2444
+ let t = e, n = t.local;
2445
+ if (!r.has(n)) return;
2446
2446
  let a = {};
2447
2447
  for (let e of Object.values(t.attributes)) {
2448
2448
  let t = e.prefix === "xmlns" && e.local === "" ? "xmlns" : e.prefix ? e.local : e.name;
2449
2449
  a[t] = e.value;
2450
2450
  }
2451
- r[i] = {
2451
+ i[n] = {
2452
2452
  namespace: t.uri,
2453
2453
  attributes: a,
2454
2454
  value: "",
2455
2455
  children: []
2456
- }, n.delete(i), o = i;
2457
- }, i.ontext = (e) => {
2458
- o && r[o] && (r[o].value += e);
2459
- }, i.oncdata = i.ontext, i.onclosetag = (e) => {
2460
- if (o === e && (o = null), n.size === 0) throw ft;
2456
+ }, r.delete(n), o = n;
2457
+ }, a.ontext = (e) => {
2458
+ o && i[o] && (i[o].value += e);
2459
+ }, a.oncdata = a.ontext, a.onclosetag = (e) => {
2460
+ if (o === e && (o = null), r.size === 0) throw ft;
2461
2461
  };
2462
2462
  try {
2463
- i.write(e).close();
2463
+ a.write(e).close();
2464
2464
  } catch (e) {
2465
- e !== ft && a("PARSE_ERROR", {
2465
+ e !== ft && t("PARSE_ERROR", {
2466
2466
  detail: String(e),
2467
2467
  cause: e instanceof Error ? e : void 0
2468
2468
  });
2469
2469
  }
2470
- return r;
2470
+ return i;
2471
2471
  }
2472
2472
  var ft = Symbol("inspectXml:earlyExit"), pt = class {
2473
2473
  constructor() {
@@ -2690,7 +2690,7 @@ function xt(e) {
2690
2690
  }
2691
2691
  function St(e) {
2692
2692
  let { element: t, defaultNamespace: n, rootElementName: r } = e;
2693
- return o(t.name === r, { detail: `Expected root element <${r}>, got <${t.name}>` }), t.attributes?.xmlns?.value ? {
2693
+ return a(t.name === r, { detail: `Expected root element <${r}>, got <${t.name}>` }), t.attributes?.xmlns?.value ? {
2694
2694
  prefix: "",
2695
2695
  uri: t.attributes.xmlns.value
2696
2696
  } : n;
@@ -2734,8 +2734,8 @@ function Et(e) {
2734
2734
  //#region src/xml/parse/parse-xml-document.ts
2735
2735
  var Dt = 32 * 1024, Ot = 2e3;
2736
2736
  async function kt(e) {
2737
- let { documentId: t, store: n, config: r, useCustomRecordsIds: i = !1, chunkOptions: a, hooks: s, perf: c = V } = e, { file: l } = e, { supportedFileExtensions: u } = r.io;
2738
- if (o(u.some((e) => l.name.toLowerCase().endsWith(e)), {
2737
+ let { documentId: t, store: n, config: r, useCustomRecordsIds: i = !1, chunkOptions: o, hooks: s, perf: c = V } = e, { file: l } = e, { supportedFileExtensions: u } = r.io;
2738
+ if (a(u.some((e) => l.name.toLowerCase().endsWith(e)), {
2739
2739
  key: "ASSERTION_FAILED",
2740
2740
  detail: `Unsupported file type: ${l.name}`
2741
2741
  }), l.size === 0) return {
@@ -2747,7 +2747,7 @@ async function kt(e) {
2747
2747
  let e = d(await l.text());
2748
2748
  l = new File([e], l.name, { type: l.type });
2749
2749
  }
2750
- let f = a?.chunkSize ?? Dt, p = a?.batchSize ?? Ot, m = new pt(), h = _t({
2750
+ let f = o?.chunkSize ?? Dt, p = o?.batchSize ?? Ot, m = new pt(), h = _t({
2751
2751
  dialecteConfig: r,
2752
2752
  useCustomRecordsIds: i,
2753
2753
  session: m,
@@ -3005,7 +3005,7 @@ var It = class {
3005
3005
  }
3006
3006
  async getDocumentInfo() {
3007
3007
  let e = await this.store.getDocument(this.documentId);
3008
- return o(e, {
3008
+ return a(e, {
3009
3009
  key: "DOCUMENT_NOT_REGISTERED",
3010
3010
  detail: `Expected document id: ${this.documentId}`
3011
3011
  }), e;
@@ -3015,7 +3015,7 @@ var It = class {
3015
3015
  context: this.context,
3016
3016
  ref: { tagName: this.dialecteConfig.rootElementName }
3017
3017
  });
3018
- return o(e, {
3018
+ return a(e, {
3019
3019
  key: "ROOT_NOT_FOUND",
3020
3020
  detail: `Expected tag name: ${this.dialecteConfig.rootElementName}`
3021
3021
  }), e;
@@ -3124,9 +3124,9 @@ var It = class {
3124
3124
  //#endregion
3125
3125
  //#region src/document/transaction/stage-operations.ts
3126
3126
  function Rt(e) {
3127
- let { context: t, status: n, record: r, oldRecord: i, newRecord: a } = e, s, c, l;
3128
- if (r && (s = m(r)), i && (c = m(i)), a && (l = m(a)), n === "created") {
3129
- o(s, {
3127
+ let { context: t, status: n, record: r, oldRecord: i, newRecord: o } = e, s, c, l;
3128
+ if (r && (s = m(r)), i && (c = m(i)), o && (l = m(o)), n === "created") {
3129
+ a(s, {
3130
3130
  detail: "Record is required for created",
3131
3131
  key: "ELEMENT_NOT_FOUND"
3132
3132
  });
@@ -3137,7 +3137,7 @@ function Rt(e) {
3137
3137
  };
3138
3138
  t.stagedOperations.log.push(e), t.stagedOperations.byId.set(s.id, e);
3139
3139
  } else if (n === "updated") {
3140
- o(c && l, {
3140
+ a(c && l, {
3141
3141
  detail: "Old record and new record are required for updated",
3142
3142
  key: "ELEMENT_NOT_FOUND"
3143
3143
  });
@@ -3148,7 +3148,7 @@ function Rt(e) {
3148
3148
  };
3149
3149
  t.stagedOperations.log.push(e), t.stagedOperations.byId.set(l.id, e);
3150
3150
  } else if (n === "deleted" && s) {
3151
- o(s, {
3151
+ a(s, {
3152
3152
  detail: "Record is required for deleted",
3153
3153
  key: "ELEMENT_NOT_FOUND"
3154
3154
  });
@@ -3190,19 +3190,19 @@ function G(e) {
3190
3190
  //#endregion
3191
3191
  //#region src/document/transaction/create/create.ts
3192
3192
  async function zt(e) {
3193
- let { dialecteConfig: t, hooks: n, context: r, query: i, parentRef: a, params: s } = e, { id: c, tagName: u, attributes: d, namespace: p, value: m } = s;
3193
+ let { dialecteConfig: t, hooks: n, context: r, query: i, parentRef: o, params: s } = e, { id: c, tagName: u, attributes: d, namespace: p, value: m } = s;
3194
3194
  Bt({
3195
3195
  attributes: d,
3196
3196
  tagName: u
3197
3197
  });
3198
3198
  let h = await O({
3199
3199
  context: r,
3200
- ref: a
3200
+ ref: o
3201
3201
  });
3202
- o(h, {
3202
+ a(h, {
3203
3203
  detail: "Parent record not found",
3204
3204
  key: "ELEMENT_NOT_FOUND",
3205
- ref: a
3205
+ ref: o
3206
3206
  });
3207
3207
  let g = f({
3208
3208
  dialecteConfig: t,
@@ -3250,12 +3250,12 @@ async function zt(e) {
3250
3250
  })
3251
3251
  }), g;
3252
3252
  }
3253
- function Bt(t) {
3254
- let { attributes: n, tagName: r } = t;
3255
- if (!(!n || !Array.isArray(n))) for (let t of n) {
3256
- let { name: n, namespace: i } = t;
3257
- n === "xmlns" || n.startsWith("xmlns:") || !n.includes(":") || typeof i == "object" && i?.prefix === n.slice(0, n.indexOf(":")) || a("PREFIXED_ATTRIBUTE_NAME", {
3258
- detail: `Attribute '${n}' on '${r}' is prefixed — pass a local name plus its namespace instead: { name: '${e(n)}', namespace }.`,
3253
+ function Bt(e) {
3254
+ let { attributes: n, tagName: r } = e;
3255
+ if (!(!n || !Array.isArray(n))) for (let e of n) {
3256
+ let { name: n, namespace: i } = e;
3257
+ n === "xmlns" || n.startsWith("xmlns:") || !n.includes(":") || typeof i == "object" && i?.prefix === n.slice(0, n.indexOf(":")) || t("PREFIXED_ATTRIBUTE_NAME", {
3258
+ detail: `Attribute '${n}' on '${r}' is prefixed — pass a local name plus its namespace instead: { name: '${o(n)}', namespace }.`,
3259
3259
  ref: { tagName: r }
3260
3260
  });
3261
3261
  }
@@ -3324,42 +3324,42 @@ async function Ut(e) {
3324
3324
  //#endregion
3325
3325
  //#region src/document/transaction/delete/delete.ts
3326
3326
  async function K(e) {
3327
- let { hooks: t, context: n, query: r, ref: i } = e, a = await O({
3327
+ let { hooks: t, context: n, query: r, ref: i } = e, o = await O({
3328
3328
  context: n,
3329
3329
  ref: i
3330
3330
  });
3331
- o(a, {
3331
+ a(o, {
3332
3332
  detail: `Record not found (tagName=${i.tagName}, id=${i.id})`,
3333
3333
  key: "ELEMENT_NOT_FOUND",
3334
3334
  ref: i
3335
- }), o(a.parent, {
3335
+ }), a(o.parent, {
3336
3336
  detail: "Cannot delete root element",
3337
3337
  key: "PROTECTED_ROOT"
3338
3338
  }), t?.beforeDelete && G({
3339
3339
  context: n,
3340
3340
  operations: await t.beforeDelete({
3341
- record: a,
3341
+ record: o,
3342
3342
  query: r
3343
3343
  })
3344
3344
  }), await q({
3345
3345
  context: n,
3346
- record: a
3346
+ record: o
3347
3347
  }), Rt({
3348
3348
  context: n,
3349
3349
  status: "deleted",
3350
- record: a
3350
+ record: o
3351
3351
  });
3352
3352
  let s = await O({
3353
3353
  context: n,
3354
- ref: h(a.parent)
3354
+ ref: h(o.parent)
3355
3355
  });
3356
- o(s, {
3357
- detail: `Parent record not found (tagName=${a.parent.tagName}, id=${a.parent.id})`,
3356
+ a(s, {
3357
+ detail: `Parent record not found (tagName=${o.parent.tagName}, id=${o.parent.id})`,
3358
3358
  key: "ELEMENT_NOT_FOUND"
3359
3359
  });
3360
3360
  let c = {
3361
3361
  ...s,
3362
- children: s.children.filter((e) => e.id !== a.id)
3362
+ children: s.children.filter((e) => e.id !== o.id)
3363
3363
  };
3364
3364
  return Rt({
3365
3365
  context: n,
@@ -3413,14 +3413,14 @@ function Gt(e) {
3413
3413
  //#endregion
3414
3414
  //#region src/document/transaction/update/update.ts
3415
3415
  async function Kt(e) {
3416
- let { dialecteConfig: t, hooks: n, context: r, query: i, ref: a, params: s } = e, { attributes: c, value: u } = s, d = await O({
3416
+ let { dialecteConfig: t, hooks: n, context: r, query: i, ref: o, params: s } = e, { attributes: c, value: u } = s, d = await O({
3417
3417
  context: r,
3418
- ref: a
3418
+ ref: o
3419
3419
  });
3420
- o(d, {
3421
- detail: `Record not found (tagName=${a.tagName}, id=${a.id})`,
3420
+ a(d, {
3421
+ detail: `Record not found (tagName=${o.tagName}, id=${o.id})`,
3422
3422
  key: "ELEMENT_NOT_FOUND",
3423
- ref: a
3423
+ ref: o
3424
3424
  });
3425
3425
  let m = d.attributes;
3426
3426
  if (c) {
@@ -3722,65 +3722,65 @@ var $t = class {
3722
3722
  createTransaction() {
3723
3723
  return new Zt(this.store, this.config, this.documentId, this.state, this.hooks, this.perf, this.signalStateChange);
3724
3724
  }
3725
- async transaction(e, t) {
3726
- this.activeTransactions > 0 && a("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);
3727
- let n = this.withAllExtensions(this.createTransaction());
3725
+ async transaction(e, n) {
3726
+ 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);
3727
+ let r = this.withAllExtensions(this.createTransaction());
3728
3728
  try {
3729
- let r = await e(n);
3730
- return await n.commit(), await this.refreshHistoryStatus(), this.broadcast({
3729
+ let t = await e(r);
3730
+ return await r.commit(), await this.refreshHistoryStatus(), this.broadcast({
3731
3731
  type: "commit",
3732
3732
  documentId: this.documentId,
3733
3733
  timestamp: this.state.lastUpdate ?? Date.now()
3734
- }), n.clearStagedOperations(), n.clearRecordCache(), this.state.history.push({
3734
+ }), r.clearStagedOperations(), r.clearRecordCache(), this.state.history.push({
3735
3735
  method: "commit",
3736
- message: t?.label ?? "Changes committed",
3736
+ message: n?.label ?? "Changes committed",
3737
3737
  timestamp: Date.now()
3738
- }), r;
3738
+ }), t;
3739
3739
  } catch (e) {
3740
- throw this.state.error ?? a("UNKNOWN", {
3740
+ throw this.state.error ?? t("UNKNOWN", {
3741
3741
  detail: e instanceof Error ? e.message : String(e),
3742
3742
  cause: e instanceof Error ? e : void 0
3743
3743
  });
3744
3744
  } finally {
3745
- n.progress.forceClear(), this.activeTransactions--, this.state.loading = !1, this.signalStateChange(!0);
3745
+ r.progress.forceClear(), this.activeTransactions--, this.state.loading = !1, this.signalStateChange(!0);
3746
3746
  }
3747
3747
  }
3748
- async prepare(e, t) {
3748
+ async prepare(e, n) {
3749
3749
  this.activeTransactions++, this.state.loading = !0, this.state.error = null;
3750
- let n = this.createTransaction();
3750
+ let r = this.createTransaction();
3751
3751
  try {
3752
- await e(this.withAllExtensions(n));
3752
+ await e(this.withAllExtensions(r));
3753
3753
  } catch (e) {
3754
- throw this.activeTransactions--, this.state.loading = !1, this.state.error ?? a("UNKNOWN", {
3754
+ throw this.activeTransactions--, this.state.loading = !1, this.state.error ?? t("UNKNOWN", {
3755
3755
  detail: e instanceof Error ? e.message : String(e),
3756
3756
  cause: e instanceof Error ? e : void 0
3757
3757
  });
3758
3758
  }
3759
3759
  this.activeTransactions--, this.state.loading = !1;
3760
- let r = n.getStagedOperations(), i = {
3761
- creates: r.filter((e) => e.status === "created").length,
3762
- updates: r.filter((e) => e.status === "updated").length,
3763
- deletes: r.filter((e) => e.status === "deleted").length
3760
+ let i = r.getStagedOperations(), a = {
3761
+ creates: i.filter((e) => e.status === "created").length,
3762
+ updates: i.filter((e) => e.status === "updated").length,
3763
+ deletes: i.filter((e) => e.status === "deleted").length
3764
3764
  }, o = !1;
3765
3765
  return {
3766
- operations: r,
3767
- summary: i,
3768
- query: n,
3766
+ operations: i,
3767
+ summary: a,
3768
+ query: r,
3769
3769
  commit: async () => {
3770
3770
  if (!o) {
3771
3771
  o = !0, this.activeTransactions++, this.state.loading = !0;
3772
3772
  try {
3773
- await n.commit(), await this.refreshHistoryStatus(), this.broadcast({
3773
+ await r.commit(), await this.refreshHistoryStatus(), this.broadcast({
3774
3774
  type: "commit",
3775
3775
  documentId: this.documentId,
3776
3776
  timestamp: this.state.lastUpdate ?? Date.now()
3777
- }), n.clearStagedOperations(), n.clearRecordCache(), this.state.history.push({
3777
+ }), r.clearStagedOperations(), r.clearRecordCache(), this.state.history.push({
3778
3778
  method: "commit",
3779
- message: t?.label ?? "Changes committed",
3779
+ message: n?.label ?? "Changes committed",
3780
3780
  timestamp: Date.now()
3781
3781
  });
3782
3782
  } catch (e) {
3783
- throw this.state.error ?? a("UNKNOWN", {
3783
+ throw this.state.error ?? t("UNKNOWN", {
3784
3784
  detail: e instanceof Error ? e.message : String(e),
3785
3785
  cause: e instanceof Error ? e : void 0
3786
3786
  });
@@ -3790,7 +3790,7 @@ var $t = class {
3790
3790
  }
3791
3791
  },
3792
3792
  discard: () => {
3793
- o || (o = !0, n.clearStagedOperations(), n.clearRecordCache());
3793
+ o || (o = !0, r.clearStagedOperations(), r.clearRecordCache());
3794
3794
  }
3795
3795
  };
3796
3796
  }
@@ -7718,54 +7718,54 @@ var Tn = {
7718
7718
  }
7719
7719
  async commit(e) {
7720
7720
  await this.ensureCurrentSchema();
7721
- let { documentId: t, creates: n, updates: r, deletes: i, onProgress: o } = e, s = this.db.table(this.resolveTableName(t)), c = n.length + r.length + i.length, l = 0;
7721
+ 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;
7722
7722
  try {
7723
7723
  await this.db.transaction("rw", s, this.db.table(Y), this.db.table(X), async () => {
7724
- let e = r.length > 0 ? await s.bulkGet(r.map((e) => e.id)) : [], u = i.length > 0 ? await s.bulkGet(i) : [];
7725
- if (n.length > 0) try {
7726
- await s.bulkAdd(n), l += n.length, o(l, c);
7724
+ let e = i.length > 0 ? await s.bulkGet(i.map((e) => e.id)) : [], u = a.length > 0 ? await s.bulkGet(a) : [];
7725
+ if (r.length > 0) try {
7726
+ await s.bulkAdd(r), l += r.length, o(l, c);
7727
7727
  } catch (e) {
7728
- a("STORE_BULK_ADD_FAILED", {
7728
+ t("STORE_BULK_ADD_FAILED", {
7729
7729
  detail: e instanceof Error ? e.message : String(e),
7730
7730
  cause: e instanceof Error ? e : void 0
7731
7731
  });
7732
7732
  }
7733
- if (r.length > 0) try {
7734
- await s.bulkPut(r), l += r.length, o(l, c);
7733
+ if (i.length > 0) try {
7734
+ await s.bulkPut(i), l += i.length, o(l, c);
7735
7735
  } catch (e) {
7736
- a("STORE_BULK_UPDATE_FAILED", {
7736
+ t("STORE_BULK_UPDATE_FAILED", {
7737
7737
  detail: e instanceof Error ? e.message : String(e),
7738
7738
  cause: e instanceof Error ? e : void 0
7739
7739
  });
7740
7740
  }
7741
- if (i.length > 0) try {
7742
- await s.bulkDelete(i), l += i.length, o(l, c);
7741
+ if (a.length > 0) try {
7742
+ await s.bulkDelete(a), l += a.length, o(l, c);
7743
7743
  } catch (e) {
7744
- a("STORE_DELETE_FAILED", {
7744
+ t("STORE_DELETE_FAILED", {
7745
7745
  detail: e instanceof Error ? e.message : String(e),
7746
7746
  cause: e instanceof Error ? e : void 0
7747
7747
  });
7748
7748
  }
7749
- let d = await this.getHead(t), f = await this.db.table(Y).where({ documentId: t }).filter((e) => e.sequenceNumber > d).toArray();
7749
+ let d = await this.getHead(n), f = await this.db.table(Y).where({ documentId: n }).filter((e) => e.sequenceNumber > d).toArray();
7750
7750
  f.length > 0 && await this.db.table(Y).bulkDelete(f.map((e) => e.id));
7751
7751
  let p = d + 1, m = {
7752
- documentId: t,
7752
+ documentId: n,
7753
7753
  sequenceNumber: p,
7754
7754
  timestamp: Date.now(),
7755
7755
  operations: {
7756
- creates: n,
7757
- updates: r.map((t, n) => ({
7756
+ creates: r,
7757
+ updates: i.map((t, n) => ({
7758
7758
  before: e[n],
7759
7759
  after: t
7760
7760
  })),
7761
7761
  deletes: u.filter(Boolean)
7762
7762
  }
7763
7763
  };
7764
- await this.db.table(Y).add(m), await this.setHead(t, p);
7764
+ await this.db.table(Y).add(m), await this.setHead(n, p);
7765
7765
  });
7766
7766
  } catch (e) {
7767
7767
  if (e instanceof Error && e.message.includes("dialecte")) throw e;
7768
- a("STORE_COMMIT_FAILED", {
7768
+ t("STORE_COMMIT_FAILED", {
7769
7769
  detail: e instanceof Error ? e.message : String(e),
7770
7770
  cause: e instanceof Error ? e : void 0
7771
7771
  });
@@ -7842,19 +7842,19 @@ var Tn = {
7842
7842
  async getStandaloneBlobs() {
7843
7843
  return await this.ensureCurrentSchema(), (await this.db.table(Z).toArray()).filter((e) => e.attachedTo.length === 0);
7844
7844
  }
7845
- async attachBlob(e, t) {
7845
+ async attachBlob(e, n) {
7846
7846
  await this.ensureCurrentSchema();
7847
- let n = await this.db.table(Z).get(e);
7848
- if (n || a("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;
7849
- let r = [...n.attachedTo, t];
7850
- await this.db.table(Z).update(e, { attachedTo: r });
7847
+ let r = await this.db.table(Z).get(e);
7848
+ 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;
7849
+ let i = [...r.attachedTo, n];
7850
+ await this.db.table(Z).update(e, { attachedTo: i });
7851
7851
  }
7852
- async detachBlob(e, t) {
7852
+ async detachBlob(e, n) {
7853
7853
  await this.ensureCurrentSchema();
7854
- let n = await this.db.table(Z).get(e);
7855
- n || a("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
7856
- let r = n.attachedTo.filter((e) => !(e.documentId === t.documentId && e.recordRef === t.recordRef));
7857
- await this.db.table(Z).update(e, { attachedTo: r });
7854
+ let r = await this.db.table(Z).get(e);
7855
+ r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
7856
+ let i = r.attachedTo.filter((e) => !(e.documentId === n.documentId && e.recordRef === n.recordRef));
7857
+ await this.db.table(Z).update(e, { attachedTo: i });
7858
7858
  }
7859
7859
  async removeBlob(e) {
7860
7860
  await this.ensureCurrentSchema();
@@ -7936,8 +7936,8 @@ var Tn = {
7936
7936
  function Dn() {
7937
7937
  return new Promise((e) => setTimeout(e, 0));
7938
7938
  }
7939
- function On(e, t) {
7940
- e.has(t) || a("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${t}" is not registered` });
7939
+ function On(e, n) {
7940
+ e.has(n) || t("DOCUMENT_NOT_REGISTERED", { detail: `Cannot add blob: owner document "${n}" is not registered` });
7941
7941
  }
7942
7942
  //#endregion
7943
7943
  //#region src/store/in-memory/in-memory-store.ts
@@ -8087,8 +8087,8 @@ var kn = class e {
8087
8087
  getDatabaseInstance() {
8088
8088
  return null;
8089
8089
  }
8090
- async addBlob(e, t) {
8091
- this.guardWritable(), this.documents.has(e.documentId) || a("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);
8090
+ async addBlob(e, n) {
8091
+ 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);
8092
8092
  }
8093
8093
  async getBlob(e) {
8094
8094
  let t = this.blobs.get(e);
@@ -8108,22 +8108,22 @@ var kn = class e {
8108
8108
  async getStandaloneBlobs() {
8109
8109
  return [...this.blobs.values()].filter((e) => e.attachedTo.length === 0);
8110
8110
  }
8111
- async attachBlob(e, t) {
8111
+ async attachBlob(e, n) {
8112
8112
  this.guardWritable();
8113
- let n = this.blobs.get(e);
8114
- n || a("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, {
8115
- ...n,
8116
- attachedTo: [...n.attachedTo, t]
8113
+ let r = this.blobs.get(e);
8114
+ 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, {
8115
+ ...r,
8116
+ attachedTo: [...r.attachedTo, n]
8117
8117
  });
8118
8118
  }
8119
- async detachBlob(e, t) {
8119
+ async detachBlob(e, n) {
8120
8120
  this.guardWritable();
8121
- let n = this.blobs.get(e);
8122
- n || a("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8123
- let r = n.attachedTo.filter((e) => !(e.documentId === t.documentId && e.recordRef === t.recordRef));
8121
+ let r = this.blobs.get(e);
8122
+ r || t("STORE_BLOB_NOT_FOUND", { detail: `Blob "${e}" not found` });
8123
+ let i = r.attachedTo.filter((e) => !(e.documentId === n.documentId && e.recordRef === n.recordRef));
8124
8124
  this.blobs.set(e, {
8125
- ...n,
8126
- attachedTo: r
8125
+ ...r,
8126
+ attachedTo: i
8127
8127
  });
8128
8128
  }
8129
8129
  async removeBlob(e) {
@@ -8140,7 +8140,7 @@ var kn = class e {
8140
8140
  return n || (n = /* @__PURE__ */ new Map(), this.records.set(t, n)), n;
8141
8141
  }
8142
8142
  guardWritable() {
8143
- this.writable || a("STORE_NOT_WRITABLE", { detail: "In-memory store is read-only. Hydrate with a real document before writing." });
8143
+ this.writable || t("STORE_NOT_WRITABLE", { detail: "In-memory store is read-only. Hydrate with a real document before writing." });
8144
8144
  }
8145
8145
  };
8146
8146
  //#endregion
@@ -8154,10 +8154,10 @@ function An(e, t, n, r) {
8154
8154
  //#endregion
8155
8155
  //#region src/project/io/export-document.ts
8156
8156
  async function jn(e) {
8157
- let { documentId: t, state: n, configs: r, store: i, projectName: a, options: s } = e, c = n.documents.get(t);
8158
- o(c, {
8157
+ let { documentId: t, state: n, configs: r, store: i, projectName: o, options: s } = e, c = n.documents.get(t);
8158
+ a(c, {
8159
8159
  key: "DOCUMENT_NOT_REGISTERED",
8160
- detail: `Document "${t}" not registered in project "${a}"`
8160
+ detail: `Document "${t}" not registered in project "${o}"`
8161
8161
  });
8162
8162
  let l = r[c.record.configKey], u = et({
8163
8163
  records: await i.getByDocumentId(t),
@@ -8177,18 +8177,18 @@ async function jn(e) {
8177
8177
  //#region src/project/io/export-blob.ts
8178
8178
  async function Mn(e) {
8179
8179
  let { blobId: t, store: n, options: r } = e, i = await n.getBlob(t);
8180
- o(i, {
8180
+ a(i, {
8181
8181
  key: "BLOB_NOT_FOUND",
8182
8182
  detail: `Blob "${t}" not found in store`
8183
8183
  });
8184
- let a = i.entry.name;
8184
+ let o = i.entry.name;
8185
8185
  return r?.withDownload && await s({
8186
8186
  data: i.data,
8187
- filename: a
8187
+ filename: o
8188
8188
  }), {
8189
8189
  entry: i.entry,
8190
8190
  data: i.data,
8191
- filename: a
8191
+ filename: o
8192
8192
  };
8193
8193
  }
8194
8194
  //#endregion
@@ -8214,8 +8214,8 @@ function Pn(e, t) {
8214
8214
  //#endregion
8215
8215
  //#region src/project/io/import-document.ts
8216
8216
  async function Fn(e) {
8217
- let { file: t, store: n, configs: r, defaultConfigKey: i, options: a, hooks: s, perf: c } = e, l = a?.configKey ?? i, u = r[l];
8218
- o(u, {
8217
+ let { file: t, store: n, configs: r, defaultConfigKey: i, options: o, hooks: s, perf: c } = e, l = o?.configKey ?? i, u = r[l];
8218
+ a(u, {
8219
8219
  key: "UNKNOWN_CONFIG_KEY",
8220
8220
  detail: `Unknown configKey: "${l}". Available: ${Object.keys(r).join(", ")}`
8221
8221
  });
@@ -8225,7 +8225,7 @@ async function Fn(e) {
8225
8225
  extension: f,
8226
8226
  configKey: l,
8227
8227
  createdAt: Date.now(),
8228
- metadata: a?.metadata
8228
+ metadata: o?.metadata
8229
8229
  };
8230
8230
  await h(n, p);
8231
8231
  let { recordCount: m } = await kt({
@@ -8233,8 +8233,8 @@ async function Fn(e) {
8233
8233
  documentId: d,
8234
8234
  store: n,
8235
8235
  config: u,
8236
- useCustomRecordsIds: a?.useCustomRecordsIds,
8237
- chunkOptions: a?.chunkOptions,
8236
+ useCustomRecordsIds: o?.useCustomRecordsIds,
8237
+ chunkOptions: o?.chunkOptions,
8238
8238
  hooks: s,
8239
8239
  perf: c
8240
8240
  });
@@ -8256,8 +8256,8 @@ async function Fn(e) {
8256
8256
  //#endregion
8257
8257
  //#region src/project/io/init-empty-document.ts
8258
8258
  async function In(e) {
8259
- let { store: t, configs: n, defaultConfigKey: r, options: i, hooks: a } = e, s = i?.configKey ?? r, c = n[s];
8260
- o(c, {
8259
+ let { store: t, configs: n, defaultConfigKey: r, options: i, hooks: o } = e, s = i?.configKey ?? r, c = n[s];
8260
+ a(c, {
8261
8261
  key: "UNKNOWN_CONFIG_KEY",
8262
8262
  detail: `Unknown configKey: "${s}". Available: ${Object.keys(n).join(", ")}`
8263
8263
  });
@@ -8272,7 +8272,7 @@ async function In(e) {
8272
8272
  await t.registerDocument(p);
8273
8273
  let m = f({
8274
8274
  dialecteConfig: c,
8275
- hooks: a,
8275
+ hooks: o,
8276
8276
  record: {
8277
8277
  id: crypto.randomUUID(),
8278
8278
  tagName: c.rootElementName,
@@ -8291,19 +8291,19 @@ async function In(e) {
8291
8291
  //#region src/project/project.ts
8292
8292
  var Ln = class {
8293
8293
  get name() {
8294
- return o(this._name !== void 0, {
8294
+ return a(this._name !== void 0, {
8295
8295
  key: "PROJECT_NOT_OPENED",
8296
8296
  detail: "Call project.open(name) before accessing project properties."
8297
8297
  }), this._name;
8298
8298
  }
8299
8299
  get store() {
8300
- return o(this._store !== void 0, {
8300
+ return a(this._store !== void 0, {
8301
8301
  key: "PROJECT_NOT_OPENED",
8302
8302
  detail: "Call project.open(name) before accessing project properties."
8303
8303
  }), this._store;
8304
8304
  }
8305
8305
  get channel() {
8306
- return o(this._channel !== void 0, {
8306
+ return a(this._channel !== void 0, {
8307
8307
  key: "PROJECT_NOT_OPENED",
8308
8308
  detail: "Call project.open(name) before accessing project properties."
8309
8309
  }), this._channel;
@@ -8438,7 +8438,7 @@ var Ln = class {
8438
8438
  }
8439
8439
  openDocument(e) {
8440
8440
  let t = this.state.documents.get(e);
8441
- o(t, {
8441
+ a(t, {
8442
8442
  key: "DOCUMENT_NOT_REGISTERED",
8443
8443
  detail: `Document "${e}" not registered in project "${this.name}"`
8444
8444
  });
@@ -8467,7 +8467,7 @@ var Ln = class {
8467
8467
  }
8468
8468
  async undo(e) {
8469
8469
  let t = this.state.documents.get(e);
8470
- o(t, {
8470
+ a(t, {
8471
8471
  key: "DOCUMENT_NOT_REGISTERED",
8472
8472
  detail: `Document "${e}" not registered in project "${this.name}"`
8473
8473
  }), await this.store.undo(e);
@@ -8480,7 +8480,7 @@ var Ln = class {
8480
8480
  }
8481
8481
  async redo(e) {
8482
8482
  let t = this.state.documents.get(e);
8483
- o(t, {
8483
+ a(t, {
8484
8484
  key: "DOCUMENT_NOT_REGISTERED",
8485
8485
  detail: `Document "${e}" not registered in project "${this.name}"`
8486
8486
  }), await this.store.redo(e);