@cbortech/cbor 0.26.6 → 0.26.8
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/README.ja.md +125 -0
- package/README.md +124 -0
- package/dist/ast/CborByteString.d.ts +25 -0
- package/dist/ast/CborEllipsis.d.ts +94 -2
- package/dist/ast/CborFloat.d.ts +10 -0
- package/dist/ast/CborItem.d.ts +93 -4
- package/dist/ast/CborNint.d.ts +9 -0
- package/dist/ast/CborSimple.d.ts +11 -2
- package/dist/ast/CborTag.d.ts +8 -0
- package/dist/ast/CborTextString.d.ts +36 -0
- package/dist/ast/CborUint.d.ts +8 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +2 -2
- package/dist/cddl/index.cjs +1 -1
- package/dist/cddl/index.js +1 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.cjs.map +1 -1
- package/dist/cdn/index.d.ts +2 -0
- package/dist/cdn/index.js +26 -26
- package/dist/cdn/index.js.map +1 -1
- package/dist/cdn/serialize-utils.d.ts +208 -9
- package/dist/extensions/dt.d.ts +3 -0
- package/dist/extensions/types.d.ts +31 -9
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +62 -99
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-BJzyBUH5.cjs +13 -0
- package/dist/mapEntries-BJzyBUH5.cjs.map +1 -0
- package/dist/{mapEntries-Czxt-cmd.js → mapEntries-Ci_dppP6.js} +1499 -1219
- package/dist/mapEntries-Ci_dppP6.js.map +1 -0
- package/dist/{schema-BmGsaEaW.cjs → schema-DgnkH0P6.cjs} +5 -5
- package/dist/{schema-BmGsaEaW.cjs.map → schema-DgnkH0P6.cjs.map} +1 -1
- package/dist/{schema-BxkgvUY6.js → schema-y8G5mDIS.js} +248 -248
- package/dist/{schema-BxkgvUY6.js.map → schema-y8G5mDIS.js.map} +1 -1
- package/dist/tokenizer-BD08xbyd.cjs +36 -0
- package/dist/tokenizer-BD08xbyd.cjs.map +1 -0
- package/dist/{tokenizer-CeuixxXi.js → tokenizer-N-vAvRdj.js} +350 -14
- package/dist/tokenizer-N-vAvRdj.js.map +1 -0
- package/dist/types.d.ts +176 -7
- package/package.json +2 -3
- package/dist/mapEntries-BhMlCwYo.cjs +0 -15
- package/dist/mapEntries-BhMlCwYo.cjs.map +0 -1
- package/dist/mapEntries-Czxt-cmd.js.map +0 -1
- package/dist/tokenizer-CeuixxXi.js.map +0 -1
- package/dist/tokenizer-EciPlN0n.cjs +0 -30
- package/dist/tokenizer-EciPlN0n.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as t,
|
|
1
|
+
import { E as e } from "./tokenizer-N-vAvRdj.js";
|
|
2
|
+
import { A as t, D as n, E as r, F as i, I as a, L as o, M as s, N as c, O as l, P as u, T as d, _ as f, b as p, g as m, h, j as g, k as ee, u as te, v as ne, w as re, x as ie, y as _ } from "./mapEntries-Ci_dppP6.js";
|
|
3
3
|
//#region src/cddl/errors.ts
|
|
4
4
|
var v = class extends SyntaxError {
|
|
5
5
|
offset;
|
|
@@ -206,7 +206,7 @@ var v = class extends SyntaxError {
|
|
|
206
206
|
else {
|
|
207
207
|
let s = ue(a);
|
|
208
208
|
try {
|
|
209
|
-
o = t === "h" ? e(s) :
|
|
209
|
+
o = t === "h" ? e(s) : ie(s);
|
|
210
210
|
} catch (e) {
|
|
211
211
|
throw !(e instanceof SyntaxError) || e instanceof v ? e : new v(e.message, {
|
|
212
212
|
offset: n,
|
|
@@ -316,21 +316,21 @@ function ue(e) {
|
|
|
316
316
|
}
|
|
317
317
|
//#endregion
|
|
318
318
|
//#region src/cddl/parser.ts
|
|
319
|
-
function
|
|
319
|
+
function S(e) {
|
|
320
320
|
let t = new le(e);
|
|
321
321
|
return {
|
|
322
|
-
rules: new
|
|
322
|
+
rules: new fe(t).parse(),
|
|
323
323
|
comments: t.comments
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
var
|
|
326
|
+
var de = /* @__PURE__ */ new Set([
|
|
327
327
|
"SLASH",
|
|
328
328
|
"RANGE_INCL",
|
|
329
329
|
"RANGE_EXCL",
|
|
330
330
|
"CTLOP",
|
|
331
331
|
"ARROW",
|
|
332
332
|
"CARET"
|
|
333
|
-
]),
|
|
333
|
+
]), fe = class {
|
|
334
334
|
t;
|
|
335
335
|
buf = [];
|
|
336
336
|
constructor(e) {
|
|
@@ -412,7 +412,7 @@ var fe = /* @__PURE__ */ new Set([
|
|
|
412
412
|
let e = this.peek().offset, t = this.tryParseOccur();
|
|
413
413
|
if (this.peek().type === "LPAREN") {
|
|
414
414
|
let n = this.consume(), r = this.parseGroup("RPAREN"), i = this.consume();
|
|
415
|
-
if (
|
|
415
|
+
if (de.has(this.peek().type)) {
|
|
416
416
|
let a = this.groupAsParenType(r, n, i), o = this.continueType1(a);
|
|
417
417
|
return this.finishEntryFromType1(e, t, o);
|
|
418
418
|
}
|
|
@@ -706,7 +706,7 @@ var fe = /* @__PURE__ */ new Set([
|
|
|
706
706
|
case "FLOAT": return {
|
|
707
707
|
kind: "value",
|
|
708
708
|
type: "float",
|
|
709
|
-
value: /^-?0[xX]/.test(e.value) ?
|
|
709
|
+
value: /^-?0[xX]/.test(e.value) ? c(e.value) : parseFloat(e.value),
|
|
710
710
|
...t
|
|
711
711
|
};
|
|
712
712
|
case "TSTR": return {
|
|
@@ -734,21 +734,21 @@ var fe = /* @__PURE__ */ new Set([
|
|
|
734
734
|
end: n.endOffset
|
|
735
735
|
};
|
|
736
736
|
}
|
|
737
|
-
},
|
|
738
|
-
function
|
|
739
|
-
if (!
|
|
740
|
-
|
|
741
|
-
for (let e of
|
|
737
|
+
}, pe = "any = #\n\nuint = #0\nnint = #1\nint = uint / nint\n\nbstr = #2\nbytes = bstr\ntstr = #3\ntext = tstr\n\ntdate = #6.0(tstr)\ntime = #6.1(number)\nnumber = int / float\nbiguint = #6.2(bstr)\nbignint = #6.3(bstr)\nbigint = biguint / bignint\ninteger = int / bigint\nunsigned = uint / biguint\ndecfrac = #6.4([e10: int, m: integer])\nbigfloat = #6.5([e2: int, m: integer])\neb64url = #6.21(any)\neb64legacy = #6.22(any)\neb16 = #6.23(any)\nencoded-cbor = #6.24(bstr)\nuri = #6.32(tstr)\nb64url = #6.33(tstr)\nb64legacy = #6.34(tstr)\nregexp = #6.35(tstr)\nmime-message = #6.36(tstr)\ncbor-any = #6.55799(any)\n\nfloat16 = #7.25\nfloat32 = #7.26\nfloat64 = #7.27\nfloat16-32 = float16 / float32\nfloat32-64 = float32 / float64\nfloat = float16-32 / float64\n\nfalse = #7.20\ntrue = #7.21\nbool = false / true\nnil = #7.22\nnull = nil\nundefined = #7.23\n", C;
|
|
738
|
+
function w() {
|
|
739
|
+
if (!C) {
|
|
740
|
+
C = /* @__PURE__ */ new Map();
|
|
741
|
+
for (let e of S(pe).rules) C.set(e.name, e);
|
|
742
742
|
}
|
|
743
|
-
return
|
|
743
|
+
return C;
|
|
744
744
|
}
|
|
745
745
|
//#endregion
|
|
746
746
|
//#region src/cddl/writer.ts
|
|
747
|
-
var
|
|
747
|
+
var me = {
|
|
748
748
|
leading: [],
|
|
749
749
|
trailing: []
|
|
750
750
|
};
|
|
751
|
-
function
|
|
751
|
+
function he(e, t) {
|
|
752
752
|
let n = {
|
|
753
753
|
unit: t?.indent === void 0 ? null : typeof t.indent == "string" ? t.indent : " ".repeat(t.indent),
|
|
754
754
|
notes: null,
|
|
@@ -756,18 +756,18 @@ function _e(e, t) {
|
|
|
756
756
|
tail: []
|
|
757
757
|
};
|
|
758
758
|
if (t?.preserveComments && t.comments !== void 0 && t.comments.length > 0 && t.source !== void 0) {
|
|
759
|
-
let r =
|
|
759
|
+
let r = ge(e, t.comments, t.source);
|
|
760
760
|
n.notes = r.notes, n.endNotes = r.endNotes, n.tail = r.tail;
|
|
761
761
|
}
|
|
762
762
|
let r = [], i = !1;
|
|
763
763
|
e.forEach((e, t) => {
|
|
764
|
-
let { text: a, multiline: o } =
|
|
764
|
+
let { text: a, multiline: o } = ve(e, n);
|
|
765
765
|
t > 0 && n.unit !== null && (o || i) && r.push(""), r.push(a), i = o;
|
|
766
766
|
});
|
|
767
767
|
for (let e of n.tail) r.push(`;${e}`);
|
|
768
768
|
return r.length === 0 ? "" : r.join("\n") + "\n";
|
|
769
769
|
}
|
|
770
|
-
function
|
|
770
|
+
function ge(e, t, n) {
|
|
771
771
|
let r = [0];
|
|
772
772
|
for (let e = 0; e < n.length; e++) n.charCodeAt(e) === 10 && r.push(e + 1);
|
|
773
773
|
let i = (e) => {
|
|
@@ -857,9 +857,9 @@ function ve(e, t, n) {
|
|
|
857
857
|
tail: h
|
|
858
858
|
};
|
|
859
859
|
}
|
|
860
|
-
var
|
|
861
|
-
function
|
|
862
|
-
let n =
|
|
860
|
+
var T = (e, t) => e.notes?.get(t) ?? me, _e = (e) => e.trailing.length === 0 ? "" : " " + e.trailing.map((e) => `;${e}`).join(" ");
|
|
861
|
+
function ve(e, t) {
|
|
862
|
+
let n = T(t, e), r = T(t, e.body), i = e.generics ? `<${e.generics.join(", ")}>` : "", a = `${e.name}${i} ${e.assign}`, o = _e({
|
|
863
863
|
leading: [],
|
|
864
864
|
trailing: [...r.trailing, ...n.trailing]
|
|
865
865
|
}), s, c = n.leading;
|
|
@@ -868,9 +868,9 @@ function be(e, t) {
|
|
|
868
868
|
s = [
|
|
869
869
|
a,
|
|
870
870
|
...r.leading.map((e) => `${n};${e}`),
|
|
871
|
-
`${n}${
|
|
871
|
+
`${n}${E(e.body, t, 1)}${o}`
|
|
872
872
|
].join("\n");
|
|
873
|
-
} else r.leading.length > 0 && (c = [...c, ...r.leading]), s = `${a} ${
|
|
873
|
+
} else r.leading.length > 0 && (c = [...c, ...r.leading]), s = `${a} ${E(e.body, t, 0)}${o}`;
|
|
874
874
|
let l = s.includes("\n");
|
|
875
875
|
return c.length === 0 ? {
|
|
876
876
|
text: s,
|
|
@@ -880,80 +880,80 @@ function be(e, t) {
|
|
|
880
880
|
multiline: l
|
|
881
881
|
};
|
|
882
882
|
}
|
|
883
|
-
function
|
|
884
|
-
let r = e.occur ? `${
|
|
885
|
-
return e.kind === "entry-group" ? `${r}${
|
|
883
|
+
function E(e, t, n) {
|
|
884
|
+
let r = e.occur ? `${ye(e.occur)} ` : "";
|
|
885
|
+
return e.kind === "entry-group" ? `${r}${D(e.group, t, n, "(", ")")}` : `${r}${e.memberKey ? `${be(e.memberKey, t, n)} ` : ""}${O(e.value, t, n)}`;
|
|
886
886
|
}
|
|
887
|
-
function
|
|
887
|
+
function ye(e) {
|
|
888
888
|
return e.marker === "*" ? `${e.min ?? ""}*${e.max ?? ""}` : e.marker;
|
|
889
889
|
}
|
|
890
|
-
function
|
|
890
|
+
function be(e, t, n) {
|
|
891
891
|
switch (e.kind) {
|
|
892
892
|
case "bareword": return `${e.key}:`;
|
|
893
893
|
case "value": return `${e.key.raw}:`;
|
|
894
|
-
case "type1": return `${
|
|
894
|
+
case "type1": return `${xe(e.key, t, n)} ${e.cut ? "^ " : ""}=>`;
|
|
895
895
|
}
|
|
896
896
|
}
|
|
897
|
-
function
|
|
897
|
+
function D(e, t, n, r, i) {
|
|
898
898
|
let a = e.choices.reduce((e, t) => e + t.length, 0), o = t.endNotes?.get(e) ?? [], s = o.length > 0 || t.notes !== null && e.choices.some((e) => e.some((e) => t.notes.has(e)));
|
|
899
|
-
if (!(t.unit !== null && (a > 1 || e.choices.length > 1 || s))) return `${r}${e.choices.map((e) => e.map((e) =>
|
|
899
|
+
if (!(t.unit !== null && (a > 1 || e.choices.length > 1 || s))) return `${r}${e.choices.map((e) => e.map((e) => E(e, t, n)).join(", ")).join(" // ") + (e.trailingComma ? "," : "")}${i}`;
|
|
900
900
|
let c = t.unit, l = c.repeat(n + 1), u = [r];
|
|
901
901
|
e.choices.forEach((r, i) => {
|
|
902
902
|
i > 0 && u.push(`${l}//`), r.forEach((a, o) => {
|
|
903
|
-
let s =
|
|
903
|
+
let s = T(t, a);
|
|
904
904
|
for (let e of s.leading) u.push(`${l};${e}`);
|
|
905
905
|
let c = !(i === e.choices.length - 1 && o === r.length - 1) || e.trailingComma ? "," : "";
|
|
906
|
-
u.push(`${l}${
|
|
906
|
+
u.push(`${l}${E(a, t, n + 1)}${c}${_e(s)}`);
|
|
907
907
|
});
|
|
908
908
|
});
|
|
909
909
|
for (let e of o) u.push(`${l};${e}`);
|
|
910
910
|
return u.push(`${c.repeat(n)}${i}`), u.join("\n");
|
|
911
911
|
}
|
|
912
|
-
function
|
|
913
|
-
return e.alternatives.map((e) =>
|
|
912
|
+
function O(e, t, n) {
|
|
913
|
+
return e.alternatives.map((e) => xe(e, t, n)).join(" / ");
|
|
914
914
|
}
|
|
915
|
-
function
|
|
915
|
+
function xe(e, t, n) {
|
|
916
916
|
let r = Ce(e.target, t, n);
|
|
917
917
|
if (!e.op || !e.controller) return r;
|
|
918
918
|
let i = Ce(e.controller, t, n);
|
|
919
919
|
return e.op.kind === "range" ? `${r}${e.op.inclusive ? ".." : "..."}${i}` : `${r} .${e.op.name} ${i}`;
|
|
920
920
|
}
|
|
921
|
-
function
|
|
922
|
-
let r = e.genericArgs ? `<${e.genericArgs.map((e) =>
|
|
921
|
+
function Se(e, t, n) {
|
|
922
|
+
let r = e.genericArgs ? `<${e.genericArgs.map((e) => xe(e, t, n)).join(", ")}>` : "";
|
|
923
923
|
return `${e.name}${r}`;
|
|
924
924
|
}
|
|
925
925
|
function Ce(e, t, n) {
|
|
926
926
|
switch (e.kind) {
|
|
927
927
|
case "value": return e.raw;
|
|
928
|
-
case "ref": return
|
|
929
|
-
case "paren": return `(${
|
|
930
|
-
case "map": return
|
|
931
|
-
case "array": return
|
|
932
|
-
case "unwrap": return `~${
|
|
933
|
-
case "enum": return e.group.kind === "ref" ? `&${
|
|
934
|
-
case "tagged": return `${e.raw ?? (typeof e.tag == "object" ? `#6.<${
|
|
935
|
-
case "major": return e.raw === void 0 ? typeof e.ai == "object" ? `#${e.major}.<${
|
|
928
|
+
case "ref": return Se(e, t, n);
|
|
929
|
+
case "paren": return `(${O(e.type, t, n)})`;
|
|
930
|
+
case "map": return D(e.group, t, n, "{", "}");
|
|
931
|
+
case "array": return D(e.group, t, n, "[", "]");
|
|
932
|
+
case "unwrap": return `~${Se(e.ref, t, n)}`;
|
|
933
|
+
case "enum": return e.group.kind === "ref" ? `&${Se(e.group, t, n)}` : `&${D(e.group, t, n, "(", ")")}`;
|
|
934
|
+
case "tagged": return `${e.raw ?? (typeof e.tag == "object" ? `#6.<${O(e.tag, t, n)}>` : `#6${e.tag === void 0 ? "" : `.${e.tag}`}`)}(${O(e.item, t, n)})`;
|
|
935
|
+
case "major": return e.raw === void 0 ? typeof e.ai == "object" ? `#${e.major}.<${O(e.ai, t, n)}>` : `#${e.major}${e.ai === void 0 ? "" : `.${e.ai}`}` : e.raw;
|
|
936
936
|
case "any": return "#";
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
939
|
//#endregion
|
|
940
940
|
//#region src/cddl/equal.ts
|
|
941
941
|
function k(e) {
|
|
942
|
-
if (e instanceof
|
|
943
|
-
if (e instanceof
|
|
942
|
+
if (e instanceof i || e instanceof u) return e.value;
|
|
943
|
+
if (e instanceof ne || e instanceof f) return e.bigValue;
|
|
944
944
|
}
|
|
945
945
|
function A(e) {
|
|
946
|
-
if (e instanceof
|
|
947
|
-
if (e instanceof
|
|
946
|
+
if (e instanceof h) return e.value;
|
|
947
|
+
if (e instanceof l) return e.chunks.map((e) => e.value).join("");
|
|
948
948
|
}
|
|
949
949
|
function j(e) {
|
|
950
|
-
if (e instanceof
|
|
951
|
-
if (e instanceof
|
|
950
|
+
if (e instanceof t) return e.value;
|
|
951
|
+
if (e instanceof ee) {
|
|
952
952
|
let t = e.chunks.map((e) => e.value), n = t.reduce((e, t) => e + t.length, 0), r = new Uint8Array(n), i = 0;
|
|
953
953
|
for (let e of t) r.set(e, i), i += e.length;
|
|
954
954
|
return r;
|
|
955
955
|
}
|
|
956
|
-
if (e instanceof
|
|
956
|
+
if (e instanceof re) {
|
|
957
957
|
let t = e.items.map((e) => e.toCBOR()), n = t.reduce((e, t) => e + t.length, 0), r = new Uint8Array(n), i = 0;
|
|
958
958
|
for (let e of t) r.set(e, i), i += e.length;
|
|
959
959
|
return r;
|
|
@@ -975,36 +975,36 @@ var Te = new TextEncoder(), Ee = new TextDecoder("utf-8", { fatal: !0 }), M = (e
|
|
|
975
975
|
}), De = (e) => {
|
|
976
976
|
let t = k(e);
|
|
977
977
|
if (t !== void 0) return t;
|
|
978
|
-
if (e instanceof
|
|
978
|
+
if (e instanceof s) return e.value;
|
|
979
979
|
}, N = (e) => e.type === "int" || e.type === "float" ? e.value : void 0, Oe = (e, t) => {
|
|
980
980
|
if (typeof e == "bigint" && typeof t == "bigint") return e < t ? -1 : +(e > t);
|
|
981
981
|
let n = Number(e), r = Number(t);
|
|
982
982
|
return n < r ? -1 : n > r ? 1 : n === r ? 0 : NaN;
|
|
983
|
-
}, ke = (e, t, n, r,
|
|
984
|
-
if (!e.matchType2(t, n,
|
|
985
|
-
let
|
|
986
|
-
if (
|
|
987
|
-
let
|
|
988
|
-
if (
|
|
989
|
-
if (t instanceof
|
|
983
|
+
}, ke = (e, t, n, r, a, o) => {
|
|
984
|
+
if (!e.matchType2(t, n, a)) return !1;
|
|
985
|
+
let s = (n) => e.matchType2(e.uint(n), r, a) ? !0 : e.fail(a, t, o, `size ${n} does not match the .size constraint`), c = A(t);
|
|
986
|
+
if (c !== void 0) return s(Te.encode(c).length);
|
|
987
|
+
let l = j(t);
|
|
988
|
+
if (l !== void 0) return s(l.length);
|
|
989
|
+
if (t instanceof i) {
|
|
990
990
|
let n = 0;
|
|
991
991
|
for (let e = t.value; e > 0n; e >>= 8n) n++;
|
|
992
|
-
let
|
|
993
|
-
if (
|
|
994
|
-
e.warnOnce(".size controller could not be analyzed; searching a bounded window of byte counts",
|
|
995
|
-
for (let t = n; t <= n + 64; t++) if (e.matchType2(e.uint(t), r,
|
|
996
|
-
return e.fail(
|
|
997
|
-
}
|
|
998
|
-
return e.fail(
|
|
999
|
-
}, Ae = (e, t, n, r,
|
|
1000
|
-
if (!e.matchType2(t, n,
|
|
1001
|
-
let
|
|
1002
|
-
if (
|
|
1003
|
-
else if (t instanceof
|
|
992
|
+
let i = e.existsIntGE(r, BigInt(n));
|
|
993
|
+
if (i !== void 0) return i ? !0 : e.fail(a, t, o, `${t.value} does not fit the .size constraint`);
|
|
994
|
+
e.warnOnce(".size controller could not be analyzed; searching a bounded window of byte counts", o);
|
|
995
|
+
for (let t = n; t <= n + 64; t++) if (e.matchType2(e.uint(t), r, a)) return !0;
|
|
996
|
+
return e.fail(a, t, o, `${t.value} does not fit the .size constraint`);
|
|
997
|
+
}
|
|
998
|
+
return e.fail(a, t, o, ".size applies to strings and unsigned integers");
|
|
999
|
+
}, Ae = (e, t, n, r, a, o) => {
|
|
1000
|
+
if (!e.matchType2(t, n, a)) return !1;
|
|
1001
|
+
let s = [], c = j(t);
|
|
1002
|
+
if (c !== void 0) for (let e = 0; e < c.length; e++) for (let t = 0; t < 8; t++) c[e] & 1 << t && s.push(e * 8 + t);
|
|
1003
|
+
else if (t instanceof i) {
|
|
1004
1004
|
let e = t.value;
|
|
1005
|
-
for (let t = 0; e > 0n; t++, e >>= 1n) e & 1n &&
|
|
1006
|
-
} else return e.fail(
|
|
1007
|
-
for (let n of
|
|
1005
|
+
for (let t = 0; e > 0n; t++, e >>= 1n) e & 1n && s.push(t);
|
|
1006
|
+
} else return e.fail(a, t, o, ".bits applies to byte strings and unsigned integers");
|
|
1007
|
+
for (let n of s) if (!e.matchType2(e.uint(n), r, a)) return e.fail(a, t, o, `bit ${n} is set but not allowed by .bits`);
|
|
1008
1008
|
return !0;
|
|
1009
1009
|
}, je = /* @__PURE__ */ new Map(), Me = (e, t, n, r, i, a) => {
|
|
1010
1010
|
if (!e.matchType2(t, n, i)) return !1;
|
|
@@ -1030,8 +1030,8 @@ var Te = new TextEncoder(), Ee = new TextDecoder("utf-8", { fatal: !0 }), M = (e
|
|
|
1030
1030
|
try {
|
|
1031
1031
|
if (e) {
|
|
1032
1032
|
let e = new Uint8Array(s.length + 2);
|
|
1033
|
-
e[0] = 159, e.set(s, 1), e[e.length - 1] = 255, c =
|
|
1034
|
-
} else c =
|
|
1033
|
+
e[0] = 159, e.set(s, 1), e[e.length - 1] = 255, c = te(e);
|
|
1034
|
+
} else c = te(s);
|
|
1035
1035
|
} catch (e) {
|
|
1036
1036
|
return t.fail(a, n, o, `byte string does not contain valid CBOR: ${e instanceof Error ? e.message : String(e)}`);
|
|
1037
1037
|
}
|
|
@@ -1132,7 +1132,7 @@ function Ue(e) {
|
|
|
1132
1132
|
}
|
|
1133
1133
|
//#endregion
|
|
1134
1134
|
//#region src/cddl/validator.ts
|
|
1135
|
-
var
|
|
1135
|
+
var We = class extends Error {}, Ge = class {
|
|
1136
1136
|
schema;
|
|
1137
1137
|
maxDepth;
|
|
1138
1138
|
maxSteps;
|
|
@@ -1149,10 +1149,10 @@ var F = class extends Error {}, We = class {
|
|
|
1149
1149
|
this.schema = e, this.maxDepth = t, this.maxSteps = n, this.features = r;
|
|
1150
1150
|
}
|
|
1151
1151
|
step() {
|
|
1152
|
-
if (++this.steps > this.maxSteps) throw new
|
|
1152
|
+
if (++this.steps > this.maxSteps) throw new We(`validation aborted: step budget of ${this.maxSteps} exceeded (pathological backtracking?)`);
|
|
1153
1153
|
}
|
|
1154
1154
|
checkDepth(e) {
|
|
1155
|
-
if (e > this.maxDepth) throw new
|
|
1155
|
+
if (e > this.maxDepth) throw new We(`validation aborted: recursion depth ${this.maxDepth} exceeded (cyclic rules without progress?)`);
|
|
1156
1156
|
}
|
|
1157
1157
|
warnOnce(e, t) {
|
|
1158
1158
|
let n = `${e}@${t?.start ?? -1}`;
|
|
@@ -1187,7 +1187,7 @@ var F = class extends Error {}, We = class {
|
|
|
1187
1187
|
return !1;
|
|
1188
1188
|
}
|
|
1189
1189
|
};
|
|
1190
|
-
function
|
|
1190
|
+
function Ke(e, t, n) {
|
|
1191
1191
|
let r = n?.rule ?? e.root?.name;
|
|
1192
1192
|
if (r === void 0) return {
|
|
1193
1193
|
valid: !1,
|
|
@@ -1196,7 +1196,7 @@ function Ge(e, t, n) {
|
|
|
1196
1196
|
path: "/"
|
|
1197
1197
|
}]
|
|
1198
1198
|
};
|
|
1199
|
-
let i = new
|
|
1199
|
+
let i = new Ge(e, n?.maxDepth ?? 256, n?.maxSteps ?? 1e6, new Set(n?.features ?? [])), a = F(i, r)?.[0]?.generics?.length ?? 0;
|
|
1200
1200
|
if (a > 0) return {
|
|
1201
1201
|
valid: !1,
|
|
1202
1202
|
errors: [{
|
|
@@ -1206,9 +1206,9 @@ function Ge(e, t, n) {
|
|
|
1206
1206
|
};
|
|
1207
1207
|
let o;
|
|
1208
1208
|
try {
|
|
1209
|
-
o =
|
|
1209
|
+
o = Ye(t, r, void 0, [], i, 0);
|
|
1210
1210
|
} catch (e) {
|
|
1211
|
-
if (!(e instanceof
|
|
1211
|
+
if (!(e instanceof We)) throw e;
|
|
1212
1212
|
return {
|
|
1213
1213
|
valid: !1,
|
|
1214
1214
|
errors: [{
|
|
@@ -1235,22 +1235,22 @@ function Ge(e, t, n) {
|
|
|
1235
1235
|
...i.warnings.length ? { warnings: i.warnings } : {}
|
|
1236
1236
|
};
|
|
1237
1237
|
}
|
|
1238
|
-
function
|
|
1238
|
+
function F(e, t) {
|
|
1239
1239
|
let n = e.schema.rules.get(t);
|
|
1240
1240
|
if (n) return n;
|
|
1241
|
-
let r =
|
|
1241
|
+
let r = w().get(t);
|
|
1242
1242
|
return r ? [r] : void 0;
|
|
1243
1243
|
}
|
|
1244
|
-
function
|
|
1244
|
+
function I(e) {
|
|
1245
1245
|
return e.kind === "entry" && !e.occur && !e.memberKey;
|
|
1246
1246
|
}
|
|
1247
|
-
function
|
|
1247
|
+
function qe(e) {
|
|
1248
1248
|
return e.kind === "entry-group" && !e.occur ? e.group.choices : [[e]];
|
|
1249
1249
|
}
|
|
1250
|
-
function
|
|
1251
|
-
return e.some((e) => !
|
|
1250
|
+
function Je(e) {
|
|
1251
|
+
return e.some((e) => !I(e.body));
|
|
1252
1252
|
}
|
|
1253
|
-
function
|
|
1253
|
+
function L(e, t, n) {
|
|
1254
1254
|
let r = e.generics;
|
|
1255
1255
|
if (!r || !t) return;
|
|
1256
1256
|
let i = /* @__PURE__ */ new Map();
|
|
@@ -1260,8 +1260,8 @@ function z(e, t, n) {
|
|
|
1260
1260
|
});
|
|
1261
1261
|
return i;
|
|
1262
1262
|
}
|
|
1263
|
-
function
|
|
1264
|
-
let c =
|
|
1263
|
+
function Ye(e, t, n, r, i, a, o, s) {
|
|
1264
|
+
let c = F(i, t);
|
|
1265
1265
|
if (!c) return i.fail(r, e, o, t.startsWith("$") ? `socket '${t}' has no definitions, so nothing matches it` : `'${t}' is not defined`);
|
|
1266
1266
|
i.checkDepth(a);
|
|
1267
1267
|
let l = i.ruleName;
|
|
@@ -1270,13 +1270,13 @@ function qe(e, t, n, r, i, a, o, s) {
|
|
|
1270
1270
|
u && ++i.preludeDepth === 1 && (i.preludeRef = o);
|
|
1271
1271
|
try {
|
|
1272
1272
|
for (let o of c) {
|
|
1273
|
-
let c =
|
|
1274
|
-
if (
|
|
1275
|
-
if (
|
|
1273
|
+
let c = L(o, s, n);
|
|
1274
|
+
if (I(o.body)) {
|
|
1275
|
+
if (R(e, o.body.value, c, r, i, a + 1)) return !0;
|
|
1276
1276
|
continue;
|
|
1277
1277
|
}
|
|
1278
|
-
let l =
|
|
1279
|
-
for (let e of l) if (!(e.length === 1 &&
|
|
1278
|
+
let l = qe(o.body), u = !0;
|
|
1279
|
+
for (let e of l) if (!(e.length === 1 && I(e[0]))) {
|
|
1280
1280
|
u = !1;
|
|
1281
1281
|
break;
|
|
1282
1282
|
}
|
|
@@ -1286,7 +1286,7 @@ function qe(e, t, n, r, i, a, o, s) {
|
|
|
1286
1286
|
}
|
|
1287
1287
|
for (let t of l) {
|
|
1288
1288
|
let n = t[0];
|
|
1289
|
-
if (
|
|
1289
|
+
if (R(e, n.value, c, r, i, a + 1)) return !0;
|
|
1290
1290
|
}
|
|
1291
1291
|
}
|
|
1292
1292
|
return !1;
|
|
@@ -1294,68 +1294,68 @@ function qe(e, t, n, r, i, a, o, s) {
|
|
|
1294
1294
|
i.ruleName = l, u && --i.preludeDepth === 0 && (i.preludeRef = void 0);
|
|
1295
1295
|
}
|
|
1296
1296
|
}
|
|
1297
|
-
function
|
|
1298
|
-
for (; e instanceof
|
|
1297
|
+
function Xe(e) {
|
|
1298
|
+
for (; e instanceof p;) e = e.inner;
|
|
1299
1299
|
return e;
|
|
1300
1300
|
}
|
|
1301
|
-
function
|
|
1302
|
-
for (let o of t.alternatives) if (
|
|
1301
|
+
function R(e, t, n, r, i, a) {
|
|
1302
|
+
for (let o of t.alternatives) if (z(e, o, n, r, i, a)) return !0;
|
|
1303
1303
|
return !1;
|
|
1304
1304
|
}
|
|
1305
|
-
function
|
|
1306
|
-
if (i.step(), e =
|
|
1307
|
-
if (t.op.kind === "range") return
|
|
1305
|
+
function z(e, t, n, r, i, a) {
|
|
1306
|
+
if (i.step(), e = Xe(e), !t.op || !t.controller) return B(e, t.target, n, r, i, a);
|
|
1307
|
+
if (t.op.kind === "range") return it(e, t, n, r, i, a);
|
|
1308
1308
|
let o = Ue(t.op.name), s = Ct(n, i, a);
|
|
1309
|
-
return o ? o(s, e, t.target, t.controller, r, t) : (i.warnOnce(`control operator .${t.op.name} is not supported; matching the target only`, t),
|
|
1309
|
+
return o ? o(s, e, t.target, t.controller, r, t) : (i.warnOnce(`control operator .${t.op.name} is not supported; matching the target only`, t), B(e, t.target, n, r, i, a));
|
|
1310
1310
|
}
|
|
1311
|
-
function
|
|
1312
|
-
if (e =
|
|
1313
|
-
switch (
|
|
1311
|
+
function B(e, t, a, o, s, c) {
|
|
1312
|
+
if (e = Xe(e), e instanceof _) return !0;
|
|
1313
|
+
switch (t.kind) {
|
|
1314
1314
|
case "any": return !0;
|
|
1315
|
-
case "value": return
|
|
1315
|
+
case "value": return H(e, t) ? !0 : s.fail(o, e, t, `expected the value ${t.raw}`);
|
|
1316
1316
|
case "ref": {
|
|
1317
|
-
let
|
|
1318
|
-
return
|
|
1317
|
+
let n = a?.get(t.name);
|
|
1318
|
+
return n && !t.genericArgs ? z(e, n.type1, n.env, o, s, c + 1) : Ye(e, t.name, a, o, s, c + 1, t, t.genericArgs);
|
|
1319
1319
|
}
|
|
1320
|
-
case "paren": return
|
|
1321
|
-
case "map": return e instanceof
|
|
1322
|
-
case "array": return e instanceof
|
|
1320
|
+
case "paren": return R(e, t.type, a, o, s, c);
|
|
1321
|
+
case "map": return e instanceof r ? _t(e, t.group, a, o, s, c + 1) : s.fail(o, e, t, "expected a map");
|
|
1322
|
+
case "array": return e instanceof n ? pt(e, t.group, a, o, s, c + 1) : s.fail(o, e, t, "expected an array");
|
|
1323
1323
|
case "tagged":
|
|
1324
|
-
if (!(e instanceof
|
|
1325
|
-
if (typeof
|
|
1326
|
-
if (e.tag !==
|
|
1327
|
-
} else if (
|
|
1328
|
-
return
|
|
1329
|
-
case "major": return
|
|
1324
|
+
if (!(e instanceof g)) return s.fail(o, e, t, "expected a tagged item");
|
|
1325
|
+
if (typeof t.tag == "bigint") {
|
|
1326
|
+
if (e.tag !== t.tag) return s.fail(o, e, t, `expected tag ${t.tag}, got ${e.tag}`);
|
|
1327
|
+
} else if (t.tag !== void 0 && !R(new i(e.tag), t.tag, a, o, s, c + 1)) return s.fail(o, e, t, `tag number ${e.tag} does not match the head type`);
|
|
1328
|
+
return R(e.content, t.item, a, o, s, c + 1);
|
|
1329
|
+
case "major": return ot(e, t, a, o, s, c);
|
|
1330
1330
|
case "unwrap": {
|
|
1331
|
-
let
|
|
1332
|
-
return
|
|
1331
|
+
let n = dt(t.ref, a, s, 0);
|
|
1332
|
+
return n ? R(e, n.type, n.env, o, s, c + 1) : (s.warnOnce(`~${t.ref.name} is used outside of an array/map group context`, t), s.fail(o, e, t, `~${t.ref.name} cannot match here`));
|
|
1333
1333
|
}
|
|
1334
1334
|
case "enum": {
|
|
1335
|
-
let
|
|
1336
|
-
return
|
|
1335
|
+
let n = t.group.kind === "ref" ? X(t.group, a, s) : Y(t.group, a);
|
|
1336
|
+
return n ? (s.checkDepth(c), V(e, n, o, s, c + 1) ? !0 : s.fail(o, e, t, "no enumeration value matches")) : s.fail(o, e, t, "'&' target does not resolve to a group");
|
|
1337
1337
|
}
|
|
1338
1338
|
}
|
|
1339
1339
|
}
|
|
1340
|
-
function
|
|
1340
|
+
function V(e, t, n, r, i) {
|
|
1341
1341
|
for (let { entries: a, env: o } of t) for (let t of a) {
|
|
1342
1342
|
if (r.step(), t.kind === "entry-group") {
|
|
1343
|
-
if (
|
|
1343
|
+
if (V(e, Y(t.group, o), n, r, i + 1)) return !0;
|
|
1344
1344
|
continue;
|
|
1345
1345
|
}
|
|
1346
1346
|
let a = lt(t, o, r);
|
|
1347
1347
|
if (a) {
|
|
1348
|
-
if (r.checkDepth(i),
|
|
1348
|
+
if (r.checkDepth(i), V(e, a, n, r, i + 1)) return !0;
|
|
1349
1349
|
continue;
|
|
1350
1350
|
}
|
|
1351
|
-
if (
|
|
1351
|
+
if (R(e, t.value, o, n, r, i + 1)) return !0;
|
|
1352
1352
|
}
|
|
1353
1353
|
return !1;
|
|
1354
1354
|
}
|
|
1355
|
-
function
|
|
1355
|
+
function H(e, t) {
|
|
1356
1356
|
switch (t.type) {
|
|
1357
1357
|
case "int": return k(e) === BigInt(t.value);
|
|
1358
|
-
case "float": return e instanceof
|
|
1358
|
+
case "float": return e instanceof s && (e.value === t.value || Number.isNaN(e.value) && Number.isNaN(t.value));
|
|
1359
1359
|
case "text": return A(e) === t.value;
|
|
1360
1360
|
case "bytes": {
|
|
1361
1361
|
let n = j(e);
|
|
@@ -1363,33 +1363,33 @@ function U(e, t) {
|
|
|
1363
1363
|
}
|
|
1364
1364
|
}
|
|
1365
1365
|
}
|
|
1366
|
-
function
|
|
1366
|
+
function U(e, t, n, r = 0) {
|
|
1367
1367
|
if (r > 32) return;
|
|
1368
1368
|
if (e.kind === "value") return e;
|
|
1369
1369
|
if (e.kind === "paren") {
|
|
1370
1370
|
let i = e.type.alternatives.length === 1 ? e.type.alternatives[0] : void 0;
|
|
1371
|
-
return !i || i.op ? void 0 :
|
|
1371
|
+
return !i || i.op ? void 0 : U(i.target, t, n, r + 1);
|
|
1372
1372
|
}
|
|
1373
1373
|
if (e.kind !== "ref") return;
|
|
1374
1374
|
let i = t?.get(e.name);
|
|
1375
|
-
if (i && !e.genericArgs) return i.type1.op ? void 0 :
|
|
1376
|
-
let a =
|
|
1375
|
+
if (i && !e.genericArgs) return i.type1.op ? void 0 : U(i.type1.target, i.env, n, r + 1);
|
|
1376
|
+
let a = F(n, e.name);
|
|
1377
1377
|
if (!a || a.length !== 1) return;
|
|
1378
1378
|
let o = a[0].body;
|
|
1379
|
-
if (!
|
|
1379
|
+
if (!I(o) || o.value.alternatives.length !== 1) return;
|
|
1380
1380
|
let s = o.value.alternatives[0];
|
|
1381
1381
|
if (s.op) return;
|
|
1382
|
-
let c =
|
|
1383
|
-
return
|
|
1382
|
+
let c = L(a[0], e.genericArgs, t);
|
|
1383
|
+
return U(s.target, c, n, r + 1);
|
|
1384
1384
|
}
|
|
1385
|
-
function
|
|
1386
|
-
return
|
|
1385
|
+
function Ze(e, t, n, r, i = 0) {
|
|
1386
|
+
return Qe(e, t, void 0, n, r, i);
|
|
1387
1387
|
}
|
|
1388
|
-
function
|
|
1389
|
-
let o =
|
|
1388
|
+
function Qe(e, t, n, r, i, a = 0) {
|
|
1389
|
+
let o = W(e, t, n, r, i, a);
|
|
1390
1390
|
return o === void 0 ? void 0 : o !== null;
|
|
1391
1391
|
}
|
|
1392
|
-
function
|
|
1392
|
+
function W(e, t, n, r, i, a = 0) {
|
|
1393
1393
|
if (n !== void 0 && t > n) return null;
|
|
1394
1394
|
if (!(a > 32)) switch (e.kind) {
|
|
1395
1395
|
case "value":
|
|
@@ -1413,25 +1413,25 @@ function G(e, t, n, r, i, a = 0) {
|
|
|
1413
1413
|
return e <= -1n && (n === void 0 || e <= n) ? e : null;
|
|
1414
1414
|
}
|
|
1415
1415
|
return null;
|
|
1416
|
-
case "paren": return
|
|
1416
|
+
case "paren": return G(e.type, t, n, r, i, a + 1);
|
|
1417
1417
|
case "ref": {
|
|
1418
1418
|
let o = r?.get(e.name);
|
|
1419
|
-
if (o && !e.genericArgs) return
|
|
1420
|
-
let s =
|
|
1419
|
+
if (o && !e.genericArgs) return $e(o.type1, t, n, o.env, i, a + 1);
|
|
1420
|
+
let s = F(i, e.name);
|
|
1421
1421
|
if (!s) return;
|
|
1422
1422
|
let c = !1, l = null;
|
|
1423
1423
|
for (let o of s) {
|
|
1424
|
-
if (!
|
|
1424
|
+
if (!I(o.body)) {
|
|
1425
1425
|
c = !0;
|
|
1426
1426
|
continue;
|
|
1427
1427
|
}
|
|
1428
|
-
let s =
|
|
1428
|
+
let s = L(o, e.genericArgs, r), u = G(o.body.value, t, n, s, i, a + 1);
|
|
1429
1429
|
typeof u == "bigint" && (l === null || u < l) && (l = u), u === void 0 && (c = !0);
|
|
1430
1430
|
}
|
|
1431
1431
|
return l ?? (c ? void 0 : null);
|
|
1432
1432
|
}
|
|
1433
1433
|
case "enum": {
|
|
1434
|
-
let o = e.group.kind === "ref" ?
|
|
1434
|
+
let o = e.group.kind === "ref" ? X(e.group, r, i) : Y(e.group, r);
|
|
1435
1435
|
if (!o) return;
|
|
1436
1436
|
let s = !1, c = null;
|
|
1437
1437
|
for (let { entries: e, env: r } of o) for (let o of e) {
|
|
@@ -1439,7 +1439,7 @@ function G(e, t, n, r, i, a = 0) {
|
|
|
1439
1439
|
s = !0;
|
|
1440
1440
|
continue;
|
|
1441
1441
|
}
|
|
1442
|
-
let e =
|
|
1442
|
+
let e = G(o.value, t, n, r, i, a + 1);
|
|
1443
1443
|
typeof e == "bigint" && (c === null || e < c) && (c = e), e === void 0 && (s = !0);
|
|
1444
1444
|
}
|
|
1445
1445
|
return c ?? (s ? void 0 : null);
|
|
@@ -1447,93 +1447,93 @@ function G(e, t, n, r, i, a = 0) {
|
|
|
1447
1447
|
default: return;
|
|
1448
1448
|
}
|
|
1449
1449
|
}
|
|
1450
|
-
function
|
|
1450
|
+
function G(e, t, n, r, i, a) {
|
|
1451
1451
|
let o = !1, s = null;
|
|
1452
1452
|
for (let c of e.alternatives) {
|
|
1453
|
-
let e =
|
|
1453
|
+
let e = $e(c, t, n, r, i, a);
|
|
1454
1454
|
typeof e == "bigint" && (s === null || e < s) && (s = e), e === void 0 && (o = !0);
|
|
1455
1455
|
}
|
|
1456
1456
|
return s ?? (o ? void 0 : null);
|
|
1457
1457
|
}
|
|
1458
|
-
function
|
|
1459
|
-
if (!e.op) return
|
|
1458
|
+
function $e(e, t, n, r, i, a) {
|
|
1459
|
+
if (!e.op) return W(e.target, t, n, r, i, a);
|
|
1460
1460
|
if (e.op.kind === "ctl") {
|
|
1461
|
-
if (e.op.name === "bits") return
|
|
1461
|
+
if (e.op.name === "bits") return tt(e.target, e.controller, t, n, r, i, a + 1);
|
|
1462
1462
|
if (e.op.name === "size") {
|
|
1463
|
-
let o =
|
|
1463
|
+
let o = W(e.target, t > 0n ? t : 0n, n, r, i, a + 1);
|
|
1464
1464
|
if (o == null) return o;
|
|
1465
|
-
let s =
|
|
1465
|
+
let s = Ze(e.controller, BigInt(rt(o)), r, i, a + 1);
|
|
1466
1466
|
return s === void 0 ? void 0 : s ? o : null;
|
|
1467
1467
|
}
|
|
1468
1468
|
if (e.op.name === "feature") {
|
|
1469
1469
|
let o = Ve(Ct(r, i, a), e.controller);
|
|
1470
|
-
return o === void 0 ? void 0 : i.features.has(o) ?
|
|
1470
|
+
return o === void 0 ? void 0 : i.features.has(o) ? W(e.target, t, n, r, i, a + 1) : (i.warnOnce(`feature "${o}" is not enabled (pass it in options.features to accept it)`, e), null);
|
|
1471
1471
|
}
|
|
1472
|
-
if (e.op.name === "and" || e.op.name === "within") return
|
|
1472
|
+
if (e.op.name === "and" || e.op.name === "within") return et(e.target, e.controller, t, n, r, i, a + 1);
|
|
1473
1473
|
if (e.op.name === "plus") {
|
|
1474
|
-
let a =
|
|
1474
|
+
let a = U(e.target, r, i), o = U(e.controller, r, i);
|
|
1475
1475
|
if (!a || !o || a.type === "text" || a.type === "bytes" || o.type === "text" || o.type === "bytes") return;
|
|
1476
1476
|
if (a.type === "float") return null;
|
|
1477
1477
|
let s = o.type === "int" ? BigInt(a.value) + BigInt(o.value) : BigInt(Math.floor(Number(a.value) + o.value));
|
|
1478
1478
|
return s >= t && (n === void 0 || s <= n) ? s : null;
|
|
1479
1479
|
}
|
|
1480
|
-
let o =
|
|
1480
|
+
let o = U(e.controller, r, i);
|
|
1481
1481
|
if (!o || o.type !== "int") return;
|
|
1482
1482
|
let s = BigInt(o.value);
|
|
1483
1483
|
switch (e.op.name) {
|
|
1484
|
-
case "eq": return
|
|
1484
|
+
case "eq": return W(e.target, s > t ? s : t, n === void 0 || s < n ? s : n, r, i, a + 1);
|
|
1485
1485
|
case "ne":
|
|
1486
1486
|
case "default": {
|
|
1487
|
-
let o =
|
|
1487
|
+
let o = W(e.target, t, n === void 0 || s - 1n < n ? s - 1n : n, r, i, a + 1);
|
|
1488
1488
|
if (typeof o == "bigint") return o;
|
|
1489
|
-
let c =
|
|
1489
|
+
let c = W(e.target, s + 1n > t ? s + 1n : t, n, r, i, a + 1);
|
|
1490
1490
|
return typeof c == "bigint" ? c : o === void 0 || c === void 0 ? void 0 : null;
|
|
1491
1491
|
}
|
|
1492
1492
|
case "lt":
|
|
1493
1493
|
case "le": {
|
|
1494
1494
|
let o = s - (e.op.name === "lt" ? 1n : 0n);
|
|
1495
|
-
return
|
|
1495
|
+
return W(e.target, t, n === void 0 || o < n ? o : n, r, i, a + 1);
|
|
1496
1496
|
}
|
|
1497
1497
|
case "gt":
|
|
1498
1498
|
case "ge": {
|
|
1499
1499
|
let o = s + (e.op.name === "gt" ? 1n : 0n);
|
|
1500
|
-
return
|
|
1500
|
+
return W(e.target, o > t ? o : t, n, r, i, a + 1);
|
|
1501
1501
|
}
|
|
1502
1502
|
default: return;
|
|
1503
1503
|
}
|
|
1504
1504
|
}
|
|
1505
|
-
let o =
|
|
1505
|
+
let o = U(e.target, r, i), s = U(e.controller, r, i);
|
|
1506
1506
|
if (!o || !s || o.type !== "int" || s.type !== "int") return;
|
|
1507
1507
|
let c = BigInt(o.value), l = BigInt(s.value) - (e.op.inclusive ? 0n : 1n), u = c > t ? c : t;
|
|
1508
1508
|
return u <= (n === void 0 || l < n ? l : n) ? u : null;
|
|
1509
1509
|
}
|
|
1510
|
-
function
|
|
1510
|
+
function et(e, t, n, r, i, a, o) {
|
|
1511
1511
|
let s = n;
|
|
1512
1512
|
for (let n = 0; n < 256; n++) {
|
|
1513
|
-
let n =
|
|
1513
|
+
let n = W(e, s, r, i, a, o + 1), c = W(t, s, r, i, a, o + 1);
|
|
1514
1514
|
if (n === null || c === null) return null;
|
|
1515
1515
|
if (n === void 0 || c === void 0) return;
|
|
1516
1516
|
if (n === c) return n;
|
|
1517
1517
|
s = n > c ? n : c;
|
|
1518
1518
|
}
|
|
1519
1519
|
}
|
|
1520
|
-
function
|
|
1520
|
+
function tt(e, t, n, r, i, a, o) {
|
|
1521
1521
|
let s = 0n;
|
|
1522
1522
|
for (let e = 0; e < 64; e++) {
|
|
1523
|
-
let n =
|
|
1523
|
+
let n = W(t, BigInt(e), BigInt(e), i, a, o + 1);
|
|
1524
1524
|
if (n === void 0) return;
|
|
1525
1525
|
n !== null && (s |= 1n << BigInt(e));
|
|
1526
1526
|
}
|
|
1527
1527
|
let c = n > 0n ? n : 0n, l = r === void 0 || r > 18446744073709551615n ? 18446744073709551615n : r;
|
|
1528
1528
|
for (let t = 0; t < 256; t++) {
|
|
1529
|
-
let t =
|
|
1529
|
+
let t = W(e, c, l, i, a, o + 1), n = nt(c, l, s);
|
|
1530
1530
|
if (t === void 0) return;
|
|
1531
1531
|
if (t === null || n === null) return null;
|
|
1532
1532
|
if (t === n) return t;
|
|
1533
1533
|
c = t > n ? t : n;
|
|
1534
1534
|
}
|
|
1535
1535
|
}
|
|
1536
|
-
function
|
|
1536
|
+
function nt(e, t, n) {
|
|
1537
1537
|
if (e < 0n && (e = 0n), e > t) return null;
|
|
1538
1538
|
let r = (i, a, o) => {
|
|
1539
1539
|
if (i < 0) return o <= t ? o : null;
|
|
@@ -1547,77 +1547,77 @@ function tt(e, t, n) {
|
|
|
1547
1547
|
};
|
|
1548
1548
|
return r(63, !1, 0n);
|
|
1549
1549
|
}
|
|
1550
|
-
function
|
|
1550
|
+
function rt(e) {
|
|
1551
1551
|
let t = 0;
|
|
1552
1552
|
for (let n = e; n > 0n; n >>= 8n) t++;
|
|
1553
1553
|
return t;
|
|
1554
1554
|
}
|
|
1555
|
-
function
|
|
1556
|
-
let o = t.op,
|
|
1557
|
-
if (!
|
|
1558
|
-
if (
|
|
1555
|
+
function it(e, t, n, r, i, a) {
|
|
1556
|
+
let o = t.op, c = U(t.target, n, i), l = U(t.controller, n, i);
|
|
1557
|
+
if (!c || !l) return i.warnOnce("range endpoints do not resolve to literal values", t), i.fail(r, e, t, "unresolvable range");
|
|
1558
|
+
if (c.type === "int" && l.type === "int") {
|
|
1559
1559
|
let n = k(e);
|
|
1560
|
-
if (n === void 0) return i.fail(r, e, t, `expected an integer in ${
|
|
1561
|
-
let a = BigInt(
|
|
1562
|
-
return n >= a && (o.inclusive ? n <=
|
|
1560
|
+
if (n === void 0) return i.fail(r, e, t, `expected an integer in ${K(t)}`);
|
|
1561
|
+
let a = BigInt(c.value), s = BigInt(l.value);
|
|
1562
|
+
return n >= a && (o.inclusive ? n <= s : n < s) || i.fail(r, e, t, `${n} is outside ${K(t)}`);
|
|
1563
1563
|
}
|
|
1564
|
-
if (
|
|
1565
|
-
if (!(e instanceof
|
|
1564
|
+
if (c.type === "float" && l.type === "float") {
|
|
1565
|
+
if (!(e instanceof s)) return i.fail(r, e, t, `expected a float in ${K(t)}`);
|
|
1566
1566
|
let n = e.value;
|
|
1567
|
-
return n >=
|
|
1567
|
+
return n >= c.value && (o.inclusive ? n <= l.value : n < l.value) || i.fail(r, e, t, `${n} is outside ${K(t)}`);
|
|
1568
1568
|
}
|
|
1569
1569
|
return i.warnOnce("range endpoints mix integer and float types", t), i.fail(r, e, t, "invalid range");
|
|
1570
1570
|
}
|
|
1571
|
-
function
|
|
1571
|
+
function K(e) {
|
|
1572
1572
|
let t = e.op;
|
|
1573
|
-
return `${
|
|
1573
|
+
return `${q(e.target)}${t.inclusive ? ".." : "..."}${q(e.controller)}`;
|
|
1574
1574
|
}
|
|
1575
|
-
function
|
|
1575
|
+
function q(e) {
|
|
1576
1576
|
return e.kind === "value" ? e.raw : e.kind === "ref" ? e.name : "…";
|
|
1577
1577
|
}
|
|
1578
|
-
var
|
|
1578
|
+
var at = {
|
|
1579
1579
|
half: 25n,
|
|
1580
1580
|
single: 26n,
|
|
1581
1581
|
double: 27n
|
|
1582
1582
|
};
|
|
1583
|
-
function
|
|
1584
|
-
let
|
|
1585
|
-
switch (
|
|
1583
|
+
function ot(e, t, a, c, l, f) {
|
|
1584
|
+
let p = (e) => t.ai === void 0 ? !0 : typeof t.ai == "bigint" ? t.ai === e : R(new i(e), t.ai, a, c, l, f + 1), m = (n) => l.fail(c, e, t, `expected ${n} (#${t.major})`);
|
|
1585
|
+
switch (t.major) {
|
|
1586
1586
|
case 0:
|
|
1587
|
-
if (!(e instanceof
|
|
1587
|
+
if (!(e instanceof i)) return m("an unsigned integer");
|
|
1588
1588
|
break;
|
|
1589
1589
|
case 1:
|
|
1590
|
-
if (!(e instanceof
|
|
1590
|
+
if (!(e instanceof u)) return m("a negative integer");
|
|
1591
1591
|
break;
|
|
1592
1592
|
case 2:
|
|
1593
|
-
if (j(e) === void 0) return
|
|
1593
|
+
if (j(e) === void 0) return m("a byte string");
|
|
1594
1594
|
break;
|
|
1595
1595
|
case 3:
|
|
1596
|
-
if (A(e) === void 0) return
|
|
1596
|
+
if (A(e) === void 0) return m("a text string");
|
|
1597
1597
|
break;
|
|
1598
1598
|
case 4:
|
|
1599
|
-
if (!(e instanceof
|
|
1599
|
+
if (!(e instanceof n)) return m("an array");
|
|
1600
1600
|
break;
|
|
1601
1601
|
case 5:
|
|
1602
|
-
if (!(e instanceof
|
|
1602
|
+
if (!(e instanceof r)) return m("a map");
|
|
1603
1603
|
break;
|
|
1604
|
-
case 6: return e instanceof
|
|
1605
|
-
case 7: return e instanceof
|
|
1606
|
-
default: return
|
|
1604
|
+
case 6: return e instanceof g ? p(e.tag) ? !0 : l.fail(c, e, t, `tag ${e.tag} does not match ${J(t)}`) : m("a tagged item");
|
|
1605
|
+
case 7: return e instanceof d ? p(BigInt(e.value)) ? !0 : l.fail(c, e, t, `simple(${e.value}) does not match ${J(t)}`) : e instanceof s ? t.ai === void 0 || p(at[e.precision ?? o(e.value)]) ? !0 : l.fail(c, e, t, `float does not match ${J(t)}`) : m("a simple value or float");
|
|
1606
|
+
default: return l.fail(c, e, t, `#${t.major} is not a valid major type`);
|
|
1607
1607
|
}
|
|
1608
|
-
return
|
|
1608
|
+
return t.ai !== void 0 && t.major <= 5 && l.warnOnce(`the additional-information constraint ${J(t)} is not checked (encoding-level)`, t), !0;
|
|
1609
1609
|
}
|
|
1610
|
-
function
|
|
1610
|
+
function J(e) {
|
|
1611
1611
|
return e.raw ?? `#${e.major}`;
|
|
1612
1612
|
}
|
|
1613
|
-
var
|
|
1613
|
+
var Y = (e, t) => e.choices.map((e) => ({
|
|
1614
1614
|
entries: e,
|
|
1615
1615
|
env: t
|
|
1616
|
-
})),
|
|
1616
|
+
})), st = {
|
|
1617
1617
|
min: 1,
|
|
1618
1618
|
max: 1
|
|
1619
1619
|
};
|
|
1620
|
-
function
|
|
1620
|
+
function ct(e) {
|
|
1621
1621
|
let t = e.occur;
|
|
1622
1622
|
return t ? t.marker === "?" ? {
|
|
1623
1623
|
min: 0,
|
|
@@ -1628,15 +1628,15 @@ function st(e) {
|
|
|
1628
1628
|
} : {
|
|
1629
1629
|
min: t.min ?? 0,
|
|
1630
1630
|
max: t.max ?? Infinity
|
|
1631
|
-
} :
|
|
1631
|
+
} : st;
|
|
1632
1632
|
}
|
|
1633
|
-
function
|
|
1634
|
-
let r =
|
|
1635
|
-
if (!r || !
|
|
1633
|
+
function X(e, t, n) {
|
|
1634
|
+
let r = F(n, e.name);
|
|
1635
|
+
if (!r || !Je(r)) return;
|
|
1636
1636
|
let i = [];
|
|
1637
1637
|
for (let n of r) {
|
|
1638
|
-
let r =
|
|
1639
|
-
for (let e of
|
|
1638
|
+
let r = L(n, e.genericArgs, t);
|
|
1639
|
+
for (let e of qe(n.body)) i.push({
|
|
1640
1640
|
entries: e,
|
|
1641
1641
|
env: r
|
|
1642
1642
|
});
|
|
@@ -1648,34 +1648,34 @@ function lt(e, t, n) {
|
|
|
1648
1648
|
let r = e.value.alternatives[0];
|
|
1649
1649
|
if (r.op) return;
|
|
1650
1650
|
let i = r.target;
|
|
1651
|
-
if (i.kind === "ref") return t?.has(i.name) && !i.genericArgs ? void 0 :
|
|
1651
|
+
if (i.kind === "ref") return t?.has(i.name) && !i.genericArgs ? void 0 : X(i, t, n) || (i.name.startsWith("$$") && !F(n, i.name) ? [] : void 0);
|
|
1652
1652
|
if (i.kind === "unwrap") return ut(i.ref, t, n, 0);
|
|
1653
1653
|
}
|
|
1654
1654
|
function ut(e, t, n, r) {
|
|
1655
1655
|
if (r > 32) return;
|
|
1656
|
-
let i =
|
|
1656
|
+
let i = F(n, e.name);
|
|
1657
1657
|
if (!i || i.length !== 1) return;
|
|
1658
|
-
let a = i[0].body, o =
|
|
1659
|
-
if (!
|
|
1658
|
+
let a = i[0].body, o = L(i[0], e.genericArgs, t);
|
|
1659
|
+
if (!I(a)) return qe(a).map((e) => ({
|
|
1660
1660
|
entries: e,
|
|
1661
1661
|
env: o
|
|
1662
1662
|
}));
|
|
1663
1663
|
if (a.value.alternatives.length !== 1) return;
|
|
1664
1664
|
let s = a.value.alternatives[0];
|
|
1665
1665
|
if (!s.op) {
|
|
1666
|
-
if (s.target.kind === "map" || s.target.kind === "array") return
|
|
1666
|
+
if (s.target.kind === "map" || s.target.kind === "array") return Y(s.target.group, o);
|
|
1667
1667
|
if (s.target.kind === "ref") return ut(s.target, o, n, r + 1);
|
|
1668
1668
|
}
|
|
1669
1669
|
}
|
|
1670
1670
|
function dt(e, t, n, r) {
|
|
1671
1671
|
if (r > 32) return;
|
|
1672
|
-
let i =
|
|
1672
|
+
let i = F(n, e.name);
|
|
1673
1673
|
if (!i || i.length !== 1) return;
|
|
1674
1674
|
let a = i[0].body;
|
|
1675
|
-
if (!
|
|
1675
|
+
if (!I(a) || a.value.alternatives.length !== 1) return;
|
|
1676
1676
|
let o = a.value.alternatives[0];
|
|
1677
1677
|
if (o.op) return;
|
|
1678
|
-
let s =
|
|
1678
|
+
let s = L(i[0], e.genericArgs, t);
|
|
1679
1679
|
if (o.target.kind === "tagged") return {
|
|
1680
1680
|
type: o.target.item,
|
|
1681
1681
|
env: s
|
|
@@ -1683,11 +1683,11 @@ function dt(e, t, n, r) {
|
|
|
1683
1683
|
if (o.target.kind === "ref") return dt(o.target, s, n, r + 1);
|
|
1684
1684
|
}
|
|
1685
1685
|
function ft(e, t, n) {
|
|
1686
|
-
let r =
|
|
1686
|
+
let r = ct(e);
|
|
1687
1687
|
if (e.kind === "entry-group") return {
|
|
1688
1688
|
kind: "group",
|
|
1689
1689
|
occur: r,
|
|
1690
|
-
choices:
|
|
1690
|
+
choices: Y(e.group, t),
|
|
1691
1691
|
node: e
|
|
1692
1692
|
};
|
|
1693
1693
|
let i = lt(e, t, n);
|
|
@@ -1706,7 +1706,7 @@ function ft(e, t, n) {
|
|
|
1706
1706
|
};
|
|
1707
1707
|
}
|
|
1708
1708
|
function pt(e, t, n, r, i, a) {
|
|
1709
|
-
return i.checkDepth(a), mt(e.items, 0,
|
|
1709
|
+
return i.checkDepth(a), mt(e.items, 0, Y(t, n), r, i, a).has(e.items.length) ? !0 : i.fail(r, e, t, `array of ${e.items.length} item(s) does not match the group`);
|
|
1710
1710
|
}
|
|
1711
1711
|
function mt(e, t, n, r, i, a) {
|
|
1712
1712
|
let o = /* @__PURE__ */ new Set();
|
|
@@ -1724,19 +1724,19 @@ function ht(e, t, n, r, i, a, o, s) {
|
|
|
1724
1724
|
l(0, t);
|
|
1725
1725
|
}
|
|
1726
1726
|
function gt(e, t, n, r, i, a) {
|
|
1727
|
-
return n.kind === "type" ?
|
|
1727
|
+
return n.kind === "type" ? R(e[t], n.type, n.env, [...r, t], i, a) ? [t + 1] : [] : (i.checkDepth(a), [...mt(e, t, n.choices, r, i, a + 1)].sort((e, t) => t - e));
|
|
1728
1728
|
}
|
|
1729
1729
|
function _t(e, t, n, r, i, a) {
|
|
1730
1730
|
i.checkDepth(a);
|
|
1731
1731
|
let o = Array(e.entries.length).fill(!1);
|
|
1732
|
-
for (let s of
|
|
1732
|
+
for (let s of Y(t, n)) if (o.fill(!1), Z(e, s.entries, 0, o, s.env, r, i, a, () => vt(e, o, r, i, t))) return !0;
|
|
1733
1733
|
return !1;
|
|
1734
1734
|
}
|
|
1735
1735
|
function vt(e, t, n, r, i) {
|
|
1736
1736
|
for (let a = 0; a < t.length; a++) {
|
|
1737
1737
|
if (t[a]) continue;
|
|
1738
1738
|
let [o, s] = e.entries[a];
|
|
1739
|
-
if (!(o instanceof
|
|
1739
|
+
if (!(o instanceof _)) return r.fail([...n, xt(o, a)], s, i, `entry ${St(o)} is not allowed by the group`), !1;
|
|
1740
1740
|
}
|
|
1741
1741
|
return !0;
|
|
1742
1742
|
}
|
|
@@ -1751,7 +1751,7 @@ function Z(e, t, n, r, i, a, o, s, c) {
|
|
|
1751
1751
|
let [n, i] = e.entries[t];
|
|
1752
1752
|
if (!yt(l.memberKey, n, l.env, a, o, s)) continue;
|
|
1753
1753
|
let c = [...a, xt(n, t)];
|
|
1754
|
-
if (
|
|
1754
|
+
if (R(i, l.type, l.env, c, o, s + 1)) {
|
|
1755
1755
|
r[t] = !0, u++;
|
|
1756
1756
|
continue;
|
|
1757
1757
|
}
|
|
@@ -1777,24 +1777,24 @@ function Z(e, t, n, r, i, a, o, s, c) {
|
|
|
1777
1777
|
return d(0);
|
|
1778
1778
|
}
|
|
1779
1779
|
function yt(e, t, n, r, i, a) {
|
|
1780
|
-
if (t =
|
|
1780
|
+
if (t = Xe(t), t instanceof _) return !0;
|
|
1781
1781
|
switch (e.kind) {
|
|
1782
1782
|
case "bareword": return A(t) === e.key;
|
|
1783
|
-
case "value": return
|
|
1784
|
-
case "type1": return
|
|
1783
|
+
case "value": return H(t, e.key);
|
|
1784
|
+
case "type1": return z(t, e.key, n, r, i, a + 1);
|
|
1785
1785
|
}
|
|
1786
1786
|
}
|
|
1787
1787
|
function bt(e) {
|
|
1788
1788
|
switch (e.kind) {
|
|
1789
1789
|
case "bareword": return `'${e.key}'`;
|
|
1790
1790
|
case "value": return e.key.raw;
|
|
1791
|
-
case "type1": return
|
|
1791
|
+
case "type1": return q(e.key.target);
|
|
1792
1792
|
}
|
|
1793
1793
|
}
|
|
1794
1794
|
function xt(e, t) {
|
|
1795
1795
|
let n = A(e);
|
|
1796
1796
|
if (n !== void 0) return n;
|
|
1797
|
-
if (e instanceof
|
|
1797
|
+
if (e instanceof i || e instanceof u) {
|
|
1798
1798
|
let t = e.value;
|
|
1799
1799
|
if (t >= BigInt(-(2 ** 53 - 1)) && t <= BigInt(2 ** 53 - 1)) return Number(t);
|
|
1800
1800
|
}
|
|
@@ -1802,26 +1802,26 @@ function xt(e, t) {
|
|
|
1802
1802
|
}
|
|
1803
1803
|
function St(e) {
|
|
1804
1804
|
let t = A(e);
|
|
1805
|
-
return t === void 0 ? e instanceof
|
|
1805
|
+
return t === void 0 ? e instanceof i || e instanceof u ? e.value.toString() : e.constructor.name.replace(/^Cbor/, "").toLowerCase() : JSON.stringify(t);
|
|
1806
1806
|
}
|
|
1807
1807
|
function Ct(e, t, n) {
|
|
1808
1808
|
return {
|
|
1809
|
-
matchType2: (r, i, a) =>
|
|
1809
|
+
matchType2: (r, i, a) => B(r, i, e, a, t, n + 1),
|
|
1810
1810
|
matchEmbedded: (r, i, a) => {
|
|
1811
1811
|
t.embeddedDepth++;
|
|
1812
1812
|
try {
|
|
1813
|
-
return
|
|
1813
|
+
return B(r, i, e, a, t, n + 1);
|
|
1814
1814
|
} finally {
|
|
1815
1815
|
t.embeddedDepth--;
|
|
1816
1816
|
}
|
|
1817
1817
|
},
|
|
1818
|
-
resolveValue: (n) =>
|
|
1819
|
-
existsIntGE: (n, r) =>
|
|
1820
|
-
matchesLiteral:
|
|
1818
|
+
resolveValue: (n) => U(n, e, t),
|
|
1819
|
+
existsIntGE: (n, r) => Ze(n, r, e, t),
|
|
1820
|
+
matchesLiteral: H,
|
|
1821
1821
|
fail: (e, n, r, i) => t.fail(e, n, r, i),
|
|
1822
1822
|
warnOnce: (e, n) => t.warnOnce(e, n),
|
|
1823
1823
|
features: t.features,
|
|
1824
|
-
uint: (e) => new
|
|
1824
|
+
uint: (e) => new i(e)
|
|
1825
1825
|
};
|
|
1826
1826
|
}
|
|
1827
1827
|
//#endregion
|
|
@@ -1837,19 +1837,19 @@ var wt = class {
|
|
|
1837
1837
|
this.source = e, this.comments = t, this.ast = n, this.rules = r, i && (this.root = i), a.length > 0 && (this.warnings = a);
|
|
1838
1838
|
}
|
|
1839
1839
|
format(e) {
|
|
1840
|
-
return
|
|
1840
|
+
return he(this.ast, {
|
|
1841
1841
|
...e,
|
|
1842
1842
|
source: this.source,
|
|
1843
1843
|
comments: this.comments
|
|
1844
1844
|
});
|
|
1845
1845
|
}
|
|
1846
1846
|
validate(e, t) {
|
|
1847
|
-
let n = e instanceof a ? e : typeof e == "string" ?
|
|
1848
|
-
return
|
|
1847
|
+
let n = e instanceof a ? e : typeof e == "string" ? m(e) : te(e);
|
|
1848
|
+
return Ke(this, n, t);
|
|
1849
1849
|
}
|
|
1850
1850
|
};
|
|
1851
1851
|
function Tt(e, t) {
|
|
1852
|
-
let { rules: n, comments: r } =
|
|
1852
|
+
let { rules: n, comments: r } = S(e), i = [], a = w();
|
|
1853
1853
|
n.length === 0 && i.push({
|
|
1854
1854
|
code: "no-rules",
|
|
1855
1855
|
message: "a CDDL data model needs at least one rule to provide the root of the definition"
|
|
@@ -1972,6 +1972,6 @@ function kt(e, t) {
|
|
|
1972
1972
|
}
|
|
1973
1973
|
}
|
|
1974
1974
|
//#endregion
|
|
1975
|
-
export {
|
|
1975
|
+
export { S as a, oe as c, w as i, v as l, Tt as n, le as o, pe as r, ae as s, wt as t };
|
|
1976
1976
|
|
|
1977
|
-
//# sourceMappingURL=schema-
|
|
1977
|
+
//# sourceMappingURL=schema-y8G5mDIS.js.map
|