@villedemontreal/correlation-id 5.3.10 → 5.4.0

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 (42) hide show
  1. package/dist/config/configs.d.ts +1 -0
  2. package/dist/config/configs.d.ts.map +1 -0
  3. package/dist/src/config/configs.d.ts +1 -0
  4. package/dist/src/config/configs.d.ts.map +1 -0
  5. package/dist/src/config/constants.d.ts +1 -0
  6. package/dist/src/config/constants.d.ts.map +1 -0
  7. package/dist/src/config/init.d.ts +1 -0
  8. package/dist/src/config/init.d.ts.map +1 -0
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/src/index.d.ts.map +1 -0
  11. package/dist/src/middleware/correlationIdMiddleware.d.ts +1 -0
  12. package/dist/src/middleware/correlationIdMiddleware.d.ts.map +1 -0
  13. package/dist/src/middleware/correlationIdMiddleware.js.map +1 -1
  14. package/dist/src/middleware/correlationIdMiddleware.test.d.ts +1 -0
  15. package/dist/src/middleware/correlationIdMiddleware.test.d.ts.map +1 -0
  16. package/dist/src/middleware/correlationIdMiddleware.test.js +100 -111
  17. package/dist/src/middleware/correlationIdMiddleware.test.js.map +1 -1
  18. package/dist/src/services/correlationIdService.d.ts +1 -0
  19. package/dist/src/services/correlationIdService.d.ts.map +1 -0
  20. package/dist/src/services/correlationIdService.js +25 -39
  21. package/dist/src/services/correlationIdService.js.map +1 -1
  22. package/dist/src/services/correlationIdService.test.d.ts +1 -0
  23. package/dist/src/services/correlationIdService.test.d.ts.map +1 -0
  24. package/dist/src/services/correlationIdService.test.js +76 -95
  25. package/dist/src/services/correlationIdService.test.js.map +1 -1
  26. package/dist/src/utils/logger.d.ts +1 -0
  27. package/dist/src/utils/logger.d.ts.map +1 -0
  28. package/dist/src/utils/testingConfigurations.d.ts +1 -0
  29. package/dist/src/utils/testingConfigurations.d.ts.map +1 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -0
  31. package/package.json +34 -26
  32. package/src/middleware/correlationIdMiddleware.ts +2 -2
  33. package/src/services/correlationIdService.ts +17 -18
  34. package/dist/scripts/index.d.ts +0 -2
  35. package/dist/scripts/index.js +0 -14
  36. package/dist/scripts/index.js.map +0 -1
  37. package/dist/scripts/lint.d.ts +0 -6
  38. package/dist/scripts/lint.js +0 -31
  39. package/dist/scripts/lint.js.map +0 -1
  40. package/dist/scripts/lintFix.d.ts +0 -6
  41. package/dist/scripts/lintFix.js +0 -40
  42. package/dist/scripts/lintFix.js.map +0 -1
@@ -113,7 +113,6 @@ class CorrelationIdServiceWithClsHooked implements ICorrelationIdService {
113
113
  try {
114
114
  work().then(resolve).catch(reject);
115
115
  } catch (err) {
116
- // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
117
116
  reject(err);
118
117
  }
119
118
  }, cid);
