bson 4.7.0 → 5.0.0-alpha.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.
Files changed (98) hide show
  1. package/bson.d.ts +207 -259
  2. package/lib/bson.bundle.js +4033 -0
  3. package/lib/bson.bundle.js.map +1 -0
  4. package/lib/bson.cjs +4028 -0
  5. package/lib/bson.cjs.map +1 -0
  6. package/lib/bson.mjs +4002 -0
  7. package/lib/bson.mjs.map +1 -0
  8. package/package.json +49 -62
  9. package/src/binary.ts +63 -52
  10. package/src/bson.ts +27 -108
  11. package/src/code.ts +24 -14
  12. package/src/constants.ts +28 -0
  13. package/src/db_ref.ts +13 -8
  14. package/src/decimal128.ts +31 -25
  15. package/src/double.ts +7 -5
  16. package/src/error.ts +0 -2
  17. package/src/extended_json.ts +148 -148
  18. package/src/index.ts +19 -0
  19. package/src/int_32.ts +7 -5
  20. package/src/long.ts +16 -16
  21. package/src/max_key.ts +6 -6
  22. package/src/min_key.ts +6 -6
  23. package/src/objectid.ts +41 -74
  24. package/src/parser/calculate_size.ts +39 -63
  25. package/src/parser/deserializer.ts +41 -112
  26. package/src/parser/serializer.ts +234 -341
  27. package/src/parser/utils.ts +1 -99
  28. package/src/regexp.ts +16 -5
  29. package/src/symbol.ts +7 -5
  30. package/src/timestamp.ts +62 -27
  31. package/src/utils/byte_utils.ts +61 -0
  32. package/src/utils/node_byte_utils.ts +141 -0
  33. package/src/utils/web_byte_utils.ts +190 -0
  34. package/src/uuid_utils.ts +15 -15
  35. package/bower.json +0 -26
  36. package/dist/bson.browser.esm.js +0 -7470
  37. package/dist/bson.browser.esm.js.map +0 -1
  38. package/dist/bson.browser.umd.js +0 -7537
  39. package/dist/bson.browser.umd.js.map +0 -1
  40. package/dist/bson.bundle.js +0 -7536
  41. package/dist/bson.bundle.js.map +0 -1
  42. package/dist/bson.esm.js +0 -5436
  43. package/dist/bson.esm.js.map +0 -1
  44. package/lib/binary.js +0 -426
  45. package/lib/binary.js.map +0 -1
  46. package/lib/bson.js +0 -251
  47. package/lib/bson.js.map +0 -1
  48. package/lib/code.js +0 -46
  49. package/lib/code.js.map +0 -1
  50. package/lib/constants.js +0 -82
  51. package/lib/constants.js.map +0 -1
  52. package/lib/db_ref.js +0 -97
  53. package/lib/db_ref.js.map +0 -1
  54. package/lib/decimal128.js +0 -669
  55. package/lib/decimal128.js.map +0 -1
  56. package/lib/double.js +0 -76
  57. package/lib/double.js.map +0 -1
  58. package/lib/ensure_buffer.js +0 -25
  59. package/lib/ensure_buffer.js.map +0 -1
  60. package/lib/error.js +0 -55
  61. package/lib/error.js.map +0 -1
  62. package/lib/extended_json.js +0 -390
  63. package/lib/extended_json.js.map +0 -1
  64. package/lib/int_32.js +0 -58
  65. package/lib/int_32.js.map +0 -1
  66. package/lib/long.js +0 -900
  67. package/lib/long.js.map +0 -1
  68. package/lib/map.js +0 -123
  69. package/lib/map.js.map +0 -1
  70. package/lib/max_key.js +0 -33
  71. package/lib/max_key.js.map +0 -1
  72. package/lib/min_key.js +0 -33
  73. package/lib/min_key.js.map +0 -1
  74. package/lib/objectid.js +0 -299
  75. package/lib/objectid.js.map +0 -1
  76. package/lib/parser/calculate_size.js +0 -194
  77. package/lib/parser/calculate_size.js.map +0 -1
  78. package/lib/parser/deserializer.js +0 -665
  79. package/lib/parser/deserializer.js.map +0 -1
  80. package/lib/parser/serializer.js +0 -867
  81. package/lib/parser/serializer.js.map +0 -1
  82. package/lib/parser/utils.js +0 -115
  83. package/lib/parser/utils.js.map +0 -1
  84. package/lib/regexp.js +0 -74
  85. package/lib/regexp.js.map +0 -1
  86. package/lib/symbol.js +0 -48
  87. package/lib/symbol.js.map +0 -1
  88. package/lib/timestamp.js +0 -102
  89. package/lib/timestamp.js.map +0 -1
  90. package/lib/utils/global.js +0 -18
  91. package/lib/utils/global.js.map +0 -1
  92. package/lib/uuid_utils.js +0 -35
  93. package/lib/uuid_utils.js.map +0 -1
  94. package/lib/validate_utf8.js +0 -47
  95. package/lib/validate_utf8.js.map +0 -1
  96. package/src/ensure_buffer.ts +0 -27
  97. package/src/map.ts +0 -119
  98. 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 };
@@ -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
- }