@cbortech/cbor 0.26.3 → 0.26.4

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
  /**
@@ -652,6 +666,71 @@ export interface CborComments {
652
666
  trailing?: CborComment[];
653
667
  dangling?: CborComment[];
654
668
  }
669
+ /**
670
+ * Options for `CBOR.validate()`.
671
+ */
672
+ export interface ValidateOptions {
673
+ /**
674
+ * Input format.
675
+ * - `'cbor'`: binary CBOR, decoded as a CBOR Sequence (RFC 8742).
676
+ * - `'cdn'`: CDN text, parsed as a CDN Sequence.
677
+ * - `'hex'`: annotated hex dump text, decoded as a CBOR Sequence.
678
+ * @default 'cbor'
679
+ */
680
+ type?: 'cbor' | 'cdn' | 'hex';
681
+ /**
682
+ * Extension plugins used while decoding/parsing.
683
+ * Mirrors `FromCBOROptions.extensions` / `FromCDNOptions.extensions`.
684
+ */
685
+ extensions?: CborExtension[];
686
+ /**
687
+ * Override the default set of bundled application-oriented extensions.
688
+ * Mirrors `FromCBOROptions.builtinExtensions`.
689
+ */
690
+ builtinExtensions?: CborExtension[] | false;
691
+ /**
692
+ * How to handle unrecognised application-extension identifiers.
693
+ * Only applies when `type` is `'cdn'`; mirrors `FromCDNOptions.unresolvedExtension`.
694
+ * @default 'cpa999'
695
+ */
696
+ unresolvedExtension?: 'cpa999' | 'error';
697
+ }
698
+ /**
699
+ * Result of `CBOR.validate()`.
700
+ */
701
+ export interface ValidateResult {
702
+ /**
703
+ * `true` when every item decoded/parsed without error and without any
704
+ * warnings. `false` when the input was malformed (see `error`) or
705
+ * well-formed but in violation of a validity constraint (see `warnings`).
706
+ */
707
+ valid: boolean;
708
+ /** Number of items successfully decoded/parsed before any error. */
709
+ count: number;
710
+ /**
711
+ * Validity violations encountered while decoding/parsing in non-strict
712
+ * mode (recoverable — decoding continued after each one). Excludes
713
+ * informational hints (see `hints`) and the fatal CDN warning that
714
+ * `error` is built from, if any.
715
+ */
716
+ warnings: (DecodeWarning | ParseWarning)[];
717
+ /**
718
+ * Informational hints (`ParseWarning.hint`) encountered while parsing,
719
+ * e.g. an app-string prefix that matches a known optional extension which
720
+ * isn't registered. Hints never affect `valid`; they are collected here so
721
+ * tooling can still surface them.
722
+ */
723
+ hints: ParseWarning[];
724
+ /**
725
+ * Set when decoding/parsing failed outright: either it threw (e.g.
726
+ * truncated CBOR data), or — for CDN input — `fromCDNSeq()` abandoned the
727
+ * rest of the sequence after a hard syntax error (reported internally as a
728
+ * `fatal` warning, which `validate()` promotes to `error` rather than
729
+ * including in `warnings`). For a CDN syntax error this is the original
730
+ * `CdnSyntaxError`, position fields intact.
731
+ */
732
+ error?: Error;
733
+ }
655
734
  /** `fromCBORSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
656
735
  export type FromCBORSeqOptions = Omit<FromCBOROptions, 'offset' | 'allowTrailing'>;
657
736
  /** `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.4",
4
4
  "description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values",
5
5
  "keywords": [
6
6
  "cbor",