@avleon/core 0.0.27 → 0.0.29

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 (77) hide show
  1. package/README.md +601 -561
  2. package/dist/application.js +1 -1
  3. package/dist/cache.d.ts +1 -1
  4. package/dist/cache.js +2 -2
  5. package/dist/collection.d.ts +25 -32
  6. package/dist/collection.js +50 -6
  7. package/dist/collection.test.d.ts +1 -0
  8. package/dist/collection.test.js +59 -0
  9. package/dist/config.d.ts +2 -0
  10. package/dist/config.js +30 -5
  11. package/dist/config.test.d.ts +1 -0
  12. package/dist/config.test.js +40 -0
  13. package/dist/controller.js +2 -2
  14. package/dist/environment-variables.js +42 -5
  15. package/dist/event-dispatcher.d.ts +23 -0
  16. package/dist/event-dispatcher.js +102 -0
  17. package/dist/event-subscriber.d.ts +15 -0
  18. package/dist/event-subscriber.js +96 -0
  19. package/dist/exceptions/http-exceptions.js +1 -1
  20. package/dist/exceptions/index.d.ts +1 -1
  21. package/dist/exceptions/system-exception.js +3 -1
  22. package/dist/file-storage.js +1 -1
  23. package/dist/helpers.js +1 -1
  24. package/dist/icore.d.ts +5 -0
  25. package/dist/icore.js +53 -18
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +6 -1
  28. package/dist/utils/index.d.ts +2 -2
  29. package/dist/utils/optional-require.js +2 -2
  30. package/dist/validation.d.ts +1 -1
  31. package/dist/websocket.d.ts +7 -0
  32. package/dist/websocket.js +20 -0
  33. package/dist/websocket.test.d.ts +0 -0
  34. package/dist/websocket.test.js +1 -0
  35. package/package.json +37 -6
  36. package/src/application.ts +104 -125
  37. package/src/authentication.ts +16 -16
  38. package/src/cache.ts +91 -91
  39. package/src/collection.test.ts +71 -0
  40. package/src/collection.ts +344 -254
  41. package/src/config.test.ts +35 -0
  42. package/src/config.ts +85 -42
  43. package/src/constants.ts +1 -1
  44. package/src/container.ts +54 -54
  45. package/src/controller.ts +125 -127
  46. package/src/decorators.ts +27 -27
  47. package/src/environment-variables.ts +53 -46
  48. package/src/event-dispatcher.ts +100 -0
  49. package/src/event-subscriber.ts +79 -0
  50. package/src/exceptions/http-exceptions.ts +86 -86
  51. package/src/exceptions/index.ts +1 -1
  52. package/src/exceptions/system-exception.ts +35 -34
  53. package/src/file-storage.ts +206 -206
  54. package/src/helpers.ts +324 -328
  55. package/src/icore.ts +1106 -1084
  56. package/src/index.ts +32 -30
  57. package/src/interfaces/avleon-application.ts +32 -40
  58. package/src/logger.ts +72 -72
  59. package/src/map-types.ts +159 -159
  60. package/src/middleware.ts +121 -98
  61. package/src/multipart.ts +116 -116
  62. package/src/openapi.ts +372 -372
  63. package/src/params.ts +111 -111
  64. package/src/queue.ts +126 -126
  65. package/src/response.ts +74 -74
  66. package/src/results.ts +30 -30
  67. package/src/route-methods.ts +186 -186
  68. package/src/swagger-schema.ts +213 -213
  69. package/src/testing.ts +220 -220
  70. package/src/types/app-builder.interface.ts +18 -19
  71. package/src/types/application.interface.ts +7 -9
  72. package/src/utils/hash.ts +8 -5
  73. package/src/utils/index.ts +2 -2
  74. package/src/utils/optional-require.ts +50 -50
  75. package/src/validation.ts +160 -156
  76. package/src/validator-extend.ts +25 -25
  77. package/src/websocket.ts +47 -0
