@qp-mongosh/shell-api 0.0.0-dev.0 → 0.0.0-dev.3
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/.eslintignore +2 -2
- package/.eslintrc.js +1 -1
- package/AUTHORS +15 -15
- package/LICENSE +200 -200
- package/bin/report-missing-help.ts +24 -24
- package/bin/report-supported-api.ts +14 -14
- package/lib/abstract-cursor.d.ts +33 -33
- package/lib/abstract-cursor.js +191 -191
- package/lib/aggregation-cursor.d.ts +6 -6
- package/lib/aggregation-cursor.js +19 -19
- package/lib/bulk.d.ts +43 -43
- package/lib/bulk.js +223 -223
- package/lib/change-stream-cursor.d.ts +28 -28
- package/lib/change-stream-cursor.js +111 -111
- package/lib/collection.d.ts +95 -95
- package/lib/collection.js +964 -964
- package/lib/cursor.d.ts +32 -32
- package/lib/cursor.js +215 -215
- package/lib/database.d.ts +116 -116
- package/lib/database.js +1223 -1223
- package/lib/dbquery.d.ts +8 -8
- package/lib/dbquery.js +28 -28
- package/lib/decorators.d.ts +73 -73
- package/lib/decorators.js +395 -395
- package/lib/enums.d.ts +28 -28
- package/lib/enums.js +33 -33
- package/lib/error-codes.d.ts +12 -12
- package/lib/error-codes.js +19 -19
- package/lib/explainable-cursor.d.ts +11 -11
- package/lib/explainable-cursor.js +31 -31
- package/lib/explainable.d.ts +32 -32
- package/lib/explainable.js +166 -166
- package/lib/field-level-encryption.d.ts +50 -50
- package/lib/field-level-encryption.js +176 -176
- package/lib/help.d.ts +22 -22
- package/lib/help.js +26 -26
- package/lib/helpers.d.ts +71 -71
- package/lib/helpers.js +588 -588
- package/lib/index.d.ts +16 -16
- package/lib/index.js +45 -45
- package/lib/interruptor.d.ts +19 -19
- package/lib/interruptor.js +62 -62
- package/lib/mongo-errors.d.ts +5 -5
- package/lib/mongo-errors.js +37 -37
- package/lib/mongo.d.ts +75 -75
- package/lib/mongo.js +476 -476
- package/lib/no-db.d.ts +5 -5
- package/lib/no-db.js +28 -28
- package/lib/plan-cache.d.ts +16 -16
- package/lib/plan-cache.js +70 -70
- package/lib/replica-set.d.ts +45 -45
- package/lib/replica-set.js +314 -314
- package/lib/result.d.ts +61 -61
- package/lib/result.js +104 -104
- package/lib/session.d.ts +25 -25
- package/lib/session.js +88 -88
- package/lib/shard.d.ts +42 -42
- package/lib/shard.js +414 -414
- package/lib/shell-api.d.ts +52 -52
- package/lib/shell-api.js +298 -298
- package/lib/shell-bson.d.ts +40 -40
- package/lib/shell-bson.js +159 -159
- package/lib/shell-instance-state.d.ts +77 -77
- package/lib/shell-instance-state.js +392 -392
- package/package.json +47 -47
- package/tsconfig.lint.json +8 -8
package/lib/shell-bson.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import Help from './help';
|
|
3
|
-
import { BinaryType, Document, bson as BSON } from '@qp-mongosh/service-provider-core';
|
|
4
|
-
interface ShellBsonBase {
|
|
5
|
-
DBRef: (namespace: string, oid: any, db?: string, fields?: Document) => typeof BSON.DBRef.prototype;
|
|
6
|
-
Map: typeof BSON.Map;
|
|
7
|
-
bsonsize: (object: any) => number;
|
|
8
|
-
MaxKey: () => typeof BSON.MaxKey.prototype;
|
|
9
|
-
MinKey: () => typeof BSON.MinKey.prototype;
|
|
10
|
-
ObjectId: (id?: string | number | typeof BSON.ObjectId.prototype | Buffer) => typeof BSON.ObjectId.prototype;
|
|
11
|
-
Timestamp: (t?: number | typeof BSON.Long.prototype | {
|
|
12
|
-
t: number;
|
|
13
|
-
i: number;
|
|
14
|
-
}, i?: number) => typeof BSON.Timestamp.prototype;
|
|
15
|
-
Code: (c?: string | Function, s?: any) => typeof BSON.Code.prototype;
|
|
16
|
-
NumberDecimal: (s?: string) => typeof BSON.Decimal128.prototype;
|
|
17
|
-
NumberInt: (v?: string) => typeof BSON.Int32.prototype;
|
|
18
|
-
NumberLong: (s?: string | number) => typeof BSON.Long.prototype;
|
|
19
|
-
ISODate: (input?: string) => Date;
|
|
20
|
-
BinData: (subtype: number, b64string: string) => BinaryType;
|
|
21
|
-
HexData: (subtype: number, hexstr: string) => BinaryType;
|
|
22
|
-
UUID: (hexstr?: string) => BinaryType;
|
|
23
|
-
MD5: (hexstr: string) => BinaryType;
|
|
24
|
-
Decimal128: typeof BSON.Decimal128;
|
|
25
|
-
BSONSymbol: typeof BSON.BSONSymbol;
|
|
26
|
-
Int32: typeof BSON.Int32;
|
|
27
|
-
Long: typeof BSON.Long;
|
|
28
|
-
Binary: typeof BSON.Binary;
|
|
29
|
-
Double: typeof BSON.Double;
|
|
30
|
-
EJSON: typeof BSON.EJSON;
|
|
31
|
-
BSONRegExp: typeof BSON.BSONRegExp;
|
|
32
|
-
}
|
|
33
|
-
declare type WithHelp<T> = {
|
|
34
|
-
[prop in keyof T]: T[prop] & {
|
|
35
|
-
help?: () => Help;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
export declare type ShellBson = WithHelp<ShellBsonBase>;
|
|
39
|
-
export default function constructShellBson(bson: typeof BSON, printWarning: (msg: string) => void): ShellBson;
|
|
40
|
-
export {};
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Help from './help';
|
|
3
|
+
import { BinaryType, Document, bson as BSON } from '@qp-mongosh/service-provider-core';
|
|
4
|
+
interface ShellBsonBase {
|
|
5
|
+
DBRef: (namespace: string, oid: any, db?: string, fields?: Document) => typeof BSON.DBRef.prototype;
|
|
6
|
+
Map: typeof BSON.Map;
|
|
7
|
+
bsonsize: (object: any) => number;
|
|
8
|
+
MaxKey: () => typeof BSON.MaxKey.prototype;
|
|
9
|
+
MinKey: () => typeof BSON.MinKey.prototype;
|
|
10
|
+
ObjectId: (id?: string | number | typeof BSON.ObjectId.prototype | Buffer) => typeof BSON.ObjectId.prototype;
|
|
11
|
+
Timestamp: (t?: number | typeof BSON.Long.prototype | {
|
|
12
|
+
t: number;
|
|
13
|
+
i: number;
|
|
14
|
+
}, i?: number) => typeof BSON.Timestamp.prototype;
|
|
15
|
+
Code: (c?: string | Function, s?: any) => typeof BSON.Code.prototype;
|
|
16
|
+
NumberDecimal: (s?: string) => typeof BSON.Decimal128.prototype;
|
|
17
|
+
NumberInt: (v?: string) => typeof BSON.Int32.prototype;
|
|
18
|
+
NumberLong: (s?: string | number) => typeof BSON.Long.prototype;
|
|
19
|
+
ISODate: (input?: string) => Date;
|
|
20
|
+
BinData: (subtype: number, b64string: string) => BinaryType;
|
|
21
|
+
HexData: (subtype: number, hexstr: string) => BinaryType;
|
|
22
|
+
UUID: (hexstr?: string) => BinaryType;
|
|
23
|
+
MD5: (hexstr: string) => BinaryType;
|
|
24
|
+
Decimal128: typeof BSON.Decimal128;
|
|
25
|
+
BSONSymbol: typeof BSON.BSONSymbol;
|
|
26
|
+
Int32: typeof BSON.Int32;
|
|
27
|
+
Long: typeof BSON.Long;
|
|
28
|
+
Binary: typeof BSON.Binary;
|
|
29
|
+
Double: typeof BSON.Double;
|
|
30
|
+
EJSON: typeof BSON.EJSON;
|
|
31
|
+
BSONRegExp: typeof BSON.BSONRegExp;
|
|
32
|
+
}
|
|
33
|
+
declare type WithHelp<T> = {
|
|
34
|
+
[prop in keyof T]: T[prop] & {
|
|
35
|
+
help?: () => Help;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare type ShellBson = WithHelp<ShellBsonBase>;
|
|
39
|
+
export default function constructShellBson(bson: typeof BSON, printWarning: (msg: string) => void): ShellBson;
|
|
40
|
+
export {};
|
package/lib/shell-bson.js
CHANGED
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const enums_1 = require("./enums");
|
|
7
|
-
const help_1 = __importDefault(require("./help"));
|
|
8
|
-
const service_provider_core_1 = require("@qp-mongosh/service-provider-core");
|
|
9
|
-
const errors_1 = require("@qp-mongosh/errors");
|
|
10
|
-
const helpers_1 = require("./helpers");
|
|
11
|
-
const crypto_1 = require("crypto");
|
|
12
|
-
function constructHelp(className) {
|
|
13
|
-
const classHelpKeyPrefix = `shell-api.classes.${className}.help`;
|
|
14
|
-
const classHelp = {
|
|
15
|
-
help: `${classHelpKeyPrefix}.description`,
|
|
16
|
-
example: `${classHelpKeyPrefix}.example`,
|
|
17
|
-
docs: `${classHelpKeyPrefix}.link`,
|
|
18
|
-
attr: []
|
|
19
|
-
};
|
|
20
|
-
return new help_1.default(classHelp);
|
|
21
|
-
}
|
|
22
|
-
function constructShellBson(bson, printWarning) {
|
|
23
|
-
const bsonNames = [
|
|
24
|
-
'Binary', 'Code', 'DBRef', 'Decimal128', 'Double', 'Int32', 'Long',
|
|
25
|
-
'MaxKey', 'MinKey', 'ObjectId', 'Timestamp', 'Map', 'BSONSymbol',
|
|
26
|
-
'BSONRegExp'
|
|
27
|
-
];
|
|
28
|
-
if (bson === undefined) {
|
|
29
|
-
bson = service_provider_core_1.bson;
|
|
30
|
-
}
|
|
31
|
-
const helps = {};
|
|
32
|
-
bsonNames.forEach((className) => {
|
|
33
|
-
if (!(className in bson)) {
|
|
34
|
-
throw new errors_1.MongoshInternalError(`${className} does not exist in provided BSON package.`);
|
|
35
|
-
}
|
|
36
|
-
const proto = bson[className].prototype;
|
|
37
|
-
proto.serverVersions = enums_1.ALL_SERVER_VERSIONS;
|
|
38
|
-
proto.platforms = enums_1.ALL_PLATFORMS;
|
|
39
|
-
proto.topologies = enums_1.ALL_TOPOLOGIES;
|
|
40
|
-
const help = constructHelp(className);
|
|
41
|
-
helps[className] = help;
|
|
42
|
-
proto.help = () => (help);
|
|
43
|
-
Object.setPrototypeOf(proto.help, help);
|
|
44
|
-
});
|
|
45
|
-
bson.BSONSymbol.prototype.serverVersions = [enums_1.ServerVersions.earliest, '1.6.0'];
|
|
46
|
-
bson.BSONSymbol.prototype.deprecated = true;
|
|
47
|
-
const bsonPkg = {
|
|
48
|
-
DBRef: Object.assign(function DBRef(namespace, oid, db, fields) {
|
|
49
|
-
(0, helpers_1.assertArgsDefinedType)([namespace, oid, db], ['string', true, [undefined, 'string'], [undefined, 'object']], 'DBRef');
|
|
50
|
-
return new bson.DBRef(namespace, oid, db, fields);
|
|
51
|
-
}, { ...bson.DBRef, prototype: bson.DBRef.prototype }),
|
|
52
|
-
Map: bson.Map,
|
|
53
|
-
bsonsize: function bsonsize(object) {
|
|
54
|
-
(0, helpers_1.assertArgsDefinedType)([object], ['object'], 'bsonsize');
|
|
55
|
-
return bson.calculateObjectSize(object);
|
|
56
|
-
},
|
|
57
|
-
MaxKey: Object.assign(function MaxKey() {
|
|
58
|
-
return new bson.MaxKey();
|
|
59
|
-
}, { ...bson.MaxKey, toBSON: () => new bson.MaxKey(), prototype: bson.MaxKey.prototype }),
|
|
60
|
-
MinKey: Object.assign(function MinKey() {
|
|
61
|
-
return new bson.MinKey();
|
|
62
|
-
}, { ...bson.MinKey, toBSON: () => new bson.MinKey(), prototype: bson.MinKey.prototype }),
|
|
63
|
-
ObjectId: Object.assign(function ObjectId(id) {
|
|
64
|
-
(0, helpers_1.assertArgsDefinedType)([id], [[undefined, 'string', 'number', 'object']], 'ObjectId');
|
|
65
|
-
return new bson.ObjectId(id);
|
|
66
|
-
}, { ...bson.ObjectId, prototype: bson.ObjectId.prototype }),
|
|
67
|
-
Timestamp: Object.assign(function Timestamp(t, i) {
|
|
68
|
-
(0, helpers_1.assertArgsDefinedType)([t, i], [['number', 'object', undefined], [undefined, 'number']], 'Timestamp');
|
|
69
|
-
if (typeof t === 'object' && t !== null && 't' in t && 'i' in t) {
|
|
70
|
-
return new bson.Timestamp(new bson.Long(t.i, t.t));
|
|
71
|
-
}
|
|
72
|
-
else if (i !== undefined || typeof t === 'number') {
|
|
73
|
-
return new bson.Timestamp(new bson.Long((i !== null && i !== void 0 ? i : 0), t));
|
|
74
|
-
}
|
|
75
|
-
return new bson.Timestamp(t);
|
|
76
|
-
}, { ...bson.Timestamp, prototype: bson.Timestamp.prototype }),
|
|
77
|
-
Code: Object.assign(function Code(c = '', s) {
|
|
78
|
-
(0, helpers_1.assertArgsDefinedType)([c, s], [[undefined, 'string', 'function'], [undefined, 'object']], 'Code');
|
|
79
|
-
return new bson.Code(c, s);
|
|
80
|
-
}, { ...bson.Code, prototype: bson.Code.prototype }),
|
|
81
|
-
NumberDecimal: Object.assign(function NumberDecimal(s = '0') {
|
|
82
|
-
(0, helpers_1.assertArgsDefinedType)([s], [['string', 'number', 'bson:Long', 'bson:Int32', 'bson:Decimal128']], 'NumberDecimal');
|
|
83
|
-
if (typeof s === 'number') {
|
|
84
|
-
printWarning('NumberDecimal: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead');
|
|
85
|
-
}
|
|
86
|
-
return bson.Decimal128.fromString(`${s}`);
|
|
87
|
-
}, { prototype: bson.Decimal128.prototype }),
|
|
88
|
-
NumberInt: Object.assign(function NumberInt(v = '0') {
|
|
89
|
-
v !== null && v !== void 0 ? v : (v = '0');
|
|
90
|
-
(0, helpers_1.assertArgsDefinedType)([v], [['string', 'number', 'bson:Long', 'bson:Int32']], 'NumberInt');
|
|
91
|
-
return new bson.Int32(parseInt(`${v}`, 10));
|
|
92
|
-
}, { prototype: bson.Int32.prototype }),
|
|
93
|
-
NumberLong: Object.assign(function NumberLong(s = '0') {
|
|
94
|
-
s !== null && s !== void 0 ? s : (s = '0');
|
|
95
|
-
(0, helpers_1.assertArgsDefinedType)([s], [['string', 'number', 'bson:Long', 'bson:Int32']], 'NumberLong');
|
|
96
|
-
if (typeof s === 'number') {
|
|
97
|
-
printWarning('NumberLong: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead');
|
|
98
|
-
return bson.Long.fromNumber(s);
|
|
99
|
-
}
|
|
100
|
-
return bson.Long.fromString(`${s}`);
|
|
101
|
-
}, { prototype: bson.Long.prototype }),
|
|
102
|
-
ISODate: function ISODate(input) {
|
|
103
|
-
if (!input)
|
|
104
|
-
input = new Date().toISOString();
|
|
105
|
-
const isoDateRegex = /^(?<Y>\d{4})-?(?<M>\d{2})-?(?<D>\d{2})([T ](?<h>\d{2})(:?(?<m>\d{2})(:?((?<s>\d{2})(\.(?<ms>\d+))?))?)?(?<tz>Z|([+-])(\d{2}):?(\d{2})?)?)?$/;
|
|
106
|
-
const match = input.match(isoDateRegex);
|
|
107
|
-
if (match !== null && match.groups !== undefined) {
|
|
108
|
-
const { Y, M, D, h, m, s, ms, tz } = match.groups;
|
|
109
|
-
const normalized = `${Y}-${M}-${D}T${h || '00'}:${m || '00'}:${s || '00'}.${ms || '000'}${tz || 'Z'}`;
|
|
110
|
-
const date = new Date(normalized);
|
|
111
|
-
if (date.getTime() >= -62167219200000 && date.getTime() <= 253402300799999) {
|
|
112
|
-
return date;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
throw new errors_1.MongoshInvalidInputError(`${JSON.stringify(input)} is not a valid ISODate`, errors_1.CommonErrors.InvalidArgument);
|
|
116
|
-
},
|
|
117
|
-
BinData: Object.assign(function BinData(subtype, b64string) {
|
|
118
|
-
(0, helpers_1.assertArgsDefinedType)([subtype, b64string], ['number', 'string'], 'BinData');
|
|
119
|
-
const buffer = Buffer.from(b64string, 'base64');
|
|
120
|
-
return new bson.Binary(buffer, subtype);
|
|
121
|
-
}, { prototype: bson.Binary.prototype }),
|
|
122
|
-
HexData: Object.assign(function HexData(subtype, hexstr) {
|
|
123
|
-
(0, helpers_1.assertArgsDefinedType)([subtype, hexstr], ['number', 'string'], 'HexData');
|
|
124
|
-
const buffer = Buffer.from(hexstr, 'hex');
|
|
125
|
-
return new bson.Binary(buffer, subtype);
|
|
126
|
-
}, { prototype: bson.Binary.prototype }),
|
|
127
|
-
UUID: Object.assign(function UUID(hexstr) {
|
|
128
|
-
if (hexstr === undefined) {
|
|
129
|
-
const uuid = (0, crypto_1.randomBytes)(16);
|
|
130
|
-
uuid[6] = (uuid[6] & 0x0f) | 0x40;
|
|
131
|
-
uuid[8] = (uuid[8] & 0x3f) | 0x80;
|
|
132
|
-
hexstr = uuid.toString('hex');
|
|
133
|
-
}
|
|
134
|
-
(0, helpers_1.assertArgsDefinedType)([hexstr], ['string'], 'UUID');
|
|
135
|
-
const buffer = Buffer.from(hexstr.replace(/-/g, ''), 'hex');
|
|
136
|
-
return new bson.Binary(buffer, bson.Binary.SUBTYPE_UUID);
|
|
137
|
-
}, { prototype: bson.Binary.prototype }),
|
|
138
|
-
MD5: Object.assign(function MD5(hexstr) {
|
|
139
|
-
(0, helpers_1.assertArgsDefinedType)([hexstr], ['string'], 'MD5');
|
|
140
|
-
const buffer = Buffer.from(hexstr, 'hex');
|
|
141
|
-
return new bson.Binary(buffer, bson.Binary.SUBTYPE_MD5);
|
|
142
|
-
}, { prototype: bson.Binary.prototype }),
|
|
143
|
-
Decimal128: bson.Decimal128,
|
|
144
|
-
BSONSymbol: bson.BSONSymbol,
|
|
145
|
-
Int32: bson.Int32,
|
|
146
|
-
Long: bson.Long,
|
|
147
|
-
Binary: bson.Binary,
|
|
148
|
-
Double: bson.Double,
|
|
149
|
-
EJSON: bson.EJSON,
|
|
150
|
-
BSONRegExp: bson.BSONRegExp
|
|
151
|
-
};
|
|
152
|
-
for (const className of Object.keys(bsonPkg)) {
|
|
153
|
-
const help = helps[className] || constructHelp(className);
|
|
154
|
-
bsonPkg[className].help = () => (help);
|
|
155
|
-
Object.setPrototypeOf(bsonPkg[className].help, help);
|
|
156
|
-
}
|
|
157
|
-
return bsonPkg;
|
|
158
|
-
}
|
|
159
|
-
exports.default = constructShellBson;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const enums_1 = require("./enums");
|
|
7
|
+
const help_1 = __importDefault(require("./help"));
|
|
8
|
+
const service_provider_core_1 = require("@qp-mongosh/service-provider-core");
|
|
9
|
+
const errors_1 = require("@qp-mongosh/errors");
|
|
10
|
+
const helpers_1 = require("./helpers");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
function constructHelp(className) {
|
|
13
|
+
const classHelpKeyPrefix = `shell-api.classes.${className}.help`;
|
|
14
|
+
const classHelp = {
|
|
15
|
+
help: `${classHelpKeyPrefix}.description`,
|
|
16
|
+
example: `${classHelpKeyPrefix}.example`,
|
|
17
|
+
docs: `${classHelpKeyPrefix}.link`,
|
|
18
|
+
attr: []
|
|
19
|
+
};
|
|
20
|
+
return new help_1.default(classHelp);
|
|
21
|
+
}
|
|
22
|
+
function constructShellBson(bson, printWarning) {
|
|
23
|
+
const bsonNames = [
|
|
24
|
+
'Binary', 'Code', 'DBRef', 'Decimal128', 'Double', 'Int32', 'Long',
|
|
25
|
+
'MaxKey', 'MinKey', 'ObjectId', 'Timestamp', 'Map', 'BSONSymbol',
|
|
26
|
+
'BSONRegExp'
|
|
27
|
+
];
|
|
28
|
+
if (bson === undefined) {
|
|
29
|
+
bson = service_provider_core_1.bson;
|
|
30
|
+
}
|
|
31
|
+
const helps = {};
|
|
32
|
+
bsonNames.forEach((className) => {
|
|
33
|
+
if (!(className in bson)) {
|
|
34
|
+
throw new errors_1.MongoshInternalError(`${className} does not exist in provided BSON package.`);
|
|
35
|
+
}
|
|
36
|
+
const proto = bson[className].prototype;
|
|
37
|
+
proto.serverVersions = enums_1.ALL_SERVER_VERSIONS;
|
|
38
|
+
proto.platforms = enums_1.ALL_PLATFORMS;
|
|
39
|
+
proto.topologies = enums_1.ALL_TOPOLOGIES;
|
|
40
|
+
const help = constructHelp(className);
|
|
41
|
+
helps[className] = help;
|
|
42
|
+
proto.help = () => (help);
|
|
43
|
+
Object.setPrototypeOf(proto.help, help);
|
|
44
|
+
});
|
|
45
|
+
bson.BSONSymbol.prototype.serverVersions = [enums_1.ServerVersions.earliest, '1.6.0'];
|
|
46
|
+
bson.BSONSymbol.prototype.deprecated = true;
|
|
47
|
+
const bsonPkg = {
|
|
48
|
+
DBRef: Object.assign(function DBRef(namespace, oid, db, fields) {
|
|
49
|
+
(0, helpers_1.assertArgsDefinedType)([namespace, oid, db], ['string', true, [undefined, 'string'], [undefined, 'object']], 'DBRef');
|
|
50
|
+
return new bson.DBRef(namespace, oid, db, fields);
|
|
51
|
+
}, { ...bson.DBRef, prototype: bson.DBRef.prototype }),
|
|
52
|
+
Map: bson.Map,
|
|
53
|
+
bsonsize: function bsonsize(object) {
|
|
54
|
+
(0, helpers_1.assertArgsDefinedType)([object], ['object'], 'bsonsize');
|
|
55
|
+
return bson.calculateObjectSize(object);
|
|
56
|
+
},
|
|
57
|
+
MaxKey: Object.assign(function MaxKey() {
|
|
58
|
+
return new bson.MaxKey();
|
|
59
|
+
}, { ...bson.MaxKey, toBSON: () => new bson.MaxKey(), prototype: bson.MaxKey.prototype }),
|
|
60
|
+
MinKey: Object.assign(function MinKey() {
|
|
61
|
+
return new bson.MinKey();
|
|
62
|
+
}, { ...bson.MinKey, toBSON: () => new bson.MinKey(), prototype: bson.MinKey.prototype }),
|
|
63
|
+
ObjectId: Object.assign(function ObjectId(id) {
|
|
64
|
+
(0, helpers_1.assertArgsDefinedType)([id], [[undefined, 'string', 'number', 'object']], 'ObjectId');
|
|
65
|
+
return new bson.ObjectId(id);
|
|
66
|
+
}, { ...bson.ObjectId, prototype: bson.ObjectId.prototype }),
|
|
67
|
+
Timestamp: Object.assign(function Timestamp(t, i) {
|
|
68
|
+
(0, helpers_1.assertArgsDefinedType)([t, i], [['number', 'object', undefined], [undefined, 'number']], 'Timestamp');
|
|
69
|
+
if (typeof t === 'object' && t !== null && 't' in t && 'i' in t) {
|
|
70
|
+
return new bson.Timestamp(new bson.Long(t.i, t.t));
|
|
71
|
+
}
|
|
72
|
+
else if (i !== undefined || typeof t === 'number') {
|
|
73
|
+
return new bson.Timestamp(new bson.Long((i !== null && i !== void 0 ? i : 0), t));
|
|
74
|
+
}
|
|
75
|
+
return new bson.Timestamp(t);
|
|
76
|
+
}, { ...bson.Timestamp, prototype: bson.Timestamp.prototype }),
|
|
77
|
+
Code: Object.assign(function Code(c = '', s) {
|
|
78
|
+
(0, helpers_1.assertArgsDefinedType)([c, s], [[undefined, 'string', 'function'], [undefined, 'object']], 'Code');
|
|
79
|
+
return new bson.Code(c, s);
|
|
80
|
+
}, { ...bson.Code, prototype: bson.Code.prototype }),
|
|
81
|
+
NumberDecimal: Object.assign(function NumberDecimal(s = '0') {
|
|
82
|
+
(0, helpers_1.assertArgsDefinedType)([s], [['string', 'number', 'bson:Long', 'bson:Int32', 'bson:Decimal128']], 'NumberDecimal');
|
|
83
|
+
if (typeof s === 'number') {
|
|
84
|
+
printWarning('NumberDecimal: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead');
|
|
85
|
+
}
|
|
86
|
+
return bson.Decimal128.fromString(`${s}`);
|
|
87
|
+
}, { prototype: bson.Decimal128.prototype }),
|
|
88
|
+
NumberInt: Object.assign(function NumberInt(v = '0') {
|
|
89
|
+
v !== null && v !== void 0 ? v : (v = '0');
|
|
90
|
+
(0, helpers_1.assertArgsDefinedType)([v], [['string', 'number', 'bson:Long', 'bson:Int32']], 'NumberInt');
|
|
91
|
+
return new bson.Int32(parseInt(`${v}`, 10));
|
|
92
|
+
}, { prototype: bson.Int32.prototype }),
|
|
93
|
+
NumberLong: Object.assign(function NumberLong(s = '0') {
|
|
94
|
+
s !== null && s !== void 0 ? s : (s = '0');
|
|
95
|
+
(0, helpers_1.assertArgsDefinedType)([s], [['string', 'number', 'bson:Long', 'bson:Int32']], 'NumberLong');
|
|
96
|
+
if (typeof s === 'number') {
|
|
97
|
+
printWarning('NumberLong: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead');
|
|
98
|
+
return bson.Long.fromNumber(s);
|
|
99
|
+
}
|
|
100
|
+
return bson.Long.fromString(`${s}`);
|
|
101
|
+
}, { prototype: bson.Long.prototype }),
|
|
102
|
+
ISODate: function ISODate(input) {
|
|
103
|
+
if (!input)
|
|
104
|
+
input = new Date().toISOString();
|
|
105
|
+
const isoDateRegex = /^(?<Y>\d{4})-?(?<M>\d{2})-?(?<D>\d{2})([T ](?<h>\d{2})(:?(?<m>\d{2})(:?((?<s>\d{2})(\.(?<ms>\d+))?))?)?(?<tz>Z|([+-])(\d{2}):?(\d{2})?)?)?$/;
|
|
106
|
+
const match = input.match(isoDateRegex);
|
|
107
|
+
if (match !== null && match.groups !== undefined) {
|
|
108
|
+
const { Y, M, D, h, m, s, ms, tz } = match.groups;
|
|
109
|
+
const normalized = `${Y}-${M}-${D}T${h || '00'}:${m || '00'}:${s || '00'}.${ms || '000'}${tz || 'Z'}`;
|
|
110
|
+
const date = new Date(normalized);
|
|
111
|
+
if (date.getTime() >= -62167219200000 && date.getTime() <= 253402300799999) {
|
|
112
|
+
return date;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
throw new errors_1.MongoshInvalidInputError(`${JSON.stringify(input)} is not a valid ISODate`, errors_1.CommonErrors.InvalidArgument);
|
|
116
|
+
},
|
|
117
|
+
BinData: Object.assign(function BinData(subtype, b64string) {
|
|
118
|
+
(0, helpers_1.assertArgsDefinedType)([subtype, b64string], ['number', 'string'], 'BinData');
|
|
119
|
+
const buffer = Buffer.from(b64string, 'base64');
|
|
120
|
+
return new bson.Binary(buffer, subtype);
|
|
121
|
+
}, { prototype: bson.Binary.prototype }),
|
|
122
|
+
HexData: Object.assign(function HexData(subtype, hexstr) {
|
|
123
|
+
(0, helpers_1.assertArgsDefinedType)([subtype, hexstr], ['number', 'string'], 'HexData');
|
|
124
|
+
const buffer = Buffer.from(hexstr, 'hex');
|
|
125
|
+
return new bson.Binary(buffer, subtype);
|
|
126
|
+
}, { prototype: bson.Binary.prototype }),
|
|
127
|
+
UUID: Object.assign(function UUID(hexstr) {
|
|
128
|
+
if (hexstr === undefined) {
|
|
129
|
+
const uuid = (0, crypto_1.randomBytes)(16);
|
|
130
|
+
uuid[6] = (uuid[6] & 0x0f) | 0x40;
|
|
131
|
+
uuid[8] = (uuid[8] & 0x3f) | 0x80;
|
|
132
|
+
hexstr = uuid.toString('hex');
|
|
133
|
+
}
|
|
134
|
+
(0, helpers_1.assertArgsDefinedType)([hexstr], ['string'], 'UUID');
|
|
135
|
+
const buffer = Buffer.from(hexstr.replace(/-/g, ''), 'hex');
|
|
136
|
+
return new bson.Binary(buffer, bson.Binary.SUBTYPE_UUID);
|
|
137
|
+
}, { prototype: bson.Binary.prototype }),
|
|
138
|
+
MD5: Object.assign(function MD5(hexstr) {
|
|
139
|
+
(0, helpers_1.assertArgsDefinedType)([hexstr], ['string'], 'MD5');
|
|
140
|
+
const buffer = Buffer.from(hexstr, 'hex');
|
|
141
|
+
return new bson.Binary(buffer, bson.Binary.SUBTYPE_MD5);
|
|
142
|
+
}, { prototype: bson.Binary.prototype }),
|
|
143
|
+
Decimal128: bson.Decimal128,
|
|
144
|
+
BSONSymbol: bson.BSONSymbol,
|
|
145
|
+
Int32: bson.Int32,
|
|
146
|
+
Long: bson.Long,
|
|
147
|
+
Binary: bson.Binary,
|
|
148
|
+
Double: bson.Double,
|
|
149
|
+
EJSON: bson.EJSON,
|
|
150
|
+
BSONRegExp: bson.BSONRegExp
|
|
151
|
+
};
|
|
152
|
+
for (const className of Object.keys(bsonPkg)) {
|
|
153
|
+
const help = helps[className] || constructHelp(className);
|
|
154
|
+
bsonPkg[className].help = () => (help);
|
|
155
|
+
Object.setPrototypeOf(bsonPkg[className].help, help);
|
|
156
|
+
}
|
|
157
|
+
return bsonPkg;
|
|
158
|
+
}
|
|
159
|
+
exports.default = constructShellBson;
|
|
160
160
|
//# sourceMappingURL=shell-bson.js.map
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { AutoEncryptionOptions, ConnectInfo, ServerApi, ServiceProvider } from '@qp-mongosh/service-provider-core';
|
|
2
|
-
import type { ApiEvent, ApiEventWithArguments, ConfigProvider, MongoshBus, ShellUserConfig } from '@qp-mongosh/types';
|
|
3
|
-
import ChangeStreamCursor from './change-stream-cursor';
|
|
4
|
-
import { Topologies } from './enums';
|
|
5
|
-
import { AggregationCursor, Cursor, Database, Mongo, ShellApi, ShellResult } from './index';
|
|
6
|
-
import { InterruptFlag } from './interruptor';
|
|
7
|
-
import { ShellBson } from './shell-bson';
|
|
8
|
-
export interface ShellCliOptions {
|
|
9
|
-
nodb?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface AutocompleteParameters {
|
|
12
|
-
topology: () => Topologies;
|
|
13
|
-
apiVersionInfo: () => Required<ServerApi> | undefined;
|
|
14
|
-
connectionInfo: () => ConnectInfo | undefined;
|
|
15
|
-
getCollectionCompletionsForCurrentDb: (collName: string) => Promise<string[]>;
|
|
16
|
-
getDatabaseCompletions: (dbName: string) => Promise<string[]>;
|
|
17
|
-
}
|
|
18
|
-
export interface OnLoadResult {
|
|
19
|
-
resolvedFilename: string;
|
|
20
|
-
evaluate(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export interface EvaluationListener extends Partial<ConfigProvider<ShellUserConfig>> {
|
|
23
|
-
onPrint?: (value: ShellResult[]) => Promise<void> | void;
|
|
24
|
-
onPrompt?: (question: string, type: 'password' | 'yesno') => Promise<string> | string;
|
|
25
|
-
onClearCommand?: () => Promise<void> | void;
|
|
26
|
-
onExit?: (exitCode?: number) => Promise<never>;
|
|
27
|
-
onLoad?: (filename: string) => Promise<OnLoadResult> | OnLoadResult;
|
|
28
|
-
startMongocryptd?: () => Promise<AutoEncryptionOptions['extraOptions']>;
|
|
29
|
-
}
|
|
30
|
-
export interface ShellPlugin {
|
|
31
|
-
transformError?: (err: Error) => Error;
|
|
32
|
-
}
|
|
33
|
-
export default class ShellInstanceState {
|
|
34
|
-
currentCursor: Cursor | AggregationCursor | ChangeStreamCursor | null;
|
|
35
|
-
currentDb: Database;
|
|
36
|
-
messageBus: MongoshBus;
|
|
37
|
-
initialServiceProvider: ServiceProvider;
|
|
38
|
-
connectionInfo: any;
|
|
39
|
-
context: any;
|
|
40
|
-
mongos: Mongo[];
|
|
41
|
-
shellApi: ShellApi;
|
|
42
|
-
shellBson: ShellBson;
|
|
43
|
-
cliOptions: ShellCliOptions;
|
|
44
|
-
evaluationListener: EvaluationListener;
|
|
45
|
-
displayBatchSizeFromDBQuery: number | undefined;
|
|
46
|
-
isInteractive: boolean;
|
|
47
|
-
apiCallDepth: number;
|
|
48
|
-
private warningsShown;
|
|
49
|
-
readonly interrupted: InterruptFlag;
|
|
50
|
-
resumeMongosAfterInterrupt: Array<{
|
|
51
|
-
mongo: Mongo;
|
|
52
|
-
resume: (() => Promise<void>) | null;
|
|
53
|
-
}> | undefined;
|
|
54
|
-
private plugins;
|
|
55
|
-
private alreadyTransformedErrors;
|
|
56
|
-
constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
|
|
57
|
-
fetchConnectionInfo(): Promise<void>;
|
|
58
|
-
close(force: boolean): Promise<void>;
|
|
59
|
-
setDbFunc(newDb: any): Database;
|
|
60
|
-
setCtx(contextObject: any): void;
|
|
61
|
-
get currentServiceProvider(): ServiceProvider;
|
|
62
|
-
emitApiCallWithArgs(event: ApiEventWithArguments): void;
|
|
63
|
-
emitApiCall(event: Omit<ApiEvent, 'callDepth'>): void;
|
|
64
|
-
setEvaluationListener(listener: EvaluationListener): void;
|
|
65
|
-
getAutocompleteParameters(): AutocompleteParameters;
|
|
66
|
-
apiVersionInfo(): Required<ServerApi> | undefined;
|
|
67
|
-
onInterruptExecution(): Promise<boolean>;
|
|
68
|
-
onResumeExecution(): Promise<boolean>;
|
|
69
|
-
getDefaultPrompt(): Promise<string>;
|
|
70
|
-
private getDefaultPromptPrefix;
|
|
71
|
-
private getTopologySpecificPrompt;
|
|
72
|
-
private getTopologySinglePrompt;
|
|
73
|
-
registerPlugin(plugin: ShellPlugin): void;
|
|
74
|
-
transformError(err: any): any;
|
|
75
|
-
printDeprecationWarning(message: string): Promise<void>;
|
|
76
|
-
printWarning(message: string): Promise<void>;
|
|
77
|
-
}
|
|
1
|
+
import { AutoEncryptionOptions, ConnectInfo, ServerApi, ServiceProvider } from '@qp-mongosh/service-provider-core';
|
|
2
|
+
import type { ApiEvent, ApiEventWithArguments, ConfigProvider, MongoshBus, ShellUserConfig } from '@qp-mongosh/types';
|
|
3
|
+
import ChangeStreamCursor from './change-stream-cursor';
|
|
4
|
+
import { Topologies } from './enums';
|
|
5
|
+
import { AggregationCursor, Cursor, Database, Mongo, ShellApi, ShellResult } from './index';
|
|
6
|
+
import { InterruptFlag } from './interruptor';
|
|
7
|
+
import { ShellBson } from './shell-bson';
|
|
8
|
+
export interface ShellCliOptions {
|
|
9
|
+
nodb?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface AutocompleteParameters {
|
|
12
|
+
topology: () => Topologies;
|
|
13
|
+
apiVersionInfo: () => Required<ServerApi> | undefined;
|
|
14
|
+
connectionInfo: () => ConnectInfo | undefined;
|
|
15
|
+
getCollectionCompletionsForCurrentDb: (collName: string) => Promise<string[]>;
|
|
16
|
+
getDatabaseCompletions: (dbName: string) => Promise<string[]>;
|
|
17
|
+
}
|
|
18
|
+
export interface OnLoadResult {
|
|
19
|
+
resolvedFilename: string;
|
|
20
|
+
evaluate(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface EvaluationListener extends Partial<ConfigProvider<ShellUserConfig>> {
|
|
23
|
+
onPrint?: (value: ShellResult[]) => Promise<void> | void;
|
|
24
|
+
onPrompt?: (question: string, type: 'password' | 'yesno') => Promise<string> | string;
|
|
25
|
+
onClearCommand?: () => Promise<void> | void;
|
|
26
|
+
onExit?: (exitCode?: number) => Promise<never>;
|
|
27
|
+
onLoad?: (filename: string) => Promise<OnLoadResult> | OnLoadResult;
|
|
28
|
+
startMongocryptd?: () => Promise<AutoEncryptionOptions['extraOptions']>;
|
|
29
|
+
}
|
|
30
|
+
export interface ShellPlugin {
|
|
31
|
+
transformError?: (err: Error) => Error;
|
|
32
|
+
}
|
|
33
|
+
export default class ShellInstanceState {
|
|
34
|
+
currentCursor: Cursor | AggregationCursor | ChangeStreamCursor | null;
|
|
35
|
+
currentDb: Database;
|
|
36
|
+
messageBus: MongoshBus;
|
|
37
|
+
initialServiceProvider: ServiceProvider;
|
|
38
|
+
connectionInfo: any;
|
|
39
|
+
context: any;
|
|
40
|
+
mongos: Mongo[];
|
|
41
|
+
shellApi: ShellApi;
|
|
42
|
+
shellBson: ShellBson;
|
|
43
|
+
cliOptions: ShellCliOptions;
|
|
44
|
+
evaluationListener: EvaluationListener;
|
|
45
|
+
displayBatchSizeFromDBQuery: number | undefined;
|
|
46
|
+
isInteractive: boolean;
|
|
47
|
+
apiCallDepth: number;
|
|
48
|
+
private warningsShown;
|
|
49
|
+
readonly interrupted: InterruptFlag;
|
|
50
|
+
resumeMongosAfterInterrupt: Array<{
|
|
51
|
+
mongo: Mongo;
|
|
52
|
+
resume: (() => Promise<void>) | null;
|
|
53
|
+
}> | undefined;
|
|
54
|
+
private plugins;
|
|
55
|
+
private alreadyTransformedErrors;
|
|
56
|
+
constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
|
|
57
|
+
fetchConnectionInfo(): Promise<void>;
|
|
58
|
+
close(force: boolean): Promise<void>;
|
|
59
|
+
setDbFunc(newDb: any): Database;
|
|
60
|
+
setCtx(contextObject: any): void;
|
|
61
|
+
get currentServiceProvider(): ServiceProvider;
|
|
62
|
+
emitApiCallWithArgs(event: ApiEventWithArguments): void;
|
|
63
|
+
emitApiCall(event: Omit<ApiEvent, 'callDepth'>): void;
|
|
64
|
+
setEvaluationListener(listener: EvaluationListener): void;
|
|
65
|
+
getAutocompleteParameters(): AutocompleteParameters;
|
|
66
|
+
apiVersionInfo(): Required<ServerApi> | undefined;
|
|
67
|
+
onInterruptExecution(): Promise<boolean>;
|
|
68
|
+
onResumeExecution(): Promise<boolean>;
|
|
69
|
+
getDefaultPrompt(): Promise<string>;
|
|
70
|
+
private getDefaultPromptPrefix;
|
|
71
|
+
private getTopologySpecificPrompt;
|
|
72
|
+
private getTopologySinglePrompt;
|
|
73
|
+
registerPlugin(plugin: ShellPlugin): void;
|
|
74
|
+
transformError(err: any): any;
|
|
75
|
+
printDeprecationWarning(message: string): Promise<void>;
|
|
76
|
+
printWarning(message: string): Promise<void>;
|
|
77
|
+
}
|