@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 ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ // Reformat the XML embedded in `/* xml */` template literals across the matched files, using the
3
+ // shared core formatter. One structural tag per line, indented, text leaves inline; interpolations
4
+ // (${ns}/${id}) and text values preserved. A snippet the parser cannot handle is left untouched.
5
+ //
6
+ // dialecte-xmlfmt 'src/**/*.test.ts' # rewrite in place
7
+ // dialecte-xmlfmt --check 'src/**/*.test.ts' # exit 1 if any file is not formatted (CI gate)
8
+ import { globSync, readFileSync, writeFileSync } from 'node:fs'
9
+
10
+ import { formatEmbeddedXml } from '../dist/utils.js'
11
+
12
+ const args = process.argv.slice(2)
13
+ const check = args.includes('--check')
14
+ const patterns = args.filter((arg) => !arg.startsWith('--'))
15
+
16
+ if (patterns.length === 0) {
17
+ console.error("usage: dialecte-xmlfmt [--check] <glob>... (e.g. 'src/**/*.test.ts')")
18
+ process.exit(2)
19
+ }
20
+
21
+ const files = [...new Set(patterns.flatMap((pattern) => globSync(pattern)))]
22
+ const changed = []
23
+ for (const file of files) {
24
+ const before = readFileSync(file, 'utf8')
25
+ const after = formatEmbeddedXml(before)
26
+ if (after === before) continue
27
+ changed.push(file)
28
+ if (!check) writeFileSync(file, after)
29
+ }
30
+
31
+ if (check && changed.length > 0) {
32
+ console.error(`dialecte-xmlfmt: ${changed.length} file(s) not formatted:`)
33
+ for (const file of changed) console.error(` ${file}`)
34
+ process.exit(1)
35
+ }
36
+ console.log(
37
+ check
38
+ ? 'dialecte-xmlfmt: all files formatted.'
39
+ : `dialecte-xmlfmt: formatted ${changed.length} file(s).`,
40
+ )
package/dist/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, l as n, o as r, p as i, r as a, u as o } from "./utils-C5_11hqg.js";
1
+ import { c as e, d as t, f as n, h as r, r as i, s as a, u as o } from "./utils-BiEx1x59.js";
2
2
  //#region src/helpers/constant.ts
3
3
  var s = "db-id", c = {
4
4
  uri: "http://dialecte.dev/XML/DEV",
@@ -95,31 +95,31 @@ function A(e) {
95
95
  tagName: n
96
96
  }));
97
97
  }
