@cbortech/cbor 0.23.0 → 0.24.0

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.
Files changed (56) hide show
  1. package/README.ja.md +58 -6
  2. package/README.md +59 -7
  3. package/dist/ast/CborArray.d.ts +17 -0
  4. package/dist/ast/CborBignum.d.ts +36 -0
  5. package/dist/ast/CborByteString.d.ts +20 -0
  6. package/dist/ast/CborEllipsis.d.ts +11 -0
  7. package/dist/ast/CborEmbeddedCBOR.d.ts +22 -0
  8. package/dist/ast/CborFloat.d.ts +27 -0
  9. package/dist/ast/CborIndefiniteByteString.d.ts +13 -0
  10. package/dist/ast/CborIndefiniteTextString.d.ts +13 -0
  11. package/dist/ast/CborItem.d.ts +91 -0
  12. package/dist/ast/CborMap.d.ts +17 -0
  13. package/dist/ast/CborNint.d.ts +27 -0
  14. package/dist/ast/CborSimple.d.ts +22 -0
  15. package/dist/ast/CborTag.d.ts +16 -0
  16. package/dist/ast/CborTextString.d.ts +15 -0
  17. package/dist/ast/CborUint.d.ts +14 -0
  18. package/dist/ast/CborUnresolvedAppExt.d.ts +16 -0
  19. package/dist/ast/index.cjs +1 -0
  20. package/dist/ast/index.d.ts +15 -0
  21. package/dist/ast/index.js +2 -0
  22. package/dist/cbor/constants.d.ts +14 -0
  23. package/dist/cbor/decoder.d.ts +11 -0
  24. package/dist/cbor/encode.d.ts +35 -0
  25. package/dist/cbor/encoder.d.ts +7 -0
  26. package/dist/cbor.d.ts +143 -0
  27. package/dist/edn/parser.d.ts +7 -0
  28. package/dist/edn/serialize-utils.d.ts +48 -0
  29. package/dist/edn/serializer.d.ts +7 -0
  30. package/dist/edn/tokenizer.d.ts +176 -0
  31. package/dist/extensions/bignum.d.ts +3 -0
  32. package/dist/extensions/builtins.d.ts +2 -0
  33. package/dist/extensions/cbordata.d.ts +4 -0
  34. package/dist/extensions/cri.d.ts +32 -0
  35. package/dist/extensions/dt.d.ts +109 -0
  36. package/dist/extensions/ip.d.ts +41 -0
  37. package/dist/extensions/types.d.ts +70 -0
  38. package/dist/index.cjs +2 -31
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +8 -695
  41. package/dist/index.js +30 -3913
  42. package/dist/index.js.map +1 -1
  43. package/dist/js/fromJS.d.ts +25 -0
  44. package/dist/js/toJS.d.ts +6 -0
  45. package/dist/mapEntries-D5MWtXqq.js +3245 -0
  46. package/dist/mapEntries-D5MWtXqq.js.map +1 -0
  47. package/dist/mapEntries-bihZ3yks.cjs +31 -0
  48. package/dist/mapEntries-bihZ3yks.cjs.map +1 -0
  49. package/dist/mapEntries.d.ts +3 -0
  50. package/dist/simple.d.ts +25 -0
  51. package/dist/tag.d.ts +45 -0
  52. package/dist/types.d.ts +362 -0
  53. package/dist/utils/float16.d.ts +38 -0
  54. package/dist/utils/hexfloat.d.ts +27 -0
  55. package/dist/utils/ip.d.ts +9 -0
  56. package/package.json +29 -17
