@bcts/dcbor 1.0.0-alpha.12 → 1.0.0-alpha.14

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.d.mts CHANGED
@@ -1136,17 +1136,244 @@ declare class CborDate implements CborTagged, CborTaggedEncodable, CborTaggedDec
1136
1136
  private constructor();
1137
1137
  }
1138
1138
  //#endregion
1139
+ //#region src/error.d.ts
1140
+ /**
1141
+ * A comprehensive set of errors that can occur during CBOR encoding and
1142
+ * decoding operations with special focus on enforcing the deterministic
1143
+ * encoding rules specified in the dCBOR specification.
1144
+ *
1145
+ * The dCBOR implementation validates all encoded CBOR against the
1146
+ * deterministic encoding requirements of RFC 8949 §4.2.1, plus additional
1147
+ * constraints defined in the dCBOR application profile. These errors represent
1148
+ * all the possible validation failures and decoding issues that can arise.
1149
+ */
1150
+ type Error =
1151
+ /**
1152
+ * The CBOR data ended prematurely during decoding, before a complete CBOR
1153
+ * item could be decoded. This typically happens when a CBOR item's
1154
+ * structure indicates more data than is actually present.
1155
+ */
1156
+ {
1157
+ readonly type: "Underrun";
1158
+ }
1159
+ /**
1160
+ * An unsupported or invalid value was encountered in a CBOR header byte.
1161
+ * The parameter contains the unsupported header byte value.
1162
+ * This can occur when decoding CBOR that uses unsupported features or is
1163
+ * malformed.
1164
+ */ | {
1165
+ readonly type: "UnsupportedHeaderValue";
1166
+ readonly value: number;
1167
+ }
1168
+ /**
1169
+ * A CBOR numeric value was encoded in a non-canonical form, violating the
1170
+ * deterministic encoding requirement of dCBOR (per Section 2.3 of the
1171
+ * dCBOR specification).
1172
+ *
1173
+ * This error is triggered when:
1174
+ * - An integer is not encoded in its shortest possible form
1175
+ * - A floating point value that could be represented as an integer was not
1176
+ * reduced
1177
+ * - A NaN value was not encoded in its canonical form (`f97e00`)
1178
+ */ | {
1179
+ readonly type: "NonCanonicalNumeric";
1180
+ }
1181
+ /**
1182
+ * An invalid CBOR simple value was encountered during decoding.
1183
+ *
1184
+ * Per Section 2.4 of the dCBOR specification, only `false`, `true`,
1185
+ * `null`, and floating point values are valid simple values in dCBOR.
1186
+ * All other major type 7 values are invalid.
1187
+ */ | {
1188
+ readonly type: "InvalidSimpleValue";
1189
+ }
1190
+ /**
1191
+ * A CBOR text string was not valid UTF-8. The parameter contains the
1192
+ * specific error message.
1193
+ *
1194
+ * All CBOR text strings (major type 3) must be valid UTF-8 per RFC 8949.
1195
+ */ | {
1196
+ readonly type: "InvalidString";
1197
+ readonly message: string;
1198
+ }
1199
+ /**
1200
+ * A CBOR text string was not encoded in Unicode Canonical Normalization
1201
+ * Form C (NFC).
1202
+ *
1203
+ * Per Section 2.5 of the dCBOR specification, all text strings must be in
1204
+ * NFC form, and decoders must reject any encoded text strings that are
1205
+ * not in NFC.
1206
+ */ | {
1207
+ readonly type: "NonCanonicalString";
1208
+ }
1209
+ /**
1210
+ * The decoded CBOR item didn't consume all input data.
1211
+ * The parameter contains the number of unused bytes.
1212
+ *
1213
+ * This error occurs when decoding functions expect exactly one CBOR item
1214
+ * but the input contains additional data after a valid CBOR item.
1215
+ */ | {
1216
+ readonly type: "UnusedData";
1217
+ readonly count: number;
1218
+ }
1219
+ /**
1220
+ * The keys in a decoded CBOR map were not in the canonical lexicographic order
1221
+ * of their encoding.
1222
+ *
1223
+ * Per the CDE specification and Section 2.1 of dCBOR, map keys must be in
1224
+ * ascending lexicographic order of their encoded representation for
1225
+ * deterministic encoding.
1226
+ */ | {
1227
+ readonly type: "MisorderedMapKey";
1228
+ }
1229
+ /**
1230
+ * A decoded CBOR map contains duplicate keys, which is invalid.
1231
+ *
1232
+ * Per Section 2.2 of the dCBOR specification, CBOR maps must not contain
1233
+ * duplicate keys, and decoders must reject encoded maps with duplicate
1234
+ * keys.
1235
+ */ | {
1236
+ readonly type: "DuplicateMapKey";
1237
+ }
1238
+ /**
1239
+ * A requested key was not found in a CBOR map during data extraction.
1240
+ */ | {
1241
+ readonly type: "MissingMapKey";
1242
+ }
1243
+ /**
1244
+ * A CBOR numeric value could not be represented in the specified target
1245
+ * numeric type.
1246
+ *
1247
+ * This occurs when attempting to convert a CBOR number to a numeric
1248
+ * type that is too small to represent the value without loss of
1249
+ * precision.
1250
+ */ | {
1251
+ readonly type: "OutOfRange";
1252
+ }
1253
+ /**
1254
+ * The CBOR value is not of the expected type for a conversion or
1255
+ * operation.
1256
+ *
1257
+ * This occurs when attempting to convert a CBOR value to a type that
1258
+ * doesn't match the actual CBOR item's type (e.g., trying to convert a
1259
+ * string to an integer).
1260
+ */ | {
1261
+ readonly type: "WrongType";
1262
+ }
1263
+ /**
1264
+ * The CBOR tagged value had a different tag than expected.
1265
+ * Contains the expected tag and the actual tag found.
1266
+ */ | {
1267
+ readonly type: "WrongTag";
1268
+ readonly expected: Tag;
1269
+ readonly actual: Tag;
1270
+ }
1271
+ /**
1272
+ * Invalid UTF‑8 in a text string.
1273
+ */ | {
1274
+ readonly type: "InvalidUtf8";
1275
+ readonly message: string;
1276
+ }
1277
+ /**
1278
+ * Invalid ISO 8601 date format.
1279
+ */ | {
1280
+ readonly type: "InvalidDate";
1281
+ readonly message: string;
1282
+ }
1283
+ /**
1284
+ * Custom error message.
1285
+ */ | {
1286
+ readonly type: "Custom";
1287
+ readonly message: string;
1288
+ };
1289
+ /**
1290
+ * Create a custom error with a message.
1291
+ *
1292
+ * Matches Rust's `Error::msg()` method.
1293
+ */
1294
+ declare const errorMsg: (message: string) => Error;
1295
+ /**
1296
+ * Convert an Error to a display string.
1297
+ *
1298
+ * Matches Rust's `Display` trait / `to_string()` method.
1299
+ */
1300
+ declare const errorToString: (error: Error) => string;
1301
+ /**
1302
+ * Result type matching Rust's `Result<T, Error>`.
1303
+ *
1304
+ * In TypeScript, we use a discriminated union for Result instead of
1305
+ * try/catch for better type safety and Rust compatibility.
1306
+ */
1307
+ type Result<T> = {
1308
+ ok: true;
1309
+ value: T;
1310
+ } | {
1311
+ ok: false;
1312
+ error: Error;
1313
+ };
1314
+ /**
1315
+ * Create a successful Result.
1316
+ */
1317
+ declare const Ok: <T>(value: T) => Result<T>;
1318
+ /**
1319
+ * Create a failed Result.
1320
+ */
1321
+ declare const Err: <T>(error: Error) => Result<T>;
1322
+ /**
1323
+ * Typed error class for all CBOR-related errors.
1324
+ *
1325
+ * Wraps the discriminated union Error type in a JavaScript Error object
1326
+ * for proper error handling with stack traces.
1327
+ *
1328
+ * @example
1329
+ * ```typescript
1330
+ * throw new CborError({ type: 'Underrun' });
1331
+ * throw new CborError({ type: 'WrongTag', expected: tag1, actual: tag2 });
1332
+ * ```
1333
+ */
1334
+ declare class CborError extends Error {
1335
+ /**
1336
+ * The structured error information.
1337
+ */
1338
+ readonly errorType: Error;
1339
+ /**
1340
+ * Create a new CborError.
1341
+ *
1342
+ * @param errorType - The discriminated union error type
1343
+ * @param message - Optional custom message (defaults to errorToString(errorType))
1344
+ */
1345
+ constructor(errorType: Error, message?: string);
1346
+ /**
1347
+ * Check if an error is a CborError.
1348
+ *
1349
+ * @param error - Error to check
1350
+ * @returns True if error is a CborError
1351
+ */
1352
+ static isCborError(error: unknown): error is CborError;
1353
+ }
1354
+ //#endregion
1139
1355
  //#region src/tags-store.d.ts
