@mxweb/core 1.0.0 → 1.0.2
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/CHANGELOG.md +82 -0
- package/dist/application.d.ts +90 -45
- package/dist/application.js +1 -1
- package/dist/application.mjs +1 -1
- package/dist/common.d.ts +149 -0
- package/dist/config.d.ts +44 -27
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/decorator.d.ts +21 -5
- package/dist/decorator.js +1 -1
- package/dist/decorator.mjs +1 -1
- package/dist/execute.d.ts +74 -22
- package/dist/execute.js +1 -1
- package/dist/execute.mjs +1 -1
- package/dist/feature.d.ts +46 -20
- package/dist/feature.js +1 -1
- package/dist/feature.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/logger.js +1 -1
- package/dist/logger.mjs +1 -1
- package/dist/service.d.ts +22 -4
- package/dist/service.js +1 -1
- package/dist/service.mjs +1 -1
- package/package.json +1 -1
package/dist/logger.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@mxweb/utils");const o={warn:"[33m",log:"[36m",error:"[31m",info:"[32m",debug:"[34m",reset:"[0m"};class
|
|
1
|
+
"use strict";var t=require("@mxweb/utils");const o={warn:"[33m",log:"[36m",error:"[31m",info:"[32m",debug:"[34m",reset:"[0m"};class e{constructor(o="@mxweb"){this.prefix=o,this.allowLog="production"!==t.getEnv("NODE_ENV")&&"false"!==t.getEnv("DEBUG")}static get instance(){return e._instance||(e._instance=new e),e._instance}static create(t){return new e(t)}isAllowLog(){return this.allowLog}formatPrefix(t){return`${o[t]}[${this.prefix}]${o.reset}`}output(t,o,e,...i){if(!this.isAllowLog())return;const s=this.formatPrefix(t);console[o](`${s} ${e}`,...i)}warn(t,...o){this.output("warn","warn",t,...o)}log(t,...o){this.output("log","log",t,...o)}error(t,...o){this.output("error","error",t,...o)}info(t,...o){this.output("info","info",t,...o)}debug(t,...o){this.output("debug","debug",t,...o)}http(t,e,i,s,r){const n=`${t} ${e} ${i>=500?o.error:i>=400?o.warn:i>=300?o.log:o.info}${i}${o.reset} - ${s} bytes in ${r}ms`;this.output("info","info",n)}timestamp(t,o,...e){if(!this.isAllowLog())return;const i=(new Date).toISOString(),s=this.formatPrefix(t);console["log"===t?"log":t](`${s} [${i}] ${o}`,...e)}json(t,o,e){if(!this.isAllowLog())return;const i=this.formatPrefix(t);console["log"===t?"log":t](`${i} ${o}:`,JSON.stringify(e,null,2))}separator(t="-",o=50){this.isAllowLog()&&console.log(t.repeat(o))}group(t,o){if(!this.isAllowLog())return;const e=this.formatPrefix("info");console.group(`${e} ${t}`),o(),console.groupEnd()}table(t,o){this.isAllowLog()&&console.table(t,o)}time(t){this.isAllowLog()&&console.time(`[${this.prefix}] ${t}`)}timeEnd(t){this.isAllowLog()&&console.timeEnd(`[${this.prefix}] ${t}`)}}const i=e.instance;exports.Logger=e,exports.logger=i;
|
package/dist/logger.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getEnv as
|
|
1
|
+
import{getEnv as o}from"@mxweb/utils";const t={warn:"[33m",log:"[36m",error:"[31m",info:"[32m",debug:"[34m",reset:"[0m"};class i{constructor(t="@mxweb"){this.prefix=t,this.allowLog="production"!==o("NODE_ENV")&&"false"!==o("DEBUG")}static get instance(){return i._instance||(i._instance=new i),i._instance}static create(o){return new i(o)}isAllowLog(){return this.allowLog}formatPrefix(o){return`${t[o]}[${this.prefix}]${t.reset}`}output(o,t,i,...s){if(!this.isAllowLog())return;const e=this.formatPrefix(o);console[t](`${e} ${i}`,...s)}warn(o,...t){this.output("warn","warn",o,...t)}log(o,...t){this.output("log","log",o,...t)}error(o,...t){this.output("error","error",o,...t)}info(o,...t){this.output("info","info",o,...t)}debug(o,...t){this.output("debug","debug",o,...t)}http(o,i,s,e,r){const n=`${o} ${i} ${s>=500?t.error:s>=400?t.warn:s>=300?t.log:t.info}${s}${t.reset} - ${e} bytes in ${r}ms`;this.output("info","info",n)}timestamp(o,t,...i){if(!this.isAllowLog())return;const s=(new Date).toISOString(),e=this.formatPrefix(o);console["log"===o?"log":o](`${e} [${s}] ${t}`,...i)}json(o,t,i){if(!this.isAllowLog())return;const s=this.formatPrefix(o);console["log"===o?"log":o](`${s} ${t}:`,JSON.stringify(i,null,2))}separator(o="-",t=50){this.isAllowLog()&&console.log(o.repeat(t))}group(o,t){if(!this.isAllowLog())return;const i=this.formatPrefix("info");console.group(`${i} ${o}`),t(),console.groupEnd()}table(o,t){this.isAllowLog()&&console.table(o,t)}time(o){this.isAllowLog()&&console.time(`[${this.prefix}] ${o}`)}timeEnd(o){this.isAllowLog()&&console.timeEnd(`[${this.prefix}] ${o}`)}}const s=i.instance;export{i as Logger,s as logger};
|
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
|
|
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
|
|
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
|
|
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