@@ -137,8 +136,8 @@ class CorrelationIdServiceWithClsHooked implements ICorrelationIdService {
137
136
  public getCidInfo(req: express.Request): ICidInfo {
138
137
  return {
139
138
  current: this.getId(),
140
- receivedInRequest: req[constants.requestExtraVariables.cidReceivedInRequest],
141
- generated: req[constants.requestExtraVariables.cidNew],
139
+ receivedInRequest: (req as any)[constants.requestExtraVariables.cidReceivedInRequest],
140
+ generated: (req as any)[constants.requestExtraVariables.cidNew],
142
141
  };
143
142
  }
144
143
 
@@ -150,23 +149,23 @@ class CorrelationIdServiceWithClsHooked implements ICorrelationIdService {
150
149
  // risk having ordering issues.
151
150
  // Note however that patching an emitter might not work in 100% cases.
152
151
  // patch emit method only once!
153
- if (!emitter[oldEmitSlot]) {
154
- emitter[oldEmitSlot] = emitter.emit;
152
+ const emitterObj: any = emitter;
153
+ if (!emitterObj[oldEmitSlot]) {
154
+ emitterObj[oldEmitSlot] = emitter.emit;
155
155
  (emitter as any).emit = (...args: any[]) => {
156
156
  // wrap the emit call within a new correlation context
157
157
  // with the bound cid.
158
158
  this.withId(() => {
159
159
  // invoke original emit method
160
- emitter[oldEmitSlot].apply(emitter, args);
161
- }, emitter[cidSlot]);
160
+ emitterObj[oldEmitSlot].apply(emitter, args);
161
+ }, emitterObj[cidSlot]);
162
162
  };
163
163
  }
164
164
  // update the cid bound to the emitter
165
- emitter[cidSlot] = this.getId();
165
+ emitterObj[cidSlot] = this.getId();
166
166
  return emitter;
167
167
  }
168
168
 
169
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
170
169
  private bindFunction<T extends Function>(target: T): T {
171
170
  return this.store.bind(target);
172
171
  }
@@ -213,31 +212,31 @@ class CorrelationIdServiceWithAsyncLocalStorage implements ICorrelationIdService
213
212
  public getCidInfo(req: express.Request): ICidInfo {
214
213
  return {
215
214
  current: this.getId(),
216
- receivedInRequest: req[constants.requestExtraVariables.cidReceivedInRequest],
217
- generated: req[constants.requestExtraVariables.cidNew],
215
+ receivedInRequest: (req as any)[constants.requestExtraVariables.cidReceivedInRequest],
216
+ generated: (req as any)[constants.requestExtraVariables.cidNew],
218
217
  };
219
218
  }
220
219
 
