cbor-x 1.5.8 → 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/README.md +12 -0
- package/decode.d.ts +1 -1
- package/decode.js +67 -9
- package/dist/decode-no-eval.cjs +65 -9
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +92 -25
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +92 -25
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +93 -25
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +149 -42
- package/dist/test.js.map +1 -1
- package/encode.js +28 -16
- package/index.d.ts +6 -1
- package/index.js +1 -1
- package/node-index.js +1 -1
- package/package.json +9 -3
package/encode.js
CHANGED
|
@@ -469,7 +469,7 @@ export class Encoder extends Decoder {
|
|
|
469
469
|
}
|
|
470
470
|
let constructor = value.constructor
|
|
471
471
|
if (constructor === Object) {
|
|
472
|
-
writeObject(value
|
|
472
|
+
writeObject(value)
|
|
473
473
|
} else if (constructor === Array) {
|
|
474
474
|
length = value.length
|
|
475
475
|
if (length < 0x18) {
|
|
@@ -564,8 +564,8 @@ export class Encoder extends Decoder {
|
|
|
564
564
|
return encode(json)
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
-
// no extension found, write as object
|
|
568
|
-
writeObject(value
|
|
567
|
+
// no extension found, write as a plain object
|
|
568
|
+
writeObject(value)
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
} else if (type === 'boolean') {
|
|
@@ -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
|
-
|
|
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
|
|
@@ -628,19 +640,19 @@ export class Encoder extends Decoder {
|
|
|
628
640
|
}
|
|
629
641
|
}
|
|
630
642
|
} :
|
|
631
|
-
(object
|
|
643
|
+
(object) => {
|
|
632
644
|
target[position++] = 0xb9 // always use map 16, so we can preallocate and set the length afterwards
|
|
633
645
|
let objectOffset = position - start
|
|
634
646
|
position += 2
|
|
635
647
|
let size = 0
|
|
636
|
-
if (encoder.keyMap) {
|
|
637
|
-
for (let key in object) if (
|
|
648
|
+
if (encoder.keyMap) {
|
|
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])
|
|
640
652
|
size++
|
|
641
653
|
}
|
|
642
654
|
} else {
|
|
643
|
-
for (let key in object) if (
|
|
655
|
+
for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
|
|
644
656
|
encode(key)
|
|
645
657
|
encode(object[key])
|
|
646
658
|
size++
|
|
@@ -649,7 +661,7 @@ export class Encoder extends Decoder {
|
|
|
649
661
|
target[objectOffset++ + start] = size >> 8
|
|
650
662
|
target[objectOffset + start] = size & 0xff
|
|
651
663
|
} :
|
|
652
|
-
(object,
|
|
664
|
+
(object, skipValues) => {
|
|
653
665
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
|
|
654
666
|
let newTransitions = 0
|
|
655
667
|
let length = 0
|
|
@@ -668,7 +680,7 @@ export class Encoder extends Decoder {
|
|
|
668
680
|
transition = nextTransition
|
|
669
681
|
}
|
|
670
682
|
} else {
|
|
671
|
-
for (let key in object) if (
|
|
683
|
+
for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
|
|
672
684
|
nextTransition = transition[key]
|
|
673
685
|
if (!nextTransition) {
|
|
674
686
|
if (transition[RECORD_SYMBOL] & 0x100000) {// this indicates it is a brancheable/extendable terminal node, so we will use this record id and extend it
|
|
@@ -728,9 +740,9 @@ export class Encoder extends Decoder {
|
|
|
728
740
|
writeArrayHeader(length + 2)
|
|
729
741
|
encode(0xe000 + recordId)
|
|
730
742
|
encode(keys)
|
|
731
|
-
if (
|
|
743
|
+
if (skipValues) return; // special exit for iterator
|
|
732
744
|
for (let key in object)
|
|
733
|
-
if (
|
|
745
|
+
if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
|
|
734
746
|
encode(object[key])
|
|
735
747
|
return
|
|
736
748
|
}
|
|
@@ -740,9 +752,9 @@ export class Encoder extends Decoder {
|
|
|
740
752
|
} else {
|
|
741
753
|
writeArrayHeader(length)
|
|
742
754
|
}
|
|
743
|
-
if (
|
|
755
|
+
if (skipValues) return; // special exit for iterator
|
|
744
756
|
for (let key in object)
|
|
745
|
-
if (
|
|
757
|
+
if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
|
|
746
758
|
encode(object[key])
|
|
747
759
|
}
|
|
748
760
|
const makeRoom = (end) => {
|
|
@@ -780,7 +792,7 @@ export class Encoder extends Decoder {
|
|
|
780
792
|
if (constructor === Object) {
|
|
781
793
|
let useRecords = encoder.useRecords !== false;
|
|
782
794
|
if (useRecords)
|
|
783
|
-
writeObject(object,
|
|
795
|
+
writeObject(object, true); // write the record identifier
|
|
784
796
|
else
|
|
785
797
|
writeEntityLength(Object.keys(object).length, 0xa0);
|
|
786
798
|
for (let key in object) {
|
|
@@ -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.
|
|
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",
|
|
@@ -55,8 +55,14 @@
|
|
|
55
55
|
"import": "./decode.js"
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"./decode-no-eval":
|
|
59
|
-
|
|
58
|
+
"./decode-no-eval": {
|
|
59
|
+
"types": "./decode.d.ts",
|
|
60
|
+
"default": "./dist/decode-no-eval.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./index-no-eval": {
|
|
63
|
+
"types": "./index.d.ts",
|
|
64
|
+
"default": "./dist/index-no-eval.cjs"
|
|
65
|
+
},
|
|
60
66
|
"./package.json": "./package.json"
|
|
61
67
|
},
|
|
62
68
|
"files": [
|