@bcts/dcbor 1.0.0-alpha.15 → 1.0.0-alpha.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/dist/index.cjs +474 -474
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -22
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +46 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +474 -474
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +489 -489
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/byte-string.ts +17 -17
- package/src/date.ts +11 -11
- package/src/map.ts +23 -23
- package/src/set.ts +9 -9
- package/src/tags-store.ts +17 -17
package/dist/index.mjs
CHANGED
|
@@ -6,14 +6,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
-
var __copyProps = (to, from
|
|
10
|
-
if (from
|
|
11
|
-
for (var keys = __getOwnPropNames(from
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
12
|
key = keys[i];
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
14
|
__defProp(to, key, {
|
|
15
|
-
get: ((k) => from
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -117,14 +117,14 @@ var require_generic_collection = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
117
117
|
};
|
|
118
118
|
GenericCollection.prototype.forEach = function(callback) {
|
|
119
119
|
var thisp = arguments[1];
|
|
120
|
-
return this.reduce(function(undefined
|
|
120
|
+
return this.reduce(function(undefined, value, key, object, depth) {
|
|
121
121
|
callback.call(thisp, value, key, object, depth);
|
|
122
122
|
}, void 0);
|
|
123
123
|
};
|
|
124
124
|
GenericCollection.prototype.map = function(callback) {
|
|
125
125
|
var thisp = arguments[1];
|
|
126
126
|
var result = [];
|
|
127
|
-
this.reduce(function(undefined
|
|
127
|
+
this.reduce(function(undefined, value, key, object, depth) {
|
|
128
128
|
result.push(callback.call(thisp, value, key, object, depth));
|
|
129
129
|
}, void 0);
|
|
130
130
|
return result;
|
|
@@ -132,7 +132,7 @@ var require_generic_collection = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
132
132
|
GenericCollection.prototype.enumerate = function(start) {
|
|
133
133
|
if (start == null) start = 0;
|
|
134
134
|
var result = [];
|
|
135
|
-
this.reduce(function(undefined
|
|
135
|
+
this.reduce(function(undefined, value) {
|
|
136
136
|
result.push([start++, value]);
|
|
137
137
|
}, void 0);
|
|
138
138
|
return result;
|
|
@@ -159,7 +159,7 @@ var require_generic_collection = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
159
159
|
};
|
|
160
160
|
GenericCollection.prototype.toObject = function() {
|
|
161
161
|
var object = {};
|
|
162
|
-
this.reduce(function(undefined
|
|
162
|
+
this.reduce(function(undefined, value, key) {
|
|
163
163
|
object[key] = value;
|
|
164
164
|
}, void 0);
|
|
165
165
|
return object;
|
|
@@ -170,7 +170,7 @@ var require_generic_collection = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
170
170
|
GenericCollection.prototype.filter = function(callback) {
|
|
171
171
|
var thisp = arguments[1];
|
|
172
172
|
var result = this.constructClone();
|
|
173
|
-
this.reduce(function(undefined
|
|
173
|
+
this.reduce(function(undefined, value, key, object, depth) {
|
|
174
174
|
if (callback.call(thisp, value, key, object, depth)) result.add(value, key);
|
|
175
175
|
}, void 0);
|
|
176
176
|
return result;
|
|
@@ -222,7 +222,7 @@ var require_generic_collection = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
222
222
|
GenericCollection.prototype.average = function(zero) {
|
|
223
223
|
var sum = zero === void 0 ? 0 : zero;
|
|
224
224
|
var count = zero === void 0 ? 0 : zero;
|
|
225
|
-
this.reduce(function(undefined
|
|
225
|
+
this.reduce(function(undefined, value) {
|
|
226
226
|
sum += value;
|
|
227
227
|
count += 1;
|
|
228
228
|
}, void 0);
|
|
@@ -903,8 +903,8 @@ var require_shim_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
903
903
|
};
|
|
904
904
|
Object.addEach = function(target, source, overrides) {
|
|
905
905
|
var overridesExistingProperty = arguments.length === 3 ? overrides : true;
|
|
906
|
-
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key
|
|
907
|
-
target[key
|
|
906
|
+
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key) {
|
|
907
|
+
target[key] = value;
|
|
908
908
|
});
|
|
909
909
|
else source.forEach(function(pair) {
|
|
910
910
|
target[pair[0]] = pair[1];
|
|
@@ -915,8 +915,8 @@ var require_shim_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
915
915
|
};
|
|
916
916
|
Object.defineEach = function(target, source, overrides, configurable, enumerable, writable) {
|
|
917
917
|
var overridesExistingProperty = arguments.length === 3 ? overrides : true;
|
|
918
|
-
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key
|
|
919
|
-
Object.defineProperty(target, key
|
|
918
|
+
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key) {
|
|
919
|
+
Object.defineProperty(target, key, {
|
|
920
920
|
value,
|
|
921
921
|
writable,
|
|
922
922
|
configurable,
|
|
@@ -1191,10 +1191,10 @@ var require_generic_order = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1191
1191
|
if (this === that) return 0;
|
|
1192
1192
|
if (!that) return 1;
|
|
1193
1193
|
var length = Math.min(this.length, that.length);
|
|
1194
|
-
var comparison = this.zip(that).reduce(function(comparison
|
|
1195
|
-
if (comparison
|
|
1194
|
+
var comparison = this.zip(that).reduce(function(comparison, pair, index) {
|
|
1195
|
+
if (comparison === 0) if (index >= length) return comparison;
|
|
1196
1196
|
else return compare(pair[0], pair[1]);
|
|
1197
|
-
else return comparison
|
|
1197
|
+
else return comparison;
|
|
1198
1198
|
}, 0);
|
|
1199
1199
|
if (comparison === 0) return this.length - that.length;
|
|
1200
1200
|
return comparison;
|
|
@@ -1544,7 +1544,7 @@ var require_generic_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1544
1544
|
};
|
|
1545
1545
|
GenericSet.prototype.forEach = function(callback) {
|
|
1546
1546
|
var thisp = arguments[1];
|
|
1547
|
-
return this.reduce(function(undefined
|
|
1547
|
+
return this.reduce(function(undefined, value, key, object, depth) {
|
|
1548
1548
|
callback.call(thisp, value, value, object, depth);
|
|
1549
1549
|
}, void 0);
|
|
1550
1550
|
};
|
|
@@ -1605,19 +1605,19 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1605
1605
|
List.prototype.find = function(value, equals, index) {
|
|
1606
1606
|
equals = equals || this.contentEquals;
|
|
1607
1607
|
var head = this.head;
|
|
1608
|
-
var at
|
|
1609
|
-
while (at
|
|
1610
|
-
if (equals(at
|
|
1611
|
-
at
|
|
1608
|
+
var at = this.scan(index, head.next);
|
|
1609
|
+
while (at !== head) {
|
|
1610
|
+
if (equals(at.value, value)) return at;
|
|
1611
|
+
at = at.next;
|
|
1612
1612
|
}
|
|
1613
1613
|
};
|
|
1614
1614
|
List.prototype.findLast = function(value, equals, index) {
|
|
1615
1615
|
equals = equals || this.contentEquals;
|
|
1616
1616
|
var head = this.head;
|
|
1617
|
-
var at
|
|
1618
|
-
while (at
|
|
1619
|
-
if (equals(at
|
|
1620
|
-
at
|
|
1617
|
+
var at = this.scan(index, head.prev);
|
|
1618
|
+
while (at !== head) {
|
|
1619
|
+
if (equals(at.value, value)) return at;
|
|
1620
|
+
at = at.prev;
|
|
1621
1621
|
}
|
|
1622
1622
|
};
|
|
1623
1623
|
List.prototype.has = function(value, equals) {
|
|
@@ -1640,14 +1640,14 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1640
1640
|
List.prototype.deleteAll = function(value, equals) {
|
|
1641
1641
|
equals = equals || this.contentEquals;
|
|
1642
1642
|
var head = this.head;
|
|
1643
|
-
var at
|
|
1643
|
+
var at = head.next;
|
|
1644
1644
|
var count = 0;
|
|
1645
|
-
while (at
|
|
1646
|
-
if (equals(value, at
|
|
1647
|
-
at
|
|
1645
|
+
while (at !== head) {
|
|
1646
|
+
if (equals(value, at.value)) {
|
|
1647
|
+
at["delete"]();
|
|
1648
1648
|
count++;
|
|
1649
1649
|
}
|
|
1650
|
-
at
|
|
1650
|
+
at = at.next;
|
|
1651
1651
|
}
|
|
1652
1652
|
this.length -= count;
|
|
1653
1653
|
return count;
|
|
@@ -1675,12 +1675,12 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1675
1675
|
this.length += arguments.length;
|
|
1676
1676
|
};
|
|
1677
1677
|
List.prototype.unshift = function() {
|
|
1678
|
-
var at
|
|
1678
|
+
var at = this.head;
|
|
1679
1679
|
for (var i = 0; i < arguments.length; i++) {
|
|
1680
1680
|
var value = arguments[i];
|
|
1681
1681
|
var node = new this.Node(value);
|
|
1682
|
-
at
|
|
1683
|
-
at
|
|
1682
|
+
at.addAfter(node);
|
|
1683
|
+
at = node;
|
|
1684
1684
|
}
|
|
1685
1685
|
this.length += arguments.length;
|
|
1686
1686
|
};
|
|
@@ -1725,41 +1725,41 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1725
1725
|
List.prototype.one = function() {
|
|
1726
1726
|
return this.peek();
|
|
1727
1727
|
};
|
|
1728
|
-
List.prototype.scan = function(at
|
|
1728
|
+
List.prototype.scan = function(at, fallback) {
|
|
1729
1729
|
var head = this.head;
|
|
1730
|
-
if (typeof at
|
|
1731
|
-
var count = at
|
|
1730
|
+
if (typeof at === "number") {
|
|
1731
|
+
var count = at;
|
|
1732
1732
|
if (count >= 0) {
|
|
1733
|
-
at
|
|
1733
|
+
at = head.next;
|
|
1734
1734
|
while (count) {
|
|
1735
1735
|
count--;
|
|
1736
|
-
at
|
|
1737
|
-
if (at
|
|
1736
|
+
at = at.next;
|
|
1737
|
+
if (at == head) break;
|
|
1738
1738
|
}
|
|
1739
1739
|
} else {
|
|
1740
|
-
at
|
|
1740
|
+
at = head;
|
|
1741
1741
|
while (count < 0) {
|
|
1742
1742
|
count++;
|
|
1743
|
-
at
|
|
1744
|
-
if (at
|
|
1743
|
+
at = at.prev;
|
|
1744
|
+
if (at == head) break;
|
|
1745
1745
|
}
|
|
1746
1746
|
}
|
|
1747
|
-
return at
|
|
1748
|
-
} else return at
|
|
1747
|
+
return at;
|
|
1748
|
+
} else return at || fallback;
|
|
1749
1749
|
};
|
|
1750
|
-
List.prototype.slice = function(at
|
|
1750
|
+
List.prototype.slice = function(at, end) {
|
|
1751
1751
|
var sliced = [];
|
|
1752
1752
|
var head = this.head;
|
|
1753
|
-
at
|
|
1753
|
+
at = this.scan(at, head.next);
|
|
1754
1754
|
end = this.scan(end, head);
|
|
1755
|
-
while (at
|
|
1756
|
-
sliced.push(at
|
|
1757
|
-
at
|
|
1755
|
+
while (at !== end && at !== head) {
|
|
1756
|
+
sliced.push(at.value);
|
|
1757
|
+
at = at.next;
|
|
1758
1758
|
}
|
|
1759
1759
|
return sliced;
|
|
1760
1760
|
};
|
|
1761
|
-
List.prototype.splice = function(at
|
|
1762
|
-
return this.swap(at
|
|
1761
|
+
List.prototype.splice = function(at, length) {
|
|
1762
|
+
return this.swap(at, length, Array.prototype.slice.call(arguments, 2));
|
|
1763
1763
|
};
|
|
1764
1764
|
List.prototype.swap = function(start, length, plus, _before, _after) {
|
|
1765
1765
|
var initial = start;
|
|
@@ -1767,31 +1767,31 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1767
1767
|
if (length == null) length = Infinity;
|
|
1768
1768
|
plus = Array.from(plus);
|
|
1769
1769
|
var minus = [];
|
|
1770
|
-
var at
|
|
1771
|
-
while (length-- && length >= 0 && at
|
|
1772
|
-
minus.push(at
|
|
1773
|
-
at
|
|
1770
|
+
var at = start;
|
|
1771
|
+
while (length-- && length >= 0 && at !== this.head) {
|
|
1772
|
+
minus.push(at.value);
|
|
1773
|
+
at = at.next;
|
|
1774
1774
|
}
|
|
1775
1775
|
_before && _before.call(this, start, plus, minus);
|
|
1776
|
-
var at
|
|
1777
|
-
for (var i = 0, at
|
|
1778
|
-
if (initial == null && at
|
|
1776
|
+
var at = start;
|
|
1777
|
+
for (var i = 0, at = start; i < minus.length; i++, at = at.next) at["delete"]();
|
|
1778
|
+
if (initial == null && at === this.head) at = this.head.next;
|
|
1779
1779
|
for (var i = 0; i < plus.length; i++) {
|
|
1780
1780
|
var node = new this.Node(plus[i]);
|
|
1781
|
-
at
|
|
1781
|
+
at.addBefore(node);
|
|
1782
1782
|
}
|
|
1783
1783
|
this.length += plus.length - minus.length;
|
|
1784
1784
|
_after && _after.call(this, start, plus, minus);
|
|
1785
1785
|
return minus;
|
|
1786
1786
|
};
|
|
1787
1787
|
List.prototype.reverse = function() {
|
|
1788
|
-
var at
|
|
1788
|
+
var at = this.head;
|
|
1789
1789
|
do {
|
|
1790
|
-
var temp = at
|
|
1791
|
-
at
|
|
1792
|
-
at
|
|
1793
|
-
at
|
|
1794
|
-
} while (at
|
|
1790
|
+
var temp = at.next;
|
|
1791
|
+
at.next = at.prev;
|
|
1792
|
+
at.prev = temp;
|
|
1793
|
+
at = at.next;
|
|
1794
|
+
} while (at !== this.head);
|
|
1795
1795
|
return this;
|
|
1796
1796
|
};
|
|
1797
1797
|
List.prototype.sort = function() {
|
|
@@ -1800,20 +1800,20 @@ var require__list = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1800
1800
|
List.prototype.reduce = function(callback, basis) {
|
|
1801
1801
|
var thisp = arguments[2];
|
|
1802
1802
|
var head = this.head;
|
|
1803
|
-
var at
|
|
1804
|
-
while (at
|
|
1805
|
-
basis = callback.call(thisp, basis, at
|
|
1806
|
-
at
|
|
1803
|
+
var at = head.next;
|
|
1804
|
+
while (at !== head) {
|
|
1805
|
+
basis = callback.call(thisp, basis, at.value, at, this);
|
|
1806
|
+
at = at.next;
|
|
1807
1807
|
}
|
|
1808
1808
|
return basis;
|
|
1809
1809
|
};
|
|
1810
1810
|
List.prototype.reduceRight = function(callback, basis) {
|
|
1811
1811
|
var thisp = arguments[2];
|
|
1812
1812
|
var head = this.head;
|
|
1813
|
-
var at
|
|
1814
|
-
while (at
|
|
1815
|
-
basis = callback.call(thisp, basis, at
|
|
1816
|
-
at
|
|
1813
|
+
var at = head.prev;
|
|
1814
|
+
while (at !== head) {
|
|
1815
|
+
basis = callback.call(thisp, basis, at.value, at, this);
|
|
1816
|
+
at = at.prev;
|
|
1817
1817
|
}
|
|
1818
1818
|
return basis;
|
|
1819
1819
|
};
|
|
@@ -2170,8 +2170,8 @@ var require_generic_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2170
2170
|
GenericMap.prototype["delete"] = function(key) {
|
|
2171
2171
|
var item = new this.Item(key);
|
|
2172
2172
|
if (this.store.has(item)) {
|
|
2173
|
-
var from
|
|
2174
|
-
if (this.dispatchesMapChanges) this.dispatchBeforeMapChange(key, from
|
|
2173
|
+
var from = this.store.get(item).value;
|
|
2174
|
+
if (this.dispatchesMapChanges) this.dispatchBeforeMapChange(key, from);
|
|
2175
2175
|
this.store["delete"](item);
|
|
2176
2176
|
this.length--;
|
|
2177
2177
|
if (this.dispatchesMapChanges) this.dispatchMapChange(key, void 0);
|
|
@@ -2182,8 +2182,8 @@ var require_generic_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2182
2182
|
GenericMap.prototype.clear = function() {
|
|
2183
2183
|
var keys, key;
|
|
2184
2184
|
if (this.dispatchesMapChanges) {
|
|
2185
|
-
this.forEach(function(value, key
|
|
2186
|
-
this.dispatchBeforeMapChange(key
|
|
2185
|
+
this.forEach(function(value, key) {
|
|
2186
|
+
this.dispatchBeforeMapChange(key, value);
|
|
2187
2187
|
}, this);
|
|
2188
2188
|
keys = this.keysArray();
|
|
2189
2189
|
}
|
|
@@ -2192,13 +2192,13 @@ var require_generic_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2192
2192
|
if (this.dispatchesMapChanges) for (var i = 0; key = keys[i]; i++) this.dispatchMapChange(key);
|
|
2193
2193
|
};
|
|
2194
2194
|
GenericMap.prototype.reduce = function(callback, basis, thisp) {
|
|
2195
|
-
return this.store.reduce(function(basis
|
|
2196
|
-
return callback.call(thisp, basis
|
|
2195
|
+
return this.store.reduce(function(basis, item) {
|
|
2196
|
+
return callback.call(thisp, basis, item.value, item.key, this);
|
|
2197
2197
|
}, basis, this);
|
|
2198
2198
|
};
|
|
2199
2199
|
GenericMap.prototype.reduceRight = function(callback, basis, thisp) {
|
|
2200
|
-
return this.store.reduceRight(function(basis
|
|
2201
|
-
return callback.call(thisp, basis
|
|
2200
|
+
return this.store.reduceRight(function(basis, item) {
|
|
2201
|
+
return callback.call(thisp, basis, item.value, item.key, this);
|
|
2202
2202
|
}, basis, this);
|
|
2203
2203
|
};
|
|
2204
2204
|
GenericMap.prototype.keysArray = function() {
|
|
@@ -2364,8 +2364,8 @@ var require__dict = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2364
2364
|
Dict.prototype.reduceRight = function(callback, basis, thisp) {
|
|
2365
2365
|
var self = this;
|
|
2366
2366
|
var store = this.store;
|
|
2367
|
-
basis = Object.keys(this.store).reduceRight(function(basis
|
|
2368
|
-
return callback.call(thisp, basis
|
|
2367
|
+
basis = Object.keys(this.store).reduceRight(function(basis, key) {
|
|
2368
|
+
return callback.call(thisp, basis, store[key], key, self);
|
|
2369
2369
|
}, basis);
|
|
2370
2370
|
if (this._hasProto) return callback.call(thisp, basis, this._protoValue, "__proto__", self);
|
|
2371
2371
|
return basis;
|
|
@@ -2495,10 +2495,10 @@ var require__fast_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2495
2495
|
var thisp = arguments[2];
|
|
2496
2496
|
var buckets = this.buckets;
|
|
2497
2497
|
var index = 0;
|
|
2498
|
-
return buckets.reduce(function(basis
|
|
2499
|
-
return bucket.reduce(function(basis
|
|
2500
|
-
return callback.call(thisp, basis
|
|
2501
|
-
}, basis
|
|
2498
|
+
return buckets.reduce(function(basis, bucket) {
|
|
2499
|
+
return bucket.reduce(function(basis, value) {
|
|
2500
|
+
return callback.call(thisp, basis, value, index++, this);
|
|
2501
|
+
}, basis, this);
|
|
2502
2502
|
}, basis, this);
|
|
2503
2503
|
};
|
|
2504
2504
|
FastSet.prototype.one = function() {
|
|
@@ -2530,17 +2530,17 @@ var require__fast_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2530
2530
|
bucket = buckets.get(hash);
|
|
2531
2531
|
callback.call(thisp, branch + charmap.through + charmap.branchDown + " " + hash);
|
|
2532
2532
|
bucket.forEach(function(value, node) {
|
|
2533
|
-
var branch
|
|
2533
|
+
var branch, below, written;
|
|
2534
2534
|
if (node === bucket.head.prev) {
|
|
2535
|
-
branch
|
|
2535
|
+
branch = charmap.fromAbove;
|
|
2536
2536
|
below = " ";
|
|
2537
2537
|
} else {
|
|
2538
|
-
branch
|
|
2538
|
+
branch = charmap.fromBoth;
|
|
2539
2539
|
below = charmap.strafe;
|
|
2540
2540
|
}
|
|
2541
2541
|
logNode(node, function(line) {
|
|
2542
2542
|
if (!written) {
|
|
2543
|
-
callback.call(thisp, leader + " " + branch
|
|
2543
|
+
callback.call(thisp, leader + " " + branch + charmap.through + charmap.through + line);
|
|
2544
2544
|
written = true;
|
|
2545
2545
|
} else callback.call(thisp, leader + " " + below + " " + line);
|
|
2546
2546
|
}, function(line) {
|
|
@@ -2726,16 +2726,16 @@ var require__set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2726
2726
|
var thisp = arguments[2];
|
|
2727
2727
|
var list = this.order;
|
|
2728
2728
|
var index = 0;
|
|
2729
|
-
return list.reduce(function(basis
|
|
2730
|
-
return callback.call(thisp, basis
|
|
2729
|
+
return list.reduce(function(basis, value) {
|
|
2730
|
+
return callback.call(thisp, basis, value, index++, this);
|
|
2731
2731
|
}, basis, this);
|
|
2732
2732
|
};
|
|
2733
2733
|
CollectionsSet.prototype.reduceRight = function(callback, basis) {
|
|
2734
2734
|
var thisp = arguments[2];
|
|
2735
2735
|
var list = this.order;
|
|
2736
2736
|
var index = this.length - 1;
|
|
2737
|
-
return list.reduceRight(function(basis
|
|
2738
|
-
return callback.call(thisp, basis
|
|
2737
|
+
return list.reduceRight(function(basis, value) {
|
|
2738
|
+
return callback.call(thisp, basis, value, index--, this);
|
|
2739
2739
|
}, basis, this);
|
|
2740
2740
|
};
|
|
2741
2741
|
CollectionsSet.prototype.iterate = function() {
|
|
@@ -2920,8 +2920,8 @@ var require__map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2920
2920
|
}
|
|
2921
2921
|
var Set = require__set().CollectionsSet;
|
|
2922
2922
|
var GenericMap = require_generic_map();
|
|
2923
|
-
CollectionsMap = Map = function Map
|
|
2924
|
-
if (!(this instanceof Map
|
|
2923
|
+
CollectionsMap = Map = function Map(values, equals, hash, getDefault) {
|
|
2924
|
+
if (!(this instanceof Map)) return new Map(values, equals, hash, getDefault);
|
|
2925
2925
|
equals = equals || Object.equals;
|
|
2926
2926
|
hash = hash || Object.hash;
|
|
2927
2927
|
getDefault = getDefault || Function.noop;
|
|
@@ -3232,15 +3232,15 @@ var require_property_changes = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3232
3232
|
return dispatchingGetter.overriddenDescriptor.value;
|
|
3233
3233
|
};
|
|
3234
3234
|
propertyListener.set = function dispatchingSetter(value) {
|
|
3235
|
-
var descriptor, isActive, overriddenDescriptor
|
|
3236
|
-
if (value !== overriddenDescriptor
|
|
3235
|
+
var descriptor, isActive, overriddenDescriptor = dispatchingSetter.overriddenDescriptor;
|
|
3236
|
+
if (value !== overriddenDescriptor.value) {
|
|
3237
3237
|
if (!(isActive = (descriptor = dispatchingSetter.descriptor).isActive)) {
|
|
3238
3238
|
descriptor.isActive = true;
|
|
3239
3239
|
try {
|
|
3240
|
-
dispatchingSetter.dispatchEach(descriptor._willChangeListeners, dispatchingSetter.key, overriddenDescriptor
|
|
3240
|
+
dispatchingSetter.dispatchEach(descriptor._willChangeListeners, dispatchingSetter.key, overriddenDescriptor.value, this);
|
|
3241
3241
|
} finally {}
|
|
3242
3242
|
}
|
|
3243
|
-
overriddenDescriptor
|
|
3243
|
+
overriddenDescriptor.value = value;
|
|
3244
3244
|
if (!isActive) try {
|
|
3245
3245
|
dispatchingSetter.dispatchEach(descriptor._changeListeners, dispatchingSetter.key, value, this);
|
|
3246
3246
|
} finally {
|
|
@@ -3587,18 +3587,18 @@ var require_sorted_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3587
3587
|
if (this.contentEquals(value, this.root.value)) return this.root;
|
|
3588
3588
|
}
|
|
3589
3589
|
};
|
|
3590
|
-
SortedSet.prototype.findGreatest = function(at
|
|
3590
|
+
SortedSet.prototype.findGreatest = function(at) {
|
|
3591
3591
|
if (this.root) {
|
|
3592
|
-
at
|
|
3593
|
-
while (at
|
|
3594
|
-
return at
|
|
3592
|
+
at = at || this.root;
|
|
3593
|
+
while (at.right) at = at.right;
|
|
3594
|
+
return at;
|
|
3595
3595
|
}
|
|
3596
3596
|
};
|
|
3597
|
-
SortedSet.prototype.findLeast = function(at
|
|
3597
|
+
SortedSet.prototype.findLeast = function(at) {
|
|
3598
3598
|
if (this.root) {
|
|
3599
|
-
at
|
|
3600
|
-
while (at
|
|
3601
|
-
return at
|
|
3599
|
+
at = at || this.root;
|
|
3600
|
+
while (at.left) at = at.left;
|
|
3601
|
+
return at;
|
|
3602
3602
|
}
|
|
3603
3603
|
};
|
|
3604
3604
|
SortedSet.prototype.findGreatestLessThanOrEqual = function(value) {
|
|
@@ -3665,8 +3665,8 @@ var require_sorted_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3665
3665
|
}
|
|
3666
3666
|
return sliced;
|
|
3667
3667
|
};
|
|
3668
|
-
SortedSet.prototype.splice = function(at
|
|
3669
|
-
return this.swap(at
|
|
3668
|
+
SortedSet.prototype.splice = function(at, length) {
|
|
3669
|
+
return this.swap(at, length, Array.prototype.slice.call(arguments, 2));
|
|
3670
3670
|
};
|
|
3671
3671
|
SortedSet.prototype.swap = function(start, length, plus) {
|
|
3672
3672
|
if (start === void 0 && length === void 0) return [];
|
|
@@ -3754,16 +3754,16 @@ var require_sorted_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3754
3754
|
};
|
|
3755
3755
|
SortedSet.prototype.splayIndex = function(index) {
|
|
3756
3756
|
if (this.root) {
|
|
3757
|
-
var at
|
|
3757
|
+
var at = this.root;
|
|
3758
3758
|
var atIndex = this.root.index;
|
|
3759
|
-
while (atIndex !== index) if (atIndex > index && at
|
|
3760
|
-
at
|
|
3761
|
-
atIndex -= 1 + (at
|
|
3762
|
-
} else if (atIndex < index && at
|
|
3763
|
-
at
|
|
3764
|
-
atIndex += 1 + (at
|
|
3759
|
+
while (atIndex !== index) if (atIndex > index && at.left) {
|
|
3760
|
+
at = at.left;
|
|
3761
|
+
atIndex -= 1 + (at.right ? at.right.length : 0);
|
|
3762
|
+
} else if (atIndex < index && at.right) {
|
|
3763
|
+
at = at.right;
|
|
3764
|
+
atIndex += 1 + (at.left ? at.left.length : 0);
|
|
3765
3765
|
} else break;
|
|
3766
|
-
this.splay(at
|
|
3766
|
+
this.splay(at.value);
|
|
3767
3767
|
return this.root.index === index;
|
|
3768
3768
|
}
|
|
3769
3769
|
return false;
|
|
@@ -3776,12 +3776,12 @@ var require_sorted_set = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3776
3776
|
if (this.root) basis = this.root.reduceRight(callback, basis, this.length - 1, thisp, this);
|
|
3777
3777
|
return basis;
|
|
3778
3778
|
};
|
|
3779
|
-
SortedSet.prototype.min = function(at
|
|
3780
|
-
var least = this.findLeast(at
|
|
3779
|
+
SortedSet.prototype.min = function(at) {
|
|
3780
|
+
var least = this.findLeast(at);
|
|
3781
3781
|
if (least) return least.value;
|
|
3782
3782
|
};
|
|
3783
|
-
SortedSet.prototype.max = function(at
|
|
3784
|
-
var greatest = this.findGreatest(at
|
|
3783
|
+
SortedSet.prototype.max = function(at) {
|
|
3784
|
+
var greatest = this.findGreatest(at);
|
|
3785
3785
|
if (greatest) return greatest.value;
|
|
3786
3786
|
};
|
|
3787
3787
|
SortedSet.prototype.one = function() {
|
|
@@ -4338,7 +4338,7 @@ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4338
4338
|
if (!Object.defineProperty || !function() {
|
|
4339
4339
|
try {
|
|
4340
4340
|
return Object.defineProperty({}, "x", {}), !0;
|
|
4341
|
-
} catch (e
|
|
4341
|
+
} catch (e) {
|
|
4342
4342
|
return !1;
|
|
4343
4343
|
}
|
|
4344
4344
|
}()) {
|
|
@@ -4346,14 +4346,14 @@ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4346
4346
|
Object.defineProperty = function(t, r, o) {
|
|
4347
4347
|
if (e) try {
|
|
4348
4348
|
return e(t, r, o);
|
|
4349
|
-
} catch (e
|
|
4349
|
+
} catch (e) {}
|
|
4350
4350
|
if (t !== Object(t)) throw TypeError("Object.defineProperty called on non-object");
|
|
4351
4351
|
return Object.prototype.__defineGetter__ && "get" in o && Object.prototype.__defineGetter__.call(t, r, o.get), Object.prototype.__defineSetter__ && "set" in o && Object.prototype.__defineSetter__.call(t, r, o.set), "value" in o && (t[r] = o.value), t;
|
|
4352
4352
|
};
|
|
4353
4353
|
}
|
|
4354
4354
|
})();
|
|
4355
|
-
(function(exports) {
|
|
4356
|
-
var exports = exports || {};
|
|
4355
|
+
(function(exports$1) {
|
|
4356
|
+
var exports$1 = exports$1 || {};
|
|
4357
4357
|
var l = "function" == typeof Object.defineProperties ? Object.defineProperty : function(c, a, d) {
|
|
4358
4358
|
c != Array.prototype && c != Object.prototype && (c[a] = d.value);
|
|
4359
4359
|
}, m = "undefined" != typeof window && window === this ? this : "undefined" != typeof global && null != global ? global : this;
|
|
@@ -4388,7 +4388,7 @@ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4388
4388
|
}
|
|
4389
4389
|
};
|
|
4390
4390
|
});
|
|
4391
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
4391
|
+
Object.defineProperty(exports$1, "__esModule", { value: !0 });
|
|
4392
4392
|
function q(c, a, d, b) {
|
|
4393
4393
|
b = void 0 === b ? c.length : b;
|
|
4394
4394
|
for (d = void 0 === d ? 0 : d; d < b; d += a) {
|
|
@@ -4531,40 +4531,40 @@ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4531
4531
|
} else if (!c || 1 > c || 53 < c) throw Error("Unsupported type: int, bits: " + c);
|
|
4532
4532
|
return a && 16 === c ? new u(5, 11) : a && 32 == c ? new u(8, 23) : a && 64 == c ? new u(11, 52) : new t(c, d, b);
|
|
4533
4533
|
}
|
|
4534
|
-
exports.pack = function(c, a, d) {
|
|
4534
|
+
exports$1.pack = function(c, a, d) {
|
|
4535
4535
|
var b = [];
|
|
4536
4536
|
A(c, a, b, 0, void 0 === d ? !1 : d);
|
|
4537
4537
|
return b;
|
|
4538
4538
|
};
|
|
4539
|
-
exports.packArray = function(c, a, d) {
|
|
4539
|
+
exports$1.packArray = function(c, a, d) {
|
|
4540
4540
|
var b = [];
|
|
4541
4541
|
w(c, a, b, 0, void 0 === d ? !1 : d);
|
|
4542
4542
|
return b;
|
|
4543
4543
|
};
|
|
4544
|
-
exports.packArrayTo = w;
|
|
4545
|
-
exports.packString = function(c) {
|
|
4544
|
+
exports$1.packArrayTo = w;
|
|
4545
|
+
exports$1.packString = function(c) {
|
|
4546
4546
|
var a = [];
|
|
4547
4547
|
r(c, a);
|
|
4548
4548
|
return a;
|
|
4549
4549
|
};
|
|
4550
|
-
exports.packStringTo = function(c, a, d) {
|
|
4550
|
+
exports$1.packStringTo = function(c, a, d) {
|
|
4551
4551
|
return r(c, a, void 0 === d ? 0 : d);
|
|
4552
4552
|
};
|
|
4553
|
-
exports.packTo = A;
|
|
4554
|
-
exports.unpack = function(c, a, d, b) {
|
|
4553
|
+
exports$1.packTo = A;
|
|
4554
|
+
exports$1.unpack = function(c, a, d, b) {
|
|
4555
4555
|
d = void 0 === d ? 0 : d;
|
|
4556
4556
|
var e = [];
|
|
4557
4557
|
y(c, a, e, d, d + Math.ceil(a.bits / 8), void 0 === b ? !1 : b);
|
|
4558
4558
|
return e[0];
|
|
4559
4559
|
};
|
|
4560
|
-
exports.unpackArray = function(c, a, d, b, e) {
|
|
4560
|
+
exports$1.unpackArray = function(c, a, d, b, e) {
|
|
4561
4561
|
b = void 0 === b ? c.length : b;
|
|
4562
4562
|
var f = [];
|
|
4563
4563
|
y(c, a, f, void 0 === d ? 0 : d, b, void 0 === e ? !1 : e);
|
|
4564
4564
|
return f;
|
|
4565
4565
|
};
|
|
4566
|
-
exports.unpackArrayTo = y;
|
|
4567
|
-
exports.unpackString = function(c, a, d) {
|
|
4566
|
+
exports$1.unpackArrayTo = y;
|
|
4567
|
+
exports$1.unpackString = function(c, a, d) {
|
|
4568
4568
|
d = void 0 === d ? c.length : d;
|
|
4569
4569
|
var b = void 0 === a ? 0 : a;
|
|
4570
4570
|
d = void 0 === d ? c.length : d;
|
|
@@ -4586,14 +4586,14 @@ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4586
4586
|
}
|
|
4587
4587
|
return a;
|
|
4588
4588
|
};
|
|
4589
|
-
typeof module !== "undefined" ? module.exports = exports : typeof define === "function" && define.amd ? define(["exports"], exports) : typeof global !== "undefined" && (global.byteData = exports);
|
|
4590
|
-
return exports;
|
|
4589
|
+
typeof module !== "undefined" ? module.exports = exports$1 : typeof define === "function" && define.amd ? define(["exports"], exports$1) : typeof global !== "undefined" && (global.byteData = exports$1);
|
|
4590
|
+
return exports$1;
|
|
4591
4591
|
})();
|
|
4592
4592
|
}));
|
|
4593
4593
|
|
|
4594
4594
|
//#endregion
|
|
4595
4595
|
//#region src/exact.ts
|
|
4596
|
-
var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
4596
|
+
var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data(), 1);
|
|
4597
4597
|
const hasFract = (n) => {
|
|
4598
4598
|
return n % 1 !== 0;
|
|
4599
4599
|
};
|
|
@@ -4927,8 +4927,8 @@ const f32CborData = (value) => {
|
|
|
4927
4927
|
const f = binary16ToNumber(numberToBinary16(n));
|
|
4928
4928
|
if (f === n) return f16CborData(f);
|
|
4929
4929
|
if (n < 0) {
|
|
4930
|
-
const u
|
|
4931
|
-
if (u
|
|
4930
|
+
const u = ExactU64.exactFromF32(-1 - n);
|
|
4931
|
+
if (u !== void 0) return encodeVarInt(typeof u === "bigint" ? Number(u) : u, MajorType.Negative);
|
|
4932
4932
|
}
|
|
4933
4933
|
const u = ExactU32.exactFromF32(n);
|
|
4934
4934
|
if (u !== void 0) return encodeVarInt(u, MajorType.Unsigned);
|
|
@@ -4945,8 +4945,8 @@ const f32CborData = (value) => {
|
|
|
4945
4945
|
const f16CborData = (value) => {
|
|
4946
4946
|
const n = value;
|
|
4947
4947
|
if (n < 0) {
|
|
4948
|
-
const u
|
|
4949
|
-
if (u
|
|
4948
|
+
const u = ExactU64.exactFromF64(-1 - n);
|
|
4949
|
+
if (u !== void 0) return encodeVarInt(typeof u === "bigint" ? Number(u) : u, MajorType.Negative);
|
|
4950
4950
|
}
|
|
4951
4951
|
const u = ExactU16.exactFromF64(n);
|
|
4952
4952
|
if (u !== void 0) return encodeVarInt(u, MajorType.Unsigned);
|
|
@@ -5100,9 +5100,9 @@ const sanitized = (str) => {
|
|
|
5100
5100
|
* Stores tags with their names and optional summarizer functions.
|
|
5101
5101
|
*/
|
|
5102
5102
|
var TagsStore = class {
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5103
|
+
_tagsByValue = /* @__PURE__ */ new Map();
|
|
5104
|
+
_tagsByName = /* @__PURE__ */ new Map();
|
|
5105
|
+
_summarizers = /* @__PURE__ */ new Map();
|
|
5106
5106
|
constructor() {}
|
|
5107
5107
|
/**
|
|
5108
5108
|
* Insert a tag into the registry.
|
|
@@ -5124,11 +5124,11 @@ var TagsStore = class {
|
|
|
5124
5124
|
insert(tag) {
|
|
5125
5125
|
const name = tag.name;
|
|
5126
5126
|
if (name === void 0 || name === "") throw new Error(`Tag ${tag.value} must have a non-empty name`);
|
|
5127
|
-
const key = this
|
|
5128
|
-
const existing = this
|
|
5127
|
+
const key = this._valueKey(tag.value);
|
|
5128
|
+
const existing = this._tagsByValue.get(key);
|
|
5129
5129
|
if (existing?.name !== void 0 && existing.name !== name) throw new Error(`Attempt to register tag: ${tag.value} '${existing.name}' with different name: '${name}'`);
|
|
5130
|
-
this
|
|
5131
|
-
this
|
|
5130
|
+
this._tagsByValue.set(key, tag);
|
|
5131
|
+
this._tagsByName.set(name, tag);
|
|
5132
5132
|
}
|
|
5133
5133
|
/**
|
|
5134
5134
|
* Insert multiple tags into the registry.
|
|
@@ -5162,31 +5162,31 @@ var TagsStore = class {
|
|
|
5162
5162
|
* });
|
|
5163
5163
|
* ```
|
|
5164
5164
|
*/
|
|
5165
|
-
setSummarizer(tagValue
|
|
5166
|
-
const key = this
|
|
5167
|
-
this
|
|
5165
|
+
setSummarizer(tagValue, summarizer) {
|
|
5166
|
+
const key = this._valueKey(tagValue);
|
|
5167
|
+
this._summarizers.set(key, summarizer);
|
|
5168
5168
|
}
|
|
5169
5169
|
assignedNameForTag(tag) {
|
|
5170
|
-
const key = this
|
|
5171
|
-
return this
|
|
5170
|
+
const key = this._valueKey(tag.value);
|
|
5171
|
+
return this._tagsByValue.get(key)?.name;
|
|
5172
5172
|
}
|
|
5173
5173
|
nameForTag(tag) {
|
|
5174
5174
|
return this.assignedNameForTag(tag) ?? tag.value.toString();
|
|
5175
5175
|
}
|
|
5176
5176
|
tagForValue(value) {
|
|
5177
|
-
const key = this
|
|
5178
|
-
return this
|
|
5177
|
+
const key = this._valueKey(value);
|
|
5178
|
+
return this._tagsByValue.get(key);
|
|
5179
5179
|
}
|
|
5180
5180
|
tagForName(name) {
|
|
5181
|
-
return this
|
|
5181
|
+
return this._tagsByName.get(name);
|
|
5182
5182
|
}
|
|
5183
5183
|
nameForValue(value) {
|
|
5184
5184
|
const tag = this.tagForValue(value);
|
|
5185
5185
|
return tag !== void 0 ? this.nameForTag(tag) : value.toString();
|
|
5186
5186
|
}
|
|
5187
5187
|
summarizer(tag) {
|
|
5188
|
-
const key = this
|
|
5189
|
-
return this
|
|
5188
|
+
const key = this._valueKey(tag);
|
|
5189
|
+
return this._summarizers.get(key);
|
|
5190
5190
|
}
|
|
5191
5191
|
/**
|
|
5192
5192
|
* Create a string key for a numeric tag value.
|
|
@@ -5194,7 +5194,7 @@ var TagsStore = class {
|
|
|
5194
5194
|
*
|
|
5195
5195
|
* @private
|
|
5196
5196
|
*/
|
|
5197
|
-
|
|
5197
|
+
_valueKey(value) {
|
|
5198
5198
|
return value.toString();
|
|
5199
5199
|
}
|
|
5200
5200
|
};
|
|
@@ -5241,9 +5241,9 @@ const bytesToHex = (bytes) => {
|
|
|
5241
5241
|
* Convert hex string to bytes.
|
|
5242
5242
|
*/
|
|
5243
5243
|
const hexToBytes = (hexString) => {
|
|
5244
|
-
const hex
|
|
5245
|
-
const bytes = new Uint8Array(hex
|
|
5246
|
-
for (let i = 0; i < hex
|
|
5244
|
+
const hex = hexString.replace(/\s/g, "");
|
|
5245
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
5246
|
+
for (let i = 0; i < hex.length; i += 2) bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
5247
5247
|
return bytes;
|
|
5248
5248
|
};
|
|
5249
5249
|
/**
|
|
@@ -5252,7 +5252,7 @@ const hexToBytes = (hexString) => {
|
|
|
5252
5252
|
* @param cbor - CBOR value to convert
|
|
5253
5253
|
* @returns Hex string
|
|
5254
5254
|
*/
|
|
5255
|
-
const hex = (cbor
|
|
5255
|
+
const hex = (cbor) => bytesToHex(cborData(cbor));
|
|
5256
5256
|
/**
|
|
5257
5257
|
* Returns the encoded hexadecimal representation of CBOR with options.
|
|
5258
5258
|
*
|
|
@@ -5264,9 +5264,9 @@ const hex = (cbor$1) => bytesToHex(cborData(cbor$1));
|
|
|
5264
5264
|
* @param opts - Formatting options
|
|
5265
5265
|
* @returns Hex string (possibly annotated)
|
|
5266
5266
|
*/
|
|
5267
|
-
const hexOpt = (cbor
|
|
5268
|
-
if (opts.annotate !== true) return hex(cbor
|
|
5269
|
-
const items = dumpItems(cbor
|
|
5267
|
+
const hexOpt = (cbor, opts = {}) => {
|
|
5268
|
+
if (opts.annotate !== true) return hex(cbor);
|
|
5269
|
+
const items = dumpItems(cbor, 0, opts);
|
|
5270
5270
|
const roundedNoteColumn = (items.reduce((largest, item) => {
|
|
5271
5271
|
return Math.max(largest, item.formatFirstColumn().length);
|
|
5272
5272
|
}, 0) + 4 & -4) - 1;
|
|
@@ -5299,35 +5299,35 @@ var DumpItem = class {
|
|
|
5299
5299
|
/**
|
|
5300
5300
|
* Generate dump items for a CBOR value (recursive).
|
|
5301
5301
|
*/
|
|
5302
|
-
function dumpItems(cbor
|
|
5302
|
+
function dumpItems(cbor, level, opts) {
|
|
5303
5303
|
const items = [];
|
|
5304
|
-
switch (cbor
|
|
5304
|
+
switch (cbor.type) {
|
|
5305
5305
|
case MajorType.Unsigned: {
|
|
5306
|
-
const data = cborData(cbor
|
|
5307
|
-
items.push(new DumpItem(level, [data], `unsigned(${cbor
|
|
5306
|
+
const data = cborData(cbor);
|
|
5307
|
+
items.push(new DumpItem(level, [data], `unsigned(${cbor.value})`));
|
|
5308
5308
|
break;
|
|
5309
5309
|
}
|
|
5310
5310
|
case MajorType.Negative: {
|
|
5311
|
-
const data = cborData(cbor
|
|
5312
|
-
const actualValue = typeof cbor
|
|
5311
|
+
const data = cborData(cbor);
|
|
5312
|
+
const actualValue = typeof cbor.value === "bigint" ? -1n - cbor.value : -1 - cbor.value;
|
|
5313
5313
|
items.push(new DumpItem(level, [data], `negative(${actualValue})`));
|
|
5314
5314
|
break;
|
|
5315
5315
|
}
|
|
5316
5316
|
case MajorType.ByteString: {
|
|
5317
|
-
const header = encodeVarInt(cbor
|
|
5318
|
-
items.push(new DumpItem(level, [header], `bytes(${cbor
|
|
5319
|
-
if (cbor
|
|
5317
|
+
const header = encodeVarInt(cbor.value.length, MajorType.ByteString);
|
|
5318
|
+
items.push(new DumpItem(level, [header], `bytes(${cbor.value.length})`));
|
|
5319
|
+
if (cbor.value.length > 0) {
|
|
5320
5320
|
let note = void 0;
|
|
5321
5321
|
try {
|
|
5322
|
-
const sanitizedText = sanitized(new TextDecoder("utf-8", { fatal: true }).decode(cbor
|
|
5322
|
+
const sanitizedText = sanitized(new TextDecoder("utf-8", { fatal: true }).decode(cbor.value));
|
|
5323
5323
|
if (sanitizedText !== void 0 && sanitizedText !== "") note = flanked(sanitizedText, "\"", "\"");
|
|
5324
5324
|
} catch {}
|
|
5325
|
-
items.push(new DumpItem(level + 1, [cbor
|
|
5325
|
+
items.push(new DumpItem(level + 1, [cbor.value], note));
|
|
5326
5326
|
}
|
|
5327
5327
|
break;
|
|
5328
5328
|
}
|
|
5329
5329
|
case MajorType.Text: {
|
|
5330
|
-
const utf8Data = new TextEncoder().encode(cbor
|
|
5330
|
+
const utf8Data = new TextEncoder().encode(cbor.value);
|
|
5331
5331
|
const header = encodeVarInt(utf8Data.length, MajorType.Text);
|
|
5332
5332
|
const firstByte = header[0];
|
|
5333
5333
|
if (firstByte === void 0) throw new CborError({
|
|
@@ -5336,61 +5336,61 @@ function dumpItems(cbor$1, level, opts) {
|
|
|
5336
5336
|
});
|
|
5337
5337
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5338
5338
|
items.push(new DumpItem(level, headerData, `text(${utf8Data.length})`));
|
|
5339
|
-
items.push(new DumpItem(level + 1, [utf8Data], flanked(cbor
|
|
5339
|
+
items.push(new DumpItem(level + 1, [utf8Data], flanked(cbor.value, "\"", "\"")));
|
|
5340
5340
|
break;
|
|
5341
5341
|
}
|
|
5342
5342
|
case MajorType.Array: {
|
|
5343
|
-
const header = encodeVarInt(cbor
|
|
5343
|
+
const header = encodeVarInt(cbor.value.length, MajorType.Array);
|
|
5344
5344
|
const firstByte = header[0];
|
|
5345
5345
|
if (firstByte === void 0) throw new CborError({
|
|
5346
5346
|
type: "Custom",
|
|
5347
5347
|
message: "Invalid varint encoding"
|
|
5348
5348
|
});
|
|
5349
5349
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5350
|
-
items.push(new DumpItem(level, headerData, `array(${cbor
|
|
5351
|
-
for (const item of cbor
|
|
5350
|
+
items.push(new DumpItem(level, headerData, `array(${cbor.value.length})`));
|
|
5351
|
+
for (const item of cbor.value) items.push(...dumpItems(item, level + 1, opts));
|
|
5352
5352
|
break;
|
|
5353
5353
|
}
|
|
5354
5354
|
case MajorType.Map: {
|
|
5355
|
-
const header = encodeVarInt(cbor
|
|
5355
|
+
const header = encodeVarInt(cbor.value.size, MajorType.Map);
|
|
5356
5356
|
const firstByte = header[0];
|
|
5357
5357
|
if (firstByte === void 0) throw new CborError({
|
|
5358
5358
|
type: "Custom",
|
|
5359
5359
|
message: "Invalid varint encoding"
|
|
5360
5360
|
});
|
|
5361
5361
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5362
|
-
items.push(new DumpItem(level, headerData, `map(${cbor
|
|
5363
|
-
for (const entry of cbor
|
|
5362
|
+
items.push(new DumpItem(level, headerData, `map(${cbor.value.size})`));
|
|
5363
|
+
for (const entry of cbor.value.entriesArray) {
|
|
5364
5364
|
items.push(...dumpItems(entry.key, level + 1, opts));
|
|
5365
5365
|
items.push(...dumpItems(entry.value, level + 1, opts));
|
|
5366
5366
|
}
|
|
5367
5367
|
break;
|
|
5368
5368
|
}
|
|
5369
5369
|
case MajorType.Tagged: {
|
|
5370
|
-
const tagValue
|
|
5371
|
-
if (tagValue
|
|
5370
|
+
const tagValue = cbor.tag;
|
|
5371
|
+
if (tagValue === void 0) throw new CborError({
|
|
5372
5372
|
type: "Custom",
|
|
5373
5373
|
message: "Tagged CBOR value must have a tag"
|
|
5374
5374
|
});
|
|
5375
|
-
const header = encodeVarInt(typeof tagValue
|
|
5375
|
+
const header = encodeVarInt(typeof tagValue === "bigint" ? Number(tagValue) : tagValue, MajorType.Tagged);
|
|
5376
5376
|
const firstByte = header[0];
|
|
5377
5377
|
if (firstByte === void 0) throw new CborError({
|
|
5378
5378
|
type: "Custom",
|
|
5379
5379
|
message: "Invalid varint encoding"
|
|
5380
5380
|
});
|
|
5381
5381
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5382
|
-
const noteComponents = [`tag(${tagValue
|
|
5383
|
-
const tag = createTag(typeof tagValue
|
|
5382
|
+
const noteComponents = [`tag(${tagValue})`];
|
|
5383
|
+
const tag = createTag(typeof tagValue === "bigint" ? Number(tagValue) : tagValue);
|
|
5384
5384
|
const tagName = opts.tagsStore?.assignedNameForTag(tag);
|
|
5385
5385
|
if (tagName !== void 0) noteComponents.push(tagName);
|
|
5386
5386
|
const tagNote = noteComponents.join(" ");
|
|
5387
5387
|
items.push(new DumpItem(level, headerData, tagNote));
|
|
5388
|
-
items.push(...dumpItems(cbor
|
|
5388
|
+
items.push(...dumpItems(cbor.value, level + 1, opts));
|
|
5389
5389
|
break;
|
|
5390
5390
|
}
|
|
5391
5391
|
case MajorType.Simple: {
|
|
5392
|
-
const data = cborData(cbor
|
|
5393
|
-
const simple = cbor
|
|
5392
|
+
const data = cborData(cbor);
|
|
5393
|
+
const simple = cbor.value;
|
|
5394
5394
|
let note;
|
|
5395
5395
|
if (simple.type === "True") note = "true";
|
|
5396
5396
|
else if (simple.type === "False") note = "false";
|
|
@@ -5446,8 +5446,8 @@ const DEFAULT_OPTS = {
|
|
|
5446
5446
|
* // date(1234567890)
|
|
5447
5447
|
* ```
|
|
5448
5448
|
*/
|
|
5449
|
-
function diagnosticOpt(cbor
|
|
5450
|
-
return formatDiagnostic(cbor
|
|
5449
|
+
function diagnosticOpt(cbor, opts) {
|
|
5450
|
+
return formatDiagnostic(cbor, {
|
|
5451
5451
|
...DEFAULT_OPTS,
|
|
5452
5452
|
...opts
|
|
5453
5453
|
});
|
|
@@ -5466,8 +5466,8 @@ function diagnosticOpt(cbor$1, opts) {
|
|
|
5466
5466
|
* // For nested structures: multi-line formatted output
|
|
5467
5467
|
* ```
|
|
5468
5468
|
*/
|
|
5469
|
-
function diagnostic(cbor
|
|
5470
|
-
return diagnosticOpt(cbor
|
|
5469
|
+
function diagnostic(cbor) {
|
|
5470
|
+
return diagnosticOpt(cbor);
|
|
5471
5471
|
}
|
|
5472
5472
|
/**
|
|
5473
5473
|
* Format CBOR value using custom summarizers for tagged values.
|
|
@@ -5486,8 +5486,8 @@ function diagnostic(cbor$1) {
|
|
|
5486
5486
|
* // "custom-summary" (instead of full content)
|
|
5487
5487
|
* ```
|
|
5488
5488
|
*/
|
|
5489
|
-
function summary(cbor
|
|
5490
|
-
return diagnosticOpt(cbor
|
|
5489
|
+
function summary(cbor) {
|
|
5490
|
+
return diagnosticOpt(cbor, {
|
|
5491
5491
|
summarize: true,
|
|
5492
5492
|
flat: true
|
|
5493
5493
|
});
|
|
@@ -5497,16 +5497,16 @@ function summary(cbor$1) {
|
|
|
5497
5497
|
*
|
|
5498
5498
|
* @internal
|
|
5499
5499
|
*/
|
|
5500
|
-
function formatDiagnostic(cbor
|
|
5501
|
-
switch (cbor
|
|
5502
|
-
case MajorType.Unsigned: return formatUnsigned(cbor
|
|
5503
|
-
case MajorType.Negative: return formatNegative(cbor
|
|
5504
|
-
case MajorType.ByteString: return formatBytes(cbor
|
|
5505
|
-
case MajorType.Text: return formatText(cbor
|
|
5506
|
-
case MajorType.Array: return formatArray(cbor
|
|
5507
|
-
case MajorType.Map: return formatMap(cbor
|
|
5508
|
-
case MajorType.Tagged: return formatTagged(cbor
|
|
5509
|
-
case MajorType.Simple: return formatSimple(cbor
|
|
5500
|
+
function formatDiagnostic(cbor, opts) {
|
|
5501
|
+
switch (cbor.type) {
|
|
5502
|
+
case MajorType.Unsigned: return formatUnsigned(cbor.value);
|
|
5503
|
+
case MajorType.Negative: return formatNegative(cbor.value);
|
|
5504
|
+
case MajorType.ByteString: return formatBytes(cbor.value);
|
|
5505
|
+
case MajorType.Text: return formatText(cbor.value);
|
|
5506
|
+
case MajorType.Array: return formatArray(cbor.value, opts);
|
|
5507
|
+
case MajorType.Map: return formatMap(cbor.value, opts);
|
|
5508
|
+
case MajorType.Tagged: return formatTagged(cbor.tag, cbor.value, opts);
|
|
5509
|
+
case MajorType.Simple: return formatSimple(cbor.value);
|
|
5510
5510
|
}
|
|
5511
5511
|
}
|
|
5512
5512
|
/**
|
|
@@ -5587,9 +5587,9 @@ function formatTagged(tag, content, opts) {
|
|
|
5587
5587
|
if (opts.summarize === true) {
|
|
5588
5588
|
const summarizer = resolveTagsStore(opts.tags)?.summarizer(tag);
|
|
5589
5589
|
if (summarizer !== void 0) {
|
|
5590
|
-
const result
|
|
5591
|
-
if (result
|
|
5592
|
-
else return `<error: ${result
|
|
5590
|
+
const result = summarizer(content, opts.flat ?? false);
|
|
5591
|
+
if (result.ok) return result.value;
|
|
5592
|
+
else return `<error: ${result.error.type === "Custom" ? result.error.message : result.error.type === "WrongTag" ? `expected CBOR tag ${result.error.expected.value}, but got ${result.error.actual.value}` : result.error.type}>`;
|
|
5593
5593
|
}
|
|
5594
5594
|
}
|
|
5595
5595
|
let comment;
|
|
@@ -5692,13 +5692,13 @@ const simpleCborData = (simple) => {
|
|
|
5692
5692
|
//#endregion
|
|
5693
5693
|
//#region src/decode.ts
|
|
5694
5694
|
function decodeCbor(data) {
|
|
5695
|
-
const { cbor
|
|
5695
|
+
const { cbor, len } = decodeCborInternal(new DataView(data.buffer, data.byteOffset, data.byteLength));
|
|
5696
5696
|
const remaining = data.length - len;
|
|
5697
5697
|
if (remaining !== 0) throw new CborError({
|
|
5698
5698
|
type: "UnusedData",
|
|
5699
5699
|
count: remaining
|
|
5700
5700
|
});
|
|
5701
|
-
return cbor
|
|
5701
|
+
return cbor;
|
|
5702
5702
|
}
|
|
5703
5703
|
function parseHeader(header) {
|
|
5704
5704
|
return {
|
|
@@ -5773,26 +5773,26 @@ function decodeCborInternal(data) {
|
|
|
5773
5773
|
const { majorType, value, varIntLen } = parseHeaderVarint(data);
|
|
5774
5774
|
switch (majorType) {
|
|
5775
5775
|
case MajorType.Unsigned: {
|
|
5776
|
-
const cbor
|
|
5776
|
+
const cbor = attachMethods({
|
|
5777
5777
|
isCbor: true,
|
|
5778
5778
|
type: MajorType.Unsigned,
|
|
5779
5779
|
value
|
|
5780
5780
|
});
|
|
5781
|
-
checkCanonicalEncoding(cbor
|
|
5781
|
+
checkCanonicalEncoding(cbor, new Uint8Array(data.buffer, data.byteOffset, varIntLen));
|
|
5782
5782
|
return {
|
|
5783
|
-
cbor
|
|
5783
|
+
cbor,
|
|
5784
5784
|
len: varIntLen
|
|
5785
5785
|
};
|
|
5786
5786
|
}
|
|
5787
5787
|
case MajorType.Negative: {
|
|
5788
|
-
const cbor
|
|
5788
|
+
const cbor = attachMethods({
|
|
5789
5789
|
isCbor: true,
|
|
5790
5790
|
type: MajorType.Negative,
|
|
5791
5791
|
value
|
|
5792
5792
|
});
|
|
5793
|
-
checkCanonicalEncoding(cbor
|
|
5793
|
+
checkCanonicalEncoding(cbor, new Uint8Array(data.buffer, data.byteOffset, varIntLen));
|
|
5794
5794
|
return {
|
|
5795
|
-
cbor
|
|
5795
|
+
cbor,
|
|
5796
5796
|
len: varIntLen
|
|
5797
5797
|
};
|
|
5798
5798
|
}
|
|
@@ -5848,9 +5848,9 @@ function decodeCborInternal(data) {
|
|
|
5848
5848
|
for (let i = 0; i < value; i++) {
|
|
5849
5849
|
const { cbor: key, len: keyLen } = decodeCborInternal(from(data, pos));
|
|
5850
5850
|
pos += keyLen;
|
|
5851
|
-
const { cbor: value
|
|
5851
|
+
const { cbor: value, len: valueLen } = decodeCborInternal(from(data, pos));
|
|
5852
5852
|
pos += valueLen;
|
|
5853
|
-
map.setNext(key, value
|
|
5853
|
+
map.setNext(key, value);
|
|
5854
5854
|
}
|
|
5855
5855
|
return {
|
|
5856
5856
|
cbor: attachMethods({
|
|
@@ -5949,8 +5949,8 @@ function decodeCborInternal(data) {
|
|
|
5949
5949
|
}
|
|
5950
5950
|
}
|
|
5951
5951
|
}
|
|
5952
|
-
function checkCanonicalEncoding(cbor
|
|
5953
|
-
if (!areBytesEqual(buf, isCbor(cbor
|
|
5952
|
+
function checkCanonicalEncoding(cbor, buf) {
|
|
5953
|
+
if (!areBytesEqual(buf, isCbor(cbor) ? cborData(cbor) : encodeCbor(cbor))) throw new CborError({ type: "NonCanonicalNumeric" });
|
|
5954
5954
|
}
|
|
5955
5955
|
|
|
5956
5956
|
//#endregion
|
|
@@ -5967,10 +5967,10 @@ function checkCanonicalEncoding(cbor$1, buf) {
|
|
|
5967
5967
|
* Extract native JavaScript value from CBOR.
|
|
5968
5968
|
* Converts CBOR types to their JavaScript equivalents.
|
|
5969
5969
|
*/
|
|
5970
|
-
const extractCbor = (cbor
|
|
5970
|
+
const extractCbor = (cbor) => {
|
|
5971
5971
|
let c;
|
|
5972
|
-
if (cbor
|
|
5973
|
-
else c = cbor
|
|
5972
|
+
if (cbor instanceof Uint8Array) c = decodeCbor(cbor);
|
|
5973
|
+
else c = cbor;
|
|
5974
5974
|
switch (c.type) {
|
|
5975
5975
|
case MajorType.Unsigned: return c.value;
|
|
5976
5976
|
case MajorType.Negative: if (typeof c.value === "bigint") return -c.value - 1n;
|
|
@@ -6001,8 +6001,8 @@ const extractCbor = (cbor$1) => {
|
|
|
6001
6001
|
* }
|
|
6002
6002
|
* ```
|
|
6003
6003
|
*/
|
|
6004
|
-
const isUnsigned = (cbor
|
|
6005
|
-
return cbor
|
|
6004
|
+
const isUnsigned = (cbor) => {
|
|
6005
|
+
return cbor.type === MajorType.Unsigned;
|
|
6006
6006
|
};
|
|
6007
6007
|
/**
|
|
6008
6008
|
* Check if CBOR value is a negative integer.
|
|
@@ -6010,8 +6010,8 @@ const isUnsigned = (cbor$1) => {
|
|
|
6010
6010
|
* @param cbor - CBOR value to check
|
|
6011
6011
|
* @returns True if value is negative integer
|
|
6012
6012
|
*/
|
|
6013
|
-
const isNegative = (cbor
|
|
6014
|
-
return cbor
|
|
6013
|
+
const isNegative = (cbor) => {
|
|
6014
|
+
return cbor.type === MajorType.Negative;
|
|
6015
6015
|
};
|
|
6016
6016
|
/**
|
|
6017
6017
|
* Check if CBOR value is any integer (unsigned or negative).
|
|
@@ -6019,8 +6019,8 @@ const isNegative = (cbor$1) => {
|
|
|
6019
6019
|
* @param cbor - CBOR value to check
|
|
6020
6020
|
* @returns True if value is an integer
|
|
6021
6021
|
*/
|
|
6022
|
-
const isInteger = (cbor
|
|
6023
|
-
return cbor
|
|
6022
|
+
const isInteger = (cbor) => {
|
|
6023
|
+
return cbor.type === MajorType.Unsigned || cbor.type === MajorType.Negative;
|
|
6024
6024
|
};
|
|
6025
6025
|
/**
|
|
6026
6026
|
* Check if CBOR value is a byte string.
|
|
@@ -6028,8 +6028,8 @@ const isInteger = (cbor$1) => {
|
|
|
6028
6028
|
* @param cbor - CBOR value to check
|
|
6029
6029
|
* @returns True if value is byte string
|
|
6030
6030
|
*/
|
|
6031
|
-
const isBytes = (cbor
|
|
6032
|
-
return cbor
|
|
6031
|
+
const isBytes = (cbor) => {
|
|
6032
|
+
return cbor.type === MajorType.ByteString;
|
|
6033
6033
|
};
|
|
6034
6034
|
/**
|
|
6035
6035
|
* Check if CBOR value is a text string.
|
|
@@ -6037,8 +6037,8 @@ const isBytes = (cbor$1) => {
|
|
|
6037
6037
|
* @param cbor - CBOR value to check
|
|
6038
6038
|
* @returns True if value is text string
|
|
6039
6039
|
*/
|
|
6040
|
-
const isText = (cbor
|
|
6041
|
-
return cbor
|
|
6040
|
+
const isText = (cbor) => {
|
|
6041
|
+
return cbor.type === MajorType.Text;
|
|
6042
6042
|
};
|
|
6043
6043
|
/**
|
|
6044
6044
|
* Check if CBOR value is an array.
|
|
@@ -6046,8 +6046,8 @@ const isText = (cbor$1) => {
|
|
|
6046
6046
|
* @param cbor - CBOR value to check
|
|
6047
6047
|
* @returns True if value is array
|
|
6048
6048
|
*/
|
|
6049
|
-
const isArray = (cbor
|
|
6050
|
-
return cbor
|
|
6049
|
+
const isArray = (cbor) => {
|
|
6050
|
+
return cbor.type === MajorType.Array;
|
|
6051
6051
|
};
|
|
6052
6052
|
/**
|
|
6053
6053
|
* Check if CBOR value is a map.
|
|
@@ -6055,8 +6055,8 @@ const isArray = (cbor$1) => {
|
|
|
6055
6055
|
* @param cbor - CBOR value to check
|
|
6056
6056
|
* @returns True if value is map
|
|
6057
6057
|
*/
|
|
6058
|
-
const isMap = (cbor
|
|
6059
|
-
return cbor
|
|
6058
|
+
const isMap = (cbor) => {
|
|
6059
|
+
return cbor.type === MajorType.Map;
|
|
6060
6060
|
};
|
|
6061
6061
|
/**
|
|
6062
6062
|
* Check if CBOR value is tagged.
|
|
@@ -6064,8 +6064,8 @@ const isMap = (cbor$1) => {
|
|
|
6064
6064
|
* @param cbor - CBOR value to check
|
|
6065
6065
|
* @returns True if value is tagged
|
|
6066
6066
|
*/
|
|
6067
|
-
const isTagged = (cbor
|
|
6068
|
-
return cbor
|
|
6067
|
+
const isTagged = (cbor) => {
|
|
6068
|
+
return cbor.type === MajorType.Tagged;
|
|
6069
6069
|
};
|
|
6070
6070
|
/**
|
|
6071
6071
|
* Check if CBOR value is a simple value.
|
|
@@ -6073,8 +6073,8 @@ const isTagged = (cbor$1) => {
|
|
|
6073
6073
|
* @param cbor - CBOR value to check
|
|
6074
6074
|
* @returns True if value is simple
|
|
6075
6075
|
*/
|
|
6076
|
-
const isSimple = (cbor
|
|
6077
|
-
return cbor
|
|
6076
|
+
const isSimple = (cbor) => {
|
|
6077
|
+
return cbor.type === MajorType.Simple;
|
|
6078
6078
|
};
|
|
6079
6079
|
/**
|
|
6080
6080
|
* Check if CBOR value is a boolean (true or false).
|
|
@@ -6082,9 +6082,9 @@ const isSimple = (cbor$1) => {
|
|
|
6082
6082
|
* @param cbor - CBOR value to check
|
|
6083
6083
|
* @returns True if value is boolean
|
|
6084
6084
|
*/
|
|
6085
|
-
const isBoolean = (cbor
|
|
6086
|
-
if (cbor
|
|
6087
|
-
return cbor
|
|
6085
|
+
const isBoolean = (cbor) => {
|
|
6086
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6087
|
+
return cbor.value.type === "False" || cbor.value.type === "True";
|
|
6088
6088
|
};
|
|
6089
6089
|
/**
|
|
6090
6090
|
* Check if CBOR value is null.
|
|
@@ -6092,9 +6092,9 @@ const isBoolean = (cbor$1) => {
|
|
|
6092
6092
|
* @param cbor - CBOR value to check
|
|
6093
6093
|
* @returns True if value is null
|
|
6094
6094
|
*/
|
|
6095
|
-
const isNull = (cbor
|
|
6096
|
-
if (cbor
|
|
6097
|
-
return cbor
|
|
6095
|
+
const isNull = (cbor) => {
|
|
6096
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6097
|
+
return cbor.value.type === "Null";
|
|
6098
6098
|
};
|
|
6099
6099
|
/**
|
|
6100
6100
|
* Check if CBOR value is a float (f16, f32, or f64).
|
|
@@ -6102,9 +6102,9 @@ const isNull = (cbor$1) => {
|
|
|
6102
6102
|
* @param cbor - CBOR value to check
|
|
6103
6103
|
* @returns True if value is float
|
|
6104
6104
|
*/
|
|
6105
|
-
const isFloat = (cbor
|
|
6106
|
-
if (cbor
|
|
6107
|
-
return isFloat$1(cbor
|
|
6105
|
+
const isFloat = (cbor) => {
|
|
6106
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6107
|
+
return isFloat$1(cbor.value);
|
|
6108
6108
|
};
|
|
6109
6109
|
/**
|
|
6110
6110
|
* Extract unsigned integer value if type matches.
|
|
@@ -6112,8 +6112,8 @@ const isFloat = (cbor$1) => {
|
|
|
6112
6112
|
* @param cbor - CBOR value
|
|
6113
6113
|
* @returns Unsigned integer or undefined
|
|
6114
6114
|
*/
|
|
6115
|
-
const asUnsigned = (cbor
|
|
6116
|
-
if (cbor
|
|
6115
|
+
const asUnsigned = (cbor) => {
|
|
6116
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6117
6117
|
};
|
|
6118
6118
|
/**
|
|
6119
6119
|
* Extract negative integer value if type matches.
|
|
@@ -6121,9 +6121,9 @@ const asUnsigned = (cbor$1) => {
|
|
|
6121
6121
|
* @param cbor - CBOR value
|
|
6122
6122
|
* @returns Negative integer or undefined
|
|
6123
6123
|
*/
|
|
6124
|
-
const asNegative = (cbor
|
|
6125
|
-
if (cbor
|
|
6126
|
-
else return -cbor
|
|
6124
|
+
const asNegative = (cbor) => {
|
|
6125
|
+
if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6126
|
+
else return -cbor.value - 1;
|
|
6127
6127
|
};
|
|
6128
6128
|
/**
|
|
6129
6129
|
* Extract any integer value (unsigned or negative) if type matches.
|
|
@@ -6131,10 +6131,10 @@ const asNegative = (cbor$1) => {
|
|
|
6131
6131
|
* @param cbor - CBOR value
|
|
6132
6132
|
* @returns Integer or undefined
|
|
6133
6133
|
*/
|
|
6134
|
-
const asInteger = (cbor
|
|
6135
|
-
if (cbor
|
|
6136
|
-
else if (cbor
|
|
6137
|
-
else return -cbor
|
|
6134
|
+
const asInteger = (cbor) => {
|
|
6135
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6136
|
+
else if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6137
|
+
else return -cbor.value - 1;
|
|
6138
6138
|
};
|
|
6139
6139
|
/**
|
|
6140
6140
|
* Extract byte string value if type matches.
|
|
@@ -6142,8 +6142,8 @@ const asInteger = (cbor$1) => {
|
|
|
6142
6142
|
* @param cbor - CBOR value
|
|
6143
6143
|
* @returns Byte string or undefined
|
|
6144
6144
|
*/
|
|
6145
|
-
const asBytes = (cbor
|
|
6146
|
-
if (cbor
|
|
6145
|
+
const asBytes = (cbor) => {
|
|
6146
|
+
if (cbor.type === MajorType.ByteString) return cbor.value;
|
|
6147
6147
|
};
|
|
6148
6148
|
/**
|
|
6149
6149
|
* Extract text string value if type matches.
|
|
@@ -6151,8 +6151,8 @@ const asBytes = (cbor$1) => {
|
|
|
6151
6151
|
* @param cbor - CBOR value
|
|
6152
6152
|
* @returns Text string or undefined
|
|
6153
6153
|
*/
|
|
6154
|
-
const asText = (cbor
|
|
6155
|
-
if (cbor
|
|
6154
|
+
const asText = (cbor) => {
|
|
6155
|
+
if (cbor.type === MajorType.Text) return cbor.value;
|
|
6156
6156
|
};
|
|
6157
6157
|
/**
|
|
6158
6158
|
* Extract array value if type matches.
|
|
@@ -6160,8 +6160,8 @@ const asText = (cbor$1) => {
|
|
|
6160
6160
|
* @param cbor - CBOR value
|
|
6161
6161
|
* @returns Array or undefined
|
|
6162
6162
|
*/
|
|
6163
|
-
const asArray = (cbor
|
|
6164
|
-
if (cbor
|
|
6163
|
+
const asArray = (cbor) => {
|
|
6164
|
+
if (cbor.type === MajorType.Array) return cbor.value;
|
|
6165
6165
|
};
|
|
6166
6166
|
/**
|
|
6167
6167
|
* Extract map value if type matches.
|
|
@@ -6169,8 +6169,8 @@ const asArray = (cbor$1) => {
|
|
|
6169
6169
|
* @param cbor - CBOR value
|
|
6170
6170
|
* @returns Map or undefined
|
|
6171
6171
|
*/
|
|
6172
|
-
const asMap = (cbor
|
|
6173
|
-
if (cbor
|
|
6172
|
+
const asMap = (cbor) => {
|
|
6173
|
+
if (cbor.type === MajorType.Map) return cbor.value;
|
|
6174
6174
|
};
|
|
6175
6175
|
/**
|
|
6176
6176
|
* Extract boolean value if type matches.
|
|
@@ -6178,10 +6178,10 @@ const asMap = (cbor$1) => {
|
|
|
6178
6178
|
* @param cbor - CBOR value
|
|
6179
6179
|
* @returns Boolean or undefined
|
|
6180
6180
|
*/
|
|
6181
|
-
const asBoolean = (cbor
|
|
6182
|
-
if (cbor
|
|
6183
|
-
if (cbor
|
|
6184
|
-
if (cbor
|
|
6181
|
+
const asBoolean = (cbor) => {
|
|
6182
|
+
if (cbor.type !== MajorType.Simple) return;
|
|
6183
|
+
if (cbor.value.type === "True") return true;
|
|
6184
|
+
if (cbor.value.type === "False") return false;
|
|
6185
6185
|
};
|
|
6186
6186
|
/**
|
|
6187
6187
|
* Extract float value if type matches.
|
|
@@ -6189,9 +6189,9 @@ const asBoolean = (cbor$1) => {
|
|
|
6189
6189
|
* @param cbor - CBOR value
|
|
6190
6190
|
* @returns Float or undefined
|
|
6191
6191
|
*/
|
|
6192
|
-
const asFloat = (cbor
|
|
6193
|
-
if (cbor
|
|
6194
|
-
const simple = cbor
|
|
6192
|
+
const asFloat = (cbor) => {
|
|
6193
|
+
if (cbor.type !== MajorType.Simple) return;
|
|
6194
|
+
const simple = cbor.value;
|
|
6195
6195
|
if (isFloat$1(simple)) return simple.value;
|
|
6196
6196
|
};
|
|
6197
6197
|
/**
|
|
@@ -6200,12 +6200,12 @@ const asFloat = (cbor$1) => {
|
|
|
6200
6200
|
* @param cbor - CBOR value
|
|
6201
6201
|
* @returns Number or undefined
|
|
6202
6202
|
*/
|
|
6203
|
-
const asNumber = (cbor
|
|
6204
|
-
if (cbor
|
|
6205
|
-
if (cbor
|
|
6206
|
-
else return -cbor
|
|
6207
|
-
if (cbor
|
|
6208
|
-
const simple = cbor
|
|
6203
|
+
const asNumber = (cbor) => {
|
|
6204
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6205
|
+
if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6206
|
+
else return -cbor.value - 1;
|
|
6207
|
+
if (cbor.type === MajorType.Simple) {
|
|
6208
|
+
const simple = cbor.value;
|
|
6209
6209
|
if (isFloat$1(simple)) return simple.value;
|
|
6210
6210
|
}
|
|
6211
6211
|
};
|
|
@@ -6216,8 +6216,8 @@ const asNumber = (cbor$1) => {
|
|
|
6216
6216
|
* @returns Unsigned integer
|
|
6217
6217
|
* @throws {CborError} With type 'WrongType' if cbor is not an unsigned integer
|
|
6218
6218
|
*/
|
|
6219
|
-
const expectUnsigned = (cbor
|
|
6220
|
-
const value = asUnsigned(cbor
|
|
6219
|
+
const expectUnsigned = (cbor) => {
|
|
6220
|
+
const value = asUnsigned(cbor);
|
|
6221
6221
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6222
6222
|
return value;
|
|
6223
6223
|
};
|
|
@@ -6228,8 +6228,8 @@ const expectUnsigned = (cbor$1) => {
|
|
|
6228
6228
|
* @returns Negative integer
|
|
6229
6229
|
* @throws {CborError} With type 'WrongType' if cbor is not a negative integer
|
|
6230
6230
|
*/
|
|
6231
|
-
const expectNegative = (cbor
|
|
6232
|
-
const value = asNegative(cbor
|
|
6231
|
+
const expectNegative = (cbor) => {
|
|
6232
|
+
const value = asNegative(cbor);
|
|
6233
6233
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6234
6234
|
return value;
|
|
6235
6235
|
};
|
|
@@ -6240,8 +6240,8 @@ const expectNegative = (cbor$1) => {
|
|
|
6240
6240
|
* @returns Integer
|
|
6241
6241
|
* @throws {CborError} With type 'WrongType' if cbor is not an integer
|
|
6242
6242
|
*/
|
|
6243
|
-
const expectInteger = (cbor
|
|
6244
|
-
const value = asInteger(cbor
|
|
6243
|
+
const expectInteger = (cbor) => {
|
|
6244
|
+
const value = asInteger(cbor);
|
|
6245
6245
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6246
6246
|
return value;
|
|
6247
6247
|
};
|
|
@@ -6252,8 +6252,8 @@ const expectInteger = (cbor$1) => {
|
|
|
6252
6252
|
* @returns Byte string
|
|
6253
6253
|
* @throws {CborError} With type 'WrongType' if cbor is not a byte string
|
|
6254
6254
|
*/
|
|
6255
|
-
const expectBytes = (cbor
|
|
6256
|
-
const value = asBytes(cbor
|
|
6255
|
+
const expectBytes = (cbor) => {
|
|
6256
|
+
const value = asBytes(cbor);
|
|
6257
6257
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6258
6258
|
return value;
|
|
6259
6259
|
};
|
|
@@ -6264,8 +6264,8 @@ const expectBytes = (cbor$1) => {
|
|
|
6264
6264
|
* @returns Text string
|
|
6265
6265
|
* @throws {CborError} With type 'WrongType' if cbor is not a text string
|
|
6266
6266
|
*/
|
|
6267
|
-
const expectText = (cbor
|
|
6268
|
-
const value = asText(cbor
|
|
6267
|
+
const expectText = (cbor) => {
|
|
6268
|
+
const value = asText(cbor);
|
|
6269
6269
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6270
6270
|
return value;
|
|
6271
6271
|
};
|
|
@@ -6276,8 +6276,8 @@ const expectText = (cbor$1) => {
|
|
|
6276
6276
|
* @returns Array
|
|
6277
6277
|
* @throws {CborError} With type 'WrongType' if cbor is not an array
|
|
6278
6278
|
*/
|
|
6279
|
-
const expectArray = (cbor
|
|
6280
|
-
const value = asArray(cbor
|
|
6279
|
+
const expectArray = (cbor) => {
|
|
6280
|
+
const value = asArray(cbor);
|
|
6281
6281
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6282
6282
|
return value;
|
|
6283
6283
|
};
|
|
@@ -6288,8 +6288,8 @@ const expectArray = (cbor$1) => {
|
|
|
6288
6288
|
* @returns Map
|
|
6289
6289
|
* @throws {CborError} With type 'WrongType' if cbor is not a map
|
|
6290
6290
|
*/
|
|
6291
|
-
const expectMap = (cbor
|
|
6292
|
-
const value = asMap(cbor
|
|
6291
|
+
const expectMap = (cbor) => {
|
|
6292
|
+
const value = asMap(cbor);
|
|
6293
6293
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6294
6294
|
return value;
|
|
6295
6295
|
};
|
|
@@ -6300,8 +6300,8 @@ const expectMap = (cbor$1) => {
|
|
|
6300
6300
|
* @returns Boolean
|
|
6301
6301
|
* @throws {CborError} With type 'WrongType' if cbor is not a boolean
|
|
6302
6302
|
*/
|
|
6303
|
-
const expectBoolean = (cbor
|
|
6304
|
-
const value = asBoolean(cbor
|
|
6303
|
+
const expectBoolean = (cbor) => {
|
|
6304
|
+
const value = asBoolean(cbor);
|
|
6305
6305
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6306
6306
|
return value;
|
|
6307
6307
|
};
|
|
@@ -6312,8 +6312,8 @@ const expectBoolean = (cbor$1) => {
|
|
|
6312
6312
|
* @returns Float
|
|
6313
6313
|
* @throws {CborError} With type 'WrongType' if cbor is not a float
|
|
6314
6314
|
*/
|
|
6315
|
-
const expectFloat = (cbor
|
|
6316
|
-
const value = asFloat(cbor
|
|
6315
|
+
const expectFloat = (cbor) => {
|
|
6316
|
+
const value = asFloat(cbor);
|
|
6317
6317
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6318
6318
|
return value;
|
|
6319
6319
|
};
|
|
@@ -6324,8 +6324,8 @@ const expectFloat = (cbor$1) => {
|
|
|
6324
6324
|
* @returns Number
|
|
6325
6325
|
* @throws {CborError} With type 'WrongType' if cbor is not a number
|
|
6326
6326
|
*/
|
|
6327
|
-
const expectNumber = (cbor
|
|
6328
|
-
const value = asNumber(cbor
|
|
6327
|
+
const expectNumber = (cbor) => {
|
|
6328
|
+
const value = asNumber(cbor);
|
|
6329
6329
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6330
6330
|
return value;
|
|
6331
6331
|
};
|
|
@@ -6336,9 +6336,9 @@ const expectNumber = (cbor$1) => {
|
|
|
6336
6336
|
* @param index - Array index
|
|
6337
6337
|
* @returns Item at index or undefined
|
|
6338
6338
|
*/
|
|
6339
|
-
const arrayItem = (cbor
|
|
6340
|
-
if (cbor
|
|
6341
|
-
const array = cbor
|
|
6339
|
+
const arrayItem = (cbor, index) => {
|
|
6340
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6341
|
+
const array = cbor.value;
|
|
6342
6342
|
if (index < 0 || index >= array.length) return;
|
|
6343
6343
|
return array[index];
|
|
6344
6344
|
};
|
|
@@ -6348,9 +6348,9 @@ const arrayItem = (cbor$1, index) => {
|
|
|
6348
6348
|
* @param cbor - CBOR value (must be array)
|
|
6349
6349
|
* @returns Array length or undefined
|
|
6350
6350
|
*/
|
|
6351
|
-
const arrayLength = (cbor
|
|
6352
|
-
if (cbor
|
|
6353
|
-
return cbor
|
|
6351
|
+
const arrayLength = (cbor) => {
|
|
6352
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6353
|
+
return cbor.value.length;
|
|
6354
6354
|
};
|
|
6355
6355
|
/**
|
|
6356
6356
|
* Check if array is empty.
|
|
@@ -6358,9 +6358,9 @@ const arrayLength = (cbor$1) => {
|
|
|
6358
6358
|
* @param cbor - CBOR value (must be array)
|
|
6359
6359
|
* @returns True if empty, false if not empty, undefined if not array
|
|
6360
6360
|
*/
|
|
6361
|
-
const arrayIsEmpty = (cbor
|
|
6362
|
-
if (cbor
|
|
6363
|
-
return cbor
|
|
6361
|
+
const arrayIsEmpty = (cbor) => {
|
|
6362
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6363
|
+
return cbor.value.length === 0;
|
|
6364
6364
|
};
|
|
6365
6365
|
/**
|
|
6366
6366
|
* Get map value by key.
|
|
@@ -6369,9 +6369,9 @@ const arrayIsEmpty = (cbor$1) => {
|
|
|
6369
6369
|
* @param key - Map key
|
|
6370
6370
|
* @returns Value for key or undefined
|
|
6371
6371
|
*/
|
|
6372
|
-
function mapValue(cbor
|
|
6373
|
-
if (cbor
|
|
6374
|
-
return cbor
|
|
6372
|
+
function mapValue(cbor, key) {
|
|
6373
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6374
|
+
return cbor.value.get(key);
|
|
6375
6375
|
}
|
|
6376
6376
|
/**
|
|
6377
6377
|
* Check if map has key.
|
|
@@ -6380,9 +6380,9 @@ function mapValue(cbor$1, key) {
|
|
|
6380
6380
|
* @param key - Map key
|
|
6381
6381
|
* @returns True if key exists, false otherwise, undefined if not map
|
|
6382
6382
|
*/
|
|
6383
|
-
function mapHas(cbor
|
|
6384
|
-
if (cbor
|
|
6385
|
-
return cbor
|
|
6383
|
+
function mapHas(cbor, key) {
|
|
6384
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6385
|
+
return cbor.value.has(key);
|
|
6386
6386
|
}
|
|
6387
6387
|
/**
|
|
6388
6388
|
* Get all map keys.
|
|
@@ -6390,9 +6390,9 @@ function mapHas(cbor$1, key) {
|
|
|
6390
6390
|
* @param cbor - CBOR value (must be map)
|
|
6391
6391
|
* @returns Array of keys or undefined
|
|
6392
6392
|
*/
|
|
6393
|
-
const mapKeys = (cbor
|
|
6394
|
-
if (cbor
|
|
6395
|
-
return cbor
|
|
6393
|
+
const mapKeys = (cbor) => {
|
|
6394
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6395
|
+
return cbor.value.entriesArray.map((e) => e.key);
|
|
6396
6396
|
};
|
|
6397
6397
|
/**
|
|
6398
6398
|
* Get all map values.
|
|
@@ -6400,9 +6400,9 @@ const mapKeys = (cbor$1) => {
|
|
|
6400
6400
|
* @param cbor - CBOR value (must be map)
|
|
6401
6401
|
* @returns Array of values or undefined
|
|
6402
6402
|
*/
|
|
6403
|
-
const mapValues = (cbor
|
|
6404
|
-
if (cbor
|
|
6405
|
-
return cbor
|
|
6403
|
+
const mapValues = (cbor) => {
|
|
6404
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6405
|
+
return cbor.value.entriesArray.map((e) => e.value);
|
|
6406
6406
|
};
|
|
6407
6407
|
/**
|
|
6408
6408
|
* Get map size.
|
|
@@ -6410,9 +6410,9 @@ const mapValues = (cbor$1) => {
|
|
|
6410
6410
|
* @param cbor - CBOR value (must be map)
|
|
6411
6411
|
* @returns Map size or undefined
|
|
6412
6412
|
*/
|
|
6413
|
-
const mapSize = (cbor
|
|
6414
|
-
if (cbor
|
|
6415
|
-
return cbor
|
|
6413
|
+
const mapSize = (cbor) => {
|
|
6414
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6415
|
+
return cbor.value.size;
|
|
6416
6416
|
};
|
|
6417
6417
|
/**
|
|
6418
6418
|
* Check if map is empty.
|
|
@@ -6420,9 +6420,9 @@ const mapSize = (cbor$1) => {
|
|
|
6420
6420
|
* @param cbor - CBOR value (must be map)
|
|
6421
6421
|
* @returns True if empty, false if not empty, undefined if not map
|
|
6422
6422
|
*/
|
|
6423
|
-
const mapIsEmpty = (cbor
|
|
6424
|
-
if (cbor
|
|
6425
|
-
return cbor
|
|
6423
|
+
const mapIsEmpty = (cbor) => {
|
|
6424
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6425
|
+
return cbor.value.size === 0;
|
|
6426
6426
|
};
|
|
6427
6427
|
/**
|
|
6428
6428
|
* Get tag value from tagged CBOR.
|
|
@@ -6430,9 +6430,9 @@ const mapIsEmpty = (cbor$1) => {
|
|
|
6430
6430
|
* @param cbor - CBOR value (must be tagged)
|
|
6431
6431
|
* @returns Tag value or undefined
|
|
6432
6432
|
*/
|
|
6433
|
-
const tagValue = (cbor
|
|
6434
|
-
if (cbor
|
|
6435
|
-
return cbor
|
|
6433
|
+
const tagValue = (cbor) => {
|
|
6434
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6435
|
+
return cbor.tag;
|
|
6436
6436
|
};
|
|
6437
6437
|
/**
|
|
6438
6438
|
* Get content from tagged CBOR.
|
|
@@ -6440,9 +6440,9 @@ const tagValue = (cbor$1) => {
|
|
|
6440
6440
|
* @param cbor - CBOR value (must be tagged)
|
|
6441
6441
|
* @returns Tagged content or undefined
|
|
6442
6442
|
*/
|
|
6443
|
-
const tagContent = (cbor
|
|
6444
|
-
if (cbor
|
|
6445
|
-
return cbor
|
|
6443
|
+
const tagContent = (cbor) => {
|
|
6444
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6445
|
+
return cbor.value;
|
|
6446
6446
|
};
|
|
6447
6447
|
/**
|
|
6448
6448
|
* Check if CBOR has a specific tag.
|
|
@@ -6451,9 +6451,9 @@ const tagContent = (cbor$1) => {
|
|
|
6451
6451
|
* @param tag - Tag value to check
|
|
6452
6452
|
* @returns True if has tag, false otherwise
|
|
6453
6453
|
*/
|
|
6454
|
-
const hasTag = (cbor
|
|
6455
|
-
if (cbor
|
|
6456
|
-
return cbor
|
|
6454
|
+
const hasTag = (cbor, tag) => {
|
|
6455
|
+
if (cbor.type !== MajorType.Tagged) return false;
|
|
6456
|
+
return cbor.tag === tag;
|
|
6457
6457
|
};
|
|
6458
6458
|
/**
|
|
6459
6459
|
* Extract content if has specific tag.
|
|
@@ -6462,8 +6462,8 @@ const hasTag = (cbor$1, tag) => {
|
|
|
6462
6462
|
* @param tag - Expected tag value
|
|
6463
6463
|
* @returns Tagged content or undefined
|
|
6464
6464
|
*/
|
|
6465
|
-
const getTaggedContent = (cbor
|
|
6466
|
-
if (cbor
|
|
6465
|
+
const getTaggedContent = (cbor, tag) => {
|
|
6466
|
+
if (cbor.type === MajorType.Tagged && cbor.tag === tag) return cbor.value;
|
|
6467
6467
|
};
|
|
6468
6468
|
/**
|
|
6469
6469
|
* Extract content if has specific tag, throwing if not.
|
|
@@ -6473,8 +6473,8 @@ const getTaggedContent = (cbor$1, tag) => {
|
|
|
6473
6473
|
* @returns Tagged content
|
|
6474
6474
|
* @throws {CborError} With type 'WrongType' if cbor is not tagged with the expected tag
|
|
6475
6475
|
*/
|
|
6476
|
-
const expectTaggedContent = (cbor
|
|
6477
|
-
const content = getTaggedContent(cbor
|
|
6476
|
+
const expectTaggedContent = (cbor, tag) => {
|
|
6477
|
+
const content = getTaggedContent(cbor, tag);
|
|
6478
6478
|
if (content === void 0) throw new CborError({ type: "WrongType" });
|
|
6479
6479
|
return content;
|
|
6480
6480
|
};
|
|
@@ -6485,12 +6485,12 @@ const expectTaggedContent = (cbor$1, tag) => {
|
|
|
6485
6485
|
* @param cbor - CBOR value
|
|
6486
6486
|
* @returns [Tag, Cbor] tuple or undefined
|
|
6487
6487
|
*/
|
|
6488
|
-
const asTaggedValue = (cbor
|
|
6489
|
-
if (cbor
|
|
6488
|
+
const asTaggedValue = (cbor) => {
|
|
6489
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6490
6490
|
return [{
|
|
6491
|
-
value: cbor
|
|
6492
|
-
name: `tag-${cbor
|
|
6493
|
-
}, cbor
|
|
6491
|
+
value: cbor.tag,
|
|
6492
|
+
name: `tag-${cbor.tag}`
|
|
6493
|
+
}, cbor.value];
|
|
6494
6494
|
};
|
|
6495
6495
|
/**
|
|
6496
6496
|
* Alias for asBytes - extract byte string value if type matches.
|
|
@@ -6506,9 +6506,9 @@ const asByteString = asBytes;
|
|
|
6506
6506
|
* @param cbor - CBOR value
|
|
6507
6507
|
* @returns Array wrapper with get() method or undefined
|
|
6508
6508
|
*/
|
|
6509
|
-
const asCborArray = (cbor
|
|
6510
|
-
if (cbor
|
|
6511
|
-
const arr = cbor
|
|
6509
|
+
const asCborArray = (cbor) => {
|
|
6510
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6511
|
+
const arr = cbor.value;
|
|
6512
6512
|
return {
|
|
6513
6513
|
length: arr.length,
|
|
6514
6514
|
get(index) {
|
|
@@ -6533,9 +6533,9 @@ const asCborMap = asMap;
|
|
|
6533
6533
|
* @param cbor - CBOR value
|
|
6534
6534
|
* @returns True if value is numeric
|
|
6535
6535
|
*/
|
|
6536
|
-
const isNumber = (cbor
|
|
6537
|
-
if (cbor
|
|
6538
|
-
if (cbor
|
|
6536
|
+
const isNumber = (cbor) => {
|
|
6537
|
+
if (cbor.type === MajorType.Unsigned || cbor.type === MajorType.Negative) return true;
|
|
6538
|
+
if (cbor.type === MajorType.Simple) return isFloat$1(cbor.value);
|
|
6539
6539
|
return false;
|
|
6540
6540
|
};
|
|
6541
6541
|
|
|
@@ -6571,13 +6571,13 @@ const isNumber = (cbor$1) => {
|
|
|
6571
6571
|
* encoded CBOR representation, ensuring deterministic encoding.
|
|
6572
6572
|
*/
|
|
6573
6573
|
var CborMap = class CborMap {
|
|
6574
|
-
|
|
6574
|
+
_dict;
|
|
6575
6575
|
/**
|
|
6576
6576
|
* Creates a new, empty CBOR Map.
|
|
6577
6577
|
* Optionally initializes from a JavaScript Map.
|
|
6578
6578
|
*/
|
|
6579
6579
|
constructor(map) {
|
|
6580
|
-
this
|
|
6580
|
+
this._dict = new import_sorted_map.SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
6581
6581
|
if (map !== void 0) for (const [key, value] of map.entries()) this.set(key, value);
|
|
6582
6582
|
}
|
|
6583
6583
|
/**
|
|
@@ -6595,7 +6595,7 @@ var CborMap = class CborMap {
|
|
|
6595
6595
|
const keyCbor = cbor(key);
|
|
6596
6596
|
const valueCbor = cbor(value);
|
|
6597
6597
|
const keyData = cborData(keyCbor);
|
|
6598
|
-
this
|
|
6598
|
+
this._dict.set(keyData, {
|
|
6599
6599
|
key: keyCbor,
|
|
6600
6600
|
value: valueCbor
|
|
6601
6601
|
});
|
|
@@ -6606,7 +6606,7 @@ var CborMap = class CborMap {
|
|
|
6606
6606
|
insert(key, value) {
|
|
6607
6607
|
this.set(key, value);
|
|
6608
6608
|
}
|
|
6609
|
-
|
|
6609
|
+
_makeKey(key) {
|
|
6610
6610
|
return cborData(cbor(key));
|
|
6611
6611
|
}
|
|
6612
6612
|
/**
|
|
@@ -6615,8 +6615,8 @@ var CborMap = class CborMap {
|
|
|
6615
6615
|
* Matches Rust's Map::get().
|
|
6616
6616
|
*/
|
|
6617
6617
|
get(key) {
|
|
6618
|
-
const keyData = this
|
|
6619
|
-
const value = this
|
|
6618
|
+
const keyData = this._makeKey(key);
|
|
6619
|
+
const value = this._dict.get(keyData);
|
|
6620
6620
|
if (value === void 0) return;
|
|
6621
6621
|
return extractCbor(value.value);
|
|
6622
6622
|
}
|
|
@@ -6635,56 +6635,56 @@ var CborMap = class CborMap {
|
|
|
6635
6635
|
* Matches Rust's Map::contains_key().
|
|
6636
6636
|
*/
|
|
6637
6637
|
containsKey(key) {
|
|
6638
|
-
const keyData = this
|
|
6639
|
-
return this
|
|
6638
|
+
const keyData = this._makeKey(key);
|
|
6639
|
+
return this._dict.has(keyData);
|
|
6640
6640
|
}
|
|
6641
6641
|
delete(key) {
|
|
6642
|
-
const keyData = this
|
|
6643
|
-
const existed = this
|
|
6644
|
-
this
|
|
6642
|
+
const keyData = this._makeKey(key);
|
|
6643
|
+
const existed = this._dict.has(keyData);
|
|
6644
|
+
this._dict.delete(keyData);
|
|
6645
6645
|
return existed;
|
|
6646
6646
|
}
|
|
6647
6647
|
has(key) {
|
|
6648
|
-
const keyData = this
|
|
6649
|
-
return this
|
|
6648
|
+
const keyData = this._makeKey(key);
|
|
6649
|
+
return this._dict.has(keyData);
|
|
6650
6650
|
}
|
|
6651
6651
|
clear() {
|
|
6652
|
-
this
|
|
6652
|
+
this._dict = new import_sorted_map.SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
6653
6653
|
}
|
|
6654
6654
|
/**
|
|
6655
6655
|
* Returns the number of entries in the map.
|
|
6656
6656
|
* Matches Rust's Map::len().
|
|
6657
6657
|
*/
|
|
6658
6658
|
get length() {
|
|
6659
|
-
return this
|
|
6659
|
+
return this._dict.length;
|
|
6660
6660
|
}
|
|
6661
6661
|
/**
|
|
6662
6662
|
* Alias for length to match JavaScript Map API.
|
|
6663
6663
|
* Also matches Rust's Map::len().
|
|
6664
6664
|
*/
|
|
6665
6665
|
get size() {
|
|
6666
|
-
return this
|
|
6666
|
+
return this._dict.length;
|
|
6667
6667
|
}
|
|
6668
6668
|
/**
|
|
6669
6669
|
* Returns the number of entries in the map.
|
|
6670
6670
|
* Matches Rust's Map::len().
|
|
6671
6671
|
*/
|
|
6672
6672
|
len() {
|
|
6673
|
-
return this
|
|
6673
|
+
return this._dict.length;
|
|
6674
6674
|
}
|
|
6675
6675
|
/**
|
|
6676
6676
|
* Checks if the map is empty.
|
|
6677
6677
|
* Matches Rust's Map::is_empty().
|
|
6678
6678
|
*/
|
|
6679
6679
|
isEmpty() {
|
|
6680
|
-
return this
|
|
6680
|
+
return this._dict.length === 0;
|
|
6681
6681
|
}
|
|
6682
6682
|
/**
|
|
6683
6683
|
* Get the entries of the map as an array.
|
|
6684
6684
|
* Keys are sorted in lexicographic order of their encoded CBOR bytes.
|
|
6685
6685
|
*/
|
|
6686
6686
|
get entriesArray() {
|
|
6687
|
-
return this
|
|
6687
|
+
return this._dict.map((value, _key) => ({
|
|
6688
6688
|
key: value.key,
|
|
6689
6689
|
value: value.value
|
|
6690
6690
|
}));
|
|
@@ -6711,16 +6711,16 @@ var CborMap = class CborMap {
|
|
|
6711
6711
|
* Matches Rust's Map::insert_next().
|
|
6712
6712
|
*/
|
|
6713
6713
|
setNext(key, value) {
|
|
6714
|
-
const lastEntry = this
|
|
6714
|
+
const lastEntry = this._dict.max();
|
|
6715
6715
|
if (lastEntry === void 0) {
|
|
6716
6716
|
this.set(key, value);
|
|
6717
6717
|
return;
|
|
6718
6718
|
}
|
|
6719
6719
|
const keyCbor = cbor(key);
|
|
6720
6720
|
const newKey = cborData(keyCbor);
|
|
6721
|
-
if (this
|
|
6722
|
-
if (lexicographicallyCompareBytes(newKey, this
|
|
6723
|
-
this
|
|
6721
|
+
if (this._dict.has(newKey)) throw new CborError({ type: "DuplicateMapKey" });
|
|
6722
|
+
if (lexicographicallyCompareBytes(newKey, this._makeKey(lastEntry.key)) <= 0) throw new CborError({ type: "MisorderedMapKey" });
|
|
6723
|
+
this._dict.set(newKey, {
|
|
6724
6724
|
key: keyCbor,
|
|
6725
6725
|
value: cbor(value)
|
|
6726
6726
|
});
|
|
@@ -6736,17 +6736,17 @@ var CborMap = class CborMap {
|
|
|
6736
6736
|
const valueDebug = CborMap.formatDebug(entry.value);
|
|
6737
6737
|
return `0x${bytesToHex(encodeCbor(entry.key))}: (${keyDebug}, ${valueDebug})`;
|
|
6738
6738
|
}
|
|
6739
|
-
static formatDebug(cbor
|
|
6740
|
-
switch (cbor
|
|
6741
|
-
case MajorType.Unsigned: return `unsigned(${cbor
|
|
6742
|
-
case MajorType.Negative: return `negative(${typeof cbor
|
|
6743
|
-
case MajorType.ByteString: return `bytes(${bytesToHex(cbor
|
|
6744
|
-
case MajorType.Text: return `text("${cbor
|
|
6745
|
-
case MajorType.Array: return `array([${cbor
|
|
6746
|
-
case MajorType.Map: return cbor
|
|
6747
|
-
case MajorType.Tagged: return `tagged(${cbor
|
|
6739
|
+
static formatDebug(cbor) {
|
|
6740
|
+
switch (cbor.type) {
|
|
6741
|
+
case MajorType.Unsigned: return `unsigned(${cbor.value})`;
|
|
6742
|
+
case MajorType.Negative: return `negative(${typeof cbor.value === "bigint" ? -cbor.value - 1n : -cbor.value - 1})`;
|
|
6743
|
+
case MajorType.ByteString: return `bytes(${bytesToHex(cbor.value)})`;
|
|
6744
|
+
case MajorType.Text: return `text("${cbor.value}")`;
|
|
6745
|
+
case MajorType.Array: return `array([${cbor.value.map(CborMap.formatDebug).join(", ")}])`;
|
|
6746
|
+
case MajorType.Map: return cbor.value.debug;
|
|
6747
|
+
case MajorType.Tagged: return `tagged(${cbor.tag}, ${CborMap.formatDebug(cbor.value)})`;
|
|
6748
6748
|
case MajorType.Simple: {
|
|
6749
|
-
const simple = cbor
|
|
6749
|
+
const simple = cbor.value;
|
|
6750
6750
|
if (typeof simple === "object" && simple !== null && "type" in simple) switch (simple.type) {
|
|
6751
6751
|
case "True": return "simple(true)";
|
|
6752
6752
|
case "False": return "simple(false)";
|
|
@@ -6755,7 +6755,7 @@ var CborMap = class CborMap {
|
|
|
6755
6755
|
}
|
|
6756
6756
|
return "simple";
|
|
6757
6757
|
}
|
|
6758
|
-
default: return diagnostic(cbor
|
|
6758
|
+
default: return diagnostic(cbor);
|
|
6759
6759
|
}
|
|
6760
6760
|
}
|
|
6761
6761
|
static entryDiagnostic(entry) {
|
|
@@ -6784,20 +6784,20 @@ var CborMap = class CborMap {
|
|
|
6784
6784
|
/**
|
|
6785
6785
|
* Types of edges in the CBOR tree traversal.
|
|
6786
6786
|
*/
|
|
6787
|
-
let EdgeType = /* @__PURE__ */ function(EdgeType
|
|
6787
|
+
let EdgeType = /* @__PURE__ */ function(EdgeType) {
|
|
6788
6788
|
/** No specific edge type (root element) */
|
|
6789
|
-
EdgeType
|
|
6789
|
+
EdgeType["None"] = "none";
|
|
6790
6790
|
/** Element within an array */
|
|
6791
|
-
EdgeType
|
|
6791
|
+
EdgeType["ArrayElement"] = "array_element";
|
|
6792
6792
|
/** Key-value pair in a map (semantic unit) */
|
|
6793
|
-
EdgeType
|
|
6793
|
+
EdgeType["MapKeyValue"] = "map_key_value";
|
|
6794
6794
|
/** Key within a map */
|
|
6795
|
-
EdgeType
|
|
6795
|
+
EdgeType["MapKey"] = "map_key";
|
|
6796
6796
|
/** Value within a map */
|
|
6797
|
-
EdgeType
|
|
6797
|
+
EdgeType["MapValue"] = "map_value";
|
|
6798
6798
|
/** Content of a tagged value */
|
|
6799
|
-
EdgeType
|
|
6800
|
-
return EdgeType
|
|
6799
|
+
EdgeType["TaggedContent"] = "tagged_content";
|
|
6800
|
+
return EdgeType;
|
|
6801
6801
|
}({});
|
|
6802
6802
|
/**
|
|
6803
6803
|
* Returns a short text label for the edge type, or undefined if no label is needed.
|
|
@@ -6908,35 +6908,35 @@ const asKeyValue = (element) => {
|
|
|
6908
6908
|
* });
|
|
6909
6909
|
* ```
|
|
6910
6910
|
*/
|
|
6911
|
-
const walk = (cbor
|
|
6912
|
-
walkInternal(cbor
|
|
6911
|
+
const walk = (cbor, initialState, visitor) => {
|
|
6912
|
+
walkInternal(cbor, 0, { type: EdgeType.None }, initialState, visitor);
|
|
6913
6913
|
};
|
|
6914
6914
|
/**
|
|
6915
6915
|
* Internal recursive walk implementation.
|
|
6916
6916
|
*
|
|
6917
6917
|
* @internal
|
|
6918
6918
|
*/
|
|
6919
|
-
function walkInternal(cbor
|
|
6919
|
+
function walkInternal(cbor, level, edge, state, visitor, skipVisit = false) {
|
|
6920
6920
|
let currentState = state;
|
|
6921
6921
|
let stopDescent = false;
|
|
6922
6922
|
if (!skipVisit) {
|
|
6923
6923
|
const [newState, stop] = visitor({
|
|
6924
6924
|
type: "single",
|
|
6925
|
-
cbor
|
|
6925
|
+
cbor
|
|
6926
6926
|
}, level, edge, currentState);
|
|
6927
6927
|
currentState = newState;
|
|
6928
6928
|
stopDescent = stop;
|
|
6929
6929
|
if (stopDescent) return currentState;
|
|
6930
6930
|
}
|
|
6931
|
-
switch (cbor
|
|
6931
|
+
switch (cbor.type) {
|
|
6932
6932
|
case MajorType.Array:
|
|
6933
|
-
currentState = walkArray(cbor
|
|
6933
|
+
currentState = walkArray(cbor, level, currentState, visitor);
|
|
6934
6934
|
break;
|
|
6935
6935
|
case MajorType.Map:
|
|
6936
|
-
currentState = walkMap(cbor
|
|
6936
|
+
currentState = walkMap(cbor, level, currentState, visitor);
|
|
6937
6937
|
break;
|
|
6938
6938
|
case MajorType.Tagged:
|
|
6939
|
-
currentState = walkTagged(cbor
|
|
6939
|
+
currentState = walkTagged(cbor, level, currentState, visitor);
|
|
6940
6940
|
break;
|
|
6941
6941
|
default: break;
|
|
6942
6942
|
}
|
|
@@ -6947,10 +6947,10 @@ function walkInternal(cbor$1, level, edge, state, visitor, skipVisit = false) {
|
|
|
6947
6947
|
*
|
|
6948
6948
|
* @internal
|
|
6949
6949
|
*/
|
|
6950
|
-
function walkArray(cbor
|
|
6950
|
+
function walkArray(cbor, level, state, visitor) {
|
|
6951
6951
|
let currentState = state;
|
|
6952
|
-
for (let index = 0; index < cbor
|
|
6953
|
-
const item = cbor
|
|
6952
|
+
for (let index = 0; index < cbor.value.length; index++) {
|
|
6953
|
+
const item = cbor.value[index];
|
|
6954
6954
|
if (item === void 0) throw new CborError({
|
|
6955
6955
|
type: "Custom",
|
|
6956
6956
|
message: `Array element at index ${index} is undefined`
|
|
@@ -6972,9 +6972,9 @@ function walkArray(cbor$1, level, state, visitor) {
|
|
|
6972
6972
|
*
|
|
6973
6973
|
* @internal
|
|
6974
6974
|
*/
|
|
6975
|
-
function walkMap(cbor
|
|
6975
|
+
function walkMap(cbor, level, state, visitor) {
|
|
6976
6976
|
let currentState = state;
|
|
6977
|
-
for (const entry of cbor
|
|
6977
|
+
for (const entry of cbor.value.entriesArray) {
|
|
6978
6978
|
const { key, value } = entry;
|
|
6979
6979
|
const [kvState, kvStop] = visitor({
|
|
6980
6980
|
type: "keyvalue",
|
|
@@ -6994,8 +6994,8 @@ function walkMap(cbor$1, level, state, visitor) {
|
|
|
6994
6994
|
*
|
|
6995
6995
|
* @internal
|
|
6996
6996
|
*/
|
|
6997
|
-
function walkTagged(cbor
|
|
6998
|
-
return walkInternal(cbor
|
|
6997
|
+
function walkTagged(cbor, level, state, visitor) {
|
|
6998
|
+
return walkInternal(cbor.value, level + 1, { type: EdgeType.TaggedContent }, state, visitor);
|
|
6999
6999
|
}
|
|
7000
7000
|
|
|
7001
7001
|
//#endregion
|
|
@@ -7205,7 +7205,7 @@ const cborData = (value) => {
|
|
|
7205
7205
|
}
|
|
7206
7206
|
case MajorType.Map: {
|
|
7207
7207
|
const entries = c.value.entriesArray;
|
|
7208
|
-
const flatArrayBytes = concatBytes(entries.map(({ key, value
|
|
7208
|
+
const flatArrayBytes = concatBytes(entries.map(({ key, value }) => concatBytes([cborData(key), cborData(value)])));
|
|
7209
7209
|
const lengthBytes = encodeVarInt(entries.length, MajorType.Map);
|
|
7210
7210
|
return new Uint8Array([...lengthBytes, ...flatArrayBytes]);
|
|
7211
7211
|
}
|
|
@@ -7227,15 +7227,15 @@ const taggedCbor = (tag, value) => {
|
|
|
7227
7227
|
const toByteString = (data) => {
|
|
7228
7228
|
return cbor(data);
|
|
7229
7229
|
};
|
|
7230
|
-
const toByteStringFromHex = (hex
|
|
7231
|
-
return toByteString(hexToBytes(hex
|
|
7230
|
+
const toByteStringFromHex = (hex) => {
|
|
7231
|
+
return toByteString(hexToBytes(hex));
|
|
7232
7232
|
};
|
|
7233
7233
|
const toTaggedValue = (tag, item) => {
|
|
7234
|
-
const tagValue
|
|
7234
|
+
const tagValue = typeof tag === "object" && "value" in tag ? tag.value : tag;
|
|
7235
7235
|
return attachMethods({
|
|
7236
7236
|
isCbor: true,
|
|
7237
7237
|
type: MajorType.Tagged,
|
|
7238
|
-
tag: tagValue
|
|
7238
|
+
tag: tagValue,
|
|
7239
7239
|
value: cbor(item)
|
|
7240
7240
|
});
|
|
7241
7241
|
};
|
|
@@ -7416,11 +7416,11 @@ const attachMethods = (obj) => {
|
|
|
7416
7416
|
validateTag(expectedTags) {
|
|
7417
7417
|
if (this.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7418
7418
|
const expectedValues = expectedTags.map((t) => t.value);
|
|
7419
|
-
const tagValue
|
|
7420
|
-
const matchingTag = expectedTags.find((t) => t.value === tagValue
|
|
7419
|
+
const tagValue = this.tag;
|
|
7420
|
+
const matchingTag = expectedTags.find((t) => t.value === tagValue);
|
|
7421
7421
|
if (matchingTag === void 0) throw new CborError({
|
|
7422
7422
|
type: "Custom",
|
|
7423
|
-
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue
|
|
7423
|
+
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue}`
|
|
7424
7424
|
});
|
|
7425
7425
|
return matchingTag;
|
|
7426
7426
|
},
|
|
@@ -7466,8 +7466,8 @@ const Cbor = {
|
|
|
7466
7466
|
tryFromData(data) {
|
|
7467
7467
|
return decodeCbor(data);
|
|
7468
7468
|
},
|
|
7469
|
-
tryFromHex(hex
|
|
7470
|
-
const data = hexToBytes(hex
|
|
7469
|
+
tryFromHex(hex) {
|
|
7470
|
+
const data = hexToBytes(hex);
|
|
7471
7471
|
return this.tryFromData(data);
|
|
7472
7472
|
}
|
|
7473
7473
|
};
|
|
@@ -7540,14 +7540,14 @@ const createTaggedCbor = (encodable) => {
|
|
|
7540
7540
|
* @returns The matching tag
|
|
7541
7541
|
* @throws Error if the value is not tagged or has an unexpected tag
|
|
7542
7542
|
*/
|
|
7543
|
-
const validateTag = (cbor
|
|
7544
|
-
if (cbor
|
|
7543
|
+
const validateTag = (cbor, expectedTags) => {
|
|
7544
|
+
if (cbor.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7545
7545
|
const expectedValues = expectedTags.map((t) => t.value);
|
|
7546
|
-
const tagValue
|
|
7547
|
-
const matchingTag = expectedTags.find((t) => t.value === tagValue
|
|
7546
|
+
const tagValue = cbor.tag;
|
|
7547
|
+
const matchingTag = expectedTags.find((t) => t.value === tagValue);
|
|
7548
7548
|
if (matchingTag === void 0) throw new CborError({
|
|
7549
7549
|
type: "Custom",
|
|
7550
|
-
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue
|
|
7550
|
+
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue}`
|
|
7551
7551
|
});
|
|
7552
7552
|
return matchingTag;
|
|
7553
7553
|
};
|
|
@@ -7558,9 +7558,9 @@ const validateTag = (cbor$1, expectedTags) => {
|
|
|
7558
7558
|
* @returns The untagged content
|
|
7559
7559
|
* @throws Error if the value is not tagged
|
|
7560
7560
|
*/
|
|
7561
|
-
const extractTaggedContent = (cbor
|
|
7562
|
-
if (cbor
|
|
7563
|
-
return cbor
|
|
7561
|
+
const extractTaggedContent = (cbor) => {
|
|
7562
|
+
if (cbor.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7563
|
+
return cbor.value;
|
|
7564
7564
|
};
|
|
7565
7565
|
|
|
7566
7566
|
//#endregion
|
|
@@ -7619,7 +7619,7 @@ const extractTaggedContent = (cbor$1) => {
|
|
|
7619
7619
|
* ```
|
|
7620
7620
|
*/
|
|
7621
7621
|
var CborDate = class CborDate {
|
|
7622
|
-
|
|
7622
|
+
_datetime;
|
|
7623
7623
|
/**
|
|
7624
7624
|
* Creates a new `CborDate` from the given JavaScript `Date`.
|
|
7625
7625
|
*
|
|
@@ -7638,7 +7638,7 @@ var CborDate = class CborDate {
|
|
|
7638
7638
|
*/
|
|
7639
7639
|
static fromDatetime(dateTime) {
|
|
7640
7640
|
const instance = new CborDate();
|
|
7641
|
-
instance
|
|
7641
|
+
instance._datetime = new Date(dateTime);
|
|
7642
7642
|
return instance;
|
|
7643
7643
|
}
|
|
7644
7644
|
/**
|
|
@@ -7802,7 +7802,7 @@ var CborDate = class CborDate {
|
|
|
7802
7802
|
* ```
|
|
7803
7803
|
*/
|
|
7804
7804
|
datetime() {
|
|
7805
|
-
return new Date(this
|
|
7805
|
+
return new Date(this._datetime);
|
|
7806
7806
|
}
|
|
7807
7807
|
/**
|
|
7808
7808
|
* Returns the `CborDate` as the number of seconds since the Unix epoch.
|
|
@@ -7821,7 +7821,7 @@ var CborDate = class CborDate {
|
|
|
7821
7821
|
* ```
|
|
7822
7822
|
*/
|
|
7823
7823
|
timestamp() {
|
|
7824
|
-
return Math.trunc(this
|
|
7824
|
+
return Math.trunc(this._datetime.getTime() / 1e3) + this._datetime.getTime() % 1e3 / 1e3;
|
|
7825
7825
|
}
|
|
7826
7826
|
/**
|
|
7827
7827
|
* Add seconds to this date.
|
|
@@ -7919,18 +7919,18 @@ var CborDate = class CborDate {
|
|
|
7919
7919
|
*
|
|
7920
7920
|
* @throws Error if the CBOR value is not a valid timestamp
|
|
7921
7921
|
*/
|
|
7922
|
-
fromUntaggedCbor(cbor
|
|
7922
|
+
fromUntaggedCbor(cbor) {
|
|
7923
7923
|
let timestamp;
|
|
7924
|
-
switch (cbor
|
|
7924
|
+
switch (cbor.type) {
|
|
7925
7925
|
case MajorType.Unsigned:
|
|
7926
|
-
timestamp = typeof cbor
|
|
7926
|
+
timestamp = typeof cbor.value === "number" ? cbor.value : Number(cbor.value);
|
|
7927
7927
|
break;
|
|
7928
7928
|
case MajorType.Negative:
|
|
7929
|
-
if (typeof cbor
|
|
7930
|
-
else timestamp = -cbor
|
|
7929
|
+
if (typeof cbor.value === "bigint") timestamp = Number(-cbor.value - 1n);
|
|
7930
|
+
else timestamp = -cbor.value - 1;
|
|
7931
7931
|
break;
|
|
7932
7932
|
case MajorType.Simple:
|
|
7933
|
-
if (cbor
|
|
7933
|
+
if (cbor.value.type === "Float") timestamp = cbor.value.value;
|
|
7934
7934
|
else throw new CborError({
|
|
7935
7935
|
type: "Custom",
|
|
7936
7936
|
message: "Invalid date CBOR: expected numeric value"
|
|
@@ -7941,7 +7941,7 @@ var CborDate = class CborDate {
|
|
|
7941
7941
|
message: "Invalid date CBOR: expected numeric value"
|
|
7942
7942
|
});
|
|
7943
7943
|
}
|
|
7944
|
-
this
|
|
7944
|
+
this._datetime = CborDate.fromTimestamp(timestamp)._datetime;
|
|
7945
7945
|
return this;
|
|
7946
7946
|
}
|
|
7947
7947
|
/**
|
|
@@ -7953,9 +7953,9 @@ var CborDate = class CborDate {
|
|
|
7953
7953
|
*
|
|
7954
7954
|
* @throws Error if the CBOR value has the wrong tag or cannot be decoded
|
|
7955
7955
|
*/
|
|
7956
|
-
fromTaggedCbor(cbor
|
|
7957
|
-
validateTag(cbor
|
|
7958
|
-
const content = extractTaggedContent(cbor
|
|
7956
|
+
fromTaggedCbor(cbor) {
|
|
7957
|
+
validateTag(cbor, this.cborTags());
|
|
7958
|
+
const content = extractTaggedContent(cbor);
|
|
7959
7959
|
return this.fromUntaggedCbor(content);
|
|
7960
7960
|
}
|
|
7961
7961
|
/**
|
|
@@ -7964,8 +7964,8 @@ var CborDate = class CborDate {
|
|
|
7964
7964
|
* @param cbor - Tagged CBOR value
|
|
7965
7965
|
* @returns New CborDate instance
|
|
7966
7966
|
*/
|
|
7967
|
-
static fromTaggedCbor(cbor
|
|
7968
|
-
return new CborDate().fromTaggedCbor(cbor
|
|
7967
|
+
static fromTaggedCbor(cbor) {
|
|
7968
|
+
return new CborDate().fromTaggedCbor(cbor);
|
|
7969
7969
|
}
|
|
7970
7970
|
/**
|
|
7971
7971
|
* Static method to create a CborDate from untagged CBOR.
|
|
@@ -7973,8 +7973,8 @@ var CborDate = class CborDate {
|
|
|
7973
7973
|
* @param cbor - Untagged CBOR value
|
|
7974
7974
|
* @returns New CborDate instance
|
|
7975
7975
|
*/
|
|
7976
|
-
static fromUntaggedCbor(cbor
|
|
7977
|
-
return new CborDate().fromUntaggedCbor(cbor
|
|
7976
|
+
static fromUntaggedCbor(cbor) {
|
|
7977
|
+
return new CborDate().fromUntaggedCbor(cbor);
|
|
7978
7978
|
}
|
|
7979
7979
|
/**
|
|
7980
7980
|
* Implementation of the `toString` method for `CborDate`.
|
|
@@ -7999,7 +7999,7 @@ var CborDate = class CborDate {
|
|
|
7999
7999
|
* ```
|
|
8000
8000
|
*/
|
|
8001
8001
|
toString() {
|
|
8002
|
-
const dt = this
|
|
8002
|
+
const dt = this._datetime;
|
|
8003
8003
|
if (!(dt.getUTCHours() !== 0 || dt.getUTCMinutes() !== 0 || dt.getUTCSeconds() !== 0)) {
|
|
8004
8004
|
const datePart = dt.toISOString().split("T")[0];
|
|
8005
8005
|
if (datePart === void 0) throw new CborError({
|
|
@@ -8016,7 +8016,7 @@ var CborDate = class CborDate {
|
|
|
8016
8016
|
* @returns true if dates represent the same moment in time
|
|
8017
8017
|
*/
|
|
8018
8018
|
equals(other) {
|
|
8019
|
-
return this
|
|
8019
|
+
return this._datetime.getTime() === other._datetime.getTime();
|
|
8020
8020
|
}
|
|
8021
8021
|
/**
|
|
8022
8022
|
* Compare two dates.
|
|
@@ -8025,8 +8025,8 @@ var CborDate = class CborDate {
|
|
|
8025
8025
|
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
|
8026
8026
|
*/
|
|
8027
8027
|
compare(other) {
|
|
8028
|
-
const thisTime = this
|
|
8029
|
-
const otherTime = other
|
|
8028
|
+
const thisTime = this._datetime.getTime();
|
|
8029
|
+
const otherTime = other._datetime.getTime();
|
|
8030
8030
|
if (thisTime < otherTime) return -1;
|
|
8031
8031
|
if (thisTime > otherTime) return 1;
|
|
8032
8032
|
return 0;
|
|
@@ -8040,7 +8040,7 @@ var CborDate = class CborDate {
|
|
|
8040
8040
|
return this.toString();
|
|
8041
8041
|
}
|
|
8042
8042
|
constructor() {
|
|
8043
|
-
this
|
|
8043
|
+
this._datetime = /* @__PURE__ */ new Date();
|
|
8044
8044
|
}
|
|
8045
8045
|
};
|
|
8046
8046
|
|
|
@@ -8246,9 +8246,9 @@ const tagsForValues = (values) => {
|
|
|
8246
8246
|
* ```
|
|
8247
8247
|
*/
|
|
8248
8248
|
var CborSet = class CborSet {
|
|
8249
|
-
|
|
8249
|
+
_map;
|
|
8250
8250
|
constructor() {
|
|
8251
|
-
this
|
|
8251
|
+
this._map = new CborMap();
|
|
8252
8252
|
}
|
|
8253
8253
|
/**
|
|
8254
8254
|
* Create CborSet from array.
|
|
@@ -8310,7 +8310,7 @@ var CborSet = class CborSet {
|
|
|
8310
8310
|
*/
|
|
8311
8311
|
insert(value) {
|
|
8312
8312
|
const cborValue = encodeCborValue(value);
|
|
8313
|
-
this
|
|
8313
|
+
this._map.set(cborValue, cborValue);
|
|
8314
8314
|
}
|
|
8315
8315
|
/**
|
|
8316
8316
|
* Check if set contains an element.
|
|
@@ -8327,7 +8327,7 @@ var CborSet = class CborSet {
|
|
|
8327
8327
|
*/
|
|
8328
8328
|
contains(value) {
|
|
8329
8329
|
const cborValue = encodeCborValue(value);
|
|
8330
|
-
return this
|
|
8330
|
+
return this._map.has(cborValue);
|
|
8331
8331
|
}
|
|
8332
8332
|
/**
|
|
8333
8333
|
* Remove an element from the set.
|
|
@@ -8344,13 +8344,13 @@ var CborSet = class CborSet {
|
|
|
8344
8344
|
*/
|
|
8345
8345
|
delete(value) {
|
|
8346
8346
|
const cborValue = encodeCborValue(value);
|
|
8347
|
-
return this
|
|
8347
|
+
return this._map.delete(cborValue);
|
|
8348
8348
|
}
|
|
8349
8349
|
/**
|
|
8350
8350
|
* Remove all elements from the set.
|
|
8351
8351
|
*/
|
|
8352
8352
|
clear() {
|
|
8353
|
-
this
|
|
8353
|
+
this._map.clear();
|
|
8354
8354
|
}
|
|
8355
8355
|
/**
|
|
8356
8356
|
* Get the number of elements in the set.
|
|
@@ -8358,7 +8358,7 @@ var CborSet = class CborSet {
|
|
|
8358
8358
|
* @returns Number of elements
|
|
8359
8359
|
*/
|
|
8360
8360
|
get size() {
|
|
8361
|
-
return this
|
|
8361
|
+
return this._map.size;
|
|
8362
8362
|
}
|
|
8363
8363
|
/**
|
|
8364
8364
|
* Check if the set is empty.
|
|
@@ -8366,7 +8366,7 @@ var CborSet = class CborSet {
|
|
|
8366
8366
|
* @returns true if set has no elements
|
|
8367
8367
|
*/
|
|
8368
8368
|
isEmpty() {
|
|
8369
|
-
return this
|
|
8369
|
+
return this._map.size === 0;
|
|
8370
8370
|
}
|
|
8371
8371
|
/**
|
|
8372
8372
|
* Create a new set containing elements in this set or the other set.
|
|
@@ -8465,7 +8465,7 @@ var CborSet = class CborSet {
|
|
|
8465
8465
|
* ```
|
|
8466
8466
|
*/
|
|
8467
8467
|
*[Symbol.iterator]() {
|
|
8468
|
-
for (const [_, value] of this
|
|
8468
|
+
for (const [_, value] of this._map) yield value;
|
|
8469
8469
|
}
|
|
8470
8470
|
/**
|
|
8471
8471
|
* Get all values as an array.
|
|
@@ -8523,8 +8523,8 @@ var CborSet = class CborSet {
|
|
|
8523
8523
|
* @param cbor - Tagged CBOR value with tag(258)
|
|
8524
8524
|
* @returns Decoded CborSet instance
|
|
8525
8525
|
*/
|
|
8526
|
-
static fromTaggedCborStatic(cbor
|
|
8527
|
-
return new CborSet().fromTaggedCbor(cbor
|
|
8526
|
+
static fromTaggedCborStatic(cbor) {
|
|
8527
|
+
return new CborSet().fromTaggedCbor(cbor);
|
|
8528
8528
|
}
|
|
8529
8529
|
/**
|
|
8530
8530
|
* Convert to CBOR array (untagged).
|
|
@@ -8656,7 +8656,7 @@ function encodeCborValue(value) {
|
|
|
8656
8656
|
* ```
|
|
8657
8657
|
*/
|
|
8658
8658
|
var ByteString = class ByteString {
|
|
8659
|
-
|
|
8659
|
+
_data;
|
|
8660
8660
|
/**
|
|
8661
8661
|
* Creates a new `ByteString` from a Uint8Array or array of bytes.
|
|
8662
8662
|
*
|
|
@@ -8672,8 +8672,8 @@ var ByteString = class ByteString {
|
|
|
8672
8672
|
* ```
|
|
8673
8673
|
*/
|
|
8674
8674
|
constructor(data) {
|
|
8675
|
-
if (Array.isArray(data)) this
|
|
8676
|
-
else this
|
|
8675
|
+
if (Array.isArray(data)) this._data = new Uint8Array(data);
|
|
8676
|
+
else this._data = new Uint8Array(data);
|
|
8677
8677
|
}
|
|
8678
8678
|
/**
|
|
8679
8679
|
* Creates a new `ByteString` from various input types.
|
|
@@ -8707,7 +8707,7 @@ var ByteString = class ByteString {
|
|
|
8707
8707
|
* ```
|
|
8708
8708
|
*/
|
|
8709
8709
|
data() {
|
|
8710
|
-
return this
|
|
8710
|
+
return this._data;
|
|
8711
8711
|
}
|
|
8712
8712
|
/**
|
|
8713
8713
|
* Returns the length of the byte string in bytes.
|
|
@@ -8724,7 +8724,7 @@ var ByteString = class ByteString {
|
|
|
8724
8724
|
* ```
|
|
8725
8725
|
*/
|
|
8726
8726
|
len() {
|
|
8727
|
-
return this
|
|
8727
|
+
return this._data.length;
|
|
8728
8728
|
}
|
|
8729
8729
|
/**
|
|
8730
8730
|
* Returns `true` if the byte string contains no bytes.
|
|
@@ -8741,7 +8741,7 @@ var ByteString = class ByteString {
|
|
|
8741
8741
|
* ```
|
|
8742
8742
|
*/
|
|
8743
8743
|
isEmpty() {
|
|
8744
|
-
return this
|
|
8744
|
+
return this._data.length === 0;
|
|
8745
8745
|
}
|
|
8746
8746
|
/**
|
|
8747
8747
|
* Extends the byte string with additional bytes.
|
|
@@ -8761,10 +8761,10 @@ var ByteString = class ByteString {
|
|
|
8761
8761
|
*/
|
|
8762
8762
|
extend(other) {
|
|
8763
8763
|
const otherArray = Array.isArray(other) ? new Uint8Array(other) : other;
|
|
8764
|
-
const newData = new Uint8Array(this
|
|
8765
|
-
newData.set(this
|
|
8766
|
-
newData.set(otherArray, this
|
|
8767
|
-
this
|
|
8764
|
+
const newData = new Uint8Array(this._data.length + otherArray.length);
|
|
8765
|
+
newData.set(this._data, 0);
|
|
8766
|
+
newData.set(otherArray, this._data.length);
|
|
8767
|
+
this._data = newData;
|
|
8768
8768
|
}
|
|
8769
8769
|
/**
|
|
8770
8770
|
* Creates a new Uint8Array containing a copy of the byte string's data.
|
|
@@ -8784,7 +8784,7 @@ var ByteString = class ByteString {
|
|
|
8784
8784
|
* ```
|
|
8785
8785
|
*/
|
|
8786
8786
|
toUint8Array() {
|
|
8787
|
-
return new Uint8Array(this
|
|
8787
|
+
return new Uint8Array(this._data);
|
|
8788
8788
|
}
|
|
8789
8789
|
/**
|
|
8790
8790
|
* Returns an iterator over the bytes in the byte string.
|
|
@@ -8810,7 +8810,7 @@ var ByteString = class ByteString {
|
|
|
8810
8810
|
* ```
|
|
8811
8811
|
*/
|
|
8812
8812
|
iter() {
|
|
8813
|
-
return this
|
|
8813
|
+
return this._data.values();
|
|
8814
8814
|
}
|
|
8815
8815
|
/**
|
|
8816
8816
|
* Makes ByteString iterable.
|
|
@@ -8830,7 +8830,7 @@ var ByteString = class ByteString {
|
|
|
8830
8830
|
* ```
|
|
8831
8831
|
*/
|
|
8832
8832
|
toCbor() {
|
|
8833
|
-
return cbor(this
|
|
8833
|
+
return cbor(this._data);
|
|
8834
8834
|
}
|
|
8835
8835
|
/**
|
|
8836
8836
|
* Attempts to convert a CBOR value into a ByteString.
|
|
@@ -8854,9 +8854,9 @@ var ByteString = class ByteString {
|
|
|
8854
8854
|
* }
|
|
8855
8855
|
* ```
|
|
8856
8856
|
*/
|
|
8857
|
-
static fromCbor(cbor
|
|
8858
|
-
if (cbor
|
|
8859
|
-
return new ByteString(cbor
|
|
8857
|
+
static fromCbor(cbor) {
|
|
8858
|
+
if (cbor.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8859
|
+
return new ByteString(cbor.value);
|
|
8860
8860
|
}
|
|
8861
8861
|
/**
|
|
8862
8862
|
* Get element at index.
|
|
@@ -8865,7 +8865,7 @@ var ByteString = class ByteString {
|
|
|
8865
8865
|
* @returns Byte at index or undefined
|
|
8866
8866
|
*/
|
|
8867
8867
|
at(index) {
|
|
8868
|
-
return this
|
|
8868
|
+
return this._data[index];
|
|
8869
8869
|
}
|
|
8870
8870
|
/**
|
|
8871
8871
|
* Equality comparison.
|
|
@@ -8874,8 +8874,8 @@ var ByteString = class ByteString {
|
|
|
8874
8874
|
* @returns true if equal
|
|
8875
8875
|
*/
|
|
8876
8876
|
equals(other) {
|
|
8877
|
-
if (this
|
|
8878
|
-
for (let i = 0; i < this
|
|
8877
|
+
if (this._data.length !== other._data.length) return false;
|
|
8878
|
+
for (let i = 0; i < this._data.length; i++) if (this._data[i] !== other._data[i]) return false;
|
|
8879
8879
|
return true;
|
|
8880
8880
|
}
|
|
8881
8881
|
/**
|