@galeh/chuka 1.1.2 → 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/decorators.d.ts +8 -0
- package/index.d.ts +270 -0
- package/index.js +217 -0
- package/middlewares.d.ts +20 -0
- package/package.json +40 -49
- package/validators.d.ts +60 -0
- package/.github/workflows/webpack.yml +0 -34
- package/config/api-extractor.decorators.json +0 -427
- package/config/api-extractor.index.json +0 -427
- package/config/api-extractor.middlewares.json +0 -427
- package/config/api-extractor.validators.json +0 -427
- package/sample/01-cats-app/package-lock.json +0 -283
- package/sample/01-cats-app/package.json +0 -19
- package/sample/01-cats-app/src/cats/cat-model.ts +0 -9
- package/sample/01-cats-app/src/cats/cats-controller.ts +0 -44
- package/sample/01-cats-app/src/cats/cats-service-interface.ts +0 -7
- package/sample/01-cats-app/src/cats/cats-service.ts +0 -27
- package/sample/01-cats-app/src/cats/create-logger.ts +0 -8
- package/sample/01-cats-app/src/main.ts +0 -30
- package/sample/01-cats-app/tsconfig.json +0 -112
- package/sample/02-socket/package-lock.json +0 -442
- package/sample/02-socket/package.json +0 -20
- package/sample/02-socket/src/controllers/http-controller.ts +0 -14
- package/sample/02-socket/src/controllers/socket-controller.ts +0 -18
- package/sample/02-socket/src/main.ts +0 -46
- package/sample/02-socket/src/middleware/create-session.ts +0 -9
- package/sample/02-socket/tsconfig.json +0 -112
- package/sample/03-authentication/db/create.sql +0 -6
- package/sample/03-authentication/package-lock.json +0 -1832
- package/sample/03-authentication/package.json +0 -23
- package/sample/03-authentication/src/config.ts +0 -21
- package/sample/03-authentication/src/controllers/auth-controller.ts +0 -54
- package/sample/03-authentication/src/enums/injection-tokens.ts +0 -5
- package/sample/03-authentication/src/enums/result-codes.ts +0 -4
- package/sample/03-authentication/src/exceptions/error.ts +0 -7
- package/sample/03-authentication/src/exceptions/password-not-found-exception.ts +0 -9
- package/sample/03-authentication/src/exceptions/unauthorized-exception.ts +0 -9
- package/sample/03-authentication/src/exceptions/user-already-exist.ts +0 -9
- package/sample/03-authentication/src/exceptions/user-not-found.ts +0 -9
- package/sample/03-authentication/src/exceptions/wrong-login-info-exception.ts +0 -8
- package/sample/03-authentication/src/main.ts +0 -42
- package/sample/03-authentication/src/middlewares/auth-handler.ts +0 -17
- package/sample/03-authentication/src/middlewares/global-error-handler.ts +0 -21
- package/sample/03-authentication/src/models/user-model.ts +0 -6
- package/sample/03-authentication/src/services/auth-service.ts +0 -50
- package/sample/03-authentication/src/services/interfaces/auth-service-interface.ts +0 -7
- package/sample/03-authentication/src/services/interfaces/user-service-interface.ts +0 -7
- package/sample/03-authentication/src/services/user-service.ts +0 -75
- package/sample/03-authentication/src/types/connection.ts +0 -3
- package/sample/03-authentication/src/types/token.ts +0 -3
- package/sample/03-authentication/src/utils/crypto.ts +0 -26
- package/sample/03-authentication/tsconfig.json +0 -112
- package/scripts/build.bash +0 -17
- package/scripts/create-package-json.js +0 -15
- package/src/app.ts +0 -197
- package/src/controller.ts +0 -204
- package/src/decorators/index.ts +0 -1
- package/src/index.ts +0 -3
- package/src/middlewares/index.ts +0 -1
- package/src/validators/body-validator.ts +0 -9
- package/src/validators/index.ts +0 -2
- package/src/validators/query-validator.ts +0 -9
- package/src/validators/validators.ts +0 -216
- package/tsconfig.json +0 -112
- package/webpack.config.js +0 -46
package/decorators.d.ts
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { inject } from 'inversify';
|
|
3
|
+
import { injectable } from 'inversify';
|
|
4
|
+
import { json } from 'express';
|
|
5
|
+
import { NextFunction } from 'express';
|
|
6
|
+
import { query } from 'express';
|
|
7
|
+
import { raw } from 'express';
|
|
8
|
+
import { Request as Request_2 } from 'express';
|
|
9
|
+
import { Response as Response_2 } from 'express';
|
|
10
|
+
import { static } from 'express';
|
|
11
|
+
import { text } from 'express';
|
|
12
|
+
import { urlencoded } from 'express';
|
|
13
|
+
import { WebSocket as WebSocket_2 } from 'ws';
|
|
14
|
+
|
|
15
|
+
export declare function and<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
|
|
16
|
+
|
|
17
|
+
declare interface ApplicationConfig {
|
|
18
|
+
routes: Array<Route>;
|
|
19
|
+
dependencies?: Array<Dependency>;
|
|
20
|
+
middlewares?: Array<RequestHandlerParams<any>>;
|
|
21
|
+
on?: EventCallback[];
|
|
22
|
+
set?: Partial<Settings>;
|
|
23
|
+
}
|
|
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
|
+
|
|
36
|
+
export declare class Controller {
|
|
37
|
+
private router;
|
|
38
|
+
constructor();
|
|
39
|
+
private [setControllerSymbol];
|
|
40
|
+
private [getRouterSymbol];
|
|
41
|
+
protected useWS<M0>(): MiniControllerWS<M0>;
|
|
42
|
+
protected useWS<M0>(middleware0: WSMiddleware<M0>): MiniControllerWS<M0>;
|
|
43
|
+
protected useWS<M0, M1>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>): MiniControllerWS<M0 & M1>;
|
|
44
|
+
protected useWS<M0, M1, M2>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>, middleware2: WSMiddleware<M2>): MiniControllerWS<M0 & M1 & M2>;
|
|
45
|
+
protected useWS<M0, M1, M2, M3>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>, middleware2: WSMiddleware<M2>, middleware3: WSMiddleware<M3>): MiniControllerWS<M0 & M1 & M2 & M3>;
|
|
46
|
+
protected use<M0>(): MiniController<M0>;
|
|
47
|
+
protected use<M0>(middleware0: RequestHandlerParams<M0>): MiniController<M0>;
|
|
48
|
+
protected use<M0, M1>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>): MiniController<M0 & M1>;
|
|
49
|
+
protected use<M0, M1, M2>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>): MiniController<M0 & M1 & M2>;
|
|
50
|
+
protected use<M0, M1, M2, M3>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>, middleware3: RequestHandlerParams<M3>): MiniController<M0 & M1 & M2 & M3>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export declare function createApp(config: ApplicationConfig): express.Application;
|
|
54
|
+
|
|
55
|
+
export declare function custom<T>(validator: (obj: T) => ValidatorReturn): Validator<T>;
|
|
56
|
+
|
|
57
|
+
declare interface Dependency {
|
|
58
|
+
provide: string;
|
|
59
|
+
useClass?: Type<any>;
|
|
60
|
+
useValue?: any;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare interface ErrorHandler<T> {
|
|
64
|
+
(err: any, req: MergePartial<Request_2, T>, res: Response_2, next: NextFunction): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare type EventCallback = {
|
|
68
|
+
event: 'connect' | 'connection' | 'close' | 'error' | 'listening' | 'lookup' | 'ready' | 'timeout' | 'mount';
|
|
69
|
+
callback: (parent: express.Application) => void;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>, `.${string}`>;
|
|
73
|
+
|
|
74
|
+
declare const getRouterSymbol: unique symbol;
|
|
75
|
+
|
|
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 }
|
|
91
|
+
|
|
92
|
+
declare type Merge<A, B> = {
|
|
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];
|
|
94
|
+
} & Omit<A, keyof B> & Omit<B, keyof A>;
|
|
95
|
+
|
|
96
|
+
declare type MergePartial<A, B> = {
|
|
97
|
+
[k in keyof A & keyof B]: (A & B)[k] extends never ? B[k] : 0 extends 1 & (A & B)[k] ? B[k] : (A & B)[k];
|
|
98
|
+
} & Omit<A, keyof B> & Partial<Omit<B, keyof A>>;
|
|
99
|
+
|
|
100
|
+
export declare interface Middleware<T> {
|
|
101
|
+
(req: MergePartial<Request_2, T>, res: Response_2, next: NextFunction): void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class MiniController<T> implements MiniControllerInterface<T> {
|
|
105
|
+
private router;
|
|
106
|
+
private middlewares;
|
|
107
|
+
constructor(router: any, middlewares: any[]);
|
|
108
|
+
all: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
109
|
+
get: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
110
|
+
post: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
111
|
+
put: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
112
|
+
delete: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
113
|
+
patch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
114
|
+
options: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
115
|
+
head: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
116
|
+
checkout: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
117
|
+
connect: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
118
|
+
copy: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
119
|
+
lock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
120
|
+
merge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
121
|
+
mkactivity: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
122
|
+
mkcol: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
123
|
+
move: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
124
|
+
'm-search': <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
125
|
+
notify: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
126
|
+
propfind: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
127
|
+
proppatch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
128
|
+
purge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
129
|
+
report: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
130
|
+
search: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
131
|
+
subscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
132
|
+
trace: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
133
|
+
unlock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
134
|
+
unsubscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
135
|
+
link: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
136
|
+
unlink: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
137
|
+
private methodImplementation;
|
|
138
|
+
use<M0>(middleware0: RequestHandlerParams<M0>): MiniController<Merge<T, M0>>;
|
|
139
|
+
use<M0, M1>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>): MiniController<Merge<T, M0 & M1>>;
|
|
140
|
+
use<M0, M1, M2>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>): MiniController<Merge<T, M0 & M1 & M2>>;
|
|
141
|
+
use<M0, M1, M2, M3>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>, middleware3: RequestHandlerParams<M3>): MiniController<Merge<T, M0 & M1 & M2 & M3>>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare interface MiniControllerInterface<T> {
|
|
145
|
+
all: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
146
|
+
get: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
147
|
+
post: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
148
|
+
put: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
149
|
+
delete: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
150
|
+
patch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
151
|
+
options: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
152
|
+
head: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
153
|
+
checkout: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
154
|
+
connect: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
155
|
+
copy: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
156
|
+
lock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
157
|
+
merge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
158
|
+
mkactivity: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
159
|
+
mkcol: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
160
|
+
move: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
161
|
+
"m-search": <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
162
|
+
notify: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
163
|
+
propfind: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
164
|
+
proppatch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
165
|
+
purge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
166
|
+
report: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
167
|
+
search: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
168
|
+
subscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
169
|
+
trace: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
170
|
+
unlock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
171
|
+
unsubscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
172
|
+
link: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
173
|
+
unlink: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare interface MiniControllerWS<T> {
|
|
177
|
+
(handler: WSHandler<T>): void;
|
|
178
|
+
}
|
|
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
|
+
|
|
186
|
+
declare interface ParamsDictionary {
|
|
187
|
+
[key: string]: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare type PathParams = string | RegExp | Array<string | RegExp>;
|
|
191
|
+
|
|
192
|
+
export { query }
|
|
193
|
+
|
|
194
|
+
export { raw }
|
|
195
|
+
|
|
196
|
+
declare type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
|
|
197
|
+
|
|
198
|
+
declare type RequestField<F extends PropertyKey, T> = Record<F, T>;
|
|
199
|
+
|
|
200
|
+
declare interface RequestHandler<T, P = ParamsDictionary> {
|
|
201
|
+
(req: Merge<Request_2, T & {
|
|
202
|
+
params: P;
|
|
203
|
+
}>, res: Response_2, next: NextFunction): void;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare type RequestHandlerParams<T> = Middleware<T> | ErrorHandler<T>;
|
|
207
|
+
|
|
208
|
+
declare interface Route {
|
|
209
|
+
path: PathParams;
|
|
210
|
+
controller: Type<Controller>;
|
|
211
|
+
children?: Array<Route>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare type RouteParameters<Route extends string> = string extends Route ? ParamsDictionary : Route extends `${string}(${string}` ? ParamsDictionary : Route extends `${string}:${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : GetRouteParameter<Rest> extends `${infer ParamName}?` ? {
|
|
215
|
+
[P in ParamName]?: string;
|
|
216
|
+
} : {
|
|
217
|
+
[P in GetRouteParameter<Rest>]: string;
|
|
218
|
+
}) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : {};
|
|
219
|
+
|
|
220
|
+
declare const setControllerSymbol: unique symbol;
|
|
221
|
+
|
|
222
|
+
declare interface Settings extends Record<SettingsEnumKeys, any> {
|
|
223
|
+
caseSensitiveRouting: boolean;
|
|
224
|
+
env: string;
|
|
225
|
+
etag: any;
|
|
226
|
+
jsonpCallbackName: string;
|
|
227
|
+
jsonEscape: boolean;
|
|
228
|
+
jsonReplacer: any;
|
|
229
|
+
jsonSpaces: any;
|
|
230
|
+
queryParser: any;
|
|
231
|
+
strictRouting: boolean;
|
|
232
|
+
subdomainOffset: number;
|
|
233
|
+
trustProxy: any;
|
|
234
|
+
views: string | string[];
|
|
235
|
+
viewCache: boolean;
|
|
236
|
+
viewEngine: string;
|
|
237
|
+
xPoweredBy: boolean;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare type SettingsEnumKeys = 'caseSensitiveRouting' | 'env' | 'etag' | 'jsonpCallbackName' | 'jsonEscape' | 'jsonReplacer' | 'jsonSpaces' | 'queryParser' | 'strictRouting' | 'subdomainOffset' | 'trustProxy' | 'views' | 'viewCache' | 'viewEngine' | 'xPoweredBy';
|
|
241
|
+
|
|
242
|
+
export { static }
|
|
243
|
+
|
|
244
|
+
export { text }
|
|
245
|
+
|
|
246
|
+
declare interface Type<T> extends Function {
|
|
247
|
+
new (...args: any[]): T;
|
|
248
|
+
}
|
|
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
|
+
|
|
266
|
+
declare type WSHandler<T> = (ws: WebSocket_2, req: Merge<Request_2, T>) => void;
|
|
267
|
+
|
|
268
|
+
export declare type WSMiddleware<T> = (ws: WebSocket_2, req: MergePartial<Request_2, T>, next: NextFunction) => void;
|
|
269
|
+
|
|
270
|
+
export { }
|
package/index.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
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 useWS(...middlewares) {\n return (handler) => {\n this.router.ws.apply(this.router, ['/', ...middlewares, handler]);\n };\n }\n use(...middlewares) {\n return new MiniController(this.router, middlewares);\n }\n};\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 use(...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/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
|
+
|
|
41
|
+
/***/ "./src/index.ts":
|
|
42
|
+
/*!**********************!*\
|
|
43
|
+
!*** ./src/index.ts ***!
|
|
44
|
+
\**********************/
|
|
45
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
46
|
+
|
|
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?");
|
|
88
|
+
|
|
89
|
+
/***/ }),
|
|
90
|
+
|
|
91
|
+
/***/ "express":
|
|
92
|
+
/*!**************************!*\
|
|
93
|
+
!*** external "express" ***!
|
|
94
|
+
\**************************/
|
|
95
|
+
/***/ ((module) => {
|
|
96
|
+
|
|
97
|
+
module.exports = require("express");
|
|
98
|
+
|
|
99
|
+
/***/ }),
|
|
100
|
+
|
|
101
|
+
/***/ "express-ws":
|
|
102
|
+
/*!*****************************!*\
|
|
103
|
+
!*** external "express-ws" ***!
|
|
104
|
+
\*****************************/
|
|
105
|
+
/***/ ((module) => {
|
|
106
|
+
|
|
107
|
+
module.exports = require("express-ws");
|
|
108
|
+
|
|
109
|
+
/***/ }),
|
|
110
|
+
|
|
111
|
+
/***/ "inversify":
|
|
112
|
+
/*!****************************!*\
|
|
113
|
+
!*** external "inversify" ***!
|
|
114
|
+
\****************************/
|
|
115
|
+
/***/ ((module) => {
|
|
116
|
+
|
|
117
|
+
module.exports = require("inversify");
|
|
118
|
+
|
|
119
|
+
/***/ }),
|
|
120
|
+
|
|
121
|
+
/***/ "reflect-metadata":
|
|
122
|
+
/*!***********************************!*\
|
|
123
|
+
!*** external "reflect-metadata" ***!
|
|
124
|
+
\***********************************/
|
|
125
|
+
/***/ ((module) => {
|
|
126
|
+
|
|
127
|
+
module.exports = require("reflect-metadata");
|
|
128
|
+
|
|
129
|
+
/***/ }),
|
|
130
|
+
|
|
131
|
+
/***/ "tslib":
|
|
132
|
+
/*!************************!*\
|
|
133
|
+
!*** external "tslib" ***!
|
|
134
|
+
\************************/
|
|
135
|
+
/***/ ((module) => {
|
|
136
|
+
|
|
137
|
+
module.exports = require("tslib");
|
|
138
|
+
|
|
139
|
+
/***/ })
|
|
140
|
+
|
|
141
|
+
/******/ });
|
|
142
|
+
/************************************************************************/
|
|
143
|
+
/******/ // The module cache
|
|
144
|
+
/******/ var __webpack_module_cache__ = {};
|
|
145
|
+
/******/
|
|
146
|
+
/******/ // The require function
|
|
147
|
+
/******/ function __webpack_require__(moduleId) {
|
|
148
|
+
/******/ // Check if module is in cache
|
|
149
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
150
|
+
/******/ if (cachedModule !== undefined) {
|
|
151
|
+
/******/ return cachedModule.exports;
|
|
152
|
+
/******/ }
|
|
153
|
+
/******/ // Create a new module (and put it into the cache)
|
|
154
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
155
|
+
/******/ // no module.id needed
|
|
156
|
+
/******/ // no module.loaded needed
|
|
157
|
+
/******/ exports: {}
|
|
158
|
+
/******/ };
|
|
159
|
+
/******/
|
|
160
|
+
/******/ // Execute the module function
|
|
161
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
162
|
+
/******/
|
|
163
|
+
/******/ // Return the exports of the module
|
|
164
|
+
/******/ return module.exports;
|
|
165
|
+
/******/ }
|
|
166
|
+
/******/
|
|
167
|
+
/************************************************************************/
|
|
168
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
169
|
+
/******/ (() => {
|
|
170
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
171
|
+
/******/ __webpack_require__.n = (module) => {
|
|
172
|
+
/******/ var getter = module && module.__esModule ?
|
|
173
|
+
/******/ () => (module['default']) :
|
|
174
|
+
/******/ () => (module);
|
|
175
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
176
|
+
/******/ return getter;
|
|
177
|
+
/******/ };
|
|
178
|
+
/******/ })();
|
|
179
|
+
/******/
|
|
180
|
+
/******/ /* webpack/runtime/define property getters */
|
|
181
|
+
/******/ (() => {
|
|
182
|
+
/******/ // define getter functions for harmony exports
|
|
183
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
184
|
+
/******/ for(var key in definition) {
|
|
185
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
186
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
187
|
+
/******/ }
|
|
188
|
+
/******/ }
|
|
189
|
+
/******/ };
|
|
190
|
+
/******/ })();
|
|
191
|
+
/******/
|
|
192
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
193
|
+
/******/ (() => {
|
|
194
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
195
|
+
/******/ })();
|
|
196
|
+
/******/
|
|
197
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
198
|
+
/******/ (() => {
|
|
199
|
+
/******/ // define __esModule on exports
|
|
200
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
201
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
202
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
203
|
+
/******/ }
|
|
204
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
205
|
+
/******/ };
|
|
206
|
+
/******/ })();
|
|
207
|
+
/******/
|
|
208
|
+
/************************************************************************/
|
|
209
|
+
/******/
|
|
210
|
+
/******/ // startup
|
|
211
|
+
/******/ // Load entry module and return exports
|
|
212
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
213
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
|
|
214
|
+
/******/ var __webpack_export_target__ = exports;
|
|
215
|
+
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
216
|
+
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
217
|
+
/******/
|
package/middlewares.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { json } from 'express';
|
|
2
|
+
import { query } from 'express';
|
|
3
|
+
import { raw } from 'express';
|
|
4
|
+
import { static } from 'express';
|
|
5
|
+
import { text } from 'express';
|
|
6
|
+
import { urlencoded } from 'express';
|
|
7
|
+
|
|
8
|
+
export { json }
|
|
9
|
+
|
|
10
|
+
export { query }
|
|
11
|
+
|
|
12
|
+
export { raw }
|
|
13
|
+
|
|
14
|
+
export { static }
|
|
15
|
+
|
|
16
|
+
export { text }
|
|
17
|
+
|
|
18
|
+
export { urlencoded }
|
|
19
|
+
|
|
20
|
+
export { }
|