@mxweb/core 1.0.2 → 1.1.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.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.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()),"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}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};