@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.
Files changed (60) hide show
  1. package/README.ja.md +193 -28
  2. package/README.md +196 -29
  3. package/dist/ast/CborAppSeqResult.d.ts +58 -3
  4. package/dist/ast/CborArray.d.ts +2 -2
  5. package/dist/ast/CborByteString.d.ts +17 -1
  6. package/dist/ast/CborEmbeddedCBOR.d.ts +2 -2
  7. package/dist/ast/CborFloat.d.ts +2 -2
  8. package/dist/ast/CborIndefiniteByteString.d.ts +25 -1
  9. package/dist/ast/CborIndefiniteTextString.d.ts +17 -1
  10. package/dist/ast/CborItem.d.ts +340 -10
  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 +30 -3
  14. package/dist/ast/CborTextString.d.ts +3 -2
  15. package/dist/ast/CborUint.d.ts +1 -1
  16. package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
  17. package/dist/ast/index.cjs +1 -1
  18. package/dist/ast/index.js +2 -2
  19. package/dist/cddl/index.cjs +1 -1
  20. package/dist/cddl/index.js +1 -1
  21. package/dist/cdn/index.cjs +2 -2
  22. package/dist/cdn/index.cjs.map +1 -1
  23. package/dist/cdn/index.js +18 -18
  24. package/dist/cdn/index.js.map +1 -1
  25. package/dist/cdn/serialize-utils.d.ts +237 -10
  26. package/dist/cdn/tokenizer.d.ts +12 -11
  27. package/dist/extensions/builtins.d.ts +5 -5
  28. package/dist/extensions/cri.d.ts +4 -4
  29. package/dist/extensions/dt.d.ts +4 -4
  30. package/dist/extensions/ip.d.ts +4 -4
  31. package/dist/extensions/types.d.ts +44 -5
  32. package/dist/index.cjs +3 -3
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +158 -158
  36. package/dist/index.js.map +1 -1
  37. package/dist/{mapEntries-Ci_dppP6.js → mapEntries-CCLaJSaJ.js} +1599 -1275
  38. package/dist/mapEntries-CCLaJSaJ.js.map +1 -0
  39. package/dist/mapEntries-CZZJScaj.cjs +13 -0
  40. package/dist/mapEntries-CZZJScaj.cjs.map +1 -0
  41. package/dist/{schema-y8G5mDIS.js → schema-DN9inJny.js} +294 -294
  42. package/dist/{schema-y8G5mDIS.js.map → schema-DN9inJny.js.map} +1 -1
  43. package/dist/schema-zsg5yCPK.cjs +63 -0
  44. package/dist/{schema-DgnkH0P6.cjs.map → schema-zsg5yCPK.cjs.map} +1 -1
  45. package/dist/serialize-utils-DhlW61ZX.cjs +37 -0
  46. package/dist/serialize-utils-DhlW61ZX.cjs.map +1 -0
  47. package/dist/{tokenizer-N-vAvRdj.js → serialize-utils-h-CVB9rg.js} +636 -358
  48. package/dist/serialize-utils-h-CVB9rg.js.map +1 -0
  49. package/dist/types.d.ts +508 -58
  50. package/dist/utils/base64.d.ts +1 -1
  51. package/dist/utils/hexfloat.d.ts +11 -3
  52. package/dist/utils/strip-comments.d.ts +1 -1
  53. package/package.json +13 -12
  54. package/dist/mapEntries-BJzyBUH5.cjs +0 -13
  55. package/dist/mapEntries-BJzyBUH5.cjs.map +0 -1
  56. package/dist/mapEntries-Ci_dppP6.js.map +0 -1
  57. package/dist/schema-DgnkH0P6.cjs +0 -63
  58. package/dist/tokenizer-BD08xbyd.cjs +0 -36
  59. package/dist/tokenizer-BD08xbyd.cjs.map +0 -1
  60. package/dist/tokenizer-N-vAvRdj.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComment, CborComments, DecodeWarning, ParseWarning } from '../types';
1
+ import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComment, CborComments, DecodeWarning, ParseWarning, ItemContext, ReadonlyToJSNodeOptions, CdnItemContext, ReadonlyToCDNOptions } from '../types';
2
2
  import { CborWriter } from '../cbor/encode';
3
3
  /** @internal One line of an annotated hex dump. */
