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