node-pluginsmanager-plugin 5.0.13 → 5.0.14
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 +1 -1
- package/lib/cjs/checkers/RangeError/checkArrayLength.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkArrayLength.js +26 -26
- package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.js +33 -33
- package/lib/cjs/checkers/RangeError/checkIntegerBetween.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkIntegerBetween.js +32 -32
- package/lib/cjs/checkers/RangeError/checkNonEmptyArray.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyArray.js +22 -22
- package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.js +22 -22
- package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.js +22 -22
- package/lib/cjs/checkers/RangeError/checkNonEmptyObject.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyObject.js +22 -22
- package/lib/cjs/checkers/RangeError/checkNonEmptyString.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNonEmptyString.js +22 -22
- package/lib/cjs/checkers/RangeError/checkNumberBetween.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkNumberBetween.js +32 -32
- package/lib/cjs/checkers/RangeError/checkObjectLength.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkObjectLength.js +31 -31
- package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.js +36 -36
- package/lib/cjs/checkers/RangeError/checkStringLength.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkStringLength.js +26 -26
- package/lib/cjs/checkers/RangeError/checkStringLengthBetween.d.ts +2 -2
- package/lib/cjs/checkers/RangeError/checkStringLengthBetween.js +33 -33
- package/lib/cjs/checkers/ReferenceError/checkExists.d.ts +2 -2
- package/lib/cjs/checkers/ReferenceError/checkExists.js +19 -19
- package/lib/cjs/checkers/TypeError/checkArray.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkArray.js +22 -22
- package/lib/cjs/checkers/TypeError/checkBoolean.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkBoolean.js +22 -22
- package/lib/cjs/checkers/TypeError/checkFunction.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkFunction.js +22 -22
- package/lib/cjs/checkers/TypeError/checkInteger.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkInteger.js +22 -22
- package/lib/cjs/checkers/TypeError/checkNumber.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkNumber.js +22 -22
- package/lib/cjs/checkers/TypeError/checkObject.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkObject.js +22 -22
- package/lib/cjs/checkers/TypeError/checkString.d.ts +2 -2
- package/lib/cjs/checkers/TypeError/checkString.js +22 -22
- package/lib/cjs/components/DescriptorUser.d.ts +27 -27
- package/lib/cjs/components/DescriptorUser.js +117 -117
- package/lib/cjs/components/Mediator.d.ts +28 -28
- package/lib/cjs/components/Mediator.js +145 -145
- package/lib/cjs/components/MediatorUser.d.ts +12 -12
- package/lib/cjs/components/MediatorUser.js +40 -40
- package/lib/cjs/components/NotFoundError.d.ts +2 -2
- package/lib/cjs/components/NotFoundError.js +7 -7
- package/lib/cjs/components/Orchestrator.d.ts +57 -57
- package/lib/cjs/components/Orchestrator.js +404 -404
- package/lib/cjs/components/Server.d.ts +55 -55
- package/lib/cjs/components/Server.js +560 -560
- package/lib/cjs/main.cjs +90 -90
- package/lib/cjs/main.d.cts +30 -30
- package/lib/cjs/utils/cleanSendedError.d.ts +1 -1
- package/lib/cjs/utils/cleanSendedError.js +24 -24
- package/lib/cjs/utils/descriptor/extractParams.d.ts +3 -3
- package/lib/cjs/utils/descriptor/extractParams.js +21 -21
- package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.d.ts +8 -8
- package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.js +34 -34
- package/lib/cjs/utils/descriptor/extractPattern.d.ts +2 -2
- package/lib/cjs/utils/descriptor/extractPattern.js +28 -28
- package/lib/cjs/utils/descriptor/extractSchemaType.d.ts +4 -4
- package/lib/cjs/utils/descriptor/extractSchemaType.js +18 -18
- package/lib/cjs/utils/file/checkFile.d.ts +1 -1
- package/lib/cjs/utils/file/checkFile.js +17 -17
- package/lib/cjs/utils/file/isFile.d.ts +1 -1
- package/lib/cjs/utils/file/isFile.js +19 -19
- package/lib/cjs/utils/file/readJSONFile.d.ts +1 -1
- package/lib/cjs/utils/file/readJSONFile.js +20 -24
- package/lib/cjs/utils/removeFirstSlash.d.ts +1 -1
- package/lib/cjs/utils/removeFirstSlash.js +8 -8
- package/lib/cjs/utils/request/extractBody.d.ts +7 -7
- package/lib/cjs/utils/request/extractBody.js +52 -52
- package/lib/cjs/utils/request/extractCookies.d.ts +4 -4
- package/lib/cjs/utils/request/extractCookies.js +53 -53
- package/lib/cjs/utils/request/extractIp.d.ts +1 -1
- package/lib/cjs/utils/request/extractIp.js +40 -40
- package/lib/cjs/utils/send.d.ts +2 -2
- package/lib/cjs/utils/send.js +57 -57
- package/lib/cjs/utils/serverCodes.d.ts +14 -14
- package/lib/cjs/utils/serverCodes.js +15 -15
- package/package.json +42 -32
- package/lib/cjs/utils/getUniqueID.d.ts +0 -1
- package/lib/cjs/utils/getUniqueID.js +0 -16
|
@@ -1,404 +1,404 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// deps
|
|
7
|
-
// externals
|
|
8
|
-
const
|
|
9
|
-
const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
|
|
10
|
-
// locals
|
|
11
|
-
const checkObject_1 = require("../checkers/TypeError/checkObject");
|
|
12
|
-
const MediatorUser_1 = __importDefault(require("./MediatorUser"));
|
|
13
|
-
const Server_1 = __importDefault(require("./Server"));
|
|
14
|
-
const checkFile_1 = __importDefault(require("../utils/file/checkFile"));
|
|
15
|
-
const readJSONFile_1 = __importDefault(require("../utils/file/readJSONFile"));
|
|
16
|
-
;
|
|
17
|
-
// module
|
|
18
|
-
class Orchestrator extends MediatorUser_1.default {
|
|
19
|
-
// constructor
|
|
20
|
-
constructor(options) {
|
|
21
|
-
super(options);
|
|
22
|
-
// protected
|
|
23
|
-
this._Server = null;
|
|
24
|
-
this._socketServer = null; // to delay socketMiddleware if necessary
|
|
25
|
-
this._checkParameters = true; // to delay checkParameters if necessary
|
|
26
|
-
this._checkResponse = true; // to delay checkResponse if necessary
|
|
27
|
-
// params
|
|
28
|
-
this._packageFile = options && "string" === typeof options.packageFile ? options.packageFile : "";
|
|
29
|
-
this._descriptorFile = options && "string" === typeof options.descriptorFile ? options.descriptorFile : "";
|
|
30
|
-
this._mediatorFile = options && "string" === typeof options.mediatorFile ? options.mediatorFile : "";
|
|
31
|
-
this._serverFile = options && "string" === typeof options.serverFile ? options.serverFile : "";
|
|
32
|
-
// extended
|
|
33
|
-
this._extended = [];
|
|
34
|
-
// public
|
|
35
|
-
this.enabled = true;
|
|
36
|
-
// native
|
|
37
|
-
this.authors = [];
|
|
38
|
-
this.description = "";
|
|
39
|
-
this.dependencies = null;
|
|
40
|
-
this.devDependencies = null;
|
|
41
|
-
this.engines = null;
|
|
42
|
-
this.license = "";
|
|
43
|
-
this.main = "";
|
|
44
|
-
this.name = "";
|
|
45
|
-
this.scripts = null;
|
|
46
|
-
this.version = "";
|
|
47
|
-
}
|
|
48
|
-
// public
|
|
49
|
-
checkDescriptor() {
|
|
50
|
-
return super.checkDescriptor().then(() => {
|
|
51
|
-
return swagger_parser_1.default.validate(this._descriptorFile);
|
|
52
|
-
}).then(() => {
|
|
53
|
-
return Promise.resolve();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
// checkers
|
|
57
|
-
checkConf() {
|
|
58
|
-
return Promise.resolve();
|
|
59
|
-
}
|
|
60
|
-
isEnable() {
|
|
61
|
-
this.enabled = true;
|
|
62
|
-
return Promise.resolve();
|
|
63
|
-
}
|
|
64
|
-
checkFiles() {
|
|
65
|
-
// check package
|
|
66
|
-
return Promise.resolve().then(() => {
|
|
67
|
-
return (0, checkFile_1.default)(this._packageFile).catch((err) => {
|
|
68
|
-
err.message = "package : " + err.message;
|
|
69
|
-
return Promise.reject(err);
|
|
70
|
-
});
|
|
71
|
-
// check Descriptor
|
|
72
|
-
}).then(() => {
|
|
73
|
-
return (0, checkFile_1.default)(this._descriptorFile).catch((err) => {
|
|
74
|
-
err.message = "descriptor : " + err.message;
|
|
75
|
-
return Promise.reject(err);
|
|
76
|
-
});
|
|
77
|
-
// check Mediator
|
|
78
|
-
}).then(() => {
|
|
79
|
-
return (0, checkFile_1.default)(this._mediatorFile).catch((err) => {
|
|
80
|
-
err.message = "mediator : " + err.message;
|
|
81
|
-
return Promise.reject(err);
|
|
82
|
-
});
|
|
83
|
-
// check Server
|
|
84
|
-
}).then(() => {
|
|
85
|
-
return (0, checkFile_1.default)(this._serverFile).catch((err) => {
|
|
86
|
-
err.message = "server : " + err.message;
|
|
87
|
-
return Promise.reject(err);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
checkServer() {
|
|
92
|
-
return (0, checkObject_1.checkObject)("Server", this._Server).then(() => {
|
|
93
|
-
return this._Server instanceof Server_1.default ? Promise.resolve() : Promise.reject(new TypeError("The plugin has an invalid Server which is not an instance (or a child) of the official Server class"));
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
// middlewares
|
|
97
|
-
disableCheckParameters() {
|
|
98
|
-
this.checkServer().then(() => {
|
|
99
|
-
this._Server.disableCheckParameters();
|
|
100
|
-
}).catch(() => {
|
|
101
|
-
this._checkParameters = false; // delay checkParameters if necessary
|
|
102
|
-
});
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
enableCheckParameters() {
|
|
106
|
-
this.checkServer().then(() => {
|
|
107
|
-
this._Server.enableCheckParameters();
|
|
108
|
-
}).catch(() => {
|
|
109
|
-
this._checkParameters = true; // delay checkParameters if necessary
|
|
110
|
-
});
|
|
111
|
-
return this;
|
|
112
|
-
}
|
|
113
|
-
disableCheckResponse() {
|
|
114
|
-
this.checkServer().then(() => {
|
|
115
|
-
this._Server.disableCheckResponse();
|
|
116
|
-
}).catch(() => {
|
|
117
|
-
this._checkResponse = false; // delay checkResponse if necessary
|
|
118
|
-
});
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
enableCheckResponse() {
|
|
122
|
-
this.checkServer().then(() => {
|
|
123
|
-
this._Server.enableCheckResponse();
|
|
124
|
-
}).catch(() => {
|
|
125
|
-
this._checkResponse = true; // delay checkResponse if necessary
|
|
126
|
-
});
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
disableCors() {
|
|
130
|
-
this.checkServer().then(() => {
|
|
131
|
-
this._Server.disableCors();
|
|
132
|
-
}).catch((err) => {
|
|
133
|
-
this.emit("error", err);
|
|
134
|
-
});
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
enableCors() {
|
|
138
|
-
this.checkServer().then(() => {
|
|
139
|
-
this._Server.enableCors();
|
|
140
|
-
}).catch((err) => {
|
|
141
|
-
this.emit("error", err);
|
|
142
|
-
});
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
appMiddleware(req, res, next) {
|
|
146
|
-
if (!this.enabled) {
|
|
147
|
-
next();
|
|
148
|
-
}
|
|
149
|
-
else if (!this.initialized) {
|
|
150
|
-
next();
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
this.checkServer().then(() => {
|
|
154
|
-
this._Server.appMiddleware(req, res, next);
|
|
155
|
-
}).catch(() => {
|
|
156
|
-
next();
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
socketMiddleware(server) {
|
|
161
|
-
if (!this.enabled) {
|
|
162
|
-
this._socketServer = server; // delay socketMiddleware if necessary
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this.checkServer().then(() => {
|
|
166
|
-
this._Server.socketMiddleware(server);
|
|
167
|
-
}).catch(() => {
|
|
168
|
-
this._socketServer = server; // delay socketMiddleware if necessary
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// load / destroy
|
|
173
|
-
load(...data) {
|
|
174
|
-
return this.checkFiles().then(() => {
|
|
175
|
-
return (0, readJSONFile_1.default)((0,
|
|
176
|
-
}).then(({ engines }) => {
|
|
177
|
-
// native
|
|
178
|
-
this.authors = [];
|
|
179
|
-
this.description = "";
|
|
180
|
-
this.dependencies = {};
|
|
181
|
-
this.devDependencies = {};
|
|
182
|
-
this.engines = engines;
|
|
183
|
-
this.license = "MIT";
|
|
184
|
-
this.main = "lib/main.js";
|
|
185
|
-
this.name = "";
|
|
186
|
-
this.scripts = {};
|
|
187
|
-
this.version = "";
|
|
188
|
-
return (0, readJSONFile_1.default)(this._packageFile);
|
|
189
|
-
// formate authors
|
|
190
|
-
}).then((data) => {
|
|
191
|
-
if (data.authors) {
|
|
192
|
-
this.authors = data.authors;
|
|
193
|
-
delete data.authors;
|
|
194
|
-
if (data.author) {
|
|
195
|
-
if (!this.authors.includes(data.author)) {
|
|
196
|
-
this.authors.push(data.author);
|
|
197
|
-
}
|
|
198
|
-
delete data.author;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else if (data.author) {
|
|
202
|
-
this.authors = [data.author];
|
|
203
|
-
delete data.author;
|
|
204
|
-
}
|
|
205
|
-
return Promise.resolve(data);
|
|
206
|
-
// formate other data
|
|
207
|
-
}).then((data) => {
|
|
208
|
-
const self = this;
|
|
209
|
-
Object.keys(data).forEach((key) => {
|
|
210
|
-
if ("function" !== typeof self[key]) {
|
|
211
|
-
if ("undefined" === typeof self[key]) {
|
|
212
|
-
this._extended.push(key);
|
|
213
|
-
}
|
|
214
|
-
self[key] = data[key];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
destroy(...data) {
|
|
220
|
-
return Promise.resolve().then(() => {
|
|
221
|
-
// protected
|
|
222
|
-
// params
|
|
223
|
-
this._packageFile = "";
|
|
224
|
-
this._descriptorFile = "";
|
|
225
|
-
this._mediatorFile = "";
|
|
226
|
-
this._serverFile = "";
|
|
227
|
-
// extended
|
|
228
|
-
this._extended.forEach((key) => {
|
|
229
|
-
delete this[key];
|
|
230
|
-
});
|
|
231
|
-
this._extended = [];
|
|
232
|
-
// public
|
|
233
|
-
// native
|
|
234
|
-
this.authors = [];
|
|
235
|
-
this.description = "";
|
|
236
|
-
this.dependencies = null;
|
|
237
|
-
this.devDependencies = null;
|
|
238
|
-
this.engines = null;
|
|
239
|
-
this.license = "";
|
|
240
|
-
this.main = "";
|
|
241
|
-
this.name = "";
|
|
242
|
-
this.scripts = null;
|
|
243
|
-
this.version = "";
|
|
244
|
-
}).then(() => {
|
|
245
|
-
this.removeAllListeners();
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
// init / release
|
|
249
|
-
init(...data) {
|
|
250
|
-
// ensure conf validity
|
|
251
|
-
return Promise.resolve().then(() => {
|
|
252
|
-
return this.checkConf();
|
|
253
|
-
// get enable status
|
|
254
|
-
}).then(() => {
|
|
255
|
-
return this.isEnable();
|
|
256
|
-
}).then(() => {
|
|
257
|
-
return !this.enabled ? Promise.resolve() : Promise.resolve().then(() => {
|
|
258
|
-
// create Descriptor
|
|
259
|
-
return swagger_parser_1.default.bundle(this._descriptorFile).then((content) => {
|
|
260
|
-
return Promise.resolve(content);
|
|
261
|
-
}).then((content) => {
|
|
262
|
-
this._Descriptor = content;
|
|
263
|
-
return this.checkDescriptor().catch((err) => {
|
|
264
|
-
this._Descriptor = null;
|
|
265
|
-
return Promise.reject(err);
|
|
266
|
-
});
|
|
267
|
-
// compare title to package name
|
|
268
|
-
}).then(() => {
|
|
269
|
-
return this._Descriptor.info.title !== this.name ? Promise.reject(new Error("The descriptor's title (\"" + this._Descriptor.info.title + "\") " +
|
|
270
|
-
"is not equals to " +
|
|
271
|
-
"the package's name (\"" + this.name + "\")")) : Promise.resolve();
|
|
272
|
-
// compare version to package version
|
|
273
|
-
}).then(() => {
|
|
274
|
-
return this._Descriptor.info.version !== this.version ? Promise.reject(new Error("The descriptor's version (\"" + this._Descriptor.info.version + "\") " +
|
|
275
|
-
"is not equals to " +
|
|
276
|
-
"the package's version (\"" + this.version + "\")")) : Promise.resolve();
|
|
277
|
-
});
|
|
278
|
-
// create Mediator
|
|
279
|
-
}).then(() => {
|
|
280
|
-
// load
|
|
281
|
-
return new Promise((resolve, reject) => {
|
|
282
|
-
try {
|
|
283
|
-
const val = require(this._mediatorFile);
|
|
284
|
-
if ("object" === typeof val && "function" === typeof val.default) {
|
|
285
|
-
resolve(val.default);
|
|
286
|
-
}
|
|
287
|
-
else if ("function" === typeof val) {
|
|
288
|
-
resolve(val);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
reject(new Error("Mediator file loaded (\"" + this._mediatorFile + "\") does not contain a valid Mediator"));
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch (e) {
|
|
295
|
-
reject(e);
|
|
296
|
-
}
|
|
297
|
-
// init
|
|
298
|
-
}).then((PluginMediator) => {
|
|
299
|
-
this._Mediator = new PluginMediator({
|
|
300
|
-
"descriptor": this._Descriptor,
|
|
301
|
-
"externalRessourcesDirectory": this._externalRessourcesDirectory,
|
|
302
|
-
"logger": this._Logger
|
|
303
|
-
});
|
|
304
|
-
// check
|
|
305
|
-
}).then(() => {
|
|
306
|
-
return this.checkMediator().then(() => {
|
|
307
|
-
// intercept errors to avoid non-catched ones
|
|
308
|
-
this._Mediator.on("error", (err) => {
|
|
309
|
-
this.emit("error", err);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
// create Server
|
|
314
|
-
}).then(() => {
|
|
315
|
-
// load
|
|
316
|
-
return new Promise((resolve, reject) => {
|
|
317
|
-
try {
|
|
318
|
-
const val = require(this._serverFile);
|
|
319
|
-
if ("object" === typeof val && "function" === typeof val.default) {
|
|
320
|
-
resolve(val.default);
|
|
321
|
-
}
|
|
322
|
-
else if ("function" === typeof val) {
|
|
323
|
-
resolve(val);
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
reject(new Error("Server file loaded (\"" + this._serverFile + "\") does not contain a valid Server"));
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
catch (e) {
|
|
330
|
-
reject(e);
|
|
331
|
-
}
|
|
332
|
-
// init
|
|
333
|
-
}).then((PluginServer) => {
|
|
334
|
-
this._Server = new PluginServer({
|
|
335
|
-
"descriptor": this._Descriptor,
|
|
336
|
-
"mediator": this._Mediator,
|
|
337
|
-
"externalRessourcesDirectory": this._externalRessourcesDirectory,
|
|
338
|
-
"logger": this._Logger
|
|
339
|
-
});
|
|
340
|
-
// check
|
|
341
|
-
}).then(() => {
|
|
342
|
-
return this.checkServer().then(() => {
|
|
343
|
-
// intercept errors to avoid non-catched ones
|
|
344
|
-
this._Server.on("error", (err) => {
|
|
345
|
-
this.emit("error", err);
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
}).then(() => {
|
|
350
|
-
return this._initWorkSpace(...data);
|
|
351
|
-
// init Server (before Mediator)
|
|
352
|
-
}).then(() => {
|
|
353
|
-
return this._Server.init(...data).then(() => {
|
|
354
|
-
if (this._socketServer) { // delayed socketMiddleware
|
|
355
|
-
this._Server.socketMiddleware(this._socketServer);
|
|
356
|
-
this._socketServer = null;
|
|
357
|
-
}
|
|
358
|
-
if (!this._checkParameters) { // delayed checkParameters
|
|
359
|
-
this._Server.disableCheckParameters();
|
|
360
|
-
}
|
|
361
|
-
if (!this._checkResponse) { // delayed checkResponse
|
|
362
|
-
this._Server.disableCheckResponse();
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
// init Mediator
|
|
366
|
-
}).then(() => {
|
|
367
|
-
return this._Mediator.init(...data);
|
|
368
|
-
}).then(() => {
|
|
369
|
-
this.initialized = true;
|
|
370
|
-
this.emit("initialized", ...data);
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
release(...data) {
|
|
375
|
-
return Promise.resolve().then(() => {
|
|
376
|
-
return this._Mediator ? this._Mediator.release(...data).then(() => {
|
|
377
|
-
this._Mediator = null;
|
|
378
|
-
}) : Promise.resolve();
|
|
379
|
-
}).then(() => {
|
|
380
|
-
return this._Server ? this._Server.release(...data).then(() => {
|
|
381
|
-
this._socketServer = null;
|
|
382
|
-
this._Server = null;
|
|
383
|
-
}) : Promise.resolve();
|
|
384
|
-
}).then(() => {
|
|
385
|
-
return this._releaseWorkSpace(...data);
|
|
386
|
-
}).then(() => {
|
|
387
|
-
this._Descriptor = null;
|
|
388
|
-
this.initialized = false;
|
|
389
|
-
this.emit("released", ...data);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
// write
|
|
393
|
-
install(...data) {
|
|
394
|
-
return Promise.resolve();
|
|
395
|
-
}
|
|
396
|
-
update(...data) {
|
|
397
|
-
return Promise.resolve();
|
|
398
|
-
}
|
|
399
|
-
uninstall(...data) {
|
|
400
|
-
return Promise.resolve();
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
exports.default = Orchestrator;
|
|
404
|
-
;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// externals
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
|
|
10
|
+
// locals
|
|
11
|
+
const checkObject_1 = require("../checkers/TypeError/checkObject");
|
|
12
|
+
const MediatorUser_1 = __importDefault(require("./MediatorUser"));
|
|
13
|
+
const Server_1 = __importDefault(require("./Server"));
|
|
14
|
+
const checkFile_1 = __importDefault(require("../utils/file/checkFile"));
|
|
15
|
+
const readJSONFile_1 = __importDefault(require("../utils/file/readJSONFile"));
|
|
16
|
+
;
|
|
17
|
+
// module
|
|
18
|
+
class Orchestrator extends MediatorUser_1.default {
|
|
19
|
+
// constructor
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super(options);
|
|
22
|
+
// protected
|
|
23
|
+
this._Server = null;
|
|
24
|
+
this._socketServer = null; // to delay socketMiddleware if necessary
|
|
25
|
+
this._checkParameters = true; // to delay checkParameters if necessary
|
|
26
|
+
this._checkResponse = true; // to delay checkResponse if necessary
|
|
27
|
+
// params
|
|
28
|
+
this._packageFile = options && "string" === typeof options.packageFile ? options.packageFile : "";
|
|
29
|
+
this._descriptorFile = options && "string" === typeof options.descriptorFile ? options.descriptorFile : "";
|
|
30
|
+
this._mediatorFile = options && "string" === typeof options.mediatorFile ? options.mediatorFile : "";
|
|
31
|
+
this._serverFile = options && "string" === typeof options.serverFile ? options.serverFile : "";
|
|
32
|
+
// extended
|
|
33
|
+
this._extended = [];
|
|
34
|
+
// public
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
// native
|
|
37
|
+
this.authors = [];
|
|
38
|
+
this.description = "";
|
|
39
|
+
this.dependencies = null;
|
|
40
|
+
this.devDependencies = null;
|
|
41
|
+
this.engines = null;
|
|
42
|
+
this.license = "";
|
|
43
|
+
this.main = "";
|
|
44
|
+
this.name = "";
|
|
45
|
+
this.scripts = null;
|
|
46
|
+
this.version = "";
|
|
47
|
+
}
|
|
48
|
+
// public
|
|
49
|
+
checkDescriptor() {
|
|
50
|
+
return super.checkDescriptor().then(() => {
|
|
51
|
+
return swagger_parser_1.default.validate(this._descriptorFile);
|
|
52
|
+
}).then(() => {
|
|
53
|
+
return Promise.resolve();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// checkers
|
|
57
|
+
checkConf() {
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
isEnable() {
|
|
61
|
+
this.enabled = true;
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
}
|
|
64
|
+
checkFiles() {
|
|
65
|
+
// check package
|
|
66
|
+
return Promise.resolve().then(() => {
|
|
67
|
+
return (0, checkFile_1.default)(this._packageFile).catch((err) => {
|
|
68
|
+
err.message = "package : " + err.message;
|
|
69
|
+
return Promise.reject(err);
|
|
70
|
+
});
|
|
71
|
+
// check Descriptor
|
|
72
|
+
}).then(() => {
|
|
73
|
+
return (0, checkFile_1.default)(this._descriptorFile).catch((err) => {
|
|
74
|
+
err.message = "descriptor : " + err.message;
|
|
75
|
+
return Promise.reject(err);
|
|
76
|
+
});
|
|
77
|
+
// check Mediator
|
|
78
|
+
}).then(() => {
|
|
79
|
+
return (0, checkFile_1.default)(this._mediatorFile).catch((err) => {
|
|
80
|
+
err.message = "mediator : " + err.message;
|
|
81
|
+
return Promise.reject(err);
|
|
82
|
+
});
|
|
83
|
+
// check Server
|
|
84
|
+
}).then(() => {
|
|
85
|
+
return (0, checkFile_1.default)(this._serverFile).catch((err) => {
|
|
86
|
+
err.message = "server : " + err.message;
|
|
87
|
+
return Promise.reject(err);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
checkServer() {
|
|
92
|
+
return (0, checkObject_1.checkObject)("Server", this._Server).then(() => {
|
|
93
|
+
return this._Server instanceof Server_1.default ? Promise.resolve() : Promise.reject(new TypeError("The plugin has an invalid Server which is not an instance (or a child) of the official Server class"));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// middlewares
|
|
97
|
+
disableCheckParameters() {
|
|
98
|
+
this.checkServer().then(() => {
|
|
99
|
+
this._Server.disableCheckParameters();
|
|
100
|
+
}).catch(() => {
|
|
101
|
+
this._checkParameters = false; // delay checkParameters if necessary
|
|
102
|
+
});
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
enableCheckParameters() {
|
|
106
|
+
this.checkServer().then(() => {
|
|
107
|
+
this._Server.enableCheckParameters();
|
|
108
|
+
}).catch(() => {
|
|
109
|
+
this._checkParameters = true; // delay checkParameters if necessary
|
|
110
|
+
});
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
disableCheckResponse() {
|
|
114
|
+
this.checkServer().then(() => {
|
|
115
|
+
this._Server.disableCheckResponse();
|
|
116
|
+
}).catch(() => {
|
|
117
|
+
this._checkResponse = false; // delay checkResponse if necessary
|
|
118
|
+
});
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
enableCheckResponse() {
|
|
122
|
+
this.checkServer().then(() => {
|
|
123
|
+
this._Server.enableCheckResponse();
|
|
124
|
+
}).catch(() => {
|
|
125
|
+
this._checkResponse = true; // delay checkResponse if necessary
|
|
126
|
+
});
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
disableCors() {
|
|
130
|
+
this.checkServer().then(() => {
|
|
131
|
+
this._Server.disableCors();
|
|
132
|
+
}).catch((err) => {
|
|
133
|
+
this.emit("error", err);
|
|
134
|
+
});
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
enableCors() {
|
|
138
|
+
this.checkServer().then(() => {
|
|
139
|
+
this._Server.enableCors();
|
|
140
|
+
}).catch((err) => {
|
|
141
|
+
this.emit("error", err);
|
|
142
|
+
});
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
appMiddleware(req, res, next) {
|
|
146
|
+
if (!this.enabled) {
|
|
147
|
+
next();
|
|
148
|
+
}
|
|
149
|
+
else if (!this.initialized) {
|
|
150
|
+
next();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.checkServer().then(() => {
|
|
154
|
+
this._Server.appMiddleware(req, res, next);
|
|
155
|
+
}).catch(() => {
|
|
156
|
+
next();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
socketMiddleware(server) {
|
|
161
|
+
if (!this.enabled) {
|
|
162
|
+
this._socketServer = server; // delay socketMiddleware if necessary
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this.checkServer().then(() => {
|
|
166
|
+
this._Server.socketMiddleware(server);
|
|
167
|
+
}).catch(() => {
|
|
168
|
+
this._socketServer = server; // delay socketMiddleware if necessary
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// load / destroy
|
|
173
|
+
load(...data) {
|
|
174
|
+
return this.checkFiles().then(() => {
|
|
175
|
+
return (0, readJSONFile_1.default)((0, node_path_1.join)(__dirname, "..", "..", "..", "package.json"));
|
|
176
|
+
}).then(({ engines }) => {
|
|
177
|
+
// native
|
|
178
|
+
this.authors = [];
|
|
179
|
+
this.description = "";
|
|
180
|
+
this.dependencies = {};
|
|
181
|
+
this.devDependencies = {};
|
|
182
|
+
this.engines = engines;
|
|
183
|
+
this.license = "MIT";
|
|
184
|
+
this.main = "lib/main.js";
|
|
185
|
+
this.name = "";
|
|
186
|
+
this.scripts = {};
|
|
187
|
+
this.version = "";
|
|
188
|
+
return (0, readJSONFile_1.default)(this._packageFile);
|
|
189
|
+
// formate authors
|
|
190
|
+
}).then((data) => {
|
|
191
|
+
if (data.authors) {
|
|
192
|
+
this.authors = data.authors;
|
|
193
|
+
delete data.authors;
|
|
194
|
+
if (data.author) {
|
|
195
|
+
if (!this.authors.includes(data.author)) {
|
|
196
|
+
this.authors.push(data.author);
|
|
197
|
+
}
|
|
198
|
+
delete data.author;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else if (data.author) {
|
|
202
|
+
this.authors = [data.author];
|
|
203
|
+
delete data.author;
|
|
204
|
+
}
|
|
205
|
+
return Promise.resolve(data);
|
|
206
|
+
// formate other data
|
|
207
|
+
}).then((data) => {
|
|
208
|
+
const self = this;
|
|
209
|
+
Object.keys(data).forEach((key) => {
|
|
210
|
+
if ("function" !== typeof self[key]) {
|
|
211
|
+
if ("undefined" === typeof self[key]) {
|
|
212
|
+
this._extended.push(key);
|
|
213
|
+
}
|
|
214
|
+
self[key] = data[key];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
destroy(...data) {
|
|
220
|
+
return Promise.resolve().then(() => {
|
|
221
|
+
// protected
|
|
222
|
+
// params
|
|
223
|
+
this._packageFile = "";
|
|
224
|
+
this._descriptorFile = "";
|
|
225
|
+
this._mediatorFile = "";
|
|
226
|
+
this._serverFile = "";
|
|
227
|
+
// extended
|
|
228
|
+
this._extended.forEach((key) => {
|
|
229
|
+
delete this[key];
|
|
230
|
+
});
|
|
231
|
+
this._extended = [];
|
|
232
|
+
// public
|
|
233
|
+
// native
|
|
234
|
+
this.authors = [];
|
|
235
|
+
this.description = "";
|
|
236
|
+
this.dependencies = null;
|
|
237
|
+
this.devDependencies = null;
|
|
238
|
+
this.engines = null;
|
|
239
|
+
this.license = "";
|
|
240
|
+
this.main = "";
|
|
241
|
+
this.name = "";
|
|
242
|
+
this.scripts = null;
|
|
243
|
+
this.version = "";
|
|
244
|
+
}).then(() => {
|
|
245
|
+
this.removeAllListeners();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// init / release
|
|
249
|
+
init(...data) {
|
|
250
|
+
// ensure conf validity
|
|
251
|
+
return Promise.resolve().then(() => {
|
|
252
|
+
return this.checkConf();
|
|
253
|
+
// get enable status
|
|
254
|
+
}).then(() => {
|
|
255
|
+
return this.isEnable();
|
|
256
|
+
}).then(() => {
|
|
257
|
+
return !this.enabled ? Promise.resolve() : Promise.resolve().then(() => {
|
|
258
|
+
// create Descriptor
|
|
259
|
+
return swagger_parser_1.default.bundle(this._descriptorFile).then((content) => {
|
|
260
|
+
return Promise.resolve(content);
|
|
261
|
+
}).then((content) => {
|
|
262
|
+
this._Descriptor = content;
|
|
263
|
+
return this.checkDescriptor().catch((err) => {
|
|
264
|
+
this._Descriptor = null;
|
|
265
|
+
return Promise.reject(err);
|
|
266
|
+
});
|
|
267
|
+
// compare title to package name
|
|
268
|
+
}).then(() => {
|
|
269
|
+
return this._Descriptor.info.title !== this.name ? Promise.reject(new Error("The descriptor's title (\"" + this._Descriptor.info.title + "\") " +
|
|
270
|
+
"is not equals to " +
|
|
271
|
+
"the package's name (\"" + this.name + "\")")) : Promise.resolve();
|
|
272
|
+
// compare version to package version
|
|
273
|
+
}).then(() => {
|
|
274
|
+
return this._Descriptor.info.version !== this.version ? Promise.reject(new Error("The descriptor's version (\"" + this._Descriptor.info.version + "\") " +
|
|
275
|
+
"is not equals to " +
|
|
276
|
+
"the package's version (\"" + this.version + "\")")) : Promise.resolve();
|
|
277
|
+
});
|
|
278
|
+
// create Mediator
|
|
279
|
+
}).then(() => {
|
|
280
|
+
// load
|
|
281
|
+
return new Promise((resolve, reject) => {
|
|
282
|
+
try {
|
|
283
|
+
const val = require(this._mediatorFile);
|
|
284
|
+
if ("object" === typeof val && "function" === typeof val.default) {
|
|
285
|
+
resolve(val.default);
|
|
286
|
+
}
|
|
287
|
+
else if ("function" === typeof val) {
|
|
288
|
+
resolve(val);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
reject(new Error("Mediator file loaded (\"" + this._mediatorFile + "\") does not contain a valid Mediator"));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
reject(e);
|
|
296
|
+
}
|
|
297
|
+
// init
|
|
298
|
+
}).then((PluginMediator) => {
|
|
299
|
+
this._Mediator = new PluginMediator({
|
|
300
|
+
"descriptor": this._Descriptor,
|
|
301
|
+
"externalRessourcesDirectory": this._externalRessourcesDirectory,
|
|
302
|
+
"logger": this._Logger
|
|
303
|
+
});
|
|
304
|
+
// check
|
|
305
|
+
}).then(() => {
|
|
306
|
+
return this.checkMediator().then(() => {
|
|
307
|
+
// intercept errors to avoid non-catched ones
|
|
308
|
+
this._Mediator.on("error", (err) => {
|
|
309
|
+
this.emit("error", err);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
// create Server
|
|
314
|
+
}).then(() => {
|
|
315
|
+
// load
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
try {
|
|
318
|
+
const val = require(this._serverFile);
|
|
319
|
+
if ("object" === typeof val && "function" === typeof val.default) {
|
|
320
|
+
resolve(val.default);
|
|
321
|
+
}
|
|
322
|
+
else if ("function" === typeof val) {
|
|
323
|
+
resolve(val);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
reject(new Error("Server file loaded (\"" + this._serverFile + "\") does not contain a valid Server"));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
reject(e);
|
|
331
|
+
}
|
|
332
|
+
// init
|
|
333
|
+
}).then((PluginServer) => {
|
|
334
|
+
this._Server = new PluginServer({
|
|
335
|
+
"descriptor": this._Descriptor,
|
|
336
|
+
"mediator": this._Mediator,
|
|
337
|
+
"externalRessourcesDirectory": this._externalRessourcesDirectory,
|
|
338
|
+
"logger": this._Logger
|
|
339
|
+
});
|
|
340
|
+
// check
|
|
341
|
+
}).then(() => {
|
|
342
|
+
return this.checkServer().then(() => {
|
|
343
|
+
// intercept errors to avoid non-catched ones
|
|
344
|
+
this._Server.on("error", (err) => {
|
|
345
|
+
this.emit("error", err);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}).then(() => {
|
|
350
|
+
return this._initWorkSpace(...data);
|
|
351
|
+
// init Server (before Mediator)
|
|
352
|
+
}).then(() => {
|
|
353
|
+
return this._Server.init(...data).then(() => {
|
|
354
|
+
if (this._socketServer) { // delayed socketMiddleware
|
|
355
|
+
this._Server.socketMiddleware(this._socketServer);
|
|
356
|
+
this._socketServer = null;
|
|
357
|
+
}
|
|
358
|
+
if (!this._checkParameters) { // delayed checkParameters
|
|
359
|
+
this._Server.disableCheckParameters();
|
|
360
|
+
}
|
|
361
|
+
if (!this._checkResponse) { // delayed checkResponse
|
|
362
|
+
this._Server.disableCheckResponse();
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
// init Mediator
|
|
366
|
+
}).then(() => {
|
|
367
|
+
return this._Mediator.init(...data);
|
|
368
|
+
}).then(() => {
|
|
369
|
+
this.initialized = true;
|
|
370
|
+
this.emit("initialized", ...data);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
release(...data) {
|
|
375
|
+
return Promise.resolve().then(() => {
|
|
376
|
+
return this._Mediator ? this._Mediator.release(...data).then(() => {
|
|
377
|
+
this._Mediator = null;
|
|
378
|
+
}) : Promise.resolve();
|
|
379
|
+
}).then(() => {
|
|
380
|
+
return this._Server ? this._Server.release(...data).then(() => {
|
|
381
|
+
this._socketServer = null;
|
|
382
|
+
this._Server = null;
|
|
383
|
+
}) : Promise.resolve();
|
|
384
|
+
}).then(() => {
|
|
385
|
+
return this._releaseWorkSpace(...data);
|
|
386
|
+
}).then(() => {
|
|
387
|
+
this._Descriptor = null;
|
|
388
|
+
this.initialized = false;
|
|
389
|
+
this.emit("released", ...data);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
// write
|
|
393
|
+
install(...data) {
|
|
394
|
+
return Promise.resolve();
|
|
395
|
+
}
|
|
396
|
+
update(...data) {
|
|
397
|
+
return Promise.resolve();
|
|
398
|
+
}
|
|
399
|
+
uninstall(...data) {
|
|
400
|
+
return Promise.resolve();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
exports.default = Orchestrator;
|
|
404
|
+
;
|