@samet-it/be-couchbase-common 1.0.8 → 1.0.9

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.
@@ -6,9 +6,7 @@ export declare class CbAdapterService implements CbAdapterServiceLike {
6
6
  private readonly _CLEAR_ERROR_INTERVAL;
7
7
  private logger;
8
8
  private _connected;
9
- private _undefined;
10
9
  private _cluster;
11
- private readonly _cbErrors;
12
10
  private readonly _nativeErrors;
13
11
  constructor();
14
12
  /**
@@ -46,8 +44,6 @@ export declare class CbAdapterService implements CbAdapterServiceLike {
46
44
  /** {@inheritDoc} */
47
45
  first<T>(rows: Array<T>): T | undefined;
48
46
  /** {@inheritDoc} */
49
- checkError(p1: string | Error, p2?: Error): void;
50
- /** {@inheritDoc} */
51
47
  createIndex<T = Record<string, unknown>>(coll: Collection, p1: (keyof T | string) | Array<keyof T | string>, name?: string): Promise<void>;
52
48
  /** {@inheritDoc} */
53
49
  createBaseIndices(coll: Collection, ...keys: Array<keyof CbEntity>): Promise<void>;
@@ -54,25 +54,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
54
54
  Object.defineProperty(exports, "__esModule", { value: true });
55
55
  exports.CbAdapterService = void 0;
56
56
  const couchbase = __importStar(require("couchbase"));
57
- const common_1 = require("@nestjs/common");
58
57
  const couchbase_1 = require("couchbase");
58
+ const common_1 = require("@nestjs/common");
59
59
  const config_1 = require("../config");
60
60
  // noinspection JSUnusedGlobalSymbols
61
61
  let CbAdapterService = class CbAdapterService {
62
62
  constructor() {
63
63
  this._CLEAR_ERROR_INTERVAL = 1000 * 60 * 60 * 24; // daily
64
- this._undefined = 0;
65
- this._cbErrors = new Map();
66
64
  this._nativeErrors = new Map();
67
65
  this.logger = new common_1.Logger(this.constructor.name);
68
66
  this._clearErrors();
69
- this._cbErrors.set('AmbiguousTimeoutError', { count: 0, log: true, known: true });
70
- this._cbErrors.set('AuthenticationFailureError', { count: 0, log: true, known: true });
71
- this._cbErrors.set('ConnectionClosedError', { count: 0, log: true, known: true });
72
- this._cbErrors.set('InternalServerFailureError', { count: 0, log: true, known: true });
73
- this._cbErrors.set('ServiceNotAvailableError', { count: 0, log: true, known: true });
74
- this._cbErrors.set('TimeoutError', { count: 0, log: true, known: true });
75
- this._cbErrors.set('UnambiguousTimeoutError', { count: 0, log: true, known: true });
76
67
  }
77
68
  /**
78
69
  * Clear native errors
@@ -90,6 +81,7 @@ let CbAdapterService = class CbAdapterService {
90
81
  yield this.exec(this._cluster.ping(), { name: 'ping' });
91
82
  }
92
83
  catch (err) {
84
+ this.logger.warn(`Ping error => [${err.name}: ${err.message}]`);
93
85
  }
94
86
  setTimeout(() => this._ping(), 30000);
95
87
  });
@@ -107,7 +99,10 @@ let CbAdapterService = class CbAdapterService {
107
99
  if (e instanceof couchbase_1.IndexExistsError) {
108
100
  return undefined;
109
101
  }
110
- this.logger.error(`!index[${(_a = e.name) !== null && _a !== void 0 ? _a : ''}] #${scope.name}] => ${sql}`, e);
102
+ this.logger.error(`Index error => [${e.name}: ${e.message}] ${JSON.stringify({
103
+ scope: scope === null || scope === void 0 ? void 0 : scope.name,
104
+ bucket: (_a = scope === null || scope === void 0 ? void 0 : scope.bucket) === null || _a === void 0 ? void 0 : _a.name
105
+ })}`);
111
106
  // throw e; // TODO
112
107
  }
113
108
  });
@@ -154,18 +149,20 @@ let CbAdapterService = class CbAdapterService {
154
149
  }
155
150
  }
156
151
  _checkError(err, opt) {
157
- var _a;
152
+ var _a, _b, _c;
153
+ let size = 1;
158
154
  if (!this._nativeErrors.has(err)) {
159
- this._nativeErrors.set(err, 1);
155
+ this._nativeErrors.set(err, size);
160
156
  }
161
157
  else {
162
- this._nativeErrors.set(err, this._nativeErrors.get(err) + 1);
158
+ size = this._nativeErrors.get(err) + 1;
159
+ this._nativeErrors.set(err, size);
163
160
  }
164
161
  if ((_a = opt === null || opt === void 0 ? void 0 : opt.ignoredErrors) === null || _a === void 0 ? void 0 : _a.includes(err)) {
165
- this.logger.warn(`${opt.name} => (${err.name})${err.message}`);
162
+ this.logger.warn(`[${size}] ${(_b = opt.name) !== null && _b !== void 0 ? _b : 'Ignored error'} => [${err.name}: ${err.message}]`);
166
163
  return;
167
164
  }
168
- this.logger.debug(`${opt.name} => (${err.name})${err.message}`, JSON.stringify(err.context));
165
+ this.logger.error(`[${size}] ${(_c = opt.name) !== null && _c !== void 0 ? _c : 'Ignored error'} => [${err.name}: ${err.message}]`, JSON.stringify(err.context));
169
166
  throw err;
170
167
  }
171
168
  /** {@inheritDoc} */
@@ -227,42 +224,6 @@ let CbAdapterService = class CbAdapterService {
227
224
  return undefined;
228
225
  }
229
226
  /** {@inheritDoc} */
230
- checkError(p1, p2) {
231
- var _a;
232
- let op;
233
- let err;
234
- if (typeof p1 === 'string') {
235
- p1 = p1.trim();
236
- op = p1 ? `(${p1})` : '';
237
- err = p2;
238
- }
239
- else {
240
- op = '';
241
- err = p1;
242
- }
243
- const name = (_a = err === null || err === void 0 ? void 0 : err.constructor) === null || _a === void 0 ? void 0 : _a.name;
244
- if (name) {
245
- if (!this._cbErrors.has(name)) {
246
- this.logger.warn(`!first[${name}] #${op} [1]`, err);
247
- this._cbErrors.set(name, { count: 1, log: true });
248
- }
249
- else {
250
- const obj = this._cbErrors.get(name);
251
- obj.count++;
252
- if (obj.known) {
253
- this.logger.debug(`!known[${name}] #${op} [${obj.count}]`, err);
254
- }
255
- else {
256
- this.logger.debug(`!unknown[${name}] #${op} [${obj.count}]`, err);
257
- }
258
- }
259
- }
260
- else {
261
- this._undefined++;
262
- this.logger.warn(`!undefined[] #${op} [${this._undefined}]`, err);
263
- }
264
- }
265
- /** {@inheritDoc} */
266
227
  createIndex(coll, p1, name) {
267
228
  return __awaiter(this, void 0, void 0, function* () {
268
229
  if (Array.isArray(p1)) {
@@ -410,7 +371,6 @@ let CbAdapterService = class CbAdapterService {
410
371
  /** {@inheritDoc} */
411
372
  connectDb() {
412
373
  return __awaiter(this, void 0, void 0, function* () {
413
- var _a;
414
374
  if (this._connected) {
415
375
  return this._cluster;
416
376
  }
@@ -426,7 +386,7 @@ let CbAdapterService = class CbAdapterService {
426
386
  return this._cluster;
427
387
  }
428
388
  catch (e) {
429
- this.logger.error(`!connection[${(_a = e.name) !== null && _a !== void 0 ? _a : ''}]`, e);
389
+ this.logger.warn(`Connection error => [${e.name}: ${e.message}]`);
430
390
  throw e;
431
391
  }
432
392
  });
@@ -43,14 +43,6 @@ export interface CbAdapterServiceLike {
43
43
  * Return first row of rows
44
44
  * */
45
45
  first<T>(rows: Array<T>): T | undefined;
46
- /**
47
- * Check error
48
- * */
49
- checkError(err: Error): void;
50
- /**
51
- * Check error with operation
52
- * */
53
- checkError(op: string, err: Error): void;
54
46
  /**
55
47
  * Create index for multiple fields
56
48
  * */
@@ -122,7 +122,6 @@ class CbRepo {
122
122
  throw e;
123
123
  }
124
124
  this._tryCount++;
125
- this.logger.error(`[${this._tryCount}] ${e.name} => ${e.message}`);
126
125
  setTimeout(() => this.onModuleInit().then().catch(e2 => {
127
126
  throw e2;
128
127
  }), 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-couchbase-common",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Couchbase common component",
5
5
  "keywords": [
6
6
  "Couchbase"