node-pluginsmanager-plugin 6.4.5 → 7.0.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 (77) hide show
  1. package/LICENSE +13 -13
  2. package/README.md +53 -48
  3. package/lib/@types/socket.io-v2.d.ts +988 -0
  4. package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.d.ts +2 -2
  5. package/lib/cjs/checkers/RangeError/checkNonEmptyObject.d.ts +2 -2
  6. package/lib/cjs/checkers/RangeError/checkNonEmptyString.d.ts +2 -2
  7. package/lib/cjs/checkers/ReferenceError/checkExists.d.ts +2 -2
  8. package/lib/cjs/checkers/TypeError/checkFunction.d.ts +2 -2
  9. package/lib/cjs/checkers/TypeError/checkInteger.d.ts +2 -2
  10. package/lib/cjs/checkers/TypeError/checkNumber.d.ts +2 -2
  11. package/lib/cjs/checkers/TypeError/checkObject.d.ts +2 -2
  12. package/lib/cjs/checkers/TypeError/checkString.d.ts +2 -2
  13. package/lib/cjs/components/DescriptorUser.d.ts +14 -7
  14. package/lib/cjs/components/DescriptorUser.js +51 -36
  15. package/lib/cjs/components/Mediator.d.ts +15 -19
  16. package/lib/cjs/components/Mediator.js +57 -37
  17. package/lib/cjs/components/MediatorUser.d.ts +5 -4
  18. package/lib/cjs/components/MediatorUser.js +12 -5
  19. package/lib/cjs/components/Orchestrator.d.ts +14 -14
  20. package/lib/cjs/components/Orchestrator.js +117 -63
  21. package/lib/cjs/components/Server.d.ts +24 -20
  22. package/lib/cjs/components/Server.js +277 -236
  23. package/lib/cjs/main.cjs +1 -40
  24. package/lib/cjs/main.d.cts +4 -16
  25. package/lib/cjs/openAPITypes.d.ts +5 -0
  26. package/lib/cjs/openAPITypes.js +3 -0
  27. package/lib/cjs/utils/cleanSendedError.d.ts +1 -1
  28. package/lib/cjs/utils/cleanSendedError.js +2 -4
  29. package/lib/cjs/utils/descriptor/extractParams.d.ts +1 -1
  30. package/lib/cjs/utils/descriptor/extractParams.js +1 -1
  31. package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.d.ts +2 -3
  32. package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.js +14 -14
  33. package/lib/cjs/utils/descriptor/extractPattern.d.ts +2 -2
  34. package/lib/cjs/utils/descriptor/extractPattern.js +5 -5
  35. package/lib/cjs/utils/descriptor/extractSchemaType.d.ts +1 -1
  36. package/lib/cjs/utils/descriptor/extractSchemaType.js +13 -8
  37. package/lib/cjs/utils/file/readJSONFile.d.ts +1 -1
  38. package/lib/cjs/utils/request/extractBody.js +9 -5
  39. package/lib/cjs/utils/request/extractCookies.d.ts +2 -2
  40. package/lib/cjs/utils/request/extractCookies.js +6 -6
  41. package/lib/cjs/utils/request/extractIp.d.ts +1 -1
  42. package/lib/cjs/utils/request/extractIp.js +19 -10
  43. package/lib/cjs/utils/request/extractMime.d.ts +1 -4
  44. package/lib/cjs/utils/request/extractMime.js +15 -11
  45. package/lib/cjs/utils/send.d.ts +4 -4
  46. package/lib/cjs/utils/send.js +27 -29
  47. package/lib/cjs/utils/server/getServerTypeFromServer.d.ts +4 -0
  48. package/lib/cjs/utils/server/getServerTypeFromServer.js +23 -0
  49. package/lib/cjs/utils/server/getSocketIOVersionFromServer.d.ts +4 -0
  50. package/lib/cjs/utils/server/getSocketIOVersionFromServer.js +19 -0
  51. package/package.json +101 -97
  52. package/lib/cjs/checkers/RangeError/checkArrayLength.d.ts +0 -2
  53. package/lib/cjs/checkers/RangeError/checkArrayLength.js +0 -23
  54. package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.d.ts +0 -2
  55. package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.js +0 -30
  56. package/lib/cjs/checkers/RangeError/checkIntegerBetween.d.ts +0 -2
  57. package/lib/cjs/checkers/RangeError/checkIntegerBetween.js +0 -29
  58. package/lib/cjs/checkers/RangeError/checkNonEmptyArray.d.ts +0 -2
  59. package/lib/cjs/checkers/RangeError/checkNonEmptyArray.js +0 -19
  60. package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.d.ts +0 -2
  61. package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.js +0 -19
  62. package/lib/cjs/checkers/RangeError/checkNumberBetween.d.ts +0 -2
  63. package/lib/cjs/checkers/RangeError/checkNumberBetween.js +0 -29
  64. package/lib/cjs/checkers/RangeError/checkObjectLength.d.ts +0 -2
  65. package/lib/cjs/checkers/RangeError/checkObjectLength.js +0 -28
  66. package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.d.ts +0 -2
  67. package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.js +0 -33
  68. package/lib/cjs/checkers/RangeError/checkStringLength.d.ts +0 -2
  69. package/lib/cjs/checkers/RangeError/checkStringLength.js +0 -23
  70. package/lib/cjs/checkers/RangeError/checkStringLengthBetween.d.ts +0 -2
  71. package/lib/cjs/checkers/RangeError/checkStringLengthBetween.js +0 -30
  72. package/lib/cjs/checkers/TypeError/checkArray.d.ts +0 -2
  73. package/lib/cjs/checkers/TypeError/checkArray.js +0 -19
  74. package/lib/cjs/checkers/TypeError/checkBoolean.d.ts +0 -2
  75. package/lib/cjs/checkers/TypeError/checkBoolean.js +0 -19
  76. package/lib/cjs/utils/jsonParser.d.ts +0 -1
  77. package/lib/cjs/utils/jsonParser.js +0 -16
