@galeh/chuka 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decorators/index.d.ts +8 -0
- package/decorators/index.js +1 -0
- package/index.d.ts +198 -0
- package/index.js +1 -0
- package/middlewares/index.d.ts +20 -0
- package/middlewares/index.js +1 -0
- package/package.json +27 -0
- package/validators/index.d.ts +59 -0
- package/validators/index.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={455:e=>{e.exports=require("inversify")}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.injectable=e.inject=void 0;var r=t(455);Object.defineProperty(e,"inject",{enumerable:!0,get:function(){return r.inject}}),Object.defineProperty(e,"injectable",{enumerable:!0,get:function(){return r.injectable}})})(),exports["@galeh/chuka/decorators"]=n})();
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import core from 'express-serve-static-core';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { interfaces } from 'inversify';
|
|
4
|
+
import ws from 'ws';
|
|
5
|
+
|
|
6
|
+
declare interface ApplicationConfig {
|
|
7
|
+
routes: Array<Route>;
|
|
8
|
+
dependencies?: Array<Dependency>;
|
|
9
|
+
middlewares?: Array<RequestHandlerParams<any>>;
|
|
10
|
+
on?: EventCallback[];
|
|
11
|
+
set?: Partial<Settings>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare class Controller {
|
|
15
|
+
private router;
|
|
16
|
+
constructor();
|
|
17
|
+
private [setControllerSymbol];
|
|
18
|
+
private [getRouterSymbol];
|
|
19
|
+
protected middlewareWS<M0>(): MiniControllerWS<M0>;
|
|
20
|
+
protected middlewareWS<M0>(middleware0: WSMiddleware<M0>): MiniControllerWS<M0>;
|
|
21
|
+
protected middlewareWS<M0, M1>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>): MiniControllerWS<M0 & M1>;
|
|
22
|
+
protected middlewareWS<M0, M1, M2>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>, middleware2: WSMiddleware<M2>): MiniControllerWS<M0 & M1 & M2>;
|
|
23
|
+
protected middlewareWS<M0, M1, M2, M3>(middleware0: WSMiddleware<M0>, middleware1: WSMiddleware<M1>, middleware2: WSMiddleware<M2>, middleware3: WSMiddleware<M3>): MiniControllerWS<M0 & M1 & M2 & M3>;
|
|
24
|
+
protected middleware<M0>(): MiniController<M0>;
|
|
25
|
+
protected middleware<M0>(middleware0: RequestHandlerParams<M0>): MiniController<M0>;
|
|
26
|
+
protected middleware<M0, M1>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>): MiniController<M0 & M1>;
|
|
27
|
+
protected middleware<M0, M1, M2>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>): MiniController<M0 & M1 & M2>;
|
|
28
|
+
protected middleware<M0, M1, M2, M3>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>, middleware3: RequestHandlerParams<M3>): MiniController<M0 & M1 & M2 & M3>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare function createApp(config: ApplicationConfig): express.Application;
|
|
32
|
+
|
|
33
|
+
declare interface Dependency {
|
|
34
|
+
provide: string;
|
|
35
|
+
useClass?: Type<any>;
|
|
36
|
+
useValue?: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare interface ErrorHandler<T> {
|
|
40
|
+
(err: any, req: MergePartial<express.Request, T>, res: express.Response, next: express.NextFunction): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare type EventCallback = {
|
|
44
|
+
event: 'connect' | 'connection' | 'close' | 'error' | 'listening' | 'lookup' | 'ready' | 'timeout' | 'mount';
|
|
45
|
+
callback: (parent: express.Application) => void;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
declare type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>, `.${string}`>;
|
|
49
|
+
|
|
50
|
+
declare const getRouterSymbol: unique symbol;
|
|
51
|
+
|
|
52
|
+
export { interfaces }
|
|
53
|
+
|
|
54
|
+
declare type Merge<A, B> = {
|
|
55
|
+
[k in keyof A & keyof B]: (A & B)[k] extends never ? B[k] : 0 extends 1 & (A & B)[k] ? B[k] : (A & B)[k];
|
|
56
|
+
} & Omit<A, keyof B> & Omit<B, keyof A>;
|
|
57
|
+
|
|
58
|
+
declare type MergePartial<A, B> = {
|
|
59
|
+
[k in keyof A & keyof B]: (A & B)[k] extends never ? B[k] : 0 extends 1 & (A & B)[k] ? B[k] : (A & B)[k];
|
|
60
|
+
} & Omit<A, keyof B> & Partial<Omit<B, keyof A>>;
|
|
61
|
+
|
|
62
|
+
export declare interface Middleware<T> {
|
|
63
|
+
(req: MergePartial<express.Request, T>, res: express.Response, next: core.NextFunction): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare class MiniController<T> implements MiniControllerInterface<T> {
|
|
67
|
+
private router;
|
|
68
|
+
private middlewares;
|
|
69
|
+
constructor(router: any, middlewares: any[]);
|
|
70
|
+
all: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
71
|
+
get: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
72
|
+
post: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
73
|
+
put: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
74
|
+
delete: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
75
|
+
patch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
76
|
+
options: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
77
|
+
head: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
78
|
+
checkout: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
79
|
+
connect: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
80
|
+
copy: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
81
|
+
lock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
82
|
+
merge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
83
|
+
mkactivity: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
84
|
+
mkcol: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
85
|
+
move: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
86
|
+
'm-search': <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
87
|
+
notify: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
88
|
+
propfind: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
89
|
+
proppatch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
90
|
+
purge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
91
|
+
report: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
92
|
+
search: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
93
|
+
subscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
94
|
+
trace: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
95
|
+
unlock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
96
|
+
unsubscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
97
|
+
link: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
98
|
+
unlink: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
99
|
+
private methodImplementation;
|
|
100
|
+
middleware<M0>(middleware0: RequestHandlerParams<M0>): MiniController<Merge<T, M0>>;
|
|
101
|
+
middleware<M0, M1>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>): MiniController<Merge<T, M0 & M1>>;
|
|
102
|
+
middleware<M0, M1, M2>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>): MiniController<Merge<T, M0 & M1 & M2>>;
|
|
103
|
+
middleware<M0, M1, M2, M3>(middleware0: RequestHandlerParams<M0>, middleware1: RequestHandlerParams<M1>, middleware2: RequestHandlerParams<M2>, middleware3: RequestHandlerParams<M3>): MiniController<Merge<T, M0 & M1 & M2 & M3>>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare interface MiniControllerInterface<T> {
|
|
107
|
+
all: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
108
|
+
get: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
109
|
+
post: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
110
|
+
put: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
111
|
+
delete: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
112
|
+
patch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
113
|
+
options: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
114
|
+
head: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
115
|
+
checkout: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
116
|
+
connect: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
117
|
+
copy: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
118
|
+
lock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
119
|
+
merge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
120
|
+
mkactivity: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
121
|
+
mkcol: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
122
|
+
move: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
123
|
+
"m-search": <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
124
|
+
notify: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
125
|
+
propfind: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
126
|
+
proppatch: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
127
|
+
purge: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
128
|
+
report: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
129
|
+
search: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
130
|
+
subscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
131
|
+
trace: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
132
|
+
unlock: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
133
|
+
unsubscribe: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
134
|
+
link: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
135
|
+
unlink: <Path extends string>(path: Path, handler: RequestHandler<T, RouteParameters<Path>>) => void;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare interface MiniControllerWS<T> {
|
|
139
|
+
(handler: WSHandler<T>): void;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare interface ParamsDictionary {
|
|
143
|
+
[key: string]: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
|
|
147
|
+
|
|
148
|
+
declare interface RequestHandler<T, P = ParamsDictionary> {
|
|
149
|
+
(req: Merge<express.Request, T & {
|
|
150
|
+
params: P;
|
|
151
|
+
}>, res: express.Response, next: core.NextFunction): void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare type RequestHandlerParams<T> = Middleware<T> | ErrorHandler<T>;
|
|
155
|
+
|
|
156
|
+
declare interface Route {
|
|
157
|
+
path: core.PathParams;
|
|
158
|
+
controller: Type<Controller>;
|
|
159
|
+
children?: Array<Route>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
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}?` ? {
|
|
163
|
+
[P in ParamName]?: string;
|
|
164
|
+
} : {
|
|
165
|
+
[P in GetRouteParameter<Rest>]: string;
|
|
166
|
+
}) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : {};
|
|
167
|
+
|
|
168
|
+
declare const setControllerSymbol: unique symbol;
|
|
169
|
+
|
|
170
|
+
declare interface Settings extends Record<SettingsEnumKeys, any> {
|
|
171
|
+
caseSensitiveRouting: boolean;
|
|
172
|
+
env: string;
|
|
173
|
+
etag: any;
|
|
174
|
+
jsonpCallbackName: string;
|
|
175
|
+
jsonEscape: boolean;
|
|
176
|
+
jsonReplacer: any;
|
|
177
|
+
jsonSpaces: any;
|
|
178
|
+
queryParser: any;
|
|
179
|
+
strictRouting: boolean;
|
|
180
|
+
subdomainOffset: number;
|
|
181
|
+
trustProxy: any;
|
|
182
|
+
views: string | string[];
|
|
183
|
+
viewCache: boolean;
|
|
184
|
+
viewEngine: string;
|
|
185
|
+
xPoweredBy: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare type SettingsEnumKeys = 'caseSensitiveRouting' | 'env' | 'etag' | 'jsonpCallbackName' | 'jsonEscape' | 'jsonReplacer' | 'jsonSpaces' | 'queryParser' | 'strictRouting' | 'subdomainOffset' | 'trustProxy' | 'views' | 'viewCache' | 'viewEngine' | 'xPoweredBy';
|
|
189
|
+
|
|
190
|
+
declare interface Type<T> extends Function {
|
|
191
|
+
new (...args: any[]): T;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare type WSHandler<T> = (ws: ws.WebSocket, req: Merge<express.Request, T>) => void;
|
|
195
|
+
|
|
196
|
+
export declare type WSMiddleware<T> = (ws: ws.WebSocket, req: MergePartial<express.Request, T>, next: express.NextFunction) => void;
|
|
197
|
+
|
|
198
|
+
export { }
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var t={752:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createApp=void 0;const o=i(4);i(236);const s=o.__importDefault(i(860)),n=i(455),r=i(120),h=o.__importDefault(i(415));function l(t,e){for(const i of t)m(e,i.controller,i.controller),i.children&&l(i.children,e)}function m(t,e,i){t.isBound(e)||t.bind(e).to(i)}function a(t,e,i){t.isBound(e)||t.bind(e).toConstantValue(i)}function d(t,e,i){for(const o of t){const t=e.get(o.controller);i[r.setControllerSymbol](o.path,t),o.children&&d(o.children,e,t)}}e.createApp=function(t){const e=(0,s.default)();t.on&&function(t,e){for(const i of e)t.on(i.event,i.callback)}(e,t.on),t.set&&function(t,e){for(const[i,o]of Object.entries(e))t.set(p[i],o)}(e,t.set),(0,h.default)(e),t.middlewares&&e.use.apply(e,t.middlewares);const i=new c(e),o=new n.Container;return function(t,e){t.dependencies&&function(t,e){for(const i of t)i.useValue?a(e,i.provide,i.useValue):i.useClass&&m(e,i.provide,i.useClass)}(t.dependencies,e),l(t.routes,e)}(t,o),d(t.routes,o,i),e};class c{constructor(t){this.app=t}[r.setControllerSymbol](t,e){this.app.use(t,e[r.getRouterSymbol]())}}class p{constructor(){this.caseSensitiveRouting="case sensitive routing",this.env="env",this.etag="etag",this.jsonpCallbackName="jsonp callback name",this.jsonEscape="json escape",this.jsonReplacer="json replacer",this.jsonSpaces="json spaces",this.queryParser="query parser",this.strictRouting="strict routing",this.subdomainOffset="subdomain offset",this.trustProxy="trust proxy",this.views="views",this.viewCache="view cache",this.viewEngine="view engine",this.xPoweredBy="x-powered-by"}}},120:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Controller=e.setControllerSymbol=e.getRouterSymbol=void 0;const o=i(4),s=o.__importDefault(i(860)),n=i(455);e.getRouterSymbol=Symbol(),e.setControllerSymbol=Symbol();let r=class{constructor(){this.router=s.default.Router()}[e.setControllerSymbol](t,i){this.router.use(t,i[e.getRouterSymbol]())}[e.getRouterSymbol](){return this.router}middlewareWS(...t){return e=>{this.router.ws.apply(this.router,["/",...t,e])}}middleware(...t){return new h(this.router,t)}};e.Controller=r,e.Controller=r=o.__decorate([(0,n.injectable)()],r);class h{constructor(t,e){this.router=t,this.middlewares=e,this.all=this.methodImplementation("all").bind(this),this.get=this.methodImplementation("get").bind(this),this.post=this.methodImplementation("post").bind(this),this.put=this.methodImplementation("put").bind(this),this.delete=this.methodImplementation("delete").bind(this),this.patch=this.methodImplementation("patch").bind(this),this.options=this.methodImplementation("options").bind(this),this.head=this.methodImplementation("head").bind(this),this.checkout=this.methodImplementation("checkout").bind(this),this.connect=this.methodImplementation("connect").bind(this),this.copy=this.methodImplementation("copy").bind(this),this.lock=this.methodImplementation("lock").bind(this),this.merge=this.methodImplementation("merge").bind(this),this.mkactivity=this.methodImplementation("mkactivity").bind(this),this.mkcol=this.methodImplementation("mkcol").bind(this),this.move=this.methodImplementation("move").bind(this),this["m-search"]=this.methodImplementation("m-search").bind(this),this.notify=this.methodImplementation("notify").bind(this),this.propfind=this.methodImplementation("propfind").bind(this),this.proppatch=this.methodImplementation("proppatch").bind(this),this.purge=this.methodImplementation("purge").bind(this),this.report=this.methodImplementation("report").bind(this),this.search=this.methodImplementation("search").bind(this),this.subscribe=this.methodImplementation("subscribe").bind(this),this.trace=this.methodImplementation("trace").bind(this),this.unlock=this.methodImplementation("unlock").bind(this),this.unsubscribe=this.methodImplementation("unsubscribe").bind(this),this.link=this.methodImplementation("link").bind(this),this.unlink=this.methodImplementation("unlink").bind(this)}methodImplementation(t){return(e,i)=>{this.router[t].apply(this.router,[e,...this.middlewares,(t,e,o)=>{i(t,e,o)}])}}middleware(...t){return new h(this.router,this.middlewares.concat(t))}}},860:t=>{t.exports=require("express")},415:t=>{t.exports=require("express-ws")},455:t=>{t.exports=require("inversify")},236:t=>{t.exports=require("reflect-metadata")},4:t=>{t.exports=require("tslib")}},e={};function i(o){var s=e[o];if(void 0!==s)return s.exports;var n=e[o]={exports:{}};return t[o](n,n.exports,i),n.exports}var o={};(()=>{var t=o;Object.defineProperty(t,"__esModule",{value:!0}),t.Controller=t.createApp=void 0;var e=i(752);Object.defineProperty(t,"createApp",{enumerable:!0,get:function(){return e.createApp}});var s=i(120);Object.defineProperty(t,"Controller",{enumerable:!0,get:function(){return s.Controller}})})(),exports["@galeh/chuka"]=o})();
|
|
@@ -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 { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={860:e=>{e.exports=require("express")}},r={};function t(n){var u=r[n];if(void 0!==u)return u.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.text=e.raw=e.query=e.urlencoded=e.static=e.json=void 0;var r=t(860);Object.defineProperty(e,"json",{enumerable:!0,get:function(){return r.json}}),Object.defineProperty(e,"static",{enumerable:!0,get:function(){return r.static}}),Object.defineProperty(e,"urlencoded",{enumerable:!0,get:function(){return r.urlencoded}}),Object.defineProperty(e,"query",{enumerable:!0,get:function(){return r.query}}),Object.defineProperty(e,"raw",{enumerable:!0,get:function(){return r.raw}}),Object.defineProperty(e,"text",{enumerable:!0,get:function(){return r.text}})})(),exports["@galeh/chuka/middlewares"]=n})();
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galeh/chuka",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "simple yet robust wrapper for expressjs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chuka",
|
|
7
|
+
"framework",
|
|
8
|
+
"web",
|
|
9
|
+
"http",
|
|
10
|
+
"rest",
|
|
11
|
+
"restful",
|
|
12
|
+
"router",
|
|
13
|
+
"app",
|
|
14
|
+
"api"
|
|
15
|
+
],
|
|
16
|
+
"author": "Hojjat Bakhtiyari <dariogaleh@gmail.com>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"express": "^4.18.2",
|
|
20
|
+
"express-ws": "^5.0.2",
|
|
21
|
+
"i": "^0.3.7",
|
|
22
|
+
"inversify": "^6.0.2",
|
|
23
|
+
"npm": "^10.2.5",
|
|
24
|
+
"reflect-metadata": "^0.2.1",
|
|
25
|
+
"tslib": "^2.6.2"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import core from 'express-serve-static-core';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
|
|
4
|
+
export declare function and<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
|
|
5
|
+
|
|
6
|
+
declare class AtomicValidator<T> extends Validator<T> {
|
|
7
|
+
private implementation;
|
|
8
|
+
queryField?: keyof T | undefined;
|
|
9
|
+
constructor(implementation: (subject: T | T[keyof T]) => ValidatorReturn, queryField?: keyof T | undefined);
|
|
10
|
+
validate(subject: T, selectedField: keyof T): ValidatorReturn;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare function bodyValidator<T>(validationLogic: ValidationLogic<T>): Middleware<{
|
|
14
|
+
body: T;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export declare function custom<T>(validator: (obj: T) => ValidatorReturn): Validator<T>;
|
|
18
|
+
|
|
19
|
+
export declare function isDefined<T>(field?: keyof T): AtomicValidator<T>;
|
|
20
|
+
|
|
21
|
+
export declare function isNull<T>(field?: keyof T): AtomicValidator<T>;
|
|
22
|
+
|
|
23
|
+
export declare function isNumber<T>(field?: keyof T): AtomicValidator<T>;
|
|
24
|
+
|
|
25
|
+
export declare function isString<T>(field?: keyof T): AtomicValidator<T>;
|
|
26
|
+
|
|
27
|
+
export declare function isUndefined<T>(field?: keyof T): AtomicValidator<T>;
|
|
28
|
+
|
|
29
|
+
declare type MergePartial<A, B> = {
|
|
30
|
+
[k in keyof A & keyof B]: (A & B)[k] extends never ? B[k] : 0 extends 1 & (A & B)[k] ? B[k] : (A & B)[k];
|
|
31
|
+
} & Omit<A, keyof B> & Partial<Omit<B, keyof A>>;
|
|
32
|
+
|
|
33
|
+
declare interface Middleware<T> {
|
|
34
|
+
(req: MergePartial<express.Request, T>, res: express.Response, next: core.NextFunction): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare function not<T>(validationFunction: Validator<T>): Validator<T>;
|
|
38
|
+
|
|
39
|
+
export declare function notNull<T>(field?: keyof T): AtomicValidator<T>;
|
|
40
|
+
|
|
41
|
+
export declare function or<T>(...validationFunctions: Array<Validator<T>>): Validator<T>;
|
|
42
|
+
|
|
43
|
+
declare type RequestField<F extends PropertyKey, T> = Record<F, T>;
|
|
44
|
+
|
|
45
|
+
declare type UnArray<T> = T extends Array<infer A> ? A : T;
|
|
46
|
+
|
|
47
|
+
export declare type ValidationLogic<T> = {
|
|
48
|
+
[k in keyof T as T[k] extends Function ? never : k]?: ValidationLogic<UnArray<T[k]>> | Validator<T>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
declare abstract class Validator<T> {
|
|
52
|
+
abstract validate(subject: T, selectedField: keyof T): ValidatorReturn;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export declare function validator<T, F extends PropertyKey>(validationLogic: ValidationLogic<T>, requestField: F): Middleware<RequestField<F, T>>;
|
|
56
|
+
|
|
57
|
+
declare type ValidatorReturn = boolean | Promise<boolean>;
|
|
58
|
+
|
|
59
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={384:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.bodyValidator=void 0;const r=n(871);t.bodyValidator=function(e){return(t,n,i)=>{(0,r.validator)(e,"body")(t,n,i)}}},871:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.bodyValidator=t.custom=t.validator=t.or=t.notNull=t.not=t.isUndefined=t.isString=t.isNumber=t.isNull=t.isDefined=t.and=void 0;var r=n(500);Object.defineProperty(t,"and",{enumerable:!0,get:function(){return r.and}}),Object.defineProperty(t,"isDefined",{enumerable:!0,get:function(){return r.isDefined}}),Object.defineProperty(t,"isNull",{enumerable:!0,get:function(){return r.isNull}}),Object.defineProperty(t,"isNumber",{enumerable:!0,get:function(){return r.isNumber}}),Object.defineProperty(t,"isString",{enumerable:!0,get:function(){return r.isString}}),Object.defineProperty(t,"isUndefined",{enumerable:!0,get:function(){return r.isUndefined}}),Object.defineProperty(t,"not",{enumerable:!0,get:function(){return r.not}}),Object.defineProperty(t,"notNull",{enumerable:!0,get:function(){return r.notNull}}),Object.defineProperty(t,"or",{enumerable:!0,get:function(){return r.or}}),Object.defineProperty(t,"validator",{enumerable:!0,get:function(){return r.validator}}),Object.defineProperty(t,"custom",{enumerable:!0,get:function(){return r.custom}});var i=n(384);Object.defineProperty(t,"bodyValidator",{enumerable:!0,get:function(){return i.bodyValidator}})},500:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.not=t.or=t.andAsync=t.and=t.notNull=t.isNull=t.isUndefined=t.isDefined=t.isNumber=t.isString=t.AtomicValidator=t.custom=t.Validator=t.validator=void 0;const r=n(752);function i(e,t){return r.__awaiter(this,void 0,void 0,(function*(){const n={};for(const r in t){const o=t[r];if(o)if(o instanceof u)try{n[r]=o.validate(e,r),n[r]instanceof Promise&&(n[r]=yield n[r],console.log(`awaited result: ${n[r]}`))}catch(e){n[r]=!1}else e[r]instanceof Array?(n[r]=e[r].map((e=>i(e,o))),n[r][0]instanceof Promise&&(n[r]=Promise.all(n[r]))):(n[r]=i(e[r],o),n[r]instanceof Promise&&(n[r]=yield n[r]));else n[r]=!0}return n}))}function o(e){for(const[t,n]of Object.entries(e)){if(!1===n)return!0;if("boolean"!=typeof n){const e=o(n);if(e)return e}}return!1}t.validator=function(e,t){return(n,r,u)=>{i(n[t],e).then((e=>{o(e)?u(e):u()})).catch(u)}};class u{}t.Validator=u;class a extends u{constructor(e){super(),this.validator=e}validate(e,t){return this.validator(e)}}t.custom=function(e){return new a(e)};class s extends u{constructor(e,t){super(),this.implementation=e,this.queryField=t}validate(e,t){return this.implementation(this.queryField?e[this.queryField]:e[t])}}t.AtomicValidator=s,t.isString=function(e){return new s((e=>"string"==typeof e),e)},t.isNumber=function(e){return new s((e=>"number"==typeof e),e)},t.isDefined=function(e){return new s((e=>null!=e),e)},t.isUndefined=function(e){return new s((e=>void 0===e),e)},t.isNull=function(e){return new s((e=>null===e),e)},t.notNull=function(e){return new s((e=>null!==e),e)};class l extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return this.validationFunctions.every((n=>n.validate(e,t)))}}class d extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return r.__awaiter(this,void 0,void 0,(function*(){const n=this.validationFunctions.map((n=>n.validate(e,t)));return(yield Promise.all(n)).every((e=>e))}))}}class c extends u{constructor(...e){super(),this.validationFunctions=e}validate(e,t){return this.validationFunctions.some((n=>n.validate(e,t)))}}class f extends u{constructor(e){super(),this.validationFunction=e}validate(e,t){return!this.validationFunction.validate(e,t)}}t.and=function(...e){return new l(...e)},t.andAsync=function(...e){return new d(...e)},t.or=function(...e){return new c(...e)},t.not=function(e){return new f(e)}},752:e=>{e.exports=require("tslib")}},t={},n=function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}(871);exports["@galeh/chuka/validators"]=n})();
|