hadron-type-checker 6.6.0 → 6.9.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 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: Record<string, unknown>;
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.6.0",
10
+ "version": "6.9.0",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "https://github.com/mongodb-js/compass.git"
@@ -17,10 +17,7 @@
17
17
  "mongodb-js"
18
18
  ],
19
19
  "main": "index.js",
20
- "exports": {
21
- "webpack": "./index.js",
22
- "require": "./index.js"
23
- },
20
+ "compass:main": "index.js",
24
21
  "scripts": {
25
22
  "test-check-ci": "npm test",
26
23
  "test": "mocha",
@@ -40,5 +37,5 @@
40
37
  "eslint-config-mongodb-js": "^5.0.3",
41
38
  "mocha": "^8.0.1"
42
39
  },
43
- "gitHead": "77166e3754e36e95c7ff7efb5a0ce5e0990b0ff7"
40
+ "gitHead": "2c4149184e87b8340851590663287b914d7ee63e"
44
41
  }
@@ -23,7 +23,7 @@ const {
23
23
  Code,
24
24
  BSONSymbol,
25
25
  Timestamp,
26
- BSONMap
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
- BSONRegexp: toRegex,
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)) {