@galeh/chuka 1.1.3 → 1.1.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/index.d.ts CHANGED
@@ -1,10 +1,19 @@
1
1
  import * as express from 'express';
2
- import { interfaces } from 'inversify';
2
+ import { inject } from 'inversify';
3
+ import { injectable } from 'inversify';
4
+ import { json } from 'express';
3
5
  import { NextFunction } from 'express';
6
+ import { query } from 'express';
7
+ import { raw } from 'express';
4
8
  import { Request as Request_2 } from 'express';
5
9
  import { Response as Response_2 } from 'express';
10
+ import { static } from 'express';
11
+ import { text } from 'express';
12
+ import { urlencoded } from 'express';
6
13
  import { WebSocket as WebSocket_2 } from 'ws';
7
14
 
15
+ export declare function and<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
16
+
8
17
  declare interface ApplicationConfig {
9
18
  routes: Array<Route>;
10
19
  dependencies?: Array<Dependency>;
@@ -13,6 +22,17 @@ declare interface ApplicationConfig {
13
22
  set?: Partial<Settings>;
14
23
  }
15
24
 
25
+ declare class AtomicValidator<T> extends Validator<T> {
26
+ private implementation;
27
+ queryField?: keyof T | undefined;
28
+ constructor(implementation: (subject: T | T[keyof T]) => ValidatorReturn, queryField?: keyof T | undefined);
29
+ validate(subject: T, selectedField: keyof T): ValidatorReturn;
30
+ }
31
+
32
+ export declare function bodyValidator<T>(validationLogic: ValidationLogic<T>): Middleware<{
33
+ body: T;
34
+ }>;
35
+
16
36
  export declare class Controller {
17
37
  private router;
18
38
  constructor();
@@ -32,6 +52,8 @@ export declare class Controller {
32
52
 
33
53
  export declare function createApp(config: ApplicationConfig): express.Application;
34
54
 
55
+ export declare function custom<T>(validator: (obj: T) => ValidatorReturn): Validator<T>;
56
+
35
57
  declare interface Dependency {
36
58
  provide: string;
37
59
  useClass?: Type<any>;
@@ -51,7 +73,21 @@ declare type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveT
51
73
 
52
74
  declare const getRouterSymbol: unique symbol;
53
75
 
54
- export { interfaces }
76
+ export { inject }
77
+
78
+ export { injectable }
79
+
80
+ export declare function isDefined<T>(field?: keyof T): AtomicValidator<T>;
81
+
82
+ export declare function isNull<T>(field?: keyof T): AtomicValidator<T>;
83
+
84
+ export declare function isNumber<T>(field?: keyof T): AtomicValidator<T>;
85
+
86
+ export declare function isString<T>(field?: keyof T): AtomicValidator<T>;
87
+
88
+ export declare function isUndefined<T>(field?: keyof T): AtomicValidator<T>;
89
+
90
+ export { json }
55
91
 
56
92
  declare type Merge<A, B> = {
57
93
  [k in keyof A & keyof B]: (A & B)[k] extends never ? B[k] : 0 extends 1 & (A & B)[k] ? B[k] : (A & B)[k];
@@ -141,14 +177,26 @@ declare interface MiniControllerWS<T> {
141
177
  (handler: WSHandler<T>): void;
142
178
  }
143
179
 
180
+ export declare function not<T>(validationFunction: Validator<T>): Validator<T>;
181
+
182
+ export declare function notNull<T>(field?: keyof T): AtomicValidator<T>;
183
+
184
+ export declare function or<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
185
+
144
186
  declare interface ParamsDictionary {
145
187
  [key: string]: string;
146
188
  }
147
189
 
148
190
  declare type PathParams = string | RegExp | Array<string | RegExp>;
149
191
 
192
+ export { query }
193
+
194
+ export { raw }
195
+
150
196
  declare type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
151
197
 
198
+ declare type RequestField<F extends PropertyKey, T> = Record<F, T>;
199
+
152
200
  declare interface RequestHandler<T, P = ParamsDictionary> {
153
201
  (req: Merge<Request_2, T & {
154
202
  params: P;
@@ -191,10 +239,30 @@ declare interface Settings extends Record<SettingsEnumKeys, any> {
191
239
 
192
240
  declare type SettingsEnumKeys = 'caseSensitiveRouting' | 'env' | 'etag' | 'jsonpCallbackName' | 'jsonEscape' | 'jsonReplacer' | 'jsonSpaces' | 'queryParser' | 'strictRouting' | 'subdomainOffset' | 'trustProxy' | 'views' | 'viewCache' | 'viewEngine' | 'xPoweredBy';
193
241
 
242
+ export { static }
243
+
244
+ export { text }
245
+
194
246
  declare interface Type<T> extends Function {
195
247
  new (...args: any[]): T;
196
248
  }
197
249
 
250
+ declare type UnArray<T> = T extends Array<infer A> ? A : T;
251
+
252
+ export { urlencoded }
253
+
254
+ export declare type ValidationLogic<T> = {
255
+ [k in keyof T as T[k] extends Function ? never : k]?: ValidationLogic<UnArray<T[k]>> | Validator<T>;
256
+ };
257
+
258
+ declare abstract class Validator<T> {
259
+ abstract validate(subject: T, selectedField: keyof T): ValidatorReturn;
260
+ }
261
+
262
+ export declare function validator<T, F extends PropertyKey>(validationLogic: ValidationLogic<T>, requestField: F): Middleware<RequestField<F, T>>;
263
+
264
+ declare type ValidatorReturn = boolean | Promise<boolean>;
265
+
198
266
  declare type WSHandler<T> = (ws: WebSocket_2, req: Merge<Request_2, T>) => void;
199
267
 
200
268
  export declare type WSMiddleware<T> = (ws: WebSocket_2, req: MergePartial<Request_2, T>, next: NextFunction) => void;
package/index.js CHANGED
@@ -28,13 +28,63 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
28
28
 
29
29
  /***/ }),
30
30
 
31
+ /***/ "./src/decorators/index.ts":
32
+ /*!*********************************!*\
33
+ !*** ./src/decorators/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 */ 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?");
38
+
39
+ /***/ }),
40
+
31
41
  /***/ "./src/index.ts":
32
42
  /*!**********************!*\
33
43
  !*** ./src/index.ts ***!
34
44
  \**********************/
35
45
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
36
46
 
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?");
47
+ 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 */ and: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.and),\n/* harmony export */ bodyValidator: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.bodyValidator),\n/* harmony export */ createApp: () => (/* reexport safe */ _app__WEBPACK_IMPORTED_MODULE_0__.createApp),\n/* harmony export */ custom: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.custom),\n/* harmony export */ inject: () => (/* reexport safe */ _decorators__WEBPACK_IMPORTED_MODULE_2__.inject),\n/* harmony export */ injectable: () => (/* reexport safe */ _decorators__WEBPACK_IMPORTED_MODULE_2__.injectable),\n/* harmony export */ isDefined: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.isDefined),\n/* harmony export */ isNull: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.isNull),\n/* harmony export */ isNumber: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.isNumber),\n/* harmony export */ isString: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.isString),\n/* harmony export */ isUndefined: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.isUndefined),\n/* harmony export */ json: () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__.json),\n/* harmony export */ not: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.not),\n/* harmony export */ notNull: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.notNull),\n/* harmony export */ or: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.or),\n/* harmony export */ query: () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__.query),\n/* harmony export */ raw: () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__.raw),\n/* harmony export */ \"static\": () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__[\"static\"]),\n/* harmony export */ text: () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__.text),\n/* harmony export */ urlencoded: () => (/* reexport safe */ _middlewares__WEBPACK_IMPORTED_MODULE_3__.urlencoded),\n/* harmony export */ validator: () => (/* reexport safe */ _validators__WEBPACK_IMPORTED_MODULE_4__.validator)\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/* harmony import */ var _decorators__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./decorators */ \"./src/decorators/index.ts\");\n/* harmony import */ var _middlewares__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./middlewares */ \"./src/middlewares/index.ts\");\n/* harmony import */ var _validators__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./validators */ \"./src/validators/index.ts\");\n\n\n\n\n\n\n\n//# sourceURL=webpack://@galeh/chuka/./src/index.ts?");
48
+
49
+ /***/ }),
50
+
51
+ /***/ "./src/middlewares/index.ts":
52
+ /*!**********************************!*\
53
+ !*** ./src/middlewares/index.ts ***!
54
+ \**********************************/
55
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
56
+
57
+ 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?");
58
+
59
+ /***/ }),
60
+
61
+ /***/ "./src/validators/body-validator.ts":
62
+ /*!******************************************!*\
63
+ !*** ./src/validators/body-validator.ts ***!
64
+ \******************************************/
65
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
66
+
67
+ 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?");
68
+
69
+ /***/ }),
70
+
71
+ /***/ "./src/validators/index.ts":
72
+ /*!*********************************!*\
73
+ !*** ./src/validators/index.ts ***!
74
+ \*********************************/
75
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
76
+
77
+ 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?");
78
+
79
+ /***/ }),
80
+
81
+ /***/ "./src/validators/validators.ts":
82
+ /*!**************************************!*\
83
+ !*** ./src/validators/validators.ts ***!
84
+ \**************************************/
85
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
86
+
87
+ 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
88
 
39
89
  /***/ }),
40
90
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galeh/chuka",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "simple yet robust wrapper for expressjs",
5
5
  "keywords": [
6
6
  "chuka",
package/decorators.js DELETED
@@ -1,107 +0,0 @@
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/middlewares.js DELETED
@@ -1,107 +0,0 @@
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/validators.js DELETED
@@ -1,105 +0,0 @@
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
- /******/