@mxweb/core 1.0.0 → 1.0.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/dist/service.d.ts CHANGED
@@ -128,24 +128,42 @@ declare class BaseService {
128
128
  */
129
129
  protected get context(): ExecuteContext;
130
130
  /**
131
- * Gets an application-level inject by name.
131
+ * Gets an application-level inject by name (async with lazy initialization).
132
132
  *
133
133
  * @typeParam T - The type of the inject (defaults to ApplicationInject)
134
134
  * @param name - The name of the inject to retrieve
135
- * @returns The inject instance or undefined if not found
135
+ * @returns Promise resolving to the inject instance or undefined if not found
136
136
  *
137
137
  * @example
138
138
  * ```ts
139
139
  * class MyService extends Service {
140
140
  * async query(sql: string) {
141
- * const db = this.getInject<Database>("db");
141
+ * const db = await this.getInject<Database>("db");
142
142
  * if (!db) throw new Error("Database not configured");
143
143
  * return db.query(sql);
144
144
  * }
145
145
  * }
146
146
  * ```
147
147
  */
148
- protected getInject<T extends ApplicationInject = ApplicationInject>(name: string): T | undefined;
148
+ protected getInject<T extends ApplicationInject = ApplicationInject>(name: string): Promise<T | undefined>;
149
+ /**
150
+ * Gets an application-level inject by name (sync, must be already initialized).
151
+ *
152
+ * @typeParam T - The type of the inject (defaults to ApplicationInject)
153
+ * @param name - The name of the inject to retrieve
154
+ * @returns The inject instance or undefined if not found/initialized
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * class MyService extends Service {
159
+ * formatData() {
160
+ * const formatter = this.getInjectSync<Formatter>("formatter");
161
+ * return formatter?.format(this.data);
162
+ * }
163
+ * }
164
+ * ```
165
+ */
166
+ protected getInjectSync<T extends ApplicationInject = ApplicationInject>(name: string): T | undefined;
149
167
  /**
150
168
  * Initializes async dependencies for this service.
151
169
  *
package/dist/service.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("./context.js");const e=new WeakMap;class i{constructor(){this._initialized=!1}get context(){return t.executeContext}getInject(e){return t.executeContext.getInject(e)}async _initDependencies(){if(this._initialized)return;const i=this.constructor.injectMap;if(!i)return void(this._initialized=!0);let n;e.has(this.constructor)?n=e.get(this.constructor):(n="function"==typeof i?await i(t.executeContext.injections):i,e.set(this.constructor,n));for(const[t,e]of Object.entries(n))this[t]=e;this._initialized=!0}}const n=i;exports.Service=n,exports.service=function(t){var e;return(e=class extends i{}).injectMap=t,e};
1
+ "use strict";var t=require("./context.js");const e=new WeakMap;class n{constructor(){this._initialized=!1}get context(){return t.executeContext}getInject(e){return t.executeContext.getInject(e)}getInjectSync(e){return t.executeContext.getInjectSync(e)}async _initDependencies(){if(this._initialized)return;const n=this.constructor.injectMap;if(!n)return void(this._initialized=!0);let i;e.has(this.constructor)?i=e.get(this.constructor):(i="function"==typeof n?await n(t.executeContext.injections):n,e.set(this.constructor,i));for(const[t,e]of Object.entries(i))this[t]=e;this._initialized=!0}}const i=n;exports.Service=i,exports.service=function(t){var e;return(e=class extends n{}).injectMap=t,e};
package/dist/service.mjs CHANGED
@@ -1 +1 @@
1
- import{executeContext as t}from"./context.mjs";const i=new WeakMap;class n{constructor(){this._initialized=!1}get context(){return t}getInject(i){return t.getInject(i)}async _initDependencies(){if(this._initialized)return;const n=this.constructor.injectMap;if(!n)return void(this._initialized=!0);let e;i.has(this.constructor)?e=i.get(this.constructor):(e="function"==typeof n?await n(t.injections):n,i.set(this.constructor,e));for(const[t,i]of Object.entries(e))this[t]=i;this._initialized=!0}}function e(t){var i;return(i=class extends n{}).injectMap=t,i}const s=n;export{s as Service,e as service};
1
+ import{executeContext as t}from"./context.mjs";const n=new WeakMap;class e{constructor(){this._initialized=!1}get context(){return t}getInject(n){return t.getInject(n)}getInjectSync(n){return t.getInjectSync(n)}async _initDependencies(){if(this._initialized)return;const e=this.constructor.injectMap;if(!e)return void(this._initialized=!0);let i;n.has(this.constructor)?i=n.get(this.constructor):(i="function"==typeof e?await e(t.injections):e,n.set(this.constructor,i));for(const[t,n]of Object.entries(i))this[t]=n;this._initialized=!0}}function i(t){var n;return(n=class extends e{}).injectMap=t,n}const c=e;export{c as Service,i as service};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxweb/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A NestJS-inspired backend framework for Next.js App Router with dependency injection, guards, interceptors, and modular architecture",
5
5
  "keywords": [
6
6
  "nextjs",