@dialecte/core 0.5.2 → 0.5.3

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/test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { N as e, V as t, gt as n, mt as r, pt as i, t as a, u as o } from "./project-Bd3fSPam.js";
1
+ import { N as e, V as t, gt as n, mt as r, pt as i, t as a, u as o } from "./project-U2L6RvRW.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-valid-xml/assert-valid-xml.ts
@@ -1,17 +1,21 @@
1
- import { DialecteErrorKey } from '../errors';
1
+ import { DialecteErrorDefinition, DialecteErrorKey } from '../errors';
2
2
  /**
3
3
  * Assert a condition, throwing a structured DialecteError if it fails.
4
4
  *
5
+ * `key` is a key of the core catalogue or an error a dialecte declared with `defineErrors`;
6
+ * `meta` says what the error is about, as data a consumer can build its own wording from.
7
+ *
5
8
  * @example
6
9
  * invariant(record, { detail: 'addChild: parent not found' })
7
10
  * invariant(ref.id, { detail: 'Singleton element has no id', key: 'ELEMENT_NOT_FOUND' })
8
11
  */
9
12
  export declare function invariant(condition: unknown, error: {
10
13
  detail: string;
11
- key?: DialecteErrorKey;
14
+ key?: DialecteErrorKey | DialecteErrorDefinition;
12
15
  ref?: {
13
16
  tagName: string;
14
17
  id?: string;
15
18
  };
19
+ meta?: Record<string, unknown>;
16
20
  }): asserts condition;
17
21
  //# sourceMappingURL=invariant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/utils/invariant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEhD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACxB,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,gBAAgB,CAAA;IACtB,GAAG,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACtC,GACC,OAAO,CAAC,SAAS,CAInB"}
1
+ {"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/utils/invariant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEzE;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACxB,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAA;IAChD,GAAG,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,GACC,OAAO,CAAC,SAAS,CAInB"}
@@ -139,30 +139,65 @@ var e = {
139
139
  };
140
140
  //#endregion
141
141
  //#region src/errors/errors.ts
142
- function t(t, r) {
143
- let i = e[t], a = {
144
- code: i.code,
142
+ function t(e, t) {
143
+ throw n(e, t);
144
+ }
145
+ function n(t, n) {
146
+ let r = typeof t == "string" ? {
145
147
  key: t,
146
- message: r.message ?? i.message,
147
- detail: r.detail,
148
- method: n((/* @__PURE__ */ Error()).stack),
149
- ref: r.ref,
150
- cause: r.cause
151
- }, o = Error(r.detail);
152
- throw o.cause = a, o;
148
+ ...e[t]
149
+ } : t, i = {
150
+ code: r.code,
151
+ key: r.key,
152
+ message: n.message ?? r.message,
153
+ detail: n.detail,
154
+ method: c((/* @__PURE__ */ Error()).stack),
155
+ ref: n.ref,
156
+ meta: n.meta,
157
+ cause: n.cause
158
+ }, a = Error(n.detail);
159
+ return a.cause = i, a;
160
+ }
161
+ function r(n) {
162
+ let r = {}, a = /* @__PURE__ */ new Map();
163
+ for (let [o, s] of Object.entries(n)) {
164
+ Object.hasOwn(e, o) && t("ASSERTION_FAILED", { detail: `defineErrors: "${o}" is a key of the core catalogue` }), i.has(s.code) && t("ASSERTION_FAILED", { detail: `defineErrors: "${o}" uses "${s.code}", a code of the core catalogue` });
165
+ let n = a.get(s.code);
166
+ n && t("ASSERTION_FAILED", { detail: `defineErrors: "${o}" uses "${s.code}", the code of "${n}"` }), a.set(s.code, o), r[o] = {
167
+ key: o,
168
+ ...s
169
+ };
170
+ }
171
+ return r;
172
+ }
173
+ var i = new Set(Object.values(e).map((e) => e.code));
174
+ function a(e) {
175
+ if (!(e instanceof Error)) return;
176
+ let t = e.cause;
177
+ if (!(!t || t instanceof Error) && !(typeof t.key != "string" || typeof t.code != "string")) return t;
178
+ }
179
+ function o(t, n) {
180
+ return Object.hasOwn(e, t.key) ? !0 : n.catalogues.some((e) => Object.hasOwn(e, t.key) && e[t.key]?.code === t.code);
153
181
  }
154
- function n(e) {
182
+ var s = new Set([
183
+ "throwDialecteError",
184
+ "createDialecteError",
185
+ "invariant",
186
+ "reportFailure"
187
+ ]);
188
+ function c(e) {
155
189
  if (!e) return "unknown";
156
- let t = e.split("\n").slice(1).find((e) => !/\b(throwDialecteError|assert)\b/.test(e));
157
- if (!t) return "unknown";
158
- let n = t.match(/\bat\s+(\S+)\s+\(([^)]+)\)/), r = n?.[1], i = n?.[2];
159
- if (!i || !r) return r ?? "unknown";
160
- let a = i.match(/(\w[\w-]*\/src\/[^?:]+)/);
161
- return a ? `${a[1].replace(/\.[^/.]+$/, "")}::${r}` : r;
190
+ let t = e.split("\n").slice(1).map((e) => e.match(/\bat\s+(?:async\s+)?(\S+)(?:\s+\[as\s+[^\]]+\])?\s+\(([^)]+)\)/)).find((e) => !l(e?.[1])), n = t?.[1]?.replace(/^Object\./, ""), r = t?.[2];
191
+ if (!r || !n) return n ?? "unknown";
192
+ let i = r.match(/(\w[\w-]*\/src\/[^?:]+)/);
193
+ return i ? `${i[1].replace(/\.[^/.]+$/, "")}::${n}` : n;
194
+ }
195
+ function l(e) {
196
+ return e ? s.has(e.slice(e.lastIndexOf(".") + 1)) : !1;
162
197
  }