221
220
  private bindEmitter<T extends EventEmitter>(emitter: T): T {
222
221
  // patch emit method only once!
223
- if (!emitter[oldEmitSlot]) {
224
- emitter[oldEmitSlot] = emitter.emit;
225
- (emitter as any).emit = (...args: any[]) => {
222
+ const emitterObj: any = emitter;
223
+ if (!emitterObj[oldEmitSlot]) {
224
+ emitterObj[oldEmitSlot] = emitter.emit;
225
+ emitterObj.emit = (...args: any[]) => {
226
226
  // use the store that was bound to this emitter
227
- const store = emitter[storeSlot];
227
+ const store = emitterObj[storeSlot];
228
228
  if (store) {
229
229
  this.storage.enterWith(store);
230
230
  }
231
231
  // invoke original emit method
232
- emitter[oldEmitSlot].call(emitter, ...args);
232
+ emitterObj[oldEmitSlot].call(emitter, ...args);
233
233
  };
234
234
  }
235
235
  // update the store bound to the emitter
236
- emitter[storeSlot] = this.storage.getStore();
236
+ emitterObj[storeSlot] = this.storage.getStore();
237
237
  return emitter;
238
238
  }
239
239
 
240
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
241
240
  private bindFunction<T extends Function>(target: T): T {
242
241
  const storage = this.storage;
243
242
  const store = this.storage.getStore();
@@ -1,2 +0,0 @@
1
- export { LintScript } from './lint';
2
- export { LintFixScript } from './lintFix';
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LintFixScript = exports.LintScript = void 0;
4
- // ==========================================
5
- // All scripts must be included here!
6
- //
7
- // The scripting library uses this index to quickly
8
- // find all the scripts available in the application.
9
- // ==========================================
10
- var lint_1 = require("./lint");
11
- Object.defineProperty(exports, "LintScript", { enumerable: true, get: function () { return lint_1.LintScript; } });
12
- var lintFix_1 = require("./lintFix");
13
- Object.defineProperty(exports, "LintFixScript", { enumerable: true, get: function () { return lintFix_1.LintFixScript; } });
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../scripts/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,qCAAqC;AACrC,EAAE;AACF,mDAAmD;AACnD,qDAAqD;AACrD,6CAA6C;AAC7C,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA"}
@@ -1,6 +0,0 @@
1
- import { ScriptBase } from '@villedemontreal/scripting/dist/src';
2
- export declare class LintScript extends ScriptBase {
3
- get name(): string;
4
- get description(): string;
5
- protected main(): Promise<void>;
6
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LintScript = void 0;
13
- const src_1 = require("@villedemontreal/scripting/dist/src");
14
- const path_1 = require("path");
15
- const configs_1 = require("../config/configs");
16
- class LintScript extends src_1.ScriptBase {
17
- get name() {
18
- return 'lint';
19
- }
20
- get description() {
21
- return `Run the ESLint validation (including ESLint and Prettier rules).`;
22
- }
23
- main() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const projectRoot = (0, path_1.resolve)(`${configs_1.configs.root}/..`);
26
- yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/eslint`, [projectRoot]);
27
- });
28
- }
29
- }
30
- exports.LintScript = LintScript;
31
- //# sourceMappingURL=lint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../scripts/lint.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAiE;AACjE,+BAA+B;AAC/B,+CAA4C;AAC5C,MAAa,UAAW,SAAQ,gBAAU;IACxC,IAAI,IAAI;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,kEAAkE,CAAC;IAC5E,CAAC;IAEe,IAAI;;YAClB,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,GAAG,iBAAO,CAAC,IAAI,KAAK,CAAC,CAAC;YAClD,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,2BAA2B,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;QAC1F,CAAC;KAAA;CACF;AAbD,gCAaC"}
@@ -1,6 +0,0 @@
1
- import { ScriptBase } from '@villedemontreal/scripting/dist/src';
2
- export declare class LintFixScript extends ScriptBase {
3
- get name(): string;
4
- get description(): string;
5
- protected main(): Promise<void>;
6
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LintFixScript = void 0;
13
- const src_1 = require("@villedemontreal/scripting/dist/src");
14
- const path_1 = require("path");
15
- const configs_1 = require("../config/configs");
16
- class LintFixScript extends src_1.ScriptBase {
17
- get name() {
18
- return 'lint-fix';
19
- }
20
- get description() {
21
- return `Fix the code using ESLint and Prettier rules).`;
22
- }
23
- main() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const projectRoot = (0, path_1.resolve)(`${configs_1.configs.root}/..`);
26
- this.logger.info(`Fixing using Prettier rules`);
27
- yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/prettier`, [
28
- '--write',
29
- projectRoot,
30
- ]);
31
- this.logger.info(`Fixing using ESLint rules`);
32
- yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/eslint`, [
33
- '--fix',
34
- projectRoot,
35
- ]);
36
- });
37
- }
38
- }
39
- exports.LintFixScript = LintFixScript;
40
- //# sourceMappingURL=lintFix.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lintFix.js","sourceRoot":"","sources":["../../scripts/lintFix.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAiE;AACjE,+BAA+B;AAC/B,+CAA4C;AAE5C,MAAa,aAAc,SAAQ,gBAAU;IAC3C,IAAI,IAAI;QACN,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,gDAAgD,CAAC;IAC1D,CAAC;IAEe,IAAI;;YAClB,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,GAAG,iBAAO,CAAC,IAAI,KAAK,CAAC,CAAC;YAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YAChD,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,6BAA6B,EAAE;gBACzE,SAAS;gBACT,WAAW;aACZ,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC9C,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,2BAA2B,EAAE;gBACvE,OAAO;gBACP,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAvBD,sCAuBC"}