@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-api.js
CHANGED
|
@@ -1,299 +1,299 @@
|
|
|
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;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const decorators_1 = require("./decorators");
|
|
13
|
-
const enums_1 = require("./enums");
|
|
14
|
-
const mongo_1 = __importDefault(require("./mongo"));
|
|
15
|
-
const result_1 = require("./result");
|
|
16
|
-
const helpers_1 = require("./helpers");
|
|
17
|
-
const service_provider_core_1 = require("@qp-mongosh/service-provider-core");
|
|
18
|
-
const errors_1 = require("@qp-mongosh/errors");
|
|
19
|
-
const dbquery_1 = require("./dbquery");
|
|
20
|
-
const util_1 = require("util");
|
|
21
|
-
const path_1 = require("path");
|
|
22
|
-
const types_1 = require("@qp-mongosh/types");
|
|
23
|
-
const i18n_1 = __importDefault(require("@qp-mongosh/i18n"));
|
|
24
|
-
const instanceStateSymbol = Symbol.for('@@mongosh.instanceState');
|
|
25
|
-
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}`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
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`;
|
|
46
|
-
}
|
|
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`;
|
|
62
|
-
}
|
|
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);
|
|
86
|
-
async function useCompleter(params, args) {
|
|
87
|
-
var _a;
|
|
88
|
-
if (args.length > 2)
|
|
89
|
-
return undefined;
|
|
90
|
-
return await params.getDatabaseCompletions((_a = args[1]) !== null && _a !== void 0 ? _a : '');
|
|
91
|
-
}
|
|
92
|
-
async function showCompleter(params, args) {
|
|
93
|
-
if (args.length > 2)
|
|
94
|
-
return undefined;
|
|
95
|
-
if (args[1] === 'd') {
|
|
96
|
-
return ['databases'];
|
|
97
|
-
}
|
|
98
|
-
const candidates = ['databases', 'dbs', 'collections', 'tables', 'profile', 'users', 'roles', 'log', 'logs'];
|
|
99
|
-
return candidates.filter(str => { var _a; return str.startsWith((_a = args[1]) !== null && _a !== void 0 ? _a : ''); });
|
|
100
|
-
}
|
|
101
|
-
let ShellApi = class ShellApi extends decorators_1.ShellApiClass {
|
|
102
|
-
constructor(instanceState) {
|
|
103
|
-
super();
|
|
104
|
-
this[instanceStateSymbol] = instanceState;
|
|
105
|
-
this[loadCallNestingLevelSymbol] = 0;
|
|
106
|
-
this.DBQuery = new dbquery_1.DBQuery(instanceState);
|
|
107
|
-
this.config = new ShellConfig(instanceState);
|
|
108
|
-
}
|
|
109
|
-
get _instanceState() {
|
|
110
|
-
return this[instanceStateSymbol];
|
|
111
|
-
}
|
|
112
|
-
get loadCallNestingLevel() {
|
|
113
|
-
return this[loadCallNestingLevelSymbol];
|
|
114
|
-
}
|
|
115
|
-
set loadCallNestingLevel(value) {
|
|
116
|
-
this[loadCallNestingLevelSymbol] = value;
|
|
117
|
-
}
|
|
118
|
-
use(db) {
|
|
119
|
-
return this._instanceState.currentDb._mongo.use(db);
|
|
120
|
-
}
|
|
121
|
-
async show(cmd, arg) {
|
|
122
|
-
return await this._instanceState.currentDb._mongo.show(cmd, arg);
|
|
123
|
-
}
|
|
124
|
-
async exit(exitCode) {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
(0, helpers_1.assertArgsDefinedType)([exitCode], [[undefined, 'number']], 'exit');
|
|
127
|
-
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'the exit/quit commands');
|
|
128
|
-
await this._instanceState.close(true);
|
|
129
|
-
await ((_b = (_a = this._instanceState.evaluationListener).onExit) === null || _b === void 0 ? void 0 : _b.call(_a, exitCode));
|
|
130
|
-
throw new errors_1.MongoshInternalError('.onExit listener returned');
|
|
131
|
-
}
|
|
132
|
-
async quit(exitCode) {
|
|
133
|
-
return await this.exit(exitCode);
|
|
134
|
-
}
|
|
135
|
-
async Mongo(uri, fleOptions, otherOptions) {
|
|
136
|
-
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
|
|
137
|
-
const mongo = new mongo_1.default(this._instanceState, uri, fleOptions, otherOptions);
|
|
138
|
-
await mongo.connect();
|
|
139
|
-
this._instanceState.mongos.push(mongo);
|
|
140
|
-
return mongo;
|
|
141
|
-
}
|
|
142
|
-
async connect(uri, user, pwd) {
|
|
143
|
-
(0, helpers_1.assertArgsDefinedType)([uri, user, pwd], ['string', [undefined, 'string'], [undefined, 'string']], 'connect');
|
|
144
|
-
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
|
|
145
|
-
const mongo = new mongo_1.default(this._instanceState, uri);
|
|
146
|
-
await mongo.connect(user, pwd);
|
|
147
|
-
this._instanceState.mongos.push(mongo);
|
|
148
|
-
const db = mongo._serviceProvider.initialDb || service_provider_core_1.DEFAULT_DB;
|
|
149
|
-
return mongo.getDB(db);
|
|
150
|
-
}
|
|
151
|
-
async it() {
|
|
152
|
-
if (!this._instanceState.currentCursor) {
|
|
153
|
-
return new result_1.CursorIterationResult();
|
|
154
|
-
}
|
|
155
|
-
return await this._instanceState.currentCursor._it();
|
|
156
|
-
}
|
|
157
|
-
version() {
|
|
158
|
-
const version = require('../package.json').version;
|
|
159
|
-
return version;
|
|
160
|
-
}
|
|
161
|
-
async load(filename) {
|
|
162
|
-
(0, helpers_1.assertArgsDefinedType)([filename], ['string'], 'load');
|
|
163
|
-
if (!this._instanceState.evaluationListener.onLoad) {
|
|
164
|
-
throw new errors_1.MongoshUnimplementedError('load is not currently implemented for this platform', errors_1.CommonErrors.NotImplemented);
|
|
165
|
-
}
|
|
166
|
-
this._instanceState.messageBus.emit('mongosh:api-load-file', {
|
|
167
|
-
nested: this.loadCallNestingLevel > 0,
|
|
168
|
-
filename
|
|
169
|
-
});
|
|
170
|
-
const { resolvedFilename, evaluate } = await this._instanceState.evaluationListener.onLoad(filename);
|
|
171
|
-
const context = this._instanceState.context;
|
|
172
|
-
const previousFilename = context.__filename;
|
|
173
|
-
context.__filename = resolvedFilename;
|
|
174
|
-
context.__dirname = (0, path_1.dirname)(resolvedFilename);
|
|
175
|
-
this.loadCallNestingLevel++;
|
|
176
|
-
try {
|
|
177
|
-
await evaluate();
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
this.loadCallNestingLevel--;
|
|
181
|
-
if (previousFilename) {
|
|
182
|
-
context.__filename = previousFilename;
|
|
183
|
-
context.__dirname = (0, path_1.dirname)(previousFilename);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
delete context.__filename;
|
|
187
|
-
delete context.__dirname;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
async enableTelemetry() {
|
|
193
|
-
var _a, _b;
|
|
194
|
-
const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', true));
|
|
195
|
-
if (result === 'success') {
|
|
196
|
-
return i18n_1.default.__('cli-repl.cli-repl.enabledTelemetry');
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async disableTelemetry() {
|
|
200
|
-
var _a, _b;
|
|
201
|
-
const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', false));
|
|
202
|
-
if (result === 'success') {
|
|
203
|
-
return i18n_1.default.__('cli-repl.cli-repl.disabledTelemetry');
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
async passwordPrompt() {
|
|
207
|
-
const { evaluationListener } = this._instanceState;
|
|
208
|
-
if (!evaluationListener.onPrompt) {
|
|
209
|
-
throw new errors_1.MongoshUnimplementedError('passwordPrompt() is not available in this shell', errors_1.CommonErrors.NotImplemented);
|
|
210
|
-
}
|
|
211
|
-
return await evaluationListener.onPrompt('Enter password', 'password');
|
|
212
|
-
}
|
|
213
|
-
async sleep(ms) {
|
|
214
|
-
return await (0, util_1.promisify)(setTimeout)(ms);
|
|
215
|
-
}
|
|
216
|
-
async print(...origArgs) {
|
|
217
|
-
var _a;
|
|
218
|
-
const { evaluationListener } = this._instanceState;
|
|
219
|
-
const args = await Promise.all(origArgs.map(arg => (0, decorators_1.toShellResult)(arg)));
|
|
220
|
-
await ((_a = evaluationListener.onPrint) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, args));
|
|
221
|
-
}
|
|
222
|
-
async printjson(...origArgs) {
|
|
223
|
-
return this.print(...origArgs);
|
|
224
|
-
}
|
|
225
|
-
async cls() {
|
|
226
|
-
var _a;
|
|
227
|
-
const { evaluationListener } = this._instanceState;
|
|
228
|
-
await ((_a = evaluationListener.onClearCommand) === null || _a === void 0 ? void 0 : _a.call(evaluationListener));
|
|
229
|
-
}
|
|
230
|
-
isInteractive() {
|
|
231
|
-
return this._instanceState.isInteractive;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
__decorate([
|
|
235
|
-
decorators_1.directShellCommand,
|
|
236
|
-
(0, decorators_1.shellCommandCompleter)(useCompleter)
|
|
237
|
-
], ShellApi.prototype, "use", null);
|
|
238
|
-
__decorate([
|
|
239
|
-
decorators_1.directShellCommand,
|
|
240
|
-
decorators_1.returnsPromise,
|
|
241
|
-
(0, decorators_1.shellCommandCompleter)(showCompleter)
|
|
242
|
-
], ShellApi.prototype, "show", null);
|
|
243
|
-
__decorate([
|
|
244
|
-
decorators_1.directShellCommand,
|
|
245
|
-
decorators_1.returnsPromise,
|
|
246
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
247
|
-
], ShellApi.prototype, "exit", null);
|
|
248
|
-
__decorate([
|
|
249
|
-
decorators_1.directShellCommand,
|
|
250
|
-
decorators_1.returnsPromise,
|
|
251
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
252
|
-
], ShellApi.prototype, "quit", null);
|
|
253
|
-
__decorate([
|
|
254
|
-
decorators_1.returnsPromise,
|
|
255
|
-
(0, decorators_1.returnType)('Mongo'),
|
|
256
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
257
|
-
], ShellApi.prototype, "Mongo", null);
|
|
258
|
-
__decorate([
|
|
259
|
-
decorators_1.returnsPromise,
|
|
260
|
-
(0, decorators_1.returnType)('Database'),
|
|
261
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
262
|
-
], ShellApi.prototype, "connect", null);
|
|
263
|
-
__decorate([
|
|
264
|
-
decorators_1.directShellCommand,
|
|
265
|
-
decorators_1.returnsPromise
|
|
266
|
-
], ShellApi.prototype, "it", null);
|
|
267
|
-
__decorate([
|
|
268
|
-
decorators_1.returnsPromise
|
|
269
|
-
], ShellApi.prototype, "load", null);
|
|
270
|
-
__decorate([
|
|
271
|
-
decorators_1.returnsPromise,
|
|
272
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
273
|
-
], ShellApi.prototype, "enableTelemetry", null);
|
|
274
|
-
__decorate([
|
|
275
|
-
decorators_1.returnsPromise,
|
|
276
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
277
|
-
], ShellApi.prototype, "disableTelemetry", null);
|
|
278
|
-
__decorate([
|
|
279
|
-
decorators_1.returnsPromise,
|
|
280
|
-
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
281
|
-
], ShellApi.prototype, "passwordPrompt", null);
|
|
282
|
-
__decorate([
|
|
283
|
-
decorators_1.returnsPromise
|
|
284
|
-
], ShellApi.prototype, "sleep", null);
|
|
285
|
-
__decorate([
|
|
286
|
-
decorators_1.returnsPromise
|
|
287
|
-
], ShellApi.prototype, "print", null);
|
|
288
|
-
__decorate([
|
|
289
|
-
decorators_1.returnsPromise
|
|
290
|
-
], ShellApi.prototype, "printjson", null);
|
|
291
|
-
__decorate([
|
|
292
|
-
decorators_1.directShellCommand,
|
|
293
|
-
decorators_1.returnsPromise
|
|
294
|
-
], ShellApi.prototype, "cls", null);
|
|
295
|
-
ShellApi = __decorate([
|
|
296
|
-
decorators_1.shellApiClassDefault
|
|
297
|
-
], ShellApi);
|
|
298
|
-
exports.default = ShellApi;
|
|
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;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const decorators_1 = require("./decorators");
|
|
13
|
+
const enums_1 = require("./enums");
|
|
14
|
+
const mongo_1 = __importDefault(require("./mongo"));
|
|
15
|
+
const result_1 = require("./result");
|
|
16
|
+
const helpers_1 = require("./helpers");
|
|
17
|
+
const service_provider_core_1 = require("@qp-mongosh/service-provider-core");
|
|
18
|
+
const errors_1 = require("@qp-mongosh/errors");
|
|
19
|
+
const dbquery_1 = require("./dbquery");
|
|
20
|
+
const util_1 = require("util");
|
|
21
|
+
const path_1 = require("path");
|
|
22
|
+
const types_1 = require("@qp-mongosh/types");
|
|
23
|
+
const i18n_1 = __importDefault(require("@qp-mongosh/i18n"));
|
|
24
|
+
const instanceStateSymbol = Symbol.for('@@mongosh.instanceState');
|
|
25
|
+
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}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
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`;
|
|
46
|
+
}
|
|
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`;
|
|
62
|
+
}
|
|
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);
|
|
86
|
+
async function useCompleter(params, args) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (args.length > 2)
|
|
89
|
+
return undefined;
|
|
90
|
+
return await params.getDatabaseCompletions((_a = args[1]) !== null && _a !== void 0 ? _a : '');
|
|
91
|
+
}
|
|
92
|
+
async function showCompleter(params, args) {
|
|
93
|
+
if (args.length > 2)
|
|
94
|
+
return undefined;
|
|
95
|
+
if (args[1] === 'd') {
|
|
96
|
+
return ['databases'];
|
|
97
|
+
}
|
|
98
|
+
const candidates = ['databases', 'dbs', 'collections', 'tables', 'profile', 'users', 'roles', 'log', 'logs'];
|
|
99
|
+
return candidates.filter(str => { var _a; return str.startsWith((_a = args[1]) !== null && _a !== void 0 ? _a : ''); });
|
|
100
|
+
}
|
|
101
|
+
let ShellApi = class ShellApi extends decorators_1.ShellApiClass {
|
|
102
|
+
constructor(instanceState) {
|
|
103
|
+
super();
|
|
104
|
+
this[instanceStateSymbol] = instanceState;
|
|
105
|
+
this[loadCallNestingLevelSymbol] = 0;
|
|
106
|
+
this.DBQuery = new dbquery_1.DBQuery(instanceState);
|
|
107
|
+
this.config = new ShellConfig(instanceState);
|
|
108
|
+
}
|
|
109
|
+
get _instanceState() {
|
|
110
|
+
return this[instanceStateSymbol];
|
|
111
|
+
}
|
|
112
|
+
get loadCallNestingLevel() {
|
|
113
|
+
return this[loadCallNestingLevelSymbol];
|
|
114
|
+
}
|
|
115
|
+
set loadCallNestingLevel(value) {
|
|
116
|
+
this[loadCallNestingLevelSymbol] = value;
|
|
117
|
+
}
|
|
118
|
+
use(db) {
|
|
119
|
+
return this._instanceState.currentDb._mongo.use(db);
|
|
120
|
+
}
|
|
121
|
+
async show(cmd, arg) {
|
|
122
|
+
return await this._instanceState.currentDb._mongo.show(cmd, arg);
|
|
123
|
+
}
|
|
124
|
+
async exit(exitCode) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
(0, helpers_1.assertArgsDefinedType)([exitCode], [[undefined, 'number']], 'exit');
|
|
127
|
+
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'the exit/quit commands');
|
|
128
|
+
await this._instanceState.close(true);
|
|
129
|
+
await ((_b = (_a = this._instanceState.evaluationListener).onExit) === null || _b === void 0 ? void 0 : _b.call(_a, exitCode));
|
|
130
|
+
throw new errors_1.MongoshInternalError('.onExit listener returned');
|
|
131
|
+
}
|
|
132
|
+
async quit(exitCode) {
|
|
133
|
+
return await this.exit(exitCode);
|
|
134
|
+
}
|
|
135
|
+
async Mongo(uri, fleOptions, otherOptions) {
|
|
136
|
+
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
|
|
137
|
+
const mongo = new mongo_1.default(this._instanceState, uri, fleOptions, otherOptions);
|
|
138
|
+
await mongo.connect();
|
|
139
|
+
this._instanceState.mongos.push(mongo);
|
|
140
|
+
return mongo;
|
|
141
|
+
}
|
|
142
|
+
async connect(uri, user, pwd) {
|
|
143
|
+
(0, helpers_1.assertArgsDefinedType)([uri, user, pwd], ['string', [undefined, 'string'], [undefined, 'string']], 'connect');
|
|
144
|
+
(0, helpers_1.assertCLI)(this._instanceState.initialServiceProvider.platform, 'new Mongo connections');
|
|
145
|
+
const mongo = new mongo_1.default(this._instanceState, uri);
|
|
146
|
+
await mongo.connect(user, pwd);
|
|
147
|
+
this._instanceState.mongos.push(mongo);
|
|
148
|
+
const db = mongo._serviceProvider.initialDb || service_provider_core_1.DEFAULT_DB;
|
|
149
|
+
return mongo.getDB(db);
|
|
150
|
+
}
|
|
151
|
+
async it() {
|
|
152
|
+
if (!this._instanceState.currentCursor) {
|
|
153
|
+
return new result_1.CursorIterationResult();
|
|
154
|
+
}
|
|
155
|
+
return await this._instanceState.currentCursor._it();
|
|
156
|
+
}
|
|
157
|
+
version() {
|
|
158
|
+
const version = require('../package.json').version;
|
|
159
|
+
return version;
|
|
160
|
+
}
|
|
161
|
+
async load(filename) {
|
|
162
|
+
(0, helpers_1.assertArgsDefinedType)([filename], ['string'], 'load');
|
|
163
|
+
if (!this._instanceState.evaluationListener.onLoad) {
|
|
164
|
+
throw new errors_1.MongoshUnimplementedError('load is not currently implemented for this platform', errors_1.CommonErrors.NotImplemented);
|
|
165
|
+
}
|
|
166
|
+
this._instanceState.messageBus.emit('mongosh:api-load-file', {
|
|
167
|
+
nested: this.loadCallNestingLevel > 0,
|
|
168
|
+
filename
|
|
169
|
+
});
|
|
170
|
+
const { resolvedFilename, evaluate } = await this._instanceState.evaluationListener.onLoad(filename);
|
|
171
|
+
const context = this._instanceState.context;
|
|
172
|
+
const previousFilename = context.__filename;
|
|
173
|
+
context.__filename = resolvedFilename;
|
|
174
|
+
context.__dirname = (0, path_1.dirname)(resolvedFilename);
|
|
175
|
+
this.loadCallNestingLevel++;
|
|
176
|
+
try {
|
|
177
|
+
await evaluate();
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
this.loadCallNestingLevel--;
|
|
181
|
+
if (previousFilename) {
|
|
182
|
+
context.__filename = previousFilename;
|
|
183
|
+
context.__dirname = (0, path_1.dirname)(previousFilename);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
delete context.__filename;
|
|
187
|
+
delete context.__dirname;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
async enableTelemetry() {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', true));
|
|
195
|
+
if (result === 'success') {
|
|
196
|
+
return i18n_1.default.__('cli-repl.cli-repl.enabledTelemetry');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async disableTelemetry() {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
const result = await ((_b = (_a = this._instanceState.evaluationListener).setConfig) === null || _b === void 0 ? void 0 : _b.call(_a, 'enableTelemetry', false));
|
|
202
|
+
if (result === 'success') {
|
|
203
|
+
return i18n_1.default.__('cli-repl.cli-repl.disabledTelemetry');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async passwordPrompt() {
|
|
207
|
+
const { evaluationListener } = this._instanceState;
|
|
208
|
+
if (!evaluationListener.onPrompt) {
|
|
209
|
+
throw new errors_1.MongoshUnimplementedError('passwordPrompt() is not available in this shell', errors_1.CommonErrors.NotImplemented);
|
|
210
|
+
}
|
|
211
|
+
return await evaluationListener.onPrompt('Enter password', 'password');
|
|
212
|
+
}
|
|
213
|
+
async sleep(ms) {
|
|
214
|
+
return await (0, util_1.promisify)(setTimeout)(ms);
|
|
215
|
+
}
|
|
216
|
+
async print(...origArgs) {
|
|
217
|
+
var _a;
|
|
218
|
+
const { evaluationListener } = this._instanceState;
|
|
219
|
+
const args = await Promise.all(origArgs.map(arg => (0, decorators_1.toShellResult)(arg)));
|
|
220
|
+
await ((_a = evaluationListener.onPrint) === null || _a === void 0 ? void 0 : _a.call(evaluationListener, args));
|
|
221
|
+
}
|
|
222
|
+
async printjson(...origArgs) {
|
|
223
|
+
return this.print(...origArgs);
|
|
224
|
+
}
|
|
225
|
+
async cls() {
|
|
226
|
+
var _a;
|
|
227
|
+
const { evaluationListener } = this._instanceState;
|
|
228
|
+
await ((_a = evaluationListener.onClearCommand) === null || _a === void 0 ? void 0 : _a.call(evaluationListener));
|
|
229
|
+
}
|
|
230
|
+
isInteractive() {
|
|
231
|
+
return this._instanceState.isInteractive;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
__decorate([
|
|
235
|
+
decorators_1.directShellCommand,
|
|
236
|
+
(0, decorators_1.shellCommandCompleter)(useCompleter)
|
|
237
|
+
], ShellApi.prototype, "use", null);
|
|
238
|
+
__decorate([
|
|
239
|
+
decorators_1.directShellCommand,
|
|
240
|
+
decorators_1.returnsPromise,
|
|
241
|
+
(0, decorators_1.shellCommandCompleter)(showCompleter)
|
|
242
|
+
], ShellApi.prototype, "show", null);
|
|
243
|
+
__decorate([
|
|
244
|
+
decorators_1.directShellCommand,
|
|
245
|
+
decorators_1.returnsPromise,
|
|
246
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
247
|
+
], ShellApi.prototype, "exit", null);
|
|
248
|
+
__decorate([
|
|
249
|
+
decorators_1.directShellCommand,
|
|
250
|
+
decorators_1.returnsPromise,
|
|
251
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
252
|
+
], ShellApi.prototype, "quit", null);
|
|
253
|
+
__decorate([
|
|
254
|
+
decorators_1.returnsPromise,
|
|
255
|
+
(0, decorators_1.returnType)('Mongo'),
|
|
256
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
257
|
+
], ShellApi.prototype, "Mongo", null);
|
|
258
|
+
__decorate([
|
|
259
|
+
decorators_1.returnsPromise,
|
|
260
|
+
(0, decorators_1.returnType)('Database'),
|
|
261
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
262
|
+
], ShellApi.prototype, "connect", null);
|
|
263
|
+
__decorate([
|
|
264
|
+
decorators_1.directShellCommand,
|
|
265
|
+
decorators_1.returnsPromise
|
|
266
|
+
], ShellApi.prototype, "it", null);
|
|
267
|
+
__decorate([
|
|
268
|
+
decorators_1.returnsPromise
|
|
269
|
+
], ShellApi.prototype, "load", null);
|
|
270
|
+
__decorate([
|
|
271
|
+
decorators_1.returnsPromise,
|
|
272
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
273
|
+
], ShellApi.prototype, "enableTelemetry", null);
|
|
274
|
+
__decorate([
|
|
275
|
+
decorators_1.returnsPromise,
|
|
276
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
277
|
+
], ShellApi.prototype, "disableTelemetry", null);
|
|
278
|
+
__decorate([
|
|
279
|
+
decorators_1.returnsPromise,
|
|
280
|
+
(0, decorators_1.platforms)([service_provider_core_1.ReplPlatform.CLI])
|
|
281
|
+
], ShellApi.prototype, "passwordPrompt", null);
|
|
282
|
+
__decorate([
|
|
283
|
+
decorators_1.returnsPromise
|
|
284
|
+
], ShellApi.prototype, "sleep", null);
|
|
285
|
+
__decorate([
|
|
286
|
+
decorators_1.returnsPromise
|
|
287
|
+
], ShellApi.prototype, "print", null);
|
|
288
|
+
__decorate([
|
|
289
|
+
decorators_1.returnsPromise
|
|
290
|
+
], ShellApi.prototype, "printjson", null);
|
|
291
|
+
__decorate([
|
|
292
|
+
decorators_1.directShellCommand,
|
|
293
|
+
decorators_1.returnsPromise
|
|
294
|
+
], ShellApi.prototype, "cls", null);
|
|
295
|
+
ShellApi = __decorate([
|
|
296
|
+
decorators_1.shellApiClassDefault
|
|
297
|
+
], ShellApi);
|
|
298
|
+
exports.default = ShellApi;
|
|
299
299
|
//# sourceMappingURL=shell-api.js.map
|