@kanjijs/platform-hono 0.2.0-beta.8 → 1.0.0-alpha.1
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/dist/context-helper.d.ts +16 -0
- package/dist/context-helper.d.ts.map +1 -0
- package/dist/context-helper.js +29 -0
- package/dist/context-helper.js.map +1 -0
- package/dist/decorators/controller.d.ts +2 -0
- package/dist/decorators/controller.d.ts.map +1 -0
- package/dist/decorators/controller.js +7 -0
- package/dist/decorators/controller.js.map +1 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +5 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/rate-limit.d.ts +11 -0
- package/dist/decorators/rate-limit.d.ts.map +1 -0
- package/dist/decorators/rate-limit.js +10 -0
- package/dist/decorators/rate-limit.js.map +1 -0
- package/dist/decorators/route.d.ts +9 -0
- package/dist/decorators/route.d.ts.map +1 -0
- package/dist/decorators/route.js +27 -0
- package/dist/decorators/route.js.map +1 -0
- package/dist/decorators/use.d.ts +3 -0
- package/dist/decorators/use.d.ts.map +1 -0
- package/dist/decorators/use.js +12 -0
- package/dist/decorators/use.js.map +1 -0
- package/dist/exception-filter.service.d.ts +8 -0
- package/dist/exception-filter.service.d.ts.map +1 -0
- package/dist/exception-filter.service.js +15 -0
- package/dist/exception-filter.service.js.map +1 -0
- package/dist/gateway/decorators.d.ts +7 -0
- package/dist/gateway/decorators.d.ts.map +1 -0
- package/dist/gateway/decorators.js +28 -0
- package/dist/gateway/decorators.js.map +1 -0
- package/dist/gateway/handler.d.ts +10 -0
- package/dist/gateway/handler.d.ts.map +1 -0
- package/dist/gateway/handler.js +142 -0
- package/dist/gateway/handler.js.map +1 -0
- package/dist/gateway/index.d.ts +5 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +5 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/ws-context.d.ts +31 -0
- package/dist/gateway/ws-context.d.ts.map +1 -0
- package/dist/gateway/ws-context.js +32 -0
- package/dist/gateway/ws-context.js.map +1 -0
- package/dist/gateway/ws-metadata-storage.d.ts +25 -0
- package/dist/gateway/ws-metadata-storage.d.ts.map +1 -0
- package/dist/gateway/ws-metadata-storage.js +39 -0
- package/dist/gateway/ws-metadata-storage.js.map +1 -0
- package/dist/hono-adapter.d.ts +19 -0
- package/dist/hono-adapter.d.ts.map +1 -0
- package/dist/hono-adapter.js +243 -0
- package/dist/hono-adapter.js.map +1 -0
- package/dist/http-metadata-storage.d.ts +22 -0
- package/dist/http-metadata-storage.d.ts.map +1 -0
- package/dist/http-metadata-storage.js +40 -0
- package/dist/http-metadata-storage.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -3336
- package/dist/index.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +13 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/middleware/rate-limit.js +86 -0
- package/dist/middleware/rate-limit.js.map +1 -0
- package/dist/middleware/request-id.d.ts +3 -0
- package/dist/middleware/request-id.d.ts.map +1 -0
- package/dist/middleware/request-id.js +7 -0
- package/dist/middleware/request-id.js.map +1 -0
- package/dist/middleware/request-logger.d.ts +4 -0
- package/dist/middleware/request-logger.d.ts.map +1 -0
- package/dist/middleware/request-logger.js +31 -0
- package/dist/middleware/request-logger.js.map +1 -0
- package/dist/types.d.ts +41 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/package.json +17 -15
- package/README.md +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { RateLimitOptions } from '../decorators/rate-limit.js';
|
|
3
|
+
interface RateLimitEntry {
|
|
4
|
+
count: number;
|
|
5
|
+
resetAt: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const _rateLimitStore: Map<string, RateLimitEntry>;
|
|
8
|
+
/**
|
|
9
|
+
* Crea un middleware de Hono para limitar la tasa de solicitudes de un endpoint.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRateLimitMiddleware(options: RateLimitOptions, routeKey: string): MiddlewareHandler;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,eAAe,6BAAoC,CAAC;AA4CjE;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,MAAM,GACf,iBAAiB,CAiDnB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TooManyRequestsError } from '@kanjijs/common';
|
|
2
|
+
export const _rateLimitStore = new Map();
|
|
3
|
+
function parseWindow(window) {
|
|
4
|
+
if (typeof window === 'number') {
|
|
5
|
+
return window;
|
|
6
|
+
}
|
|
7
|
+
const match = window.match(/^(\d+)(ms|s|m|h|d)$/);
|
|
8
|
+
if (!match) {
|
|
9
|
+
throw new Error(`Formato de ventana de rate limit inválido: ${window}`);
|
|
10
|
+
}
|
|
11
|
+
const value = parseInt(match[1], 10);
|
|
12
|
+
const unit = match[2];
|
|
13
|
+
switch (unit) {
|
|
14
|
+
case 'ms':
|
|
15
|
+
return value;
|
|
16
|
+
case 's':
|
|
17
|
+
return value * 1000;
|
|
18
|
+
case 'm':
|
|
19
|
+
return value * 60 * 1000;
|
|
20
|
+
case 'h':
|
|
21
|
+
return value * 60 * 60 * 1000;
|
|
22
|
+
case 'd':
|
|
23
|
+
return value * 24 * 60 * 60 * 1000;
|
|
24
|
+
default:
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Cleanup periódico para evitar memory leaks
|
|
29
|
+
const CLEANUP_INTERVAL_MS = 60000; // 1 minuto
|
|
30
|
+
const cleanupTimer = setInterval(() => {
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
for (const [key, entry] of _rateLimitStore.entries()) {
|
|
33
|
+
if (entry.resetAt <= now) {
|
|
34
|
+
_rateLimitStore.delete(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, CLEANUP_INTERVAL_MS);
|
|
38
|
+
// Permitir que el proceso de Bun termine de manera limpia sin esperar a que finalice el timer
|
|
39
|
+
if (typeof cleanupTimer.unref === 'function') {
|
|
40
|
+
cleanupTimer.unref();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Crea un middleware de Hono para limitar la tasa de solicitudes de un endpoint.
|
|
44
|
+
*/
|
|
45
|
+
export function createRateLimitMiddleware(options, routeKey) {
|
|
46
|
+
const windowMs = parseWindow(options.window);
|
|
47
|
+
return async (c, next) => {
|
|
48
|
+
let clientKey = '';
|
|
49
|
+
if (options.by === 'ip') {
|
|
50
|
+
const forwardedFor = c.req.header('x-forwarded-for');
|
|
51
|
+
const realIp = c.req.header('x-real-ip');
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
const remoteAddr = c.env?.incoming?.socket?.remoteAddress; // fallback para entornos Hono genéricos
|
|
54
|
+
clientKey = forwardedFor || realIp || remoteAddr || 'ip:unknown';
|
|
55
|
+
}
|
|
56
|
+
else if (options.by === 'user') {
|
|
57
|
+
const user = c.get('kanji.auth.user');
|
|
58
|
+
const principal = c.get('kanji.auth.principal');
|
|
59
|
+
clientKey = user?.id || principal?.id || 'user:anonymous';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
clientKey = 'global';
|
|
63
|
+
}
|
|
64
|
+
const key = `rate-limit:${routeKey}:${clientKey}`;
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
let entry = _rateLimitStore.get(key);
|
|
67
|
+
if (!entry || entry.resetAt <= now) {
|
|
68
|
+
entry = {
|
|
69
|
+
count: 0,
|
|
70
|
+
resetAt: now + windowMs,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
entry.count++;
|
|
74
|
+
_rateLimitStore.set(key, entry);
|
|
75
|
+
const remaining = Math.max(0, options.limit - entry.count);
|
|
76
|
+
const resetSeconds = Math.ceil((entry.resetAt - now) / 1000);
|
|
77
|
+
c.header('X-RateLimit-Limit', String(options.limit));
|
|
78
|
+
c.header('X-RateLimit-Remaining', String(remaining));
|
|
79
|
+
c.header('X-RateLimit-Reset', String(resetSeconds));
|
|
80
|
+
if (entry.count > options.limit) {
|
|
81
|
+
throw new TooManyRequestsError('Límite de solicitudes excedido. Por favor intente más tarde.');
|
|
82
|
+
}
|
|
83
|
+
await next();
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAQvD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEjE,SAAS,WAAW,CAAC,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,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id.js","sourceRoot":"","sources":["../../src/middleware/request-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAsB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;IACtE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAoB,EAAE,UAAU,EAAE,CAAC,CAAC;IACpD,MAAM,IAAI,EAAE,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.d.ts","sourceRoot":"","sources":["../../src/middleware/request-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,iBAAiB,CA6B/E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LOGGER } from '@kanjijs/common';
|
|
2
|
+
export function requestLoggerMiddleware(container) {
|
|
3
|
+
// Resolve dependency once during initialization to avoid request-time lookup overhead
|
|
4
|
+
const logger = container.getInstances().get(LOGGER);
|
|
5
|
+
return async (c, next) => {
|
|
6
|
+
if (!logger) {
|
|
7
|
+
return next();
|
|
8
|
+
}
|
|
9
|
+
const startTime = performance.now();
|
|
10
|
+
const method = c.req.method;
|
|
11
|
+
const path = c.req.path; // Efficient path resolution without URL parsing overhead
|
|
12
|
+
try {
|
|
13
|
+
await next();
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
const duration = (performance.now() - startTime).toFixed(2);
|
|
17
|
+
const status = c.res.status;
|
|
18
|
+
const message = `${method} ${path} - ${status} - +${duration}ms`;
|
|
19
|
+
if (status >= 500) {
|
|
20
|
+
logger.error(message, undefined, 'Router');
|
|
21
|
+
}
|
|
22
|
+
else if (status >= 400) {
|
|
23
|
+
logger.warn(message, 'Router');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
logger.log(message, 'Router');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=request-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.js","sourceRoot":"","sources":["../../src/middleware/request-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAe,MAAM,iBAAiB,CAAC;AAGtD,MAAM,UAAU,uBAAuB,CAAC,SAAoB;IAC1D,sFAAsF;IACtF,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAA4B,CAAC;IAE/E,OAAO,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACvB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;QAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,yDAAyD;QAElF,IAAI,CAAC;YACH,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,MAAM,QAAQ,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5D,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;YAC5B,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,IAAI,MAAM,MAAM,OAAO,QAAQ,IAAI,CAAC;YAEjE,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBAClB,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;iBAAM,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBACzB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import { KanjiLogger } from '@kanjijs/common';
|
|
3
|
+
export declare const KANJI_CTX: {
|
|
4
|
+
readonly VALIDATED_BODY: "kanji.validated.body";
|
|
5
|
+
readonly VALIDATED_QUERY: "kanji.validated.query";
|
|
6
|
+
readonly VALIDATED_PARAMS: "kanji.validated.params";
|
|
7
|
+
readonly VALIDATED_HEADERS: "kanji.validated.headers";
|
|
8
|
+
readonly VALIDATED_COOKIES: "kanji.validated.cookies";
|
|
9
|
+
readonly AUTH_USER: "kanji.auth.user";
|
|
10
|
+
readonly AUTH_SESSION: "kanji.auth.session";
|
|
11
|
+
readonly AUTH_ROLES: "kanji.auth.roles";
|
|
12
|
+
readonly AUTH_PRINCIPAL: "kanji.auth.principal";
|
|
13
|
+
readonly AUTH_SCOPES: "kanji.auth.scopes";
|
|
14
|
+
readonly AUTHZ_CACHE: "kanji.authz.cache";
|
|
15
|
+
readonly AUTHZ_DECISION: "kanji.authz.decision";
|
|
16
|
+
readonly REQUEST_ID: "kanji.requestId";
|
|
17
|
+
readonly CONTAINER: "kanji.container";
|
|
18
|
+
};
|
|
19
|
+
export interface CorsOptions {
|
|
20
|
+
origin?: string | string[] | ((origin: string) => string);
|
|
21
|
+
allowMethods?: string[];
|
|
22
|
+
allowHeaders?: string[];
|
|
23
|
+
credentials?: boolean;
|
|
24
|
+
maxAge?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ContractMetadata {
|
|
27
|
+
method: string;
|
|
28
|
+
path: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Validator {
|
|
31
|
+
validate(contract: ContractMetadata): MiddlewareHandler;
|
|
32
|
+
}
|
|
33
|
+
export interface KanjijsPlatformOptions {
|
|
34
|
+
validator?: Validator;
|
|
35
|
+
logger?: KanjiLogger | boolean;
|
|
36
|
+
requestLogger?: boolean;
|
|
37
|
+
cors?: CorsOptions | boolean;
|
|
38
|
+
exceptionFilters?: Array<new (...args: never[]) => any>;
|
|
39
|
+
}
|
|
40
|
+
export type KanjijsAdapterOptions = KanjijsPlatformOptions;
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;CAeZ,CAAC;AAEX,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAC1D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;CACzD;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;CACzD;AAED,MAAM,MAAM,qBAAqB,GAAG,sBAAsB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/platform-hono/src/types.ts
|
|
2
|
+
export const KANJI_CTX = {
|
|
3
|
+
VALIDATED_BODY: 'kanji.validated.body',
|
|
4
|
+
VALIDATED_QUERY: 'kanji.validated.query',
|
|
5
|
+
VALIDATED_PARAMS: 'kanji.validated.params',
|
|
6
|
+
VALIDATED_HEADERS: 'kanji.validated.headers',
|
|
7
|
+
VALIDATED_COOKIES: 'kanji.validated.cookies',
|
|
8
|
+
AUTH_USER: 'kanji.auth.user',
|
|
9
|
+
AUTH_SESSION: 'kanji.auth.session',
|
|
10
|
+
AUTH_ROLES: 'kanji.auth.roles',
|
|
11
|
+
AUTH_PRINCIPAL: 'kanji.auth.principal',
|
|
12
|
+
AUTH_SCOPES: 'kanji.auth.scopes',
|
|
13
|
+
AUTHZ_CACHE: 'kanji.authz.cache',
|
|
14
|
+
AUTHZ_DECISION: 'kanji.authz.decision',
|
|
15
|
+
REQUEST_ID: 'kanji.requestId',
|
|
16
|
+
CONTAINER: 'kanji.container',
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAKtC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,cAAc,EAAE,sBAAsB;IACtC,eAAe,EAAE,uBAAuB;IACxC,gBAAgB,EAAE,wBAAwB;IAC1C,iBAAiB,EAAE,yBAAyB;IAC5C,iBAAiB,EAAE,yBAAyB;IAC5C,SAAS,EAAE,iBAAiB;IAC5B,YAAY,EAAE,oBAAoB;IAClC,UAAU,EAAE,kBAAkB;IAC9B,cAAc,EAAE,sBAAsB;IACtC,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,mBAAmB;IAChC,cAAc,EAAE,sBAAsB;IACtC,UAAU,EAAE,iBAAiB;IAC7B,SAAS,EAAE,iBAAiB;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/platform-hono",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
5
4
|
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
5
|
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
"README.md",
|
|
10
|
-
"LICENSE"
|
|
6
|
+
"dist"
|
|
11
7
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
},
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
15
10
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
11
|
+
"hono": "4.12.27",
|
|
12
|
+
"reflect-metadata": "0.2.2",
|
|
13
|
+
"@kanjijs/common": "1.0.0-alpha.1",
|
|
14
|
+
"@kanjijs/core": "1.0.0-alpha.1"
|
|
20
15
|
},
|
|
21
16
|
"peerDependencies": {
|
|
22
|
-
"
|
|
17
|
+
"typescript": "6.0.3",
|
|
18
|
+
"@kanjijs/auth": "1.0.0-alpha.1",
|
|
19
|
+
"@kanjijs/contracts": "1.0.0-alpha.1"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"dev": "tsc --watch",
|
|
24
|
+
"test": "bun test"
|
|
23
25
|
}
|
|
24
|
-
}
|
|
26
|
+
}
|
package/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# @kanjijs/platform-hono
|
|
2
|
-
|
|
3
|
-
The default HTTP adapter for [Kanjijs Framework](https://github.com/kanjijs-framework), utilizing [Hono](https://hono.dev/) for high-performance routing.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { KanjijsAdapter } from "@kanjijs/platform-hono";
|
|
9
|
-
import { AppModule } from "./app.module";
|
|
10
|
-
|
|
11
|
-
// Create Hono app from Root Module
|
|
12
|
-
const app = KanjijsAdapter.create(AppModule);
|
|
13
|
-
|
|
14
|
-
// Serve with Bun
|
|
15
|
-
export default {
|
|
16
|
-
port: 3000,
|
|
17
|
-
fetch: app.fetch
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Features
|
|
22
|
-
|
|
23
|
-
- **KanjijsAdapter**: Recursively scans your Module tree to register controllers.
|
|
24
|
-
- **Middleware Support**: Seamless integration with native Hono middlewares via `@Use` and Global Middleware injection.
|
|
25
|
-
- **Validation Middleware**: Automatically enforces Zod contracts on Requests (Headers, Path, Query, Body).
|
|
26
|
-
- **Dependency Injection**: Built-in `KanjijsIoC` container resolution for Controllers.
|
|
27
|
-
- **Request Context**: Automatically generates `x-request-id` header and initializes context for `@kanjijs/logger`.
|
|
28
|
-
- **Global Exception Filters**: Automatically catches all errors (404, 500, Zod) and transforms them into a standard JSON response (`{ statusCode, message, error }`).
|
|
29
|
-
- **Security Headers**: Integrated support for Helmet and Throttler headers.
|