@mxweb/core 1.0.2 → 1.2.0

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/feature.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  import { ControllerConstructor } from "./controller";
11
11
  import { RouteMatched, Router } from "./router";
12
12
  import { FeatureHooks, FeatureHooksOptions } from "./hooks";
13
- import { FeatureInject, FeatureInjectFactory, RouteMethod } from "./common";
13
+ import { DecoratorOptions, FeatureInjectFactory, Filter, Guard, Interceptor, Pipe, RouteMethod } from "./common";
14
14
  /**
15
15
  * Type for feature-specific dependency injection configuration.
16
16
  * Array of factory functions that register injects.
@@ -41,7 +41,7 @@ export type FeatureInjects = FeatureInjectFactory[];
41
41
  export type FeatureImports = unknown[] | (() => unknown[]) | (() => Promise<unknown[]>);
42
42
  /**
43
43
  * Configuration options for creating a Feature.
44
- * Extends FeatureHooksOptions for lifecycle hooks.
44
+ * Extends FeatureHooksOptions for lifecycle hooks and DecoratorOptions for guards/filters/interceptors/pipes.
45
45
  *
46
46
  * @example
47
47
  * ```ts
@@ -52,13 +52,17 @@ export type FeatureImports = unknown[] | (() => unknown[]) | (() => Promise<unkn
52
52
  * Route.post("/products", "create"),
53
53
  * ),
54
54
  * imports: [Connection.forFeature([ProductEntity])],
55
- * injects: { productRepo: new ProductRepository() },
55
+ * injects: [(registry) => registry.set("productRepo", () => new ProductRepository())],
56
+ * guards: [AuthGuard],
57
+ * filters: [HttpExceptionFilter],
58
+ * interceptors: [LoggingInterceptor],
59
+ * pipes: [ValidationPipe],
56
60
  * onStart: () => console.log("Product feature started"),
57
61
  * onRequest: (ctx) => console.log("Product feature request"),
58
62
  * };
59
63
  * ```
60
64
  */
