@xrystal/core 3.13.2 → 3.13.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
CHANGED
|
@@ -70,8 +70,8 @@ export default class LoggerService {
|
|
|
70
70
|
connectKafka();
|
|
71
71
|
}
|
|
72
72
|
this.winstonLoader({
|
|
73
|
-
loadPath: config?.loadPath
|
|
74
|
-
loggerLevel: config?.loggerLevel
|
|
73
|
+
loadPath: config?.loadPath,
|
|
74
|
+
loggerLevel: config?.loggerLevel
|
|
75
75
|
});
|
|
76
76
|
};
|
|
77
77
|
safeReplacer = (key, value) => {
|
package/source/project/index.js
CHANGED
|
@@ -50,7 +50,7 @@ const coreLoader = async ({}) => {
|
|
|
50
50
|
{
|
|
51
51
|
service: LocalizationsService,
|
|
52
52
|
props: {
|
|
53
|
-
loadPath: path.
|
|
53
|
+
loadPath: path.join(rootFolderPath, configs.loaders.localization.loadPath),
|
|
54
54
|
fallbackLang: configs.loaders.localization.fallbackLang,
|
|
55
55
|
preloadLang: configs.loaders.localization.preloadLangs
|
|
56
56
|
}
|
|
@@ -8,17 +8,26 @@ export class X {
|
|
|
8
8
|
strict: true
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
load(patterns, verbose =
|
|
11
|
+
load(patterns, verbose = false) {
|
|
12
|
+
if (!patterns || (Array.isArray(patterns) && patterns.length === 0))
|
|
13
|
+
return this;
|
|
12
14
|
const cwd = process.cwd();
|
|
13
|
-
const resolvedPatterns = (Array.isArray(patterns) ? patterns : [patterns])
|
|
15
|
+
const resolvedPatterns = (Array.isArray(patterns) ? patterns : [patterns])
|
|
16
|
+
.filter(p => typeof p === 'string')
|
|
17
|
+
.map(p => {
|
|
14
18
|
const resolved = path.isAbsolute(p) ? p : path.resolve(cwd, p);
|
|
15
19
|
return resolved.replace(/\\/g, '/');
|
|
16
20
|
});
|
|
17
|
-
|
|
21
|
+
let modules = [];
|
|
22
|
+
try {
|
|
23
|
+
modules = listModules(resolvedPatterns);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.error(`[DI] Critical: Path resolution failed: ${err.message}`);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
18
29
|
for (const m of modules) {
|
|
19
|
-
if (m.path.endsWith('.d.ts') ||
|
|
20
|
-
m.path.endsWith('.map') ||
|
|
21
|
-
m.path === __filename)
|
|
30
|
+
if (m.path === __filename || m.path.endsWith('.d.ts') || m.path.endsWith('.map'))
|
|
22
31
|
continue;
|
|
23
32
|
try {
|
|
24
33
|
const loaded = require(m.path);
|
|
@@ -30,22 +39,26 @@ export class X {
|
|
|
30
39
|
if (isClass) {
|
|
31
40
|
const className = dependency.name;
|
|
32
41
|
const name = className.charAt(0).toLowerCase() + className.slice(1);
|
|
33
|
-
if (!this.
|
|
42
|
+
if (!this.isRegistered(name)) {
|
|
34
43
|
this.container.register({
|
|
35
44
|
[name]: asClass(dependency).singleton()
|
|
36
45
|
});
|
|
46
|
+
if (verbose)
|
|
47
|
+
console.log(`[DI] Registered: ${name}`);
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
catch (err) {
|
|
41
|
-
|
|
52
|
+
console.error(`[DI] Critical: Failed to load module at ${m.path}:`, err.message);
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
55
|
if (verbose)
|
|
45
|
-
console.log('[DI]
|
|
56
|
+
console.log('[DI] Load completed. Total registrations:', Object.keys(this.container.registrations).length);
|
|
46
57
|
return this;
|
|
47
58
|
}
|
|
48
59
|
register(Dependency) {
|
|
60
|
+
if (!Dependency?.name)
|
|
61
|
+
return this;
|
|
49
62
|
const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
|
|
50
63
|
if (this.isRegistered(name))
|
|
51
64
|
return this;
|
|
@@ -55,41 +68,54 @@ export class X {
|
|
|
55
68
|
return this;
|
|
56
69
|
}
|
|
57
70
|
registerAll(dependencies) {
|
|
71
|
+
if (!Array.isArray(dependencies))
|
|
72
|
+
return this;
|
|
58
73
|
dependencies.forEach(dep => this.register(dep));
|
|
59
74
|
return this;
|
|
60
75
|
}
|
|
61
76
|
registerInstance(name, instance) {
|
|
62
|
-
if (this.isRegistered(name))
|
|
77
|
+
if (!name || this.isRegistered(name))
|
|
63
78
|
return this;
|
|
79
|
+
const formattedName = name.charAt(0).toLowerCase() + name.slice(1);
|
|
64
80
|
this.container.register({
|
|
65
|
-
[
|
|
81
|
+
[formattedName]: asValue(instance)
|
|
66
82
|
});
|
|
67
83
|
return this;
|
|
68
84
|
}
|
|
69
|
-
async initialize(input) {
|
|
85
|
+
async initialize(input, verbose = false) {
|
|
70
86
|
const cradle = this.container.cradle;
|
|
71
87
|
const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
|
|
72
88
|
const propsMap = new Map();
|
|
89
|
+
const initializedNames = [];
|
|
73
90
|
inputList.forEach(item => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
if (item?.service) {
|
|
92
|
+
const name = typeof item.service === 'function'
|
|
93
|
+
? item.service.name.charAt(0).toLowerCase() + item.service.name.slice(1)
|
|
94
|
+
: item.service;
|
|
95
|
+
propsMap.set(name, item.props);
|
|
96
|
+
}
|
|
78
97
|
});
|
|
79
|
-
for (const key of Object.keys(
|
|
98
|
+
for (const key of Object.keys(this.container.registrations)) {
|
|
80
99
|
const instance = cradle[key];
|
|
81
100
|
if (instance && typeof instance.load === 'function') {
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
try {
|
|
102
|
+
const props = propsMap.get(key) || {};
|
|
103
|
+
await instance.load(props);
|
|
104
|
+
initializedNames.push(key);
|
|
84
105
|
}
|
|
85
|
-
|
|
86
|
-
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.error(`[DI] Critical: Service "${key}" failed to initialize:`, err.message);
|
|
87
108
|
}
|
|
88
109
|
}
|
|
89
110
|
}
|
|
111
|
+
if (verbose && initializedNames.length > 0) {
|
|
112
|
+
console.log('[DI] Successfully initialized:', initializedNames);
|
|
113
|
+
}
|
|
90
114
|
return this;
|
|
91
115
|
}
|
|
92
116
|
get(target) {
|
|
117
|
+
if (!target)
|
|
118
|
+
throw new Error('[DI] Target is required for resolution');
|
|
93
119
|
const resolveName = typeof target === 'function'
|
|
94
120
|
? target.name.charAt(0).toLowerCase() + target.name.slice(1)
|
|
95
121
|
: target;
|