@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.
Files changed (66) hide show
  1. package/.eslintignore +2 -2
  2. package/.eslintrc.js +1 -1
  3. package/AUTHORS +15 -15
  4. package/LICENSE +200 -200
  5. package/bin/report-missing-help.ts +24 -24
  6. package/bin/report-supported-api.ts +14 -14
  7. package/lib/abstract-cursor.d.ts +33 -33
  8. package/lib/abstract-cursor.js +191 -191
  9. package/lib/aggregation-cursor.d.ts +6 -6
  10. package/lib/aggregation-cursor.js +19 -19
  11. package/lib/bulk.d.ts +43 -43
  12. package/lib/bulk.js +223 -223
  13. package/lib/change-stream-cursor.d.ts +28 -28
  14. package/lib/change-stream-cursor.js +111 -111
  15. package/lib/collection.d.ts +95 -95
  16. package/lib/collection.js +964 -964
  17. package/lib/cursor.d.ts +32 -32
  18. package/lib/cursor.js +215 -215
  19. package/lib/database.d.ts +116 -116
  20. package/lib/database.js +1223 -1223
  21. package/lib/dbquery.d.ts +8 -8
  22. package/lib/dbquery.js +28 -28
  23. package/lib/decorators.d.ts +73 -73
  24. package/lib/decorators.js +395 -395
  25. package/lib/enums.d.ts +28 -28
  26. package/lib/enums.js +33 -33
  27. package/lib/error-codes.d.ts +12 -12
  28. package/lib/error-codes.js +19 -19
  29. package/lib/explainable-cursor.d.ts +11 -11
  30. package/lib/explainable-cursor.js +31 -31
  31. package/lib/explainable.d.ts +32 -32
  32. package/lib/explainable.js +166 -166
  33. package/lib/field-level-encryption.d.ts +50 -50
  34. package/lib/field-level-encryption.js +176 -176
  35. package/lib/help.d.ts +22 -22
  36. package/lib/help.js +26 -26
  37. package/lib/helpers.d.ts +71 -71
  38. package/lib/helpers.js +588 -588
  39. package/lib/index.d.ts +16 -16
  40. package/lib/index.js +45 -45
  41. package/lib/interruptor.d.ts +19 -19
  42. package/lib/interruptor.js +62 -62
  43. package/lib/mongo-errors.d.ts +5 -5
  44. package/lib/mongo-errors.js +37 -37
  45. package/lib/mongo.d.ts +75 -75
  46. package/lib/mongo.js +476 -476
  47. package/lib/no-db.d.ts +5 -5
  48. package/lib/no-db.js +28 -28
  49. package/lib/plan-cache.d.ts +16 -16
  50. package/lib/plan-cache.js +70 -70
  51. package/lib/replica-set.d.ts +45 -45
  52. package/lib/replica-set.js +314 -314
  53. package/lib/result.d.ts +61 -61
  54. package/lib/result.js +104 -104
  55. package/lib/session.d.ts +25 -25
  56. package/lib/session.js +88 -88
  57. package/lib/shard.d.ts +42 -42
  58. package/lib/shard.js +414 -414
  59. package/lib/shell-api.d.ts +52 -52
  60. package/lib/shell-api.js +298 -298
  61. package/lib/shell-bson.d.ts +40 -40
  62. package/lib/shell-bson.js +159 -159
  63. package/lib/shell-instance-state.d.ts +77 -77
  64. package/lib/shell-instance-state.js +392 -392
  65. package/package.json +47 -47
  66. package/tsconfig.lint.json +8 -8
