@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
|
@@ -210,7 +210,15 @@ export declare function serializeContainer(p: {
|
|
|
210
210
|
* this to its encoded content's byte length instead.
|
|
211
211
|
*/
|
|
212
212
|
canonicalCount?: () => bigint;
|
|
213
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Whether entry `i` structurally has any captured comments (parse-time
|
|
215
|
+
* presence only — not whether they'll actually be shown; see `hasComments`
|
|
216
|
+
* in the implementation, which additionally consults `entryOptions(i)` so
|
|
217
|
+
* an entry whose own override hides its comments doesn't force multi-line
|
|
218
|
+
* layout, and an entry whose own override *shows* comments the container's
|
|
219
|
+
* own `preserveComments` would otherwise hide still gets the chance to).
|
|
220
|
+
*/
|
|
221
|
+
hasEntryComments: (i: number) => boolean;
|
|
214
222
|
/** Render entry `i` at child depth (`item` or `key: value`). */
|
|
215
223
|
renderEntry: (i: number, colSep: string) => string;
|
|
216
224
|
/**
|
|
@@ -229,7 +237,8 @@ export declare function serializeContainer(p: {
|
|
|
229
237
|
* no nested array/map — a multi-word string reads better with a line of
|
|
230
238
|
* its own. This does *not* also cover a prefixed literal like `h'...'`
|
|
231
239
|
* (which has no word count to check at all, but still disqualifies under
|
|
232
|
-
* the strict rule)
|
|
240
|
+
* the strict rule) or an app-string like `dt'...'` (word-counted, strict
|
|
241
|
+
* rule only) — that's covered separately, generically, by
|
|
233
242
|
* `isPrefixedLiteralText` (checked against the rendered entry `s` below)
|
|
234
243
|
* or, for a `CborTag`, `isMultiWordRenderedLiteral`. Omitted = never
|
|
235
244
|
* disqualifies.
|
|
@@ -257,6 +266,17 @@ export declare function serializeContainer(p: {
|
|
|
257
266
|
entryLeadingNode: (i: number) => Commented;
|
|
258
267
|
/** Pre-formatted trailing comment text for entry `i` (starts with ' ', or ''). */
|
|
259
268
|
entryTrailing: (i: number, style: 'c-style' | 'cdn-style' | undefined) => string;
|
|
269
|
+
/**
|
|
270
|
+
* Per-entry options for entry `i`'s own comment handling (whether to
|
|
271
|
+
* emit its comments at all, and in which style) — distinct from
|
|
272
|
+
* `options` above, which still governs the container-wide layout
|
|
273
|
+
* decisions (single-line vs multi-line, `hasComments`'s own gate, the
|
|
274
|
+
* container's own dangling comments). Omitted when the caller never
|
|
275
|
+
* resolves per-entry options at all (`toCDN()`'s `itemOptions` isn't in
|
|
276
|
+
* play), in which case every entry falls back to `options` — identical
|
|
277
|
+
* to this parameter not existing.
|
|
278
|
+
*/
|
|
279
|
+
entryOptions?: (i: number) => ToCDNOptions | undefined;
|
|
260
280
|
}): string;
|
|
261
281
|
/**
|
|
262
282
|
* Single-child counterpart to `serializeContainer`, for a wrapper that
|
|
@@ -277,8 +297,17 @@ export declare function serializeContainer(p: {
|
|
|
277
297
|
* rendering, `depth` otherwise (matching a plain value's existing
|
|
278
298
|
* "transparent" nesting — `tag(content)` doesn't indent `content` an extra
|
|
279
299
|
* level when there's nothing to justify going multi-line for).
|
|
300
|
+
*
|
|
301
|
+
* `childOptions` — the child's own resolved options, distinct from
|
|
302
|
+
* `options` (the wrapper's) when `toCDN()`'s `itemOptions` has overridden
|
|
303
|
+
* something for the child specifically (see `CborTag._toCDN`) — governs
|
|
304
|
+
* only the child's *own* leading/trailing comments (whether to show them
|
|
305
|
+
* at all, and in which style); `options` still governs whether to go
|
|
306
|
+
* multi-line at all and the wrapper's own dangling comments, the same way
|
|
307
|
+
* `serializeContainer`'s container-wide `options` does for its own
|
|
308
|
+
* dangling comments even when its `entryOptions` resolves per-entry ones.
|
|
280
309
|
*/
|
|
281
|
-
export declare function renderSingleChildWithComments(child: Commented, wrapper: Commented, options: ToCDNOptions | undefined, depth: number, renderChild: (childDepth: number) => string, openChar: '(', closeChar: ')'): string;
|
|
310
|
+
export declare function renderSingleChildWithComments(child: Commented, wrapper: Commented, options: ToCDNOptions | undefined, childOptions: ToCDNOptions | undefined, depth: number, renderChild: (childDepth: number) => string, openChar: '(', closeChar: ')'): string;
|
|
282
311
|
export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex', sqstr?: 'printable-string' | 'string' | 'none'): string;
|
|
283
312
|
/**
|
|
284
313
|
* True when `bytes` would render as a bare sqstr literal (`'...'`) under
|
|
@@ -296,17 +325,18 @@ export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'ba
|
|
|
296
325
|
*/
|
|
297
326
|
export declare function isMultiWordByteString(bytes: Uint8Array, sqstr?: 'printable-string' | 'string' | 'none'): boolean;
|
|
298
327
|
/**
|
|
299
|
-
* True when `rendered` — a single entry's own CDN rendering —
|
|
300
|
-
*
|
|
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
|
|
328
|
+
* True when `rendered` — a single entry's own CDN rendering — starts with
|
|
329
|
+
* a prefixed literal that disqualifies under the strict
|
|
305
330
|
* `inlineLeafContainers` rule (`CborArray`/`CborMap`, and the
|
|
306
|
-
* indefinite-length string groups)
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
331
|
+
* indefinite-length string groups): a byte-string literal (`h'...'`,
|
|
332
|
+
* `b64'...'`), which has no natural word boundary to check (like a byte
|
|
333
|
+
* string's own prefixed-literal case in `isMultiWordByteString`), or an
|
|
334
|
+
* app-string extension literal (`ip'...'`, `dt'...'`, `e'...'`, or any
|
|
335
|
+
* other, built-in or user-defined) whose own content has two or more
|
|
336
|
+
* words — the latter is word-counted like a text string, so `e'alg'`
|
|
337
|
+
* stays a leaf while `dt'1969-07-21T02:56:16Z'` doesn't. The loose rule
|
|
338
|
+
* (only `CborEmbeddedCBOR`/`<<...>>`) treats either as an ordinary leaf
|
|
339
|
+
* instead, never calling this.
|
|
310
340
|
*
|
|
311
341
|
* This is a generic, rendering-based catch-all — unlike `isMultiWordByteString`,
|
|
312
342
|
* it doesn't need per-extension-class support, so it also covers any
|
|
@@ -337,8 +367,11 @@ export declare function isPrefixedLiteralText(rendered: string): boolean;
|
|
|
337
367
|
* - A bare quoted literal (`"..."`, `` `...` ``, or a bare `'...'` sqstr):
|
|
338
368
|
* always counts if its *decoded* content has two or more words,
|
|
339
369
|
* regardless of `strict` — matching a text string's own word count.
|
|
340
|
-
* - A prefixed literal (`h'...'`, `b64'...'
|
|
341
|
-
*
|
|
370
|
+
* - A prefixed byte-string literal (`h'...'`, `b64'...'`): has no natural
|
|
371
|
+
* word boundary to check, so it counts only when `strict`.
|
|
372
|
+
* - An app-string extension literal (`ip'...'`, `dt'...'`, `e'...'`, ...):
|
|
373
|
+
* counts only when `strict` *and* its content has two or more words (see
|
|
374
|
+
* `isPrefixedLiteralText`).
|
|
342
375
|
* - A generic tag wrapper (`tagNum[_EI](...)`) spanning the *entire* input:
|
|
343
376
|
* peels off just that one layer and recurses on what's inside (handling
|
|
344
377
|
* nested tags one layer at a time) — this is what lets a plain `CborTag`
|
|
@@ -359,6 +392,8 @@ export declare function isPrefixedLiteralText(rendered: string): boolean;
|
|
|
359
392
|
* all) still always counts, while a prefixed-literal item
|
|
360
393
|
* (`ilbs<<h'00'>>`) — unlike the same literal bare or tag-wrapped —
|
|
361
394
|
* does not.
|
|
395
|
+
* - A rendered array/map counts under the strict rule, including one
|
|
396
|
+
* exposed by `appPrefix: false` inside otherwise leaf-like tag wrappers.
|
|
362
397
|
* - Anything else (a number, `true`/`false`, multiple top-level tokens that
|
|
363
398
|
* aren't one of the wrappers above, ...) never counts.
|
|
364
399
|
*
|
package/dist/extensions/cri.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const TAG_CRI = 99n;
|
|
|
11
11
|
* Falls back to generic array notation if the content cannot be expressed as a URI.
|
|
12
12
|
*/
|
|
13
13
|
export declare class CborCriExt extends CborArray {
|
|
14
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
14
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* tag(99, CRI array) whose toCDN() emits CRI'…' notation.
|
|
@@ -19,7 +19,7 @@ export declare class CborCriExt extends CborArray {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class CborTaggedCriExt extends CborTag {
|
|
21
21
|
constructor(content: CborArray);
|
|
22
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
22
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Create the cri/CRI CborExtension (§3.7 and §6.2.5 of draft-ietf-cbor-edn-literals-27).
|
package/dist/extensions/dt.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class CborEpochDtExtUint extends CborUint {
|
|
|
32
32
|
encodingWidth?: EncodingWidth;
|
|
33
33
|
ednSource?: string;
|
|
34
34
|
});
|
|
35
|
-
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
35
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Negative epoch timestamp whose toCDN() emits dt'…' notation.
|
|
@@ -43,7 +43,7 @@ export declare class CborEpochDtExtNint extends CborNint {
|
|
|
43
43
|
encodingWidth?: EncodingWidth;
|
|
44
44
|
ednSource?: string;
|
|
45
45
|
});
|
|
46
|
-
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
46
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Float epoch timestamp whose toCDN() emits dt'…' notation.
|
|
@@ -54,7 +54,7 @@ export declare class CborEpochDtExtFloat extends CborFloat {
|
|
|
54
54
|
precision?: 'half' | 'single' | 'double';
|
|
55
55
|
literalSource?: string;
|
|
56
56
|
});
|
|
57
|
-
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
57
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* CBOR tag(1, epoch) whose toCDN() emits DT'…' notation.
|
|
@@ -64,7 +64,7 @@ export declare class CborTaggedEpochDtExt extends CborTag {
|
|
|
64
64
|
constructor(datetimeOrContent: string | CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat, options?: {
|
|
65
65
|
encodingWidth?: EncodingWidth;
|
|
66
66
|
});
|
|
67
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
67
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* CBOR tag(1, epoch) whose toJS() returns a plain Date object.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { FromCBOROptions, ToCDNOptions, ToJSOptions } from '../types';
|
|
2
|
+
import { CborExtension } from './types';
|
|
3
|
+
import { CborItem } from '../ast/CborItem';
|
|
4
|
+
import { CborUint } from '../ast/CborUint';
|
|
5
|
+
import { CborNint } from '../ast/CborNint';
|
|
6
|
+
import { EncodingWidth } from '../cbor/encode';
|
|
7
|
+
import { CddlSchema } from '../cddl/schema';
|
|
8
|
+
import { ValidateOptions } from '../cddl/validator';
|
|
9
|
+
export declare const PREFIX_EREF = "e";
|
|
10
|
+
interface ERefNodeOptions {
|
|
11
|
+
encodingWidth?: EncodingWidth;
|
|
12
|
+
ednSource?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `toJS()` may use `refName` as this key's JS property name —
|
|
15
|
+
* `false` when `fromJS()` would *not* convert that name back to this
|
|
16
|
+
* integer key at this position (its string-key conversion is stricter
|
|
17
|
+
* than annotation — see `cddl/eRefScope.ts`'s module doc), so a
|
|
18
|
+
* `toJS()` → `fromJS()` round trip would otherwise silently turn the key
|
|
19
|
+
* into literal text. The `e'name'` label is then display-only: `toCDN()`
|
|
20
|
+
* still emits it, while `toJS()` treats the key as the plain integer it
|
|
21
|
+
* is. Set by `annotateERefKeys()`; defaults to `true`.
|
|
22
|
+
*/
|
|
23
|
+
jsKey?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A non-negative integer whose value a CDDL model names — `_toCDN()` emits
|
|
27
|
+
* `e'name'` notation unless `appPrefix` is `false`.
|
|
28
|
+
*/
|
|
29
|
+
export declare class CborERefUint extends CborUint {
|
|
30
|
+
readonly refName: string;
|
|
31
|
+
/** See `ERefNodeOptions.jsKey`. */
|
|
32
|
+
readonly jsKey: boolean;
|
|
33
|
+
constructor(value: number | bigint, refName: string, options?: ERefNodeOptions);
|
|
34
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
35
|
+
_jsObjectKey(options: ToJSOptions | undefined): string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A negative integer whose value a CDDL model names — `_toCDN()` emits
|
|
39
|
+
* `e'name'` notation unless `appPrefix` is `false`.
|
|
40
|
+
*/
|
|
41
|
+
export declare class CborERefNint extends CborNint {
|
|
42
|
+
readonly refName: string;
|
|
43
|
+
/** See `ERefNodeOptions.jsKey`. */
|
|
44
|
+
readonly jsKey: boolean;
|
|
45
|
+
constructor(value: number | bigint, refName: string, options?: ERefNodeOptions);
|
|
46
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
47
|
+
_jsObjectKey(options: ToJSOptions | undefined): string | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the `e'...'` `CborExtension` for one compiled CDDL schema.
|
|
51
|
+
*
|
|
52
|
+
* `parseAppString('e', 'title', …)` resolves `title` via the schema's
|
|
53
|
+
* `getERefTables().byName` and returns the appropriately-signed
|
|
54
|
+
* `CborERefUint`/`CborERefNint`. A name the schema does not define (or
|
|
55
|
+
* defines ambiguously — bound to more than one value — or defines only as a
|
|
56
|
+
* non-integer constant; see the module doc's Scope note) is a hard parse
|
|
57
|
+
* error, always thrown regardless of `onError`: there is no best-effort
|
|
58
|
+
* value to fall back to.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createERefExtension(schema: CddlSchema): CborExtension;
|
|
61
|
+
/**
|
|
62
|
+
* Walk a CDDL-validated item tree and, for every plain (not already
|
|
63
|
+
* annotated) `CborUint`/`CborNint` used as a `CborMap` key — or as a map
|
|
64
|
+
* *value* whose own type is a closed `&(name: value)` choice of named
|
|
65
|
+
* integer constants (see `eRefValueFor()`'s own doc) — replace that node
|
|
66
|
+
* in place with the corresponding `CborERefUint`/`CborERefNint` — so
|
|
67
|
+
* `toCDN()` naturally emits `e'name'` notation (and, for a key, `toJS()`
|
|
68
|
+
* naturally uses `name` as the plain-object key — both by default;
|
|
69
|
+
* `appPrefix: false` / `eRefKeys: false` opt back out), without the caller
|
|
70
|
+
* having to spell `e'...'` in the original CBOR/CDN/JS source at all.
|
|
71
|
+
*
|
|
72
|
+
* Position-aware, exactly like `FromJSOptions.eRefKeys`'s own reverse
|
|
73
|
+
* direction (`cddl/eRefScope.ts`): starting from the schema's root rule (or
|
|
74
|
+
* `ruleName`, matching `ValidateOptions.rule` — the same rule the item was
|
|
75
|
+
* actually validated against), a key is only annotated with a name bound at
|
|
76
|
+
* a member-key position within the CDDL type actually reachable at *that*
|
|
77
|
+
* key's own structural position, descending through nested maps the same
|
|
78
|
+
* way this walk itself does — never a name that merely exists *somewhere*
|
|
79
|
+
* in the schema. This is deliberate, not merely cosmetic: a name that
|
|
80
|
+
* exists elsewhere in the schema but isn't reachable from this position is
|
|
81
|
+
* exactly the kind of name `fromJS()`'s `eRefKeys` option (correctly)
|
|
82
|
+
* refuses to convert back, so annotating with it here would make
|
|
83
|
+
* `toJS()` → `fromJS()` silently turn the original integer key into a
|
|
84
|
+
* *different*, wrong one (a plain text key, if the name isn't reachable at
|
|
85
|
+
* all) instead of round-tripping it byte-for-byte. A name reachable at this
|
|
86
|
+
* position also always satisfies `resolvesGloballyTo()` — the same
|
|
87
|
+
* schema-wide-uniqueness check `fromJS()` applies before labeling — so
|
|
88
|
+
* `e'name'` here always parses back to the same value via `fromCDN()`
|
|
89
|
+
* against the same schema too. A value's own label doesn't carry this same
|
|
90
|
+
* round-trip risk at all (see `eRefValueFor()`'s own doc for why), but is
|
|
91
|
+
* still gated by `resolvesGloballyTo()` for the CDN-reparse property alone.
|
|
92
|
+
*
|
|
93
|
+
* Data-aware, too: a key takes a name only from the group entry that
|
|
94
|
+
* actually consumed it in validation — read back from the validator's own
|
|
95
|
+
* map matching (`traceMapGroup()`), so value types, occurrence limits,
|
|
96
|
+
* entries already consumed and sub-group backtracking all count exactly as
|
|
97
|
+
* they did there — and nested content is only
|
|
98
|
+
* resolved against the value types that really matched. `ruleOrOptions`
|
|
99
|
+
* takes the same `ValidateOptions` validation used (`rule`, `features`, …)
|
|
100
|
+
* so those checks agree with it.
|
|
101
|
+
*
|
|
102
|
+
* Only descends through `CborArray`/`CborMap`/`CborTag` — the structural
|
|
103
|
+
* containers a CDDL-validated data model is built from — plus embedded
|
|
104
|
+
* CBOR: an array element or map value whose type is `bstr .cbor T` (or
|
|
105
|
+
* `.cborseq`) — e.g. COSE's `protected: bstr .cbor header_map` — is
|
|
106
|
+
* replaced by a `<<…>>` `CborEmbeddedCBOR` of its decoded content (only
|
|
107
|
+
* when that re-encodes to exactly the same bytes, so `toCBOR()`/`toJS()`
|
|
108
|
+
* are unchanged), and it, or a `<<…>>` already in CDN source, is annotated
|
|
109
|
+
* against `T` in turn (see `expandEmbedded()`/`walkEmbedded()`). Other node
|
|
110
|
+
* types (e.g. an indefinite-length string chunk) are left untouched, and
|
|
111
|
+
* their contents are not searched for map keys of their own. A map key is itself
|
|
112
|
+
* walked too (after any replacement of its own) — CBOR permits a map or
|
|
113
|
+
* array as a key, and an integer key nested inside *that* still needs
|
|
114
|
+
* annotating, e.g. `{{-1: "a"}: "b"}` — but never with a *positional*
|
|
115
|
+
* scope, the same way `fromJS()`'s own reverse direction never resolves
|
|
116
|
+
* `eRefKeys` names for a map key either (only this module's Scope note
|
|
117
|
+
* applies: a key reached this way simply gets no eRefKeys-eligible names of
|
|
118
|
+
* its own).
|
|
119
|
+
*
|
|
120
|
+
* `decodeOptions` are the caller's own decode-time extension settings
|
|
121
|
+
* (`extensions`/`builtinExtensions`, as given to `fromCBOR()`/`fromCDN()`/
|
|
122
|
+
* …), forwarded to the decode of embedded content — like tag 24's own
|
|
123
|
+
* (`extensions/cbordata.ts`) — so e.g. a bundled extension disabled via
|
|
124
|
+
* `builtinExtensions: false` stays disabled inside `<<…>>` too. Any other
|
|
125
|
+
* field is ignored; the inner decode is always strict, and content that
|
|
126
|
+
* doesn't decode that way is simply left as its bytes.
|
|
127
|
+
*
|
|
128
|
+
* Mutates `item` (and its descendants) in place; call only on a tree the
|
|
129
|
+
* caller exclusively owns and has not yet handed to anyone else — this is
|
|
130
|
+
* exactly the state a freshly decoded/parsed/constructed item is in right
|
|
131
|
+
* after CDDL validation succeeds, which is the only place this is called
|
|
132
|
+
* from (see `cbor.ts`'s `assertCddl()`).
|
|
133
|
+
*/
|
|
134
|
+
export declare function annotateERefKeys(item: CborItem, schema: CddlSchema, ruleOrOptions?: string | ValidateOptions, decodeOptions?: Pick<FromCBOROptions, 'extensions' | 'builtinExtensions'>): void;
|
|
135
|
+
export {};
|
package/dist/extensions/ip.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { CborArray } from '../ast/CborArray';
|
|
|
8
8
|
* Bare IP address byte string whose toCDN() emits ip'…' notation.
|
|
9
9
|
*/
|
|
10
10
|
export declare class CborIpExt extends CborByteString {
|
|
11
|
-
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
11
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number, path?: readonly unknown[]): string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Bare IP address prefix (CIDR) whose toCDN() emits ip'…/prefix' notation.
|
|
@@ -17,7 +17,7 @@ export declare class CborIpExt extends CborByteString {
|
|
|
17
17
|
export declare class CborIpPrefixExt extends CborArray {
|
|
18
18
|
private readonly _isV4;
|
|
19
19
|
constructor(prefixLen: number, truncated: Uint8Array, isV4: boolean);
|
|
20
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
20
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* CBOR tag(52/54, …) IP address whose toCDN() emits IP'…' notation.
|
|
@@ -26,7 +26,7 @@ export declare class CborIpPrefixExt extends CborArray {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class CborTaggedIpExt extends CborTag {
|
|
28
28
|
constructor(tag: bigint, content: CborItem);
|
|
29
|
-
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
29
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Create an ip/IP CborExtension (RFC 9164 / §3.3 of draft-ietf-cbor-edn-literals-27).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CborItem } from '../ast/CborItem';
|
|
2
|
-
import { FromCBOROptions, FromJSOptions } from '../types';
|
|
2
|
+
import { FromCBOROptions, FromJSOptions, ReadonlyToJSNodeOptions } from '../types';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/**
|
|
5
5
|
* Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
|
|
@@ -116,4 +116,43 @@ export interface CborExtension {
|
|
|
116
116
|
* (e.g. `value is Date`) for better static type inference at the call site.
|
|
117
117
|
*/
|
|
118
118
|
isJSType?(value: unknown): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Called during `toJS()` for every node, before that node's own default
|
|
121
|
+
* conversion, when this extension is listed in `ToJSOptions.extensions`.
|
|
122
|
+
* Return `undefined` to fall through to the next extension (then, if none
|
|
123
|
+
* claim the node, its own default conversion). Typically checks the
|
|
124
|
+
* node's class/shape (e.g. `item instanceof CborTaggedEpochDtExt`) rather
|
|
125
|
+
* than a tag number, since app-string forms without a wrapping tag (e.g.
|
|
126
|
+
* `dt'...'`) never reach `parseTag`-style tag-number dispatch either.
|
|
127
|
+
*
|
|
128
|
+
* The result is wrapped in `{ value }` — rather than returned directly —
|
|
129
|
+
* so a legitimate conversion result of `undefined` (CBOR `undefined`,
|
|
130
|
+
* simple 23) can be distinguished from "this extension doesn't handle
|
|
131
|
+
* this node".
|
|
132
|
+
*
|
|
133
|
+
* `options` never carries a `reviver` — its type is
|
|
134
|
+
* `ReadonlyToJSNodeOptions`, not `ToJSOptions` — so this hook has no way
|
|
135
|
+
* to make its result depend on whether one is present. That matters
|
|
136
|
+
* because `CborArray`/`CborMap.toObject`, when a `reviver` *is* present
|
|
137
|
+
* elsewhere in the call, convert each child more than once: once (with
|
|
138
|
+
* `reviver` itself stripped, though `itemOptions`/`extensions` stay
|
|
139
|
+
* active) to pre-populate a holder visible to an *earlier* sibling's own
|
|
140
|
+
* reviver call as `this[j]`, and once more, for real, to compute the
|
|
141
|
+
* value the container actually keeps. This hook is offered each of those
|
|
142
|
+
* conversions independently — once per visit, not deduplicated across
|
|
143
|
+
* them — precisely so that a `this[j]` observation reflects this hook's
|
|
144
|
+
* conversion (e.g. a `Date`) rather than the node's un-converted default.
|
|
145
|
+
* `options.extensions`, if present, is likewise a fresh copy each call —
|
|
146
|
+
* mutating it in place has no effect elsewhere.
|
|
147
|
+
* A deeply nested structure can multiply this further: a container
|
|
148
|
+
* several levels down may run its own such pre-population pass while
|
|
149
|
+
* itself sitting inside an *outer* container's pre-population pass, so
|
|
150
|
+
* the same node can in principle be offered to this hook more than
|
|
151
|
+
* twice. Whatever this hook returns for one visit only ever affects that
|
|
152
|
+
* visit's own value; reviving of the value a *container* holds still
|
|
153
|
+
* happens afterwards, exactly once per visit, in that container itself.
|
|
154
|
+
*/
|
|
155
|
+
toJS?(item: CborItem, options: ReadonlyToJSNodeOptions): {
|
|
156
|
+
value: unknown;
|
|
157
|
+
} | undefined;
|
|
119
158
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-
|
|
2
|
-
`)}static toHex(e,
|
|
3
|
-
`)}static fromHex(e,
|
|
4
|
-
`,t);return n<0?e.length:n}function
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-DQ8T3Mzw.cjs"),t=require("./mapEntries-DwHPAzCN.cjs"),n=require("./schema-YiigSWjR.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=8;function o(e,n,r,i){if(t.l(e,n,r).valid)return n;let a=[];if(!t.l(e,n,r,{infer:!0,trail:a}).valid)return n;let o=u(a);return!o||o.size===0?n:h(n,o,i)}function s(e,t,n,r){p(t);let i=new Set;for(let e of r)!e.inferred&&d(e.item)&&i.add(e.item);for(let r=0;i.size>0&&r<a;r++){let r=c(e,t,n,i);if(!r)return;if(r.size===i.size){for(let e of i)e._implicit=!0;return}i=r}}function c(e,n,r,i){if(t.l(e,n,r,{stripped:i,trail:[]}).valid)return new Set;let a=[];if(!t.l(e,n,r,{infer:!0,stripped:i,trail:a}).valid)return new Set;let o=new Map;for(let e of i){let t=l(e,i),n=f(t[t.length-1].content);(o.get(n)?.length??0)<t.length&&o.set(n,t)}let s=u(a);if(!s)return;let c=new Set;for(let[e,t]of s){let n=o.get(e);if(!n)return;if(n.length===t.length&&n.every((e,n)=>e.tag===t[n]))for(let e of n)c.add(e)}return c}function l(e,n){let r=[],i=e;for(;i instanceof t.B&&n.has(i);)r.push(i),i=f(i.content);return r}function u(e){let t=new Map;for(let n of e){if(!n.inferred)continue;let e=t.get(n.item);e||t.set(n.item,e=[]);let r=e[n.layer];if(r===void 0)e[n.layer]=n.tag;else if(r!==n.tag)return}for(let e of t.values())for(let t=0;t<e.length;t++)if(e[t]===void 0)return;return t}function d(e){return e instanceof t.B&&e._toJS===t.B.prototype._toJS}function f(e){for(;e instanceof t.A;)e=e.inner;return e}function p(e){m(e,p),e instanceof t.B&&(e._implicit=!1)}function m(e,n){if(e instanceof t.I)e.items.forEach(n);else if(e instanceof t.F)for(let[t,r]of e.entries)n(t),n(r);else e instanceof t.B?n(e.content):e instanceof t.A&&n(e.inner)}function h(e,n,r){let i=e=>{if(e instanceof t.I){let{items:t}=e;for(let e=0;e<t.length;e++)t[e]=i(t[e])}else if(e instanceof t.F)for(let t of e.entries)t[0]=i(t[0]),t[1]=i(t[1]);else e instanceof t.B&&(e.content=i(e.content));let a=e,o=n.get(e)??[];for(let e=o.length-1;e>=0;e--)a=r(o[e],a);return a};return i(e)}var g=new Map,_=64;function v(e){if(typeof e!=`string`)return e;let t=g.get(e);return t||(t=n.n(e),g.size>=_&&g.delete(g.keys().next().value),g.set(e,t)),t}function y(e,n,r,i,a){if(n){a&&a.implicitTags!==!1&&(e=o(n,e,r,(e,n)=>t.i(e,n,a)));let c=[],l=t.l(n,e,r,{trail:c});if(!l.valid)throw new t.Z(l.errors,l.warnings);s(n,e,r,c),t.s(e,n,r,i)}return e}function b(e,n){return n?{...e,extensions:[t.c(n),...e?.extensions??[]]}:e}function x(e,t){return y(e,v(t?.cddl),t?.cddlValidationOptions,t)}var S=class n{static OMIT=t.K;static TAG=t.q;static Tag=t.Y;static Simple=t.G;static MapEntries=t.t;static dt_as_Date=t.T;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,t){let r=n.fromCBOR(e,this.#t(t));return r._defaults=this.#e,r}fromCDN(e,t){let r=n.fromCDN(e,this.#t(t));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,t){let r=n.fromJS(e,this.#t(t));return r._defaults=this.#e,r}fromHexDump(e,t){let r=n.fromHexDump(e,this.#t(t));return r._defaults=this.#e,r}*fromCBORSeq(e,t){for(let r of n.fromCBORSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromCDNSeq(e,t){for(let r of n.fromCDNSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,t){for(let r of n.fromHexDumpSeq(e,this.#t(t)))r._defaults=this.#e,yield r}decode(e,t){return n.decode(e,this.#t(t))}*decodeSeq(e,t){yield*n.decodeSeq(e,this.#t(t))}*parseSeq(e,t){yield*n.parseSeq(e,this.#t(t))}encode(e,t){return n.encode(e,this.#t(t))}compile(e,t){return n.compile(e,this.#t(t))}decompile(e,t){return n.decompile(e,this.#t(t))}toHex(e,t){return n.toHex(e,this.#t(t))}fromHex(e,t){return n.fromHex(e,this.#t(t))}validate(e,t){return n.validate(e,this.#t(t))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,t){let r=this.#t(t),i=n.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,t){let r=this.#t(t);return n.fromCDN(e,r).toCBOR(r)}parse(e,t){if(typeof t==`function`){let r=this.#t({reviver:t});return n.fromCDN(e,r).toJS(r)}let r=this.#t(t);return n.fromCDN(e,r).toJS(r)}stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i={...this.#e};return t===null?i.replacer=void 0:(typeof t==`function`||Array.isArray(t))&&(i.replacer=t),r!==void 0&&(i.indent=k(r)),n.stringify(e,i)}return n.stringify(e,this.#t(t??void 0))}format(e,t){return n.format(e,this.#t(t))}static fromCBOR(e,n){return x(t.x(e,n),n)}static fromCDN(e,n){let r=v(n?.cddl);return y(t.D(e,b(n,r)),r,n?.cddlValidationOptions,n)}static fromEDN(e,t){return n.fromCDN(e,t)}static*fromHexDumpSeq(e,t){let r=[],i=C(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*n.fromCBORSeq(new Uint8Array(r),t)}static*fromCBORSeq(e,n){let r=v(n?.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=t.x(i,{...n,offset:a,allowTrailing:!0});yield y(e,r,n?.cddlValidationOptions,n),a=e.end}}static*fromCDNSeq(n,r){let i=v(r?.cddl),a=e.D(r)||!!r?.preserveAll,o=0,s=!0;for(;;){let{offset:c,hadSeparator:l,commaOffset:u}=O(n,o,r,a?s?`all`:`after-newline`:`none`);if(s&&u>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);E(e,u,r)}if(c>=n.length||a&&D(n,c)&&O(n,c,r).offset>=n.length)break;if(!s&&!l){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);E(e,c,r)}o=c;let d;try{d=t.D(n,b({...r,offset:o,allowTrailing:!0,_skipRS:!0},i))}catch(t){if(r?.strict!==!1)throw t;E(t instanceof Error?t.message:String(t),o,r,!0,t instanceof e.I?t:void 0);break}yield y(d,i,r?.cddlValidationOptions,r),o=d.end,s=!1}}static fromJS(e,n){let r=v(n?.cddl);return y(t.r(e,n,r),r,n?.cddlValidationOptions,n,n??{})}static fromHexDump(e,n){let r=[],i=C(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 x(t.x(new Uint8Array(r),n),n)}static decode(e,t){return n.fromCBOR(e,t).toJS(t)}static*decodeSeq(e,t){for(let r of n.fromCBORSeq(e,t))yield r.toJS(t)}static*parseSeq(e,t){for(let r of n.fromCDNSeq(e,t))yield r.toJS(t)}static encode(e,t){return n.fromJS(e,t).toCBOR(t)}static compile(e,t){let r=[...n.fromCDNSeq(e,t)].map(e=>e.toCBOR(t)),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,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toCDN(t)).join(`
|
|
2
|
+
`)}static toHex(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toHexDump(t)).join(`
|
|
3
|
+
`)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),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(r,i){let a=[],o=[],s,c=v(i?.cddl),l={strict:!1,extensions:c?[t.c(c),...i?.extensions??[]]:i?.extensions,builtinExtensions:i?.builtinExtensions,onWarning:e=>{if(`hint`in e&&e.hint){o.push(e);return}if(`fatal`in e&&e.fatal){s=e;return}a.push(e)}},u=[],d=[],f=e=>{if(!c)return;let t=c.validate(e,i?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=c?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=i?.type??`cbor`;if(e===`cdn`){let e={...l,unresolvedExtension:i?.unresolvedExtension};for(let t of n.fromCDNSeq(r,e))m++,f(t)}else if(e===`hex`)for(let e of n.fromHexDumpSeq(r,l))m++,f(e);else for(let e of n.fromCBORSeq(r,l))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:a,hints:o,error:e instanceof Error?e:Error(String(e)),...p}}if(s){let t=s.cause instanceof Error?s.cause:new e.I(s.message,{offset:s.offset});return{valid:!1,count:m,warnings:a,hints:o,error:t,...p}}return{valid:a.length===0&&u.length===0,count:m,warnings:a,hints:o,...p}}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,a=k(r);if(i){let n=t.n(e,i);return n===void 0||n===t.K?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n,a=v(i?.cddl);if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(n===void 0||n===t.K)return;let{replacer:r,...o}=i;return y(t.r(n,Object.keys(o).length>0?o:void 0,a),a,i.cddlValidationOptions,i,o).toCDN(i)}return y(t.r(e,i,a),a,i?.cddlValidationOptions,i,i??{}).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function C(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=w(e,n+2),t+=` `;continue}if(r===`—`){n=w(e,n+1),t+=` `;continue}if(r===`#`){n=w(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=w(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+=T(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+=T(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function w(e,t){let n=e.indexOf(`
|
|
4
|
+
`,t);return n<0?e.length:n}function T(e){return e.replace(/[^\r\n]/g,` `)}function E(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 D(e,t){let n=e[t];return n===`#`||n===`/`}function O(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
|
-
`,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);
|
|
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);
|
|
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
|
|
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);E(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
|
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);E(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 k(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=t.h,exports.CBOR=S,exports.default=S,exports.CBOR_OMIT=t.K,exports.CBOR_TAG=t.q,exports.CborERefNint=t.a,exports.CborERefUint=t.o,exports.CddlMismatchError=t.Z,exports.CdnSyntaxError=e.I,exports.MapEntries=t.t,exports.Null=t.J,exports.Simple=t.G,exports.Tag=t.Y,exports.Undefined=t.X,exports.annotateERefKeys=t.s,exports.b1=t.y,exports.b32=t.j,exports.createERefExtension=t.c,exports.cri=t.S,exports.dt=t.w,exports.dt_as_Date=t.T,exports.float=t.g,exports.h32=t.M,exports.ilbs=t._,exports.ilts=t.v,exports.ip=t.C,exports.same=i,exports.t1=t.b;
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|