@cbortech/cbor 0.26.8 → 0.27.0
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 +120 -28
- package/README.md +121 -29
- package/dist/ast/CborAppSeqResult.d.ts +22 -0
- package/dist/ast/CborByteString.d.ts +16 -0
- package/dist/ast/CborEmbeddedCBOR.d.ts +1 -1
- package/dist/ast/CborFloat.d.ts +1 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +24 -0
- package/dist/ast/CborIndefiniteTextString.d.ts +16 -0
- package/dist/ast/CborItem.d.ts +44 -4
- package/dist/ast/CborTag.d.ts +27 -0
- package/dist/ast/CborTextString.d.ts +2 -1
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cddl/index.cjs +1 -1
- package/dist/cddl/index.js +1 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.cjs.map +1 -1
- package/dist/cdn/index.js +18 -18
- package/dist/cdn/index.js.map +1 -1
- package/dist/cdn/serialize-utils.d.ts +207 -8
- package/dist/cdn/tokenizer.d.ts +12 -11
- package/dist/extensions/builtins.d.ts +5 -5
- package/dist/extensions/cri.d.ts +2 -2
- package/dist/extensions/ip.d.ts +1 -1
- package/dist/extensions/types.d.ts +4 -4
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -158
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-C1f7G0AM.cjs +13 -0
- package/dist/mapEntries-C1f7G0AM.cjs.map +1 -0
- package/dist/{mapEntries-Ci_dppP6.js → mapEntries-CvLdiN0h.js} +1362 -1219
- package/dist/mapEntries-CvLdiN0h.js.map +1 -0
- package/dist/{schema-y8G5mDIS.js → schema-CNfrVRYp.js} +294 -294
- package/dist/{schema-y8G5mDIS.js.map → schema-CNfrVRYp.js.map} +1 -1
- package/dist/schema-iXpYtKQl.cjs +63 -0
- package/dist/{schema-DgnkH0P6.cjs.map → schema-iXpYtKQl.cjs.map} +1 -1
- package/dist/{tokenizer-N-vAvRdj.js → serialize-utils-BuIZPaUc.js} +626 -358
- package/dist/serialize-utils-BuIZPaUc.js.map +1 -0
- package/dist/serialize-utils-CjTqQivB.cjs +37 -0
- package/dist/serialize-utils-CjTqQivB.cjs.map +1 -0
- package/dist/types.d.ts +235 -58
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/hexfloat.d.ts +1 -1
- package/dist/utils/strip-comments.d.ts +1 -1
- package/package.json +8 -6
- package/dist/mapEntries-BJzyBUH5.cjs +0 -13
- package/dist/mapEntries-BJzyBUH5.cjs.map +0 -1
- package/dist/mapEntries-Ci_dppP6.js.map +0 -1
- package/dist/schema-DgnkH0P6.cjs +0 -63
- package/dist/tokenizer-BD08xbyd.cjs +0 -36
- package/dist/tokenizer-BD08xbyd.cjs.map +0 -1
- package/dist/tokenizer-N-vAvRdj.js.map +0 -1
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { CborComment, CborComments, ToCDNOptions } from '../types';
|
|
2
2
|
import { EncodingWidth } from '../cbor/encode';
|
|
3
3
|
import { AppSeqEncodingEdit, AppSeqSourceFeatures } from '../ast/CborItem';
|
|
4
|
+
/**
|
|
5
|
+
* Append every element of `source` onto `target` in place.
|
|
6
|
+
*
|
|
7
|
+
* Not `target.push(...source)`: spreading a large array as call arguments
|
|
8
|
+
* can exceed the engine's argument-count limit (observed with hex-dump
|
|
9
|
+
* lines for a deeply nested large array/map, and with CDN reflow
|
|
10
|
+
* breakpoints for a large embedded array — RangeError: Maximum call stack
|
|
11
|
+
* size exceeded).
|
|
12
|
+
*/
|
|
13
|
+
export declare function pushAll<T>(target: T[], source: readonly T[]): void;
|
|
4
14
|
/** Resolve indent option to a string, or null for single-line output. */
|
|
5
15
|
export declare function resolveIndent(options: ToCDNOptions | undefined): string | null;
|
|
6
16
|
/** Build the indent prefix for a given depth. */
|
|
@@ -19,12 +29,59 @@ export declare function indentOf(indentStr: string, depth: number): string;
|
|
|
19
29
|
* other comment kind.
|
|
20
30
|
*/
|
|
21
31
|
export declare function joinConcatParts(literals: readonly string[], indentStr: string | null, depth: number, midComments?: readonly (readonly string[])[]): string;
|
|
32
|
+
/**
|
|
33
|
+
* Serialize string parts as a `t1<<...>>` / `b1<<...>>` app-sequence
|
|
34
|
+
* (draft-ietf-cbor-edn-literals-27 §3.5) — the `modernConcat` replacement
|
|
35
|
+
* for `joinConcatParts`'s `+`-joining. Unlike a `+` chain, this
|
|
36
|
+
* notation has its own closing delimiter, so (matching how `<<...>>`/
|
|
37
|
+
* `CborEmbeddedCBOR` places its own encoding-width indicator, and unlike
|
|
38
|
+
* `emitParts`, which has nowhere else to put it) `suffix` is appended after
|
|
39
|
+
* `>>` rather than onto the last literal — it describes the one merged value
|
|
40
|
+
* `t1<<...>>` denotes as a whole, not any individual argument.
|
|
41
|
+
*
|
|
42
|
+
* Always single-line (an app-sequence is loose/collapsible, like
|
|
43
|
+
* every other `<<...>>` form), except when there's a mid-chain comment to
|
|
44
|
+
* preserve — nothing else forces it multi-line, since (unlike a real `+`
|
|
45
|
+
* chain) there's no risk of an unbounded single line growing unreadable that
|
|
46
|
+
* this format was ever meant to solve; a comment is the one thing a single
|
|
47
|
+
* line genuinely cannot hold, mirroring `joinConcatParts`'s own reason for
|
|
48
|
+
* going multi-line.
|
|
49
|
+
*/
|
|
50
|
+
export declare function joinAppSeqParts(prefix: 't1' | 'b1', literals: readonly string[], suffix: string, indentStr: string | null, depth: number, midComments?: readonly (readonly string[])[]): string;
|
|
22
51
|
export interface Commented {
|
|
23
52
|
comments?: CborComments;
|
|
24
53
|
blankLineBefore?: boolean;
|
|
25
54
|
}
|
|
26
55
|
export declare function hasPreservedComments(item: Commented): boolean;
|
|
27
56
|
export declare function hasContainerLayoutComments(item: Commented): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Subset of `ToCDNOptions` needed to resolve comment on/off + style —
|
|
59
|
+
* accepted structurally so callers with a narrower/wider options type (or a
|
|
60
|
+
* plain `FromCDNOptions`, which shares both fields) don't need a cast.
|
|
61
|
+
*/
|
|
62
|
+
interface CommentOptions {
|
|
63
|
+
preserveComments?: boolean | 'c-style' | 'cdn-style';
|
|
64
|
+
comments?: 'strip' | 'c-style' | 'cdn-style';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether comments should be emitted for freshly-regenerated output (as
|
|
68
|
+
* opposed to a preserved app-sequence/raw-tag source — see
|
|
69
|
+
* `decideTaggedAppSeqRendering`'s own comment handling for that case, which
|
|
70
|
+
* has a different "nothing set" default).
|
|
71
|
+
*
|
|
72
|
+
* `preserveComments: true` always emits (verbatim); otherwise, comments are
|
|
73
|
+
* emitted only when `comments` requests a real style (not `'strip'`,
|
|
74
|
+
* the default when unset) — matching the deprecated `preserveComments:
|
|
75
|
+
* 'c-style'/'cdn-style'` shorthand, which behaves the same as `comments`
|
|
76
|
+
* set to that value.
|
|
77
|
+
*/
|
|
78
|
+
export declare function shouldEmitComments(options: CommentOptions | undefined): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The marker style to normalize emitted comments to, or `undefined` for
|
|
81
|
+
* verbatim (original markers kept as-is). Only meaningful when
|
|
82
|
+
* `shouldEmitComments` is `true`; see its doc for the on/off precedence.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveCommentStyle(options: CommentOptions | undefined): 'c-style' | 'cdn-style' | undefined;
|
|
28
85
|
/**
|
|
29
86
|
* Convert a single comment's text to the requested marker style.
|
|
30
87
|
*
|
|
@@ -125,6 +182,17 @@ export declare function serializeContainer(p: {
|
|
|
125
182
|
closeChar: string;
|
|
126
183
|
count: number;
|
|
127
184
|
indefiniteLength: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Whether an indefinite-length container shows the `_` marker
|
|
187
|
+
* (`(_ "a", "b")`) before its content. Defaults to `true`; set `false` for
|
|
188
|
+
* a container that denotes an indefinite-length value through some other
|
|
189
|
+
* notation entirely (e.g. `ilts<<"a", "b">>`) rather than through the
|
|
190
|
+
* `_`-marked legacy streamstring form — the value is still genuinely
|
|
191
|
+
* indefinite-length (so `indefiniteLength: true` still correctly
|
|
192
|
+
* suppresses any encoding-width suffix, which has no meaning for it), but
|
|
193
|
+
* that other notation has no `_` marker of its own to show.
|
|
194
|
+
*/
|
|
195
|
+
indefiniteMarker?: boolean;
|
|
128
196
|
encodingWidth: EncodingWidth | undefined;
|
|
129
197
|
/**
|
|
130
198
|
* Where the resolved encoding-indicator suffix is placed.
|
|
@@ -147,11 +215,44 @@ export declare function serializeContainer(p: {
|
|
|
147
215
|
renderEntry: (i: number, colSep: string) => string;
|
|
148
216
|
/**
|
|
149
217
|
* Whether entry `i` contains no nested array/map, so it may stay on the
|
|
150
|
-
* container's line under `inlineLeafContainers
|
|
151
|
-
*
|
|
152
|
-
*
|
|
218
|
+
* container's line under `inlineLeafContainers` (or always, when
|
|
219
|
+
* `alwaysInlineLeaf` is set). Omitted = always a leaf (used by
|
|
220
|
+
* `CborEmbeddedCBOR`, where an entry that is itself a container still
|
|
221
|
+
* inlines as long as its own rendering fits on one line).
|
|
153
222
|
*/
|
|
154
223
|
entryIsLeaf?: (i: number) => boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Whether entry `i` is, or wraps, a text string or byte string with two or
|
|
226
|
+
* more words (`isMultiWordText` / `isMultiWordByteString`). When true,
|
|
227
|
+
* disqualifies the container from staying on one line under
|
|
228
|
+
* `inlineLeafContainers` (or `alwaysInlineLeaf`) even though the entry has
|
|
229
|
+
* no nested array/map — a multi-word string reads better with a line of
|
|
230
|
+
* its own. This does *not* also cover a prefixed literal like `h'...'`
|
|
231
|
+
* (which has no word count to check at all, but still disqualifies under
|
|
232
|
+
* the strict rule) — that's covered separately, generically, by
|
|
233
|
+
* `isPrefixedLiteralText` (checked against the rendered entry `s` below)
|
|
234
|
+
* or, for a `CborTag`, `isMultiWordRenderedLiteral`. Omitted = never
|
|
235
|
+
* disqualifies.
|
|
236
|
+
*/
|
|
237
|
+
entryIsMultiWordText?: (i: number) => boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Always run the one-line collapse probe, regardless of
|
|
240
|
+
* `options.inlineLeafContainers`. Set only by `CborEmbeddedCBOR`
|
|
241
|
+
* (`<<...>>`): unlike `CborArray`/`CborMap`, where spreading entries one
|
|
242
|
+
* per line is a deliberate structural default that `inlineLeafContainers`
|
|
243
|
+
* opts out of, a flat sequence of encoded items has no such structure to
|
|
244
|
+
* display — there's nothing gained by always breaking it, so it
|
|
245
|
+
* collapses onto one line whenever it fits independent of the option.
|
|
246
|
+
* Indefinite-length string groups (`(_ "a", "b")`) do *not* get this
|
|
247
|
+
* treatment — they follow CborArray/CborMap's option-gated default
|
|
248
|
+
* instead, providing `entryIsLeaf` the same way (see `strict` below),
|
|
249
|
+
* despite also being a "loose rule" container in the
|
|
250
|
+
* `_containsCdnContainer`/`entryHasContainer` sense (a chunk can never
|
|
251
|
+
* actually be an array/map, so that distinction is moot for them in
|
|
252
|
+
* practice). This flag and the loose/strict distinction are genuinely
|
|
253
|
+
* independent concerns, not the same thing.
|
|
254
|
+
*/
|
|
255
|
+
alwaysInlineLeaf?: boolean;
|
|
155
256
|
/** Node whose leading comments are emitted above entry `i` (item / map key). */
|
|
156
257
|
entryLeadingNode: (i: number) => Commented;
|
|
157
258
|
/** Pre-formatted trailing comment text for entry `i` (starts with ' ', or ''). */
|
|
@@ -179,6 +280,93 @@ export declare function serializeContainer(p: {
|
|
|
179
280
|
*/
|
|
180
281
|
export declare function renderSingleChildWithComments(child: Commented, wrapper: Commented, options: ToCDNOptions | undefined, depth: number, renderChild: (childDepth: number) => string, openChar: '(', closeChar: ')'): string;
|
|
181
282
|
export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex', sqstr?: 'printable-string' | 'string' | 'none'): string;
|
|
283
|
+
/**
|
|
284
|
+
* True when `bytes` would render as a bare sqstr literal (`'...'`) under
|
|
285
|
+
* `sqstr` *and* its decoded text has two or more words — same rule as a
|
|
286
|
+
* plain text string's own word count. Otherwise (it would render as a
|
|
287
|
+
* prefixed literal like `h'...'`/`b64'...'`, or as something else entirely
|
|
288
|
+
* via a subclass overriding `_toCDN()`) this returns `false`: a prefixed
|
|
289
|
+
* literal has no natural word boundary to predict from raw bytes alone,
|
|
290
|
+
* and — unlike this function, which never renders anything — the actual
|
|
291
|
+
* "does the real output look like a disqualifying prefixed literal, tag
|
|
292
|
+
* wrapping, or app-sequence spelling" question is answered generically
|
|
293
|
+
* from the *rendered* text instead, by `isPrefixedLiteralText` (for a bare
|
|
294
|
+
* entry) or `isMultiWordRenderedLiteral` (for a `CborTag`, which needs to
|
|
295
|
+
* see through its own digits/parens onto whatever they wrap).
|
|
296
|
+
*/
|
|
297
|
+
export declare function isMultiWordByteString(bytes: Uint8Array, sqstr?: 'printable-string' | 'string' | 'none'): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* True when `rendered` — a single entry's own CDN rendering — is shaped
|
|
300
|
+
* like a prefixed literal: an identifier immediately followed by `'` or a
|
|
301
|
+
* backtick (`h'...'`, `b64'...'`, `ip'...'`, `dt'...'`, or any other
|
|
302
|
+
* app-string extension's own spelling, built-in or user-defined). These
|
|
303
|
+
* have no natural word boundary to check, so — like a byte string's own
|
|
304
|
+
* prefixed-literal case in `isMultiWordByteString` — the strict
|
|
305
|
+
* `inlineLeafContainers` rule (`CborArray`/`CborMap`, and the
|
|
306
|
+
* indefinite-length string groups) always disqualifies a container from
|
|
307
|
+
* collapsing onto one line when an entry looks like this; the loose rule
|
|
308
|
+
* (only `CborEmbeddedCBOR`/`<<...>>`) treats it as an ordinary leaf
|
|
309
|
+
* instead.
|
|
310
|
+
*
|
|
311
|
+
* This is a generic, rendering-based catch-all — unlike `isMultiWordByteString`,
|
|
312
|
+
* it doesn't need per-extension-class support, so it also covers any
|
|
313
|
+
* app-string extension (registered under `CborExtension.appStringPrefixes`)
|
|
314
|
+
* without that extension's own `CborItem` subclass needing to know about
|
|
315
|
+
* `inlineLeafContainers` at all. It only sees a *bare* prefixed literal
|
|
316
|
+
* (nothing else in `rendered`); `CborTag` uses `isMultiWordRenderedLiteral`
|
|
317
|
+
* instead to see through its own tag digits/parens onto whatever they wrap.
|
|
318
|
+
*/
|
|
319
|
+
export declare function isPrefixedLiteralText(rendered: string): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* True when `rendered` — a leaf entry's own, already-rendered CDN text —
|
|
322
|
+
* counts as multi-word for `inlineLeafContainers`'s purposes, determined by
|
|
323
|
+
* tokenizing `rendered` itself rather than predicting from whichever
|
|
324
|
+
* `CborItem` subclass produced it. This makes it exact regardless of *how*
|
|
325
|
+
* the text came to look the way it does — a `CborTag` subclass
|
|
326
|
+
* (`CborTaggedIpExt`) overriding `_toCDN()` to render `IP<<'...'>>` instead
|
|
327
|
+
* of generic `52(...)` tag notation, a preserved `preserveByteString`
|
|
328
|
+
* spelling, `encodingIndicators: 'always'` adding an explicit `_N`/`_i`
|
|
329
|
+
* suffix everywhere, or anything else — since it never assumes a rendering
|
|
330
|
+
* path, only reads the result.
|
|
331
|
+
*
|
|
332
|
+
* Recognizes these shapes. Any of them may be followed by one trailing
|
|
333
|
+
* `ENCODING_INDICATOR` token (`_0`.._3`/`_i`) — stripped *before* any shape
|
|
334
|
+
* is recognized (not just for a bare literal), since it can trail a tag or
|
|
335
|
+
* an app-sequence wrapper too and never changes a value's own shape or
|
|
336
|
+
* word count:
|
|
337
|
+
* - A bare quoted literal (`"..."`, `` `...` ``, or a bare `'...'` sqstr):
|
|
338
|
+
* always counts if its *decoded* content has two or more words,
|
|
339
|
+
* regardless of `strict` — matching a text string's own word count.
|
|
340
|
+
* - A prefixed literal (`h'...'`, `b64'...'`, `ip'...'`, `dt'...'`, ...):
|
|
341
|
+
* has no natural word boundary to check, so it counts only when `strict`.
|
|
342
|
+
* - A generic tag wrapper (`tagNum[_EI](...)`) spanning the *entire* input:
|
|
343
|
+
* peels off just that one layer and recurses on what's inside (handling
|
|
344
|
+
* nested tags one layer at a time) — this is what lets a plain `CborTag`
|
|
345
|
+
* whose content is one of the shapes above still count, e.g.
|
|
346
|
+
* `100(dt'...')`, `100("two words")`, or (with `encodingIndicators:
|
|
347
|
+
* 'always'`) `100_0("two words"_i)`.
|
|
348
|
+
* - An app-sequence wrapper (`prefix<<item item ...>>`, tokenized as one
|
|
349
|
+
* `APP_SEQUENCE` opener and a plain `GT_GT` closer) spanning the *entire*
|
|
350
|
+
* input: unlike a tag, its own `<<...>>` is never peeled away — reading
|
|
351
|
+
* fine inline is the whole point of that notation, not a transparent
|
|
352
|
+
* single-value rewrap — but each top-level item inside (items may be
|
|
353
|
+
* separated by a comma, by whitespace alone, or both, per CDN's own
|
|
354
|
+
* grammar — `consumeOneItem` finds each one's extent structurally rather
|
|
355
|
+
* than only splitting at commas) is checked under the *loose* rule
|
|
356
|
+
* (`strict: false`, matching `<<...>>` itself) regardless of the
|
|
357
|
+
* `strict` this function was called with, so a multi-word text item
|
|
358
|
+
* (`ilts<<"two words">>`, or `ilts<<"two words" "x">>` with no comma at
|
|
359
|
+
* all) still always counts, while a prefixed-literal item
|
|
360
|
+
* (`ilbs<<h'00'>>`) — unlike the same literal bare or tag-wrapped —
|
|
361
|
+
* does not.
|
|
362
|
+
* - Anything else (a number, `true`/`false`, multiple top-level tokens that
|
|
363
|
+
* aren't one of the wrappers above, ...) never counts.
|
|
364
|
+
*
|
|
365
|
+
* Tokenizing can throw on malformed input; since `rendered` is always this
|
|
366
|
+
* library's own output, that should never happen, but a failure is treated
|
|
367
|
+
* as "not multi-word" rather than propagating.
|
|
368
|
+
*/
|
|
369
|
+
export declare function isMultiWordRenderedLiteral(rendered: string, strict: boolean): boolean;
|
|
182
370
|
/**
|
|
183
371
|
* Which comment syntax a byte-string literal's raw source recognizes —
|
|
184
372
|
* `undefined` when it has none at all (its content is data, not a comment
|
|
@@ -188,12 +376,12 @@ export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'ba
|
|
|
188
376
|
* `b32`/`h32` objects by reference — never guessed later from the prefix
|
|
189
377
|
* string, since a user extension can register under any prefix, including
|
|
190
378
|
* one a built-in also uses; see `CborByteString.ednCommentSyntax`).
|
|
191
|
-
* - `'full'`: `#`, `//`, `/* *\/`, and `/ /` (§
|
|
379
|
+
* - `'full'`: `#`, `//`, `/* *\/`, and `/ /` (§6.2.1/§6.3.3) — `h'...'`
|
|
192
380
|
* and its backtick form, and the built-in `b32'...'`/`h32'...'`
|
|
193
381
|
* extensions, which share hex's comment syntax (`utils/strip-comments.ts`).
|
|
194
382
|
* - `'hash-only'`: only `#` line comments — standard base64 (`b64'...'`),
|
|
195
383
|
* where `/` is valid data (e.g. `//8=` decodes to 0xFFFF), never a
|
|
196
|
-
* comment marker (see Tokenizer._readByteContent, §
|
|
384
|
+
* comment marker (see Tokenizer._readByteContent, §6.2.2).
|
|
197
385
|
*/
|
|
198
386
|
export type ByteCommentSyntax = 'full' | 'hash-only';
|
|
199
387
|
/**
|
|
@@ -223,6 +411,16 @@ export declare function escapeAppString(s: string): string;
|
|
|
223
411
|
* Produce an EDN double-quoted string literal `"..."` from a string value.
|
|
224
412
|
*/
|
|
225
413
|
export declare function escapeString(s: string): string;
|
|
414
|
+
/**
|
|
415
|
+
* True when `value` contains two or more "words" per `Intl.Segmenter`'s
|
|
416
|
+
* word-boundary rules (UAX #29): e.g. `"Hello, World!"` is two words (a
|
|
417
|
+
* comma breaks them), `"3.14"` is one (a decimal point between digits
|
|
418
|
+
* doesn't), and space-less scripts like Japanese/Chinese still split on
|
|
419
|
+
* their own dictionary-based word boundaries. Used by `inlineLeafContainers`
|
|
420
|
+
* to keep a multi-word string entry off the container's shared line even
|
|
421
|
+
* when it would otherwise qualify as a leaf.
|
|
422
|
+
*/
|
|
423
|
+
export declare function isMultiWordText(value: string): boolean;
|
|
226
424
|
/** Produce the numeric string for a float value (with decimal point if needed). */
|
|
227
425
|
export declare function floatValueToString(value: number): string;
|
|
228
426
|
/**
|
|
@@ -241,13 +439,13 @@ export declare function canonicalEncodingWidth(n: bigint): EncodingWidth;
|
|
|
241
439
|
* @param getCanonical - lazily compute the canonical width (only called in 'always' mode)
|
|
242
440
|
*/
|
|
243
441
|
export declare function resolveEiSuffix(options: ToCDNOptions | undefined, encodingWidth: EncodingWidth | undefined, getCanonical: () => EncodingWidth): string;
|
|
244
|
-
/** How a node should render under `
|
|
442
|
+
/** How a node should render under `preserveAppPrefix`. */
|
|
245
443
|
export type AppSeqRenderDecision = 'verbatim' | 'adjusted' | 'source' | 'structural' | 'normal';
|
|
246
444
|
/**
|
|
247
445
|
* Decide how an extension result node — from a `prefix'...'` /
|
|
248
446
|
* `` prefix`...` `` / `prefix<<...>>` source, or (for a tag-wrapper node
|
|
249
447
|
* that also has a generic `CborTag` fallback to delegate to) a raw tag
|
|
250
|
-
* literal `N(...)` — should render under `ToCDNOptions.
|
|
448
|
+
* literal `N(...)` — should render under `ToCDNOptions.preserveAppPrefix`.
|
|
251
449
|
*
|
|
252
450
|
* A raw-tag source is recognised by `ednSource !== undefined`: the parser
|
|
253
451
|
* only ever sets a tag-wrapper's `ednSource` (the tag *number's* digit
|
|
@@ -282,7 +480,7 @@ export type AppSeqRenderDecision = 'verbatim' | 'adjusted' | 'source' | 'structu
|
|
|
282
480
|
* `preserveConcatenation` override.
|
|
283
481
|
* Verbatim raw-tag text inherently contains the nested literal spelling.
|
|
284
482
|
* - `'normal'`: fall through to the class's own notation regeneration
|
|
285
|
-
* (`prefix'...'`), unaffected by `
|
|
483
|
+
* (`prefix'...'`), unaffected by `preserveAppPrefix`. For `<<...>>`,
|
|
286
484
|
* this is also used when replaying its sole inner item would defeat an
|
|
287
485
|
* explicitly disabled, relevant literal-preservation option.
|
|
288
486
|
*
|
|
@@ -313,3 +511,4 @@ export declare function adjustRawAppSeqSource(appSeqSource: string, options: ToC
|
|
|
313
511
|
* reliable way to locate it.
|
|
314
512
|
*/
|
|
315
513
|
export declare function adjustAppSeqIndicator(appSeqSource: string, newSuffix: string, options: ToCDNOptions | undefined, innerItemEnd: number | undefined, comments: readonly CborComment[] | undefined): string;
|
|
514
|
+
export {};
|
package/dist/cdn/tokenizer.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare class Tokenizer {
|
|
|
81
81
|
* Returns true if a comment was consumed, false if the current char is not a
|
|
82
82
|
* comment start. `quote` is the closing delimiter character.
|
|
83
83
|
*
|
|
84
|
-
* Supports / ... /, /* *\/, //, and # comment forms (§2.
|
|
84
|
+
* Supports / ... /, /* *\/, //, and # comment forms (§2.1).
|
|
85
85
|
*/
|
|
86
86
|
private _skipByteStringComment;
|
|
87
87
|
/**
|
|
@@ -98,7 +98,7 @@ export declare class Tokenizer {
|
|
|
98
98
|
* Called with `i` pointing at the comment-start character.
|
|
99
99
|
* Returns the index after the comment, or -1 if no comment was found.
|
|
100
100
|
*
|
|
101
|
-
* Supports / ... /, /* *\/, //, and # comment forms (§2.
|
|
101
|
+
* Supports / ... /, /* *\/, //, and # comment forms (§2.1).
|
|
102
102
|
* `context` is used in unterminated-comment error messages.
|
|
103
103
|
*/
|
|
104
104
|
private _skipRawComment;
|
|
@@ -113,13 +113,13 @@ export declare class Tokenizer {
|
|
|
113
113
|
* - Literal LF (U+000A) is allowed; all other C0 controls and U+007F are rejected.
|
|
114
114
|
* - Literal CR (U+000D) is silently stripped (source-level CRLF normalisation).
|
|
115
115
|
* - Only spec-defined escape sequences are accepted; `\q` etc. throw SyntaxError.
|
|
116
|
-
* - `\/` is valid only in double-quoted strings (not in escapable-s, §
|
|
116
|
+
* - `\/` is valid only in double-quoted strings (not in escapable-s, §6.1).
|
|
117
117
|
* - `\\` (backslash) is valid in both single- and double-quoted strings.
|
|
118
118
|
* - `\uXXXX` for a high surrogate must be immediately followed by `\uXXXX` for
|
|
119
119
|
* the corresponding low surrogate; lone surrogates are rejected.
|
|
120
120
|
* - `\u{N}` … `\u{10FFFF}` extended syntax is supported; surrogates are rejected.
|
|
121
121
|
* - In single-quoted strings, `\u` escapes to printable ASCII (U+0020–U+007E)
|
|
122
|
-
* are forbidden (hexchar-s restriction, draft-
|
|
122
|
+
* are forbidden (hexchar-s restriction, draft-ietf-cbor-edn-literals-27 §6.1).
|
|
123
123
|
*/
|
|
124
124
|
private _readStringContent;
|
|
125
125
|
/**
|
|
@@ -134,13 +134,14 @@ export declare class Tokenizer {
|
|
|
134
134
|
* which is then decoded into the corresponding non-BMP code point.
|
|
135
135
|
*
|
|
136
136
|
* In single-quoted strings (`quote === "'"`), `\u` escapes that resolve to
|
|
137
|
-
* printable ASCII (U+0020–U+007E) are rejected per draft-
|
|
137
|
+
* printable ASCII (U+0020–U+007E) are rejected per draft-ietf-cbor-edn-literals-27
|
|
138
|
+
* §6.1 hexchar-s.
|
|
138
139
|
* Use `\\` for backslash (U+005C) and `\'` for the single-quote delimiter.
|
|
139
140
|
*/
|
|
140
141
|
private _readUnicodeEscape;
|
|
141
142
|
/**
|
|
142
143
|
* Read raw text-string content between N-backtick delimiters
|
|
143
|
-
* (§2.
|
|
144
|
+
* (§2.3.3 of draft-ietf-cbor-edn-literals-27).
|
|
144
145
|
*
|
|
145
146
|
* - The opening delimiter is the maximal run of consecutive backticks (N ≥ 1).
|
|
146
147
|
* - No escape sequences are processed — content is taken verbatim.
|
|
@@ -153,7 +154,7 @@ export declare class Tokenizer {
|
|
|
153
154
|
*/
|
|
154
155
|
private _readRawStringContent;
|
|
155
156
|
/**
|
|
156
|
-
* Post-process raw hex content from a `h``…``\` raw string (§
|
|
157
|
+
* Post-process raw hex content from a `h``…``\` raw string (§6.3.3).
|
|
157
158
|
*
|
|
158
159
|
* Skips:
|
|
159
160
|
* - lblank whitespace (LF, SP; also CR for source-level normalisation)
|
|
@@ -162,13 +163,13 @@ export declare class Tokenizer {
|
|
|
162
163
|
* Detects `...` ellipsis sequences.
|
|
163
164
|
*
|
|
164
165
|
* A trailing `# comment` immediately before the closing delimiter is allowed
|
|
165
|
-
* per §
|
|
166
|
+
* per §6.3.3 `r-app-string-h`.
|
|
166
167
|
*
|
|
167
168
|
* Returns { value: hex-string-with-ellipsis-markers, elided: boolean }
|
|
168
169
|
*/
|
|
169
170
|
private _processRawHexContent;
|
|
170
171
|
/**
|
|
171
|
-
* Post-process raw base64 content from a `b64``…``\` raw string (§
|
|
172
|
+
* Post-process raw base64 content from a `b64``…``\` raw string (§6.3.4).
|
|
172
173
|
*
|
|
173
174
|
* Skips:
|
|
174
175
|
* - lblank whitespace (LF, SP; also CR for source-level normalisation)
|
|
@@ -180,12 +181,12 @@ export declare class Tokenizer {
|
|
|
180
181
|
/**
|
|
181
182
|
* Read raw byte-string content between `quote` chars (b64 / b64url).
|
|
182
183
|
*
|
|
183
|
-
* Strips whitespace and skips `# ...` line comments per §2.
|
|
184
|
+
* Strips whitespace and skips `# ...` line comments per §6.2.2.
|
|
184
185
|
* `/` is NOT treated as a comment delimiter because it is a valid base64 character.
|
|
185
186
|
*/
|
|
186
187
|
private _readByteContent;
|
|
187
188
|
/**
|
|
188
|
-
* Read hex byte-string content, recognising `...` ellipsis sequences (§
|
|
189
|
+
* Read hex byte-string content, recognising `...` ellipsis sequences (§5.2).
|
|
189
190
|
*
|
|
190
191
|
* Returns the raw hex string (with `...` markers embedded) and a flag
|
|
191
192
|
* indicating whether any ellipsis was found.
|
|
@@ -2,17 +2,17 @@ import { CborExtension } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Core data-model extensions (bignum tags 2/3, embedded-CBOR tag 24, and the
|
|
4
4
|
* CPA888 ellipsis tag). These implement base CBOR/EDN representation rather
|
|
5
|
-
* than an
|
|
6
|
-
*
|
|
5
|
+
* than an app-extension, so they are always active and are not affected by
|
|
6
|
+
* the `builtinExtensions` option.
|
|
7
7
|
*/
|
|
8
8
|
export declare const CORE_EXTENSIONS: readonly CborExtension[];
|
|
9
9
|
/**
|
|
10
|
-
* Default
|
|
10
|
+
* Default app-extensions bundled with the library.
|
|
11
11
|
* Overridable per call via `builtinExtensions` (an array to use instead, or
|
|
12
12
|
* `false` to disable all of them).
|
|
13
13
|
*
|
|
14
|
-
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §
|
|
15
|
-
* draft-ietf-cbor-edn-literals-
|
|
14
|
+
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §3 of
|
|
15
|
+
* draft-ietf-cbor-edn-literals-27; `cri`, `ilbs`, `ilts`, and `float` are
|
|
16
16
|
* bundled but not mandatory.
|
|
17
17
|
*/
|
|
18
18
|
export declare const BUILTIN_EXTENSIONS: readonly CborExtension[];
|
package/dist/extensions/cri.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CborExtension } from './types';
|
|
|
3
3
|
import { CborArray } from '../ast/CborArray';
|
|
4
4
|
import { CborTag } from '../ast/CborTag';
|
|
5
5
|
/**
|
|
6
|
-
* CBOR tag number for the tagged CRI variant (§3.
|
|
6
|
+
* CBOR tag number for the tagged CRI variant (§3.7 and §6.2.5 of draft-ietf-cbor-edn-literals-27).
|
|
7
7
|
*/
|
|
8
8
|
export declare const TAG_CRI = 99n;
|
|
9
9
|
/**
|
|
@@ -22,7 +22,7 @@ export declare class CborTaggedCriExt extends CborTag {
|
|
|
22
22
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Create the cri/CRI CborExtension (§3.
|
|
25
|
+
* Create the cri/CRI CborExtension (§3.7 and §6.2.5 of draft-ietf-cbor-edn-literals-27).
|
|
26
26
|
*
|
|
27
27
|
* - `cri'uri'` → CborCriExt (bare CRI array, no CBOR tag)
|
|
28
28
|
* - `CRI'uri'` → CborTaggedCriExt tag(99, CRI array)
|
package/dist/extensions/ip.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare class CborTaggedIpExt extends CborTag {
|
|
|
29
29
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Create an ip/IP CborExtension (RFC 9164 / §3.
|
|
32
|
+
* Create an ip/IP CborExtension (RFC 9164 / §3.3 of draft-ietf-cbor-edn-literals-27).
|
|
33
33
|
*
|
|
34
34
|
* - `ip'addr'` → CborIpExt (bare byte string, 4 or 16 bytes)
|
|
35
35
|
* - `IP'addr'` → CborTaggedIpExt tag(52 or 54, bytes)
|
|
@@ -3,7 +3,7 @@ import { FromCBOROptions, FromJSOptions } from '../types';
|
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/**
|
|
5
5
|
* Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
|
|
6
|
-
*
|
|
6
|
+
* app-string prefixes or CBOR tag numbers.
|
|
7
7
|
*
|
|
8
8
|
* Pass instances via `FromCDNOptions.extensions`, `FromCBOROptions.extensions`,
|
|
9
9
|
* or `FromJSOptions.extensions`.
|
|
@@ -52,7 +52,7 @@ export interface CborExtension {
|
|
|
52
52
|
*/
|
|
53
53
|
parseAppSequence?(prefix: string, items: CborItem[], onError?: (msg: string) => void): CborItem;
|
|
54
54
|
/**
|
|
55
|
-
* Controls how the CDN parser preserves the original
|
|
55
|
+
* Controls how the CDN parser preserves the original app-string
|
|
56
56
|
* / -sequence / raw-tag source text — `prefix'...'`, `` prefix`...` ``,
|
|
57
57
|
* `prefix<<...>>`, or a raw tag literal `N(...)` resolved via `parseTag`
|
|
58
58
|
* — for round-tripping through `toCDN()`.
|
|
@@ -60,7 +60,7 @@ export interface CborExtension {
|
|
|
60
60
|
* - `true`: the parser wraps the result of `parseAppSequence` (only —
|
|
61
61
|
* `parseAppString` and `parseTag` results are unaffected) in a
|
|
62
62
|
* `CborAppSeqResult`, which round-trips the original `<<...>>` notation
|
|
63
|
-
* unconditionally whenever `
|
|
63
|
+
* unconditionally whenever `appPrefix !== false` (no extra option
|
|
64
64
|
* needed). Use this when the result has no dedicated subclass whose
|
|
65
65
|
* identity callers rely on (e.g. `instanceof` checks) — the wrapper
|
|
66
66
|
* changes the returned node's type.
|
|
@@ -68,7 +68,7 @@ export interface CborExtension {
|
|
|
68
68
|
* results alike, the parser instead sets `appSeqSource` directly on the
|
|
69
69
|
* *same* result node (preserving its class/identity) and leaves it to
|
|
70
70
|
* the node's own `_toCDN()` override to decide whether to use it — by
|
|
71
|
-
* convention, only when `ToCDNOptions.
|
|
71
|
+
* convention, only when `ToCDNOptions.preserveAppPrefix` is set, so
|
|
72
72
|
* the default output keeps regenerating `prefix'...'` form from the
|
|
73
73
|
* resolved value. This covers a `` prefix`...` `` (backtick) source, a
|
|
74
74
|
* non-canonically-spelled `prefix'...'` source, and a raw tag literal
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-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(`
|
|
2
2
|
`)}static toHex(e,n){return[...t.fromCBORSeq(e,n)].map(e=>e.toHexDump(n)).join(`
|
|
3
|
-
`)}static fromHex(e,n){let r=[...t.fromHexDumpSeq(e,n)].map(e=>e.toCBOR(n)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static validate(n,r){let i=[],a=[],o,c={strict:!1,extensions:r?.extensions,builtinExtensions:r?.builtinExtensions,onWarning:e=>{if(`hint`in e&&e.hint){a.push(e);return}if(`fatal`in e&&e.fatal){o=e;return}i.push(e)}},l=s(r?.cddl),u=[],d=[],f=e=>{if(!l)return;let t=l.validate(e,r?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=l?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=r?.type??`cbor`;if(e===`cdn`){let e={...c,unresolvedExtension:r?.unresolvedExtension};for(let r of t.fromCDNSeq(n,e))m++,f(r)}else if(e===`hex`)for(let e of t.fromHexDumpSeq(n,c))m++,f(e);else for(let e of t.fromCBORSeq(n,c))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:i,hints:a,error:e instanceof Error?e:Error(String(e)),...p}}if(o){let t=o.cause instanceof Error?o.cause:new e.
|
|
3
|
+
`)}static fromHex(e,n){let r=[...t.fromHexDumpSeq(e,n)].map(e=>e.toCBOR(n)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static validate(n,r){let i=[],a=[],o,c={strict:!1,extensions:r?.extensions,builtinExtensions:r?.builtinExtensions,onWarning:e=>{if(`hint`in e&&e.hint){a.push(e);return}if(`fatal`in e&&e.fatal){o=e;return}i.push(e)}},l=s(r?.cddl),u=[],d=[],f=e=>{if(!l)return;let t=l.validate(e,r?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=l?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=r?.type??`cbor`;if(e===`cdn`){let e={...c,unresolvedExtension:r?.unresolvedExtension};for(let r of t.fromCDNSeq(n,e))m++,f(r)}else if(e===`hex`)for(let e of t.fromHexDumpSeq(n,c))m++,f(e);else for(let e of t.fromCBORSeq(n,c))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:i,hints:a,error:e instanceof Error?e:Error(String(e)),...p}}if(o){let t=o.cause instanceof Error?o.cause:new e.I(o.message,{offset:o.offset});return{valid:!1,count:m,warnings:i,hints:a,error:t,...p}}return{valid:i.length===0&&u.length===0,count:m,warnings:i,hints:a,...p}}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i=typeof t==`function`||Array.isArray(t)?t:void 0,a=_(r);if(i){let t=n.n(e,i);return t===void 0||t===n.R?void 0:n.r(t).toCDN(a===void 0?void 0:{indent:a})}return n.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=t;if(i?.replacer){let t=n.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(t===void 0||t===n.R)return;let{replacer:r,...a}=i;return l(n.r(t,Object.keys(a).length>0?a:void 0),i).toCDN(i)}return l(n.r(e,i),i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};function d(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=f(e,n+2),t+=` `;continue}if(r===`—`){n=f(e,n+1),t+=` `;continue}if(r===`#`){n=f(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=f(e,n+2),t+=` `;continue}if(r===`/`&&i===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=p(e.slice(n,r+2)),n=r+2;continue}if(r===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=p(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function f(e,t){let n=e.indexOf(`
|
|
4
4
|
`,t);return n<0?e.length:n}function p(e){return e.replace(/[^\r\n]/g,` `)}function m(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i&&(o.cause=i),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function h(e,t){let n=e[t];return n===`#`||n===`/`}function g(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
|
|
5
5
|
`){a=!0,s=!0,i++;continue}if(t===`#`){if(a=!0,l())break;let t=e.indexOf(`
|
|
6
6
|
`,i+1);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`/`){if(a=!0,l())break;let t=e.indexOf(`
|
|
7
7
|
`,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);m(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
|
8
8
|
`)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);m(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
|
9
|
-
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function _(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.BUILTIN_EXTENSIONS=n.i,exports.CBOR=u,exports.default=u,exports.CBOR_OMIT=n.
|
|
9
|
+
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function _(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.BUILTIN_EXTENSIONS=n.i,exports.CBOR=u,exports.default=u,exports.CBOR_OMIT=n.R,exports.CBOR_TAG=n.z,exports.CddlMismatchError=t.s,exports.CdnSyntaxError=e.I,exports.MapEntries=n.t,exports.Null=n.B,exports.Simple=n.L,exports.Tag=n.V,exports.Undefined=n.H,exports.b1=n.c,exports.b32=n.x,exports.cri=n.d,exports.dt=n.p,exports.dt_as_Date=n.m,exports.float=n.a,exports.h32=n.S,exports.ilbs=n.o,exports.ilts=n.s,exports.ip=n.f,exports.same=i,exports.t1=n.l;
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|