@mongosh/shell-api 2.1.1 → 2.1.4

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 (59) hide show
  1. package/AUTHORS +1 -0
  2. package/lib/abstract-cursor.js +176 -132
  3. package/lib/abstract-cursor.js.map +1 -1
  4. package/lib/aggregate-or-find-cursor.js +102 -51
  5. package/lib/aggregate-or-find-cursor.js.map +1 -1
  6. package/lib/aggregation-cursor.js +59 -13
  7. package/lib/aggregation-cursor.js.map +1 -1
  8. package/lib/bulk.js +248 -197
  9. package/lib/bulk.js.map +1 -1
  10. package/lib/change-stream-cursor.js +145 -101
  11. package/lib/change-stream-cursor.js.map +1 -1
  12. package/lib/collection.d.ts +2 -1
  13. package/lib/collection.js +1185 -1245
  14. package/lib/collection.js.map +1 -1
  15. package/lib/cursor.js +238 -203
  16. package/lib/cursor.js.map +1 -1
  17. package/lib/database.js +1189 -1206
  18. package/lib/database.js.map +1 -1
  19. package/lib/dbquery.js +68 -22
  20. package/lib/dbquery.js.map +1 -1
  21. package/lib/decorators.d.ts +39 -13
  22. package/lib/decorators.js +34 -34
  23. package/lib/decorators.js.map +1 -1
  24. package/lib/explainable-cursor.js +66 -20
  25. package/lib/explainable-cursor.js.map +1 -1
  26. package/lib/explainable.js +214 -179
  27. package/lib/explainable.js.map +1 -1
  28. package/lib/field-level-encryption.js +286 -235
  29. package/lib/field-level-encryption.js.map +1 -1
  30. package/lib/helpers.d.ts +9 -1
  31. package/lib/helpers.js +24 -17
  32. package/lib/helpers.js.map +1 -1
  33. package/lib/interruptor.js.map +1 -1
  34. package/lib/log-entry.js.map +1 -1
  35. package/lib/mongo-errors.js +3 -1
  36. package/lib/mongo-errors.js.map +1 -1
  37. package/lib/mongo.js +581 -547
  38. package/lib/mongo.js.map +1 -1
  39. package/lib/plan-cache.js +108 -64
  40. package/lib/plan-cache.js.map +1 -1
  41. package/lib/replica-set.js +290 -277
  42. package/lib/replica-set.js.map +1 -1
  43. package/lib/result.js +228 -91
  44. package/lib/result.js.map +1 -1
  45. package/lib/run-command-cursor.js +59 -13
  46. package/lib/run-command-cursor.js.map +1 -1
  47. package/lib/session.js +123 -76
  48. package/lib/session.js.map +1 -1
  49. package/lib/shard.js +507 -514
  50. package/lib/shard.js.map +1 -1
  51. package/lib/shell-api.js +313 -268
  52. package/lib/shell-api.js.map +1 -1
  53. package/lib/shell-bson.js.map +1 -1
  54. package/lib/shell-instance-state.js.map +1 -1
  55. package/lib/stream-processor.js +139 -92
  56. package/lib/stream-processor.js.map +1 -1
  57. package/lib/streams.js +158 -110
  58. package/lib/streams.js.map +1 -1
  59. package/package.json +10 -10
package/lib/shell-api.js CHANGED
@@ -1,9 +1,41 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
7
39
  };
8
40
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -23,66 +55,79 @@ const types_1 = require("@mongosh/types");
23
55
  const i18n_1 = __importDefault(require("@mongosh/i18n"));
24
56
  const instanceStateSymbol = Symbol.for('@@mongosh.instanceState');
25
57
  const loadCallNestingLevelSymbol = Symbol.for('@@mongosh.loadCallNestingLevel');
