@xrystal/core 3.13.7 → 3.14.0
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
package/source/project/index.js
CHANGED
|
@@ -19,7 +19,11 @@ const coreLoader = async ({}) => {
|
|
|
19
19
|
x
|
|
20
20
|
.load([
|
|
21
21
|
path.join(__dirname, '..', 'loader', '**/*.{ts,js}'),
|
|
22
|
-
],
|
|
22
|
+
], {
|
|
23
|
+
exclude: [
|
|
24
|
+
path.join(__dirname, '..', 'utils', '**/class.x.{ts,js}'),
|
|
25
|
+
]
|
|
26
|
+
})
|
|
23
27
|
.initialize([
|
|
24
28
|
{
|
|
25
29
|
service: SystemService,
|
|
@@ -2,7 +2,11 @@ export declare class X {
|
|
|
2
2
|
private container;
|
|
3
3
|
private initializedNames;
|
|
4
4
|
constructor();
|
|
5
|
-
|
|
5
|
+
private getSource;
|
|
6
|
+
load(patterns: string | string[], options?: {
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
exclude?: string | Function | (string | Function)[];
|
|
9
|
+
}): this;
|
|
6
10
|
register(Dependency: any): this;
|
|
7
11
|
registerAll(dependencies: any[]): this;
|
|
8
12
|
registerInstance(name: string, instance: any): this;
|
|
@@ -9,43 +9,29 @@ export class X {
|
|
|
9
9
|
strict: true
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
getSource(filePath) {
|
|
13
|
+
const projectRoot = process.cwd().replace(/\\/g, '/');
|
|
14
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
15
|
+
return normalizedPath.includes('node_modules') || !normalizedPath.startsWith(projectRoot) ? 'LIB' : 'APP';
|
|
16
|
+
}
|
|
17
|
+
load(patterns, options = {}) {
|
|
18
|
+
const { verbose = false, exclude = [] } = options;
|
|
18
19
|
const cwd = process.cwd();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const resolvedPatterns = [];
|
|
25
|
-
for (const p of input) {
|
|
26
|
-
if (typeof p !== 'string') {
|
|
27
|
-
console.error(`[DI] Critical: load() metoduna geçersiz path gönderildi. Beklenen: string, Gelen: ${typeof p}`, p);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const resolved = path.isAbsolute(p) ? p : path.resolve(cwd, p);
|
|
32
|
-
resolvedPatterns.push(resolved.replace(/\\/g, '/'));
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
console.error(`[DI] Path resolve hatası (${p}):`, err.message);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (resolvedPatterns.length === 0)
|
|
39
|
-
return this;
|
|
20
|
+
const excludeList = Array.isArray(exclude) ? exclude : [exclude];
|
|
21
|
+
const resolvedPatterns = (Array.isArray(patterns) ? patterns : [patterns]).map(p => {
|
|
22
|
+
const resolved = path.isAbsolute(p) ? p : path.resolve(cwd, p);
|
|
23
|
+
return resolved.replace(/\\/g, '/');
|
|
24
|
+
});
|
|
40
25
|
let modules = [];
|
|
41
26
|
try {
|
|
42
27
|
modules = listModules(resolvedPatterns);
|
|
43
28
|
}
|
|
44
29
|
catch (err) {
|
|
45
|
-
console.error(`[DI]
|
|
30
|
+
console.error(`[DI][CRITICAL] Path resolution failed: ${err.message}`);
|
|
46
31
|
return this;
|
|
47
32
|
}
|
|
48
33
|
for (const m of modules) {
|
|
34
|
+
const source = this.getSource(m.path);
|
|
49
35
|
if (m.path === __filename || m.path.endsWith('.d.ts') || m.path.endsWith('.map'))
|
|
50
36
|
continue;
|
|
51
37
|
try {
|
|
@@ -54,6 +40,20 @@ export class X {
|
|
|
54
40
|
if (!dependency) {
|
|
55
41
|
dependency = Object.values(loaded).find(val => typeof val === 'function' && !!val.prototype && !!val.name);
|
|
56
42
|
}
|
|
43
|
+
const isExcluded = excludeList.some(ex => {
|
|
44
|
+
if (typeof ex === 'string') {
|
|
45
|
+
return m.path.includes(ex) || m.name === ex;
|
|
46
|
+
}
|
|
47
|
+
if (typeof ex === 'function') {
|
|
48
|
+
return dependency === ex;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
});
|
|
52
|
+
if (isExcluded) {
|
|
53
|
+
if (verbose)
|
|
54
|
+
console.log(`[DI][${source}] Excluded: ${m.name}`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
57
|
const isClass = typeof dependency === 'function' && !!dependency.prototype && !!dependency.name;
|
|
58
58
|
if (isClass) {
|
|
59
59
|
const className = dependency.name;
|
|
@@ -61,21 +61,19 @@ export class X {
|
|
|
61
61
|
if (!this.isRegistered(name)) {
|
|
62
62
|
this.container.register({ [name]: asClass(dependency).singleton() });
|
|
63
63
|
if (verbose)
|
|
64
|
-
console.log(`[DI] Registered: ${name}`);
|
|
64
|
+
console.log(`[DI][${source}] Registered: ${name}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
69
|
-
console.error(`[DI]
|
|
69
|
+
console.error(`[DI][${source}] Load Error in ${m.name}:`, err.message);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
74
|
register(Dependency) {
|
|
75
|
-
if (!Dependency
|
|
76
|
-
console.error('[DI] register() başarısız: Geçersiz sınıf.', Dependency);
|
|
75
|
+
if (!Dependency?.name)
|
|
77
76
|
return this;
|
|
78
|
-
}
|
|
79
77
|
const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
|
|
80
78
|
if (this.isRegistered(name))
|
|
81
79
|
return this;
|
|
@@ -83,16 +81,13 @@ export class X {
|
|
|
83
81
|
return this;
|
|
84
82
|
}
|
|
85
83
|
registerAll(dependencies) {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
dependencies.forEach(dep => this.register(dep));
|
|
84
|
+
if (Array.isArray(dependencies))
|
|
85
|
+
dependencies.forEach(dep => this.register(dep));
|
|
89
86
|
return this;
|
|
90
87
|
}
|
|
91
88
|
registerInstance(name, instance) {
|
|
92
|
-
if (!name)
|
|
93
|
-
console.error('[DI] registerInstance() başarısız: İsim boş.');
|
|
89
|
+
if (!name)
|
|
94
90
|
return this;
|
|
95
|
-
}
|
|
96
91
|
const formattedName = name.charAt(0).toLowerCase() + name.slice(1);
|
|
97
92
|
if (this.isRegistered(formattedName))
|
|
98
93
|
return this;
|
|
@@ -102,52 +97,45 @@ export class X {
|
|
|
102
97
|
async initialize(input, verbose = false) {
|
|
103
98
|
const cradle = this.container.cradle;
|
|
104
99
|
const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
|
|
100
|
+
const propsMap = new Map();
|
|
105
101
|
for (const item of inputList) {
|
|
106
|
-
if (!item
|
|
102
|
+
if (!item?.service)
|
|
107
103
|
continue;
|
|
108
|
-
const name = typeof item.service === 'function'
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (!name || this.initializedNames.has(name))
|
|
112
|
-
continue;
|
|
113
|
-
const instance = cradle[name];
|
|
114
|
-
if (instance && typeof instance.load === 'function') {
|
|
115
|
-
try {
|
|
116
|
-
await instance.load(item.props || {});
|
|
117
|
-
this.initializedNames.add(name);
|
|
118
|
-
if (verbose)
|
|
119
|
-
console.log(`[DI] Initialized (Priority): ${name}`);
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
console.error(`[DI] Critical: Priority service "${name}" failed:`, err.message);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
104
|
+
const name = typeof item.service === 'function' ? item.service.name.charAt(0).toLowerCase() + item.service.name.slice(1) : item.service;
|
|
105
|
+
if (name)
|
|
106
|
+
propsMap.set(name, item.props);
|
|
125
107
|
}
|
|
126
|
-
|
|
108
|
+
const registrationKeys = Object.keys(this.container.registrations);
|
|
109
|
+
const allKeys = new Set([...propsMap.keys(), ...registrationKeys]);
|
|
110
|
+
for (const key of allKeys) {
|
|
127
111
|
if (this.initializedNames.has(key))
|
|
128
112
|
continue;
|
|
129
113
|
const instance = cradle[key];
|
|
130
114
|
if (instance && typeof instance.load === 'function') {
|
|
115
|
+
const source = instance.constructor && instance.constructor.name ? 'APP' : 'LIB';
|
|
131
116
|
try {
|
|
132
|
-
|
|
117
|
+
const props = propsMap.get(key) || {};
|
|
118
|
+
await instance.load(props);
|
|
133
119
|
this.initializedNames.add(key);
|
|
134
120
|
if (verbose)
|
|
135
|
-
console.log(`[DI] Initialized
|
|
121
|
+
console.log(`[DI][${source}] Initialized: ${key}`);
|
|
136
122
|
}
|
|
137
123
|
catch (err) {
|
|
138
|
-
console.error(`[DI]
|
|
124
|
+
console.error(`[DI][${source}] Initialization Failed: ${key} ->`, err.message);
|
|
139
125
|
}
|
|
140
126
|
}
|
|
141
127
|
}
|
|
142
128
|
return this;
|
|
143
129
|
}
|
|
144
130
|
get(target) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
131
|
+
try {
|
|
132
|
+
const resolveName = typeof target === 'function' ? target.name.charAt(0).toLowerCase() + target.name.slice(1) : target;
|
|
133
|
+
return this.container.resolve(resolveName);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
console.error(`[DI][ERROR] Resolution Failed:`, err.message);
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
151
139
|
}
|
|
152
140
|
get cradle() { return this.container.cradle; }
|
|
153
141
|
isRegistered(name) {
|