@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
package/src/index.ts CHANGED
@@ -1,30 +1,32 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import * as sw from "./swagger-schema";
8
- export * from "./icore";
9
- export * from "./testing";
10
- export { inject, validateRequestBody,pick, exclude } from "./helpers";
11
- export * from "./decorators";
12
- export * from "./middleware";
13
- export * from "./config";
14
- export * from "./openapi";
15
- export * from "./map-types";
16
- export * from "./response";
17
- export * from "./exceptions";
18
- export * from "./validator-extend";
19
- export * from "./validation";
20
- export * from "./environment-variables";
21
- export * from "./collection";
22
- export * from "./queue";
23
- export * from "./utils/hash";
24
- export * from "./multipart";
25
- export * from "./file-storage";
26
- export * from "./logger";
27
-
28
- export const GetSchema = sw.generateSwaggerSchema;
29
-
30
- export { default as Container } from "./container";
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
7
+ import * as sw from "./swagger-schema";
8
+ export * from "./icore";
9
+ export * from "./testing";
10
+ export { inject, validateRequestBody, pick, exclude } from "./helpers";
11
+ export * from "./decorators";
12
+ export * from "./middleware";
13
+ export * from "./config";
14
+ export * from "./openapi";
15
+ export * from "./map-types";
16
+ export * from "./response";
17
+ export * from "./exceptions";
18
+ export * from "./validator-extend";
19
+ export * from "./validation";
20
+ export * from "./environment-variables";
21
+ export * from "./collection";
22
+ export * from "./queue";
23
+ export * from "./utils/hash";
24
+ export * from "./multipart";
25
+ export * from "./file-storage";
26
+ export * from "./logger";
27
+ export * from "./event-dispatcher";
28
+ export { Subscribe, Private } from "./event-subscriber";
29
+
30
+ export const GetSchema = sw.generateSwaggerSchema;
31
+
32
+ export { default as AvleonContainer } from "./container";
@@ -1,40 +1,32 @@
1
-
2
-
3
- interface AvleonApplication {
4
-
5
- // all use
6
- useCors: () => void;
7
- /**
8
- * function for register database
9
- * @param options datasource options. options can be plain object or avleon config class
10
- * */
11
- useDatasource: () => void;
12
- useMultipart: () => void;
13
- useOpenApi: () => void;
14
- useMiddlewares: () => void;
15
- useAuthorization: () => void;
16
- useSerialization: () => void;
17
- useControllers: () => void;
18
- useStaticFiles: () => void;
19
- /**
20
- * @experimental
21
- * use https as defalut http protocol
22
- * */
23
- useHttps: () => void;
24
-
25
-
26
- // all map
27
- mapGet: () => void;
28
- mapPost: () => void;
29
- mapPut: () => void;
30
- mapPatch: () => void;
31
- mapOptions: () => void;
32
- mapGroup: () => void;
33
- // all others
34
- // run
35
- run: () => void;
36
- }
37
-
38
-
39
-
40
-
1
+ interface AvleonApplication {
2
+ // all use
3
+ useCors: () => void;
4
+ /**
5
+ * function for register database
6
+ * @param options datasource options. options can be plain object or avleon config class
7
+ * */
8
+ useDatasource: () => void;
9
+ useMultipart: () => void;
10
+ useOpenApi: () => void;
11
+ useMiddlewares: () => void;
12
+ useAuthorization: () => void;
13
+ useSerialization: () => void;
14
+ useControllers: () => void;
15
+ useStaticFiles: () => void;
16
+ /**
17
+ * @experimental
18
+ * use https as defalut http protocol
19
+ * */
20
+ useHttps: () => void;
21
+
22
+ // all map
23
+ mapGet: () => void;
24
+ mapPost: () => void;
25
+ mapPut: () => void;
26
+ mapPatch: () => void;
27
+ mapOptions: () => void;
28
+ mapGroup: () => void;
29
+ // all others
30
+ // run
31
+ run: () => void;
32
+ }
package/src/logger.ts CHANGED
@@ -1,72 +1,72 @@
1
- import pino from "pino";
2
- import { AppService } from "./decorators";
3
-
4
- @AppService
5
- export class LoggerService {
6
- private logger: pino.Logger;
7
-
8
- constructor() {
9
- this.logger = pino({
10
- level: process.env.LOG_LEVEL || "info",
11
- transport: {
12
- target: "pino-pretty",
13
- options: {
14
- translateTime: "SYS:standard",
15
- ignore: "pid,hostname",
16
- },
17
- },
18
- });
19
- }
20
-
21
- getLogger(): pino.Logger {
22
- return this.logger;
23
- }
24
-
25
- info(message: string, obj?: any): void {
26
- if (obj) {
27
- this.logger.info(obj, message);
28
- } else {
29
- this.logger.info(message);
30
- }
31
- }
32
-
33
- error(message: string, obj?: any): void {
34
- if (obj) {
35
- this.logger.error(obj, message);
36
- } else {
37
- this.logger.error(message);
38
- }
39
- }
40
-
41
- warn(message: string, obj?: any): void {
42
- if (obj) {
43
- this.logger.warn(obj, message);
44
- } else {
45
- this.logger.warn(message);
46
- }
47
- }
48
-
49
- debug(message: string, obj?: any): void {
50
- if (obj) {
51
- this.logger.debug(obj, message);
52
- } else {
53
- this.logger.debug(message);
54
- }
55
- }
56
-
57
- fatal(message: string, obj?: any): void {
58
- if (obj) {
59
- this.logger.fatal(obj, message);
60
- } else {
61
- this.logger.fatal(message);
62
- }
63
- }
64
-
65
- trace(message: string, obj?: any): void {
66
- if (obj) {
67
- this.logger.trace(obj, message);
68
- } else {
69
- this.logger.trace(message);
70
- }
71
- }
72
- }
1
+ import pino from "pino";
2
+ import { AppService } from "./decorators";
3
+
4
+ @AppService
5
+ export class LoggerService {
6
+ private logger: pino.Logger;
7
+
8
+ constructor() {
9
+ this.logger = pino({
10
+ level: process.env.LOG_LEVEL || "info",
11
+ transport: {
12
+ target: "pino-pretty",
13
+ options: {
14
+ translateTime: "SYS:standard",
15
+ ignore: "pid,hostname",
16
+ },
17
+ },
18
+ });
19
+ }
20
+
21
+ getLogger(): pino.Logger {
22
+ return this.logger;
23
+ }
24
+
25
+ info(message: string, obj?: any): void {
26
+ if (obj) {
27
+ this.logger.info(obj, message);
28
+ } else {
29
+ this.logger.info(message);
30
+ }
31
+ }
32
+
33
+ error(message: string, obj?: any): void {
34
+ if (obj) {
35
+ this.logger.error(obj, message);
36
+ } else {
37
+ this.logger.error(message);
38
+ }
39
+ }
40
+
41
+ warn(message: string, obj?: any): void {
42
+ if (obj) {
43
+ this.logger.warn(obj, message);
44
+ } else {
45
+ this.logger.warn(message);
46
+ }
47
+ }
48
+
49
+ debug(message: string, obj?: any): void {
50
+ if (obj) {
51
+ this.logger.debug(obj, message);
52
+ } else {
53
+ this.logger.debug(message);
54
+ }
55
+ }
56
+
57
+ fatal(message: string, obj?: any): void {
58
+ if (obj) {
59
+ this.logger.fatal(obj, message);
60
+ } else {
61
+ this.logger.fatal(message);
62
+ }
63
+ }
64
+
65
+ trace(message: string, obj?: any): void {
66
+ if (obj) {
67
+ this.logger.trace(obj, message);
68
+ } else {
69
+ this.logger.trace(message);
70
+ }
71
+ }
72
+ }
package/src/map-types.ts CHANGED
@@ -1,159 +1,159 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
-
8
- //
9
- type Constructor<T = any> = new (...args: any[]) => T;
10
-
11
- export function PartialType<T>(
12
- BaseClass: Constructor<T>,
13
- ): Constructor<Partial<T>> {
14
- const baseProperties: string[] = [];
15
- let currentPrototype = BaseClass.prototype;
16
-
17
- // Collect properties from the base class (including inherited ones)
18
- while (currentPrototype && currentPrototype !== Object.prototype) {
19
- const properties = Object.getOwnPropertyNames(currentPrototype).filter(
20
- (prop) => prop !== "constructor", // Exclude the constructor
21
- );
22
-
23
- // Retrieve metadata for each property
24
- properties.forEach((key) => {
25
- // Check if the property has type metadata (design:type)
26
- const designType = Reflect.getMetadata(
27
- "design:type",
28
- currentPrototype,
29
- key,
30
- );
31
- if (designType) {
32
- baseProperties.push(key);
33
- }
34
-
35
- // Retrieve validation metadata (class-validator)
36
- const validationMetadata = Reflect.getMetadataKeys(currentPrototype, key);
37
- validationMetadata.forEach((metadataKey) => {});
38
- });
39
-
40
- currentPrototype = Object.getPrototypeOf(currentPrototype); // Move up the prototype chain
41
- }
42
-
43
- class PartialClass {}
44
-
45
- // Define properties as optional and copy metadata
46
- baseProperties.forEach((key) => {
47
- const propertyType = Reflect.getMetadata(
48
- "design:type",
49
- BaseClass.prototype,
50
- key,
51
- );
52
- Reflect.defineMetadata(
53
- "design:type",
54
- propertyType,
55
- PartialClass.prototype,
56
- key,
57
- );
58
-
59
- // Propagate class-validator metadata to the new class
60
- const validationMetadataKeys =
61
- Reflect.getMetadataKeys(BaseClass.prototype, key) || [];
62
- validationMetadataKeys.forEach((metadataKey) => {
63
- const metadataValue = Reflect.getMetadata(
64
- metadataKey,
65
- BaseClass.prototype,
66
- key,
67
- );
68
- Reflect.defineMetadata(
69
- metadataKey,
70
- metadataValue,
71
- PartialClass.prototype,
72
- key,
73
- );
74
- });
75
- });
76
-
77
- // Copy other metadata from the base class (non-property metadata)
78
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
79
- const metadataValue = Reflect.getMetadata(key, BaseClass.prototype);
80
- Reflect.defineMetadata(key, metadataValue, PartialClass.prototype);
81
- });
82
-
83
- return PartialClass as Constructor<Partial<T>>;
84
- }
85
-
86
- /**
87
- * Utility to pick specific properties from a class.
88
- */
89
- export function PickType<T, K extends keyof T>(
90
- BaseClass: Constructor<T>,
91
- keys: K[],
92
- ): Constructor<Pick<T, K>> {
93
- class PickClass {
94
- constructor() {
95
- (keys as string[]).forEach((key: string) => {
96
- Reflect.defineMetadata(
97
- "design:type",
98
- Reflect.getMetadata("design:type", BaseClass.prototype, key),
99
- this,
100
- key,
101
- );
102
- });
103
- }
104
- }
105
-
106
- Reflect.decorate([Reflect.metadata("design:properties", keys)], PickClass);
107
-
108
- // Copy metadata from BaseClass to PickClass
109
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
110
- Reflect.defineMetadata(
111
- key,
112
- Reflect.getMetadata(key, BaseClass.prototype),
113
- PickClass.prototype,
114
- );
115
- });
116
-
117
- return PickClass as Constructor<Pick<T, K>>;
118
- }
119
-
120
- /**
121
- * Utility to omit specific properties from a class.
122
- */
123
- export function OmitType<T, K extends keyof T>(
124
- BaseClass: Constructor<T>,
125
- keys: K[],
126
- ): Constructor<Omit<T, K>> {
127
- const allKeys = Reflect.getMetadata("design:properties", BaseClass) || [];
128
- const omitKeys = new Set(keys);
129
- const finalKeys = allKeys.filter((key: string) => !omitKeys.has(key as any));
130
-
131
- class OmitClass {
132
- constructor() {
133
- finalKeys.forEach((key: string) => {
134
- Reflect.defineMetadata(
135
- "design:type",
136
- Reflect.getMetadata("design:type", BaseClass.prototype, key),
137
- this,
138
- key,
139
- );
140
- });
141
- }
142
- }
143
-
144
- Reflect.decorate(
145
- [Reflect.metadata("design:properties", finalKeys)],
146
- OmitClass,
147
- );
148
-
149
- // Copy metadata from BaseClass to OmitClass
150
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
151
- Reflect.defineMetadata(
152
- key,
153
- Reflect.getMetadata(key, BaseClass.prototype),
154
- OmitClass.prototype,
155
- );
156
- });
157
-
158
- return OmitClass as Constructor<Omit<T, K>>;
159
- }
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
7
+
8
+ //
9
+ type Constructor<T = any> = new (...args: any[]) => T;
10
+
11
+ export function PartialType<T>(
12
+ BaseClass: Constructor<T>,
13
+ ): Constructor<Partial<T>> {
14
+ const baseProperties: string[] = [];
15
+ let currentPrototype = BaseClass.prototype;
16
+
17
+ // Collect properties from the base class (including inherited ones)
18
+ while (currentPrototype && currentPrototype !== Object.prototype) {
19
+ const properties = Object.getOwnPropertyNames(currentPrototype).filter(
20
+ (prop) => prop !== "constructor", // Exclude the constructor
21
+ );
22
+
23
+ // Retrieve metadata for each property
24
+ properties.forEach((key) => {
25
+ // Check if the property has type metadata (design:type)
26
+ const designType = Reflect.getMetadata(
27
+ "design:type",
28
+ currentPrototype,
29
+ key,
30
+ );
31
+ if (designType) {
32
+ baseProperties.push(key);
33
+ }
34
+
35
+ // Retrieve validation metadata (class-validator)
36
+ const validationMetadata = Reflect.getMetadataKeys(currentPrototype, key);
37
+ validationMetadata.forEach((metadataKey) => {});
38
+ });
39
+
40
+ currentPrototype = Object.getPrototypeOf(currentPrototype); // Move up the prototype chain
41
+ }
42
+
43
+ class PartialClass {}
44
+
45
+ // Define properties as optional and copy metadata
46
+ baseProperties.forEach((key) => {
47
+ const propertyType = Reflect.getMetadata(
48
+ "design:type",
49
+ BaseClass.prototype,
50
+ key,
51
+ );
52
+ Reflect.defineMetadata(
53
+ "design:type",
54
+ propertyType,
55
+ PartialClass.prototype,
56
+ key,
57
+ );
58
+
59
+ // Propagate class-validator metadata to the new class
60
+ const validationMetadataKeys =
61
+ Reflect.getMetadataKeys(BaseClass.prototype, key) || [];
62
+ validationMetadataKeys.forEach((metadataKey) => {
63
+ const metadataValue = Reflect.getMetadata(
64
+ metadataKey,
65
+ BaseClass.prototype,
66
+ key,
67
+ );
68
+ Reflect.defineMetadata(
69
+ metadataKey,
70
+ metadataValue,
71
+ PartialClass.prototype,
72
+ key,
73
+ );
74
+ });
75
+ });
76
+
77
+ // Copy other metadata from the base class (non-property metadata)
78
+ Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
79
+ const metadataValue = Reflect.getMetadata(key, BaseClass.prototype);
80
+ Reflect.defineMetadata(key, metadataValue, PartialClass.prototype);
81
+ });
82
+
83
+ return PartialClass as Constructor<Partial<T>>;
84
+ }
85
+
86
+ /**
87
+ * Utility to pick specific properties from a class.
88
+ */
89
+ export function PickType<T, K extends keyof T>(
90
+ BaseClass: Constructor<T>,
91
+ keys: K[],
92
+ ): Constructor<Pick<T, K>> {
93
+ class PickClass {
94
+ constructor() {
95
+ (keys as string[]).forEach((key: string) => {
96
+ Reflect.defineMetadata(
97
+ "design:type",
98
+ Reflect.getMetadata("design:type", BaseClass.prototype, key),
99
+ this,
100
+ key,
101
+ );
102
+ });
103
+ }
104
+ }
105
+
106
+ Reflect.decorate([Reflect.metadata("design:properties", keys)], PickClass);
107
+
108
+ // Copy metadata from BaseClass to PickClass
109
+ Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
110
+ Reflect.defineMetadata(
111
+ key,
112
+ Reflect.getMetadata(key, BaseClass.prototype),
113
+ PickClass.prototype,
114
+ );
115
+ });
116
+
117
+ return PickClass as Constructor<Pick<T, K>>;
118
+ }
119
+
120
+ /**
121
+ * Utility to omit specific properties from a class.
122
+ */
123
+ export function OmitType<T, K extends keyof T>(
124
+ BaseClass: Constructor<T>,
125
+ keys: K[],
126
+ ): Constructor<Omit<T, K>> {
127
+ const allKeys = Reflect.getMetadata("design:properties", BaseClass) || [];
128
+ const omitKeys = new Set(keys);
129
+ const finalKeys = allKeys.filter((key: string) => !omitKeys.has(key as any));
130
+
131
+ class OmitClass {
132
+ constructor() {
133
+ finalKeys.forEach((key: string) => {
134
+ Reflect.defineMetadata(
135
+ "design:type",
136
+ Reflect.getMetadata("design:type", BaseClass.prototype, key),
137
+ this,
138
+ key,
139
+ );
140
+ });
141
+ }
142
+ }
143
+
144
+ Reflect.decorate(
145
+ [Reflect.metadata("design:properties", finalKeys)],
146
+ OmitClass,
147
+ );
148
+
149
+ // Copy metadata from BaseClass to OmitClass
150
+ Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
151
+ Reflect.defineMetadata(
152
+ key,
153
+ Reflect.getMetadata(key, BaseClass.prototype),
154
+ OmitClass.prototype,
155
+ );
156
+ });
157
+
158
+ return OmitClass as Constructor<Omit<T, K>>;
159
+ }