@cbortech/cbor 0.26.3 → 0.26.4
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/README.ja.md +29 -0
- package/README.md +31 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor.d.ts +31 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +58 -2
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-CV9kf2OS.cjs → mapEntries-DDJxbotH.cjs} +3 -3
- package/dist/mapEntries-DDJxbotH.cjs.map +1 -0
- package/dist/{mapEntries-BZCOgqIt.js → mapEntries-hyNVtz5Z.js} +15 -6
- package/dist/mapEntries-hyNVtz5Z.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/package.json +1 -1
- package/dist/mapEntries-BZCOgqIt.js.map +0 -1
- package/dist/mapEntries-CV9kf2OS.cjs.map +0 -1
package/README.ja.md
CHANGED
|
@@ -346,6 +346,35 @@ CBOR.format("h'68' + b64'aQ'", {
|
|
|
346
346
|
// "h'68' + b64'aQ'"
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
+
### CBOR / CDN / hex dump のバリデーション
|
|
350
|
+
|
|
351
|
+
`validate` は入力の well-formedness と validity を、例外を投げずにチェックします。
|
|
352
|
+
重複したマップキーなど回復可能な違反は例外にせず `warnings` に集約され、真に不正な
|
|
353
|
+
データのみ `error` として報告されます(CDN の構文エラーの場合は位置情報を保持した
|
|
354
|
+
`CdnSyntaxError`)。未登録のオプション拡張に一致する app-string prefix などの
|
|
355
|
+
情報ヒントは `valid` に影響せず、`hints` に分けて集約されます。`type` で入力形式を
|
|
356
|
+
指定します: `'cbor'`(デフォルト)、`'cdn'`、`'hex'`。
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import { CBOR } from '@cbortech/cbor';
|
|
360
|
+
|
|
361
|
+
// CBOR バイト列 — キー "a" の重複は回復可能な違反
|
|
362
|
+
CBOR.validate(new Uint8Array([0xa2, 0x61, 0x61, 0x01, 0x61, 0x61, 0x02]), {
|
|
363
|
+
type: 'cbor',
|
|
364
|
+
});
|
|
365
|
+
// { valid: false, count: 1, warnings: [{ message: 'duplicate map key at offset 4', offset: 4 }], hints: [] }
|
|
366
|
+
|
|
367
|
+
// CDN テキスト — well-formed な入力
|
|
368
|
+
CBOR.validate('{"a": 1}', { type: 'cdn' });
|
|
369
|
+
// { valid: true, count: 1, warnings: [], hints: [] }
|
|
370
|
+
|
|
371
|
+
// アノテーション付き hex dump テキスト — 長さ3の配列なのに要素が2つしかない
|
|
372
|
+
CBOR.validate('83 -- Array of length 3\n 01 -- 1\n 02 -- 2', {
|
|
373
|
+
type: 'hex',
|
|
374
|
+
});
|
|
375
|
+
// { valid: false, count: 0, warnings: [], hints: [], error: Error(...) }
|
|
376
|
+
```
|
|
377
|
+
|
|
349
378
|
## AST を扱う
|
|
350
379
|
|
|
351
380
|
`CBOR.fromCBOR()`、`CBOR.fromCDN()`、`CBOR.fromJS()` は CBOR item を返します。
|
package/README.md
CHANGED
|
@@ -351,6 +351,37 @@ CBOR.format("h'68' + b64'aQ'", {
|
|
|
351
351
|
// "h'68' + b64'aQ'"
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
+
### Validate CBOR / CDN / hex dump
|
|
355
|
+
|
|
356
|
+
`validate` checks input for well-formedness and validity without throwing.
|
|
357
|
+
Recoverable violations (e.g. duplicate map keys) are collected into
|
|
358
|
+
`warnings` instead of stopping decoding; truly malformed data is reported via
|
|
359
|
+
`error` instead (for CDN syntax errors, a `CdnSyntaxError` with its position
|
|
360
|
+
fields intact). Informational hints — e.g. an app-string prefix that matches
|
|
361
|
+
a known optional extension which isn't registered — never affect `valid` and
|
|
362
|
+
are collected separately into `hints`. `type` selects the input format:
|
|
363
|
+
`'cbor'` (default), `'cdn'`, or `'hex'`.
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
import { CBOR } from '@cbortech/cbor';
|
|
367
|
+
|
|
368
|
+
// CBOR bytes — duplicate map key "a" is a recoverable violation
|
|
369
|
+
CBOR.validate(new Uint8Array([0xa2, 0x61, 0x61, 0x01, 0x61, 0x61, 0x02]), {
|
|
370
|
+
type: 'cbor',
|
|
371
|
+
});
|
|
372
|
+
// { valid: false, count: 1, warnings: [{ message: 'duplicate map key at offset 4', offset: 4 }], hints: [] }
|
|
373
|
+
|
|
374
|
+
// CDN text — well-formed input
|
|
375
|
+
CBOR.validate('{"a": 1}', { type: 'cdn' });
|
|
376
|
+
// { valid: true, count: 1, warnings: [], hints: [] }
|
|
377
|
+
|
|
378
|
+
// Annotated hex dump text — truncated array (length 3, only 2 elements present)
|
|
379
|
+
CBOR.validate('83 -- Array of length 3\n 01 -- 1\n 02 -- 2', {
|
|
380
|
+
type: 'hex',
|
|
381
|
+
});
|
|
382
|
+
// { valid: false, count: 0, warnings: [], hints: [], error: Error(...) }
|
|
383
|
+
```
|
|
384
|
+
|
|
354
385
|
## Working With The AST
|
|
355
386
|
|
|
356
387
|
`CBOR.fromCBOR()`, `CBOR.fromCDN()`, and `CBOR.fromJS()` return a CBOR item.
|
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-DDJxbotH.cjs");exports.CborArray=e.C,exports.CborBigNint=e.v,exports.CborBigUint=e.y,exports.CborByteString=e.E,exports.CborEmbeddedCBOR=e.b,exports.CborFloat=e.O,exports.CborIndefiniteByteString=e.T,exports.CborIndefiniteTextString=e.w,exports.CborItem=e.j,exports.CborMap=e.S,exports.CborNint=e.k,exports.CborSimple=e.x,exports.CborTag=e.D,exports.CborTextString=e.g,exports.CborUint=e.A;
|
package/dist/ast/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as e, C as t, D as n, E as r, O as i, S as a, T as o, b as s, g as c, j as l, k as u, v as d, w as f, x as p, y as m } from "../mapEntries-
|
|
1
|
+
import { A as e, C as t, D as n, E as r, O as i, S as a, T as o, b as s, g as c, j as l, k as u, v as d, w as f, x as p, y as m } from "../mapEntries-hyNVtz5Z.js";
|
|
2
2
|
export { t as CborArray, d as CborBigNint, m as CborBigUint, r as CborByteString, s as CborEmbeddedCBOR, i as CborFloat, o as CborIndefiniteByteString, f as CborIndefiniteTextString, l as CborItem, a as CborMap, u as CborNint, p as CborSimple, n as CborTag, c as CborTextString, e as CborUint };
|
package/dist/cbor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CborItem } from './ast/CborItem';
|
|
2
|
-
import { CBOROptions, FromCBOROptions, FromCBORSeqOptions, FromCDNOptions, FromCDNSeqOptions, FromHexDumpOptions, FromJSOptions, ToCBOROptions, ToCDNOptions, ToHexDumpOptions, ToJSOptions, CBOR_OMIT } from './types';
|
|
2
|
+
import { CBOROptions, FromCBOROptions, FromCBORSeqOptions, FromCDNOptions, FromCDNSeqOptions, FromHexDumpOptions, FromJSOptions, ToCBOROptions, ToCDNOptions, ToHexDumpOptions, ToJSOptions, ValidateOptions, ValidateResult, CBOR_OMIT } from './types';
|
|
3
3
|
import { dt_as_Date as _dt_as_Date } from './extensions/dt';
|
|
4
4
|
import { MapEntries as _MapEntries } from './mapEntries';
|
|
5
5
|
import { Simple as _Simple } from './simple';
|
|
@@ -69,6 +69,11 @@ export declare class CBOR {
|
|
|
69
69
|
decompile(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToCDNOptions): string;
|
|
70
70
|
toHex(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToHexDumpOptions): string;
|
|
71
71
|
fromHex(text: string, options?: FromHexDumpOptions & ToCBOROptions): Uint8Array;
|
|
72
|
+
/**
|
|
73
|
+
* Check CBOR / CDN / hex dump input for well-formedness and validity,
|
|
74
|
+
* without throwing.
|
|
75
|
+
*/
|
|
76
|
+
validate(input: ArrayBufferView | ArrayBufferLike | string, options?: ValidateOptions): ValidateResult;
|
|
72
77
|
/** @deprecated Use `decompile()` instead. */
|
|
73
78
|
cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
74
79
|
/** @deprecated Use `decompile()` instead. */
|
|
@@ -149,6 +154,31 @@ export declare class CBOR {
|
|
|
149
154
|
* Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.
|
|
150
155
|
*/
|
|
151
156
|
static fromHex(text: string, options?: FromHexDumpOptions & ToCBOROptions): Uint8Array;
|
|
157
|
+
/**
|
|
158
|
+
* Check CBOR / CDN / hex dump input for well-formedness and validity,
|
|
159
|
+
* without throwing.
|
|
160
|
+
*
|
|
161
|
+
* Decodes/parses the input as a sequence (CBOR Sequence per RFC 8742, or a
|
|
162
|
+
* CDN Sequence) in non-strict mode: recoverable violations are collected
|
|
163
|
+
* into `warnings` instead of stopping decoding, while malformed input
|
|
164
|
+
* (e.g. truncated data, hard syntax errors — including a CDN Sequence
|
|
165
|
+
* abandoned after a hard syntax error) is reported via `error`.
|
|
166
|
+
* Informational hints about optional extensions that aren't registered
|
|
167
|
+
* (`ParseWarning.hint`) are not treated as violations; they are collected
|
|
168
|
+
* separately into `hints`.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const result = CBOR.validate(bytes);
|
|
172
|
+
* if (!result.valid) {
|
|
173
|
+
* if (result.error) console.error(`invalid: ${result.error.message}`);
|
|
174
|
+
* for (const w of result.warnings) console.warn(w.message);
|
|
175
|
+
* }
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* // CDN text input
|
|
179
|
+
* CBOR.validate('{"a": 1}', { type: 'cdn' });
|
|
180
|
+
*/
|
|
181
|
+
static validate(input: ArrayBufferView | ArrayBufferLike | string, options?: ValidateOptions): ValidateResult;
|
|
152
182
|
/**
|
|
153
183
|
* Convert CBOR binary data directly to a CDN text string.
|
|
154
184
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-EciPlN0n.cjs"),t=require("./mapEntries-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-EciPlN0n.cjs"),t=require("./mapEntries-DDJxbotH.cjs");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(e,r,i){return new t.E(a(t.o(r),n,i),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(e,n,i){return new t.E(a(t.o(n),r,i),{ednEncoding:`base32hex`})}};function c(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 l={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(!c(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}},u=class n{static OMIT=t.N;static TAG=t.P;static Tag=t.I;static Simple=t.M;static MapEntries=t.t;static dt_as_Date=t.h;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,t){let r=n.fromCBOR(e,this.#t(t));return r._defaults=this.#e,r}fromCDN(e,t){let r=n.fromCDN(e,this.#t(t));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,t){let r=n.fromJS(e,this.#t(t));return r._defaults=this.#e,r}fromHexDump(e,t){let r=n.fromHexDump(e,this.#t(t));return r._defaults=this.#e,r}*fromCBORSeq(e,t){for(let r of n.fromCBORSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromCDNSeq(e,t){for(let r of n.fromCDNSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,t){for(let r of n.fromHexDumpSeq(e,this.#t(t)))r._defaults=this.#e,yield r}decode(e,t){return n.decode(e,this.#t(t))}*decodeSeq(e,t){yield*n.decodeSeq(e,this.#t(t))}*parseSeq(e,t){yield*n.parseSeq(e,this.#t(t))}encode(e,t){return n.encode(e,this.#t(t))}compile(e,t){return n.compile(e,this.#t(t))}decompile(e,t){return n.decompile(e,this.#t(t))}toHex(e,t){return n.toHex(e,this.#t(t))}fromHex(e,t){return n.fromHex(e,this.#t(t))}validate(e,t){return n.validate(e,this.#t(t))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,t){let r=this.#t(t),i=n.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,t){let r=this.#t(t);return n.fromCDN(e,r).toCBOR(r)}parse(e,t){if(typeof t==`function`){let r=this.#t({reviver:t});return n.fromCDN(e,r).toJS(r)}let r=this.#t(t);return n.fromCDN(e,r).toJS(r)}stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i={...this.#e};return t===null?i.replacer=void 0:(typeof t==`function`||Array.isArray(t))&&(i.replacer=t),r!==void 0&&(i.indent=_(r)),n.stringify(e,i)}return n.stringify(e,this.#t(t??void 0))}format(e,t){return n.format(e,this.#t(t))}static fromCBOR(e,n){return t.d(e,n)}static fromCDN(e,n){return t._(e,n)}static fromEDN(e,t){return n.fromCDN(e,t)}static*fromHexDumpSeq(e,t){let r=[],i=d(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);yield*n.fromCBORSeq(new Uint8Array(r),t)}static*fromCBORSeq(e,n){let r=e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i=0;for(;i<r.byteLength;){let e=t.d(r,{...n,offset:i,allowTrailing:!0});yield e,i=e.end}}static*fromCDNSeq(n,r){let i=!!r?.preserveComments,a=0,o=!0;for(;;){let{offset:s,hadSeparator:c,commaOffset:l}=g(n,a,r,i?o?`all`:`after-newline`:`none`);if(o&&l>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);m(e,l,r)}if(s>=n.length||i&&h(n,s)&&g(n,s,r).offset>=n.length)break;if(!o&&!c){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);m(e,s,r)}a=s;let u;try{u=t._(n,{...r,offset:a,allowTrailing:!0,_skipRS:!0})}catch(t){if(r?.strict!==!1)throw t;m(t instanceof Error?t.message:String(t),a,r,!0,t instanceof e.o?t:void 0);break}yield u,a=u.end,o=!1}}static fromJS(e,n){return t.r(e,n)}static fromHexDump(e,n){let r=[],i=d(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);return t.d(new Uint8Array(r),n)}static decode(e,t){return n.fromCBOR(e,t).toJS(t)}static*decodeSeq(e,t){for(let r of n.fromCBORSeq(e,t))yield r.toJS(t)}static*parseSeq(e,t){for(let r of n.fromCDNSeq(e,t))yield r.toJS(t)}static encode(e,t){return n.fromJS(e,t).toCBOR(t)}static compile(e,t){let r=[...n.fromCDNSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static decompile(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toCDN(t)).join(`
|
|
2
2
|
`)}static toHex(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toHexDump(t)).join(`
|
|
3
|
-
`)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,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=_(r);if(i){let n=t.n(e,i);return n===void 0||n===t.N?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(n===void 0||n===t.N)return;let{replacer:r,...a}=i;return t.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return t.r(e,i).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function d(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=f(e,n+2),t+=` `;continue}if(r===`—`){n=f(e,n+1),t+=` `;continue}if(r===`#`){n=f(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=f(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+=p(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+=p(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function f(e,t){let n=e.indexOf(`
|
|
4
|
-
`,t);return n<0?e.length:n}function p(e){return e.replace(/[^\r\n]/g,` `)}function m(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function h(e,t){let n=e[t];return n===`#`||n===`/`}function g(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
|
|
3
|
+
`)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static validate(t,r){let i=[],a=[],o,s={strict:!1,extensions:r?.extensions,builtinExtensions:r?.builtinExtensions,onWarning:e=>{if(`hint`in e&&e.hint){a.push(e);return}if(`fatal`in e&&e.fatal){o=e;return}i.push(e)}},c=0;try{let e=r?.type??`cbor`;if(e===`cdn`){let e={...s,unresolvedExtension:r?.unresolvedExtension};for(let r of n.fromCDNSeq(t,e))c++}else if(e===`hex`)for(let e of n.fromHexDumpSeq(t,s))c++;else for(let e of n.fromCBORSeq(t,s))c++}catch(e){return{valid:!1,count:c,warnings:i,hints:a,error:e instanceof Error?e:Error(String(e))}}if(o){let t=o.cause instanceof Error?o.cause:new e.o(o.message,{offset:o.offset});return{valid:!1,count:c,warnings:i,hints:a,error:t}}return{valid:i.length===0,count:c,warnings:i,hints:a}}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,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=_(r);if(i){let n=t.n(e,i);return n===void 0||n===t.N?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(n===void 0||n===t.N)return;let{replacer:r,...a}=i;return t.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return t.r(e,i).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function d(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=f(e,n+2),t+=` `;continue}if(r===`—`){n=f(e,n+1),t+=` `;continue}if(r===`#`){n=f(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=f(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+=p(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+=p(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function f(e,t){let n=e.indexOf(`
|
|
4
|
+
`,t);return n<0?e.length:n}function p(e){return e.replace(/[^\r\n]/g,` `)}function m(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i&&(o.cause=i),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function h(e,t){let n=e[t];return n===`#`||n===`/`}function g(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
|
|
5
5
|
`){a=!0,s=!0,i++;continue}if(t===`#`){if(a=!0,l())break;let t=e.indexOf(`
|
|
6
6
|
`,i+1);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`/`){if(a=!0,l())break;let t=e.indexOf(`
|
|
7
7
|
`,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);m(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/extensions/b32.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCBORSeqOptions,\n FromCDNOptions,\n FromCDNSeqOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ParseWarning,\n ToCBOROptions,\n ToCDNOptions,\n ToHexDumpOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { CdnSyntaxError } from './cdn/errors';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromCBORSeq(input, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem> {\n for (const item of CBOR.fromCDNSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromHexDumpSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.decodeSeq(input, this.#merge(options));\n }\n\n *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.parseSeq(text, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.compile(text, this.#merge(options));\n }\n\n decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return CBOR.decompile(input, this.#merge(options));\n }\n\n toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return CBOR.toHex(input, this.#merge(options));\n }\n\n fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromHex(text, this.#merge(options));\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n const merged = this.#merge(options);\n const node = CBOR.fromCBOR(input, merged);\n node._defaults = this.#defaults;\n return node.toCDN(merged);\n }\n\n /** @deprecated Use `compile()` instead. */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n /** @deprecated Use `compile()` instead. */\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n const merged = this.#merge(options);\n return CBOR.fromCDN(text, merged).toCBOR(merged);\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** アノテーション付き hex dump テキストから CBOR Sequence を item ごとにデコードするジェネレータ。 */\n static *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n yield* CBOR.fromCBORSeq(new Uint8Array(bytes), options);\n }\n\n /** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */\n static *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n const bytes =\n input instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== 'undefined' &&\n input instanceof SharedArrayBuffer)\n ? new Uint8Array(input)\n : new Uint8Array(\n (input as ArrayBufferView).buffer,\n (input as ArrayBufferView).byteOffset,\n (input as ArrayBufferView).byteLength\n );\n let offset = 0;\n while (offset < bytes.byteLength) {\n const item = decodeCBOR(bytes, {\n ...options,\n offset,\n allowTrailing: true,\n });\n yield item;\n offset = item.end!;\n }\n }\n\n /**\n * CDN テキストの複数 item を 1 つずつパースするジェネレータ。\n *\n * `preserveComments` が有効な場合、item 間のコメントは次の item の\n * leading コメントとして、item と同じ行にあるコメントはその item の\n * trailing コメントとして付与される。最後の item の後の行にだけ\n * コメントが残る場合、そのコメントはどの item にも属さず破棄される。\n */\n static *fromCDNSeq(\n text: string,\n options?: FromCDNSeqOptions\n ): Generator<CborItem> {\n const preserve = !!options?.preserveComments;\n let offset = 0;\n let isFirst = true;\n while (true) {\n const {\n offset: next,\n hadSeparator,\n commaOffset,\n } = skipCDNSeparator(\n text,\n offset,\n options,\n preserve ? (isFirst ? 'all' : 'after-newline') : 'none'\n );\n // Leading comma: comma before the first item (including comma-only input).\n // Checked before the EOF break so that \",\" alone is also caught.\n // Trailing comma is valid per ABNF SOC = S [\",\" S] and is silently accepted.\n if (isFirst && commaOffset >= 0) {\n const msg = 'leading comma in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, commaOffset, options);\n }\n if (next >= text.length) break;\n // Stopped at a comment that should lead the next item: make sure an\n // item actually follows. If only comments remain, we are done (the\n // remaining comments belong to no item and are dropped, matching the\n // behaviour of `preserveComments: false`).\n if (preserve && isCDNCommentStart(text, next)) {\n const lookahead = skipCDNSeparator(text, next, options);\n if (lookahead.offset >= text.length) break;\n }\n if (!isFirst && !hadSeparator) {\n const msg =\n 'CDN sequence items must be separated by whitespace, comma, or comment';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, next, options);\n }\n offset = next;\n let item: CborItem;\n try {\n // _skipRS: true causes the tokenizer to treat RS (U+001E, RFC 7464) as\n // whitespace, preventing it from corrupting string-literal contents via\n // a global text replacement.\n item = parseCDN(text, {\n ...options,\n offset,\n allowTrailing: true,\n _skipRS: true,\n } as FromCDNOptions);\n } catch (e) {\n if (options?.strict !== false) throw e;\n emitCDNSeqWarning(\n e instanceof Error ? e.message : String(e),\n offset,\n options,\n true,\n e instanceof CdnSyntaxError ? e : undefined\n );\n break;\n }\n yield item;\n offset = item.end!;\n isFirst = false;\n }\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Decode a CBOR Sequence (RFC 8742), yielding each item as a JavaScript value. */\n static *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCBORSeq(input, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Parse a CDN Sequence text string, yielding each item as a JavaScript value. */\n static *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCDNSeq(text, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Compile a CDN text string to CBOR binary data.\n * Multi-item CDN Sequences produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromCDNSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Decompile CBOR binary data to a CDN text string.\n * CBOR Sequences (RFC 8742) produce multi-item CDN output, with items separated by newlines.\n */\n static decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toCDN(options))\n .join('\\n');\n }\n\n /**\n * Convert CBOR binary data to an annotated hex dump string.\n * CBOR Sequences (RFC 8742) produce one dump per item, separated by newlines.\n */\n static toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toHexDump(options))\n .join('\\n');\n }\n\n /**\n * Parse an annotated hex dump string to CBOR binary data.\n * Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromHexDumpSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.decompile()` instead.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /** @deprecated Use `CBOR.decompile()` instead. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.compile()` instead.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /** @deprecated Use `CBOR.compile()` instead. */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits,\n opts.builtinExtensions\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\nfunction emitCDNSeqWarning(\n msg: string,\n fallbackOffset: number,\n options: FromCDNSeqOptions | undefined,\n fatal?: boolean,\n cause?: CdnSyntaxError\n): void {\n const offset = cause?.offset ?? fallbackOffset;\n const w: ParseWarning = { message: msg, offset };\n if (fatal) w.fatal = true;\n if (cause?.offset !== undefined) {\n w.line = cause.line;\n w.column = cause.column;\n w.endOffset = cause.endOffset;\n }\n if (options?.onWarning) options.onWarning(w);\n else if (!options?.silent)\n console.warn(`CDN sequence warning at offset ${offset}: ${msg}`);\n}\n\n/** Whether `text[i]` starts a CDN comment (`#`, `//`, `/* … *\\/`, or `/ … /`). */\nfunction isCDNCommentStart(text: string, i: number): boolean {\n const ch = text[i];\n return ch === '#' || ch === '/';\n}\n\n/**\n * CDN sequence の item 間にある空白・コメント・省略可能なカンマを読み飛ばし、\n * 次の item が始まる文字位置と、何らかの separator が存在したかどうかを返す。\n * 未終端のブロックコメントは strict モードでは throw し、\n * strict: false の場合は警告を emit して末尾まで読み飛ばす。\n *\n * `stopAtComments` は `preserveComments` 有効時にコメントを次の item の\n * leading コメントとして残すためのモード:\n * - `'none'`: コメントも読み飛ばす(従来動作)\n * - `'all'`: 最初のコメントで停止する(先頭 item 用)\n * - `'after-newline'`: 改行より後のコメントで停止する。直前 item と同じ行の\n * コメントはその item の trailing コメントとして既に付与されているため読み飛ばす。\n */\nfunction skipCDNSeparator(\n text: string,\n from: number,\n options: FromCDNSeqOptions | undefined,\n stopAtComments: 'none' | 'after-newline' | 'all' = 'none'\n): { offset: number; hadSeparator: boolean; commaOffset: number } {\n let i = from;\n let hadSeparator = false;\n let seenComma = false;\n let seenNewline = false;\n let commaOffset = -1;\n const stopHere = (): boolean =>\n stopAtComments === 'all' ||\n (stopAtComments === 'after-newline' && seenNewline);\n while (i < text.length) {\n const ch = text[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\r' || ch === '\\x1e') {\n hadSeparator = true;\n i++;\n continue;\n }\n if (ch === '\\n') {\n hadSeparator = true;\n seenNewline = true;\n i++;\n continue;\n }\n if (ch === '#') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 1);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 2);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '*') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('*/', i + 2);\n if (end < 0) {\n const msg = 'unterminated /* comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 2;\n }\n continue;\n }\n if (ch === '/' && text[i + 1] !== '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('/', i + 1);\n if (end < 0) {\n const msg = 'unterminated / comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 1;\n }\n continue;\n }\n if (ch === ',' && !seenComma) {\n hadSeparator = true;\n seenComma = true;\n commaOffset = i;\n i++;\n continue;\n }\n break;\n }\n return { offset: i, hadSeparator, commaOffset };\n}\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":"kLAIA,IAAM,EAAY,mCACZ,EAAY,mCAElB,SAAS,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MAChB,IAAM,EAAM,EAAK,QAAQ,IAAK,EAAI,CAAC,EACnC,GAAI,EAAM,EAAG,CACX,IAAM,EAAM,yCACZ,GAAI,GAAS,SAAW,GAAO,MAAU,YAAY,CAAG,EACxD,EAAkB,EAAK,EAAG,EAAS,EAAI,EACvC,EAAI,EAAK,MACX,MACM,EAAK,MAAM,EAAG,CAAG,CAAC,CAAC,SAAS;CAAI,IAAG,EAAc,IACrD,EAAI,EAAM,EAEZ,QACF,CACA,GAAI,IAAO,KAAO,CAAC,EAAW,CAC5B,EAAe,GACf,EAAY,GACZ,EAAc,EACd,IACA,QACF,CACA,KACF,CACA,MAAO,CAAE,OAAQ,EAAG,eAAc,aAAY,CAChD,CAGA,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAK,CAAC,CAAC,EACrD,OAAO,IAAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/extensions/b32.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n DecodeWarning,\n FromCBOROptions,\n FromCBORSeqOptions,\n FromCDNOptions,\n FromCDNSeqOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ParseWarning,\n ToCBOROptions,\n ToCDNOptions,\n ToHexDumpOptions,\n ToJSOptions,\n ValidateOptions,\n ValidateResult,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { CdnSyntaxError } from './cdn/errors';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromCBORSeq(input, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem> {\n for (const item of CBOR.fromCDNSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromHexDumpSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.decodeSeq(input, this.#merge(options));\n }\n\n *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.parseSeq(text, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.compile(text, this.#merge(options));\n }\n\n decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return CBOR.decompile(input, this.#merge(options));\n }\n\n toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return CBOR.toHex(input, this.#merge(options));\n }\n\n fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromHex(text, this.#merge(options));\n }\n\n /**\n * Check CBOR / CDN / hex dump input for well-formedness and validity,\n * without throwing.\n */\n validate(\n input: ArrayBufferView | ArrayBufferLike | string,\n options?: ValidateOptions\n ): ValidateResult {\n return CBOR.validate(input, this.#merge(options));\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n const merged = this.#merge(options);\n const node = CBOR.fromCBOR(input, merged);\n node._defaults = this.#defaults;\n return node.toCDN(merged);\n }\n\n /** @deprecated Use `compile()` instead. */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n /** @deprecated Use `compile()` instead. */\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n const merged = this.#merge(options);\n return CBOR.fromCDN(text, merged).toCBOR(merged);\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** アノテーション付き hex dump テキストから CBOR Sequence を item ごとにデコードするジェネレータ。 */\n static *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n yield* CBOR.fromCBORSeq(new Uint8Array(bytes), options);\n }\n\n /** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */\n static *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n const bytes =\n input instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== 'undefined' &&\n input instanceof SharedArrayBuffer)\n ? new Uint8Array(input)\n : new Uint8Array(\n (input as ArrayBufferView).buffer,\n (input as ArrayBufferView).byteOffset,\n (input as ArrayBufferView).byteLength\n );\n let offset = 0;\n while (offset < bytes.byteLength) {\n const item = decodeCBOR(bytes, {\n ...options,\n offset,\n allowTrailing: true,\n });\n yield item;\n offset = item.end!;\n }\n }\n\n /**\n * CDN テキストの複数 item を 1 つずつパースするジェネレータ。\n *\n * `preserveComments` が有効な場合、item 間のコメントは次の item の\n * leading コメントとして、item と同じ行にあるコメントはその item の\n * trailing コメントとして付与される。最後の item の後の行にだけ\n * コメントが残る場合、そのコメントはどの item にも属さず破棄される。\n */\n static *fromCDNSeq(\n text: string,\n options?: FromCDNSeqOptions\n ): Generator<CborItem> {\n const preserve = !!options?.preserveComments;\n let offset = 0;\n let isFirst = true;\n while (true) {\n const {\n offset: next,\n hadSeparator,\n commaOffset,\n } = skipCDNSeparator(\n text,\n offset,\n options,\n preserve ? (isFirst ? 'all' : 'after-newline') : 'none'\n );\n // Leading comma: comma before the first item (including comma-only input).\n // Checked before the EOF break so that \",\" alone is also caught.\n // Trailing comma is valid per ABNF SOC = S [\",\" S] and is silently accepted.\n if (isFirst && commaOffset >= 0) {\n const msg = 'leading comma in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, commaOffset, options);\n }\n if (next >= text.length) break;\n // Stopped at a comment that should lead the next item: make sure an\n // item actually follows. If only comments remain, we are done (the\n // remaining comments belong to no item and are dropped, matching the\n // behaviour of `preserveComments: false`).\n if (preserve && isCDNCommentStart(text, next)) {\n const lookahead = skipCDNSeparator(text, next, options);\n if (lookahead.offset >= text.length) break;\n }\n if (!isFirst && !hadSeparator) {\n const msg =\n 'CDN sequence items must be separated by whitespace, comma, or comment';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, next, options);\n }\n offset = next;\n let item: CborItem;\n try {\n // _skipRS: true causes the tokenizer to treat RS (U+001E, RFC 7464) as\n // whitespace, preventing it from corrupting string-literal contents via\n // a global text replacement.\n item = parseCDN(text, {\n ...options,\n offset,\n allowTrailing: true,\n _skipRS: true,\n } as FromCDNOptions);\n } catch (e) {\n if (options?.strict !== false) throw e;\n emitCDNSeqWarning(\n e instanceof Error ? e.message : String(e),\n offset,\n options,\n true,\n e instanceof CdnSyntaxError ? e : undefined\n );\n break;\n }\n yield item;\n offset = item.end!;\n isFirst = false;\n }\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Decode a CBOR Sequence (RFC 8742), yielding each item as a JavaScript value. */\n static *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCBORSeq(input, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Parse a CDN Sequence text string, yielding each item as a JavaScript value. */\n static *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCDNSeq(text, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Compile a CDN text string to CBOR binary data.\n * Multi-item CDN Sequences produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromCDNSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Decompile CBOR binary data to a CDN text string.\n * CBOR Sequences (RFC 8742) produce multi-item CDN output, with items separated by newlines.\n */\n static decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toCDN(options))\n .join('\\n');\n }\n\n /**\n * Convert CBOR binary data to an annotated hex dump string.\n * CBOR Sequences (RFC 8742) produce one dump per item, separated by newlines.\n */\n static toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toHexDump(options))\n .join('\\n');\n }\n\n /**\n * Parse an annotated hex dump string to CBOR binary data.\n * Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromHexDumpSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Check CBOR / CDN / hex dump input for well-formedness and validity,\n * without throwing.\n *\n * Decodes/parses the input as a sequence (CBOR Sequence per RFC 8742, or a\n * CDN Sequence) in non-strict mode: recoverable violations are collected\n * into `warnings` instead of stopping decoding, while malformed input\n * (e.g. truncated data, hard syntax errors — including a CDN Sequence\n * abandoned after a hard syntax error) is reported via `error`.\n * Informational hints about optional extensions that aren't registered\n * (`ParseWarning.hint`) are not treated as violations; they are collected\n * separately into `hints`.\n *\n * @example\n * const result = CBOR.validate(bytes);\n * if (!result.valid) {\n * if (result.error) console.error(`invalid: ${result.error.message}`);\n * for (const w of result.warnings) console.warn(w.message);\n * }\n *\n * @example\n * // CDN text input\n * CBOR.validate('{\"a\": 1}', { type: 'cdn' });\n */\n static validate(\n input: ArrayBufferView | ArrayBufferLike | string,\n options?: ValidateOptions\n ): ValidateResult {\n const warnings: (DecodeWarning | ParseWarning)[] = [];\n const hints: ParseWarning[] = [];\n let fatal: ParseWarning | undefined;\n const seqOptions = {\n strict: false,\n extensions: options?.extensions,\n builtinExtensions: options?.builtinExtensions,\n onWarning: (w: DecodeWarning | ParseWarning) => {\n if ('hint' in w && w.hint) {\n hints.push(w);\n return;\n }\n if ('fatal' in w && w.fatal) {\n fatal = w;\n return;\n }\n warnings.push(w);\n },\n };\n let count = 0;\n try {\n const type = options?.type ?? 'cbor';\n if (type === 'cdn') {\n const cdnOptions: FromCDNSeqOptions = {\n ...seqOptions,\n unresolvedExtension: options?.unresolvedExtension,\n };\n for (const _ of CBOR.fromCDNSeq(input as string, cdnOptions)) count++;\n } else if (type === 'hex') {\n for (const _ of CBOR.fromHexDumpSeq(input as string, seqOptions))\n count++;\n } else {\n for (const _ of CBOR.fromCBORSeq(\n input as ArrayBufferView | ArrayBufferLike,\n seqOptions\n ))\n count++;\n }\n } catch (err) {\n return {\n valid: false,\n count,\n warnings,\n hints,\n error: err instanceof Error ? err : new Error(String(err)),\n };\n }\n if (fatal) {\n // Prefer the original syntax error (position fields intact); the\n // unterminated-comment fatals are emitted without one, so rebuild a\n // CdnSyntaxError carrying at least the warning's offset.\n const error =\n fatal.cause instanceof Error\n ? fatal.cause\n : new CdnSyntaxError(fatal.message, { offset: fatal.offset });\n return { valid: false, count, warnings, hints, error };\n }\n return { valid: warnings.length === 0, count, warnings, hints };\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.decompile()` instead.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /** @deprecated Use `CBOR.decompile()` instead. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.compile()` instead.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /** @deprecated Use `CBOR.compile()` instead. */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits,\n opts.builtinExtensions\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\nfunction emitCDNSeqWarning(\n msg: string,\n fallbackOffset: number,\n options: FromCDNSeqOptions | undefined,\n fatal?: boolean,\n cause?: CdnSyntaxError\n): void {\n const offset = cause?.offset ?? fallbackOffset;\n const w: ParseWarning = { message: msg, offset };\n if (fatal) w.fatal = true;\n if (cause) w.cause = cause;\n if (cause?.offset !== undefined) {\n w.line = cause.line;\n w.column = cause.column;\n w.endOffset = cause.endOffset;\n }\n if (options?.onWarning) options.onWarning(w);\n else if (!options?.silent)\n console.warn(`CDN sequence warning at offset ${offset}: ${msg}`);\n}\n\n/** Whether `text[i]` starts a CDN comment (`#`, `//`, `/* … *\\/`, or `/ … /`). */\nfunction isCDNCommentStart(text: string, i: number): boolean {\n const ch = text[i];\n return ch === '#' || ch === '/';\n}\n\n/**\n * CDN sequence の item 間にある空白・コメント・省略可能なカンマを読み飛ばし、\n * 次の item が始まる文字位置と、何らかの separator が存在したかどうかを返す。\n * 未終端のブロックコメントは strict モードでは throw し、\n * strict: false の場合は警告を emit して末尾まで読み飛ばす。\n *\n * `stopAtComments` は `preserveComments` 有効時にコメントを次の item の\n * leading コメントとして残すためのモード:\n * - `'none'`: コメントも読み飛ばす(従来動作)\n * - `'all'`: 最初のコメントで停止する(先頭 item 用)\n * - `'after-newline'`: 改行より後のコメントで停止する。直前 item と同じ行の\n * コメントはその item の trailing コメントとして既に付与されているため読み飛ばす。\n */\nfunction skipCDNSeparator(\n text: string,\n from: number,\n options: FromCDNSeqOptions | undefined,\n stopAtComments: 'none' | 'after-newline' | 'all' = 'none'\n): { offset: number; hadSeparator: boolean; commaOffset: number } {\n let i = from;\n let hadSeparator = false;\n let seenComma = false;\n let seenNewline = false;\n let commaOffset = -1;\n const stopHere = (): boolean =>\n stopAtComments === 'all' ||\n (stopAtComments === 'after-newline' && seenNewline);\n while (i < text.length) {\n const ch = text[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\r' || ch === '\\x1e') {\n hadSeparator = true;\n i++;\n continue;\n }\n if (ch === '\\n') {\n hadSeparator = true;\n seenNewline = true;\n i++;\n continue;\n }\n if (ch === '#') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 1);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 2);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '*') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('*/', i + 2);\n if (end < 0) {\n const msg = 'unterminated /* comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 2;\n }\n continue;\n }\n if (ch === '/' && text[i + 1] !== '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('/', i + 1);\n if (end < 0) {\n const msg = 'unterminated / comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 1;\n }\n continue;\n }\n if (ch === ',' && !seenComma) {\n hadSeparator = true;\n seenComma = true;\n commaOffset = i;\n i++;\n continue;\n }\n break;\n }\n return { offset: i, hadSeparator, commaOffset };\n}\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":"kLAIA,IAAM,EAAY,mCACZ,EAAY,mCAElB,SAAS,EAAmB,EAAqB,CAC/C,IAAI,EAAM,EAAI,OACd,KAAO,EAAM,GAAK,EAAI,WAAW,EAAM,CAAC,IAAM,IAAM,IACpD,OAAO,EAAI,MAAM,EAAG,CAAG,CACzB,CAEA,S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;CAAI,IAAG,EAAc,IACrD,EAAI,EAAM,EAEZ,QACF,CACA,GAAI,IAAO,KAAO,CAAC,EAAW,CAC5B,EAAe,GACf,EAAY,GACZ,EAAc,EACd,IACA,QACF,CACA,KACF,CACA,MAAO,CAAE,OAAQ,EAAG,eAAc,aAAY,CAChD,CAGA,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAK,CAAC,CAAC,EACrD,OAAO,IAAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CBOROptions, CborExtension, DecodeWarning, ParseWarning, FromCBOROptions, FromCBORSeqOptions, ToCBOROptions, FromCDNOptions, FromCDNSeqOptions, ToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, } from './types';
|
|
1
|
+
export type { CBOROptions, CborExtension, DecodeWarning, ParseWarning, FromCBOROptions, FromCBORSeqOptions, ToCBOROptions, FromCDNOptions, FromCDNSeqOptions, ToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, ValidateOptions, ValidateResult, } from './types';
|
|
2
2
|
export { CdnSyntaxError } from './cdn/errors';
|
|
3
3
|
export { CBOR_TAG, Null, Tag, Undefined } from './tag';
|
|
4
4
|
export { CBOR_OMIT } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as e } from "./tokenizer-CeuixxXi.js";
|
|
2
|
-
import { E as t, F as n, I as r, L as i, M as a, N as o, P as s, _ as c, a as l, c as u, d, f, h as p, i as m, l as h, m as g, n as _, o as v, p as y, r as b, s as x, t as S, u as C } from "./mapEntries-
|
|
2
|
+
import { E as t, F as n, I as r, L as i, M as a, N as o, P as s, _ as c, a as l, c as u, d, f, h as p, i as m, l as h, m as g, n as _, o as v, p as y, r as b, s as x, t as S, u as C } from "./mapEntries-hyNVtz5Z.js";
|
|
3
3
|
//#region src/extensions/b32.ts
|
|
4
4
|
var w = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", T = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
5
5
|
function E(e) {
|
|
@@ -125,6 +125,9 @@ var j = {
|
|
|
125
125
|
fromHex(e, n) {
|
|
126
126
|
return t.fromHex(e, this.#t(n));
|
|
127
127
|
}
|
|
128
|
+
validate(e, n) {
|
|
129
|
+
return t.validate(e, this.#t(n));
|
|
130
|
+
}
|
|
128
131
|
cborToCborEdn(e, t) {
|
|
129
132
|
return this.cborToCdn(e, t);
|
|
130
133
|
}
|
|
@@ -254,6 +257,59 @@ var j = {
|
|
|
254
257
|
for (let e of r) a.set(e, o), o += e.length;
|
|
255
258
|
return a;
|
|
256
259
|
}
|
|
260
|
+
static validate(n, r) {
|
|
261
|
+
let i = [], a = [], o, s = {
|
|
262
|
+
strict: !1,
|
|
263
|
+
extensions: r?.extensions,
|
|
264
|
+
builtinExtensions: r?.builtinExtensions,
|
|
265
|
+
onWarning: (e) => {
|
|
266
|
+
if ("hint" in e && e.hint) {
|
|
267
|
+
a.push(e);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if ("fatal" in e && e.fatal) {
|
|
271
|
+
o = e;
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
i.push(e);
|
|
275
|
+
}
|
|
276
|
+
}, c = 0;
|
|
277
|
+
try {
|
|
278
|
+
let e = r?.type ?? "cbor";
|
|
279
|
+
if (e === "cdn") {
|
|
280
|
+
let e = {
|
|
281
|
+
...s,
|
|
282
|
+
unresolvedExtension: r?.unresolvedExtension
|
|
283
|
+
};
|
|
284
|
+
for (let r of t.fromCDNSeq(n, e)) c++;
|
|
285
|
+
} else if (e === "hex") for (let e of t.fromHexDumpSeq(n, s)) c++;
|
|
286
|
+
else for (let e of t.fromCBORSeq(n, s)) c++;
|
|
287
|
+
} catch (e) {
|
|
288
|
+
return {
|
|
289
|
+
valid: !1,
|
|
290
|
+
count: c,
|
|
291
|
+
warnings: i,
|
|
292
|
+
hints: a,
|
|
293
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
if (o) {
|
|
297
|
+
let t = o.cause instanceof Error ? o.cause : new e(o.message, { offset: o.offset });
|
|
298
|
+
return {
|
|
299
|
+
valid: !1,
|
|
300
|
+
count: c,
|
|
301
|
+
warnings: i,
|
|
302
|
+
hints: a,
|
|
303
|
+
error: t
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
valid: i.length === 0,
|
|
308
|
+
count: c,
|
|
309
|
+
warnings: i,
|
|
310
|
+
hints: a
|
|
311
|
+
};
|
|
312
|
+
}
|
|
257
313
|
static cborToCdn(e, n) {
|
|
258
314
|
return t.fromCBOR(e, n).toCDN(n);
|
|
259
315
|
}
|
|
@@ -339,7 +395,7 @@ function I(e, t, n, r, i) {
|
|
|
339
395
|
message: e,
|
|
340
396
|
offset: a
|
|
341
397
|
};
|
|
342
|
-
r && (o.fatal = !0), i?.offset !== void 0 && (o.line = i.line, o.column = i.column, o.endOffset = i.endOffset), n?.onWarning ? n.onWarning(o) : n?.silent || console.warn(`CDN sequence warning at offset ${a}: ${e}`);
|
|
398
|
+
r && (o.fatal = !0), i && (o.cause = i), i?.offset !== void 0 && (o.line = i.line, o.column = i.column, o.endOffset = i.endOffset), n?.onWarning ? n.onWarning(o) : n?.silent || console.warn(`CDN sequence warning at offset ${a}: ${e}`);
|
|
343
399
|
}
|
|
344
400
|
function L(e, t) {
|
|
345
401
|
let n = e[t];
|