@galeh/chuka 1.1.6 → 1.1.9
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/index.d.ts +3 -2
- package/index.js +91 -81
- package/package.json +8 -4
package/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ declare interface ErrorHandler<T> {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
declare type EventCallback = {
|
|
68
|
-
event: '
|
|
68
|
+
event: 'mount';
|
|
69
69
|
callback: (parent: express.Application) => void;
|
|
70
70
|
};
|
|
71
71
|
|
|
@@ -259,7 +259,8 @@ declare abstract class Validator<T> {
|
|
|
259
259
|
abstract validate(subject: T, selectedField: keyof T): ValidatorReturn;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
declare function validator_2<T, F extends PropertyKey>(validationLogic: ValidationLogic<T>, requestField: F): Middleware<RequestField<F, T>>;
|
|
263
|
+
export { validator_2 as validator }
|
|
263
264
|
|
|
264
265
|
declare type ValidatorReturn = boolean | Promise<boolean>;
|
|
265
266
|
|
package/index.js
CHANGED
|
@@ -6,171 +6,181 @@
|
|
|
6
6
|
* or disable the default devtool with "devtool: false".
|
|
7
7
|
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
8
|
*/
|
|
9
|
-
/******/
|
|
9
|
+
/******/ (() => { // webpackBootstrap
|
|
10
|
+
/******/ "use strict";
|
|
11
|
+
/******/ var __webpack_modules__ = ({
|
|
10
12
|
|
|
11
|
-
/***/ "./src/app.ts"
|
|
13
|
+
/***/ "./src/app.ts"
|
|
12
14
|
/*!********************!*\
|
|
13
15
|
!*** ./src/app.ts ***!
|
|
14
16
|
\********************/
|
|
15
|
-
|
|
17
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
16
18
|
|
|
17
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.createApp =
|
|
19
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.createApp = createApp;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"tslib\");\n__webpack_require__(/*! reflect-metadata */ \"reflect-metadata\");\nconst express = tslib_1.__importStar(__webpack_require__(/*! express */ \"express\"));\nconst inversify_1 = __webpack_require__(/*! inversify */ \"inversify\");\nconst controller_1 = __webpack_require__(/*! ./controller */ \"./src/controller.ts\");\nconst ws = tslib_1.__importStar(__webpack_require__(/*! express-ws */ \"express-ws\"));\nfunction createApp(config) {\n const app = express.default();\n if (config.on) {\n setEventCallbacks(app, config.on);\n }\n if (config.set) {\n applySettings(app, config.set);\n }\n ws.default(app);\n if (config.middlewares) {\n app.use.apply(app, config.middlewares);\n }\n const controllerEmulator = new ControllerEmulator(app);\n const container = new inversify_1.Container();\n initAllDependencies(config, container);\n initControllers(config.routes, container, controllerEmulator);\n return app;\n}\nfunction setEventCallbacks(app, settings) {\n for (const setting of settings) {\n app.on(setting.event, setting.callback);\n }\n}\nfunction applySettings(app, settings) {\n for (const [key, value] of Object.entries(settings)) {\n // @ts-ignore\n app.set(SettingsEnum[key], value);\n }\n}\nfunction initAllDependencies(config, container) {\n if (config.dependencies) {\n initDependencies(config.dependencies, container);\n }\n initControllersAsDependency(config.routes, container);\n}\nfunction initDependencies(dependencies, container) {\n for (const dep of dependencies) {\n if (dep.useValue) {\n bindValue(container, dep.provide, dep.useValue);\n continue;\n }\n if (dep.useClass) {\n bindClass(container, dep.provide, dep.useClass);\n continue;\n }\n }\n}\nfunction initControllersAsDependency(routes, container) {\n for (const route of routes) {\n bindClass(container, route.controller, route.controller);\n if (route.children) {\n initControllersAsDependency(route.children, container);\n }\n }\n}\nfunction bindClass(container, token, classtype) {\n if (!container.isBound(token)) {\n container.bind(token).to(classtype);\n }\n}\nfunction bindValue(container, token, value) {\n if (!container.isBound(token)) {\n container.bind(token).toConstantValue(value);\n }\n}\nfunction bindFactory(container, token, factory) {\n if (!container.isBound(token)) {\n container.bind(token).toFactory(factory);\n }\n}\nfunction initControllers(routes, container, app) {\n for (const route of routes) {\n const controller = container.get(route.controller);\n app[controller_1.setControllerSymbol](route.path, controller);\n if (route.children) {\n initControllers(route.children, container, controller);\n }\n }\n}\nclass ControllerEmulator {\n constructor(app) {\n this.app = app;\n }\n [controller_1.setControllerSymbol](path, subrouter) {\n this.app.use(path, subrouter[controller_1.getRouterSymbol]());\n }\n}\nclass SettingsEnum {\n constructor() {\n this.caseSensitiveRouting = 'case sensitive routing';\n this.env = 'env';\n this.etag = 'etag';\n this.jsonpCallbackName = 'jsonp callback name';\n this.jsonEscape = 'json escape';\n this.jsonReplacer = 'json replacer';\n this.jsonSpaces = 'json spaces';\n this.queryParser = 'query parser';\n this.strictRouting = 'strict routing';\n this.subdomainOffset = 'subdomain offset';\n this.trustProxy = 'trust proxy';\n this.views = 'views';\n this.viewCache = 'view cache';\n this.viewEngine = 'view engine';\n this.xPoweredBy = 'x-powered-by';\n }\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/app.ts?\n}");
|
|
18
20
|
|
|
19
|
-
/***/ }
|
|
21
|
+
/***/ },
|
|
20
22
|
|
|
21
|
-
/***/ "./src/controller.ts"
|
|
23
|
+
/***/ "./src/controller.ts"
|
|
22
24
|
/*!***************************!*\
|
|
23
25
|
!*** ./src/controller.ts ***!
|
|
24
26
|
\***************************/
|
|
25
|
-
|
|
27
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
26
28
|
|
|
27
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Controller = exports.setControllerSymbol = exports.getRouterSymbol = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"tslib\");\nconst express_1 = __webpack_require__(/*! express */ \"express\");\nconst inversify_1 = __webpack_require__(/*! inversify */ \"inversify\");\nexports.getRouterSymbol = Symbol();\nexports.setControllerSymbol = Symbol();\nlet Controller = class Controller {\n constructor() {\n this.router = (0, express_1.Router)();\n }\n [exports.setControllerSymbol](path, subrouter) {\n this.router.use(path, subrouter[exports.getRouterSymbol]());\n }\n [exports.getRouterSymbol]() {\n return this.router;\n }\n useWS(...middlewares) {\n return (handler) => {\n this.router.ws.apply(this.router, ['/', ...middlewares, handler]);\n };\n }\n use(...middlewares) {\n return new MiniController(this.router, middlewares);\n }\n};\nexports.Controller = Controller;\nexports.Controller = Controller = tslib_1.__decorate([\n (0, inversify_1.injectable)()\n], Controller);\nclass MiniController {\n constructor(router, middlewares) {\n this.router = router;\n this.middlewares = middlewares;\n this.all = this.methodImplementation('all').bind(this);\n this.get = this.methodImplementation('get').bind(this);\n this.post = this.methodImplementation('post').bind(this);\n this.put = this.methodImplementation('put').bind(this);\n this.delete = this.methodImplementation('delete').bind(this);\n this.patch = this.methodImplementation('patch').bind(this);\n this.options = this.methodImplementation('options').bind(this);\n this.head = this.methodImplementation('head').bind(this);\n this.checkout = this.methodImplementation('checkout').bind(this);\n this.connect = this.methodImplementation('connect').bind(this);\n this.copy = this.methodImplementation('copy').bind(this);\n this.lock = this.methodImplementation('lock').bind(this);\n this.merge = this.methodImplementation('merge').bind(this);\n this.mkactivity = this.methodImplementation('mkactivity').bind(this);\n this.mkcol = this.methodImplementation('mkcol').bind(this);\n this.move = this.methodImplementation('move').bind(this);\n this['m-search'] = this.methodImplementation('m-search').bind(this);\n this.notify = this.methodImplementation('notify').bind(this);\n this.propfind = this.methodImplementation('propfind').bind(this);\n this.proppatch = this.methodImplementation('proppatch').bind(this);\n this.purge = this.methodImplementation('purge').bind(this);\n this.report = this.methodImplementation('report').bind(this);\n this.search = this.methodImplementation('search').bind(this);\n this.subscribe = this.methodImplementation('subscribe').bind(this);\n this.trace = this.methodImplementation('trace').bind(this);\n this.unlock = this.methodImplementation('unlock').bind(this);\n this.unsubscribe = this.methodImplementation('unsubscribe').bind(this);\n this.link = this.methodImplementation('link').bind(this);\n this.unlink = this.methodImplementation('unlink').bind(this);\n }\n methodImplementation(methodName) {\n return (path, handler) => {\n this.router[methodName].apply(this.router, [\n path,\n ...this.middlewares,\n (req, res, next) => {\n handler(req, res, next);\n }\n ]);\n };\n }\n use(...middlewares) {\n return new MiniController(this.router, this.middlewares.concat(middlewares));\n }\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/controller.ts
|
|
29
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Controller = exports.setControllerSymbol = exports.getRouterSymbol = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"tslib\");\nconst express_1 = __webpack_require__(/*! express */ \"express\");\nconst inversify_1 = __webpack_require__(/*! inversify */ \"inversify\");\nexports.getRouterSymbol = Symbol();\nexports.setControllerSymbol = Symbol();\nlet Controller = class Controller {\n constructor() {\n this.router = (0, express_1.Router)();\n }\n [exports.setControllerSymbol](path, subrouter) {\n this.router.use(path, subrouter[exports.getRouterSymbol]());\n }\n [exports.getRouterSymbol]() {\n return this.router;\n }\n useWS(...middlewares) {\n return (handler) => {\n this.router.ws.apply(this.router, ['/', ...middlewares, handler]);\n };\n }\n use(...middlewares) {\n return new MiniController(this.router, middlewares);\n }\n};\nexports.Controller = Controller;\nexports.Controller = Controller = tslib_1.__decorate([\n (0, inversify_1.injectable)()\n], Controller);\nclass MiniController {\n constructor(router, middlewares) {\n this.router = router;\n this.middlewares = middlewares;\n this.all = this.methodImplementation('all').bind(this);\n this.get = this.methodImplementation('get').bind(this);\n this.post = this.methodImplementation('post').bind(this);\n this.put = this.methodImplementation('put').bind(this);\n this.delete = this.methodImplementation('delete').bind(this);\n this.patch = this.methodImplementation('patch').bind(this);\n this.options = this.methodImplementation('options').bind(this);\n this.head = this.methodImplementation('head').bind(this);\n this.checkout = this.methodImplementation('checkout').bind(this);\n this.connect = this.methodImplementation('connect').bind(this);\n this.copy = this.methodImplementation('copy').bind(this);\n this.lock = this.methodImplementation('lock').bind(this);\n this.merge = this.methodImplementation('merge').bind(this);\n this.mkactivity = this.methodImplementation('mkactivity').bind(this);\n this.mkcol = this.methodImplementation('mkcol').bind(this);\n this.move = this.methodImplementation('move').bind(this);\n this['m-search'] = this.methodImplementation('m-search').bind(this);\n this.notify = this.methodImplementation('notify').bind(this);\n this.propfind = this.methodImplementation('propfind').bind(this);\n this.proppatch = this.methodImplementation('proppatch').bind(this);\n this.purge = this.methodImplementation('purge').bind(this);\n this.report = this.methodImplementation('report').bind(this);\n this.search = this.methodImplementation('search').bind(this);\n this.subscribe = this.methodImplementation('subscribe').bind(this);\n this.trace = this.methodImplementation('trace').bind(this);\n this.unlock = this.methodImplementation('unlock').bind(this);\n this.unsubscribe = this.methodImplementation('unsubscribe').bind(this);\n this.link = this.methodImplementation('link').bind(this);\n this.unlink = this.methodImplementation('unlink').bind(this);\n }\n methodImplementation(methodName) {\n return (path, handler) => {\n this.router[methodName].apply(this.router, [\n path,\n ...this.middlewares,\n (req, res, next) => {\n handler(req, res, next);\n }\n ]);\n };\n }\n use(...middlewares) {\n return new MiniController(this.router, this.middlewares.concat(middlewares));\n }\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/controller.ts?\n}");
|
|
28
30
|
|
|
29
|
-
/***/ }
|
|
31
|
+
/***/ },
|
|
30
32
|
|
|
31
|
-
/***/ "./src/decorators/index.ts"
|
|
33
|
+
/***/ "./src/decorators/index.ts"
|
|
32
34
|
/*!*********************************!*\
|
|
33
35
|
!*** ./src/decorators/index.ts ***!
|
|
34
36
|
\*********************************/
|
|
35
|
-
|
|
37
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
36
38
|
|
|
37
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.injectable = exports.inject = void 0;\nvar inversify_1 = __webpack_require__(/*! inversify */ \"inversify\");\nObject.defineProperty(exports, \"inject\", ({ enumerable: true, get: function () { return inversify_1.inject; } }));\nObject.defineProperty(exports, \"injectable\", ({ enumerable: true, get: function () { return inversify_1.injectable; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/decorators/index.ts
|
|
39
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.injectable = exports.inject = void 0;\nvar inversify_1 = __webpack_require__(/*! inversify */ \"inversify\");\nObject.defineProperty(exports, \"inject\", ({ enumerable: true, get: function () { return inversify_1.inject; } }));\nObject.defineProperty(exports, \"injectable\", ({ enumerable: true, get: function () { return inversify_1.injectable; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/decorators/index.ts?\n}");
|
|
38
40
|
|
|
39
|
-
/***/ }
|
|
41
|
+
/***/ },
|
|
40
42
|
|
|
41
|
-
/***/ "./src/index.ts"
|
|
43
|
+
/***/ "./src/index.ts"
|
|
42
44
|
/*!**********************!*\
|
|
43
45
|
!*** ./src/index.ts ***!
|
|
44
46
|
\**********************/
|
|
45
|
-
|
|
47
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
46
48
|
|
|
47
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Controller = exports.createApp = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"tslib\");\nvar app_1 = __webpack_require__(/*! ./app */ \"./src/app.ts\");\nObject.defineProperty(exports, \"createApp\", ({ enumerable: true, get: function () { return app_1.createApp; } }));\nvar controller_1 = __webpack_require__(/*! ./controller */ \"./src/controller.ts\");\nObject.defineProperty(exports, \"Controller\", ({ enumerable: true, get: function () { return controller_1.Controller; } }));\ntslib_1.__exportStar(__webpack_require__(/*! ./decorators */ \"./src/decorators/index.ts\"), exports);\ntslib_1.__exportStar(__webpack_require__(/*! ./middlewares */ \"./src/middlewares/index.ts\"), exports);\ntslib_1.__exportStar(__webpack_require__(/*! ./validators */ \"./src/validators/index.ts\"), exports);\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/index.ts
|
|
49
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Controller = exports.createApp = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"tslib\");\nvar app_1 = __webpack_require__(/*! ./app */ \"./src/app.ts\");\nObject.defineProperty(exports, \"createApp\", ({ enumerable: true, get: function () { return app_1.createApp; } }));\nvar controller_1 = __webpack_require__(/*! ./controller */ \"./src/controller.ts\");\nObject.defineProperty(exports, \"Controller\", ({ enumerable: true, get: function () { return controller_1.Controller; } }));\ntslib_1.__exportStar(__webpack_require__(/*! ./decorators */ \"./src/decorators/index.ts\"), exports);\ntslib_1.__exportStar(__webpack_require__(/*! ./middlewares */ \"./src/middlewares/index.ts\"), exports);\ntslib_1.__exportStar(__webpack_require__(/*! ./validators */ \"./src/validators/index.ts\"), exports);\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/index.ts?\n}");
|
|
48
50
|
|
|
49
|
-
/***/ }
|
|
51
|
+
/***/ },
|
|
50
52
|
|
|
51
|
-
/***/ "./src/middlewares/index.ts"
|
|
53
|
+
/***/ "./src/middlewares/index.ts"
|
|
52
54
|
/*!**********************************!*\
|
|
53
55
|
!*** ./src/middlewares/index.ts ***!
|
|
54
56
|
\**********************************/
|
|
55
|
-
|
|
57
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
56
58
|
|
|
57
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.text = exports.raw = exports.query = exports.urlencoded = exports[\"static\"] = exports.json = void 0;\nvar express_1 = __webpack_require__(/*! express */ \"express\");\nObject.defineProperty(exports, \"json\", ({ enumerable: true, get: function () { return express_1.json; } }));\nObject.defineProperty(exports, \"static\", ({ enumerable: true, get: function () { return express_1.static; } }));\nObject.defineProperty(exports, \"urlencoded\", ({ enumerable: true, get: function () { return express_1.urlencoded; } }));\nObject.defineProperty(exports, \"query\", ({ enumerable: true, get: function () { return express_1.query; } }));\nObject.defineProperty(exports, \"raw\", ({ enumerable: true, get: function () { return express_1.raw; } }));\nObject.defineProperty(exports, \"text\", ({ enumerable: true, get: function () { return express_1.text; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/middlewares/index.ts
|
|
59
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.text = exports.raw = exports.query = exports.urlencoded = exports[\"static\"] = exports.json = void 0;\nvar express_1 = __webpack_require__(/*! express */ \"express\");\nObject.defineProperty(exports, \"json\", ({ enumerable: true, get: function () { return express_1.json; } }));\nObject.defineProperty(exports, \"static\", ({ enumerable: true, get: function () { return express_1.static; } }));\nObject.defineProperty(exports, \"urlencoded\", ({ enumerable: true, get: function () { return express_1.urlencoded; } }));\nObject.defineProperty(exports, \"query\", ({ enumerable: true, get: function () { return express_1.query; } }));\nObject.defineProperty(exports, \"raw\", ({ enumerable: true, get: function () { return express_1.raw; } }));\nObject.defineProperty(exports, \"text\", ({ enumerable: true, get: function () { return express_1.text; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/middlewares/index.ts?\n}");
|
|
58
60
|
|
|
59
|
-
/***/ }
|
|
61
|
+
/***/ },
|
|
60
62
|
|
|
61
|
-
/***/ "./src/validators/body-validator.ts"
|
|
63
|
+
/***/ "./src/validators/body-validator.ts"
|
|
62
64
|
/*!******************************************!*\
|
|
63
65
|
!*** ./src/validators/body-validator.ts ***!
|
|
64
66
|
\******************************************/
|
|
65
|
-
|
|
67
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
66
68
|
|
|
67
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.bodyValidator =
|
|
69
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.bodyValidator = bodyValidator;\nconst _1 = __webpack_require__(/*! . */ \"./src/validators/index.ts\");\nfunction bodyValidator(validationLogic) {\n return (req, res, next) => {\n (0, _1.validator)(validationLogic, 'body')(req, res, next);\n };\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/body-validator.ts?\n}");
|
|
68
70
|
|
|
69
|
-
/***/ }
|
|
71
|
+
/***/ },
|
|
70
72
|
|
|
71
|
-
/***/ "./src/validators/index.ts"
|
|
73
|
+
/***/ "./src/validators/index.ts"
|
|
72
74
|
/*!*********************************!*\
|
|
73
75
|
!*** ./src/validators/index.ts ***!
|
|
74
76
|
\*********************************/
|
|
75
|
-
|
|
77
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
76
78
|
|
|
77
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.bodyValidator = exports.custom = exports.validator = exports.or = exports.notNull = exports.not = exports.isUndefined = exports.isString = exports.isNumber = exports.isNull = exports.isDefined = exports.and = void 0;\nvar validators_1 = __webpack_require__(/*! ./validators */ \"./src/validators/validators.ts\");\nObject.defineProperty(exports, \"and\", ({ enumerable: true, get: function () { return validators_1.and; } }));\nObject.defineProperty(exports, \"isDefined\", ({ enumerable: true, get: function () { return validators_1.isDefined; } }));\nObject.defineProperty(exports, \"isNull\", ({ enumerable: true, get: function () { return validators_1.isNull; } }));\nObject.defineProperty(exports, \"isNumber\", ({ enumerable: true, get: function () { return validators_1.isNumber; } }));\nObject.defineProperty(exports, \"isString\", ({ enumerable: true, get: function () { return validators_1.isString; } }));\nObject.defineProperty(exports, \"isUndefined\", ({ enumerable: true, get: function () { return validators_1.isUndefined; } }));\nObject.defineProperty(exports, \"not\", ({ enumerable: true, get: function () { return validators_1.not; } }));\nObject.defineProperty(exports, \"notNull\", ({ enumerable: true, get: function () { return validators_1.notNull; } }));\nObject.defineProperty(exports, \"or\", ({ enumerable: true, get: function () { return validators_1.or; } }));\nObject.defineProperty(exports, \"validator\", ({ enumerable: true, get: function () { return validators_1.validator; } }));\nObject.defineProperty(exports, \"custom\", ({ enumerable: true, get: function () { return validators_1.custom; } }));\nvar body_validator_1 = __webpack_require__(/*! ./body-validator */ \"./src/validators/body-validator.ts\");\nObject.defineProperty(exports, \"bodyValidator\", ({ enumerable: true, get: function () { return body_validator_1.bodyValidator; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/index.ts
|
|
79
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.bodyValidator = exports.custom = exports.validator = exports.or = exports.notNull = exports.not = exports.isUndefined = exports.isString = exports.isNumber = exports.isNull = exports.isDefined = exports.and = void 0;\nvar validators_1 = __webpack_require__(/*! ./validators */ \"./src/validators/validators.ts\");\nObject.defineProperty(exports, \"and\", ({ enumerable: true, get: function () { return validators_1.and; } }));\nObject.defineProperty(exports, \"isDefined\", ({ enumerable: true, get: function () { return validators_1.isDefined; } }));\nObject.defineProperty(exports, \"isNull\", ({ enumerable: true, get: function () { return validators_1.isNull; } }));\nObject.defineProperty(exports, \"isNumber\", ({ enumerable: true, get: function () { return validators_1.isNumber; } }));\nObject.defineProperty(exports, \"isString\", ({ enumerable: true, get: function () { return validators_1.isString; } }));\nObject.defineProperty(exports, \"isUndefined\", ({ enumerable: true, get: function () { return validators_1.isUndefined; } }));\nObject.defineProperty(exports, \"not\", ({ enumerable: true, get: function () { return validators_1.not; } }));\nObject.defineProperty(exports, \"notNull\", ({ enumerable: true, get: function () { return validators_1.notNull; } }));\nObject.defineProperty(exports, \"or\", ({ enumerable: true, get: function () { return validators_1.or; } }));\nObject.defineProperty(exports, \"validator\", ({ enumerable: true, get: function () { return validators_1.validator; } }));\nObject.defineProperty(exports, \"custom\", ({ enumerable: true, get: function () { return validators_1.custom; } }));\nvar body_validator_1 = __webpack_require__(/*! ./body-validator */ \"./src/validators/body-validator.ts\");\nObject.defineProperty(exports, \"bodyValidator\", ({ enumerable: true, get: function () { return body_validator_1.bodyValidator; } }));\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/index.ts?\n}");
|
|
78
80
|
|
|
79
|
-
/***/ }
|
|
81
|
+
/***/ },
|
|
80
82
|
|
|
81
|
-
/***/ "./src/validators/validators.ts"
|
|
83
|
+
/***/ "./src/validators/validators.ts"
|
|
82
84
|
/*!**************************************!*\
|
|
83
85
|
!*** ./src/validators/validators.ts ***!
|
|
84
86
|
\**************************************/
|
|
85
|
-
|
|
87
|
+
(__unused_webpack_module, exports) {
|
|
86
88
|
|
|
87
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.
|
|
89
|
+
eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.AtomicValidator = exports.Validator = void 0;\nexports.validator = validator;\nexports.custom = custom;\nexports.isString = isString;\nexports.isNumber = isNumber;\nexports.isDefined = isDefined;\nexports.isUndefined = isUndefined;\nexports.isNull = isNull;\nexports.notNull = notNull;\nexports.and = and;\nexports.andAsync = andAsync;\nexports.or = or;\nexports.not = not;\nfunction validator(validationLogic, requestField) {\n return (req, res, next) => {\n // @ts-ignore\n applyValidation(req[requestField], validationLogic).then(errors => {\n const result = isThereAnyErrors(errors);\n if (result) {\n next(errors);\n }\n else {\n next();\n }\n }).catch(next);\n };\n}\nasync function applyValidation(obj, validationLogic) {\n const validationResult = {};\n for (const key in validationLogic) {\n const atomicValidator = validationLogic[key];\n if (atomicValidator) {\n if (atomicValidator instanceof Validator) {\n try {\n validationResult[key] = atomicValidator.validate(obj, key);\n if (validationResult[key] instanceof Promise) {\n validationResult[key] = await validationResult[key];\n console.log(`awaited result: ${validationResult[key]}`);\n }\n }\n catch (err) {\n validationResult[key] = false;\n }\n }\n else {\n if (obj[key] instanceof Array) {\n validationResult[key] = obj[key].map(objj => applyValidation(objj, atomicValidator));\n if (validationResult[key][0] instanceof Promise) {\n validationResult[key] = Promise.all(validationResult[key]);\n }\n }\n else {\n validationResult[key] = applyValidation(obj[key], atomicValidator);\n if (validationResult[key] instanceof Promise) {\n validationResult[key] = await validationResult[key];\n }\n }\n }\n }\n else {\n validationResult[key] = true;\n }\n }\n return validationResult;\n}\nfunction isThereAnyErrors(obj) {\n for (const [key, value] of Object.entries(obj)) {\n if (value === false) {\n return true;\n }\n else if (typeof value !== 'boolean') {\n const partialRes = isThereAnyErrors(value);\n if (partialRes) {\n return partialRes;\n }\n }\n }\n return false;\n}\n// type ValidationFunction<T> = (subject: T) => boolean;\nclass Validator {\n}\nexports.Validator = Validator;\nclass CustomValidator extends Validator {\n constructor(validator) {\n super();\n this.validator = validator;\n }\n validate(subject, selectedField) {\n return this.validator(subject);\n }\n}\nfunction custom(validator) {\n return new CustomValidator(validator);\n}\nclass AtomicValidator extends Validator {\n constructor(implementation, queryField) {\n super();\n this.implementation = implementation;\n this.queryField = queryField;\n }\n validate(subject, selectedField) {\n return this.implementation(this.queryField ? subject[this.queryField] : subject[selectedField]);\n }\n}\nexports.AtomicValidator = AtomicValidator;\nfunction isString(field) {\n return new AtomicValidator((subject) => {\n return typeof subject === 'string';\n }, field);\n}\nfunction isNumber(field) {\n return new AtomicValidator((subject) => {\n return typeof subject === 'number';\n }, field);\n}\nfunction isDefined(field) {\n return new AtomicValidator((subject) => {\n return subject != undefined;\n }, field);\n}\nfunction isUndefined(field) {\n return new AtomicValidator((subject) => {\n return subject === undefined;\n }, field);\n}\nfunction isNull(field) {\n return new AtomicValidator((subject) => {\n return subject === null;\n }, field);\n}\nfunction notNull(field) {\n return new AtomicValidator((subject) => {\n return subject !== null;\n }, field);\n}\nclass AndValidator extends Validator {\n constructor(...validationFunctions) {\n super();\n this.validationFunctions = validationFunctions;\n }\n validate(subject, selectedField) {\n return this.validationFunctions.every(eachValidator => eachValidator.validate(subject, selectedField));\n }\n}\nclass AndValidatorAsync extends Validator {\n constructor(...validationFunctions) {\n super();\n this.validationFunctions = validationFunctions;\n }\n async validate(subject, selectedField) {\n const allPromises = this.validationFunctions.map(eachValidator => eachValidator.validate(subject, selectedField));\n const allResults = await Promise.all(allPromises);\n return allResults.every(val => val);\n }\n}\nclass OrValidator extends Validator {\n constructor(...validationFunctions) {\n super();\n this.validationFunctions = validationFunctions;\n }\n validate(subject, selectedField) {\n return this.validationFunctions.some(eachValidator => eachValidator.validate(subject, selectedField));\n }\n}\nclass NotValidator extends Validator {\n constructor(validationFunctions) {\n super();\n this.validationFunction = validationFunctions;\n }\n validate(subject, selectedField) {\n return !this.validationFunction.validate(subject, selectedField);\n }\n}\nfunction and(...validationFunctions) {\n return new AndValidator(...validationFunctions);\n}\nfunction andAsync(...validationFunctions) {\n return new AndValidatorAsync(...validationFunctions);\n}\nfunction or(...validationFunctions) {\n return new OrValidator(...validationFunctions);\n}\nfunction not(validationFunction) {\n return new NotValidator(validationFunction);\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/validators.ts?\n}");
|
|
88
90
|
|
|
89
|
-
/***/ }
|
|
91
|
+
/***/ },
|
|
90
92
|
|
|
91
|
-
/***/ "express"
|
|
93
|
+
/***/ "express"
|
|
92
94
|
/*!**************************!*\
|
|
93
95
|
!*** external "express" ***!
|
|
94
96
|
\**************************/
|
|
95
|
-
|
|
97
|
+
(module) {
|
|
96
98
|
|
|
97
99
|
module.exports = require("express");
|
|
98
100
|
|
|
99
|
-
/***/ }
|
|
101
|
+
/***/ },
|
|
100
102
|
|
|
101
|
-
/***/ "express-ws"
|
|
103
|
+
/***/ "express-ws"
|
|
102
104
|
/*!*****************************!*\
|
|
103
105
|
!*** external "express-ws" ***!
|
|
104
106
|
\*****************************/
|
|
105
|
-
|
|
107
|
+
(module) {
|
|
106
108
|
|
|
107
109
|
module.exports = require("express-ws");
|
|
108
110
|
|
|
109
|
-
/***/ }
|
|
111
|
+
/***/ },
|
|
110
112
|
|
|
111
|
-
/***/ "inversify"
|
|
113
|
+
/***/ "inversify"
|
|
112
114
|
/*!****************************!*\
|
|
113
115
|
!*** external "inversify" ***!
|
|
114
116
|
\****************************/
|
|
115
|
-
|
|
117
|
+
(module) {
|
|
116
118
|
|
|
117
119
|
module.exports = require("inversify");
|
|
118
120
|
|
|
119
|
-
/***/ }
|
|
121
|
+
/***/ },
|
|
120
122
|
|
|
121
|
-
/***/ "reflect-metadata"
|
|
123
|
+
/***/ "reflect-metadata"
|
|
122
124
|
/*!***********************************!*\
|
|
123
125
|
!*** external "reflect-metadata" ***!
|
|
124
126
|
\***********************************/
|
|
125
|
-
|
|
127
|
+
(module) {
|
|
126
128
|
|
|
127
129
|
module.exports = require("reflect-metadata");
|
|
128
130
|
|
|
129
|
-
/***/ }
|
|
131
|
+
/***/ },
|
|
130
132
|
|
|
131
|
-
/***/ "tslib"
|
|
133
|
+
/***/ "tslib"
|
|
132
134
|
/*!************************!*\
|
|
133
135
|
!*** external "tslib" ***!
|
|
134
136
|
\************************/
|
|
135
|
-
|
|
137
|
+
(module) {
|
|
136
138
|
|
|
137
139
|
module.exports = require("tslib");
|
|
138
140
|
|
|
139
|
-
/***/ }
|
|
141
|
+
/***/ }
|
|
140
142
|
|
|
141
|
-
/******/
|
|
143
|
+
/******/ });
|
|
142
144
|
/************************************************************************/
|
|
143
|
-
/******/
|
|
144
|
-
/******/
|
|
145
|
-
/******/
|
|
146
|
-
/******/
|
|
147
|
-
/******/
|
|
148
|
-
/******/
|
|
149
|
-
/******/
|
|
150
|
-
/******/
|
|
151
|
-
/******/
|
|
145
|
+
/******/ // The module cache
|
|
146
|
+
/******/ var __webpack_module_cache__ = {};
|
|
147
|
+
/******/
|
|
148
|
+
/******/ // The require function
|
|
149
|
+
/******/ function __webpack_require__(moduleId) {
|
|
150
|
+
/******/ // Check if module is in cache
|
|
151
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
152
|
+
/******/ if (cachedModule !== undefined) {
|
|
153
|
+
/******/ return cachedModule.exports;
|
|
154
|
+
/******/ }
|
|
155
|
+
/******/ // Check if module exists (development only)
|
|
156
|
+
/******/ if (__webpack_modules__[moduleId] === undefined) {
|
|
157
|
+
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
158
|
+
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
159
|
+
/******/ throw e;
|
|
160
|
+
/******/ }
|
|
161
|
+
/******/ // Create a new module (and put it into the cache)
|
|
162
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
163
|
+
/******/ // no module.id needed
|
|
164
|
+
/******/ // no module.loaded needed
|
|
165
|
+
/******/ exports: {}
|
|
166
|
+
/******/ };
|
|
167
|
+
/******/
|
|
168
|
+
/******/ // Execute the module function
|
|
169
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
170
|
+
/******/
|
|
171
|
+
/******/ // Return the exports of the module
|
|
172
|
+
/******/ return module.exports;
|
|
152
173
|
/******/ }
|
|
153
|
-
/******/
|
|
154
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
155
|
-
/******/ // no module.id needed
|
|
156
|
-
/******/ // no module.loaded needed
|
|
157
|
-
/******/ exports: {}
|
|
158
|
-
/******/ };
|
|
159
|
-
/******/
|
|
160
|
-
/******/ // Execute the module function
|
|
161
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
162
|
-
/******/
|
|
163
|
-
/******/ // Return the exports of the module
|
|
164
|
-
/******/ return module.exports;
|
|
165
|
-
/******/ }
|
|
166
|
-
/******/
|
|
174
|
+
/******/
|
|
167
175
|
/************************************************************************/
|
|
168
|
-
/******/
|
|
169
|
-
/******/
|
|
170
|
-
/******/
|
|
171
|
-
/******/
|
|
172
|
-
/******/
|
|
173
|
-
/******/
|
|
174
|
-
/******/
|
|
175
|
-
/******/
|
|
176
|
-
/******/
|
|
176
|
+
/******/
|
|
177
|
+
/******/ // startup
|
|
178
|
+
/******/ // Load entry module and return exports
|
|
179
|
+
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
180
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
|
|
181
|
+
/******/ var __webpack_export_target__ = exports;
|
|
182
|
+
/******/ for(var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
183
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
184
|
+
/******/
|
|
185
|
+
/******/ })()
|
|
186
|
+
;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galeh/chuka",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "simple yet robust wrapper for expressjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chuka",
|
|
@@ -34,9 +34,13 @@
|
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://github.com/hgaleh/chuka.git"
|
|
37
|
+
"url": "git+https://github.com/hgaleh/chuka.git"
|
|
38
38
|
},
|
|
39
|
-
"type": "commonjs",
|
|
40
39
|
"main": "index.js",
|
|
41
|
-
"types": "index.d.ts"
|
|
40
|
+
"types": "index.d.ts",
|
|
41
|
+
"type": "commonjs",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/hgaleh/chuka/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/hgaleh/chuka#readme"
|
|
42
46
|
}
|