@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bcts/dcbor",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blockchain Commons Deterministic CBOR (dCBOR) for TypeScript",
|
|
6
6
|
"license": "BSD-2-Clause-Patent",
|
|
@@ -71,15 +71,15 @@
|
|
|
71
71
|
"@bcts/tsconfig": "^0.1.0",
|
|
72
72
|
"@eslint/js": "^9.39.2",
|
|
73
73
|
"@types/collections": "^5.1.5",
|
|
74
|
-
"@types/node": "^25.0.
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
76
|
-
"@typescript-eslint/parser": "^8.
|
|
74
|
+
"@types/node": "^25.0.10",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
76
|
+
"@typescript-eslint/parser": "^8.53.1",
|
|
77
77
|
"eslint": "^9.39.2",
|
|
78
78
|
"ts-node": "^10.9.2",
|
|
79
|
-
"tsdown": "^0.
|
|
80
|
-
"typedoc": "^0.28.
|
|
79
|
+
"tsdown": "^0.20.1",
|
|
80
|
+
"typedoc": "^0.28.16",
|
|
81
81
|
"typescript": "^5.9.3",
|
|
82
|
-
"vitest": "^4.0.
|
|
82
|
+
"vitest": "^4.0.18"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"byte-data": "^19.0.1",
|
package/src/byte-string.ts
CHANGED
|
@@ -44,7 +44,7 @@ import { CborError } from "./error";
|
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
export class ByteString {
|
|
47
|
-
|
|
47
|
+
private _data: Uint8Array;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new `ByteString` from a Uint8Array or array of bytes.
|
|
@@ -62,9 +62,9 @@ export class ByteString {
|
|
|
62
62
|
*/
|
|
63
63
|
constructor(data: Uint8Array | number[]) {
|
|
64
64
|
if (Array.isArray(data)) {
|
|
65
|
-
this
|
|
65
|
+
this._data = new Uint8Array(data);
|
|
66
66
|
} else {
|
|
67
|
-
this
|
|
67
|
+
this._data = new Uint8Array(data);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -103,7 +103,7 @@ export class ByteString {
|
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
data(): Uint8Array {
|
|
106
|
-
return this
|
|
106
|
+
return this._data;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
@@ -121,7 +121,7 @@ export class ByteString {
|
|
|
121
121
|
* ```
|
|
122
122
|
*/
|
|
123
123
|
len(): number {
|
|
124
|
-
return this
|
|
124
|
+
return this._data.length;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -139,7 +139,7 @@ export class ByteString {
|
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
141
|
isEmpty(): boolean {
|
|
142
|
-
return this
|
|
142
|
+
return this._data.length === 0;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
/**
|
|
@@ -160,10 +160,10 @@ export class ByteString {
|
|
|
160
160
|
*/
|
|
161
161
|
extend(other: Uint8Array | number[]): void {
|
|
162
162
|
const otherArray = Array.isArray(other) ? new Uint8Array(other) : other;
|
|
163
|
-
const newData = new Uint8Array(this
|
|
164
|
-
newData.set(this
|
|
165
|
-
newData.set(otherArray, this
|
|
166
|
-
this
|
|
163
|
+
const newData = new Uint8Array(this._data.length + otherArray.length);
|
|
164
|
+
newData.set(this._data, 0);
|
|
165
|
+
newData.set(otherArray, this._data.length);
|
|
166
|
+
this._data = newData;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/**
|
|
@@ -184,7 +184,7 @@ export class ByteString {
|
|
|
184
184
|
* ```
|
|
185
185
|
*/
|
|
186
186
|
toUint8Array(): Uint8Array {
|
|
187
|
-
return new Uint8Array(this
|
|
187
|
+
return new Uint8Array(this._data);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
/**
|
|
@@ -211,7 +211,7 @@ export class ByteString {
|
|
|
211
211
|
* ```
|
|
212
212
|
*/
|
|
213
213
|
iter(): Iterator<number> {
|
|
214
|
-
return this
|
|
214
|
+
return this._data.values();
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
/**
|
|
@@ -233,7 +233,7 @@ export class ByteString {
|
|
|
233
233
|
* ```
|
|
234
234
|
*/
|
|
235
235
|
toCbor(): Cbor {
|
|
236
|
-
return toCbor(this
|
|
236
|
+
return toCbor(this._data);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
/**
|
|
@@ -272,7 +272,7 @@ export class ByteString {
|
|
|
272
272
|
* @returns Byte at index or undefined
|
|
273
273
|
*/
|
|
274
274
|
at(index: number): number | undefined {
|
|
275
|
-
return this
|
|
275
|
+
return this._data[index];
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
/**
|
|
@@ -282,9 +282,9 @@ export class ByteString {
|
|
|
282
282
|
* @returns true if equal
|
|
283
283
|
*/
|
|
284
284
|
equals(other: ByteString): boolean {
|
|
285
|
-
if (this
|
|
286
|
-
for (let i = 0; i < this
|
|
287
|
-
if (this
|
|
285
|
+
if (this._data.length !== other._data.length) return false;
|
|
286
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
287
|
+
if (this._data[i] !== other._data[i]) return false;
|
|
288
288
|
}
|
|
289
289
|
return true;
|
|
290
290
|
}
|
package/src/date.ts
CHANGED
|
@@ -67,7 +67,7 @@ import { CborError } from "./error";
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDecodable<CborDate> {
|
|
70
|
-
|
|
70
|
+
private _datetime: Date;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Creates a new `CborDate` from the given JavaScript `Date`.
|
|
@@ -87,7 +87,7 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
87
87
|
*/
|
|
88
88
|
static fromDatetime(dateTime: Date): CborDate {
|
|
89
89
|
const instance = new CborDate();
|
|
90
|
-
instance
|
|
90
|
+
instance._datetime = new Date(dateTime);
|
|
91
91
|
return instance;
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -265,7 +265,7 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
265
265
|
* ```
|
|
266
266
|
*/
|
|
267
267
|
datetime(): Date {
|
|
268
|
-
return new Date(this
|
|
268
|
+
return new Date(this._datetime);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/**
|
|
@@ -285,8 +285,8 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
285
285
|
* ```
|
|
286
286
|
*/
|
|
287
287
|
timestamp(): number {
|
|
288
|
-
const wholeSecondsSinceUnixEpoch = Math.trunc(this
|
|
289
|
-
const msecs = this
|
|
288
|
+
const wholeSecondsSinceUnixEpoch = Math.trunc(this._datetime.getTime() / 1000);
|
|
289
|
+
const msecs = this._datetime.getTime() % 1000;
|
|
290
290
|
return wholeSecondsSinceUnixEpoch + msecs / 1000.0;
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -430,7 +430,7 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
const date = CborDate.fromTimestamp(timestamp);
|
|
433
|
-
this
|
|
433
|
+
this._datetime = date._datetime;
|
|
434
434
|
return this;
|
|
435
435
|
}
|
|
436
436
|
|
|
@@ -495,7 +495,7 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
495
495
|
* ```
|
|
496
496
|
*/
|
|
497
497
|
toString(): string {
|
|
498
|
-
const dt = this
|
|
498
|
+
const dt = this._datetime;
|
|
499
499
|
// Check only hours, minutes, and seconds (not milliseconds) to match Rust behavior
|
|
500
500
|
const hasTime = dt.getUTCHours() !== 0 || dt.getUTCMinutes() !== 0 || dt.getUTCSeconds() !== 0;
|
|
501
501
|
|
|
@@ -521,7 +521,7 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
521
521
|
* @returns true if dates represent the same moment in time
|
|
522
522
|
*/
|
|
523
523
|
equals(other: CborDate): boolean {
|
|
524
|
-
return this
|
|
524
|
+
return this._datetime.getTime() === other._datetime.getTime();
|
|
525
525
|
}
|
|
526
526
|
|
|
527
527
|
/**
|
|
@@ -531,8 +531,8 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
531
531
|
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
|
532
532
|
*/
|
|
533
533
|
compare(other: CborDate): number {
|
|
534
|
-
const thisTime = this
|
|
535
|
-
const otherTime = other
|
|
534
|
+
const thisTime = this._datetime.getTime();
|
|
535
|
+
const otherTime = other._datetime.getTime();
|
|
536
536
|
if (thisTime < otherTime) return -1;
|
|
537
537
|
if (thisTime > otherTime) return 1;
|
|
538
538
|
return 0;
|
|
@@ -548,6 +548,6 @@ export class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDeco
|
|
|
548
548
|
}
|
|
549
549
|
|
|
550
550
|
private constructor() {
|
|
551
|
-
this
|
|
551
|
+
this._datetime = new Date();
|
|
552
552
|
}
|
|
553
553
|
}
|
package/src/map.ts
CHANGED
|
@@ -44,14 +44,14 @@ export interface MapEntry {
|
|
|
44
44
|
* encoded CBOR representation, ensuring deterministic encoding.
|
|
45
45
|
*/
|
|
46
46
|
export class CborMap {
|
|
47
|
-
|
|
47
|
+
private _dict: SortedMap<MapKey, MapEntry>;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new, empty CBOR Map.
|
|
51
51
|
* Optionally initializes from a JavaScript Map.
|
|
52
52
|
*/
|
|
53
53
|
constructor(map?: Map<unknown, unknown>) {
|
|
54
|
-
this
|
|
54
|
+
this._dict = new SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
55
55
|
|
|
56
56
|
if (map !== undefined) {
|
|
57
57
|
for (const [key, value] of map.entries()) {
|
|
@@ -76,7 +76,7 @@ export class CborMap {
|
|
|
76
76
|
const keyCbor = cbor(key);
|
|
77
77
|
const valueCbor = cbor(value);
|
|
78
78
|
const keyData = cborData(keyCbor);
|
|
79
|
-
this
|
|
79
|
+
this._dict.set(keyData, { key: keyCbor, value: valueCbor });
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
@@ -86,7 +86,7 @@ export class CborMap {
|
|
|
86
86
|
this.set(key, value);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
private _makeKey<K extends CborInput>(key: K): MapKey {
|
|
90
90
|
const keyCbor = cbor(key);
|
|
91
91
|
return cborData(keyCbor);
|
|
92
92
|
}
|
|
@@ -97,8 +97,8 @@ export class CborMap {
|
|
|
97
97
|
* Matches Rust's Map::get().
|
|
98
98
|
*/
|
|
99
99
|
get<K extends CborInput, V>(key: K): V | undefined {
|
|
100
|
-
const keyData = this
|
|
101
|
-
const value = this
|
|
100
|
+
const keyData = this._makeKey(key);
|
|
101
|
+
const value = this._dict.get(keyData);
|
|
102
102
|
if (value === undefined) {
|
|
103
103
|
return undefined;
|
|
104
104
|
}
|
|
@@ -124,24 +124,24 @@ export class CborMap {
|
|
|
124
124
|
* Matches Rust's Map::contains_key().
|
|
125
125
|
*/
|
|
126
126
|
containsKey<K extends CborInput>(key: K): boolean {
|
|
127
|
-
const keyData = this
|
|
128
|
-
return this
|
|
127
|
+
const keyData = this._makeKey(key);
|
|
128
|
+
return this._dict.has(keyData);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
delete<K extends CborInput>(key: K): boolean {
|
|
132
|
-
const keyData = this
|
|
133
|
-
const existed = this
|
|
134
|
-
this
|
|
132
|
+
const keyData = this._makeKey(key);
|
|
133
|
+
const existed = this._dict.has(keyData);
|
|
134
|
+
this._dict.delete(keyData);
|
|
135
135
|
return existed;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
has<K extends CborInput>(key: K): boolean {
|
|
139
|
-
const keyData = this
|
|
140
|
-
return this
|
|
139
|
+
const keyData = this._makeKey(key);
|
|
140
|
+
return this._dict.has(keyData);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
clear(): void {
|
|
144
|
-
this
|
|
144
|
+
this._dict = new SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
@@ -149,7 +149,7 @@ export class CborMap {
|
|
|
149
149
|
* Matches Rust's Map::len().
|
|
150
150
|
*/
|
|
151
151
|
get length(): number {
|
|
152
|
-
return this
|
|
152
|
+
return this._dict.length;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
@@ -157,7 +157,7 @@ export class CborMap {
|
|
|
157
157
|
* Also matches Rust's Map::len().
|
|
158
158
|
*/
|
|
159
159
|
get size(): number {
|
|
160
|
-
return this
|
|
160
|
+
return this._dict.length;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
@@ -165,7 +165,7 @@ export class CborMap {
|
|
|
165
165
|
* Matches Rust's Map::len().
|
|
166
166
|
*/
|
|
167
167
|
len(): number {
|
|
168
|
-
return this
|
|
168
|
+
return this._dict.length;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
@@ -173,7 +173,7 @@ export class CborMap {
|
|
|
173
173
|
* Matches Rust's Map::is_empty().
|
|
174
174
|
*/
|
|
175
175
|
isEmpty(): boolean {
|
|
176
|
-
return this
|
|
176
|
+
return this._dict.length === 0;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -181,7 +181,7 @@ export class CborMap {
|
|
|
181
181
|
* Keys are sorted in lexicographic order of their encoded CBOR bytes.
|
|
182
182
|
*/
|
|
183
183
|
get entriesArray(): MapEntry[] {
|
|
184
|
-
return this
|
|
184
|
+
return this._dict.map((value: MapEntry, _key: MapKey) => ({
|
|
185
185
|
key: value.key,
|
|
186
186
|
value: value.value,
|
|
187
187
|
}));
|
|
@@ -213,21 +213,21 @@ export class CborMap {
|
|
|
213
213
|
* Matches Rust's Map::insert_next().
|
|
214
214
|
*/
|
|
215
215
|
setNext<K extends CborInput, V extends CborInput>(key: K, value: V): void {
|
|
216
|
-
const lastEntry = this
|
|
216
|
+
const lastEntry = this._dict.max();
|
|
217
217
|
if (lastEntry === undefined) {
|
|
218
218
|
this.set(key, value);
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
221
|
const keyCbor = cbor(key);
|
|
222
222
|
const newKey = cborData(keyCbor);
|
|
223
|
-
if (this
|
|
223
|
+
if (this._dict.has(newKey)) {
|
|
224
224
|
throw new CborError({ type: "DuplicateMapKey" });
|
|
225
225
|
}
|
|
226
|
-
const lastEntryKey = this
|
|
226
|
+
const lastEntryKey = this._makeKey(lastEntry.key);
|
|
227
227
|
if (lexicographicallyCompareBytes(newKey, lastEntryKey) <= 0) {
|
|
228
228
|
throw new CborError({ type: "MisorderedMapKey" });
|
|
229
229
|
}
|
|
230
|
-
this
|
|
230
|
+
this._dict.set(newKey, { key: keyCbor, value: cbor(value) });
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
get debug(): string {
|
package/src/set.ts
CHANGED
|
@@ -47,10 +47,10 @@ import { CborError } from "./error";
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet> {
|
|
50
|
-
readonly
|
|
50
|
+
private readonly _map: CborMap;
|
|
51
51
|
|
|
52
52
|
constructor() {
|
|
53
|
-
this
|
|
53
|
+
this._map = new CborMap();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// =========================================================================
|
|
@@ -127,7 +127,7 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
127
127
|
insert(value: CborInput): void {
|
|
128
128
|
const cborValue = encodeCborValue(value);
|
|
129
129
|
// In a set, key and value are the same
|
|
130
|
-
this
|
|
130
|
+
this._map.set(cborValue, cborValue);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -145,7 +145,7 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
145
145
|
*/
|
|
146
146
|
contains(value: CborInput): boolean {
|
|
147
147
|
const cborValue = encodeCborValue(value);
|
|
148
|
-
return this
|
|
148
|
+
return this._map.has(cborValue);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
/**
|
|
@@ -163,14 +163,14 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
163
163
|
*/
|
|
164
164
|
delete(value: CborInput): boolean {
|
|
165
165
|
const cborValue = encodeCborValue(value);
|
|
166
|
-
return this
|
|
166
|
+
return this._map.delete(cborValue);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* Remove all elements from the set.
|
|
171
171
|
*/
|
|
172
172
|
clear(): void {
|
|
173
|
-
this
|
|
173
|
+
this._map.clear();
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
@@ -179,7 +179,7 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
179
179
|
* @returns Number of elements
|
|
180
180
|
*/
|
|
181
181
|
get size(): number {
|
|
182
|
-
return this
|
|
182
|
+
return this._map.size;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
/**
|
|
@@ -188,7 +188,7 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
188
188
|
* @returns true if set has no elements
|
|
189
189
|
*/
|
|
190
190
|
isEmpty(): boolean {
|
|
191
|
-
return this
|
|
191
|
+
return this._map.size === 0;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// =========================================================================
|
|
@@ -313,7 +313,7 @@ export class CborSet implements CborTaggedEncodable, CborTaggedDecodable<CborSet
|
|
|
313
313
|
* ```
|
|
314
314
|
*/
|
|
315
315
|
*[Symbol.iterator](): Iterator<Cbor> {
|
|
316
|
-
for (const [_, value] of this
|
|
316
|
+
for (const [_, value] of this._map) {
|
|
317
317
|
yield value;
|
|
318
318
|
}
|
|
319
319
|
}
|
package/src/tags-store.ts
CHANGED
|
@@ -89,9 +89,9 @@ export interface TagsStoreTrait {
|
|
|
89
89
|
* Stores tags with their names and optional summarizer functions.
|
|
90
90
|
*/
|
|
91
91
|
export class TagsStore implements TagsStoreTrait {
|
|
92
|
-
readonly
|
|
93
|
-
readonly
|
|
94
|
-
readonly
|
|
92
|
+
private readonly _tagsByValue = new Map<string, Tag>();
|
|
93
|
+
private readonly _tagsByName = new Map<string, Tag>();
|
|
94
|
+
private readonly _summarizers = new Map<string, CborSummarizer>();
|
|
95
95
|
|
|
96
96
|
constructor() {
|
|
97
97
|
// Start with empty store, matching Rust's Default implementation
|
|
@@ -123,8 +123,8 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
123
123
|
throw new Error(`Tag ${tag.value} must have a non-empty name`);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
const key = this
|
|
127
|
-
const existing = this
|
|
126
|
+
const key = this._valueKey(tag.value);
|
|
127
|
+
const existing = this._tagsByValue.get(key);
|
|
128
128
|
|
|
129
129
|
// Rust: if old_name != name { panic!(...) }
|
|
130
130
|
if (existing?.name !== undefined && existing.name !== name) {
|
|
@@ -133,8 +133,8 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
133
133
|
);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
this
|
|
137
|
-
this
|
|
136
|
+
this._tagsByValue.set(key, tag);
|
|
137
|
+
this._tagsByName.set(name, tag);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -173,13 +173,13 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
setSummarizer(tagValue: CborNumber, summarizer: CborSummarizer): void {
|
|
176
|
-
const key = this
|
|
177
|
-
this
|
|
176
|
+
const key = this._valueKey(tagValue);
|
|
177
|
+
this._summarizers.set(key, summarizer);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
assignedNameForTag(tag: Tag): string | undefined {
|
|
181
|
-
const key = this
|
|
182
|
-
const stored = this
|
|
181
|
+
const key = this._valueKey(tag.value);
|
|
182
|
+
const stored = this._tagsByValue.get(key);
|
|
183
183
|
return stored?.name;
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -188,12 +188,12 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
tagForValue(value: CborNumber): Tag | undefined {
|
|
191
|
-
const key = this
|
|
192
|
-
return this
|
|
191
|
+
const key = this._valueKey(value);
|
|
192
|
+
return this._tagsByValue.get(key);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
tagForName(name: string): Tag | undefined {
|
|
196
|
-
return this
|
|
196
|
+
return this._tagsByName.get(name);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
nameForValue(value: CborNumber): string {
|
|
@@ -202,8 +202,8 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
summarizer(tag: CborNumber): CborSummarizer | undefined {
|
|
205
|
-
const key = this
|
|
206
|
-
return this
|
|
205
|
+
const key = this._valueKey(tag);
|
|
206
|
+
return this._summarizers.get(key);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
@@ -212,7 +212,7 @@ export class TagsStore implements TagsStoreTrait {
|
|
|
212
212
|
*
|
|
213
213
|
* @private
|
|
214
214
|
*/
|
|
215
|
-
|
|
215
|
+
private _valueKey(value: CborNumber): string {
|
|
216
216
|
return value.toString();
|
|
217
217
|
}
|
|
218
218
|
}
|