@devbro/neko-router 0.1.6 → 0.1.8

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.
Files changed (44) hide show
  1. package/dist/CompiledRoute.mjs +26 -49
  2. package/dist/CompiledRoute.mjs.map +1 -1
  3. package/dist/Controller.mjs +14 -35
  4. package/dist/Controller.mjs.map +1 -1
  5. package/dist/Middleware.mjs.map +1 -1
  6. package/dist/MiddlewareFactory.mjs +1 -1
  7. package/dist/MiddlewareFactory.mjs.map +1 -1
  8. package/dist/Route.mjs +2 -1
  9. package/dist/Route.mjs.map +1 -1
  10. package/dist/Router.mjs +7 -29
  11. package/dist/Router.mjs.map +1 -1
  12. package/dist/helpers.mjs +16 -40
  13. package/dist/helpers.mjs.map +1 -1
  14. package/dist/index.js +463 -17
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +8 -8
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +6 -3
  19. package/dist/CompiledRoute.d.ts +0 -22
  20. package/dist/CompiledRoute.js +0 -161
  21. package/dist/CompiledRoute.js.map +0 -1
  22. package/dist/Controller.d.ts +0 -42
  23. package/dist/Controller.js +0 -154
  24. package/dist/Controller.js.map +0 -1
  25. package/dist/Middleware-C8dxjlFD.d.ts +0 -30
  26. package/dist/Middleware.d.ts +0 -2
  27. package/dist/Middleware.js +0 -35
  28. package/dist/Middleware.js.map +0 -1
  29. package/dist/MiddlewareFactory.d.ts +0 -8
  30. package/dist/MiddlewareFactory.js +0 -42
  31. package/dist/MiddlewareFactory.js.map +0 -1
  32. package/dist/Route.d.ts +0 -40
  33. package/dist/Route.js +0 -138
  34. package/dist/Route.js.map +0 -1
  35. package/dist/Router.d.ts +0 -19
  36. package/dist/Router.js +0 -118
  37. package/dist/Router.js.map +0 -1
  38. package/dist/helpers.d.ts +0 -6
  39. package/dist/helpers.js +0 -70
  40. package/dist/helpers.js.map +0 -1
  41. package/dist/index.d.ts +0 -8
  42. package/dist/types.d.ts +0 -2
  43. package/dist/types.js +0 -17
  44. package/dist/types.js.map +0 -1
