node-pluginsmanager-plugin 6.5.0 → 7.0.1
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.
- package/LICENSE +13 -13
- package/README.md +53 -48
- package/lib/@types/socket.io-v2.d.ts +988 -0
- package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyObject.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyString.d.ts +2 -2
- package/lib/cjs/checkers/ReferenceError/checkExists.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkFunction.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkInteger.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkNumber.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkObject.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkString.d.ts +2 -2
- package/lib/cjs/components/DescriptorUser.d.ts +10 -11
- package/lib/cjs/components/DescriptorUser.js +51 -40
- package/lib/cjs/components/Mediator.d.ts +12 -17
- package/lib/cjs/components/Mediator.js +59 -39
- package/lib/cjs/components/MediatorUser.d.ts +2 -2
- package/lib/cjs/components/MediatorUser.js +12 -5
- package/lib/cjs/components/Orchestrator.d.ts +13 -13
- package/lib/cjs/components/Orchestrator.js +123 -69
- package/lib/cjs/components/Server.d.ts +22 -19
- package/lib/cjs/components/Server.js +279 -238
- package/lib/cjs/main.cjs +1 -40
- package/lib/cjs/main.d.cts +3 -15
- package/lib/cjs/openAPITypes.d.ts +5 -0
- package/lib/cjs/openAPITypes.js +3 -0
- package/lib/cjs/utils/cleanSendedError.d.ts +1 -1
- package/lib/cjs/utils/cleanSendedError.js +2 -4
- package/lib/cjs/utils/descriptor/extractParams.d.ts +1 -1
- package/lib/cjs/utils/descriptor/extractParams.js +1 -1
- package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.d.ts +2 -3
- package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.js +14 -14
- package/lib/cjs/utils/descriptor/extractPattern.d.ts +2 -2
- package/lib/cjs/utils/descriptor/extractPattern.js +5 -5
- package/lib/cjs/utils/descriptor/extractSchemaType.d.ts +1 -1
- package/lib/cjs/utils/descriptor/extractSchemaType.js +13 -8
- package/lib/cjs/utils/file/readJSONFile.d.ts +1 -1
- package/lib/cjs/utils/request/extractBody.js +9 -5
- package/lib/cjs/utils/request/extractCookies.d.ts +1 -1
- package/lib/cjs/utils/request/extractCookies.js +6 -6
- package/lib/cjs/utils/request/extractIp.d.ts +1 -1
- package/lib/cjs/utils/request/extractIp.js +19 -10
- package/lib/cjs/utils/request/extractMime.d.ts +1 -4
- package/lib/cjs/utils/request/extractMime.js +15 -11
- package/lib/cjs/utils/send.d.ts +4 -4
- package/lib/cjs/utils/send.js +27 -29
- package/lib/cjs/utils/server/getServerTypeFromServer.d.ts +4 -0
- package/lib/cjs/utils/server/getServerTypeFromServer.js +23 -0
- package/lib/cjs/utils/server/getSocketIOVersionFromServer.d.ts +4 -0
- package/lib/cjs/utils/server/getSocketIOVersionFromServer.js +19 -0
- package/package.json +101 -97
- package/lib/cjs/checkers/RangeError/checkArrayLength.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkArrayLength.js +0 -23
- package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.js +0 -30
- package/lib/cjs/checkers/RangeError/checkIntegerBetween.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkIntegerBetween.js +0 -29
- package/lib/cjs/checkers/RangeError/checkNonEmptyArray.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyArray.js +0 -19
- package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.js +0 -19
- package/lib/cjs/checkers/RangeError/checkNumberBetween.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkNumberBetween.js +0 -29
- package/lib/cjs/checkers/RangeError/checkObjectLength.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkObjectLength.js +0 -28
- package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.js +0 -33
- package/lib/cjs/checkers/RangeError/checkStringLength.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkStringLength.js +0 -23
- package/lib/cjs/checkers/RangeError/checkStringLengthBetween.d.ts +0 -2
- package/lib/cjs/checkers/RangeError/checkStringLengthBetween.js +0 -30
- package/lib/cjs/checkers/TypeError/checkArray.d.ts +0 -2
- package/lib/cjs/checkers/TypeError/checkArray.js +0 -19
- package/lib/cjs/checkers/TypeError/checkBoolean.d.ts +0 -2
- package/lib/cjs/checkers/TypeError/checkBoolean.js +0 -19
- package/lib/cjs/utils/jsonParser.d.ts +0 -1
- package/lib/cjs/utils/jsonParser.js +0 -16
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function checkNonEmptyNumberSync(dataName: string, data:
|
|
2
|
-
export declare function checkNonEmptyNumber(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkNonEmptyObject(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkNonEmptyString(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkExists(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkFunction(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkInteger(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkNumber(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkObject(dataName: string, data:
|
|
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:
|
|
2
|
-
export declare function checkString(dataName: string, data:
|
|
1
|
+
export declare function checkStringSync(dataName: string, data: unknown): ReferenceError | TypeError | null;
|
|
2
|
+
export declare function checkString(dataName: string, data: unknown): Promise<void>;
|
|
@@ -3,32 +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
|
-
"
|
|
6
|
+
"externalResourcesDirectory": string;
|
|
7
7
|
"descriptor"?: OpenApiDocument;
|
|
8
8
|
"logger"?: tLogger;
|
|
9
9
|
}
|
|
10
|
-
export type tEventMap<T> = Record<keyof T,
|
|
11
|
-
export type tEventsNoEvent =
|
|
10
|
+
export type tEventMap<T> = Record<keyof T, unknown[]>;
|
|
11
|
+
export type tEventsNoEvent = {};
|
|
12
12
|
export interface iEventsMinimal {
|
|
13
13
|
"error": [Error];
|
|
14
|
-
"initialized": [
|
|
15
|
-
"released": [
|
|
14
|
+
"initialized": [unknown];
|
|
15
|
+
"released": [unknown];
|
|
16
16
|
}
|
|
17
17
|
export default class DescriptorUser<T extends tEventMap<T> = tEventsNoEvent> extends EventEmitter<T> {
|
|
18
18
|
initialized: boolean;
|
|
19
19
|
protected _descriptorValidated: boolean;
|
|
20
|
-
protected
|
|
20
|
+
protected _externalResourcesDirectory: string;
|
|
21
21
|
protected _Descriptor: OpenApiDocument | null;
|
|
22
22
|
protected _Logger: tLogger | null;
|
|
23
23
|
constructor(options: iDescriptorUserOptions);
|
|
24
|
-
protected _initWorkSpace(...data:
|
|
25
|
-
protected _releaseWorkSpace(...data:
|
|
24
|
+
protected _initWorkSpace(...data: unknown[]): Promise<void>;
|
|
25
|
+
protected _releaseWorkSpace(...data: unknown[]): Promise<void>;
|
|
26
26
|
protected _log(type: tLogType, message: string | Error, bold?: boolean): this;
|
|
27
|
-
protected _emitEventGenericForTSPurposeDONOTUSE(event: string, ...args: any[]): boolean;
|
|
28
27
|
getPluginName(): string;
|
|
29
28
|
getPluginVersion(): string;
|
|
30
29
|
getPluginDescription(): string;
|
|
31
|
-
init(...data:
|
|
32
|
-
release(...data:
|
|
30
|
+
init(...data: unknown[]): Promise<void>;
|
|
31
|
+
release(...data: unknown[]): Promise<void>;
|
|
33
32
|
checkDescriptor(): Promise<void>;
|
|
34
33
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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-
|
|
20
|
-
// Please note the fact that "init" and "release" method MUST NOT be re-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
@@ -51,72 +65,69 @@ class DescriptorUser extends node_events_1.EventEmitter {
|
|
|
51
65
|
}
|
|
52
66
|
return this;
|
|
53
67
|
}
|
|
54
|
-
// used to faint the typing of EventEmitter for emit into a generic class (which MUST be inherited anyway) like Mediator/Server/Orchestrator
|
|
55
|
-
_emitEventGenericForTSPurposeDONOTUSE(event, ...args) {
|
|
56
|
-
return this.emit(event, ...args);
|
|
57
|
-
}
|
|
58
68
|
// public
|
|
59
69
|
getPluginName() {
|
|
60
|
-
return this._Descriptor
|
|
70
|
+
return this._Descriptor?.info.title ?? "";
|
|
61
71
|
}
|
|
62
72
|
getPluginVersion() {
|
|
63
|
-
return this._Descriptor
|
|
73
|
+
return this._Descriptor?.info.version ?? "";
|
|
64
74
|
}
|
|
65
75
|
getPluginDescription() {
|
|
66
|
-
return this._Descriptor
|
|
76
|
+
return this._Descriptor?.info.description ?? "";
|
|
67
77
|
}
|
|
68
78
|
// must be inherited
|
|
69
79
|
init(...data) {
|
|
70
|
-
console.log("DescriptorUser", "init", ...data);
|
|
71
80
|
return Promise.reject(new Error("\"init\" method must be inherited"));
|
|
72
81
|
}
|
|
73
82
|
// must be inherited
|
|
74
83
|
release(...data) {
|
|
75
|
-
console.log("DescriptorUser", "release", ...data);
|
|
76
84
|
return Promise.reject(new Error("\"release\" method must be inherited"));
|
|
77
85
|
}
|
|
78
86
|
// must be inherited
|
|
79
87
|
checkDescriptor() {
|
|
88
|
+
if (this._descriptorValidated) {
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
}
|
|
80
91
|
// check Descriptor object
|
|
81
|
-
return
|
|
92
|
+
return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor", this._Descriptor).then(() => {
|
|
82
93
|
// check info object
|
|
83
94
|
return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor.info", this._Descriptor.info).then(() => {
|
|
95
|
+
const { title, version } = this._Descriptor.info;
|
|
84
96
|
// check title
|
|
85
|
-
return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.title",
|
|
86
|
-
return
|
|
87
|
-
? Promise.reject(new Error("The descriptor's 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 + "\") "
|
|
88
100
|
+ "is not equals in lower case (package.json convention)"))
|
|
89
101
|
: Promise.resolve();
|
|
90
102
|
// check version
|
|
91
103
|
}).then(() => {
|
|
92
|
-
return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version",
|
|
104
|
+
return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version", version);
|
|
93
105
|
});
|
|
94
106
|
});
|
|
95
107
|
}).then(() => {
|
|
108
|
+
const { paths } = this._Descriptor;
|
|
96
109
|
// check paths object
|
|
97
|
-
return (
|
|
110
|
+
return (0, checkObject_1.checkObject)("Descriptor.paths", paths).then(() => {
|
|
98
111
|
// check multiple operationIds
|
|
99
112
|
return Promise.resolve().then(() => {
|
|
100
113
|
const operationIds = [];
|
|
101
|
-
Object.keys(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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);
|
|
106
120
|
}
|
|
107
121
|
});
|
|
108
122
|
});
|
|
109
123
|
let multiple = false;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
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;
|
|
118
128
|
break;
|
|
119
129
|
}
|
|
130
|
+
seen.add(operationIds[i]);
|
|
120
131
|
}
|
|
121
132
|
return multiple ? Promise.reject(new Error("There is multiple operationIds in [\" " + operationIds.join("\", ") + " \"]")) : Promise.resolve();
|
|
122
133
|
});
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import { OpenApiValidator } from "express-openapi-validate";
|
|
2
2
|
import DescriptorUser from "./DescriptorUser";
|
|
3
3
|
import type { iDescriptorUserOptions, tEventMap, iEventsMinimal } from "./DescriptorUser";
|
|
4
|
-
import type {
|
|
5
|
-
export interface iIncomingMessageForMediatorValidation extends iIncomingMessage {
|
|
6
|
-
"body": any;
|
|
7
|
-
}
|
|
8
|
-
export interface iServerResponseForMediatorValidation extends iServerResponse {
|
|
9
|
-
"body": any;
|
|
10
|
-
}
|
|
4
|
+
import type { iFormatedServerResponseForValidation } from "./Server";
|
|
11
5
|
export interface iUrlAllowedParameters {
|
|
12
|
-
"path"?: Record<string,
|
|
13
|
-
"query"?: Record<string,
|
|
14
|
-
"headers"?: Record<string,
|
|
15
|
-
"cookies"?: Record<string,
|
|
16
|
-
"header"?: Record<string,
|
|
17
|
-
"cookie"?: Record<string,
|
|
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>;
|
|
18
12
|
}
|
|
13
|
+
export type iOperationHandler = (url: iUrlAllowedParameters, body: unknown) => Promise<string>;
|
|
19
14
|
export default class Mediator<T extends tEventMap<T> = iEventsMinimal> extends DescriptorUser<T> {
|
|
20
15
|
protected _validator: OpenApiValidator | null;
|
|
21
16
|
constructor(options: iDescriptorUserOptions);
|
|
22
|
-
checkParameters(operationId: string, urlParams?: iUrlAllowedParameters, bodyParams?:
|
|
23
|
-
checkResponse(operationId: string, res:
|
|
24
|
-
init(...data:
|
|
25
|
-
release(...data:
|
|
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>;
|
|
26
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
|
|
28
|
-
"query": urlParams
|
|
29
|
-
"headers": urlParams
|
|
30
|
-
"cookies": urlParams
|
|
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
|
|
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);
|
|
62
|
+
const validateRequest = this._validator.validate(req.method, req.path);
|
|
61
63
|
validateRequest(req, null, (err) => {
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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 && [
|
|
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
|
|
111
|
-
|
|
112
|
-
|
|
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
|
});
|
|
@@ -133,7 +153,7 @@ class Mediator extends DescriptorUser_1.default {
|
|
|
133
153
|
return this._initWorkSpace(...data).then(() => {
|
|
134
154
|
this._validator = new express_openapi_validate_1.OpenApiValidator(this._Descriptor);
|
|
135
155
|
this.initialized = true;
|
|
136
|
-
this.
|
|
156
|
+
this.emit("initialized", ...data);
|
|
137
157
|
});
|
|
138
158
|
}
|
|
139
159
|
release(...data) {
|
|
@@ -142,7 +162,7 @@ class Mediator extends DescriptorUser_1.default {
|
|
|
142
162
|
this._Descriptor = null;
|
|
143
163
|
this._validator = null;
|
|
144
164
|
this.initialized = false;
|
|
145
|
-
this.
|
|
165
|
+
this.emit("released", ...data);
|
|
146
166
|
}).then(() => {
|
|
147
167
|
this.removeAllListeners();
|
|
148
168
|
});
|
|
@@ -7,7 +7,7 @@ export interface iMediatorUserOptions extends iDescriptorUserOptions {
|
|
|
7
7
|
export default class MediatorUser<T extends tEventMap<T> = tEventsNoEvent> extends DescriptorUser<T> {
|
|
8
8
|
protected _Mediator: Mediator | null;
|
|
9
9
|
constructor(options: iMediatorUserOptions);
|
|
10
|
-
protected _initWorkSpace(...data:
|
|
11
|
-
protected _releaseWorkSpace(...data:
|
|
10
|
+
protected _initWorkSpace(...data: unknown[]): Promise<void>;
|
|
11
|
+
protected _releaseWorkSpace(...data: unknown[]): Promise<void>;
|
|
12
12
|
checkMediator(): Promise<void>;
|
|
13
13
|
}
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 type { 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 {
|
|
6
|
+
import type { Server as SocketIOServerV2 } from "../../@types/socket.io-v2";
|
|
7
7
|
import type { tLogger, tEventMap, iEventsMinimal } from "./DescriptorUser";
|
|
8
8
|
export interface iOrchestratorOptions {
|
|
9
|
-
"
|
|
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<T extends tEventMap<T> = iEventsMinimal> extends MediatorUser<T> {
|
|
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<T extends tEventMap<T> = iEventsMinimal> exten
|
|
|
45
45
|
enableCheckResponse(): this;
|
|
46
46
|
disableCors(): this;
|
|
47
47
|
enableCors(): this;
|
|
48
|
-
appMiddleware(req: IncomingMessage, res:
|
|
48
|
+
appMiddleware(req: IncomingMessage, res: ServerResponse, next: () => void): void;
|
|
49
49
|
socketMiddleware(server: WebSocketServer | SocketIOServer): void;
|
|
50
|
-
load(...data:
|
|
51
|
-
destroy(...data:
|
|
52
|
-
init(...data:
|
|
53
|
-
release(...data:
|
|
54
|
-
install(...data:
|
|
55
|
-
update(...data:
|
|
56
|
-
uninstall(...data:
|
|
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
|
}
|