@cbortech/cbor 0.26.3 → 0.26.5

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/dist/types.d.ts CHANGED
@@ -114,6 +114,20 @@ export interface ParseWarning {
114
114
  * fatal warnings as errors.
115
115
  */
116
116
  fatal?: boolean;
117
+ /**
118
+ * `true` when this entry is an informational hint (e.g. an app-string
119
+ * prefix matches a known optional extension that isn't registered) rather
120
+ * than a validity violation. Parsing is unaffected either way, but tooling
121
+ * that treats `onWarning` calls as failures (see `CBOR.validate()`) should
122
+ * not count these against validity.
123
+ */
124
+ hint?: boolean;
125
+ /**
126
+ * For a `fatal` warning built from a caught syntax error (see
127
+ * `CdnSyntaxError`), the original error object with its position fields
128
+ * intact. `CBOR.validate()` promotes this into `ValidateResult.error`.
129
+ */
130
+ cause?: Error;
117
131
  }
118
132
  export interface FromCBOROptions {
119
133
  /**
@@ -437,6 +451,11 @@ export interface ToCDNOptions {
437
451
  * - `number`: number of spaces
438
452
  * - `string`: literal indent string (e.g. `'\t'`)
439
453
  * - omit for single-line output
454
+ *
455
+ * Like `JSON.stringify`, `0` and `''` are equivalent to omitting the
456
+ * option: the output is a single line. Single-line output is guaranteed
457
+ * to contain no newlines; layout-dependent options (`preserveComments`,
458
+ * `splitCdn`, `splitNewline`, `preserveConcatenation`) are ignored.
440
459
  */
441
460
  indent?: number | string;
442
461
  /**
@@ -451,8 +470,9 @@ export interface ToCDNOptions {
451
470
  * kept as-is.
452
471
  * - `false` / omitted: strip all comments from the output.
453
472
  *
454
- * When enabled for containers, comment-bearing arrays/maps are emitted in
455
- * multi-line form even if `indent` is omitted.
473
+ * Only effective when `indent` enables pretty-printing: single-line
474
+ * output strips all comments, since line comments (`#`, `//`) can only
475
+ * be terminated by a newline.
456
476
  *
457
477
  * @default false
458
478
  */
@@ -471,6 +491,10 @@ export interface ToCDNOptions {
471
491
  * When enabled, this takes precedence over `bstrEncoding` and `sqstr` for
472
492
  * byte strings that carry original EDN source text.
473
493
  *
494
+ * In single-line output (no `indent`), an original spelling that spans
495
+ * multiple lines (e.g. a byte string literal with interior line comments)
496
+ * falls back to normal serialization; single-line spellings are kept.
497
+ *
474
498
  * @default false
475
499
  */
476
500
  preserveByteString?: boolean;
@@ -487,6 +511,9 @@ export interface ToCDNOptions {
487
511
  * Raw byte string forms (e.g. `` h`...` ``) are covered by
488
512
  * `preserveByteString`, not this option.
489
513
  *
514
+ * In single-line output (no `indent`), a spelling that spans multiple
515
+ * lines falls back to normal escaping; single-line spellings are kept.
516
+ *
490
517
  * @default false
491
518
  */
492
519
  preserveRawString?: boolean;
@@ -542,7 +569,7 @@ export interface ToCDNOptions {
542
569
  floatFormat?: 'decimal' | 'hex';
543
570
  /**
544
571
  * Split long text strings using CDN string concatenation syntax (`"a" + "b"`).
545
- * Only effective when `indent` is specified.
572
+ * Only effective when `indent` enables pretty-printing.
546
573
  *
547
574
  * - `'newline'`: split at newline characters
548
575
  * - `'cdn'`: split according to CDN structure when the string content
@@ -598,7 +625,8 @@ export interface ToCDNOptions {
598
625
  * text strings whose content parses as CDN, while `splitNewline` combines
599
626
  * with this option by further splitting the preserved parts at newline
600
627
  * characters. Has no effect on values that did not originate from a CDN
601
- * concatenation.
628
+ * concatenation, and only takes effect when `indent` enables
629
+ * pretty-printing (single-line output joins the parts into one literal).
602
630
  *
603
631
  * @default false
604
632
  */
@@ -652,6 +680,71 @@ export interface CborComments {
652
680
  trailing?: CborComment[];
653
681
  dangling?: CborComment[];
654
682
  }
683
+ /**
684
+ * Options for `CBOR.validate()`.
685
+ */
686
+ export interface ValidateOptions {
687
+ /**
688
+ * Input format.
689
+ * - `'cbor'`: binary CBOR, decoded as a CBOR Sequence (RFC 8742).
690
+ * - `'cdn'`: CDN text, parsed as a CDN Sequence.
691
+ * - `'hex'`: annotated hex dump text, decoded as a CBOR Sequence.
692
+ * @default 'cbor'
693
+ */
694
+ type?: 'cbor' | 'cdn' | 'hex';
695
+ /**
696
+ * Extension plugins used while decoding/parsing.
697
+ * Mirrors `FromCBOROptions.extensions` / `FromCDNOptions.extensions`.
698
+ */
699
+ extensions?: CborExtension[];
700
+ /**
701
+ * Override the default set of bundled application-oriented extensions.
702
+ * Mirrors `FromCBOROptions.builtinExtensions`.
703
+ */
704
+ builtinExtensions?: CborExtension[] | false;
705
+ /**
706
+ * How to handle unrecognised application-extension identifiers.
707
+ * Only applies when `type` is `'cdn'`; mirrors `FromCDNOptions.unresolvedExtension`.
708
+ * @default 'cpa999'
709
+ */
710
+ unresolvedExtension?: 'cpa999' | 'error';
711
+ }
712
+ /**
713
+ * Result of `CBOR.validate()`.
714
+ */
715
+ export interface ValidateResult {
716
+ /**
717
+ * `true` when every item decoded/parsed without error and without any
718
+ * warnings. `false` when the input was malformed (see `error`) or
719
+ * well-formed but in violation of a validity constraint (see `warnings`).
720
+ */
721
+ valid: boolean;
722
+ /** Number of items successfully decoded/parsed before any error. */
723
+ count: number;
724
+ /**
725
+ * Validity violations encountered while decoding/parsing in non-strict
726
+ * mode (recoverable — decoding continued after each one). Excludes
727
+ * informational hints (see `hints`) and the fatal CDN warning that
728
+ * `error` is built from, if any.
729
+ */
730
+ warnings: (DecodeWarning | ParseWarning)[];
731
+ /**
732
+ * Informational hints (`ParseWarning.hint`) encountered while parsing,
733
+ * e.g. an app-string prefix that matches a known optional extension which
734
+ * isn't registered. Hints never affect `valid`; they are collected here so
735
+ * tooling can still surface them.
736
+ */
737
+ hints: ParseWarning[];
738
+ /**
739
+ * Set when decoding/parsing failed outright: either it threw (e.g.
740
+ * truncated CBOR data), or — for CDN input — `fromCDNSeq()` abandoned the
741
+ * rest of the sequence after a hard syntax error (reported internally as a
742
+ * `fatal` warning, which `validate()` promotes to `error` rather than
743
+ * including in `warnings`). For a CDN syntax error this is the original
744
+ * `CdnSyntaxError`, position fields intact.
745
+ */
746
+ error?: Error;
747
+ }
655
748
  /** `fromCBORSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
656
749
  export type FromCBORSeqOptions = Omit<FromCBOROptions, 'offset' | 'allowTrailing'>;
657
750
  /** `fromCDNSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cbortech/cbor",
3
- "version": "0.26.3",
3
+ "version": "0.26.5",
4
4
  "description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values",
5
5
  "keywords": [
6
6
  "cbor",