1356
+ /**
1357
+ * Result type for summarizer functions, matching Rust's Result<String, Error>.
1358
+ */
1359
+ type SummarizerResult = {
1360
+ readonly ok: true;
1361
+ readonly value: string;
1362
+ } | {
1363
+ readonly ok: false;
1364
+ readonly error: Error;
1365
+ };
1140
1366
  /**
1141
1367
  * Function type for custom CBOR value summarizers.
1142
1368
  *
1143
1369
  * Summarizers provide custom string representations for tagged values.
1370
+ * Returns a Result type matching Rust's `Result<String, Error>`.
1144
1371
  *
1145
1372
  * @param cbor - The CBOR value to summarize
1146
1373
  * @param flat - If true, produce single-line output
1147
- * @returns String summary of the value
1374
+ * @returns Result with summary string on success, or error on failure
1148
1375
  */
1149
- type CborSummarizer = (cbor: Cbor, flat: boolean) => string;
1376
+ type CborSummarizer = (cbor: Cbor, flat: boolean) => SummarizerResult;
1150
1377
  /**
1151
1378
  * Interface for tag store operations.
1152
1379
  */
@@ -1205,7 +1432,13 @@ declare class TagsStore implements TagsStoreTrait {
1205
1432
  /**
1206
1433
  * Insert a tag into the registry.
1207
1434
  *
1208
- * @param tag - The tag to register
1435
+ * Matches Rust's TagsStore::insert() behavior:
1436
+ * - Throws if the tag name is undefined or empty
1437
+ * - Throws if a tag with the same value exists with a different name
1438
+ * - Allows re-registering the same tag value with the same name
1439
+ *
1440
+ * @param tag - The tag to register (must have a non-empty name)
1441
+ * @throws Error if tag has no name, empty name, or conflicts with existing registration
1209
1442
  *
1210
1443
  * @example
1211
1444
  * ```typescript
@@ -1245,35 +1478,12 @@ declare class TagsStore implements TagsStoreTrait {
1245
1478
  * ```
1246
1479
  */
1247
1480
  setSummarizer(tagValue: CborNumber, summarizer: CborSummarizer): void;
1248
- /**
1249
- * Remove a tag from the registry.
1250
- *
1251
- * @param tagValue - The numeric tag value to remove
1252
- * @returns true if a tag was removed, false otherwise
1253
- */
1254
- remove(tagValue: CborNumber): boolean;
1255
1481
  assignedNameForTag(tag: Tag): string | undefined;
1256
1482
  nameForTag(tag: Tag): string;
1257
1483
  tagForValue(value: CborNumber): Tag | undefined;
1258
1484
  tagForName(name: string): Tag | undefined;
1259
1485
  nameForValue(value: CborNumber): string;
1260
1486
  summarizer(tag: CborNumber): CborSummarizer | undefined;
1261
- /**
1262
- * Get all registered tags.
1263
- *
1264
- * @returns Array of all registered tags
1265
- */
1266
- getAllTags(): Tag[];
1267
- /**
1268
- * Clear all registered tags and summarizers.
1269
- */
1270
- clear(): void;
1271
- /**
1272
- * Get the number of registered tags.
1273
- *
1274
- * @returns Number of tags in the registry
1275
- */
1276
- get size(): number;
1277
1487
  }
