@samet-it/be-couchbase-common 1.1.7 → 1.1.8

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.
@@ -9,12 +9,32 @@ const env_1 = require("@leyyo/env");
9
9
  exports.couchbaseCommonConfig = env_1.envCore.configure
10
10
  .scope('CouchbaseCommon', 'CB')
11
11
  .start()
12
- .field('PROTOCOL').text().def('couchbase').end()
13
- .field('HOST').text().required().end()
14
- .field('PORT').integer().end()
15
- .field('USER').text().required().end()
16
- .field('PASS').text().required().end()
17
- .field('BUCKET').text().required().end()
18
- .field('SCOPE').text().required().end()
19
- .field('CREATE_INDICES').boolean().def(false).end()
12
+ // @formatter:off
13
+ .field('ENABLED')
14
+ .boolean().def(true).end()
15
+ .field('PROTOCOL')
16
+ .off(v => !v.ENABLED)
17
+ .text().def('couchbase').end()
18
+ .field('HOST')
19
+ .off(v => !v.ENABLED)
20
+ .text().required().end()
21
+ .field('PORT')
22
+ .off(v => !v.ENABLED)
23
+ .integer().end()
24
+ .field('USER')
25
+ .off(v => !v.ENABLED)
26
+ .text().required().end()
27
+ .field('PASS')
28
+ .off(v => !v.ENABLED)
29
+ .text().required().end()
30
+ .field('BUCKET')
31
+ .off(v => !v.ENABLED)
32
+ .text().required().end()
33
+ .field('SCOPE')
34
+ .off(v => !v.ENABLED)
35
+ .text().required().end()
36
+ .field('CREATE_INDICES')
37
+ .off(v => !v.ENABLED)
38
+ .boolean().def(false).end()
39
+ // @formatter:on
20
40
  .finish();
@@ -1,5 +1,9 @@
1
1
  import type { EnvBase } from "@leyyo/env";
