@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.
@@ -2,6 +2,7 @@ export * from './assert-xml';
2
2
  export * from './config';
3
3
  export * from './constant';
4
4
  export * from './create-test-dialecte';
5
+ export * from './normalize-uuids';
5
6
  export * from './run-test-cases';
6
7
  export type * from './run-test-cases.type';
7
8
  export * from './test-record';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,mBAAmB,uBAAuB,CAAA;AAC1C,cAAc,eAAe,CAAA;AAC7B,mBAAmB,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,mBAAmB,uBAAuB,CAAA;AAC1C,cAAc,eAAe,CAAA;AAC7B,mBAAmB,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function normalizeUuids(text: string): string;
2
+ //# sourceMappingURL=normalize-uuids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-uuids.d.ts","sourceRoot":"","sources":["../../src/test/normalize-uuids.ts"],"names":[],"mappings":"AAYA,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASnD"}
package/dist/test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { N as e, V as t, ft as n, ht as r, pt as i, t as a, u as o } from "./project-FFHlnZpz.js";
1
+ import { N as e, V as t, ft as n, ht as r, pt as i, t as a, u as o } from "./project-nvZv2ie8.js";
2
2
  import { DIALECTE_NAMESPACES as s, standardizeRecord as c, toTrackedRecord as l, toTreeRecord as u } from "./helpers.js";
3
3
  import { expect as d, it as f } from "vitest";
4
4
  //#region src/test/assert-xml/xpath-parser.ts
@@ -2769,18 +2769,30 @@ async function B(t) {
2769
2769
  };
2770
2770
  }
2771
2771
  //#endregion
2772
+ //#region src/test/normalize-uuids.ts
2773
+ var V = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
2774
+ function H(e) {
2775
+ let t = /* @__PURE__ */ new Map();
2776
+ return e.replace(V, (e) => {
2777
+ let n = t.get(e);
2778
+ if (n) return n;
2779
+ let r = `uuid-${t.size + 1}`;
2780
+ return t.set(e, r), r;
2781
+ });
2782
+ }
2783
+ //#endregion
2772
2784
  //#region src/test/run-test-cases.ts