package/dist/Route.js DELETED
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var Route_exports = {};
20
- __export(Route_exports, {
21
- Route: () => Route
22
- });
23
- module.exports = __toCommonJS(Route_exports);
24
- class Route {
25
- constructor(methods, path, handler) {
26
- this.methods = methods;
27
- this.path = path;
28
- this.handler = handler;
29
- this.middlewares = [];
30
- this.urlRegex = this.pathToRegex(path);
31
- }
32
- pathToRegex(path) {
33
- const lex = this.lexUrlPath(path);
34
- return this.tokensToRegex(lex);
35
- }
36
- lexUrlPath(path) {
37
- const tokens = [];
38
- let i = 0;
39
- while (i < path.length) {
40
- const char = path[i];
41
- if (char === "/") {
42
- tokens.push({ type: "SLASH", value: "/" });
43
- i++;
44
- } else if (char === ":") {
45
- let start = i + 1;
46
- while (start < path.length && /[a-zA-Z0-9_]/.test(path[start])) {
47
- start++;
48
- }
49
- tokens.push({ type: "PARAM", value: path.slice(i + 1, start) });
50
- i = start;
51
- } else if (char === "*") {
52
- let start = i + 1;
53
- while (start < path.length && /[a-zA-Z0-9_]/.test(path[start])) {
54
- start++;
55
- }
56
- tokens.push({ type: "WILDCARD", value: path.slice(i + 1, start) });
57
- i = start;
58
- } else {
59
- let start = i;
60
- while (start < path.length && !["/", ":", "*"].includes(path[start])) {
61
- start++;
62
- }
63
- tokens.push({ type: "TEXT", value: path.slice(i, start) });
64
- i = start;
65
- }
66
- }
67
- return tokens;
68
- }
69
- tokensToRegex(tokens) {
70
- const regexParts = [];
71
- for (const token of tokens) {
72
- if (token.type === "SLASH") {
73
- regexParts.push("\\/");
74
- } else if (token.type === "PARAM") {
75
- regexParts.push(`(?<${token.value}>[^\\/]+)`);
76
- } else if (token.type === "WILDCARD") {
77
- regexParts.push("(.+)");
78
- } else if (token.type === "TEXT") {
79
- regexParts.push(token.value.replace(/[-\/\\^$.*+?()[\]{}|]/g, "\\$&"));
80
- }
81
- }
82
- if (regexParts.length > 0 && regexParts[regexParts.length - 1] === "\\/") {
83
- regexParts[regexParts.length - 1] = "\\/?";
84
- } else {
85
- regexParts.push("\\/?");
86
- }
87
- return new RegExp(`^${regexParts.join("")}$`);
88
- }
89
- /**
90
- * to evaludate if request is a match for this route
91
- * @param request http request
92
- * @returns return true if route is a match for this request
93
- */
94
- test(request) {
95
- if (this.methods.indexOf(request.method) === -1) {
96
- return false;
97
- }
98
- const url = new URL(request.url || "/", "http://localhost");
99
- return this.testPath(url.pathname);
100
- }
101
- testPath(pathname) {
102
- return this.urlRegex.test(pathname);
103
- }
104
- /**
105
- * returns details of the match, otherwise it returns false
106
- * @param request the request to match
107
- * @returns object cotaining details of match including matched params
108
- */
109
- match(request) {
110
- if (this.methods.indexOf(request.method) === -1) {
111
- return false;
112
- }
113
- const url = new URL(request.url || "/", "http://localhost");
114
- const r = this.urlRegex.exec(url.pathname);
115
- if (!r) {
116
- return false;
117
- }
118
- return {
119
- url,
120
- params: r.groups || {}
121
- };
122
- }
123
- addMiddleware(middlewares) {
124
- this.middlewares = this.middlewares.concat(middlewares);
125
- return this;
126
- }
127
- getMiddlewares() {
128
- return this.middlewares;
129
- }
130
- callHanlder(request, response) {
131
- return this.handler(request, response);
132
- }
133
- }
134
- // Annotate the CommonJS export names for ESM import in node:
135
- 0 && (module.exports = {
136
- Route
137
- });
138
- //# sourceMappingURL=Route.js.map
package/dist/Route.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Route.ts"],"sourcesContent":["import { Middleware } from './Middleware';\nimport { MiddlewareFactory } from './MiddlewareFactory';\nimport { HandlerType, HttpMethod, MiddlewareProvider } from './types';\nimport { LexerToken, Request, Response } from './types';\n\nexport class Route {\n private middlewares: MiddlewareProvider[] = [];\n private urlRegex: RegExp;\n constructor(\n public methods: HttpMethod[],\n public path: string,\n public handler: HandlerType\n ) {\n this.urlRegex = this.pathToRegex(path);\n }\n pathToRegex(path: string): RegExp {\n const lex = this.lexUrlPath(path);\n return this.tokensToRegex(lex);\n }\n\n lexUrlPath(path: string) {\n const tokens = [];\n let i = 0;\n\n while (i < path.length) {\n const char = path[i];\n\n if (char === '/') {\n tokens.push({ type: 'SLASH', value: '/' });\n i++;\n } else if (char === ':') {\n let start = i + 1;\n while (start < path.length && /[a-zA-Z0-9_]/.test(path[start])) {\n start++;\n }\n tokens.push({ type: 'PARAM', value: path.slice(i + 1, start) });\n i = start;\n } else if (char === '*') {\n let start = i + 1;\n while (start < path.length && /[a-zA-Z0-9_]/.test(path[start])) {\n start++;\n }\n tokens.push({ type: 'WILDCARD', value: path.slice(i + 1, start) });\n i = start;\n } else {\n let start = i;\n while (start < path.length && !['/', ':', '*'].includes(path[start])) {\n start++;\n }\n tokens.push({ type: 'TEXT', value: path.slice(i, start) });\n i = start;\n }\n }\n\n return tokens;\n }\n tokensToRegex(tokens: LexerToken[]) {\n const regexParts = [];\n\n for (const token of tokens) {\n if (token.type === 'SLASH') {\n regexParts.push('\\\\/');\n } else if (token.type === 'PARAM') {\n regexParts.push(`(?<${token.value}>[^\\\\/]+)`);\n } else if (token.type === 'WILDCARD') {\n regexParts.push('(.+)');\n } else if (token.type === 'TEXT') {\n regexParts.push(token.value.replace(/[-\\/\\\\^$.*+?()[\\]{}|]/g, '\\\\$&'));\n }\n }\n\n if (regexParts.length > 0 && regexParts[regexParts.length - 1] === '\\\\/') {\n regexParts[regexParts.length - 1] = '\\\\/?';\n } else {\n regexParts.push('\\\\/?');\n }\n\n return new RegExp(`^${regexParts.join('')}$`);\n }\n\n /**\n * to evaludate if request is a match for this route\n * @param request http request\n * @returns return true if route is a match for this request\n */\n test(request: Request) {\n if (this.methods.indexOf(request.method as HttpMethod) === -1) {\n return false;\n }\n const url = new URL(request.url || '/', 'http://localhost');\n return this.testPath(url.pathname);\n }\n\n testPath(pathname: string) {\n return this.urlRegex.test(pathname);\n }\n\n /**\n * returns details of the match, otherwise it returns false\n * @param request the request to match\n * @returns object cotaining details of match including matched params\n */\n match(request: Request) {\n if (this.methods.indexOf(request.method as HttpMethod) === -1) {\n return false;\n }\n\n const url = new URL(request.url || '/', 'http://localhost');\n\n const r = this.urlRegex.exec(url.pathname);\n if (!r) {\n return false;\n }\n\n return {\n url,\n params: r.groups || {},\n };\n }\n\n addMiddleware(middlewares: MiddlewareProvider | MiddlewareProvider[]) {\n this.middlewares = this.middlewares.concat(middlewares);\n return this;\n }\n\n getMiddlewares() {\n return this.middlewares;\n }\n\n callHanlder(request: Request, response: Response) {\n return this.handler(request, response);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,MAAM;AAAA,EAGjB,YACS,SACA,MACA,SACP;AAHO;AACA;AACA;AALT,SAAQ,cAAoC,CAAC;AAO3C,SAAK,WAAW,KAAK,YAAY,IAAI;AAAA,EACvC;AAAA,EACA,YAAY,MAAsB;AAChC,UAAM,MAAM,KAAK,WAAW,IAAI;AAChC,WAAO,KAAK,cAAc,GAAG;AAAA,EAC/B;AAAA,EAEA,WAAW,MAAc;AACvB,UAAM,SAAS,CAAC;AAChB,QAAI,IAAI;AAER,WAAO,IAAI,KAAK,QAAQ;AACtB,YAAM,OAAO,KAAK,CAAC;AAEnB,UAAI,SAAS,KAAK;AAChB,eAAO,KAAK,EAAE,MAAM,SAAS,OAAO,IAAI,CAAC;AACzC;AAAA,MACF,WAAW,SAAS,KAAK;AACvB,YAAI,QAAQ,IAAI;AAChB,eAAO,QAAQ,KAAK,UAAU,eAAe,KAAK,KAAK,KAAK,CAAC,GAAG;AAC9D;AAAA,QACF;AACA,eAAO,KAAK,EAAE,MAAM,SAAS,OAAO,KAAK,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC;AAC9D,YAAI;AAAA,MACN,WAAW,SAAS,KAAK;AACvB,YAAI,QAAQ,IAAI;AAChB,eAAO,QAAQ,KAAK,UAAU,eAAe,KAAK,KAAK,KAAK,CAAC,GAAG;AAC9D;AAAA,QACF;AACA,eAAO,KAAK,EAAE,MAAM,YAAY,OAAO,KAAK,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC;AACjE,YAAI;AAAA,MACN,OAAO;AACL,YAAI,QAAQ;AACZ,eAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,KAAK,KAAK,GAAG,EAAE,SAAS,KAAK,KAAK,CAAC,GAAG;AACpE;AAAA,QACF;AACA,eAAO,KAAK,EAAE,MAAM,QAAQ,OAAO,KAAK,MAAM,GAAG,KAAK,EAAE,CAAC;AACzD,YAAI;AAAA,MACN;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EACA,cAAc,QAAsB;AAClC,UAAM,aAAa,CAAC;AAEpB,eAAW,SAAS,QAAQ;AAC1B,UAAI,MAAM,SAAS,SAAS;AAC1B,mBAAW,KAAK,KAAK;AAAA,MACvB,WAAW,MAAM,SAAS,SAAS;AACjC,mBAAW,KAAK,MAAM,MAAM,KAAK,WAAW;AAAA,MAC9C,WAAW,MAAM,SAAS,YAAY;AACpC,mBAAW,KAAK,MAAM;AAAA,MACxB,WAAW,MAAM,SAAS,QAAQ;AAChC,mBAAW,KAAK,MAAM,MAAM,QAAQ,0BAA0B,MAAM,CAAC;AAAA,MACvE;AAAA,IACF;AAEA,QAAI,WAAW,SAAS,KAAK,WAAW,WAAW,SAAS,CAAC,MAAM,OAAO;AACxE,iBAAW,WAAW,SAAS,CAAC,IAAI;AAAA,IACtC,OAAO;AACL,iBAAW,KAAK,MAAM;AAAA,IACxB;AAEA,WAAO,IAAI,OAAO,IAAI,WAAW,KAAK,EAAE,CAAC,GAAG;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAK,SAAkB;AACrB,QAAI,KAAK,QAAQ,QAAQ,QAAQ,MAAoB,MAAM,IAAI;AAC7D,aAAO;AAAA,IACT;AACA,UAAM,MAAM,IAAI,IAAI,QAAQ,OAAO,KAAK,kBAAkB;AAC1D,WAAO,KAAK,SAAS,IAAI,QAAQ;AAAA,EACnC;AAAA,EAEA,SAAS,UAAkB;AACzB,WAAO,KAAK,SAAS,KAAK,QAAQ;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAkB;AACtB,QAAI,KAAK,QAAQ,QAAQ,QAAQ,MAAoB,MAAM,IAAI;AAC7D,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,IAAI,IAAI,QAAQ,OAAO,KAAK,kBAAkB;AAE1D,UAAM,IAAI,KAAK,SAAS,KAAK,IAAI,QAAQ;AACzC,QAAI,CAAC,GAAG;AACN,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,EAAE,UAAU,CAAC;AAAA,IACvB;AAAA,EACF;AAAA,EAEA,cAAc,aAAwD;AACpE,SAAK,cAAc,KAAK,YAAY,OAAO,WAAW;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY,SAAkB,UAAoB;AAChD,WAAO,KAAK,QAAQ,SAAS,QAAQ;AAAA,EACvC;AACF;","names":[]}
package/dist/Router.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { CompiledRoute } from './CompiledRoute.js';
2
- import { BaseController } from './Controller.js';
3
- import { Route } from './Route.js';
4
- import { b as HttpMethod, H as HandlerType, M as MiddlewareProvider, R as Request, a as Response } from './Middleware-C8dxjlFD.js';
5
- import 'http';
6
-
7
- declare class Router {
8
- private middlewares;
9
- routes: Route[];
10
- addRoute(methods: HttpMethod[], path: string, handler: HandlerType): Route;
11
- getMiddlewares(): MiddlewareProvider[];
12
- addController(controller: typeof BaseController): void;
13
- addGlobalMiddleware(middlewares: MiddlewareProvider | MiddlewareProvider[]): void;
14
- resolve(request: Request): Route | undefined;
15
- resolveMultiple(request: Request): Route[];
16
- getCompiledRoute(request: Request, response: Response): CompiledRoute | undefined;
17
- }
18
-
19
- export { Router };
package/dist/Router.js DELETED
@@ -1,118 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var __async = (__this, __arguments, generator) => {
30
- return new Promise((resolve, reject) => {
31
- var fulfilled = (value) => {
32
- try {
33
- step(generator.next(value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- };
38
- var rejected = (value) => {
39
- try {
40
- step(generator.throw(value));
41
- } catch (e) {
42
- reject(e);
43
- }
44
- };
45
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
- step((generator = generator.apply(__this, __arguments)).next());
47
- });
48
- };
49
- var Router_exports = {};
50
- __export(Router_exports, {
51
- Router: () => Router
52
- });
53
- module.exports = __toCommonJS(Router_exports);
54
- var import_CompiledRoute = require("./CompiledRoute");
55
- var import_Route = require("./Route");
56
- var import_path = __toESM(require("path"));
57
- class Router {
58
- constructor() {
59
- this.middlewares = [];
60
- this.routes = [];
61
- }
62
- addRoute(methods, path2, handler) {
63
- const route = new import_Route.Route(methods, path2, handler);
64
- this.routes.push(route);
65
- return route;
66
- }
67
- getMiddlewares() {
68
- return [...this.middlewares];
69
- }
70
- addController(controller) {
71
- const basePath = controller.basePath || "";
72
- for (const route of controller.routes) {
73
- const urlPath = import_path.default.join(basePath, route.path);
74
- this.addRoute(route.methods, urlPath, (req, res) => __async(this, null, function* () {
75
- const controllerInstance = controller.getInstance();
76
- return yield controllerInstance[route.handler]();
77
- })).addMiddleware([...controller.baseMiddlewares, ...route.middlewares]);
78
- }
79
- }
80
- addGlobalMiddleware(middlewares) {
81
- this.middlewares = this.middlewares.concat(middlewares);
82
- }
83
- resolve(request) {
84
- for (const route of this.routes) {
85
- if (route.test(request)) {
86
- return route;
87
- }
88
- }
89
- return void 0;
90
- }
91
- resolveMultiple(request) {
92
- const rc = [];
93
- const url = new URL(request.url || "/", "http://localhost");
94
- for (const route of this.routes) {
95
- if (route.testPath(url.pathname)) {
96
- rc.push(route);
97
- }
98
- }
99
- return rc;
100
- }
101
- getCompiledRoute(request, response) {
102
- const route = this.resolve(request);
103
- if (!route) {
104
- return void 0;
105
- }
106
- const match = route.match(request);
107
- if (!match) {
108
- return void 0;
109
- }
110
- request.params = match.params;
111
- return new import_CompiledRoute.CompiledRoute(route, request, response, this.middlewares);
112
- }
113
- }
114
- // Annotate the CommonJS export names for ESM import in node:
115
- 0 && (module.exports = {
116
- Router
117
- });
118
- //# sourceMappingURL=Router.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Router.ts"],"sourcesContent":["import { CompiledRoute } from './CompiledRoute';\nimport { BaseController } from './Controller';\nimport { Middleware } from './Middleware';\nimport { MiddlewareFactory } from './MiddlewareFactory';\nimport { Route } from './Route';\nimport { HandlerType, HttpMethod, MiddlewareProvider } from './types';\nimport { LexerToken, Request, Response } from './types';\nimport path from 'path';\n\nexport class Router {\n private middlewares: MiddlewareProvider[] = [];\n routes: Route[] = [];\n addRoute(methods: HttpMethod[], path: string, handler: HandlerType) {\n const route: Route = new Route(methods, path, handler);\n this.routes.push(route);\n return route;\n }\n\n getMiddlewares() {\n return [...this.middlewares];\n }\n\n addController(controller: typeof BaseController) {\n const basePath = controller.basePath || '';\n for (const route of controller.routes) {\n const urlPath = path.join(basePath, route.path);\n this.addRoute(route.methods, urlPath, async (req: Request, res: Response) => {\n const controllerInstance = controller.getInstance();\n // @ts-ignore\n return await controllerInstance[route.handler]();\n }).addMiddleware([...controller.baseMiddlewares, ...route.middlewares]);\n }\n }\n\n addGlobalMiddleware(middlewares: MiddlewareProvider | MiddlewareProvider[]) {\n this.middlewares = this.middlewares.concat(middlewares);\n }\n\n resolve(request: Request): Route | undefined {\n for (const route of this.routes) {\n if (route.test(request)) {\n return route;\n }\n }\n return undefined;\n }\n\n resolveMultiple(request: Request): Route[] {\n const rc: Route[] = [];\n const url = new URL(request.url || '/', 'http://localhost');\n for (const route of this.routes) {\n if (route.testPath(url.pathname)) {\n rc.push(route);\n }\n }\n return rc;\n }\n\n getCompiledRoute(request: Request, response: Response) {\n const route = this.resolve(request);\n if (!route) {\n return undefined;\n }\n const match = route.match(request);\n if (!match) {\n return undefined;\n }\n\n request.params = match.params;\n return new CompiledRoute(route, request, response, this.middlewares);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAI9B,mBAAsB;AAGtB,kBAAiB;AAEV,MAAM,OAAO;AAAA,EAAb;AACL,SAAQ,cAAoC,CAAC;AAC7C,kBAAkB,CAAC;AAAA;AAAA,EACnB,SAAS,SAAuBA,OAAc,SAAsB;AAClE,UAAM,QAAe,IAAI,mBAAM,SAASA,OAAM,OAAO;AACrD,SAAK,OAAO,KAAK,KAAK;AACtB,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB;AACf,WAAO,CAAC,GAAG,KAAK,WAAW;AAAA,EAC7B;AAAA,EAEA,cAAc,YAAmC;AAC/C,UAAM,WAAW,WAAW,YAAY;AACxC,eAAW,SAAS,WAAW,QAAQ;AACrC,YAAM,UAAU,YAAAA,QAAK,KAAK,UAAU,MAAM,IAAI;AAC9C,WAAK,SAAS,MAAM,SAAS,SAAS,CAAO,KAAc,QAAkB;AAC3E,cAAM,qBAAqB,WAAW,YAAY;AAElD,eAAO,MAAM,mBAAmB,MAAM,OAAO,EAAE;AAAA,MACjD,EAAC,EAAE,cAAc,CAAC,GAAG,WAAW,iBAAiB,GAAG,MAAM,WAAW,CAAC;AAAA,IACxE;AAAA,EACF;AAAA,EAEA,oBAAoB,aAAwD;AAC1E,SAAK,cAAc,KAAK,YAAY,OAAO,WAAW;AAAA,EACxD;AAAA,EAEA,QAAQ,SAAqC;AAC3C,eAAW,SAAS,KAAK,QAAQ;AAC/B,UAAI,MAAM,KAAK,OAAO,GAAG;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,SAA2B;AACzC,UAAM,KAAc,CAAC;AACrB,UAAM,MAAM,IAAI,IAAI,QAAQ,OAAO,KAAK,kBAAkB;AAC1D,eAAW,SAAS,KAAK,QAAQ;AAC/B,UAAI,MAAM,SAAS,IAAI,QAAQ,GAAG;AAChC,WAAG,KAAK,KAAK;AAAA,MACf;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,SAAkB,UAAoB;AACrD,UAAM,QAAQ,KAAK,QAAQ,OAAO;AAClC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,MAAM,MAAM,OAAO;AACjC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,YAAQ,SAAS,MAAM;AACvB,WAAO,IAAI,mCAAc,OAAO,SAAS,UAAU,KAAK,WAAW;AAAA,EACrE;AACF;","names":["path"]}
package/dist/helpers.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { c as Middleware, R as Request, a as Response } from './Middleware-C8dxjlFD.js';
2
- import 'http';
3
-
4
- declare function runNext(middlewares: Middleware[], req: Request, res: Response, final: (request: Request, response: Response) => Promise<void>): Promise<void>;
5
-
6
- export { runNext };
package/dist/helpers.js DELETED
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __async = (__this, __arguments, generator) => {
20
- return new Promise((resolve, reject) => {
21
- var fulfilled = (value) => {
22
- try {
23
- step(generator.next(value));
24
- } catch (e) {
25
- reject(e);
26
- }
27
- };
28
- var rejected = (value) => {
29
- try {
30
- step(generator.throw(value));
31
- } catch (e) {
32
- reject(e);
33
- }
34
- };
35
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
- step((generator = generator.apply(__this, __arguments)).next());
37
- });
38
- };
39
- var helpers_exports = {};
40
- __export(helpers_exports, {
41
- runNext: () => runNext
42
- });
43
- module.exports = __toCommonJS(helpers_exports);
44
- var import_Middleware = require("./Middleware");
45
- function runNext(middlewares, req, res, final) {
46
- return __async(this, null, function* () {
47
- let index = 0;
48
- function next() {
49
- return __async(this, null, function* () {
50
- if (index >= middlewares.length) {
51
- return yield final(req, res);
52
- }
53
- const middleware = middlewares[index++];
54
- if (middleware instanceof import_Middleware.Middleware) {
55
- yield middleware.call(req, res, next);
56
- } else if (typeof middleware === "function") {
57
- yield middleware(req, res, next);
58
- } else {
59
- throw new Error("does not know how to run middleware");
60
- }
61
- });
62
- }
63
- yield next();
64
- });
65
- }
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- runNext
69
- });
70
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { Middleware } from './Middleware';\nimport { Request, Response } from './types';\n\nexport async function runNext(\n middlewares: Middleware[],\n req: Request,\n res: Response,\n final: (request: Request, response: Response) => Promise<void>\n) {\n let index = 0;\n\n async function next() {\n if (index >= middlewares.length) {\n return await final(req, res);\n }\n\n const middleware: Middleware | any = middlewares[index++];\n\n if (middleware instanceof Middleware) {\n await middleware.call(req, res, next);\n } else if (typeof middleware === 'function') {\n await middleware(req, res, next);\n } else {\n throw new Error('does not know how to run middleware');\n }\n }\n\n await next();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA2B;AAG3B,SAAsB,QACpB,aACA,KACA,KACA,OACA;AAAA;AACA,QAAI,QAAQ;AAEZ,aAAe,OAAO;AAAA;AACpB,YAAI,SAAS,YAAY,QAAQ;AAC/B,iBAAO,MAAM,MAAM,KAAK,GAAG;AAAA,QAC7B;AAEA,cAAM,aAA+B,YAAY,OAAO;AAExD,YAAI,sBAAsB,8BAAY;AACpC,gBAAM,WAAW,KAAK,KAAK,KAAK,IAAI;AAAA,QACtC,WAAW,OAAO,eAAe,YAAY;AAC3C,gBAAM,WAAW,KAAK,KAAK,IAAI;AAAA,QACjC,OAAO;AACL,gBAAM,IAAI,MAAM,qCAAqC;AAAA,QACvD;AAAA,MACF;AAAA;AAEA,UAAM,KAAK;AAAA,EACb;AAAA;","names":[]}
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { C as ControllerDecoratorOptions, H as HandlerType, b as HttpMethod, L as LexerToken, c as Middleware, M as MiddlewareProvider, R as Request, a as Response } from './Middleware-C8dxjlFD.js';
2
- export { CompiledRoute } from './CompiledRoute.js';
3
- export { BaseController, Controller, Delete, Get, Options, Patch, Post, Put, createParamDecorator } from './Controller.js';
4
- export { Route } from './Route.js';
5
- export { Router } from './Router.js';
6
- export { MiddlewareFactory } from './MiddlewareFactory.js';
7
- export { runNext } from './helpers.js';
8
- import 'http';
package/dist/types.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import 'http';
2
- export { C as ControllerDecoratorOptions, H as HandlerType, b as HttpMethod, L as LexerToken, M as MiddlewareProvider, R as Request, a as Response } from './Middleware-C8dxjlFD.js';
package/dist/types.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
17
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { IncomingMessage, ServerResponse } from 'http';\nimport { Middleware } from './Middleware';\n\nexport type Request = IncomingMessage & {\n params: any;\n method: HttpMethod;\n headers?: Record<string, string>;\n body?: any;\n raw_body?: any;\n files?: any;\n query?: Record<string, string>;\n};\n\nexport type Response = ServerResponse;\n\nexport type LexerToken = {\n type: string;\n value: string;\n};\n\nexport type HandlerType = (\n req: Request,\n res: Response,\n next?: (() => any) | undefined\n) => Promise<any> | any;\n\nexport type ControllerDecoratorOptions = {\n middlewares?: MiddlewareProvider[];\n};\n\nexport type MiddlewareProvider =\n | typeof Middleware\n | Middleware\n | ((request: Request, response: Response, next: () => Promise<void>) => Promise<void>);\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}