@xrystal/core 3.21.1 → 3.21.4
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/package.json +1 -1
- package/source/loader/clients/index.d.ts +1 -1
- package/source/loader/clients/index.js +1 -1
- package/source/loader/configs/index.d.ts +1 -1
- package/source/loader/configs/index.js +1 -1
- package/source/loader/controller/index.d.ts +1 -1
- package/source/loader/controller/index.js +1 -1
- package/source/loader/events/index.d.ts +1 -1
- package/source/loader/events/index.js +1 -1
- package/source/loader/localizations/index.d.ts +1 -1
- package/source/loader/localizations/index.js +1 -1
- package/source/loader/logger/index.d.ts +1 -1
- package/source/loader/logger/index.js +1 -1
- package/source/loader/system/index.d.ts +1 -1
- package/source/loader/system/index.js +1 -1
- package/source/utils/helpers/core/index.d.ts +2 -0
- package/source/utils/helpers/core/index.js +9 -1
- package/source/utils/models/classes/class.interfaces.d.ts +3 -3
- package/source/utils/models/classes/class.interfaces.js +3 -3
- package/source/utils/models/classes/class.x.js +20 -9
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ export default class ClientsService {
|
|
|
5
5
|
constructor({ configsService }) {
|
|
6
6
|
this.#configsService = configsService;
|
|
7
7
|
}
|
|
8
|
-
async
|
|
8
|
+
async onInit() {
|
|
9
9
|
const baseClient = new BaseApiClient({
|
|
10
10
|
clientName: CoreServiceEnum.BASE_API_CLIENT,
|
|
11
11
|
baseURL: this.#configsService.all.baseApiUri || ''
|
|
@@ -37,7 +37,7 @@ export default class ConfigsService implements IService<any> {
|
|
|
37
37
|
constructor({ systemService }: {
|
|
38
38
|
systemService: SystemService;
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
onInit: ({}: {}) => Promise<void>;
|
|
41
41
|
setConfig(newConfigs: any): void;
|
|
42
42
|
_<K extends keyof IConfig>(key: K): IConfig[K];
|
|
43
43
|
get all(): IConfig;
|
|
@@ -51,7 +51,7 @@ export declare abstract class ControllerService extends Controller implements IS
|
|
|
51
51
|
systemService: SystemService;
|
|
52
52
|
loggerService: LoggerService;
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
onInit(): Promise<void>;
|
|
55
55
|
schema({ checks, logic, response }: {
|
|
56
56
|
checks?: (args: any) => Promise<any>;
|
|
57
57
|
logic?: (args: any) => Promise<any>;
|
|
@@ -77,7 +77,7 @@ export class ControllerService extends Controller {
|
|
|
77
77
|
this.systemService = systemService;
|
|
78
78
|
this.logger = loggerService;
|
|
79
79
|
}
|
|
80
|
-
async
|
|
80
|
+
async onInit() {
|
|
81
81
|
const protocols = this.systemService?.tmp?.configs?.loaders?.controller?.protocols;
|
|
82
82
|
this.supportedProtocols = Array.isArray(protocols) ? protocols : [protocols || ProtocolEnum.HTTP];
|
|
83
83
|
}
|
|
@@ -8,7 +8,7 @@ export default class LocalizationsService implements IService<any> {
|
|
|
8
8
|
systemService: SystemService;
|
|
9
9
|
configsService: ConfigsService;
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
onInit: ({}: {}) => any;
|
|
12
12
|
i18next: ({ loadPath, fallbackLang, preloadLang, }: {
|
|
13
13
|
loadPath?: string;
|
|
14
14
|
fallbackLang?: string;
|
|
@@ -9,7 +9,7 @@ export default class LocalizationsService {
|
|
|
9
9
|
this.#systemService = systemService;
|
|
10
10
|
this.#configsService = configsService;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
onInit = ({}) => {
|
|
13
13
|
const localization = this.#systemService.tmp.configs.loaders.localization;
|
|
14
14
|
this.i18next({
|
|
15
15
|
loadPath: localization.loadPath,
|
|
@@ -26,7 +26,7 @@ export default class LoggerService implements IService<any> {
|
|
|
26
26
|
systemService: SystemService;
|
|
27
27
|
configsService: ConfigsService;
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
onInit: () => Promise<void>;
|
|
30
30
|
winstonLoader: ({ loadPath, loggerLevel }: {
|
|
31
31
|
loadPath: string;
|
|
32
32
|
loggerLevel: string;
|
|
@@ -44,7 +44,7 @@ export default class LoggerService {
|
|
|
44
44
|
this.#systemService = systemService;
|
|
45
45
|
this.#configsService = configsService;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
onInit = async () => {
|
|
48
48
|
this.serviceName = this.#systemService?.tmp?.configs?.service;
|
|
49
49
|
this.kafkaLogsTopic = this.#configsService?.all?.kafkaLogsTopic;
|
|
50
50
|
winston.addColors(customColors);
|
|
@@ -3,7 +3,7 @@ export default class SystemService implements IService<any> {
|
|
|
3
3
|
protected _core: Record<string, any>;
|
|
4
4
|
protected _tmp: Record<string, any>;
|
|
5
5
|
cwd: string;
|
|
6
|
-
|
|
6
|
+
onInit: ({ core }: {
|
|
7
7
|
core: any;
|
|
8
8
|
}) => Promise<void>;
|
|
9
9
|
private initializeKafkaInfrastructure;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ProtocolEnum } from "../../index.js";
|
|
1
2
|
export declare const getCore: () => {
|
|
2
3
|
_: any;
|
|
3
4
|
};
|
|
@@ -8,6 +9,7 @@ export declare const getTmpConfig: ({ root, tmpFileName, ext }: {
|
|
|
8
9
|
}) => any;
|
|
9
10
|
export declare function resolveObjWithHandlebars(obj: any, context: any): any;
|
|
10
11
|
export declare function findFileRecursively(startDir: string, baseName: string, extName?: string, excludedDirs?: string[]): string | null;
|
|
12
|
+
export declare const protocol: (callback: () => Promise<any>, protocol?: ProtocolEnum) => Promise<any>;
|
|
11
13
|
export declare const argvsConverter: (argvs: string) => {
|
|
12
14
|
[key: string]: string;
|
|
13
15
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import Handlebars from 'handlebars';
|
|
4
|
-
import { Constants, TmpFileLoader } from "../../index.js";
|
|
4
|
+
import { Constants, ProtocolEnum, TmpFileLoader } from "../../index.js";
|
|
5
|
+
import { controllerContextStorage } from "../../../loader/controller";
|
|
5
6
|
export const getCore = () => {
|
|
6
7
|
const ownerTmpFilePath = findFileRecursively(".", Constants.defaultTmpFileName, Constants.defaultTmpFileExt);
|
|
7
8
|
if (!ownerTmpFilePath) {
|
|
@@ -75,6 +76,13 @@ export function findFileRecursively(startDir, baseName, extName = '', excludedDi
|
|
|
75
76
|
return null;
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
export const protocol = async (callback, protocol = ProtocolEnum.HTTP) => {
|
|
80
|
+
const store = controllerContextStorage.getStore();
|
|
81
|
+
if (store) {
|
|
82
|
+
store.protocol = protocol;
|
|
83
|
+
}
|
|
84
|
+
return await callback();
|
|
85
|
+
};
|
|
78
86
|
// => ---
|
|
79
87
|
export const argvsConverter = (argvs) => {
|
|
80
88
|
const reelArgvs = argvs?.slice(2);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare abstract class ILifeCycle<T = any> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
onInit(props?: T | {}): Promise<void>;
|
|
3
|
+
onAfterInit?(_context?: any): Promise<void> | void;
|
|
4
|
+
onDispose?(_context?: any): Promise<void> | void;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class IService<T = any> extends ILifeCycle<T> {
|
|
7
7
|
}
|
|
@@ -106,14 +106,14 @@ class DIM extends X {
|
|
|
106
106
|
continue;
|
|
107
107
|
try {
|
|
108
108
|
const instance = this.container.cradle[name];
|
|
109
|
-
if (instance && typeof instance.
|
|
110
|
-
await instance.
|
|
109
|
+
if (instance && typeof instance.onInit === 'function') {
|
|
110
|
+
await instance.onInit(item.props || {});
|
|
111
111
|
}
|
|
112
112
|
this.initializedNames.add(name);
|
|
113
113
|
}
|
|
114
114
|
catch (err) {
|
|
115
115
|
if (verbose)
|
|
116
|
-
console.error(`[DI] Priority
|
|
116
|
+
console.error(`[DI] Priority onInit Failed (${name}):`, err.message);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
const allKeys = Object.keys(this.container.registrations);
|
|
@@ -125,26 +125,26 @@ class DIM extends X {
|
|
|
125
125
|
continue;
|
|
126
126
|
try {
|
|
127
127
|
const instance = this.container.cradle[key];
|
|
128
|
-
if (instance && typeof instance.
|
|
129
|
-
await instance.
|
|
128
|
+
if (instance && typeof instance.onInit === 'function') {
|
|
129
|
+
await instance.onInit({});
|
|
130
130
|
}
|
|
131
131
|
this.initializedNames.add(key);
|
|
132
132
|
}
|
|
133
133
|
catch (err) {
|
|
134
134
|
if (verbose)
|
|
135
|
-
console.error(`[DI] Auto
|
|
135
|
+
console.error(`[DI] Auto onInit Failed (${key}):`, err.message);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
for (const name of this.initializedNames) {
|
|
139
139
|
try {
|
|
140
140
|
const instance = this.container.cradle[name];
|
|
141
|
-
if (instance && typeof instance.
|
|
142
|
-
await instance.
|
|
141
|
+
if (instance && typeof instance.onAfterInit === 'function') {
|
|
142
|
+
await instance.onAfterInit();
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
catch (err) {
|
|
146
146
|
if (verbose)
|
|
147
|
-
console.error(`[DI]
|
|
147
|
+
console.error(`[DI] onAfterInit Failed (${name}):`, err.message);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -158,6 +158,17 @@ class DIM extends X {
|
|
|
158
158
|
return this.container.resolve(resolveName);
|
|
159
159
|
}
|
|
160
160
|
async shutdown() {
|
|
161
|
+
for (const name of this.initializedNames) {
|
|
162
|
+
try {
|
|
163
|
+
const instance = this.container.cradle[name];
|
|
164
|
+
if (instance && typeof instance.onDispose === 'function') {
|
|
165
|
+
await instance.onDispose();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
console.error(`[DI] onDispose Failed (${name})`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
161
172
|
await this.container.dispose();
|
|
162
173
|
}
|
|
163
174
|
get cradle() { return this.container.cradle; }
|