alado 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -0
- package/README.md +515 -0
- package/ROADMAP.md +0 -0
- package/accets/swagger-initializer.js +20 -0
- package/dist/alado-server/alado-server.d.ts +18 -0
- package/dist/alado-server/alado-server.js +66 -0
- package/dist/alado-server/alado-server.js.map +1 -0
- package/dist/alado-server/index.d.ts +1 -0
- package/dist/alado-server/index.js +6 -0
- package/dist/alado-server/index.js.map +1 -0
- package/dist/constants/content-type.d.ts +6 -0
- package/dist/constants/content-type.js +11 -0
- package/dist/constants/content-type.js.map +1 -0
- package/dist/constants/default-doc-object.d.ts +1 -0
- package/dist/constants/default-doc-object.js +122 -0
- package/dist/constants/default-doc-object.js.map +1 -0
- package/dist/constants/http-method.d.ts +10 -0
- package/dist/constants/http-method.js +15 -0
- package/dist/constants/http-method.js.map +1 -0
- package/dist/constants/http-status.d.ts +1 -0
- package/dist/constants/http-status.js +79 -0
- package/dist/constants/http-status.js.map +1 -0
- package/dist/constants/index.d.ts +5 -0
- package/dist/constants/index.js +22 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/reg-ex.d.ts +5 -0
- package/dist/constants/reg-ex.js +9 -0
- package/dist/constants/reg-ex.js.map +1 -0
- package/dist/dto/alado-server-error.d.ts +4 -0
- package/dist/dto/alado-server-error.js +3 -0
- package/dist/dto/alado-server-error.js.map +1 -0
- package/dist/dto/alado-server-logger.d.ts +3 -0
- package/dist/dto/alado-server-logger.js +3 -0
- package/dist/dto/alado-server-logger.js.map +1 -0
- package/dist/dto/context.d.ts +11 -0
- package/dist/dto/context.js +3 -0
- package/dist/dto/context.js.map +1 -0
- package/dist/dto/index.d.ts +8 -0
- package/dist/dto/index.js +25 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/property-definition.d.ts +30 -0
- package/dist/dto/property-definition.js +3 -0
- package/dist/dto/property-definition.js.map +1 -0
- package/dist/dto/request-authentication.d.ts +9 -0
- package/dist/dto/request-authentication.js +3 -0
- package/dist/dto/request-authentication.js.map +1 -0
- package/dist/dto/request.d.ts +28 -0
- package/dist/dto/request.js +3 -0
- package/dist/dto/request.js.map +1 -0
- package/dist/dto/response.d.ts +7 -0
- package/dist/dto/response.js +3 -0
- package/dist/dto/response.js.map +1 -0
- package/dist/dto/route.d.ts +9 -0
- package/dist/dto/route.js +3 -0
- package/dist/dto/route.js.map +1 -0
- package/dist/factory/http-server-factory.d.ts +8 -0
- package/dist/factory/http-server-factory.js +16 -0
- package/dist/factory/http-server-factory.js.map +1 -0
- package/dist/factory/index.d.ts +2 -0
- package/dist/factory/index.js +19 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/factory/open-api-doc-factory.d.ts +2 -0
- package/dist/factory/open-api-doc-factory.js +151 -0
- package/dist/factory/open-api-doc-factory.js.map +1 -0
- package/dist/helpers/accessor/get-property.d.ts +1 -0
- package/dist/helpers/accessor/get-property.js +38 -0
- package/dist/helpers/accessor/get-property.js.map +1 -0
- package/dist/helpers/accessor/index.d.ts +2 -0
- package/dist/helpers/accessor/index.js +19 -0
- package/dist/helpers/accessor/index.js.map +1 -0
- package/dist/helpers/accessor/set-property.d.ts +1 -0
- package/dist/helpers/accessor/set-property.js +45 -0
- package/dist/helpers/accessor/set-property.js.map +1 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +21 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/parser/authenticate.d.ts +2 -0
- package/dist/helpers/parser/authenticate.js +27 -0
- package/dist/helpers/parser/authenticate.js.map +1 -0
- package/dist/helpers/parser/body-parser.d.ts +3 -0
- package/dist/helpers/parser/body-parser.js +68 -0
- package/dist/helpers/parser/body-parser.js.map +1 -0
- package/dist/helpers/parser/index.d.ts +3 -0
- package/dist/helpers/parser/index.js +20 -0
- package/dist/helpers/parser/index.js.map +1 -0
- package/dist/helpers/parser/query-parser.d.ts +1 -0
- package/dist/helpers/parser/query-parser.js +24 -0
- package/dist/helpers/parser/query-parser.js.map +1 -0
- package/dist/helpers/service/clear-route.d.ts +1 -0
- package/dist/helpers/service/clear-route.js +16 -0
- package/dist/helpers/service/clear-route.js.map +1 -0
- package/dist/helpers/service/index.d.ts +2 -0
- package/dist/helpers/service/index.js +19 -0
- package/dist/helpers/service/index.js.map +1 -0
- package/dist/helpers/service/is-readable-stream.d.ts +3 -0
- package/dist/helpers/service/is-readable-stream.js +15 -0
- package/dist/helpers/service/is-readable-stream.js.map +1 -0
- package/dist/helpers/validate/alado-options/index.d.ts +1 -0
- package/dist/helpers/validate/alado-options/index.js +18 -0
- package/dist/helpers/validate/alado-options/index.js.map +1 -0
- package/dist/helpers/validate/alado-options/validate-alado-options.d.ts +2 -0
- package/dist/helpers/validate/alado-options/validate-alado-options.js +79 -0
- package/dist/helpers/validate/alado-options/validate-alado-options.js.map +1 -0
- package/dist/helpers/validate/context/index.d.ts +3 -0
- package/dist/helpers/validate/context/index.js +20 -0
- package/dist/helpers/validate/context/index.js.map +1 -0
- package/dist/helpers/validate/context/validate-context.d.ts +3 -0
- package/dist/helpers/validate/context/validate-context.js +165 -0
- package/dist/helpers/validate/context/validate-context.js.map +1 -0
- package/dist/helpers/validate/context/validate-request-files.d.ts +2 -0
- package/dist/helpers/validate/context/validate-request-files.js +33 -0
- package/dist/helpers/validate/context/validate-request-files.js.map +1 -0
- package/dist/helpers/validate/context/validate-request-part.d.ts +5 -0
- package/dist/helpers/validate/context/validate-request-part.js +46 -0
- package/dist/helpers/validate/context/validate-request-part.js.map +1 -0
- package/dist/helpers/validate/index.d.ts +2 -0
- package/dist/helpers/validate/index.js +19 -0
- package/dist/helpers/validate/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/options/alado-server-options.d.ts +12 -0
- package/dist/options/alado-server-options.js +3 -0
- package/dist/options/alado-server-options.js.map +1 -0
- package/dist/options/context-options.d.ts +8 -0
- package/dist/options/context-options.js +3 -0
- package/dist/options/context-options.js.map +1 -0
- package/dist/options/cors-options.d.ts +7 -0
- package/dist/options/cors-options.js +3 -0
- package/dist/options/cors-options.js.map +1 -0
- package/dist/options/index.d.ts +6 -0
- package/dist/options/index.js +23 -0
- package/dist/options/index.js.map +1 -0
- package/dist/options/open-api-doc.d.ts +10 -0
- package/dist/options/open-api-doc.js +3 -0
- package/dist/options/open-api-doc.js.map +1 -0
- package/dist/options/request-processor-options.d.ts +9 -0
- package/dist/options/request-processor-options.js +3 -0
- package/dist/options/request-processor-options.js.map +1 -0
- package/dist/options/router-options.d.ts +8 -0
- package/dist/options/router-options.js +3 -0
- package/dist/options/router-options.js.map +1 -0
- package/dist/request-processor/index.d.ts +1 -0
- package/dist/request-processor/index.js +18 -0
- package/dist/request-processor/index.js.map +1 -0
- package/dist/request-processor/request-processor.d.ts +11 -0
- package/dist/request-processor/request-processor.js +163 -0
- package/dist/request-processor/request-processor.js.map +1 -0
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +18 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/router.d.ts +14 -0
- package/dist/router/router.js +110 -0
- package/dist/router/router.js.map +1 -0
- package/package.json +47 -0
- package/postinstall.sh +3 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAladoOptions = void 0;
|
|
4
|
+
function validatePort(port) {
|
|
5
|
+
if (typeof port !== 'number') {
|
|
6
|
+
throw new Error('AladoServerOptions.port should be a number');
|
|
7
|
+
}
|
|
8
|
+
if (port < 0 || port > 65535 || port - Math.ceil(port)) {
|
|
9
|
+
throw new Error('AladoServerOptions.port should be a positive integer less than 65536');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function validateCors(cors) {
|
|
13
|
+
if (!cors || typeof cors !== 'object') {
|
|
14
|
+
throw new Error('AladoServerOptions.cors should be an object');
|
|
15
|
+
}
|
|
16
|
+
if (typeof cors.enable !== 'boolean') {
|
|
17
|
+
throw new Error('AladoServerOptions.cors.enable should be a boolean');
|
|
18
|
+
}
|
|
19
|
+
else if (!cors.enable) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const key in cors) {
|
|
23
|
+
switch (key) {
|
|
24
|
+
case 'allowedOrigin':
|
|
25
|
+
if (typeof cors[key] !== 'string' || !cors[key]) {
|
|
26
|
+
throw new Error('AladoServerOptions.cors.allowedOrigin should be a non-empty string');
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'allowedHeaders':
|
|
30
|
+
case 'exposeHeaders':
|
|
31
|
+
if (!Array.isArray(cors[key]) || cors[key].some(item => typeof item !== 'string')) {
|
|
32
|
+
throw new Error(`AladoServerOptions.cors.${key} should be an array of string`);
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function validateOpenApiDoc(openApiDoc) {
|
|
39
|
+
if (!openApiDoc || typeof openApiDoc !== 'object') {
|
|
40
|
+
throw new Error('AladoServerOptions.openApiDoc should be an object');
|
|
41
|
+
}
|
|
42
|
+
if (typeof openApiDoc?.enable !== 'boolean') {
|
|
43
|
+
throw new Error('AladoServerOptions.openApiDoc.enable should be a boolean');
|
|
44
|
+
}
|
|
45
|
+
else if (!openApiDoc.enable) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (typeof openApiDoc.route !== 'string') {
|
|
49
|
+
throw new Error('AladoServerOptions.openApiDoc.route should be a non-empty string');
|
|
50
|
+
}
|
|
51
|
+
if (typeof openApiDoc.info !== 'object') {
|
|
52
|
+
throw new Error('AladoServerOptions.openApiDoc.info should be an object');
|
|
53
|
+
}
|
|
54
|
+
for (const key in openApiDoc.info) {
|
|
55
|
+
if (typeof openApiDoc?.info[key] !== 'string') {
|
|
56
|
+
throw new Error(`AladoServerOptions.openApiDoc.info.${key} should be a string`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function validateLogger(logger) {
|
|
61
|
+
if (!logger) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
else if (typeof logger !== 'object') {
|
|
65
|
+
throw new Error('AladoServerOptions.logger should be an object');
|
|
66
|
+
}
|
|
67
|
+
if (typeof logger.log !== 'function') {
|
|
68
|
+
throw new Error('AladoServerOptions.logger.log should be a function');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function validateAladoOptions(options) {
|
|
72
|
+
const { port, cors, openApiDoc, logger } = options;
|
|
73
|
+
validatePort(port);
|
|
74
|
+
validateCors(cors);
|
|
75
|
+
validateOpenApiDoc(openApiDoc);
|
|
76
|
+
validateLogger(logger);
|
|
77
|
+
}
|
|
78
|
+
exports.validateAladoOptions = validateAladoOptions;
|
|
79
|
+
//# sourceMappingURL=validate-alado-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-alado-options.js","sourceRoot":"","sources":["../../../../src/helpers/validate/alado-options/validate-alado-options.ts"],"names":[],"mappings":";;;AAGA,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAG,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAiB;IACrC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,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C,kEAAkE,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;QAClC,IAAI,OAAO,UAAU,EAAE,IAAI,CAAC,GAA2B,CAAC,KAAK,QAAQ,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,qBAAqB,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAAyB;IAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;IACT,CAAC;SAAM,IAAI,OAAO,MAAM,KAAI,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;AACH,CAAC;AAED,SAAgB,oBAAoB,CAAC,OAA2B;IAC9D,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,MAAM,EACP,GAAG,OAAO,CAAC;IACZ,YAAY,CAAC,IAAI,CAAC,CAAC;IACnB,YAAY,CAAC,IAAI,CAAC,CAAC;IACnB,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/B,cAAc,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAXD,oDAWC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./validate-context"), exports);
|
|
18
|
+
__exportStar(require("./validate-request-files"), exports);
|
|
19
|
+
__exportStar(require("./validate-request-part"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,2DAAyC;AACzC,0DAAwC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateContext = exports.validateContextOptions = void 0;
|
|
4
|
+
const _const_1 = require("../../../constants");
|
|
5
|
+
function validateError(path, error, errorName) {
|
|
6
|
+
if (!error) {
|
|
7
|
+
throw new Error(`${path}.${errorName || 'error'} is required property"`);
|
|
8
|
+
}
|
|
9
|
+
if (typeof error.statusCode !== 'number' || error.statusCode <= 100 || error.statusCode >= 600) {
|
|
10
|
+
throw new Error(`${path}.${errorName || 'error'}.statusCode should be a valid http response status code"`);
|
|
11
|
+
}
|
|
12
|
+
if (!error.message || typeof error.message !== 'string') {
|
|
13
|
+
throw new Error(`${path}.${errorName || 'error'}.message should be a non-empty string"`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function validateContextAuth(auth) {
|
|
17
|
+
const { inputProperty, outputProperty, handler, required, error, } = auth;
|
|
18
|
+
if (!inputProperty) {
|
|
19
|
+
throw new Error(`RequestAuthentication.inputProperty is required property`);
|
|
20
|
+
}
|
|
21
|
+
if (!_const_1.inputPropertyRegex.test(inputProperty)) {
|
|
22
|
+
throw new Error(`RequestAuthentication.inputProperty should point to the nested property of headers|path|query|body`);
|
|
23
|
+
}
|
|
24
|
+
if (!outputProperty) {
|
|
25
|
+
throw new Error(`RequestAuthentication.outputProperty is required property `);
|
|
26
|
+
}
|
|
27
|
+
if (!_const_1.outputPropertyRegex.test(outputProperty)) {
|
|
28
|
+
throw new Error(`RequestAuthentication.outputProperty should point to the auth or one of its nested properties`);
|
|
29
|
+
}
|
|
30
|
+
if (!handler) {
|
|
31
|
+
throw new Error(`RequestAuthentication.handler is required property"`);
|
|
32
|
+
}
|
|
33
|
+
if (typeof handler !== 'function') {
|
|
34
|
+
throw new Error(`RequestAuthentication.handler should be a function"`);
|
|
35
|
+
}
|
|
36
|
+
if (required !== undefined && typeof required !== 'boolean') {
|
|
37
|
+
throw new Error(`RequestAuthentication.required should be a boolean`);
|
|
38
|
+
}
|
|
39
|
+
validateError('RequestAuthentication', error);
|
|
40
|
+
}
|
|
41
|
+
function validateContextOptions(context, useApiDoc) {
|
|
42
|
+
if (context.options) {
|
|
43
|
+
if (typeof context.options !== 'object') {
|
|
44
|
+
throw new Error(`Context.options should be an object`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof context.options.allowUnknownFields !== 'boolean') {
|
|
47
|
+
throw new Error(`Context.options.allowUnknownFields should be a boolean`);
|
|
48
|
+
}
|
|
49
|
+
if (useApiDoc) {
|
|
50
|
+
if (typeof context.options.openApiDoc !== 'object' && context.options?.openApiDoc) {
|
|
51
|
+
throw new Error(`Context.options.openApiDoc should be an object`);
|
|
52
|
+
}
|
|
53
|
+
else if (typeof context.options?.openApiDoc === 'object' && context.options?.openApiDoc) {
|
|
54
|
+
if (typeof context.options?.openApiDoc?.operationId !== 'string') {
|
|
55
|
+
throw new Error(`Context.options.openApiDoc.operationId should be unique string`);
|
|
56
|
+
}
|
|
57
|
+
if (typeof context.options?.openApiDoc?.description !== 'string') {
|
|
58
|
+
throw new Error(`Context.options.openApiDoc.description should be a string`);
|
|
59
|
+
}
|
|
60
|
+
if (context.options?.openApiDoc?.tags && !Array.isArray(context.options?.openApiDoc?.tags)) {
|
|
61
|
+
throw new Error(`Context.options.openApiDoc.tags should be an array of strings`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.validateContextOptions = validateContextOptions;
|
|
68
|
+
function validateContext(context, useApiDoc) {
|
|
69
|
+
if (!context || typeof context !== 'object') {
|
|
70
|
+
throw new Error(`Context should be an object`);
|
|
71
|
+
}
|
|
72
|
+
if (!context.title) {
|
|
73
|
+
throw new Error(`Context.title is required property`);
|
|
74
|
+
}
|
|
75
|
+
if (typeof context.title !== 'string') {
|
|
76
|
+
throw new Error(`Context.title should be a string`);
|
|
77
|
+
}
|
|
78
|
+
validateContextOptions(context, useApiDoc);
|
|
79
|
+
if (context.auth) {
|
|
80
|
+
validateContextAuth(context.auth);
|
|
81
|
+
}
|
|
82
|
+
if (context.request) {
|
|
83
|
+
const { headers, path, query, body, files } = context.request;
|
|
84
|
+
for (const obj of [headers, path, query, body]) {
|
|
85
|
+
if (obj) {
|
|
86
|
+
for (const prop in obj) {
|
|
87
|
+
validatePropertyDefinition(obj[prop]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (files) {
|
|
92
|
+
for (const prop in files) {
|
|
93
|
+
validateFilePropertyDefinition(files[prop]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!context.response) {
|
|
98
|
+
throw new Error(`Context.response should be an object`);
|
|
99
|
+
}
|
|
100
|
+
validateContextResponse(context.response);
|
|
101
|
+
}
|
|
102
|
+
exports.validateContext = validateContext;
|
|
103
|
+
function validatePropertyDefinitionDoc(doc) {
|
|
104
|
+
if (!doc.schema) {
|
|
105
|
+
throw new Error(`propertyDefinition.openApiDoc.schema is required"`);
|
|
106
|
+
}
|
|
107
|
+
if (typeof doc.schema !== 'object') {
|
|
108
|
+
throw new Error(`propertyDefinition.openApiDoc.schema should be an object"`);
|
|
109
|
+
}
|
|
110
|
+
// todo: move to const
|
|
111
|
+
for (const key in doc.schema) {
|
|
112
|
+
if (!['type', '$ref', 'enum', 'items'].includes(key)) {
|
|
113
|
+
throw new Error(`propertyDefinition.openApiDoc.schema[property] - property should be one of ($ref, type, enum, items)"`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function validatePropertyDefinition(propertyDefinition) {
|
|
118
|
+
const { handler, error, required } = propertyDefinition.validation;
|
|
119
|
+
if (!handler) {
|
|
120
|
+
throw new Error(`PropertyDefinition.validation.handler is required property"`);
|
|
121
|
+
}
|
|
122
|
+
if (typeof handler !== 'function') {
|
|
123
|
+
throw new Error(`PropertyDefinition.validation.handler should be a function"`);
|
|
124
|
+
}
|
|
125
|
+
if (required !== undefined && typeof required !== 'boolean') {
|
|
126
|
+
throw new Error(`PropertyDefinition.validation.required should be a boolean`);
|
|
127
|
+
}
|
|
128
|
+
validateError('PropertyDefinition.validate', error);
|
|
129
|
+
if (propertyDefinition.transform && typeof propertyDefinition.transform !== 'function') {
|
|
130
|
+
throw new Error(`PropertyDefinition.transform should be a function"`);
|
|
131
|
+
}
|
|
132
|
+
if (propertyDefinition.openApiDoc) {
|
|
133
|
+
validatePropertyDefinitionDoc(propertyDefinition.openApiDoc);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function validateFilePropertyDefinition(filePropertyDefinition) {
|
|
137
|
+
const { required, mimetypes, maxSize, mimetypeError, maxSizeError, requiredError } = filePropertyDefinition;
|
|
138
|
+
if (required !== undefined && typeof required !== 'boolean') {
|
|
139
|
+
throw new Error(`FilePropertyDefinition.required should be a boolean`);
|
|
140
|
+
}
|
|
141
|
+
if (!Array.isArray(mimetypes) || mimetypes.some(item => !item || typeof item !== 'string')) {
|
|
142
|
+
throw new Error(`FilePropertyDefinition.mimetypes should be an array of string`);
|
|
143
|
+
}
|
|
144
|
+
if (typeof maxSize !== 'number' || maxSize <= 0) {
|
|
145
|
+
throw new Error(`FilePropertyDefinition.maxSize should be a positive number`);
|
|
146
|
+
}
|
|
147
|
+
validateError('FilePropertyDefinition', mimetypeError, 'mimetypeError');
|
|
148
|
+
validateError('FilePropertyDefinition', maxSizeError, 'maxSizeError');
|
|
149
|
+
validateError('FilePropertyDefinition', requiredError, 'requiredError');
|
|
150
|
+
}
|
|
151
|
+
function validateContextResponse(response) {
|
|
152
|
+
if (typeof response.statusCode !== 'number' || response.statusCode <= 100 || response.statusCode >= 600) {
|
|
153
|
+
throw new Error(`Response.statusCode should be a valid http response status code"`);
|
|
154
|
+
}
|
|
155
|
+
if (response.title && typeof response.title !== 'string') {
|
|
156
|
+
throw new Error(`Response.title should be a string`);
|
|
157
|
+
}
|
|
158
|
+
if (response.headers && typeof response.headers !== 'object') {
|
|
159
|
+
throw new Error(`Response.headers should be an object`);
|
|
160
|
+
}
|
|
161
|
+
if (response.statusCode !== 204 && !response.body) {
|
|
162
|
+
throw new Error(`Response.body should be defined or Response.statusCode should be changed to 204 (No Content)`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=validate-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-context.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-context.ts"],"names":[],"mappings":";;;AAAA,mCAAiE;AAYjE,SAAS,aAAa,CAAC,IAAY,EAAE,KAAuB,EAAE,SAAkB;IAC9E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,IAA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ACtE,aAAa,CAAC,wBAAwB,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;AAC1E,CAAC;AAGD,SAAS,uBAAuB,CAAC,QAAuB;IACtD,IAAI,OAAO,QAAQ,CAAC,UAAU,KAAK,QAAQ,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAG,CAAC;QACzG,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IACrF,CAAC;IACD,IAAI,QAAQ,CAAC,KAAK,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,8FAA8F,CAAC,CAAC;IAClH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequestFiles = void 0;
|
|
4
|
+
function validateRequestFiles(context, request) {
|
|
5
|
+
const { files } = context.request;
|
|
6
|
+
if (files) {
|
|
7
|
+
for (const file in files) {
|
|
8
|
+
const { required, mimetypes, maxSize, requiredError, maxSizeError, mimetypeError } = files[file];
|
|
9
|
+
if (required && (!request.files || !request.files[file])) {
|
|
10
|
+
return requiredError;
|
|
11
|
+
}
|
|
12
|
+
const { size, mimetype } = request.files[file];
|
|
13
|
+
if (!mimetypes.includes(mimetype)) {
|
|
14
|
+
return mimetypeError;
|
|
15
|
+
}
|
|
16
|
+
if (size > maxSize) {
|
|
17
|
+
return maxSizeError;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!context.options?.allowUnknownFields) {
|
|
21
|
+
for (const f in request.files) {
|
|
22
|
+
if (!files[f]) {
|
|
23
|
+
delete request.files[f];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
request.files = {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.validateRequestFiles = validateRequestFiles;
|
|
33
|
+
//# sourceMappingURL=validate-request-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request-files.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-files.ts"],"names":[],"mappings":";;;AAEA,SAAgB,oBAAoB,CAAC,OAAqB,EAAE,OAAY;IACtE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,aAAa,EACb,YAAY,EACZ,aAAa,EACd,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAChB,IAAI,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACzD,OAAO,aAAa,CAAC;YACvB,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClC,OAAO,aAAa,CAAC;YACvB,CAAC;YACD,IAAI,IAAI,GAAG,OAAO,EAAE,CAAC;gBACnB,OAAO,YAAY,CAAC;YACtB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,EAAE,CAAC;YACzC,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC9B,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBACd,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;IACrB,CAAC;AAEH,CAAC;AAlCD,oDAkCC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequestPart = void 0;
|
|
4
|
+
const nonProcessingRequestParts = ['files', 'auth'];
|
|
5
|
+
async function validateRequestPart(key, context, request) {
|
|
6
|
+
if (nonProcessingRequestParts.includes(key)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (!Object.keys(context.request[key]).length && !context.options?.allowUnknownFields) {
|
|
10
|
+
request[key] = {};
|
|
11
|
+
}
|
|
12
|
+
for (const property in context.request[key]) {
|
|
13
|
+
const { validation, transform } = context.request[key][property];
|
|
14
|
+
const { required, handler, error } = validation;
|
|
15
|
+
if (required && (!request[key] || !Object.prototype.hasOwnProperty.apply(request[key], [property]))) {
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
if (handler && Object.prototype.hasOwnProperty.apply(request[key], [property])) {
|
|
19
|
+
try {
|
|
20
|
+
let value = request[key][property];
|
|
21
|
+
const isValid = await handler.apply(request, [value]);
|
|
22
|
+
if (!isValid) {
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
if (transform) {
|
|
26
|
+
value = await transform.apply(request, [value]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return {
|
|
31
|
+
statusCode: error.statusCode,
|
|
32
|
+
message: e.message
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!context.options?.allowUnknownFields) {
|
|
38
|
+
for (const prop in request[key]) {
|
|
39
|
+
if (key !== 'headers' && (!context.request[key] || !Object.prototype.hasOwnProperty.apply(context.request[key], [prop]))) {
|
|
40
|
+
delete request[key][prop];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.validateRequestPart = validateRequestPart;
|
|
46
|
+
//# sourceMappingURL=validate-request-part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request-part.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-part.ts"],"names":[],"mappings":";;;AAEA,MAAM,yBAAyB,GAAa,CAAC,OAAO,EAAC,MAAM,CAAC,CAAC;AAEtD,KAAK,UAAU,mBAAmB,CAAC,GAAyB,EAAE,OAAqB,EAAE,OAAY;IACtG,IAAI,yBAAyB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,OAAO;IACT,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,EAAE,CAAC;QACtF,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;IACnB,CAAC;IACD,KAAM,MAAM,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAG,CAAC;QAC9C,MAAM,EACJ,UAAU,EACV,SAAS,EACV,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAuB,CAAC;QACzD,MAAM,EACJ,QAAQ,EACR,OAAO,EACP,KAAK,EACN,GAAG,UAAU,CAAC;QAEf,IAAI,QAAQ,IAAI,CAAC,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AI,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1H,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;AAEH,CAAC;AAjDD,kDAiDC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./alado-options"), exports);
|
|
18
|
+
__exportStar(require("./context"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/validate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,4CAA0B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Context, ContextRequest, RequestAuthentication, Request, Response, PropertyDefinition, FilePropertyDefinition } from './dto';
|
|
2
|
+
export { AladoServerOptions, ContextOptions, CorsOptions, OpenApiDoc } from './options';
|
|
3
|
+
export { HttpMethod, httpStatus } from './constants';
|
|
4
|
+
export { AladoServer } from './alado-server';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AladoServer = exports.httpStatus = exports.HttpMethod = void 0;
|
|
4
|
+
var _const_1 = require("./constants");
|
|
5
|
+
Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return _const_1.HttpMethod; } });
|
|
6
|
+
Object.defineProperty(exports, "httpStatus", { enumerable: true, get: function () { return _const_1.httpStatus; } });
|
|
7
|
+
var _alado_1 = require("./alado-server");
|
|
8
|
+
Object.defineProperty(exports, "AladoServer", { enumerable: true, get: function () { return _alado_1.AladoServer; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAeA,iCAGgB;AAFd,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AAEZ,iCAEgB;AADd,qGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AladoServerLogger } from '../dto';
|
|
3
|
+
import { OpenApiDoc } from './open-api-doc';
|
|
4
|
+
import { CorsOptions } from './cors-options';
|
|
5
|
+
import { SecureContextOptions } from 'tls';
|
|
6
|
+
export interface AladoServerOptions {
|
|
7
|
+
port: number;
|
|
8
|
+
cors: CorsOptions;
|
|
9
|
+
openApiDoc: OpenApiDoc;
|
|
10
|
+
ssl?: SecureContextOptions;
|
|
11
|
+
logger?: AladoServerLogger;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alado-server-options.js","sourceRoot":"","sources":["../../src/options/alado-server-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-options.js","sourceRoot":"","sources":["../../src/options/context-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-options.js","sourceRoot":"","sources":["../../src/options/cors-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context-options"), exports);
|
|
18
|
+
__exportStar(require("./cors-options"), exports);
|
|
19
|
+
__exportStar(require("./alado-server-options"), exports);
|
|
20
|
+
__exportStar(require("./router-options"), exports);
|
|
21
|
+
__exportStar(require("./open-api-doc"), exports);
|
|
22
|
+
__exportStar(require("./request-processor-options"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,iDAA+B;AAC/B,yDAAuC;AACvC,mDAAiC;AACjC,iDAA+B;AAC/B,8DAA4C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-api-doc.js","sourceRoot":"","sources":["../../src/options/open-api-doc.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Router } from '../router';
|
|
2
|
+
import { OpenApiDoc } from './open-api-doc';
|
|
3
|
+
import { AladoServerLogger } from '../dto';
|
|
4
|
+
export interface RequestProcessorOptions {
|
|
5
|
+
router: Router;
|
|
6
|
+
openApiDoc: OpenApiDoc;
|
|
7
|
+
enableCors?: boolean;
|
|
8
|
+
logger?: AladoServerLogger;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-processor-options.js","sourceRoot":"","sources":["../../src/options/request-processor-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-options.js","sourceRoot":"","sources":["../../src/options/router-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './request-processor';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./request-processor"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-processor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|