@dialecte/core 0.4.15 → 0.4.17
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/assert-valid-xml/assert-valid-xml.d.ts +24 -0
- package/dist/test/assert-valid-xml/assert-valid-xml.d.ts.map +1 -0
- package/dist/test/assert-valid-xml/assert-valid-xml.types.d.ts +41 -0
- package/dist/test/assert-valid-xml/assert-valid-xml.types.d.ts.map +1 -0
- package/dist/test/assert-valid-xml/index.d.ts +3 -0
- package/dist/test/assert-valid-xml/index.d.ts.map +1 -0
- package/dist/test/index.d.ts +2 -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 +173 -71
- 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
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 {
|
|
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(
|
|
99
|
-
let { attribute:
|
|
100
|
-
typeof
|
|
101
|
-
detail: `Unknown namespace '${
|
|
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 =
|
|
104
|
-
let l =
|
|
103
|
+
})) : c = i.namespace;
|
|
104
|
+
let l = i.name.indexOf(":");
|
|
105
105
|
if (!c && l !== -1) {
|
|
106
|
-
let e =
|
|
107
|
-
e !== "xmlns" && (c =
|
|
108
|
-
detail: `Unknown namespace prefix '${e}' on attribute '${
|
|
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
|
-
...
|
|
114
|
-
name: `${c.prefix}:${
|
|
113
|
+
...i,
|
|
114
|
+
name: `${c.prefix}:${a(i.name)}`,
|
|
115
115
|
namespace: c
|
|
116
|
-
} : (
|
|
117
|
-
...
|
|
116
|
+
} : (i.namespace, {
|
|
117
|
+
...i,
|
|
118
118
|
namespace: c
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
function M(e) {
|
|
122
|
-
return
|
|
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:
|
|
131
|
-
tagName:
|
|
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:
|
|
133
|
+
dialecteConfig: t
|
|
134
134
|
}) : [], f = {
|
|
135
135
|
id: u,
|
|
136
|
-
tagName:
|
|
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:
|
|
144
|
-
children:
|
|
145
|
-
}, p = Object.values(
|
|
146
|
-
if (!(
|
|
147
|
-
let h =
|
|
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
|
-
}), _ =
|
|
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 =
|
|
158
|
+
}), y = r.parent?.tagName, b = y ? t.definition[y]?.children?.details?.[a]?.namespace : void 0, x = {
|
|
159
159
|
...f,
|
|
160
|
-
namespace: b ??
|
|
161
|
-
attributes:
|
|
160
|
+
namespace: b ?? t.definition[a].namespace,
|
|
161
|
+
attributes: o(v, h)
|
|
162
162
|
};
|
|
163
|
-
return
|
|
163
|
+
return n?.afterStandardizedRecord && (x = n.afterStandardizedRecord({ record: x }), x = {
|
|
164
164
|
...x,
|
|
165
|
-
attributes:
|
|
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(
|
|
171
|
-
let { dialecteConfig:
|
|
172
|
-
for (let
|
|
173
|
-
let a =
|
|
174
|
-
dialecteConfig:
|
|
175
|
-
tagName:
|
|
176
|
-
attributeName:
|
|
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 &&
|
|
179
|
-
detail: `Attribute '${
|
|
180
|
-
ref: { tagName:
|
|
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
|
|
189
|
-
a
|
|
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): ${
|
|
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-
|
|
2
|
-
import {
|
|
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 };
|