@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/shard.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 };
@@ -15,529 +47,490 @@ const enums_1 = require("./enums");
15
47
  const result_1 = require("./result");
16
48
  const history_1 = require("@mongosh/history");
17
49
  const semver_1 = __importDefault(require("semver"));
18
- let Shard = class Shard extends decorators_1.ShellApiWithMongoClass {
19
- constructor(database) {
20
- super();
21
- this._database = database;
22
- }
23
- get _mongo() {
24
- return this._database._mongo;
25
- }
26
- [enums_1.asPrintable]() {
27
- return `Shard class connected to ${(0, history_1.redactURICredentials)(this._database._mongo._uri)} via db ${this._database._name}`;
28
- }
29
- _emitShardApiCall(methodName, methodArguments = {}) {
30
- this._database._mongo._instanceState.emitApiCallWithArgs({
31
- method: methodName,
32
- class: 'Shard',
33
- arguments: methodArguments,
34
- });
35
- }
36
- async enableSharding(database, primaryShard) {
37
- (0, helpers_1.assertArgsDefinedType)([database, primaryShard], ['string', [undefined, 'string']], 'Shard.enableSharding');
38
- this._emitShardApiCall('enableSharding', { database, primaryShard });
39
- const cmd = {
40
- enableSharding: database,
41
- };
42
- if (primaryShard !== undefined) {
43
- cmd.primaryShard = primaryShard;
44
- }
45
- try {
46
- return await this._database._runAdminCommand(cmd);
47
- }
48
- catch (error) {
49
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
50
- error.message = `${error.message}. Are you connected to mongos?`;
50
+ let Shard = (() => {
51
+ let _classDecorators = [decorators_1.shellApiClassDefault];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _classSuper = decorators_1.ShellApiWithMongoClass;
56
+ let _instanceExtraInitializers = [];
57
+ let _enableSharding_decorators;
58
+ let _commitReshardCollection_decorators;
59
+ let _abortReshardCollection_decorators;
60
+ let _shardCollection_decorators;
61
+ let _reshardCollection_decorators;
62
+ let _status_decorators;
63
+ let _addShard_decorators;
64
+ let _addShardToZone_decorators;
65
+ let _addShardTag_decorators;
66
+ let _updateZoneKeyRange_decorators;
67
+ let _addTagRange_decorators;
68
+ let _removeRangeFromZone_decorators;
69
+ let _removeTagRange_decorators;
70
+ let _removeShardFromZone_decorators;
71
+ let _removeShardTag_decorators;
72
+ let _enableAutoSplit_decorators;
73
+ let _disableAutoSplit_decorators;
74
+ let _splitAt_decorators;
75
+ let _splitFind_decorators;
76
+ let _moveChunk_decorators;
77
+ let _balancerCollectionStatus_decorators;
78
+ let _enableBalancing_decorators;
79
+ let _disableBalancing_decorators;
80
+ let _getBalancerState_decorators;
81
+ let _isBalancerRunning_decorators;
82
+ let _startBalancer_decorators;
83
+ let _stopBalancer_decorators;
84
+ let _setBalancerState_decorators;
85
+ let _getShardedDataDistribution_decorators;
86
+ let _startAutoMerger_decorators;
87
+ let _stopAutoMerger_decorators;
88
+ let _isAutoMergerEnabled_decorators;
89
+ let _disableAutoMerger_decorators;
90
+ let _enableAutoMerger_decorators;
91
+ let _checkMetadataConsistency_decorators;
92
+ var Shard = _classThis = class extends _classSuper {
93
+ constructor(database) {
94
+ super();
95
+ this._database = (__runInitializers(this, _instanceExtraInitializers), void 0);
96
+ this._database = database;
97
+ }
98
+ get _mongo() {
99
+ return this._database._mongo;
100
+ }
101
+ [enums_1.asPrintable]() {
102
+ return `Shard class connected to ${(0, history_1.redactURICredentials)(this._database._mongo._uri)} via db ${this._database._name}`;
103
+ }
104
+ _emitShardApiCall(methodName, methodArguments = {}) {
105
+ this._database._mongo._instanceState.emitApiCallWithArgs({
106
+ method: methodName,
107
+ class: 'Shard',
108
+ arguments: methodArguments,
109
+ });
110
+ }
111
+ async enableSharding(database, primaryShard) {
112
+ (0, helpers_1.assertArgsDefinedType)([database, primaryShard], ['string', [undefined, 'string']], 'Shard.enableSharding');
113
+ this._emitShardApiCall('enableSharding', { database, primaryShard });
114
+ const cmd = {
115
+ enableSharding: database,
116
+ };
117
+ if (primaryShard !== undefined) {
118
+ cmd.primaryShard = primaryShard;
119
+ }
120
+ try {
121
+ return await this._database._runAdminCommand(cmd);
122
+ }
123
+ catch (error) {
124
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
125
+ error.message = `${error.message}. Are you connected to mongos?`;
126
+ }
127
+ throw error;
51
128
  }
52
- throw error;
53
129
  }
54
- }
55
- async commitReshardCollection(namespace) {
56
- (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.commitReshardCollection');
57
- this._emitShardApiCall('commitReshardCollection', { namespace });
58
- return await this._database._runAdminCommand({
59
- commitReshardCollection: namespace,
60
- });
61
- }
62
- async abortReshardCollection(namespace) {
63
- (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.abortReshardCollection');
64
- this._emitShardApiCall('abortReshardCollection', { namespace });
65
- return await this._database._runAdminCommand({
66
- abortReshardCollection: namespace,
67
- });
68
- }
69
- async shardCollection(namespace, key, unique, options) {
70
- return await this._runShardCollection('shardCollection', namespace, key, unique, options);
71
- }
72
- async reshardCollection(namespace, key, unique, options) {
73
- return await this._runShardCollection('reshardCollection', namespace, key, unique, options);
74
- }
75
- async _runShardCollection(command, namespace, key, unique, options) {
76
- (0, helpers_1.assertArgsDefinedType)([namespace, key, unique, options], [
77
- 'string',
78
- 'object',
79
- [undefined, 'boolean', 'object'],
80
- [undefined, 'object'],
81
- ], `Shard.${command}`);
82
- this._emitShardApiCall(command, { namespace, key, unique, options });
83
- if (typeof unique === 'object' && unique !== null) {
84
- options = unique;
85
- unique = undefined;
86
- }
87
- const cmd = {
88
- [command]: namespace,
89
- key: key,
90
- };
91
- if (unique !== undefined) {
92
- cmd.unique = unique;
93
- }
94
- try {
95
- return await this._database._runAdminCommand({ ...cmd, ...options });
96
- }
97
- catch (error) {
98
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
99
- error.message = `${error.message}. Are you connected to mongos?`;
130
+ async commitReshardCollection(namespace) {
131
+ (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.commitReshardCollection');
132
+ this._emitShardApiCall('commitReshardCollection', { namespace });
133
+ return await this._database._runAdminCommand({
134
+ commitReshardCollection: namespace,
135
+ });
136
+ }
137
+ async abortReshardCollection(namespace) {
138
+ (0, helpers_1.assertArgsDefinedType)([namespace], ['string'], 'Shard.abortReshardCollection');
139
+ this._emitShardApiCall('abortReshardCollection', { namespace });
140
+ return await this._database._runAdminCommand({
141
+ abortReshardCollection: namespace,
142
+ });
143
+ }
144
+ async shardCollection(namespace, key, unique, options) {
145
+ return await this._runShardCollection('shardCollection', namespace, key, unique, options);
146
+ }
147
+ async reshardCollection(namespace, key, unique, options) {
148
+ return await this._runShardCollection('reshardCollection', namespace, key, unique, options);
149
+ }
150
+ async _runShardCollection(command, namespace, key, unique, options) {
151
+ (0, helpers_1.assertArgsDefinedType)([namespace, key, unique, options], [
152
+ 'string',
153
+ 'object',
154
+ [undefined, 'boolean', 'object'],
155
+ [undefined, 'object'],
156
+ ], `Shard.${command}`);
157
+ this._emitShardApiCall(command, { namespace, key, unique, options });
158
+ if (typeof unique === 'object' && unique !== null) {
159
+ options = unique;
160
+ unique = undefined;
161
+ }
162
+ const cmd = {
163
+ [command]: namespace,
164
+ key: key,
165
+ };
166
+ if (unique !== undefined) {
167
+ cmd.unique = unique;
168
+ }
169
+ try {
170
+ return await this._database._runAdminCommand({ ...cmd, ...options });
171
+ }
172
+ catch (error) {
173
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
174
+ error.message = `${error.message}. Are you connected to mongos?`;
175
+ }
176
+ throw error;
100
177
  }
101
- throw error;
102
178
  }
103
- }
104
- async status(verbose = false, configDB) {
105
- const result = await (0, helpers_1.getPrintableShardStatus)(configDB !== null && configDB !== void 0 ? configDB : (await (0, helpers_1.getConfigDB)(this._database)), verbose);
106
- return new result_1.CommandResult('StatsResult', result);
107
- }
108
- async addShard(url) {
109
- (0, helpers_1.assertArgsDefinedType)([url], ['string'], 'Shard.addShard');
110
- await (0, helpers_1.getConfigDB)(this._database);
111
- this._emitShardApiCall('addShard', { url });
112
- return this._database._runAdminCommand({
113
- addShard: url,
114
- });
115
- }
116
- async addShardToZone(shard, zone) {
117
- (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.addShardToZone');
118
- this._emitShardApiCall('addShardToZone', { shard, zone });
119
- await (0, helpers_1.getConfigDB)(this._database);
120
- return this._database._runAdminCommand({
121
- addShardToZone: shard,
122
- zone: zone,
123
- });
124
- }
125
- async addShardTag(shard, tag) {
126
- (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.addShardTag');
127
- this._emitShardApiCall('addShardTag', { shard, tag });
128
- try {
129
- return await this.addShardToZone(shard, tag);
130
- }
131
- catch (error) {
132
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
133
- error.message = `${error.message}. This method aliases to addShardToZone which exists only for server versions > 3.4.`;
179
+ async status(verbose = false, configDB) {
180
+ const result = await (0, helpers_1.getPrintableShardStatus)(configDB !== null && configDB !== void 0 ? configDB : (await (0, helpers_1.getConfigDB)(this._database)), verbose);
181
+ return new result_1.CommandResult('StatsResult', result);
182
+ }
183
+ async addShard(url) {
184
+ (0, helpers_1.assertArgsDefinedType)([url], ['string'], 'Shard.addShard');
185
+ await (0, helpers_1.getConfigDB)(this._database);
186
+ this._emitShardApiCall('addShard', { url });
187
+ return this._database._runAdminCommand({
188
+ addShard: url,
189
+ });
190
+ }
191
+ async addShardToZone(shard, zone) {
192
+ (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.addShardToZone');
193
+ this._emitShardApiCall('addShardToZone', { shard, zone });
194
+ await (0, helpers_1.getConfigDB)(this._database);
195
+ return this._database._runAdminCommand({
196
+ addShardToZone: shard,
197
+ zone: zone,
198
+ });
199
+ }
200
+ async addShardTag(shard, tag) {
201
+ (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.addShardTag');
202
+ this._emitShardApiCall('addShardTag', { shard, tag });
203
+ try {
204
+ return await this.addShardToZone(shard, tag);
205
+ }
206
+ catch (error) {
207
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
208
+ error.message = `${error.message}. This method aliases to addShardToZone which exists only for server versions > 3.4.`;
209
+ }
210
+ throw error;
134
211
  }
135
- throw error;
136
212
  }
137
- }
138
- async updateZoneKeyRange(namespace, min, max, zone) {
139
- (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.updateZoneKeyRange');
140
- this._emitShardApiCall('updateZoneKeyRange', { namespace, min, max, zone });
141
- await (0, helpers_1.getConfigDB)(this._database);
142
- return await this._database._runAdminCommand({
143
- updateZoneKeyRange: namespace,
144
- min,
145
- max,
146
- zone,
147
- });
148
- }
149
- async addTagRange(namespace, min, max, zone) {
150
- (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.addTagRange');
151
- this._emitShardApiCall('addTagRange', { namespace, min, max, zone });
152
- try {
153
- return await this.updateZoneKeyRange(namespace, min, max, zone);
154
- }
155
- catch (error) {
156
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
157
- error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
213
+ async updateZoneKeyRange(namespace, min, max, zone) {
214
+ (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.updateZoneKeyRange');
215
+ this._emitShardApiCall('updateZoneKeyRange', { namespace, min, max, zone });
216
+ await (0, helpers_1.getConfigDB)(this._database);
217
+ return await this._database._runAdminCommand({
218
+ updateZoneKeyRange: namespace,
219
+ min,
220
+ max,
221
+ zone,
222
+ });
223
+ }
224
+ async addTagRange(namespace, min, max, zone) {
225
+ (0, helpers_1.assertArgsDefinedType)([namespace, min, max, zone], ['string', 'object', 'object', true], 'Shard.addTagRange');
226
+ this._emitShardApiCall('addTagRange', { namespace, min, max, zone });
227
+ try {
228
+ return await this.updateZoneKeyRange(namespace, min, max, zone);
229
+ }
230
+ catch (error) {
231
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
232
+ error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
233
+ }
234
+ throw error;
158
235
  }
159
- throw error;
160
236
  }
161
- }
162
- async removeRangeFromZone(ns, min, max) {
163
- (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeRangeFromZone');
164
- this._emitShardApiCall('removeRangeFromZone', { ns, min, max });
165
- return this.updateZoneKeyRange(ns, min, max, null);
166
- }
167
- async removeTagRange(ns, min, max) {
168
- (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeTagRange');
169
- this._emitShardApiCall('removeTagRange', { ns, min, max });
170
- try {
171
- return await this.updateZoneKeyRange(ns, min, max, null);
172
- }
173
- catch (error) {
174
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
175
- error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
237
+ async removeRangeFromZone(ns, min, max) {
238
+ (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeRangeFromZone');
239
+ this._emitShardApiCall('removeRangeFromZone', { ns, min, max });
240
+ return this.updateZoneKeyRange(ns, min, max, null);
241
+ }
242
+ async removeTagRange(ns, min, max) {
243
+ (0, helpers_1.assertArgsDefinedType)([ns, min, max], ['string', 'object', 'object'], 'Shard.removeTagRange');
244
+ this._emitShardApiCall('removeTagRange', { ns, min, max });
245
+ try {
246
+ return await this.updateZoneKeyRange(ns, min, max, null);
247
+ }
248
+ catch (error) {
249
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
250
+ error.message = `${error.message}. This method aliases to updateZoneKeyRange which exists only for server versions > 3.4.`;
251
+ }
252
+ throw error;
176
253
  }
177
- throw error;
178
254
  }
179
- }
180
- async removeShardFromZone(shard, zone) {
181
- (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.removeShardFromZone');
182
- this._emitShardApiCall('removeShardFromZone', { shard, zone });
183
- await (0, helpers_1.getConfigDB)(this._database);
184
- return await this._database._runAdminCommand({
185
- removeShardFromZone: shard,
186
- zone: zone,
187
- });
188
- }
189
- async removeShardTag(shard, tag) {
190
- (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.removeShardTag');
191
- this._emitShardApiCall('removeTagRange', { shard, tag });
192
- try {
193
- return await this.removeShardFromZone(shard, tag);
194
- }
195
- catch (error) {
196
- if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
197
- error.message = `${error.message}. This method aliases to removeShardFromZone which exists only for server versions > 3.4.`;
255
+ async removeShardFromZone(shard, zone) {
256
+ (0, helpers_1.assertArgsDefinedType)([shard, zone], ['string', 'string'], 'Shard.removeShardFromZone');
257
+ this._emitShardApiCall('removeShardFromZone', { shard, zone });
258
+ await (0, helpers_1.getConfigDB)(this._database);
259
+ return await this._database._runAdminCommand({
260
+ removeShardFromZone: shard,
261
+ zone: zone,
262
+ });
263
+ }
264
+ async removeShardTag(shard, tag) {
265
+ (0, helpers_1.assertArgsDefinedType)([shard, tag], ['string', 'string'], 'Shard.removeShardTag');
266
+ this._emitShardApiCall('removeTagRange', { shard, tag });
267
+ try {
268
+ return await this.removeShardFromZone(shard, tag);
269
+ }
270
+ catch (error) {
271
+ if ((error === null || error === void 0 ? void 0 : error.codeName) === 'CommandNotFound') {
272
+ error.message = `${error.message}. This method aliases to removeShardFromZone which exists only for server versions > 3.4.`;
273
+ }
274
+ throw error;
198
275
  }
199
- throw error;
200
276
  }
201
- }
202
- async enableAutoSplit() {
203
- if (this._instanceState.connectionInfo.buildInfo.version &&
204
- semver_1.default.gte(this._instanceState.connectionInfo.buildInfo.version, '6.0.3')) {
205
- await this._instanceState.printDeprecationWarning('Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. For details, see Balancing Policy Changes: https://www.mongodb.com/docs/manual/release-notes/6.0/#balancing-policy-changes\n');
206
- }
207
- this._emitShardApiCall('enableAutoSplit', {});
208
- const config = await (0, helpers_1.getConfigDB)(this._database);
209
- return (await config
210
- .getCollection('settings')
211
- .updateOne({ _id: 'autosplit' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
212
- }
213
- async disableAutoSplit() {
214
- if (this._instanceState.connectionInfo.buildInfo.version &&
215
- semver_1.default.gte(this._instanceState.connectionInfo.buildInfo.version, '6.0.3')) {
216
- await this._instanceState.printDeprecationWarning('Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. For details, see Balancing Policy Changes: https://www.mongodb.com/docs/manual/release-notes/6.0/#balancing-policy-changes\n');
217
- }
218
- this._emitShardApiCall('disableAutoSplit', {});
219
- const config = await (0, helpers_1.getConfigDB)(this._database);
220
- return (await config
221
- .getCollection('settings')
222
- .updateOne({ _id: 'autosplit' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
223
- }
224
- async splitAt(ns, query) {
225
- (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitAt');
226
- this._emitShardApiCall('splitAt', { ns, query });
227
- return this._database._runAdminCommand({
228
- split: ns,
229
- middle: query,
230
- });
231
- }
232
- async splitFind(ns, query) {
233
- (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitFind');
234
- this._emitShardApiCall('splitFind', { ns, query });
235
- return this._database._runAdminCommand({
236
- split: ns,
237
- find: query,
238
- });
239
- }
240
- async moveChunk(ns, query, destination) {
241
- (0, helpers_1.assertArgsDefinedType)([ns, query, destination], ['string', 'object', 'string'], 'Shard.moveChunk');
242
- this._emitShardApiCall('moveChunk', { ns, query, destination });
243
- return this._database._runAdminCommand({
244
- moveChunk: ns,
245
- find: query,
246
- to: destination,
247
- });
248
- }
249
- async balancerCollectionStatus(ns) {
250
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.balancerCollectionStatus');
251
- this._emitShardApiCall('balancerCollectionStatus', { ns });
252
- return this._database._runAdminCommand({
253
- balancerCollectionStatus: ns,
254
- });
255
- }
256
- async enableBalancing(ns) {
257
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableBalancing');
258
- this._emitShardApiCall('enableBalancing', { ns });
259
- const config = await (0, helpers_1.getConfigDB)(this._database);
260
- return (await config
261
- .getCollection('collections')
262
- .updateOne({ _id: ns }, { $set: { noBalance: false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
263
- }
264
- async disableBalancing(ns) {
265
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableBalancing');
266
- this._emitShardApiCall('disableBalancing', { ns });
267
- const config = await (0, helpers_1.getConfigDB)(this._database);
268
- return (await config
269
- .getCollection('collections')
270
- .updateOne({ _id: ns }, { $set: { noBalance: true } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
271
- }
272
- async getBalancerState() {
273
- this._emitShardApiCall('getBalancerState', {});
274
- const config = await (0, helpers_1.getConfigDB)(this._database);
275
- const doc = await config
276
- .getCollection('settings')
277
- .findOne({ _id: 'balancer' });
278
- if (doc === null || doc === undefined) {
279
- return true;
280
- }
281
- return !doc.stopped;
282
- }
283
- async isBalancerRunning() {
284
- this._emitShardApiCall('isBalancerRunning', {});
285
- await (0, helpers_1.getConfigDB)(this._database);
286
- return this._database._runAdminCommand({
287
- balancerStatus: 1,
288
- });
289
- }
290
- async startBalancer(timeout = 60000) {
291
- (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.startBalancer');
292
- this._emitShardApiCall('startBalancer', { timeout });
293
- return this._database._runAdminCommand({
294
- balancerStart: 1,
295
- maxTimeMS: timeout,
296
- });
297
- }
298
- async stopBalancer(timeout = 60000) {
299
- (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.stopBalancer');
300
- this._emitShardApiCall('stopBalancer', { timeout });
301
- return this._database._runAdminCommand({
302
- balancerStop: 1,
303
- maxTimeMS: timeout,
304
- });
305
- }
306
- async setBalancerState(state) {
307
- (0, helpers_1.assertArgsDefinedType)([state], ['boolean'], 'Shard.setBalancerState');
308
- this._emitShardApiCall('setBalancerState', { state });
309
- if (state) {
310
- return this.startBalancer();
277
+ async enableAutoSplit() {
278
+ if (this._instanceState.connectionInfo.buildInfo.version &&
279
+ semver_1.default.gte(this._instanceState.connectionInfo.buildInfo.version, '6.0.3')) {
280
+ await this._instanceState.printDeprecationWarning('Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. For details, see Balancing Policy Changes: https://www.mongodb.com/docs/manual/release-notes/6.0/#balancing-policy-changes\n');
281
+ }
282
+ this._emitShardApiCall('enableAutoSplit', {});
283
+ const config = await (0, helpers_1.getConfigDB)(this._database);
284
+ return (await config
285
+ .getCollection('settings')
286
+ .updateOne({ _id: 'autosplit' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
311
287
  }
312
- return this.stopBalancer();
313
- }
314
- async getShardedDataDistribution(options = {}) {
315
- var _a;
316
- this._emitShardApiCall('getShardedDataDistribution', {});
317
- const cursor = await this._database
318
- .getSiblingDB('admin')
319
- .aggregate([{ $shardedDataDistribution: options }]);
320
- try {
321
- await cursor.hasNext();
322
- }
323
- catch (err) {
324
- if (((_a = err.code) === null || _a === void 0 ? void 0 : _a.valueOf()) === 40324) {
325
- err.message = `sh.getShardedDataDistribution only works on mongos and MongoDB server versions greater than 6.0.3 [Original Error: ${err.message}]`;
288
+ async disableAutoSplit() {
289
+ if (this._instanceState.connectionInfo.buildInfo.version &&
290
+ semver_1.default.gte(this._instanceState.connectionInfo.buildInfo.version, '6.0.3')) {
291
+ await this._instanceState.printDeprecationWarning('Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. For details, see Balancing Policy Changes: https://www.mongodb.com/docs/manual/release-notes/6.0/#balancing-policy-changes\n');
326
292
  }
327
- throw err;
293
+ this._emitShardApiCall('disableAutoSplit', {});
294
+ const config = await (0, helpers_1.getConfigDB)(this._database);
295
+ return (await config
296
+ .getCollection('settings')
297
+ .updateOne({ _id: 'autosplit' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
328
298
  }
329
- return cursor;
330
- }
331
- async startAutoMerger() {
332
- this._emitShardApiCall('startAutoMerger', {});
333
- const config = await (0, helpers_1.getConfigDB)(this._database);
334
- return (await config
335
- .getCollection('settings')
336
- .updateOne({ _id: 'automerge' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
337
- }
338
- async stopAutoMerger() {
339
- this._emitShardApiCall('stopAutoMerger', {});
340
- const config = await (0, helpers_1.getConfigDB)(this._database);
341
- return (await config
342
- .getCollection('settings')
343
- .updateOne({ _id: 'automerge' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
344
- }
345
- async isAutoMergerEnabled() {
346
- this._emitShardApiCall('isAutoMergerEnabled', {});
347
- const config = await (0, helpers_1.getConfigDB)(this._database);
348
- const doc = await config
349
- .getCollection('settings')
350
- .findOne({ _id: 'automerge' });
351
- if (doc === null || doc === undefined) {
352
- return true;
353
- }
354
- return doc.enabled;
355
- }
356
- async disableAutoMerger(ns) {
357
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableAutoMerger');
358
- this._emitShardApiCall('disableAutoMerger', { ns });
359
- const config = await (0, helpers_1.getConfigDB)(this._database);
360
- return (await config
361
- .getCollection('collections')
362
- .updateOne({ _id: ns }, { $set: { enableAutoMerge: false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
363
- }
364
- async enableAutoMerger(ns) {
365
- (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableAutoMerger');
366
- this._emitShardApiCall('enableAutoMerger', { ns });
367
- const config = await (0, helpers_1.getConfigDB)(this._database);
368
- return (await config
369
- .getCollection('collections')
370
- .updateOne({ _id: ns }, { $unset: { enableAutoMerge: 1 } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
371
- }
372
- async checkMetadataConsistency(options = {}) {
373
- this._emitShardApiCall('checkMetadataConsistency', { options });
374
- return this._database._runAdminCursorCommand({
375
- checkMetadataConsistency: 1,
376
- });
377
- }
378
- };
379
- __decorate([
380
- decorators_1.returnsPromise,
381
- (0, decorators_1.apiVersions)([])
382
- ], Shard.prototype, "enableSharding", null);
383
- __decorate([
384
- decorators_1.returnsPromise,
385
- (0, decorators_1.apiVersions)([]),
386
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
387
- ], Shard.prototype, "commitReshardCollection", null);
388
- __decorate([
389
- decorators_1.returnsPromise,
390
- (0, decorators_1.apiVersions)([]),
391
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
392
- ], Shard.prototype, "abortReshardCollection", null);
393
- __decorate([
394
- decorators_1.returnsPromise,
395
- (0, decorators_1.apiVersions)([])
396
- ], Shard.prototype, "shardCollection", null);
397
- __decorate([
398
- decorators_1.returnsPromise,
399
- (0, decorators_1.apiVersions)([]),
400
- (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
401
- ], Shard.prototype, "reshardCollection", null);
402
- __decorate([
403
- decorators_1.returnsPromise,
404
- (0, decorators_1.apiVersions)([1])
405
- ], Shard.prototype, "status", null);
406
- __decorate([
407
- decorators_1.returnsPromise,
408
- (0, decorators_1.apiVersions)([])
409
- ], Shard.prototype, "addShard", null);
410
- __decorate([
411
- decorators_1.returnsPromise,
412
- (0, decorators_1.apiVersions)([]),
413
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
414
- ], Shard.prototype, "addShardToZone", null);
415
- __decorate([
416
- decorators_1.returnsPromise,
417
- (0, decorators_1.apiVersions)([]),
418
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
419
- ], Shard.prototype, "addShardTag", null);
420
- __decorate([
421
- decorators_1.returnsPromise,
422
- (0, decorators_1.apiVersions)([])
423
- ], Shard.prototype, "updateZoneKeyRange", null);
424
- __decorate([
425
- decorators_1.returnsPromise,
426
- (0, decorators_1.apiVersions)([]),
427
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
428
- ], Shard.prototype, "addTagRange", null);
429
- __decorate([
430
- decorators_1.returnsPromise,
431
- (0, decorators_1.apiVersions)([]),
432
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
433
- ], Shard.prototype, "removeRangeFromZone", null);
434
- __decorate([
435
- decorators_1.returnsPromise,
436
- (0, decorators_1.apiVersions)([]),
437
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
438
- ], Shard.prototype, "removeTagRange", null);
439
- __decorate([
440
- decorators_1.returnsPromise,
441
- (0, decorators_1.apiVersions)([]),
442
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
443
- ], Shard.prototype, "removeShardFromZone", null);
444
- __decorate([
445
- decorators_1.returnsPromise,
446
- (0, decorators_1.apiVersions)([]),
447
- (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])
448
- ], Shard.prototype, "removeShardTag", null);
449
- __decorate([
450
- decorators_1.returnsPromise,
451
- (0, decorators_1.apiVersions)([1]),
452
- (0, decorators_1.serverVersions)(['3.4.0', '6.0.2'])
453
- ], Shard.prototype, "enableAutoSplit", null);
454
- __decorate([
455
- decorators_1.returnsPromise,
456
- (0, decorators_1.apiVersions)([1]),
457
- (0, decorators_1.serverVersions)(['3.4.0', '6.0.2'])
458
- ], Shard.prototype, "disableAutoSplit", null);
459
- __decorate([
460
- decorators_1.returnsPromise,
461
- (0, decorators_1.apiVersions)([])
462
- ], Shard.prototype, "splitAt", null);
463
- __decorate([
464
- decorators_1.returnsPromise,
465
- (0, decorators_1.apiVersions)([])
466
- ], Shard.prototype, "splitFind", null);
467
- __decorate([
468
- decorators_1.returnsPromise,
469
- (0, decorators_1.apiVersions)([])
470
- ], Shard.prototype, "moveChunk", null);
471
- __decorate([
472
- decorators_1.returnsPromise,
473
- (0, decorators_1.apiVersions)([]),
474
- (0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest])
475
- ], Shard.prototype, "balancerCollectionStatus", null);
476
- __decorate([
477
- decorators_1.returnsPromise,
478
- (0, decorators_1.apiVersions)([])
479
- ], Shard.prototype, "enableBalancing", null);
480
- __decorate([
481
- decorators_1.returnsPromise,
482
- (0, decorators_1.apiVersions)([])
483
- ], Shard.prototype, "disableBalancing", null);
484
- __decorate([
485
- decorators_1.returnsPromise,
486
- (0, decorators_1.apiVersions)([])
487
- ], Shard.prototype, "getBalancerState", null);
488
- __decorate([
489
- decorators_1.returnsPromise,
490
- (0, decorators_1.apiVersions)([])
491
- ], Shard.prototype, "isBalancerRunning", null);
492
- __decorate([
493
- decorators_1.returnsPromise,
494
- (0, decorators_1.apiVersions)([])
495
- ], Shard.prototype, "startBalancer", null);
496
- __decorate([
497
- decorators_1.returnsPromise,
498
- (0, decorators_1.apiVersions)([])
499
- ], Shard.prototype, "stopBalancer", null);
500
- __decorate([
501
- decorators_1.returnsPromise,
502
- (0, decorators_1.apiVersions)([])
503
- ], Shard.prototype, "setBalancerState", null);
504
- __decorate([
505
- decorators_1.returnsPromise,
506
- (0, decorators_1.apiVersions)([]),
507
- (0, decorators_1.serverVersions)(['6.0.3', enums_1.ServerVersions.latest]),
508
- (0, decorators_1.returnType)('AggregationCursor')
509
- ], Shard.prototype, "getShardedDataDistribution", null);
510
- __decorate([
511
- decorators_1.returnsPromise,
512
- (0, decorators_1.apiVersions)([]),
513
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
514
- ], Shard.prototype, "startAutoMerger", null);
515
- __decorate([
516
- decorators_1.returnsPromise,
517
- (0, decorators_1.apiVersions)([]),
518
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
519
- ], Shard.prototype, "stopAutoMerger", null);
520
- __decorate([
521
- decorators_1.returnsPromise,
522
- (0, decorators_1.apiVersions)([]),
523
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
524
- ], Shard.prototype, "isAutoMergerEnabled", null);
525
- __decorate([
526
- decorators_1.returnsPromise,
527
- (0, decorators_1.apiVersions)([]),
528
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
529
- ], Shard.prototype, "disableAutoMerger", null);
530
- __decorate([
531
- decorators_1.returnsPromise,
532
- (0, decorators_1.apiVersions)([]),
533
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
534
- ], Shard.prototype, "enableAutoMerger", null);
535
- __decorate([
536
- decorators_1.returnsPromise,
537
- (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])
538
- ], Shard.prototype, "checkMetadataConsistency", null);
539
- Shard = __decorate([
540
- decorators_1.shellApiClassDefault
541
- ], Shard);
299
+ async splitAt(ns, query) {
300
+ (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitAt');
301
+ this._emitShardApiCall('splitAt', { ns, query });
302
+ return this._database._runAdminCommand({
303
+ split: ns,
304
+ middle: query,
305
+ });
306
+ }
307
+ async splitFind(ns, query) {
308
+ (0, helpers_1.assertArgsDefinedType)([ns, query], ['string', 'object'], 'Shard.splitFind');
309
+ this._emitShardApiCall('splitFind', { ns, query });
310
+ return this._database._runAdminCommand({
311
+ split: ns,
312
+ find: query,
313
+ });
314
+ }
315
+ async moveChunk(ns, query, destination) {
316
+ (0, helpers_1.assertArgsDefinedType)([ns, query, destination], ['string', 'object', 'string'], 'Shard.moveChunk');
317
+ this._emitShardApiCall('moveChunk', { ns, query, destination });
318
+ return this._database._runAdminCommand({
319
+ moveChunk: ns,
320
+ find: query,
321
+ to: destination,
322
+ });
323
+ }
324
+ async balancerCollectionStatus(ns) {
325
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.balancerCollectionStatus');
326
+ this._emitShardApiCall('balancerCollectionStatus', { ns });
327
+ return this._database._runAdminCommand({
328
+ balancerCollectionStatus: ns,
329
+ });
330
+ }
331
+ async enableBalancing(ns) {
332
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableBalancing');
333
+ this._emitShardApiCall('enableBalancing', { ns });
334
+ const config = await (0, helpers_1.getConfigDB)(this._database);
335
+ return (await config
336
+ .getCollection('collections')
337
+ .updateOne({ _id: ns }, { $set: { noBalance: false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
338
+ }
339
+ async disableBalancing(ns) {
340
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableBalancing');
341
+ this._emitShardApiCall('disableBalancing', { ns });
342
+ const config = await (0, helpers_1.getConfigDB)(this._database);
343
+ return (await config
344
+ .getCollection('collections')
345
+ .updateOne({ _id: ns }, { $set: { noBalance: true } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
346
+ }
347
+ async getBalancerState() {
348
+ this._emitShardApiCall('getBalancerState', {});
349
+ const config = await (0, helpers_1.getConfigDB)(this._database);
350
+ const doc = await config
351
+ .getCollection('settings')
352
+ .findOne({ _id: 'balancer' });
353
+ if (doc === null || doc === undefined) {
354
+ return true;
355
+ }
356
+ return !doc.stopped;
357
+ }
358
+ async isBalancerRunning() {
359
+ this._emitShardApiCall('isBalancerRunning', {});
360
+ await (0, helpers_1.getConfigDB)(this._database);
361
+ return this._database._runAdminCommand({
362
+ balancerStatus: 1,
363
+ });
364
+ }
365
+ async startBalancer(timeout = 60000) {
366
+ (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.startBalancer');
367
+ this._emitShardApiCall('startBalancer', { timeout });
368
+ return this._database._runAdminCommand({
369
+ balancerStart: 1,
370
+ maxTimeMS: timeout,
371
+ });
372
+ }
373
+ async stopBalancer(timeout = 60000) {
374
+ (0, helpers_1.assertArgsDefinedType)([timeout], ['number'], 'Shard.stopBalancer');
375
+ this._emitShardApiCall('stopBalancer', { timeout });
376
+ return this._database._runAdminCommand({
377
+ balancerStop: 1,
378
+ maxTimeMS: timeout,
379
+ });
380
+ }
381
+ async setBalancerState(state) {
382
+ (0, helpers_1.assertArgsDefinedType)([state], ['boolean'], 'Shard.setBalancerState');
383
+ this._emitShardApiCall('setBalancerState', { state });
384
+ if (state) {
385
+ return this.startBalancer();
386
+ }
387
+ return this.stopBalancer();
388
+ }
389
+ async getShardedDataDistribution(options = {}) {
390
+ var _a;
391
+ this._emitShardApiCall('getShardedDataDistribution', {});
392
+ const cursor = await this._database
393
+ .getSiblingDB('admin')
394
+ .aggregate([{ $shardedDataDistribution: options }]);
395
+ try {
396
+ await cursor.hasNext();
397
+ }
398
+ catch (err) {
399
+ if (((_a = err.code) === null || _a === void 0 ? void 0 : _a.valueOf()) === 40324) {
400
+ err.message = `sh.getShardedDataDistribution only works on mongos and MongoDB server versions greater than 6.0.3 [Original Error: ${err.message}]`;
401
+ }
402
+ throw err;
403
+ }
404
+ return cursor;
405
+ }
406
+ async startAutoMerger() {
407
+ this._emitShardApiCall('startAutoMerger', {});
408
+ const config = await (0, helpers_1.getConfigDB)(this._database);
409
+ return (await config
410
+ .getCollection('settings')
411
+ .updateOne({ _id: 'automerge' }, { $set: { enabled: true } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
412
+ }
413
+ async stopAutoMerger() {
414
+ this._emitShardApiCall('stopAutoMerger', {});
415
+ const config = await (0, helpers_1.getConfigDB)(this._database);
416
+ return (await config
417
+ .getCollection('settings')
418
+ .updateOne({ _id: 'automerge' }, { $set: { enabled: false } }, { upsert: true, writeConcern: { w: 'majority', wtimeout: 30000 } }));
419
+ }
420
+ async isAutoMergerEnabled() {
421
+ this._emitShardApiCall('isAutoMergerEnabled', {});
422
+ const config = await (0, helpers_1.getConfigDB)(this._database);
423
+ const doc = await config
424
+ .getCollection('settings')
425
+ .findOne({ _id: 'automerge' });
426
+ if (doc === null || doc === undefined) {
427
+ return true;
428
+ }
429
+ return doc.enabled;
430
+ }
431
+ async disableAutoMerger(ns) {
432
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.disableAutoMerger');
433
+ this._emitShardApiCall('disableAutoMerger', { ns });
434
+ const config = await (0, helpers_1.getConfigDB)(this._database);
435
+ return (await config
436
+ .getCollection('collections')
437
+ .updateOne({ _id: ns }, { $set: { enableAutoMerge: false } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
438
+ }
439
+ async enableAutoMerger(ns) {
440
+ (0, helpers_1.assertArgsDefinedType)([ns], ['string'], 'Shard.enableAutoMerger');
441
+ this._emitShardApiCall('enableAutoMerger', { ns });
442
+ const config = await (0, helpers_1.getConfigDB)(this._database);
443
+ return (await config
444
+ .getCollection('collections')
445
+ .updateOne({ _id: ns }, { $unset: { enableAutoMerge: 1 } }, { writeConcern: { w: 'majority', wtimeout: 60000 } }));
446
+ }
447
+ async checkMetadataConsistency(options = {}) {
448
+ this._emitShardApiCall('checkMetadataConsistency', { options });
449
+ return this._database._runAdminCursorCommand({
450
+ checkMetadataConsistency: 1,
451
+ });
452
+ }
453
+ };
454
+ __setFunctionName(_classThis, "Shard");
455
+ (() => {
456
+ var _a;
457
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
458
+ _enableSharding_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
459
+ _commitReshardCollection_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])];
460
+ _abortReshardCollection_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])];
461
+ _shardCollection_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
462
+ _reshardCollection_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])];
463
+ _status_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([1])];
464
+ _addShard_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
465
+ _addShardToZone_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
466
+ _addShardTag_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
467
+ _updateZoneKeyRange_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
468
+ _addTagRange_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
469
+ _removeRangeFromZone_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
470
+ _removeTagRange_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
471
+ _removeShardFromZone_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
472
+ _removeShardTag_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest])];
473
+ _enableAutoSplit_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([1]), (0, decorators_1.serverVersions)(['3.4.0', '6.0.2'])];
474
+ _disableAutoSplit_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([1]), (0, decorators_1.serverVersions)(['3.4.0', '6.0.2'])];
475
+ _splitAt_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
476
+ _splitFind_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
477
+ _moveChunk_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
478
+ _balancerCollectionStatus_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest])];
479
+ _enableBalancing_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
480
+ _disableBalancing_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
481
+ _getBalancerState_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
482
+ _isBalancerRunning_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
483
+ _startBalancer_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
484
+ _stopBalancer_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
485
+ _setBalancerState_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
486
+ _getShardedDataDistribution_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['6.0.3', enums_1.ServerVersions.latest]), (0, decorators_1.returnType)('AggregationCursor')];
487
+ _startAutoMerger_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
488
+ _stopAutoMerger_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
489
+ _isAutoMergerEnabled_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
490
+ _disableAutoMerger_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
491
+ _enableAutoMerger_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
492
+ _checkMetadataConsistency_decorators = [decorators_1.returnsPromise, (0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest])];
493
+ __esDecorate(_classThis, null, _enableSharding_decorators, { kind: "method", name: "enableSharding", static: false, private: false, access: { has: obj => "enableSharding" in obj, get: obj => obj.enableSharding }, metadata: _metadata }, null, _instanceExtraInitializers);
494
+ __esDecorate(_classThis, null, _commitReshardCollection_decorators, { kind: "method", name: "commitReshardCollection", static: false, private: false, access: { has: obj => "commitReshardCollection" in obj, get: obj => obj.commitReshardCollection }, metadata: _metadata }, null, _instanceExtraInitializers);
495
+ __esDecorate(_classThis, null, _abortReshardCollection_decorators, { kind: "method", name: "abortReshardCollection", static: false, private: false, access: { has: obj => "abortReshardCollection" in obj, get: obj => obj.abortReshardCollection }, metadata: _metadata }, null, _instanceExtraInitializers);
496
+ __esDecorate(_classThis, null, _shardCollection_decorators, { kind: "method", name: "shardCollection", static: false, private: false, access: { has: obj => "shardCollection" in obj, get: obj => obj.shardCollection }, metadata: _metadata }, null, _instanceExtraInitializers);
497
+ __esDecorate(_classThis, null, _reshardCollection_decorators, { kind: "method", name: "reshardCollection", static: false, private: false, access: { has: obj => "reshardCollection" in obj, get: obj => obj.reshardCollection }, metadata: _metadata }, null, _instanceExtraInitializers);
498
+ __esDecorate(_classThis, null, _status_decorators, { kind: "method", name: "status", static: false, private: false, access: { has: obj => "status" in obj, get: obj => obj.status }, metadata: _metadata }, null, _instanceExtraInitializers);
499
+ __esDecorate(_classThis, null, _addShard_decorators, { kind: "method", name: "addShard", static: false, private: false, access: { has: obj => "addShard" in obj, get: obj => obj.addShard }, metadata: _metadata }, null, _instanceExtraInitializers);
500
+ __esDecorate(_classThis, null, _addShardToZone_decorators, { kind: "method", name: "addShardToZone", static: false, private: false, access: { has: obj => "addShardToZone" in obj, get: obj => obj.addShardToZone }, metadata: _metadata }, null, _instanceExtraInitializers);
501
+ __esDecorate(_classThis, null, _addShardTag_decorators, { kind: "method", name: "addShardTag", static: false, private: false, access: { has: obj => "addShardTag" in obj, get: obj => obj.addShardTag }, metadata: _metadata }, null, _instanceExtraInitializers);
502
+ __esDecorate(_classThis, null, _updateZoneKeyRange_decorators, { kind: "method", name: "updateZoneKeyRange", static: false, private: false, access: { has: obj => "updateZoneKeyRange" in obj, get: obj => obj.updateZoneKeyRange }, metadata: _metadata }, null, _instanceExtraInitializers);
503
+ __esDecorate(_classThis, null, _addTagRange_decorators, { kind: "method", name: "addTagRange", static: false, private: false, access: { has: obj => "addTagRange" in obj, get: obj => obj.addTagRange }, metadata: _metadata }, null, _instanceExtraInitializers);
504
+ __esDecorate(_classThis, null, _removeRangeFromZone_decorators, { kind: "method", name: "removeRangeFromZone", static: false, private: false, access: { has: obj => "removeRangeFromZone" in obj, get: obj => obj.removeRangeFromZone }, metadata: _metadata }, null, _instanceExtraInitializers);
505
+ __esDecorate(_classThis, null, _removeTagRange_decorators, { kind: "method", name: "removeTagRange", static: false, private: false, access: { has: obj => "removeTagRange" in obj, get: obj => obj.removeTagRange }, metadata: _metadata }, null, _instanceExtraInitializers);
506
+ __esDecorate(_classThis, null, _removeShardFromZone_decorators, { kind: "method", name: "removeShardFromZone", static: false, private: false, access: { has: obj => "removeShardFromZone" in obj, get: obj => obj.removeShardFromZone }, metadata: _metadata }, null, _instanceExtraInitializers);
507
+ __esDecorate(_classThis, null, _removeShardTag_decorators, { kind: "method", name: "removeShardTag", static: false, private: false, access: { has: obj => "removeShardTag" in obj, get: obj => obj.removeShardTag }, metadata: _metadata }, null, _instanceExtraInitializers);
508
+ __esDecorate(_classThis, null, _enableAutoSplit_decorators, { kind: "method", name: "enableAutoSplit", static: false, private: false, access: { has: obj => "enableAutoSplit" in obj, get: obj => obj.enableAutoSplit }, metadata: _metadata }, null, _instanceExtraInitializers);
509
+ __esDecorate(_classThis, null, _disableAutoSplit_decorators, { kind: "method", name: "disableAutoSplit", static: false, private: false, access: { has: obj => "disableAutoSplit" in obj, get: obj => obj.disableAutoSplit }, metadata: _metadata }, null, _instanceExtraInitializers);
510
+ __esDecorate(_classThis, null, _splitAt_decorators, { kind: "method", name: "splitAt", static: false, private: false, access: { has: obj => "splitAt" in obj, get: obj => obj.splitAt }, metadata: _metadata }, null, _instanceExtraInitializers);
511
+ __esDecorate(_classThis, null, _splitFind_decorators, { kind: "method", name: "splitFind", static: false, private: false, access: { has: obj => "splitFind" in obj, get: obj => obj.splitFind }, metadata: _metadata }, null, _instanceExtraInitializers);
512
+ __esDecorate(_classThis, null, _moveChunk_decorators, { kind: "method", name: "moveChunk", static: false, private: false, access: { has: obj => "moveChunk" in obj, get: obj => obj.moveChunk }, metadata: _metadata }, null, _instanceExtraInitializers);
513
+ __esDecorate(_classThis, null, _balancerCollectionStatus_decorators, { kind: "method", name: "balancerCollectionStatus", static: false, private: false, access: { has: obj => "balancerCollectionStatus" in obj, get: obj => obj.balancerCollectionStatus }, metadata: _metadata }, null, _instanceExtraInitializers);
514
+ __esDecorate(_classThis, null, _enableBalancing_decorators, { kind: "method", name: "enableBalancing", static: false, private: false, access: { has: obj => "enableBalancing" in obj, get: obj => obj.enableBalancing }, metadata: _metadata }, null, _instanceExtraInitializers);
515
+ __esDecorate(_classThis, null, _disableBalancing_decorators, { kind: "method", name: "disableBalancing", static: false, private: false, access: { has: obj => "disableBalancing" in obj, get: obj => obj.disableBalancing }, metadata: _metadata }, null, _instanceExtraInitializers);
516
+ __esDecorate(_classThis, null, _getBalancerState_decorators, { kind: "method", name: "getBalancerState", static: false, private: false, access: { has: obj => "getBalancerState" in obj, get: obj => obj.getBalancerState }, metadata: _metadata }, null, _instanceExtraInitializers);
517
+ __esDecorate(_classThis, null, _isBalancerRunning_decorators, { kind: "method", name: "isBalancerRunning", static: false, private: false, access: { has: obj => "isBalancerRunning" in obj, get: obj => obj.isBalancerRunning }, metadata: _metadata }, null, _instanceExtraInitializers);
518
+ __esDecorate(_classThis, null, _startBalancer_decorators, { kind: "method", name: "startBalancer", static: false, private: false, access: { has: obj => "startBalancer" in obj, get: obj => obj.startBalancer }, metadata: _metadata }, null, _instanceExtraInitializers);
519
+ __esDecorate(_classThis, null, _stopBalancer_decorators, { kind: "method", name: "stopBalancer", static: false, private: false, access: { has: obj => "stopBalancer" in obj, get: obj => obj.stopBalancer }, metadata: _metadata }, null, _instanceExtraInitializers);
520
+ __esDecorate(_classThis, null, _setBalancerState_decorators, { kind: "method", name: "setBalancerState", static: false, private: false, access: { has: obj => "setBalancerState" in obj, get: obj => obj.setBalancerState }, metadata: _metadata }, null, _instanceExtraInitializers);
521
+ __esDecorate(_classThis, null, _getShardedDataDistribution_decorators, { kind: "method", name: "getShardedDataDistribution", static: false, private: false, access: { has: obj => "getShardedDataDistribution" in obj, get: obj => obj.getShardedDataDistribution }, metadata: _metadata }, null, _instanceExtraInitializers);
522
+ __esDecorate(_classThis, null, _startAutoMerger_decorators, { kind: "method", name: "startAutoMerger", static: false, private: false, access: { has: obj => "startAutoMerger" in obj, get: obj => obj.startAutoMerger }, metadata: _metadata }, null, _instanceExtraInitializers);
523
+ __esDecorate(_classThis, null, _stopAutoMerger_decorators, { kind: "method", name: "stopAutoMerger", static: false, private: false, access: { has: obj => "stopAutoMerger" in obj, get: obj => obj.stopAutoMerger }, metadata: _metadata }, null, _instanceExtraInitializers);
524
+ __esDecorate(_classThis, null, _isAutoMergerEnabled_decorators, { kind: "method", name: "isAutoMergerEnabled", static: false, private: false, access: { has: obj => "isAutoMergerEnabled" in obj, get: obj => obj.isAutoMergerEnabled }, metadata: _metadata }, null, _instanceExtraInitializers);
525
+ __esDecorate(_classThis, null, _disableAutoMerger_decorators, { kind: "method", name: "disableAutoMerger", static: false, private: false, access: { has: obj => "disableAutoMerger" in obj, get: obj => obj.disableAutoMerger }, metadata: _metadata }, null, _instanceExtraInitializers);
526
+ __esDecorate(_classThis, null, _enableAutoMerger_decorators, { kind: "method", name: "enableAutoMerger", static: false, private: false, access: { has: obj => "enableAutoMerger" in obj, get: obj => obj.enableAutoMerger }, metadata: _metadata }, null, _instanceExtraInitializers);
527
+ __esDecorate(_classThis, null, _checkMetadataConsistency_decorators, { kind: "method", name: "checkMetadataConsistency", static: false, private: false, access: { has: obj => "checkMetadataConsistency" in obj, get: obj => obj.checkMetadataConsistency }, metadata: _metadata }, null, _instanceExtraInitializers);
528
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
529
+ Shard = _classThis = _classDescriptor.value;
530
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
531
+ __runInitializers(_classThis, _classExtraInitializers);
532
+ })();
533
+ return Shard = _classThis;
534
+ })();
542
535
  exports.default = Shard;
543
536
  //# sourceMappingURL=shard.js.map