@bool-ts/core 1.3.1 → 1.4.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.
Files changed (68) hide show
  1. package/.prettierrc +11 -0
  2. package/LICENSE +21 -21
  3. package/__test/controller.ts +66 -79
  4. package/__test/index.ts +8 -11
  5. package/__test/interfaces.ts +7 -7
  6. package/__test/module.ts +16 -17
  7. package/__test/repository.ts +16 -16
  8. package/__test/service.ts +20 -20
  9. package/bun.lockb +0 -0
  10. package/dist/decorators/arguments.d.ts +31 -0
  11. package/dist/decorators/arguments.js +67 -0
  12. package/dist/decorators/controller.d.ts +2 -2
  13. package/dist/decorators/controller.js +6 -10
  14. package/dist/decorators/http.d.ts +1 -1
  15. package/dist/decorators/http.js +16 -101
  16. package/dist/decorators/index.d.ts +1 -0
  17. package/dist/decorators/index.js +7 -26
  18. package/dist/decorators/inject.js +5 -9
  19. package/dist/decorators/injectable.d.ts +2 -2
  20. package/dist/decorators/injectable.js +4 -8
  21. package/dist/decorators/module.d.ts +4 -2
  22. package/dist/decorators/module.js +4 -8
  23. package/dist/decorators/zodSchema.d.ts +1 -1
  24. package/dist/decorators/zodSchema.js +5 -8
  25. package/dist/entities/index.d.ts +3 -0
  26. package/dist/entities/index.js +3 -0
  27. package/dist/entities/route.d.ts +101 -0
  28. package/dist/entities/route.js +257 -0
  29. package/dist/entities/router.d.ts +10 -0
  30. package/dist/entities/router.js +25 -0
  31. package/dist/entities/routerGroup.d.ts +14 -0
  32. package/dist/entities/routerGroup.js +24 -0
  33. package/dist/hooks/factory.d.ts +12 -12
  34. package/dist/hooks/factory.js +180 -151
  35. package/dist/hooks/index.js +2 -7
  36. package/dist/hooks/injector.js +7 -10
  37. package/dist/http/clientError.d.ts +1 -1
  38. package/dist/http/clientError.js +3 -7
  39. package/dist/http/index.d.ts +12 -2
  40. package/dist/http/index.js +34 -73
  41. package/dist/http/serverError.js +3 -7
  42. package/dist/index.js +5 -21
  43. package/dist/interfaces/index.js +1 -3
  44. package/dist/ultils/asyncFunction.js +1 -4
  45. package/dist/ultils/index.js +1 -17
  46. package/package.json +30 -33
  47. package/src/decorators/arguments.ts +128 -0
  48. package/src/decorators/controller.ts +14 -18
  49. package/src/decorators/http.ts +81 -191
  50. package/src/decorators/index.ts +7 -6
  51. package/src/decorators/inject.ts +13 -19
  52. package/src/decorators/injectable.ts +11 -12
  53. package/src/decorators/module.ts +21 -22
  54. package/src/decorators/zodSchema.ts +20 -27
  55. package/src/entities/index.ts +3 -0
  56. package/src/entities/route.ts +328 -0
  57. package/src/entities/router.ts +35 -0
  58. package/src/entities/routerGroup.ts +34 -0
  59. package/src/hooks/factory.ts +285 -205
  60. package/src/hooks/index.ts +2 -2
  61. package/src/hooks/injector.ts +43 -43
  62. package/src/http/clientError.ts +45 -56
  63. package/src/http/index.ts +63 -72
  64. package/src/http/serverError.ts +38 -38
  65. package/src/index.ts +6 -6
  66. package/src/interfaces/index.ts +3 -3
  67. package/test.http +30 -28
  68. package/tsconfig.json +107 -109
