@galeh/chuka 1.0.2 → 1.0.4
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/decorators.js +107 -0
- package/index.d.ts +11 -8
- package/index.js +167 -1
- package/middlewares.js +107 -0
- package/package.json +15 -2
- package/{validators/index.d.ts → validators.d.ts} +4 -2
- package/validators.js +105 -0
- package/decorators/index.js +0 -1
- package/middlewares/index.js +0 -1
- package/validators/index.js +0 -1
- /package/{decorators/index.d.ts → decorators.d.ts} +0 -0
- /package/{middlewares/index.d.ts → middlewares.d.ts} +0 -0
package/decorators.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ var __webpack_modules__ = ({
|
|
10
|
+
|
|
11
|
+
/***/ "./src/decorators/index.ts":
|
|
12
|
+
/*!*********************************!*\
|
|
13
|
+
!*** ./src/decorators/index.ts ***!
|
|
14
|
+
\*********************************/
|
|
15
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16
|
+
|
|
17
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ inject: () => (/* reexport safe */ inversify__WEBPACK_IMPORTED_MODULE_0__.inject),\n/* harmony export */ injectable: () => (/* reexport safe */ inversify__WEBPACK_IMPORTED_MODULE_0__.injectable)\n/* harmony export */ });\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! inversify */ \"inversify\");\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(inversify__WEBPACK_IMPORTED_MODULE_0__);\n\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/decorators/index.ts?");
|
|
18
|
+
|
|
19
|
+
/***/ }),
|
|
20
|
+
|
|
21
|
+
/***/ "inversify":
|
|
22
|
+
/*!****************************!*\
|
|
23
|
+
!*** external "inversify" ***!
|
|
24
|
+
\****************************/
|
|
25
|
+
/***/ ((module) => {
|
|
26
|
+
|
|
27
|
+
module.exports = require("inversify");
|
|
28
|
+
|
|
29
|
+
/***/ })
|
|
30
|
+
|
|
31
|
+
/******/ });
|
|
32
|
+
/************************************************************************/
|
|
33
|
+
/******/ // The module cache
|
|
34
|
+
/******/ var __webpack_module_cache__ = {};
|
|
35
|
+
/******/
|
|
36
|
+
/******/ // The require function
|
|
37
|
+
/******/ function __webpack_require__(moduleId) {
|
|
38
|
+
/******/ // Check if module is in cache
|
|
39
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
40
|
+
/******/ if (cachedModule !== undefined) {
|
|
41
|
+
/******/ return cachedModule.exports;
|
|
42
|
+
/******/ }
|
|
43
|
+
/******/ // Create a new module (and put it into the cache)
|
|
44
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
45
|
+
/******/ // no module.id needed
|
|
46
|
+
/******/ // no module.loaded needed
|
|
47
|
+
/******/ exports: {}
|
|
48
|
+
/******/ };
|
|
49
|
+
/******/
|
|
50
|
+
/******/ // Execute the module function
|
|
51
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
52
|
+
/******/
|
|
53
|
+
/******/ // Return the exports of the module
|
|
54
|
+
/******/ return module.exports;
|
|
55
|
+
/******/ }
|
|
56
|
+
/******/
|
|
57
|
+
/************************************************************************/
|
|
58
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
59
|
+
/******/ (() => {
|
|
60
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
61
|
+
/******/ __webpack_require__.n = (module) => {
|
|
62
|
+
/******/ var getter = module && module.__esModule ?
|
|
63
|
+
/******/ () => (module['default']) :
|
|
64
|
+
/******/ () => (module);
|
|
65
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
66
|
+
/******/ return getter;
|
|
67
|
+
/******/ };
|
|
68
|
+
/******/ })();
|
|
69
|
+
/******/
|
|
70
|
+
/******/ /* webpack/runtime/define property getters */
|
|
71
|
+
/******/ (() => {
|
|
72
|
+
/******/ // define getter functions for harmony exports
|
|
73
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
74
|
+
/******/ for(var key in definition) {
|
|
75
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
76
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
77
|
+
/******/ }
|
|
78
|
+
/******/ }
|
|
79
|
+
/******/ };
|
|
80
|
+
/******/ })();
|
|
81
|
+
/******/
|
|
82
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
83
|
+
/******/ (() => {
|
|
84
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
85
|
+
/******/ })();
|
|
86
|
+
/******/
|
|
87
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
88
|
+
/******/ (() => {
|
|
89
|
+
/******/ // define __esModule on exports
|
|
90
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
91
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
92
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
93
|
+
/******/ }
|
|
94
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
95
|
+
/******/ };
|
|
96
|
+
/******/ })();
|
|
97
|
+
/******/
|
|
98
|
+
/************************************************************************/
|
|
99
|
+
/******/
|
|
100
|
+
/******/ // startup
|
|
101
|
+
/******/ // Load entry module and return exports
|
|
102
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
103
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/decorators/index.ts");
|
|
104
|
+
/******/ var __webpack_export_target__ = exports;
|
|
105
|
+
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
106
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
107
|
+
/******/
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import express from 'express';
|
|
1
|
+
import * as express from 'express';
|
|
2
2
|
import { interfaces } from 'inversify';
|
|
3
|
-
import
|
|
3
|
+
import { NextFunction } from 'express';
|
|
4
|
+
import { Request as Request_2 } from 'express';
|
|
5
|
+
import { Response as Response_2 } from 'express';
|
|
6
|
+
import { WebSocket as WebSocket_2 } from 'ws';
|
|
4
7
|
|
|
5
8
|
declare interface ApplicationConfig {
|
|
6
9
|
routes: Array<Route>;
|
|
@@ -36,7 +39,7 @@ declare interface Dependency {
|
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
declare interface ErrorHandler<T> {
|
|
39
|
-
(err: any, req: MergePartial<
|
|
42
|
+
(err: any, req: MergePartial<Request_2, T>, res: Response_2, next: NextFunction): void;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
declare type EventCallback = {
|
|
@@ -59,7 +62,7 @@ declare type MergePartial<A, B> = {
|
|
|
59
62
|
} & Omit<A, keyof B> & Partial<Omit<B, keyof A>>;
|
|
60
63
|
|
|
61
64
|
export declare interface Middleware<T> {
|
|
62
|
-
(req: MergePartial<
|
|
65
|
+
(req: MergePartial<Request_2, T>, res: Response_2, next: NextFunction): void;
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
declare class MiniController<T> implements MiniControllerInterface<T> {
|
|
@@ -147,9 +150,9 @@ declare type PathParams = string | RegExp | Array<string | RegExp>;
|
|
|
147
150
|
declare type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
|
|
148
151
|
|
|
149
152
|
declare interface RequestHandler<T, P = ParamsDictionary> {
|
|
150
|
-
(req: Merge<
|
|
153
|
+
(req: Merge<Request_2, T & {
|
|
151
154
|
params: P;
|
|
152
|
-
}>, res:
|
|
155
|
+
}>, res: Response_2, next: NextFunction): void;
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
declare type RequestHandlerParams<T> = Middleware<T> | ErrorHandler<T>;
|
|
@@ -192,8 +195,8 @@ declare interface Type<T> extends Function {
|
|
|
192
195
|
new (...args: any[]): T;
|
|
193
196
|
}
|
|
194
197
|
|
|
195
|
-
declare type WSHandler<T> = (ws:
|
|
198
|
+
declare type WSHandler<T> = (ws: WebSocket_2, req: Merge<Request_2, T>) => void;
|
|
196
199
|
|
|
197
|
-
export declare type WSMiddleware<T> = (ws:
|
|
200
|
+
export declare type WSMiddleware<T> = (ws: WebSocket_2, req: MergePartial<Request_2, T>, next: NextFunction) => void;
|
|
198
201
|
|
|
199
202
|
export { }
|
package/index.js
CHANGED
|
@@ -1 +1,167 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ var __webpack_modules__ = ({
|
|
10
|
+
|
|
11
|
+
/***/ "./src/app.ts":
|
|
12
|
+
/*!********************!*\
|
|
13
|
+
!*** ./src/app.ts ***!
|
|
14
|
+
\********************/
|
|
15
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16
|
+
|
|
17
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ createApp: () => (/* binding */ createApp)\n/* harmony export */ });\n/* harmony import */ var reflect_metadata__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! reflect-metadata */ \"reflect-metadata\");\n/* harmony import */ var reflect_metadata__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reflect_metadata__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! express */ \"express\");\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! inversify */ \"inversify\");\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(inversify__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _controller__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./controller */ \"./src/controller.ts\");\n/* harmony import */ var express_ws__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! express-ws */ \"express-ws\");\n/* harmony import */ var express_ws__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(express_ws__WEBPACK_IMPORTED_MODULE_3__);\n\n\n\n\n\nfunction createApp(config) {\n const app = express__WEBPACK_IMPORTED_MODULE_1___default()();\n if (config.on) {\n setEventCallbacks(app, config.on);\n }\n if (config.set) {\n applySettings(app, config.set);\n }\n express_ws__WEBPACK_IMPORTED_MODULE_3___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__WEBPACK_IMPORTED_MODULE_2__.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__WEBPACK_IMPORTED_MODULE_4__.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__WEBPACK_IMPORTED_MODULE_4__.setControllerSymbol](path, subrouter) {\n this.app.use(path, subrouter[_controller__WEBPACK_IMPORTED_MODULE_4__.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?");
|
|
18
|
+
|
|
19
|
+
/***/ }),
|
|
20
|
+
|
|
21
|
+
/***/ "./src/controller.ts":
|
|
22
|
+
/*!***************************!*\
|
|
23
|
+
!*** ./src/controller.ts ***!
|
|
24
|
+
\***************************/
|
|
25
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
26
|
+
|
|
27
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Controller: () => (/* binding */ Controller),\n/* harmony export */ getRouterSymbol: () => (/* binding */ getRouterSymbol),\n/* harmony export */ setControllerSymbol: () => (/* binding */ setControllerSymbol)\n/* harmony export */ });\n/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ \"tslib\");\n/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! express */ \"express\");\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! inversify */ \"inversify\");\n/* harmony import */ var inversify__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(inversify__WEBPACK_IMPORTED_MODULE_2__);\n\n\n\nconst getRouterSymbol = Symbol();\nconst setControllerSymbol = Symbol();\nlet Controller = class Controller {\n constructor() {\n this.router = (0,express__WEBPACK_IMPORTED_MODULE_1__.Router)();\n }\n [setControllerSymbol](path, subrouter) {\n this.router.use(path, subrouter[getRouterSymbol]());\n }\n [getRouterSymbol]() {\n return this.router;\n }\n middlewareWS(...middlewares) {\n return (handler) => {\n this.router.ws.apply(this.router, ['/', ...middlewares, handler]);\n };\n }\n middleware(...middlewares) {\n return new MiniController(this.router, middlewares);\n }\n};\nController = (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__decorate)([\n (0,inversify__WEBPACK_IMPORTED_MODULE_2__.injectable)()\n], Controller);\n\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 middleware(...middlewares) {\n return new MiniController(this.router, this.middlewares.concat(middlewares));\n }\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/controller.ts?");
|
|
28
|
+
|
|
29
|
+
/***/ }),
|
|
30
|
+
|
|
31
|
+
/***/ "./src/index.ts":
|
|
32
|
+
/*!**********************!*\
|
|
33
|
+
!*** ./src/index.ts ***!
|
|
34
|
+
\**********************/
|
|
35
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
36
|
+
|
|
37
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Controller: () => (/* reexport safe */ _controller__WEBPACK_IMPORTED_MODULE_1__.Controller),\n/* harmony export */ createApp: () => (/* reexport safe */ _app__WEBPACK_IMPORTED_MODULE_0__.createApp)\n/* harmony export */ });\n/* harmony import */ var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./app */ \"./src/app.ts\");\n/* harmony import */ var _controller__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./controller */ \"./src/controller.ts\");\n\n\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/index.ts?");
|
|
38
|
+
|
|
39
|
+
/***/ }),
|
|
40
|
+
|
|
41
|
+
/***/ "express":
|
|
42
|
+
/*!**************************!*\
|
|
43
|
+
!*** external "express" ***!
|
|
44
|
+
\**************************/
|
|
45
|
+
/***/ ((module) => {
|
|
46
|
+
|
|
47
|
+
module.exports = require("express");
|
|
48
|
+
|
|
49
|
+
/***/ }),
|
|
50
|
+
|
|
51
|
+
/***/ "express-ws":
|
|
52
|
+
/*!*****************************!*\
|
|
53
|
+
!*** external "express-ws" ***!
|
|
54
|
+
\*****************************/
|
|
55
|
+
/***/ ((module) => {
|
|
56
|
+
|
|
57
|
+
module.exports = require("express-ws");
|
|
58
|
+
|
|
59
|
+
/***/ }),
|
|
60
|
+
|
|
61
|
+
/***/ "inversify":
|
|
62
|
+
/*!****************************!*\
|
|
63
|
+
!*** external "inversify" ***!
|
|
64
|
+
\****************************/
|
|
65
|
+
/***/ ((module) => {
|
|
66
|
+
|
|
67
|
+
module.exports = require("inversify");
|
|
68
|
+
|
|
69
|
+
/***/ }),
|
|
70
|
+
|
|
71
|
+
/***/ "reflect-metadata":
|
|
72
|
+
/*!***********************************!*\
|
|
73
|
+
!*** external "reflect-metadata" ***!
|
|
74
|
+
\***********************************/
|
|
75
|
+
/***/ ((module) => {
|
|
76
|
+
|
|
77
|
+
module.exports = require("reflect-metadata");
|
|
78
|
+
|
|
79
|
+
/***/ }),
|
|
80
|
+
|
|
81
|
+
/***/ "tslib":
|
|
82
|
+
/*!************************!*\
|
|
83
|
+
!*** external "tslib" ***!
|
|
84
|
+
\************************/
|
|
85
|
+
/***/ ((module) => {
|
|
86
|
+
|
|
87
|
+
module.exports = require("tslib");
|
|
88
|
+
|
|
89
|
+
/***/ })
|
|
90
|
+
|
|
91
|
+
/******/ });
|
|
92
|
+
/************************************************************************/
|
|
93
|
+
/******/ // The module cache
|
|
94
|
+
/******/ var __webpack_module_cache__ = {};
|
|
95
|
+
/******/
|
|
96
|
+
/******/ // The require function
|
|
97
|
+
/******/ function __webpack_require__(moduleId) {
|
|
98
|
+
/******/ // Check if module is in cache
|
|
99
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
100
|
+
/******/ if (cachedModule !== undefined) {
|
|
101
|
+
/******/ return cachedModule.exports;
|
|
102
|
+
/******/ }
|
|
103
|
+
/******/ // Create a new module (and put it into the cache)
|
|
104
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
105
|
+
/******/ // no module.id needed
|
|
106
|
+
/******/ // no module.loaded needed
|
|
107
|
+
/******/ exports: {}
|
|
108
|
+
/******/ };
|
|
109
|
+
/******/
|
|
110
|
+
/******/ // Execute the module function
|
|
111
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
112
|
+
/******/
|
|
113
|
+
/******/ // Return the exports of the module
|
|
114
|
+
/******/ return module.exports;
|
|
115
|
+
/******/ }
|
|
116
|
+
/******/
|
|
117
|
+
/************************************************************************/
|
|
118
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
119
|
+
/******/ (() => {
|
|
120
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
121
|
+
/******/ __webpack_require__.n = (module) => {
|
|
122
|
+
/******/ var getter = module && module.__esModule ?
|
|
123
|
+
/******/ () => (module['default']) :
|
|
124
|
+
/******/ () => (module);
|
|
125
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
126
|
+
/******/ return getter;
|
|
127
|
+
/******/ };
|
|
128
|
+
/******/ })();
|
|
129
|
+
/******/
|
|
130
|
+
/******/ /* webpack/runtime/define property getters */
|
|
131
|
+
/******/ (() => {
|
|
132
|
+
/******/ // define getter functions for harmony exports
|
|
133
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
134
|
+
/******/ for(var key in definition) {
|
|
135
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
136
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
137
|
+
/******/ }
|
|
138
|
+
/******/ }
|
|
139
|
+
/******/ };
|
|
140
|
+
/******/ })();
|
|
141
|
+
/******/
|
|
142
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
143
|
+
/******/ (() => {
|
|
144
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
145
|
+
/******/ })();
|
|
146
|
+
/******/
|
|
147
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
148
|
+
/******/ (() => {
|
|
149
|
+
/******/ // define __esModule on exports
|
|
150
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
151
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
152
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
153
|
+
/******/ }
|
|
154
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
155
|
+
/******/ };
|
|
156
|
+
/******/ })();
|
|
157
|
+
/******/
|
|
158
|
+
/************************************************************************/
|
|
159
|
+
/******/
|
|
160
|
+
/******/ // startup
|
|
161
|
+
/******/ // Load entry module and return exports
|
|
162
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
163
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
|
|
164
|
+
/******/ var __webpack_export_target__ = exports;
|
|
165
|
+
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
166
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
167
|
+
/******/
|
package/middlewares.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ var __webpack_modules__ = ({
|
|
10
|
+
|
|
11
|
+
/***/ "./src/middlewares/index.ts":
|
|
12
|
+
/*!**********************************!*\
|
|
13
|
+
!*** ./src/middlewares/index.ts ***!
|
|
14
|
+
\**********************************/
|
|
15
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16
|
+
|
|
17
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ json: () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__.json),\n/* harmony export */ query: () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__.query),\n/* harmony export */ raw: () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__.raw),\n/* harmony export */ \"static\": () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__[\"static\"]),\n/* harmony export */ text: () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__.text),\n/* harmony export */ urlencoded: () => (/* reexport safe */ express__WEBPACK_IMPORTED_MODULE_0__.urlencoded)\n/* harmony export */ });\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! express */ \"express\");\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_0__);\n\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/middlewares/index.ts?");
|
|
18
|
+
|
|
19
|
+
/***/ }),
|
|
20
|
+
|
|
21
|
+
/***/ "express":
|
|
22
|
+
/*!**************************!*\
|
|
23
|
+
!*** external "express" ***!
|
|
24
|
+
\**************************/
|
|
25
|
+
/***/ ((module) => {
|
|
26
|
+
|
|
27
|
+
module.exports = require("express");
|
|
28
|
+
|
|
29
|
+
/***/ })
|
|
30
|
+
|
|
31
|
+
/******/ });
|
|
32
|
+
/************************************************************************/
|
|
33
|
+
/******/ // The module cache
|
|
34
|
+
/******/ var __webpack_module_cache__ = {};
|
|
35
|
+
/******/
|
|
36
|
+
/******/ // The require function
|
|
37
|
+
/******/ function __webpack_require__(moduleId) {
|
|
38
|
+
/******/ // Check if module is in cache
|
|
39
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
40
|
+
/******/ if (cachedModule !== undefined) {
|
|
41
|
+
/******/ return cachedModule.exports;
|
|
42
|
+
/******/ }
|
|
43
|
+
/******/ // Create a new module (and put it into the cache)
|
|
44
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
45
|
+
/******/ // no module.id needed
|
|
46
|
+
/******/ // no module.loaded needed
|
|
47
|
+
/******/ exports: {}
|
|
48
|
+
/******/ };
|
|
49
|
+
/******/
|
|
50
|
+
/******/ // Execute the module function
|
|
51
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
52
|
+
/******/
|
|
53
|
+
/******/ // Return the exports of the module
|
|
54
|
+
/******/ return module.exports;
|
|
55
|
+
/******/ }
|
|
56
|
+
/******/
|
|
57
|
+
/************************************************************************/
|
|
58
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
59
|
+
/******/ (() => {
|
|
60
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
61
|
+
/******/ __webpack_require__.n = (module) => {
|
|
62
|
+
/******/ var getter = module && module.__esModule ?
|
|
63
|
+
/******/ () => (module['default']) :
|
|
64
|
+
/******/ () => (module);
|
|
65
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
66
|
+
/******/ return getter;
|
|
67
|
+
/******/ };
|
|
68
|
+
/******/ })();
|
|
69
|
+
/******/
|
|
70
|
+
/******/ /* webpack/runtime/define property getters */
|
|
71
|
+
/******/ (() => {
|
|
72
|
+
/******/ // define getter functions for harmony exports
|
|
73
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
74
|
+
/******/ for(var key in definition) {
|
|
75
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
76
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
77
|
+
/******/ }
|
|
78
|
+
/******/ }
|
|
79
|
+
/******/ };
|
|
80
|
+
/******/ })();
|
|
81
|
+
/******/
|
|
82
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
83
|
+
/******/ (() => {
|
|
84
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
85
|
+
/******/ })();
|
|
86
|
+
/******/
|
|
87
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
88
|
+
/******/ (() => {
|
|
89
|
+
/******/ // define __esModule on exports
|
|
90
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
91
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
92
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
93
|
+
/******/ }
|
|
94
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
95
|
+
/******/ };
|
|
96
|
+
/******/ })();
|
|
97
|
+
/******/
|
|
98
|
+
/************************************************************************/
|
|
99
|
+
/******/
|
|
100
|
+
/******/ // startup
|
|
101
|
+
/******/ // Load entry module and return exports
|
|
102
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
103
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/middlewares/index.ts");
|
|
104
|
+
/******/ var __webpack_export_target__ = exports;
|
|
105
|
+
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
106
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
107
|
+
/******/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galeh/chuka",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "simple yet robust wrapper for expressjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chuka",
|
|
@@ -24,5 +24,18 @@
|
|
|
24
24
|
"@types/express": "^4.17.21",
|
|
25
25
|
"@types/express-ws": "^3.0.4",
|
|
26
26
|
"@types/ws": "^8.5.10"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">= 12.7"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/hgaleh/chuka.git"
|
|
38
|
+
},
|
|
39
|
+
"type": "commonjs",
|
|
40
|
+
"main": "index.js"
|
|
28
41
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NextFunction } from 'express';
|
|
2
|
+
import { Request as Request_2 } from 'express';
|
|
3
|
+
import { Response as Response_2 } from 'express';
|
|
2
4
|
|
|
3
5
|
export declare function and<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
|
|
4
6
|
|
|
@@ -30,7 +32,7 @@ declare type MergePartial<A, B> = {
|
|
|
30
32
|
} & Omit<A, keyof B> & Partial<Omit<B, keyof A>>;
|
|
31
33
|
|
|
32
34
|
declare interface Middleware<T> {
|
|
33
|
-
(req: MergePartial<
|
|
35
|
+
(req: MergePartial<Request_2, T>, res: Response_2, next: NextFunction): void;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export declare function not<T>(validationFunction: Validator<T>): Validator<T>;
|
package/validators.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ var __webpack_modules__ = ({
|
|
10
|
+
|
|
11
|
+
/***/ "./src/validators/body-validator.ts":
|
|
12
|
+
/*!******************************************!*\
|
|
13
|
+
!*** ./src/validators/body-validator.ts ***!
|
|
14
|
+
\******************************************/
|
|
15
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16
|
+
|
|
17
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ bodyValidator: () => (/* binding */ bodyValidator)\n/* harmony export */ });\n/* harmony import */ var ___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! . */ \"./src/validators/validators.ts\");\n\nfunction bodyValidator(validationLogic) {\n return (req, res, next) => {\n (0,___WEBPACK_IMPORTED_MODULE_0__.validator)(validationLogic, 'body')(req, res, next);\n };\n}\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/body-validator.ts?");
|
|
18
|
+
|
|
19
|
+
/***/ }),
|
|
20
|
+
|
|
21
|
+
/***/ "./src/validators/index.ts":
|
|
22
|
+
/*!*********************************!*\
|
|
23
|
+
!*** ./src/validators/index.ts ***!
|
|
24
|
+
\*********************************/
|
|
25
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
26
|
+
|
|
27
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ and: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.and),\n/* harmony export */ bodyValidator: () => (/* reexport safe */ _body_validator__WEBPACK_IMPORTED_MODULE_1__.bodyValidator),\n/* harmony export */ custom: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.custom),\n/* harmony export */ isDefined: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.isDefined),\n/* harmony export */ isNull: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.isNull),\n/* harmony export */ isNumber: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.isNumber),\n/* harmony export */ isString: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.isString),\n/* harmony export */ isUndefined: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.isUndefined),\n/* harmony export */ not: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.not),\n/* harmony export */ notNull: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.notNull),\n/* harmony export */ or: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.or),\n/* harmony export */ validator: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_0__.validator)\n/* harmony export */ });\n/* harmony import */ var _validators__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./validators */ \"./src/validators/validators.ts\");\n/* harmony import */ var _body_validator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./body-validator */ \"./src/validators/body-validator.ts\");\n\n\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/validators/index.ts?");
|
|
28
|
+
|
|
29
|
+
/***/ }),
|
|
30
|
+
|
|
31
|
+
/***/ "./src/validators/validators.ts":
|
|
32
|
+
/*!**************************************!*\
|
|
33
|
+
!*** ./src/validators/validators.ts ***!
|
|
34
|
+
\**************************************/
|
|
35
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
36
|
+
|
|
37
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ AtomicValidator: () => (/* binding */ AtomicValidator),\n/* harmony export */ Validator: () => (/* binding */ Validator),\n/* harmony export */ and: () => (/* binding */ and),\n/* harmony export */ andAsync: () => (/* binding */ andAsync),\n/* harmony export */ custom: () => (/* binding */ custom),\n/* harmony export */ isDefined: () => (/* binding */ isDefined),\n/* harmony export */ isNull: () => (/* binding */ isNull),\n/* harmony export */ isNumber: () => (/* binding */ isNumber),\n/* harmony export */ isString: () => (/* binding */ isString),\n/* harmony export */ isUndefined: () => (/* binding */ isUndefined),\n/* harmony export */ not: () => (/* binding */ not),\n/* harmony export */ notNull: () => (/* binding */ notNull),\n/* harmony export */ or: () => (/* binding */ or),\n/* harmony export */ validator: () => (/* binding */ validator)\n/* harmony export */ });\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}\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}\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?");
|
|
38
|
+
|
|
39
|
+
/***/ })
|
|
40
|
+
|
|
41
|
+
/******/ });
|
|
42
|
+
/************************************************************************/
|
|
43
|
+
/******/ // The module cache
|
|
44
|
+
/******/ var __webpack_module_cache__ = {};
|
|
45
|
+
/******/
|
|
46
|
+
/******/ // The require function
|
|
47
|
+
/******/ function __webpack_require__(moduleId) {
|
|
48
|
+
/******/ // Check if module is in cache
|
|
49
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
50
|
+
/******/ if (cachedModule !== undefined) {
|
|
51
|
+
/******/ return cachedModule.exports;
|
|
52
|
+
/******/ }
|
|
53
|
+
/******/ // Create a new module (and put it into the cache)
|
|
54
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
55
|
+
/******/ // no module.id needed
|
|
56
|
+
/******/ // no module.loaded needed
|
|
57
|
+
/******/ exports: {}
|
|
58
|
+
/******/ };
|
|
59
|
+
/******/
|
|
60
|
+
/******/ // Execute the module function
|
|
61
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
62
|
+
/******/
|
|
63
|
+
/******/ // Return the exports of the module
|
|
64
|
+
/******/ return module.exports;
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/
|
|
67
|
+
/************************************************************************/
|
|
68
|
+
/******/ /* webpack/runtime/define property getters */
|
|
69
|
+
/******/ (() => {
|
|
70
|
+
/******/ // define getter functions for harmony exports
|
|
71
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
72
|
+
/******/ for(var key in definition) {
|
|
73
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
74
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
75
|
+
/******/ }
|
|
76
|
+
/******/ }
|
|
77
|
+
/******/ };
|
|
78
|
+
/******/ })();
|
|
79
|
+
/******/
|
|
80
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
81
|
+
/******/ (() => {
|
|
82
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
86
|
+
/******/ (() => {
|
|
87
|
+
/******/ // define __esModule on exports
|
|
88
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
89
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
90
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
91
|
+
/******/ }
|
|
92
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
93
|
+
/******/ };
|
|
94
|
+
/******/ })();
|
|
95
|
+
/******/
|
|
96
|
+
/************************************************************************/
|
|
97
|
+
/******/
|
|
98
|
+
/******/ // startup
|
|
99
|
+
/******/ // Load entry module and return exports
|
|
100
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
101
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/validators/index.ts");
|
|
102
|
+
/******/ var __webpack_export_target__ = exports;
|
|
103
|
+
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
104
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
105
|
+
/******/
|
package/decorators/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{"use strict";var e={455:e=>{e.exports=require("inversify")}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.injectable=e.inject=void 0;var r=t(455);Object.defineProperty(e,"inject",{enumerable:!0,get:function(){return r.inject}}),Object.defineProperty(e,"injectable",{enumerable:!0,get:function(){return r.injectable}})})(),exports["@galeh/chuka/decorators"]=n})();
|
package/middlewares/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{"use strict";var e={860:e=>{e.exports=require("express")}},r={};function t(n){var u=r[n];if(void 0!==u)return u.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.text=e.raw=e.query=e.urlencoded=e.static=e.json=void 0;var r=t(860);Object.defineProperty(e,"json",{enumerable:!0,get:function(){return r.json}}),Object.defineProperty(e,"static",{enumerable:!0,get:function(){return r.static}}),Object.defineProperty(e,"urlencoded",{enumerable:!0,get:function(){return r.urlencoded}}),Object.defineProperty(e,"query",{enumerable:!0,get:function(){return r.query}}),Object.defineProperty(e,"raw",{enumerable:!0,get:function(){return r.raw}}),Object.defineProperty(e,"text",{enumerable:!0,get:function(){return r.text}})})(),exports["@galeh/chuka/middlewares"]=n})();
|
package/validators/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{"use strict";var e={384:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.bodyValidator=void 0;const r=n(871);t.bodyValidator=function(e){return(t,n,i)=>{(0,r.validator)(e,"body")(t,n,i)}}},871:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.bodyValidator=t.custom=t.validator=t.or=t.notNull=t.not=t.isUndefined=t.isString=t.isNumber=t.isNull=t.isDefined=t.and=void 0;var r=n(500);Object.defineProperty(t,"and",{enumerable:!0,get:function(){return r.and}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return r.isDefined}}),Object.defineProperty(t,"isNull",{enumerable:!0,get:function(){return r.isNull}}),Object.defineProperty(t,"isNumber",{enumerable:!0,get:function(){return r.isNumber}}),Object.defineProperty(t,"isString",{enumerable:!0,get:function(){return r.isString}}),Object.defineProperty(t,"isUndefined",{enumerable:!0,get:function(){return r.isUndefined}}),Object.defineProperty(t,"not",{enumerable:!0,get:function(){return r.not}}),Object.defineProperty(t,"notNull",{enumerable:!0,get:function(){return r.notNull}}),Object.defineProperty(t,"or",{enumerable:!0,get:function(){return r.or}}),Object.defineProperty(t,"validator",{enumerable:!0,get:function(){return r.validator}}),Object.defineProperty(t,"custom",{enumerable:!0,get:function(){return r.custom}});var i=n(384);Object.defineProperty(t,"bodyValidator",{enumerable:!0,get:function(){return i.bodyValidator}})},500:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.not=t.or=t.andAsync=t.and=t.notNull=t.isNull=t.isUndefined=t.isDefined=t.isNumber=t.isString=t.AtomicValidator=t.custom=t.Validator=t.validator=void 0;const r=n(752);function i(e,t){return r.__awaiter(this,void 0,void 0,(function*(){const n={};for(const r in t){const o=t[r];if(o)if(o instanceof u)try{n[r]=o.validate(e,r),n[r]instanceof Promise&&(n[r]=yield n[r],console.log(`awaited result: ${n[r]}`))}catch(e){n[r]=!1}else e[r]instanceof Array?(n[r]=e[r].map((e=>i(e,o))),n[r][0]instanceof Promise&&(n[r]=Promise.all(n[r]))):(n[r]=i(e[r],o),n[r]instanceof Promise&&(n[r]=yield n[r]));else n[r]=!0}return n}))}function o(e){for(const[t,n]of Object.entries(e)){if(!1===n)return!0;if("boolean"!=typeof n){const e=o(n);if(e)return e}}return!1}t.validator=function(e,t){return(n,r,u)=>{i(n[t],e).then((e=>{o(e)?u(e):u()})).catch(u)}};class u{}t.Validator=u;class a extends u{constructor(e){super(),this.validator=e}validate(e,t){return this.validator(e)}}t.custom=function(e){return new a(e)};class s extends u{constructor(e,t){super(),this.implementation=e,this.queryField=t}validate(e,t){return this.implementation(this.queryField?e[this.queryField]:e[t])}}t.AtomicValidator=s,t.isString=function(e){return new s((e=>"string"==typeof e),e)},t.isNumber=function(e){return new s((e=>"number"==typeof e),e)},t.isDefined=function(e){return new s((e=>null!=e),e)},t.isUndefined=function(e){return new s((e=>void 0===e),e)},t.isNull=function(e){return new s((e=>null===e),e)},t.notNull=function(e){return new s((e=>null!==e),e)};class l extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return this.validationFunctions.every((n=>n.validate(e,t)))}}class d extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return r.__awaiter(this,void 0,void 0,(function*(){const n=this.validationFunctions.map((n=>n.validate(e,t)));return(yield Promise.all(n)).every((e=>e))}))}}class c extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return this.validationFunctions.some((n=>n.validate(e,t)))}}class f extends u{constructor(e){super(),this.validationFunction=e}validate(e,t){return!this.validationFunction.validate(e,t)}}t.and=function(...e){return new l(...e)},t.andAsync=function(...e){return new d(...e)},t.or=function(...e){return new c(...e)},t.not=function(e){return new f(e)}},752:e=>{e.exports=require("tslib")}},t={},n=function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}(871);exports["@galeh/chuka/validators"]=n})();
|
|
File without changes
|
|
File without changes
|