@cbortech/cbor 0.26.5 → 0.26.7
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 +239 -34
- package/README.md +242 -38
- package/dist/ast/CborByteString.d.ts +14 -0
- package/dist/ast/CborEllipsis.d.ts +94 -2
- package/dist/ast/CborFloat.d.ts +10 -0
- package/dist/ast/CborItem.d.ts +93 -4
- package/dist/ast/CborNint.d.ts +9 -0
- package/dist/ast/CborSimple.d.ts +11 -2
- package/dist/ast/CborTag.d.ts +8 -0
- package/dist/ast/CborTextString.d.ts +20 -0
- package/dist/ast/CborUint.d.ts +8 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor.d.ts +8 -0
- package/dist/cddl/ast.d.ts +196 -0
- package/dist/cddl/controls.d.ts +28 -0
- package/dist/cddl/equal.d.ts +19 -0
- package/dist/cddl/errors.d.ts +91 -0
- package/dist/cddl/index.cjs +3 -0
- package/dist/cddl/index.cjs.map +1 -0
- package/dist/cddl/index.d.ts +52 -0
- package/dist/cddl/index.js +67 -0
- package/dist/cddl/index.js.map +1 -0
- package/dist/cddl/parser.d.ts +13 -0
- package/dist/cddl/position.d.ts +13 -0
- package/dist/cddl/prelude.d.ts +5 -0
- package/dist/cddl/schema.d.ts +90 -0
- package/dist/cddl/tokenizer.d.ts +138 -0
- package/dist/cddl/validator.d.ts +30 -0
- package/dist/cddl/writer.d.ts +23 -0
- package/dist/cdn/serialize-utils.d.ts +186 -8
- package/dist/extensions/dt.d.ts +3 -0
- package/dist/extensions/types.d.ts +31 -9
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +97 -107
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-D2NyeCX3.cjs +17 -0
- package/dist/mapEntries-D2NyeCX3.cjs.map +1 -0
- package/dist/{mapEntries-Clr-oNtQ.js → mapEntries-DxrDre2P.js} +1498 -991
- package/dist/mapEntries-DxrDre2P.js.map +1 -0
- package/dist/schema-Bofmsptw.js +1977 -0
- package/dist/schema-Bofmsptw.js.map +1 -0
- package/dist/schema-t_bdPk8_.cjs +63 -0
- package/dist/schema-t_bdPk8_.cjs.map +1 -0
- package/dist/types.d.ts +258 -7
- package/dist/utils/base64.d.ts +12 -0
- package/package.json +24 -7
- package/dist/mapEntries-6hy7UgeN.cjs +0 -15
- package/dist/mapEntries-6hy7UgeN.cjs.map +0 -1
- package/dist/mapEntries-Clr-oNtQ.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { CborExtension } from './extensions/types';
|
|
2
|
+
import { CddlSchema } from './cddl/schema';
|
|
3
|
+
import { ValidateOptions as CddlValidateOptions } from './cddl/validator';
|
|
4
|
+
import { CddlValidationError, CddlValidationWarning } from './cddl/errors';
|
|
2
5
|
/**
|
|
3
6
|
* Shared option types and plugin interfaces.
|
|
4
7
|
*/
|
|
@@ -216,6 +219,29 @@ export interface FromCBOROptions {
|
|
|
216
219
|
* @default false
|
|
217
220
|
*/
|
|
218
221
|
silent?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* CDDL schema to validate decoded items against: either a compiled schema
|
|
224
|
+
* (`CDDL.compile()` from `@cbortech/cbor/cddl`) or CDDL source text.
|
|
225
|
+
* Source text is compiled on first use with default compile options and
|
|
226
|
+
* cached, so passing the same string repeatedly does not recompile; pass a
|
|
227
|
+
* compiled schema to control `CompileOptions` yourself. Invalid CDDL text
|
|
228
|
+
* throws `CddlSyntaxError` / `CddlSemanticError` at the call site.
|
|
229
|
+
*
|
|
230
|
+
* Each decoded item is validated after decoding, against the schema's
|
|
231
|
+
* root rule by default (or `cddlValidationOptions.rule`, if set); a
|
|
232
|
+
* mismatch throws {@link CddlMismatchError}. Sequence entry points
|
|
233
|
+
* (`fromCBORSeq`, `decodeSeq`, …) validate each item of the sequence
|
|
234
|
+
* individually against that same rule. `CBOR.validate()` collects
|
|
235
|
+
* mismatches into `ValidateResult.cddlErrors` instead of throwing.
|
|
236
|
+
*/
|
|
237
|
+
cddl?: CddlSchema | string;
|
|
238
|
+
/**
|
|
239
|
+
* Options forwarded to the CDDL validator when `cddl` is supplied
|
|
240
|
+
* (`features` for the `.feature` control operator, `maxDepth`,
|
|
241
|
+
* `maxSteps`, and `rule` to validate against a rule other than the
|
|
242
|
+
* schema's root). Ignored without `cddl`.
|
|
243
|
+
*/
|
|
244
|
+
cddlValidationOptions?: CddlValidateOptions;
|
|
219
245
|
}
|
|
220
246
|
/**
|
|
221
247
|
* Options for parsing an annotated hex dump.
|
|
@@ -253,6 +279,16 @@ export interface FromHexDumpOptions {
|
|
|
253
279
|
* @default false
|
|
254
280
|
*/
|
|
255
281
|
silent?: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Compiled CDDL schema to validate decoded items against.
|
|
284
|
+
* Mirrors `FromCBOROptions.cddl`.
|
|
285
|
+
*/
|
|
286
|
+
cddl?: CddlSchema | string;
|
|
287
|
+
/**
|
|
288
|
+
* Options forwarded to the CDDL validator.
|
|
289
|
+
* Mirrors `FromCBOROptions.cddlValidationOptions`.
|
|
290
|
+
*/
|
|
291
|
+
cddlValidationOptions?: CddlValidateOptions;
|
|
256
292
|
}
|
|
257
293
|
export interface FromCDNOptions {
|
|
258
294
|
/**
|
|
@@ -353,6 +389,17 @@ export interface FromCDNOptions {
|
|
|
353
389
|
* @default false
|
|
354
390
|
*/
|
|
355
391
|
preserveComments?: boolean | 'c-style' | 'cdn-style';
|
|
392
|
+
/**
|
|
393
|
+
* Shorthand for `ToCDNOptions.preserveAll`, so a single option enables
|
|
394
|
+
* round-tripping through both `fromCDN()` and `toCDN()` (as
|
|
395
|
+
* `CBOR.format()` does internally). On the parse side, this only implies
|
|
396
|
+
* `preserveComments: true` (comments must be captured while parsing to be
|
|
397
|
+
* re-emittable); the other `preserve*` behaviors are always captured by
|
|
398
|
+
* the parser and only need to be turned on for `toCDN()`.
|
|
399
|
+
*
|
|
400
|
+
* @default false
|
|
401
|
+
*/
|
|
402
|
+
preserveAll?: boolean;
|
|
356
403
|
/**
|
|
357
404
|
* Controls how CDN/EDN validity violations are handled.
|
|
358
405
|
*
|
|
@@ -386,6 +433,16 @@ export interface FromCDNOptions {
|
|
|
386
433
|
* @default false
|
|
387
434
|
*/
|
|
388
435
|
silent?: boolean;
|
|
436
|
+
/**
|
|
437
|
+
* Compiled CDDL schema to validate parsed items against.
|
|
438
|
+
* Mirrors `FromCBOROptions.cddl`.
|
|
439
|
+
*/
|
|
440
|
+
cddl?: CddlSchema | string;
|
|
441
|
+
/**
|
|
442
|
+
* Options forwarded to the CDDL validator.
|
|
443
|
+
* Mirrors `FromCBOROptions.cddlValidationOptions`.
|
|
444
|
+
*/
|
|
445
|
+
cddlValidationOptions?: CddlValidateOptions;
|
|
389
446
|
}
|
|
390
447
|
/**
|
|
391
448
|
* Options for parsing Concise Diagnostic Notation (CDN).
|
|
@@ -444,6 +501,16 @@ export interface FromJSOptions {
|
|
|
444
501
|
* @default false
|
|
445
502
|
*/
|
|
446
503
|
undefinedOmits?: boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Compiled CDDL schema to validate the constructed item against, before
|
|
506
|
+
* encoding/serialization. Mirrors `FromCBOROptions.cddl`.
|
|
507
|
+
*/
|
|
508
|
+
cddl?: CddlSchema | string;
|
|
509
|
+
/**
|
|
510
|
+
* Options forwarded to the CDDL validator.
|
|
511
|
+
* Mirrors `FromCBOROptions.cddlValidationOptions`.
|
|
512
|
+
*/
|
|
513
|
+
cddlValidationOptions?: CddlValidateOptions;
|
|
447
514
|
}
|
|
448
515
|
export interface ToCDNOptions {
|
|
449
516
|
/**
|
|
@@ -455,9 +522,34 @@ export interface ToCDNOptions {
|
|
|
455
522
|
* Like `JSON.stringify`, `0` and `''` are equivalent to omitting the
|
|
456
523
|
* option: the output is a single line. Single-line output is guaranteed
|
|
457
524
|
* to contain no newlines; layout-dependent options (`preserveComments`,
|
|
458
|
-
* `splitCdn`, `splitNewline`, `preserveConcatenation`)
|
|
525
|
+
* `preserveBlankLines`, `splitCdn`, `splitNewline`, `preserveConcatenation`)
|
|
526
|
+
* are ignored.
|
|
459
527
|
*/
|
|
460
528
|
indent?: number | string;
|
|
529
|
+
/**
|
|
530
|
+
* Master switch that turns on every `preserve*` option below at once —
|
|
531
|
+
* `preserveComments`, `preserveByteString`, `preserveRawString`,
|
|
532
|
+
* `preserveTextString`, `preserveConcatenation`, `preserveNumberFormat`,
|
|
533
|
+
* `preserveAppSequence`, and `preserveBlankLines` — for reformatting CDN
|
|
534
|
+
* text (e.g. on save in an editor) with minimal changes: only
|
|
535
|
+
* whitespace/indentation, plus anything an explicitly-set individual
|
|
536
|
+
* option overrides.
|
|
537
|
+
*
|
|
538
|
+
* An option explicitly set to a value (including `false`) is left as-is;
|
|
539
|
+
* `preserveAll` only fills in the ones left `undefined`. So
|
|
540
|
+
* `{ preserveAll: true, preserveNumberFormat: false }` preserves
|
|
541
|
+
* everything except number literal spelling.
|
|
542
|
+
*
|
|
543
|
+
* When parsing via `CBOR.fromCDN()` separately from `toCDN()` (rather
|
|
544
|
+
* than through `CBOR.format()`, which passes the same options to both),
|
|
545
|
+
* also pass `preserveAll` (or `preserveComments`) to `FromCDNOptions` so
|
|
546
|
+
* comments are captured in the first place — see
|
|
547
|
+
* `FromCDNOptions.preserveAll`. Bignums are unaffected by
|
|
548
|
+
* `preserveNumberFormat` even under `preserveAll`; see that option.
|
|
549
|
+
*
|
|
550
|
+
* @default false
|
|
551
|
+
*/
|
|
552
|
+
preserveAll?: boolean;
|
|
461
553
|
/**
|
|
462
554
|
* Emit comments previously captured by `FromCDNOptions.preserveComments`.
|
|
463
555
|
*
|
|
@@ -477,23 +569,48 @@ export interface ToCDNOptions {
|
|
|
477
569
|
* @default false
|
|
478
570
|
*/
|
|
479
571
|
preserveComments?: boolean | 'c-style' | 'cdn-style';
|
|
572
|
+
/**
|
|
573
|
+
* Re-emit a blank line above an array/map entry (or indefinite-length
|
|
574
|
+
* string chunk) that had one before it anywhere in the parsed CDN source,
|
|
575
|
+
* so paragraph-like groupings of entries survive a reformat. At most one
|
|
576
|
+
* blank line is ever emitted per gap, regardless of how many blank lines
|
|
577
|
+
* were originally there.
|
|
578
|
+
*
|
|
579
|
+
* Detection is based purely on entry source positions — it does not
|
|
580
|
+
* require `preserveComments` and is unaffected by whether comments are
|
|
581
|
+
* emitted.
|
|
582
|
+
*
|
|
583
|
+
* Only effective when `indent` enables pretty-printing. A container with
|
|
584
|
+
* a preserved blank line is always emitted one-entry-per-line, the same
|
|
585
|
+
* as a container with preserved comments (see `inlineLeafContainers`).
|
|
586
|
+
*
|
|
587
|
+
* @default false
|
|
588
|
+
*/
|
|
589
|
+
preserveBlankLines?: boolean;
|
|
480
590
|
/**
|
|
481
591
|
* Re-emit byte string literals parsed from CDN using their original source
|
|
482
592
|
* text when available.
|
|
483
593
|
*
|
|
484
594
|
* This preserves the spelling and interior layout of non-concatenated
|
|
485
595
|
* `h'...'`, `b64'...'`, `b32'...'`, `h32'...'`, raw-backtick byte strings,
|
|
486
|
-
* and single-quoted byte strings
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
596
|
+
* and single-quoted byte strings — including a `h'xx...yy'`-family elided
|
|
597
|
+
* literal (§4.2), whose spelling is kept independently of
|
|
598
|
+
* `preserveConcatenation` when it has no `+` of its own (see that
|
|
599
|
+
* option). Byte strings produced by `+` concatenation are normalised as
|
|
600
|
+
* usual; combine with `preserveConcatenation` to keep both the part
|
|
601
|
+
* boundaries and each part's spelling.
|
|
602
|
+
*
|
|
603
|
+
* A comment inside the literal is stripped unless `preserveComments` is
|
|
604
|
+
* also set — `preserveByteString` alone preserves everything about the
|
|
605
|
+
* literal's spelling *except* its comments, the same as an unpreserved
|
|
606
|
+
* literal (re-derived from the decoded value) never has comments either.
|
|
490
607
|
*
|
|
491
608
|
* When enabled, this takes precedence over `bstrEncoding` and `sqstr` for
|
|
492
609
|
* byte strings that carry original EDN source text.
|
|
493
610
|
*
|
|
494
611
|
* In single-line output (no `indent`), an original spelling that spans
|
|
495
|
-
* multiple lines
|
|
496
|
-
*
|
|
612
|
+
* multiple lines — after any comment is stripped — falls back to normal
|
|
613
|
+
* serialization; single-line spellings are kept.
|
|
497
614
|
*
|
|
498
615
|
* @default false
|
|
499
616
|
*/
|
|
@@ -517,6 +634,48 @@ export interface ToCDNOptions {
|
|
|
517
634
|
* @default false
|
|
518
635
|
*/
|
|
519
636
|
preserveRawString?: boolean;
|
|
637
|
+
/**
|
|
638
|
+
* Re-emit double-quoted text strings (`"..."`) using their original CDN
|
|
639
|
+
* source spelling — escape sequences (`é` vs. the literal character),
|
|
640
|
+
* quoting choices, etc. — instead of re-escaping them from the decoded
|
|
641
|
+
* string value.
|
|
642
|
+
*
|
|
643
|
+
* Applies to non-concatenated double-quoted literals only; a string
|
|
644
|
+
* reached via `+` concatenation is normalised as usual regardless of this
|
|
645
|
+
* option. Preserved strings are emitted verbatim: they are never
|
|
646
|
+
* re-indented or split by `splitCdn` / `splitNewline`.
|
|
647
|
+
*
|
|
648
|
+
* Raw backtick literals (`` `...` ``) are covered by `preserveRawString`,
|
|
649
|
+
* not this option.
|
|
650
|
+
*
|
|
651
|
+
* In single-line output (no `indent`), a spelling that spans multiple
|
|
652
|
+
* lines falls back to normal escaping; single-line spellings are kept.
|
|
653
|
+
*
|
|
654
|
+
* @default false
|
|
655
|
+
*/
|
|
656
|
+
preserveTextString?: boolean;
|
|
657
|
+
/**
|
|
658
|
+
* Re-emit integer and floating-point literals using their original CDN
|
|
659
|
+
* source spelling — base (`0xff` / `0o377` / `0b101` / decimal), digit
|
|
660
|
+
* spelling, decimal point / exponent form, and encoding-indicator suffix
|
|
661
|
+
* (e.g. `1.5_1`) — instead of normalising them via `intFormat` /
|
|
662
|
+
* `floatFormat` and recomputed encoding indicators.
|
|
663
|
+
*
|
|
664
|
+
* Takes precedence over `intFormat` and `floatFormat` for literals parsed
|
|
665
|
+
* from CDN text. Values that did not originate from CDN text (e.g. built
|
|
666
|
+
* via `CBOR.from()` or decoded from CBOR bytes) always fall back to normal
|
|
667
|
+
* formatting, since there is no original spelling to preserve. Bignums
|
|
668
|
+
* (integers outside the uint64/int64 range) are unaffected and always
|
|
669
|
+
* render as plain decimal.
|
|
670
|
+
*
|
|
671
|
+
* Combine with `preserveByteString`, `preserveRawString`,
|
|
672
|
+
* `preserveConcatenation`, and `preserveComments` to reformat CDN text
|
|
673
|
+
* (e.g. whitespace/indentation only) with minimal changes to the rest of
|
|
674
|
+
* the source.
|
|
675
|
+
*
|
|
676
|
+
* @default false
|
|
677
|
+
*/
|
|
678
|
+
preserveNumberFormat?: boolean;
|
|
520
679
|
/**
|
|
521
680
|
* Whether to emit commas between array/map elements.
|
|
522
681
|
* - `'comma'`: emit commas (`[1, 2, 3]`)
|
|
@@ -551,6 +710,37 @@ export interface ToCDNOptions {
|
|
|
551
710
|
* @default true
|
|
552
711
|
*/
|
|
553
712
|
appStrings?: boolean;
|
|
713
|
+
/**
|
|
714
|
+
* For built-in extensions that support application-string notation
|
|
715
|
+
* (`prefix'...'` or `` prefix`...` ``), application-sequence notation
|
|
716
|
+
* (`prefix<<...>>`), and/or a raw tag literal (`N(...)`), re-emit a value
|
|
717
|
+
* using its exact original spelling instead of normalizing it to the
|
|
718
|
+
* regenerated `prefix'...'` form.
|
|
719
|
+
*
|
|
720
|
+
* By default, an extension like `dt`/`DT` or `ip`/`IP` regenerates its
|
|
721
|
+
* notation from the resolved value on every call — so
|
|
722
|
+
* `` DT`1969-07-21T02:56:16Z` ``, `DT<<'1969-07-21T02:56:16Z'>>`, and even
|
|
723
|
+
* the raw tag form `1(1749772800)` all become
|
|
724
|
+
* `DT'2025-06-13T00:00:00Z'`-style `prefix'...'` notation, even though all
|
|
725
|
+
* of these denote the same value. `preserveAppSequence` keeps the
|
|
726
|
+
* original spelling instead — whichever quoting (`'...'` vs `` `...` ``),
|
|
727
|
+
* bracketing (`<<...>>`), or raw tag form was used. Has no effect when
|
|
728
|
+
* `appStrings` is `false` (raw tag notation is used either way regardless
|
|
729
|
+
* of the original spelling), or on values not parsed from one of these
|
|
730
|
+
* forms.
|
|
731
|
+
*
|
|
732
|
+
* In single-line output (no `indent`), a spelling that spans multiple
|
|
733
|
+
* lines falls back to normal (regenerated) notation; single-line
|
|
734
|
+
* spellings are kept.
|
|
735
|
+
*
|
|
736
|
+
* An explicit `preserveComments` setting is still applied to comments
|
|
737
|
+
* inside a preserved application-sequence spelling: marker styles are
|
|
738
|
+
* normalised without changing the notation family, and `false` removes
|
|
739
|
+
* the comments while retaining the surrounding source spelling.
|
|
740
|
+
*
|
|
741
|
+
* @default false
|
|
742
|
+
*/
|
|
743
|
+
preserveAppSequence?: boolean;
|
|
554
744
|
/**
|
|
555
745
|
* Numeric format for integer values in CDN output.
|
|
556
746
|
* - `'decimal'`: standard decimal notation (e.g. `42`, `-14159024`)
|
|
@@ -628,6 +818,19 @@ export interface ToCDNOptions {
|
|
|
628
818
|
* concatenation, and only takes effect when `indent` enables
|
|
629
819
|
* pretty-printing (single-line output joins the parts into one literal).
|
|
630
820
|
*
|
|
821
|
+
* Also applies within an elision (`...`, §4.2 of
|
|
822
|
+
* draft-ietf-cbor-edn-literals-25): a `+`-joined fragment on either side of
|
|
823
|
+
* an ellipsis keeps its own part boundaries too (e.g. `'test' +
|
|
824
|
+
* h'1234...abcd' + ...` stays exactly as written instead of merging
|
|
825
|
+
* `'test'` into the byte fragment before it), and byte-string elision
|
|
826
|
+
* keeps the `h'xx' + ... + h'yy'` spelling instead of the default compact
|
|
827
|
+
* `h'xx...yy'` literal. Unlike the text/byte-string case above, this
|
|
828
|
+
* applies regardless of `indent`, and the parts stay on one line even
|
|
829
|
+
* under `indent` (elision is always single-line): a `+` boundary inside an
|
|
830
|
+
* ellipsis is never a lossless merge — the elided middle can't be "joined
|
|
831
|
+
* in" — so there's no indent-dependent fallback to prefer, and no reason
|
|
832
|
+
* to reflow it.
|
|
833
|
+
*
|
|
631
834
|
* @default false
|
|
632
835
|
*/
|
|
633
836
|
preserveConcatenation?: boolean;
|
|
@@ -638,6 +841,12 @@ export interface ToCDNOptions {
|
|
|
638
841
|
* `{"a": 1}`, `(_ "a", "b")`). Nested leaf containers still collapse
|
|
639
842
|
* individually: `[[1, 2], [3, 4]]` renders with one inner array per line.
|
|
640
843
|
*
|
|
844
|
+
* `<<...>>` (CBOR Sequence Literal / embedded CBOR) is the one exception:
|
|
845
|
+
* since it's a flat sequence of encoded items rather than a
|
|
846
|
+
* nested-structure display, an entry that is itself an array/map still
|
|
847
|
+
* inlines there as long as its own rendering fits on one line — e.g.
|
|
848
|
+
* `<<{1: -7}>>` stays on one line, even though `[{1: -7}]` would not.
|
|
849
|
+
*
|
|
641
850
|
* Containers with preserved comments are always emitted in multi-line
|
|
642
851
|
* form. Has no effect when `indent` is omitted.
|
|
643
852
|
*
|
|
@@ -674,6 +883,15 @@ export interface CborComment {
|
|
|
674
883
|
end: number;
|
|
675
884
|
line: number;
|
|
676
885
|
col: number;
|
|
886
|
+
/**
|
|
887
|
+
* `true` when this is a `leading` comment that ends on the same source
|
|
888
|
+
* line as the node it's attached to — e.g. `/ protected / << ... >>` in an
|
|
889
|
+
* RFC 9052-style annotated array, as opposed to a comment on its own line
|
|
890
|
+
* above the value. `toCDN()` renders these as an inline prefix on the
|
|
891
|
+
* value's own line instead of a separate line above it. `undefined` for
|
|
892
|
+
* `trailing`/`dangling` comments, where it doesn't apply.
|
|
893
|
+
*/
|
|
894
|
+
sameLine?: boolean;
|
|
677
895
|
}
|
|
678
896
|
export interface CborComments {
|
|
679
897
|
leading?: CborComment[];
|
|
@@ -708,6 +926,27 @@ export interface ValidateOptions {
|
|
|
708
926
|
* @default 'cpa999'
|
|
709
927
|
*/
|
|
710
928
|
unresolvedExtension?: 'cpa999' | 'error';
|
|
929
|
+
/**
|
|
930
|
+
* CDDL schema to validate each decoded/parsed item against: either a
|
|
931
|
+
* compiled schema (`CDDL.compile()` from `@cbortech/cbor/cddl`) or CDDL
|
|
932
|
+
* source text (compiled on first use and cached; mirrors
|
|
933
|
+
* `FromCBOROptions.cddl`).
|
|
934
|
+
*
|
|
935
|
+
* Unlike the throwing entry points, `CBOR.validate()` does not throw on a
|
|
936
|
+
* mismatch: failures are collected into `ValidateResult.cddlErrors` (and
|
|
937
|
+
* validator observations into `ValidateResult.cddlWarnings`), and any
|
|
938
|
+
* mismatch makes `valid` `false`. Each item of a sequence is validated
|
|
939
|
+
* individually against the schema's root rule by default (or
|
|
940
|
+
* `cddlValidationOptions.rule`, if set). Note that invalid CDDL source
|
|
941
|
+
* text itself still throws (`CddlSyntaxError` / `CddlSemanticError`): the
|
|
942
|
+
* schema is part of the call, not the data being validated.
|
|
943
|
+
*/
|
|
944
|
+
cddl?: CddlSchema | string;
|
|
945
|
+
/**
|
|
946
|
+
* Options forwarded to the CDDL validator.
|
|
947
|
+
* Mirrors `FromCBOROptions.cddlValidationOptions`.
|
|
948
|
+
*/
|
|
949
|
+
cddlValidationOptions?: CddlValidateOptions;
|
|
711
950
|
}
|
|
712
951
|
/**
|
|
713
952
|
* Result of `CBOR.validate()`.
|
|
@@ -744,6 +983,18 @@ export interface ValidateResult {
|
|
|
744
983
|
* `CdnSyntaxError`, position fields intact.
|
|
745
984
|
*/
|
|
746
985
|
error?: Error;
|
|
986
|
+
/**
|
|
987
|
+
* CDDL validation failures, collected per decoded item. Only present when
|
|
988
|
+
* `ValidateOptions.cddl` was supplied (empty array when every item
|
|
989
|
+
* matched). Any entry makes `valid` `false`.
|
|
990
|
+
*/
|
|
991
|
+
cddlErrors?: CddlValidationError[];
|
|
992
|
+
/**
|
|
993
|
+
* Non-fatal CDDL validator observations (e.g. unsupported control
|
|
994
|
+
* operators whose constraints were skipped). Only present when
|
|
995
|
+
* `ValidateOptions.cddl` was supplied. Never affects `valid`.
|
|
996
|
+
*/
|
|
997
|
+
cddlWarnings?: CddlValidationWarning[];
|
|
747
998
|
}
|
|
748
999
|
/** `fromCBORSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
|
|
749
1000
|
export type FromCBORSeqOptions = Omit<FromCBOROptions, 'offset' | 'allowTrailing'>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode base64 text (classic or URL-safe alphabet, padding optional) into
|
|
3
|
+
* bytes, with strict RFC 4648 validation.
|
|
4
|
+
*
|
|
5
|
+
* Used by the CDN parser (b64'…' literals, §5.3.4) and the CDDL tokenizer
|
|
6
|
+
* (b64'…' byte strings, RFC 8610 §3.1).
|
|
7
|
+
*
|
|
8
|
+
* Recoverable deviations (padding-count mismatches, non-zero trailing bits)
|
|
9
|
+
* are reported through `onRecoverableError` when provided; otherwise they
|
|
10
|
+
* throw a plain SyntaxError, which callers wrap with position information.
|
|
11
|
+
*/
|
|
12
|
+
export declare function base64ToBytes(b64: string, onRecoverableError?: (msg: string) => void): Uint8Array;
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbortech/cbor",
|
|
3
|
-
"version": "0.26.
|
|
4
|
-
"description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values",
|
|
3
|
+
"version": "0.26.7",
|
|
4
|
+
"description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values with CDDL validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cbor",
|
|
7
7
|
"cdn",
|
|
8
|
+
"cddl",
|
|
9
|
+
"cddl-validation",
|
|
10
|
+
"rfc8610",
|
|
8
11
|
"cbor-edn",
|
|
9
12
|
"diagnostic-notation",
|
|
10
13
|
"json",
|
|
@@ -60,6 +63,16 @@
|
|
|
60
63
|
"types": "./dist/cdn/index.d.ts",
|
|
61
64
|
"default": "./dist/cdn/index.cjs"
|
|
62
65
|
}
|
|
66
|
+
},
|
|
67
|
+
"./cddl": {
|
|
68
|
+
"import": {
|
|
69
|
+
"types": "./dist/cddl/index.d.ts",
|
|
70
|
+
"default": "./dist/cddl/index.js"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./dist/cddl/index.d.ts",
|
|
74
|
+
"default": "./dist/cddl/index.cjs"
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
},
|
|
65
78
|
"files": [
|
|
@@ -81,11 +94,13 @@
|
|
|
81
94
|
"start": "node dist/index.js",
|
|
82
95
|
"dev": "npm run build && npm start",
|
|
83
96
|
"clean": "node -e \"['dist','coverage'].forEach(d=>require('fs').rmSync(d,{recursive:true,force:true}))\"",
|
|
84
|
-
"test": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts",
|
|
97
|
+
"test": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts --exclude src/cddl/cddl-corpus.test.ts --exclude src/cddl/cddl-validation-vectors.test.ts --exclude site/src/playground.browser.test.ts",
|
|
85
98
|
"test:exports": "npm run build && node scripts/check-package-exports.mjs",
|
|
86
|
-
"test:node": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts",
|
|
99
|
+
"test:node": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts --exclude src/cddl/cddl-corpus.test.ts --exclude src/cddl/cddl-validation-vectors.test.ts --exclude site/src/playground.browser.test.ts",
|
|
87
100
|
"test:edn-vectors": "vitest run src/cdn/edn-test-vectors.test.ts",
|
|
88
101
|
"test:edn-abnf": "vitest run src/cdn/edn-abnf-vectors.test.ts",
|
|
102
|
+
"test:cddl-corpus": "vitest run src/cddl/cddl-corpus.test.ts",
|
|
103
|
+
"test:cddl-vectors": "vitest run src/cddl/cddl-validation-vectors.test.ts",
|
|
89
104
|
"test:chromium": "cross-env BROWSER=chromium vitest run --config vitest.browser.config.ts",
|
|
90
105
|
"test:firefox": "cross-env BROWSER=firefox vitest run --config vitest.browser.config.ts",
|
|
91
106
|
"test:webkit": "cross-env BROWSER=webkit vitest run --config vitest.browser.config.ts",
|
|
@@ -99,9 +114,11 @@
|
|
|
99
114
|
"site:clean": "npm run --workspace site clean",
|
|
100
115
|
"site:dev": "npm run build && npm run --workspace site dev",
|
|
101
116
|
"site:build": "npm run build && npm run --workspace site build",
|
|
102
|
-
"site:preview": "npm run site:build && npm run --workspace site preview"
|
|
117
|
+
"site:preview": "npm run site:build && npm run --workspace site preview",
|
|
118
|
+
"site:test": "npm run build && npm run --workspace site test"
|
|
103
119
|
},
|
|
104
120
|
"devDependencies": {
|
|
121
|
+
"@cbortech/hash-extension": "^0.2.3",
|
|
105
122
|
"@types/node": "^24.13.3",
|
|
106
123
|
"@vitest/browser": "^4.1.10",
|
|
107
124
|
"@vitest/browser-playwright": "^4.1.10",
|
|
@@ -109,9 +126,9 @@
|
|
|
109
126
|
"@vitest/ui": "^4.1.10",
|
|
110
127
|
"cross-env": "^10.1.0",
|
|
111
128
|
"playwright": "^1.61.1",
|
|
112
|
-
"prettier": "^3.9.
|
|
129
|
+
"prettier": "^3.9.6",
|
|
113
130
|
"typescript": "^5.9.3",
|
|
114
|
-
"vite": "^8.1.
|
|
131
|
+
"vite": "^8.1.5",
|
|
115
132
|
"vite-plugin-dts": "^4.5.4",
|
|
116
133
|
"vitest": "^4.1.10"
|
|
117
134
|
}
|