4
4
  export interface AnnotatedLine {
@@ -19,7 +19,7 @@ export interface AppSeqEncodingEdit {
19
19
  * Original literal features used by the sole item inside a preserved
20
20
  * `prefix<<item>>` source. They let serialization honour an explicitly
21
21
  * disabled sibling `preserve*` option instead of replaying that literal
22
- * verbatim through `preserveAppSequence`.
22
+ * verbatim through `preserveAppPrefix`.
23
23
  */
24
24
  export interface AppSeqSourceFeatures {
25
25
  byteString?: boolean;
@@ -27,6 +27,194 @@ export interface AppSeqSourceFeatures {
27
27
  rawString?: boolean;
28
28
  concatenation?: boolean;
29
29
  }
30
+ /**
31
+ * @internal
32
+ * Cheap upfront check for whether per-node option/extension resolution is
33
+ * needed at all for a given `toJS()` options object. Container nodes use
34
+ * this to choose between the plain `child._toJS(options)` recursion (when
35
+ * `false`, identical cost to before `itemOptions`/`extensions` existed) and
36
+ * `child._toJSChild(options, path, ctx)` (when `true`).
37
+ */
38
+ export declare function needsItemDispatch(options: ToJSOptions | undefined): boolean;
39
+ /**
40
+ * @internal
41
+ * Options for a reviver-driven container's "raw" structural pre-population
42
+ * pass (see `CborArray`/`CborMap.toObject`) — `reviver` removed, everything
43
+ * else (including `itemOptions`/`extensions`) left as-is.
44
+ *
45
+ * This pass's output is never returned to the caller as the final result —
46
+ * every position it computes is unconditionally overwritten by the *real*
47
+ * (revived) pass's own result before `toJS()` returns — but it is not
48
+ * write-only scaffolding either: a `reviver` reads it directly, as `this[j]`
49
+ * for a not-yet-processed sibling `j`, while deciding how to revive an
50
+ * *earlier* sibling (matching `JSON.parse`'s own reviver contract, which
51
+ * this replicates). That value must reflect `itemOptions`/`extensions`
52
+ * exactly as the real pass would — e.g. an `integerAs: 'bigint'` override
53
+ * for position `j` — or a reviver reading `this[j]` would see the wrong
54
+ * type. So `itemOptions`/`extensions` stay active here, unlike `reviver`
55
+ * itself.
56
+ *
57
+ * Running dispatch during this pass is safe only because callers building
58
+ * a child's occurrence for it — `CborArray`/`CborMap.toObject` — insert
59
+ * `RAW_PASS_MARKER` into that occurrence (see `Occurrence`), so its
60
+ * resolutions are filed under a different `DispatchCache` key than the
61
+ * real pass's and can never be reused *by* the real pass, however many
62
+ * ancestor levels apart the two passes are. That distinction matters for
63
+ * more than consistency — a composite (non-scalar) map key is itself
64
+ * revived differently between the two passes (this pass leaves its own
65
+ * nested content entirely unrevived, matching `this[j]`'s contract above;
66
+ * the real pass revives it normally), so a value node whose
67
+ * `ItemContext.path` is built from that key's converted JS value would
68
+ * otherwise see a stale, pre-revival path if the real pass reused this
69
+ * pass's cached decision.
70
+ */
71
+ export declare function withoutReviver(options: ToJSOptions | undefined): ToJSOptions | undefined;
72
+ /**
73
+ * @internal
74
+ * Build the `reviver`-free, `extensions`-copied view of `options` handed
75
+ * to code that must not be able to mutate options actually in effect
76
+ * elsewhere in the tree — `ItemContext.options` and the `options`
77
+ * parameter of `CborExtension.toJS()` — see `ReadonlyToJSNodeOptions`.
78
+ *
79
+ * A plain `{ ...options, reviver: undefined }` spread (as `withoutReviver`
80
+ * does) is not enough here: `extensions`, if present, would still be the
81
+ * *same array* `options.extensions` is, so `.push()`/`.splice()`/etc. on
82
+ * the copy would still mutate the original in place — corrupting it for
83
+ * this node's own later use, its siblings, and the caller. `extensions` is
84
+ * the only field on `ToJSOptions` that's an ordinary mutable container, so
85
+ * it's the only one that needs its own copy here.
86
+ */
87
+ export declare function toReadonlyNodeOptions(options: ToJSOptions): ReadonlyToJSNodeOptions;
88
+ /**
89
+ * @internal
90
+ * Stable, allocation-light identifier for "this occurrence of a node" —
91
+ * used only to key `DispatchCache` lookups, never exposed via
92
+ * `ItemContext`. Built exactly the way `ItemContext.path` is (accumulated
93
+ * from the root, one element per container level, unchanged through a
94
+ * tag/app-sequence wrapper), but from *structural* container positions —
95
+ * an array index, or a map entry's ordinal paired with a `'k'`/`'v'` role
96
+ * tag (see `CborArray`/`CborMap`) — rather than from the JS values `path`
97
+ * is built from.
98
+ *
99
+ * That distinction matters in two ways `path` alone (or even `path` plus
100
+ * only the *immediate* container's identity) does not cover:
101
+ *
102
+ * - A composite (non-scalar) map key re-converts to a *new* array/object
103
+ * every time its JS value is asked for, so two visits to the very same
104
+ * logical position produce `path`s that are structurally equal but not
105
+ * reference-equal at that segment — unusable for matching.
106
+ * - Two different positions can legitimately produce the very same `path`,
107
+ * when duplicate map entries carry equal keys (e.g. two `"a"` entries).
108
+ * - A *container* (not just a leaf) can itself be a shared node instance
109
+ * reused at two positions (e.g. the same `CborArray` placed at two
110
+ * different indices of an outer array). Matching only on `{immediate
111
+ * parent identity, local slot}` — as an earlier version of this type
112
+ * did — correctly distinguishes the *container's own* two occurrences,
113
+ * but not its *descendants'*: each of the shared container's children
114
+ * would resolve `{parent: <the shared container>, slot: <local index>}`
115
+ * identically regardless of which of the container's own two
116
+ * occurrences was being converted, silently conflating them. Chaining
117
+ * the full occurrence from the root — rather than just one level —
118
+ * avoids this: the shared container's own two occurrences differ
119
+ * earlier in the chain, so appending the same local slot to each still
120
+ * yields two different full chains for its children.
121
+ *
122
+ * A local slot only needs to be unique among its own container's direct
123
+ * children — `CborArray` uses the element index (`number`) directly;
124
+ * `CborMap` prefixes a map entry's ordinal with `'k'`/`'v'`
125
+ * (`` `k${i}` ``/`` `v${i}` ``) so a key and its own value, which share an
126
+ * ordinal, don't collide.
127
+ *
128
+ * `RAW_PASS_MARKER` (see below) is the one non-structural element this
129
+ * chain can contain: `CborArray`/`CborMap.toObject` insert it — once,
130
+ * immediately before that level's own local slot — only when building a
131
+ * child's occurrence for their raw structural pre-population pass (see
132
+ * `withoutReviver`), never for the real, revived pass. That's what lets
133
+ * `_toJSChild`'s cache correctly tell apart the *distinct* raw-pass
134
+ * resolutions a single occurrence can otherwise receive when more than one
135
+ * ancestor level forks — e.g. the very same value node visited once
136
+ * through an outer container's own raw pass (before *any* ancestor has
137
+ * revived anything) and once more through a different, inner container's
138
+ * own raw pass nested inside the outer's real pass (after some ancestor,
139
+ * such as a composite map key, *has* already been revived) — two visits
140
+ * that share every structural coordinate yet must not share a cached
141
+ * decision, since what a reviver-sensitive value like that key converts to
142
+ * differs between them (see `DispatchCacheEntry`). A container that isn't
143
+ * itself forking (no `reviver` in its own options, so it takes the plain,
144
+ * unsplit path) never inserts the marker — it simply passes the
145
+ * occurrence chain it was given through unchanged before extending it with
146
+ * its own children's local slots, the same way it always did.
147
+ */
148
+ export type Occurrence = readonly unknown[];
149
+ /**
150
+ * @internal
151
+ * Sentinel inserted into an `Occurrence` chain by `CborArray`/
152
+ * `CborMap.toObject` when building a child's occurrence for their own raw
153
+ * structural pre-population pass — see `Occurrence`'s own note. A
154
+ * dedicated symbol rather than a string/number so it can never collide
155
+ * with an ordinary local slot value (an array index or a `` `k${i}` ``/
156
+ * `` `v${i}` `` map-entry tag).
157
+ */
158
+ export declare const RAW_PASS_MARKER: unique symbol;
159
+ /**
160
+ * @internal
161
+ * The root value's occurrence, for `toJS()`'s own top-level `_toJSChild()`
162
+ * call — empty, the same way `ItemContext.path` is empty at the root. Also
163
+ * used by `CborTag`/`CborAppSeqResult` as a defensive fallback if `_toJS()`
164
+ * is ever invoked without an `occurrence` (only possible via a direct,
165
+ * non-`toJS()` call to `_toJS()`, which the dispatch cache never sees).
166
+ */
167
+ export declare const ROOT_OCCURRENCE: Occurrence;
168
+ /**
169
+ * @internal
170
+ * Cheap upfront check for whether per-node option resolution is needed at
171
+ * all for a given `toCDN()` options object — the `toCDN()` analogue of
172
+ * `needsItemDispatch`.
173
+ */
174
+ export declare function needsCdnItemDispatch(options: ToCDNOptions | undefined): boolean;
175
+ /**
176
+ * @internal
177
+ * Build the copied-`textStringFormat` view of `options` handed to
178
+ * `CdnItemContext.options` — the `toCDN()` analogue of
179
+ * `toReadonlyNodeOptions`; see `ReadonlyToCDNOptions`. Also strips
180
+ * `CDN_OVERRIDE_TRACKER` (see there) — `ctx.options` is documented as
181
+ * reflecting the current *effective options*, so it should never expose an
182
+ * internal, out-of-band bookkeeping key that isn't part of `ToCDNOptions` at
183
+ * all, even though it isn't otherwise observable through any named field.
184
+ */
185
+ export declare function toReadonlyCdnOptions(options: ToCDNOptions): ReadonlyToCDNOptions;
186
+ /**
187
+ * @internal
188
+ * Out-of-band symbol key that lets a caller (currently only
189
+ * `CborAppSeqResult._toCDN`) track, across an entire `_resolveCdnOptions()`
190
+ * subtree, whether `itemOptions` ever actually returned an override —
191
+ * without touching `options.itemOptions` itself.
192
+ *
193
+ * `CborAppSeqResult` needs to know whether its preserved verbatim source is
194
+ * still exactly right after offering `itemOptions` a chance to override one
195
+ * of its descendants (see its own doc). Wrapping `options.itemOptions` in a
196
+ * tracking function was tried first, but that function becomes
197
+ * `ctx.options.itemOptions` for every descendant (`_resolveCdnOptions`
198
+ * builds `ctx.options` from the very `options` it was given) — a pure
199
+ * `itemOptions` callback could tell it apart from the caller's own function
200
+ * by identity, observing a difference between an ordinary subtree and one
201
+ * reached through an app-sequence wrapper that `ctx.options`'s "current
202
+ * effective options" contract never promises.
203
+ *
204
+ * A symbol-keyed property on `options` instead survives every
205
+ * `{...options, ...override}` merge `_resolveCdnOptions` performs exactly
206
+ * the same way `itemOptions` itself does (object spread copies symbol keys
207
+ * too, and by reference — the same tracker box is shared, never cloned, by
208
+ * every node in the subtree), while never being part of the public
209
+ * `ToCDNOptions` shape or observable through any named field — see
210
+ * `toReadonlyCdnOptions`, which explicitly strips it before building
211
+ * `ctx.options`.
212
+ */
213
+ export declare const CDN_OVERRIDE_TRACKER: unique symbol;
214
+ /** @internal Mutable box referenced (never copied) via `CDN_OVERRIDE_TRACKER`. */
215
+ export interface CdnOverrideTrackerBox {
216
+ applied: boolean;
217
+ }
30
218
  /**
31
219
  * Abstract base class for all CBOR AST nodes.
32
220
  *
@@ -63,11 +251,11 @@ export declare abstract class CborItem {
63
251
  */
64
252
  blankLineBefore?: boolean;
65
253
  /**
66
- * Original application-string/-sequence source text — `prefix'...'`,
254
+ * Original app-string/-sequence source text — `prefix'...'`,
67
255
  * `` prefix`...` ``, or `prefix<<...>>` — set by the parser when the
68
256
  * resolving extension declares `preserveAppSeqSource: 'optional'`. A
69
257
  * subclass's own `_toCDN()` override may check this (gated behind
70
- * `ToCDNOptions.preserveAppSequence`) to round-trip the exact original
258
+ * `ToCDNOptions.preserveAppPrefix`) to round-trip the exact original
71
259
  * spelling instead of always regenerating `prefix'...'` notation from the
72
260
  * resolved value. Left `undefined` for nodes not parsed from one of these
73
261
  * forms.
@@ -77,7 +265,7 @@ export declare abstract class CborItem {
77
265
  * Comments contained within `appSeqSource`, with `start`/`end` offsets
78
266
  * relative to that string. These spans allow comment markers to be
79
267
  * converted (or comments to be removed) without regenerating and thereby
80
- * losing the original application-string/-sequence notation.
268
+ * losing the original app-string/-sequence notation.
81
269
  */
82
270
  appSeqComments?: CborComment[];
83
271
  /**
@@ -140,6 +328,57 @@ export declare abstract class CborItem {
140
328
  * `_toCDN()`, which omits `entryIsLeaf` for that reason.
141
329
  */
142
330
  get _containsCdnContainer(): boolean;
331
+ /**
332
+ * @internal
333
+ * True when this node's own text content (a text string, or a byte
334
+ * string that would render as bare sqstr text) has two or more words —
335
+ * `inlineLeafContainers` never collapses a container whose entries hold
336
+ * such a string onto the container's own line, even though the entry
337
+ * itself has no nested array/map, since a multi-word string reads better
338
+ * with room of its own. See `isMultiWordText()`/`isMultiWordByteString()`
339
+ * in `cdn/serialize-utils.ts`. Takes `options` because whether a byte
340
+ * string even renders as text (`'...'`) rather than a prefixed literal
341
+ * (`h'...'`, `b64'...'`, ...) depends on the `sqstr` option.
342
+ *
343
+ * This method deliberately does *not* also cover the "is this (or does
344
+ * it wrap) a prefixed literal" question — a prefixed literal has no word
345
+ * count to check, but still disqualifies under the strict rule (and, per
346
+ * `strict`, is an ordinary leaf under the loose one). That's handled
347
+ * generically elsewhere instead, from the *actual rendered text* rather
348
+ * than predicted from this node's type: `isPrefixedLiteralText` for a
349
+ * bare entry (`serializeContainer` checks it against the already
350
+ * rendered `s`), or `isMultiWordRenderedLiteral` for `CborTag`, which
351
+ * overrides this method entirely to tokenize its own `_toCDN()` output
352
+ * instead of delegating here — necessary because a `CborTag` subclass
353
+ * (`CborTaggedIpExt`, `CborTaggedEpochDtExt`, ...) may override `_toCDN()`
354
+ * to render something that doesn't look like generic `tagNum(content)`
355
+ * notation at all, which a semantic prediction from `this.content` alone
356
+ * could never know about.
357
+ *
358
+ * `strict` (default `true`) is passed down by whichever container's own
359
+ * `_toCDN` directly holds this entry: `true` for the strict rule
360
+ * (`CborArray`/`CborMap`, and `CborIndefiniteTextString`/
361
+ * `CborIndefiniteByteString` too — all four provide `entryIsLeaf`),
362
+ * `false` only for `CborEmbeddedCBOR` (`<<...>>`), the one container
363
+ * whose collapse isn't gated behind `inlineLeafContainers` at all and
364
+ * the only one that omits `entryIsLeaf`. This base implementation and
365
+ * `CborTextString`/`CborByteString`'s overrides ignore `strict` (a text
366
+ * string's, or byte string's own sqstr-text, word count is unaffected by
367
+ * it either way) — only `CborTag` (and, transitively, `CborAppSeqResult`
368
+ * delegating to its inner value) actually consult it.
369
+ *
370
+ * `path` is this entry's own full path (see `CdnItemContext.path`),
371
+ * passed down by the same caller for the same reason `renderEntry`
372
+ * receives it: `CborTag`/`CborAppSeqResult` re-render `this` here (see
373
+ * their own overrides) purely to answer this method's question, and that
374
+ * re-render must resolve any of *its own* descendants' `itemOptions`
375
+ * against the entry's real path — not an empty one — or a descendant
376
+ * several levels inside a tag-wrapped entry could see a different
377
+ * `ctx.path` here than the real render further down gives it. Only
378
+ * `CborTag`/`CborAppSeqResult` consult it; every other override ignores
379
+ * it, the same as `strict`.
380
+ */
381
+ _isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean, _path?: readonly unknown[]): boolean;
143
382
  /** Serialize this node to CBOR binary. */
144
383
  toCBOR(options?: ToCBOROptions): Uint8Array;
145
384
  /** Serialize this node to a CDN text string. */
@@ -206,17 +445,108 @@ export declare abstract class CborItem {
206
445
  * @internal
207
446
  * Depth-aware CDN serialization.
208
447
  * Leaf nodes receive `depth` but may ignore it.
209
- * Container nodes use `depth` for indentation and call
210
- * `child._toCDN(options, depth + 1)` when recursing.
448
+ * Container nodes use `depth` for indentation and, when recursing, must
449
+ * resolve each child's options via `child._resolveCdnOptions()` first
450
+ * (rather than passing `options` straight through) so `itemOptions` is
451
+ * honored for every node, not just the root — see `_resolveCdnOptions`.
452
+ * `path` is this node's own full path from the root (see
453
+ * `CdnItemContext.path`); only meaningful when `needsCdnItemDispatch()`
454
+ * is `true` for the options in effect — leaf implementations that don't
455
+ * recurse can ignore it, as can any implementation when dispatch isn't
456
+ * in play.
211
457
  */
212
- abstract _toCDN(options: ToCDNOptions | undefined, depth: number): string;
458
+ abstract _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
459
+ /**
460
+ * @internal
461
+ * Resolve `options.itemOptions` for this node (if any), returning the
462
+ * options a caller should use for both this node's own `_toCDN()` call
463
+ * and (via `_isMultiWordText()`) any layout probe of it — see
464
+ * `CdnItemContext`. Unlike `toJS()`'s `_toJSChild()`, this never caches:
465
+ * see the "toCDN() per-item dispatch" note above `needsCdnItemDispatch`
466
+ * for why that's both unnecessary and, per this codebase's own prior
467
+ * experience with `CborTag._isMultiWordText`, unsafe here specifically.
468
+ *
469
+ * `ctx` follows the same "no `key`, derived from `path`'s last element"
470
+ * convention `_toJSChild()` uses (see there) — a caller passes
471
+ * `parent`/`keyNode`/`isMapKey` only; `key` is filled in here.
472
+ */
473
+ _resolveCdnOptions(options: ToCDNOptions | undefined, path: readonly unknown[], ctx: Omit<CdnItemContext, 'path' | 'key' | 'options'>): ToCDNOptions | undefined;
213
474
  /**
214
475
  * @internal
215
476
  * Core conversion logic implemented by each subclass.
216
- * Container nodes apply `options.reviver` to their direct children.
477
+ * Container nodes apply `options.reviver` to their direct children, and
478
+ * must recurse via `child._toJSChild()` (never `child._toJS()` directly)
479
+ * so that `options.itemOptions`/`options.extensions` are honored for
480
+ * every node, not just the root — see `_toJSChild`.
481
+ * `path` is this node's own full path from the root (see `ItemContext.path`);
482
+ * only meaningful, and only ever non-empty, when `needsItemDispatch()` is
483
+ * `true` for the options in effect — leaf implementations that don't
484
+ * recurse can ignore it. `occurrence` is this node's own cache-matching
485
+ * identity (see `Occurrence`) — `CborArray`/`CborMap` build on it to
486
+ * derive their children's own occurrences, and `CborTag`/`CborAppSeqResult`
487
+ * pass it through unchanged to their content's `_toJSChild()` call; leaf
488
+ * implementations that don't recurse can ignore it.
217
489
  * Do not call this directly — use `toJS()` instead.
218
490
  */
219
- abstract _toJS(options?: ToJSOptions): unknown;
491
+ abstract _toJS(options?: ToJSOptions, path?: readonly unknown[], occurrence?: Occurrence): unknown;
492
+ /**
493
+ * @internal
494
+ * Entry point container nodes must use when recursing into a child during
495
+ * `toJS()`, instead of calling `child._toJS(options)` directly, so that
496
+ * `options.itemOptions` and `options.extensions` (toJS hooks) are honored
497
+ * for every node in the tree, not just the root.
498
+ *
499
+ * Guarded by `needsItemDispatch()` at each call site rather than
500
+ * internally, so that containers can skip straight to the cheap
501
+ * `child._toJS(options)` call — matching pre-`itemOptions` behavior
502
+ * exactly, with no extra allocation — whenever neither option is in play
503
+ * for the whole conversion.
504
+ *
505
+ * `path` is this child's own full path from the root, already computed by
506
+ * the caller: `[...parentPath, key]` for an array element or map
507
+ * entry/key, or the parent's own `path` unchanged for a transparent
508
+ * wrapper's content (`CborTag`, `CborAppSeqResult`) — see
509
+ * `ItemContext.path`. `ctx.key` is *not* supplied by the caller — it's
510
+ * derived here from `path`'s own last element (or left `undefined` for
511
+ * the root and for `isMapKey` visits), which is what keeps a wrapper's
512
+ * content correctly reporting its outer key: since `CborTag`/
513
+ * `CborAppSeqResult` pass their own unmodified `path` straight through,
514
+ * that derivation naturally recovers the tag's own key for its content
515
+ * too, matching `ItemContext.key`'s documented invariant of always
516
+ * equalling `path`'s last element outside those two exceptions.
517
+ *
518
+ * `occurrence` identifies this child's position for cache-matching
519
+ * purposes only (see `Occurrence`) — deliberately separate from `path`,
520
+ * which is built from *converted JS values* and so is unreliable for
521
+ * that: matching on `path` alone either double-resolves the same position
522
+ * (a composite map key converts to a fresh, non-`===` array/object every
523
+ * time) or wrongly conflates two different positions that happen to
524
+ * convert to equal `path`s (duplicate map entries with equal keys).
525
+ * `occurrence` avoids both by construction — see `Occurrence`.
526
+ *
527
+ * A single node can be visited more than once *at the same occurrence* in
528
+ * one `toJS()` call — a `reviver`-driven `CborArray`/`CborMap` converts
529
+ * each child once to pre-populate an unrevived holder and once more to
530
+ * compute the revived value (see their own `_toJS()`), and either pass
531
+ * may itself recurse through a `CborTag`/`CborAppSeqResult` wrapper that
532
+ * adds no occurrence of its own (content shares the wrapper's). The raw
533
+ * pre-population pass's own occurrence for a child is distinguished from
534
+ * the real pass's by `RAW_PASS_MARKER` (see `Occurrence`), so that even
535
+ * distinct, *nested* raw passes reaching the same node — one from an
536
+ * outer container's own split, one from a different, inner container's
537
+ * own split nested inside the outer's real pass — resolve independently
538
+ * rather than colliding with each other. Neither `options.itemOptions`
539
+ * nor an `extensions` `toJS()` hook may run more than once for the same
540
+ * occurrence despite all that, since either may be stateful — so the
541
+ * *decision* (not the reviver-dependent application of an `itemOptions`
542
+ * override — see `DispatchOutcome`) is cached in `options`'s dispatch
543
+ * cache, when one is present, and reused on a later visit to that exact
544
+ * occurrence. A node *reused* at more than one occurrence (the same
545
+ * `CborItem` instance placed at two positions in a hand-built tree)
546
+ * still resolves once per occurrence, never conflating two different
547
+ * ones.
548
+ */
549
+ _toJSChild(options: ToJSOptions | undefined, path: readonly unknown[], occurrence: Occurrence, ctx: Omit<ItemContext, 'path' | 'key' | 'options'>): unknown;
220
550
  /**
221
551
  * @internal
222
552
  * Collect annotated-hex lines for this node.
@@ -12,7 +12,7 @@ export declare class CborMap extends CborItem {
12
12
  });
13
13
  get _containsCdnContainer(): boolean;
14
14
  _encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
15
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
15
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
16
16
  _toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
17
- _toJS(options?: ToJSOptions): unknown;
17
+ _toJS(options?: ToJSOptions, path?: readonly unknown[], occurrence?: readonly unknown[]): unknown;
18
18
  }
@@ -31,6 +31,6 @@ export declare class CborNint extends CborItem {
31
31
  /** The actual decoded negative value (−1 − argument). */
32
32
  get value(): bigint;
33
33
  _encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
34
- _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
34
+ _toCDN(options: ToCDNOptions | undefined, _depth: number, _path?: readonly unknown[]): string;
35
35
  _toJS(options?: ToJSOptions): unknown;
36
36
  }
@@ -1,5 +1,5 @@
1
1
  import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
2
- import { CborItem, AnnotatedLine } from './CborItem';
2
+ import { CborItem, AnnotatedLine, Occurrence } from './CborItem';
3
3
  import { CborWriter, EncodingWidth } from '../cbor/encode';
4
4
  /** CBOR Major Type 6 — tagged data item. */
5
5
  export declare class CborTag extends CborItem {
@@ -18,8 +18,35 @@ export declare class CborTag extends CborItem {
18
18
  ednSource?: string;
19
19
  });
20
20
  get _containsCdnContainer(): boolean;
21
+ /**
22
+ * Checked by tokenizing `this._toCDN()`'s own actual output — not by
23
+ * delegating to `this.content._isMultiWordText()` (a semantic prediction
24
+ * from the AST) — because a subclass may override `_toCDN()` to render
25
+ * something that doesn't match generic `tagNum(content)` notation at all
26
+ * (`CborTaggedIpExt` renders `IP<<'192.0.2.42'>>`, `CborTaggedEpochDtExt`
27
+ * renders `DT'...'`/`DT<<...>>`, ...); a check based on `this.content`
28
+ * would be looking at the wrong thing entirely for those. Tokenizing the
29
+ * real output instead is exact regardless of which class produced it —
30
+ * see `isMultiWordRenderedLiteral`, which also handles the plain,
31
+ * generic-tag case (peeling `tagNum[_EI](...)` to see what's inside, so
32
+ * `100(dt'...')` and `100("two words")` still work the same as before).
33
+ *
34
+ * Deliberately *not* cached: an earlier version cached this render on
35
+ * the instance keyed by `options` reference alone, which was wrong two
36
+ * ways — (1) `preserveConcatenation`'s continuation-line indentation
37
+ * *does* depend on depth even for leaf content, so a render cached at
38
+ * depth 0 here and reused by `_toCDN`'s real render at a different depth
39
+ * produced under-indented continuation lines; (2) the cache persisted
40
+ * on the node forever and was keyed only by object identity, so
41
+ * mutating the same `options` object between two `toCDN()` calls
42
+ * silently returned the first call's stale result. `this` is re-rendered
43
+ * here and again by the real `_toCDN` call from whatever holds this
44
+ * entry — an accepted, narrow cost (only tag-wrapped entries reach this
45
+ * at all).
46
+ */
47
+ _isMultiWordText(options: ToCDNOptions | undefined, strict?: boolean, path?: readonly unknown[]): boolean;
21
48
  _encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
22
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
49
+ _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
23
50
  _toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
24
- _toJS(options?: ToJSOptions): unknown;
51
+ _toJS(options?: ToJSOptions, path?: readonly unknown[], occurrence?: Occurrence): unknown;
25
52
  }