1278
1488
  /**
1279
1489
  * Get the global tags store instance.
@@ -1399,97 +1609,54 @@ declare const asKeyValue: (element: WalkElement) => [Cbor, Cbor] | undefined;
1399
1609
  */
1400
1610
  type Visitor<State> = (element: WalkElement, level: number, edge: EdgeTypeVariant, state: State) => [State, boolean];
1401
1611
  /**
1402
- * Helper: Count all elements in a CBOR tree.
1612
+ * Walk a CBOR tree, visiting each element with a visitor function.
1403
1613
  *
1404
- * @param cbor - The CBOR value to count
1405
- * @returns Total number of elements visited
1614
+ * The visitor function is called for each element in the tree, in depth-first order.
1615
+ * State is threaded through the traversal, allowing accumulation of results.
1406
1616
  *
1407
- * @example
1408
- * ```typescript
1409
- * const structure = cbor([1, 2, [3, 4]]);
1410
- * const count = countElements(structure);
1411
- * console.log(count); // 6 (array, 1, 2, inner array, 3, 4)
1412
- * ```
1413
- */
1414
- declare const countElements: (cbor: Cbor) => number;
1415
- /**
1416
- * Helper: Collect all elements at a specific depth level.
1617
+ * For maps, the visitor is called with:
1618
+ * 1. A 'keyvalue' element containing both key and value
1619
+ * 2. The key individually (if descent wasn't stopped)
1620
+ * 3. The value individually (if descent wasn't stopped)
1417
1621
  *
1622
+ * @template State - The type of state to thread through the traversal
1418
1623
  * @param cbor - The CBOR value to traverse
1419
- * @param targetLevel - The depth level to collect (0 = root)
1420
- * @returns Array of CBOR values at the target level
1624
+ * @param initialState - Initial state value
1625
+ * @param visitor - Function to call for each element
1421
1626
  *
1422
1627
  * @example
1423
1628
  * ```typescript
1424
- * const structure = cbor([[1, 2], [3, 4]]);
1425
- * const level1 = collectAtLevel(structure, 1);
1426
- * // Returns: [[1, 2], [3, 4]]
1427
- * const level2 = collectAtLevel(structure, 2);
1428
- * // Returns: [1, 2, 3, 4]
1429
- * ```
1430
- */
1431
- declare const collectAtLevel: (cbor: Cbor, targetLevel: number) => Cbor[];
1432
- /**
1433
- * Helper: Find first element matching a predicate.
1629
+ * // Count all text strings in a structure using RefCell-like pattern
1630
+ * const count = { value: 0 };
1434
1631
  *
1435
- * @template T - Type of extracted value
1436
- * @param cbor - The CBOR value to search
1437
- * @param predicate - Function to test each element
1438
- * @returns First matching element, or undefined if not found
1632
+ * const structure = cbor({ name: 'Alice', tags: ['urgent', 'draft'] });
1633
+ * walk(structure, null, (element, level, edge, state) => {
1634
+ * if (element.type === 'single' && element.cbor.type === MajorType.Text) {
1635
+ * count.value++;
1636
+ * }
1637
+ * return [state, false];
1638
+ * });
1639
+ * console.log(count.value); // 3 (name, urgent, draft)
1640
+ * ```
1439
1641
  *
1440
1642
  * @example
1441
1643
  * ```typescript
1442
- * const structure = cbor({ users: [
1443
- * { name: 'Alice', age: 30 },
1444
- * { name: 'Bob', age: 25 }
1445
- * ]});
1644
+ * // Find first occurrence and stop
1645
+ * const structure = cbor([1, 2, 3, 'found', 5, 6]);
1646
+ * let found = false;
1446
1647
  *
1447
- * const bob = findFirst(structure, (element) => {
1648
+ * walk(structure, null, (element, level, edge, state) => {
1448
1649
  * if (element.type === 'single' &&
1449
1650
  * element.cbor.type === MajorType.Text &&
1450
- * element.cbor.value === 'Bob') {
1451
- * return true;
1651
+ * element.cbor.value === 'found') {
1652
+ * found = true;
1653
+ * return [null, true]; // Stop descending
1452
1654
  * }
1453
- * return false;
1454
- * });
1455
- * ```
1456
- */
1457
- declare const findFirst: (cbor: Cbor, predicate: (element: WalkElement) => boolean) => Cbor | undefined;
1458
- /**
1459
- * Helper: Collect all text strings in a CBOR tree.
1460
- *
1461
- * @param cbor - The CBOR value to traverse
1462
- * @returns Array of all text string values found
1463
- *
1464
- * @example
1465
- * ```typescript
1466
- * const doc = cbor({
1467
- * title: 'Document',
1468
- * tags: ['urgent', 'draft'],
1469
- * author: { name: 'Alice' }
1655
+ * return [null, false];
1470
1656
  * });
1471
- *
1472
- * const texts = collectAllText(doc);
1473
- * // Returns: ['Document', 'urgent', 'draft', 'Alice']
1474
1657
  * ```
1475
1658
  */
