@avleon/core 0.0.26 → 0.0.28
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/README.md +601 -561
- package/package.json +38 -6
- package/src/application.ts +104 -125
- package/src/authentication.ts +16 -16
- package/src/cache.ts +91 -91
- package/src/collection.test.ts +71 -0
- package/src/collection.ts +344 -254
- package/src/config.test.ts +35 -0
- package/src/config.ts +85 -42
- package/src/constants.ts +1 -1
- package/src/container.ts +54 -54
- package/src/controller.ts +125 -127
- package/src/decorators.ts +27 -27
- package/src/environment-variables.ts +53 -46
- package/src/exceptions/http-exceptions.ts +86 -86
- package/src/exceptions/index.ts +1 -1
- package/src/exceptions/system-exception.ts +35 -34
- package/src/file-storage.ts +206 -206
- package/src/helpers.ts +324 -328
- package/src/icore.ts +66 -90
- package/src/index.ts +30 -30
- package/src/interfaces/avleon-application.ts +32 -40
- package/src/logger.ts +72 -72
- package/src/map-types.ts +159 -159
- package/src/middleware.ts +119 -98
- package/src/multipart.ts +116 -116
- package/src/openapi.ts +372 -372
- package/src/params.ts +111 -111
- package/src/queue.ts +126 -126
- package/src/response.ts +74 -74
- package/src/results.ts +30 -30
- package/src/route-methods.ts +186 -186
- package/src/swagger-schema.ts +213 -213
- package/src/testing.ts +220 -220
- package/src/types/app-builder.interface.ts +18 -19
- package/src/types/application.interface.ts +7 -9
- package/src/utils/hash.ts +8 -5
- package/src/utils/index.ts +2 -2
- package/src/utils/optional-require.ts +50 -50
- package/src/validation.ts +160 -156
- package/src/validator-extend.ts +25 -25
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
|
+
}
|