@dialecte/core 0.4.15 → 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.
- package/bin/xmlfmt.mjs +40 -0
- package/dist/helpers.js +43 -43
- package/dist/index.js +2 -2
- package/dist/{project-FFHlnZpz.js → project-nvZv2ie8.js} +254 -254
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/normalize-uuids.d.ts +2 -0
- package/dist/test/normalize-uuids.d.ts.map +1 -0
- package/dist/test.js +32 -20
- package/dist/utils/format-xml.d.ts +25 -0
- package/dist/utils/format-xml.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/{utils-C5_11hqg.js → utils-BiEx1x59.js} +138 -4
- package/dist/utils.js +2 -2
- package/package.json +6 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
122
|
-
e !==
|
|
123
|
-
detail: `Expected tagName '${
|
|
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:
|
|
126
|
-
id:
|
|
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:
|
|
200
|
-
if (
|
|
199
|
+
let { context: n, ref: r } = e;
|
|
200
|
+
if (n.stagedOperations.log.length > 0) {
|
|
201
201
|
let e = oe({
|
|
202
|
-
stagedOperations:
|
|
203
|
-
tagName:
|
|
204
|
-
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
|
|
210
|
-
if (
|
|
211
|
-
let e = `__singleton_${
|
|
212
|
-
|
|
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(
|
|
215
|
-
e ? (
|
|
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 (
|
|
218
|
-
detail: `Expected tagName '${
|
|
219
|
-
ref:
|
|
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
|
-
...
|
|
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(
|
|
597
|
-
let { context:
|
|
598
|
-
context:
|
|
599
|
-
ref:
|
|
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 } =
|
|
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,
|
|
622
|
-
if (
|
|
623
|
-
let
|
|
624
|
-
return
|
|
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:
|
|
630
|
-
context:
|
|
631
|
-
ref:
|
|
632
|
-
}), l = c?.attributes ?? [], u = a === void 0 ? "" :
|
|
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(
|
|
653
|
-
let { context:
|
|
654
|
-
context:
|
|
655
|
-
ref:
|
|
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
|
|
659
|
-
for (let
|
|
660
|
-
if (
|
|
661
|
-
let
|
|
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:
|
|
664
|
+
attributeName: i,
|
|
665
665
|
defaults: a
|
|
666
666
|
});
|
|
667
|
-
if (
|
|
668
|
-
let { namespace: l } =
|
|
667
|
+
if (r === void 0) continue;
|
|
668
|
+
let { namespace: l } = e({
|
|
669
669
|
dialecteConfig: o,
|
|
670
670
|
tagName: s.tagName,
|
|
671
|
-
attributeName:
|
|
671
|
+
attributeName: i
|
|
672
672
|
});
|
|
673
673
|
c.push({
|
|
674
|
-
name:
|
|
675
|
-
value:
|
|
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:
|
|
800
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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 =
|
|
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
|
-
|
|
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
|
-
}),
|
|
1075
|
+
}), o;
|
|
1076
1076
|
for (let e of r.values()) if (e.tagName === t.dialecteConfig.rootElementName) {
|
|
1077
|
-
|
|
1077
|
+
o = e.id;
|
|
1078
1078
|
break;
|
|
1079
1079
|
}
|
|
1080
|
-
return o
|
|
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:
|
|
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])),
|
|
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
|
-
|
|
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 :
|
|
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, ...
|
|
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:
|
|
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
|
-
|
|
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:
|
|
1427
|
+
declareNamespaces: o
|
|
1428
1428
|
});
|
|
1429
|
-
return
|
|
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:
|
|
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:
|
|
1449
|
+
declareNamespaces: o
|
|
1450
1450
|
}), f;
|
|
1451
1451
|
}
|
|
1452
1452
|
function tt(e) {
|
|
1453
|
-
let { index: t, config: n, withDatabaseIds: i, xmlDocument:
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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(
|
|
1528
|
-
let { config:
|
|
1529
|
-
for (let
|
|
1530
|
-
if (lt(
|
|
1531
|
-
if (!ct(
|
|
1532
|
-
|
|
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
|
|
1535
|
+
let i = o(e.name);
|
|
1536
1536
|
if (!c) {
|
|
1537
|
-
|
|
1537
|
+
r.setAttribute(`${e.namespace.prefix}:${i}`, String(e.value));
|
|
1538
1538
|
continue;
|
|
1539
1539
|
}
|
|
1540
|
-
|
|
1541
|
-
config:
|
|
1542
|
-
document:
|
|
1543
|
-
namespace:
|
|
1540
|
+
a || at({
|
|
1541
|
+
config: t,
|
|
1542
|
+
document: n,
|
|
1543
|
+
namespace: e.namespace,
|
|
1544
1544
|
isFragment: s
|
|
1545
|
-
}),
|
|
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(
|
|
1559
|
-
let { config:
|
|
1560
|
-
dialecteConfig:
|
|
1561
|
-
tagName:
|
|
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 :
|
|
1565
|
-
if (
|
|
1566
|
-
let
|
|
1567
|
-
dialecteConfig:
|
|
1568
|
-
tagName:
|
|
1569
|
-
attributeName:
|
|
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 (!(
|
|
1573
|
-
let e = `${
|
|
1574
|
-
|
|
1575
|
-
} else
|
|
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(
|
|
1579
|
-
let { config:
|
|
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 =
|
|
1582
|
-
if (l) for (let [
|
|
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:
|
|
1585
|
-
tagName:
|
|
1586
|
-
attributeName:
|
|
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
|
|
1591
|
-
(u.namespace ?
|
|
1592
|
-
config:
|
|
1593
|
-
document:
|
|
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
|
-
}),
|
|
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,
|
|
2437
|
-
let
|
|
2438
|
-
for (let e of
|
|
2439
|
-
let
|
|
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
|
-
|
|
2444
|
-
let t = e,
|
|
2445
|
-
if (!
|
|
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
|
-
|
|
2451
|
+
i[n] = {
|
|
2452
2452
|
namespace: t.uri,
|
|
2453
2453
|
attributes: a,
|
|
2454
2454
|
value: "",
|
|
2455
2455
|
children: []
|
|
2456
|
-
},
|
|
2457
|
-
},
|
|
2458
|
-
o &&
|
|
2459
|
-
},
|
|
2460
|
-
if (o === e && (o = null),
|
|
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
|
-
|
|
2463
|
+
a.write(e).close();
|
|
2464
2464
|
} catch (e) {
|
|
2465
|
-
e !== ft &&
|
|
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
|
|
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
|
|
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:
|
|
2738
|
-
if (
|
|
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 =
|
|
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
|
|
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
|
|
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:
|
|
3128
|
-
if (r && (s = m(r)), i && (c = m(i)),
|
|
3129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
3200
|
+
ref: o
|
|
3201
3201
|
});
|
|
3202
|
-
|
|
3202
|
+
a(h, {
|
|
3203
3203
|
detail: "Parent record not found",
|
|
3204
3204
|
key: "ELEMENT_NOT_FOUND",
|
|
3205
|
-
ref:
|
|
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(
|
|
3254
|
-
let { attributes: n, tagName: r } =
|
|
3255
|
-
if (!(!n || !Array.isArray(n))) for (let
|
|
3256
|
-
let { name: n, namespace: i } =
|
|
3257
|
-
n === "xmlns" || n.startsWith("xmlns:") || !n.includes(":") || typeof i == "object" && i?.prefix === n.slice(0, n.indexOf(":")) ||
|
|
3258
|
-
detail: `Attribute '${n}' on '${r}' is prefixed — pass a local name plus its namespace instead: { name: '${
|
|
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,
|
|
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
|
|
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
|
|
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:
|
|
3341
|
+
record: o,
|
|
3342
3342
|
query: r
|
|
3343
3343
|
})
|
|
3344
3344
|
}), await q({
|
|
3345
3345
|
context: n,
|
|
3346
|
-
record:
|
|
3346
|
+
record: o
|
|
3347
3347
|
}), Rt({
|
|
3348
3348
|
context: n,
|
|
3349
3349
|
status: "deleted",
|
|
3350
|
-
record:
|
|
3350
|
+
record: o
|
|
3351
3351
|
});
|
|
3352
3352
|
let s = await O({
|
|
3353
3353
|
context: n,
|
|
3354
|
-
ref: h(
|
|
3354
|
+
ref: h(o.parent)
|
|
3355
3355
|
});
|
|
3356
|
-
|
|
3357
|
-
detail: `Parent record not found (tagName=${
|
|
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 !==
|
|
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:
|
|
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:
|
|
3418
|
+
ref: o
|
|
3419
3419
|
});
|
|
3420
|
-
|
|
3421
|
-
detail: `Record not found (tagName=${
|
|
3420
|
+
a(d, {
|
|
3421
|
+
detail: `Record not found (tagName=${o.tagName}, id=${o.id})`,
|
|
3422
3422
|
key: "ELEMENT_NOT_FOUND",
|
|
3423
|
-
ref:
|
|
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,
|
|
3726
|
-
this.activeTransactions > 0 &&
|
|
3727
|
-
let
|
|
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
|
|
3730
|
-
return await
|
|
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
|
-
}),
|
|
3734
|
+
}), r.clearStagedOperations(), r.clearRecordCache(), this.state.history.push({
|
|
3735
3735
|
method: "commit",
|
|
3736
|
-
message:
|
|
3736
|
+
message: n?.label ?? "Changes committed",
|
|
3737
3737
|
timestamp: Date.now()
|
|
3738
|
-
}),
|
|
3738
|
+
}), t;
|
|
3739
3739
|
} catch (e) {
|
|
3740
|
-
throw this.state.error ??
|
|
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
|
-
|
|
3745
|
+
r.progress.forceClear(), this.activeTransactions--, this.state.loading = !1, this.signalStateChange(!0);
|
|
3746
3746
|
}
|
|
3747
3747
|
}
|
|
3748
|
-
async prepare(e,
|
|
3748
|
+
async prepare(e, n) {
|
|
3749
3749
|
this.activeTransactions++, this.state.loading = !0, this.state.error = null;
|
|
3750
|
-
let
|
|
3750
|
+
let r = this.createTransaction();
|
|
3751
3751
|
try {
|
|
3752
|
-
await e(this.withAllExtensions(
|
|
3752
|
+
await e(this.withAllExtensions(r));
|
|
3753
3753
|
} catch (e) {
|
|
3754
|
-
throw this.activeTransactions--, this.state.loading = !1, this.state.error ??
|
|
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
|
|
3761
|
-
creates:
|
|
3762
|
-
updates:
|
|
3763
|
-
deletes:
|
|
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:
|
|
3767
|
-
summary:
|
|
3768
|
-
query:
|
|
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
|
|
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
|
-
}),
|
|
3777
|
+
}), r.clearStagedOperations(), r.clearRecordCache(), this.state.history.push({
|
|
3778
3778
|
method: "commit",
|
|
3779
|
-
message:
|
|
3779
|
+
message: n?.label ?? "Changes committed",
|
|
3780
3780
|
timestamp: Date.now()
|
|
3781
3781
|
});
|
|
3782
3782
|
} catch (e) {
|
|
3783
|
-
throw this.state.error ??
|
|
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,
|
|
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:
|
|
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 =
|
|
7725
|
-
if (
|
|
7726
|
-
await s.bulkAdd(
|
|
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
|
-
|
|
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 (
|
|
7734
|
-
await s.bulkPut(
|
|
7733
|
+
if (i.length > 0) try {
|
|
7734
|
+
await s.bulkPut(i), l += i.length, o(l, c);
|
|
7735
7735
|
} catch (e) {
|
|
7736
|
-
|
|
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 (
|
|
7742
|
-
await s.bulkDelete(
|
|
7741
|
+
if (a.length > 0) try {
|
|
7742
|
+
await s.bulkDelete(a), l += a.length, o(l, c);
|
|
7743
7743
|
} catch (e) {
|
|
7744
|
-
|
|
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(
|
|
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:
|
|
7752
|
+
documentId: n,
|
|
7753
7753
|
sequenceNumber: p,
|
|
7754
7754
|
timestamp: Date.now(),
|
|
7755
7755
|
operations: {
|
|
7756
|
-
creates:
|
|
7757
|
-
updates:
|
|
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(
|
|
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
|
-
|
|
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,
|
|
7845
|
+
async attachBlob(e, n) {
|
|
7846
7846
|
await this.ensureCurrentSchema();
|
|
7847
|
-
let
|
|
7848
|
-
if (
|
|
7849
|
-
let
|
|
7850
|
-
await this.db.table(Z).update(e, { attachedTo:
|
|
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,
|
|
7852
|
+
async detachBlob(e, n) {
|
|
7853
7853
|
await this.ensureCurrentSchema();
|
|
7854
|
-
let
|
|
7855
|
-
|
|
7856
|
-
let
|
|
7857
|
-
await this.db.table(Z).update(e, { attachedTo:
|
|
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,
|
|
7940
|
-
e.has(
|
|
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,
|
|
8091
|
-
this.guardWritable(), this.documents.has(e.documentId) ||
|
|
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,
|
|
8111
|
+
async attachBlob(e, n) {
|
|
8112
8112
|
this.guardWritable();
|
|
8113
|
-
let
|
|
8114
|
-
|
|
8115
|
-
...
|
|
8116
|
-
attachedTo: [...
|
|
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,
|
|
8119
|
+
async detachBlob(e, n) {
|
|
8120
8120
|
this.guardWritable();
|
|
8121
|
-
let
|
|
8122
|
-
|
|
8123
|
-
let
|
|
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
|
-
...
|
|
8126
|
-
attachedTo:
|
|
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 ||
|
|
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:
|
|
8158
|
-
|
|
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 "${
|
|
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
|
-
|
|
8180
|
+
a(i, {
|
|
8181
8181
|
key: "BLOB_NOT_FOUND",
|
|
8182
8182
|
detail: `Blob "${t}" not found in store`
|
|
8183
8183
|
});
|
|
8184
|
-
let
|
|
8184
|
+
let o = i.entry.name;
|
|
8185
8185
|
return r?.withDownload && await s({
|
|
8186
8186
|
data: i.data,
|
|
8187
|
-
filename:
|
|
8187
|
+
filename: o
|
|
8188
8188
|
}), {
|
|
8189
8189
|
entry: i.entry,
|
|
8190
8190
|
data: i.data,
|
|
8191
|
-
filename:
|
|
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:
|
|
8218
|
-
|
|
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:
|
|
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:
|
|
8237
|
-
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:
|
|
8260
|
-
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|