1476
- declare const collectAllText: (cbor: Cbor) => string[];
1477
- /**
1478
- * Helper: Get the maximum depth of a CBOR tree.
1479
- *
1480
- * @param cbor - The CBOR value to measure
1481
- * @returns Maximum depth (0 for leaf values, 1+ for containers)
1482
- *
1483
- * @example
1484
- * ```typescript
1485
- * const flat = cbor([1, 2, 3]);
1486
- * console.log(maxDepth(flat)); // 1
1487
- *
1488
- * const nested = cbor([[[1]]]);
1489
- * console.log(maxDepth(nested)); // 3
1490
- * ```
1491
- */
1492
- declare const maxDepth: (cbor: Cbor) => number;
1659
+ declare const walk: <State>(cbor: Cbor, initialState: State, visitor: Visitor<State>) => void;
1493
1660
  //#endregion
1494
1661
  //#region src/cbor.d.ts
1495
1662
  declare const MajorType: {
@@ -1671,7 +1838,7 @@ interface CborMethods {
1671
1838
  * @param initialState - Initial state for the visitor
1672
1839
  * @param visitor - Visitor function called for each element
1673
1840
  */
1674
- walk<State>(initialState: State, visitor: Visitor<State>): State;
1841
+ walk<State>(initialState: State, visitor: Visitor<State>): void;
1675
1842
  /**
1676
1843
  * Validate that value has one of the expected tags.
1677
1844
  * @param expectedTags - Array of expected tag values
@@ -2453,222 +2620,6 @@ interface CborDecodable<T> {
2453
2620
  */
2454
2621
  interface CborCodable<T> extends CborEncodable, CborDecodable<T> {}
2455
2622
  //#endregion
2456
- //#region src/error.d.ts
2457
- /**
2458
- * A comprehensive set of errors that can occur during CBOR encoding and
2459
- * decoding operations with special focus on enforcing the deterministic
2460
- * encoding rules specified in the dCBOR specification.
2461
- *
2462
- * The dCBOR implementation validates all encoded CBOR against the
2463
- * deterministic encoding requirements of RFC 8949 §4.2.1, plus additional
2464
- * constraints defined in the dCBOR application profile. These errors represent
2465
- * all the possible validation failures and decoding issues that can arise.
2466
- */
2467
- type Error =
2468
- /**
2469
- * The CBOR data ended prematurely during decoding, before a complete CBOR
2470
- * item could be decoded. This typically happens when a CBOR item's
2471
- * structure indicates more data than is actually present.
2472
- */
2473
- {
2474
- readonly type: "Underrun";
2475
- }
2476
- /**
2477
- * An unsupported or invalid value was encountered in a CBOR header byte.
2478
- * The parameter contains the unsupported header byte value.
2479
- * This can occur when decoding CBOR that uses unsupported features or is
2480
- * malformed.
2481
- */ | {
2482
- readonly type: "UnsupportedHeaderValue";
2483
- readonly value: number;
2484
- }
2485
- /**
2486
- * A CBOR numeric value was encoded in a non-canonical form, violating the
2487
- * deterministic encoding requirement of dCBOR (per Section 2.3 of the
2488
- * dCBOR specification).
2489
- *
2490
- * This error is triggered when:
2491
- * - An integer is not encoded in its shortest possible form
2492
- * - A floating point value that could be represented as an integer was not
2493
- * reduced
2494
- * - A NaN value was not encoded in its canonical form (`f97e00`)
2495
- */ | {
2496
- readonly type: "NonCanonicalNumeric";
2497
- }
2498
- /**
2499
- * An invalid CBOR simple value was encountered during decoding.
2500
- *
2501
- * Per Section 2.4 of the dCBOR specification, only `false`, `true`,
2502
- * `null`, and floating point values are valid simple values in dCBOR.
2503
- * All other major type 7 values are invalid.
2504
- */ | {
2505
- readonly type: "InvalidSimpleValue";
2506
- }
2507
- /**
2508
- * A CBOR text string was not valid UTF-8. The parameter contains the
2509
- * specific error message.
2510
- *
2511
- * All CBOR text strings (major type 3) must be valid UTF-8 per RFC 8949.
2512
- */ | {
2513
- readonly type: "InvalidString";
2514
- readonly message: string;
2515
- }
2516
- /**
2517
- * A CBOR text string was not encoded in Unicode Canonical Normalization
2518
- * Form C (NFC).
2519
- *
2520
- * Per Section 2.5 of the dCBOR specification, all text strings must be in
2521
- * NFC form, and decoders must reject any encoded text strings that are
2522
- * not in NFC.
2523
- */ | {
2524
- readonly type: "NonCanonicalString";
2525
- }
2526
- /**
2527
- * The decoded CBOR item didn't consume all input data.
2528
- * The parameter contains the number of unused bytes.
2529
- *
2530
- * This error occurs when decoding functions expect exactly one CBOR item
2531
- * but the input contains additional data after a valid CBOR item.
2532
- */ | {
2533
- readonly type: "UnusedData";
2534
- readonly count: number;
2535
- }
2536
- /**
2537
- * The keys in a decoded CBOR map were not in the canonical lexicographic order
2538
- * of their encoding.
2539
- *
2540
- * Per the CDE specification and Section 2.1 of dCBOR, map keys must be in
2541
- * ascending lexicographic order of their encoded representation for
2542
- * deterministic encoding.
2543
- */ | {
2544
- readonly type: "MisorderedMapKey";
2545
- }
2546
- /**
2547
- * A decoded CBOR map contains duplicate keys, which is invalid.
2548
- *
2549
- * Per Section 2.2 of the dCBOR specification, CBOR maps must not contain
2550
- * duplicate keys, and decoders must reject encoded maps with duplicate
2551
- * keys.
2552
- */ | {
2553
- readonly type: "DuplicateMapKey";
2554
- }
2555
- /**
2556
- * A requested key was not found in a CBOR map during data extraction.
2557
- */ | {
2558
- readonly type: "MissingMapKey";
2559
- }
2560
- /**
2561
- * A CBOR numeric value could not be represented in the specified target
2562
- * numeric type.
2563
- *
2564
- * This occurs when attempting to convert a CBOR number to a numeric
2565
- * type that is too small to represent the value without loss of
2566
- * precision.
2567
- */ | {
2568
- readonly type: "OutOfRange";
2569
- }
2570
- /**
2571
- * The CBOR value is not of the expected type for a conversion or
2572
- * operation.
2573
- *
2574
- * This occurs when attempting to convert a CBOR value to a type that
2575
- * doesn't match the actual CBOR item's type (e.g., trying to convert a
2576
- * string to an integer).
2577
- */ | {
2578
- readonly type: "WrongType";
2579
- }
2580
- /**
2581
- * The CBOR tagged value had a different tag than expected.
2582
- * Contains the expected tag and the actual tag found.
2583
- */ | {
2584
- readonly type: "WrongTag";
2585
- readonly expected: Tag;
2586
- readonly actual: Tag;
2587
- }
2588
- /**
2589
- * Invalid UTF‑8 in a text string.
2590
- */ | {
2591
- readonly type: "InvalidUtf8";
2592
- readonly message: string;
2593
- }
2594
- /**
2595
- * Invalid ISO 8601 date format.
2596
- */ | {
2597
- readonly type: "InvalidDate";
2598
- readonly message: string;
2599
- }
2600
- /**
2601
- * Custom error message.
2602
- */ | {
2603
- readonly type: "Custom";
2604
- readonly message: string;
2605
- };
2606
- /**
2607
- * Create a custom error with a message.
2608
- *
2609
- * Matches Rust's `Error::msg()` method.
2610
- */
2611
- declare const errorMsg: (message: string) => Error;
2612
- /**
2613
- * Convert an Error to a display string.
2614
- *
2615
- * Matches Rust's `Display` trait / `to_string()` method.
2616
- */
2617
- declare const errorToString: (error: Error) => string;
2618
- /**
2619
- * Result type matching Rust's `Result<T, Error>`.
2620
- *
2621
- * In TypeScript, we use a discriminated union for Result instead of
2622
- * try/catch for better type safety and Rust compatibility.
2623
- */
2624
- type Result<T> = {
2625
- ok: true;
2626
- value: T;
2627
- } | {
2628
- ok: false;
2629
- error: Error;
2630
- };
2631
- /**
2632
- * Create a successful Result.
2633
- */
2634
- declare const Ok: <T>(value: T) => Result<T>;
2635
- /**
2636
- * Create a failed Result.
2637
- */
2638
- declare const Err: <T>(error: Error) => Result<T>;
2639
- /**
2640
- * Typed error class for all CBOR-related errors.
2641
- *
2642
- * Wraps the discriminated union Error type in a JavaScript Error object
2643
- * for proper error handling with stack traces.
2644
- *
2645
- * @example
2646
- * ```typescript
2647
- * throw new CborError({ type: 'Underrun' });
2648
- * throw new CborError({ type: 'WrongTag', expected: tag1, actual: tag2 });
2649
- * ```
2650
- */
2651
- declare class CborError extends Error {
2652
- /**
2653
- * The structured error information.
2654
- */
2655
- readonly errorType: Error;
2656
- /**
2657
- * Create a new CborError.
2658
- *
2659
- * @param errorType - The discriminated union error type
2660
- * @param message - Optional custom message (defaults to errorToString(errorType))
2661
- */
2662
- constructor(errorType: Error, message?: string);
2663
- /**
2664
- * Check if an error is a CborError.
2665
- *
2666
- * @param error - Error to check
2667
- * @returns True if error is a CborError
2668
- */
2669
- static isCborError(error: unknown): error is CborError;
2670
- }
2671
- //#endregion
2672
2623
  //#region src/float.d.ts
2673
2624
  /**
2674
2625
  * Check if a number has a fractional part.
@@ -3103,5 +3054,5 @@ declare const asCborMap: (cbor: Cbor) => CborMap | undefined;
3103
3054
  */
3104
3055
  declare const isNumber: (cbor: Cbor) => boolean;
3105
3056
  //#endregion
3106
- export { ByteString, Cbor, type CborArrayType, type CborArrayWrapper, type CborByteStringType, type CborCodable, CborDate, type CborDecodable, type CborEncodable, CborError, type CborInput, CborMap, type CborMapType, type CborMethods, type CborNegativeType, type CborNumber, CborSet, type CborSimpleType, type CborSummarizer, type CborTagged, type CborTaggedCodable, type CborTaggedDecodable, type CborTaggedEncodable, type CborTaggedType, type CborTextType, type CborUnsignedType, type DiagFormatOpts, type EdgeType, type EdgeTypeVariant, Err, type Error, type HexFormatOpts, MajorType, type MapEntry, Ok, type Result, type Simple, TAG_BASE16, TAG_BASE64, TAG_BASE64URL, TAG_BASE64URL_TEXT, TAG_BASE64_TEXT, TAG_BIGFLOAT, TAG_BINARY_UUID, TAG_DATE, TAG_DATE_TIME_STRING, TAG_DECIMAL_FRACTION, TAG_ENCODED_CBOR, TAG_EPOCH_DATE, TAG_EPOCH_DATE_TIME, TAG_MIME_MESSAGE, TAG_NAME_DATE, TAG_NEGATIVE_BIGNUM, TAG_POSITIVE_BIGNUM, TAG_REGEXP, TAG_SELF_DESCRIBE_CBOR, TAG_SET, TAG_STRING_REF_NAMESPACE, TAG_URI, TAG_UUID, type Tag, TagsStore, type TagsStoreTrait, type Visitor, type WalkElement, arrayIsEmpty, arrayItem, arrayLength, asArray, asBoolean, asByteString, asBytes, asCborArray, asCborMap, asFloat, asInteger, asKeyValue, asMap, asNegative, asNumber, asSingle, asTaggedValue, asText, asUnsigned, bytesToHex, cbor, cborData, collectAllText, collectAtLevel, countElements, createTag, createTaggedCbor, decodeCbor, decodeVarInt, decodeVarIntData, diagnosticOpt, edgeLabel, encodeVarInt, errorMsg, errorToString, expectArray, expectBoolean, expectBoolean as tryIntoBool, expectBytes, expectBytes as tryIntoByteString, expectFloat, expectInteger, expectMap, expectNegative, expectNumber, expectTaggedContent, expectTaggedContent as tryExpectedTaggedValue, expectText, expectText as tryIntoText, expectUnsigned, extractCbor, extractTaggedContent, findFirst, getGlobalTagsStore, getTaggedContent, hasFractionalPart, hasTag, hexOpt, hexToBytes, isArray, isBoolean, isBytes, isFloat, isInteger, isMap, isNaN, isNegative, isNull, isNumber, isSimple, isTagged, isText, isUnsigned, mapHas, mapIsEmpty, mapKeys, mapSize, mapValue, mapValues, maxDepth, registerTags, registerTagsIn, simpleName, summary, tagContent, tagValue, tagsForValues, toByteString, toByteStringFromHex, toTaggedValue, validateTag };
3057
+ export { ByteString, Cbor, type CborArrayType, type CborArrayWrapper, type CborByteStringType, type CborCodable, CborDate, type CborDecodable, type CborEncodable, CborError, type CborInput, CborMap, type CborMapType, type CborMethods, type CborNegativeType, type CborNumber, CborSet, type CborSimpleType, type CborSummarizer, type CborTagged, type CborTaggedCodable, type CborTaggedDecodable, type CborTaggedEncodable, type CborTaggedType, type CborTextType, type CborUnsignedType, type DiagFormatOpts, type EdgeType, type EdgeTypeVariant, Err, type Error, type HexFormatOpts, MajorType, type MapEntry, Ok, type Result, type Simple, type SummarizerResult, TAG_BASE16, TAG_BASE64, TAG_BASE64URL, TAG_BASE64URL_TEXT, TAG_BASE64_TEXT, TAG_BIGFLOAT, TAG_BINARY_UUID, TAG_DATE, TAG_DATE_TIME_STRING, TAG_DECIMAL_FRACTION, TAG_ENCODED_CBOR, TAG_EPOCH_DATE, TAG_EPOCH_DATE_TIME, TAG_MIME_MESSAGE, TAG_NAME_DATE, TAG_NEGATIVE_BIGNUM, TAG_POSITIVE_BIGNUM, TAG_REGEXP, TAG_SELF_DESCRIBE_CBOR, TAG_SET, TAG_STRING_REF_NAMESPACE, TAG_URI, TAG_UUID, type Tag, TagsStore, type TagsStoreTrait, type Visitor, type WalkElement, arrayIsEmpty, arrayItem, arrayLength, asArray, asBoolean, asByteString, asBytes, asCborArray, asCborMap, asFloat, asInteger, asKeyValue, asMap, asNegative, asNumber, asSingle, asTaggedValue, asText, asUnsigned, bytesToHex, cbor, cborData, createTag, createTaggedCbor, decodeCbor, decodeVarInt, decodeVarIntData, diagnosticOpt, edgeLabel, encodeVarInt, errorMsg, errorToString, expectArray, expectBoolean, expectBoolean as tryIntoBool, expectBytes, expectBytes as tryIntoByteString, expectFloat, expectInteger, expectMap, expectNegative, expectNumber, expectTaggedContent, expectTaggedContent as tryExpectedTaggedValue, expectText, expectText as tryIntoText, expectUnsigned, extractCbor, extractTaggedContent, getGlobalTagsStore, getTaggedContent, hasFractionalPart, hasTag, hexOpt, hexToBytes, isArray, isBoolean, isBytes, isFloat, isInteger, isMap, isNaN, isNegative, isNull, isNumber, isSimple, isTagged, isText, isUnsigned, mapHas, mapIsEmpty, mapKeys, mapSize, mapValue, mapValues, registerTags, registerTagsIn, simpleName, summary, tagContent, tagValue, tagsForValues, toByteString, toByteStringFromHex, toTaggedValue, validateTag, walk };
3107
3058
  //# sourceMappingURL=index.d.mts.map