package/README.ja.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [CBOR](#準拠している仕様)、[CBOR-EDN](#準拠している仕様)、JavaScript 値を相互変換するための TypeScript ライブラリです。
4
4
 
5
- このパッケージは、現時点では `CBOR` ファサードを中心にした小さな公開 API だけを提供します。
6
- 低レベルのパーサー、エンコーダー、AST クラスは、まだドキュメント上の公開 API には含めていません。
5
+ このパッケージは `CBOR` ファサードに加えて、extension の実装に必要な CBOR AST ノードクラス用の entrypoint を公開します。
6
+ 低レベルのパーサー、エンコーダー内部は、ドキュメント上の公開 API には含めていません。
7
7
 
8
8
  ## インストール
9
9
 
@@ -57,7 +57,9 @@ console.log(value);
57
57
  ```ts
58
58
  import { CBOR } from '@cbortech/cbor';
59
59
 
60
- const text = CBOR.cborToCborEdn(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
60
+ const text = CBOR.fromCBOR(
61
+ new Uint8Array([0x83, 0x01, 0x02, 0x03])
62
+ ).toEDN();
61
63
 
62
64
  console.log(text);
63
65
  // [1,2,3]
@@ -68,7 +70,7 @@ console.log(text);
68
70
  ```ts
69
71
  import { CBOR } from '@cbortech/cbor';
70
72
 
71
- const bytes = CBOR.cborEdnToCbor('[1, 2, 3]');
73
+ const bytes = CBOR.fromEDN('[1, 2, 3]').toCBOR();
72
74
 
73
75
  console.log(bytes);
74
76
  // Uint8Array([0x83, 0x01, 0x02, 0x03])
@@ -175,12 +177,15 @@ console.log(text);
175
177
  ## AST を扱う
176
178
 
177
179
  `CBOR.fromCBOR()`、`CBOR.fromEDN()`、`CBOR.fromJS()` は CBOR item を返します。
178
- 具体的なノードクラスはまだ公開 API としてドキュメント化していませんが、すべての item は次のメソッドを持ちます。
180
+ `CborTextString`、`CborByteString`、`CborArray`、`CborTag` などの具体的なノードクラスは、
181
+ extension 向けに `@cbortech/cbor/ast` から export されています。すべての item は次のメソッドを持ちます。
179
182
 
180
183
  ```ts
181
184
  import { CBOR } from '@cbortech/cbor';
185
+ import { CborItem } from '@cbortech/cbor/ast';
182
186
 
183
187
  const item = CBOR.fromEDN('{ "x": 1 }');
188
+ item satisfies CborItem;
184
189
 
185
190
  const bytes = item.toCBOR();
186
191
  const text = item.toEDN();
@@ -321,6 +326,41 @@ console.log(text);
321
326
  // DT'2026-05-06T00:00:00Z'
322
327
  ```
323
328
 
329
+ ## オプション extension
330
+
331
+ 追加の application extension は別パッケージとして公開されています。必要なものを
332
+ インストールし、`extensions` オプションに渡して使います。
333
+
334
+ `hash` は CBOR-EDN の仕様に含まれる application extension ですが、利用には
335
+ 外部パッケージが必要です。そのため、このパッケージ本体には含めず、
336
+ `@cbortech/hash-extension` として提供しています。
337
+
338
+ `uuid` は CBOR-EDN の仕様には定められていない、このライブラリ独自の
339
+ application extension です。仕様上の標準機能と区別するため、
340
+ `@cbortech/uuid-extension` として別パッケージで提供しています。
341
+
342
+ ```bash
343
+ npm install @cbortech/hash-extension @cbortech/uuid-extension
344
+ ```
345
+
346
+ ```ts
347
+ import { CBOR } from '@cbortech/cbor';
348
+ import hashExtension from '@cbortech/hash-extension';
349
+ import uuidExtension from '@cbortech/uuid-extension';
350
+
351
+ const cbor = new CBOR({
352
+ extensions: [hashExtension, uuidExtension],
353
+ });
354
+
355
+ const digest = cbor.fromEDN("hash'foo'");
356
+ console.log(digest.toEDN());
357
+ // hash'foo'
358
+
359
+ const id = cbor.fromEDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
360
+ console.log(id.toEDN());
361
+ // uuid'550e8400-e29b-41d4-a716-446655440000'
362
+ ```
363
+
324
364
  ## タグ
325
365
 
326
366
  JavaScript 上で CBOR のタグ付き値を扱うには `CBOR.Tag` を使います。
@@ -347,6 +387,18 @@ console.log(CBOR.Tag.getValue(value));
347
387
  // "hello"
348
388
  ```
349
389
 
390
+ タグ情報が不要で、中身だけを通常の JavaScript 値として扱いたい場合は
391
+ `stripTags: true` を指定できます。
392
+
393
+ ```ts
394
+ import { CBOR } from '@cbortech/cbor';
395
+
396
+ const value = CBOR.parse('42("hello")', { stripTags: true });
397
+
398
+ console.log(value);
399
+ // "hello"
400
+ ```
401
+
350
402
  ## Simple 値
351
403
 
352
404
  `false`、`true`、`null`、`undefined` 以外の CBOR simple value には `CBOR.Simple` を使います。
@@ -460,7 +512,7 @@ console.log(item.toEDN());
460
512
  このライブラリは次の仕様を対象にしています。
461
513
 
462
514
  - [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
463
- - [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-23](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/23/)
515
+ - [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-24](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/24/)
464
516
 
465
517
  CBOR-EDN は、CBOR データを人間が読み書きしやすいテキストとして表現するための記法です。
466
518
  サンプル、テストベクター、デバッグ、fixture、設定ファイルに近い用途など、CBOR のバイト列をそのまま扱うと読みにくい場面で役立ちます。
package/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  TypeScript library for converting between [CBOR](#specifications),
4
4
  [CBOR-EDN](#specifications), and JavaScript values.
5
5
 
6
- This package currently exposes a small public API centered on the `CBOR` facade.
7
- Lower-level parser, encoder, and AST classes are intentionally not part of the
8
- documented public API yet.
6
+ This package exposes the `CBOR` facade plus a separate AST entrypoint for the
7
+ CBOR node classes needed by extensions. Lower-level parser and encoder internals
8
+ are not part of the documented public API.
9
9
 
10
10
  ## Install
11
11
 
@@ -59,7 +59,9 @@ console.log(value);
59
59
  ```ts
60
60
  import { CBOR } from '@cbortech/cbor';
61
61
 
62
- const text = CBOR.cborToCborEdn(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
62
+ const text = CBOR.fromCBOR(
63
+ new Uint8Array([0x83, 0x01, 0x02, 0x03])
64
+ ).toEDN();
63
65
 
64
66
  console.log(text);
65
67
  // [1,2,3]
@@ -70,7 +72,7 @@ console.log(text);
70
72
  ```ts
71
73
  import { CBOR } from '@cbortech/cbor';
72
74
 
73
- const bytes = CBOR.cborEdnToCbor('[1, 2, 3]');
75
+ const bytes = CBOR.fromEDN('[1, 2, 3]').toCBOR();
74
76
 
75
77
  console.log(bytes);
76
78
  // Uint8Array([0x83, 0x01, 0x02, 0x03])
@@ -177,13 +179,16 @@ console.log(text);
177
179
  ## Working With The AST
178
180
 
179
181
  `CBOR.fromCBOR()`, `CBOR.fromEDN()`, and `CBOR.fromJS()` return a CBOR item.
180
- The concrete node classes are not documented as public API yet, but every item
182
+ Concrete node classes such as `CborTextString`, `CborByteString`, `CborArray`,
183
+ and `CborTag` are exported from `@cbortech/cbor/ast` for extensions. Every item
181
184
  supports these methods:
182
185
 
183
186
  ```ts
184
187
  import { CBOR } from '@cbortech/cbor';
188
+ import { CborItem } from '@cbortech/cbor/ast';
185
189
 
186
190
  const item = CBOR.fromEDN('{ "x": 1 }');
191
+ item satisfies CborItem;
187
192
 
188
193
  const bytes = item.toCBOR();
189
194
  const text = item.toEDN();
@@ -325,6 +330,41 @@ console.log(text);
325
330
  // DT'2026-05-06T00:00:00Z'
326
331
  ```
327
332
 
333
+ ## Optional Extensions
334
+
335
+ Additional application extensions are published as separate packages. Install
336
+ the ones you need and pass them through the `extensions` option.
337
+
338
+ `hash` is an application extension defined by the CBOR-EDN specification, but
339
+ it requires an external package. For that reason, it is not bundled with this
340
+ package and is provided separately as `@cbortech/hash-extension`.
341
+
342
+ `uuid` is a library-specific application extension that is not defined by the
343
+ CBOR-EDN specification. To keep it distinct from standard CBOR-EDN features, it
344
+ is provided separately as `@cbortech/uuid-extension`.
345
+
346
+ ```bash
347
+ npm install @cbortech/hash-extension @cbortech/uuid-extension
348
+ ```
349
+
350
+ ```ts
351
+ import { CBOR } from '@cbortech/cbor';
352
+ import hashExtension from '@cbortech/hash-extension';
353
+ import uuidExtension from '@cbortech/uuid-extension';
354
+
355
+ const cbor = new CBOR({
356
+ extensions: [hashExtension, uuidExtension],
357
+ });
358
+
359
+ const digest = cbor.fromEDN("hash'foo'");
360
+ console.log(digest.toEDN());
361
+ // hash'foo'
362
+
363
+ const id = cbor.fromEDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
364
+ console.log(id.toEDN());
365
+ // uuid'550e8400-e29b-41d4-a716-446655440000'
366
+ ```
367
+
328
368
  ## Tags
329
369
 
330
370
  Use `CBOR.Tag` for CBOR tagged values in JavaScript.
@@ -351,6 +391,18 @@ console.log(CBOR.Tag.getValue(value));
351
391
  // "hello"
352
392
  ```
353
393
 
394
+ Use `stripTags: true` when you only need the tagged content as a plain
395
+ JavaScript value.
396
+
397
+ ```ts
398
+ import { CBOR } from '@cbortech/cbor';
399
+
400
+ const value = CBOR.parse('42("hello")', { stripTags: true });
401
+
402
+ console.log(value);
403
+ // "hello"
404
+ ```
405
+
354
406
  ## Simple Values
355
407
 
356
408
  Use `CBOR.Simple` for CBOR simple values other than `false`, `true`, `null`, and
@@ -466,7 +518,7 @@ The `CBOR` facade also exposes:
466
518
  This library targets:
467
519
 
468
520
  - [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
469
- - [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-23](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/23/)
521
+ - [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-24](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/24/)
470
522
 
471
523
  CBOR-EDN is a human-readable text notation for CBOR data. It is useful for
472
524
  examples, test vectors, debugging, fixtures, and configuration-like files where
@@ -0,0 +1,17 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 4 — array (definite- or indefinite-length). */
5
+ export declare class CborArray extends CborItem {
6
+ readonly items: CborItem[];
7
+ readonly indefiniteLength: boolean;
8
+ readonly encodingWidth: EncodingWidth | undefined;
9
+ constructor(items: CborItem[], options?: {
10
+ indefiniteLength?: boolean;
11
+ encodingWidth?: EncodingWidth;
12
+ });
13
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
14
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
15
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
16
+ _toJS(options?: ToJSOptions): unknown;
17
+ }
@@ -0,0 +1,36 @@
1
+ import { ToEDNOptions, ToJSOptions } from '../types';
2
+ import { CborTag } from './CborTag';
3
+ export declare const BIGNUM_UINT_TAG = 2n;
4
+ export declare const BIGNUM_NINT_TAG = 3n;
5
+ /**
6
+ * Encode a non-negative bigint as a minimal big-endian byte string.
7
+ * Zero is encoded as the empty byte string per RFC 8949 §3.4.3.
8
+ */
9
+ export declare function bigintToBytes(n: bigint): Uint8Array;
10
+ /**
11
+ * Decode a big-endian byte string to a non-negative bigint.
12
+ * Empty bytes → 0n.
13
+ */
14
+ export declare function bytesToBigint(bytes: Uint8Array): bigint;
15
+ /**
16
+ * Unsigned bignum — integers ≥ 2^64.
17
+ * Wire format: tag(2, big-endian byte string).
18
+ * toEDN() emits the plain decimal integer.
19
+ */
20
+ export declare class CborBigUint extends CborTag {
21
+ readonly bigValue: bigint;
22
+ constructor(value: bigint);
23
+ _toEDN(_options: ToEDNOptions | undefined, _depth: number): string;
24
+ _toJS(_options?: ToJSOptions): bigint;
25
+ }
26
+ /**
27
+ * Negative bignum — integers ≤ -(2^64 + 1).
28
+ * Wire format: tag(3, big-endian byte string of (-1 - value)).
29
+ * toEDN() emits the plain decimal integer.
30
+ */
31
+ export declare class CborBigNint extends CborTag {
32
+ readonly bigValue: bigint;
33
+ constructor(value: bigint);
34
+ _toEDN(_options: ToEDNOptions | undefined, _depth: number): string;
35
+ _toJS(_options?: ToJSOptions): bigint;
36
+ }
@@ -0,0 +1,20 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 2 — definite-length byte string. */
5
+ export declare class CborByteString extends CborItem {
6
+ readonly indefiniteLength: false;
7
+ readonly value: Uint8Array;
8
+ /** Preferred EDN encoding for this byte string. */
9
+ readonly ednEncoding: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex';
10
+ readonly encodingWidth: EncodingWidth | undefined;
11
+ readonly ednSource: string | undefined;
12
+ constructor(value: Uint8Array, options?: {
13
+ ednEncoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex';
14
+ encodingWidth?: EncodingWidth;
15
+ ednSource?: string;
16
+ });
17
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
18
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
19
+ _toJS(_options?: ToJSOptions): unknown;
20
+ }
@@ -0,0 +1,11 @@
1
+ import { ToEDNOptions } from '../types';
2
+ import { CborTag } from './CborTag';
3
+ import { CborItem } from './CborItem';
4
+ export declare const CPA888_TAG = 888n;
5
+ export declare class CborEllipsis extends CborTag {
6
+ /** Subtree elision: 888(null) */
7
+ constructor();
8
+ /** String/bytes elision: 888([items...]) */
9
+ constructor(items: CborItem[]);
10
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
11
+ }
@@ -0,0 +1,22 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ /**
4
+ * CBOR Sequence Literal (§2.5.6) — `<<item, item, ...>>`.
5
+ *
6
+ * Encodes as a definite-length byte string whose value is the concatenation
7
+ * of the CBOR encodings of the contained items.
8
+ *
9
+ * @example
10
+ * // <<1, 2>> → h'0102'
11
+ * new CborEmbeddedCBOR([new CborUint(1n), new CborUint(2n)])
12
+ */
13
+ export declare class CborEmbeddedCBOR extends CborItem {
14
+ readonly items: CborItem[];
15
+ constructor(items: CborItem[]);
16
+ /** The raw concatenated CBOR bytes of all contained items. */
17
+ private _content;
18
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
19
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
20
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
21
+ _toJS(_options?: ToJSOptions): unknown;
22
+ }
@@ -0,0 +1,27 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ export type FloatPrecision = 'half' | 'single' | 'double';
4
+ /**
5
+ * CBOR Major Type 7 — IEEE 754 floating-point number.
6
+ *
7
+ * `precision` records the encoding size from the original CBOR stream so
8
+ * that lossless round-trips are preserved. When constructing from a JS
9
+ * `number`, omit `precision` (`undefined`) and the encoder will choose
10
+ * the smallest encoding that preserves the value exactly.
11
+ */
12
+ export declare class CborFloat extends CborItem {
13
+ readonly value: number;
14
+ /**
15
+ * Encoding size hint.
16
+ * - `'half'` / `'single'` / `'double'`: use exactly this size (set by the
17
+ * decoder to guarantee lossless round-trips).
18
+ * - `undefined`: encoder auto-selects the smallest lossless size.
19
+ */
20
+ readonly precision: FloatPrecision | undefined;
21
+ constructor(value: number, options?: {
22
+ precision?: FloatPrecision;
23
+ });
24
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
25
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
26
+ _toJS(_options?: ToJSOptions): unknown;
27
+ }
@@ -0,0 +1,13 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ import { CborByteString } from './CborByteString';
4
+ /** CBOR Major Type 2 — indefinite-length byte string (chunked). */
5
+ export declare class CborIndefiniteByteString extends CborItem {
6
+ readonly indefiniteLength: true;
7
+ readonly chunks: CborByteString[];
8
+ constructor(chunks: CborByteString[]);
9
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
10
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
11
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
12
+ _toJS(_options?: ToJSOptions): unknown;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ import { CborTextString } from './CborTextString';
4
+ /** CBOR Major Type 3 — indefinite-length UTF-8 text string (chunked). */
5
+ export declare class CborIndefiniteTextString extends CborItem {
6
+ readonly indefiniteLength: true;
7
+ readonly chunks: CborTextString[];
8
+ constructor(chunks: CborTextString[]);
9
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
10
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
11
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
12
+ _toJS(_options?: ToJSOptions): unknown;
13
+ }
@@ -0,0 +1,91 @@
1
+ import { CBOROptions, ToEDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComments } from '../types';
2
+ /** @internal One line of an annotated hex dump. */
3
+ export interface AnnotatedLine {
4
+ depth: number;
5
+ hex: string;
6
+ comment: string;
7
+ }
8
+ /**
9
+ * Abstract base class for all CBOR AST nodes.
10
+ *
11
+ * Every node can serialize itself to CBOR binary, CBOR-EDN text, and a
12
+ * plain JavaScript value. Concrete implementations are provided in each
13
+ * subclass (added in later phases).
14
+ */
15
+ export declare abstract class CborItem {
16
+ /**
17
+ * Character offset of the first character of this item in the parsed source.
18
+ * Set by parsers; undefined when the node was constructed directly.
19
+ * For CBOR input this is a byte offset.
20
+ */
21
+ start?: number;
22
+ /**
23
+ * Character offset just past the last character of this item in the parsed source.
24
+ * Set by parsers; undefined when the node was constructed directly.
25
+ * For CBOR input this is a byte offset.
26
+ */
27
+ end?: number;
28
+ /**
29
+ * Comments captured from CBOR-EDN source when `preserveComments` is enabled.
30
+ * They do not affect CBOR bytes or JS conversion.
31
+ */
32
+ comments?: CborComments;
33
+ /**
34
+ * Default options bound by a {@link CBOR} instance factory method.
35
+ * Per-call options always take precedence.
36
+ * @internal
37
+ */
38
+ _defaults?: CBOROptions;
39
+ /** Serialize this node to CBOR binary. */
40
+ toCBOR(options?: ToCBOROptions): Uint8Array;
41
+ /** Serialize this node to a CBOR-EDN text string. */
42
+ toEDN(options?: ToEDNOptions): string;
43
+ /**
44
+ * Convert this CBOR AST node to a plain JavaScript value.
45
+ *
46
+ * If `options.reviver` is supplied it is called with key `''` on the root
47
+ * result after the full tree has been converted (matching the semantics of
48
+ * `JSON.parse`). Container nodes call the reviver on each of their direct
49
+ * children during conversion, so the walk is bottom-up.
50
+ */
51
+ toJS(options?: ToJSOptions): unknown;
52
+ /**
53
+ * Generate an RFC 8949 §3 style annotated hex dump of this value.
54
+ *
55
+ * @example
56
+ * const cbor = CBOR.fromEDN('[_ 1, [2, 3]]');
57
+ * console.log(cbor.toHexDump());
58
+ * // 9F -- Start indefinite-length array
59
+ * // 01 -- 1
60
+ * // 82 -- Array of length 2
61
+ * // 02 -- 2
62
+ * // 03 -- 3
63
+ * // FF -- "break"
64
+ * // FF -- "break"
65
+ */
66
+ toHexDump(options?: ToHexDumpOptions): string;
67
+ /** @internal Subclass CBOR encoding implementation. */
68
+ abstract _toCBOR(options?: ToCBOROptions): Uint8Array;
69
+ /**
70
+ * @internal
71
+ * Depth-aware EDN serialization.
72
+ * Leaf nodes receive `depth` but may ignore it.
73
+ * Container nodes use `depth` for indentation and call
74
+ * `child._toEDN(options, depth + 1)` when recursing.
75
+ */
76
+ abstract _toEDN(options: ToEDNOptions | undefined, depth: number): string;
77
+ /**
78
+ * @internal
79
+ * Core conversion logic implemented by each subclass.
80
+ * Container nodes apply `options.reviver` to their direct children.
81
+ * Do not call this directly — use `toJS()` instead.
82
+ */
83
+ abstract _toJS(options?: ToJSOptions): unknown;
84
+ /**
85
+ * @internal
86
+ * Collect annotated-hex lines for this node.
87
+ * Leaf nodes emit a single line; container nodes override to emit
88
+ * open/close lines with recursively collected children.
89
+ */
90
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
91
+ }
@@ -0,0 +1,17 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 5 — map (definite- or indefinite-length). */
5
+ export declare class CborMap extends CborItem {
6
+ readonly entries: [CborItem, CborItem][];
7
+ readonly indefiniteLength: boolean;
8
+ readonly encodingWidth: EncodingWidth | undefined;
9
+ constructor(entries: [CborItem, CborItem][], options?: {
10
+ indefiniteLength?: boolean;
11
+ encodingWidth?: EncodingWidth;
12
+ });
13
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
14
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
15
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
16
+ _toJS(options?: ToJSOptions): unknown;
17
+ }
@@ -0,0 +1,27 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /**
5
+ * CBOR Major Type 1 — negative integer (−2^64 … −1).
6
+ *
7
+ * The constructor accepts the actual negative value (e.g. `-5n`).
8
+ * Internally the CBOR "argument" `n` is stored, where the decoded value
9
+ * equals `−1 − n`. This matches the wire encoding directly.
10
+ *
11
+ * Examples:
12
+ * new CborNint(-1n) → argument = 0n
13
+ * new CborNint(-5n) → argument = 4n
14
+ */
15
+ export declare class CborNint extends CborItem {
16
+ /** CBOR raw argument n, where actual value = −1 − n. */
17
+ readonly argument: bigint;
18
+ readonly encodingWidth: EncodingWidth | undefined;
19
+ constructor(value: number | bigint, options?: {
20
+ encodingWidth?: EncodingWidth;
21
+ });
22
+ /** The actual decoded negative value (−1 − argument). */
23
+ get value(): bigint;
24
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
25
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
26
+ _toJS(options?: ToJSOptions): unknown;
27
+ }
@@ -0,0 +1,22 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ /**
4
+ * CBOR Major Type 7 — simple value (0–255).
5
+ *
6
+ * Well-known values:
7
+ * 20 → false
8
+ * 21 → true
9
+ * 22 → null
10
+ * 23 → undefined
11
+ */
12
+ export declare class CborSimple extends CborItem {
13
+ readonly value: number;
14
+ constructor(value: number);
15
+ static readonly FALSE: CborSimple;
16
+ static readonly TRUE: CborSimple;
17
+ static readonly NULL: CborSimple;
18
+ static readonly UNDEFINED: CborSimple;
19
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
20
+ _toEDN(_options: ToEDNOptions | undefined, _depth: number): string;
21
+ _toJS(_options?: ToJSOptions): unknown;
22
+ }
@@ -0,0 +1,16 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem, AnnotatedLine } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 6 — tagged data item. */
5
+ export declare class CborTag extends CborItem {
6
+ readonly tag: bigint;
7
+ readonly content: CborItem;
8
+ readonly encodingWidth: EncodingWidth | undefined;
9
+ constructor(tag: number | bigint, content: CborItem, options?: {
10
+ encodingWidth?: EncodingWidth;
11
+ });
12
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
13
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
14
+ _toHexDump(depth: number, options?: ToEDNOptions): AnnotatedLine[];
15
+ _toJS(options?: ToJSOptions): unknown;
16
+ }
@@ -0,0 +1,15 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 3 — definite-length UTF-8 text string. */
5
+ export declare class CborTextString extends CborItem {
6
+ readonly indefiniteLength: false;
7
+ readonly value: string;
8
+ readonly encodingWidth: EncodingWidth | undefined;
9
+ constructor(value: string, options?: {
10
+ encodingWidth?: EncodingWidth;
11
+ });
12
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
13
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
14
+ _toJS(_options?: ToJSOptions): unknown;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { ToEDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ import { EncodingWidth } from '../cbor/encode';
4
+ /** CBOR Major Type 0 — unsigned integer (0 … 2^64−1). */
5
+ export declare class CborUint extends CborItem {
6
+ readonly value: bigint;
7
+ readonly encodingWidth: EncodingWidth | undefined;
8
+ constructor(value: number | bigint, options?: {
9
+ encodingWidth?: EncodingWidth;
10
+ });
11
+ _toCBOR(_options?: ToCBOROptions): Uint8Array;
12
+ _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
13
+ _toJS(options?: ToJSOptions): unknown;
14
+ }
@@ -0,0 +1,16 @@
1
+ import { ToEDNOptions } from '../types';
2
+ import { CborTag } from './CborTag';
3
+ import { CborItem } from './CborItem';
4
+ /** Provisional tag number for the Unresolved Application-Extension stand-in. */
5
+ export declare const CPA999_TAG = 999n;
6
+ /**
7
+ * Stand-in for an unrecognised EDN application-extension literal.
8
+ *
9
+ * Structure:
10
+ * App-string: CPA999([prefix, text])
11
+ * App-sequence: CPA999([prefix, [items...]])
12
+ */
13
+ export declare class CborUnresolvedAppExt extends CborTag {
14
+ constructor(prefix: string, items: CborItem[]);
15
+ _toEDN(options: ToEDNOptions | undefined, depth: number): string;
16
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../mapEntries-bihZ3yks.cjs`);exports.CborArray=e.p,exports.CborBigNint=e.c,exports.CborBigUint=e.l,exports.CborByteString=e.g,exports.CborEmbeddedCBOR=e.u,exports.CborFloat=e.v,exports.CborIndefiniteByteString=e.h,exports.CborIndefiniteTextString=e.m,exports.CborItem=e.x,exports.CborMap=e.f,exports.CborNint=e.y,exports.CborSimple=e.d,exports.CborTag=e._,exports.CborTextString=e.o,exports.CborUint=e.b;
@@ -0,0 +1,15 @@
1
+ export { CborItem } from './CborItem';
2
+ export { CborUint } from './CborUint';
3
+ export { CborBigUint, CborBigNint } from './CborBignum';
4
+ export { CborNint } from './CborNint';
5
+ export { CborByteString } from './CborByteString';
6
+ export { CborIndefiniteByteString } from './CborIndefiniteByteString';
7
+ export { CborTextString } from './CborTextString';
8
+ export { CborIndefiniteTextString } from './CborIndefiniteTextString';
9
+ export { CborArray } from './CborArray';
10
+ export { CborEmbeddedCBOR } from './CborEmbeddedCBOR';
11
+ export { CborMap } from './CborMap';
12
+ export { CborTag } from './CborTag';
13
+ export { CborFloat } from './CborFloat';
14
+ export type { FloatPrecision } from './CborFloat';
15
+ export { CborSimple } from './CborSimple';
@@ -0,0 +1,2 @@
1
+ import { _ as e, b as t, c as n, d as r, f as i, g as a, h as o, l as s, m as c, o as l, p as u, u as d, v as f, x as p, y as m } from "../mapEntries-D5MWtXqq.js";
2
+ export { u as CborArray, n as CborBigNint, s as CborBigUint, a as CborByteString, d as CborEmbeddedCBOR, f as CborFloat, o as CborIndefiniteByteString, c as CborIndefiniteTextString, p as CborItem, i as CborMap, m as CborNint, r as CborSimple, e as CborTag, l as CborTextString, t as CborUint };