@xrystal/core 3.21.0 → 3.21.3
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/models/classes/class.interfaces.d.ts +3 -2
- package/source/utils/models/classes/class.interfaces.js +4 -2
- package/source/utils/models/classes/class.x.d.ts +4 -3
- package/source/utils/models/classes/class.x.js +35 -17
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,6 +1,7 @@
|
|
|
1
1
|
export declare abstract class ILifeCycle<T = any> {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
onInit(props?: T | {}): Promise<void>;
|
|
3
|
+
onAfterInit?(_context?: any): Promise<void> | void;
|
|
4
|
+
onDispose?(_context?: any): Promise<void> | void;
|
|
4
5
|
}
|
|
5
6
|
export declare abstract class IService<T = any> extends ILifeCycle<T> {
|
|
6
7
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AwilixContainer, LifetimeType } from 'awilix';
|
|
2
|
+
export declare const xSymbol: unique symbol;
|
|
2
3
|
type Constructor<T> = new (...args: any[]) => T;
|
|
3
4
|
type AbstractConstructor<T> = abstract new (...args: any[]) => T;
|
|
4
|
-
declare abstract class
|
|
5
|
+
declare abstract class X {
|
|
5
6
|
protected checkRegistration(container: AwilixContainer, name: string): boolean;
|
|
6
7
|
}
|
|
7
|
-
declare class
|
|
8
|
+
declare class DIM extends X {
|
|
8
9
|
private container;
|
|
9
10
|
private initializedNames;
|
|
10
11
|
private loadedPaths;
|
|
@@ -30,5 +31,5 @@ declare class X extends XHelper {
|
|
|
30
31
|
shutdown(): Promise<void>;
|
|
31
32
|
get cradle(): any;
|
|
32
33
|
}
|
|
33
|
-
declare const _default:
|
|
34
|
+
declare const _default: DIM;
|
|
34
35
|
export default _default;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createContainer, asClass, asValue, InjectionMode, listModules, Lifetime } from 'awilix';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
|
|
4
|
+
export const xSymbol = Symbol.for('@xrystal/core/di-container');
|
|
5
|
+
class X {
|
|
5
6
|
checkRegistration(container, name) {
|
|
6
7
|
return !!container.registrations[name];
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
class
|
|
10
|
+
class DIM extends X {
|
|
10
11
|
container;
|
|
11
12
|
initializedNames = new Set();
|
|
12
13
|
loadedPaths = new Set();
|
|
@@ -96,7 +97,6 @@ class X extends XHelper {
|
|
|
96
97
|
this.isInitializing = true;
|
|
97
98
|
try {
|
|
98
99
|
const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
|
|
99
|
-
// 1. ADIM: Senin verdiğin sıraya göre TEK TEK yükle (Senin için en önemli yer)
|
|
100
100
|
for (const item of inputList) {
|
|
101
101
|
const name = this.getName(item.service);
|
|
102
102
|
if (!name || this.initializedNames.has(name))
|
|
@@ -105,20 +105,17 @@ class X extends XHelper {
|
|
|
105
105
|
if (!reg || reg.lifetime !== Lifetime.SINGLETON)
|
|
106
106
|
continue;
|
|
107
107
|
try {
|
|
108
|
-
// Awilix instance'ı oluşturur (constructor çalışır)
|
|
109
108
|
const instance = this.container.cradle[name];
|
|
110
|
-
if (instance && typeof instance.
|
|
111
|
-
|
|
112
|
-
await instance.load(item.props || {});
|
|
109
|
+
if (instance && typeof instance.onInit === 'function') {
|
|
110
|
+
await instance.onInit(item.props || {});
|
|
113
111
|
}
|
|
114
112
|
this.initializedNames.add(name);
|
|
115
113
|
}
|
|
116
114
|
catch (err) {
|
|
117
115
|
if (verbose)
|
|
118
|
-
console.error(`[DI] Priority
|
|
116
|
+
console.error(`[DI] Priority onInit Failed (${name}):`, err.message);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
// 2. ADIM: Listede olmayan ama register edilmiş diğer geri kalan singleton'ları yükle
|
|
122
119
|
const allKeys = Object.keys(this.container.registrations);
|
|
123
120
|
for (const key of allKeys) {
|
|
124
121
|
if (this.initializedNames.has(key))
|
|
@@ -128,14 +125,26 @@ class X extends XHelper {
|
|
|
128
125
|
continue;
|
|
129
126
|
try {
|
|
130
127
|
const instance = this.container.cradle[key];
|
|
131
|
-
if (instance && typeof instance.
|
|
132
|
-
await instance.
|
|
128
|
+
if (instance && typeof instance.onInit === 'function') {
|
|
129
|
+
await instance.onInit({});
|
|
133
130
|
}
|
|
134
131
|
this.initializedNames.add(key);
|
|
135
132
|
}
|
|
136
133
|
catch (err) {
|
|
137
134
|
if (verbose)
|
|
138
|
-
console.error(`[DI] Auto
|
|
135
|
+
console.error(`[DI] Auto onInit Failed (${key}):`, err.message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const name of this.initializedNames) {
|
|
139
|
+
try {
|
|
140
|
+
const instance = this.container.cradle[name];
|
|
141
|
+
if (instance && typeof instance.onAfterInit === 'function') {
|
|
142
|
+
await instance.onAfterInit();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
if (verbose)
|
|
147
|
+
console.error(`[DI] onAfterInit Failed (${name}):`, err.message);
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
}
|
|
@@ -149,13 +158,22 @@ class X extends XHelper {
|
|
|
149
158
|
return this.container.resolve(resolveName);
|
|
150
159
|
}
|
|
151
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
|
+
}
|
|
152
172
|
await this.container.dispose();
|
|
153
173
|
}
|
|
154
174
|
get cradle() { return this.container.cradle; }
|
|
155
175
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (!globalObj[X_SYMBOL]) {
|
|
159
|
-
globalObj[X_SYMBOL] = new X();
|
|
176
|
+
if (!global[xSymbol]) {
|
|
177
|
+
global[xSymbol] = new DIM();
|
|
160
178
|
}
|
|
161
|
-
export default
|
|
179
|
+
export default global[xSymbol];
|