1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.BucketManager = exports.BucketSettings = exports.CompressionMode = exports.EvictionPolicy = exports.StorageBackend = exports.BucketType = exports.ConflictResolutionType = void 0;
|
4 | const bindingutilities_1 = require("./bindingutilities");
|
5 | const utilities_1 = require("./utilities");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var ConflictResolutionType;
|
13 | (function (ConflictResolutionType) {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | ConflictResolutionType["Timestamp"] = "lww";
|
20 | |
21 |
|
22 |
|
23 | ConflictResolutionType["SequenceNumber"] = "seqno";
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | ConflictResolutionType["Custom"] = "custom";
|
31 | })(ConflictResolutionType || (exports.ConflictResolutionType = ConflictResolutionType = {}));
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var BucketType;
|
38 | (function (BucketType) {
|
39 | |
40 |
|
41 |
|
42 | BucketType["Couchbase"] = "membase";
|
43 | |
44 |
|
45 |
|
46 | BucketType["Memcached"] = "memcached";
|
47 | |
48 |
|
49 |
|
50 | BucketType["Ephemeral"] = "ephemeral";
|
51 | })(BucketType || (exports.BucketType = BucketType = {}));
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var StorageBackend;
|
58 | (function (StorageBackend) {
|
59 | |
60 |
|
61 |
|
62 | StorageBackend["Couchstore"] = "couchstore";
|
63 | |
64 |
|
65 |
|
66 | StorageBackend["Magma"] = "magma";
|
67 | })(StorageBackend || (exports.StorageBackend = StorageBackend = {}));
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var EvictionPolicy;
|
74 | (function (EvictionPolicy) {
|
75 | |
76 |
|
77 |
|
78 | EvictionPolicy["FullEviction"] = "fullEviction";
|
79 | |
80 |
|
81 |
|
82 | EvictionPolicy["ValueOnly"] = "valueOnly";
|
83 | |
84 |
|
85 |
|
86 | EvictionPolicy["NotRecentlyUsed"] = "nruEviction";
|
87 | |
88 |
|
89 |
|
90 | EvictionPolicy["NoEviction"] = "noEviction";
|
91 | })(EvictionPolicy || (exports.EvictionPolicy = EvictionPolicy = {}));
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | var CompressionMode;
|
98 | (function (CompressionMode) {
|
99 | |
100 |
|
101 |
|
102 | CompressionMode["Off"] = "off";
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 | CompressionMode["Passive"] = "passive";
|
109 | |
110 |
|
111 |
|
112 |
|
113 | CompressionMode["Active"] = "active";
|
114 | })(CompressionMode || (exports.CompressionMode = CompressionMode = {}));
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | class BucketSettings {
|
121 | |
122 |
|
123 |
|
124 | constructor(data) {
|
125 | this.name = data.name;
|
126 | this.flushEnabled = data.flushEnabled;
|
127 | this.ramQuotaMB = data.ramQuotaMB;
|
128 | this.numReplicas = data.numReplicas;
|
129 | this.replicaIndexes = data.replicaIndexes;
|
130 | this.bucketType = data.bucketType;
|
131 | this.storageBackend = data.storageBackend;
|
132 | this.evictionPolicy = data.evictionPolicy;
|
133 | this.maxExpiry = data.maxExpiry;
|
134 | this.compressionMode = data.compressionMode;
|
135 | this.minimumDurabilityLevel = data.minimumDurabilityLevel;
|
136 | this.historyRetentionCollectionDefault =
|
137 | data.historyRetentionCollectionDefault;
|
138 | this.historyRetentionDuration = data.historyRetentionDuration;
|
139 | this.historyRetentionBytes = data.historyRetentionBytes;
|
140 | }
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 | get maxTTL() {
|
147 | var _a;
|
148 | return (_a = this.maxExpiry) !== null && _a !== void 0 ? _a : 0;
|
149 | }
|
150 | set maxTTL(val) {
|
151 | this.maxExpiry = val;
|
152 | }
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 | get ejectionMethod() {
|
159 | return this.evictionPolicy;
|
160 | }
|
161 | set ejectionMethod(val) {
|
162 | this.evictionPolicy = val;
|
163 | }
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | get durabilityMinLevel() {
|
171 | return (0, utilities_1.duraLevelToNsServerStr)(this.minimumDurabilityLevel);
|
172 | }
|
173 | |
174 |
|
175 |
|
176 | static _toCppData(data) {
|
177 | return {
|
178 | name: data.name,
|
179 | bucket_type: (0, bindingutilities_1.bucketTypeToCpp)(data.bucketType),
|
180 | ram_quota_mb: data.ramQuotaMB,
|
181 | max_expiry: data.maxTTL || data.maxExpiry,
|
182 | compression_mode: (0, bindingutilities_1.bucketCompressionModeToCpp)(data.compressionMode),
|
183 | minimum_durability_level: (0, bindingutilities_1.durabilityToCpp)((0, utilities_1.nsServerStrToDuraLevel)(data.durabilityMinLevel)) ||
|
184 | (0, bindingutilities_1.durabilityToCpp)(data.minimumDurabilityLevel),
|
185 | num_replicas: data.numReplicas,
|
186 | replica_indexes: data.replicaIndexes,
|
187 | flush_enabled: data.flushEnabled,
|
188 | eviction_policy: (0, bindingutilities_1.bucketEvictionPolicyToCpp)(data.evictionPolicy),
|
189 | storage_backend: (0, bindingutilities_1.bucketStorageBackendToCpp)(data.storageBackend),
|
190 | history_retention_collection_default: data.historyRetentionCollectionDefault,
|
191 | history_retention_bytes: data.historyRetentionBytes,
|
192 | history_retention_duration: data.historyRetentionDuration,
|
193 | };
|
194 | }
|
195 | |
196 |
|
197 |
|
198 | static _fromCppData(data) {
|
199 | return new BucketSettings({
|
200 | name: data.name,
|
201 | flushEnabled: data.flush_enabled,
|
202 | ramQuotaMB: data.ram_quota_mb,
|
203 | numReplicas: data.num_replicas,
|
204 | replicaIndexes: data.replica_indexes,
|
205 | bucketType: (0, bindingutilities_1.bucketTypeFromCpp)(data.bucket_type),
|
206 | storageBackend: (0, bindingutilities_1.bucketStorageBackendFromCpp)(data.storage_backend),
|
207 | evictionPolicy: (0, bindingutilities_1.bucketEvictionPolicyFromCpp)(data.eviction_policy),
|
208 | maxExpiry: data.max_expiry,
|
209 | compressionMode: (0, bindingutilities_1.bucketCompressionModeFromCpp)(data.compression_mode),
|
210 | historyRetentionCollectionDefault: data.history_retention_collection_default,
|
211 | historyRetentionBytes: data.history_retention_bytes,
|
212 | historyRetentionDuration: data.history_retention_duration,
|
213 | minimumDurabilityLevel: (0, bindingutilities_1.durabilityFromCpp)(data.minimum_durability_level),
|
214 | maxTTL: 0,
|
215 | durabilityMinLevel: '',
|
216 | ejectionMethod: '',
|
217 | });
|
218 | }
|
219 | }
|
220 | exports.BucketSettings = BucketSettings;
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | class CreateBucketSettings extends BucketSettings {
|
228 | |
229 |
|
230 |
|
231 | constructor(data) {
|
232 | super(data);
|
233 | this.conflictResolutionType = data.conflictResolutionType;
|
234 | }
|
235 | |
236 |
|
237 |
|
238 | static _toCppData(data) {
|
239 | return {
|
240 | ...BucketSettings._toCppData(data),
|
241 | conflict_resolution_type: (0, bindingutilities_1.bucketConflictResolutionTypeToCpp)(data.conflictResolutionType),
|
242 | };
|
243 | }
|
244 | }
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 | class BucketManager {
|
252 | |
253 |
|
254 |
|
255 | constructor(cluster) {
|
256 | this._cluster = cluster;
|
257 | }
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | async createBucket(settings, options, callback) {
|
266 | if (options instanceof Function) {
|
267 | callback = arguments[1];
|
268 | options = undefined;
|
269 | }
|
270 | if (!options) {
|
271 | options = {};
|
272 | }
|
273 | const timeout = options.timeout || this._cluster.managementTimeout;
|
274 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
275 | const bucketData = CreateBucketSettings._toCppData(settings);
|
276 | this._cluster.conn.managementBucketCreate({
|
277 | bucket: bucketData,
|
278 | timeout: timeout,
|
279 | }, (cppErr) => {
|
280 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
281 | if (err) {
|
282 | return wrapCallback(err, null);
|
283 | }
|
284 | wrapCallback(err);
|
285 | });
|
286 | }, callback);
|
287 | }
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 | async updateBucket(settings, options, callback) {
|
296 | if (options instanceof Function) {
|
297 | callback = arguments[1];
|
298 | options = undefined;
|
299 | }
|
300 | if (!options) {
|
301 | options = {};
|
302 | }
|
303 | const timeout = options.timeout || this._cluster.managementTimeout;
|
304 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
305 | const bucketData = BucketSettings._toCppData(settings);
|
306 | this._cluster.conn.managementBucketUpdate({
|
307 | bucket: bucketData,
|
308 | timeout: timeout,
|
309 | }, (cppErr) => {
|
310 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
311 | if (err) {
|
312 | return wrapCallback(err, null);
|
313 | }
|
314 | wrapCallback(err);
|
315 | });
|
316 | }, callback);
|
317 | }
|
318 | |
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | async dropBucket(bucketName, options, callback) {
|
326 | if (options instanceof Function) {
|
327 | callback = arguments[1];
|
328 | options = undefined;
|
329 | }
|
330 | if (!options) {
|
331 | options = {};
|
332 | }
|
333 | const timeout = options.timeout || this._cluster.managementTimeout;
|
334 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
335 | this._cluster.conn.managementBucketDrop({
|
336 | name: bucketName,
|
337 | timeout: timeout,
|
338 | }, (cppErr) => {
|
339 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
340 | if (err) {
|
341 | return wrapCallback(err, null);
|
342 | }
|
343 | wrapCallback(err);
|
344 | });
|
345 | }, callback);
|
346 | }
|
347 | |
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | async getBucket(bucketName, options, callback) {
|
355 | if (options instanceof Function) {
|
356 | callback = arguments[1];
|
357 | options = undefined;
|
358 | }
|
359 | if (!options) {
|
360 | options = {};
|
361 | }
|
362 | const timeout = options.timeout || this._cluster.managementTimeout;
|
363 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
364 | this._cluster.conn.managementBucketGet({
|
365 | name: bucketName,
|
366 | timeout: timeout,
|
367 | }, (cppErr, resp) => {
|
368 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
369 | if (err) {
|
370 | return wrapCallback(err, null);
|
371 | }
|
372 | const bucket = BucketSettings._fromCppData(resp.bucket);
|
373 | wrapCallback(null, bucket);
|
374 | });
|
375 | }, callback);
|
376 | }
|
377 | |
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 | async getAllBuckets(options, callback) {
|
384 | if (options instanceof Function) {
|
385 | callback = arguments[0];
|
386 | options = undefined;
|
387 | }
|
388 | if (!options) {
|
389 | options = {};
|
390 | }
|
391 | const timeout = options.timeout || this._cluster.managementTimeout;
|
392 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
393 | this._cluster.conn.managementBucketGetAll({
|
394 | timeout: timeout,
|
395 | }, (cppErr, resp) => {
|
396 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
397 | if (err) {
|
398 | return wrapCallback(err, null);
|
399 | }
|
400 | const buckets = resp.buckets.map((bucketData) => BucketSettings._fromCppData(bucketData));
|
401 | wrapCallback(null, buckets);
|
402 | });
|
403 | }, callback);
|
404 | }
|
405 | |
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | async flushBucket(bucketName, options, callback) {
|
413 | if (options instanceof Function) {
|
414 | callback = arguments[1];
|
415 | options = undefined;
|
416 | }
|
417 | if (!options) {
|
418 | options = {};
|
419 | }
|
420 | const timeout = options.timeout || this._cluster.managementTimeout;
|
421 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
422 | this._cluster.conn.managementBucketFlush({
|
423 | name: bucketName,
|
424 | timeout: timeout,
|
425 | }, (cppErr) => {
|
426 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
427 | if (err) {
|
428 | return wrapCallback(err, null);
|
429 | }
|
430 | wrapCallback(err);
|
431 | });
|
432 | }, callback);
|
433 | }
|
434 | }
|
435 | exports.BucketManager = BucketManager;
|