bson 4.7.0 → 5.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/bson.d.ts +207 -259
- package/lib/bson.bundle.js +4034 -0
- package/lib/bson.bundle.js.map +1 -0
- package/lib/bson.cjs +4029 -0
- package/lib/bson.cjs.map +1 -0
- package/lib/bson.mjs +4003 -0
- package/lib/bson.mjs.map +1 -0
- package/package.json +49 -62
- package/src/binary.ts +64 -53
- package/src/bson.ts +27 -108
- package/src/code.ts +25 -14
- package/src/constants.ts +33 -0
- package/src/db_ref.ts +14 -8
- package/src/decimal128.ts +32 -25
- package/src/double.ts +8 -5
- package/src/error.ts +0 -2
- package/src/extended_json.ts +148 -148
- package/src/index.ts +19 -0
- package/src/int_32.ts +8 -5
- package/src/long.ts +17 -16
- package/src/max_key.ts +8 -6
- package/src/min_key.ts +8 -6
- package/src/objectid.ts +42 -74
- package/src/parser/calculate_size.ts +39 -63
- package/src/parser/deserializer.ts +41 -112
- package/src/parser/serializer.ts +234 -341
- package/src/parser/utils.ts +1 -99
- package/src/regexp.ts +17 -5
- package/src/symbol.ts +9 -5
- package/src/timestamp.ts +63 -27
- package/src/utils/byte_utils.ts +61 -0
- package/src/utils/node_byte_utils.ts +141 -0
- package/src/utils/web_byte_utils.ts +190 -0
- package/src/uuid_utils.ts +15 -15
- package/bower.json +0 -26
- package/dist/bson.browser.esm.js +0 -7470
- package/dist/bson.browser.esm.js.map +0 -1
- package/dist/bson.browser.umd.js +0 -7537
- package/dist/bson.browser.umd.js.map +0 -1
- package/dist/bson.bundle.js +0 -7536
- package/dist/bson.bundle.js.map +0 -1
- package/dist/bson.esm.js +0 -5436
- package/dist/bson.esm.js.map +0 -1
- package/lib/binary.js +0 -426
- package/lib/binary.js.map +0 -1
- package/lib/bson.js +0 -251
- package/lib/bson.js.map +0 -1
- package/lib/code.js +0 -46
- package/lib/code.js.map +0 -1
- package/lib/constants.js +0 -82
- package/lib/constants.js.map +0 -1
- package/lib/db_ref.js +0 -97
- package/lib/db_ref.js.map +0 -1
- package/lib/decimal128.js +0 -669
- package/lib/decimal128.js.map +0 -1
- package/lib/double.js +0 -76
- package/lib/double.js.map +0 -1
- package/lib/ensure_buffer.js +0 -25
- package/lib/ensure_buffer.js.map +0 -1
- package/lib/error.js +0 -55
- package/lib/error.js.map +0 -1
- package/lib/extended_json.js +0 -390
- package/lib/extended_json.js.map +0 -1
- package/lib/int_32.js +0 -58
- package/lib/int_32.js.map +0 -1
- package/lib/long.js +0 -900
- package/lib/long.js.map +0 -1
- package/lib/map.js +0 -123
- package/lib/map.js.map +0 -1
- package/lib/max_key.js +0 -33
- package/lib/max_key.js.map +0 -1
- package/lib/min_key.js +0 -33
- package/lib/min_key.js.map +0 -1
- package/lib/objectid.js +0 -299
- package/lib/objectid.js.map +0 -1
- package/lib/parser/calculate_size.js +0 -194
- package/lib/parser/calculate_size.js.map +0 -1
- package/lib/parser/deserializer.js +0 -665
- package/lib/parser/deserializer.js.map +0 -1
- package/lib/parser/serializer.js +0 -867
- package/lib/parser/serializer.js.map +0 -1
- package/lib/parser/utils.js +0 -115
- package/lib/parser/utils.js.map +0 -1
- package/lib/regexp.js +0 -74
- package/lib/regexp.js.map +0 -1
- package/lib/symbol.js +0 -48
- package/lib/symbol.js.map +0 -1
- package/lib/timestamp.js +0 -102
- package/lib/timestamp.js.map +0 -1
- package/lib/utils/global.js +0 -18
- package/lib/utils/global.js.map +0 -1
- package/lib/uuid_utils.js +0 -35
- package/lib/uuid_utils.js.map +0 -1
- package/lib/validate_utf8.js +0 -47
- package/lib/validate_utf8.js.map +0 -1
- package/src/ensure_buffer.ts +0 -27
- package/src/map.ts +0 -119
- package/src/utils/global.ts +0 -22
package/src/map.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
// We have an ES6 Map available, return the native instance
|
|
3
|
-
|
|
4
|
-
import { getGlobal } from './utils/global';
|
|
5
|
-
|
|
6
|
-
/** @public */
|
|
7
|
-
let bsonMap: MapConstructor;
|
|
8
|
-
|
|
9
|
-
const bsonGlobal = getGlobal<{ Map?: MapConstructor }>();
|
|
10
|
-
if (bsonGlobal.Map) {
|
|
11
|
-
bsonMap = bsonGlobal.Map;
|
|
12
|
-
} else {
|
|
13
|
-
// We will return a polyfill
|
|
14
|
-
bsonMap = class Map {
|
|
15
|
-
private _keys: string[];
|
|
16
|
-
private _values: Record<string, any>;
|
|
17
|
-
constructor(array: [string, any][] = []) {
|
|
18
|
-
this._keys = [];
|
|
19
|
-
this._values = {};
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < array.length; i++) {
|
|
22
|
-
if (array[i] == null) continue; // skip null and undefined
|
|
23
|
-
const entry = array[i];
|
|
24
|
-
const key = entry[0];
|
|
25
|
-
const value = entry[1];
|
|
26
|
-
// Add the key to the list of keys in order
|
|
27
|
-
this._keys.push(key);
|
|
28
|
-
// Add the key and value to the values dictionary with a point
|
|
29
|
-
// to the location in the ordered keys list
|
|
30
|
-
this._values[key] = { v: value, i: this._keys.length - 1 };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
clear() {
|
|
34
|
-
this._keys = [];
|
|
35
|
-
this._values = {};
|
|
36
|
-
}
|
|
37
|
-
delete(key: string) {
|
|
38
|
-
const value = this._values[key];
|
|
39
|
-
if (value == null) return false;
|
|
40
|
-
// Delete entry
|
|
41
|
-
delete this._values[key];
|
|
42
|
-
// Remove the key from the ordered keys list
|
|
43
|
-
this._keys.splice(value.i, 1);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
entries() {
|
|
47
|
-
let index = 0;
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
next: () => {
|
|
51
|
-
const key = this._keys[index++];
|
|
52
|
-
return {
|
|
53
|
-
value: key !== undefined ? [key, this._values[key].v] : undefined,
|
|
54
|
-
done: key !== undefined ? false : true
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
forEach(callback: (this: this, value: any, key: string, self: this) => void, self?: this) {
|
|
60
|
-
self = self || this;
|
|
61
|
-
|
|
62
|
-
for (let i = 0; i < this._keys.length; i++) {
|
|
63
|
-
const key = this._keys[i];
|
|
64
|
-
// Call the forEach callback
|
|
65
|
-
callback.call(self, this._values[key].v, key, self);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
get(key: string) {
|
|
69
|
-
return this._values[key] ? this._values[key].v : undefined;
|
|
70
|
-
}
|
|
71
|
-
has(key: string) {
|
|
72
|
-
return this._values[key] != null;
|
|
73
|
-
}
|
|
74
|
-
keys() {
|
|
75
|
-
let index = 0;
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
next: () => {
|
|
79
|
-
const key = this._keys[index++];
|
|
80
|
-
return {
|
|
81
|
-
value: key !== undefined ? key : undefined,
|
|
82
|
-
done: key !== undefined ? false : true
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
set(key: string, value: any) {
|
|
88
|
-
if (this._values[key]) {
|
|
89
|
-
this._values[key].v = value;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Add the key to the list of keys in order
|
|
94
|
-
this._keys.push(key);
|
|
95
|
-
// Add the key and value to the values dictionary with a point
|
|
96
|
-
// to the location in the ordered keys list
|
|
97
|
-
this._values[key] = { v: value, i: this._keys.length - 1 };
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
values() {
|
|
101
|
-
let index = 0;
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
next: () => {
|
|
105
|
-
const key = this._keys[index++];
|
|
106
|
-
return {
|
|
107
|
-
value: key !== undefined ? this._values[key].v : undefined,
|
|
108
|
-
done: key !== undefined ? false : true
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
get size() {
|
|
114
|
-
return this._keys.length;
|
|
115
|
-
}
|
|
116
|
-
} as unknown as MapConstructor;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export { bsonMap as Map };
|
package/src/utils/global.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* We do not want to have to include DOM types just for this check */
|
|
3
|
-
declare const window: unknown;
|
|
4
|
-
declare const self: unknown;
|
|
5
|
-
declare const global: unknown;
|
|
6
|
-
|
|
7
|
-
function checkForMath(potentialGlobal: any) {
|
|
8
|
-
// eslint-disable-next-line eqeqeq
|
|
9
|
-
return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
13
|
-
export function getGlobal<T = Record<string, unknown>>(): T {
|
|
14
|
-
return (
|
|
15
|
-
checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
16
|
-
checkForMath(typeof window === 'object' && window) ||
|
|
17
|
-
checkForMath(typeof self === 'object' && self) ||
|
|
18
|
-
checkForMath(typeof global === 'object' && global) ||
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
20
|
-
Function('return this')()
|
|
21
|
-
);
|
|
22
|
-
}
|