@cbortech/cbor 0.26.8 → 0.27.1
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 +193 -28
- package/README.md +196 -29
- package/dist/ast/CborAppSeqResult.d.ts +58 -3
- package/dist/ast/CborArray.d.ts +2 -2
- package/dist/ast/CborByteString.d.ts +17 -1
- package/dist/ast/CborEmbeddedCBOR.d.ts +2 -2
- package/dist/ast/CborFloat.d.ts +2 -2
- package/dist/ast/CborIndefiniteByteString.d.ts +25 -1
- package/dist/ast/CborIndefiniteTextString.d.ts +17 -1
- package/dist/ast/CborItem.d.ts +340 -10
- package/dist/ast/CborMap.d.ts +2 -2
- package/dist/ast/CborNint.d.ts +1 -1
- package/dist/ast/CborTag.d.ts +30 -3
- package/dist/ast/CborTextString.d.ts +3 -2
- package/dist/ast/CborUint.d.ts +1 -1
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cddl/index.cjs +1 -1
- package/dist/cddl/index.js +1 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.cjs.map +1 -1
- package/dist/cdn/index.js +18 -18
- package/dist/cdn/index.js.map +1 -1
- package/dist/cdn/serialize-utils.d.ts +237 -10
- package/dist/cdn/tokenizer.d.ts +12 -11
- package/dist/extensions/builtins.d.ts +5 -5
- package/dist/extensions/cri.d.ts +4 -4
- package/dist/extensions/dt.d.ts +4 -4
- package/dist/extensions/ip.d.ts +4 -4
- package/dist/extensions/types.d.ts +44 -5
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +158 -158
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-Ci_dppP6.js → mapEntries-CCLaJSaJ.js} +1599 -1275
- package/dist/mapEntries-CCLaJSaJ.js.map +1 -0
- package/dist/mapEntries-CZZJScaj.cjs +13 -0
- package/dist/mapEntries-CZZJScaj.cjs.map +1 -0
- package/dist/{schema-y8G5mDIS.js → schema-DN9inJny.js} +294 -294
- package/dist/{schema-y8G5mDIS.js.map → schema-DN9inJny.js.map} +1 -1
- package/dist/schema-zsg5yCPK.cjs +63 -0
- package/dist/{schema-DgnkH0P6.cjs.map → schema-zsg5yCPK.cjs.map} +1 -1
- package/dist/serialize-utils-DhlW61ZX.cjs +37 -0
- package/dist/serialize-utils-DhlW61ZX.cjs.map +1 -0
- package/dist/{tokenizer-N-vAvRdj.js → serialize-utils-h-CVB9rg.js} +636 -358
- package/dist/serialize-utils-h-CVB9rg.js.map +1 -0
- package/dist/types.d.ts +508 -58
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/hexfloat.d.ts +11 -3
- package/dist/utils/strip-comments.d.ts +1 -1
- package/package.json +13 -12
- package/dist/mapEntries-BJzyBUH5.cjs +0 -13
- package/dist/mapEntries-BJzyBUH5.cjs.map +0 -1
- package/dist/mapEntries-Ci_dppP6.js.map +0 -1
- package/dist/schema-DgnkH0P6.cjs +0 -63
- package/dist/tokenizer-BD08xbyd.cjs +0 -36
- package/dist/tokenizer-BD08xbyd.cjs.map +0 -1
- package/dist/tokenizer-N-vAvRdj.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CborItem } from '../ast/CborItem';
|
|
2
|
-
import { FromCBOROptions, FromJSOptions } from '../types';
|
|
2
|
+
import { FromCBOROptions, FromJSOptions, ReadonlyToJSNodeOptions } from '../types';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/**
|
|
5
5
|
* Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
|
|
6
|
-
*
|
|
6
|
+
* app-string prefixes or CBOR tag numbers.
|
|
7
7
|
*
|
|
8
8
|
* Pass instances via `FromCDNOptions.extensions`, `FromCBOROptions.extensions`,
|
|
9
9
|
* or `FromJSOptions.extensions`.
|
|
@@ -52,7 +52,7 @@ export interface CborExtension {
|
|
|
52
52
|
*/
|
|
53
53
|
parseAppSequence?(prefix: string, items: CborItem[], onError?: (msg: string) => void): CborItem;
|
|
54
54
|
/**
|
|
55
|
-
* Controls how the CDN parser preserves the original
|
|
55
|
+
* Controls how the CDN parser preserves the original app-string
|
|
56
56
|
* / -sequence / raw-tag source text — `prefix'...'`, `` prefix`...` ``,
|
|
57
57
|
* `prefix<<...>>`, or a raw tag literal `N(...)` resolved via `parseTag`
|
|
58
58
|
* — for round-tripping through `toCDN()`.
|
|
@@ -60,7 +60,7 @@ export interface CborExtension {
|
|
|
60
60
|
* - `true`: the parser wraps the result of `parseAppSequence` (only —
|
|
61
61
|
* `parseAppString` and `parseTag` results are unaffected) in a
|
|
62
62
|
* `CborAppSeqResult`, which round-trips the original `<<...>>` notation
|
|
63
|
-
* unconditionally whenever `
|
|
63
|
+
* unconditionally whenever `appPrefix !== false` (no extra option
|
|
64
64
|
* needed). Use this when the result has no dedicated subclass whose
|
|
65
65
|
* identity callers rely on (e.g. `instanceof` checks) — the wrapper
|
|
66
66
|
* changes the returned node's type.
|
|
@@ -68,7 +68,7 @@ export interface CborExtension {
|
|
|
68
68
|
* results alike, the parser instead sets `appSeqSource` directly on the
|
|
69
69
|
* *same* result node (preserving its class/identity) and leaves it to
|
|
70
70
|
* the node's own `_toCDN()` override to decide whether to use it — by
|
|
71
|
-
* convention, only when `ToCDNOptions.
|
|
71
|
+
* convention, only when `ToCDNOptions.preserveAppPrefix` is set, so
|
|
72
72
|
* the default output keeps regenerating `prefix'...'` form from the
|
|
73
73
|
* resolved value. This covers a `` prefix`...` `` (backtick) source, a
|
|
74
74
|
* non-canonically-spelled `prefix'...'` source, and a raw tag literal
|
|
@@ -116,4 +116,43 @@ export interface CborExtension {
|
|
|
116
116
|
* (e.g. `value is Date`) for better static type inference at the call site.
|
|
117
117
|
*/
|
|
118
118
|
isJSType?(value: unknown): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Called during `toJS()` for every node, before that node's own default
|
|
121
|
+
* conversion, when this extension is listed in `ToJSOptions.extensions`.
|
|
122
|
+
* Return `undefined` to fall through to the next extension (then, if none
|
|
123
|
+
* claim the node, its own default conversion). Typically checks the
|
|
124
|
+
* node's class/shape (e.g. `item instanceof CborTaggedEpochDtExt`) rather
|
|
125
|
+
* than a tag number, since app-string forms without a wrapping tag (e.g.
|
|
126
|
+
* `dt'...'`) never reach `parseTag`-style tag-number dispatch either.
|
|
127
|
+
*
|
|
128
|
+
* The result is wrapped in `{ value }` — rather than returned directly —
|
|
129
|
+
* so a legitimate conversion result of `undefined` (CBOR `undefined`,
|
|
130
|
+
* simple 23) can be distinguished from "this extension doesn't handle
|
|
131
|
+
* this node".
|
|
132
|
+
*
|
|
133
|
+
* `options` never carries a `reviver` — its type is
|
|
134
|
+
* `ReadonlyToJSNodeOptions`, not `ToJSOptions` — so this hook has no way
|
|
135
|
+
* to make its result depend on whether one is present. That matters
|
|
136
|
+
* because `CborArray`/`CborMap.toObject`, when a `reviver` *is* present
|
|
137
|
+
* elsewhere in the call, convert each child more than once: once (with
|
|
138
|
+
* `reviver` itself stripped, though `itemOptions`/`extensions` stay
|
|
139
|
+
* active) to pre-populate a holder visible to an *earlier* sibling's own
|
|
140
|
+
* reviver call as `this[j]`, and once more, for real, to compute the
|
|
141
|
+
* value the container actually keeps. This hook is offered each of those
|
|
142
|
+
* conversions independently — once per visit, not deduplicated across
|
|
143
|
+
* them — precisely so that a `this[j]` observation reflects this hook's
|
|
144
|
+
* conversion (e.g. a `Date`) rather than the node's un-converted default.
|
|
145
|
+
* `options.extensions`, if present, is likewise a fresh copy each call —
|
|
146
|
+
* mutating it in place has no effect elsewhere.
|
|
147
|
+
* A deeply nested structure can multiply this further: a container
|
|
148
|
+
* several levels down may run its own such pre-population pass while
|
|
149
|
+
* itself sitting inside an *outer* container's pre-population pass, so
|
|
150
|
+
* the same node can in principle be offered to this hook more than
|
|
151
|
+
* twice. Whatever this hook returns for one visit only ever affects that
|
|
152
|
+
* visit's own value; reviving of the value a *container* holds still
|
|
153
|
+
* happens afterwards, exactly once per visit, in that container itself.
|
|
154
|
+
*/
|
|
155
|
+
toJS?(item: CborItem, options: ReadonlyToJSNodeOptions): {
|
|
156
|
+
value: unknown;
|
|
157
|
+
} | undefined;
|
|
119
158
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-DhlW61ZX.cjs"),t=require("./schema-zsg5yCPK.cjs"),n=require("./mapEntries-CZZJScaj.cjs");function r(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 i={appStringPrefixes:[`same`],preserveAppSeqSource:!0,parseAppSequence(e,t,n){if(t.length===0)throw SyntaxError(`same<<...>> requires at least one item`);let i=t[0],a=i.toCBOR();for(let e=1;e<t.length;e++)if(!r(a,t[e].toCBOR())){let t=`same<<...>>: item ${e} produces different CBOR bytes than item 0`;if(n)n(t);else throw SyntaxError(t)}return i}},a=new Map,o=64;function s(e){if(typeof e!=`string`)return e;let n=a.get(e);return n||(n=t.n(e),a.size>=o&&a.delete(a.keys().next().value),a.set(e,n)),n}function c(e,n,r){if(n){let i=n.validate(e,r);if(!i.valid)throw new t.s(i.errors,i.warnings)}return e}function l(e,t){return c(e,s(t?.cddl),t?.cddlValidationOptions)}var u=class t{static OMIT=n.R;static TAG=n.z;static Tag=n.V;static Simple=n.L;static MapEntries=n.t;static dt_as_Date=n.m;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromCDN(e,n){let r=t.fromCDN(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}*fromCBORSeq(e,n){for(let r of t.fromCBORSeq(e,this.#t(n)))r._defaults=this.#e,yield r}*fromCDNSeq(e,n){for(let r of t.fromCDNSeq(e,this.#t(n)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,n){for(let r of t.fromHexDumpSeq(e,this.#t(n)))r._defaults=this.#e,yield r}decode(e,n){return t.decode(e,this.#t(n))}*decodeSeq(e,n){yield*t.decodeSeq(e,this.#t(n))}*parseSeq(e,n){yield*t.parseSeq(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}compile(e,n){return t.compile(e,this.#t(n))}decompile(e,n){return t.decompile(e,this.#t(n))}toHex(e,n){return t.toHex(e,this.#t(n))}fromHex(e,n){return t.fromHex(e,this.#t(n))}validate(e,n){return t.validate(e,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,n){let r=this.#t(n),i=t.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,n){let r=this.#t(n);return t.fromCDN(e,r).toCBOR(r)}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromCDN(e,r).toJS(r)}let r=this.#t(n);return t.fromCDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=_(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(e,t){return l(n.u(e,t),t)}static fromCDN(e,t){return l(n.g(e,t),t)}static fromEDN(e,n){return t.fromCDN(e,n)}static*fromHexDumpSeq(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)}`);yield*t.fromCBORSeq(new Uint8Array(r),n)}static*fromCBORSeq(e,t){let r=s(t?.cddl),i=e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a=0;for(;a<i.byteLength;){let e=n.u(i,{...t,offset:a,allowTrailing:!0});yield c(e,r,t?.cddlValidationOptions),a=e.end}}static*fromCDNSeq(t,r){let i=s(r?.cddl),a=e.D(r)||!!r?.preserveAll,o=0,l=!0;for(;;){let{offset:s,hadSeparator:u,commaOffset:d}=g(t,o,r,a?l?`all`:`after-newline`:`none`);if(l&&d>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);m(e,d,r)}if(s>=t.length||a&&h(t,s)&&g(t,s,r).offset>=t.length)break;if(!l&&!u){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);m(e,s,r)}o=s;let f;try{f=n.g(t,{...r,offset:o,allowTrailing:!0,_skipRS:!0})}catch(t){if(r?.strict!==!1)throw t;m(t instanceof Error?t.message:String(t),o,r,!0,t instanceof e.I?t:void 0);break}yield c(f,i,r?.cddlValidationOptions),o=f.end,l=!1}}static fromJS(e,t){return l(n.r(e,t),t)}static fromHexDump(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)}`);return l(n.u(new Uint8Array(r),t),t)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static*decodeSeq(e,n){for(let r of t.fromCBORSeq(e,n))yield r.toJS(n)}static*parseSeq(e,n){for(let r of t.fromCDNSeq(e,n))yield r.toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static compile(e,n){let r=[...t.fromCDNSeq(e,n)].map(e=>e.toCBOR(n)),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,n){return[...t.fromCBORSeq(e,n)].map(e=>e.toCDN(n)).join(`
|
|
2
2
|
`)}static toHex(e,n){return[...t.fromCBORSeq(e,n)].map(e=>e.toHexDump(n)).join(`
|
|
3
|
-
`)}static fromHex(e,n){let r=[...t.fromHexDumpSeq(e,n)].map(e=>e.toCBOR(n)),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(n,r){let i=[],a=[],o,c={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)}},l=s(r?.cddl),u=[],d=[],f=e=>{if(!l)return;let t=l.validate(e,r?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=l?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=r?.type??`cbor`;if(e===`cdn`){let e={...c,unresolvedExtension:r?.unresolvedExtension};for(let r of t.fromCDNSeq(n,e))m++,f(r)}else if(e===`hex`)for(let e of t.fromHexDumpSeq(n,c))m++,f(e);else for(let e of t.fromCBORSeq(n,c))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:i,hints:a,error:e instanceof Error?e:Error(String(e)),...p}}if(o){let t=o.cause instanceof Error?o.cause:new e.
|
|
3
|
+
`)}static fromHex(e,n){let r=[...t.fromHexDumpSeq(e,n)].map(e=>e.toCBOR(n)),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(n,r){let i=[],a=[],o,c={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)}},l=s(r?.cddl),u=[],d=[],f=e=>{if(!l)return;let t=l.validate(e,r?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=l?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=r?.type??`cbor`;if(e===`cdn`){let e={...c,unresolvedExtension:r?.unresolvedExtension};for(let r of t.fromCDNSeq(n,e))m++,f(r)}else if(e===`hex`)for(let e of t.fromHexDumpSeq(n,c))m++,f(e);else for(let e of t.fromCBORSeq(n,c))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:i,hints:a,error:e instanceof Error?e:Error(String(e)),...p}}if(o){let t=o.cause instanceof Error?o.cause:new e.I(o.message,{offset:o.offset});return{valid:!1,count:m,warnings:i,hints:a,error:t,...p}}return{valid:i.length===0&&u.length===0,count:m,warnings:i,hints:a,...p}}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i=typeof t==`function`||Array.isArray(t)?t:void 0,a=_(r);if(i){let t=n.n(e,i);return t===void 0||t===n.R?void 0:n.r(t).toCDN(a===void 0?void 0:{indent:a})}return n.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=t;if(i?.replacer){let t=n.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(t===void 0||t===n.R)return;let{replacer:r,...a}=i;return l(n.r(t,Object.keys(a).length>0?a:void 0),i).toCDN(i)}return l(n.r(e,i),i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};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
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(`
|
|
8
8
|
`)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);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(`
|
|
9
|
-
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function _(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.BUILTIN_EXTENSIONS=n.i,exports.CBOR=u,exports.default=u,exports.CBOR_OMIT=n.
|
|
9
|
+
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function _(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.BUILTIN_EXTENSIONS=n.i,exports.CBOR=u,exports.default=u,exports.CBOR_OMIT=n.R,exports.CBOR_TAG=n.z,exports.CddlMismatchError=t.s,exports.CdnSyntaxError=e.I,exports.MapEntries=n.t,exports.Null=n.B,exports.Simple=n.L,exports.Tag=n.V,exports.Undefined=n.H,exports.b1=n.c,exports.b32=n.x,exports.cri=n.d,exports.dt=n.p,exports.dt_as_Date=n.m,exports.float=n.a,exports.h32=n.S,exports.ilbs=n.o,exports.ilts=n.s,exports.ip=n.f,exports.same=i,exports.t1=n.l;
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["/**\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 { CddlMismatchError } from './cddl/errors';\nimport { compile as compileCDDL, CddlSchema } from './cddl/schema';\nimport type { ValidateOptions as CddlValidateOptions } from './cddl/validator';\nimport type { CddlValidationError, CddlValidationWarning } from './cddl/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 * Cache for schemas compiled from CDDL source text passed as the `cddl`\n * option, so repeated per-call use of the same string does not recompile.\n * Bounded: the oldest entry is evicted once the cap is reached.\n */\nconst compiledCddlCache = new Map<string, CddlSchema>();\nconst COMPILED_CDDL_CACHE_MAX = 64;\n\n/**\n * Resolve the `cddl` option to a compiled schema: pass compiled schemas\n * through, compile (and cache) CDDL source text.\n */\nfunction resolveCddl(\n cddl: CddlSchema | string | undefined\n): CddlSchema | undefined {\n if (typeof cddl !== 'string') return cddl;\n let schema = compiledCddlCache.get(cddl);\n if (!schema) {\n schema = compileCDDL(cddl);\n if (compiledCddlCache.size >= COMPILED_CDDL_CACHE_MAX) {\n compiledCddlCache.delete(compiledCddlCache.keys().next().value!);\n }\n compiledCddlCache.set(cddl, schema);\n }\n return schema;\n}\n\n/**\n * Validate an item against a resolved schema (if any) and throw\n * {@link CddlMismatchError} on mismatch.\n */\nfunction assertCddl(\n item: CborItem,\n schema: CddlSchema | undefined,\n validationOptions?: CddlValidateOptions\n): CborItem {\n if (schema) {\n const result = schema.validate(item, validationOptions);\n if (!result.valid) {\n throw new CddlMismatchError(result.errors, result.warnings);\n }\n }\n return item;\n}\n\n/**\n * When a CDDL schema is supplied via the `cddl` option, validate the item\n * against it and throw {@link CddlMismatchError} on mismatch.\n */\nfunction checkCddl(\n item: CborItem,\n options?: {\n cddl?: CddlSchema | string;\n cddlValidationOptions?: CddlValidateOptions;\n }\n): CborItem {\n return assertCddl(\n item,\n resolveCddl(options?.cddl),\n options?.cddlValidationOptions\n );\n}\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 checkCddl(decodeCBOR(input, options), options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return checkCddl(parseCDN(text, options), 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 // Resolve up front so invalid CDDL source text throws even when the\n // sequence turns out to be empty.\n const cddlSchema = resolveCddl(options?.cddl);\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 assertCddl(item, cddlSchema, options?.cddlValidationOptions);\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 // Resolve up front so invalid CDDL source text throws even when the\n // sequence turns out to be empty.\n const cddlSchema = resolveCddl(options?.cddl);\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 assertCddl(item, cddlSchema, options?.cddlValidationOptions);\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 checkCddl(_fromJS(value, options), 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 checkCddl(decodeCBOR(new Uint8Array(bytes), options), 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 * @example\n * // Schema validation with a compiled CDDL schema\n * import { CDDL } from '@cbortech/cbor/cddl';\n * const schema = CDDL.compile('person = { name: tstr, ? age: uint }');\n * const result = CBOR.validate('{\"name\": \"kudo\"}', { type: 'cdn', cddl: schema });\n * result.valid; // true\n * result.cddlErrors; // []\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 // `cddl` is deliberately not forwarded to the Seq generators: a mismatch\n // must be collected below, not thrown from inside the generator.\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 const schema = resolveCddl(options?.cddl);\n const cddlErrors: CddlValidationError[] = [];\n const cddlWarnings: CddlValidationWarning[] = [];\n const checkItem = (item: CborItem) => {\n if (!schema) return;\n const result = schema.validate(item, options?.cddlValidationOptions);\n cddlErrors.push(...result.errors);\n if (result.warnings) cddlWarnings.push(...result.warnings);\n };\n const cddlFields = schema ? { cddlErrors, cddlWarnings } : {};\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 item of CBOR.fromCDNSeq(input as string, cdnOptions)) {\n count++;\n checkItem(item);\n }\n } else if (type === 'hex') {\n for (const item of CBOR.fromHexDumpSeq(input as string, seqOptions)) {\n count++;\n checkItem(item);\n }\n } else {\n for (const item of CBOR.fromCBORSeq(\n input as ArrayBufferView | ArrayBufferLike,\n seqOptions\n )) {\n count++;\n checkItem(item);\n }\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 ...cddlFields,\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, ...cddlFields };\n }\n return {\n valid: warnings.length === 0 && cddlErrors.length === 0,\n count,\n warnings,\n hints,\n ...cddlFields,\n };\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 checkCddl(\n _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ),\n opts\n ).toCDN(opts);\n }\n return checkCddl(\n _fromJS(value, opts as FromJSOptions | undefined),\n opts\n ).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":"qNA6BA,SAAS,EAAW,EAAe,EAAwB,CACzD,GAAI,EAAE,SAAW,EAAE,OAAQ,MAAO,GAClC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,GAAI,EAAE,KAAO,EAAE,GAAI,MAAO,GAC7D,MAAO,EACT,CAMA,IAAa,EAAsB,CACjC,kBAAmB,CAAC,MAAM,EAC1B,qBAAsB,GAEtB,iBACE,EACA,EACA,EACU,CACV,GAAI,EAAM,SAAW,EACnB,MAAU,YAAY,wCAAwC,EAChE,IAAM,EAAQ,EAAM,GACd,EAAY,EAAM,OAAO,EAC/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AI,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/same.ts","../src/cbor.ts"],"sourcesContent":["/**\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; `appPrefix: 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 { shouldEmitComments } from './cdn/serialize-utils';\nimport { CddlMismatchError } from './cddl/errors';\nimport { compile as compileCDDL, CddlSchema } from './cddl/schema';\nimport type { ValidateOptions as CddlValidateOptions } from './cddl/validator';\nimport type { CddlValidationError, CddlValidationWarning } from './cddl/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 * Cache for schemas compiled from CDDL source text passed as the `cddl`\n * option, so repeated per-call use of the same string does not recompile.\n * Bounded: the oldest entry is evicted once the cap is reached.\n */\nconst compiledCddlCache = new Map<string, CddlSchema>();\nconst COMPILED_CDDL_CACHE_MAX = 64;\n\n/**\n * Resolve the `cddl` option to a compiled schema: pass compiled schemas\n * through, compile (and cache) CDDL source text.\n */\nfunction resolveCddl(\n cddl: CddlSchema | string | undefined\n): CddlSchema | undefined {\n if (typeof cddl !== 'string') return cddl;\n let schema = compiledCddlCache.get(cddl);\n if (!schema) {\n schema = compileCDDL(cddl);\n if (compiledCddlCache.size >= COMPILED_CDDL_CACHE_MAX) {\n compiledCddlCache.delete(compiledCddlCache.keys().next().value!);\n }\n compiledCddlCache.set(cddl, schema);\n }\n return schema;\n}\n\n/**\n * Validate an item against a resolved schema (if any) and throw\n * {@link CddlMismatchError} on mismatch.\n */\nfunction assertCddl(\n item: CborItem,\n schema: CddlSchema | undefined,\n validationOptions?: CddlValidateOptions\n): CborItem {\n if (schema) {\n const result = schema.validate(item, validationOptions);\n if (!result.valid) {\n throw new CddlMismatchError(result.errors, result.warnings);\n }\n }\n return item;\n}\n\n/**\n * When a CDDL schema is supplied via the `cddl` option, validate the item\n * against it and throw {@link CddlMismatchError} on mismatch.\n */\nfunction checkCddl(\n item: CborItem,\n options?: {\n cddl?: CddlSchema | string;\n cddlValidationOptions?: CddlValidateOptions;\n }\n): CborItem {\n return assertCddl(\n item,\n resolveCddl(options?.cddl),\n options?.cddlValidationOptions\n );\n}\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 checkCddl(decodeCBOR(input, options), options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return checkCddl(parseCDN(text, options), 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 // Resolve up front so invalid CDDL source text throws even when the\n // sequence turns out to be empty.\n const cddlSchema = resolveCddl(options?.cddl);\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 assertCddl(item, cddlSchema, options?.cddlValidationOptions);\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 // Resolve up front so invalid CDDL source text throws even when the\n // sequence turns out to be empty.\n const cddlSchema = resolveCddl(options?.cddl);\n const preserve = shouldEmitComments(options) || !!options?.preserveAll;\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 assertCddl(item, cddlSchema, options?.cddlValidationOptions);\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 checkCddl(_fromJS(value, options), 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 checkCddl(decodeCBOR(new Uint8Array(bytes), options), 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 * @example\n * // Schema validation with a compiled CDDL schema\n * import { CDDL } from '@cbortech/cbor/cddl';\n * const schema = CDDL.compile('person = { name: tstr, ? age: uint }');\n * const result = CBOR.validate('{\"name\": \"kudo\"}', { type: 'cdn', cddl: schema });\n * result.valid; // true\n * result.cddlErrors; // []\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 // `cddl` is deliberately not forwarded to the Seq generators: a mismatch\n // must be collected below, not thrown from inside the generator.\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 const schema = resolveCddl(options?.cddl);\n const cddlErrors: CddlValidationError[] = [];\n const cddlWarnings: CddlValidationWarning[] = [];\n const checkItem = (item: CborItem) => {\n if (!schema) return;\n const result = schema.validate(item, options?.cddlValidationOptions);\n cddlErrors.push(...result.errors);\n if (result.warnings) cddlWarnings.push(...result.warnings);\n };\n const cddlFields = schema ? { cddlErrors, cddlWarnings } : {};\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 item of CBOR.fromCDNSeq(input as string, cdnOptions)) {\n count++;\n checkItem(item);\n }\n } else if (type === 'hex') {\n for (const item of CBOR.fromHexDumpSeq(input as string, seqOptions)) {\n count++;\n checkItem(item);\n }\n } else {\n for (const item of CBOR.fromCBORSeq(\n input as ArrayBufferView | ArrayBufferLike,\n seqOptions\n )) {\n count++;\n checkItem(item);\n }\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 ...cddlFields,\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, ...cddlFields };\n }\n return {\n valid: warnings.length === 0 && cddlErrors.length === 0,\n count,\n warnings,\n hints,\n ...cddlFields,\n };\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 checkCddl(\n _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ),\n opts\n ).toCDN(opts);\n }\n return checkCddl(\n _fromJS(value, opts as FromJSOptions | undefined),\n opts\n ).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":"2NA6BA,SAAS,EAAW,EAAe,EAAwB,CACzD,GAAI,EAAE,SAAW,EAAE,OAAQ,MAAO,GAClC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,GAAI,EAAE,KAAO,EAAE,GAAI,MAAO,GAC7D,MAAO,EACT,CAMA,IAAa,EAAsB,CACjC,kBAAmB,CAAC,MAAM,EAC1B,q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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, CborComment, CborComments, DecodeWarning, ParseWarning, FromCBOROptions, FromCBORSeqOptions, ToCBOROptions, FromCDNOptions, FromCDNSeqOptions, ToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, ValidateOptions, ValidateResult, } from './types';
|
|
1
|
+
export type { CBOROptions, CborExtension, CborComment, CborComments, DecodeWarning, ParseWarning, FromCBOROptions, FromCBORSeqOptions, ToCBOROptions, FromCDNOptions, FromCDNSeqOptions, ToCDNOptions, ReadonlyToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, ToJSNodeOptions, ReadonlyToJSNodeOptions, ItemContext, CdnItemContext, FromHexDumpOptions, ToHexDumpOptions, ValidateOptions, ValidateResult, } from './types';
|
|
2
2
|
export type { EncodingWidth } from './cbor/encode';
|
|
3
3
|
export { CdnSyntaxError } from './cdn/errors';
|
|
4
4
|
export { CddlMismatchError } from './cddl/errors';
|