@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/CHANGELOG.md +294 -0
- package/dist/application.d.ts +90 -37
- package/dist/application.js +1 -1
- package/dist/application.mjs +1 -1
- package/dist/common.d.ts +255 -3
- package/dist/config.d.ts +18 -0
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/decorator.d.ts +12 -5
- package/dist/execute.d.ts +293 -135
- package/dist/execute.js +1 -1
- package/dist/execute.mjs +1 -1
- package/dist/feature.d.ts +48 -10
- package/dist/feature.js +1 -1
- package/dist/feature.mjs +1 -1
- package/dist/hooks.d.ts +5 -6
- 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/response.d.ts +297 -227
- package/dist/response.js +1 -1
- package/dist/response.mjs +1 -1
- package/dist/route.d.ts +106 -2
- package/dist/route.js +1 -1
- package/dist/route.mjs +1 -1
- package/dist/service.d.ts +9 -8
- package/package.json +1 -6
package/dist/response.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";class e{constructor(e,t,s,r){this.body=e,this.status=t,this.statusText=s,this.headers=new Headers(r),this.headers.set("Content-Type","application/json")}json(){return this.body}static json(t,s){return new e(t,s?.status??200,s?.statusText??"OK",s?.headers)}}class t{static toJSON(e,t=200,s="Successfully",r=null,o=null){return{success:t>=200&&t<400,message:s,code:e,status:t,data:r,error:o}}static options(){return(new t).success()}success(s=null,r){return e.json(t.toJSON("SUCCESS",200,r,s,null),{status:200})}created(s=null,r){return e.json(t.toJSON("CREATED",201,r??"Resource created successfully",s,null),{status:201})}accepted(s=null,r){return e.json(t.toJSON("ACCEPTED",202,r??"Request accepted successfully",s,null),{status:202})}noContent(s){return e.json(t.toJSON("NO_CONTENT",204,s??"No content",null,null),{status:204})}resourceMovedPermanently(){return e.json(t.toJSON("MOVED_PERMANENTLY",301,"Resource moved permanently",null,null),{status:301})}resourceMovedTemporarily(){return e.json(t.toJSON("REDIRECTED",302,"Resource moved temporarily",null,null),{status:302})}badRequest(s="Bad Request",r){return e.json(t.toJSON("BAD_REQUEST",400,s,null,r??{message:"The server could not understand the request due to invalid syntax",name:"BadRequestError",code:"BAD_REQUEST"}),{status:400})}unauthorized(s="Unauthorized",r){return e.json(t.toJSON("UNAUTHORIZED",401,s,null,r??{message:"Authentication is required and has failed or has not yet been provided",name:"UnauthorizedError",code:"AUTHENTICATION_REQUIRED"}),{status:401})}forbidden(s="Forbidden",r){return e.json(t.toJSON("FORBIDDEN",403,s,null,r??{message:"You do not have permission to access this resource",name:"ForbiddenError",code:"ACCESS_FORBIDDEN"}),{status:403})}notFound(s="Not Found",r){return e.json(t.toJSON("NOT_FOUND",404,s,null,r??{message:"The requested resource was not found",name:"NotFoundError",code:"URL_NOT_FOUND"}),{status:404})}methodNotAllowed(s="Method Not Allowed",r){return e.json(t.toJSON("METHOD_NOT_ALLOWED",405,s,null,r??{message:"The HTTP method is not allowed for this resource",name:"MethodNotAllowedError",code:"METHOD_NOT_ALLOWED"}),{status:405})}notAcceptable(s="Not Acceptable",r){return e.json(t.toJSON("NOT_ACCEPTABLE",406,s,null,r??{message:"The server cannot produce a response matching the acceptable values",name:"NotAcceptableError",code:"NOT_ACCEPTABLE"}),{status:406})}requestTimeout(s="Request Timeout",r){return e.json(t.toJSON("REQUEST_TIMEOUT",408,s,null,r??{message:"The server timed out waiting for the request",name:"RequestTimeoutError",code:"REQUEST_TIMEOUT"}),{status:408})}conflict(s="Conflict",r){return e.json(t.toJSON("CONFLICT",409,s,null,r??{message:"The request could not be completed due to a conflict with the current state of the resource",name:"ConflictError",code:"RESOURCE_CONFLICT"}),{status:409})}gone(s="Gone",r){return e.json(t.toJSON("GONE",410,s,null,r??{message:"The requested resource is no longer available and has been permanently removed",name:"GoneError",code:"RESOURCE_GONE"}),{status:410})}payloadTooLarge(s="Payload Too Large",r){return e.json(t.toJSON("PAYLOAD_TOO_LARGE",413,s,null,r??{message:"The request payload is larger than the server is willing to process",name:"PayloadTooLargeError",code:"PAYLOAD_TOO_LARGE"}),{status:413})}unsupportedMediaType(s="Unsupported Media Type",r){return e.json(t.toJSON("UNSUPPORTED_MEDIA_TYPE",415,s,null,r??{message:"The media format of the requested data is not supported by the server",name:"UnsupportedMediaTypeError",code:"UNSUPPORTED_MEDIA_TYPE"}),{status:415})}unprocessableEntity(s="Unprocessable Entity",r){return e.json(t.toJSON("UNPROCESSABLE_ENTITY",422,s,null,r??{message:"The request was well-formed but was unable to be followed due to semantic errors",name:"UnprocessableEntityError",code:"UNPROCESSABLE_ENTITY"}),{status:422})}tooManyRequests(s="Too Many Requests",r){return e.json(t.toJSON("TOO_MANY_REQUESTS",429,s,null,r??{message:"You have sent too many requests in a given amount of time",name:"TooManyRequestsError",code:"TOO_MANY_REQUESTS"}),{status:429})}internalServer(s){return e.json(t.toJSON("INTERNAL_SERVER_ERROR",500,"Internal Server Error",null,s??{message:"An unexpected error occurred on the server",name:"InternalServerError",code:"INTERNAL_SERVER_ERROR"}),{status:500})}notImplemented(s="Not Implemented",r){return e.json(t.toJSON("NOT_IMPLEMENTED",501,s,null,r??{message:"The requested functionality is not implemented",name:"NotImplementedError",code:"NOT_IMPLEMENTED"}),{status:501})}badGateway(s="Bad Gateway",r){return e.json(t.toJSON("BAD_GATEWAY",502,s,null,r??{message:"Received an invalid response from the upstream server",name:"BadGatewayError",code:"BAD_GATEWAY"}),{status:502})}serviceUnavailable(s="Service Unavailable",r){return e.json(t.toJSON("SERVICE_UNAVAILABLE",503,s,null,r??{message:"The server is currently unable to handle the request",name:"ServiceUnavailableError",code:"SERVICE_UNAVAILABLE"}),{status:503})}gatewayTimeout(s="Gateway Timeout",r){return e.json(t.toJSON("GATEWAY_TIMEOUT",504,s,null,r??{message:"The server did not receive a timely response from the upstream server",name:"GatewayTimeoutError",code:"GATEWAY_TIMEOUT"}),{status:504})}}exports.CoreResponse=e,exports.ServerResponse=t,exports.applyTransformer=function(e,t){if("function"==typeof e&&"json"in e){return e.json(t.body,{status:t.status,statusText:t.statusText,headers:t.headers})}return e(t)};
|
package/dist/response.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
class e{constructor(e,t,s,r){this.body=e,this.status=t,this.statusText=s,this.headers=new Headers(r),this.headers.set("Content-Type","application/json")}json(){return this.body}static json(t,s){return new e(t,s?.status??200,s?.statusText??"OK",s?.headers)}}function t(e,t){if("function"==typeof e&&"json"in e){return e.json(t.body,{status:t.status,statusText:t.statusText,headers:t.headers})}return e(t)}class s{static toJSON(e,t=200,s="Successfully",r=null,o=null){return{success:t>=200&&t<400,message:s,code:e,status:t,data:r,error:o}}static options(){return(new s).success()}success(t=null,r){return e.json(s.toJSON("SUCCESS",200,r,t,null),{status:200})}created(t=null,r){return e.json(s.toJSON("CREATED",201,r??"Resource created successfully",t,null),{status:201})}accepted(t=null,r){return e.json(s.toJSON("ACCEPTED",202,r??"Request accepted successfully",t,null),{status:202})}noContent(t){return e.json(s.toJSON("NO_CONTENT",204,t??"No content",null,null),{status:204})}resourceMovedPermanently(){return e.json(s.toJSON("MOVED_PERMANENTLY",301,"Resource moved permanently",null,null),{status:301})}resourceMovedTemporarily(){return e.json(s.toJSON("REDIRECTED",302,"Resource moved temporarily",null,null),{status:302})}badRequest(t="Bad Request",r){return e.json(s.toJSON("BAD_REQUEST",400,t,null,r??{message:"The server could not understand the request due to invalid syntax",name:"BadRequestError",code:"BAD_REQUEST"}),{status:400})}unauthorized(t="Unauthorized",r){return e.json(s.toJSON("UNAUTHORIZED",401,t,null,r??{message:"Authentication is required and has failed or has not yet been provided",name:"UnauthorizedError",code:"AUTHENTICATION_REQUIRED"}),{status:401})}forbidden(t="Forbidden",r){return e.json(s.toJSON("FORBIDDEN",403,t,null,r??{message:"You do not have permission to access this resource",name:"ForbiddenError",code:"ACCESS_FORBIDDEN"}),{status:403})}notFound(t="Not Found",r){return e.json(s.toJSON("NOT_FOUND",404,t,null,r??{message:"The requested resource was not found",name:"NotFoundError",code:"URL_NOT_FOUND"}),{status:404})}methodNotAllowed(t="Method Not Allowed",r){return e.json(s.toJSON("METHOD_NOT_ALLOWED",405,t,null,r??{message:"The HTTP method is not allowed for this resource",name:"MethodNotAllowedError",code:"METHOD_NOT_ALLOWED"}),{status:405})}notAcceptable(t="Not Acceptable",r){return e.json(s.toJSON("NOT_ACCEPTABLE",406,t,null,r??{message:"The server cannot produce a response matching the acceptable values",name:"NotAcceptableError",code:"NOT_ACCEPTABLE"}),{status:406})}requestTimeout(t="Request Timeout",r){return e.json(s.toJSON("REQUEST_TIMEOUT",408,t,null,r??{message:"The server timed out waiting for the request",name:"RequestTimeoutError",code:"REQUEST_TIMEOUT"}),{status:408})}conflict(t="Conflict",r){return e.json(s.toJSON("CONFLICT",409,t,null,r??{message:"The request could not be completed due to a conflict with the current state of the resource",name:"ConflictError",code:"RESOURCE_CONFLICT"}),{status:409})}gone(t="Gone",r){return e.json(s.toJSON("GONE",410,t,null,r??{message:"The requested resource is no longer available and has been permanently removed",name:"GoneError",code:"RESOURCE_GONE"}),{status:410})}payloadTooLarge(t="Payload Too Large",r){return e.json(s.toJSON("PAYLOAD_TOO_LARGE",413,t,null,r??{message:"The request payload is larger than the server is willing to process",name:"PayloadTooLargeError",code:"PAYLOAD_TOO_LARGE"}),{status:413})}unsupportedMediaType(t="Unsupported Media Type",r){return e.json(s.toJSON("UNSUPPORTED_MEDIA_TYPE",415,t,null,r??{message:"The media format of the requested data is not supported by the server",name:"UnsupportedMediaTypeError",code:"UNSUPPORTED_MEDIA_TYPE"}),{status:415})}unprocessableEntity(t="Unprocessable Entity",r){return e.json(s.toJSON("UNPROCESSABLE_ENTITY",422,t,null,r??{message:"The request was well-formed but was unable to be followed due to semantic errors",name:"UnprocessableEntityError",code:"UNPROCESSABLE_ENTITY"}),{status:422})}tooManyRequests(t="Too Many Requests",r){return e.json(s.toJSON("TOO_MANY_REQUESTS",429,t,null,r??{message:"You have sent too many requests in a given amount of time",name:"TooManyRequestsError",code:"TOO_MANY_REQUESTS"}),{status:429})}internalServer(t){return e.json(s.toJSON("INTERNAL_SERVER_ERROR",500,"Internal Server Error",null,t??{message:"An unexpected error occurred on the server",name:"InternalServerError",code:"INTERNAL_SERVER_ERROR"}),{status:500})}notImplemented(t="Not Implemented",r){return e.json(s.toJSON("NOT_IMPLEMENTED",501,t,null,r??{message:"The requested functionality is not implemented",name:"NotImplementedError",code:"NOT_IMPLEMENTED"}),{status:501})}badGateway(t="Bad Gateway",r){return e.json(s.toJSON("BAD_GATEWAY",502,t,null,r??{message:"Received an invalid response from the upstream server",name:"BadGatewayError",code:"BAD_GATEWAY"}),{status:502})}serviceUnavailable(t="Service Unavailable",r){return e.json(s.toJSON("SERVICE_UNAVAILABLE",503,t,null,r??{message:"The server is currently unable to handle the request",name:"ServiceUnavailableError",code:"SERVICE_UNAVAILABLE"}),{status:503})}gatewayTimeout(t="Gateway Timeout",r){return e.json(s.toJSON("GATEWAY_TIMEOUT",504,t,null,r??{message:"The server did not receive a timely response from the upstream server",name:"GatewayTimeoutError",code:"GATEWAY_TIMEOUT"}),{status:504})}}export{e as CoreResponse,s as ServerResponse,t as applyTransformer};
|
package/dist/route.d.ts
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* })
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
import { RouteMethod } from "./common";
|
|
36
|
+
import { Filter, Guard, Interceptor, Pipe, RouteMethod } from "./common";
|
|
37
37
|
import { DecoratorResult } from "./decorator";
|
|
38
38
|
import { Reflect, RouteHandler, RouteMiddleware } from "./execute";
|
|
39
39
|
/**
|
|
@@ -69,7 +69,8 @@ export declare class Route {
|
|
|
69
69
|
private readonly path;
|
|
70
70
|
private readonly action;
|
|
71
71
|
private readonly reflect;
|
|
72
|
-
private readonly
|
|
72
|
+
private readonly middlewaresHandlers;
|
|
73
|
+
private readonly decoratorResults;
|
|
73
74
|
/**
|
|
74
75
|
* Private constructor to enforce factory method usage.
|
|
75
76
|
*
|
|
@@ -80,6 +81,108 @@ export declare class Route {
|
|
|
80
81
|
* @param middlewares - Array of middleware functions for this route
|
|
81
82
|
*/
|
|
82
83
|
private constructor();
|
|
84
|
+
/**
|
|
85
|
+
* Adds decorators to this route using a fluent chain API.
|
|
86
|
+
* Decorators are stored and only applied when getReflect() is called.
|
|
87
|
+
*
|
|
88
|
+
* @param decorators - One or more DecoratorResult objects (e.g., UseGuards(), SetMetadata(), etc.)
|
|
89
|
+
* @returns A new Route instance with the decorators added
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* Route.get("/users", "findAll")
|
|
94
|
+
* .decorators(UseGuards(AuthGuard), SetMetadata("roles", ["admin"]))
|
|
95
|
+
*
|
|
96
|
+
* // Or combine multiple decorators
|
|
97
|
+
* Route.get("/admin", "dashboard")
|
|
98
|
+
* .decorators(
|
|
99
|
+
* UseGuards(AuthGuard, RolesGuard),
|
|
100
|
+
* UseInterceptors(LoggingInterceptor),
|
|
101
|
+
* SetMetadata("roles", ["admin"])
|
|
102
|
+
* )
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
decorators(...decorators: DecoratorResult[]): Route;
|
|
106
|
+
/**
|
|
107
|
+
* Adds middlewares to this route using a fluent chain API.
|
|
108
|
+
*
|
|
109
|
+
* @param middlewares - Middleware functions to add
|
|
110
|
+
* @returns A new Route instance with the middlewares added
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* Route.get("/users", "findAll")
|
|
115
|
+
* .middlewares(loggingMiddleware, rateLimitMiddleware)
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
middlewares(...middlewares: RouteMiddleware[]): Route;
|
|
119
|
+
/**
|
|
120
|
+
* Adds guards to this route using a fluent chain API.
|
|
121
|
+
*
|
|
122
|
+
* @param guards - Guard classes to add
|
|
123
|
+
* @returns A new Route instance with the guards added
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* Route.get("/users", "findAll")
|
|
128
|
+
* .guards(AuthGuard, RolesGuard)
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
guards(...guards: Guard[]): Route;
|
|
132
|
+
/**
|
|
133
|
+
* Adds exception filters to this route using a fluent chain API.
|
|
134
|
+
*
|
|
135
|
+
* @param filters - Filter classes to add
|
|
136
|
+
* @returns A new Route instance with the filters added
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* Route.get("/users", "findAll")
|
|
141
|
+
* .filters(HttpExceptionFilter, ValidationExceptionFilter)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
filters(...filters: Filter[]): Route;
|
|
145
|
+
/**
|
|
146
|
+
* Adds interceptors to this route using a fluent chain API.
|
|
147
|
+
*
|
|
148
|
+
* @param interceptors - Interceptor classes to add
|
|
149
|
+
* @returns A new Route instance with the interceptors added
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* Route.get("/users", "findAll")
|
|
154
|
+
* .interceptors(LoggingInterceptor, CacheInterceptor)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
interceptors(...interceptors: Interceptor[]): Route;
|
|
158
|
+
/**
|
|
159
|
+
* Adds pipes to this route using a fluent chain API.
|
|
160
|
+
*
|
|
161
|
+
* @param pipes - Pipe classes to add
|
|
162
|
+
* @returns A new Route instance with the pipes added
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* Route.get("/users/:id", "findOne")
|
|
167
|
+
* .pipes(ValidationPipe, ParseIntPipe)
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
pipes(...pipes: Pipe[]): Route;
|
|
171
|
+
/**
|
|
172
|
+
* Sets a metadata key-value pair on this route using a fluent chain API.
|
|
173
|
+
*
|
|
174
|
+
* @param key - The metadata key
|
|
175
|
+
* @param value - The metadata value
|
|
176
|
+
* @returns A new Route instance with the metadata added
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* Route.get("/admin/users", "findAll")
|
|
181
|
+
* .metadata("roles", ["admin"])
|
|
182
|
+
* .metadata("public", false)
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
metadata(key: string, value: unknown): Route;
|
|
83
186
|
/**
|
|
84
187
|
* Gets the HTTP method for this route.
|
|
85
188
|
*
|
|
@@ -118,6 +221,7 @@ export declare class Route {
|
|
|
118
221
|
getAction(): string | RouteHandler;
|
|
119
222
|
/**
|
|
120
223
|
* Gets the Reflect instance containing route-level decorators.
|
|
224
|
+
* Applies any pending decorators from the chain and merges with the base reflect.
|
|
121
225
|
*
|
|
122
226
|
* @returns The Reflect instance with guards, filters, interceptors, pipes, and metadata
|
|
123
227
|
*/
|
package/dist/route.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("./common.js"),e=require("./execute.js");class
|
|
1
|
+
"use strict";var t=require("./common.js"),e=require("./execute.js");class s{constructor(t,e,s,r,i=[],a=[]){this.method=t,this.path=e,this.action=s,this.reflect=r,this.middlewaresHandlers=i,this.decoratorResults=a}decorators(...t){return new s(this.method,this.path,this.action,this.reflect,this.middlewaresHandlers,[...this.decoratorResults,...t])}middlewares(...t){return new s(this.method,this.path,this.action,this.reflect,[...this.middlewaresHandlers,...t],this.decoratorResults)}guards(...t){const r=this.reflect,i=new e.Reflect(r.getAllMetadata(),new Set([...r.getGuards(),...t]),r.getFilters(),r.getInterceptors(),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}filters(...t){const r=this.reflect,i=new e.Reflect(r.getAllMetadata(),r.getGuards(),new Set([...r.getFilters(),...t]),r.getInterceptors(),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}interceptors(...t){const r=this.reflect,i=new e.Reflect(r.getAllMetadata(),r.getGuards(),r.getFilters(),new Set([...r.getInterceptors(),...t]),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}pipes(...t){const r=this.reflect,i=new e.Reflect(r.getAllMetadata(),r.getGuards(),r.getFilters(),r.getInterceptors(),new Set([...r.getPipes(),...t]));return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}metadata(t,r){const i=this.reflect,a=new Map(i.getAllMetadata());a.set(t,r);const h=new e.Reflect(a,i.getGuards(),i.getFilters(),i.getInterceptors(),i.getPipes());return new s(this.method,this.path,this.action,h,this.middlewaresHandlers,this.decoratorResults)}getMethod(){return this.method}getPath(){return this.path}getAction(){return this.action}getReflect(){if(0===this.decoratorResults.length)return this.reflect;const t=new Set([...this.reflect.getGuards()]),s=new Set([...this.reflect.getFilters()]),r=new Set([...this.reflect.getInterceptors()]),i=new Set([...this.reflect.getPipes()]),a=new Map([...this.reflect.getAllMetadata()]);return this.decoratorResults.forEach(e=>{e.guards.forEach(e=>t.add(e)),e.filters.forEach(t=>s.add(t)),e.interceptors.forEach(t=>r.add(t)),e.pipes.forEach(t=>i.add(t)),e.metadata.forEach((t,e)=>a.set(e,t))}),new e.Reflect(a,t,s,r,i)}getMiddlewares(){return this.middlewaresHandlers}static normalize(t,s){let r={guards:new Set,filters:new Set,interceptors:new Set,pipes:new Set,metadata:new Map};"function"==typeof t?s.unshift(t):t&&(r=t);return[new e.Reflect(r.metadata,r.guards,r.filters,r.interceptors,r.pipes),s]}static route(t,e,r,i,a=[]){return new s(t,e,r,...this.normalize(i,a))}static get(e,s,r,...i){return this.route(t.RouteMethod.GET,e,s,r,i)}static post(e,s,r,...i){return this.route(t.RouteMethod.POST,e,s,r,i)}static put(e,s,r,...i){return this.route(t.RouteMethod.PUT,e,s,r,i)}static patch(e,s,r,...i){return this.route(t.RouteMethod.PATCH,e,s,r,i)}static delete(e,s,r,...i){return this.route(t.RouteMethod.DELETE,e,s,r,i)}static head(e,s,r,...i){return this.route(t.RouteMethod.HEAD,e,s,r,i)}static options(e,s,r,...i){return this.route(t.RouteMethod.OPTIONS,e,s,r,i)}}exports.Route=s;
|
package/dist/route.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{RouteMethod as t}from"./common.mjs";import{Reflect as e}from"./execute.mjs";class
|
|
1
|
+
import{RouteMethod as t}from"./common.mjs";import{Reflect as e}from"./execute.mjs";class s{constructor(t,e,s,r,i=[],a=[]){this.method=t,this.path=e,this.action=s,this.reflect=r,this.middlewaresHandlers=i,this.decoratorResults=a}decorators(...t){return new s(this.method,this.path,this.action,this.reflect,this.middlewaresHandlers,[...this.decoratorResults,...t])}middlewares(...t){return new s(this.method,this.path,this.action,this.reflect,[...this.middlewaresHandlers,...t],this.decoratorResults)}guards(...t){const r=this.reflect,i=new e(r.getAllMetadata(),new Set([...r.getGuards(),...t]),r.getFilters(),r.getInterceptors(),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}filters(...t){const r=this.reflect,i=new e(r.getAllMetadata(),r.getGuards(),new Set([...r.getFilters(),...t]),r.getInterceptors(),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}interceptors(...t){const r=this.reflect,i=new e(r.getAllMetadata(),r.getGuards(),r.getFilters(),new Set([...r.getInterceptors(),...t]),r.getPipes());return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}pipes(...t){const r=this.reflect,i=new e(r.getAllMetadata(),r.getGuards(),r.getFilters(),r.getInterceptors(),new Set([...r.getPipes(),...t]));return new s(this.method,this.path,this.action,i,this.middlewaresHandlers,this.decoratorResults)}metadata(t,r){const i=this.reflect,a=new Map(i.getAllMetadata());a.set(t,r);const h=new e(a,i.getGuards(),i.getFilters(),i.getInterceptors(),i.getPipes());return new s(this.method,this.path,this.action,h,this.middlewaresHandlers,this.decoratorResults)}getMethod(){return this.method}getPath(){return this.path}getAction(){return this.action}getReflect(){if(0===this.decoratorResults.length)return this.reflect;const t=new Set([...this.reflect.getGuards()]),s=new Set([...this.reflect.getFilters()]),r=new Set([...this.reflect.getInterceptors()]),i=new Set([...this.reflect.getPipes()]),a=new Map([...this.reflect.getAllMetadata()]);return this.decoratorResults.forEach(e=>{e.guards.forEach(e=>t.add(e)),e.filters.forEach(t=>s.add(t)),e.interceptors.forEach(t=>r.add(t)),e.pipes.forEach(t=>i.add(t)),e.metadata.forEach((t,e)=>a.set(e,t))}),new e(a,t,s,r,i)}getMiddlewares(){return this.middlewaresHandlers}static normalize(t,s){let r={guards:new Set,filters:new Set,interceptors:new Set,pipes:new Set,metadata:new Map};"function"==typeof t?s.unshift(t):t&&(r=t);return[new e(r.metadata,r.guards,r.filters,r.interceptors,r.pipes),s]}static route(t,e,r,i,a=[]){return new s(t,e,r,...this.normalize(i,a))}static get(e,s,r,...i){return this.route(t.GET,e,s,r,i)}static post(e,s,r,...i){return this.route(t.POST,e,s,r,i)}static put(e,s,r,...i){return this.route(t.PUT,e,s,r,i)}static patch(e,s,r,...i){return this.route(t.PATCH,e,s,r,i)}static delete(e,s,r,...i){return this.route(t.DELETE,e,s,r,i)}static head(e,s,r,...i){return this.route(t.HEAD,e,s,r,i)}static options(e,s,r,...i){return this.route(t.OPTIONS,e,s,r,i)}}export{s as Route};
|
package/dist/service.d.ts
CHANGED
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
* }
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
import { ApplicationInject } from "./common";
|
|
43
42
|
import { ExecuteContext } from "./execute";
|
|
44
43
|
/**
|
|
45
44
|
* Type for service injection configuration.
|
|
@@ -129,29 +128,31 @@ declare class BaseService {
|
|
|
129
128
|
protected get context(): ExecuteContext;
|
|
130
129
|
/**
|
|
131
130
|
* Gets an application-level inject by name (async with lazy initialization).
|
|
131
|
+
* Returns the result of switch() if available, otherwise the raw instance.
|
|
132
132
|
*
|
|
133
|
-
* @typeParam T - The type
|
|
133
|
+
* @typeParam T - The expected return type (from switch() or the inject itself)
|
|
134
134
|
* @param name - The name of the inject to retrieve
|
|
135
|
-
* @returns Promise resolving to the
|
|
135
|
+
* @returns Promise resolving to the switched value 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 = await this.getInject<
|
|
141
|
+
* const db = await this.getInject<DatabaseClient>("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
|
|
148
|
+
protected getInject<T = unknown>(name: string): Promise<T | undefined>;
|
|
149
149
|
/**
|
|
150
150
|
* Gets an application-level inject by name (sync, must be already initialized).
|
|
151
|
+
* Returns the result of switch() if available, otherwise the raw instance.
|
|
151
152
|
*
|
|
152
|
-
* @typeParam T - The type
|
|
153
|
+
* @typeParam T - The expected return type (from switch() or the inject itself)
|
|
153
154
|
* @param name - The name of the inject to retrieve
|
|
154
|
-
* @returns The
|
|
155
|
+
* @returns The switched value or undefined if not found/initialized
|
|
155
156
|
*
|
|
156
157
|
* @example
|
|
157
158
|
* ```ts
|
|
@@ -163,7 +164,7 @@ declare class BaseService {
|
|
|
163
164
|
* }
|
|
164
165
|
* ```
|
|
165
166
|
*/
|
|
166
|
-
protected getInjectSync<T
|
|
167
|
+
protected getInjectSync<T = unknown>(name: string): T | undefined;
|
|
167
168
|
/**
|
|
168
169
|
* Initializes async dependencies for this service.
|
|
169
170
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxweb/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"node": ">=14.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@mxweb/utils": "^0.0.4",
|
|
44
43
|
"@rollup/plugin-babel": "^6.1.0",
|
|
45
44
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
46
45
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
@@ -59,10 +58,6 @@
|
|
|
59
58
|
"rollup": "^4.53.4",
|
|
60
59
|
"typescript": "^5"
|
|
61
60
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"@mxweb/utils": "^0.0.4",
|
|
64
|
-
"next": ">=16.0.10"
|
|
65
|
-
},
|
|
66
61
|
"scripts": {
|
|
67
62
|
"clean": "rimraf dist",
|
|
68
63
|
"build": "yarn clean && yarn lint && rollup -c",
|