@@ -1,26 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.controllerRouteZodSchemaKey = exports.ZodSchema = exports.controllerRoutesKey = exports.Options = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.moduleKey = exports.Module = exports.injectableKey = exports.Injectable = exports.injectKey = exports.Inject = exports.controllerKey = exports.Controller = void 0;
4
- var controller_1 = require("./controller");
5
- Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return controller_1.Controller; } });
6
- Object.defineProperty(exports, "controllerKey", { enumerable: true, get: function () { return controller_1.controllerKey; } });
7
- var inject_1 = require("./inject");
8
- Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return inject_1.Inject; } });
9
- Object.defineProperty(exports, "injectKey", { enumerable: true, get: function () { return inject_1.injectKey; } });
10
- var injectable_1 = require("./injectable");
11
- Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_1.Injectable; } });
12
- Object.defineProperty(exports, "injectableKey", { enumerable: true, get: function () { return injectable_1.injectableKey; } });
13
- var module_1 = require("./module");
14
- Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_1.Module; } });
15
- Object.defineProperty(exports, "moduleKey", { enumerable: true, get: function () { return module_1.moduleKey; } });
16
- var http_1 = require("./http");
17
- Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return http_1.Get; } });
18
- Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return http_1.Post; } });
19
- Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return http_1.Put; } });
20
- Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return http_1.Patch; } });
21
- Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return http_1.Delete; } });
22
- Object.defineProperty(exports, "Options", { enumerable: true, get: function () { return http_1.Options; } });
23
- Object.defineProperty(exports, "controllerRoutesKey", { enumerable: true, get: function () { return http_1.controllerRoutesKey; } });
24
- var zodSchema_1 = require("./zodSchema");
25
- Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zodSchema_1.ZodSchema; } });
26
- Object.defineProperty(exports, "controllerRouteZodSchemaKey", { enumerable: true, get: function () { return zodSchema_1.controllerRouteZodSchemaKey; } });
1
+ export { Headers, Body, Params, Query, EArgumentTypes } from "./arguments";
2
+ export { Controller, controllerKey } from "./controller";
3
+ export { Inject, injectKey } from "./inject";
4
+ export { Injectable, injectableKey } from "./injectable";
5
+ export { Module, moduleKey } from "./module";
6
+ export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey } from "./http";
7
+ export { ZodSchema, controllerRouteZodSchemaKey } from "./zodSchema";
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Inject = exports.injectKey = void 0;
4
- exports.injectKey = "design:paramtypes";
5
- const Inject = (classDefinition) => {
1
+ export const injectKey = "design:paramtypes";
2
+ export const Inject = (classDefinition) => {
6
3
  return (target, methodName, parameterIndex) => {
7
- const designParameterTypes = Reflect.getMetadata(exports.injectKey, target) || [];
4
+ const designParameterTypes = Reflect.getMetadata(injectKey, target) || [];
8
5
  designParameterTypes[parameterIndex] = classDefinition;
9
- Reflect.defineMetadata(exports.injectKey, designParameterTypes, target);
6
+ Reflect.defineMetadata(injectKey, designParameterTypes, target);
10
7
  };
11
8
  };
12
- exports.Inject = Inject;
13
- exports.default = exports.Inject;
9
+ export default Inject;
@@ -1,3 +1,3 @@
1
- export declare const injectableKey = "__bool:injectable__";
2
- export declare const Injectable: () => <T extends Object>(target: T, context?: ClassDecoratorContext) => T;
1
+ export declare const injectableKey: unique symbol;
2
+ export declare const Injectable: () => <T extends Object>(target: T) => T;
3
3
  export default Injectable;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Injectable = exports.injectableKey = void 0;
4
- exports.injectableKey = "__bool:injectable__";
5
- const Injectable = () => (target, context) => {
6
- Reflect.defineMetadata(exports.injectableKey, undefined, target);
1
+ export const injectableKey = Symbol.for("__bool:injectable__");
2
+ export const Injectable = () => (target) => {
3
+ Reflect.defineMetadata(injectableKey, undefined, target);
7
4
  return target;
8
5
  };
9
- exports.Injectable = Injectable;
10
- exports.default = exports.Injectable;
6
+ export default Injectable;
@@ -5,6 +5,8 @@ export type TModuleOptions = Partial<{
5
5
  allowOrigins: string | Array<string>;
6
6
  allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
7
7
  }> | undefined;
8
- export declare const moduleKey = "__bool:module__";
9
- export declare const Module: (args?: TModuleOptions) => <T extends new (...args: any[]) => {}>(target: T, context?: ClassDecoratorContext) => T;
8
+ export declare const moduleKey: unique symbol;
9
+ export declare const Module: (args?: TModuleOptions) => <T extends {
10
+ new (...args: any[]): {};
11
+ }>(target: T) => T;
10
12
  export default Module;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Module = exports.moduleKey = void 0;
4
- exports.moduleKey = "__bool:module__";
5
- const Module = (args) => (target, context) => {
6
- Reflect.defineMetadata(exports.moduleKey, args, target);
1
+ export const moduleKey = Symbol.for("__bool:module__");
2
+ export const Module = (args) => (target) => {
3
+ Reflect.defineMetadata(moduleKey, args, target);
7
4
  return target;
8
5
  };
9
- exports.Module = Module;
10
- exports.default = exports.Module;
6
+ export default Module;
@@ -1,3 +1,3 @@
1
1
  import * as Zod from "zod";
2
- export declare const controllerRouteZodSchemaKey = "__bool:controller.route.zodSchema__";
2
+ export declare const controllerRouteZodSchemaKey: unique symbol;
3
3
  export declare const ZodSchema: (schema: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZodSchema = exports.controllerRouteZodSchemaKey = void 0;
4
- exports.controllerRouteZodSchemaKey = "__bool:controller.route.zodSchema__";
5
- const ZodSchema = (schema) => {
1
+ import * as Zod from "zod";
2
+ export const controllerRouteZodSchemaKey = Symbol.for("__bool:controller.route.zodSchema__");
3
+ export const ZodSchema = (schema) => {
6
4
  return (target, methodName, parameterIndex) => {
7
5
  if (!methodName) {
8
6
  return;
9
7
  }
10
- const zodSchemasMetadata = Reflect.getOwnMetadata(exports.controllerRouteZodSchemaKey, target.constructor, methodName) || {};
8
+ const zodSchemasMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName) || {};
11
9
  zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
12
10
  index: parameterIndex,
13
11
  schema: schema
14
12
  };
15
- Reflect.defineMetadata(exports.controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
13
+ Reflect.defineMetadata(controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
16
14
  };
17
15
  };
18
- exports.ZodSchema = ZodSchema;
@@ -0,0 +1,3 @@
1
+ export { Route } from "./route";
2
+ export { Router } from "./router";
3
+ export { RouterGroup } from "./routerGroup";
@@ -0,0 +1,3 @@
1
+ export { Route } from "./route";
2
+ export { Router } from "./router";
3
+ export { RouterGroup } from "./routerGroup";
@@ -0,0 +1,101 @@
1
+ import type { THttpMethods } from "../http";
2
+ type THandler<T = unknown> = Required<{
3
+ constructor: new (...args: Array<any>) => T;
4
+ funcName: string | symbol;
5
+ func: (...args: Array<any>) => unknown;
6
+ }>;
7
+ export declare class Route {
8
+ static rootPattern: string;
9
+ readonly alias: string;
10
+ private _map;
11
+ constructor(alias: string);
12
+ test(pathname: string, method: keyof THttpMethods): Readonly<{
13
+ params: Record<string, string>;
14
+ handlers: Array<THandler>;
15
+ }> | false | undefined;
16
+ /**
17
+ *
18
+ */
19
+ isMatch(pathname: string, method: keyof THttpMethods): boolean | undefined;
20
+ /**
21
+ *
22
+ * @param handlers
23
+ * @returns
24
+ */
25
+ get(...handlers: Array<THandler>): this;
26
+ /**
27
+ *
28
+ * @param handlers
29
+ * @returns
30
+ */
31
+ post(...handlers: Array<THandler>): this;
32
+ /**
33
+ *
34
+ * @param handlers
35
+ * @returns
36
+ */
37
+ put(...handlers: Array<THandler>): this;
38
+ /**
39
+ *
40
+ * @param handlers
41
+ * @returns
42
+ */
43
+ delete(...handlers: Array<THandler>): this;
44
+ /**
45
+ *
46
+ * @param handlers
47
+ * @returns
48
+ */
49
+ connect(...handlers: Array<THandler>): this | Map<keyof THttpMethods, Required<{
50
+ constructor: new (...args: Array<any>) => unknown;
51
+ funcName: string | symbol;
52
+ func: (...args: Array<any>) => unknown;
53
+ }>[]>;
54
+ /**
55
+ *
56
+ * @param handlers
57
+ * @returns
58
+ */
59
+ options(...handlers: Array<THandler>): this | Map<keyof THttpMethods, Required<{
60
+ constructor: new (...args: Array<any>) => unknown;
61
+ funcName: string | symbol;
62
+ func: (...args: Array<any>) => unknown;
63
+ }>[]>;
64
+ /**
65
+ *
66
+ * @param handlers
67
+ * @returns
68
+ */
69
+ trace(...handlers: Array<THandler>): this | Map<keyof THttpMethods, Required<{
70
+ constructor: new (...args: Array<any>) => unknown;
71
+ funcName: string | symbol;
72
+ func: (...args: Array<any>) => unknown;
73
+ }>[]>;
74
+ /**
75
+ *
76
+ * @param handlers
77
+ * @returns
78
+ */
79
+ patch(...handlers: Array<THandler>): this | Map<keyof THttpMethods, Required<{
80
+ constructor: new (...args: Array<any>) => unknown;
81
+ funcName: string | symbol;
82
+ func: (...args: Array<any>) => unknown;
83
+ }>[]>;
84
+ /**
85
+ *
86
+ * @param handlers
87
+ * @returns
88
+ */
89
+ private _thinAlias;
90
+ /**
91
+ * Internal get fullpath after check regular expression
92
+ * @returns
93
+ */
94
+ get _fullPath(): string;
95
+ /**
96
+ * Internal get filterd path after check regular expression
97
+ * @returns
98
+ */
99
+ get _filteredPath(): string;
100
+ }
101
+ export default Route;
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ export class Route {
3
+ static rootPattern = ":([a-z0-9A-Z_.-]{1,})";
4
+ alias;
5
+ _map = new Map();
6
+ constructor(alias) {
7
+ this.alias = this._thinAlias(alias);
8
+ }
9
+ test(pathname, method) {
10
+ try {
11
+ const handlers = this._map.get(method);
12
+ const aliasSplitted = this.alias.split("/");
13
+ const currentPathNameSplitted = this._thinAlias(pathname).split("/");
14
+ if (!handlers) {
15
+ return undefined;
16
+ }
17
+ // Compare splitted length
18
+ if (aliasSplitted.length !== currentPathNameSplitted.length) {
19
+ return undefined;
20
+ }
21
+ const parameters = Object();
22
+ for (let index = 0; index < aliasSplitted.length; index++) {
23
+ const aliasPart = aliasSplitted[index];
24
+ const pathnamePart = currentPathNameSplitted[index];
25
+ // Check pathmane path match a dynamic syntax, if no match => start compare equal or not
26
+ if (!new RegExp(Route.rootPattern, "g").test(aliasPart)) {
27
+ if (aliasPart !== pathnamePart)
28
+ return undefined;
29
+ }
30
+ else {
31
+ let isFailed = false;
32
+ aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
33
+ if (offset === 0) {
34
+ Object.assign(parameters, {
35
+ [key]: pathnamePart
36
+ });
37
+ }
38
+ return match;
39
+ });
40
+ if (isFailed) {
41
+ console.log(3, "isFailed", isFailed);
42
+ return undefined;
43
+ }
44
+ }
45
+ continue;
46
+ }
47
+ return Object.freeze({
48
+ params: parameters,
49
+ handlers: handlers
50
+ });
51
+ }
52
+ catch (err) {
53
+ console.error(err);
54
+ return false;
55
+ }
56
+ }
57
+ /**
58
+ *
59
+ */
60
+ isMatch(pathname, method) {
61
+ try {
62
+ const handlers = this._map.get(method);
63
+ if (!handlers) {
64
+ return undefined;
65
+ }
66
+ const aliasSplitted = this.alias.split("/");
67
+ const currentPathNameSplitted = this._thinAlias(pathname).split("/");
68
+ // Compare splitted length
69
+ if (aliasSplitted.length !== currentPathNameSplitted.length) {
70
+ return false;
71
+ }
72
+ const parameters = Object();
73
+ for (let index = 0; index < aliasSplitted.length; index++) {
74
+ const aliasPart = aliasSplitted[index];
75
+ const pathnamePart = currentPathNameSplitted[index];
76
+ // Check pathmane path match a dynamic syntax, if no match => start compare equal or not
77
+ if (!new RegExp(Route.rootPattern, "g").test(aliasPart)) {
78
+ if (aliasPart !== pathnamePart) {
79
+ return false;
80
+ }
81
+ }
82
+ else {
83
+ let isFailed = false;
84
+ aliasPart.replace(new RegExp(Route.rootPattern, "g"), (subString, key, value) => {
85
+ if (!new RegExp(value, "g").test(pathnamePart)) {
86
+ isFailed = true;
87
+ }
88
+ else {
89
+ Object.assign(parameters, {
90
+ [key]: pathnamePart
91
+ });
92
+ }
93
+ return "";
94
+ });
95
+ if (isFailed) {
96
+ return false;
97
+ }
98
+ }
99
+ continue;
100
+ }
101
+ return true;
102
+ }
103
+ catch (err) {
104
+ console.error(err);
105
+ return undefined;
106
+ }
107
+ }
108
+ /**
109
+ *
110
+ * @param handlers
111
+ * @returns
112
+ */
113
+ get(...handlers) {
114
+ const currentHandlers = this._map.get("GET");
115
+ if (!currentHandlers) {
116
+ this._map.set("GET", handlers);
117
+ }
118
+ return this;
119
+ }
120
+ /**
121
+ *
122
+ * @param handlers
123
+ * @returns
124
+ */
125
+ post(...handlers) {
126
+ const currentHandlers = this._map.get("POST");
127
+ if (!currentHandlers) {
128
+ this._map.set("POST", handlers);
129
+ }
130
+ return this;
131
+ }
132
+ /**
133
+ *
134
+ * @param handlers
135
+ * @returns
136
+ */
137
+ put(...handlers) {
138
+ const currentHandlers = this._map.get("PUT");
139
+ if (!currentHandlers) {
140
+ this._map.set("PUT", handlers);
141
+ }
142
+ return this;
143
+ }
144
+ /**
145
+ *
146
+ * @param handlers
147
+ * @returns
148
+ */
149
+ delete(...handlers) {
150
+ const currentHandlers = this._map.get("DELETE");
151
+ if (!currentHandlers) {
152
+ this._map.set("DELETE", handlers);
153
+ }
154
+ return this;
155
+ }
156
+ /**
157
+ *
158
+ * @param handlers
159
+ * @returns
160
+ */
161
+ connect(...handlers) {
162
+ const currentHandlers = this._map.get("CONNECT");
163
+ if (!currentHandlers) {
164
+ return this._map.set("CONNECT", handlers);
165
+ }
166
+ return this;
167
+ }
168
+ /**
169
+ *
170
+ * @param handlers
171
+ * @returns
172
+ */
173
+ options(...handlers) {
174
+ const currentHandlers = this._map.get("OPTIONS");
175
+ if (!currentHandlers) {
176
+ return this._map.set("OPTIONS", handlers);
177
+ }
178
+ return this;
179
+ }
180
+ /**
181
+ *
182
+ * @param handlers
183
+ * @returns
184
+ */
185
+ trace(...handlers) {
186
+ const currentHandlers = this._map.get("TRACE");
187
+ if (!currentHandlers) {
188
+ return this._map.set("TRACE", handlers);
189
+ }
190
+ return this;
191
+ }
192
+ /**
193
+ *
194
+ * @param handlers
195
+ * @returns
196
+ */
197
+ patch(...handlers) {
198
+ const currentHandlers = this._map.get("PATCH");
199
+ if (!currentHandlers) {
200
+ return this._map.set("PATCH", handlers);
201
+ }
202
+ return this;
203
+ }
204
+ /**
205
+ *
206
+ * @param handlers
207
+ * @returns
208
+ */
209
+ _thinAlias(alias) {
210
+ return alias.replace(new RegExp("[/]{2,}", "g"), "/").replace(new RegExp("^[/]|[/]$", "g"), "");
211
+ }
212
+ /**
213
+ * Internal get fullpath after check regular expression
214
+ * @returns
215
+ */
216
+ get _fullPath() {
217
+ // Split path to start filter
218
+ const pathSplited = this.alias.split("/");
219
+ const blockFiltered = pathSplited.map((value, index) => {
220
+ // Initialize full parameter regex to validate
221
+ let validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})(\\(.*?\\))", "g");
222
+ if (!validateReg.test(value)) {
223
+ // Initialize key parameter regex to validate
224
+ validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})", "g");
225
+ if (!validateReg.test(value)) {
226
+ return value;
227
+ }
228
+ return value.replace(validateReg, (value, index) => `${value}(.*?)`);
229
+ }
230
+ return value;
231
+ });
232
+ return blockFiltered.join("/");
233
+ }
234
+ /**
235
+ * Internal get filterd path after check regular expression
236
+ * @returns
237
+ */
238
+ get _filteredPath() {
239
+ // Split path to start filter
240
+ const pathSplited = this.alias.split("/");
241
+ //
242
+ const blockFiltered = pathSplited.map((value, index) => {
243
+ let validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})((.*?))", "g");
244
+ if (!validateReg.test(value)) {
245
+ // Initialize key parameter regex to validate
246
+ validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})", "g");
247
+ if (!validateReg.test(value)) {
248
+ return value;
249
+ }
250
+ return value.replace(validateReg, (value, index) => "(.*?)");
251
+ }
252
+ return value.replace(validateReg, (subString, arg_01, arg_02) => arg_02);
253
+ });
254
+ return blockFiltered.join("/");
255
+ }
256
+ }
257
+ export default Route;
@@ -0,0 +1,10 @@
1
+ import Route from "./route";
2
+ export declare class Router {
3
+ readonly alias: string;
4
+ private _routes;
5
+ constructor(alias: string);
6
+ route(alias: string): Route;
7
+ private _thinAlias;
8
+ get routes(): Map<string, Route>;
9
+ }
10
+ export default Router;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ import Route from "./route";
3
+ export class Router {
4
+ alias;
5
+ _routes = new Map();
6
+ constructor(alias) {
7
+ this.alias = this._thinAlias(alias);
8
+ }
9
+ route(alias) {
10
+ const thinAlias = this._thinAlias(`${this.alias}/${alias}`);
11
+ const route = this._routes.get(thinAlias);
12
+ const newRoute = !route ? new Route(`${this.alias}/${alias}`) : route;
13
+ if (!route) {
14
+ this._routes.set(thinAlias, newRoute);
15
+ }
16
+ return newRoute;
17
+ }
18
+ _thinAlias(alias) {
19
+ return alias.replace(new RegExp("[/]{2,}", "g"), "/").replace(new RegExp("^[/]|[/]$", "g"), "");
20
+ }
21
+ get routes() {
22
+ return this._routes;
23
+ }
24
+ }
25
+ export default Router;
@@ -0,0 +1,14 @@
1
+ import type { THttpMethods } from "../http";
2
+ import type { Router } from "./router";
3
+ export declare class RouterGroup {
4
+ private _routers;
5
+ add(...routers: Array<Router>): this;
6
+ find(pathame: string, method: keyof THttpMethods): Readonly<{
7
+ params: Record<string, string>;
8
+ handlers: Array<Required<{
9
+ constructor: new (...args: Array<any>) => unknown;
10
+ funcName: string | symbol;
11
+ func: (...args: Array<any>) => unknown;
12
+ }>>;
13
+ }> | undefined;
14
+ }
@@ -0,0 +1,24 @@
1
+ export class RouterGroup {
2
+ _routers = new Map();
3
+ add(...routers) {
4
+ for (let i = 0; i < routers.length; i++) {
5
+ if (this._routers.has(routers[i].alias)) {
6
+ continue;
7
+ }
8
+ this._routers.set(routers[i].alias, routers[i]);
9
+ }
10
+ return this;
11
+ }
12
+ find(pathame, method) {
13
+ for (const router of [...this._routers.values()]) {
14
+ for (const route of router.routes.values()) {
15
+ const result = route.test(pathame, method);
16
+ if (!result) {
17
+ continue;
18
+ }
19
+ return result;
20
+ }
21
+ }
22
+ return undefined;
23
+ }
24
+ }
@@ -1,19 +1,19 @@
1
- import "reflect-metadata";
2
1
  import "colors";
