1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AnalyticsIndexManager = exports.AzureExternalAnalyticsLink = exports.S3ExternalAnalyticsLink = exports.CouchbaseRemoteAnalyticsLink = exports.AnalyticsLink = exports.CouchbaseAnalyticsEncryptionSettings = exports.AnalyticsIndex = exports.AnalyticsDataset = exports.AnalyticsEncryptionLevel = exports.AnalyticsLinkType = void 0;
|
4 | const errors_1 = require("./errors");
|
5 | const httpexecutor_1 = require("./httpexecutor");
|
6 | const utilities_1 = require("./utilities");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var AnalyticsLinkType;
|
13 | (function (AnalyticsLinkType) {
|
14 | |
15 |
|
16 |
|
17 | AnalyticsLinkType["S3External"] = "s3";
|
18 | |
19 |
|
20 |
|
21 | AnalyticsLinkType["AzureBlobExternal"] = "azureblob";
|
22 | |
23 |
|
24 |
|
25 | AnalyticsLinkType["CouchbaseRemote"] = "couchbase";
|
26 | })(AnalyticsLinkType || (exports.AnalyticsLinkType = AnalyticsLinkType = {}));
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var AnalyticsEncryptionLevel;
|
33 | (function (AnalyticsEncryptionLevel) {
|
34 | |
35 |
|
36 |
|
37 | AnalyticsEncryptionLevel["None"] = "none";
|
38 | |
39 |
|
40 |
|
41 | AnalyticsEncryptionLevel["Half"] = "half";
|
42 | |
43 |
|
44 |
|
45 | AnalyticsEncryptionLevel["Full"] = "full";
|
46 | })(AnalyticsEncryptionLevel || (exports.AnalyticsEncryptionLevel = AnalyticsEncryptionLevel = {}));
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | class AnalyticsDataset {
|
53 | |
54 |
|
55 |
|
56 | constructor(data) {
|
57 | this.name = data.name;
|
58 | this.dataverseName = data.dataverseName;
|
59 | this.linkName = data.linkName;
|
60 | this.bucketName = data.bucketName;
|
61 | }
|
62 | }
|
63 | exports.AnalyticsDataset = AnalyticsDataset;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | class AnalyticsIndex {
|
70 | |
71 |
|
72 |
|
73 | constructor(data) {
|
74 | this.name = data.name;
|
75 | this.datasetName = data.datasetName;
|
76 | this.dataverseName = data.dataverseName;
|
77 | this.isPrimary = data.isPrimary;
|
78 | }
|
79 | }
|
80 | exports.AnalyticsIndex = AnalyticsIndex;
|
81 |
|
82 |
|
83 |
|
84 | class CouchbaseAnalyticsEncryptionSettings {
|
85 | |
86 |
|
87 |
|
88 | constructor(data) {
|
89 | this.encryptionLevel = data.encryptionLevel;
|
90 | this.certificate = data.certificate;
|
91 | this.clientCertificate = data.clientCertificate;
|
92 | this.clientKey = data.clientKey;
|
93 | }
|
94 | }
|
95 | exports.CouchbaseAnalyticsEncryptionSettings = CouchbaseAnalyticsEncryptionSettings;
|
96 |
|
97 |
|
98 |
|
99 | class AnalyticsLink {
|
100 | |
101 |
|
102 |
|
103 | constructor() {
|
104 | this.linkType = '';
|
105 | }
|
106 | |
107 |
|
108 |
|
109 | static _toHttpData(data) {
|
110 | if (data.linkType === AnalyticsLinkType.CouchbaseRemote) {
|
111 | return CouchbaseRemoteAnalyticsLink._toHttpData(data);
|
112 | }
|
113 | else if (data.linkType === AnalyticsLinkType.S3External) {
|
114 | return S3ExternalAnalyticsLink._toHttpData(data);
|
115 | }
|
116 | else if (data.linkType === AnalyticsLinkType.AzureBlobExternal) {
|
117 | return AzureExternalAnalyticsLink._toHttpData(data);
|
118 | }
|
119 | else {
|
120 | throw new Error('invalid link type');
|
121 | }
|
122 | }
|
123 | |
124 |
|
125 |
|
126 | static _fromHttpData(data) {
|
127 | if (data.type === 'couchbase') {
|
128 | return CouchbaseRemoteAnalyticsLink._fromHttpData(data);
|
129 | }
|
130 | else if (data.type === 's3') {
|
131 | return S3ExternalAnalyticsLink._fromHttpData(data);
|
132 | }
|
133 | else if (data.type === 'azure') {
|
134 | return AzureExternalAnalyticsLink._fromHttpData(data);
|
135 | }
|
136 | else {
|
137 | throw new Error('invalid link type');
|
138 | }
|
139 | }
|
140 | }
|
141 | exports.AnalyticsLink = AnalyticsLink;
|
142 |
|
143 |
|
144 |
|
145 | class CouchbaseRemoteAnalyticsLink extends AnalyticsLink {
|
146 | |
147 |
|
148 |
|
149 | constructor(data) {
|
150 | super();
|
151 | this.linkType = AnalyticsLinkType.CouchbaseRemote;
|
152 | this.dataverse = data.dataverse;
|
153 | this.name = data.name;
|
154 | this.hostname = data.hostname;
|
155 | this.encryption = data.encryption;
|
156 | this.username = data.username;
|
157 | this.password = data.password;
|
158 | }
|
159 | |
160 |
|
161 |
|
162 | static _toHttpData(data) {
|
163 | let dvSpecific;
|
164 | if (data.dataverse.indexOf('/') !== -1) {
|
165 | const encDataverse = encodeURIComponent(data.dataverse);
|
166 | const encName = encodeURIComponent(data.name);
|
167 | dvSpecific = {
|
168 | httpPath: `/analytics/link/${encDataverse}/${encName}`,
|
169 | };
|
170 | }
|
171 | else {
|
172 | dvSpecific = {
|
173 | httpPath: `/analytics/link`,
|
174 | dataverse: data.dataverse,
|
175 | name: data.name,
|
176 | };
|
177 | }
|
178 | return {
|
179 | type: 'couchbase',
|
180 | ...dvSpecific,
|
181 | hostname: data.hostname,
|
182 | username: data.username,
|
183 | password: data.password,
|
184 | encryption: data.encryption ? data.encryption.encryptionLevel : undefined,
|
185 | certificate: data.encryption
|
186 | ? data.encryption.certificate
|
187 | ? data.encryption.certificate.toString()
|
188 | : undefined
|
189 | : undefined,
|
190 | clientCertificate: data.encryption
|
191 | ? data.encryption.clientCertificate
|
192 | ? data.encryption.clientCertificate.toString()
|
193 | : undefined
|
194 | : undefined,
|
195 | clientKey: data.encryption
|
196 | ? data.encryption.clientKey
|
197 | ? data.encryption.clientKey.toString()
|
198 | : undefined
|
199 | : undefined,
|
200 | };
|
201 | }
|
202 | |
203 |
|
204 |
|
205 | static _fromHttpData(data) {
|
206 | return new CouchbaseRemoteAnalyticsLink({
|
207 | linkType: AnalyticsLinkType.CouchbaseRemote,
|
208 | dataverse: data.dataverse || data.scope,
|
209 | name: data.name,
|
210 | hostname: data.activeHostname,
|
211 | encryption: new CouchbaseAnalyticsEncryptionSettings({
|
212 | encryptionLevel: data.encryption,
|
213 | certificate: Buffer.from(data.certificate),
|
214 | clientCertificate: Buffer.from(data.clientCertificate),
|
215 | clientKey: Buffer.from(data.clientKey),
|
216 | }),
|
217 | username: data.username,
|
218 | password: undefined,
|
219 | });
|
220 | }
|
221 | }
|
222 | exports.CouchbaseRemoteAnalyticsLink = CouchbaseRemoteAnalyticsLink;
|
223 |
|
224 |
|
225 |
|
226 | class S3ExternalAnalyticsLink extends AnalyticsLink {
|
227 | |
228 |
|
229 |
|
230 | constructor(data) {
|
231 | super();
|
232 | this.linkType = AnalyticsLinkType.S3External;
|
233 | this.dataverse = data.dataverse;
|
234 | this.name = data.name;
|
235 | this.accessKeyId = data.accessKeyId;
|
236 | this.secretAccessKey = data.secretAccessKey;
|
237 | this.sessionToken = data.sessionToken;
|
238 | this.region = data.region;
|
239 | this.serviceEndpoint = data.serviceEndpoint;
|
240 | }
|
241 | |
242 |
|
243 |
|
244 | static _toHttpData(data) {
|
245 | let dvSpecific;
|
246 | if (data.dataverse.indexOf('/') !== -1) {
|
247 | const encDataverse = encodeURIComponent(data.dataverse);
|
248 | const encName = encodeURIComponent(data.name);
|
249 | dvSpecific = {
|
250 | httpPath: `/analytics/link/${encDataverse}/${encName}`,
|
251 | };
|
252 | }
|
253 | else {
|
254 | dvSpecific = {
|
255 | httpPath: `/analytics/link`,
|
256 | dataverse: data.dataverse,
|
257 | name: data.name,
|
258 | };
|
259 | }
|
260 | return {
|
261 | type: 's3',
|
262 | ...dvSpecific,
|
263 | accessKeyId: data.accessKeyId,
|
264 | secretAccessKey: data.secretAccessKey,
|
265 | region: data.region,
|
266 | sessionToken: data.sessionToken,
|
267 | serviceEndpoint: data.serviceEndpoint,
|
268 | };
|
269 | }
|
270 | |
271 |
|
272 |
|
273 | static _fromHttpData(data) {
|
274 | return new S3ExternalAnalyticsLink({
|
275 | linkType: AnalyticsLinkType.S3External,
|
276 | dataverse: data.dataverse || data.scope,
|
277 | name: data.name,
|
278 | accessKeyId: data.accessKeyId,
|
279 | secretAccessKey: undefined,
|
280 | region: data.region,
|
281 | sessionToken: undefined,
|
282 | serviceEndpoint: data.serviceEndpoint,
|
283 | });
|
284 | }
|
285 | }
|
286 | exports.S3ExternalAnalyticsLink = S3ExternalAnalyticsLink;
|
287 |
|
288 |
|
289 |
|
290 | class AzureExternalAnalyticsLink extends AnalyticsLink {
|
291 | |
292 |
|
293 |
|
294 | constructor(data) {
|
295 | super();
|
296 | this.linkType = AnalyticsLinkType.AzureBlobExternal;
|
297 | this.dataverse = data.dataverse;
|
298 | this.name = data.name;
|
299 | this.connectionString = data.connectionString;
|
300 | this.accountName = data.accountName;
|
301 | this.accountKey = data.accountKey;
|
302 | this.sharedAccessSignature = data.sharedAccessSignature;
|
303 | this.blobEndpoint = data.blobEndpoint;
|
304 | this.endpointSuffix = data.endpointSuffix;
|
305 | }
|
306 | |
307 |
|
308 |
|
309 | static _toHttpData(data) {
|
310 | let dvSpecific;
|
311 | if (data.dataverse.indexOf('/') !== -1) {
|
312 | const encDataverse = encodeURIComponent(data.dataverse);
|
313 | const encName = encodeURIComponent(data.name);
|
314 | dvSpecific = {
|
315 | httpPath: `/analytics/link/${encDataverse}/${encName}`,
|
316 | };
|
317 | }
|
318 | else {
|
319 | dvSpecific = {
|
320 | httpPath: `/analytics/link`,
|
321 | dataverse: data.dataverse,
|
322 | name: data.name,
|
323 | };
|
324 | }
|
325 | return {
|
326 | type: 'azure',
|
327 | ...dvSpecific,
|
328 | connectionString: data.connectionString,
|
329 | accountName: data.accountName,
|
330 | accountKey: data.accountKey,
|
331 | sharedAccessSignature: data.sharedAccessSignature,
|
332 | blobEndpoint: data.blobEndpoint,
|
333 | endpointSuffix: data.endpointSuffix,
|
334 | };
|
335 | }
|
336 | |
337 |
|
338 |
|
339 | static _fromHttpData(data) {
|
340 | return new AzureExternalAnalyticsLink({
|
341 | linkType: AnalyticsLinkType.AzureBlobExternal,
|
342 | dataverse: data.dataverse || data.scope,
|
343 | name: data.name,
|
344 | connectionString: undefined,
|
345 | accountName: data.accountName,
|
346 | accountKey: undefined,
|
347 | sharedAccessSignature: undefined,
|
348 | blobEndpoint: data.blobEndpoint,
|
349 | endpointSuffix: data.endpointSuffix,
|
350 | });
|
351 | }
|
352 | }
|
353 | exports.AzureExternalAnalyticsLink = AzureExternalAnalyticsLink;
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | class AnalyticsIndexManager {
|
361 | |
362 |
|
363 |
|
364 | constructor(cluster) {
|
365 | this._cluster = cluster;
|
366 | }
|
367 | get _http() {
|
368 | return new httpexecutor_1.HttpExecutor(this._cluster.conn);
|
369 | }
|
370 | |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | async createDataverse(dataverseName, options, callback) {
|
378 | if (options instanceof Function) {
|
379 | callback = arguments[1];
|
380 | options = undefined;
|
381 | }
|
382 | if (!options) {
|
383 | options = {};
|
384 | }
|
385 | let qs = '';
|
386 | qs += 'CREATE DATAVERSE';
|
387 | qs += ' `' + dataverseName.split('/').join('`.`') + '`';
|
388 | if (options.ignoreIfExists) {
|
389 | qs += ' IF NOT EXISTS';
|
390 | }
|
391 | const timeout = options.timeout || this._cluster.managementTimeout;
|
392 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
393 | try {
|
394 | await this._cluster.analyticsQuery(qs, {
|
395 | timeout: timeout,
|
396 | });
|
397 | }
|
398 | catch (err) {
|
399 | if (err instanceof errors_1.DataverseExistsError) {
|
400 | throw err;
|
401 | }
|
402 | throw new errors_1.CouchbaseError('failed to create dataverse', err);
|
403 | }
|
404 | }, callback);
|
405 | }
|
406 | |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 | async dropDataverse(dataverseName, options, callback) {
|
414 | if (options instanceof Function) {
|
415 | callback = arguments[1];
|
416 | options = undefined;
|
417 | }
|
418 | if (!options) {
|
419 | options = {};
|
420 | }
|
421 | let qs = '';
|
422 | qs += 'DROP DATAVERSE';
|
423 | qs += ' `' + dataverseName.split('/').join('`.`') + '`';
|
424 | if (options.ignoreIfNotExists) {
|
425 | qs += ' IF EXISTS';
|
426 | }
|
427 | const timeout = options.timeout || this._cluster.managementTimeout;
|
428 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
429 | try {
|
430 | await this._cluster.analyticsQuery(qs, {
|
431 | timeout: timeout,
|
432 | });
|
433 | }
|
434 | catch (err) {
|
435 | if (err instanceof errors_1.DataverseNotFoundError) {
|
436 | throw err;
|
437 | }
|
438 | throw new errors_1.CouchbaseError('failed to drop dataverse', err);
|
439 | }
|
440 | }, callback);
|
441 | }
|
442 | |
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 | async createDataset(bucketName, datasetName, options, callback) {
|
451 | if (options instanceof Function) {
|
452 | callback = arguments[2];
|
453 | options = undefined;
|
454 | }
|
455 | if (!options) {
|
456 | options = {};
|
457 | }
|
458 | let qs = '';
|
459 | qs += 'CREATE DATASET';
|
460 | if (options.ignoreIfExists) {
|
461 | qs += ' IF NOT EXISTS';
|
462 | }
|
463 | if (options.dataverseName) {
|
464 | qs +=
|
465 | ' `' +
|
466 | options.dataverseName.split('/').join('`.`') +
|
467 | '`.`' +
|
468 | datasetName +
|
469 | '`';
|
470 | }
|
471 | else {
|
472 | qs += ' `' + datasetName + '`';
|
473 | }
|
474 | qs += ' ON `' + bucketName + '`';
|
475 | if (options.condition) {
|
476 | qs += ' WHERE ' + options.condition;
|
477 | }
|
478 | const timeout = options.timeout || this._cluster.managementTimeout;
|
479 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
480 | try {
|
481 | await this._cluster.analyticsQuery(qs, {
|
482 | timeout: timeout,
|
483 | });
|
484 | }
|
485 | catch (err) {
|
486 | if (err instanceof errors_1.DatasetExistsError) {
|
487 | throw err;
|
488 | }
|
489 | throw new errors_1.CouchbaseError('failed to create dataset', err);
|
490 | }
|
491 | }, callback);
|
492 | }
|
493 | |
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 | async dropDataset(datasetName, options, callback) {
|
501 | if (options instanceof Function) {
|
502 | callback = arguments[1];
|
503 | options = undefined;
|
504 | }
|
505 | if (!options) {
|
506 | options = {};
|
507 | }
|
508 | let qs = '';
|
509 | qs += 'DROP DATASET';
|
510 | if (options.dataverseName) {
|
511 | qs +=
|
512 | ' `' +
|
513 | options.dataverseName.split('/').join('`.`') +
|
514 | '`.`' +
|
515 | datasetName +
|
516 | '`';
|
517 | }
|
518 | else {
|
519 | qs += ' `' + datasetName + '`';
|
520 | }
|
521 | if (options.ignoreIfNotExists) {
|
522 | qs += ' IF EXISTS';
|
523 | }
|
524 | const timeout = options.timeout || this._cluster.managementTimeout;
|
525 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
526 | try {
|
527 | await this._cluster.analyticsQuery(qs, {
|
528 | timeout: timeout,
|
529 | });
|
530 | }
|
531 | catch (err) {
|
532 | if (err instanceof errors_1.DatasetNotFoundError) {
|
533 | throw err;
|
534 | }
|
535 | throw new errors_1.CouchbaseError('failed to drop dataset', err);
|
536 | }
|
537 | }, callback);
|
538 | }
|
539 | |
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 | async getAllDatasets(options, callback) {
|
546 | if (options instanceof Function) {
|
547 | callback = arguments[0];
|
548 | options = undefined;
|
549 | }
|
550 | if (!options) {
|
551 | options = {};
|
552 | }
|
553 | const qs = 'SELECT d.* FROM `Metadata`.`Dataset` d WHERE d.DataverseName <> "Metadata"';
|
554 | const timeout = options.timeout || this._cluster.managementTimeout;
|
555 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
556 | const res = await this._cluster.analyticsQuery(qs, {
|
557 | timeout: timeout,
|
558 | });
|
559 | const datasets = res.rows.map((row) => new AnalyticsDataset({
|
560 | name: row.DatasetName,
|
561 | dataverseName: row.DataverseName,
|
562 | linkName: row.LinkName,
|
563 | bucketName: row.BucketName,
|
564 | }));
|
565 | return datasets;
|
566 | }, callback);
|
567 | }
|
568 | |
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 | async createIndex(datasetName, indexName, fields, options, callback) {
|
578 | if (options instanceof Function) {
|
579 | callback = arguments[3];
|
580 | options = undefined;
|
581 | }
|
582 | if (!options) {
|
583 | options = {};
|
584 | }
|
585 | let qs = '';
|
586 | qs += 'CREATE INDEX';
|
587 | qs += ' `' + indexName + '`';
|
588 | if (options.ignoreIfExists) {
|
589 | qs += ' IF NOT EXISTS';
|
590 | }
|
591 | if (options.dataverseName) {
|
592 | qs +=
|
593 | ' ON `' +
|
594 | options.dataverseName.split('/').join('`.`') +
|
595 | '`.`' +
|
596 | datasetName +
|
597 | '`';
|
598 | }
|
599 | else {
|
600 | qs += ' ON `' + datasetName + '`';
|
601 | }
|
602 | qs += ' (';
|
603 | qs += Object.keys(fields)
|
604 | .map((i) => '`' + i + '`: ' + fields[i])
|
605 | .join(', ');
|
606 | qs += ')';
|
607 | const timeout = options.timeout || this._cluster.managementTimeout;
|
608 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
609 | await this._cluster.analyticsQuery(qs, {
|
610 | timeout: timeout,
|
611 | });
|
612 | }, callback);
|
613 | }
|
614 | |
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 | async dropIndex(datasetName, indexName, options, callback) {
|
623 | if (options instanceof Function) {
|
624 | callback = arguments[2];
|
625 | options = undefined;
|
626 | }
|
627 | if (!options) {
|
628 | options = {};
|
629 | }
|
630 | let qs = '';
|
631 | qs += 'DROP INDEX';
|
632 | if (options.dataverseName) {
|
633 | qs +=
|
634 | ' `' +
|
635 | options.dataverseName.split('/').join('`.`') +
|
636 | '`.`' +
|
637 | datasetName +
|
638 | '`';
|
639 | }
|
640 | else {
|
641 | qs += ' `' + datasetName + '`';
|
642 | }
|
643 | qs += '.`' + indexName + '`';
|
644 | if (options.ignoreIfNotExists) {
|
645 | qs += ' IF EXISTS';
|
646 | }
|
647 | const timeout = options.timeout || this._cluster.managementTimeout;
|
648 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
649 | await this._cluster.analyticsQuery(qs, {
|
650 | timeout: timeout,
|
651 | });
|
652 | }, callback);
|
653 | }
|
654 | |
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | async getAllIndexes(options, callback) {
|
661 | if (options instanceof Function) {
|
662 | callback = arguments[0];
|
663 | options = undefined;
|
664 | }
|
665 | if (!options) {
|
666 | options = {};
|
667 | }
|
668 | const qs = 'SELECT d.* FROM `Metadata`.`Index` d WHERE d.DataverseName <> "Metadata"';
|
669 | const timeout = options.timeout || this._cluster.managementTimeout;
|
670 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
671 | const res = await this._cluster.analyticsQuery(qs, {
|
672 | timeout: timeout,
|
673 | });
|
674 | const indexes = res.rows.map((row) => new AnalyticsIndex({
|
675 | name: row.IndexName,
|
676 | datasetName: row.DatasetName,
|
677 | dataverseName: row.DataverseName,
|
678 | isPrimary: row.IsPrimary,
|
679 | }));
|
680 | return indexes;
|
681 | }, callback);
|
682 | }
|
683 | |
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 | async connectLink(linkName, options, callback) {
|
691 | if (options instanceof Function) {
|
692 | callback = arguments[1];
|
693 | options = undefined;
|
694 | }
|
695 | if (!options) {
|
696 | options = {};
|
697 | }
|
698 | const qs = 'CONNECT LINK ' + linkName;
|
699 | const timeout = options.timeout || this._cluster.managementTimeout;
|
700 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
701 | await this._cluster.analyticsQuery(qs, {
|
702 | timeout: timeout,
|
703 | });
|
704 | }, callback);
|
705 | }
|
706 | |
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 | async disconnectLink(linkName, options, callback) {
|
714 | if (options instanceof Function) {
|
715 | callback = arguments[1];
|
716 | options = undefined;
|
717 | }
|
718 | if (!options) {
|
719 | options = {};
|
720 | }
|
721 | const qs = 'DISCONNECT LINK ' + linkName;
|
722 | const timeout = options.timeout || this._cluster.managementTimeout;
|
723 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
724 | await this._cluster.analyticsQuery(qs, {
|
725 | timeout: timeout,
|
726 | });
|
727 | }, callback);
|
728 | }
|
729 | |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 | async getPendingMutations(options, callback) {
|
736 | if (options instanceof Function) {
|
737 | callback = arguments[0];
|
738 | options = undefined;
|
739 | }
|
740 | if (!options) {
|
741 | options = {};
|
742 | }
|
743 | const timeout = options.timeout || this._cluster.managementTimeout;
|
744 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
745 | const res = await this._http.request({
|
746 | type: httpexecutor_1.HttpServiceType.Analytics,
|
747 | method: httpexecutor_1.HttpMethod.Get,
|
748 | path: `/analytics/node/agg/stats/remaining`,
|
749 | timeout: timeout,
|
750 | });
|
751 | if (res.statusCode !== 200) {
|
752 | const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
|
753 | throw new errors_1.CouchbaseError('failed to get pending mutations', undefined, errCtx);
|
754 | }
|
755 | return JSON.parse(res.body.toString());
|
756 | }, callback);
|
757 | }
|
758 | |
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 | async createLink(link, options, callback) {
|
766 | if (options instanceof Function) {
|
767 | callback = arguments[1];
|
768 | options = undefined;
|
769 | }
|
770 | if (!options) {
|
771 | options = {};
|
772 | }
|
773 | const timeout = options.timeout || this._cluster.managementTimeout;
|
774 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
775 | const linkData = AnalyticsLink._toHttpData(link);
|
776 | const res = await this._http.request({
|
777 | type: httpexecutor_1.HttpServiceType.Analytics,
|
778 | method: httpexecutor_1.HttpMethod.Post,
|
779 | path: linkData.httpPath,
|
780 | contentType: 'application/x-www-form-urlencoded',
|
781 | body: (0, utilities_1.cbQsStringify)({
|
782 | linkData,
|
783 | httpPath: undefined,
|
784 | }),
|
785 | timeout: timeout,
|
786 | });
|
787 | if (res.statusCode !== 200) {
|
788 | const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
|
789 | const errText = res.body.toString().toLowerCase();
|
790 | if (errText.includes('24055')) {
|
791 | throw new errors_1.LinkExistsError(undefined, errCtx);
|
792 | }
|
793 | else if (errText.includes('24034')) {
|
794 | throw new errors_1.DataverseNotFoundError(undefined, errCtx);
|
795 | }
|
796 | throw new errors_1.CouchbaseError('failed to create link', undefined, errCtx);
|
797 | }
|
798 | }, callback);
|
799 | }
|
800 | |
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 | async replaceLink(link, options, callback) {
|
808 | if (options instanceof Function) {
|
809 | callback = arguments[1];
|
810 | options = undefined;
|
811 | }
|
812 | if (!options) {
|
813 | options = {};
|
814 | }
|
815 | const timeout = options.timeout || this._cluster.managementTimeout;
|
816 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
817 | const linkData = AnalyticsLink._toHttpData(link);
|
818 | const res = await this._http.request({
|
819 | type: httpexecutor_1.HttpServiceType.Analytics,
|
820 | method: httpexecutor_1.HttpMethod.Put,
|
821 | path: linkData.httpPath,
|
822 | contentType: 'application/x-www-form-urlencoded',
|
823 | body: (0, utilities_1.cbQsStringify)({
|
824 | linkData,
|
825 | httpPath: undefined,
|
826 | }),
|
827 | timeout: timeout,
|
828 | });
|
829 | if (res.statusCode !== 200) {
|
830 | const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
|
831 | const errText = res.body.toString().toLowerCase();
|
832 | if (errText.includes('24055')) {
|
833 | throw new errors_1.LinkExistsError(undefined, errCtx);
|
834 | }
|
835 | else if (errText.includes('24034')) {
|
836 | throw new errors_1.DataverseNotFoundError(undefined, errCtx);
|
837 | }
|
838 | throw new errors_1.CouchbaseError('failed to replace link', undefined, errCtx);
|
839 | }
|
840 | }, callback);
|
841 | }
|
842 | |
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 | async dropLink(linkName, dataverseName, options, callback) {
|
851 | if (options instanceof Function) {
|
852 | callback = arguments[2];
|
853 | options = undefined;
|
854 | }
|
855 | if (!options) {
|
856 | options = {};
|
857 | }
|
858 | const timeout = options.timeout || this._cluster.managementTimeout;
|
859 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
860 | let httpPath;
|
861 | let httpParams;
|
862 | if (dataverseName.indexOf('/') !== -1) {
|
863 | const encDataverse = encodeURIComponent(dataverseName);
|
864 | const encName = encodeURIComponent(linkName);
|
865 | httpPath = `/analytics/link/${encDataverse}/${encName}`;
|
866 | httpParams = {};
|
867 | }
|
868 | else {
|
869 | httpPath = `/analytics/link`;
|
870 | httpParams = {
|
871 | dataverse: dataverseName,
|
872 | name: linkName,
|
873 | };
|
874 | }
|
875 | const res = await this._http.request({
|
876 | type: httpexecutor_1.HttpServiceType.Analytics,
|
877 | method: httpexecutor_1.HttpMethod.Delete,
|
878 | path: httpPath,
|
879 | contentType: 'application/x-www-form-urlencoded',
|
880 | body: (0, utilities_1.cbQsStringify)(httpParams),
|
881 | timeout: timeout,
|
882 | });
|
883 | if (res.statusCode !== 200) {
|
884 | const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
|
885 | const errText = res.body.toString().toLowerCase();
|
886 | if (errText.includes('24055')) {
|
887 | throw new errors_1.LinkExistsError(undefined, errCtx);
|
888 | }
|
889 | else if (errText.includes('24034')) {
|
890 | throw new errors_1.DataverseNotFoundError(undefined, errCtx);
|
891 | }
|
892 | throw new errors_1.CouchbaseError('failed to delete link', undefined, errCtx);
|
893 | }
|
894 | }, callback);
|
895 | }
|
896 | |
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 | async getAllLinks(options, callback) {
|
903 | if (options instanceof Function) {
|
904 | callback = arguments[0];
|
905 | options = undefined;
|
906 | }
|
907 | if (!options) {
|
908 | options = {};
|
909 | }
|
910 | const dataverseName = options.dataverse;
|
911 | const linkName = options.name;
|
912 | const linkType = options.linkType;
|
913 | const timeout = options.timeout || this._cluster.managementTimeout;
|
914 | return utilities_1.PromiseHelper.wrapAsync(async () => {
|
915 | let httpPath;
|
916 | if (dataverseName && dataverseName.indexOf('/') !== -1) {
|
917 | const encDataverse = encodeURIComponent(dataverseName);
|
918 | httpPath = `/analytics/link/${encDataverse}`;
|
919 | if (linkName) {
|
920 | const encName = encodeURIComponent(linkName);
|
921 | httpPath += `/${encName}`;
|
922 | }
|
923 | httpPath += '?';
|
924 | if (linkType) {
|
925 | httpPath += `type=${linkType}&`;
|
926 | }
|
927 | }
|
928 | else {
|
929 | httpPath = `/analytics/link?`;
|
930 | if (dataverseName) {
|
931 | httpPath += `dataverse=${dataverseName}&`;
|
932 | if (linkName) {
|
933 | httpPath += `dataverse=${linkName}&`;
|
934 | }
|
935 | }
|
936 | if (linkType) {
|
937 | httpPath += `type=${linkType}&`;
|
938 | }
|
939 | }
|
940 | const res = await this._http.request({
|
941 | type: httpexecutor_1.HttpServiceType.Analytics,
|
942 | method: httpexecutor_1.HttpMethod.Get,
|
943 | path: httpPath,
|
944 | timeout: timeout,
|
945 | });
|
946 | if (res.statusCode !== 200) {
|
947 | const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
|
948 | const errText = res.body.toString().toLowerCase();
|
949 | if (errText.includes('24034')) {
|
950 | throw new errors_1.DataverseNotFoundError(undefined, errCtx);
|
951 | }
|
952 | throw new errors_1.CouchbaseError('failed to get links', undefined, errCtx);
|
953 | }
|
954 | const linksData = JSON.parse(res.body.toString());
|
955 | const links = linksData.map((linkData) => AnalyticsLink._fromHttpData(linkData));
|
956 | return links;
|
957 | }, callback);
|
958 | }
|
959 | }
|
960 | exports.AnalyticsIndexManager = AnalyticsIndexManager;
|