@cbortech/cbor 0.27.0 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +100 -0
- package/README.md +103 -0
- package/dist/ast/CborAppSeqResult.d.ts +37 -4
- package/dist/ast/CborArray.d.ts +2 -2
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +1 -1
- package/dist/ast/CborFloat.d.ts +1 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +1 -1
- package/dist/ast/CborIndefiniteTextString.d.ts +1 -1
- package/dist/ast/CborItem.d.ts +314 -9
- package/dist/ast/CborMap.d.ts +2 -2
- package/dist/ast/CborNint.d.ts +1 -1
- package/dist/ast/CborTag.d.ts +26 -4
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +1 -1
- package/dist/ast/CborUnresolvedAppExt.d.ts +9 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor/tagLabels.d.ts +26 -0
- package/dist/cddl/eRefScope.d.ts +241 -0
- package/dist/cddl/eref.d.ts +64 -0
- package/dist/cddl/implicitTags.d.ts +28 -0
- package/dist/cddl/index.cjs +2 -2
- package/dist/cddl/index.cjs.map +1 -1
- package/dist/cddl/index.d.ts +2 -0
- package/dist/cddl/index.js +26 -25
- package/dist/cddl/index.js.map +1 -1
- package/dist/cddl/validator.d.ts +98 -2
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +50 -15
- package/dist/extensions/cri.d.ts +2 -2
- package/dist/extensions/dt.d.ts +4 -4
- package/dist/extensions/eref.d.ts +135 -0
- package/dist/extensions/ip.d.ts +3 -3
- package/dist/extensions/types.d.ts +40 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +190 -81
- package/dist/index.js.map +1 -1
- package/dist/js/fromJS.d.ts +23 -1
- package/dist/mapEntries-8zshEr-t.js +7085 -0
- package/dist/mapEntries-8zshEr-t.js.map +1 -0
- package/dist/mapEntries-DwHPAzCN.cjs +68 -0
- package/dist/mapEntries-DwHPAzCN.cjs.map +1 -0
- package/dist/schema-7r2xjpMK.js +345 -0
- package/dist/schema-7r2xjpMK.js.map +1 -0
- package/dist/schema-YiigSWjR.cjs +8 -0
- package/dist/schema-YiigSWjR.cjs.map +1 -0
- package/dist/{serialize-utils-BuIZPaUc.js → serialize-utils-BQtutOo6.js} +70 -52
- package/dist/serialize-utils-BQtutOo6.js.map +1 -0
- package/dist/{serialize-utils-CjTqQivB.cjs → serialize-utils-DQ8T3Mzw.cjs} +9 -9
- package/dist/serialize-utils-DQ8T3Mzw.cjs.map +1 -0
- package/dist/types.d.ts +426 -4
- package/dist/utils/hexfloat.d.ts +10 -2
- package/package.json +13 -14
- package/dist/mapEntries-C1f7G0AM.cjs +0 -13
- package/dist/mapEntries-C1f7G0AM.cjs.map +0 -1
- package/dist/mapEntries-CvLdiN0h.js +0 -3946
- package/dist/mapEntries-CvLdiN0h.js.map +0 -1
- package/dist/schema-CNfrVRYp.js +0 -1977
- package/dist/schema-CNfrVRYp.js.map +0 -1
- package/dist/schema-iXpYtKQl.cjs +0 -63
- package/dist/schema-iXpYtKQl.cjs.map +0 -1
- package/dist/serialize-utils-BuIZPaUc.js.map +0 -1
- package/dist/serialize-utils-CjTqQivB.cjs.map +0 -1
package/dist/ast/CborItem.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -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
|
*
|
|
@@ -153,8 +341,10 @@ export declare abstract class CborItem {
|
|
|
153
341
|
* (`h'...'`, `b64'...'`, ...) depends on the `sqstr` option.
|
|
154
342
|
*
|
|
155
343
|
* This method deliberately does *not* also cover the "is this (or does
|
|
156
|
-
* it wrap) a prefixed literal" question — a
|
|
157
|
-
* count to check,
|
|
344
|
+
* it wrap) a prefixed literal" question — a byte-string literal has no
|
|
345
|
+
* word count to check, and an app-string literal (`dt'...'`) is
|
|
346
|
+
* word-counted from its rendered content, but either disqualifies only
|
|
347
|
+
* under the strict rule (and, per
|
|
158
348
|
* `strict`, is an ordinary leaf under the loose one). That's handled
|
|
159
349
|
* generically elsewhere instead, from the *actual rendered text* rather
|
|
160
350
|
* than predicted from this node's type: `isPrefixedLiteralText` for a
|
|
@@ -178,8 +368,32 @@ export declare abstract class CborItem {
|
|
|
178
368
|
* string's, or byte string's own sqstr-text, word count is unaffected by
|
|
179
369
|
* it either way) — only `CborTag` (and, transitively, `CborAppSeqResult`
|
|
180
370
|
* delegating to its inner value) actually consult it.
|
|
371
|
+
*
|
|
372
|
+
* `path` is this entry's own full path (see `CdnItemContext.path`),
|
|
373
|
+
* passed down by the same caller for the same reason `renderEntry`
|
|
374
|
+
* receives it: `CborTag`/`CborAppSeqResult` re-render `this` here (see
|
|
375
|
+
* their own overrides) purely to answer this method's question, and that
|
|
376
|
+
* re-render must resolve any of *its own* descendants' `itemOptions`
|
|
377
|
+
* against the entry's real path — not an empty one — or a descendant
|
|
378
|
+
* several levels inside a tag-wrapped entry could see a different
|
|
379
|
+
* `ctx.path` here than the real render further down gives it. Only
|
|
380
|
+
* `CborTag`/`CborAppSeqResult` consult it; every other override ignores
|
|
381
|
+
* it, the same as `strict`.
|
|
181
382
|
*/
|
|
182
|
-
_isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean): boolean;
|
|
383
|
+
_isMultiWordText(_options: ToCDNOptions | undefined, _strict?: boolean, _path?: readonly unknown[]): boolean;
|
|
384
|
+
/**
|
|
385
|
+
* @internal
|
|
386
|
+
* Optional override: an alternate plain-string spelling to use as this
|
|
387
|
+
* node's `toJS()` object key, in place of `CborMap.toObject()`'s generic
|
|
388
|
+
* `toCDN()` fallback for a non-text-string key. Returns `undefined` to use
|
|
389
|
+
* that default. The base class implements no such override; a subclass
|
|
390
|
+
* that carries an alternate key spelling for a non-text key (e.g. a CDDL
|
|
391
|
+
* e-ref annotated integer key — see `extensions/eref.ts`) overrides this
|
|
392
|
+
* instead of `CborMap` special-casing that subclass directly. Takes the
|
|
393
|
+
* full `ToJSOptions` (unlike `_toCDN`'s options) since a key-naming choice
|
|
394
|
+
* like e-ref's `eRefKeys` is a `toJS()`-only concept with no CDN analogue.
|
|
395
|
+
*/
|
|
396
|
+
_jsObjectKey(_options: ToJSOptions | undefined): string | undefined;
|
|
183
397
|
/** Serialize this node to CBOR binary. */
|
|
184
398
|
toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
185
399
|
/** Serialize this node to a CDN text string. */
|
|
@@ -246,17 +460,108 @@ export declare abstract class CborItem {
|
|
|
246
460
|
* @internal
|
|
247
461
|
* Depth-aware CDN serialization.
|
|
248
462
|
* Leaf nodes receive `depth` but may ignore it.
|
|
249
|
-
* Container nodes use `depth` for indentation and
|
|
250
|
-
* `child.
|
|
463
|
+
* Container nodes use `depth` for indentation and, when recursing, must
|
|
464
|
+
* resolve each child's options via `child._resolveCdnOptions()` first
|
|
465
|
+
* (rather than passing `options` straight through) so `itemOptions` is
|
|
466
|
+
* honored for every node, not just the root — see `_resolveCdnOptions`.
|
|
467
|
+
* `path` is this node's own full path from the root (see
|
|
468
|
+
* `CdnItemContext.path`); only meaningful when `needsCdnItemDispatch()`
|
|
469
|
+
* is `true` for the options in effect — leaf implementations that don't
|
|
470
|
+
* recurse can ignore it, as can any implementation when dispatch isn't
|
|
471
|
+
* in play.
|
|
251
472
|
*/
|
|
252
|
-
abstract _toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
473
|
+
abstract _toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
474
|
+
/**
|
|
475
|
+
* @internal
|
|
476
|
+
* Resolve `options.itemOptions` for this node (if any), returning the
|
|
477
|
+
* options a caller should use for both this node's own `_toCDN()` call
|
|
478
|
+
* and (via `_isMultiWordText()`) any layout probe of it — see
|
|
479
|
+
* `CdnItemContext`. Unlike `toJS()`'s `_toJSChild()`, this never caches:
|
|
480
|
+
* see the "toCDN() per-item dispatch" note above `needsCdnItemDispatch`
|
|
481
|
+
* for why that's both unnecessary and, per this codebase's own prior
|
|
482
|
+
* experience with `CborTag._isMultiWordText`, unsafe here specifically.
|
|
483
|
+
*
|
|
484
|
+
* `ctx` follows the same "no `key`, derived from `path`'s last element"
|
|
485
|
+
* convention `_toJSChild()` uses (see there) — a caller passes
|
|
486
|
+
* `parent`/`keyNode`/`isMapKey` only; `key` is filled in here.
|
|
487
|
+
*/
|
|
488
|
+
_resolveCdnOptions(options: ToCDNOptions | undefined, path: readonly unknown[], ctx: Omit<CdnItemContext, 'path' | 'key' | 'options'>): ToCDNOptions | undefined;
|
|
253
489
|
/**
|
|
254
490
|
* @internal
|
|
255
491
|
* Core conversion logic implemented by each subclass.
|
|
256
|
-
* Container nodes apply `options.reviver` to their direct children
|
|
492
|
+
* Container nodes apply `options.reviver` to their direct children, and
|
|
493
|
+
* must recurse via `child._toJSChild()` (never `child._toJS()` directly)
|
|
494
|
+
* so that `options.itemOptions`/`options.extensions` are honored for
|
|
495
|
+
* every node, not just the root — see `_toJSChild`.
|
|
496
|
+
* `path` is this node's own full path from the root (see `ItemContext.path`);
|
|
497
|
+
* only meaningful, and only ever non-empty, when `needsItemDispatch()` is
|
|
498
|
+
* `true` for the options in effect — leaf implementations that don't
|
|
499
|
+
* recurse can ignore it. `occurrence` is this node's own cache-matching
|
|
500
|
+
* identity (see `Occurrence`) — `CborArray`/`CborMap` build on it to
|
|
501
|
+
* derive their children's own occurrences, and `CborTag`/`CborAppSeqResult`
|
|
502
|
+
* pass it through unchanged to their content's `_toJSChild()` call; leaf
|
|
503
|
+
* implementations that don't recurse can ignore it.
|
|
257
504
|
* Do not call this directly — use `toJS()` instead.
|
|
258
505
|
*/
|
|
259
|
-
abstract _toJS(options?: ToJSOptions): unknown;
|
|
506
|
+
abstract _toJS(options?: ToJSOptions, path?: readonly unknown[], occurrence?: Occurrence): unknown;
|
|
507
|
+
/**
|
|
508
|
+
* @internal
|
|
509
|
+
* Entry point container nodes must use when recursing into a child during
|
|
510
|
+
* `toJS()`, instead of calling `child._toJS(options)` directly, so that
|
|
511
|
+
* `options.itemOptions` and `options.extensions` (toJS hooks) are honored
|
|
512
|
+
* for every node in the tree, not just the root.
|
|
513
|
+
*
|
|
514
|
+
* Guarded by `needsItemDispatch()` at each call site rather than
|
|
515
|
+
* internally, so that containers can skip straight to the cheap
|
|
516
|
+
* `child._toJS(options)` call — matching pre-`itemOptions` behavior
|
|
517
|
+
* exactly, with no extra allocation — whenever neither option is in play
|
|
518
|
+
* for the whole conversion.
|
|
519
|
+
*
|
|
520
|
+
* `path` is this child's own full path from the root, already computed by
|
|
521
|
+
* the caller: `[...parentPath, key]` for an array element or map
|
|
522
|
+
* entry/key, or the parent's own `path` unchanged for a transparent
|
|
523
|
+
* wrapper's content (`CborTag`, `CborAppSeqResult`) — see
|
|
524
|
+
* `ItemContext.path`. `ctx.key` is *not* supplied by the caller — it's
|
|
525
|
+
* derived here from `path`'s own last element (or left `undefined` for
|
|
526
|
+
* the root and for `isMapKey` visits), which is what keeps a wrapper's
|
|
527
|
+
* content correctly reporting its outer key: since `CborTag`/
|
|
528
|
+
* `CborAppSeqResult` pass their own unmodified `path` straight through,
|
|
529
|
+
* that derivation naturally recovers the tag's own key for its content
|
|
530
|
+
* too, matching `ItemContext.key`'s documented invariant of always
|
|
531
|
+
* equalling `path`'s last element outside those two exceptions.
|
|
532
|
+
*
|
|
533
|
+
* `occurrence` identifies this child's position for cache-matching
|
|
534
|
+
* purposes only (see `Occurrence`) — deliberately separate from `path`,
|
|
535
|
+
* which is built from *converted JS values* and so is unreliable for
|
|
536
|
+
* that: matching on `path` alone either double-resolves the same position
|
|
537
|
+
* (a composite map key converts to a fresh, non-`===` array/object every
|
|
538
|
+
* time) or wrongly conflates two different positions that happen to
|
|
539
|
+
* convert to equal `path`s (duplicate map entries with equal keys).
|
|
540
|
+
* `occurrence` avoids both by construction — see `Occurrence`.
|
|
541
|
+
*
|
|
542
|
+
* A single node can be visited more than once *at the same occurrence* in
|
|
543
|
+
* one `toJS()` call — a `reviver`-driven `CborArray`/`CborMap` converts
|
|
544
|
+
* each child once to pre-populate an unrevived holder and once more to
|
|
545
|
+
* compute the revived value (see their own `_toJS()`), and either pass
|
|
546
|
+
* may itself recurse through a `CborTag`/`CborAppSeqResult` wrapper that
|
|
547
|
+
* adds no occurrence of its own (content shares the wrapper's). The raw
|
|
548
|
+
* pre-population pass's own occurrence for a child is distinguished from
|
|
549
|
+
* the real pass's by `RAW_PASS_MARKER` (see `Occurrence`), so that even
|
|
550
|
+
* distinct, *nested* raw passes reaching the same node — one from an
|
|
551
|
+
* outer container's own split, one from a different, inner container's
|
|
552
|
+
* own split nested inside the outer's real pass — resolve independently
|
|
553
|
+
* rather than colliding with each other. Neither `options.itemOptions`
|
|
554
|
+
* nor an `extensions` `toJS()` hook may run more than once for the same
|
|
555
|
+
* occurrence despite all that, since either may be stateful — so the
|
|
556
|
+
* *decision* (not the reviver-dependent application of an `itemOptions`
|
|
557
|
+
* override — see `DispatchOutcome`) is cached in `options`'s dispatch
|
|
558
|
+
* cache, when one is present, and reused on a later visit to that exact
|
|
559
|
+
* occurrence. A node *reused* at more than one occurrence (the same
|
|
560
|
+
* `CborItem` instance placed at two positions in a hand-built tree)
|
|
561
|
+
* still resolves once per occurrence, never conflating two different
|
|
562
|
+
* ones.
|
|
563
|
+
*/
|
|
564
|
+
_toJSChild(options: ToJSOptions | undefined, path: readonly unknown[], occurrence: Occurrence, ctx: Omit<ItemContext, 'path' | 'key' | 'options'>): unknown;
|
|
260
565
|
/**
|
|
261
566
|
* @internal
|
|
262
567
|
* Collect annotated-hex lines for this node.
|
package/dist/ast/CborMap.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/ast/CborNint.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/ast/CborTag.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -13,6 +13,14 @@ export declare class CborTag extends CborItem {
|
|
|
13
13
|
* (`0x3e7`, decimal, …) when `preserveNumberFormat` is set.
|
|
14
14
|
*/
|
|
15
15
|
ednSource?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Set by `cddl`-validated decoding/parsing/conversion when the schema
|
|
18
|
+
* itself implies this tag at its position (see `cddl/implicitTags.ts`),
|
|
19
|
+
* so `toJS()` can leave it off the JS value — see
|
|
20
|
+
* `ToJSOptions.implicitTags`.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
_implicit: boolean;
|
|
16
24
|
constructor(tag: number | bigint, content: CborItem, options?: {
|
|
17
25
|
encodingWidth?: EncodingWidth;
|
|
18
26
|
ednSource?: string;
|
|
@@ -44,9 +52,23 @@ export declare class CborTag extends CborItem {
|
|
|
44
52
|
* entry — an accepted, narrow cost (only tag-wrapped entries reach this
|
|
45
53
|
* at all).
|
|
46
54
|
*/
|
|
47
|
-
_isMultiWordText(options: ToCDNOptions | undefined, strict?: boolean): boolean;
|
|
55
|
+
_isMultiWordText(options: ToCDNOptions | undefined, strict?: boolean, path?: readonly unknown[]): boolean;
|
|
48
56
|
_encodeTo(writer: CborWriter, options?: ToCBOROptions): void;
|
|
49
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
57
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
58
|
+
/**
|
|
59
|
+
* The hex-dump comment for this tag's head: `Tag N`, followed by an
|
|
60
|
+
* RFC 9277 label when there is one — `Tag 55799 (self-described CBOR)`,
|
|
61
|
+
* `Tag 1668546929 (CoAP Content-Format 112)`, `Tag 1330664270 ("OPSN")`
|
|
62
|
+
* for a protocol-specific tag spelling four printable ASCII characters.
|
|
63
|
+
*/
|
|
64
|
+
hexDumpComment(): string;
|
|
50
65
|
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
51
|
-
_toJS(options?: ToJSOptions): unknown;
|
|
66
|
+
_toJS(options?: ToJSOptions, path?: readonly unknown[], occurrence?: Occurrence): unknown;
|
|
67
|
+
/**
|
|
68
|
+
* Attach this tag to the converted content `value` — unless `stripTags`,
|
|
69
|
+
* or the tag is schema-implied (`_implicit`) and `implicitTags` isn't
|
|
70
|
+
* `false`.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
_tagJS(value: unknown, options?: ToJSOptions): unknown;
|
|
52
74
|
}
|
|
@@ -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
|
}
|
package/dist/ast/CborUint.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -12,5 +12,14 @@ export declare const CPA999_TAG = 999n;
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class CborUnresolvedAppExt extends CborTag {
|
|
14
14
|
constructor(prefix: string, items: CborItem[]);
|
|
15
|
+
/** App-string form (`prefix'text'`), as opposed to an app-sequence. */
|
|
16
|
+
private get _isAppString();
|
|
17
|
+
/**
|
|
18
|
+
* An app-string (`e'alg'`) renders as a plain literal, not the
|
|
19
|
+
* `[prefix, text]` array it wraps, so it's a leaf for
|
|
20
|
+
* `inlineLeafContainers` — word-counted like a text string instead (via
|
|
21
|
+
* `CborTag._isMultiWordText`'s tokenizing of the rendered output).
|
|
22
|
+
*/
|
|
23
|
+
get _containsCdnContainer(): boolean;
|
|
15
24
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
16
25
|
}
|
package/dist/ast/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-DwHPAzCN.cjs");exports.CborArray=e.I,exports.CborBigNint=e.O,exports.CborBigUint=e.k,exports.CborByteString=e.z,exports.CborEmbeddedCBOR=e.N,exports.CborFloat=e.V,exports.CborIndefiniteByteString=e.R,exports.CborIndefiniteTextString=e.L,exports.CborItem=e.W,exports.CborMap=e.F,exports.CborNint=e.H,exports.CborSimple=e.P,exports.CborTag=e.B,exports.CborTextString=e.E,exports.CborUint=e.U;
|
package/dist/ast/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { B as e, E as t, F as n, H as r, I as i, L as a, N as o, O as s, P as c, R as l, U as u, V as d, W as f, k as p, z as m } from "../mapEntries-8zshEr-t.js";
|
|
2
|
+
export { i as CborArray, s as CborBigNint, p as CborBigUint, m as CborByteString, o as CborEmbeddedCBOR, d as CborFloat, l as CborIndefiniteByteString, a as CborIndefiniteTextString, f as CborItem, n as CborMap, r as CborNint, c as CborSimple, e as CborTag, t as CborTextString, u as CborUint };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable labels for tag numbers defined by RFC 9277 (On Stable
|
|
3
|
+
* Storage for Items in CBOR), used to annotate `Tag N` hex-dump comments.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Inverse of RFC 9277 Appendix B's `TN(ct) = 0x63740101 + (ct / 255) *
|
|
7
|
+
* 256 + ct % 255`: returns the CoAP Content-Format number `tag` stands for, or
|
|
8
|
+
* `undefined` when `tag` isn't in that range. The mapping never produces a
|
|
9
|
+
* zero byte, so a tag with a zero in either of its low two bytes isn't one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function coapContentFormatOfTag(tag: bigint): number | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The four ASCII characters spelled by a protocol-specific tag number
|
|
14
|
+
* (RFC 9277 §2.1 encourages a mnemonic of four ASCII codes, e.g.
|
|
15
|
+
* `1330664270` = `0x4F50534E` = `"OPSN"`), or `undefined` when `tag` is
|
|
16
|
+
* outside `0x01000000`..`0xFFFFFFFF` or any byte isn't printable ASCII
|
|
17
|
+
* (`0x20`..`0x7E`).
|
|
18
|
+
*/
|
|
19
|
+
export declare function asciiMnemonicOfTag(tag: bigint): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* RFC 9277 label for `tag`, for a hex-dump comment — `self-described CBOR`,
|
|
22
|
+
* `CoAP Content-Format 112`, `"OPSN"` — or `undefined` when there's none.
|
|
23
|
+
* The CoAP range is checked before the ASCII mnemonic: it is a specific
|
|
24
|
+
* allocation, and its `"ct"` prefix would otherwise read as a mnemonic.
|
|
25
|
+
*/
|
|
26
|
+
export declare function rfc9277TagLabel(tag: bigint): string | undefined;
|