3
- export type TBoolFactoryOptions = Partial<{
2
+ import "reflect-metadata";
3
+ import Qs from "qs";
4
+ import * as Zod from "zod";
5
+ import { RouterGroup } from "../entities";
6
+ export type TBoolFactoryOptions = Required<{
7
+ port: number;
8
+ }> & Partial<{
9
+ prefix: string;
4
10
  debug: boolean;
5
11
  log: Partial<{
6
12
  methods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
7
13
  }>;
8
- queryParser: Partial<{
9
- depth: 10;
10
- arrayLimit: 50;
11
- }>;
12
- prefix: string;
14
+ queryParser: Parameters<typeof Qs.parse>[1];
13
15
  }>;
14
- /**
15
- *
16
- * @param target
17
- */
18
- export declare const BoolFactory: (target: new (...args: any[]) => unknown, options?: TBoolFactoryOptions) => import("express-serve-static-core").Express;
16
+ export declare const controllerCreator: (controllerConstructor: new (...args: any[]) => unknown, group: RouterGroup) => RouterGroup;
17
+ export declare const controllerActionArgumentsResolution: (data: unknown, zodSchema: Zod.Schema, argumentIndex: number, funcName: string | symbol) => Promise<any>;
18
+ export declare const BoolFactory: (target: new (...args: any[]) => unknown, options: TBoolFactoryOptions) => void;
19
19
  export default BoolFactory;