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