@@ -1,186 +1,186 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
-
8
- import { CONTROLLER_META_KEY, ROUTE_META_KEY } from "./container";
9
- import { OpenApiOptions } from "./openapi";
10
- import { HttpResponse } from "./response";
11
- import { Results } from "./results";
12
- export type RouteMethods =
13
- | "GET"
14
- | "POST"
15
- | "PUT"
16
- | "PATCH"
17
- | "DELETE"
18
- | "OPTIONS"
19
- | "ALL";
20
-
21
- const schema: OpenApiOptions = {
22
- tags: ["hello"],
23
- };
24
-
25
- /**
26
- * Options for defining a route's method and metadata.
27
- */
28
- export type RouteMethodOptions = {
29
- /**
30
- * HTTP method for the route (e.g., GET, POST, PUT, DELETE).
31
- */
32
- method?: RouteMethods;
33
-
34
- /**
35
- * The path or endpoint for the route (e.g., "/users/:id").
36
- */
37
- path?: string;
38
-
39
- /**
40
- * OpenAPI metadata for the route, including summary and description.
41
- */
42
- openapi?: OpenApiOptions;
43
-
44
- /**
45
- * Name of the route.
46
- *
47
- * @description If Swagger is enabled in the project, this will appear as a tag in the generated documentation.
48
- */
49
- name?: string;
50
- };
51
-
52
- // Overloads
53
-
54
- // Implementation
55
- export function createRouteDecorator(
56
- method: RouteMethods = "GET",
57
- ): (
58
- pathOrOptions: string | RouteMethodOptions,
59
- maybeOptions?: RouteMethodOptions,
60
- ) => MethodDecorator {
61
- return function (
62
- pathOrOptions: string | RouteMethodOptions,
63
- maybeOptions?: RouteMethodOptions,
64
- ): MethodDecorator {
65
- return function (
66
- target,
67
- propertyKey: string | symbol,
68
- descriptor: PropertyDescriptor,
69
- ) {
70
- let path = "/";
71
- let options: RouteMethodOptions = {};
72
-
73
- if (typeof pathOrOptions === "string") {
74
- path = pathOrOptions;
75
- options = maybeOptions || {};
76
- } else if (typeof pathOrOptions === "object") {
77
- options = pathOrOptions;
78
- path = options.name || "/";
79
- }
80
-
81
- // Define metadata
82
- Reflect.defineMetadata("route:path", path, target, propertyKey);
83
- Reflect.defineMetadata(
84
- "route:method",
85
- method || "GET",
86
- target,
87
- propertyKey,
88
- );
89
- Reflect.getMetadata(CONTROLLER_META_KEY, target.constructor);
90
- Reflect.defineMetadata(
91
- ROUTE_META_KEY,
92
- { ...options, method, path, controller: target.constructor.name },
93
- target,
94
- propertyKey,
95
- );
96
-
97
- if (options) {
98
- Reflect.defineMetadata("route:options", options, target, propertyKey);
99
- }
100
- };
101
- };
102
- }
103
-
104
- // Usage Example
105
- /**
106
- * @description HTTP Get method
107
- * @param {string} path
108
- */
109
- export function Get(path?: string): MethodDecorator;
110
- export function Get(path: string | RouteMethodOptions): MethodDecorator;
111
- /**
112
- * @description HTTP Get method
113
- * @param {string} path
114
- * @param {RouteMethodOptions} options
115
- */
116
- export function Get(path: string, options: RouteMethodOptions): MethodDecorator;
117
- export function Get(
118
- path?: string | RouteMethodOptions,
119
- options?: RouteMethodOptions,
120
- ) {
121
- const parsedPath =
122
- !path && !options ? "/" : (path as string | RouteMethodOptions);
123
- if (options) {
124
- return createRouteDecorator("GET")(parsedPath, options);
125
- } else {
126
- return createRouteDecorator("GET")(parsedPath);
127
- }
128
- }
129
-
130
- export function Post(path?: string): MethodDecorator;
131
- export function Post(path: string | RouteMethodOptions): MethodDecorator;
132
- export function Post(
133
- path: string,
134
- options: RouteMethodOptions,
135
- ): MethodDecorator;
136
- export function Post(
137
- path?: string | RouteMethodOptions,
138
- options?: RouteMethodOptions,
139
- ) {
140
- const parsedPath =
141
- !path && !options ? "/" : (path as string | RouteMethodOptions);
142
- if (options) {
143
- return createRouteDecorator("POST")(parsedPath, options);
144
- } else {
145
- return createRouteDecorator("POST")(parsedPath);
146
- }
147
- }
148
-
149
- export function Put(path?: string): MethodDecorator;
150
- export function Put(path: string | RouteMethodOptions): MethodDecorator;
151
- export function Put(path: string, options: RouteMethodOptions): MethodDecorator;
152
- export function Put(
153
- path?: string | RouteMethodOptions,
154
- options?: RouteMethodOptions,
155
- ) {
156
- const parsedPath =
157
- !path && !options ? "/" : (path as string | RouteMethodOptions);
158
- if (options) {
159
- return createRouteDecorator("PUT")(parsedPath, options);
160
- } else {
161
- return createRouteDecorator("PUT")(parsedPath);
162
- }
163
- }
164
-
165
- export function Delete(path?: string): MethodDecorator;
166
- export function Delete(path: string | RouteMethodOptions): MethodDecorator;
167
- export function Delete(
168
- path: string,
169
- options: RouteMethodOptions,
170
- ): MethodDecorator;
171
- export function Delete(
172
- path?: string | RouteMethodOptions,
173
- options?: RouteMethodOptions,
174
- ) {
175
- const parsedPath =
176
- !path && !options ? "/" : (path as string | RouteMethodOptions);
177
- if (options) {
178
- return createRouteDecorator("DELETE")(parsedPath, options);
179
- } else {
180
- return createRouteDecorator("DELETE")(parsedPath);
181
- }
182
- }
183
-
184
- export const Patch = createRouteDecorator("PATCH");
185
- export const Options = createRouteDecorator("OPTIONS");
186
- export const All = createRouteDecorator("ALL");
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
7
+
8
+ import { CONTROLLER_META_KEY, ROUTE_META_KEY } from "./container";
9
+ import { OpenApiOptions } from "./openapi";
10
+ import { HttpResponse } from "./response";
11
+ import { Results } from "./results";
12
+ export type RouteMethods =
13
+ | "GET"
14
+ | "POST"
15
+ | "PUT"
16
+ | "PATCH"
17
+ | "DELETE"
18
+ | "OPTIONS"
19
+ | "ALL";
20
+
21
+ const schema: OpenApiOptions = {
22
+ tags: ["hello"],
23
+ };
24
+
25
+ /**
26
+ * Options for defining a route's method and metadata.
27
+ */
28
+ export type RouteMethodOptions = {
29
+ /**
30
+ * HTTP method for the route (e.g., GET, POST, PUT, DELETE).
31
+ */
32
+ method?: RouteMethods;
33
+
34
+ /**
35
+ * The path or endpoint for the route (e.g., "/users/:id").
36
+ */
37
+ path?: string;
38
+
39
+ /**
40
+ * OpenAPI metadata for the route, including summary and description.
41
+ */
42
+ openapi?: OpenApiOptions;
43
+
44
+ /**
45
+ * Name of the route.
46
+ *
47
+ * @description If Swagger is enabled in the project, this will appear as a tag in the generated documentation.
48
+ */
49
+ name?: string;
50
+ };
51
+
52
+ // Overloads
53
+
54
+ // Implementation
55
+ export function createRouteDecorator(
56
+ method: RouteMethods = "GET",
57
+ ): (
58
+ pathOrOptions: string | RouteMethodOptions,
59
+ maybeOptions?: RouteMethodOptions,
60
+ ) => MethodDecorator {
61
+ return function (
62
+ pathOrOptions: string | RouteMethodOptions,
63
+ maybeOptions?: RouteMethodOptions,
64
+ ): MethodDecorator {
65
+ return function (
66
+ target,
67
+ propertyKey: string | symbol,
68
+ descriptor: PropertyDescriptor,
69
+ ) {
70
+ let path = "/";
71
+ let options: RouteMethodOptions = {};
72
+
73
+ if (typeof pathOrOptions === "string") {
74
+ path = pathOrOptions;
75
+ options = maybeOptions || {};
76
+ } else if (typeof pathOrOptions === "object") {
77
+ options = pathOrOptions;
78
+ path = options.name || "/";
79
+ }
80
+
81
+ // Define metadata
82
+ Reflect.defineMetadata("route:path", path, target, propertyKey);
83
+ Reflect.defineMetadata(
84
+ "route:method",
85
+ method || "GET",
86
+ target,
87
+ propertyKey,
88
+ );
89
+ Reflect.getMetadata(CONTROLLER_META_KEY, target.constructor);
90
+ Reflect.defineMetadata(
91
+ ROUTE_META_KEY,
92
+ { ...options, method, path, controller: target.constructor.name },
93
+ target,
94
+ propertyKey,
95
+ );
96
+
97
+ if (options) {
98
+ Reflect.defineMetadata("route:options", options, target, propertyKey);
99
+ }
100
+ };
101
+ };
102
+ }
103
+
104
+ // Usage Example
105
+ /**
106
+ * @description HTTP Get method
107
+ * @param {string} path
108
+ */
109
+ export function Get(path?: string): MethodDecorator;
110
+ export function Get(path: string | RouteMethodOptions): MethodDecorator;
111
+ /**
112
+ * @description HTTP Get method
113
+ * @param {string} path
114
+ * @param {RouteMethodOptions} options
115
+ */
116
+ export function Get(path: string, options: RouteMethodOptions): MethodDecorator;
117
+ export function Get(
118
+ path?: string | RouteMethodOptions,
119
+ options?: RouteMethodOptions,
120
+ ) {
121
+ const parsedPath =
122
+ !path && !options ? "/" : (path as string | RouteMethodOptions);
123
+ if (options) {
124
+ return createRouteDecorator("GET")(parsedPath, options);
125
+ } else {
126
+ return createRouteDecorator("GET")(parsedPath);
127
+ }
128
+ }
129
+
130
+ export function Post(path?: string): MethodDecorator;
131
+ export function Post(path: string | RouteMethodOptions): MethodDecorator;
132
+ export function Post(
133
+ path: string,
134
+ options: RouteMethodOptions,
135
+ ): MethodDecorator;
136
+ export function Post(
137
+ path?: string | RouteMethodOptions,
138
+ options?: RouteMethodOptions,
139
+ ) {
140
+ const parsedPath =
141
+ !path && !options ? "/" : (path as string | RouteMethodOptions);
142
+ if (options) {
143
+ return createRouteDecorator("POST")(parsedPath, options);
144
+ } else {
145
+ return createRouteDecorator("POST")(parsedPath);
146
+ }
147
+ }
148
+
149
+ export function Put(path?: string): MethodDecorator;
150
+ export function Put(path: string | RouteMethodOptions): MethodDecorator;
151
+ export function Put(path: string, options: RouteMethodOptions): MethodDecorator;
152
+ export function Put(
153
+ path?: string | RouteMethodOptions,
154
+ options?: RouteMethodOptions,
155
+ ) {
156
+ const parsedPath =
157
+ !path && !options ? "/" : (path as string | RouteMethodOptions);
158
+ if (options) {
159
+ return createRouteDecorator("PUT")(parsedPath, options);
160
+ } else {
161
+ return createRouteDecorator("PUT")(parsedPath);
162
+ }
163
+ }
164
+
165
+ export function Delete(path?: string): MethodDecorator;
166
+ export function Delete(path: string | RouteMethodOptions): MethodDecorator;
167
+ export function Delete(
168
+ path: string,
169
+ options: RouteMethodOptions,
170
+ ): MethodDecorator;
171
+ export function Delete(
172
+ path?: string | RouteMethodOptions,
173
+ options?: RouteMethodOptions,
174
+ ) {
175
+ const parsedPath =
176
+ !path && !options ? "/" : (path as string | RouteMethodOptions);
177
+ if (options) {
178
+ return createRouteDecorator("DELETE")(parsedPath, options);
179
+ } else {
180
+ return createRouteDecorator("DELETE")(parsedPath);
181
+ }
182
+ }
183
+
184
+ export const Patch = createRouteDecorator("PATCH");
185
+ export const Options = createRouteDecorator("OPTIONS");
186
+ export const All = createRouteDecorator("ALL");