@xrystal/core 3.13.4 → 3.13.5

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.4",
4
+ "version": "3.13.5",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -40,9 +40,7 @@ export class X {
40
40
  const className = dependency.name;
41
41
  const name = className.charAt(0).toLowerCase() + className.slice(1);
42
42
  if (!this.isRegistered(name)) {
43
- this.container.register({
44
- [name]: asClass(dependency).singleton()
45
- });
43
+ this.container.register({ [name]: asClass(dependency).singleton() });
46
44
  if (verbose)
47
45
  console.log(`[DI] Registered: ${name}`);
48
46
  }
@@ -52,8 +50,6 @@ export class X {
52
50
  console.error(`[DI] Critical: Failed to load module at ${m.path}:`, err.message);
53
51
  }
54
52
  }
55
- if (verbose)
56
- console.log('[DI] Load completed. Total registrations:', Object.keys(this.container.registrations).length);
57
53
  return this;
58
54
  }
59
55
  register(Dependency) {
@@ -62,9 +58,7 @@ export class X {
62
58
  const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
63
59
  if (this.isRegistered(name))
64
60
  return this;
65
- this.container.register({
66
- [name]: asClass(Dependency).singleton()
67
- });
61
+ this.container.register({ [name]: asClass(Dependency).singleton() });
68
62
  return this;
69
63
  }
70
64
  registerAll(dependencies) {
@@ -77,55 +71,59 @@ export class X {
77
71
  if (!name || this.isRegistered(name))
78
72
  return this;
79
73
  const formattedName = name.charAt(0).toLowerCase() + name.slice(1);
80
- this.container.register({
81
- [formattedName]: asValue(instance)
82
- });
74
+ this.container.register({ [formattedName]: asValue(instance) });
83
75
  return this;
84
76
  }
85
77
  async initialize(input, verbose = false) {
86
78
  const cradle = this.container.cradle;
87
79
  const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
88
- const propsMap = new Map();
89
- const initializedNames = [];
90
- inputList.forEach(item => {
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);
80
+ const initializedNames = new Set();
81
+ for (const item of inputList) {
82
+ if (!item?.service)
83
+ continue;
84
+ const name = typeof item.service === 'function'
85
+ ? item.service.name.charAt(0).toLowerCase() + item.service.name.slice(1)
86
+ : item.service;
87
+ const instance = cradle[name];
88
+ if (instance && typeof instance.load === 'function') {
89
+ try {
90
+ await instance.load(item.props || {});
91
+ initializedNames.add(name);
92
+ if (verbose)
93
+ console.log(`[DI] Initialized (Priority): ${name}`);
94
+ }
95
+ catch (err) {
96
+ console.error(`[DI] Critical: Priority service "${name}" failed:`, err.message);
97
+ }
96
98
  }
97
- });
99
+ }
98
100
  for (const key of Object.keys(this.container.registrations)) {
101
+ if (initializedNames.has(key))
102
+ continue;
99
103
  const instance = cradle[key];
100
104
  if (instance && typeof instance.load === 'function') {
101
105
  try {
102
- const props = propsMap.get(key) || {};
103
- await instance.load(props);
104
- initializedNames.push(key);
106
+ await instance.load({});
107
+ initializedNames.add(key);
108
+ if (verbose)
109
+ console.log(`[DI] Initialized (Auto): ${key}`);
105
110
  }
106
111
  catch (err) {
107
- console.error(`[DI] Critical: Service "${key}" failed to initialize:`, err.message);
112
+ console.error(`[DI] Critical: Auto service "${key}" failed:`, err.message);
108
113
  }
109
114
  }
110
115
  }
111
- if (verbose && initializedNames.length > 0) {
112
- console.log('[DI] Successfully initialized:', initializedNames);
113
- }
114
116
  return this;
115
117
  }
116
118
  get(target) {
117
119
  if (!target)
118
- throw new Error('[DI] Target is required for resolution');
120
+ throw new Error('[DI] Target is required');
119
121
  const resolveName = typeof target === 'function'
120
122
  ? target.name.charAt(0).toLowerCase() + target.name.slice(1)
121
123
  : target;
122
124
  return this.container.resolve(resolveName);
123
125
  }
124
- get cradle() {
125
- return this.container.cradle;
126
- }
127
- isRegistered(name) {
128
- return !!this.container.registrations[name];
129
- }
126
+ get cradle() { return this.container.cradle; }
127
+ isRegistered(name) { return !!this.container.registrations[name]; }
130
128
  }
131
129
  export default new X();