163
198
  //#endregion
164
199
  //#region src/utils/resolve-definition.ts
165
- function r(e) {
200
+ function u(e) {
166
201
  let { dialecteConfig: t, record: n } = e, r = t.definition[n.tagName];
167
202
  if (r === void 0) return;
168
203
  let i = n.parent?.tagName;
@@ -183,75 +218,75 @@ function r(e) {
183
218
  }
184
219
  //#endregion
185
220
  //#region src/utils/attribute-rules.ts
186
- function i(e) {
187
- let { dialecteConfig: t, record: n, attributeName: i } = e, a = t.elements.includes(n.tagName), o = a ? r({
221
+ function d(e) {
222
+ let { dialecteConfig: t, record: n, attributeName: r } = e, i = t.elements.includes(n.tagName), a = i ? u({
188
223
  dialecteConfig: t,
189
224
  record: n
190
- }) : void 0, s = o?.attributes.details[i];
225
+ }) : void 0, o = a?.attributes.details[r];
191
226
  return {
192
- isKnownElement: a,
193
- isDefined: !!s,
194
- isRequired: !!s?.required,
195
- isIdentityField: o?.attributes.identityFields?.includes(i) ?? !1,
196
- fixed: s?.fixed,
197
- default: s?.default,
198
- namespace: s?.namespace || void 0
227
+ isKnownElement: i,
228
+ isDefined: !!o,
229
+ isRequired: !!o?.required,
230
+ isIdentityField: a?.attributes.identityFields?.includes(r) ?? !1,
231
+ fixed: o?.fixed,
232
+ default: o?.default,
233
+ namespace: o?.namespace || void 0
199
234
  };
200
235
  }
201
- function a(e) {
202
- let { dialecteConfig: t, record: n, attributeName: r, defaults: a } = e;
203
- if (a === "none") return;
204
- let o = i({
236
+ function f(e) {
237
+ let { dialecteConfig: t, record: n, attributeName: r, defaults: i } = e;
238
+ if (i === "none") return;
239
+ let a = d({
205
240
  dialecteConfig: t,
206
241
  record: n,
207
242
  attributeName: r
208
243
  });
209
- if (a === "required") return o.isRequired || o.fixed !== void 0 ? o.fixed ?? o.default ?? "" : void 0;
210
- if (o.fixed !== void 0) return o.fixed;
211
- if (o.default) return o.default;
244
+ if (i === "required") return a.isRequired || a.fixed !== void 0 ? a.fixed ?? a.default ?? "" : void 0;
245
+ if (a.fixed !== void 0) return a.fixed;
246
+ if (a.default) return a.default;
212
247
  }
213
- function o(e) {
214
- let { dialecteConfig: t, record: n, attributeName: r, value: a } = e, o = i({
248
+ function p(e) {
249
+ let { dialecteConfig: t, record: n, attributeName: r, value: i } = e, a = d({
215
250
  dialecteConfig: t,
216
251
  record: n,
217
252
  attributeName: r
218
- }), s = o.fixed ?? o.default;
219
- return s !== void 0 && a === s;
253
+ }), o = a.fixed ?? a.default;
254
+ return o !== void 0 && i === o;
220
255
  }
221
- function s(e) {
256
+ function m(e) {
222
257
  let t = e.lastIndexOf(":");
223
258
  return t === -1 ? e : e.slice(t + 1);
224
259
  }
225
- function c(e, t) {
260
+ function h(e, t) {
226
261
  if (t) return Object.values(e.namespaces).find((e) => e.prefix === t);
227
262
  }
228
- function l(e, t) {
229
- return e.namespaces[t] ?? c(e, t);
263
+ function g(e, t) {
264
+ return e.namespaces[t] ?? h(e, t);
230
265
  }
231
- function u(e, t) {
266
+ function _(e, t) {
232
267
  return e.namespaces[t]?.prefix ?? t;
233
268
  }
234
- function d(e, t) {
269
+ function v(e, t) {
235
270
  let n = e.namespace?.uri ?? "", r = t.namespace?.uri ?? "";
236
271
  return n === r ? e.name === t.name ? 0 : e.name < t.name ? -1 : 1 : n < r ? -1 : 1;
237
272
  }
238
- function f(e, t) {
239
- let n = t.flatMap((t) => e.filter((e) => e.name === t)), r = e.filter((e) => !t.includes(e.name)).sort(d);
273
+ function y(e, t) {
274
+ let n = t.flatMap((t) => e.filter((e) => e.name === t)), r = e.filter((e) => !t.includes(e.name)).sort(v);
240
275
  return [...n, ...r];
241
276
  }
242
277
  //#endregion
243
278
  //#region src/utils/format-xml.ts
244
- function p(e, t = {}) {
245
- let n = t.indent ?? " ", r = t.baseIndent ?? "", i = g(h(e.trim())), a = [];
246
- for (let e of i) v(e, r, n, a);
279
+ function b(e, t = {}) {
280
+ let n = t.indent ?? " ", r = t.baseIndent ?? "", i = C(S(e.trim())), a = [];
281
+ for (let e of i) T(e, r, n, a);
247
282
  return a.join("\n");
248
283
  }
249
- function m(e, t) {
284
+ function x(e, t) {
250
285
  let n = t;
251
286
  for (; n < e.length && !/[\s/>]/.test(e[n]);) n++;
252
287
  return e.slice(t, n);
253
288
  }
254
- function h(e) {
289
+ function S(e) {
255
290
  let t = [], n = 0;
256
291
  for (; n < e.length;) {
257
292
  if (e[n] === "<") {
@@ -282,15 +317,15 @@ function h(e) {
282
317
  let a = r < e.length ? r + 1 : e.length, o = e.slice(n, a);
283
318
  n = a, o[1] === "/" ? t.push({
284
319
  type: "close",
285
- name: m(o, 2),
320
+ name: x(o, 2),
286
321
  raw: o
287
322
  }) : o.endsWith("/>") ? t.push({
288
323
  type: "selfclose",
289
- name: m(o, 1),
324
+ name: x(o, 1),
290
325
  raw: o
291
326
  }) : t.push({
292
327
  type: "open",
293
- name: m(o, 1),
328
+ name: x(o, 1),
294
329
  raw: o
295
330
  });
296
331
  continue;
@@ -303,7 +338,7 @@ function h(e) {
303
338
  }
304
339
  return t;
305
340
  }
306
- function g(e) {
341
+ function C(e) {
307
342
  let t = 0, n = () => {
308
343
  let r = [];
309
344
  for (; t < e.length;) {
@@ -333,10 +368,10 @@ function g(e) {
333
368
  };
334
369
  return n();
335
370
  }
336
- function _(e) {
337
- return e.kind === "element" ? e.selfClosing ? e.openRaw : `${e.openRaw}${e.children.map(_).join("")}</${e.name}>` : e.raw;
371
+ function w(e) {
372
+ return e.kind === "element" ? e.selfClosing ? e.openRaw : `${e.openRaw}${e.children.map(w).join("")}</${e.name}>` : e.raw;
338
373
  }
339
- function v(e, t, n, r) {
374
+ function T(e, t, n, r) {
340
375
  if (e.kind === "text") {
341
376
  e.raw.trim() !== "" && r.push(t + e.raw.trim());
342
377
  return;
@@ -356,17 +391,17 @@ function v(e, t, n, r) {
356
391
  return;
357
392
  }
358
393
  if (o) {
359
- r.push(t + e.openRaw + e.children.map(_).join("") + i);
394
+ r.push(t + e.openRaw + e.children.map(w).join("") + i);
360
395
  return;
361
396
  }
362
397
  r.push(t + e.openRaw);
363
- for (let i of e.children) i.kind !== "text" && v(i, t + n, n, r);
398
+ for (let i of e.children) i.kind !== "text" && T(i, t + n, n, r);
364
399
  r.push(t + i);
365
400
  }
366
- function y(e, t = {}) {
401
+ function E(e, t = {}) {
367
402
  let n = t.indent ?? " ";
368
403
  return e.replace(/^([ \t]*)(.*?\/\*\s*xml\s*\*\/[ \t]*)`([\s\S]*?)`/gm, (e, t, r, i) => {
369
- let a = p(i, {
404
+ let a = b(i, {
370
405
  indent: n,
371
406
  baseIndent: t + n
372
407
  });
@@ -375,17 +410,18 @@ function y(e, t = {}) {
375
410
  }
376
411
  //#endregion
377
412
  //#region src/utils/invariant.ts
378
- function b(e, n) {
413
+ function D(e, n) {
379
414
  if (e) return;
380
- let { detail: r, key: i = "ASSERTION_FAILED", ref: a } = n;
415
+ let { detail: r, key: i = "ASSERTION_FAILED", ref: a, meta: o } = n;
381
416
  t(i, {
382
417
  detail: r,
383
- ref: a
418
+ ref: a,
419
+ meta: o
384
420
  });
385
421
  }
386
422
  //#endregion
387
423
  //#region src/utils/order-children.ts
388
- function x(e) {
424
+ function O(e) {
389
425
  let { parentTagName: t, children: n, childrenConfig: r } = e, i = r[t];
390
426
  if (!i || i.length === 0) return n;
391
427
  let a = new Set(i), o = /* @__PURE__ */ new Map();
@@ -404,7 +440,7 @@ function x(e) {
404
440
  }
405
441
  //#endregion
406
442
  //#region src/utils/save-to-disk.ts
407
- async function S(e) {
443
+ async function k(e) {
408
444
  let { data: t, filename: n, pickerType: r } = e;
409
445
  if ("showSaveFilePicker" in window) try {
410
446
  let e = await (await window.showSaveFilePicker({
@@ -422,4 +458,4 @@ async function S(e) {
422
458
  a.href = i, a.download = n, document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(i);
423
459
  }
424
460
  //#endregion
425
- export { e as _, p as a, i as c, c as d, l as f, t as g, r as h, y as i, o as l, a as m, x as n, d as o, u as p, b as r, s, S as t, f as u };
461
+ export { r as _, b as a, a as b, d as c, h as d, g as f, n as g, u as h, E as i, p as l, f as m, O as n, v as o, _ as p, D as r, m as s, k as t, y as u, o as v, e as x, t as y };
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m } from "./utils-ERge2irW.js";
1
+ import { a as e, c as t, d as n, f as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m } from "./utils-Cgqv3qwv.js";
2
2
  export { l as compareQualifiedAttributes, f as extractLocalName, a as formatEmbeddedXml, e as formatXml, t as getAttributeRules, d as invariant, o as isSchemaDefaultValue, m as orderAttributesBySequence, c as orderByConfigSequence, i as resolveDefinition, n as resolveNamespaceByPrefix, r as resolveNamespaceByScope, u as resolvePrefixByNamespaceScope, s as resolveSchemaAttributeValue, p as saveToDisk };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {