cbor-x 1.5.3 → 1.5.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/encode.js CHANGED
@@ -557,6 +557,13 @@ export class Encoder extends Decoder {
557
557
  error.iteratorNotHandled = true;
558
558
  throw error;
559
559
  }
560
+ if (this.useToJSON && value.toJSON) {
561
+ const json = value.toJSON()
562
+ // if for some reason value.toJSON returns itself it'll loop forever
563
+ if (json !== value)
564
+ return encode(json)
565
+ }
566
+
560
567
  // no extension found, write as object
561
568
  writeObject(value, !value.hasOwnProperty) // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
562
569
  }
@@ -611,7 +618,7 @@ export class Encoder extends Decoder {
611
618
  let key
612
619
  if (encoder.keyMap) {
613
620
  for (let i = 0; i < length; i++) {
614
- encode(encodeKey(keys[i]))
621
+ encode(encoder.encodeKey(keys[i]))
615
622
  encode(vals[i])
616
623
  }
617
624
  } else {
package/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export interface Options {
21
21
  maxSharedStructures?: number
22
22
  maxOwnStructures?: number
23
23
  useSelfDescribedHeader?: boolean
24
+ useToJSON?: boolean
24
25
  keyMap?: {}
25
26
  shouldShareStructure?: (keys: string[]) => boolean
26
27
  getStructures?(): {}[]
@@ -28,6 +29,7 @@ export interface Options {
28
29
  onInvalidDate?: () => any
29
30
  tagUint8Array?: boolean
30
31
  pack?: boolean
32
+ sequential?: boolean
31
33
  }
32
34
  type ClassOf<T> = new (...args: any[]) => T;
33
35
  interface Extension<T, R> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cbor-x",
3
3
  "author": "Kris Zyp",
4
- "version": "1.5.3",
4
+ "version": "1.5.5",
5
5
  "description": "Ultra-fast and conformant CBOR (RFC 8949) implementation with support for numerous tag extensions including records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/stream.js CHANGED
@@ -13,10 +13,12 @@ export class EncoderStream extends Transform {
13
13
  this.encoder = options.encoder || new Encoder(options)
14
14
  }
15
15
  async _transform(value, encoding, callback) {
16
- for await (let chunk of this.encoder.encodeAsAsyncIterable(value)) {
17
- this.push(chunk)
18
- }
19
- callback()
16
+ try {
17
+ for await (let chunk of this.encoder.encodeAsAsyncIterable(value)) {
18
+ this.push(chunk)
19
+ }
20
+ callback()
21
+ } catch(error) { callback (error) }
20
22
  }
21
23
  }
22
24
 
@@ -37,13 +39,14 @@ export class DecoderStream extends Transform {
37
39
  let values
38
40
  try {
39
41
  values = this.decoder.decodeMultiple(chunk)
42
+ callback()
40
43
  } catch(error) {
41
44
  if (error.incomplete) {
42
45
  this.incompleteBuffer = chunk.slice(error.lastPosition)
43
46
  values = error.values
47
+ } else {
48
+ callback(error)
44
49
  }
45
- else
46
- throw error
47
50
  } finally {
48
51
  for (let value of values || []) {
49
52
  if (value === null)
@@ -51,7 +54,6 @@ export class DecoderStream extends Transform {
51
54
  this.push(value)
52
55
  }
53
56
  }
54
- if (callback) callback()
55
57
  }
56
58
  getNullValue() {
57
59
  return Symbol.for(null)