bson 6.10.4 β 7.0.0-alpha.1
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 +11 -1
- package/bson.d.ts +21 -14
- package/lib/bson.bundle.js +84 -53
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +84 -53
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +89 -52
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +93 -54
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +83 -55
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +9 -10
- package/src/binary.ts +4 -1
- package/src/bson.ts +1 -1
- package/src/bson_value.ts +24 -1
- package/src/constants.ts +1 -1
- package/src/extended_json.ts +0 -3
- package/src/long.ts +4 -9
- package/src/objectid.ts +25 -25
- package/src/timestamp.ts +10 -1
- package/src/utils/node_byte_utils.ts +15 -22
- package/src/utils/number_utils.ts +4 -13
- package/vendor/base64/LICENSE-MIT.txt +0 -20
- package/vendor/base64/README.md +0 -112
- package/vendor/base64/base64.js +0 -157
- package/vendor/base64/package.json +0 -43
- package/vendor/text-encoding/LICENSE.md +0 -237
- package/vendor/text-encoding/README.md +0 -111
- package/vendor/text-encoding/index.js +0 -9
- package/vendor/text-encoding/lib/encoding-indexes.js +0 -47
- package/vendor/text-encoding/lib/encoding.js +0 -3301
- package/vendor/text-encoding/package.json +0 -37
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"vendor"
|
|
15
15
|
],
|
|
16
16
|
"types": "bson.d.ts",
|
|
17
|
-
"version": "
|
|
17
|
+
"version": "7.0.0-alpha.1",
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "The MongoDB NodeJS Team",
|
|
20
20
|
"email": "dbx-node@mongodb.com"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
33
33
|
"@types/chai": "^4.3.17",
|
|
34
34
|
"@types/mocha": "^10.0.7",
|
|
35
|
-
"@types/node": "^
|
|
35
|
+
"@types/node": "^24.2.1",
|
|
36
36
|
"@types/sinon": "^17.0.4",
|
|
37
37
|
"@types/sinon-chai": "^3.2.12",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
|
@@ -41,13 +41,12 @@
|
|
|
41
41
|
"chai": "^4.4.1",
|
|
42
42
|
"chalk": "^5.3.0",
|
|
43
43
|
"dbx-js-tools": "github:mongodb-js/dbx-js-tools#main",
|
|
44
|
-
"eslint": "^9.
|
|
44
|
+
"eslint": "^9.33.0",
|
|
45
45
|
"eslint-config-prettier": "^10.1.2",
|
|
46
|
-
"eslint-plugin-no-bigint-usage": "file:etc/eslint/no-bigint-usage",
|
|
47
46
|
"eslint-plugin-prettier": "^5.2.6",
|
|
48
47
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
49
48
|
"magic-string": "^0.30.11",
|
|
50
|
-
"mocha": "^
|
|
49
|
+
"mocha": "^11.7.1",
|
|
51
50
|
"node-fetch": "^3.3.2",
|
|
52
51
|
"nyc": "^15.1.0",
|
|
53
52
|
"prettier": "^3.5.3",
|
|
@@ -57,7 +56,8 @@
|
|
|
57
56
|
"source-map-support": "^0.5.21",
|
|
58
57
|
"tar": "^7.4.3",
|
|
59
58
|
"ts-node": "^10.9.2",
|
|
60
|
-
"tsd": "^0.
|
|
59
|
+
"tsd": "^0.33.0",
|
|
60
|
+
"tslib": "^2.8.1",
|
|
61
61
|
"typescript": "^5.8.3",
|
|
62
62
|
"typescript-cached-transpile": "0.0.6",
|
|
63
63
|
"uuid": "^11.1.0"
|
|
@@ -93,15 +93,14 @@
|
|
|
93
93
|
"require": "./lib/bson.cjs"
|
|
94
94
|
},
|
|
95
95
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
96
|
+
"node": ">=20.19.0"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"pretest": "npm run build",
|
|
100
|
-
"test": "npm run check:node && npm run check:web
|
|
100
|
+
"test": "npm run check:node && npm run check:web",
|
|
101
101
|
"check:node": "WEB=false mocha test/node",
|
|
102
102
|
"check:tsd": "npm run build:dts && tsd",
|
|
103
103
|
"check:web": "WEB=true mocha test/node",
|
|
104
|
-
"check:web-no-bigint": "WEB=true NO_BIGINT=true mocha test/node",
|
|
105
104
|
"check:granular-bench": "npm run build:bench && npm run check:baseline-bench && node ./test/bench/etc/run_granular_benchmarks.js",
|
|
106
105
|
"check:spec-bench": "npm run build:bench && npm run check:baseline-bench && node ./test/bench/lib/spec/bsonBench.js",
|
|
107
106
|
"check:custom-bench": "npm run build && npm run check:baseline-bench && node ./test/bench/custom/main.mjs",
|
|
@@ -117,4 +116,4 @@
|
|
|
117
116
|
"prepare": "node etc/prepare.js",
|
|
118
117
|
"release": "standard-version -i HISTORY.md"
|
|
119
118
|
}
|
|
120
|
-
}
|
|
119
|
+
}
|
package/src/binary.ts
CHANGED
|
@@ -45,7 +45,10 @@ export class Binary extends BSONValue {
|
|
|
45
45
|
static readonly SUBTYPE_DEFAULT = 0;
|
|
46
46
|
/** Function BSON type */
|
|
47
47
|
static readonly SUBTYPE_FUNCTION = 1;
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Legacy default BSON Binary type
|
|
50
|
+
* @deprecated BSON Binary subtype 2 is deprecated in the BSON specification
|
|
51
|
+
*/
|
|
49
52
|
static readonly SUBTYPE_BYTE_ARRAY = 2;
|
|
50
53
|
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
|
|
51
54
|
static readonly SUBTYPE_UUID_OLD = 3;
|
package/src/bson.ts
CHANGED
|
@@ -50,7 +50,7 @@ export {
|
|
|
50
50
|
BSONRegExp,
|
|
51
51
|
Decimal128
|
|
52
52
|
};
|
|
53
|
-
export { BSONValue } from './bson_value';
|
|
53
|
+
export { BSONValue, bsonType, type BSONTypeTag } from './bson_value';
|
|
54
54
|
export { BSONError, BSONVersionError, BSONRuntimeError, BSONOffsetError } from './error';
|
|
55
55
|
export { BSONType } from './constants';
|
|
56
56
|
export { EJSON } from './extended_json';
|
package/src/bson_value.ts
CHANGED
|
@@ -2,10 +2,33 @@ import { BSON_MAJOR_VERSION } from './constants';
|
|
|
2
2
|
import { type InspectFn } from './parser/utils';
|
|
3
3
|
import { BSON_VERSION_SYMBOL } from './constants';
|
|
4
4
|
|
|
5
|
+
/** @public */
|
|
6
|
+
export type BSONTypeTag =
|
|
7
|
+
| 'BSONRegExp'
|
|
8
|
+
| 'BSONSymbol'
|
|
9
|
+
| 'ObjectId'
|
|
10
|
+
| 'Binary'
|
|
11
|
+
| 'Decimal128'
|
|
12
|
+
| 'Double'
|
|
13
|
+
| 'Int32'
|
|
14
|
+
| 'Long'
|
|
15
|
+
| 'MaxKey'
|
|
16
|
+
| 'MinKey'
|
|
17
|
+
| 'Timestamp'
|
|
18
|
+
| 'Code'
|
|
19
|
+
| 'DBRef';
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export const bsonType = Symbol.for('@@mdb.bson.type');
|
|
23
|
+
|
|
5
24
|
/** @public */
|
|
6
25
|
export abstract class BSONValue {
|
|
7
26
|
/** @public */
|
|
8
|
-
public abstract get _bsontype():
|
|
27
|
+
public abstract get _bsontype(): BSONTypeTag;
|
|
28
|
+
|
|
29
|
+
public get [bsonType](): this['_bsontype'] {
|
|
30
|
+
return this._bsontype;
|
|
31
|
+
}
|
|
9
32
|
|
|
10
33
|
/** @internal */
|
|
11
34
|
get [BSON_VERSION_SYMBOL](): typeof BSON_MAJOR_VERSION {
|
package/src/constants.ts
CHANGED
package/src/extended_json.ts
CHANGED
|
@@ -102,7 +102,6 @@ function deserializeValue(value: any, options: EJSONOptions = {}) {
|
|
|
102
102
|
}
|
|
103
103
|
if (in64BitRange) {
|
|
104
104
|
if (options.useBigInt64) {
|
|
105
|
-
// eslint-disable-next-line no-restricted-globals -- This is allowed here as useBigInt64=true
|
|
106
105
|
return BigInt(value);
|
|
107
106
|
}
|
|
108
107
|
return Long.fromNumber(value);
|
|
@@ -275,12 +274,10 @@ function serializeValue(value: any, options: EJSONSerializeOptions): any {
|
|
|
275
274
|
}
|
|
276
275
|
|
|
277
276
|
if (typeof value === 'bigint') {
|
|
278
|
-
/* eslint-disable no-restricted-globals -- This is allowed as we are accepting a bigint as input */
|
|
279
277
|
if (!options.relaxed) {
|
|
280
278
|
return { $numberLong: BigInt.asIntN(64, value).toString() };
|
|
281
279
|
}
|
|
282
280
|
return Number(BigInt.asIntN(64, value));
|
|
283
|
-
/* eslint-enable */
|
|
284
281
|
}
|
|
285
282
|
|
|
286
283
|
if (value instanceof RegExp || isRegExp(value)) {
|
package/src/long.ts
CHANGED
|
@@ -258,10 +258,8 @@ export class Long extends BSONValue {
|
|
|
258
258
|
* @returns The corresponding Long value
|
|
259
259
|
*/
|
|
260
260
|
static fromBigInt(value: bigint, unsigned?: boolean): Long {
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
// eslint-disable-next-line no-restricted-globals
|
|
264
|
-
const FROM_BIGINT_BIT_SHIFT = BigInt(32);
|
|
261
|
+
const FROM_BIGINT_BIT_MASK = 0xffffffffn;
|
|
262
|
+
const FROM_BIGINT_BIT_SHIFT = 32n;
|
|
265
263
|
return new Long(
|
|
266
264
|
Number(value & FROM_BIGINT_BIT_MASK),
|
|
267
265
|
Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK),
|
|
@@ -366,7 +364,7 @@ export class Long extends BSONValue {
|
|
|
366
364
|
let unsigned = false;
|
|
367
365
|
if (typeof unsignedOrRadix === 'number') {
|
|
368
366
|
// For goog.math.long compatibility
|
|
369
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
367
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
370
368
|
} else {
|
|
371
369
|
unsigned = !!unsignedOrRadix;
|
|
372
370
|
}
|
|
@@ -456,7 +454,7 @@ export class Long extends BSONValue {
|
|
|
456
454
|
let unsigned = false;
|
|
457
455
|
if (typeof unsignedOrRadix === 'number') {
|
|
458
456
|
// For goog.math.long compatibility
|
|
459
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
457
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
460
458
|
} else {
|
|
461
459
|
unsigned = !!unsignedOrRadix;
|
|
462
460
|
}
|
|
@@ -1077,7 +1075,6 @@ export class Long extends BSONValue {
|
|
|
1077
1075
|
|
|
1078
1076
|
/** Converts the Long to a BigInt (arbitrary precision). */
|
|
1079
1077
|
toBigInt(): bigint {
|
|
1080
|
-
// eslint-disable-next-line no-restricted-globals -- This is allowed here as it is explicitly requesting a bigint
|
|
1081
1078
|
return BigInt(this.toString());
|
|
1082
1079
|
}
|
|
1083
1080
|
|
|
@@ -1223,10 +1220,8 @@ export class Long extends BSONValue {
|
|
|
1223
1220
|
}
|
|
1224
1221
|
|
|
1225
1222
|
if (useBigInt64) {
|
|
1226
|
-
/* eslint-disable no-restricted-globals -- Can use BigInt here as useBigInt64=true */
|
|
1227
1223
|
const bigIntResult = BigInt(doc.$numberLong);
|
|
1228
1224
|
return BigInt.asIntN(64, bigIntResult);
|
|
1229
|
-
/* eslint-enable */
|
|
1230
1225
|
}
|
|
1231
1226
|
|
|
1232
1227
|
const longResult = Long.fromString(doc.$numberLong);
|
package/src/objectid.ts
CHANGED
|
@@ -7,9 +7,6 @@ import { NumberUtils } from './utils/number_utils';
|
|
|
7
7
|
// Unique sequence for the current process (initialized on first use)
|
|
8
8
|
let PROCESS_UNIQUE: Uint8Array | null = null;
|
|
9
9
|
|
|
10
|
-
/** ObjectId hexString cache @internal */
|
|
11
|
-
const __idCache = new WeakMap(); // TODO(NODE-6549): convert this to #__id private field when target updated to ES2022
|
|
12
|
-
|
|
13
10
|
/** @public */
|
|
14
11
|
export interface ObjectIdLike {
|
|
15
12
|
id: string | Uint8Array;
|
|
@@ -35,18 +32,22 @@ export class ObjectId extends BSONValue {
|
|
|
35
32
|
/** @internal */
|
|
36
33
|
private static index = Math.floor(Math.random() * 0xffffff);
|
|
37
34
|
|
|
38
|
-
static cacheHexString: boolean;
|
|
35
|
+
static cacheHexString: boolean = false;
|
|
39
36
|
|
|
40
37
|
/** ObjectId Bytes @internal */
|
|
41
38
|
private buffer!: Uint8Array;
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
|
-
*
|
|
41
|
+
* If hex string caching is enabled, contains the cached hex string. Otherwise, is null.
|
|
45
42
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* Note that #hexString is populated lazily, and as a result simply checking `this.#hexString != null` is
|
|
44
|
+
* not sufficient to determine if caching is enabled. `ObjectId.prototype.isCached()` can be used to
|
|
45
|
+
* determine if the hex string has been cached yet for an ObjectId.
|
|
48
46
|
*/
|
|
49
|
-
|
|
47
|
+
#cachedHexString: string | null = null;
|
|
48
|
+
|
|
49
|
+
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
|
50
|
+
constructor();
|
|
50
51
|
/**
|
|
51
52
|
* Create ObjectId from a 24 character hex string.
|
|
52
53
|
*
|
|
@@ -71,20 +72,18 @@ export class ObjectId extends BSONValue {
|
|
|
71
72
|
* @param inputId - A 12 byte binary Buffer.
|
|
72
73
|
*/
|
|
73
74
|
constructor(inputId: Uint8Array);
|
|
74
|
-
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
|
75
|
-
constructor();
|
|
76
75
|
/**
|
|
77
76
|
* Implementation overload.
|
|
78
77
|
*
|
|
79
78
|
* @param inputId - All input types that are used in the constructor implementation.
|
|
80
79
|
*/
|
|
81
|
-
constructor(inputId?: string |
|
|
80
|
+
constructor(inputId?: string | ObjectId | ObjectIdLike | Uint8Array);
|
|
82
81
|
/**
|
|
83
82
|
* Create a new ObjectId.
|
|
84
83
|
*
|
|
85
84
|
* @param inputId - An input value to create a new ObjectId from.
|
|
86
85
|
*/
|
|
87
|
-
constructor(inputId?: string |
|
|
86
|
+
constructor(inputId?: string | ObjectId | ObjectIdLike | Uint8Array) {
|
|
88
87
|
super();
|
|
89
88
|
// workingId is set based on type of input and whether valid id exists for the input
|
|
90
89
|
let workingId;
|
|
@@ -102,19 +101,19 @@ export class ObjectId extends BSONValue {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
// The following cases use workingId to construct an ObjectId
|
|
105
|
-
if (workingId == null
|
|
104
|
+
if (workingId == null) {
|
|
106
105
|
// The most common use case (blank id, new objectId instance)
|
|
107
106
|
// Generate a new id
|
|
108
|
-
this.buffer = ObjectId.generate(
|
|
107
|
+
this.buffer = ObjectId.generate();
|
|
109
108
|
} else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
|
110
|
-
// If
|
|
109
|
+
// If instanceof matches we can escape calling ensure buffer in Node.js environments
|
|
111
110
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
112
111
|
} else if (typeof workingId === 'string') {
|
|
113
112
|
if (ObjectId.validateHexString(workingId)) {
|
|
114
113
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
115
114
|
// If we are caching the hex string
|
|
116
115
|
if (ObjectId.cacheHexString) {
|
|
117
|
-
|
|
116
|
+
this.#cachedHexString = workingId;
|
|
118
117
|
}
|
|
119
118
|
} else {
|
|
120
119
|
throw new BSONError(
|
|
@@ -137,7 +136,7 @@ export class ObjectId extends BSONValue {
|
|
|
137
136
|
set id(value: Uint8Array) {
|
|
138
137
|
this.buffer = value;
|
|
139
138
|
if (ObjectId.cacheHexString) {
|
|
140
|
-
|
|
139
|
+
this.#cachedHexString = ByteUtils.toHex(value);
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
|
|
@@ -166,15 +165,12 @@ export class ObjectId extends BSONValue {
|
|
|
166
165
|
|
|
167
166
|
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
|
|
168
167
|
toHexString(): string {
|
|
169
|
-
if (
|
|
170
|
-
const __id = __idCache.get(this);
|
|
171
|
-
if (__id) return __id;
|
|
172
|
-
}
|
|
168
|
+
if (this.#cachedHexString) return this.#cachedHexString.toLowerCase();
|
|
173
169
|
|
|
174
170
|
const hexString = ByteUtils.toHex(this.id);
|
|
175
171
|
|
|
176
172
|
if (ObjectId.cacheHexString) {
|
|
177
|
-
|
|
173
|
+
this.#cachedHexString = hexString;
|
|
178
174
|
}
|
|
179
175
|
|
|
180
176
|
return hexString;
|
|
@@ -349,7 +345,7 @@ export class ObjectId extends BSONValue {
|
|
|
349
345
|
* Checks if a value can be used to create a valid bson ObjectId
|
|
350
346
|
* @param id - any JS value
|
|
351
347
|
*/
|
|
352
|
-
static isValid(id: string |
|
|
348
|
+
static isValid(id: string | ObjectId | ObjectIdLike | Uint8Array): boolean {
|
|
353
349
|
if (id == null) return false;
|
|
354
350
|
if (typeof id === 'string') return ObjectId.validateHexString(id);
|
|
355
351
|
|
|
@@ -372,9 +368,13 @@ export class ObjectId extends BSONValue {
|
|
|
372
368
|
return new ObjectId(doc.$oid);
|
|
373
369
|
}
|
|
374
370
|
|
|
375
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* @internal
|
|
373
|
+
*
|
|
374
|
+
* used for testing
|
|
375
|
+
*/
|
|
376
376
|
private isCached(): boolean {
|
|
377
|
-
return ObjectId.cacheHexString &&
|
|
377
|
+
return ObjectId.cacheHexString && this.#cachedHexString != null;
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
/**
|
package/src/timestamp.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { bsonType } from './bson_value';
|
|
1
2
|
import { BSONError } from './error';
|
|
2
3
|
import type { Int32 } from './int_32';
|
|
3
4
|
import { Long } from './long';
|
|
4
5
|
import { type InspectFn, defaultInspect } from './parser/utils';
|
|
5
6
|
|
|
6
7
|
/** @public */
|
|
7
|
-
export type TimestampOverrides =
|
|
8
|
+
export type TimestampOverrides =
|
|
9
|
+
| '_bsontype'
|
|
10
|
+
| 'toExtendedJSON'
|
|
11
|
+
| 'fromExtendedJSON'
|
|
12
|
+
| 'inspect'
|
|
13
|
+
| typeof bsonType;
|
|
8
14
|
/** @public */
|
|
9
15
|
export type LongWithoutOverrides = new (
|
|
10
16
|
low: unknown,
|
|
@@ -35,6 +41,9 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
35
41
|
get _bsontype(): 'Timestamp' {
|
|
36
42
|
return 'Timestamp';
|
|
37
43
|
}
|
|
44
|
+
get [bsonType](): 'Timestamp' {
|
|
45
|
+
return 'Timestamp';
|
|
46
|
+
}
|
|
38
47
|
|
|
39
48
|
static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
40
49
|
|
|
@@ -17,7 +17,7 @@ type NodeJsBufferConstructor = Omit<Uint8ArrayConstructor, 'from'> & {
|
|
|
17
17
|
from(array: number[]): NodeJsBuffer;
|
|
18
18
|
from(array: Uint8Array): NodeJsBuffer;
|
|
19
19
|
from(array: ArrayBuffer): NodeJsBuffer;
|
|
20
|
-
from(array:
|
|
20
|
+
from(array: ArrayBufferLike, byteOffset: number, byteLength: number): NodeJsBuffer;
|
|
21
21
|
from(base64: string, encoding: NodeJsEncoding): NodeJsBuffer;
|
|
22
22
|
byteLength(input: string, encoding: 'utf8'): number;
|
|
23
23
|
isBuffer(value: unknown): value is NodeJsBuffer;
|
|
@@ -26,34 +26,27 @@ type NodeJsBufferConstructor = Omit<Uint8ArrayConstructor, 'from'> & {
|
|
|
26
26
|
// This can be nullish, but we gate the nodejs functions on being exported whether or not this exists
|
|
27
27
|
// Node.js global
|
|
28
28
|
declare const Buffer: NodeJsBufferConstructor;
|
|
29
|
-
declare const require: (mod: 'crypto') => { randomBytes: (byteLength: number) => Uint8Array };
|
|
30
29
|
|
|
31
30
|
/** @internal */
|
|
32
|
-
|
|
31
|
+
function nodejsMathRandomBytes(byteLength: number): NodeJsBuffer {
|
|
33
32
|
return nodeJsByteUtils.fromNumberArray(
|
|
34
33
|
Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256))
|
|
35
34
|
);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* when generating an es module bundle.
|
|
52
|
-
*/
|
|
53
|
-
const nodejsRandomBytes: (byteLength: number) => Uint8Array = (() => {
|
|
54
|
-
try {
|
|
55
|
-
return require('crypto').randomBytes;
|
|
56
|
-
} catch {
|
|
37
|
+
/** @internal */
|
|
38
|
+
function nodejsSecureRandomBytes(byteLength: number): NodeJsBuffer {
|
|
39
|
+
// @ts-expect-error: crypto.getRandomValues cannot actually be null here
|
|
40
|
+
return crypto.getRandomValues(nodeJsByteUtils.allocate(byteLength));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const nodejsRandomBytes = (() => {
|
|
44
|
+
const { crypto } = globalThis as {
|
|
45
|
+
crypto?: { getRandomValues?: (space: Uint8Array) => Uint8Array };
|
|
46
|
+
};
|
|
47
|
+
if (crypto != null && typeof crypto.getRandomValues === 'function') {
|
|
48
|
+
return nodejsSecureRandomBytes;
|
|
49
|
+
} else {
|
|
57
50
|
return nodejsMathRandomBytes;
|
|
58
51
|
}
|
|
59
52
|
})();
|
|
@@ -83,7 +83,6 @@ export const NumberUtils: NumberUtils = {
|
|
|
83
83
|
|
|
84
84
|
/** Reads a little-endian 64-bit integer from source */
|
|
85
85
|
getBigInt64LE(source: Uint8Array, offset: number): bigint {
|
|
86
|
-
// eslint-disable-next-line no-restricted-globals
|
|
87
86
|
const hi = BigInt(
|
|
88
87
|
source[offset + 4] +
|
|
89
88
|
source[offset + 5] * 256 +
|
|
@@ -91,15 +90,14 @@ export const NumberUtils: NumberUtils = {
|
|
|
91
90
|
(source[offset + 7] << 24)
|
|
92
91
|
); // Overflow
|
|
93
92
|
|
|
94
|
-
// eslint-disable-next-line no-restricted-globals
|
|
95
93
|
const lo = BigInt(
|
|
96
94
|
source[offset] +
|
|
97
95
|
source[offset + 1] * 256 +
|
|
98
96
|
source[offset + 2] * 65536 +
|
|
99
97
|
source[offset + 3] * 16777216
|
|
100
98
|
);
|
|
101
|
-
|
|
102
|
-
return (hi <<
|
|
99
|
+
|
|
100
|
+
return (hi << 32n) + lo;
|
|
103
101
|
},
|
|
104
102
|
|
|
105
103
|
/** Reads a little-endian 64-bit float from source */
|
|
@@ -153,8 +151,7 @@ export const NumberUtils: NumberUtils = {
|
|
|
153
151
|
|
|
154
152
|
/** Write a little-endian 64-bit integer to source */
|
|
155
153
|
setBigInt64LE(destination: Uint8Array, offset: number, value: bigint): 8 {
|
|
156
|
-
|
|
157
|
-
const mask32bits = BigInt(0xffff_ffff);
|
|
154
|
+
const mask32bits = 0xffff_ffffn;
|
|
158
155
|
|
|
159
156
|
/** lower 32 bits */
|
|
160
157
|
let lo = Number(value & mask32bits);
|
|
@@ -166,13 +163,7 @@ export const NumberUtils: NumberUtils = {
|
|
|
166
163
|
lo >>= 8;
|
|
167
164
|
destination[offset + 3] = lo;
|
|
168
165
|
|
|
169
|
-
|
|
170
|
-
eslint-disable-next-line no-restricted-globals
|
|
171
|
-
-- This is allowed here as useBigInt64=true
|
|
172
|
-
|
|
173
|
-
upper 32 bits
|
|
174
|
-
*/
|
|
175
|
-
let hi = Number((value >> BigInt(32)) & mask32bits);
|
|
166
|
+
let hi = Number((value >> 32n) & mask32bits);
|
|
176
167
|
destination[offset + 4] = hi;
|
|
177
168
|
hi >>= 8;
|
|
178
169
|
destination[offset + 5] = hi;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/vendor/base64/README.md
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# base64 [](https://travis-ci.org/mathiasbynens/base64) [](https://coveralls.io/r/mathiasbynens/base64)
|
|
2
|
-
|
|
3
|
-
_base64_ is a robust base64 encoder/decoder that is fully compatible with [`atob()` and `btoa()`](https://html.spec.whatwg.org/multipage/webappapis.html#atob), written in JavaScript. The base64-encoding and -decoding algorithms it uses are fully [RFC 4648](https://tools.ietf.org/html/rfc4648#section-4) compliant.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Via [npm](https://www.npmjs.com/):
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install base-64
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
In a browser:
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<script src="base64.js"></script>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
In [Narwhal](http://narwhaljs.org/), [Node.js](https://nodejs.org/), and [RingoJS](http://ringojs.org/):
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
var base64 = require('base-64');
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
In [Rhino](http://www.mozilla.org/rhino/):
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
load('base64.js');
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Using an AMD loader like [RequireJS](http://requirejs.org/):
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
require(
|
|
35
|
-
{
|
|
36
|
-
'paths': {
|
|
37
|
-
'base64': 'path/to/base64'
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
['base64'],
|
|
41
|
-
function(base64) {
|
|
42
|
-
console.log(base64);
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## API
|
|
48
|
-
|
|
49
|
-
### `base64.version`
|
|
50
|
-
|
|
51
|
-
A string representing the semantic version number.
|
|
52
|
-
|
|
53
|
-
### `base64.encode(input)`
|
|
54
|
-
|
|
55
|
-
This function takes a byte string (the `input` parameter) and encodes it according to base64. The input data must be in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values `0x00` to `0xFF`. The `base64.encode()` function is designed to be fully compatible with [`btoa()` as described in the HTML Standard](https://html.spec.whatwg.org/multipage/webappapis.html#dom-windowbase64-btoa).
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
var encodedData = base64.encode(input);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
To base64-encode any Unicode string, [encode it as UTF-8 first](https://github.com/mathiasbynens/utf8.js#utf8encodestring):
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
var base64 = require('base-64');
|
|
65
|
-
var utf8 = require('utf8');
|
|
66
|
-
|
|
67
|
-
var text = 'foo Β© bar π baz';
|
|
68
|
-
var bytes = utf8.encode(text);
|
|
69
|
-
var encoded = base64.encode(bytes);
|
|
70
|
-
console.log(encoded);
|
|
71
|
-
// β 'Zm9vIMKpIGJhciDwnYyGIGJheg=='
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### `base64.decode(input)`
|
|
75
|
-
|
|
76
|
-
This function takes a base64-encoded string (the `input` parameter) and decodes it. The return value is in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values `0x00` to `0xFF`. The `base64.decode()` function is designed to be fully compatible with [`atob()` as described in the HTML Standard](https://html.spec.whatwg.org/multipage/webappapis.html#dom-windowbase64-atob).
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
var decodedData = base64.decode(encodedData);
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
To base64-decode UTF-8-encoded data back into a Unicode string, [UTF-8-decode it](https://github.com/mathiasbynens/utf8.js#utf8decodebytestring) after base64-decoding it:
|
|
83
|
-
|
|
84
|
-
```js
|
|
85
|
-
var encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';
|
|
86
|
-
var bytes = base64.decode(encoded);
|
|
87
|
-
var text = utf8.decode(bytes);
|
|
88
|
-
console.log(text);
|
|
89
|
-
// β 'foo Β© bar π baz'
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Support
|
|
93
|
-
|
|
94
|
-
_base64_ is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.
|
|
95
|
-
|
|
96
|
-
## Unit tests & code coverage
|
|
97
|
-
|
|
98
|
-
After cloning this repository, run `npm install` to install the dependencies needed for development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.
|
|
99
|
-
|
|
100
|
-
Once thatβs done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use `grunt test`.
|
|
101
|
-
|
|
102
|
-
To generate the code coverage report, use `grunt cover`.
|
|
103
|
-
|
|
104
|
-
## Author
|
|
105
|
-
|
|
106
|
-
| [](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
|
107
|
-
|---|
|
|
108
|
-
| [Mathias Bynens](https://mathiasbynens.be/) |
|
|
109
|
-
|
|
110
|
-
## License
|
|
111
|
-
|
|
112
|
-
_base64_ is available under the [MIT](https://mths.be/mit) license.
|