@mongosh/shell-bson 1.1.0 → 3.0.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/AUTHORS +1 -0
- package/lib/bson-export.d.ts +5 -2
- package/lib/bson-export.js +7 -0
- package/lib/bson-export.js.map +1 -1
- package/lib/helpers.js +2 -1
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -1
- package/lib/printable-bson.d.ts +2 -3
- package/lib/printable-bson.js.map +1 -1
- package/package.json +6 -8
- package/src/bson-export.ts +7 -0
- package/src/helpers.ts +4 -1
- package/src/index.ts +1 -1
- package/src/printable-bson.ts +3 -6
- package/src/shell-bson.spec.ts +19 -19
- package/.depcheckrc +0 -16
package/AUTHORS
CHANGED
package/lib/bson-export.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, calculateObjectSize, Double, EJSON, UUID, BSONRegExp } from 'bson';
|
|
2
|
-
export type { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, Double, EJSON, UUID, BSONRegExp, calculateObjectSize, };
|
|
1
|
+
import type { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, calculateObjectSize, Double, EJSON, UUID, BSONRegExp, BSONTypeTag } from 'bson';
|
|
2
|
+
export type { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, Double, EJSON, UUID, BSONRegExp, calculateObjectSize, BSONTypeTag, };
|
|
3
|
+
import { bsonType } from 'bson';
|
|
4
|
+
export { bsonType };
|
|
5
|
+
export declare function getBsonType(value: any): BSONTypeTag | undefined;
|
|
3
6
|
export type BSON = {
|
|
4
7
|
ObjectId: typeof ObjectId;
|
|
5
8
|
DBRef: typeof DBRef;
|
package/lib/bson-export.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bsonType = void 0;
|
|
4
|
+
exports.getBsonType = getBsonType;
|
|
5
|
+
const bson_1 = require("bson");
|
|
6
|
+
Object.defineProperty(exports, "bsonType", { enumerable: true, get: function () { return bson_1.bsonType; } });
|
|
7
|
+
function getBsonType(value) {
|
|
8
|
+
return value?.[bson_1.bsonType];
|
|
9
|
+
}
|
|
3
10
|
//# sourceMappingURL=bson-export.js.map
|
package/lib/bson-export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bson-export.js","sourceRoot":"","sources":["../src/bson-export.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"bson-export.js","sourceRoot":"","sources":["../src/bson-export.ts"],"names":[],"mappings":";;;AAwCA,kCAEC;AAJD,+BAAgC;AACvB,yFADA,eAAQ,OACA;AACjB,SAAgB,WAAW,CAAC,KAAU;IACpC,OAAO,KAAK,EAAE,CAAC,eAAQ,CAAC,CAAC;AAC3B,CAAC"}
|
package/lib/helpers.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.assignAll = assignAll;
|
|
|
5
5
|
exports.pickWithExactKeyMatch = pickWithExactKeyMatch;
|
|
6
6
|
exports.assertArgsDefinedType = assertArgsDefinedType;
|
|
7
7
|
const errors_1 = require("@mongosh/errors");
|
|
8
|
+
const bson_export_1 = require("./bson-export");
|
|
8
9
|
function functionCtorWithoutProps(ClassCtor) {
|
|
9
10
|
function fnCtor(...args) {
|
|
10
11
|
if (new.target) {
|
|
@@ -56,7 +57,7 @@ function assertArgsDefinedType(args, expectedTypes, func) {
|
|
|
56
57
|
}
|
|
57
58
|
const expectedTypesList = typeof expected === 'string' ? [expected] : expected;
|
|
58
59
|
const isExpectedTypeof = expectedTypesList.includes(typeof arg);
|
|
59
|
-
const isExpectedBson = expectedTypesList.includes(`bson:${arg
|
|
60
|
+
const isExpectedBson = expectedTypesList.includes(`bson:${(0, bson_export_1.getBsonType)(arg)}`);
|
|
60
61
|
if (!isExpectedTypeof && !isExpectedBson) {
|
|
61
62
|
const expectedMsg = expectedTypesList
|
|
62
63
|
.filter((e) => e !== undefined)
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AAOA,4DAoBC;AAcD,8BAkBC;AAID,sDAYC;AAOD,sDA2CC;AA7HD,4CAAyE;AACzE,+CAA4C;AAM5C,SAAgB,wBAAwB,CAGtC,SAAY;IAKZ,SAAS,MAAM,CAAC,GAAG,IAAW;QAC5B,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACf,OAAO,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;IAChE,MAAM,cAAc,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1E,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,MAAa,CAAC;AACvB,CAAC;AAcD,SAAgB,SAAS,CAAC,MAAU,EAAE,GAAG,OAAa;IACpD,MAAM,iBAAiB,GAAG,EAAE,CAAC;IAC7B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC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,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.makeBsonStringifiers = exports.makePrintableBson = exports.constructShellBson = void 0;
|
|
18
|
+
__exportStar(require("./bson-export"), exports);
|
|
4
19
|
var shell_bson_1 = require("./shell-bson");
|
|
5
20
|
Object.defineProperty(exports, "constructShellBson", { enumerable: true, get: function () { return shell_bson_1.constructShellBson; } });
|
|
6
21
|
var printable_bson_1 = require("./printable-bson");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2CAAkE;AAAzD,gHAAA,kBAAkB,OAAA;AAC3B,mDAA2E;AAAlE,mHAAA,iBAAiB,OAAA;AAAE,sHAAA,oBAAoB,OAAA"}
|
package/lib/printable-bson.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { BSONTypeTag } from 'bson';
|
|
1
2
|
import type { BSON } from './';
|
|
2
3
|
import type { CustomInspectFunction } from 'util';
|
|
3
|
-
|
|
4
|
-
export declare const makeBsonStringifiers: (bsonLibrary: BSON) => Record<BSONClassKey | 'ObjectID', CustomInspectFunction>;
|
|
4
|
+
export declare const makeBsonStringifiers: (bsonLibrary: BSON) => Record<BSONTypeTag | 'ObjectID', CustomInspectFunction>;
|
|
5
5
|
export declare function makePrintableBson(bsonLibrary: BSON): void;
|
|
6
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printable-bson.js","sourceRoot":"","sources":["../src/printable-bson.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"printable-bson.js","sourceRoot":"","sources":["../src/printable-bson.ts"],"names":[],"mappings":";;;AAyJA,8CAYC;AA9JD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAE/D,IAAI,eAEH,CAAC;AACF,SAAS,iBAAiB,CACxB,GAAqB,EACrB,OAAuB;IAEvB,IAAI,CAAC;QACH,eAAe,KAAf,eAAe,GAAK,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,EAAC;QAC5C,OAAO,eAAe,CAAC,GAAG,EAAE;YAC1B,GAAG,OAAO;YAEV,cAAc,EAAE,eAAe,CAAC,cAAc,CAAC,cAAc;SAC9D,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACrB,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,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GAAG,IAAI,WAAW,CAAC,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,GAAiB,CAAC,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5C,GAAW,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/shell-bson",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "mongosh-style BSON handling",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh/tree/main/packages/shell-bson#readme",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"url": "git+https://github.com/mongodb-js/mongosh.git"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"check": "npm run lint
|
|
21
|
-
"depcheck": "depcheck",
|
|
20
|
+
"check": "npm run lint",
|
|
22
21
|
"compile": "tsc -p tsconfig.json",
|
|
23
22
|
"eslint": "eslint",
|
|
24
23
|
"lint": "npm run eslint . && npm run prettier -- --check .",
|
|
@@ -37,19 +36,18 @@
|
|
|
37
36
|
"unitTestsOnly": true
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@mongosh/errors": "^2.4.
|
|
39
|
+
"@mongosh/errors": "^2.4.6"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
|
-
"bson": "^
|
|
42
|
+
"bson": "^7.2.0"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
|
|
47
46
|
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
|
48
47
|
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
|
|
49
|
-
"bson": "^
|
|
50
|
-
"depcheck": "^1.4.7",
|
|
48
|
+
"bson": "^7.2.0",
|
|
51
49
|
"eslint": "^7.25.0",
|
|
52
50
|
"prettier": "^2.8.8"
|
|
53
51
|
},
|
|
54
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1ae76759bb28ace817059c00cfefa6055aec35c4"
|
|
55
53
|
}
|
package/src/bson-export.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
EJSON,
|
|
16
16
|
UUID,
|
|
17
17
|
BSONRegExp,
|
|
18
|
+
BSONTypeTag,
|
|
18
19
|
} from 'bson';
|
|
19
20
|
export type {
|
|
20
21
|
ObjectId,
|
|
@@ -33,7 +34,13 @@ export type {
|
|
|
33
34
|
UUID,
|
|
34
35
|
BSONRegExp,
|
|
35
36
|
calculateObjectSize,
|
|
37
|
+
BSONTypeTag,
|
|
36
38
|
};
|
|
39
|
+
import { bsonType } from 'bson';
|
|
40
|
+
export { bsonType };
|
|
41
|
+
export function getBsonType(value: any): BSONTypeTag | undefined {
|
|
42
|
+
return value?.[bsonType];
|
|
43
|
+
}
|
|
37
44
|
export type BSON = {
|
|
38
45
|
ObjectId: typeof ObjectId;
|
|
39
46
|
DBRef: typeof DBRef;
|
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MongoshInvalidInputError, CommonErrors } from '@mongosh/errors';
|
|
2
|
+
import { getBsonType } from './bson-export';
|
|
2
3
|
|
|
3
4
|
// Create a copy of a class so that it's constructible without `new`, i.e.
|
|
4
5
|
// class A {}; B = functionCtor(A);
|
|
@@ -105,7 +106,9 @@ export function assertArgsDefinedType(
|
|
|
105
106
|
const expectedTypesList: Array<string | undefined> =
|
|
106
107
|
typeof expected === 'string' ? [expected] : expected;
|
|
107
108
|
const isExpectedTypeof = expectedTypesList.includes(typeof arg);
|
|
108
|
-
const isExpectedBson = expectedTypesList.includes(
|
|
109
|
+
const isExpectedBson = expectedTypesList.includes(
|
|
110
|
+
`bson:${getBsonType(arg)}`
|
|
111
|
+
);
|
|
109
112
|
|
|
110
113
|
if (!isExpectedTypeof && !isExpectedBson) {
|
|
111
114
|
const expectedMsg = expectedTypesList
|
package/src/index.ts
CHANGED
package/src/printable-bson.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BSONTypeTag } from 'bson';
|
|
1
2
|
import type { BSON } from './';
|
|
2
3
|
import type {
|
|
3
4
|
InspectOptionsStylized,
|
|
@@ -5,10 +6,6 @@ import type {
|
|
|
5
6
|
InspectOptions,
|
|
6
7
|
} from 'util';
|
|
7
8
|
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
8
|
-
type BSONClassKey = BSON[Exclude<
|
|
9
|
-
keyof BSON,
|
|
10
|
-
'EJSON' | 'calculateObjectSize'
|
|
11
|
-
>]['prototype']['_bsontype'];
|
|
12
9
|
|
|
13
10
|
let coreUtilInspect: ((obj: any, options: InspectOptions) => string) & {
|
|
14
11
|
defaultOptions: InspectOptions;
|
|
@@ -49,7 +46,7 @@ function removeTypedArrayPrefixFromInspectResult(str: string): string {
|
|
|
49
46
|
// Create a Node.js-util-inspect() style custom inspect function that
|
|
50
47
|
// strips 'new ' from inspect results but otherwise uses the Node.js
|
|
51
48
|
// driver's bson library's inspect functions.
|
|
52
|
-
function makeClasslessInspect<K extends
|
|
49
|
+
function makeClasslessInspect<K extends BSONTypeTag>(
|
|
53
50
|
cls: BSON[K]
|
|
54
51
|
): CustomInspectFunction {
|
|
55
52
|
const originalInspect = cls.prototype.inspect;
|
|
@@ -100,7 +97,7 @@ const makeBinaryVectorInspect = (bsonLibrary: BSON): CustomInspectFunction => {
|
|
|
100
97
|
|
|
101
98
|
export const makeBsonStringifiers: (
|
|
102
99
|
bsonLibrary: BSON
|
|
103
|
-
) => Record<
|
|
100
|
+
) => Record<BSONTypeTag | 'ObjectID', CustomInspectFunction> = (
|
|
104
101
|
bsonLibrary
|
|
105
102
|
) => {
|
|
106
103
|
const binaryVectorInspect = makeBinaryVectorInspect(bsonLibrary);
|
package/src/shell-bson.spec.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { expect } from 'chai';
|
|
|
9
9
|
import sinonChai from 'sinon-chai';
|
|
10
10
|
import sinon from 'sinon';
|
|
11
11
|
import type { BSON, ShellBson } from './';
|
|
12
|
-
import { constructShellBson } from './';
|
|
12
|
+
import { constructShellBson, getBsonType } from './';
|
|
13
13
|
chai.use(sinonChai);
|
|
14
14
|
|
|
15
15
|
const hex_1234 = '31323334';
|
|
@@ -49,11 +49,11 @@ describe('Shell BSON', function () {
|
|
|
49
49
|
describe('DBRef', function () {
|
|
50
50
|
it('without new', function () {
|
|
51
51
|
const s = shellBson.DBRef('namespace', 'oid');
|
|
52
|
-
expect(s
|
|
52
|
+
expect(getBsonType(s)).to.equal('DBRef');
|
|
53
53
|
});
|
|
54
54
|
it('with new', function () {
|
|
55
55
|
const s = new (shellBson.DBRef as any)('namespace', 'oid');
|
|
56
|
-
expect(s
|
|
56
|
+
expect(getBsonType(s)).to.equal('DBRef');
|
|
57
57
|
});
|
|
58
58
|
it('has help and other metadata', function () {
|
|
59
59
|
const s = shellBson.DBRef('namespace', 'oid');
|
|
@@ -97,15 +97,15 @@ describe('Shell BSON', function () {
|
|
|
97
97
|
describe('MaxKey', function () {
|
|
98
98
|
it('without new', function () {
|
|
99
99
|
const s = shellBson.MaxKey();
|
|
100
|
-
expect(s
|
|
100
|
+
expect(getBsonType(s)).to.equal('MaxKey');
|
|
101
101
|
});
|
|
102
102
|
it('with new', function () {
|
|
103
103
|
const s = new (shellBson.MaxKey as any)();
|
|
104
|
-
expect(s
|
|
104
|
+
expect(getBsonType(s)).to.equal('MaxKey');
|
|
105
105
|
});
|
|
106
106
|
it('using toBSON', function () {
|
|
107
107
|
const s = (shellBson.MaxKey as any).toBSON();
|
|
108
|
-
expect(s
|
|
108
|
+
expect(getBsonType(s)).to.equal('MaxKey');
|
|
109
109
|
});
|
|
110
110
|
it('has help and other metadata', function () {
|
|
111
111
|
const s = shellBson.MaxKey();
|
|
@@ -117,15 +117,15 @@ describe('Shell BSON', function () {
|
|
|
117
117
|
describe('MinKey', function () {
|
|
118
118
|
it('without new', function () {
|
|
119
119
|
const s = shellBson.MinKey();
|
|
120
|
-
expect(s
|
|
120
|
+
expect(getBsonType(s)).to.equal('MinKey');
|
|
121
121
|
});
|
|
122
122
|
it('with new', function () {
|
|
123
123
|
const s = new (shellBson.MinKey as any)();
|
|
124
|
-
expect(s
|
|
124
|
+
expect(getBsonType(s)).to.equal('MinKey');
|
|
125
125
|
});
|
|
126
126
|
it('using toBSON', function () {
|
|
127
127
|
const s = (shellBson.MinKey as any).toBSON();
|
|
128
|
-
expect(s
|
|
128
|
+
expect(getBsonType(s)).to.equal('MinKey');
|
|
129
129
|
});
|
|
130
130
|
it('has help and other metadata', function () {
|
|
131
131
|
const s = shellBson.MinKey();
|
|
@@ -155,29 +155,29 @@ describe('Shell BSON', function () {
|
|
|
155
155
|
describe('ObjectId', function () {
|
|
156
156
|
it('without new', function () {
|
|
157
157
|
const s = shellBson.ObjectId('5ebbe8e2905bb493d6981b6b');
|
|
158
|
-
expect(s
|
|
158
|
+
expect(getBsonType(s)).to.equal('ObjectId');
|
|
159
159
|
expect(s.toHexString()).to.equal('5ebbe8e2905bb493d6981b6b');
|
|
160
160
|
});
|
|
161
161
|
it('with new', function () {
|
|
162
162
|
const s = new (shellBson.ObjectId as any)('5ebbe8e2905bb493d6981b6b');
|
|
163
|
-
expect(s
|
|
163
|
+
expect(getBsonType(s)).to.equal('ObjectId');
|
|
164
164
|
expect(s.toHexString()).to.equal('5ebbe8e2905bb493d6981b6b');
|
|
165
165
|
});
|
|
166
166
|
it('works with an integer argument', function () {
|
|
167
167
|
const s = new (shellBson.ObjectId as any)(0x12345678);
|
|
168
|
-
expect(s
|
|
168
|
+
expect(getBsonType(s)).to.equal('ObjectId');
|
|
169
169
|
expect(s.toHexString().slice(0, 8)).to.equal('12345678');
|
|
170
170
|
});
|
|
171
171
|
it('can be created through createFromTime', function () {
|
|
172
172
|
const s = (shellBson.ObjectId as any).createFromTime(0x12345678);
|
|
173
|
-
expect(s
|
|
173
|
+
expect(getBsonType(s)).to.equal('ObjectId');
|
|
174
174
|
expect(s.toHexString().slice(0, 8)).to.equal('12345678');
|
|
175
175
|
});
|
|
176
176
|
it('can be created using createFromHexString', function () {
|
|
177
177
|
const s = shellBson.ObjectId.createFromHexString(
|
|
178
178
|
'64c122afaf44ca299136bbc3'
|
|
179
179
|
);
|
|
180
|
-
expect(s
|
|
180
|
+
expect(getBsonType(s)).to.equal('ObjectId');
|
|
181
181
|
expect(s.toHexString()).to.equal('64c122afaf44ca299136bbc3');
|
|
182
182
|
});
|
|
183
183
|
it('has help and other metadata', function () {
|
|
@@ -198,12 +198,12 @@ describe('Shell BSON', function () {
|
|
|
198
198
|
describe('BSONSymbol', function () {
|
|
199
199
|
it('without new', function () {
|
|
200
200
|
const s = (shellBson.BSONSymbol as any)('5ebbe8e2905bb493d6981b6b');
|
|
201
|
-
expect(s
|
|
201
|
+
expect(getBsonType(s)).to.equal('BSONSymbol');
|
|
202
202
|
expect(s.toString()).to.equal('5ebbe8e2905bb493d6981b6b');
|
|
203
203
|
});
|
|
204
204
|
it('with new', function () {
|
|
205
205
|
const s = new (shellBson.BSONSymbol as any)('5ebbe8e2905bb493d6981b6b');
|
|
206
|
-
expect(s
|
|
206
|
+
expect(getBsonType(s)).to.equal('BSONSymbol');
|
|
207
207
|
expect(s.toString()).to.equal('5ebbe8e2905bb493d6981b6b');
|
|
208
208
|
});
|
|
209
209
|
it('has help and other metadata', function () {
|
|
@@ -215,15 +215,15 @@ describe('Shell BSON', function () {
|
|
|
215
215
|
describe('Timestamp', function () {
|
|
216
216
|
it('without new', function () {
|
|
217
217
|
const s = shellBson.Timestamp(0, 100);
|
|
218
|
-
expect(s
|
|
218
|
+
expect(getBsonType(s)).to.equal('Timestamp');
|
|
219
219
|
});
|
|
220
220
|
it('with new', function () {
|
|
221
221
|
const s = new (shellBson.Timestamp as any)(0, 100);
|
|
222
|
-
expect(s
|
|
222
|
+
expect(getBsonType(s)).to.equal('Timestamp');
|
|
223
223
|
});
|
|
224
224
|
it('with a long argument', function () {
|
|
225
225
|
const s = shellBson.Timestamp((shellBson.Long as any)(1, 2));
|
|
226
|
-
expect(s
|
|
226
|
+
expect(getBsonType(s)).to.equal('Timestamp');
|
|
227
227
|
expect((s as any).toExtendedJSON()).to.deep.equal({
|
|
228
228
|
$timestamp: { t: 2, i: 1 },
|
|
229
229
|
});
|
package/.depcheckrc
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
ignores:
|
|
2
|
-
- '@mongodb-js/eslint-config-mongosh'
|
|
3
|
-
- '@mongodb-js/tsconfig-mongosh'
|
|
4
|
-
- '@mongodb-js/prettier-config-devtools'
|
|
5
|
-
- '@typescript-eslint/parser'
|
|
6
|
-
- '@typescript-eslint/eslint-plugin'
|
|
7
|
-
- chai
|
|
8
|
-
- sinon
|
|
9
|
-
- sinon-chai
|
|
10
|
-
- ts-sinon
|
|
11
|
-
- eslint-plugin-mocha
|
|
12
|
-
- eslint-config-mongodb-js
|
|
13
|
-
# needed as a peer dependency of @mongodb-js/devtools-connect
|
|
14
|
-
- mongodb
|
|
15
|
-
ignore-patterns:
|
|
16
|
-
- .eslintrc.js
|