@@ -25,7 +25,7 @@ export declare class CborTextString extends CborItem {
25
25
  /**
26
26
  * `true` at index `i`, aligned with `ednParts`, when that part came from a
27
27
  * byte-string literal on the right of a text-leading `+` concatenation
28
- * (decoded as UTF-8 and merged in per §5.1) rather than a double-quoted
28
+ * (decoded as UTF-8 and merged in per draft-25 §5.1) rather than a double-quoted
29
29
  * `"..."` literal. Both cases leave `ednPartSources[i]` `undefined` (byte
30
30
  * strings have no preserved raw source here, same as an unpreserved
31
31
  * double-quoted literal), so this is what lets `appSeqSourceFeatures`
@@ -57,7 +57,8 @@ export declare class CborTextString extends CborItem {
57
57
  end: number;
58
58
  }[];
59
59
  });
60
+ _isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean, _path?: readonly unknown[]): boolean;
60
61
  _encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
61
- _toCDN(options: ToCDNOptions | undefined, depth: number): string;
62
+ _toCDN(options: ToCDNOptions | undefined, depth: number, _path?: readonly unknown[]): string;
62
63
  _toJS(_options?: ToJSOptions): unknown;
63
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,10 +1,10 @@
1
1
  import { ToCDNOptions } from '../types';
2
2
  import { CborTag } from './CborTag';
3
3
  import { CborItem } from './CborItem';
4
- /** Provisional tag number for the Unresolved Application-Extension stand-in. */
4
+ /** Provisional tag number for the Unresolved App-Extension stand-in. */
5
5
  export declare const CPA999_TAG = 999n;
6
6
  /**
7
- * Stand-in for an unrecognised EDN application-extension literal.
7
+ * Stand-in for an unrecognised EDN app-extension literal.
8
8
  *
9
9
  * Structure:
10
10
  * App-string: CPA999([prefix, text])
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-BJzyBUH5.cjs");exports.CborArray=e.D,exports.CborBigNint=e._,exports.CborBigUint=e.v,exports.CborByteString=e.A,exports.CborEmbeddedCBOR=e.w,exports.CborFloat=e.M,exports.CborIndefiniteByteString=e.k,exports.CborIndefiniteTextString=e.O,exports.CborItem=e.I,exports.CborMap=e.E,exports.CborNint=e.P,exports.CborSimple=e.T,exports.CborTag=e.j,exports.CborTextString=e.h,exports.CborUint=e.F;
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, D as t, E as n, F as r, I as i, M 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-Ci_dppP6.js";
2
- export { t as CborArray, l as CborBigNint, p as CborBigUint, e as CborByteString, m as CborEmbeddedCBOR, a as CborFloat, f as CborIndefiniteByteString, o as CborIndefiniteTextString, i as CborItem, n as CborMap, s as CborNint, c as CborSimple, d as CborTag, u as CborTextString, r as CborUint };
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
+ 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-DgnkH0P6.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-y8G5mDIS.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("../tokenizer-BD08xbyd.cjs");function t(t){let n=new e.t(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.t(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.D?i:new e.D(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
- `?(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.D,exports.adjustAppSeqIndicator=e.n,exports.adjustRawAppSeqSource=e.r,exports.canonicalEncodingWidth=e.i,exports.decideTaggedAppSeqRendering=e.s,exports.resolveEiSuffix=e._,exports.tokenize=t,exports.tokenizeLenient=n;
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
+ `?(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
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/cdn/index.ts"],"sourcesContent":["/**\n * Public lower-level CDN tokenization and serialization API\n * (`@cbortech/cbor/cdn`).\n *\n * Exposes the same lexer the parser uses, so tooling such as syntax\n * highlighters stays in exact agreement with parsing behavior. Also exposes\n * the `preserveAppSequence` source-preservation primitives that the built-in\n * `dt`/`ip`/`cri` extensions use, so a third-party `CborExtension` whose\n * result has its own dedicated notation (regenerated from a resolved value,\n * the way `dt'...'`/`ip'...'`/`cri'...'` do) can support `preserveAppSequence`\n * too, instead of always discarding the original `` prefix`...` ``,\n * non-canonical `prefix'...'`, or raw-tag `N(...)` source spelling. See the\n * `dt`/`ip`/`cri` extension sources for the pattern these are meant to be\n * used in.\n */\n\nimport { Tokenizer, type Token, type EdnComment } from './tokenizer';\nimport { CdnSyntaxError } from './errors';\n\nexport type { Token, TokenType, EdnComment } from './tokenizer';\nexport { CdnSyntaxError } from './errors';\n\nexport {\n resolveEiSuffix,\n canonicalEncodingWidth,\n decideTaggedAppSeqRendering,\n adjustRawAppSeqSource,\n adjustAppSeqIndicator,\n} from './serialize-utils';\nexport type { AppSeqRenderDecision } from './serialize-utils';\n\nexport interface TokenizeResult {\n /** Scanned tokens in source order, excluding the final EOF token. */\n tokens: Token[];\n /** Comments encountered while scanning, in source order. */\n comments: EdnComment[];\n}\n\nexport interface TokenizeLenientResult extends TokenizeResult {\n /**\n * The scan failure, if any. When set, `tokens` ends with a synthetic\n * `ERROR` token covering the source from the last clean token to the end\n * of the input.\n */\n error?: CdnSyntaxError;\n}\n\n/**\n * Tokenize CDN text. Throws {@link CdnSyntaxError} on invalid input.\n */\nexport function tokenize(text: string): TokenizeResult {\n const tokenizer = new Tokenizer(text);\n const tokens: Token[] = [];\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n}\n\n/**\n * Error-tolerant tokenization for editors and highlighters: never throws on\n * invalid input. Tokens before the failure are returned as scanned; the\n * remainder of the input is covered by a single synthetic `ERROR` token and\n * the failure is reported in `error`.\n */\nexport function tokenizeLenient(text: string): TokenizeLenientResult {\n const tokenizer = new Tokenizer(text);\n const tokens: Token[] = [];\n try {\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n } catch (e) {\n const error =\n e instanceof CdnSyntaxError\n ? e\n : new CdnSyntaxError(e instanceof Error ? e.message : String(e));\n const start = tokenizer.lastEndOffset;\n if (start < text.length) {\n let line = 1;\n let col = 1;\n for (let i = 0; i < start; i++) {\n if (text[i] === '\\n') {\n line++;\n col = 1;\n } else {\n col++;\n }\n }\n tokens.push({\n type: 'ERROR',\n value: text.slice(start),\n raw: text.slice(start),\n line,\n col,\n offset: start,\n endOffset: text.length,\n });\n }\n return { tokens, comments: tokenizer.comments, error };\n }\n}\n"],"mappings":"gHAkDA,SAAgB,EAAS,EAA8B,CACrD,IAAM,EAAY,IAAI,EAAA,EAAU,CAAI,EAC9B,EAAkB,CAAC,EACzB,OAAS,CACP,IAAM,EAAM,EAAU,QAAQ,EAC9B,GAAI,EAAI,OAAS,MAAO,MACxB,EAAO,KAAK,CAAG,CACjB,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,QAAS,CAChD,CAQA,SAAgB,EAAgB,EAAqC,CACnE,IAAM,EAAY,IAAI,EAAA,EAAU,CAAI,EAC9B,EAAkB,CAAC,EACzB,GAAI,CACF,OAAS,CACP,IAAM,EAAM,EAAU,QAAQ,EAC9B,GAAI,EAAI,OAAS,MAAO,MACxB,EAAO,KAAK,CAAG,CACjB,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,QAAS,CAChD,OAAS,EAAG,CACV,IAAM,EACJ,aAAa,EAAA,EACT,EACA,IAAI,EAAA,EAAe,aAAa,MAAQ,EAAE,QAAU,OAAO,CAAC,CAAC,EAC7D,EAAQ,EAAU,cACxB,GAAI,EAAQ,EAAK,OAAQ,CACvB,IAAI,EAAO,EACP,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,IACrB,EAAK,KAAO;GACd,IACA,EAAM,GAEN,IAGJ,EAAO,KAAK,CACV,KAAM,QACN,MAAO,EAAK,MAAM,CAAK,EACvB,IAAK,EAAK,MAAM,CAAK,EACrB,OACA,MACA,OAAQ,EACR,UAAW,EAAK,MAClB,CAAC,CACH,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,SAAU,OAAM,CACvD,CACF"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/cdn/index.ts"],"sourcesContent":["/**\n * Public lower-level CDN tokenization and serialization API\n * (`@cbortech/cbor/cdn`).\n *\n * Exposes the same lexer the parser uses, so tooling such as syntax\n * highlighters stays in exact agreement with parsing behavior. Also exposes\n * the `preserveAppSeqSource` source-preservation primitives that the built-in\n * `dt`/`ip`/`cri` extensions use, so a third-party `CborExtension` whose\n * result has its own dedicated notation (regenerated from a resolved value,\n * the way `dt'...'`/`ip'...'`/`cri'...'` do) can support `preserveAppSeqSource`\n * too, instead of always discarding the original `` prefix`...` ``,\n * non-canonical `prefix'...'`, or raw-tag `N(...)` source spelling. See the\n * `dt`/`ip`/`cri` extension sources for the pattern these are meant to be\n * used in.\n */\n\nimport { Tokenizer, type Token, type EdnComment } from './tokenizer';\nimport { CdnSyntaxError } from './errors';\n\nexport type { Token, TokenType, EdnComment } from './tokenizer';\nexport { CdnSyntaxError } from './errors';\n\nexport {\n resolveEiSuffix,\n canonicalEncodingWidth,\n decideTaggedAppSeqRendering,\n adjustRawAppSeqSource,\n adjustAppSeqIndicator,\n} from './serialize-utils';\nexport type { AppSeqRenderDecision } from './serialize-utils';\n\nexport interface TokenizeResult {\n /** Scanned tokens in source order, excluding the final EOF token. */\n tokens: Token[];\n /** Comments encountered while scanning, in source order. */\n comments: EdnComment[];\n}\n\nexport interface TokenizeLenientResult extends TokenizeResult {\n /**\n * The scan failure, if any. When set, `tokens` ends with a synthetic\n * `ERROR` token covering the source from the last clean token to the end\n * of the input.\n */\n error?: CdnSyntaxError;\n}\n\n/**\n * Tokenize CDN text. Throws {@link CdnSyntaxError} on invalid input.\n */\nexport function tokenize(text: string): TokenizeResult {\n const tokenizer = new Tokenizer(text);\n const tokens: Token[] = [];\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n}\n\n/**\n * Error-tolerant tokenization for editors and highlighters: never throws on\n * invalid input. Tokens before the failure are returned as scanned; the\n * remainder of the input is covered by a single synthetic `ERROR` token and\n * the failure is reported in `error`.\n */\nexport function tokenizeLenient(text: string): TokenizeLenientResult {\n const tokenizer = new Tokenizer(text);\n const tokens: Token[] = [];\n try {\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n } catch (e) {\n const error =\n e instanceof CdnSyntaxError\n ? e\n : new CdnSyntaxError(e instanceof Error ? e.message : String(e));\n const start = tokenizer.lastEndOffset;\n if (start < text.length) {\n let line = 1;\n let col = 1;\n for (let i = 0; i < start; i++) {\n if (text[i] === '\\n') {\n line++;\n col = 1;\n } else {\n col++;\n }\n }\n tokens.push({\n type: 'ERROR',\n value: text.slice(start),\n raw: text.slice(start),\n line,\n col,\n offset: start,\n endOffset: text.length,\n });\n }\n return { tokens, comments: tokenizer.comments, error };\n }\n}\n"],"mappings":"sHAkDA,SAAgB,EAAS,EAA8B,CACrD,IAAM,EAAY,IAAI,EAAA,EAAU,CAAI,EAC9B,EAAkB,CAAC,EACzB,OAAS,CACP,IAAM,EAAM,EAAU,QAAQ,EAC9B,GAAI,EAAI,OAAS,MAAO,MACxB,EAAO,KAAK,CAAG,CACjB,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,QAAS,CAChD,CAQA,SAAgB,EAAgB,EAAqC,CACnE,IAAM,EAAY,IAAI,EAAA,EAAU,CAAI,EAC9B,EAAkB,CAAC,EACzB,GAAI,CACF,OAAS,CACP,IAAM,EAAM,EAAU,QAAQ,EAC9B,GAAI,EAAI,OAAS,MAAO,MACxB,EAAO,KAAK,CAAG,CACjB,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,QAAS,CAChD,OAAS,EAAG,CACV,IAAM,EACJ,aAAa,EAAA,EACT,EACA,IAAI,EAAA,EAAe,aAAa,MAAQ,EAAE,QAAU,OAAO,CAAC,CAAC,EAC7D,EAAQ,EAAU,cACxB,GAAI,EAAQ,EAAK,OAAQ,CACvB,IAAI,EAAO,EACP,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,IACrB,EAAK,KAAO;GACd,IACA,EAAM,GAEN,IAGJ,EAAO,KAAK,CACV,KAAM,QACN,MAAO,EAAK,MAAM,CAAK,EACvB,IAAK,EAAK,MAAM,CAAK,EACrB,OACA,MACA,OAAQ,EACR,UAAW,EAAK,MAClB,CAAC,CACH,CACA,MAAO,CAAE,SAAQ,SAAU,EAAU,SAAU,OAAM,CACvD,CACF"}
package/dist/cdn/index.js CHANGED
@@ -1,35 +1,35 @@
1
- import { D as e, _ as t, i as n, n as r, r as i, s as a, t as o } from "../tokenizer-N-vAvRdj.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
- function s(e) {
4
- let t = new o(e), n = [];
3
+ function s(t) {
4
+ let n = new e(t), r = [];
5
5
  for (;;) {
6
- let e = t.consume();
6
+ let e = n.consume();
7
7
  if (e.type === "EOF") break;
8
- n.push(e);
8
+ r.push(e);
9
9
  }
10
10
  return {
11
- tokens: n,
12
- comments: t.comments
11
+ tokens: r,
12
+ comments: n.comments
13
13
  };
14
14
  }
15
15
  function c(t) {
16
- let n = new o(t), r = [];
16
+ let r = new e(t), i = [];
17
17
  try {
18
18
  for (;;) {
19
- let e = n.consume();
19
+ let e = r.consume();
20
20
  if (e.type === "EOF") break;
21
- r.push(e);
21
+ i.push(e);
22
22
  }
23
23
  return {
24
- tokens: r,
25
- comments: n.comments
24
+ tokens: i,
25
+ comments: r.comments
26
26
  };
27
- } catch (i) {
28
- let a = i instanceof e ? i : new e(i instanceof Error ? i.message : String(i)), o = n.lastEndOffset;
27
+ } catch (e) {
28
+ let a = e instanceof n ? e : new n(e instanceof Error ? e.message : String(e)), o = r.lastEndOffset;
29
29
  if (o < t.length) {
30
30
  let e = 1, n = 1;
31
31
  for (let r = 0; r < o; r++) t[r] === "\n" ? (e++, n = 1) : n++;
32
- r.push({
32
+ i.push({
33
33
  type: "ERROR",
34
34
  value: t.slice(o),
35
35
  raw: t.slice(o),
@@ -40,13 +40,13 @@ function c(t) {
40
40
  });
41
41
  }
42
42
  return {
43
- tokens: r,
44
- comments: n.comments,
43
+ tokens: i,
44
+ comments: r.comments,
45
45
  error: a
46
46
  };
47
47
  }
48
48
  }
49
49
  //#endregion
50
- export { e as CdnSyntaxError, r as adjustAppSeqIndicator, i as adjustRawAppSeqSource, n as canonicalEncodingWidth, a as decideTaggedAppSeqRendering, t as resolveEiSuffix, s as tokenize, c as tokenizeLenient };
50
+ export { n as CdnSyntaxError, o as adjustAppSeqIndicator, r as adjustRawAppSeqSource, a as canonicalEncodingWidth, i as decideTaggedAppSeqRendering, t as resolveEiSuffix, s as tokenize, c as tokenizeLenient };
51
51
 
52
52
  //# sourceMappingURL=index.js.map