@cbortech/cbor 0.25.1 → 0.25.2
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/ast/CborAppSeqResult.d.ts +2 -1
- package/dist/ast/CborArray.d.ts +2 -2
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +2 -1
- package/dist/ast/CborFloat.d.ts +2 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +2 -1
- package/dist/ast/CborIndefiniteTextString.d.ts +2 -1
- package/dist/ast/CborItem.d.ts +29 -2
- package/dist/ast/CborMap.d.ts +2 -2
- package/dist/ast/CborNint.d.ts +2 -2
- package/dist/ast/CborSimple.d.ts +2 -1
- package/dist/ast/CborTag.d.ts +2 -2
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor/encode.d.ts +38 -4
- package/dist/cdn/tokenizer.d.ts +24 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +24 -24
- package/dist/{mapEntries-ZR8QJ0Yj.js → mapEntries-BMMPg2FB.js} +1042 -937
- package/dist/mapEntries-BMMPg2FB.js.map +1 -0
- package/dist/mapEntries-DZKHc3VY.cjs +39 -0
- package/dist/mapEntries-DZKHc3VY.cjs.map +1 -0
- package/package.json +3 -2
- package/dist/mapEntries-BccT62HT.cjs +0 -36
- package/dist/mapEntries-BccT62HT.cjs.map +0 -1
- package/dist/mapEntries-ZR8QJ0Yj.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToCBOROptions, ToJSOptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
+
import { CborWriter } from '../cbor/encode';
|
|
3
4
|
/**
|
|
4
5
|
* Wraps a resolved app-sequence result and preserves the original EDN source
|
|
5
6
|
* text for round-trip fidelity.
|
|
@@ -14,7 +15,7 @@ export declare class CborAppSeqResult extends CborItem {
|
|
|
14
15
|
readonly inner: CborItem;
|
|
15
16
|
readonly ednSource: string;
|
|
16
17
|
constructor(inner: CborItem, ednSource: string);
|
|
17
|
-
|
|
18
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
18
19
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
19
20
|
_toJS(options?: ToJSOptions): unknown;
|
|
20
21
|
}
|
package/dist/ast/CborArray.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 4 — array (definite- or indefinite-length). */
|
|
5
5
|
export declare class CborArray extends CborItem {
|
|
6
6
|
readonly items: CborItem[];
|
|
@@ -10,7 +10,7 @@ export declare class CborArray extends CborItem {
|
|
|
10
10
|
indefiniteLength?: boolean;
|
|
11
11
|
encodingWidth?: EncodingWidth;
|
|
12
12
|
});
|
|
13
|
-
|
|
13
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
14
14
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
15
15
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
16
16
|
_toJS(options?: ToJSOptions): unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 2 — definite-length byte string. */
|
|
5
5
|
export declare class CborByteString extends CborItem {
|
|
6
6
|
readonly indefiniteLength: false;
|
|
@@ -14,7 +14,7 @@ export declare class CborByteString extends CborItem {
|
|
|
14
14
|
encodingWidth?: EncodingWidth;
|
|
15
15
|
ednSource?: string;
|
|
16
16
|
});
|
|
17
|
-
|
|
17
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
18
18
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
19
19
|
_toJS(_options?: ToJSOptions): unknown;
|
|
20
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
|
+
import { CborWriter } from '../cbor/encode';
|
|
3
4
|
/**
|
|
4
5
|
* CBOR Sequence Literal (§2.5.6) — `<<item, item, ...>>`.
|
|
5
6
|
*
|
|
@@ -15,7 +16,7 @@ export declare class CborEmbeddedCBOR extends CborItem {
|
|
|
15
16
|
constructor(items: CborItem[]);
|
|
16
17
|
/** The raw concatenated CBOR bytes of all contained items. */
|
|
17
18
|
private _content;
|
|
18
|
-
|
|
19
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
19
20
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
20
21
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
21
22
|
_toJS(_options?: ToJSOptions): unknown;
|
package/dist/ast/CborFloat.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
+
import { CborWriter } from '../cbor/encode';
|
|
3
4
|
export type FloatPrecision = 'half' | 'single' | 'double';
|
|
4
5
|
/**
|
|
5
6
|
* CBOR Major Type 7 — IEEE 754 floating-point number.
|
|
@@ -27,7 +28,7 @@ export declare class CborFloat extends CborItem {
|
|
|
27
28
|
constructor(value: number, options?: {
|
|
28
29
|
precision?: FloatPrecision;
|
|
29
30
|
});
|
|
30
|
-
|
|
31
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
31
32
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
32
33
|
_toJS(_options?: ToJSOptions): unknown;
|
|
33
34
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { CborByteString } from './CborByteString';
|
|
4
|
+
import { CborWriter } from '../cbor/encode';
|
|
4
5
|
/** CBOR Major Type 2 — indefinite-length byte string (chunked). */
|
|
5
6
|
export declare class CborIndefiniteByteString extends CborItem {
|
|
6
7
|
readonly indefiniteLength: true;
|
|
7
8
|
readonly chunks: CborByteString[];
|
|
8
9
|
constructor(chunks: CborByteString[]);
|
|
9
|
-
|
|
10
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
10
11
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
11
12
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
12
13
|
_toJS(_options?: ToJSOptions): unknown;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { CborTextString } from './CborTextString';
|
|
4
|
+
import { CborWriter } from '../cbor/encode';
|
|
4
5
|
/** CBOR Major Type 3 — indefinite-length UTF-8 text string (chunked). */
|
|
5
6
|
export declare class CborIndefiniteTextString extends CborItem {
|
|
6
7
|
readonly indefiniteLength: true;
|
|
7
8
|
readonly chunks: CborTextString[];
|
|
8
9
|
constructor(chunks: CborTextString[]);
|
|
9
|
-
|
|
10
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
10
11
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
11
12
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
12
13
|
_toJS(_options?: ToJSOptions): unknown;
|
package/dist/ast/CborItem.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComments, DecodeWarning, ParseWarning } from '../types';
|
|
2
|
+
import { CborWriter } from '../cbor/encode';
|
|
2
3
|
/** @internal One line of an annotated hex dump. */
|
|
3
4
|
export interface AnnotatedLine {
|
|
4
5
|
depth: number;
|
|
@@ -76,8 +77,34 @@ export declare abstract class CborItem {
|
|
|
76
77
|
* // FF -- "break"
|
|
77
78
|
*/
|
|
78
79
|
toHexDump(options?: ToHexDumpOptions): string;
|
|
79
|
-
/**
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
* Encode this node into `writer`, honoring `_toCBOR()` overrides.
|
|
83
|
+
*
|
|
84
|
+
* This is the entry point used by `toCBOR()` and by container nodes when
|
|
85
|
+
* recursing into children. A subclass that overrides `_toCBOR()` (e.g. to
|
|
86
|
+
* emit a pre-computed bit pattern) is authoritative even when one of its
|
|
87
|
+
* built-in base classes implements `_encodeTo()`.
|
|
88
|
+
*/
|
|
89
|
+
_encode(writer: CborWriter, options?: ToCBOROptions): void;
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
* Write this node's CBOR encoding into `writer`.
|
|
93
|
+
*
|
|
94
|
+
* Built-in nodes override this so that an entire encode pass shares one
|
|
95
|
+
* growing buffer (no per-node Uint8Array allocations or re-copies).
|
|
96
|
+
* Container implementations must recurse via `child._encode()`, never
|
|
97
|
+
* `child._encodeTo()`, so that `_toCBOR()` overrides are honored.
|
|
98
|
+
*/
|
|
99
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
* Subclass CBOR encoding implementation.
|
|
103
|
+
* The default builds the bytes via `_encodeTo()`; subclasses may instead
|
|
104
|
+
* override this method directly when producing a standalone byte array is
|
|
105
|
+
* more natural (e.g. emitting a pre-computed bit pattern).
|
|
106
|
+
*/
|
|
107
|
+
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
81
108
|
/**
|
|
82
109
|
* @internal
|
|
83
110
|
* Depth-aware CDN serialization.
|
package/dist/ast/CborMap.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 5 — map (definite- or indefinite-length). */
|
|
5
5
|
export declare class CborMap extends CborItem {
|
|
6
6
|
readonly entries: [CborItem, CborItem][];
|
|
@@ -10,7 +10,7 @@ export declare class CborMap extends CborItem {
|
|
|
10
10
|
indefiniteLength?: boolean;
|
|
11
11
|
encodingWidth?: EncodingWidth;
|
|
12
12
|
});
|
|
13
|
-
|
|
13
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
14
14
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
15
15
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
16
16
|
_toJS(options?: ToJSOptions): unknown;
|
package/dist/ast/CborNint.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/**
|
|
5
5
|
* CBOR Major Type 1 — negative integer (−2^64 … −1).
|
|
6
6
|
*
|
|
@@ -21,7 +21,7 @@ export declare class CborNint extends CborItem {
|
|
|
21
21
|
});
|
|
22
22
|
/** The actual decoded negative value (−1 − argument). */
|
|
23
23
|
get value(): bigint;
|
|
24
|
-
|
|
24
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
25
25
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
26
26
|
_toJS(options?: ToJSOptions): unknown;
|
|
27
27
|
}
|
package/dist/ast/CborSimple.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
+
import { CborWriter } from '../cbor/encode';
|
|
3
4
|
/**
|
|
4
5
|
* CBOR Major Type 7 — simple value (0–255).
|
|
5
6
|
*
|
|
@@ -16,7 +17,7 @@ export declare class CborSimple extends CborItem {
|
|
|
16
17
|
static readonly TRUE: CborSimple;
|
|
17
18
|
static readonly NULL: CborSimple;
|
|
18
19
|
static readonly UNDEFINED: CborSimple;
|
|
19
|
-
|
|
20
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
20
21
|
_toCDN(_options: ToCDNOptions | undefined, _depth: number): string;
|
|
21
22
|
_toJS(_options?: ToJSOptions): unknown;
|
|
22
23
|
}
|
package/dist/ast/CborTag.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 6 — tagged data item. */
|
|
5
5
|
export declare class CborTag extends CborItem {
|
|
6
6
|
readonly tag: bigint;
|
|
@@ -9,7 +9,7 @@ export declare class CborTag extends CborItem {
|
|
|
9
9
|
constructor(tag: number | bigint, content: CborItem, options?: {
|
|
10
10
|
encodingWidth?: EncodingWidth;
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
13
13
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
14
14
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
15
15
|
_toJS(options?: ToJSOptions): unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 3 — definite-length UTF-8 text string. */
|
|
5
5
|
export declare class CborTextString extends CborItem {
|
|
6
6
|
readonly indefiniteLength: false;
|
|
@@ -9,7 +9,7 @@ export declare class CborTextString extends CborItem {
|
|
|
9
9
|
constructor(value: string, options?: {
|
|
10
10
|
encodingWidth?: EncodingWidth;
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
13
13
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
14
14
|
_toJS(_options?: ToJSOptions): unknown;
|
|
15
15
|
}
|
package/dist/ast/CborUint.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
|
-
import { EncodingWidth } from '../cbor/encode';
|
|
3
|
+
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 0 — unsigned integer (0 … 2^64−1). */
|
|
5
5
|
export declare class CborUint extends CborItem {
|
|
6
6
|
readonly value: bigint;
|
|
@@ -8,7 +8,7 @@ export declare class CborUint extends CborItem {
|
|
|
8
8
|
constructor(value: number | bigint, options?: {
|
|
9
9
|
encodingWidth?: EncodingWidth;
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
12
12
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
13
13
|
_toJS(options?: ToJSOptions): unknown;
|
|
14
14
|
}
|
package/dist/ast/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-DZKHc3VY.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;
|
package/dist/ast/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
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-BMMPg2FB.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 };
|
package/dist/cbor/encode.d.ts
CHANGED
|
@@ -9,15 +9,49 @@ import { FloatPrecision } from '../ast/CborFloat';
|
|
|
9
9
|
*/
|
|
10
10
|
export type EncodingWidth = 'i' | 0 | 1 | 2 | 3;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Growable byte buffer used by the CBOR encoder.
|
|
13
|
+
*
|
|
14
|
+
* AST nodes write themselves into a single shared writer via `_encodeTo`,
|
|
15
|
+
* so an encode pass performs one buffer copy at the end instead of
|
|
16
|
+
* re-copying every child's bytes at each nesting level.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare class CborWriter {
|
|
21
|
+
private buf;
|
|
22
|
+
private len;
|
|
23
|
+
constructor(initialCapacity?: number);
|
|
24
|
+
private _ensure;
|
|
25
|
+
writeByte(b: number): void;
|
|
26
|
+
writeBytes(bytes: Uint8Array): void;
|
|
27
|
+
writeUint16(value: number): void;
|
|
28
|
+
writeUint32(value: number): void;
|
|
29
|
+
writeBigUint64(value: bigint): void;
|
|
30
|
+
writeFloat16(value: number): void;
|
|
31
|
+
writeFloat32(value: number): void;
|
|
32
|
+
writeFloat64(value: number): void;
|
|
33
|
+
/** Copy of the bytes written so far. */
|
|
34
|
+
finish(): Uint8Array;
|
|
35
|
+
}
|
|
36
|
+
/** Maximum CBOR argument value representable with the given encoding width. */
|
|
37
|
+
export declare function maxForEncodingWidth(ew: EncodingWidth): bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Write a CBOR initial byte + argument into `w`.
|
|
13
40
|
*
|
|
14
41
|
* When `encodingWidth` is provided the argument is always written using that
|
|
15
42
|
* many additional bytes (AI = 24 + encodingWidth), even if the value would fit
|
|
16
43
|
* in fewer bytes. Without it the smallest valid encoding is chosen.
|
|
44
|
+
*
|
|
45
|
+
* `value` may be a number (common for lengths and counts — avoids a BigInt
|
|
46
|
+
* allocation per head) or a bigint (required for full uint64 range).
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeHeadTo(w: CborWriter, mt: number, value: number | bigint, encodingWidth?: EncodingWidth): void;
|
|
49
|
+
/**
|
|
50
|
+
* Encode a CBOR initial byte + argument into a Uint8Array.
|
|
51
|
+
* Convenience wrapper around {@link writeHeadTo} for callers that need the
|
|
52
|
+
* bytes directly (e.g. hex dumps).
|
|
17
53
|
*/
|
|
18
|
-
export declare function writeHead(mt: number, value: bigint, encodingWidth?: EncodingWidth): Uint8Array;
|
|
19
|
-
/** Concatenate multiple Uint8Arrays into one. */
|
|
20
|
-
export declare function concat(parts: Uint8Array[]): Uint8Array;
|
|
54
|
+
export declare function writeHead(mt: number, value: number | bigint, encodingWidth?: EncodingWidth): Uint8Array;
|
|
21
55
|
/**
|
|
22
56
|
* Returns true if `value` can be exactly represented as a float16 without
|
|
23
57
|
* precision loss (including -0, Infinity, -Infinity, NaN identity).
|
package/dist/cdn/tokenizer.d.ts
CHANGED
|
@@ -174,6 +174,30 @@ export declare class Tokenizer {
|
|
|
174
174
|
private _readHexByteContentElisionAware;
|
|
175
175
|
private _readNext;
|
|
176
176
|
private _readNextCore;
|
|
177
|
+
/**
|
|
178
|
+
* Try to read `Infinity[_N]` immediately after a `+`/`-` sign at this.pos.
|
|
179
|
+
*
|
|
180
|
+
* Returns null when the input is not an Infinity literal (e.g. an identifier
|
|
181
|
+
* like `Infinityx` that merely starts with "Infinity"); the caller then
|
|
182
|
+
* falls back to its sign handling.
|
|
183
|
+
*
|
|
184
|
+
* All encoding-indicator suffixes _0–_7/_i are tokenized here; the parser
|
|
185
|
+
* validates them and rejects/warns on the invalid ones (_0, _4–_7, _i).
|
|
186
|
+
*
|
|
187
|
+
* Uses startsWith with a position argument instead of slicing the remainder
|
|
188
|
+
* of the input, which would allocate a substring for every sign token.
|
|
189
|
+
*/
|
|
190
|
+
private _readSignedInfinity;
|
|
191
|
+
/** Advance past a run of hex digits. Digits contain no newlines, so a
|
|
192
|
+
* plain column update is safe. */
|
|
193
|
+
private _skipHexDigits;
|
|
194
|
+
/** Advance past a run of decimal digits (same newline-free guarantee). */
|
|
195
|
+
private _skipDecimalDigits;
|
|
196
|
+
/**
|
|
197
|
+
* Consume a trailing _0–_7/_i encoding-indicator suffix when present and
|
|
198
|
+
* not followed by another identifier character.
|
|
199
|
+
*/
|
|
200
|
+
private _tryConsumeEncodingSuffix;
|
|
177
201
|
private _readNumber;
|
|
178
202
|
private _readIdent;
|
|
179
203
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./mapEntries-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./mapEntries-DZKHc3VY.cjs");function t(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
|
|
2
2
|
`||r===`\r`){n++;continue}if(r===`#`){for(;n<e.length&&e[n]!==`
|
|
3
3
|
`;)n++;continue}if(r===`/`){let t=e[n+1]??``;if(t===`/`){for(;n<e.length&&e[n]!==`
|
|
4
|
-
`;)n++;continue}if(t===`*`){for(n+=2;n<e.length&&!(e[n]===`*`&&(e[n+1]??``)===`/`);)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n+=2;continue}for(n++;n<e.length&&e[n]!==`/`;)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n++;continue}t+=r,n++}return t}var n=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,r=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function i(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===61;)t--;return e.slice(0,t)}function a(e,t,n){let r=i(e).toUpperCase(),a=r.length%8;if(a===1||a===3||a===6)throw SyntaxError(`invalid base32 length: ${r.length} characters`);let o=new Uint8Array(128).fill(255);for(let e=0;e<t.length;e++)o[t.charCodeAt(e)]=e;let s=new Uint8Array(Math.floor(r.length*5/8)),c=0,l=0,u=0;for(let e of r){let t=e.charCodeAt(0),n=t<128?o[t]:255;if(n===255)throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);c=c<<5|n,l+=5,l>=8&&(l-=8,s[u++]=c>>l&255)}if(l>0&&c&(1<<l)-1){let e=`non-zero trailing bits in base32 input`;if(n)n(e);else throw SyntaxError(e)}return s}var o={appStringPrefixes:[`b32`],parseAppString(r,i,o){return new e.g(a(t(i),n,o),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(n,i,o){return new e.g(a(t(i),r,o),{ednEncoding:`base32hex`})}},c=typeof Uint8Array.fromHex==`function`?e=>Uint8Array.fromHex(e):e=>{let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t},l=class extends e.v{_bits;constructor(t){super(e.
|
|
4
|
+
`;)n++;continue}if(t===`*`){for(n+=2;n<e.length&&!(e[n]===`*`&&(e[n+1]??``)===`/`);)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n+=2;continue}for(n++;n<e.length&&e[n]!==`/`;)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n++;continue}t+=r,n++}return t}var n=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,r=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function i(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===61;)t--;return e.slice(0,t)}function a(e,t,n){let r=i(e).toUpperCase(),a=r.length%8;if(a===1||a===3||a===6)throw SyntaxError(`invalid base32 length: ${r.length} characters`);let o=new Uint8Array(128).fill(255);for(let e=0;e<t.length;e++)o[t.charCodeAt(e)]=e;let s=new Uint8Array(Math.floor(r.length*5/8)),c=0,l=0,u=0;for(let e of r){let t=e.charCodeAt(0),n=t<128?o[t]:255;if(n===255)throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);c=c<<5|n,l+=5,l>=8&&(l-=8,s[u++]=c>>l&255)}if(l>0&&c&(1<<l)-1){let e=`non-zero trailing bits in base32 input`;if(n)n(e);else throw SyntaxError(e)}return s}var o={appStringPrefixes:[`b32`],parseAppString(r,i,o){return new e.g(a(t(i),n,o),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(n,i,o){return new e.g(a(t(i),r,o),{ednEncoding:`base32hex`})}},c=typeof Uint8Array.fromHex==`function`?e=>Uint8Array.fromHex(e):e=>{let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t},l=class extends e.v{_bits;constructor(t){super(e.S(t),{precision:`half`}),this._bits=t&65535}_toCBOR(){return new Uint8Array([249,this._bits>>8&255,this._bits&255])}},u=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat32(0,!1),{precision:`single`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(5);return e[0]=250,e.set(this._raw,1),e}},d=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat64(0,!1),{precision:`double`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(9);return e[0]=251,e.set(this._raw,1),e}};function f(e){if(e.length===2)return new l(e[0]<<8|e[1]);if(e.length===4)return new u(e);if(e.length===8)return new d(e);throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`)}var p={appStringPrefixes:[`float`],parseAppString(e,n){let r=t(n);if(!/^[0-9a-fA-F]*$/.test(r))throw SyntaxError(`float'...' contains non-hex characters`);if(r.length%2!=0)throw SyntaxError(`float'...' hex content has odd length (${r.length} digits)`);return f(c(r))},parseAppSequence(t,n,r){if(n.length===0)throw SyntaxError(`float<<...>> requires exactly one byte-string item`);if(n.length>1){let e=`float<<...>> expects 1 item; got ${n.length} — using first`;if(r)r(e);else throw SyntaxError(e)}if(!(n[0]instanceof e.g))throw SyntaxError(`float<<...>> item must be a byte string`);return f(n[0].value)}};function m(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var h={appStringPrefixes:[`same`],preserveAppSeqSource:!0,parseAppSequence(e,t,n){if(t.length===0)throw SyntaxError(`same<<...>> requires at least one item`);let r=t[0],i=r.toCBOR();for(let e=1;e<t.length;e++)if(!m(i,t[e].toCBOR())){let t=`same<<...>>: item ${e} produces different CBOR bytes than item 0`;if(n)n(t);else throw SyntaxError(t)}return r}},g=class t{static OMIT=e.w;static TAG=e.T;static Tag=e.D;static Simple=e.C;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromCDN(e,n){let r=t.fromCDN(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,n){return t.cborToCdn(e,this.#t(n))}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,n){return t.cdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromCDN(e,r).toJS(r)}let r=this.#t(n);return t.fromCDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=b(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromCDN(t,n){return e.s(t,n)}static fromEDN(e,n){return t.fromCDN(e,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,n){let r=[],i=_(t).trim().split(/\s+/).filter(Boolean);for(let e of i){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);r.push(parseInt(e,16))}return e.i(new Uint8Array(r),n)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.cborToCdn(e,n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.cdnToCbor(e,n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,a=b(r);if(i){let n=e.n(t,i);return n===void 0||n===e.w?void 0:e.r(n).toCDN(a===void 0?void 0:{indent:a})}return e.r(t).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.w)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return e.r(t,i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};function _(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=v(e,n+2),t+=` `;continue}if(r===`#`){n=v(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=v(e,n+2),t+=` `;continue}if(r===`/`&&i===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+2)),n=r+2;continue}if(r===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function v(e,t){let n=e.indexOf(`
|
|
5
5
|
`,t);return n<0?e.length:n}function y(e){return e.replace(/[^\r\n]/g,` `)}function b(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=g,exports.default=g,exports.CBOR_OMIT=e.w,exports.CBOR_TAG=e.T,exports.MapEntries=e.t,exports.Null=e.E,exports.Simple=e.C,exports.Tag=e.D,exports.Undefined=e.O,exports.b32=o,exports.dt_as_Date=e.a,exports.float=p,exports.h32=s,exports.same=h;
|
|
6
6
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as e, D as t, E as n, O as r,
|
|
1
|
+
import { C as e, D as t, E as n, O as r, S as i, T as a, a as o, g as s, i as c, n as l, r as u, s as d, t as f, v as p, w as m } from "./mapEntries-BMMPg2FB.js";
|
|
2
2
|
//#region src/utils/strip-comments.ts
|
|
3
3
|
function h(e) {
|
|
4
4
|
let t = "", n = 0;
|
|
@@ -62,21 +62,21 @@ function y(e, t, n) {
|
|
|
62
62
|
var b = {
|
|
63
63
|
appStringPrefixes: ["b32"],
|
|
64
64
|
parseAppString(e, t, n) {
|
|
65
|
-
return new
|
|
65
|
+
return new s(y(h(t), g, n), { ednEncoding: "base32" });
|
|
66
66
|
}
|
|
67
67
|
}, x = {
|
|
68
68
|
appStringPrefixes: ["h32"],
|
|
69
69
|
parseAppString(e, t, n) {
|
|
70
|
-
return new
|
|
70
|
+
return new s(y(h(t), _, n), { ednEncoding: "base32hex" });
|
|
71
71
|
}
|
|
72
72
|
}, S = typeof Uint8Array.fromHex == "function" ? (e) => Uint8Array.fromHex(e) : (e) => {
|
|
73
73
|
let t = new Uint8Array(e.length / 2);
|
|
74
74
|
for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.slice(n, n + 2), 16);
|
|
75
75
|
return t;
|
|
76
|
-
}, C = class extends
|
|
76
|
+
}, C = class extends p {
|
|
77
77
|
_bits;
|
|
78
78
|
constructor(e) {
|
|
79
|
-
super(
|
|
79
|
+
super(i(e), { precision: "half" }), this._bits = e & 65535;
|
|
80
80
|
}
|
|
81
81
|
_toCBOR() {
|
|
82
82
|
return new Uint8Array([
|
|
@@ -85,7 +85,7 @@ var b = {
|
|
|
85
85
|
this._bits & 255
|
|
86
86
|
]);
|
|
87
87
|
}
|
|
88
|
-
}, w = class extends
|
|
88
|
+
}, w = class extends p {
|
|
89
89
|
_raw;
|
|
90
90
|
constructor(e) {
|
|
91
91
|
super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
|
|
@@ -94,7 +94,7 @@ var b = {
|
|
|
94
94
|
let e = new Uint8Array(5);
|
|
95
95
|
return e[0] = 250, e.set(this._raw, 1), e;
|
|
96
96
|
}
|
|
97
|
-
}, T = class extends
|
|
97
|
+
}, T = class extends p {
|
|
98
98
|
_raw;
|
|
99
99
|
constructor(e) {
|
|
100
100
|
super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
|
|
@@ -125,7 +125,7 @@ var D = {
|
|
|
125
125
|
if (n) n(e);
|
|
126
126
|
else throw SyntaxError(e);
|
|
127
127
|
}
|
|
128
|
-
if (!(t[0] instanceof
|
|
128
|
+
if (!(t[0] instanceof s)) throw SyntaxError("float<<...>> item must be a byte string");
|
|
129
129
|
return E(t[0].value);
|
|
130
130
|
}
|
|
131
131
|
};
|
|
@@ -150,12 +150,12 @@ var k = {
|
|
|
150
150
|
return r;
|
|
151
151
|
}
|
|
152
152
|
}, A = class n {
|
|
153
|
-
static OMIT =
|
|
154
|
-
static TAG =
|
|
153
|
+
static OMIT = m;
|
|
154
|
+
static TAG = a;
|
|
155
155
|
static Tag = t;
|
|
156
156
|
static Simple = e;
|
|
157
|
-
static MapEntries =
|
|
158
|
-
static dt_as_Date =
|
|
157
|
+
static MapEntries = f;
|
|
158
|
+
static dt_as_Date = o;
|
|
159
159
|
#e;
|
|
160
160
|
constructor(e) {
|
|
161
161
|
this.#e = e ?? {};
|
|
@@ -222,16 +222,16 @@ var k = {
|
|
|
222
222
|
return n.format(e, this.#t(t));
|
|
223
223
|
}
|
|
224
224
|
static fromCBOR(e, t) {
|
|
225
|
-
return
|
|
225
|
+
return c(e, t);
|
|
226
226
|
}
|
|
227
227
|
static fromCDN(e, t) {
|
|
228
|
-
return
|
|
228
|
+
return d(e, t);
|
|
229
229
|
}
|
|
230
230
|
static fromEDN(e, t) {
|
|
231
231
|
return n.fromCDN(e, t);
|
|
232
232
|
}
|
|
233
233
|
static fromJS(e, t) {
|
|
234
|
-
return
|
|
234
|
+
return u(e, t);
|
|
235
235
|
}
|
|
236
236
|
static fromHexDump(e, t) {
|
|
237
237
|
let n = [], r = j(e).trim().split(/\s+/).filter(Boolean);
|
|
@@ -239,7 +239,7 @@ var k = {
|
|
|
239
239
|
if (!/^[0-9A-Fa-f]{2}$/.test(e)) throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
240
240
|
n.push(parseInt(e, 16));
|
|
241
241
|
}
|
|
242
|
-
return
|
|
242
|
+
return c(new Uint8Array(n), t);
|
|
243
243
|
}
|
|
244
244
|
static decode(e, t) {
|
|
245
245
|
return n.fromCBOR(e, t).toJS(t);
|
|
@@ -266,19 +266,19 @@ var k = {
|
|
|
266
266
|
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
267
267
|
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i = P(n);
|
|
268
268
|
if (r) {
|
|
269
|
-
let t =
|
|
270
|
-
return t === void 0 || t ===
|
|
269
|
+
let t = l(e, r);
|
|
270
|
+
return t === void 0 || t === m ? void 0 : u(t).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
271
271
|
}
|
|
272
|
-
return
|
|
272
|
+
return u(e).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
273
273
|
}
|
|
274
274
|
let r = t;
|
|
275
275
|
if (r?.replacer) {
|
|
276
|
-
let t =
|
|
277
|
-
if (t === void 0 || t ===
|
|
276
|
+
let t = l(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
277
|
+
if (t === void 0 || t === m) return;
|
|
278
278
|
let { replacer: n, ...i } = r;
|
|
279
|
-
return
|
|
279
|
+
return u(t, Object.keys(i).length > 0 ? i : void 0).toCDN(r);
|
|
280
280
|
}
|
|
281
|
-
return
|
|
281
|
+
return u(e, r).toCDN(r);
|
|
282
282
|
}
|
|
283
283
|
static format(e, t) {
|
|
284
284
|
return n.fromCDN(e, t).toCDN(t);
|
|
@@ -331,6 +331,6 @@ function P(e) {
|
|
|
331
331
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
332
332
|
}
|
|
333
333
|
//#endregion
|
|
334
|
-
export { A as CBOR, A as default,
|
|
334
|
+
export { A as CBOR, A as default, m as CBOR_OMIT, a as CBOR_TAG, f as MapEntries, n as Null, e as Simple, t as Tag, r as Undefined, b as b32, o as dt_as_Date, D as float, x as h32, k as same };
|
|
335
335
|
|
|
336
336
|
//# sourceMappingURL=index.js.map
|