@ajke/core 0.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/LICENSE +21 -0
- package/README.md +357 -0
- package/dist/chunk-AT2R2CGV.js +234 -0
- package/dist/chunk-AT2R2CGV.js.map +1 -0
- package/dist/chunk-EUXUH3YW.js +15 -0
- package/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/chunk-YUBEJL4T.cjs +234 -0
- package/dist/chunk-YUBEJL4T.cjs.map +1 -0
- package/dist/chunk-ZBDE64SD.cjs +15 -0
- package/dist/chunk-ZBDE64SD.cjs.map +1 -0
- package/dist/config.cjs +10 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +13 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -0
- package/dist/index.cjs +974 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +974 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/index.cjs +10 -0
- package/dist/middleware/index.cjs.map +1 -0
- package/dist/middleware/index.d.cts +18 -0
- package/dist/middleware/index.d.ts +18 -0
- package/dist/middleware/index.js +10 -0
- package/dist/middleware/index.js.map +1 -0
- package/package.json +56 -0
- package/src/README.md +285 -0
- package/src/config.ts +14 -0
- package/src/context/execution-context.ts +36 -0
- package/src/context/index.ts +1 -0
- package/src/decorators/core/exception-filters.decorator.ts +24 -0
- package/src/decorators/core/index.ts +6 -0
- package/src/decorators/core/injectable.decorator.ts +41 -0
- package/src/decorators/core/optional.decorator.ts +9 -0
- package/src/decorators/core/set-metadata.decorator.ts +20 -0
- package/src/decorators/core/use-guards.decorator.ts +14 -0
- package/src/decorators/core/use-interceptors.decorator.ts +16 -0
- package/src/decorators/http/controller.decorator.ts +230 -0
- package/src/decorators/http/header.decorator.ts +11 -0
- package/src/decorators/http/http-code.decorator.ts +8 -0
- package/src/decorators/http/index.ts +6 -0
- package/src/decorators/http/redirect.decorator.ts +13 -0
- package/src/decorators/http/route-mapping.decorator.ts +22 -0
- package/src/decorators/http/route-params.decorator.ts +60 -0
- package/src/decorators/index.ts +3 -0
- package/src/decorators/modules/global.decorator.ts +8 -0
- package/src/decorators/modules/index.ts +2 -0
- package/src/decorators/modules/module.decorator.ts +16 -0
- package/src/exceptions/http-exception.ts +17 -0
- package/src/exceptions/http-exceptions.ts +85 -0
- package/src/exceptions/index.ts +2 -0
- package/src/index.ts +11 -0
- package/src/injector/index.ts +1 -0
- package/src/injector/injector.ts +103 -0
- package/src/injector/module-compiler.ts +48 -0
- package/src/injector/module.factory.ts +74 -0
- package/src/interfaces/core/filter.interface.ts +5 -0
- package/src/interfaces/core/guard.interface.ts +5 -0
- package/src/interfaces/core/index.ts +5 -0
- package/src/interfaces/core/interceptor.interface.ts +9 -0
- package/src/interfaces/core/lifecycle.interface.ts +19 -0
- package/src/interfaces/core/pipe.interface.ts +9 -0
- package/src/interfaces/http/index.ts +1 -0
- package/src/interfaces/http/response.interface.ts +27 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/modules/index.ts +1 -0
- package/src/interfaces/modules/module.interface.ts +17 -0
- package/src/middleware/error-handler.middleware.ts +63 -0
- package/src/middleware/index.ts +2 -0
- package/src/middleware/request-logger.middleware.ts +17 -0
- package/src/pipes/index.ts +3 -0
- package/src/pipes/validate.pipe.ts +79 -0
- package/src/pipes/zod-query.pipe.ts +42 -0
- package/src/pipes/zod-validate.pipe.ts +49 -0
- package/src/services/index.ts +1 -0
- package/src/services/reflector.service.ts +24 -0
- package/src/utils/apply-decorators.util.ts +17 -0
- package/src/utils/forward-ref.util.ts +14 -0
- package/src/utils/index.ts +22 -0
- package/src/utils/logger.util.ts +189 -0
- package/src/utils/response.util.ts +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Hono, Context } from 'hono';
|
|
2
|
+
export { errorHandler, requestLogger } from './middleware/index.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const INJECT_CUSTOM_TOKENS_KEY = "wilt:inject:custom:tokens";
|
|
6
|
+
declare function Injectable(): (target: any) => void;
|
|
7
|
+
declare function Inject(token?: any): (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => any;
|
|
8
|
+
|
|
9
|
+
interface CustomDecorator<TKey = string> {
|
|
10
|
+
(target: any, key?: any, descriptor?: any): any;
|
|
11
|
+
KEY: TKey;
|
|
12
|
+
}
|
|
13
|
+
declare function SetMetadata<K = string, V = any>(metadataKey: K, metadataValue: V): CustomDecorator<K>;
|
|
14
|
+
|
|
15
|
+
declare const GUARDS_METADATA = "wilt:guards";
|
|
16
|
+
declare function UseGuards(...guards: (new (...args: any[]) => any)[]): MethodDecorator & ClassDecorator;
|
|
17
|
+
|
|
18
|
+
declare const INTERCEPTORS_METADATA = "wilt:interceptors";
|
|
19
|
+
declare function UseInterceptors(...interceptors: (new (...args: any[]) => any)[]): MethodDecorator & ClassDecorator;
|
|
20
|
+
|
|
21
|
+
declare const FILTERS_METADATA = "wilt:filters";
|
|
22
|
+
declare const CATCH_METADATA = "wilt:catch";
|
|
23
|
+
declare function Catch(...exceptions: (new (...args: any[]) => any)[]): ClassDecorator;
|
|
24
|
+
declare function UseFilters(...filters: (new (...args: any[]) => any)[]): MethodDecorator & ClassDecorator;
|
|
25
|
+
|
|
26
|
+
declare const OPTIONAL_METADATA = "wilt:optional";
|
|
27
|
+
declare function Optional(): ParameterDecorator;
|
|
28
|
+
|
|
29
|
+
declare function Controller(prefix?: string): (target: any) => void;
|
|
30
|
+
declare function registerControllerRoutes(router: Hono<{
|
|
31
|
+
Bindings: any;
|
|
32
|
+
}>, controller: any, prefix?: string, instanceRegistry?: Map<any, any>): void;
|
|
33
|
+
|
|
34
|
+
declare const Get: (path?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
35
|
+
declare const Post: (path?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
36
|
+
declare const Put: (path?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
37
|
+
declare const Delete: (path?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
38
|
+
declare const Patch: (path?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
39
|
+
|
|
40
|
+
declare const ROUTE_PARAMS_METADATA = "wilt:route-params";
|
|
41
|
+
declare const TOTAL_PARAMS_METADATA = "wilt:total-params";
|
|
42
|
+
type RouteParamType = "body" | "param" | "query" | "headers" | "ip" | "req";
|
|
43
|
+
interface RouteParamMetadata {
|
|
44
|
+
index: number;
|
|
45
|
+
type: RouteParamType;
|
|
46
|
+
data?: string;
|
|
47
|
+
}
|
|
48
|
+
declare const Body: (data?: string) => ParameterDecorator;
|
|
49
|
+
declare const Param: (data?: string) => ParameterDecorator;
|
|
50
|
+
declare const Query: (data?: string) => ParameterDecorator;
|
|
51
|
+
declare const Headers: (data?: string) => ParameterDecorator;
|
|
52
|
+
declare function Ip(): ParameterDecorator;
|
|
53
|
+
declare function Req(): ParameterDecorator;
|
|
54
|
+
|
|
55
|
+
declare const HTTP_CODE_METADATA = "wilt:http-code";
|
|
56
|
+
declare function HttpCode(statusCode: number): MethodDecorator;
|
|
57
|
+
|
|
58
|
+
declare const HEADER_METADATA = "wilt:response-headers";
|
|
59
|
+
declare function Header(name: string, value: string): MethodDecorator;
|
|
60
|
+
|
|
61
|
+
declare const REDIRECT_METADATA = "wilt:redirect";
|
|
62
|
+
interface RedirectMetadata {
|
|
63
|
+
url: string;
|
|
64
|
+
statusCode: number;
|
|
65
|
+
}
|
|
66
|
+
declare function Redirect(url: string, statusCode?: number): MethodDecorator;
|
|
67
|
+
|
|
68
|
+
interface ForwardReference<T = any> {
|
|
69
|
+
forwardRef: () => T;
|
|
70
|
+
}
|
|
71
|
+
interface ModuleMetadata {
|
|
72
|
+
imports?: any[];
|
|
73
|
+
controllers?: any[];
|
|
74
|
+
providers?: any[];
|
|
75
|
+
exports?: any[];
|
|
76
|
+
entities?: any[];
|
|
77
|
+
}
|
|
78
|
+
interface RouteMetadata {
|
|
79
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
80
|
+
path: string;
|
|
81
|
+
handler: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare function Module(config: ModuleMetadata): (target: any) => void;
|
|
85
|
+
|
|
86
|
+
declare const GLOBAL_MODULE_METADATA = "wilt:global";
|
|
87
|
+
declare function Global(): ClassDecorator;
|
|
88
|
+
|
|
89
|
+
declare function createModule<B extends object = Record<string, unknown>>(moduleClass: any, { middlewares }?: {
|
|
90
|
+
middlewares?: any[];
|
|
91
|
+
}): Hono<{
|
|
92
|
+
Bindings: B;
|
|
93
|
+
}>;
|
|
94
|
+
|
|
95
|
+
type HttpStatusCode = 200 | 201 | 202 | 400 | 401 | 403 | 404 | 409 | 500;
|
|
96
|
+
interface BaseResponse<T = any> {
|
|
97
|
+
success: boolean;
|
|
98
|
+
data?: T;
|
|
99
|
+
message?: string;
|
|
100
|
+
timestamp: string;
|
|
101
|
+
}
|
|
102
|
+
interface PaginatedResponse<T = any> extends BaseResponse<T[]> {
|
|
103
|
+
pagination: {
|
|
104
|
+
page: number;
|
|
105
|
+
limit: number;
|
|
106
|
+
total: number;
|
|
107
|
+
totalPages: number;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface ErrorResponse {
|
|
111
|
+
success: false;
|
|
112
|
+
error: {
|
|
113
|
+
code: string;
|
|
114
|
+
message: string;
|
|
115
|
+
stack?: string;
|
|
116
|
+
};
|
|
117
|
+
timestamp: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface HttpArgumentsHost {
|
|
121
|
+
getRequest<T = Context>(): T;
|
|
122
|
+
}
|
|
123
|
+
interface ArgumentsHost {
|
|
124
|
+
switchToHttp(): HttpArgumentsHost;
|
|
125
|
+
}
|
|
126
|
+
interface ExecutionContext extends ArgumentsHost {
|
|
127
|
+
getClass<T = any>(): new (...args: any[]) => T;
|
|
128
|
+
getHandler(): Function;
|
|
129
|
+
}
|
|
130
|
+
declare function createExecutionContext(c: Context, controllerClass: any, handler: Function): ExecutionContext;
|
|
131
|
+
declare function createArgumentsHost(c: Context): ArgumentsHost;
|
|
132
|
+
|
|
133
|
+
interface CanActivate {
|
|
134
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface CallHandler<T = any> {
|
|
138
|
+
handle(): Promise<T>;
|
|
139
|
+
}
|
|
140
|
+
interface NestInterceptor<T = any, R = any> {
|
|
141
|
+
intercept(context: ExecutionContext, next: CallHandler<T>): Promise<R>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface ExceptionFilter<T = any> {
|
|
145
|
+
catch(exception: T, host: ArgumentsHost): Response | Promise<Response> | void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface ArgumentMetadata {
|
|
149
|
+
type: "body" | "query" | "param" | "custom";
|
|
150
|
+
metatype?: new (...args: any[]) => any;
|
|
151
|
+
data?: string;
|
|
152
|
+
}
|
|
153
|
+
interface PipeTransform<T = any, R = any> {
|
|
154
|
+
transform(value: T, metadata: ArgumentMetadata): R | Promise<R>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface OnModuleInit {
|
|
158
|
+
onModuleInit(): void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
interface OnModuleDestroy {
|
|
161
|
+
onModuleDestroy(): void | Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
interface OnApplicationBootstrap {
|
|
164
|
+
onApplicationBootstrap(): void | Promise<void>;
|
|
165
|
+
}
|
|
166
|
+
interface BeforeApplicationShutdown {
|
|
167
|
+
beforeApplicationShutdown(signal?: string): void | Promise<void>;
|
|
168
|
+
}
|
|
169
|
+
interface OnApplicationShutdown {
|
|
170
|
+
onApplicationShutdown(signal?: string): void | Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface ValidationRule {
|
|
174
|
+
field: string;
|
|
175
|
+
required?: boolean;
|
|
176
|
+
type?: "string" | "number" | "boolean" | "object" | "array";
|
|
177
|
+
minLength?: number;
|
|
178
|
+
maxLength?: number;
|
|
179
|
+
pattern?: RegExp;
|
|
180
|
+
custom?: (value: any) => boolean;
|
|
181
|
+
}
|
|
182
|
+
declare function Validate(rules: ValidationRule[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
183
|
+
|
|
184
|
+
declare function ZodValidate(schema: z.ZodSchema): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
185
|
+
|
|
186
|
+
declare function QueryValidate(schema: z.ZodSchema): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
187
|
+
|
|
188
|
+
declare class HttpException extends Error {
|
|
189
|
+
private readonly response;
|
|
190
|
+
private readonly statusCode;
|
|
191
|
+
constructor(response: string | Record<string, any>, statusCode: number);
|
|
192
|
+
getStatus(): number;
|
|
193
|
+
getResponse(): string | Record<string, any>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare class BadRequestException extends HttpException {
|
|
197
|
+
constructor(message?: string | Record<string, any>);
|
|
198
|
+
}
|
|
199
|
+
declare class UnauthorizedException extends HttpException {
|
|
200
|
+
constructor(message?: string | Record<string, any>);
|
|
201
|
+
}
|
|
202
|
+
declare class ForbiddenException extends HttpException {
|
|
203
|
+
constructor(message?: string | Record<string, any>);
|
|
204
|
+
}
|
|
205
|
+
declare class NotFoundException extends HttpException {
|
|
206
|
+
constructor(message?: string | Record<string, any>);
|
|
207
|
+
}
|
|
208
|
+
declare class MethodNotAllowedException extends HttpException {
|
|
209
|
+
constructor(message?: string | Record<string, any>);
|
|
210
|
+
}
|
|
211
|
+
declare class ConflictException extends HttpException {
|
|
212
|
+
constructor(message?: string | Record<string, any>);
|
|
213
|
+
}
|
|
214
|
+
declare class GoneException extends HttpException {
|
|
215
|
+
constructor(message?: string | Record<string, any>);
|
|
216
|
+
}
|
|
217
|
+
declare class UnprocessableEntityException extends HttpException {
|
|
218
|
+
constructor(message?: string | Record<string, any>);
|
|
219
|
+
}
|
|
220
|
+
declare class TooManyRequestsException extends HttpException {
|
|
221
|
+
constructor(message?: string | Record<string, any>);
|
|
222
|
+
}
|
|
223
|
+
declare class InternalServerErrorException extends HttpException {
|
|
224
|
+
constructor(message?: string | Record<string, any>);
|
|
225
|
+
}
|
|
226
|
+
declare class NotImplementedException extends HttpException {
|
|
227
|
+
constructor(message?: string | Record<string, any>);
|
|
228
|
+
}
|
|
229
|
+
declare class ServiceUnavailableException extends HttpException {
|
|
230
|
+
constructor(message?: string | Record<string, any>);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
declare class Reflector {
|
|
234
|
+
get<T = any>(metadataKey: string, target: Function): T;
|
|
235
|
+
getAllAndOverride<T = any>(metadataKey: string, targets: Function[]): T;
|
|
236
|
+
getAllAndMerge<T extends any[] = any[]>(metadataKey: string, targets: Function[]): T;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare function forwardRef<T = any>(fn: () => T): ForwardReference<T>;
|
|
240
|
+
declare function isForwardRef(val: any): val is ForwardReference;
|
|
241
|
+
|
|
242
|
+
declare class _ResponseUtil {
|
|
243
|
+
private static instance;
|
|
244
|
+
private logger;
|
|
245
|
+
private constructor();
|
|
246
|
+
static getInstance(): _ResponseUtil;
|
|
247
|
+
success<T>(c: Context, data: T, message?: string, status?: HttpStatusCode): Response;
|
|
248
|
+
error(c: Context, message: string, status?: HttpStatusCode): Response;
|
|
249
|
+
paginated<T>(c: Context, data: T[], page: number, limit: number, total: number, message?: string): Response;
|
|
250
|
+
}
|
|
251
|
+
declare const ResponseUtil: _ResponseUtil;
|
|
252
|
+
|
|
253
|
+
declare function applyDecorators(...decorators: (ClassDecorator | MethodDecorator | PropertyDecorator)[]): (...args: any[]) => any;
|
|
254
|
+
|
|
255
|
+
export { type ArgumentMetadata, type ArgumentsHost, BadRequestException, type BaseResponse, type BeforeApplicationShutdown, Body, CATCH_METADATA, type CallHandler, type CanActivate, Catch, ConflictException, Controller, type CustomDecorator, Delete, type ErrorResponse, type ExceptionFilter, type ExecutionContext, FILTERS_METADATA, ForbiddenException, type ForwardReference, GLOBAL_MODULE_METADATA, GUARDS_METADATA, Get, Global, GoneException, HEADER_METADATA, HTTP_CODE_METADATA, Header, Headers, type HttpArgumentsHost, HttpCode, HttpException, type HttpStatusCode, INJECT_CUSTOM_TOKENS_KEY, INTERCEPTORS_METADATA, Inject, Injectable, InternalServerErrorException, Ip, MethodNotAllowedException, Module, type ModuleMetadata, type NestInterceptor, NotFoundException, NotImplementedException, OPTIONAL_METADATA, type OnApplicationBootstrap, type OnApplicationShutdown, type OnModuleDestroy, type OnModuleInit, Optional, type PaginatedResponse, Param, Patch, type PipeTransform, Post, Put, Query, QueryValidate, REDIRECT_METADATA, ROUTE_PARAMS_METADATA, Redirect, type RedirectMetadata, Reflector, Req, Req as Request, ResponseUtil, type RouteMetadata, type RouteParamMetadata, type RouteParamType, ServiceUnavailableException, SetMetadata, TOTAL_PARAMS_METADATA, TooManyRequestsException, UnauthorizedException, UnprocessableEntityException, UseFilters, UseGuards, UseInterceptors, Validate, type ValidationRule, ZodValidate, _ResponseUtil, applyDecorators, createArgumentsHost, createExecutionContext, createModule, forwardRef, isForwardRef, registerControllerRoutes };
|