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.
Files changed (88) hide show
  1. package/LICENSE +1 -1
  2. package/lib/cjs/checkers/RangeError/checkArrayLength.d.ts +2 -2
  3. package/lib/cjs/checkers/RangeError/checkArrayLength.js +26 -26
  4. package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.d.ts +2 -2
  5. package/lib/cjs/checkers/RangeError/checkArrayLengthBetween.js +33 -33
  6. package/lib/cjs/checkers/RangeError/checkIntegerBetween.d.ts +2 -2
  7. package/lib/cjs/checkers/RangeError/checkIntegerBetween.js +32 -32
  8. package/lib/cjs/checkers/RangeError/checkNonEmptyArray.d.ts +2 -2
  9. package/lib/cjs/checkers/RangeError/checkNonEmptyArray.js +22 -22
  10. package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.d.ts +2 -2
  11. package/lib/cjs/checkers/RangeError/checkNonEmptyInteger.js +22 -22
  12. package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.d.ts +2 -2
  13. package/lib/cjs/checkers/RangeError/checkNonEmptyNumber.js +22 -22
  14. package/lib/cjs/checkers/RangeError/checkNonEmptyObject.d.ts +2 -2
  15. package/lib/cjs/checkers/RangeError/checkNonEmptyObject.js +22 -22
  16. package/lib/cjs/checkers/RangeError/checkNonEmptyString.d.ts +2 -2
  17. package/lib/cjs/checkers/RangeError/checkNonEmptyString.js +22 -22
  18. package/lib/cjs/checkers/RangeError/checkNumberBetween.d.ts +2 -2
  19. package/lib/cjs/checkers/RangeError/checkNumberBetween.js +32 -32
  20. package/lib/cjs/checkers/RangeError/checkObjectLength.d.ts +2 -2
  21. package/lib/cjs/checkers/RangeError/checkObjectLength.js +31 -31
  22. package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.d.ts +2 -2
  23. package/lib/cjs/checkers/RangeError/checkObjectLengthBetween.js +36 -36
  24. package/lib/cjs/checkers/RangeError/checkStringLength.d.ts +2 -2
  25. package/lib/cjs/checkers/RangeError/checkStringLength.js +26 -26
  26. package/lib/cjs/checkers/RangeError/checkStringLengthBetween.d.ts +2 -2
  27. package/lib/cjs/checkers/RangeError/checkStringLengthBetween.js +33 -33
  28. package/lib/cjs/checkers/ReferenceError/checkExists.d.ts +2 -2
  29. package/lib/cjs/checkers/ReferenceError/checkExists.js +19 -19
  30. package/lib/cjs/checkers/TypeError/checkArray.d.ts +2 -2
  31. package/lib/cjs/checkers/TypeError/checkArray.js +22 -22
  32. package/lib/cjs/checkers/TypeError/checkBoolean.d.ts +2 -2
  33. package/lib/cjs/checkers/TypeError/checkBoolean.js +22 -22
  34. package/lib/cjs/checkers/TypeError/checkFunction.d.ts +2 -2
  35. package/lib/cjs/checkers/TypeError/checkFunction.js +22 -22
  36. package/lib/cjs/checkers/TypeError/checkInteger.d.ts +2 -2
  37. package/lib/cjs/checkers/TypeError/checkInteger.js +22 -22
  38. package/lib/cjs/checkers/TypeError/checkNumber.d.ts +2 -2
  39. package/lib/cjs/checkers/TypeError/checkNumber.js +22 -22
  40. package/lib/cjs/checkers/TypeError/checkObject.d.ts +2 -2
  41. package/lib/cjs/checkers/TypeError/checkObject.js +22 -22
  42. package/lib/cjs/checkers/TypeError/checkString.d.ts +2 -2
  43. package/lib/cjs/checkers/TypeError/checkString.js +22 -22
  44. package/lib/cjs/components/DescriptorUser.d.ts +27 -27
  45. package/lib/cjs/components/DescriptorUser.js +117 -117
  46. package/lib/cjs/components/Mediator.d.ts +28 -28
  47. package/lib/cjs/components/Mediator.js +145 -145
  48. package/lib/cjs/components/MediatorUser.d.ts +12 -12
  49. package/lib/cjs/components/MediatorUser.js +40 -40
  50. package/lib/cjs/components/NotFoundError.d.ts +2 -2
  51. package/lib/cjs/components/NotFoundError.js +7 -7
  52. package/lib/cjs/components/Orchestrator.d.ts +57 -57
  53. package/lib/cjs/components/Orchestrator.js +404 -404
  54. package/lib/cjs/components/Server.d.ts +55 -55
  55. package/lib/cjs/components/Server.js +560 -560
  56. package/lib/cjs/main.cjs +90 -90
  57. package/lib/cjs/main.d.cts +30 -30
  58. package/lib/cjs/utils/cleanSendedError.d.ts +1 -1
  59. package/lib/cjs/utils/cleanSendedError.js +24 -24
  60. package/lib/cjs/utils/descriptor/extractParams.d.ts +3 -3
  61. package/lib/cjs/utils/descriptor/extractParams.js +21 -21
  62. package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.d.ts +8 -8
  63. package/lib/cjs/utils/descriptor/extractPathMethodByOperationId.js +34 -34
  64. package/lib/cjs/utils/descriptor/extractPattern.d.ts +2 -2
  65. package/lib/cjs/utils/descriptor/extractPattern.js +28 -28
  66. package/lib/cjs/utils/descriptor/extractSchemaType.d.ts +4 -4
  67. package/lib/cjs/utils/descriptor/extractSchemaType.js +18 -18
  68. package/lib/cjs/utils/file/checkFile.d.ts +1 -1
  69. package/lib/cjs/utils/file/checkFile.js +17 -17
  70. package/lib/cjs/utils/file/isFile.d.ts +1 -1
  71. package/lib/cjs/utils/file/isFile.js +19 -19
  72. package/lib/cjs/utils/file/readJSONFile.d.ts +1 -1
  73. package/lib/cjs/utils/file/readJSONFile.js +20 -24
  74. package/lib/cjs/utils/removeFirstSlash.d.ts +1 -1
  75. package/lib/cjs/utils/removeFirstSlash.js +8 -8
  76. package/lib/cjs/utils/request/extractBody.d.ts +7 -7
  77. package/lib/cjs/utils/request/extractBody.js +52 -52
  78. package/lib/cjs/utils/request/extractCookies.d.ts +4 -4
  79. package/lib/cjs/utils/request/extractCookies.js +53 -53
  80. package/lib/cjs/utils/request/extractIp.d.ts +1 -1
  81. package/lib/cjs/utils/request/extractIp.js +40 -40
  82. package/lib/cjs/utils/send.d.ts +2 -2
  83. package/lib/cjs/utils/send.js +57 -57
  84. package/lib/cjs/utils/serverCodes.d.ts +14 -14
  85. package/lib/cjs/utils/serverCodes.js +15 -15
  86. package/package.json +42 -32
  87. package/lib/cjs/utils/getUniqueID.d.ts +0 -1
  88. package/lib/cjs/utils/getUniqueID.js +0 -16
