@bcts/uniform-resources 1.0.0-alpha.11 → 1.0.0-alpha.13
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 +38 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -247
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -247
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +38 -112
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +38 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/error.ts +11 -0
- package/src/index.ts +5 -24
- package/src/multipart-decoder.ts +0 -22
- package/src/multipart-encoder.ts +0 -27
package/dist/index.iife.js
CHANGED
|
@@ -4900,7 +4900,13 @@ var bctsUniformResources = (function(exports) {
|
|
|
4900
4900
|
/**
|
|
4901
4901
|
* Insert a tag into the registry.
|
|
4902
4902
|
*
|
|
4903
|
-
*
|
|
4903
|
+
* Matches Rust's TagsStore::insert() behavior:
|
|
4904
|
+
* - Throws if the tag name is undefined or empty
|
|
4905
|
+
* - Throws if a tag with the same value exists with a different name
|
|
4906
|
+
* - Allows re-registering the same tag value with the same name
|
|
4907
|
+
*
|
|
4908
|
+
* @param tag - The tag to register (must have a non-empty name)
|
|
4909
|
+
* @throws Error if tag has no name, empty name, or conflicts with existing registration
|
|
4904
4910
|
*
|
|
4905
4911
|
* @example
|
|
4906
4912
|
* ```typescript
|
|
@@ -4909,9 +4915,13 @@ var bctsUniformResources = (function(exports) {
|
|
|
4909
4915
|
* ```
|
|
4910
4916
|
*/
|
|
4911
4917
|
insert(tag) {
|
|
4918
|
+
const name = tag.name;
|
|
4919
|
+
if (name === void 0 || name === "") throw new Error(`Tag ${tag.value} must have a non-empty name`);
|
|
4912
4920
|
const key = this.#valueKey(tag.value);
|
|
4921
|
+
const existing = this.#tagsByValue.get(key);
|
|
4922
|
+
if (existing?.name !== void 0 && existing.name !== name) throw new Error(`Attempt to register tag: ${tag.value} '${existing.name}' with different name: '${name}'`);
|
|
4913
4923
|
this.#tagsByValue.set(key, tag);
|
|
4914
|
-
|
|
4924
|
+
this.#tagsByName.set(name, tag);
|
|
4915
4925
|
}
|
|
4916
4926
|
/**
|
|
4917
4927
|
* Insert multiple tags into the registry.
|
|
@@ -4949,21 +4959,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
4949
4959
|
const key = this.#valueKey(tagValue$1);
|
|
4950
4960
|
this.#summarizers.set(key, summarizer);
|
|
4951
4961
|
}
|
|
4952
|
-
/**
|
|
4953
|
-
* Remove a tag from the registry.
|
|
4954
|
-
*
|
|
4955
|
-
* @param tagValue - The numeric tag value to remove
|
|
4956
|
-
* @returns true if a tag was removed, false otherwise
|
|
4957
|
-
*/
|
|
4958
|
-
remove(tagValue$1) {
|
|
4959
|
-
const key = this.#valueKey(tagValue$1);
|
|
4960
|
-
const tag = this.#tagsByValue.get(key);
|
|
4961
|
-
if (tag === void 0) return false;
|
|
4962
|
-
this.#tagsByValue.delete(key);
|
|
4963
|
-
if (tag.name !== void 0) this.#tagsByName.delete(tag.name);
|
|
4964
|
-
this.#summarizers.delete(key);
|
|
4965
|
-
return true;
|
|
4966
|
-
}
|
|
4967
4962
|
assignedNameForTag(tag) {
|
|
4968
4963
|
const key = this.#valueKey(tag.value);
|
|
4969
4964
|
return this.#tagsByValue.get(key)?.name;
|
|
@@ -4987,30 +4982,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
4987
4982
|
return this.#summarizers.get(key);
|
|
4988
4983
|
}
|
|
4989
4984
|
/**
|
|
4990
|
-
* Get all registered tags.
|
|
4991
|
-
*
|
|
4992
|
-
* @returns Array of all registered tags
|
|
4993
|
-
*/
|
|
4994
|
-
getAllTags() {
|
|
4995
|
-
return Array.from(this.#tagsByValue.values());
|
|
4996
|
-
}
|
|
4997
|
-
/**
|
|
4998
|
-
* Clear all registered tags and summarizers.
|
|
4999
|
-
*/
|
|
5000
|
-
clear() {
|
|
5001
|
-
this.#tagsByValue.clear();
|
|
5002
|
-
this.#tagsByName.clear();
|
|
5003
|
-
this.#summarizers.clear();
|
|
5004
|
-
}
|
|
5005
|
-
/**
|
|
5006
|
-
* Get the number of registered tags.
|
|
5007
|
-
*
|
|
5008
|
-
* @returns Number of tags in the registry
|
|
5009
|
-
*/
|
|
5010
|
-
get size() {
|
|
5011
|
-
return this.#tagsByValue.size;
|
|
5012
|
-
}
|
|
5013
|
-
/**
|
|
5014
4985
|
* Create a string key for a numeric tag value.
|
|
5015
4986
|
* Handles both number and bigint types.
|
|
5016
4987
|
*
|
|
@@ -5373,11 +5344,17 @@ var bctsUniformResources = (function(exports) {
|
|
|
5373
5344
|
}
|
|
5374
5345
|
/**
|
|
5375
5346
|
* Format tagged value.
|
|
5347
|
+
*
|
|
5348
|
+
* Matches Rust's diag_item() for Tagged case.
|
|
5376
5349
|
*/
|
|
5377
5350
|
function formatTagged(tag, content, opts) {
|
|
5378
5351
|
if (opts.summarize === true) {
|
|
5379
5352
|
const summarizer = resolveTagsStore(opts.tags)?.summarizer(tag);
|
|
5380
|
-
if (summarizer !== void 0)
|
|
5353
|
+
if (summarizer !== void 0) {
|
|
5354
|
+
const result$1 = summarizer(content, opts.flat ?? false);
|
|
5355
|
+
if (result$1.ok) return result$1.value;
|
|
5356
|
+
else return `<error: ${result$1.error.type === "Custom" ? result$1.error.message : result$1.error.type === "WrongTag" ? `expected CBOR tag ${result$1.error.expected.value}, but got ${result$1.error.actual.value}` : result$1.error.type}>`;
|
|
5357
|
+
}
|
|
5381
5358
|
}
|
|
5382
5359
|
let comment;
|
|
5383
5360
|
if (opts.annotate === true) {
|
|
@@ -6008,21 +5985,20 @@ var bctsUniformResources = (function(exports) {
|
|
|
6008
5985
|
* @param cbor - The CBOR value to traverse
|
|
6009
5986
|
* @param initialState - Initial state value
|
|
6010
5987
|
* @param visitor - Function to call for each element
|
|
6011
|
-
* @returns Final state after traversal
|
|
6012
5988
|
*
|
|
6013
5989
|
* @example
|
|
6014
5990
|
* ```typescript
|
|
6015
|
-
* // Count all text strings in a structure
|
|
6016
|
-
*
|
|
5991
|
+
* // Count all text strings in a structure using RefCell-like pattern
|
|
5992
|
+
* const count = { value: 0 };
|
|
6017
5993
|
*
|
|
6018
5994
|
* const structure = cbor({ name: 'Alice', tags: ['urgent', 'draft'] });
|
|
6019
|
-
*
|
|
5995
|
+
* walk(structure, null, (element, level, edge, state) => {
|
|
6020
5996
|
* if (element.type === 'single' && element.cbor.type === MajorType.Text) {
|
|
6021
|
-
*
|
|
5997
|
+
* count.value++;
|
|
6022
5998
|
* }
|
|
6023
5999
|
* return [state, false];
|
|
6024
6000
|
* });
|
|
6025
|
-
* console.log(
|
|
6001
|
+
* console.log(count.value); // 3 (name, urgent, draft)
|
|
6026
6002
|
* ```
|
|
6027
6003
|
*
|
|
6028
6004
|
* @example
|
|
@@ -6031,7 +6007,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
6031
6007
|
* const structure = cbor([1, 2, 3, 'found', 5, 6]);
|
|
6032
6008
|
* let found = false;
|
|
6033
6009
|
*
|
|
6034
|
-
* walk(structure, null, (element, level, edge) => {
|
|
6010
|
+
* walk(structure, null, (element, level, edge, state) => {
|
|
6035
6011
|
* if (element.type === 'single' &&
|
|
6036
6012
|
* element.cbor.type === MajorType.Text &&
|
|
6037
6013
|
* element.cbor.value === 'found') {
|
|
@@ -6043,7 +6019,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
6043
6019
|
* ```
|
|
6044
6020
|
*/
|
|
6045
6021
|
const walk = (cbor$1, initialState, visitor) => {
|
|
6046
|
-
|
|
6022
|
+
walkInternal(cbor$1, 0, { type: EdgeType.None }, initialState, visitor);
|
|
6047
6023
|
};
|
|
6048
6024
|
/**
|
|
6049
6025
|
* Internal recursive walk implementation.
|
|
@@ -6527,7 +6503,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
6527
6503
|
return this.value;
|
|
6528
6504
|
},
|
|
6529
6505
|
walk(initialState, visitor) {
|
|
6530
|
-
|
|
6506
|
+
walk(this, initialState, visitor);
|
|
6531
6507
|
},
|
|
6532
6508
|
validateTag(expectedTags) {
|
|
6533
6509
|
if (this.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
@@ -6663,6 +6639,16 @@ var bctsUniformResources = (function(exports) {
|
|
|
6663
6639
|
}
|
|
6664
6640
|
};
|
|
6665
6641
|
/**
|
|
6642
|
+
* Error type for UR decoder errors.
|
|
6643
|
+
* Matches Rust's Error::UR(String) variant.
|
|
6644
|
+
*/
|
|
6645
|
+
var URDecodeError = class extends URError {
|
|
6646
|
+
constructor(message) {
|
|
6647
|
+
super(`UR decoder error (${message})`);
|
|
6648
|
+
this.name = "URDecodeError";
|
|
6649
|
+
}
|
|
6650
|
+
};
|
|
6651
|
+
/**
|
|
6666
6652
|
* Helper function to check if a result is an error.
|
|
6667
6653
|
*/
|
|
6668
6654
|
function isError(result) {
|
|
@@ -6691,13 +6677,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
6691
6677
|
return Array.from(urType).every((char) => isURTypeChar(char));
|
|
6692
6678
|
}
|
|
6693
6679
|
/**
|
|
6694
|
-
* Validates and returns a UR type, or throws an error if invalid.
|
|
6695
|
-
*/
|
|
6696
|
-
function validateURType(urType) {
|
|
6697
|
-
if (!isValidURType(urType)) throw new InvalidTypeError();
|
|
6698
|
-
return urType;
|
|
6699
|
-
}
|
|
6700
|
-
/**
|
|
6701
6680
|
* Bytewords for encoding/decoding bytes as words.
|
|
6702
6681
|
* See: https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-004-bytewords.md
|
|
6703
6682
|
*/
|
|
@@ -8125,14 +8104,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
8125
8104
|
this._fountainEncoder = new FountainEncoder(ur.cbor().toData(), maxFragmentLen);
|
|
8126
8105
|
}
|
|
8127
8106
|
/**
|
|
8128
|
-
* Returns whether the message fits in a single part.
|
|
8129
|
-
*
|
|
8130
|
-
* For single-part messages, consider using UR.string() directly.
|
|
8131
|
-
*/
|
|
8132
|
-
isSinglePart() {
|
|
8133
|
-
return this._fountainEncoder.isSinglePart();
|
|
8134
|
-
}
|
|
8135
|
-
/**
|
|
8136
8107
|
* Gets the next part of the encoding.
|
|
8137
8108
|
*
|
|
8138
8109
|
* Parts 1 through seqLen are "pure" fragments containing one piece each.
|
|
@@ -8190,22 +8161,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
8190
8161
|
partsCount() {
|
|
8191
8162
|
return this._fountainEncoder.seqLen;
|
|
8192
8163
|
}
|
|
8193
|
-
/**
|
|
8194
|
-
* Checks if all pure parts have been emitted.
|
|
8195
|
-
*
|
|
8196
|
-
* Even after this returns true, you can continue calling nextPart()
|
|
8197
|
-
* to generate additional rateless parts for redundancy.
|
|
8198
|
-
*/
|
|
8199
|
-
isComplete() {
|
|
8200
|
-
return this._fountainEncoder.isComplete();
|
|
8201
|
-
}
|
|
8202
|
-
/**
|
|
8203
|
-
* Resets the encoder to start from the beginning.
|
|
8204
|
-
*/
|
|
8205
|
-
reset() {
|
|
8206
|
-
this._currentIndex = 0;
|
|
8207
|
-
this._fountainEncoder.reset();
|
|
8208
|
-
}
|
|
8209
8164
|
};
|
|
8210
8165
|
|
|
8211
8166
|
//#endregion
|
|
@@ -8316,48 +8271,25 @@ var bctsUniformResources = (function(exports) {
|
|
|
8316
8271
|
message() {
|
|
8317
8272
|
return this._decodedMessage;
|
|
8318
8273
|
}
|
|
8319
|
-
/**
|
|
8320
|
-
* Returns the decoding progress as a fraction (0 to 1).
|
|
8321
|
-
*/
|
|
8322
|
-
progress() {
|
|
8323
|
-
if (this._decodedMessage !== null) return 1;
|
|
8324
|
-
if (this._fountainDecoder === null) return 0;
|
|
8325
|
-
return this._fountainDecoder.progress();
|
|
8326
|
-
}
|
|
8327
|
-
/**
|
|
8328
|
-
* Resets the decoder to receive a new message.
|
|
8329
|
-
*/
|
|
8330
|
-
reset() {
|
|
8331
|
-
this._urType = null;
|
|
8332
|
-
this._fountainDecoder = null;
|
|
8333
|
-
this._decodedMessage = null;
|
|
8334
|
-
}
|
|
8335
8274
|
};
|
|
8336
8275
|
|
|
8337
8276
|
//#endregion
|
|
8338
8277
|
exports.BYTEMOJIS = BYTEMOJIS;
|
|
8339
8278
|
exports.BYTEWORDS = BYTEWORDS;
|
|
8340
|
-
exports.BYTEWORDS_MAP = BYTEWORDS_MAP;
|
|
8341
8279
|
exports.BytewordsError = BytewordsError;
|
|
8342
8280
|
exports.BytewordsStyle = BytewordsStyle;
|
|
8343
8281
|
exports.CBORError = CBORError;
|
|
8344
|
-
exports.FountainDecoder = FountainDecoder;
|
|
8345
|
-
exports.FountainEncoder = FountainEncoder;
|
|
8346
8282
|
exports.InvalidSchemeError = InvalidSchemeError;
|
|
8347
8283
|
exports.InvalidTypeError = InvalidTypeError;
|
|
8348
|
-
exports.MINIMAL_BYTEWORDS_MAP = MINIMAL_BYTEWORDS_MAP;
|
|
8349
8284
|
exports.MultipartDecoder = MultipartDecoder;
|
|
8350
8285
|
exports.MultipartEncoder = MultipartEncoder;
|
|
8351
8286
|
exports.NotSinglePartError = NotSinglePartError;
|
|
8352
8287
|
exports.TypeUnspecifiedError = TypeUnspecifiedError;
|
|
8353
8288
|
exports.UR = UR;
|
|
8289
|
+
exports.URDecodeError = URDecodeError;
|
|
8354
8290
|
exports.URError = URError;
|
|
8355
8291
|
exports.URType = URType;
|
|
8356
8292
|
exports.UnexpectedTypeError = UnexpectedTypeError;
|
|
8357
|
-
exports.Xoshiro256 = Xoshiro256;
|
|
8358
|
-
exports.chooseFragments = chooseFragments;
|
|
8359
|
-
exports.crc32 = crc32;
|
|
8360
|
-
exports.createSeed = createSeed;
|
|
8361
8293
|
exports.decodeBytewords = decodeBytewords;
|
|
8362
8294
|
exports.encodeBytemojisIdentifier = encodeBytemojisIdentifier;
|
|
8363
8295
|
exports.encodeBytewords = encodeBytewords;
|
|
@@ -8366,12 +8298,6 @@ exports.isError = isError;
|
|
|
8366
8298
|
exports.isURCodable = isURCodable;
|
|
8367
8299
|
exports.isURDecodable = isURDecodable;
|
|
8368
8300
|
exports.isUREncodable = isUREncodable;
|
|
8369
|
-
exports.isURTypeChar = isURTypeChar;
|
|
8370
|
-
exports.isValidURType = isValidURType;
|
|
8371
|
-
exports.mixFragments = mixFragments;
|
|
8372
|
-
exports.splitMessage = splitMessage;
|
|
8373
|
-
exports.validateURType = validateURType;
|
|
8374
|
-
exports.xorBytes = xorBytes;
|
|
8375
8301
|
return exports;
|
|
8376
8302
|
})({});
|
|
8377
8303
|
//# sourceMappingURL=index.iife.js.map
|