@xrystal/core 3.13.6 → 3.13.7

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.13.6",
4
+ "version": "3.13.7",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -6,7 +6,6 @@ export declare class X {
6
6
  register(Dependency: any): this;
7
7
  registerAll(dependencies: any[]): this;
8
8
  registerInstance(name: string, instance: any): this;
9
- remove(target: string | any): this;
10
9
  initialize(input?: {
11
10
  service: any;
12
11
  props?: any;
@@ -10,21 +10,39 @@ export class X {
10
10
  });
11
11
  }
12
12
  load(patterns, verbose = false) {
13
- if (!patterns || (Array.isArray(patterns) && patterns.length === 0))
13
+ if (!patterns) {
14
+ if (verbose)
15
+ console.warn('[DI] load() çağrıldı ama patterns undefined.');
14
16
  return this;
17
+ }
15
18
  const cwd = process.cwd();
16
- const resolvedPatterns = (Array.isArray(patterns) ? patterns : [patterns])
17
- .filter(p => typeof p === 'string')
18
- .map(p => {
19
- const resolved = path.isAbsolute(p) ? p : path.resolve(cwd, p);
20
- return resolved.replace(/\\/g, '/');
21
- });
19
+ if (!cwd) {
20
+ console.error('[DI] Critical: process.cwd() undefined döndü!');
21
+ return this;
22
+ }
23
+ const input = Array.isArray(patterns) ? patterns : [patterns];
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;
22
40
  let modules = [];
23
41
  try {
24
42
  modules = listModules(resolvedPatterns);
25
43
  }
26
44
  catch (err) {
27
- console.error(`[DI] Critical: Path resolution failed: ${err.message}`);
45
+ console.error(`[DI] Critical: listModules patladı. Patternlar:`, resolvedPatterns, err.message);
28
46
  return this;
29
47
  }
30
48
  for (const m of modules) {
@@ -48,14 +66,16 @@ export class X {
48
66
  }
49
67
  }
50
68
  catch (err) {
51
- console.error(`[DI] Critical: Failed to load module at ${m.path}:`, err.message);
69
+ console.error(`[DI] Critical: Modül yüklenemedi (${m.path}):`, err.message);
52
70
  }
53
71
  }
54
72
  return this;
55
73
  }
56
74
  register(Dependency) {
57
- if (!Dependency?.name)
75
+ if (!Dependency || !Dependency.name) {
76
+ console.error('[DI] register() başarısız: Geçersiz sınıf.', Dependency);
58
77
  return this;
78
+ }
59
79
  const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
60
80
  if (this.isRegistered(name))
61
81
  return this;
@@ -69,46 +89,38 @@ export class X {
69
89
  return this;
70
90
  }
71
91
  registerInstance(name, instance) {
72
- if (!name)
92
+ if (!name) {
93
+ console.error('[DI] registerInstance() başarısız: İsim boş.');
73
94
  return this;
95
+ }
74
96
  const formattedName = name.charAt(0).toLowerCase() + name.slice(1);
75
97
  if (this.isRegistered(formattedName))
76
98
  return this;
77
99
  this.container.register({ [formattedName]: asValue(instance) });
78
100
  return this;
79
101
  }
80
- remove(target) {
81
- const name = typeof target === 'function'
82
- ? target.name.charAt(0).toLowerCase() + target.name.slice(1)
83
- : target;
84
- this.container.register(name, asValue(undefined));
85
- this.initializedNames.delete(name);
86
- return this;
87
- }
88
102
  async initialize(input, verbose = false) {
89
103
  const cradle = this.container.cradle;
90
104
  const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
91
105
  for (const item of inputList) {
92
- if (!item?.service)
106
+ if (!item || !item.service)
93
107
  continue;
94
108
  const name = typeof item.service === 'function'
95
109
  ? item.service.name.charAt(0).toLowerCase() + item.service.name.slice(1)
96
110
  : item.service;
97
- if (this.initializedNames.has(name))
111
+ if (!name || this.initializedNames.has(name))
98
112
  continue;
99
113
  const instance = cradle[name];
100
- if (instance) {
101
- if (typeof instance.load === 'function') {
102
- try {
103
- await instance.load(item.props || {});
104
- if (verbose)
105
- console.log(`[DI] Initialized (Priority): ${name}`);
106
- }
107
- catch (err) {
108
- console.error(`[DI] Critical: Priority service "${name}" failed:`, err.message);
109
- }
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);
110
123
  }
111
- this.initializedNames.add(name);
112
124
  }
113
125
  }
114
126
  for (const key of Object.keys(this.container.registrations)) {
@@ -118,6 +130,7 @@ export class X {
118
130
  if (instance && typeof instance.load === 'function') {
119
131
  try {
120
132
  await instance.load({});
133
+ this.initializedNames.add(key);
121
134
  if (verbose)
122
135
  console.log(`[DI] Initialized (Auto): ${key}`);
123
136
  }
@@ -125,13 +138,12 @@ export class X {
125
138
  console.error(`[DI] Critical: Auto service "${key}" failed:`, err.message);
126
139
  }
127
140
  }
128
- this.initializedNames.add(key);
129
141
  }
130
142
  return this;
131
143
  }
132
144
  get(target) {
133
145
  if (!target)
134
- throw new Error('[DI] Target is required');
146
+ throw new Error('[DI] get() çağrıldı ama hedef (target) undefined.');
135
147
  const resolveName = typeof target === 'function'
136
148
  ? target.name.charAt(0).toLowerCase() + target.name.slice(1)
137
149
  : target;