@@ -1,27 +1,27 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- import { OpenApiDocument } from "express-openapi-validate";
4
- export type tLogType = "data" | "debug" | "log" | "info" | "success" | "warning" | "error";
5
- export type tLogger = (type: tLogType, message: string | Error, bold?: boolean, pluginName?: string) => void;
6
- export interface iDescriptorUserOptions {
7
- "externalRessourcesDirectory": string;
8
- "descriptor"?: OpenApiDocument;
9
- "logger"?: tLogger;
10
- }
11
- export default class DescriptorUser extends EventEmitter {
12
- initialized: boolean;
13
- protected _descriptorValidated: boolean;
14
- protected _externalRessourcesDirectory: string;
15
- protected _Descriptor: OpenApiDocument | null;
16
- protected _Logger: tLogger | null;
17
- constructor(options: iDescriptorUserOptions);
18
- protected _initWorkSpace(...data: any): Promise<void>;
19
- protected _releaseWorkSpace(...data: any): Promise<void>;
20
- protected _log(type: tLogType, message: string | Error, bold?: boolean): this;
21
- getPluginName(): string;
22
- getPluginVersion(): string;
23
- getPluginDescription(): string;
24
- init(...data: any): Promise<void>;
25
- release(...data: any): Promise<void>;
26
- checkDescriptor(): Promise<void>;
27
- }
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from "node:events";
3
+ import { OpenApiDocument } from "express-openapi-validate";
4
+ export type tLogType = "data" | "debug" | "log" | "info" | "success" | "warning" | "error";
5
+ export type tLogger = (type: tLogType, message: string | Error, bold?: boolean, pluginName?: string) => void;
6
+ export interface iDescriptorUserOptions {
7
+ "externalRessourcesDirectory": string;
8
+ "descriptor"?: OpenApiDocument;
9
+ "logger"?: tLogger;
10
+ }
11
+ export default class DescriptorUser extends EventEmitter {
12
+ initialized: boolean;
13
+ protected _descriptorValidated: boolean;
14
+ protected _externalRessourcesDirectory: string;
15
+ protected _Descriptor: OpenApiDocument | null;
16
+ protected _Logger: tLogger | null;
17
+ constructor(options: iDescriptorUserOptions);
18
+ protected _initWorkSpace(...data: any): Promise<void>;
19
+ protected _releaseWorkSpace(...data: any): Promise<void>;
20
+ protected _log(type: tLogType, message: string | Error, bold?: boolean): this;
21
+ getPluginName(): string;
22
+ getPluginVersion(): string;
23
+ getPluginDescription(): string;
24
+ init(...data: any): Promise<void>;
25
+ release(...data: any): Promise<void>;
26
+ checkDescriptor(): Promise<void>;
27
+ }
@@ -1,117 +1,117 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // deps
4
- // natives
5
- const events_1 = require("events");
6
- // locals
7
- const checkObject_1 = require("../checkers/TypeError/checkObject");
8
- const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
9
- const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
10
- ;
11
- // consts
12
- const LOG_TYPES_ALLOWED = ["log", "info", "success", "warning", "error"];
13
- // module
14
- // Please note the fact that "_initWorkSpace" and "_releaseWorkSpace" method MUST be re-writted in Mediator class, and not in MediatorUser childs.
15
- // Please note the fact that "init" and "release" method MUST NOT be re-writted. Each child has is own init logic.
16
- class DescriptorUser extends events_1.EventEmitter {
17
- // constructor
18
- constructor(options) {
19
- super();
20
- // public
21
- this.initialized = false;
22
- // protected
23
- this._descriptorValidated = false;
24
- this._externalRessourcesDirectory = options && "string" === typeof options.externalRessourcesDirectory ?
25
- options.externalRessourcesDirectory : "";
26
- this._Descriptor = options && "object" === typeof options.descriptor ?
27
- options.descriptor : null;
28
- this._Logger = options && "function" === typeof options.logger ?
29
- options.logger : null;
30
- }
31
- // protected
32
- // must be inherited
33
- _initWorkSpace(...data) {
34
- return Promise.reject(new Error("\"_initWorkSpace\" method must be inherited"));
35
- }
36
- // must be inherited
37
- _releaseWorkSpace(...data) {
38
- return Promise.reject(new Error("\"_releaseWorkSpace\" method must be inherited"));
39
- }
40
- _log(type, message, bold) {
41
- if (message && "function" === typeof this._Logger && LOG_TYPES_ALLOWED.includes(type)) {
42
- this._Logger(type, message, bold, this.getPluginName());
43
- }
44
- return this;
45
- }
46
- // public
47
- getPluginName() {
48
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.title ? this._Descriptor.info.title : "";
49
- }
50
- getPluginVersion() {
51
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.version ? this._Descriptor.info.version : "";
52
- }
53
- getPluginDescription() {
54
- return this._Descriptor && this._Descriptor.info && this._Descriptor.info.description ? this._Descriptor.info.description : "";
55
- }
56
- // must be inherited
57
- init(...data) {
58
- console.log("DescriptorUser", "init", ...data);
59
- return Promise.reject(new Error("\"init\" method must be inherited"));
60
- }
61
- // must be inherited
62
- release(...data) {
63
- console.log("DescriptorUser", "release", ...data);
64
- return Promise.reject(new Error("\"release\" method must be inherited"));
65
- }
66
- // must be inherited
67
- checkDescriptor() {
68
- // check Descriptor object
69
- return this._descriptorValidated ? Promise.resolve() : (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor", this._Descriptor).then(() => {
70
- // check info object
71
- return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor.info", this._Descriptor.info).then(() => {
72
- // check title
73
- return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.title", this._Descriptor.info.title).then(() => {
74
- return this._Descriptor.info.title !== this._Descriptor.info.title.toLowerCase() ?
75
- Promise.reject(new Error("The descriptor's title (\"" + this._Descriptor.info.title + "\") " +
76
- "is not equals in lower case (package.json convention)")) : Promise.resolve();
77
- // check version
78
- }).then(() => {
79
- return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version", this._Descriptor.info.version);
80
- });
81
- });
82
- }).then(() => {
83
- // check paths object
84
- return ((0, checkObject_1.checkObject)("Descriptor.paths", this._Descriptor.paths)).then(() => {
85
- // check multiple operationIds
86
- return Promise.resolve().then(() => {
87
- const operationIds = [];
88
- Object.keys(this._Descriptor.paths).forEach((p) => {
89
- Object.keys(this._Descriptor.paths[p]).forEach((m) => {
90
- const path = this._Descriptor.paths[p];
91
- if (path[m].operationId) {
92
- operationIds.push(path[m].operationId);
93
- }
94
- });
95
- });
96
- let multiple = false;
97
- for (let i = 0; i < operationIds.length - 1; ++i) {
98
- for (let j = i + 1; j < operationIds.length; ++j) {
99
- if (operationIds[i] === operationIds[j]) {
100
- multiple = true;
101
- break;
102
- }
103
- }
104
- if (multiple) {
105
- break;
106
- }
107
- }
108
- return multiple ? Promise.reject(new Error("There is multiple operationIds in [\" " + operationIds.join("\", ") + " \"]")) : Promise.resolve();
109
- });
110
- });
111
- }).then(() => {
112
- this._descriptorValidated = true;
113
- });
114
- }
115
- }
116
- exports.default = DescriptorUser;
117
- ;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // deps
4
+ // natives
5
+ const node_events_1 = require("node:events");
6
+ // locals
7
+ const checkObject_1 = require("../checkers/TypeError/checkObject");
8
+ const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
9
+ const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
10
+ ;
11
+ // consts
12
+ const LOG_TYPES_ALLOWED = ["log", "info", "success", "warning", "error"];
13
+ // module
14
+ // Please note the fact that "_initWorkSpace" and "_releaseWorkSpace" method MUST be re-writted in Mediator class, and not in MediatorUser childs.
15
+ // Please note the fact that "init" and "release" method MUST NOT be re-writted. Each child has is own init logic.
16
+ class DescriptorUser extends node_events_1.EventEmitter {
17
+ // constructor
18
+ constructor(options) {
19
+ super();
20
+ // public
21
+ this.initialized = false;
22
+ // protected
23
+ this._descriptorValidated = false;
24
+ this._externalRessourcesDirectory = options && "string" === typeof options.externalRessourcesDirectory ?
25
+ options.externalRessourcesDirectory : "";
26
+ this._Descriptor = options && "object" === typeof options.descriptor ?
27
+ options.descriptor : null;
28
+ this._Logger = options && "function" === typeof options.logger ?
29
+ options.logger : null;
30
+ }
31
+ // protected
32
+ // must be inherited
33
+ _initWorkSpace(...data) {
34
+ return Promise.reject(new Error("\"_initWorkSpace\" method must be inherited"));
35
+ }
36
+ // must be inherited
37
+ _releaseWorkSpace(...data) {
38
+ return Promise.reject(new Error("\"_releaseWorkSpace\" method must be inherited"));
39
+ }
40
+ _log(type, message, bold) {
41
+ if (message && "function" === typeof this._Logger && LOG_TYPES_ALLOWED.includes(type)) {
42
+ this._Logger(type, message, bold, this.getPluginName());
43
+ }
44
+ return this;
45
+ }
46
+ // public
47
+ getPluginName() {
48
+ return this._Descriptor && this._Descriptor.info && this._Descriptor.info.title ? this._Descriptor.info.title : "";
49
+ }
50
+ getPluginVersion() {
51
+ return this._Descriptor && this._Descriptor.info && this._Descriptor.info.version ? this._Descriptor.info.version : "";
52
+ }
53
+ getPluginDescription() {
54
+ return this._Descriptor && this._Descriptor.info && this._Descriptor.info.description ? this._Descriptor.info.description : "";
55
+ }
56
+ // must be inherited
57
+ init(...data) {
58
+ console.log("DescriptorUser", "init", ...data);
59
+ return Promise.reject(new Error("\"init\" method must be inherited"));
60
+ }
61
+ // must be inherited
62
+ release(...data) {
63
+ console.log("DescriptorUser", "release", ...data);
64
+ return Promise.reject(new Error("\"release\" method must be inherited"));
65
+ }
66
+ // must be inherited
67
+ checkDescriptor() {
68
+ // check Descriptor object
69
+ return this._descriptorValidated ? Promise.resolve() : (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor", this._Descriptor).then(() => {
70
+ // check info object
71
+ return (0, checkNonEmptyObject_1.checkNonEmptyObject)("Descriptor.info", this._Descriptor.info).then(() => {
72
+ // check title
73
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.title", this._Descriptor.info.title).then(() => {
74
+ return this._Descriptor.info.title !== this._Descriptor.info.title.toLowerCase() ?
75
+ Promise.reject(new Error("The descriptor's title (\"" + this._Descriptor.info.title + "\") " +
76
+ "is not equals in lower case (package.json convention)")) : Promise.resolve();
77
+ // check version
78
+ }).then(() => {
79
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("Descriptor.info.version", this._Descriptor.info.version);
80
+ });
81
+ });
82
+ }).then(() => {
83
+ // check paths object
84
+ return ((0, checkObject_1.checkObject)("Descriptor.paths", this._Descriptor.paths)).then(() => {
85
+ // check multiple operationIds
86
+ return Promise.resolve().then(() => {
87
+ const operationIds = [];
88
+ Object.keys(this._Descriptor.paths).forEach((p) => {
89
+ Object.keys(this._Descriptor.paths[p]).forEach((m) => {
90
+ const path = this._Descriptor.paths[p];
91
+ if (path[m].operationId) {
92
+ operationIds.push(path[m].operationId);
93
+ }
94
+ });
95
+ });
96
+ let multiple = false;
97
+ for (let i = 0; i < operationIds.length - 1; ++i) {
98
+ for (let j = i + 1; j < operationIds.length; ++j) {
99
+ if (operationIds[i] === operationIds[j]) {
100
+ multiple = true;
101
+ break;
102
+ }
103
+ }
104
+ if (multiple) {
105
+ break;
106
+ }
107
+ }
108
+ return multiple ? Promise.reject(new Error("There is multiple operationIds in [\" " + operationIds.join("\", ") + " \"]")) : Promise.resolve();
109
+ });
110
+ });
111
+ }).then(() => {
112
+ this._descriptorValidated = true;
113
+ });
114
+ }
115
+ }
116
+ exports.default = DescriptorUser;
117
+ ;
@@ -1,28 +1,28 @@
1
- import { OpenApiValidator } from "express-openapi-validate";
2
- import { iServerResponse } from "./Server";
3
- import DescriptorUser, { iDescriptorUserOptions } from "./DescriptorUser";
4
- export interface iUrlParameters {
5
- "path": {
6
- [key: string]: any;
7
- };
8
- "query": {
9
- [key: string]: any;
10
- };
11
- "headers": {
12
- [key: string]: any;
13
- };
14
- "cookies": {
15
- [key: string]: any;
16
- };
17
- }
18
- export interface iBodyParameters {
19
- [key: string]: any;
20
- }
21
- export default class Mediator extends DescriptorUser {
22
- protected _validator: OpenApiValidator | null;
23
- constructor(options: iDescriptorUserOptions);
24
- checkParameters(operationId: string, urlParams: iUrlParameters, bodyParams: iBodyParameters): Promise<void>;
25
- checkResponse(operationId: string, res: iServerResponse): Promise<void>;
26
- init(...data: any): Promise<void>;
27
- release(...data: any): Promise<void>;
28
- }
1
+ import { OpenApiValidator } from "express-openapi-validate";
2
+ import { iServerResponse } from "./Server";
3
+ import DescriptorUser, { iDescriptorUserOptions } from "./DescriptorUser";
4
+ export interface iUrlParameters {
5
+ "path": {
6
+ [key: string]: any;
7
+ };
8
+ "query": {
9
+ [key: string]: any;
10
+ };
11
+ "headers": {
12
+ [key: string]: any;
13
+ };
14
+ "cookies": {
15
+ [key: string]: any;
16
+ };
17
+ }
18
+ export interface iBodyParameters {
19
+ [key: string]: any;
20
+ }
21
+ export default class Mediator extends DescriptorUser {
22
+ protected _validator: OpenApiValidator | null;
23
+ constructor(options: iDescriptorUserOptions);
24
+ checkParameters(operationId: string, urlParams: iUrlParameters, bodyParams: iBodyParameters): Promise<void>;
25
+ checkResponse(operationId: string, res: iServerResponse): Promise<void>;
26
+ init(...data: any): Promise<void>;
27
+ release(...data: any): Promise<void>;
28
+ }
@@ -1,145 +1,145 @@
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 express_openapi_validate_1 = require("express-openapi-validate");
9
- const checkObject_1 = require("../checkers/TypeError/checkObject");
10
- const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
11
- const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
12
- const extractPathMethodByOperationId_1 = __importDefault(require("../utils/descriptor/extractPathMethodByOperationId"));
13
- const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
14
- // module
15
- class Mediator extends DescriptorUser_1.default {
16
- // constructor
17
- constructor(options) {
18
- super(options);
19
- this._validator = null;
20
- }
21
- // public
22
- // Check sended parameters by method name (used by the Server)
23
- checkParameters(operationId, urlParams, bodyParams) {
24
- // parameters validation
25
- return this.checkDescriptor().then(() => {
26
- return (0, checkNonEmptyString_1.checkNonEmptyString)("operationId", operationId);
27
- }).then(() => {
28
- return (0, checkNonEmptyObject_1.checkNonEmptyObject)("urlParams", urlParams).then(() => {
29
- return (0, checkObject_1.checkObject)("urlParams.path", urlParams.path);
30
- }).then(() => {
31
- return (0, checkObject_1.checkObject)("urlParams.query", urlParams.query);
32
- }).then(() => {
33
- return (0, checkObject_1.checkObject)("urlParams.headers", urlParams.headers);
34
- }).then(() => {
35
- return (0, checkObject_1.checkObject)("urlParams.cookies", urlParams.cookies);
36
- });
37
- }).then(() => {
38
- return (0, checkObject_1.checkObject)("bodyParams", bodyParams);
39
- }).then(() => {
40
- // search wanted operation
41
- const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
42
- return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
43
- const req = {
44
- "path": foundPathMethod.path,
45
- "method": foundPathMethod.method,
46
- "params": urlParams.path,
47
- "query": urlParams.query,
48
- "headers": urlParams.headers,
49
- "cookies": urlParams.cookies,
50
- "body": bodyParams
51
- };
52
- const validateRequest = this._validator.validate(req.method, req.path); // set to "any" for ts validation
53
- validateRequest(req, null, (err) => {
54
- return err ? reject(err) : resolve();
55
- });
56
- });
57
- }).catch((err) => {
58
- return err instanceof express_openapi_validate_1.ValidationError ? Promise.resolve().then(() => {
59
- switch (err.data[0].keyword) { // extract first Error
60
- case "required":
61
- return Promise.reject(new ReferenceError(err.message));
62
- case "type":
63
- return Promise.reject(new TypeError(err.message));
64
- case "minimum":
65
- case "maximum":
66
- case "minLength":
67
- case "maxLength":
68
- case "minItems":
69
- case "maxItems":
70
- case "enum":
71
- return Promise.reject(new RangeError(err.message));
72
- default:
73
- return Promise.reject(new Error(err.message));
74
- }
75
- }) : Promise.reject(err);
76
- });
77
- }
78
- // Check sended parameters by method name (used by the Server)
79
- checkResponse(operationId, res) {
80
- // parameters validation
81
- return this.checkDescriptor().then(() => {
82
- return (0, checkNonEmptyString_1.checkNonEmptyString)("operationId", operationId);
83
- }).then(() => {
84
- // search wanted operation
85
- const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
86
- return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
87
- // no content, no validation
88
- if (204 === res.statusCode) {
89
- return "undefined" !== typeof res.body ? reject(new ReferenceError("You should not have content data with 204 statusCode")) : resolve();
90
- }
91
- // no content, no validation (put requests)
92
- else if (201 === res.statusCode && "undefined" === typeof res.body) {
93
- return resolve();
94
- }
95
- // validator cannot correctly check pure boolean return
96
- else if ("undefined" !== typeof res.body && ["true", "false"].includes(res.body)) {
97
- return resolve();
98
- }
99
- else {
100
- try {
101
- res.headers = res.getHeaders();
102
- if ("undefined" === typeof res.body) {
103
- res.body = null;
104
- }
105
- else {
106
- res.body = "string" === typeof res.body ? JSON.parse(res.body) : res.body;
107
- }
108
- const validateResponse = this._validator.validateResponse(foundPathMethod.method, foundPathMethod.path);
109
- validateResponse(res);
110
- return resolve();
111
- }
112
- catch (e) {
113
- return reject(new Error("[" + foundPathMethod.method + "]" +
114
- foundPathMethod.path +
115
- " (" + foundPathMethod.operationId + ") => " +
116
- res.statusCode +
117
- "\r\n" +
118
- (e.message ? e.message : e)));
119
- }
120
- }
121
- });
122
- });
123
- }
124
- // init / release
125
- init(...data) {
126
- return this._initWorkSpace(...data).then(() => {
127
- this._validator = new express_openapi_validate_1.OpenApiValidator(this._Descriptor);
128
- this.initialized = true;
129
- this.emit("initialized", ...data);
130
- });
131
- }
132
- release(...data) {
133
- return this._releaseWorkSpace(...data).then(() => {
134
- // can only be released by Orchestrator
135
- this._Descriptor = null;
136
- this._validator = null;
137
- this.initialized = false;
138
- this.emit("released", ...data);
139
- }).then(() => {
140
- this.removeAllListeners();
141
- });
142
- }
143
- }
144
- exports.default = Mediator;
145
- ;
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 express_openapi_validate_1 = require("express-openapi-validate");
9
+ const checkObject_1 = require("../checkers/TypeError/checkObject");
10
+ const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
11
+ const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
12
+ const extractPathMethodByOperationId_1 = __importDefault(require("../utils/descriptor/extractPathMethodByOperationId"));
13
+ const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
14
+ // module
15
+ class Mediator extends DescriptorUser_1.default {
16
+ // constructor
17
+ constructor(options) {
18
+ super(options);
19
+ this._validator = null;
20
+ }
21
+ // public
22
+ // Check sended parameters by method name (used by the Server)
23
+ checkParameters(operationId, urlParams, bodyParams) {
24
+ // parameters validation
25
+ return this.checkDescriptor().then(() => {
26
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("operationId", operationId);
27
+ }).then(() => {
28
+ return (0, checkNonEmptyObject_1.checkNonEmptyObject)("urlParams", urlParams).then(() => {
29
+ return (0, checkObject_1.checkObject)("urlParams.path", urlParams.path);
30
+ }).then(() => {
31
+ return (0, checkObject_1.checkObject)("urlParams.query", urlParams.query);
32
+ }).then(() => {
33
+ return (0, checkObject_1.checkObject)("urlParams.headers", urlParams.headers);
34
+ }).then(() => {
35
+ return (0, checkObject_1.checkObject)("urlParams.cookies", urlParams.cookies);
36
+ });
37
+ }).then(() => {
38
+ return (0, checkObject_1.checkObject)("bodyParams", bodyParams);
39
+ }).then(() => {
40
+ // search wanted operation
41
+ const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
42
+ return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
43
+ const req = {
44
+ "path": foundPathMethod.path,
45
+ "method": foundPathMethod.method,
46
+ "params": urlParams.path,
47
+ "query": urlParams.query,
48
+ "headers": urlParams.headers,
49
+ "cookies": urlParams.cookies,
50
+ "body": bodyParams
51
+ };
52
+ const validateRequest = this._validator.validate(req.method, req.path); // set to "any" for ts validation
53
+ validateRequest(req, null, (err) => {
54
+ return err ? reject(err) : resolve();
55
+ });
56
+ });
57
+ }).catch((err) => {
58
+ return err instanceof express_openapi_validate_1.ValidationError ? Promise.resolve().then(() => {
59
+ switch (err.data[0].keyword) { // extract first Error
60
+ case "required":
61
+ return Promise.reject(new ReferenceError(err.message));
62
+ case "type":
63
+ return Promise.reject(new TypeError(err.message));
64
+ case "minimum":
65
+ case "maximum":
66
+ case "minLength":
67
+ case "maxLength":
68
+ case "minItems":
69
+ case "maxItems":
70
+ case "enum":
71
+ return Promise.reject(new RangeError(err.message));
72
+ default:
73
+ return Promise.reject(new Error(err.message));
74
+ }
75
+ }) : Promise.reject(err);
76
+ });
77
+ }
78
+ // Check sended parameters by method name (used by the Server)
79
+ checkResponse(operationId, res) {
80
+ // parameters validation
81
+ return this.checkDescriptor().then(() => {
82
+ return (0, checkNonEmptyString_1.checkNonEmptyString)("operationId", operationId);
83
+ }).then(() => {
84
+ // search wanted operation
85
+ const foundPathMethod = (0, extractPathMethodByOperationId_1.default)(this._Descriptor.paths, operationId);
86
+ return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
87
+ // no content, no validation
88
+ if (204 === res.statusCode) {
89
+ return "undefined" !== typeof res.body ? reject(new ReferenceError("You should not have content data with 204 statusCode")) : resolve();
90
+ }
91
+ // no content, no validation (put requests)
92
+ else if (201 === res.statusCode && "undefined" === typeof res.body) {
93
+ return resolve();
94
+ }
95
+ // validator cannot correctly check pure boolean return
96
+ else if ("undefined" !== typeof res.body && ["true", "false"].includes(res.body)) {
97
+ return resolve();
98
+ }
99
+ else {
100
+ try {
101
+ res.headers = res.getHeaders();
102
+ if ("undefined" === typeof res.body) {
103
+ res.body = null;
104
+ }
105
+ else {
106
+ res.body = "string" === typeof res.body ? JSON.parse(res.body) : res.body;
107
+ }
108
+ const validateResponse = this._validator.validateResponse(foundPathMethod.method, foundPathMethod.path);
109
+ validateResponse(res);
110
+ return resolve();
111
+ }
112
+ catch (e) {
113
+ return reject(new Error("[" + foundPathMethod.method + "]" +
114
+ foundPathMethod.path +
115
+ " (" + foundPathMethod.operationId + ") => " +
116
+ res.statusCode +
117
+ "\r\n" +
118
+ (e.message ? e.message : e)));
119
+ }
120
+ }
121
+ });
122
+ });
123
+ }
124
+ // init / release
125
+ init(...data) {
126
+ return this._initWorkSpace(...data).then(() => {
127
+ this._validator = new express_openapi_validate_1.OpenApiValidator(this._Descriptor);
128
+ this.initialized = true;
129
+ this.emit("initialized", ...data);
130
+ });
131
+ }
132
+ release(...data) {
133
+ return this._releaseWorkSpace(...data).then(() => {
134
+ // can only be released by Orchestrator
135
+ this._Descriptor = null;
136
+ this._validator = null;
137
+ this.initialized = false;
138
+ this.emit("released", ...data);
139
+ }).then(() => {
140
+ this.removeAllListeners();
141
+ });
142
+ }
143
+ }
144
+ exports.default = Mediator;
145
+ ;