61
- export interface FeatureInitialize extends FeatureHooksOptions {
65
+ export interface FeatureInitialize extends FeatureHooksOptions, DecoratorOptions {
62
66
  /** The controller class that handles requests for this feature */
63
67
  controller: ControllerConstructor<any>;
64
68
  /** Router with registered routes for this feature */
@@ -148,6 +152,14 @@ export declare class Feature {
148
152
  private factoriesRegistered;
149
153
  /** Flag indicating if imports have been loaded */
150
154
  private importsLoaded;
155
+ /** Feature-level guards */
156
+ private guards;
157
+ /** Feature-level exception filters */
158
+ private filters;
159
+ /** Feature-level interceptors */
160
+ private interceptors;
161
+ /** Feature-level pipes */
162
+ private pipes;
151
163
  /**
152
164
  * Private constructor - use Feature.create() to instantiate.
153
165
  *
@@ -208,25 +220,27 @@ export declare class Feature {
208
220
  /**
209
221
  * Retrieves a feature-specific inject by name (async - lazy initialization).
210
222
  * If instance doesn't exist, calls factory to create it and runs onFeature().
223
+ * Returns the result of switch() if available, otherwise the raw instance.
211
224
  *
212
- * @template T - Expected type of the inject (must extend FeatureInject)
225
+ * @template T - Expected return type (from switch() or the inject itself)
213
226
  * @param name - The name of the inject to retrieve
214
- * @returns Promise resolving to the inject instance or undefined if not found
227
+ * @returns Promise resolving to the switched value or undefined if not found
215
228
  *
216
229
  * @example
217
230
  * ```ts
218
231
  * const repo = await feature.getInject<ProductRepository>("productRepo");
219
232
  * ```
220
233
  */
221
- getInject<T extends FeatureInject>(name: string): Promise<T | undefined>;
234
+ getInject<T = unknown>(name: string): Promise<T | undefined>;
222
235
  /**
223
236
  * Retrieves a feature-specific inject synchronously (only if already initialized).
237
+ * Returns the result of switch() if available, otherwise the raw instance.
224
238
  *
225
- * @template T - Expected type of the inject (must extend FeatureInject)
239
+ * @template T - Expected return type (from switch() or the inject itself)
226
240
  * @param name - The name of the inject to retrieve
227
- * @returns The inject instance or undefined if not found/not initialized
241
+ * @returns The switched value or undefined if not found/not initialized
228
242
  */
229
- getInjectSync<T extends FeatureInject>(name: string): T | undefined;
243
+ getInjectSync<T = unknown>(name: string): T | undefined;
230
244
  /**
231
245
  * Checks if a feature-specific inject factory is registered by name.
232
246
  *
@@ -254,6 +268,30 @@ export declare class Feature {
254
268
  * @returns The FeatureHooks instance
255
269
  */
256
270
  getHooks(): FeatureHooks;
271
+ /**
272
+ * Returns the feature-level guards.
273
+ *
274
+ * @returns Set of guard classes for this feature
275
+ */
276
+ getGuards(): Set<Guard>;
277
+ /**
278
+ * Returns the feature-level exception filters.
279
+ *
280
+ * @returns Set of filter classes for this feature
281
+ */
282
+ getFilters(): Set<Filter>;
283
+ /**
284
+ * Returns the feature-level interceptors.
285
+ *
286
+ * @returns Set of interceptor classes for this feature
287
+ */
288
+ getInterceptors(): Set<Interceptor>;
289
+ /**
290
+ * Returns the feature-level pipes.
291
+ *
292
+ * @returns Set of pipe classes for this feature
293
+ */
294
+ getPipes(): Set<Pipe>;
257
295
  /**
258
296
  * Attempts to match a request against this feature's routes.
259
297
  *
package/dist/feature.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("./hooks.js");class e{constructor(e,s,i){this.options=e,this.ControllerContructor=s,this.router=i,this.routeMatched=null,this.controller=null,this.injects=new Map,this.factoriesRegistered=!1,this.importsLoaded=!1,this.hooks=new t.FeatureHooks(this.options),this.registry=this.createInjectRegistry()}createInjectRegistry(){return{get:t=>this.getInject(t),set:(t,e)=>{this.injects.set(t,{factory:e})}}}static create(t){return new e(t,t.controller,t.router)}async loadImports(){if(this.importsLoaded)return;this.importsLoaded=!0;const{imports:t}=this.options;if(!t)return;"function"==typeof t&&await t()}async loadInjects(){if(await this.loadImports(),this.factoriesRegistered)return;this.factoriesRegistered=!0;const{injects:t}=this.options;if(t&&t.length)for(const e of t)await e(this.registry)}async destroyInjects(){for(const[t,e]of this.injects)if(e.instance&&e.instance.onFeatureDestroy)try{await e.instance.onFeatureDestroy()}catch(t){}this.injects.clear(),this.factoriesRegistered=!1}async getInject(t){const e=this.injects.get(t);if(e)return e.instance||(e.instance=await e.factory(this.registry),"function"==typeof e.instance.onFeature&&await e.instance.onFeature()),e.instance}getInjectSync(t){const e=this.injects.get(t);return e?.instance}hasInject(t){return this.injects.has(t)}isInjectInitialized(t){const e=this.injects.get(t);return!!e?.instance}getController(){if(!this.controller){const t=this.ControllerContructor;this.controller=new t}return this.controller}getHooks(){return this.hooks}matchRoute(t,e){return this.routeMatched=this.router.match(t,e),this.routeMatched}}exports.Feature=e;
1
+ "use strict";var t=require("./hooks.js");class e{constructor(e,s,i){this.options=e,this.ControllerContructor=s,this.router=i,this.routeMatched=null,this.controller=null,this.injects=new Map,this.factoriesRegistered=!1,this.importsLoaded=!1,this.guards=new Set,this.filters=new Set,this.interceptors=new Set,this.pipes=new Set,this.hooks=new t.FeatureHooks(this.options),this.registry=this.createInjectRegistry(),e.guards&&e.guards.forEach(t=>this.guards.add(t)),e.filters&&e.filters.forEach(t=>this.filters.add(t)),e.interceptors&&e.interceptors.forEach(t=>this.interceptors.add(t)),e.pipes&&e.pipes.forEach(t=>this.pipes.add(t))}createInjectRegistry(){return{get:t=>this.getInject(t),set:(t,e)=>{this.injects.set(t,{factory:e})}}}static create(t){return new e(t,t.controller,t.router)}async loadImports(){if(this.importsLoaded)return;this.importsLoaded=!0;const{imports:t}=this.options;if(!t)return;"function"==typeof t&&await t()}async loadInjects(){if(await this.loadImports(),this.factoriesRegistered)return;this.factoriesRegistered=!0;const{injects:t}=this.options;if(t&&t.length)for(const e of t)await e(this.registry)}async destroyInjects(){for(const[t,e]of this.injects)if(e.instance&&e.instance.onFeatureDestroy)try{await e.instance.onFeatureDestroy()}catch(t){}this.injects.clear(),this.factoriesRegistered=!1}async getInject(t){const e=this.injects.get(t);if(e)return e.instance||(e.instance=await e.factory(this.registry),"function"==typeof e.instance.onFeature&&await e.instance.onFeature()),"function"==typeof e.instance.switch?e.instance.switch():e.instance}getInjectSync(t){const e=this.injects.get(t);if(e?.instance)return"function"==typeof e.instance.switch?e.instance.switch():e.instance}hasInject(t){return this.injects.has(t)}isInjectInitialized(t){const e=this.injects.get(t);return!!e?.instance}getController(){if(!this.controller){const t=this.ControllerContructor;this.controller=new t}return this.controller}getHooks(){return this.hooks}getGuards(){return this.guards}getFilters(){return this.filters}getInterceptors(){return this.interceptors}getPipes(){return this.pipes}matchRoute(t,e){return this.routeMatched=this.router.match(t,e),this.routeMatched}}exports.Feature=e;
package/dist/feature.mjs CHANGED
@@ -1 +1 @@
1
- import{FeatureHooks as t}from"./hooks.mjs";class e{constructor(e,s,i){this.options=e,this.ControllerContructor=s,this.router=i,this.routeMatched=null,this.controller=null,this.injects=new Map,this.factoriesRegistered=!1,this.importsLoaded=!1,this.hooks=new t(this.options),this.registry=this.createInjectRegistry()}createInjectRegistry(){return{get:t=>this.getInject(t),set:(t,e)=>{this.injects.set(t,{factory:e})}}}static create(t){return new e(t,t.controller,t.router)}async loadImports(){if(this.importsLoaded)return;this.importsLoaded=!0;const{imports:t}=this.options;if(!t)return;"function"==typeof t&&await t()}async loadInjects(){if(await this.loadImports(),this.factoriesRegistered)return;this.factoriesRegistered=!0;const{injects:t}=this.options;if(t&&t.length)for(const e of t)await e(this.registry)}async destroyInjects(){for(const[t,e]of this.injects)if(e.instance&&e.instance.onFeatureDestroy)try{await e.instance.onFeatureDestroy()}catch(t){}this.injects.clear(),this.factoriesRegistered=!1}async getInject(t){const e=this.injects.get(t);if(e)return e.instance||(e.instance=await e.factory(this.registry),"function"==typeof e.instance.onFeature&&await e.instance.onFeature()),e.instance}getInjectSync(t){const e=this.injects.get(t);return e?.instance}hasInject(t){return this.injects.has(t)}isInjectInitialized(t){const e=this.injects.get(t);return!!e?.instance}getController(){if(!this.controller){const t=this.ControllerContructor;this.controller=new t}return this.controller}getHooks(){return this.hooks}matchRoute(t,e){return this.routeMatched=this.router.match(t,e),this.routeMatched}}export{e as Feature};
1
+ import{FeatureHooks as t}from"./hooks.mjs";class e{constructor(e,s,i){this.options=e,this.ControllerContructor=s,this.router=i,this.routeMatched=null,this.controller=null,this.injects=new Map,this.factoriesRegistered=!1,this.importsLoaded=!1,this.guards=new Set,this.filters=new Set,this.interceptors=new Set,this.pipes=new Set,this.hooks=new t(this.options),this.registry=this.createInjectRegistry(),e.guards&&e.guards.forEach(t=>this.guards.add(t)),e.filters&&e.filters.forEach(t=>this.filters.add(t)),e.interceptors&&e.interceptors.forEach(t=>this.interceptors.add(t)),e.pipes&&e.pipes.forEach(t=>this.pipes.add(t))}createInjectRegistry(){return{get:t=>this.getInject(t),set:(t,e)=>{this.injects.set(t,{factory:e})}}}static create(t){return new e(t,t.controller,t.router)}async loadImports(){if(this.importsLoaded)return;this.importsLoaded=!0;const{imports:t}=this.options;if(!t)return;"function"==typeof t&&await t()}async loadInjects(){if(await this.loadImports(),this.factoriesRegistered)return;this.factoriesRegistered=!0;const{injects:t}=this.options;if(t&&t.length)for(const e of t)await e(this.registry)}async destroyInjects(){for(const[t,e]of this.injects)if(e.instance&&e.instance.onFeatureDestroy)try{await e.instance.onFeatureDestroy()}catch(t){}this.injects.clear(),this.factoriesRegistered=!1}async getInject(t){const e=this.injects.get(t);if(e)return e.instance||(e.instance=await e.factory(this.registry),"function"==typeof e.instance.onFeature&&await e.instance.onFeature()),"function"==typeof e.instance.switch?e.instance.switch():e.instance}getInjectSync(t){const e=this.injects.get(t);if(e?.instance)return"function"==typeof e.instance.switch?e.instance.switch():e.instance}hasInject(t){return this.injects.has(t)}isInjectInitialized(t){const e=this.injects.get(t);return!!e?.instance}getController(){if(!this.controller){const t=this.ControllerContructor;this.controller=new t}return this.controller}getHooks(){return this.hooks}getGuards(){return this.guards}getFilters(){return this.filters}getInterceptors(){return this.interceptors}getPipes(){return this.pipes}matchRoute(t,e){return this.routeMatched=this.router.match(t,e),this.routeMatched}}export{e as Feature};
package/dist/hooks.d.ts CHANGED
@@ -9,9 +9,8 @@
9
9
  *
10
10
  * @module hooks
11
11
  */
12
- import { NextRequest } from "next/server";
13
12
  import { RouteMethod } from "./common";
14
- import type { RequestContext } from "./execute";
13
+ import type { CoreRequest, RequestContext } from "./execute";
15
14
  /**
16
15
  * Configuration options for Application-level lifecycle hooks.
17
16
  *
@@ -48,10 +47,10 @@ export interface ApplicationHooksOptions {
48
47
  * No full context is available - only the raw request and method.
49
48
  * Use for early request logging, global rate limiting, etc.
50
49
  *
51
- * @param req - The incoming Next.js request
50
+ * @param req - The incoming request
52
51
  * @param method - The HTTP method of the request
53
52
  */
54
- onRequest?(req: NextRequest, method: RouteMethod): void | Promise<void>;
53
+ onRequest?(req: CoreRequest, method: RouteMethod): void | Promise<void>;
55
54
  /**
56
55
  * Called on every request AFTER the route handler completes.
57
56
  * Full request context is available.
@@ -223,10 +222,10 @@ export declare class RequestHooks {
223
222
  * Executes the Application onRequest hook.
224
223
  * Called before route matching. Only runs once per request.
225
224
  *
226
- * @param req - The incoming Next.js request
225
+ * @param req - The incoming request
227
226
  * @param method - The HTTP method
228
227
  */
229
- appRequest(req: NextRequest, method: RouteMethod): Promise<void>;
228
+ appRequest(req: CoreRequest, method: RouteMethod): Promise<void>;
230
229
  /**
231
230
  * Executes the Application onResponse hook.
232
231
  * Called after dispatch and feature hooks. Only runs once per request.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var r=require("./application.js"),e=require("./common.js"),o=require("./config.js"),t=require("./controller.js"),s=require("./decorator.js"),a=require("./error.js"),p=require("./execute.js"),x=require("./feature.js"),i=require("./hooks.js"),n=require("./logger.js"),u=require("./response.js"),c=require("./route.js"),l=require("./router.js"),E=require("./service.js");exports.Application=r.Application,exports.InjectionRegistry=e.InjectionRegistry,Object.defineProperty(exports,"RouteMethod",{enumerable:!0,get:function(){return e.RouteMethod}}),exports.Config=o.Config,exports.Controller=t.Controller,exports.controller=t.controller,exports.Body=s.Body,exports.FormData=s.FormData,exports.Header=s.Header,exports.Headers=s.Headers,exports.Inject=s.Inject,exports.InjectSync=s.InjectSync,exports.Metadata=s.Metadata,exports.Param=s.Param,exports.Params=s.Params,exports.Query=s.Query,exports.QueryParam=s.QueryParam,exports.Request=s.Request,exports.SetMetadata=s.SetMetadata,exports.Text=s.Text,exports.UseFilters=s.UseFilters,exports.UseGuards=s.UseGuards,exports.UseInterceptors=s.UseInterceptors,exports.UsePipes=s.UsePipes,exports.applyDecorators=s.applyDecorators,exports.createDecorator=s.createDecorator,exports.BadGatewayError=a.BadGatewayError,exports.BadRequestError=a.BadRequestError,exports.ConflictError=a.ConflictError,exports.ForbiddenError=a.ForbiddenError,exports.GatewayTimeoutError=a.GatewayTimeoutError,exports.GoneError=a.GoneError,exports.HttpError=a.HttpError,exports.InternalServerError=a.InternalServerError,exports.MethodNotAllowedError=a.MethodNotAllowedError,exports.NotAcceptableError=a.NotAcceptableError,exports.NotFoundError=a.NotFoundError,exports.NotImplementedError=a.NotImplementedError,exports.PayloadTooLargeError=a.PayloadTooLargeError,exports.RequestTimeoutError=a.RequestTimeoutError,exports.ServiceUnavailableError=a.ServiceUnavailableError,exports.TooManyRequestsError=a.TooManyRequestsError,exports.UnauthorizedError=a.UnauthorizedError,exports.UnprocessableEntityError=a.UnprocessableEntityError,exports.UnsupportedMediaTypeError=a.UnsupportedMediaTypeError,exports.ValidateError=a.ValidateError,exports.ExecuteContext=p.ExecuteContext,exports.Reflect=p.Reflect,exports.Feature=x.Feature,exports.ApplicationHooks=i.ApplicationHooks,exports.FeatureHooks=i.FeatureHooks,exports.RequestHooks=i.RequestHooks,exports.Logger=n.Logger,exports.logger=n.logger,exports.ServerResponse=u.ServerResponse,exports.Route=c.Route,exports.Router=l.Router,exports.Service=E.Service,exports.service=E.service;
1
+ "use strict";var r=require("./application.js"),e=require("./common.js"),o=require("./config.js"),t=require("./controller.js"),s=require("./decorator.js"),a=require("./error.js"),p=require("./execute.js"),x=require("./feature.js"),n=require("./hooks.js"),i=require("./logger.js"),u=require("./response.js"),c=require("./route.js"),l=require("./router.js"),E=require("./service.js");exports.Application=r.Application,exports.InjectionRegistry=e.InjectionRegistry,Object.defineProperty(exports,"RouteMethod",{enumerable:!0,get:function(){return e.RouteMethod}}),exports.Config=o.Config,exports.Controller=t.Controller,exports.controller=t.controller,exports.Body=s.Body,exports.FormData=s.FormData,exports.Header=s.Header,exports.Headers=s.Headers,exports.Inject=s.Inject,exports.InjectSync=s.InjectSync,exports.Metadata=s.Metadata,exports.Param=s.Param,exports.Params=s.Params,exports.Query=s.Query,exports.QueryParam=s.QueryParam,exports.Request=s.Request,exports.SetMetadata=s.SetMetadata,exports.Text=s.Text,exports.UseFilters=s.UseFilters,exports.UseGuards=s.UseGuards,exports.UseInterceptors=s.UseInterceptors,exports.UsePipes=s.UsePipes,exports.applyDecorators=s.applyDecorators,exports.createDecorator=s.createDecorator,exports.BadGatewayError=a.BadGatewayError,exports.BadRequestError=a.BadRequestError,exports.ConflictError=a.ConflictError,exports.ForbiddenError=a.ForbiddenError,exports.GatewayTimeoutError=a.GatewayTimeoutError,exports.GoneError=a.GoneError,exports.HttpError=a.HttpError,exports.InternalServerError=a.InternalServerError,exports.MethodNotAllowedError=a.MethodNotAllowedError,exports.NotAcceptableError=a.NotAcceptableError,exports.NotFoundError=a.NotFoundError,exports.NotImplementedError=a.NotImplementedError,exports.PayloadTooLargeError=a.PayloadTooLargeError,exports.RequestTimeoutError=a.RequestTimeoutError,exports.ServiceUnavailableError=a.ServiceUnavailableError,exports.TooManyRequestsError=a.TooManyRequestsError,exports.UnauthorizedError=a.UnauthorizedError,exports.UnprocessableEntityError=a.UnprocessableEntityError,exports.UnsupportedMediaTypeError=a.UnsupportedMediaTypeError,exports.ValidateError=a.ValidateError,exports.CoreSearchParams=p.CoreSearchParams,exports.ExecuteContext=p.ExecuteContext,exports.Reflect=p.Reflect,exports.Feature=x.Feature,exports.ApplicationHooks=n.ApplicationHooks,exports.FeatureHooks=n.FeatureHooks,exports.RequestHooks=n.RequestHooks,exports.Logger=i.Logger,exports.logger=i.logger,exports.CoreResponse=u.CoreResponse,exports.ServerResponse=u.ServerResponse,exports.applyTransformer=u.applyTransformer,exports.Route=c.Route,exports.Router=l.Router,exports.Service=E.Service,exports.service=E.service;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{Application}from"./application.mjs";export{InjectionRegistry,RouteMethod}from"./common.mjs";export{Config}from"./config.mjs";export{Controller,controller}from"./controller.mjs";export{Body,FormData,Header,Headers,Inject,InjectSync,Metadata,Param,Params,Query,QueryParam,Request,SetMetadata,Text,UseFilters,UseGuards,UseInterceptors,UsePipes,applyDecorators,createDecorator}from"./decorator.mjs";export{BadGatewayError,BadRequestError,ConflictError,ForbiddenError,GatewayTimeoutError,GoneError,HttpError,InternalServerError,MethodNotAllowedError,NotAcceptableError,NotFoundError,NotImplementedError,PayloadTooLargeError,RequestTimeoutError,ServiceUnavailableError,TooManyRequestsError,UnauthorizedError,UnprocessableEntityError,UnsupportedMediaTypeError,ValidateError}from"./error.mjs";export{ExecuteContext,Reflect}from"./execute.mjs";export{Feature}from"./feature.mjs";export{ApplicationHooks,FeatureHooks,RequestHooks}from"./hooks.mjs";export{Logger,logger}from"./logger.mjs";export{ServerResponse}from"./response.mjs";export{Route}from"./route.mjs";export{Router}from"./router.mjs";export{Service,service}from"./service.mjs";
1
+ export{Application}from"./application.mjs";export{InjectionRegistry,RouteMethod}from"./common.mjs";export{Config}from"./config.mjs";export{Controller,controller}from"./controller.mjs";export{Body,FormData,Header,Headers,Inject,InjectSync,Metadata,Param,Params,Query,QueryParam,Request,SetMetadata,Text,UseFilters,UseGuards,UseInterceptors,UsePipes,applyDecorators,createDecorator}from"./decorator.mjs";export{BadGatewayError,BadRequestError,ConflictError,ForbiddenError,GatewayTimeoutError,GoneError,HttpError,InternalServerError,MethodNotAllowedError,NotAcceptableError,NotFoundError,NotImplementedError,PayloadTooLargeError,RequestTimeoutError,ServiceUnavailableError,TooManyRequestsError,UnauthorizedError,UnprocessableEntityError,UnsupportedMediaTypeError,ValidateError}from"./error.mjs";export{CoreSearchParams,ExecuteContext,Reflect}from"./execute.mjs";export{Feature}from"./feature.mjs";export{ApplicationHooks,FeatureHooks,RequestHooks}from"./hooks.mjs";export{Logger,logger}from"./logger.mjs";export{CoreResponse,ServerResponse,applyTransformer}from"./response.mjs";export{Route}from"./route.mjs";export{Router}from"./router.mjs";export{Service,service}from"./service.mjs";
package/dist/logger.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@mxweb/utils");const o={warn:"",log:"",error:"",info:"",debug:"",reset:""};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;
1
+ "use strict";function o(o){return"undefined"!=typeof process?process.env[o]:void 0}const t={warn:"",log:"",error:"",info:"",debug:"",reset:""};class e{constructor(t="@mxweb"){this.prefix=t,this.allowLog="production"!==o("NODE_ENV")&&"false"!==o("DEBUG")}static get instance(){return e._instance||(e._instance=new e),e._instance}static create(o){return new e(o)}isAllowLog(){return this.allowLog}formatPrefix(o){return`${t[o]}[${this.prefix}]${t.reset}`}output(o,t,e,...s){if(!this.isAllowLog())return;const i=this.formatPrefix(o);console[t](`${i} ${e}`,...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,e,s,i,r){const n=`${o} ${e} ${s>=500?t.error:s>=400?t.warn:s>=300?t.log:t.info}${s}${t.reset} - ${i} bytes in ${r}ms`;this.output("info","info",n)}timestamp(o,t,...e){if(!this.isAllowLog())return;const s=(new Date).toISOString(),i=this.formatPrefix(o);console["log"===o?"log":o](`${i} [${s}] ${t}`,...e)}json(o,t,e){if(!this.isAllowLog())return;const s=this.formatPrefix(o);console["log"===o?"log":o](`${s} ${t}:`,JSON.stringify(e,null,2))}separator(o="-",t=50){this.isAllowLog()&&console.log(o.repeat(t))}group(o,t){if(!this.isAllowLog())return;const e=this.formatPrefix("info");console.group(`${e} ${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=e.instance;exports.Logger=e,exports.logger=s;
package/dist/logger.mjs CHANGED
@@ -1 +1 @@
1
- import{getEnv as o}from"@mxweb/utils";const t={warn:"",log:"",error:"",info:"",debug:"",reset:""};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};
1
+ function o(o){return"undefined"!=typeof process?process.env[o]:void 0}const t={warn:"",log:"",error:"",info:"",debug:"",reset:""};class e{constructor(t="@mxweb"){this.prefix=t,this.allowLog="production"!==o("NODE_ENV")&&"false"!==o("DEBUG")}static get instance(){return e._instance||(e._instance=new e),e._instance}static create(o){return new e(o)}isAllowLog(){return this.allowLog}formatPrefix(o){return`${t[o]}[${this.prefix}]${t.reset}`}output(o,t,e,...i){if(!this.isAllowLog())return;const s=this.formatPrefix(o);console[t](`${s} ${e}`,...i)}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,e,i,s,r){const n=`${o} ${e} ${i>=500?t.error:i>=400?t.warn:i>=300?t.log:t.info}${i}${t.reset} - ${s} bytes in ${r}ms`;this.output("info","info",n)}timestamp(o,t,...e){if(!this.isAllowLog())return;const i=(new Date).toISOString(),s=this.formatPrefix(o);console["log"===o?"log":o](`${s} [${i}] ${t}`,...e)}json(o,t,e){if(!this.isAllowLog())return;const i=this.formatPrefix(o);console["log"===o?"log":o](`${i} ${t}:`,JSON.stringify(e,null,2))}separator(o="-",t=50){this.isAllowLog()&&console.log(o.repeat(t))}group(o,t){if(!this.isAllowLog())return;const e=this.formatPrefix("info");console.group(`${e} ${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 i=e.instance;export{e as Logger,i as logger};