@cbortech/cbor 0.27.0 → 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.
Files changed (48) hide show
  1. package/README.ja.md +73 -0
  2. package/README.md +75 -0
  3. package/dist/ast/CborAppSeqResult.d.ts +37 -4
  4. package/dist/ast/CborArray.d.ts +2 -2
  5. package/dist/ast/CborByteString.d.ts +2 -2
  6. package/dist/ast/CborEmbeddedCBOR.d.ts +1 -1
  7. package/dist/ast/CborFloat.d.ts +1 -1
  8. package/dist/ast/CborIndefiniteByteString.d.ts +1 -1
  9. package/dist/ast/CborIndefiniteTextString.d.ts +1 -1
  10. package/dist/ast/CborItem.d.ts +297 -7
  11. package/dist/ast/CborMap.d.ts +2 -2
  12. package/dist/ast/CborNint.d.ts +1 -1
  13. package/dist/ast/CborTag.d.ts +4 -4
  14. package/dist/ast/CborTextString.d.ts +2 -2
  15. package/dist/ast/CborUint.d.ts +1 -1
  16. package/dist/ast/index.cjs +1 -1
  17. package/dist/ast/index.js +1 -1
  18. package/dist/cddl/index.cjs +1 -1
  19. package/dist/cddl/index.js +1 -1
  20. package/dist/cdn/index.cjs +1 -1
  21. package/dist/cdn/index.js +1 -1
  22. package/dist/cdn/serialize-utils.d.ts +30 -2
  23. package/dist/extensions/cri.d.ts +2 -2
  24. package/dist/extensions/dt.d.ts +4 -4
  25. package/dist/extensions/ip.d.ts +3 -3
  26. package/dist/extensions/types.d.ts +40 -1
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +3 -3
  30. package/dist/{mapEntries-CvLdiN0h.js → mapEntries-CCLaJSaJ.js} +1114 -933
  31. package/dist/mapEntries-CCLaJSaJ.js.map +1 -0
  32. package/dist/mapEntries-CZZJScaj.cjs +13 -0
  33. package/dist/mapEntries-CZZJScaj.cjs.map +1 -0
  34. package/dist/{schema-CNfrVRYp.js → schema-DN9inJny.js} +3 -3
  35. package/dist/{schema-CNfrVRYp.js.map → schema-DN9inJny.js.map} +1 -1
  36. package/dist/{schema-iXpYtKQl.cjs → schema-zsg5yCPK.cjs} +2 -2
  37. package/dist/{schema-iXpYtKQl.cjs.map → schema-zsg5yCPK.cjs.map} +1 -1
  38. package/dist/{serialize-utils-CjTqQivB.cjs → serialize-utils-DhlW61ZX.cjs} +6 -6
  39. package/dist/serialize-utils-DhlW61ZX.cjs.map +1 -0
  40. package/dist/{serialize-utils-BuIZPaUc.js → serialize-utils-h-CVB9rg.js} +57 -47
  41. package/dist/{serialize-utils-BuIZPaUc.js.map → serialize-utils-h-CVB9rg.js.map} +1 -1
  42. package/dist/types.d.ts +273 -0
  43. package/dist/utils/hexfloat.d.ts +10 -2
  44. package/package.json +7 -8
  45. package/dist/mapEntries-C1f7G0AM.cjs +0 -13
  46. package/dist/mapEntries-C1f7G0AM.cjs.map +0 -1
  47. package/dist/mapEntries-CvLdiN0h.js.map +0 -1
  48. package/dist/serialize-utils-CjTqQivB.cjs.map +0 -1
@@ -57,8 +57,8 @@ export declare class CborTextString extends CborItem {
57
57
  end: number;
58
58
  }[];
59
59
  });
60
- _isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean): boolean;
60
+ _isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean, _path?: readonly unknown[]): boolean;
61
61
  _encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
62
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
62
+ _toCDN(options: ToCDNOptions | undefined, depth: number, _path?: readonly unknown[]): string;
63
63
  _toJS(_options?: ToJSOptions): unknown;
64
64
  }
@@ -17,6 +17,6 @@ export declare class CborUint extends CborItem {
17
17
  ednSource?: string;
18
18
  });
19
19
  _encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
20
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
20
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, _path?: readonly unknown[]): string;
21
21
  _toJS(options?: ToJSOptions): unknown;