@@ -1,2 +1,2 @@
1
- export declare function checkNonEmptyNumberSync(dataName: string, data: any): ReferenceError | TypeError | RangeError | null;
2
- export declare function checkNonEmptyNumber(dataName: string, data: any): Promise<void>;
1
+ export declare function checkNonEmptyNumberSync(dataName: string, data: unknown): ReferenceError | TypeError | RangeError | null;
2
+ export declare function checkNonEmptyNumber(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkNonEmptyObjectSync(dataName: string, data: any): ReferenceError | TypeError | RangeError | null;
2
- export declare function checkNonEmptyObject(dataName: string, data: any): Promise<void>;
1
+ export declare function checkNonEmptyObjectSync(dataName: string, data: unknown): ReferenceError | TypeError | RangeError | null;
2
+ export declare function checkNonEmptyObject(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkNonEmptyStringSync(dataName: string, data: any): ReferenceError | TypeError | RangeError | null;
2
- export declare function checkNonEmptyString(dataName: string, data: any): Promise<void>;
1
+ export declare function checkNonEmptyStringSync(dataName: string, data: unknown): ReferenceError | TypeError | RangeError | null;
2
+ export declare function checkNonEmptyString(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkExistsSync(dataName: string, data: any): ReferenceError | null;
2
- export declare function checkExists(dataName: string, data: any): Promise<void>;
1
+ export declare function checkExistsSync(dataName: string, data: unknown): ReferenceError | null;
2
+ export declare function checkExists(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkFunctionSync(dataName: string, data: any): ReferenceError | TypeError | null;
2
- export declare function checkFunction(dataName: string, data: any): Promise<void>;
1
+ export declare function checkFunctionSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
2
+ export declare function checkFunction(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkIntegerSync(dataName: string, data: any): ReferenceError | TypeError | null;
2
- export declare function checkInteger(dataName: string, data: any): Promise<void>;
1
+ export declare function checkIntegerSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
2
+ export declare function checkInteger(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkNumberSync(dataName: string, data: any): ReferenceError | TypeError | null;
2
- export declare function checkNumber(dataName: string, data: any): Promise<void>;
1
+ export declare function checkNumberSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
2
+ export declare function checkNumber(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkObjectSync(dataName: string, data: any): ReferenceError | TypeError | null;
2
- export declare function checkObject(dataName: string, data: any): Promise<void>;
1
+ export declare function checkObjectSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
2
+ export declare function checkObject(dataName: string, data: unknown): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare function checkStringSync(dataName: string, data: any): ReferenceError | TypeError | null;
2
- export declare function checkString(dataName: string, data: any): Promise<void>;
1
+ export declare function checkStringSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
2
+ export declare function checkString(dataName: string, data: unknown): Promise<void>;
@@ -3,24 +3,31 @@ import type { OpenApiDocument } from "express-openapi-validate";
3
3
  export type tLogType = "data" | "debug" | "log" | "info" | "success" | "warning" | "error";
4
4
  export type tLogger = (type: tLogType, message: string | Error, bold?: boolean, pluginName?: string) => void;
5
5
  export interface iDescriptorUserOptions {
6
- "externalRessourcesDirectory": string;
6
+ "externalResourcesDirectory": string;
7
7
  "descriptor"?: OpenApiDocument;
8
8
  "logger"?: tLogger;
9
9
  }
10
- export default class DescriptorUser extends EventEmitter {
10
+ export type tEventMap<T> = Record<keyof T, unknown[]>;
11
+ export type tEventsNoEvent = {};
12
+ export interface iEventsMinimal {
13
+ "error": [Error];
14
+ "initialized": [unknown];
15
+ "released": [unknown];
16
+ }
17
+ export default class DescriptorUser<T extends tEventMap<T> = tEventsNoEvent> extends EventEmitter<T> {
11
18
  initialized: boolean;
12
19
  protected _descriptorValidated: boolean;
13
- protected _externalRessourcesDirectory: string;
20
+ protected _externalResourcesDirectory: string;
14
21
  protected _Descriptor: OpenApiDocument | null;
15
22
  protected _Logger: tLogger | null;
16
23
  constructor(options: iDescriptorUserOptions);
17
- protected _initWorkSpace(...data: any): Promise<void>;
18
- protected _releaseWorkSpace(...data: any): Promise<void>;
24
+ protected _initWorkSpace(...data: unknown[]): Promise<void>;
25
+ protected _releaseWorkSpace(...data: unknown[]): Promise<void>;
19
26
  protected _log(type: tLogType, message: string | Error, bold?: boolean): this;
20
27
  getPluginName(): string;
21
28
  getPluginVersion(): string;
22
29
  getPluginDescription(): string;
23
- init(...data: any): Promise<void>;
24
- release(...data: any): Promise<void>;
30
+ init(...data: unknown[]): Promise<void>;
31
+ release(...data: unknown[]): Promise<void>;
25
32
  checkDescriptor(): Promise<void>;
26
33
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
- // deps
2
+ /*
3
+ eslint-disable @typescript-eslint/no-unused-vars
4
+ */
5
+ // => @typescript-eslint/no-unused-vars is disabled to allow inheritance with proper signature
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ // deps
4
8
  // natives
5
9
  const node_events_1 = require("node:events");
6
10
  // locals
@@ -16,9 +20,17 @@ const LOG_TYPES_ALLOWED = [
16
20
  "error"
17
21
  ];
18
22
  // module
19
- // Please note the fact that "_initWorkSpace" and "_releaseWorkSpace" method MUST be re-writted in Mediator class, and not in MediatorUser childs.
20
- // Please note the fact that "init" and "release" method MUST NOT be re-writted. Each child has is own init logic.
23
+ // Please note the fact that "_initWorkSpace" and "_releaseWorkSpace" method MUST be re-written in Mediator class, and not in MediatorUser childs.
24
+ // Please note the fact that "init" and "release" method MUST NOT be re-written. Each child has its own init logic.
21
25
  class DescriptorUser extends node_events_1.EventEmitter {
26
+ // attributes
27
+ // public
28
+ initialized;
29
+ // protected
30
+ _descriptorValidated;
31
+ _externalResourcesDirectory;
32
+ _Descriptor;
33
+ _Logger;
22
34
  // constructor
23
35
  constructor(options) {
24
36
  super();
@@ -26,15 +38,17 @@ class DescriptorUser extends node_events_1.EventEmitter {
26
38
  this.initialized = false;
27
39
  // protected
28
40
  this._descriptorValidated = false;
29
- this._externalRessourcesDirectory = "string" === typeof (options === null || options === void 0 ? void 0 : options.externalRessourcesDirectory)
30
- ? options.externalRessourcesDirectory
31
- : "";
32
- this._Descriptor = "object" === typeof (options === null || options === void 0 ? void 0 : options.descriptor)
33
- ? options.descriptor
34
- : null;
35
- this._Logger = "function" === typeof (options === null || options === void 0 ? void 0 : options.logger)
36
- ? options.logger
37
- : null;
41
+ // mandatory props
42
+ if ("object" !== typeof options) {
43
+ throw new ReferenceError("\"options\" must be a non-null object");
44
+ }
45
+ if ("string" !== typeof options.externalResourcesDirectory) {
46
+ throw new ReferenceError("\"options.externalResourcesDirectory\" must be a string");
47
+ }
48
+ // optional props
49
+ this._externalResourcesDirectory = options.externalResourcesDirectory;
50
+ this._Descriptor = options.descriptor ?? null;
51
+ this._Logger = options.logger ?? null;
38
52
  }
39
53
  // protected
40
54
  // must be inherited
@@ -53,66 +67,67 @@ class DescriptorUser extends node_events_1.EventEmitter {
53
67
  }
54
68
  // public
55
69
  getPluginName() {
56
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.title ? this._Descriptor.info.title : "";
70
+ return this._Descriptor?.info.title ?? "";
57
71
  }
58
72
  getPluginVersion() {
59
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.version ? this._Descriptor.info.version : "";
73
+ return this._Descriptor?.info.version ?? "";
60
74
  }
61
75
  getPluginDescription() {
62
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.description ? this._Descriptor.info.description : "";
76
+ return this._Descriptor?.info.description ?? "";
63
77
  }
64
78
  // must be inherited
65
79
  init(...data) {
66
- console.log("DescriptorUser", "init", ...data);
67
80
  return Promise.reject(new Error("\"init\" method must be inherited"));
68
81
  }
69
82
  // must be inherited
70
83
  release(...data) {
71
- console.log("DescriptorUser", "release", ...data);
72
84
  return Promise.reject(new Error("\"release\" method must be inherited"));
73
85
  }
74
86
  // must be inherited
75
87
  checkDescriptor() {
88
+ if (this._descriptorValidated) {
89
+ return Promise.resolve();
90
+ }
76
91
  // check Descriptor object
77
- return this._descriptorValidated ? Promise.resolve() : (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor", this._Descriptor).then(() => {
92
+ return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor", this._Descriptor).then(() => {
78
93
  // check info object
79
94
  return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor.info", this._Descriptor.info).then(() => {
95
+ const { title, version } = this._Descriptor.info;
80
96
  // check title
81
- return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.title", this._Descriptor.info.title).then(() => {
82
- return this._Descriptor.info.title !== this._Descriptor.info.title.toLowerCase()
83
- ? Promise.reject(new Error("The descriptor's title (\"" + this._Descriptor.info.title + "\") "
97
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.title", title).then(() => {
98
+ return title !== title.toLowerCase()
99
+ ? Promise.reject(new Error("The descriptor's title (\"" + title + "\") "
84
100
  + "is not equals in lower case (package.json convention)"))
85
101
  : Promise.resolve();
86
102
  // check version
87
103
  }).then(() => {
88
- return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version", this._Descriptor.info.version);
104
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version", version);
89
105
  });
90
106
  });
91
107
  }).then(() => {
108
+ const { paths } = this._Descriptor;
92
109
  // check paths object
93
- return ((0, checkObject_1.checkObject)("Descriptor.paths", this._Descriptor.paths)).then(() => {
110
+ return (0, checkObject_1.checkObject)("Descriptor.paths", paths).then(() => {
94
111
  // check multiple operationIds
95
112
  return Promise.resolve().then(() => {
96
113
  const operationIds = [];
97
- Object.keys(this._Descriptor.paths).forEach((p) => {
98
- Object.keys(this._Descriptor.paths[p]).forEach((m) => {
99
- const path = this._Descriptor.paths[p];
100
- if (path[m].operationId) {
101
- operationIds.push(path[m].operationId);
114
+ Object.keys(paths).forEach((pathname) => {
115
+ const path = paths[pathname];
116
+ Object.keys(path).forEach((method) => {
117
+ const operation = path[method];
118
+ if ("string" === typeof operation?.operationId) {
119
+ operationIds.push(operation.operationId);
102
120
  }
103
121
  });
104
122
  });
105
123
  let multiple = false;
106
- for (let i = 0; i < operationIds.length - 1; ++i) {
107
- for (let j = i + 1; j < operationIds.length; ++j) {
108
- if (operationIds[i] === operationIds[j]) {
109
- multiple = true;
110
- break;
111
- }
112
- }
113
- if (multiple) {
124
+ const seen = new Set();
125
+ for (let i = 0; i < operationIds.length; ++i) {
126
+ if (seen.has(operationIds[i])) {
127
+ multiple = true;
114
128
  break;
115
129
  }
130
+ seen.add(operationIds[i]);
116
131
  }
117
132
  return multiple ? Promise.reject(new Error("There is multiple operationIds in [\" " + operationIds.join("\", ") + " \"]")) : Promise.resolve();
118
133
  });
@@ -1,25 +1,21 @@
1
1
  import { OpenApiValidator } from "express-openapi-validate";
2
- import DescriptorUser, { type iDescriptorUserOptions } from "./DescriptorUser";
3
- import type { iIncomingMessage, iServerResponse } from "./Server";
4
- export interface iIncomingMessageForMediatorValidation extends iIncomingMessage {
5
- "body": any;
6
- }
7
- export interface iServerResponseForMediatorValidation extends iServerResponse {
8
- "body": any;
9
- }
2
+ import DescriptorUser from "./DescriptorUser";
3
+ import type { iDescriptorUserOptions, tEventMap, iEventsMinimal } from "./DescriptorUser";
4
+ import type { iFormatedServerResponseForValidation } from "./Server";
10
5
  export interface iUrlAllowedParameters {
11
- "path"?: Record<string, any>;
12
- "query"?: Record<string, any>;
13
- "headers"?: Record<string, any>;
14
- "cookies"?: Record<string, any>;
15
- "header"?: Record<string, any>;
16
- "cookie"?: Record<string, any>;
6
+ "path"?: Record<string, unknown>;
7
+ "query"?: Record<string, unknown>;
8
+ "headers"?: Record<string, unknown>;
9
+ "cookies"?: Record<string, unknown>;
10
+ "header"?: Record<string, unknown>;
11
+ "cookie"?: Record<string, unknown>;
17
12
  }
18
- export default class Mediator extends DescriptorUser {
13
+ export type iOperationHandler = (url: iUrlAllowedParameters, body: unknown) => Promise<string>;
14
+ export default class Mediator<T extends tEventMap<T> = iEventsMinimal> extends DescriptorUser<T> {
19
15
  protected _validator: OpenApiValidator | null;
20
16
  constructor(options: iDescriptorUserOptions);
21
- checkParameters(operationId: string, urlParams?: iUrlAllowedParameters, bodyParams?: any): Promise<void>;
22
- checkResponse(operationId: string, res: iServerResponseForMediatorValidation): Promise<void>;
23
- init(...data: any): Promise<void>;
24
- release(...data: any): Promise<void>;
17
+ checkParameters(operationId: string, urlParams?: iUrlAllowedParameters, bodyParams?: unknown): Promise<void>;
18
+ checkResponse(operationId: string, res: iFormatedServerResponseForValidation): Promise<void>;
19
+ init(...data: unknown[]): Promise<void>;
20
+ release(...data: unknown[]): Promise<void>;
25
21
  }
@@ -14,6 +14,9 @@ const extractPathMethodByOperationId_1 = __importDefault(require("../utils/descr
14
14
  const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
15
15
  // module
16
16
  class Mediator extends DescriptorUser_1.default {
17
+ // attributes
18
+ // protected
19
+ _validator;
17
20
  // constructor
18
21
  constructor(options) {
19
22
  super(options);
@@ -22,12 +25,11 @@ class Mediator extends DescriptorUser_1.default {
22
25
  // public
23
26
  // Check sended parameters by method name (used by the Server)
24
27
  checkParameters(operationId, urlParams, bodyParams) {
25
- var _a, _b, _c, _d, _e, _f;
26
28
  const urlControlledParameters = {
27
- "path": urlParams ? (_a = urlParams === null || urlParams === void 0 ? void 0 : urlParams.path) !== null && _a !== void 0 ? _a : {} : {},
28
- "query": urlParams ? (_b = urlParams === null || urlParams === void 0 ? void 0 : urlParams.query) !== null && _b !== void 0 ? _b : {} : {},
29
- "headers": urlParams ? (_d = (_c = urlParams === null || urlParams === void 0 ? void 0 : urlParams.headers) !== null && _c !== void 0 ? _c : urlParams === null || urlParams === void 0 ? void 0 : urlParams.header) !== null && _d !== void 0 ? _d : {} : {},
30
- "cookies": urlParams ? (_f = (_e = urlParams === null || urlParams === void 0 ? void 0 : urlParams.cookies) !== null && _e !== void 0 ? _e : urlParams === null || urlParams === void 0 ? void 0 : urlParams.cookie) !== null && _f !== void 0 ? _f : {} : {},
29
+ "path": urlParams?.path ?? {},
30
+ "query": urlParams?.query ?? {},
31
+ "headers": urlParams?.headers ?? urlParams?.header ?? {},
32
+ "cookies": urlParams?.cookies ?? urlParams?.cookie ?? {}
31
33
  };
32
34
  // parameters validation
33
35
  return this.checkDescriptor().then(() => {
@@ -46,7 +48,7 @@ class Mediator extends DescriptorUser_1.default {
46
48
  });
47
49
  }).then(() => {
48
50
  // search wanted operation
49
- const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
51
+ const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor?.paths, operationId);
50
52
  return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
51
53
  const req = {
52
54
  "path": foundPathMethod.path,
@@ -57,31 +59,51 @@ class Mediator extends DescriptorUser_1.default {
57
59
  "cookies": urlControlledParameters.cookies,
58
60
  "body": bodyParams
59
61
  };
60
- const validateRequest = this._validator.validate(req.method, req.path); // set to "any" for ts validation
62
+ const validateRequest = this._validator.validate(req.method, req.path);
61
63
  validateRequest(req, null, (err) => {
62
- return err ? reject(err) : resolve();
64
+ if ("undefined" === typeof err || null === err) {
65
+ return resolve();
66
+ }
67
+ else if (err instanceof Error) {
68
+ return reject(err);
69
+ }
70
+ else if ("object" === typeof err) {
71
+ if ("undefined" !== typeof err.message) {
72
+ return reject(new Error(err.message));
73
+ }
74
+ return reject(new Error(err));
75
+ }
76
+ return reject(new Error(String(err)));
63
77
  });
64
78
  });
65
79
  }).catch((err) => {
66
- return err instanceof express_openapi_validate_1.ValidationError ? Promise.resolve().then(() => {
67
- switch (err.data[0].keyword) { // extract first Error
68
- case "required":
69
- return Promise.reject(new ReferenceError(err.message));
70
- case "type":
71
- case "pattern":
72
- return Promise.reject(new TypeError(err.message));
73
- case "minimum":
74
- case "maximum":
75
- case "minLength":
76
- case "maxLength":
77
- case "minItems":
78
- case "maxItems":
79
- case "enum":
80
- return Promise.reject(new RangeError(err.message));
81
- default:
82
- return Promise.reject(new Error(err.message));
83
- }
84
- }) : Promise.reject(err);
80
+ if (!(err instanceof express_openapi_validate_1.ValidationError)) {
81
+ return Promise.reject(err);
82
+ }
83
+ if ("object" !== typeof err.data
84
+ || !(err.data instanceof Array)
85
+ || 0 >= err.data.length
86
+ || "object" !== typeof err.data[0]
87
+ || "string" !== typeof err.data[0].keyword) {
88
+ return Promise.reject(new Error(err.message));
89
+ }
90
+ switch (err.data[0].keyword) { // extract first Error
91
+ case "required":
92
+ return Promise.reject(new ReferenceError(err.message));
93
+ case "type":
94
+ case "pattern":
95
+ return Promise.reject(new TypeError(err.message));
96
+ case "minimum":
97
+ case "maximum":
98
+ case "minLength":
99
+ case "maxLength":
100
+ case "minItems":
101
+ case "maxItems":
102
+ case "enum":
103
+ return Promise.reject(new RangeError(err.message));
104
+ default:
105
+ return Promise.reject(new Error(err.message));
106
+ }
85
107
  });
86
108
  }
87
109
  // Check sended parameters by method name (used by the Server)
@@ -91,7 +113,7 @@ class Mediator extends DescriptorUser_1.default {
91
113
  return (0, checkNonEmptyString_1.checkNonEmptyString)("operationId", operationId);
92
114
  }).then(() => {
93
115
  // search wanted operation
94
- const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
116
+ const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor?.paths, operationId);
95
117
  return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
96
118
  // no content, no validation
97
119
  if (204 === res.statusCode) {
@@ -102,18 +124,16 @@ class Mediator extends DescriptorUser_1.default {
102
124
  return resolve();
103
125
  }
104
126
  // validator cannot correctly check pure boolean return
105
- else if ("undefined" !== typeof res.body && ["true", "false", true, false].includes(res.body)) {
127
+ else if ("undefined" !== typeof res.body && [
128
+ "true", "false", true, false
129
+ ].includes(res.body)) {
106
130
  return resolve();
107
131
  }
108
132
  else {
109
133
  try {
110
- const mutedRes = Object.assign({}, res);
111
- mutedRes.headers = res.getHeaders();
112
- if ("undefined" === typeof mutedRes.body || "" === mutedRes.body) {
113
- mutedRes.body = {};
114
- }
115
- const validateResponse = this._validator.validateResponse(foundPathMethod.method, foundPathMethod.path);
116
- validateResponse(mutedRes);
134
+ const validateResponse = this._validator
135
+ .validateResponse(foundPathMethod.method, foundPathMethod.path);
136
+ validateResponse(res);
117
137
  return resolve();
118
138
  }
119
139
  catch (e) {
@@ -122,7 +142,7 @@ class Mediator extends DescriptorUser_1.default {
122
142
  + " (" + foundPathMethod.operationId + ") => "
123
143
  + res.statusCode
124
144
  + "\r\n"
125
- + (e.message ? e.message : e)));
145
+ + (e.message ? e.message : String(e))));
126
146
  }
127
147
  }
128
148
  });
@@ -1,12 +1,13 @@
1
- import DescriptorUser, { type iDescriptorUserOptions } from "./DescriptorUser";
1
+ import DescriptorUser from "./DescriptorUser";
2
2
  import Mediator from "./Mediator";
3
+ import type { iDescriptorUserOptions, tEventMap, tEventsNoEvent } from "./DescriptorUser";
3
4
  export interface iMediatorUserOptions extends iDescriptorUserOptions {
4
5
  "mediator"?: Mediator;
5
6
  }
6
- export default class MediatorUser extends DescriptorUser {
7
+ export default class MediatorUser<T extends tEventMap<T> = tEventsNoEvent> extends DescriptorUser<T> {
7
8
  protected _Mediator: Mediator | null;
8
9
  constructor(options: iMediatorUserOptions);
9
- protected _initWorkSpace(...data: any): Promise<void>;
10
- protected _releaseWorkSpace(...data: any): Promise<void>;
10
+ protected _initWorkSpace(...data: unknown[]): Promise<void>;
11
+ protected _releaseWorkSpace(...data: unknown[]): Promise<void>;
11
12
  checkMediator(): Promise<void>;
12
13
  }
@@ -1,21 +1,28 @@
1
1
  "use strict";
2
- // deps
2
+ /*
3
+ eslint-disable @typescript-eslint/no-unused-vars
4
+ */
5
+ // => @typescript-eslint/no-unused-vars is disabled to allow inheritance with proper signature
3
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
8
  };
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ // deps
7
11
  // locals
8
12
  const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
9
13
  const Mediator_1 = __importDefault(require("./Mediator"));
10
14
  // module
11
- // Please note the fact that "init" and "release" method MUST NOT be re-writted. Each child has is own init logic
15
+ // Please note the fact that "init" and "release" method MUST NOT be re-written. Each child has its own init logic
12
16
  class MediatorUser extends DescriptorUser_1.default {
17
+ // attributes
18
+ // protected
19
+ _Mediator; // provided by "mediator" option, sent by the [Orchestrator](./Orchestrator.md)
13
20
  // constructor
14
21
  constructor(options) {
15
22
  super(options);
16
- this._Mediator = options && "undefined" !== typeof options.mediator
17
- ? options.mediator
18
- : null;
23
+ // protected
24
+ // optional props
25
+ this._Mediator = options.mediator ?? null;
19
26
  }
20
27
  // protected
21
28
  _initWorkSpace(...data) {
@@ -1,21 +1,21 @@
1
1
  import MediatorUser from "./MediatorUser";
2
2
  import Server from "./Server";
3
- import { IncomingMessage } from "node:http";
3
+ import type { IncomingMessage, ServerResponse } from "node:http";
4
4
  import type { Server as SocketIOServer } from "socket.io";
5
5
  import type { Server as WebSocketServer } from "ws";
6
- import type { iServerResponse } from "./Server";
7
- import type { tLogger } from "./DescriptorUser";
6
+ import type { Server as SocketIOServerV2 } from "../../@types/socket.io-v2";
7
+ import type { tLogger, tEventMap, iEventsMinimal } from "./DescriptorUser";
8
8
  export interface iOrchestratorOptions {
9
- "externalRessourcesDirectory": string;
9
+ "externalResourcesDirectory": string;
10
10
  "packageFile": string;
11
11
  "descriptorFile": string;
12
12
  "mediatorFile": string;
13
13
  "serverFile": string;
14
14
  "logger"?: tLogger;
15
15
  }
16
- export default class Orchestrator extends MediatorUser {
16
+ export default class Orchestrator<T extends iEventsMinimal & tEventMap<T> = iEventsMinimal> extends MediatorUser<T> {
17
17
  protected _Server: Server | null;
18
- protected _socketServer: WebSocketServer | SocketIOServer | null;
18
+ protected _socketServer: WebSocketServer | SocketIOServer | SocketIOServerV2 | null;
19
19
  protected _checkParameters: boolean;
20
20
  protected _checkResponse: boolean;
21
21
  protected _packageFile: string;
@@ -45,13 +45,13 @@ export default class Orchestrator extends MediatorUser {
45
45
  enableCheckResponse(): this;
46
46
  disableCors(): this;
47
47
  enableCors(): this;
48
- appMiddleware(req: IncomingMessage, res: iServerResponse, next: () => void): void;
48
+ appMiddleware(req: IncomingMessage, res: ServerResponse, next: () => void): void;
49
49
  socketMiddleware(server: WebSocketServer | SocketIOServer): void;
50
- load(...data: any): Promise<void>;
51
- destroy(...data: any): Promise<void>;
52
- init(...data: any): Promise<void>;
53
- release(...data: any): Promise<void>;
54
- install(...data: any): Promise<void>;
55
- update(...data: any): Promise<void>;
56
- uninstall(...data: any): Promise<void>;
50
+ load(...data: unknown[]): Promise<void>;
51
+ destroy(...data: unknown[]): Promise<void>;
52
+ init(...data: unknown[]): Promise<void>;
53
+ release(...data: unknown[]): Promise<void>;
54
+ install(...data: unknown[]): Promise<void>;
55
+ update(...data: unknown[]): Promise<void>;
56
+ uninstall(...data: unknown[]): Promise<void>;
57
57
  }