2773
- var V = crypto.randomUUID.bind(crypto);
2774
- function H() {
2785
+ var U = crypto.randomUUID.bind(crypto);
2786
+ function W() {
2775
2787
  let e = 0;
2776
2788
  return function() {
2777
2789
  return `${e++}`;
2778
2790
  };
2779
2791
  }
2780
- function U(e) {
2792
+ function G(e) {
2781
2793
  let { testCases: t, act: n, extensions: r, hooks: i, dialecteConfig: a = R } = e, { assertExpectedElementQueries: o, assertUnexpectedElementQueries: s } = g({ namespaces: a.namespaces });
2782
2794
  for (let [e, c] of Object.entries(t)) (c.only ? f.only : f)(e, async () => {
2783
- crypto.randomUUID = V;
2795
+ crypto.randomUUID = U;
2784
2796
  let { project: e, source: t, target: l } = await z({
2785
2797
  sourceXml: c.sourceXml,
2786
2798
  targetXml: c.targetXml,
@@ -2789,7 +2801,7 @@ function U(e) {
2789
2801
  hooks: i
2790
2802
  });
2791
2803
  try {
2792
- crypto.randomUUID = H();
2804
+ crypto.randomUUID = W();
2793
2805
  let r = await n({
2794
2806
  testCase: c,
2795
2807
  project: e,
@@ -2810,14 +2822,14 @@ function U(e) {
2810
2822
  queries: c.unexpectedQueries
2811
2823
  });
2812
2824
  } finally {
2813
- crypto.randomUUID = V, await e.destroy();
2825
+ crypto.randomUUID = U, await e.destroy();
2814
2826
  }
2815
2827
  });
2816
2828
  }
2817
- function W(e) {
2829
+ function K(e) {
2818
2830
  let { testCases: t, act: n, extensions: r, hooks: i, dialecteConfig: a = R } = e;
2819
2831
  for (let [e, o] of Object.entries(t)) (o.only ? f.only : f)(e, async () => {
2820
- crypto.randomUUID = V;
2832
+ crypto.randomUUID = U;
2821
2833
  let { project: e, source: t, target: s } = await z({
2822
2834
  sourceXml: o.sourceXml,
2823
2835
  targetXml: o.targetXml,
@@ -2826,42 +2838,42 @@ function W(e) {
2826
2838
  hooks: i
2827
2839
  });
2828
2840
  try {
2829
- crypto.randomUUID = H(), await n({
2841
+ crypto.randomUUID = W(), await n({
2830
2842
  testCase: o,
2831
2843
  project: e,
2832
2844
  source: t.document,
2833
2845
  target: s?.document
2834
2846
  });
2835
2847
  } finally {
2836
- crypto.randomUUID = V, await e.destroy();
2848
+ crypto.randomUUID = U, await e.destroy();
2837
2849
  }
2838
2850
  });
2839
2851
  }
2840
- function G(e, t) {
2852
+ function q(e, t) {
2841
2853
  for (let [n, r] of Object.entries(e)) (r.only ? f.only : f)(n, () => t(r));
2842
2854
  }
2843
- var K = q({ dialecteConfig: R });
2844
- function q(e) {
2855
+ var J = Y({ dialecteConfig: R });
2856
+ function Y(e) {
2845
2857
  let { dialecteConfig: t, hooks: n, extensions: r } = e;
2846
2858
  return {
2847
- withExport: (e) => U({
2859
+ withExport: (e) => G({
2848
2860
  dialecteConfig: t,
2849
2861
  extensions: r,
2850
2862
  hooks: n,
2851
2863
  ...e
2852
2864
  }),
2853
- withoutExport: (e) => W({
2865
+ withoutExport: (e) => K({
2854
2866
  dialecteConfig: t,
2855
2867
  extensions: r,
2856
2868
  hooks: n,
2857
2869
  ...e
2858
2870
  }),
2859
- generic: G
2871
+ generic: q
2860
2872
  };
2861
2873
  }
2862
2874
  //#endregion
2863
2875
  //#region src/test/test-record.ts
2864
- function J(e) {
2876
+ function X(e) {
2865
2877
  function t(t) {
2866
2878
  let { record: n, type: r = "raw" } = t, i = c({
2867
2879
  record: n,
@@ -2876,6 +2888,6 @@ function J(e) {
2876
2888
  }
2877
2889
  return t;
2878
2890
  }
2879
- var Y = J(R);
2891
+ var Z = X(R);
2880
2892
  //#endregion
2881
- export { L as DATABASE_CONFIG, C as DIALECTE_TEST_NAMESPACES, I as IO_CONFIG, R as TEST_DIALECTE_CONFIG, w as XMLNS_DEFAULT_NAMESPACE, T as XMLNS_DEV_NAMESPACE, E as XMLNS_EXT_NAMESPACE, _ as assertExpectedElementQueries, y as assertUnexpectedElementQueries, H as createMockRandomUUID, B as createTestContext, z as createTestProject, Y as createTestRecord, J as createTestRecordFactory, q as createTestRunner, g as createXmlAssertions, K as runTestCases, p as splitXpathIntoSteps };
2893
+ export { L as DATABASE_CONFIG, C as DIALECTE_TEST_NAMESPACES, I as IO_CONFIG, R as TEST_DIALECTE_CONFIG, w as XMLNS_DEFAULT_NAMESPACE, T as XMLNS_DEV_NAMESPACE, E as XMLNS_EXT_NAMESPACE, _ as assertExpectedElementQueries, y as assertUnexpectedElementQueries, W as createMockRandomUUID, B as createTestContext, z as createTestProject, Z as createTestRecord, X as createTestRecordFactory, Y as createTestRunner, g as createXmlAssertions, H as normalizeUuids, J as runTestCases, p as splitXpathIntoSteps };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Format an XML string to a canonical, readable shape: one structural tag per line, indented by depth,
3
+ * with pure-text leaves kept inline (`<Name ...>text</Name>`).
4
+ *
5
+ * NON-VALIDATING and tolerant of `${...}` template interpolations (treated as opaque characters), so it
6
+ * works on XML embedded in JS/TS template literals — where a `${templateUuid}` interpolation can stand
7
+ * for a whole attribute, which a real XML parser silently mis-parses. It only rewrites the insignificant
8
+ * whitespace *between* elements: attribute text and leaf text are preserved verbatim, and an element with
9
+ * mixed text + element content is emitted with its original inner content untouched, so no significant
10
+ * value is ever altered. Idempotent.
11
+ */
12
+ export declare function formatXml(source: string, options?: {
13
+ indent?: string;
14
+ baseIndent?: string;
15
+ }): string;
16
+ /**
17
+ * Reformat every XML snippet embedded in a JS/TS source string — a template literal preceded by a
18
+ * `/* xml *\/` marker comment — with {@link formatXml}, re-indented under the marker's own line with the
19
+ * closing backtick aligned to the statement. Leaves the rest of the source untouched. The reusable core
20
+ * of an `xmlfmt`-style step for test fixtures (see the `dialecte-xmlfmt` bin).
21
+ */
22
+ export declare function formatEmbeddedXml(sourceCode: string, options?: {
23
+ indent?: string;
24
+ }): string;
25
+ //# sourceMappingURL=format-xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-xml.d.ts","sourceRoot":"","sources":["../../src/utils/format-xml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACpD,MAAM,CAOR;AAyJD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAW/F"}
@@ -1,4 +1,5 @@
1
1
  export * from './attribute-rules';
2
+ export * from './format-xml';
2
3
  export * from './invariant';
3
4
  export * from './order-children';
4
5
  export * from './save-to-disk';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA"}
@@ -216,8 +216,142 @@ function d(e, t) {
216
216
  return [...n, ...r];
217
217
  }
218
218
  //#endregion
219
+ //#region src/utils/format-xml.ts
220
+ function f(e, t = {}) {
221
+ let n = t.indent ?? " ", r = t.baseIndent ?? "", i = h(m(e.trim())), a = [];
222
+ for (let e of i) _(e, r, n, a);
223
+ return a.join("\n");
224
+ }
225
+ function p(e, t) {
226
+ let n = t;
227
+ for (; n < e.length && !/[\s/>]/.test(e[n]);) n++;
228
+ return e.slice(t, n);
229
+ }
230
+ function m(e) {
231
+ let t = [], n = 0;
232
+ for (; n < e.length;) {
233
+ if (e[n] === "<") {
234
+ if (e.startsWith("<!--", n)) {
235
+ let r = e.indexOf("-->", n + 4), i = r === -1 ? e.length : r + 3;
236
+ t.push({
237
+ type: "comment",
238
+ raw: e.slice(n, i)
239
+ }), n = i;
240
+ continue;
241
+ }
242
+ if (e[n + 1] === "!" || e[n + 1] === "?") {
243
+ let r = e.indexOf(">", n), i = r === -1 ? e.length : r + 1;
244
+ t.push({
245
+ type: "other",
246
+ raw: e.slice(n, i)
247
+ }), n = i;
248
+ continue;
249
+ }
250
+ let r = n + 1, i;
251
+ for (; r < e.length;) {
252
+ let t = e[r];
253
+ if (i) t === i && (i = void 0);
254
+ else if (t === "\"" || t === "'") i = t;
255
+ else if (t === ">") break;
256
+ r++;
257
+ }
258
+ let a = r < e.length ? r + 1 : e.length, o = e.slice(n, a);
259
+ n = a, o[1] === "/" ? t.push({
260
+ type: "close",
261
+ name: p(o, 2),
262
+ raw: o
263
+ }) : o.endsWith("/>") ? t.push({
264
+ type: "selfclose",
265
+ name: p(o, 1),
266
+ raw: o
267
+ }) : t.push({
268
+ type: "open",
269
+ name: p(o, 1),
270
+ raw: o
271
+ });
272
+ continue;
273
+ }
274
+ let r = e.indexOf("<", n), i = r === -1 ? e.length : r;
275
+ t.push({
276
+ type: "text",
277
+ raw: e.slice(n, i)
278
+ }), n = i;
279
+ }
280
+ return t;
281
+ }
282
+ function h(e) {
283
+ let t = 0, n = () => {
284
+ let r = [];
285
+ for (; t < e.length;) {
286
+ let i = e[t];
287
+ if (i.type === "close") return r;
288
+ if (t++, i.type === "open") {
289
+ let a = {
290
+ kind: "element",
291
+ name: i.name,
292
+ openRaw: i.raw,
293
+ selfClosing: !1,
294
+ children: n()
295
+ };
296
+ e[t]?.type === "close" && t++, r.push(a);
297
+ } else i.type === "selfclose" ? r.push({
298
+ kind: "element",
299
+ name: i.name,
300
+ openRaw: i.raw,
301
+ selfClosing: !0,
302
+ children: []
303
+ }) : r.push({
304
+ kind: i.type,
305
+ raw: i.raw
306
+ });
307
+ }
308
+ return r;
309
+ };
310
+ return n();
311
+ }
312
+ function g(e) {
313
+ return e.kind === "element" ? e.selfClosing ? e.openRaw : `${e.openRaw}${e.children.map(g).join("")}</${e.name}>` : e.raw;
314
+ }
315
+ function _(e, t, n, r) {
316
+ if (e.kind === "text") {
317
+ e.raw.trim() !== "" && r.push(t + e.raw.trim());
318
+ return;
319
+ }
320
+ if (e.kind === "comment" || e.kind === "other") {
321
+ r.push(t + e.raw.trim());
322
+ return;
323
+ }
324
+ if (e.selfClosing) {
325
+ r.push(t + e.openRaw);
326
+ return;
327
+ }
328
+ let i = `</${e.name}>`, a = e.children.some((e) => e.kind !== "text"), o = e.children.some((e) => e.kind === "text" && e.raw.trim() !== "");
329
+ if (!a) {
330
+ let n = e.children.map((e) => e.kind === "text" ? e.raw : "").join("");
331
+ r.push(t + e.openRaw + n + i);
332
+ return;
333
+ }
334
+ if (o) {
335
+ r.push(t + e.openRaw + e.children.map(g).join("") + i);
336
+ return;
337
+ }
338
+ r.push(t + e.openRaw);
339
+ for (let i of e.children) i.kind !== "text" && _(i, t + n, n, r);
340
+ r.push(t + i);
341
+ }
342
+ function v(e, t = {}) {
343
+ let n = t.indent ?? " ";
344
+ return e.replace(/^([ \t]*)(.*?\/\*\s*xml\s*\*\/[ \t]*)`([\s\S]*?)`/gm, (e, t, r, i) => {
345
+ let a = f(i, {
346
+ indent: n,
347
+ baseIndent: t + n
348
+ });
349
+ return a.includes("\n") ? `${t}${r}\`\n${a}\n${t}\`` : `${t}${r}\`${a.trim()}\``;
350
+ });
351
+ }
352
+ //#endregion
219
353
  //#region src/utils/invariant.ts
220
- function f(e, n) {
354
+ function y(e, n) {
221
355
  if (e) return;
222
356
  let { detail: r, key: i = "ASSERTION_FAILED", ref: a } = n;
223
357
  t(i, {
@@ -227,7 +361,7 @@ function f(e, n) {
227
361
  }
228
362
  //#endregion
229
363
  //#region src/utils/order-children.ts
230
- function p(e) {
364
+ function b(e) {
231
365
  let { parentTagName: t, children: n, childrenConfig: r } = e, i = r[t];
232
366
  if (!i || i.length === 0) return n;
233
367
  let a = new Set(i), o = /* @__PURE__ */ new Map();
@@ -246,7 +380,7 @@ function p(e) {
246
380
  }
247
381
  //#endregion
248
382
  //#region src/utils/save-to-disk.ts
249
- async function m(e) {
383
+ async function x(e) {
250
384
  let { data: t, filename: n, pickerType: r } = e;
251
385
  if ("showSaveFilePicker" in window) try {
252
386
  let e = await (await window.showSaveFilePicker({
@@ -264,4 +398,4 @@ async function m(e) {
264
398
  a.href = i, a.download = n, document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(i);
265
399
  }
266
400
  //#endregion
267
- export { o as a, d as c, l as d, i as f, u as i, s as l, e as m, p as n, r as o, t as p, f as r, a as s, m as t, c as u };
401
+ export { f as a, r as c, s as d, c as f, e as g, t as h, v as i, a as l, i as m, b as n, u as o, l as p, y as r, o as s, x as t, d as u };
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./utils-C5_11hqg.js";
2
- export { i as compareQualifiedAttributes, e as extractLocalName, s as getAttributeRules, c as invariant, l as isSchemaDefaultValue, t as orderAttributesBySequence, o as orderByConfigSequence, a as resolveNamespaceByPrefix, d as resolveNamespaceByScope, n as resolvePrefixByNamespaceScope, r as resolveSchemaAttributeValue, u as saveToDisk };
1
+ import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./utils-BiEx1x59.js";
2
+ export { c as compareQualifiedAttributes, d as extractLocalName, i as formatEmbeddedXml, e as formatXml, t as getAttributeRules, u as invariant, a as isSchemaDefaultValue, p as orderAttributesBySequence, s as orderByConfigSequence, n as resolveNamespaceByPrefix, r as resolveNamespaceByScope, l as resolvePrefixByNamespaceScope, o as resolveSchemaAttributeValue, f as saveToDisk };
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.4.15",
3
+ "version": "0.4.16",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/dialecte/core.git"
9
9
  },
10
+ "bin": {
11
+ "dialecte-xmlfmt": "bin/xmlfmt.mjs"
12
+ },
10
13
  "source": "src/index.ts",
11
14
  "files": [
12
- "dist"
15
+ "dist",
16
+ "bin"
13
17
  ],
14
18
  "type": "module",
15
19
  "exports": {