@xrystal/core 3.21.0 → 3.21.1

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.21.0",
4
+ "version": "3.21.1",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,5 +1,6 @@
1
1
  export declare abstract class ILifeCycle<T = any> {
2
2
  load(props?: T | {}): Promise<void>;
3
+ ready?(_context?: any): Promise<void> | void;
3
4
  dispose?(_context?: any): Promise<void> | void;
4
5
  }
5
6
  export declare abstract class IService<T = any> extends ILifeCycle<T> {
@@ -1,6 +1,8 @@
1
1
  export class ILifeCycle {
2
2
  async load(props = {}) {
3
3
  }
4
+ ready(_context) {
5
+ }
4
6
  dispose(_context) {
5
7
  }
6
8
  }
@@ -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 XHelper {
5
+ declare abstract class X {
5
6
  protected checkRegistration(container: AwilixContainer, name: string): boolean;
6
7
  }
7
- declare class X extends XHelper {
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: X;
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
- class XHelper {
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 X extends XHelper {
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,10 +105,8 @@ 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
109
  if (instance && typeof instance.load === 'function') {
111
- // Burada await ediyoruz, yani bu servis bitmeden döngü ilerlemez
112
110
  await instance.load(item.props || {});
113
111
  }
114
112
  this.initializedNames.add(name);
@@ -118,7 +116,6 @@ class X extends XHelper {
118
116
  console.error(`[DI] Priority Init 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))
@@ -138,6 +135,18 @@ class X extends XHelper {
138
135
  console.error(`[DI] Auto Init Failed (${key}):`, err.message);
139
136
  }
140
137
  }
138
+ for (const name of this.initializedNames) {
139
+ try {
140
+ const instance = this.container.cradle[name];
141
+ if (instance && typeof instance.ready === 'function') {
142
+ await instance.afterInit();
143
+ }
144
+ }
145
+ catch (err) {
146
+ if (verbose)
147
+ console.error(`[DI] afterInit Hook Failed (${name}):`, err.message);
148
+ }
149
+ }
141
150
  }
142
151
  finally {
143
152
  this.isInitializing = false;
@@ -153,9 +162,7 @@ class X extends XHelper {
153
162
  }
154
163
  get cradle() { return this.container.cradle; }
155
164
  }
156
- const X_SYMBOL = Symbol.for('X');
157
- const globalObj = global;
158
- if (!globalObj[X_SYMBOL]) {
159
- globalObj[X_SYMBOL] = new X();
165
+ if (!global[xSymbol]) {
166
+ global[xSymbol] = new DIM();
160
167
  }
161
- export default globalObj[X_SYMBOL];
168
+ export default global[xSymbol];