2
2
  export interface CouchbaseCommonConf extends EnvBase {
3
+ /**
4
+ * Protocol
5
+ * */
6
+ readonly ENABLED: boolean;
3
7
  /**
4
8
  * Protocol
5
9
  * */
@@ -167,6 +167,9 @@ class CbConnection extends be_db_common_1.DbConnection {
167
167
  /** {@inheritDoc} */
168
168
  more(link, lines, p1) {
169
169
  return __awaiter(this, void 0, void 0, function* () {
170
+ if (!this._props.enabled) {
171
+ return { success: true, rows: [] };
172
+ }
170
173
  const opt = this.buildOpt(p1);
171
174
  const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
172
175
  if (opt.printSql) {
@@ -193,6 +196,9 @@ class CbConnection extends be_db_common_1.DbConnection {
193
196
  /** {@inheritDoc} */
194
197
  one(link, lines, p1) {
195
198
  return __awaiter(this, void 0, void 0, function* () {
199
+ if (!this._props.enabled) {
200
+ return { success: true, row: undefined };
201
+ }
196
202
  const opt = this.buildOpt(p1);
197
203
  const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
198
204
  if (opt.printSql) {
@@ -221,6 +227,9 @@ class CbConnection extends be_db_common_1.DbConnection {
221
227
  /** {@inheritDoc} */
222
228
  connect() {
223
229
  return __awaiter(this, void 0, void 0, function* () {
230
+ if (!this._props.enabled) {
231
+ return false;
232
+ }
224
233
  const { _props: props } = this;
225
234
  if (props.isConnected) {
226
235
  return true;
@@ -258,6 +267,9 @@ class CbConnection extends be_db_common_1.DbConnection {
258
267
  /** {@inheritDoc} */
259
268
  ping(next) {
260
269
  return __awaiter(this, void 0, void 0, function* () {
270
+ if (!this._props.enabled) {
271
+ return false;
272
+ }
261
273
  const { _props: props } = this;
262
274
  let result = false;
263
275
  try {
@@ -251,6 +251,9 @@ class CbRepo extends be_db_common_1.DbRepo {
251
251
  $getByPrimary(key, p1, ignoreCheck) {
252
252
  return __awaiter(this, void 0, void 0, function* () {
253
253
  const { conn, useSoftDelete, collection, full } = this._props;
254
+ if (!conn.props.enabled) {
255
+ return undefined;
256
+ }
254
257
  const opt = conn.buildOpt(p1, '$getById');
255
258
  if (!ignoreCheck) {
256
259
  (0, type_2.assertText)(key, { field: 'id', where: 'CbRepo', method: '$getByPrimary' });
@@ -278,6 +281,9 @@ class CbRepo extends be_db_common_1.DbRepo {
278
281
  $getBySecondary(key, p1, ignoreCheck) {
279
282
  return __awaiter(this, void 0, void 0, function* () {
280
283
  const { conn, useSoftDelete, useNumericId, full } = this._props;
284
+ if (!conn.props.enabled) {
285
+ return undefined;
286
+ }
281
287
  if (!ignoreCheck) {
282
288
  if (useNumericId) {
283
289
  (0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$getBySecondary' });
@@ -304,10 +310,13 @@ class CbRepo extends be_db_common_1.DbRepo {
304
310
  $existsByPrimary(key, p1, ignoreCheck) {
305
311
  return __awaiter(this, void 0, void 0, function* () {
306
312
  var _a, _b, _c;
313
+ const { useSoftDelete, conn, collection, full } = this._props;
314
+ if (!conn.props.enabled) {
315
+ return false;
316
+ }
307
317
  if (!ignoreCheck) {
308
318
  (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$existsByPrimary' });
309
319
  }
310
- const { useSoftDelete, conn, collection, full } = this._props;
311
320
  const opt = conn.buildOpt(p1, '$existsByPrimary');
312
321
  if (!useSoftDelete) {
313
322
  return (_b = (_a = (yield conn.exec(collection.exists(key, opt), opt))) === null || _a === void 0 ? void 0 : _a.exists) !== null && _b !== void 0 ? _b : false;
@@ -328,6 +337,9 @@ class CbRepo extends be_db_common_1.DbRepo {
328
337
  return __awaiter(this, void 0, void 0, function* () {
329
338
  var _a;
330
339
  const { useSoftDelete, useNumericId, conn, full } = this._props;
340
+ if (!conn.props.enabled) {
341
+ return false;
342
+ }
331
343
  if (!ignoreCheck) {
332
344
  if (useNumericId) {
333
345
  (0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$existsBySecondary' });
@@ -353,13 +365,16 @@ class CbRepo extends be_db_common_1.DbRepo {
353
365
  /** @inheritDoc */
354
366
  $listByPrimary(keys, p1, ignoreCheck) {
355
367
  return __awaiter(this, void 0, void 0, function* () {
368
+ const { useSoftDelete, conn, full } = this._props;
369
+ if (!conn.props.enabled) {
370
+ return [];
371
+ }
356
372
  if (!ignoreCheck) {
357
373
  (0, type_2.assertArray)(keys, { field: 'keys', where: 'CbRepo', method: '$listByPrimary' });
358
374
  keys.forEach((key, index) => {
359
375
  (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$listByPrimary', index });
360
376
  });
361
377
  }
362
- const { useSoftDelete, conn, full } = this._props;
363
378
  const opt = conn.buildOpt(p1, '$listByIds');
364
379
  const lines = (0, be_db_common_1.dbLines)();
365
380
  lines
@@ -375,6 +390,9 @@ class CbRepo extends be_db_common_1.DbRepo {
375
390
  $listBySecondary(keys, p1, ignoreCheck) {
376
391
  return __awaiter(this, void 0, void 0, function* () {
377
392
  const { useSoftDelete, useNumericId, conn, full } = this._props;
393
+ if (!conn.props.enabled) {
394
+ return [];
395
+ }
378
396
  if (!ignoreCheck) {
379
397
  (0, type_2.assertArray)(keys, { field: 'keys', where: 'CbRepo', method: '$listBySecondary' });
380
398
  keys.forEach((key, index) => {
@@ -403,6 +421,9 @@ class CbRepo extends be_db_common_1.DbRepo {
403
421
  $filter(query, p1) {
404
422
  return __awaiter(this, void 0, void 0, function* () {
405
423
  const { useSoftDelete, conn, full } = this._props;
424
+ if (!conn.props.enabled) {
425
+ return [];
426
+ }
406
427
  const opt = conn.buildOpt(p1, '$filter');
407
428
  // @todo - work for query builder
408
429
  const lines = (0, be_db_common_1.dbLines)();
@@ -419,6 +440,9 @@ class CbRepo extends be_db_common_1.DbRepo {
419
440
  $insert(doc, p1, ignoreCheck) {
420
441
  return __awaiter(this, void 0, void 0, function* () {
421
442
  const { conn, collection, noInsert, useNumericId } = this._props;
443
+ if (!conn.props.enabled) {
444
+ return undefined;
445
+ }
422
446
  const opt = conn.buildOpt(p1, '$insert');
423
447
  const param = { where: 'CbRepo', method: '$insert', queryName: opt.name };
424
448
  if (noInsert) {
@@ -444,6 +468,9 @@ class CbRepo extends be_db_common_1.DbRepo {
444
468
  $replace(doc, p1, ignoreCheck) {
445
469
  return __awaiter(this, void 0, void 0, function* () {
446
470
  const { conn, collection, noUpdate, useNumericId } = this._props;
471
+ if (!conn.props.enabled) {
472
+ return undefined;
473
+ }
447
474
  const opt = conn.buildOpt(p1, '$replace');
448
475
  const param = { where: 'CbRepo', method: '$replace', queryName: opt.name };
449
476
  if (noUpdate) {
@@ -469,6 +496,9 @@ class CbRepo extends be_db_common_1.DbRepo {
469
496
  $upsert(doc, p1, ignoreCheck) {
470
497
  return __awaiter(this, void 0, void 0, function* () {
471
498
  const { conn, collection, noUpdate, noInsert, useNumericId } = this._props;
499
+ if (!conn.props.enabled) {
500
+ return undefined;
501
+ }
472
502
  const opt = conn.buildOpt(p1, '$upsert');
473
503
  const param = { where: 'CbRepo', method: '$upsert', queryName: opt.name };
474
504
  if (noUpdate || noInsert) {
@@ -494,6 +524,9 @@ class CbRepo extends be_db_common_1.DbRepo {
494
524
  $updateByPrimary(key, doc, p1, ignoreCheck) {
495
525
  return __awaiter(this, void 0, void 0, function* () {
496
526
  const { conn, full, noUpdate, useSoftDelete } = this._props;
527
+ if (!conn.props.enabled) {
528
+ return undefined;
529
+ }
497
530
  const opt = conn.buildOpt(p1, '$updateByPrimary');
498
531
  const param = { where: 'CbRepo', method: '$updateByPrimary', queryName: opt.name };
499
532
  if (noUpdate) {
@@ -541,6 +574,9 @@ class CbRepo extends be_db_common_1.DbRepo {
541
574
  return __awaiter(this, void 0, void 0, function* () {
542
575
  var _a;
543
576
  const { useNumericId, noUpdate, useSoftDelete, conn, full } = this._props;
577
+ if (!conn.props.enabled) {
578
+ return undefined;
579
+ }
544
580
  const opt = conn.buildOpt(p1, '$updateBySecondary');
545
581
  const param = { where: 'CbRepo', method: '$updateBySecondary', queryName: opt.name };
546
582
  if (noUpdate) {
@@ -594,6 +630,9 @@ class CbRepo extends be_db_common_1.DbRepo {
594
630
  $removeByPrimary(key, p1, ignoreCheck) {
595
631
  return __awaiter(this, void 0, void 0, function* () {
596
632
  const { useSoftDelete, noRemove, conn, full, collection } = this._props;
633
+ if (!conn.props.enabled) {
634
+ return undefined;
635
+ }
597
636
  const opt = conn.buildOpt(p1, '$removeByPrimary');
598
637
  const param = { where: 'CbRepo', method: '$removeByPrimary', queryName: opt.name };
599
638
  if (noRemove) {
@@ -622,6 +661,9 @@ class CbRepo extends be_db_common_1.DbRepo {
622
661
  return __awaiter(this, void 0, void 0, function* () {
623
662
  var _a;
624
663
  const { useNumericId, noRemove, useSoftDelete, conn, full } = this._props;
664
+ if (!conn.props.enabled) {
665
+ return undefined;
666
+ }
625
667
  const opt = conn.buildOpt(p1, '$removeBySecondary');
626
668
  const param = { where: 'CbRepo', method: '$removeBySecondary', queryName: opt.name };
627
669
  if (noRemove) {
@@ -652,6 +694,9 @@ class CbRepo extends be_db_common_1.DbRepo {
652
694
  $trashByPrimary(key, p1, ignoreCheck) {
653
695
  return __awaiter(this, void 0, void 0, function* () {
654
696
  const { useSoftDelete, noTrash, conn, full } = this._props;
697
+ if (!conn.props.enabled) {
698
+ return undefined;
699
+ }
655
700
  const opt = conn.buildOpt(p1, '$trashByPrimary');
656
701
  const param = { where: 'CbRepo', method: '$trashByPrimary', queryName: opt.name };
657
702
  if (noTrash) {
@@ -685,6 +730,9 @@ class CbRepo extends be_db_common_1.DbRepo {
685
730
  return __awaiter(this, void 0, void 0, function* () {
686
731
  var _a;
687
732
  const { useSoftDelete, noTrash, useNumericId, conn, full } = this._props;
733
+ if (!conn.props.enabled) {
734
+ return undefined;
735
+ }
688
736
  const opt = conn.buildOpt(p1, '$trashBySecondary');
689
737
  const param = { where: 'CbRepo', method: '$trashBySecondary', queryName: opt.name };
690
738
  if (noTrash) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-couchbase-common",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Couchbase common component",
5
5
  "keywords": [
6
6
  "Couchbase"
@@ -66,13 +66,13 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@leyyo/common": "^1.2.3",
70
- "@leyyo/env": "^1.2.1",
69
+ "@leyyo/common": "^1.2.4",
70
+ "@leyyo/env": "^1.2.5",
71
71
  "@leyyo/query": "^1.2.1",
72
72
  "@leyyo/type": "^1.1.1",
73
- "@samet-it/be-base-common": "^1.1.3",
74
- "@samet-it/be-cache-common": "^1.1.3",
75
- "@samet-it/be-db-common": "^1.1.4",
73
+ "@samet-it/be-base-common": "^1.1.4",
74
+ "@samet-it/be-cache-common": "^1.1.6",
75
+ "@samet-it/be-db-common": "^1.1.5",
76
76
  "couchbase": "^4.6.0"
77
77
  }
78
78
  }