22
22
  }
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-C1f7G0AM.cjs");exports.CborArray=e.E,exports.CborBigNint=e._,exports.CborBigUint=e.v,exports.CborByteString=e.k,exports.CborEmbeddedCBOR=e.C,exports.CborFloat=e.j,exports.CborIndefiniteByteString=e.O,exports.CborIndefiniteTextString=e.D,exports.CborItem=e.F,exports.CborMap=e.T,exports.CborNint=e.N,exports.CborSimple=e.w,exports.CborTag=e.A,exports.CborTextString=e.h,exports.CborUint=e.P;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-CZZJScaj.cjs");exports.CborArray=e.E,exports.CborBigNint=e._,exports.CborBigUint=e.v,exports.CborByteString=e.k,exports.CborEmbeddedCBOR=e.C,exports.CborFloat=e.j,exports.CborIndefiniteByteString=e.O,exports.CborIndefiniteTextString=e.D,exports.CborItem=e.F,exports.CborMap=e.T,exports.CborNint=e.N,exports.CborSimple=e.w,exports.CborTag=e.A,exports.CborTextString=e.h,exports.CborUint=e.P;
package/dist/ast/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { A as e, C as t, D as n, E as r, F as i, N as a, O as o, P as s, T as c, _ as l, h as u, j as d, k as f, v as p, w as m } from "../mapEntries-CvLdiN0h.js";
1
+ import { A as e, C as t, D as n, E as r, F as i, N as a, O as o, P as s, T as c, _ as l, h as u, j as d, k as f, v as p, w as m } from "../mapEntries-CCLaJSaJ.js";
2
2
  export { r as CborArray, l as CborBigNint, p as CborBigUint, f as CborByteString, t as CborEmbeddedCBOR, d as CborFloat, o as CborIndefiniteByteString, n as CborIndefiniteTextString, i as CborItem, c as CborMap, a as CborNint, m as CborSimple, e as CborTag, u as CborTextString, s as CborUint };
