hadron-type-checker 6.5.0 → 6.8.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/index.d.ts +51 -0
- package/package.json +2 -2
- package/src/type-checker.js +6 -7
package/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ObjectId,
|
|
3
|
+
MinKey,
|
|
4
|
+
MaxKey,
|
|
5
|
+
Long,
|
|
6
|
+
Double,
|
|
7
|
+
Int32,
|
|
8
|
+
Decimal128,
|
|
9
|
+
Binary,
|
|
10
|
+
BSONRegExp,
|
|
11
|
+
Code,
|
|
12
|
+
BSONSymbol,
|
|
13
|
+
Timestamp
|
|
14
|
+
} from 'bson';
|
|
15
|
+
|
|
16
|
+
export type TypeCastMap = {
|
|
17
|
+
Array: unknown[];
|
|
18
|
+
Binary: Binary;
|
|
19
|
+
Boolean: boolean;
|
|
20
|
+
Code: Code;
|
|
21
|
+
Date: Date;
|
|
22
|
+
Decimal128: Decimal128;
|
|
23
|
+
Double: Double;
|
|
24
|
+
Int32: Int32;
|
|
25
|
+
Int64: Long;
|
|
26
|
+
MaxKey: MaxKey;
|
|
27
|
+
MinKey: MinKey;
|
|
28
|
+
Null: null;
|
|
29
|
+
Object: Object;
|
|
30
|
+
ObjectId: ObjectId;
|
|
31
|
+
BSONRegExp: BSONRegExp;
|
|
32
|
+
String: string;
|
|
33
|
+
BSONSymbol: BSONSymbol;
|
|
34
|
+
Timestamp: Timestamp;
|
|
35
|
+
Undefined: undefined;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type TypeCastTypes = keyof TypeCastMap;
|
|
39
|
+
|
|
40
|
+
declare class TypeChecker {
|
|
41
|
+
cast<O = unknown, T extends string = string>(
|
|
42
|
+
object: O,
|
|
43
|
+
type: T
|
|
44
|
+
): T extends TypeCastTypes ? TypeCastMap[T] : O;
|
|
45
|
+
type(object: unknown): TypeCastTypes;
|
|
46
|
+
castableTypes(highPrecisionSupport?: boolean): TypeCastTypes[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare const typeCheckerInstance: TypeChecker;
|
|
50
|
+
|
|
51
|
+
export default typeCheckerInstance;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"email": "compass@mongodb.com"
|
|
8
8
|
},
|
|
9
9
|
"homepage": "https://github.com/mongodb-js/compass",
|
|
10
|
-
"version": "6.
|
|
10
|
+
"version": "6.8.0",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/mongodb-js/compass.git"
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"eslint-config-mongodb-js": "^5.0.3",
|
|
41
41
|
"mocha": "^8.0.1"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "a1283df32eb52881cc00eb73f8d435f772cdbfde"
|
|
44
44
|
}
|
package/src/type-checker.js
CHANGED
|
@@ -23,7 +23,7 @@ const {
|
|
|
23
23
|
Code,
|
|
24
24
|
BSONSymbol,
|
|
25
25
|
Timestamp,
|
|
26
|
-
|
|
26
|
+
Map
|
|
27
27
|
} = require('bson');
|
|
28
28
|
/**
|
|
29
29
|
* The object string.
|
|
@@ -57,6 +57,7 @@ const DECIMAL_128 = 'Decimal128';
|
|
|
57
57
|
const OBJECT_TYPE = '[object Object]';
|
|
58
58
|
const EMPTY = '';
|
|
59
59
|
const OBJECT_ID = 'ObjectID';
|
|
60
|
+
const SYMBOL = 'Symbol';
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* The bson type field.
|
|
@@ -227,10 +228,6 @@ const toTimestamp = (object) => {
|
|
|
227
228
|
return Timestamp.fromNumber(number);
|
|
228
229
|
};
|
|
229
230
|
|
|
230
|
-
const toMap = (object) => {
|
|
231
|
-
return new BSONMap(object);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
231
|
/**
|
|
235
232
|
* The functions to cast to a type.
|
|
236
233
|
*/
|
|
@@ -249,10 +246,9 @@ const CASTERS = {
|
|
|
249
246
|
Null: toNull,
|
|
250
247
|
Object: toObject,
|
|
251
248
|
ObjectId: toObjectID,
|
|
252
|
-
|
|
249
|
+
BSONRegExp: toRegex,
|
|
253
250
|
String: toString,
|
|
254
251
|
BSONSymbol: toSymbol,
|
|
255
|
-
BSONMap: toMap,
|
|
256
252
|
Timestamp: toTimestamp,
|
|
257
253
|
Undefined: toUndefined
|
|
258
254
|
};
|
|
@@ -343,6 +339,9 @@ class TypeChecker {
|
|
|
343
339
|
if (object._bsontype === OBJECT_ID) {
|
|
344
340
|
return 'ObjectId';
|
|
345
341
|
}
|
|
342
|
+
if (object._bsontype === SYMBOL) {
|
|
343
|
+
return 'BSONSymbol';
|
|
344
|
+
}
|
|
346
345
|
return object._bsontype;
|
|
347
346
|
}
|
|
348
347
|
if (isNumber(object)) {
|