26
- let ShellConfig = class ShellConfig extends decorators_1.ShellApiClass {
27
- constructor(instanceState) {
28
- super();
29
- this._instanceState = instanceState;
30
- this.defaults = Object.freeze(new types_1.ShellUserConfig());
31
- }
32
- async set(key, value) {
33
- var _a, _b;
34
- (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.set');
35
- const { evaluationListener } = this._instanceState;
36
- const isValidKey = (await this._allKeys()).includes(key);
37
- if (isValidKey) {
38
- const validationResult = await ((_a = evaluationListener.validateConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key, value));
39
- if (validationResult) {
40
- return `Cannot set option "${key}": ${validationResult}`;
58
+ let ShellConfig = (() => {
59
+ let _classDecorators = [decorators_1.shellApiClassDefault];
60
+ let _classDescriptor;
61
+ let _classExtraInitializers = [];
62
+ let _classThis;
63
+ let _classSuper = decorators_1.ShellApiClass;
64
+ let _instanceExtraInitializers = [];
65
+ let _set_decorators;
66
+ let _get_decorators;
67
+ let _reset_decorators;
68
+ var ShellConfig = _classThis = class extends _classSuper {
69
+ constructor(instanceState) {
70
+ super();
71
+ this._instanceState = (__runInitializers(this, _instanceExtraInitializers), void 0);
72
+ this._instanceState = instanceState;
73
+ this.defaults = Object.freeze(new types_1.ShellUserConfig());
74
+ }
75
+ async set(key, value) {
76
+ var _a, _b;
77
+ (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.set');
78
+ const { evaluationListener } = this._instanceState;
79
+ const isValidKey = (await this._allKeys()).includes(key);
80
+ if (isValidKey) {
81
+ const validationResult = await ((_a = evaluationListener.validateConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key, value));
82
+ if (validationResult) {
83
+ return `Cannot set option "${key}": ${validationResult}`;
84
+ }
85
+ }
86
+ const result = isValidKey && (await ((_b = evaluationListener.setConfig) === null || _b === void 0 ? void 0 : _b.call(evaluationListener, key, value)));
87
+ if (result !== 'success') {
88
+ return `Option "${key}" is not available in this environment`;
41
89
  }
90
+ return `Setting "${key}" has been changed`;
42
91
  }
43
- const result = isValidKey && (await ((_b = evaluationListener.setConfig) === null || _b === void 0 ? void 0 : _b.call(evaluationListener, key, value)));
44
- if (result !== 'success') {
45
- return `Option "${key}" is not available in this environment`;
92
+ async get(key) {
93
+ var _a, _b;
94
+ (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.get');
95
+ const { evaluationListener } = this._instanceState;
96
+ return (_b = (await ((_a = evaluationListener.getConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key)))) !== null && _b !== void 0 ? _b : this.defaults[key];
46
97
  }
47
- return `Setting "${key}" has been changed`;
48
- }
49
- async get(key) {
50
- var _a, _b;
51
- (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.get');
52
- const { evaluationListener } = this._instanceState;
53
- return (_b = (await ((_a = evaluationListener.getConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key)))) !== null && _b !== void 0 ? _b : this.defaults[key];
54
- }
55
- async reset(key) {
56
- var _a;
57
- (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.reset');
58
- const { evaluationListener } = this._instanceState;
59
- const result = await ((_a = evaluationListener.resetConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key));
60
- if (result !== 'success') {
61
- return `Option "${key}" cannot be changed in this environment`;
98
+ async reset(key) {
99
+ var _a;
100
+ (0, helpers_1.assertArgsDefinedType)([key], ['string'], 'config.reset');
101
+ const { evaluationListener } = this._instanceState;
102
+ const result = await ((_a = evaluationListener.resetConfig) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, key));
103
+ if (result !== 'success') {
104
+ return `Option "${key}" cannot be changed in this environment`;
105
+ }
106
+ return `Setting "${key}" has been reset to its default value`;
62
107
  }
63
- return `Setting "${key}" has been reset to its default value`;
64
- }
65
- async _allKeys() {
66
- var _a, _b;
67
- const { evaluationListener } = this._instanceState;
68
- return ((_b = (await ((_a = evaluationListener.listConfigOptions) === null || _a === void 0 ? void 0 : _a.call(evaluationListener)))) !== null && _b !== void 0 ? _b : Object.keys(this.defaults));
69
- }
70
- async [enums_1.asPrintable]() {
71
- return new Map(await Promise.all((await this._allKeys()).map(async (key) => [key, await this.get(key)])));
72
- }
73
- };
74
- __decorate([
75
- decorators_1.returnsPromise
76
- ], ShellConfig.prototype, "set", null);
77
- __decorate([
78
- decorators_1.returnsPromise
79
- ], ShellConfig.prototype, "get", null);
80
- __decorate([
81
- decorators_1.returnsPromise
82
- ], ShellConfig.prototype, "reset", null);
83
- ShellConfig = __decorate([
84
- decorators_1.shellApiClassDefault
85
- ], ShellConfig);
108
+ async _allKeys() {
109
+ var _a, _b;
110
+ const { evaluationListener } = this._instanceState;
111
+ return ((_b = (await ((_a = evaluationListener.listConfigOptions) === null || _a === void 0 ? void 0 : _a.call(evaluationListener)))) !== null && _b !== void 0 ? _b : Object.keys(this.defaults));
112
+ }
113
+ async [(_set_decorators = [decorators_1.returnsPromise], _get_decorators = [decorators_1.returnsPromise], _reset_decorators = [decorators_1.returnsPromise], enums_1.asPrintable)]() {
114
+ return new Map(await Promise.all((await this._allKeys()).map(async (key) => [key, await this.get(key)])));
115
+ }
116
+ };
117
+ __setFunctionName(_classThis, "ShellConfig");
118
+ (() => {
119
+ var _a;
120
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
121
+ __esDecorate(_classThis, null, _set_decorators, { kind: "method", name: "set", static: false, private: false, access: { has: obj => "set" in obj, get: obj => obj.set }, metadata: _metadata }, null, _instanceExtraInitializers);
122
+ __esDecorate(_classThis, null, _get_decorators, { kind: "method", name: "get", static: false, private: false, access: { has: obj => "get" in obj, get: obj => obj.get }, metadata: _metadata }, null, _instanceExtraInitializers);
123
+ __esDecorate(_classThis, null, _reset_decorators, { kind: "method", name: "reset", static: false, private: false, access: { has: obj => "reset" in obj, get: obj => obj.reset }, metadata: _metadata }, null, _instanceExtraInitializers);
124
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
125
+ ShellConfig = _classThis = _classDescriptor.value;
126
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
127
+ __runInitializers(_classThis, _classExtraInitializers);
128
+ })();
129
+ return ShellConfig = _classThis;
130
+ })();
86
131
  async function useCompleter(params, args) {
87
132
  var _a;
88
133
  if (args.length > 2)
@@ -111,219 +156,219 @@ async function showCompleter(params, args) {
111
156
  ];
112
157
  return candidates.filter((str) => { var _a; return str.startsWith((_a = args[1]) !== null && _a !== void 0 ? _a : ''); });
113
158
  }
114
- let ShellApi = class ShellApi extends decorators_1.ShellApiClass {
115
- constructor(instanceState) {
116
- super();
117
- this[instanceStateSymbol] = instanceState;
118
- this[loadCallNestingLevelSymbol] = 0;
119
- this.DBQuery = new dbquery_1.DBQuery(instanceState);
120
- this.config = new ShellConfig(instanceState);
121
- }
122
- get _instanceState() {
123
- return this[instanceStateSymbol];
124
- }
125
- get loadCallNestingLevel() {
126
- return this[loadCallNestingLevelSymbol];
127
- }
128
- set loadCallNestingLevel(value) {
129
- this[loadCallNestingLevelSymbol] = value;
130
- }
131
- use(db) {
132
- return this._instanceState.currentDb._mongo.use(db);
133
- }
134
- async show(cmd, arg) {
135
- return await this._instanceState.currentDb._mongo.show(cmd, arg);
136
- }
137
- async _untrackedShow(cmd, arg) {
138
- return await this._instanceState.currentDb._mongo.show(cmd, arg, false);
139
- }
140
- async exit(exitCode) {
141
- var _a, _b;
142
- (0, helpers_1.assertArgsDefinedType)([exitCode], [[undefined, 'number']], 'exit');
143
- (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'the exit/quit commands');
144
- await this._instanceState.close(true);
145
- await ((_b = (_a = this._instanceState.evaluationListener).onExit) === null || _b === void 0 ? void 0 : _b.call(_a, exitCode));
146
- throw new errors_1.MongoshInternalError('.onExit listener returned');
147
- }
148
- async quit(exitCode) {
149
- return await this.exit(exitCode);
150
- }
151
- async Mongo(uri, fleOptions, otherOptions) {
152
- (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
153
- const mongo = new mongo_1.default(this._instanceState, uri, fleOptions, otherOptions);
154
- await mongo.connect();
155
- this._instanceState.mongos.push(mongo);
156
- return mongo;
157
- }
158
- async connect(uri, user, pwd) {
159
- (0, helpers_1.assertArgsDefinedType)([uri, user, pwd], ['string', [undefined, 'string'], [undefined, 'string']], 'connect');
160
- (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
161
- const mongo = new mongo_1.default(this._instanceState, uri);
162
- await mongo.connect(user, pwd);
163
- this._instanceState.mongos.push(mongo);
164
- const db = mongo._serviceProvider.initialDb || service_provider_core_1.DEFAULT_DB;
165
- return mongo.getDB(db);
166
- }
167
- async it() {
168
- if (!this._instanceState.currentCursor) {
169
- return new result_1.CursorIterationResult();
159
+ let ShellApi = (() => {
160
+ var _a;
161
+ let _classDecorators = [decorators_1.shellApiClassDefault];
162
+ let _classDescriptor;
163
+ let _classExtraInitializers = [];
164
+ let _classThis;
165
+ let _classSuper = decorators_1.ShellApiClass;
166
+ let _instanceExtraInitializers = [];
167
+ let _use_decorators;
168
+ let _show_decorators;
169
+ let __untrackedShow_decorators;
170
+ let _exit_decorators;
171
+ let _quit_decorators;
172
+ let _Mongo_decorators;
173
+ let _connect_decorators;
174
+ let _it_decorators;
175
+ let _load_decorators;
176
+ let _enableTelemetry_decorators;
177
+ let _disableTelemetry_decorators;
178
+ let _passwordPrompt_decorators;
179
+ let _sleep_decorators;
180
+ let _print_decorators;
181
+ let _printjson_decorators;
182
+ let _convertShardKeyToHashed_decorators;
183
+ let _cls_decorators;
184
+ var ShellApi = _classThis = class extends _classSuper {
185
+ constructor(instanceState) {
186
+ super();
187
+ this[_a] = (__runInitializers(this, _instanceExtraInitializers), void 0);
188
+ this[instanceStateSymbol] = instanceState;
189
+ this[loadCallNestingLevelSymbol] = 0;
190
+ this.DBQuery = new dbquery_1.DBQuery(instanceState);
191
+ this.config = new ShellConfig(instanceState);
170
192
  }
171
- return await this._instanceState.currentCursor._it();
172
- }
173
- version() {
174
- const version = require('../package.json').version;
175
- return version;
176
- }
177
- async load(filename) {
178
- (0, helpers_1.assertArgsDefinedType)([filename], ['string'], 'load');
179
- if (!this._instanceState.evaluationListener.onLoad) {
180
- throw new errors_1.MongoshUnimplementedError('load is not currently implemented for this platform', errors_1.CommonErrors.NotImplemented);
181
- }
182
- this._instanceState.messageBus.emit('mongosh:api-load-file', {
183
- nested: this.loadCallNestingLevel > 0,
184
- filename,
185
- });
186
- const { resolvedFilename, evaluate } = await this._instanceState.evaluationListener.onLoad(filename);
187
- const context = this._instanceState.context;
188
- const previousFilename = context.__filename;
189
- context.__filename = resolvedFilename;
190
- context.__dirname = (0, path_1.dirname)(resolvedFilename);
191
- this.loadCallNestingLevel++;
192
- try {
193
- await evaluate();
194
- }
195
- finally {
196
- this.loadCallNestingLevel--;
197
- if (previousFilename) {
198
- context.__filename = previousFilename;
199
- context.__dirname = (0, path_1.dirname)(previousFilename);
193
+ get _instanceState() {
194
+ return this[instanceStateSymbol];
195
+ }
196
+ get loadCallNestingLevel() {
197
+ return this[loadCallNestingLevelSymbol];
198
+ }
199
+ set loadCallNestingLevel(value) {
200
+ this[loadCallNestingLevelSymbol] = value;
201
+ }
202
+ use(db) {
203
+ return this._instanceState.currentDb._mongo.use(db);
204
+ }
205
+ async show(cmd, arg) {
206
+ return await this._instanceState.currentDb._mongo.show(cmd, arg);
207
+ }
208
+ async _untrackedShow(cmd, arg) {
209
+ return await this._instanceState.currentDb._mongo.show(cmd, arg, false);
210
+ }
211
+ async exit(exitCode) {
212
+ var _b, _c;
213
+ (0, helpers_1.assertArgsDefinedType)([exitCode], [[undefined, 'number']], 'exit');
214
+ (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'the exit/quit commands');
215
+ await this._instanceState.close(true);
216
+ await ((_c = (_b = this._instanceState.evaluationListener).onExit) === null || _c === void 0 ? void 0 : _c.call(_b, exitCode));
217
+ throw new errors_1.MongoshInternalError('.onExit listener returned');
218
+ }
219
+ async quit(exitCode) {
220
+ return await this.exit(exitCode);
221
+ }
222
+ async Mongo(uri, fleOptions, otherOptions) {
223
+ (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
224
+ const mongo = new mongo_1.default(this._instanceState, uri, fleOptions, otherOptions);
225
+ await mongo.connect();
226
+ this._instanceState.mongos.push(mongo);
227
+ return mongo;
228
+ }
229
+ async connect(uri, user, pwd) {
230
+ (0, helpers_1.assertArgsDefinedType)([uri, user, pwd], ['string', [undefined, 'string'], [undefined, 'string']], 'connect');
231
+ (0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
232
+ const mongo = new mongo_1.default(this._instanceState, uri);
233
+ await mongo.connect(user, pwd);
234
+ this._instanceState.mongos.push(mongo);
235
+ const db = mongo._serviceProvider.initialDb || service_provider_core_1.DEFAULT_DB;
236
+ return mongo.getDB(db);
237
+ }
238
+ async it() {
239
+ if (!this._instanceState.currentCursor) {
240
+ return new result_1.CursorIterationResult();
241
+ }
242
+ return await this._instanceState.currentCursor._it();
243
+ }
244
+ version() {
245
+ const version = require('../package.json').version;
246
+ return version;
247
+ }
248
+ async load(filename) {
249
+ (0, helpers_1.assertArgsDefinedType)([filename], ['string'], 'load');
250
+ if (!this._instanceState.evaluationListener.onLoad) {
251
+ throw new errors_1.MongoshUnimplementedError('load is not currently implemented for this platform', errors_1.CommonErrors.NotImplemented);
252
+ }
253
+ this._instanceState.messageBus.emit('mongosh:api-load-file', {
254
+ nested: this.loadCallNestingLevel > 0,
255
+ filename,
256
+ });
257
+ const { resolvedFilename, evaluate } = await this._instanceState.evaluationListener.onLoad(filename);
258
+ const context = this._instanceState.context;
259
+ const previousFilename = context.__filename;
260
+ context.__filename = resolvedFilename;
261
+ context.__dirname = (0, path_1.dirname)(resolvedFilename);
262
+ this.loadCallNestingLevel++;
263
+ try {
264
+ await evaluate();
200
265
  }
201
- else {
202
- delete context.__filename;
203
- delete context.__dirname;
266
+ finally {
267
+ this.loadCallNestingLevel--;
268
+ if (previousFilename) {
269
+ context.__filename = previousFilename;
270
+ context.__dirname = (0, path_1.dirname)(previousFilename);
271
+ }
272
+ else {
273
+ delete context.__filename;
274
+ delete context.__dirname;
275
+ }
204
276
  }
277
+ return true;
205
278
  }
206
- return true;
207
- }
208
- async enableTelemetry() {
209
- var _a, _b;
210
- const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', true));
211
- if (result === 'success') {
212
- return i18n_1.default.__('cli-repl.cli-repl.enabledTelemetry');
279
+ async enableTelemetry() {
280
+ var _b, _c;
281
+ const result = await ((_c = (_b = this._instanceState.evaluationListener).setConfig) === null || _c === void 0 ? void 0 : _c.call(_b, 'enableTelemetry', true));
282
+ if (result === 'success') {
283
+ return i18n_1.default.__('cli-repl.cli-repl.enabledTelemetry');
284
+ }
213
285
  }
214
- }
215
- async disableTelemetry() {
216
- var _a, _b;
217
- const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', false));
218
- if (result === 'success') {
219
- return i18n_1.default.__('cli-repl.cli-repl.disabledTelemetry');
286
+ async disableTelemetry() {
287
+ var _b, _c;
288
+ const result = await ((_c = (_b = this._instanceState.evaluationListener).setConfig) === null || _c === void 0 ? void 0 : _c.call(_b, 'enableTelemetry', false));
289
+ if (result === 'success') {
290
+ return i18n_1.default.__('cli-repl.cli-repl.disabledTelemetry');
291
+ }
220
292
  }
221
- }
222
- async passwordPrompt() {
223
- const { evaluationListener } = this._instanceState;
224
- if (!evaluationListener.onPrompt) {
225
- throw new errors_1.MongoshUnimplementedError('passwordPrompt() is not available in this shell', errors_1.CommonErrors.NotImplemented);
293
+ async passwordPrompt() {
294
+ const { evaluationListener } = this._instanceState;
295
+ if (!evaluationListener.onPrompt) {
296
+ throw new errors_1.MongoshUnimplementedError('passwordPrompt() is not available in this shell', errors_1.CommonErrors.NotImplemented);
297
+ }
298
+ return await evaluationListener.onPrompt('Enter password', 'password');
226
299
  }
227
- return await evaluationListener.onPrompt('Enter password', 'password');
228
- }
229
- async sleep(ms) {
230
- return await (0, util_1.promisify)(setTimeout)(ms);
231
- }
232
- async _print(origArgs, type) {
233
- var _a;
234
- const { evaluationListener } = this._instanceState;
235
- const args = await Promise.all(origArgs.map((arg) => (0, decorators_1.toShellResult)(arg)));
236
- await ((_a = evaluationListener.onPrint) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, args, type));
237
- }
238
- async print(...origArgs) {
239
- await this._print(origArgs, 'print');
240
- }
241
- async printjson(...origArgs) {
242
- await this._print(origArgs, 'printjson');
243
- }
244
- async convertShardKeyToHashed(value) {
245
- return this._instanceState.currentDb._mongo.convertShardKeyToHashed(value);
246
- }
247
- async cls() {
248
- var _a;
249
- const { evaluationListener } = this._instanceState;
250
- await ((_a = evaluationListener.onClearCommand) === null || _a === void 0 ? void 0 : _a.call(evaluationListener));
251
- }
252
- isInteractive() {
253
- return this._instanceState.isInteractive;
254
- }
255
- };
256
- __decorate([
257
- decorators_1.directShellCommand,
258
- (0, decorators_1.shellCommandCompleter)(useCompleter)
259
- ], ShellApi.prototype, "use", null);
260
- __decorate([
261
- decorators_1.directShellCommand,
262
- decorators_1.returnsPromise,
263
- (0, decorators_1.shellCommandCompleter)(showCompleter)
264
- ], ShellApi.prototype, "show", null);
265
- __decorate([
266
- decorators_1.directShellCommand,
267
- decorators_1.returnsPromise,
268
- (0, decorators_1.shellCommandCompleter)(showCompleter)
269
- ], ShellApi.prototype, "_untrackedShow", null);
270
- __decorate([
271
- decorators_1.directShellCommand,
272
- decorators_1.returnsPromise,
273
- (0, decorators_1.platforms)(['CLI'])
274
- ], ShellApi.prototype, "exit", null);
275
- __decorate([
276
- decorators_1.directShellCommand,
277
- decorators_1.returnsPromise,
278
- (0, decorators_1.platforms)(['CLI'])
279
- ], ShellApi.prototype, "quit", null);
280
- __decorate([
281
- decorators_1.returnsPromise,
282
- (0, decorators_1.returnType)('Mongo'),
283
- (0, decorators_1.platforms)(['CLI'])
284
- ], ShellApi.prototype, "Mongo", null);
285
- __decorate([
286
- decorators_1.returnsPromise,
287
- (0, decorators_1.returnType)('Database'),
288
- (0, decorators_1.platforms)(['CLI'])
289
- ], ShellApi.prototype, "connect", null);
290
- __decorate([
291
- decorators_1.directShellCommand,
292
- decorators_1.returnsPromise
293
- ], ShellApi.prototype, "it", null);
294
- __decorate([
295
- decorators_1.returnsPromise
296
- ], ShellApi.prototype, "load", null);
297
- __decorate([
298
- decorators_1.returnsPromise,
299
- (0, decorators_1.platforms)(['CLI'])
300
- ], ShellApi.prototype, "enableTelemetry", null);
301
- __decorate([
302
- decorators_1.returnsPromise,
303
- (0, decorators_1.platforms)(['CLI'])
304
- ], ShellApi.prototype, "disableTelemetry", null);
305
- __decorate([
306
- decorators_1.returnsPromise,
307
- (0, decorators_1.platforms)(['CLI'])
308
- ], ShellApi.prototype, "passwordPrompt", null);
309
- __decorate([
310
- decorators_1.returnsPromise
311
- ], ShellApi.prototype, "sleep", null);
312
- __decorate([
313
- decorators_1.returnsPromise
314
- ], ShellApi.prototype, "print", null);
315
- __decorate([
316
- decorators_1.returnsPromise
317
- ], ShellApi.prototype, "printjson", null);
318
- __decorate([
319
- decorators_1.returnsPromise
320
- ], ShellApi.prototype, "convertShardKeyToHashed", null);
321
- __decorate([
322
- decorators_1.directShellCommand,
323
- decorators_1.returnsPromise
324
- ], ShellApi.prototype, "cls", null);
325
- ShellApi = __decorate([
326
- decorators_1.shellApiClassDefault
327
- ], ShellApi);
300
+ async sleep(ms) {
301
+ return await (0, util_1.promisify)(setTimeout)(ms);
302
+ }
303
+ async _print(origArgs, type) {
304
+ var _b;
305
+ const { evaluationListener } = this._instanceState;
306
+ const args = await Promise.all(origArgs.map((arg) => (0, decorators_1.toShellResult)(arg)));
307
+ await ((_b = evaluationListener.onPrint) === null || _b === void 0 ? void 0 : _b.call(evaluationListener, args, type));
308
+ }
309
+ async print(...origArgs) {
310
+ await this._print(origArgs, 'print');
311
+ }
312
+ async printjson(...origArgs) {
313
+ await this._print(origArgs, 'printjson');
314
+ }
315
+ async convertShardKeyToHashed(value) {
316
+ return this._instanceState.currentDb._mongo.convertShardKeyToHashed(value);
317
+ }
318
+ async cls() {
319
+ var _b;
320
+ const { evaluationListener } = this._instanceState;
321
+ await ((_b = evaluationListener.onClearCommand) === null || _b === void 0 ? void 0 : _b.call(evaluationListener));
322
+ }
323
+ isInteractive() {
324
+ return this._instanceState.isInteractive;
325
+ }
326
+ };
327
+ _a = instanceStateSymbol;
328
+ __setFunctionName(_classThis, "ShellApi");
329
+ (() => {
330
+ var _b;
331
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
332
+ _use_decorators = [decorators_1.directShellCommand, (0, decorators_1.shellCommandCompleter)(useCompleter)];
333
+ _show_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise, (0, decorators_1.shellCommandCompleter)(showCompleter)];
334
+ __untrackedShow_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise, (0, decorators_1.shellCommandCompleter)(showCompleter)];
335
+ _exit_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise, (0, decorators_1.platforms)(['CLI'])];
336
+ _quit_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise, (0, decorators_1.platforms)(['CLI'])];
337
+ _Mongo_decorators = [decorators_1.returnsPromise, (0, decorators_1.returnType)('Mongo'), (0, decorators_1.platforms)(['CLI'])];
338
+ _connect_decorators = [decorators_1.returnsPromise, (0, decorators_1.returnType)('Database'), (0, decorators_1.platforms)(['CLI'])];
339
+ _it_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise];
340
+ _load_decorators = [decorators_1.returnsPromise];
341
+ _enableTelemetry_decorators = [decorators_1.returnsPromise, (0, decorators_1.platforms)(['CLI'])];
342
+ _disableTelemetry_decorators = [decorators_1.returnsPromise, (0, decorators_1.platforms)(['CLI'])];
343
+ _passwordPrompt_decorators = [decorators_1.returnsPromise, (0, decorators_1.platforms)(['CLI'])];
344
+ _sleep_decorators = [decorators_1.returnsPromise];
345
+ _print_decorators = [decorators_1.returnsPromise];
346
+ _printjson_decorators = [decorators_1.returnsPromise];
347
+ _convertShardKeyToHashed_decorators = [decorators_1.returnsPromise];
348
+ _cls_decorators = [decorators_1.directShellCommand, decorators_1.returnsPromise];
349
+ __esDecorate(_classThis, null, _use_decorators, { kind: "method", name: "use", static: false, private: false, access: { has: obj => "use" in obj, get: obj => obj.use }, metadata: _metadata }, null, _instanceExtraInitializers);
350
+ __esDecorate(_classThis, null, _show_decorators, { kind: "method", name: "show", static: false, private: false, access: { has: obj => "show" in obj, get: obj => obj.show }, metadata: _metadata }, null, _instanceExtraInitializers);
351
+ __esDecorate(_classThis, null, __untrackedShow_decorators, { kind: "method", name: "_untrackedShow", static: false, private: false, access: { has: obj => "_untrackedShow" in obj, get: obj => obj._untrackedShow }, metadata: _metadata }, null, _instanceExtraInitializers);
352
+ __esDecorate(_classThis, null, _exit_decorators, { kind: "method", name: "exit", static: false, private: false, access: { has: obj => "exit" in obj, get: obj => obj.exit }, metadata: _metadata }, null, _instanceExtraInitializers);
353
+ __esDecorate(_classThis, null, _quit_decorators, { kind: "method", name: "quit", static: false, private: false, access: { has: obj => "quit" in obj, get: obj => obj.quit }, metadata: _metadata }, null, _instanceExtraInitializers);
354
+ __esDecorate(_classThis, null, _Mongo_decorators, { kind: "method", name: "Mongo", static: false, private: false, access: { has: obj => "Mongo" in obj, get: obj => obj.Mongo }, metadata: _metadata }, null, _instanceExtraInitializers);
355
+ __esDecorate(_classThis, null, _connect_decorators, { kind: "method", name: "connect", static: false, private: false, access: { has: obj => "connect" in obj, get: obj => obj.connect }, metadata: _metadata }, null, _instanceExtraInitializers);
356
+ __esDecorate(_classThis, null, _it_decorators, { kind: "method", name: "it", static: false, private: false, access: { has: obj => "it" in obj, get: obj => obj.it }, metadata: _metadata }, null, _instanceExtraInitializers);
357
+ __esDecorate(_classThis, null, _load_decorators, { kind: "method", name: "load", static: false, private: false, access: { has: obj => "load" in obj, get: obj => obj.load }, metadata: _metadata }, null, _instanceExtraInitializers);
358
+ __esDecorate(_classThis, null, _enableTelemetry_decorators, { kind: "method", name: "enableTelemetry", static: false, private: false, access: { has: obj => "enableTelemetry" in obj, get: obj => obj.enableTelemetry }, metadata: _metadata }, null, _instanceExtraInitializers);
359
+ __esDecorate(_classThis, null, _disableTelemetry_decorators, { kind: "method", name: "disableTelemetry", static: false, private: false, access: { has: obj => "disableTelemetry" in obj, get: obj => obj.disableTelemetry }, metadata: _metadata }, null, _instanceExtraInitializers);
360
+ __esDecorate(_classThis, null, _passwordPrompt_decorators, { kind: "method", name: "passwordPrompt", static: false, private: false, access: { has: obj => "passwordPrompt" in obj, get: obj => obj.passwordPrompt }, metadata: _metadata }, null, _instanceExtraInitializers);
361
+ __esDecorate(_classThis, null, _sleep_decorators, { kind: "method", name: "sleep", static: false, private: false, access: { has: obj => "sleep" in obj, get: obj => obj.sleep }, metadata: _metadata }, null, _instanceExtraInitializers);
362
+ __esDecorate(_classThis, null, _print_decorators, { kind: "method", name: "print", static: false, private: false, access: { has: obj => "print" in obj, get: obj => obj.print }, metadata: _metadata }, null, _instanceExtraInitializers);
363
+ __esDecorate(_classThis, null, _printjson_decorators, { kind: "method", name: "printjson", static: false, private: false, access: { has: obj => "printjson" in obj, get: obj => obj.printjson }, metadata: _metadata }, null, _instanceExtraInitializers);
364
+ __esDecorate(_classThis, null, _convertShardKeyToHashed_decorators, { kind: "method", name: "convertShardKeyToHashed", static: false, private: false, access: { has: obj => "convertShardKeyToHashed" in obj, get: obj => obj.convertShardKeyToHashed }, metadata: _metadata }, null, _instanceExtraInitializers);
365
+ __esDecorate(_classThis, null, _cls_decorators, { kind: "method", name: "cls", static: false, private: false, access: { has: obj => "cls" in obj, get: obj => obj.cls }, metadata: _metadata }, null, _instanceExtraInitializers);
366
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
367
+ ShellApi = _classThis = _classDescriptor.value;
368
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
369
+ __runInitializers(_classThis, _classExtraInitializers);
370
+ })();
371
+ return ShellApi = _classThis;
372
+ })();
328
373
  exports.default = ShellApi;
329
374
  //# sourceMappingURL=shell-api.js.map