@dialecte/core 0.1.6 → 0.1.7

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as s, a, Q as r, T as i, b as o, c as l, d, f as c, g as u, h as b, e as n, j as A, k as g, l as m, m as D, n as R, p, q as T, r as f, s as E, t as x, u as F, v as h, w as k, y as B, z as C, i as _, A as y, B as I, C as O, o as j } from "./index-Cl4q6wr5.js";
2
- import { E as U, t as X } from "./index-CqwLClK7.js";
1
+ import { D as s, a, Q as r, T as i, b as o, c as l, d, f as c, g as u, h as b, e as n, j as A, k as g, l as m, m as D, n as R, p, q as T, r as f, s as E, t as x, u as F, v as h, w as k, y as B, z as C, i as _, A as y, B as I, C as O, o as j } from "./index-BcfPvtox.js";
2
+ import { E as U, t as X } from "./index-BCraeB5h.js";
3
3
  export {
4
4
  s as DexieStore,
5
5
  a as Document,
@@ -1,12 +1,32 @@
1
1
  import { TEST_DIALECTE_CONFIG } from './config';
2
- import { BaseTestCase, TestCases, ActParams, ActResult } from './run-test-cases.type';
2
+ import { BaseTestCase, BaseXmlTestCase, TestCases, ActParams, ActResult } from './run-test-cases.type';
3
3
  import { AnyDialecteConfig } from '../types';
4
4
  type TestDialecteConfig = typeof TEST_DIALECTE_CONFIG;
5
5
  export declare function createMockRandomUUID(): () => `${string}-${string}-${string}-${string}-${string}`;
6
- export declare function runTestCases<GenericTestCase extends BaseTestCase, GenericConfig extends AnyDialecteConfig = TestDialecteConfig>(params: {
6
+ export declare function runXmlTestCases<GenericTestCase extends BaseXmlTestCase, GenericConfig extends AnyDialecteConfig = TestDialecteConfig>(params: {
7
7
  testCases: TestCases<GenericTestCase>;
8
8
  act: (params: ActParams<GenericConfig, GenericTestCase>) => Promise<ActResult>;
9
9
  dialecteConfig?: GenericConfig;
10
10
  }): void;
11
+ export declare function runXmlTestCases<GenericTestCase extends BaseXmlTestCase, GenericConfig extends AnyDialecteConfig = TestDialecteConfig>(params: {
12
+ testCases: TestCases<GenericTestCase>;
13
+ act: (params: ActParams<GenericConfig, GenericTestCase>) => Promise<void>;
14
+ dialecteConfig?: GenericConfig;
15
+ }): void;
16
+ /**
17
+ * Runs a record of synchronous test cases where each key is the test description.
18
+ * Use for pure-function table-driven tests that need no XML or async setup.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * runTestCases<{ input: number; expected: number }>({
23
+ * 'positive → doubled': { input: 2, expected: 4 },
24
+ * 'zero → zero': { input: 0, expected: 0 },
25
+ * }, ({ input, expected }) => {
26
+ * expect(double(input)).toBe(expected)
27
+ * })
28
+ * ```
29
+ */
30
+ export declare function runTestCases<GenericTestCase extends BaseTestCase>(testCases: Record<string, GenericTestCase>, act: (testCase: GenericTestCase) => void): void;
11
31
  export {};
12
32
  //# sourceMappingURL=run-test-cases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-test-cases.d.ts","sourceRoot":"","sources":["../../src/test/run-test-cases.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAO/C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAC1F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,KAAK,kBAAkB,GAAG,OAAO,oBAAoB,CAAA;AAMrD,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAKhG;AAID,wBAAgB,YAAY,CAC3B,eAAe,SAAS,YAAY,EACpC,aAAa,SAAS,iBAAiB,GAAG,kBAAkB,EAC3D,MAAM,EAAE;IACT,SAAS,EAAE,SAAS,CAAC,eAAe,CAAC,CAAA;IACrC,GAAG,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,aAAa,EAAE,eAAe,CAAC,KAAK,OAAO,CA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Ae,SAAS,YAAY,EAChE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAC1C,GAAG,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,GACtC,IAAI,CAKN"}
@@ -1,18 +1,20 @@
1
1
  import { Document } from '../document';
2
2
  import { AnyDialecteConfig } from '../types';
3
3
  export type BaseTestCase = {
4
+ only?: boolean;
5
+ };
6
+ export type BaseXmlTestCase = BaseTestCase & {
4
7
  sourceXml: string;
5
8
  targetXml?: string;
6
- only?: boolean;
7
9
  expectedQueries?: string[];
8
10
  unexpectedQueries?: string[];
9
11
  };
10
- export type TestCases<GenericTestCase extends BaseTestCase> = Record<string, GenericTestCase>;
12
+ export type TestCases<GenericTestCase extends BaseXmlTestCase> = Record<string, GenericTestCase>;
11
13
  export type TestContext<GenericConfig extends AnyDialecteConfig> = {
12
14
  document: Document<GenericConfig>;
13
15
  databaseName: string;
14
16
  };
15
- export type ActParams<GenericConfig extends AnyDialecteConfig, GenericTestCase extends BaseTestCase> = {
17
+ export type ActParams<GenericConfig extends AnyDialecteConfig, GenericTestCase extends BaseXmlTestCase> = {
16
18
  testCase: GenericTestCase;
17
19
  source: TestContext<GenericConfig>;
18
20
  target?: TestContext<GenericConfig>;
@@ -1 +1 @@
1
- {"version":3,"file":"run-test-cases.type.d.ts","sourceRoot":"","sources":["../../src/test/run-test-cases.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,MAAM,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B,CAAA;AAED,M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AE,QAAQ,CAAC,aAAa,CAAC,CAAA;IACjC,YAAY,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,SAAS,CACpB,aAAa,SAAS,iBAAiB,EACvC,eAAe,SAAS,eAAe,IACpC;IACH,QAAQ,EAAE,eAAe,CAAA;IACzB,MAAM,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACvB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA"}
package/dist/test.js CHANGED
@@ -1,153 +1,153 @@
1
- import { expect as l, it as x } from "vitest";
2
- import { x as E, D as b, i as X, o as q, e as f } from "./index-Cl4q6wr5.js";
3
- import { D as S, s as D, l as L, k as T } from "./standardizing-27Zk5ECm.js";
4
- function h(a) {
5
- const e = w(a);
1
+ import { expect as o, it as d } from "vitest";
2
+ import { x as b, D as X, i as q, o as S, e as v } from "./index-BcfPvtox.js";
3
+ import { DIALECTE_DEV_NAMESPACE as D, standardizeRecord as T, toTreeRecord as L, toTrackedRecord as w } from "./helpers.js";
4
+ function E(a) {
5
+ const e = O(a);
6
6
  if (e.length === 0)
7
7
  return [a];
8
8
  const t = [];
9
- for (const A of e)
10
- t.push(a.slice(0, A));
9
+ for (const B of e)
10
+ t.push(a.slice(0, B));
11
11
  return t.push(a), t;
12
12
  }
13
- function w(a) {
13
+ function O(a) {
14
14
  const e = [];
15
- let t = 0, A = 0, B = null;
16
- for (let r = 0; r < a.length; r++) {
17
- const _ = a[r];
18
- if (B) {
19
- _ === B && (B = null);
15
+ let t = 0, B = 0, A = null;
16
+ for (let _ = 0; _ < a.length; _++) {
17
+ const r = a[_];
18
+ if (A) {
19
+ r === A && (A = null);
20
20
  continue;
21
21
  }
22
- if (_ === '"' || _ === "'") {
23
- B = _;
22
+ if (r === '"' || r === "'") {
23
+ A = r;
24
24
  continue;
25
25
  }
26
- if (_ === "[") {
26
+ if (r === "[") {
27
27
  t++;
28
28
  continue;
29
29
  }
30
- if (_ === "]") {
30
+ if (r === "]") {
31
31
  t--;
32
32
  continue;
33
33
  }
34
- if (_ === "(") {
35
- A++;
34
+ if (r === "(") {
35
+ B++;
36
36
  continue;
37
37
  }
38
- if (_ === ")") {
39
- A--;
38
+ if (r === ")") {
39
+ B--;
40
40
  continue;
41
41
  }
42
- if (!(t > 0 || A > 0) && _ === "/") {
43
- if (r === 0) {
44
- a[r + 1] === "/" && r++;
42
+ if (!(t > 0 || B > 0) && r === "/") {
43
+ if (_ === 0) {
44
+ a[_ + 1] === "/" && _++;
45
45
  continue;
46
46
  }
47
- if (e.length === 0 && r === 1 && a[0] === "/")
47
+ if (e.length === 0 && _ === 1 && a[0] === "/")
48
48
  continue;
49
- e.push(r), a[r + 1] === "/" && r++;
49
+ e.push(_), a[_ + 1] === "/" && _++;
50
50
  }
51
51
  }
52
52
  return e;
53
53
  }
54
- function O(a) {
55
- const { namespaces: e } = a, t = g(e);
54
+ function g(a) {
55
+ const { namespaces: e } = a, t = R(e);
56
56
  return {
57
- assertExpectedElementQueries(A) {
58
- M({ ...A, nsResolver: t });
57
+ assertExpectedElementQueries(B) {
58
+ M({ ...B, nsResolver: t });
59
59
  },
60
- assertUnexpectedElementQueries(A) {
61
- k({ ...A, nsResolver: t });
60
+ assertUnexpectedElementQueries(B) {
61
+ k({ ...B, nsResolver: t });
62
62
  }
63
63
  };
64
64
  }
65
65
  function M(a) {
66
- const { xmlDocument: e, queries: t, nsResolver: A } = a;
67
- for (const B of t)
68
- R({ xmlDocument: e, xpath: B, nsResolver: A });
66
+ const { xmlDocument: e, queries: t, nsResolver: B } = a;
67
+ for (const A of t)
68
+ V({ xmlDocument: e, xpath: A, nsResolver: B });
69
69
  }
70
- function g(a) {
70
+ function R(a) {
71
71
  return (e) => e ? a[e]?.uri ?? null : null;
72
72
  }
73
73
  function k(a) {
74
- const { xmlDocument: e, queries: t, nsResolver: A } = a;
75
- for (const B of t)
76
- V({ xmlDocument: e, xpath: B, nsResolver: A });
74
+ const { xmlDocument: e, queries: t, nsResolver: B } = a;
75
+ for (const A of t)
76
+ F({ xmlDocument: e, xpath: A, nsResolver: B });
77
77
  }
78
- function R(a) {
79
- const { xmlDocument: e, xpath: t, nsResolver: A } = a, B = h(t);
80
- let r = null, _ = 0;
81
- for (let C = 0; C < B.length; C++) {
82
- const s = B[C], c = e.evaluate(
78
+ function V(a) {
79
+ const { xmlDocument: e, xpath: t, nsResolver: B } = a, A = E(t);
80
+ let _ = null, r = 0;
81
+ for (let C = 0; C < A.length; C++) {
82
+ const s = A[C], c = e.evaluate(
83
83
  s,
84
84
  e,
85
- A ?? null,
85
+ B ?? null,
86
86
  XPathResult.FIRST_ORDERED_NODE_TYPE,
87
87
  null
88
88
  ).singleNodeValue;
89
89
  if (c) {
90
- r = c, _ = C + 1;
90
+ _ = c, r = C + 1;
91
91
  continue;
92
92
  }
93
- const i = C === 0 ? B[0] : t.slice(B[C - 1].length), n = _ === 0 ? `[No parent matched — failed from document root]
93
+ const u = C === 0 ? A[0] : t.slice(A[C - 1].length), i = r === 0 ? `[No parent matched — failed from document root]
94
94
  Document:
95
- ${d({ xml: new XMLSerializer().serializeToString(e) })}` : `[Last match at step ${_}/${B.length}]:
96
- ${r ? d({ xml: r.outerHTML }) : "(none)"}`;
97
- l(
95
+ ${l({ xml: new XMLSerializer().serializeToString(e) })}` : `[Last match at step ${r}/${A.length}]:
96
+ ${_ ? l({ xml: _.outerHTML }) : "(none)"}`;
97
+ o(
98
98
  c,
99
99
  `Element not found in XML.
100
- Failed at step ${C + 1}/${B.length}: ${i.trim()}
100
+ Failed at step ${C + 1}/${A.length}: ${u.trim()}
101
101
  Full XPath: ${t}
102
- ${n}`
102
+ ${i}`
103
103
  ).toBeTruthy();
104
104
  return;
105
105
  }
106
106
  }
107
- function d(a) {
107
+ function l(a) {
108
108
  const { xml: e } = a;
109
109
  try {
110
- return E(e, { indentation: " ", collapseContent: !0 });
110
+ return b(e, { indentation: " ", collapseContent: !0 });
111
111
  } catch {
112
112
  return e;
113
113
  }
114
114
  }
115
- function V(a) {
116
- const { xmlDocument: e, xpath: t, nsResolver: A } = a, B = h(t);
117
- if (B.length > 1) {
115
+ function F(a) {
116
+ const { xmlDocument: e, xpath: t, nsResolver: B } = a, A = E(t);
117
+ if (A.length > 1) {
118
118
  let C = null;
119
- for (let s = 0; s < B.length - 1; s++) {
120
- const u = B[s], i = e.evaluate(
121
- u,
119
+ for (let s = 0; s < A.length - 1; s++) {
120
+ const n = A[s], u = e.evaluate(
121
+ n,
122
122
  e,
123
- A ?? null,
123
+ B ?? null,
124
124
  XPathResult.FIRST_ORDERED_NODE_TYPE,
125
125
  null
126
- ).singleNodeValue, n = s === 0 ? B[0] : t.slice(B[s - 1].length), v = s === 0 ? "[Document root — no parent context]" : `[Parent element found at step ${s}]:
127
- ${C ? d({ xml: C.outerHTML }) : "(none)"}`;
128
- l(
129
- i,
126
+ ).singleNodeValue, i = s === 0 ? A[0] : t.slice(A[s - 1].length), m = s === 0 ? "[Document root — no parent context]" : `[Parent element found at step ${s}]:
127
+ ${C ? l({ xml: C.outerHTML }) : "(none)"}`;
128
+ o(
129
+ u,
130
130
  `Absent assertion is unreliable: ancestor step does not exist.
131
131
  The query passes but for the wrong reason — an ancestor is missing, not the target element.
132
- Missing at step ${s + 1}/${B.length}: ${n.trim()}
132
+ Missing at step ${s + 1}/${A.length}: ${i.trim()}
133
133
  Full XPath: ${t}
134
- ${v}`
135
- ).toBeTruthy(), C = i;
134
+ ${m}`
135
+ ).toBeTruthy(), C = u;
136
136
  }
137
137
  }
138
- const _ = e.evaluate(
138
+ const r = e.evaluate(
139
139
  t,
140
140
  e,
141
- A ?? null,
141
+ B ?? null,
142
142
  XPathResult.FIRST_ORDERED_NODE_TYPE,
143
143
  null
144
144
  ).singleNodeValue;
145
- l(
146
- _,
145
+ o(
146
+ r,
147
147
  `Element should NOT exist in XML but was found.
148
148
  XPath: ${t}
149
149
  Found:
150
- ${_ ? d({ xml: _.outerHTML }) : "(none)"}`
150
+ ${r ? l({ xml: r.outerHTML }) : "(none)"}`
151
151
  ).toBeFalsy();
152
152
  }
153
153
  const p = {
@@ -155,12 +155,12 @@ const p = {
155
155
  uri: "http://dialecte.dev/XML/DEFAULT",
156
156
  prefix: ""
157
157
  },
158
- dev: S,
158
+ dev: D,
159
159
  ext: {
160
160
  uri: "http://dialecte.dev/XML/DEV-EXT",
161
161
  prefix: "ext"
162
162
  }
163
- }, ee = `xmlns="${p.default.uri}"`, te = `xmlns:${p.dev.prefix}="${p.dev.uri}"`, ae = `xmlns:${p.ext.prefix}="${p.ext.uri}"`, F = [
163
+ }, te = `xmlns="${p.default.uri}"`, ae = `xmlns:${p.dev.prefix}="${p.dev.uri}"`, Be = `xmlns:${p.ext.prefix}="${p.ext.uri}"`, N = [
164
164
  "A",
165
165
  "AAAA_1",
166
166
  "AAAA_2",
@@ -192,7 +192,7 @@ const p = {
192
192
  "CC_2",
193
193
  "CC_3",
194
194
  "Root"
195
- ], N = {
195
+ ], U = {
196
196
  A: ["AA_1", "AA_2", "AA_3"],
197
197
  AAAA_1: [],
198
198
  AAAA_2: [],
@@ -224,7 +224,7 @@ const p = {
224
224
  CC_2: ["CCC_1", "CCC_2", "CCC_3"],
225
225
  CC_3: ["CCC_1", "CCC_2", "CCC_3"],
226
226
  Root: ["A", "B", "C"]
227
- }, U = {
227
+ }, y = {
228
228
  A: ["Root"],
229
229
  AAAA_1: ["AAA_1", "AAA_2", "AAA_3"],
230
230
  AAAA_2: ["AAA_1", "AAA_2", "AAA_3"],
@@ -256,7 +256,7 @@ const p = {
256
256
  CC_2: ["C"],
257
257
  CC_3: ["C"],
258
258
  Root: []
259
- }, y = {
259
+ }, I = {
260
260
  A: ["AAAA_1", "AAAA_2", "AAAA_3", "AAA_1", "AAA_2", "AAA_3", "AA_1", "AA_2", "AA_3"],
261
261
  AAAA_1: [],
262
262
  AAAA_2: [],
@@ -319,7 +319,7 @@ const p = {
319
319
  "CC_2",
320
320
  "CC_3"
321
321
  ]
322
- }, I = {
322
+ }, $ = {
323
323
  A: ["Root"],
324
324
  AAAA_1: ["A", "AAA_1", "AAA_2", "AAA_3", "AA_1", "AA_2", "AA_3", "Root"],
325
325
  AAAA_2: ["A", "AAA_1", "AAA_2", "AAA_3", "AA_1", "AA_2", "AA_3", "Root"],
@@ -351,7 +351,7 @@ const p = {
351
351
  CC_2: ["C", "Root"],
352
352
  CC_3: ["C", "Root"],
353
353
  Root: []
354
- }, $ = "Root", P = ["A", "AA_1", "B", "BB_1", "C", "CC_1", "CC_2", "Root"], Q = {
354
+ }, P = "Root", Q = ["A", "AA_1", "B", "BB_1", "C", "CC_1", "CC_2", "Root"], z = {
355
355
  A: {
356
356
  aA: "",
357
357
  bA: "",
@@ -506,7 +506,7 @@ const p = {
506
506
  "ext:root": "",
507
507
  root: ""
508
508
  }
509
- }, z = {
509
+ }, G = {
510
510
  A: {
511
511
  tag: "A",
512
512
  namespace: { prefix: "", uri: "http://dialecte.dev/XML/DEFAULT" },
@@ -1508,49 +1508,49 @@ const p = {
1508
1508
  }
1509
1509
  ]
1510
1510
  }
1511
- }, G = {
1512
- supportedFileExtensions: [".xml"]
1513
1511
  }, H = {
1512
+ supportedFileExtensions: [".xml"]
1513
+ }, Y = {
1514
1514
  tables: {
1515
1515
  xmlElements: {
1516
1516
  name: "xmlElements",
1517
1517
  schema: "id, tagName, [id+tagName], parent.id, parent.tagName, *children.id, *children.tagName"
1518
1518
  }
1519
1519
  }
1520
- }, o = {
1521
- rootElementName: $,
1522
- singletonElements: P,
1523
- elements: F,
1520
+ }, x = {
1521
+ rootElementName: P,
1522
+ singletonElements: Q,
1523
+ elements: N,
1524
1524
  namespaces: p,
1525
- attributes: Q,
1526
- children: N,
1527
- parents: U,
1528
- descendants: y,
1529
- ancestors: I,
1530
- database: H,
1531
- io: G,
1532
- definition: z,
1525
+ attributes: z,
1526
+ children: U,
1527
+ parents: y,
1528
+ descendants: I,
1529
+ ancestors: $,
1530
+ database: Y,
1531
+ io: H,
1532
+ definition: G,
1533
1533
  hooks: {}
1534
1534
  };
1535
- async function m(a) {
1536
- const { xmlString: e, dialecteConfig: t = o } = a, A = `test-${crypto.randomUUID()}.xml`, B = new File([e], A, { type: "text/xml" }), _ = (await X({
1537
- files: [B],
1535
+ async function h(a) {
1536
+ const { xmlString: e, dialecteConfig: t = x } = a, B = `test-${crypto.randomUUID()}.xml`, A = new File([e], B, { type: "text/xml" }), r = (await q({
1537
+ files: [A],
1538
1538
  dialecteConfig: t,
1539
1539
  useCustomRecordsIds: !0
1540
- }))[0], C = q({
1540
+ }))[0], C = S({
1541
1541
  config: t,
1542
- storage: { type: "local", databaseName: _ }
1542
+ storage: { type: "local", databaseName: r }
1543
1543
  });
1544
1544
  return {
1545
1545
  document: C,
1546
- databaseName: _,
1546
+ databaseName: r,
1547
1547
  exportCurrentTest: async (c) => {
1548
- const { extension: i = t.io.supportedFileExtensions[0], withDatabaseIds: n = !1 } = c || {};
1549
- return f({
1548
+ const { extension: u = t.io.supportedFileExtensions[0], withDatabaseIds: i = !1 } = c || {};
1549
+ return v({
1550
1550
  dialecteConfig: t,
1551
- databaseName: _,
1552
- extension: i,
1553
- withDatabaseIds: n
1551
+ databaseName: r,
1552
+ extension: u,
1553
+ withDatabaseIds: i
1554
1554
  });
1555
1555
  },
1556
1556
  cleanup: async () => {
@@ -1558,87 +1558,99 @@ async function m(a) {
1558
1558
  }
1559
1559
  };
1560
1560
  }
1561
- function Be(a) {
1561
+ function Ae(a) {
1562
1562
  const { databaseName: e, dialecteConfig: t } = a;
1563
1563
  return {
1564
- store: new b(e, t),
1564
+ store: new X(e, t),
1565
1565
  recordCache: /* @__PURE__ */ new Map(),
1566
1566
  stagedOperations: []
1567
1567
  };
1568
1568
  }
1569
- const Y = crypto.randomUUID.bind(crypto);
1570
- function j() {
1569
+ const j = crypto.randomUUID.bind(crypto);
1570
+ function Z() {
1571
1571
  let a = 0;
1572
1572
  return function() {
1573
1573
  return `${a++}`;
1574
1574
  };
1575
1575
  }
1576
- function Ae(a) {
1576
+ function Ce(a) {
1577
1577
  const {
1578
1578
  testCases: e,
1579
1579
  act: t,
1580
- dialecteConfig: A = o
1581
- } = a, { assertExpectedElementQueries: B, assertUnexpectedElementQueries: r } = O({
1582
- namespaces: A.namespaces
1580
+ dialecteConfig: B = x
1581
+ } = a, { assertExpectedElementQueries: A, assertUnexpectedElementQueries: _ } = g({
1582
+ namespaces: B.namespaces
1583
1583
  });
1584
- for (const [_, C] of Object.entries(e))
1585
- (C.only ? x.only : x)(_, async () => {
1586
- crypto.randomUUID = Y;
1587
- const u = await m({
1584
+ for (const [r, C] of Object.entries(e))
1585
+ (C.only ? d.only : d)(r, async () => {
1586
+ crypto.randomUUID = j;
1587
+ const n = await h({
1588
1588
  xmlString: C.sourceXml,
1589
- dialecteConfig: A
1590
- }), c = C.targetXml ? await m({ xmlString: C.targetXml, dialecteConfig: A }) : void 0;
1589
+ dialecteConfig: B
1590
+ }), c = C.targetXml ? await h({ xmlString: C.targetXml, dialecteConfig: B }) : void 0;
1591
1591
  try {
1592
- crypto.randomUUID = j();
1593
- const { assertDatabaseName: i } = await t({
1592
+ crypto.randomUUID = Z();
1593
+ const i = (await t({
1594
1594
  testCase: C,
1595
- source: { document: u.document, databaseName: u.databaseName },
1595
+ source: { document: n.document, databaseName: n.databaseName },
1596
1596
  target: c ? { document: c.document, databaseName: c.databaseName } : void 0
1597
- }), { xmlDocument: n } = await f({
1598
- dialecteConfig: A,
1599
- databaseName: i,
1600
- extension: A.io.supportedFileExtensions[0],
1601
- withDatabaseIds: !0
1602
- });
1603
- C.expectedQueries?.length && B({ xmlDocument: n, queries: C.expectedQueries }), C.unexpectedQueries?.length && r({ xmlDocument: n, queries: C.unexpectedQueries });
1597
+ }))?.assertDatabaseName;
1598
+ if (C.expectedQueries?.length || C.unexpectedQueries?.length) {
1599
+ if (!i)
1600
+ throw new Error(
1601
+ `Test "${r}": assertDatabaseName is required when expectedQueries or unexpectedQueries are defined`
1602
+ );
1603
+ const { xmlDocument: f } = await v({
1604
+ dialecteConfig: B,
1605
+ databaseName: i,
1606
+ extension: B.io.supportedFileExtensions[0],
1607
+ withDatabaseIds: !0
1608
+ });
1609
+ C.expectedQueries?.length && A({ xmlDocument: f, queries: C.expectedQueries }), C.unexpectedQueries?.length && _({ xmlDocument: f, queries: C.unexpectedQueries });
1610
+ }
1604
1611
  } finally {
1605
- await u.cleanup(), await c?.cleanup();
1612
+ await n.cleanup(), await c?.cleanup();
1606
1613
  }
1607
1614
  });
1608
1615
  }
1609
- function Z(a) {
1616
+ function re(a, e) {
1617
+ for (const [t, B] of Object.entries(a))
1618
+ (B.only ? d.only : d)(t, () => e(B));
1619
+ }
1620
+ function J(a) {
1610
1621
  function e(t) {
1611
- const { record: A, type: B = "raw" } = t, r = D({ record: A, dialecteConfig: a });
1612
- switch (B) {
1622
+ const { record: B, type: A = "raw" } = t, _ = T({ record: B, dialecteConfig: a });
1623
+ switch (A) {
1613
1624
  case "raw":
1614
- return r;
1625
+ return _;
1615
1626
  case "tracked":
1616
- return T({ record: r });
1627
+ return w({ record: _ });
1617
1628
  case "tree":
1618
- return L({ record: r });
1629
+ return L({ record: _ });
1619
1630
  default:
1620
- throw new Error(`Unsupported record type: ${B}`);
1631
+ throw new Error(`Unsupported record type: ${A}`);
1621
1632
  }
1622
1633
  }
1623
1634
  return e;
1624
1635
  }
1625
- const Ce = Z(o);
1636
+ const _e = J(x);
1626
1637
  export {
1627
- H as DATABASE_CONFIG,
1638
+ Y as DATABASE_CONFIG,
1628
1639
  p as DIALECTE_NAMESPACES,
1629
- G as IO_CONFIG,
1630
- o as TEST_DIALECTE_CONFIG,
1631
- ee as XMLNS_DEFAULT_NAMESPACE,
1632
- te as XMLNS_DEV_NAMESPACE,
1633
- ae as XMLNS_EXT_NAMESPACE,
1640
+ H as IO_CONFIG,
1641
+ x as TEST_DIALECTE_CONFIG,
1642
+ te as XMLNS_DEFAULT_NAMESPACE,
1643
+ ae as XMLNS_DEV_NAMESPACE,
1644
+ Be as XMLNS_EXT_NAMESPACE,
1634
1645
  M as assertExpectedElementQueries,
1635
1646
  k as assertUnexpectedElementQueries,
1636
- j as createMockRandomUUID,
1637
- Be as createTestContext,
1638
- m as createTestDialecte,
1639
- Ce as createTestRecord,
1640
- Z as createTestRecordFactory,
1641
- O as createXmlAssertions,
1642
- Ae as runTestCases,
1643
- h as splitXpathIntoSteps
1647
+ Z as createMockRandomUUID,
1648
+ Ae as createTestContext,
1649
+ h as createTestDialecte,
1650
+ _e as createTestRecord,
1651
+ J as createTestRecordFactory,
1652
+ g as createXmlAssertions,
1653
+ re as runTestCases,
1654
+ Ce as runXmlTestCases,
1655
+ E as splitXpathIntoSteps
1644
1656
  };
@@ -2,7 +2,7 @@ import { AnyDefinition } from './definition';
2
2
  import { ImportOptions, ExportOptions, IOHooks } from './io';
3
3
  import { Operation } from './operations';
4
4
  import { Namespace, RawRecord, TreeRecord } from './records';
5
- import { Context } from '../document';
5
+ import { Context, CloneMapping } from '../document';
6
6
  export type RawDialecteConfig<GenericElementNames extends readonly string[], GenericRootElement extends GenericElementNames[number], GenericAttributes extends Record<string, any>, GenericChildren extends Record<string, readonly string[]>, GenericParents extends Record<string, readonly string[]>, GenericDescendants extends Record<string, readonly string[]>, GenericAncestors extends Record<string, readonly string[]>> = {
7
7
  rootElementName: GenericRootElement;
8
8
  singletonElements?: readonly GenericElementNames[number][];
@@ -51,6 +51,34 @@ export type TransactionHooks = {
51
51
  parentRecord: RawRecord<GenericConfig, GenericParentElement>;
52
52
  context: Context<GenericConfig>;
53
53
  }) => Promise<Operation<GenericConfig>[]>;
54
+ /**
55
+ * Called after deepClone completes all recursive cloning.
56
+ * Receives the full source→target mapping. Return additional operations to stage
57
+ */
58
+ afterDeepClone?: <GenericConfig extends AnyDialecteConfig>(params: {
59
+ mappings: CloneMapping<GenericConfig>[];
60
+ context: Context<GenericConfig>;
61
+ }) => Promise<Operation<GenericConfig>[]>;
62
+ /**
63
+ * Called after a record is updated (attributes or value changed).
64
+ * Return additional operations to stage (e.g., update path attrs on dependent refs).
65
+ */
66
+ afterUpdated?: <GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(params: {
67
+ oldRecord: RawRecord<GenericConfig, GenericElement>;
68
+ newRecord: RawRecord<GenericConfig, GenericElement>;
69
+ context: Context<GenericConfig>;
70
+ }) => Promise<Operation<GenericConfig>[]>;
71
+ /**
72
+ * Called before a record and its subtree are staged for deletion.
73
+ * Root and all descendants are still live in context at this point.
74
+ *
75
+ * Return additional operations to stage (e.g., clear or delete ref elements
76
+ * pointing to this record or any of its descendants).
77
+ */
78
+ beforeDelete?: <GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(params: {
79
+ record: RawRecord<GenericConfig, GenericElement>;
80
+ context: Context<GenericConfig>;
81
+ }) => Promise<Operation<GenericConfig>[]>;
54
82
  };
55
83
  export type DatabaseConfig = Readonly<{
56
84
  tables: {