98
- function j(t) {
99
- let { attribute: r, dialecteConfig: a, tagName: s } = t, c;
100
- typeof r.namespace == "string" ? (c = o(a, r.namespace), c || i("UNKNOWN_NAMESPACE_PREFIX", {
101
- detail: `Unknown namespace '${r.namespace}' on attribute '${r.name}' — use a registered namespace key or pass a full { name, namespace: { prefix, uri } }.`,
98
+ function j(e) {
99
+ let { attribute: i, dialecteConfig: o, tagName: s } = e, c;
100
+ typeof i.namespace == "string" ? (c = n(o, i.namespace), c || r("UNKNOWN_NAMESPACE_PREFIX", {
101
+ detail: `Unknown namespace '${i.namespace}' on attribute '${i.name}' — use a registered namespace key or pass a full { name, namespace: { prefix, uri } }.`,
102
102
  ref: { tagName: s }
103
- })) : c = r.namespace;
104
- let l = r.name.indexOf(":");
103
+ })) : c = i.namespace;
104
+ let l = i.name.indexOf(":");
105
105
  if (!c && l !== -1) {
106
- let e = r.name.slice(0, l);
107
- e !== "xmlns" && (c = n(a, e), c || i("UNKNOWN_NAMESPACE_PREFIX", {
108
- detail: `Unknown namespace prefix '${e}' on attribute '${r.name}' — pass it explicitly as { name, namespace: { prefix, uri } }.`,
106
+ let e = i.name.slice(0, l);
107
+ e !== "xmlns" && (c = t(o, e), c || r("UNKNOWN_NAMESPACE_PREFIX", {
108
+ detail: `Unknown namespace prefix '${e}' on attribute '${i.name}' — pass it explicitly as { name, namespace: { prefix, uri } }.`,
109
109
  ref: { tagName: s }
110
110
  }));
111
111
  }
112
112
  return c && c.prefix && c.prefix !== "xmlns" ? {
113
- ...r,
114
- name: `${c.prefix}:${e(r.name)}`,
113
+ ...i,
114
+ name: `${c.prefix}:${a(i.name)}`,
115
115
  namespace: c
116
- } : (r.namespace, {
117
- ...r,
116
+ } : (i.namespace, {
117
+ ...i,
118
118
  namespace: c
119
119
  });
120
120
  }
121
121
  function M(e) {
122
- return a(e, { detail: "The record or ref is undefined" }), {
122
+ return i(e, { detail: "The record or ref is undefined" }), {
123
123
  id: e.id,
124
124
  tagName: e.tagName
125
125
  };
@@ -127,57 +127,57 @@ function M(e) {
127
127
  //#endregion
128
128
  //#region src/helpers/standardizing.ts
129
129
  function N(e) {
130
- let { dialecteConfig: n, hooks: r, record: i } = e, { id: a, tagName: o, attributes: s, namespace: c, value: l } = i, u = a ?? crypto.randomUUID(), d = s ? A({
131
- tagName: o,
130
+ let { dialecteConfig: t, hooks: n, record: r } = e, { id: i, tagName: a, attributes: s, namespace: c, value: l } = r, u = i ?? crypto.randomUUID(), d = s ? A({
131
+ tagName: a,
132
132
  attributes: s,
133
- dialecteConfig: n
133
+ dialecteConfig: t
134
134
  }) : [], f = {
135
135
  id: u,
136
- tagName: o,
136
+ tagName: a,
137
137
  attributes: d,
138
138
  namespace: c ?? {
139
139
  prefix: "prefixNeededForNotSupportedNamespace",
140
140
  uri: "uriNeededForNotSupportedNamespace"
141
141
  },
142
142
  value: l ?? "",
143
- parent: i.parent ?? null,
144
- children: i.children ?? []
145
- }, p = Object.values(n.namespaces).map(({ uri: e }) => e), m = c?.uri != null && !p.includes(c.uri);
146
- if (!(n.elements.includes(o) && !m)) return f;
147
- let h = n.definition[o].attributes.sequence, g = d.filter((e) => {
143
+ parent: r.parent ?? null,
144
+ children: r.children ?? []
145
+ }, p = Object.values(t.namespaces).map(({ uri: e }) => e), m = c?.uri != null && !p.includes(c.uri);
146
+ if (!(t.elements.includes(a) && !m)) return f;
147
+ let h = t.definition[a].attributes.sequence, g = d.filter((e) => {
148
148
  let t = h.includes(e.name), n = "namespace" in e && e.namespace != null;
149
149
  if (!t && !n) return !1;
150
150
  let r = e.value === void 0 || e.value === null || e.value === "";
151
151
  return !(t && r);
152
- }), _ = n.namespaces.default.uri, v = g.map((e) => {
152
+ }), _ = t.namespaces.default.uri, v = g.map((e) => {
153
153
  if ("namespace" in e && e.namespace?.uri === _) {
154
154
  let { namespace: t, ...n } = e;
155
155
  return n;
156
156
  }
157
157
  return e;
158
- }), y = i.parent?.tagName, b = y ? n.definition[y]?.children?.details?.[o]?.namespace : void 0, x = {
158
+ }), y = r.parent?.tagName, b = y ? t.definition[y]?.children?.details?.[a]?.namespace : void 0, x = {
159
159
  ...f,
160
- namespace: b ?? n.definition[o].namespace,
161
- attributes: t(v, h)
160
+ namespace: b ?? t.definition[a].namespace,
161
+ attributes: o(v, h)
162
162
  };
163
- return r?.afterStandardizedRecord && (x = r.afterStandardizedRecord({ record: x }), x = {
163
+ return n?.afterStandardizedRecord && (x = n.afterStandardizedRecord({ record: x }), x = {
164
164
  ...x,
165
- attributes: t(x.attributes, h)
165
+ attributes: o(x.attributes, h)
166
166
  }), x;
167
167
  }
168
168
  //#endregion
169
169
  //#region src/helpers/assert-fixed.ts
170
- function P(e) {
171
- let { dialecteConfig: t, tagName: n, attributes: a } = e;
172
- for (let e of a) {
173
- let a = r({
174
- dialecteConfig: t,
175
- tagName: n,
176
- attributeName: e.name
170
+ function P(t) {
171
+ let { dialecteConfig: n, tagName: i, attributes: a } = t;
172
+ for (let t of a) {
173
+ let a = e({
174
+ dialecteConfig: n,
175
+ tagName: i,
176
+ attributeName: t.name
177
177
  });
178
- a.fixed !== void 0 && e.value !== a.fixed && i("FIXED_VALUE_VIOLATION", {
179
- detail: `Attribute '${e.name}' on '${n}' is fixed to '${a.fixed}' but was set to '${String(e.value)}'.`,
180
- ref: { tagName: n }
178
+ a.fixed !== void 0 && t.value !== a.fixed && r("FIXED_VALUE_VIOLATION", {
179
+ detail: `Attribute '${t.name}' on '${i}' is fixed to '${a.fixed}' but was set to '${String(t.value)}'.`,
180
+ ref: { tagName: i }
181
181
  });
182
182
  }
183
183
  }
@@ -185,10 +185,10 @@ function P(e) {
185
185
  //#region src/helpers/merge-extensions.ts
186
186
  function F(e, t, n, r) {
187
187
  if (!e || !t) return;
188
- let i = Object.keys(t).filter((t) => t in e);
189
- a(i.length === 0, {
188
+ let a = Object.keys(t).filter((t) => t in e);
189
+ i(a.length === 0, {
190
190
  key: "EXTENSION_METHOD_COLLISION",
191
- detail: `Module "${n}" has conflicting ${r} method(s): ${i.map((e) => `"${e}"`).join(", ")}`
191
+ detail: `Module "${n}" has conflicting ${r} method(s): ${a.map((e) => `"${e}"`).join(", ")}`
192
192
  });
193
193
  }
194
194
  function I(e) {
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as e, A as t, B as n, C as r, D as i, E as a, F as o, G as s, H as c, I as l, J as u, K as d, L as f, M as p, N as m, O as h, P as g, Q as _, R as v, S as y, T as b, U as x, W as S, X as C, Y as w, Z as T, _ as E, a as D, at as O, b as k, c as A, ct as j, d as M, dt as N, et as P, f as F, ft as I, g as L, h as R, i as z, it as B, j as V, k as H, l as U, lt as W, m as G, mt as K, n as q, nt as J, o as Y, ot as X, p as Z, q as Q, r as $, rt as ee, s as te, st as ne, t as re, tt as ie, u as ae, ut as oe, v as se, w as ce, x as le, y as ue, z as de } from "./project-FFHlnZpz.js";
2
- import { m as fe, p as pe } from "./utils-C5_11hqg.js";
1
+ import { $ as e, A as t, B as n, C as r, D as i, E as a, F as o, G as s, H as c, I as l, J as u, K as d, L as f, M as p, N as m, O as h, P as g, Q as _, R as v, S as y, T as b, U as x, W as S, X as C, Y as w, Z as T, _ as E, a as D, at as O, b as k, c as A, ct as j, d as M, dt as N, et as P, f as F, ft as I, g as L, h as R, i as z, it as B, j as V, k as H, l as U, lt as W, m as G, mt as K, n as q, nt as J, o as Y, ot as X, p as Z, q as Q, r as $, rt as ee, s as te, st as ne, t as re, tt as ie, u as ae, ut as oe, v as se, w as ce, x as le, y as ue, z as de } from "./project-nvZv2ie8.js";
2
+ import { g as fe, h as pe } from "./utils-BiEx1x59.js";
3
3
  export { H as AnyQuery, i as AnyTransaction, M as BLOBS_SCHEMA, F as BLOB_DATA_SCHEMA, Z as CHANGELOG_SCHEMA, G as DOCUMENTS_SCHEMA, ae as DexieStore, ce as Document, fe as ERROR_CATALOG, U as InMemoryStore, R as META_SCHEMA, m as NOOP_PERF, g as ParseSession, re as Project, h as Query, L as TABLE_BLOBS, E as TABLE_BLOB_PREFIX, se as TABLE_CHANGELOG, ue as TABLE_DOCUMENTS, k as TABLE_META, le as TABLE_RECORD_PREFIX, de as TEMP_IDB_ID_ATTRIBUTE_NAME, a as Transaction, d as applyOmit, s as applyOrder, C as applyUnwrap, K as bindExtensions, y as blobTableName, z as buildDocumentState, l as buildXmlDocument, x as collectSnapshotRecords, p as createPerf, I as createStagedOperations, f as downloadFile, Y as exportBlob, te as exportDocument, B as findAncestors, J as findByAttributes, ie as findDescendants, n as formatXml, e as getAttribute, P as getAttributeFullObject, T as getAttributes, _ as getAttributesFullObject, X as getChild, O as getChildren, W as getRecord, j as getRecords, ne as getRecordsByTagName, t as getSnapshot, S as getTree, $ as importDocument, oe as indexStagedDeletesByParent, q as initEmptyDocument, o as inspectXml, Q as isOmitted, b as isTransactionContext, ee as matchesAttributeFilter, N as overlayAllStaged, u as parseOmit, V as parseXmlFile, D as reconcileDocumentState, r as recordTableName, c as recordsToTree, A as resolveStore, w as shouldStopTraversal, pe as throwDialecteError, v as xmlDocumentToString };