@@ -1,3 +1,3 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../schema-iXpYtKQl.cjs");function t(e,t){let n=Math.max(0,Math.min(t,e.length)),r=1,i=0;for(let t=0;t<n;t++)e.charCodeAt(t)===10&&(r++,i=t+1);return{line:r,column:n-i+1}}var n=class{static compile(t,n){return e.n(t,n)}};function r(t){let n=new e.o(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function i(t){let n=new e.o(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.l?i:new e.l(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../schema-zsg5yCPK.cjs");function t(e,t){let n=Math.max(0,Math.min(t,e.length)),r=1,i=0;for(let t=0;t<n;t++)e.charCodeAt(t)===10&&(r++,i=t+1);return{line:r,column:n-i+1}}var n=class{static compile(t,n){return e.n(t,n)}};function r(t){let n=new e.o(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function i(t){let n=new e.o(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.l?i:new e.l(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
2
2
  `?(e++,n=1):n++;r.push({type:`ERROR`,value:t.slice(o),raw:t.slice(o),line:e,col:n,offset:o,endOffset:t.length})}return{tokens:r,comments:n.comments,error:a}}}exports.CDDL=n,exports.default=n,exports.CddlMismatchError=e.s,exports.CddlSchema=e.t,exports.CddlSemanticError=e.c,exports.CddlSyntaxError=e.l,exports.PRELUDE_CDDL=e.r,exports.getPreludeRules=e.i,exports.parseCDDL=e.a,exports.positionAt=t,exports.tokenize=r,exports.tokenizeLenient=i;
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "../schema-CNfrVRYp.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "../schema-DN9inJny.js";
2
2
  //#region src/cddl/position.ts
3
3
  function l(e, t) {
4
4
  let n = Math.max(0, Math.min(t, e.length)), r = 1, i = 0;
@@ -1,3 +1,3 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../serialize-utils-CjTqQivB.cjs");function t(t){let n=new e.A(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function n(t){let n=new e.A(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.I?i:new e.I(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../serialize-utils-DhlW61ZX.cjs");function t(t){let n=new e.A(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function n(t){let n=new e.A(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.I?i:new e.I(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
2
2
  `?(e++,n=1):n++;r.push({type:`ERROR`,value:t.slice(o),raw:t.slice(o),line:e,col:n,offset:o,endOffset:t.length})}return{tokens:r,comments:n.comments,error:a}}}exports.CdnSyntaxError=e.I,exports.adjustAppSeqIndicator=e.t,exports.adjustRawAppSeqSource=e.n,exports.canonicalEncodingWidth=e.r,exports.decideTaggedAppSeqRendering=e.o,exports.resolveEiSuffix=e.C,exports.tokenize=t,exports.tokenizeLenient=n;
3
3
  //# sourceMappingURL=index.cjs.map
package/dist/cdn/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as e, C as t, I as n, n as r, o as i, r as a, t as o } from "../serialize-utils-BuIZPaUc.js";
1
+ import { A as e, C as t, I as n, n as r, o as i, r as a, t as o } from "../serialize-utils-h-CVB9rg.js";
2
2
  //#region src/cdn/index.ts
3
3
  function s(t) {
4
4
  let n = new e(t), r = [];
@@ -210,7 +210,15 @@ export declare function serializeContainer(p: {
210
210
  * this to its encoded content's byte length instead.
211
211
  */
212
212
  canonicalCount?: () => bigint;
213
- hasEntryComments: () => boolean;
213
+ /**
214
+ * Whether entry `i` structurally has any captured comments (parse-time
215
+ * presence only — not whether they'll actually be shown; see `hasComments`
216
+ * in the implementation, which additionally consults `entryOptions(i)` so
217
+ * an entry whose own override hides its comments doesn't force multi-line
218
+ * layout, and an entry whose own override *shows* comments the container's
219
+ * own `preserveComments` would otherwise hide still gets the chance to).
220
+ */
221
+ hasEntryComments: (i: number) => boolean;
214
222
  /** Render entry `i` at child depth (`item` or `key: value`). */
215
223
  renderEntry: (i: number, colSep: string) => string;
216
224
  /**
@@ -257,6 +265,17 @@ export declare function serializeContainer(p: {
257
265
  entryLeadingNode: (i: number) => Commented;
258
266
  /** Pre-formatted trailing comment text for entry `i` (starts with ' ', or ''). */
259
267
  entryTrailing: (i: number, style: 'c-style' | 'cdn-style' | undefined) => string;
268
+ /**
269
+ * Per-entry options for entry `i`'s own comment handling (whether to
270
+ * emit its comments at all, and in which style) — distinct from
271
+ * `options` above, which still governs the container-wide layout
272
+ * decisions (single-line vs multi-line, `hasComments`'s own gate, the
273
+ * container's own dangling comments). Omitted when the caller never
274
+ * resolves per-entry options at all (`toCDN()`'s `itemOptions` isn't in
275
+ * play), in which case every entry falls back to `options` — identical
276
+ * to this parameter not existing.
277
+ */
278
+ entryOptions?: (i: number) => ToCDNOptions | undefined;
260
279
  }): string;
261
280
  /**
262
281
  * Single-child counterpart to `serializeContainer`, for a wrapper that
@@ -277,8 +296,17 @@ export declare function serializeContainer(p: {
277
296
  * rendering, `depth` otherwise (matching a plain value's existing
278
297
  * "transparent" nesting — `tag(content)` doesn't indent `content` an extra
279
298
  * level when there's nothing to justify going multi-line for).
299
+ *
300
+ * `childOptions` — the child's own resolved options, distinct from
301
+ * `options` (the wrapper's) when `toCDN()`'s `itemOptions` has overridden
302
+ * something for the child specifically (see `CborTag._toCDN`) — governs
303
+ * only the child's *own* leading/trailing comments (whether to show them
304
+ * at all, and in which style); `options` still governs whether to go
305
+ * multi-line at all and the wrapper's own dangling comments, the same way
306
+ * `serializeContainer`'s container-wide `options` does for its own
307
+ * dangling comments even when its `entryOptions` resolves per-entry ones.
280
308
  */
281
- export declare function renderSingleChildWithComments(child: Commented, wrapper: Commented, options: ToCDNOptions | undefined, depth: number, renderChild: (childDepth: number) => string, openChar: '(', closeChar: ')'): string;
309
+ export declare function renderSingleChildWithComments(child: Commented, wrapper: Commented, options: ToCDNOptions | undefined, childOptions: ToCDNOptions | undefined, depth: number, renderChild: (childDepth: number) => string, openChar: '(', closeChar: ')'): string;
282
310
  export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex', sqstr?: 'printable-string' | 'string' | 'none'): string;
283
311
  /**
284
312
  * True when `bytes` would render as a bare sqstr literal (`'...'`) under
@@ -11,7 +11,7 @@ export declare const TAG_CRI = 99n;
11
11
  * Falls back to generic array notation if the content cannot be expressed as a URI.
12
12
  */
13
13
  export declare class CborCriExt extends CborArray {
14
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
14
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
15
15
  }
16
16
  /**
17
17
  * tag(99, CRI array) whose toCDN() emits CRI'…' notation.
@@ -19,7 +19,7 @@ export declare class CborCriExt extends CborArray {
19
19
  */
20
20
  export declare class CborTaggedCriExt extends CborTag {
21
21
  constructor(content: CborArray);
22
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
22
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
23
23
  }
24
24
  /**
25
25
  * Create the cri/CRI CborExtension (§3.7 and §6.2.5 of draft-ietf-cbor-edn-literals-27).
@@ -32,7 +32,7 @@ export declare class CborEpochDtExtUint extends CborUint {
32
32
  encodingWidth?: EncodingWidth;
33
33
  ednSource?: string;
34
34
  });
35
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
35
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
36
36
  }
37
37
  /**
38
38
  * Negative epoch timestamp whose toCDN() emits dt'…' notation.
@@ -43,7 +43,7 @@ export declare class CborEpochDtExtNint extends CborNint {
43
43
  encodingWidth?: EncodingWidth;
44
44
  ednSource?: string;
45
45
  });
46
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
46
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
47
47
  }
48
48
  /**
49
49
  * Float epoch timestamp whose toCDN() emits dt'…' notation.
@@ -54,7 +54,7 @@ export declare class CborEpochDtExtFloat extends CborFloat {
54
54
  precision?: 'half' | 'single' | 'double';
55
55
  literalSource?: string;
56
56
  });
57
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
57
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
58
58
  }
59
59
  /**
60
60
  * CBOR tag(1, epoch) whose toCDN() emits DT'…' notation.
@@ -64,7 +64,7 @@ export declare class CborTaggedEpochDtExt extends CborTag {
64
64
  constructor(datetimeOrContent: string | CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat, options?: {
65
65
  encodingWidth?: EncodingWidth;
66
66
  });
67
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
67
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
68
68
  }
69
69
  /**
70
70
  * CBOR tag(1, epoch) whose toJS() returns a plain Date object.
@@ -8,7 +8,7 @@ import { CborArray } from '../ast/CborArray';
8
8
  * Bare IP address byte string whose toCDN() emits ip'…' notation.
9
9
  */
10
10
  export declare class CborIpExt extends CborByteString {
11
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
11
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
12
12
  }
13
13
  /**
14
14
  * Bare IP address prefix (CIDR) whose toCDN() emits ip'…/prefix' notation.
@@ -17,7 +17,7 @@ export declare class CborIpExt extends CborByteString {
17
17
  export declare class CborIpPrefixExt extends CborArray {
18
18
  private readonly _isV4;
19
19
  constructor(prefixLen: number, truncated: Uint8Array, isV4: boolean);
20
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
20
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
21
21
  }
22
22
  /**
23
23
  * CBOR tag(52/54, …) IP address whose toCDN() emits IP'…' notation.
@@ -26,7 +26,7 @@ export declare class CborIpPrefixExt extends CborArray {
26
26
  */
27
27
  export declare class CborTaggedIpExt extends CborTag {
28
28
  constructor(tag: bigint, content: CborItem);
29
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
29
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
30
30
  }
31
31
  /**
32
32
  * Create an ip/IP CborExtension (RFC 9164 / §3.3 of draft-ietf-cbor-edn-literals-27).
@@ -1,5 +1,5 @@
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
@@ -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,4 +1,4 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-CjTqQivB.cjs"),t=require("./schema-iXpYtKQl.cjs"),n=require("./mapEntries-C1f7G0AM.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(`
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
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===`
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';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { D as e, I as t } from "./serialize-utils-BuIZPaUc.js";
2
- import { n, s as r } from "./schema-CNfrVRYp.js";
3
- import { B as i, H as a, L as o, R as s, S as c, V as l, a as u, c as d, d as f, f as p, g as m, i as h, l as g, m as _, n as v, o as y, p as b, r as x, s as S, t as C, u as w, x as T, z as E } from "./mapEntries-CvLdiN0h.js";
1
+ import { D as e, I as t } from "./serialize-utils-h-CVB9rg.js";
2
+ import { n, s as r } from "./schema-DN9inJny.js";
3
+ import { B as i, H as a, L as o, R as s, S as c, V as l, a as u, c as d, d as f, f as p, g as m, i as h, l as g, m as _, n as v, o as y, p as b, r as x, s as S, t as C, u as w, x as T, z as E } from "./mapEntries-CCLaJSaJ.js";
4
4
  //#region src/extensions/same.ts
5
5
  function D(e, t) {
6
6
  if (e.length !== t.length) return !1;