cbor-x 1.5.9 → 1.6.0

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
@@ -585,7 +585,19 @@ export class Encoder extends Decoder {
585
585
  target[position++] = 0xfb
586
586
  targetView.setFloat64(position, Number(value))
587
587
  } else {
588
- throw new RangeError(value + ' was too large to fit in CBOR 64-bit integer format, set largeBigIntToFloat to convert to float-64')
588
+ if (value >= BigInt(0))
589
+ target[position++] = 0xc2 // tag 2
590
+ else {
591
+ target[position++] = 0xc3 // tag 2
592
+ value = BigInt(-1) - value;
593
+ }
594
+ let bytes = [];
595
+ while (value) {
596
+ bytes.push(Number(value & BigInt(0xff)));
597
+ value >>= BigInt(8);
598
+ }
599
+ writeBuffer(new Uint8Array(bytes.reverse()), makeRoom);
600
+ return;
589
601
  }
590
602
  }
591
603
  position += 8
@@ -633,7 +645,7 @@ export class Encoder extends Decoder {
633
645
  let objectOffset = position - start
634
646
  position += 2
635
647
  let size = 0
636
- if (encoder.keyMap) {
648
+ if (encoder.keyMap) {
637
649
  for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
638
650
  encode(encoder.encodeKey(key))
639
651
  encode(object[key])
@@ -805,7 +817,7 @@ export class Encoder extends Decoder {
805
817
  yield* tryEncode(value, iterateProperties, 'element');
806
818
  } else encode(value);
807
819
  }
808
- } else if (object[Symbol.iterator]) {
820
+ } else if (object[Symbol.iterator] && !object.buffer) { // iterator, but exclude typed arrays
809
821
  target[position++] = 0x9f; // start indefinite array
810
822
  for (let value of object) {
811
823
  if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
package/index.d.ts CHANGED
@@ -4,7 +4,11 @@ export enum FLOAT32_OPTIONS {
4
4
  DECIMAL_ROUND = 3,
5
5
  DECIMAL_FIT = 4
6
6
  }
7
-
7
+ export interface SizeLimitOptions {
8
+ maxArraySize: number;
9
+ maxMapSize: number;
10
+ maxObjectSize: number;
11
+ }
8
12
  export interface Options {
9
13
  alwaysUseFloat?: boolean
10
14
  useFloat32?: FLOAT32_OPTIONS
@@ -43,6 +47,7 @@ export class Decoder {
43
47
  decode(messagePack: Buffer | Uint8Array): any
44
48
  decodeMultiple(messagePack: Buffer | Uint8Array, forEach?: (value: any) => any): [] | void
45
49
  }
50
+ export function setMaxLimits(options: SizeLimitOptions): void
46
51
  export function decode(messagePack: Buffer | Uint8Array): any
47
52
  export function decodeMultiple(messagePack: Buffer | Uint8Array, forEach?: (value: any) => any): [] | void
48
53
  export function addExtension<T, R>(extension: Extension<T, R>): void
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { Encoder, addExtension, encode, encodeAsIterable, encodeAsAsyncIterable, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE } from './encode.js'
2
- export { Tag, Decoder, decodeMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './decode.js'
2
+ export { Tag, Decoder, decodeMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled, setSizeLimits } from './decode.js'
3
3
  export { decodeIter, encodeIter } from './iterators.js'
package/node-index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Encoder, addExtension, encode, encodeAsIterable, encodeAsAsyncIterable, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE } from './encode.js'
2
- export { Tag, Decoder, decodeMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './decode.js'
2
+ export { Tag, Decoder, decodeMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled, setSizeLimits } from './decode.js'
3
3
  export { EncoderStream, DecoderStream } from './stream.js'
4
4
  export { decodeIter, encodeIter } from './iterators.js'
5
5
  export const useRecords = false
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cbor-x",
3
3
  "author": "Kris Zyp",
4
- "version": "1.5.9",
4
+ "version": "1.6.0",
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",