package/lib/shard.js CHANGED
@@ -1,415 +1,415 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const decorators_1 = require("./decorators");
10
- const helpers_1 = require("./helpers");
11
- const enums_1 = require("./enums");
12
- const result_1 = require("./result");
13
- const history_1 = require("@qp-mongosh/history");
14
- let Shard = class Shard extends decorators_1.ShellApiWithMongoClass {
15
- constructor(database) {
16
- super();
17
- this._database = database;
18
- }
19
- get _mongo() {
20
- return this._database._mongo;
21
- }
22
- [enums_1.asPrintable]() {
23
- return `Shard class connected to ${(0, history_1.redactURICredentials)(this._database._mongo._uri)} via db ${this._database._name}`;
24
- }
25
- _emitShardApiCall(methodName, methodArguments = {}) {
26
- this._database._mongo._instanceState.emitApiCallWithArgs({
27
- method: methodName,
28
- class: 'Shard',
29
- arguments: methodArguments
30
- });
31
- }
32
- async enableSharding(database, primaryShard) {
33
- (0, helpers_1.assertArgsDefinedType)([database, primaryShard], ['string', [undefined, 'string']], 'Shard.enableSharding');
34
- this._emitShardApiCall('enableSharding', { database, primaryShard });
35
- const cmd = {
36
- enableSharding: database
37
- };
38
- if (primaryShard !== undefined) {
39
- cmd.primaryShard = primaryShard;
40
- }
41
- try {
42
- return await this._database._runAdminCommand(cmd);
43
- }
44
- catch (error) {
45
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
46
- error.message = `${error.message}. Are you connected to mongos?`;
47
- }
48
- throw error;
49
- }
50
- }
51
- async commitReshardCollection(namespace) {
52
- (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.commitReshardCollection');
53
- this._emitShardApiCall('commitReshardCollection', { namespace });
54
- return await this._database._runAdminCommand({
55
- commitReshardCollection: namespace
56
- });
57
- }
58
- async abortReshardCollection(namespace) {
59
- (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.abortReshardCollection');
60
- this._emitShardApiCall('abortReshardCollection', { namespace });
61
- return await this._database._runAdminCommand({
62
- abortReshardCollection: namespace
63
- });
64
- }
65
- async shardCollection(namespace, key, unique, options) {
66
- return await this._runShardCollection('shardCollection', namespace, key, unique, options);
67
- }
68
- async reshardCollection(namespace, key, unique, options) {
69
- return await this._runShardCollection('reshardCollection', namespace, key, unique, options);
70
- }
71
- async _runShardCollection(command, namespace, key, unique, options) {
72
- (0, helpers_1.assertArgsDefinedType)([namespace, key, unique, options], ['string', 'object', [undefined, 'boolean', 'object'], [undefined, 'object']], `Shard.${command}`);
73
- this._emitShardApiCall(command, { namespace, key, unique, options });
74
- if (typeof unique === 'object' && unique !== null) {
75
- options = unique;
76
- unique = undefined;
77
- }
78
- const cmd = {
79
- [command]: namespace,
80
- key: key
81
- };
82
- if (unique !== undefined) {
83
- cmd.unique = unique;
84
- }
85
- try {
86
- return await this._database._runAdminCommand({ ...cmd, ...options });
87
- }
88
- catch (error) {
89
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
90
- error.message = `${error.message}. Are you connected to mongos?`;
91
- }
92
- throw error;
93
- }
94
- }
95
- async status(verbose = false, configDB) {
96
- const result = await (0, helpers_1.getPrintableShardStatus)(configDB !== null && configDB !== void 0 ? configDB : await (0, helpers_1.getConfigDB)(this._database), verbose);
97
- return new result_1.CommandResult('StatsResult', result);
98
- }
99
- async addShard(url) {
100
- (0, helpers_1.assertArgsDefinedType)([url], ['string'], 'Shard.addShard');
101
- await (0, helpers_1.getConfigDB)(this._database);
102
- this._emitShardApiCall('addShard', { url });
103
- return this._database._runAdminCommand({
104
- addShard: url
105
- });
106
- }
107
- async addShardToZone(shard, zone) {
108
- (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.addShardToZone');
109
- this._emitShardApiCall('addShardToZone', { shard, zone });
110
- await (0, helpers_1.getConfigDB)(this._database);
111
- return this._database._runAdminCommand({
112
- addShardToZone: shard,
113
- zone: zone
114
- });
115
- }
116
- async addShardTag(shard, tag) {
117
- (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.addShardTag');
118
- this._emitShardApiCall('addShardTag', { shard, tag });
119
- try {
120
- return await this.addShardToZone(shard, tag);
121
- }
122
- catch (error) {
123
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
124
- error.message = `${error.message}. This method aliases to addShardToZone which exists only for server versions > 3.4.`;
125
- }
126
- throw error;
127
- }
128
- }
129
- async updateZoneKeyRange(namespace, min, max, zone) {
130
- (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.updateZoneKeyRange');
131
- this._emitShardApiCall('updateZoneKeyRange', { namespace, min, max, zone });
132
- await (0, helpers_1.getConfigDB)(this._database);
133
- return await this._database._runAdminCommand({
134
- updateZoneKeyRange: namespace,
135
- min,
136
- max,
137
- zone
138
- });
139
- }
140
- async addTagRange(namespace, min, max, zone) {
141
- (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.addTagRange');
142
- this._emitShardApiCall('addTagRange', { namespace, min, max, zone });
143
- try {
144
- return await this.updateZoneKeyRange(namespace, min, max, zone);
145
- }
146
- catch (error) {
147
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
148
- error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
149
- }
150
- throw error;
151
- }
152
- }
153
- async removeRangeFromZone(ns, min, max) {
154
- (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeRangeFromZone');
155
- this._emitShardApiCall('removeRangeFromZone', { ns, min, max });
156
- return this.updateZoneKeyRange(ns, min, max, null);
157
- }
158
- async removeTagRange(ns, min, max) {
159
- (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeTagRange');
160
- this._emitShardApiCall('removeTagRange', { ns, min, max });
161
- try {
162
- return await this.updateZoneKeyRange(ns, min, max, null);
163
- }
164
- catch (error) {
165
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
166
- error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
167
- }
168
- throw error;
169
- }
170
- }
171
- async removeShardFromZone(shard, zone) {
172
- (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.removeShardFromZone');
173
- this._emitShardApiCall('removeShardFromZone', { shard, zone });
174
- await (0, helpers_1.getConfigDB)(this._database);
175
- return await this._database._runAdminCommand({
176
- removeShardFromZone: shard,
177
- zone: zone
178
- });
179
- }
180
- async removeShardTag(shard, tag) {
181
- (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.removeShardTag');
182
- this._emitShardApiCall('removeTagRange', { shard, tag });
183
- try {
184
- return await this.removeShardFromZone(shard, tag);
185
- }
186
- catch (error) {
187
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
188
- error.message = `${error.message}. This method aliases to removeShardFromZone which exists only for server versions > 3.4.`;
189
- }
190
- throw error;
191
- }
192
- }
193
- async enableAutoSplit() {
194
- this._emitShardApiCall('enableAutoSplit', {});
195
- const config = await (0, helpers_1.getConfigDB)(this._database);
196
- return await config.getCollection('settings').updateOne({ _id: 'autosplit' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } });
197
- }
198
- async disableAutoSplit() {
199
- this._emitShardApiCall('disableAutoSplit', {});
200
- const config = await (0, helpers_1.getConfigDB)(this._database);
201
- return await config.getCollection('settings').updateOne({ _id: 'autosplit' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } });
202
- }
203
- async splitAt(ns, query) {
204
- (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitAt');
205
- this._emitShardApiCall('splitAt', { ns, query });
206
- return this._database._runAdminCommand({
207
- split: ns,
208
- middle: query
209
- });
210
- }
211
- async splitFind(ns, query) {
212
- (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitFind');
213
- this._emitShardApiCall('splitFind', { ns, query });
214
- return this._database._runAdminCommand({
215
- split: ns,
216
- find: query
217
- });
218
- }
219
- async moveChunk(ns, query, destination) {
220
- (0, helpers_1.assertArgsDefinedType)([ns, query, destination], ['string', 'object', 'string'], 'Shard.moveChunk');
221
- this._emitShardApiCall('moveChunk', { ns, query, destination });
222
- return this._database._runAdminCommand({
223
- moveChunk: ns,
224
- find: query,
225
- to: destination
226
- });
227
- }
228
- async balancerCollectionStatus(ns) {
229
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.balancerCollectionStatus');
230
- this._emitShardApiCall('balancerCollectionStatus', { ns });
231
- return this._database._runAdminCommand({
232
- balancerCollectionStatus: ns
233
- });
234
- }
235
- async enableBalancing(ns) {
236
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableBalancing');
237
- this._emitShardApiCall('enableBalancing', { ns });
238
- const config = await (0, helpers_1.getConfigDB)(this._database);
239
- return await config.getCollection('collections').updateOne({ _id: ns }, { $set: { 'noBalance': false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } });
240
- }
241
- async disableBalancing(ns) {
242
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableBalancing');
243
- this._emitShardApiCall('disableBalancing', { ns });
244
- const config = await (0, helpers_1.getConfigDB)(this._database);
245
- return await config.getCollection('collections').updateOne({ _id: ns }, { $set: { 'noBalance': true } }, { writeConcern: { w: 'majority', wtimeout: 60000 } });
246
- }
247
- async getBalancerState() {
248
- this._emitShardApiCall('getBalancerState', {});
249
- const config = await (0, helpers_1.getConfigDB)(this._database);
250
- const doc = await config.getCollection('settings').findOne({ _id: 'balancer' });
251
- if (doc === null || doc === undefined) {
252
- return true;
253
- }
254
- return !doc.stopped;
255
- }
256
- async isBalancerRunning() {
257
- this._emitShardApiCall('isBalancerRunning', {});
258
- await (0, helpers_1.getConfigDB)(this._database);
259
- return this._database._runAdminCommand({
260
- balancerStatus: 1
261
- });
262
- }
263
- async startBalancer(timeout = 60000) {
264
- (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.startBalancer');
265
- this._emitShardApiCall('startBalancer', { timeout });
266
- return this._database._runAdminCommand({
267
- balancerStart: 1, maxTimeMS: timeout
268
- });
269
- }
270
- async stopBalancer(timeout = 60000) {
271
- (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.stopBalancer');
272
- this._emitShardApiCall('stopBalancer', { timeout });
273
- return this._database._runAdminCommand({
274
- balancerStop: 1, maxTimeMS: timeout
275
- });
276
- }
277
- async setBalancerState(state) {
278
- (0, helpers_1.assertArgsDefinedType)([state], ['boolean'], 'Shard.setBalancerState');
279
- this._emitShardApiCall('setBalancerState', { state });
280
- if (state) {
281
- return this.startBalancer();
282
- }
283
- return this.stopBalancer();
284
- }
285
- };
286
- __decorate([
287
- decorators_1.returnsPromise,
288
- (0, decorators_1.apiVersions)([])
289
- ], Shard.prototype, "enableSharding", null);
290
- __decorate([
291
- decorators_1.returnsPromise,
292
- (0, decorators_1.apiVersions)([]),
293
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
294
- ], Shard.prototype, "commitReshardCollection", null);
295
- __decorate([
296
- decorators_1.returnsPromise,
297
- (0, decorators_1.apiVersions)([]),
298
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
299
- ], Shard.prototype, "abortReshardCollection", null);
300
- __decorate([
301
- decorators_1.returnsPromise,
302
- (0, decorators_1.apiVersions)([])
303
- ], Shard.prototype, "shardCollection", null);
304
- __decorate([
305
- decorators_1.returnsPromise,
306
- (0, decorators_1.apiVersions)([]),
307
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
308
- ], Shard.prototype, "reshardCollection", null);
309
- __decorate([
310
- decorators_1.returnsPromise,
311
- (0, decorators_1.apiVersions)([1])
312
- ], Shard.prototype, "status", null);
313
- __decorate([
314
- decorators_1.returnsPromise,
315
- (0, decorators_1.apiVersions)([])
316
- ], Shard.prototype, "addShard", null);
317
- __decorate([
318
- decorators_1.returnsPromise,
319
- (0, decorators_1.apiVersions)([]),
320
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
321
- ], Shard.prototype, "addShardToZone", null);
322
- __decorate([
323
- decorators_1.returnsPromise,
324
- (0, decorators_1.apiVersions)([]),
325
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
326
- ], Shard.prototype, "addShardTag", null);
327
- __decorate([
328
- decorators_1.returnsPromise,
329
- (0, decorators_1.apiVersions)([])
330
- ], Shard.prototype, "updateZoneKeyRange", null);
331
- __decorate([
332
- decorators_1.returnsPromise,
333
- (0, decorators_1.apiVersions)([]),
334
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
335
- ], Shard.prototype, "addTagRange", null);
336
- __decorate([
337
- decorators_1.returnsPromise,
338
- (0, decorators_1.apiVersions)([]),
339
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
340
- ], Shard.prototype, "removeRangeFromZone", null);
341
- __decorate([
342
- decorators_1.returnsPromise,
343
- (0, decorators_1.apiVersions)([]),
344
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
345
- ], Shard.prototype, "removeTagRange", null);
346
- __decorate([
347
- decorators_1.returnsPromise,
348
- (0, decorators_1.apiVersions)([]),
349
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
350
- ], Shard.prototype, "removeShardFromZone", null);
351
- __decorate([
352
- decorators_1.returnsPromise,
353
- (0, decorators_1.apiVersions)([]),
354
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
355
- ], Shard.prototype, "removeShardTag", null);
356
- __decorate([
357
- decorators_1.returnsPromise,
358
- (0, decorators_1.apiVersions)([1]),
359
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
360
- ], Shard.prototype, "enableAutoSplit", null);
361
- __decorate([
362
- decorators_1.returnsPromise,
363
- (0, decorators_1.apiVersions)([1]),
364
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
365
- ], Shard.prototype, "disableAutoSplit", null);
366
- __decorate([
367
- decorators_1.returnsPromise,
368
- (0, decorators_1.apiVersions)([])
369
- ], Shard.prototype, "splitAt", null);
370
- __decorate([
371
- decorators_1.returnsPromise,
372
- (0, decorators_1.apiVersions)([])
373
- ], Shard.prototype, "splitFind", null);
374
- __decorate([
375
- decorators_1.returnsPromise,
376
- (0, decorators_1.apiVersions)([])
377
- ], Shard.prototype, "moveChunk", null);
378
- __decorate([
379
- decorators_1.returnsPromise,
380
- (0, decorators_1.apiVersions)([]),
381
- (0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest])
382
- ], Shard.prototype, "balancerCollectionStatus", null);
383
- __decorate([
384
- decorators_1.returnsPromise,
385
- (0, decorators_1.apiVersions)([])
386
- ], Shard.prototype, "enableBalancing", null);
387
- __decorate([
388
- decorators_1.returnsPromise,
389
- (0, decorators_1.apiVersions)([])
390
- ], Shard.prototype, "disableBalancing", null);
391
- __decorate([
392
- decorators_1.returnsPromise,
393
- (0, decorators_1.apiVersions)([])
394
- ], Shard.prototype, "getBalancerState", null);
395
- __decorate([
396
- decorators_1.returnsPromise,
397
- (0, decorators_1.apiVersions)([])
398
- ], Shard.prototype, "isBalancerRunning", null);
399
- __decorate([
400
- decorators_1.returnsPromise,
401
- (0, decorators_1.apiVersions)([])
402
- ], Shard.prototype, "startBalancer", null);
403
- __decorate([
404
- decorators_1.returnsPromise,
405
- (0, decorators_1.apiVersions)([])
406
- ], Shard.prototype, "stopBalancer", null);
407
- __decorate([
408
- decorators_1.returnsPromise,
409
- (0, decorators_1.apiVersions)([])
410
- ], Shard.prototype, "setBalancerState", null);
411
- Shard = __decorate([
412
- decorators_1.shellApiClassDefault
413
- ], Shard);
414
- exports.default = Shard;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const decorators_1 = require("./decorators");
10
+ const helpers_1 = require("./helpers");
11
+ const enums_1 = require("./enums");
12
+ const result_1 = require("./result");
13
+ const history_1 = require("@qp-mongosh/history");
14
+ let Shard = class Shard extends decorators_1.ShellApiWithMongoClass {
15
+ constructor(database) {
16
+ super();
17
+ this._database = database;
18
+ }
19
+ get _mongo() {
20
+ return this._database._mongo;
21
+ }
22
+ [enums_1.asPrintable]() {
23
+ return `Shard class connected to ${(0, history_1.redactURICredentials)(this._database._mongo._uri)} via db ${this._database._name}`;
24
+ }
25
+ _emitShardApiCall(methodName, methodArguments = {}) {
26
+ this._database._mongo._instanceState.emitApiCallWithArgs({
27
+ method: methodName,
28
+ class: 'Shard',
29
+ arguments: methodArguments
30
+ });
31
+ }
32
+ async enableSharding(database, primaryShard) {
33
+ (0, helpers_1.assertArgsDefinedType)([database, primaryShard], ['string', [undefined, 'string']], 'Shard.enableSharding');
34
+ this._emitShardApiCall('enableSharding', { database, primaryShard });
35
+ const cmd = {
36
+ enableSharding: database
37
+ };
38
+ if (primaryShard !== undefined) {
39
+ cmd.primaryShard = primaryShard;
40
+ }
41
+ try {
42
+ return await this._database._runAdminCommand(cmd);
43
+ }
44
+ catch (error) {
45
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
46
+ error.message = `${error.message}. Are you connected to mongos?`;
47
+ }
48
+ throw error;
49
+ }
50
+ }
51
+ async commitReshardCollection(namespace) {
52
+ (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.commitReshardCollection');
53
+ this._emitShardApiCall('commitReshardCollection', { namespace });
54
+ return await this._database._runAdminCommand({
55
+ commitReshardCollection: namespace
56
+ });
57
+ }
58
+ async abortReshardCollection(namespace) {
59
+ (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.abortReshardCollection');
60
+ this._emitShardApiCall('abortReshardCollection', { namespace });
61
+ return await this._database._runAdminCommand({
62
+ abortReshardCollection: namespace
63
+ });
64
+ }
65
+ async shardCollection(namespace, key, unique, options) {
66
+ return await this._runShardCollection('shardCollection', namespace, key, unique, options);
67
+ }
68
+ async reshardCollection(namespace, key, unique, options) {
69
+ return await this._runShardCollection('reshardCollection', namespace, key, unique, options);
70
+ }
71
+ async _runShardCollection(command, namespace, key, unique, options) {
72
+ (0, helpers_1.assertArgsDefinedType)([namespace, key, unique, options], ['string', 'object', [undefined, 'boolean', 'object'], [undefined, 'object']], `Shard.${command}`);
73
+ this._emitShardApiCall(command, { namespace, key, unique, options });
74
+ if (typeof unique === 'object' && unique !== null) {
75
+ options = unique;
76
+ unique = undefined;
77
+ }
78
+ const cmd = {
79
+ [command]: namespace,
80
+ key: key
81
+ };
82
+ if (unique !== undefined) {
83
+ cmd.unique = unique;
84
+ }
85
+ try {
86
+ return await this._database._runAdminCommand({ ...cmd, ...options });
87
+ }
88
+ catch (error) {
89
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
90
+ error.message = `${error.message}. Are you connected to mongos?`;
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ async status(verbose = false, configDB) {
96
+ const result = await (0, helpers_1.getPrintableShardStatus)(configDB !== null && configDB !== void 0 ? configDB : await (0, helpers_1.getConfigDB)(this._database), verbose);
97
+ return new result_1.CommandResult('StatsResult', result);
98
+ }
99
+ async addShard(url) {
100
+ (0, helpers_1.assertArgsDefinedType)([url], ['string'], 'Shard.addShard');
101
+ await (0, helpers_1.getConfigDB)(this._database);
102
+ this._emitShardApiCall('addShard', { url });
103
+ return this._database._runAdminCommand({
104
+ addShard: url
105
+ });
106
+ }
107
+ async addShardToZone(shard, zone) {
108
+ (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.addShardToZone');
109
+ this._emitShardApiCall('addShardToZone', { shard, zone });
110
+ await (0, helpers_1.getConfigDB)(this._database);
111
+ return this._database._runAdminCommand({
112
+ addShardToZone: shard,
113
+ zone: zone
114
+ });
115
+ }
116
+ async addShardTag(shard, tag) {
117
+ (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.addShardTag');
118
+ this._emitShardApiCall('addShardTag', { shard, tag });
119
+ try {
120
+ return await this.addShardToZone(shard, tag);
121
+ }
122
+ catch (error) {
123
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
124
+ error.message = `${error.message}. This method aliases to addShardToZone which exists only for server versions > 3.4.`;
125
+ }
126
+ throw error;
127
+ }
128
+ }
129
+ async updateZoneKeyRange(namespace, min, max, zone) {
130
+ (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.updateZoneKeyRange');
131
+ this._emitShardApiCall('updateZoneKeyRange', { namespace, min, max, zone });
132
+ await (0, helpers_1.getConfigDB)(this._database);
133
+ return await this._database._runAdminCommand({
134
+ updateZoneKeyRange: namespace,
135
+ min,
136
+ max,
137
+ zone
138
+ });
139
+ }
140
+ async addTagRange(namespace, min, max, zone) {
141
+ (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.addTagRange');
142
+ this._emitShardApiCall('addTagRange', { namespace, min, max, zone });
143
+ try {
144
+ return await this.updateZoneKeyRange(namespace, min, max, zone);
145
+ }
146
+ catch (error) {
147
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
148
+ error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
149
+ }
150
+ throw error;
151
+ }
152
+ }
153
+ async removeRangeFromZone(ns, min, max) {
154
+ (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeRangeFromZone');
155
+ this._emitShardApiCall('removeRangeFromZone', { ns, min, max });
156
+ return this.updateZoneKeyRange(ns, min, max, null);
157
+ }
158
+ async removeTagRange(ns, min, max) {
159
+ (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeTagRange');
160
+ this._emitShardApiCall('removeTagRange', { ns, min, max });
161
+ try {
162
+ return await this.updateZoneKeyRange(ns, min, max, null);
163
+ }
164
+ catch (error) {
165
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
166
+ error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
167
+ }
168
+ throw error;
169
+ }
170
+ }
171
+ async removeShardFromZone(shard, zone) {
172
+ (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.removeShardFromZone');
173
+ this._emitShardApiCall('removeShardFromZone', { shard, zone });
174
+ await (0, helpers_1.getConfigDB)(this._database);
175
+ return await this._database._runAdminCommand({
176
+ removeShardFromZone: shard,
177
+ zone: zone
178
+ });
179
+ }
180
+ async removeShardTag(shard, tag) {
181
+ (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.removeShardTag');
182
+ this._emitShardApiCall('removeTagRange', { shard, tag });
183
+ try {
184
+ return await this.removeShardFromZone(shard, tag);
185
+ }
186
+ catch (error) {
187
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
188
+ error.message = `${error.message}. This method aliases to removeShardFromZone which exists only for server versions > 3.4.`;
189
+ }
190
+ throw error;
191
+ }
192
+ }
193
+ async enableAutoSplit() {
194
+ this._emitShardApiCall('enableAutoSplit', {});
195
+ const config = await (0, helpers_1.getConfigDB)(this._database);
196
+ return await config.getCollection('settings').updateOne({ _id: 'autosplit' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } });
197
+ }
198
+ async disableAutoSplit() {
199
+ this._emitShardApiCall('disableAutoSplit', {});
200
+ const config = await (0, helpers_1.getConfigDB)(this._database);
201
+ return await config.getCollection('settings').updateOne({ _id: 'autosplit' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } });
202
+ }
203
+ async splitAt(ns, query) {
204
+ (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitAt');
205
+ this._emitShardApiCall('splitAt', { ns, query });
206
+ return this._database._runAdminCommand({
207
+ split: ns,
208
+ middle: query
209
+ });
210
+ }
211
+ async splitFind(ns, query) {
212
+ (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitFind');
213
+ this._emitShardApiCall('splitFind', { ns, query });
214
+ return this._database._runAdminCommand({
215
+ split: ns,
216
+ find: query
217
+ });
218
+ }
219
+ async moveChunk(ns, query, destination) {
220
+ (0, helpers_1.assertArgsDefinedType)([ns, query, destination], ['string', 'object', 'string'], 'Shard.moveChunk');
221
+ this._emitShardApiCall('moveChunk', { ns, query, destination });
222
+ return this._database._runAdminCommand({
223
+ moveChunk: ns,
224
+ find: query,
225
+ to: destination
226
+ });
227
+ }
228
+ async balancerCollectionStatus(ns) {
229
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.balancerCollectionStatus');
230
+ this._emitShardApiCall('balancerCollectionStatus', { ns });
231
+ return this._database._runAdminCommand({
232
+ balancerCollectionStatus: ns
233
+ });
234
+ }
235
+ async enableBalancing(ns) {
236
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableBalancing');
237
+ this._emitShardApiCall('enableBalancing', { ns });
238
+ const config = await (0, helpers_1.getConfigDB)(this._database);
239
+ return await config.getCollection('collections').updateOne({ _id: ns }, { $set: { 'noBalance': false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } });
240
+ }
241
+ async disableBalancing(ns) {
242
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableBalancing');
243
+ this._emitShardApiCall('disableBalancing', { ns });
244
+ const config = await (0, helpers_1.getConfigDB)(this._database);
245
+ return await config.getCollection('collections').updateOne({ _id: ns }, { $set: { 'noBalance': true } }, { writeConcern: { w: 'majority', wtimeout: 60000 } });
246
+ }
247
+ async getBalancerState() {
248
+ this._emitShardApiCall('getBalancerState', {});
249
+ const config = await (0, helpers_1.getConfigDB)(this._database);
250
+ const doc = await config.getCollection('settings').findOne({ _id: 'balancer' });
251
+ if (doc === null || doc === undefined) {
252
+ return true;
253
+ }
254
+ return !doc.stopped;
255
+ }
256
+ async isBalancerRunning() {
257
+ this._emitShardApiCall('isBalancerRunning', {});
258
+ await (0, helpers_1.getConfigDB)(this._database);
259
+ return this._database._runAdminCommand({
260
+ balancerStatus: 1
261
+ });
262
+ }
263
+ async startBalancer(timeout = 60000) {
264
+ (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.startBalancer');
265
+ this._emitShardApiCall('startBalancer', { timeout });
266
+ return this._database._runAdminCommand({
267
+ balancerStart: 1, maxTimeMS: timeout
268
+ });
269
+ }
270
+ async stopBalancer(timeout = 60000) {
271
+ (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.stopBalancer');
272
+ this._emitShardApiCall('stopBalancer', { timeout });
273
+ return this._database._runAdminCommand({
274
+ balancerStop: 1, maxTimeMS: timeout
275
+ });
276
+ }
277
+ async setBalancerState(state) {
278
+ (0, helpers_1.assertArgsDefinedType)([state], ['boolean'], 'Shard.setBalancerState');
279
+ this._emitShardApiCall('setBalancerState', { state });
280
+ if (state) {
281
+ return this.startBalancer();
282
+ }
283
+ return this.stopBalancer();
284
+ }
285
+ };
286
+ __decorate([
287
+ decorators_1.returnsPromise,
288
+ (0, decorators_1.apiVersions)([])
289
+ ], Shard.prototype, "enableSharding", null);
290
+ __decorate([
291
+ decorators_1.returnsPromise,
292
+ (0, decorators_1.apiVersions)([]),
293
+ (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
294
+ ], Shard.prototype, "commitReshardCollection", null);
295
+ __decorate([
296
+ decorators_1.returnsPromise,
297
+ (0, decorators_1.apiVersions)([]),
298
+ (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
299
+ ], Shard.prototype, "abortReshardCollection", null);
300
+ __decorate([
301
+ decorators_1.returnsPromise,
302
+ (0, decorators_1.apiVersions)([])
303
+ ], Shard.prototype, "shardCollection", null);
304
+ __decorate([
305
+ decorators_1.returnsPromise,
306
+ (0, decorators_1.apiVersions)([]),
307
+ (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
308
+ ], Shard.prototype, "reshardCollection", null);
309
+ __decorate([
310
+ decorators_1.returnsPromise,
311
+ (0, decorators_1.apiVersions)([1])
312
+ ], Shard.prototype, "status", null);
313
+ __decorate([
314
+ decorators_1.returnsPromise,
315
+ (0, decorators_1.apiVersions)([])
316
+ ], Shard.prototype, "addShard", null);
317
+ __decorate([
318
+ decorators_1.returnsPromise,
319
+ (0, decorators_1.apiVersions)([]),
320
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
321
+ ], Shard.prototype, "addShardToZone", null);
322
+ __decorate([
323
+ decorators_1.returnsPromise,
324
+ (0, decorators_1.apiVersions)([]),
325
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
326
+ ], Shard.prototype, "addShardTag", null);
327
+ __decorate([
328
+ decorators_1.returnsPromise,
329
+ (0, decorators_1.apiVersions)([])
330
+ ], Shard.prototype, "updateZoneKeyRange", null);
331
+ __decorate([
332
+ decorators_1.returnsPromise,
333
+ (0, decorators_1.apiVersions)([]),
334
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
335
+ ], Shard.prototype, "addTagRange", null);
336
+ __decorate([
337
+ decorators_1.returnsPromise,
338
+ (0, decorators_1.apiVersions)([]),
339
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
340
+ ], Shard.prototype, "removeRangeFromZone", null);
341
+ __decorate([
342
+ decorators_1.returnsPromise,
343
+ (0, decorators_1.apiVersions)([]),
344
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
345
+ ], Shard.prototype, "removeTagRange", null);
346
+ __decorate([
347
+ decorators_1.returnsPromise,
348
+ (0, decorators_1.apiVersions)([]),
349
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
350
+ ], Shard.prototype, "removeShardFromZone", null);
351
+ __decorate([
352
+ decorators_1.returnsPromise,
353
+ (0, decorators_1.apiVersions)([]),
354
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
355
+ ], Shard.prototype, "removeShardTag", null);
356
+ __decorate([
357
+ decorators_1.returnsPromise,
358
+ (0, decorators_1.apiVersions)([1]),
359
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
360
+ ], Shard.prototype, "enableAutoSplit", null);
361
+ __decorate([
362
+ decorators_1.returnsPromise,
363
+ (0, decorators_1.apiVersions)([1]),
364
+ (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
365
+ ], Shard.prototype, "disableAutoSplit", null);
366
+ __decorate([
367
+ decorators_1.returnsPromise,
368
+ (0, decorators_1.apiVersions)([])
369
+ ], Shard.prototype, "splitAt", null);
370
+ __decorate([
371
+ decorators_1.returnsPromise,
372
+ (0, decorators_1.apiVersions)([])
373
+ ], Shard.prototype, "splitFind", null);
374
+ __decorate([
375
+ decorators_1.returnsPromise,
376
+ (0, decorators_1.apiVersions)([])
377
+ ], Shard.prototype, "moveChunk", null);
378
+ __decorate([
379
+ decorators_1.returnsPromise,
380
+ (0, decorators_1.apiVersions)([]),
381
+ (0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest])
382
+ ], Shard.prototype, "balancerCollectionStatus", null);
383
+ __decorate([
384
+ decorators_1.returnsPromise,
385
+ (0, decorators_1.apiVersions)([])
386
+ ], Shard.prototype, "enableBalancing", null);
387
+ __decorate([
388
+ decorators_1.returnsPromise,
389
+ (0, decorators_1.apiVersions)([])
390
+ ], Shard.prototype, "disableBalancing", null);
391
+ __decorate([
392
+ decorators_1.returnsPromise,
393
+ (0, decorators_1.apiVersions)([])
394
+ ], Shard.prototype, "getBalancerState", null);
395
+ __decorate([
396
+ decorators_1.returnsPromise,
397
+ (0, decorators_1.apiVersions)([])
398
+ ], Shard.prototype, "isBalancerRunning", null);
399
+ __decorate([
400
+ decorators_1.returnsPromise,
401
+ (0, decorators_1.apiVersions)([])
402
+ ], Shard.prototype, "startBalancer", null);
403
+ __decorate([
404
+ decorators_1.returnsPromise,
405
+ (0, decorators_1.apiVersions)([])
406
+ ], Shard.prototype, "stopBalancer", null);
407
+ __decorate([
408
+ decorators_1.returnsPromise,
409
+ (0, decorators_1.apiVersions)([])
410
+ ], Shard.prototype, "setBalancerState", null);
411
+ Shard = __decorate([
412
+ decorators_1.shellApiClassDefault
413
+ ], Shard);
414
+ exports.default = Shard;
415
415
  //# sourceMappingURL=shard.js.map