@cbortech/cbor 0.25.6 → 0.25.8

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,8 +114,10 @@ export interface FromCBOROptions {
114
114
  * Allow bytes after the decoded item.
115
115
  *
116
116
  * When `false`, decoding still requires the item to consume the remaining
117
- * input, preserving the historical single-item behaviour. Set this to `true`
118
- * when using `CborItem.end` to continue decoding a CBOR Sequence.
117
+ * input, preserving the historical single-item behaviour. With `strict: false`
118
+ * a trailing byte becomes a recoverable warning rather than an error, but
119
+ * truly malformed trailing data (e.g. truncated items) still throws. Set this
120
+ * to `true` when using `CborItem.end` to continue decoding a CBOR Sequence.
119
121
  *
120
122
  * @example
121
123
  * // Read two items from a CBOR Sequence, validating that the second is last.
@@ -141,7 +143,9 @@ export interface FromCBOROptions {
141
143
  * with a best-effort interpretation of the data.
142
144
  *
143
145
  * Truly malformed data (e.g. truncated input, reserved AI values) always
144
- * throws regardless of this setting.
146
+ * throws regardless of this setting. Trailing bytes after a successfully
147
+ * decoded item are a recoverable violation and are therefore controlled by
148
+ * this flag.
145
149
  *
146
150
  * @default true
147
151
  */
@@ -176,6 +180,27 @@ export interface FromHexDumpOptions {
176
180
  * returning a non-`undefined` value replaces the default `CborTag` node.
177
181
  */
178
182
  extensions?: CborExtension[];
183
+ /**
184
+ * Controls how CBOR validity violations are handled during hex-dump decoding.
185
+ * Mirrors `FromCBOROptions.strict`. With `strict: false`, trailing bytes after
186
+ * the first decoded item (i.e. a CBOR Sequence) emit a warning instead of
187
+ * throwing, allowing the first item to be returned.
188
+ *
189
+ * @default true
190
+ */
191
+ strict?: boolean;
192
+ /**
193
+ * Callback invoked when a CBOR validity violation is detected.
194
+ * Mirrors `FromCBOROptions.onWarning`.
195
+ */
196
+ onWarning?: (warning: DecodeWarning) => void;
197
+ /**
198
+ * When `true`, suppresses the default `console.warn` output for violations.
199
+ * Mirrors `FromCBOROptions.silent`.
200
+ *
201
+ * @default false
202
+ */
203
+ silent?: boolean;
179
204
  }
180
205
  export interface FromCDNOptions {
181
206
  /**
@@ -189,8 +214,11 @@ export interface FromCDNOptions {
189
214
  * Allow tokens after the parsed item.
190
215
  *
191
216
  * When `false`, parsing still requires the item to consume the remaining
192
- * input, preserving the historical single-item behaviour. Set this to `true`
193
- * when using `CborItem.end` to continue parsing a CDN sequence.
217
+ * input, preserving the historical single-item behaviour. With `strict: false`
218
+ * a trailing token becomes a recoverable warning rather than an error, but
219
+ * hard lexer errors in the trailing content (e.g. unterminated strings) still
220
+ * throw. Set this to `true` when using `CborItem.end` to continue parsing a
221
+ * CDN sequence.
194
222
  * Top-level comma separators are not skipped by `fromCDN()` itself; handle
195
223
  * them in sequence-level code before passing the next `offset`. For example,
196
224
  * after parsing `1, 2`, the first item's `end` points just before the comma;
@@ -258,8 +286,10 @@ export interface FromCDNOptions {
258
286
  * - `false`: recoverable violations call `onWarning` and parsing continues
259
287
  * with a best-effort interpretation of the input.
260
288
  *
261
- * Hard syntax errors (e.g. unterminated strings, unexpected tokens) always
262
- * throw regardless of this setting.
289
+ * Hard syntax errors (e.g. unterminated strings, unexpected tokens that
290
+ * prevent parsing a value) always throw regardless of this setting.
291
+ * A trailing token after a successfully-parsed value is a recoverable
292
+ * violation and is therefore controlled by this flag.
263
293
  *
264
294
  * @default true
265
295
  */
@@ -473,6 +503,10 @@ export interface CborComments {
473
503
  trailing?: CborComment[];
474
504
  dangling?: CborComment[];
475
505
  }
506
+ /** `fromCBORSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
507
+ export type FromCBORSeqOptions = Omit<FromCBOROptions, 'offset' | 'allowTrailing'>;
508
+ /** `fromCDNSeq()` の options(`offset`/`allowTrailing` はジェネレータが管理するため除外)。 */
509
+ export type FromCDNSeqOptions = Omit<FromCDNOptions, 'offset' | 'allowTrailing'>;
476
510
  /**
477
511
  * Combined options for the `CBOR` constructor.
478
512
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cbortech/cbor",
3
- "version": "0.25.6",
3
+ "version": "0.25.8",
4
4
  "description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values",
5
5
  "keywords": [
6
6
  "cbor",
@@ -108,10 +108,10 @@
108
108
  "@vitest/coverage-v8": "^4.1.9",
109
109
  "@vitest/ui": "^4.1.9",
110
110
  "cross-env": "^10.1.0",
111
- "playwright": "^1.61.0",
111
+ "playwright": "^1.61.1",
112
112
  "prettier": "^3.8.4",
113
113
  "typescript": "^5.9.3",
114
- "vite": "^8.0.16",
114
+ "vite": "^8.1.0",
115
115
  "vite-plugin-dts": "^4.5.4",
116
116
  "vitest": "^4.1.9"
117
117
  }