raiton 6.6.0-beta.14 → 6.7.0-beta.15
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 +10 -0
- package/README.md +16 -9
- package/build/bin/index.mjs +8170 -3997
- package/deno.json +4 -1
- package/docs/contributors/framework/README.md +2 -0
- package/docs/contributors/framework/cache/README.md +55 -0
- package/docs/contributors/framework/cache/cache.md +86 -0
- package/docs/contributors/framework/cache/etag.md +82 -0
- package/docs/contributors/framework/decorators/README.md +1 -0
- package/docs/contributors/framework/runtime.md +13 -3
- package/docs/user-guide/README.md +1 -0
- package/docs/user-guide/cache.md +79 -0
- package/docs/user-guide/cli.md +35 -3
- package/docs/user-guide/decorators/README.md +1 -0
- package/docs/user-guide/decorators/cache.md +79 -0
- package/docs/user-guide/runtime.md +2 -1
- package/package.json +8 -3
- package/source/bin/bootstrapper.ts +4 -4
- package/source/bin/cli-tools.ts +27 -3
- package/source/bin/cli.ts +2 -2
- package/source/bin/commands.registry.ts +17 -0
- package/source/bin/constants.ts +1 -0
- package/source/bin/index.ts +2 -2
- package/source/commands/artifact.command.ts +2 -2
- package/source/commands/build.command.ts +2 -2
- package/source/commands/develop.command.ts +4 -5
- package/source/commands/grafts.command.ts +1 -1
- package/source/commands/start.command.ts +2 -2
- package/source/core/application.ts +10 -10
- package/source/core/artifacts/artifact.ts +1 -1
- package/source/core/artifacts/index.ts +1 -1
- package/source/core/builder.ts +69 -15
- package/source/core/bytes.util.ts +1 -1
- package/source/core/commands.ts +24 -14
- package/source/core/config/config.ts +2 -2
- package/source/core/config/define.ts +2 -2
- package/source/core/config/index.ts +2 -2
- package/source/core/context.ts +1 -1
- package/source/core/controller/builder.ts +9 -9
- package/source/core/controller/compiler.ts +6 -6
- package/source/core/controller/index.ts +4 -4
- package/source/core/controller/metadata.ts +2 -2
- package/source/core/controller/tracker.ts +1 -1
- package/source/core/directories.ts +3 -2
- package/source/core/guards.ts +1 -1
- package/source/core/helpers/index.ts +1 -1
- package/source/core/hooks.ts +1 -1
- package/source/core/index.ts +16 -16
- package/source/core/injection/index.ts +1 -1
- package/source/core/injection/injection.ts +3 -3
- package/source/core/mcp/builder.ts +8 -8
- package/source/core/mcp/index.ts +3 -3
- package/source/core/mcp/metadata.ts +2 -2
- package/source/core/mcp/tracker.ts +1 -1
- package/source/core/middleware/compose.ts +2 -2
- package/source/core/middleware/index.ts +2 -2
- package/source/core/middleware/pipeline.ts +2 -2
- package/source/core/plugins/index.ts +2 -2
- package/source/core/plugins/plugin.ts +1 -1
- package/source/core/plugins/scope.ts +4 -4
- package/source/core/raiton.ts +1 -1
- package/source/core/router/handler.ts +30 -6
- package/source/core/router/handler.utils.ts +3 -3
- package/source/core/router/index.ts +4 -4
- package/source/core/router/matcher.ts +1 -1
- package/source/core/router/route.ts +1 -1
- package/source/core/router/router.ts +4 -4
- package/source/core/server.ts +1 -1
- package/source/core/socket/builder.ts +2 -2
- package/source/core/socket/index.ts +2 -2
- package/source/core/socket/metadata.ts +2 -2
- package/source/core/thread.ts +51 -22
- package/source/framework/artifacts.ts +5 -5
- package/source/framework/cache/cache.decorator.ts +35 -0
- package/source/framework/cache/cache.ts +197 -0
- package/source/framework/cache/etag.ts +174 -0
- package/source/framework/cache/index.ts +4 -0
- package/source/framework/cache/types.ts +111 -0
- package/source/framework/constants/decorators.constant.ts +2 -0
- package/source/framework/constants/index.ts +2 -2
- package/source/framework/decorators/access-guard.decorator.ts +2 -2
- package/source/framework/decorators/api-response.decorator.ts +1 -1
- package/source/framework/decorators/api.decorator.ts +1 -1
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +4 -4
- package/source/framework/decorators/csrf-token.decorator.ts +1 -1
- package/source/framework/decorators/guard.decorator.ts +4 -4
- package/source/framework/decorators/health-check.decorator.ts +3 -3
- package/source/framework/decorators/index.ts +14 -14
- package/source/framework/decorators/injection.decorator.ts +3 -3
- package/source/framework/decorators/mcp.decorator.ts +4 -4
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -2
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +4 -4
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +2 -2
- package/source/framework/enums/index.ts +8 -8
- package/source/framework/enums/runtime.enum.ts +1 -2
- package/source/framework/env.ts +2 -2
- package/source/framework/exceptions/http-exception.ts +3 -3
- package/source/framework/exceptions/index.ts +2 -2
- package/source/framework/health-check.ts +4 -4
- package/source/framework/index.ts +18 -17
- package/source/framework/mcp/handler.ts +3 -3
- package/source/framework/mcp/index.ts +3 -3
- package/source/framework/mcp/protocol.ts +1 -1
- package/source/framework/mcp/streamable-http.ts +3 -3
- package/source/framework/parameter-bag.ts +2 -2
- package/source/framework/plugins/body-parser.plugin.ts +3 -3
- package/source/framework/plugins/index.ts +4 -4
- package/source/framework/plugins/mcp.plugin.ts +5 -5
- package/source/framework/plugins/openapi.plugin.ts +4 -4
- package/source/framework/plugins/security/body-limit.ts +3 -3
- package/source/framework/plugins/security/cors.ts +2 -2
- package/source/framework/plugins/security/csrf.ts +6 -6
- package/source/framework/plugins/security/headers.ts +2 -2
- package/source/framework/plugins/security/index.ts +6 -6
- package/source/framework/plugins/security/method-guard.ts +3 -3
- package/source/framework/plugins/security/rate-limit.ts +3 -3
- package/source/framework/repositories.ts +1 -1
- package/source/framework/responses/error.ts +2 -2
- package/source/framework/responses/helpers.ts +3 -3
- package/source/framework/responses/http-throwable.ts +3 -3
- package/source/framework/responses/http.ts +3 -3
- package/source/framework/responses/index.ts +4 -4
- package/source/framework/runtime/bun/server.ts +5 -5
- package/source/framework/runtime/deno/server.ts +156 -96
- package/source/framework/runtime/index.ts +11 -17
- package/source/framework/runtime/node/reply.ts +1 -1
- package/source/framework/runtime/node/request.ts +2 -2
- package/source/framework/runtime/node/server.ts +3 -3
- package/source/framework/runtime/web/server.ts +2 -2
- package/source/framework/services.ts +1 -1
- package/source/framework/utilities/csrf.util.ts +1 -1
- package/source/framework/utilities/index.ts +10 -10
- package/source/framework/utilities/openapi.utils.ts +7 -7
- package/source/framework/utilities/utilities.util.ts +1 -1
- package/source/types/application.ts +2 -2
- package/source/types/builder.ts +1 -1
- package/source/types/config.ts +1 -1
- package/source/types/controller.ts +3 -3
- package/source/types/core.ts +1 -1
- package/source/types/csrf.ts +1 -1
- package/source/types/guard.ts +1 -1
- package/source/types/http-responses.ts +1 -1
- package/source/types/index.ts +26 -26
- package/source/types/injection.ts +1 -1
- package/source/types/middleware.ts +1 -1
- package/source/types/plugin.ts +1 -1
- package/source/types/raiton.ts +1 -1
- package/source/types/responses.ts +2 -2
- package/source/types/router.ts +2 -2
- package/source/types/runtime.ts +3 -5
- package/source/types/thread.ts +4 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {secureHeaders} from './headers'
|
|
2
|
-
import {secureCors} from './cors'
|
|
3
|
-
import {secureRateLimit} from './rate-limit'
|
|
4
|
-
import {secureBodyLimit} from './body-limit'
|
|
5
|
-
import {secureMethodGuard} from './method-guard'
|
|
6
|
-
import {secureCsrf} from './csrf'
|
|
1
|
+
import {secureHeaders} from './headers.ts'
|
|
2
|
+
import {secureCors} from './cors.ts'
|
|
3
|
+
import {secureRateLimit} from './rate-limit.ts'
|
|
4
|
+
import {secureBodyLimit} from './body-limit.ts'
|
|
5
|
+
import {secureMethodGuard} from './method-guard.ts'
|
|
6
|
+
import {secureCsrf} from './csrf.ts'
|
|
7
7
|
|
|
8
8
|
export class Security {
|
|
9
9
|
static headers = secureHeaders
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
|
-
import {RaitonResponses, HttpStatus} from "
|
|
1
|
+
import {definePlugin} from "../../../core/plugins/index.ts";
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types/index.ts";
|
|
3
|
+
import {RaitonResponses, HttpStatus} from "../../index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export const secureMethodGuard = (allowed: string[]) =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
|
-
import {RaitonResponses, HttpStatus} from "
|
|
1
|
+
import {definePlugin} from "../../../core/plugins/index.ts";
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types/index.ts";
|
|
3
|
+
import {RaitonResponses, HttpStatus} from "../../index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export interface RateLimitOptions {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {HttpResponse, HttpStatus} from "
|
|
2
|
-
import {HttpResponseInterface} from "../../types";
|
|
3
|
-
import {Raiton} from "../../core";
|
|
1
|
+
import {HttpResponse, HttpStatus} from "../index.ts";
|
|
2
|
+
import {HttpResponseInterface} from "../../types/index.ts";
|
|
3
|
+
import {Raiton} from "../../core/index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export function RaitonResponses(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {HttpResponseInterface} from "../../types";
|
|
2
|
-
import {HttpStatus} from "../enums";
|
|
3
|
-
import {Raiton} from "../../core";
|
|
1
|
+
import {HttpResponseInterface} from "../../types/index.ts";
|
|
2
|
+
import {HttpStatus} from "../enums/index.ts";
|
|
3
|
+
import {Raiton} from "../../core/index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class ThrowableResponse extends Error {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {HttpResponseInterface} from "../../types";
|
|
2
|
-
import {HttpStatus} from "../enums";
|
|
3
|
-
import {ThrowableResponse} from ".";
|
|
1
|
+
import {HttpResponseInterface} from "../../types/index.ts";
|
|
2
|
+
import {HttpStatus} from "../enums/index.ts";
|
|
3
|
+
import {ThrowableResponse} from "./index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class HttpResponse {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./error"
|
|
2
|
-
export * from "./http-throwable"
|
|
3
|
-
export * from "./http"
|
|
4
|
-
export * from "./helpers"
|
|
1
|
+
export * from "./error.ts"
|
|
2
|
+
export * from "./http-throwable.ts"
|
|
3
|
+
export * from "./http.ts"
|
|
4
|
+
export * from "./helpers.ts"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RuntimeAdapterInterface,
|
|
3
3
|
RuntimeServerOptionsInterface,
|
|
4
|
-
} from '../../../types'
|
|
4
|
+
} from '../../../types/index.ts'
|
|
5
5
|
import {Logger} from "@protorians/logger";
|
|
6
|
-
import {getRealIp} from "../../utilities";
|
|
7
|
-
import {findSocketForPath} from "../../../core/socket";
|
|
8
|
-
import {Injection} from "../../../core/injection";
|
|
9
|
-
import {RaitonResponses, HttpStatus} from "
|
|
6
|
+
import {getRealIp} from "../../utilities/index.ts";
|
|
7
|
+
import {findSocketForPath} from "../../../core/socket/index.ts";
|
|
8
|
+
import {Injection} from "../../../core/injection/index.ts";
|
|
9
|
+
import {RaitonResponses, HttpStatus} from "../../index.ts";
|
|
10
10
|
|
|
11
11
|
export const bunRuntime: RuntimeAdapterInterface = {
|
|
12
12
|
createServer(handler, options?: RuntimeServerOptionsInterface) {
|
|
@@ -1,106 +1,166 @@
|
|
|
1
|
-
import {RuntimeAdapterInterface,
|
|
1
|
+
import {RuntimeAdapterInterface, RuntimeServerOptionsInterface} from '../../../types/index.ts'
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import {getRealIp} from "../../utilities";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// get url(): string { return this.req.url; }
|
|
9
|
-
// get headers(): Headers { return new Headers(this.req.headers); }
|
|
10
|
-
// get body(): any { return this.req.body; }
|
|
11
|
-
// get query(): Record<string, any> | undefined { return undefined; }
|
|
12
|
-
// get params(): Record<string, any> | undefined { return undefined; }
|
|
13
|
-
// get file(): any { return undefined; }
|
|
14
|
-
// get files(): any { return undefined; }
|
|
15
|
-
// get remoteAddress(): string | undefined { return undefined; }
|
|
16
|
-
// get ip(): string | undefined { return getRealIp(this.headers, this.remoteAddress); }
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
// class DenoReply implements RuntimeReplyInterface {
|
|
20
|
-
// private statusCode: number = 200;
|
|
21
|
-
// private headers: Headers = new Headers();
|
|
22
|
-
// private body: BodyInit | null = null;
|
|
23
|
-
//
|
|
24
|
-
// status(code: number): void { this.statusCode = code; }
|
|
25
|
-
// header(name: string, value: string): void { this.headers.set(name, value); }
|
|
26
|
-
// send(body: any): void {
|
|
27
|
-
// if (body === undefined) {
|
|
28
|
-
// this.body = null;
|
|
29
|
-
// } else if (typeof body === 'string' || body instanceof Uint8Array) {
|
|
30
|
-
// this.body = body;
|
|
31
|
-
// } else {
|
|
32
|
-
// if (!this.headers.has('content-type')) {
|
|
33
|
-
// this.headers.set('content-type', 'application/json');
|
|
34
|
-
// }
|
|
35
|
-
// this.body = JSON.stringify(body);
|
|
36
|
-
// }
|
|
37
|
-
// }
|
|
38
|
-
// text(text: string | Buffer): void {
|
|
39
|
-
// // Accept string, Uint8Array, or any other value (including Buffer-like)
|
|
40
|
-
// if (typeof text === 'string' || text instanceof Uint8Array) {
|
|
41
|
-
// this.body = text;
|
|
42
|
-
// } else {
|
|
43
|
-
// // Fallback: treat as JSON string
|
|
44
|
-
// this.body = JSON.stringify(text);
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// json(json: any): void {
|
|
48
|
-
// this.headers.set('content-type', 'application/json');
|
|
49
|
-
// this.body = JSON.stringify(json);
|
|
50
|
-
// }
|
|
51
|
-
// type(contentType: string): void {
|
|
52
|
-
// this.headers.set('content-type', contentType);
|
|
53
|
-
// }
|
|
54
|
-
// toResponse(): Response {
|
|
55
|
-
// let bodyToSend: BodyInit = '';
|
|
56
|
-
// if (this.body instanceof Uint8Array) {
|
|
57
|
-
// bodyToSend = this.body;
|
|
58
|
-
// } else if (typeof this.body === 'string') {
|
|
59
|
-
// bodyToSend = this.body;
|
|
60
|
-
// } else if (this.body === null) {
|
|
61
|
-
// bodyToSend = '';
|
|
62
|
-
// } else {
|
|
63
|
-
// // fallback: treat as JSON
|
|
64
|
-
// bodyToSend = JSON.stringify(this.body);
|
|
65
|
-
// }
|
|
66
|
-
// return new Response(bodyToSend, { status: this.statusCode, headers: this.headers });
|
|
67
|
-
// }
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @alpha Not ready
|
|
72
|
-
*/
|
|
3
|
+
import {getRealIp} from "../../utilities/index.ts";
|
|
4
|
+
import {findSocketForPath} from "../../../core/socket/index.ts";
|
|
5
|
+
import {Injection} from "../../../core/injection/index.ts";
|
|
6
|
+
import {RaitonResponses, HttpStatus} from "../../index.ts";
|
|
7
|
+
|
|
73
8
|
export const denoRuntime: RuntimeAdapterInterface = {
|
|
74
|
-
createServer(handler) {
|
|
75
|
-
|
|
9
|
+
createServer(handler, options?: RuntimeServerOptionsInterface) {
|
|
10
|
+
if (typeof Deno === 'undefined') throw new Error(
|
|
11
|
+
'Deno is not available, please run this script with the Deno runtime (`deno run --allow-net ...`)'
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
let server: Deno.HttpServer | null = null
|
|
15
|
+
|
|
16
|
+
const socketHandlers = {
|
|
17
|
+
open(socket: WebSocket, entry: any) {
|
|
18
|
+
try {
|
|
19
|
+
const instance: any = Injection.resolve(entry.construct)
|
|
20
|
+
if (!instance) return
|
|
21
|
+
|
|
22
|
+
socket.onmessage = async (event: MessageEvent) => {
|
|
23
|
+
try {
|
|
24
|
+
let payload: any = event.data
|
|
25
|
+
if (typeof payload === 'string') {
|
|
26
|
+
try { payload = JSON.parse(payload) } catch { /* keep raw string */ }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const eventName = payload && typeof payload === 'object' ? payload.event : undefined
|
|
30
|
+
const evt = eventName
|
|
31
|
+
? entry.metadata.events.find((item: any) => item.name === eventName && (item.type === 'event' || item.type === 'message'))
|
|
32
|
+
: entry.metadata.events.find((item: any) => item.type === 'message')
|
|
33
|
+
|
|
34
|
+
if (!evt) {
|
|
35
|
+
socket.send(JSON.stringify(RaitonResponses(
|
|
36
|
+
`Socket event "${eventName ?? 'message'}" not found`,
|
|
37
|
+
null,
|
|
38
|
+
HttpStatus.NOT_FOUND
|
|
39
|
+
)))
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const response = await instance[evt.propertyKey]?.(payload?.data ?? payload)
|
|
44
|
+
if (response !== undefined) {
|
|
45
|
+
socket.send(JSON.stringify(response))
|
|
46
|
+
}
|
|
47
|
+
} catch (e: any) {
|
|
48
|
+
Logger.error('Socket message failed', e.message ?? e)
|
|
49
|
+
socket.send(JSON.stringify(RaitonResponses(
|
|
50
|
+
'Internal server error',
|
|
51
|
+
null,
|
|
52
|
+
HttpStatus.INTERNAL_SERVER_ERROR
|
|
53
|
+
)))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const connect = entry.metadata.events.find((event: any) => event.type === 'connect')
|
|
58
|
+
if (connect) instance[connect.propertyKey]?.()
|
|
59
|
+
} catch (e: any) {
|
|
60
|
+
Logger.error('Socket connect failed', e.message ?? e)
|
|
61
|
+
try { socket.close(1011, 'Internal error') } catch { /* noop */ }
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
close(socket: WebSocket, entry: any) {
|
|
65
|
+
try {
|
|
66
|
+
const instance = (socket as any)._instance
|
|
67
|
+
if (!instance) return
|
|
68
|
+
|
|
69
|
+
const disconnect = entry.metadata.events.find((event: any) => event.type === 'disconnect')
|
|
70
|
+
if (disconnect) instance[disconnect.propertyKey]?.()
|
|
71
|
+
} catch (e: any) {
|
|
72
|
+
Logger.error('Socket disconnect failed', e.message ?? e)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
76
|
|
|
77
77
|
return {
|
|
78
78
|
async listen(port, hostname) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
server = Deno.serve(
|
|
80
|
+
{
|
|
81
|
+
port: Number(port),
|
|
82
|
+
hostname,
|
|
83
|
+
onListen() {
|
|
84
|
+
Logger.log('Deno server listening')
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async (request, info) => {
|
|
88
|
+
const upgrade = request.headers.get('upgrade')?.toLowerCase()
|
|
89
|
+
const pathname = new URL(request.url).pathname
|
|
90
|
+
|
|
91
|
+
if (upgrade === 'websocket') {
|
|
92
|
+
const socketEntry = findSocketForPath(pathname, options?.prefix)
|
|
93
|
+
if (socketEntry) {
|
|
94
|
+
const {socket, response} = Deno.upgradeWebSocket(request)
|
|
95
|
+
const instance: any = Injection.resolve(socketEntry.construct)
|
|
96
|
+
;(socket as any)._instance = instance
|
|
97
|
+
socket.onopen = () => socketHandlers.open(socket, socketEntry)
|
|
98
|
+
socket.onclose = () => socketHandlers.close(socket, socketEntry)
|
|
99
|
+
return response
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let responseBody: any
|
|
104
|
+
let statusCode = 200
|
|
105
|
+
const headers = new Headers()
|
|
106
|
+
|
|
107
|
+
const remoteAddress = info.remoteAddr?.hostname
|
|
108
|
+
|
|
109
|
+
await handler(
|
|
110
|
+
{
|
|
111
|
+
method: request.method,
|
|
112
|
+
url: request.url,
|
|
113
|
+
headers: request.headers as any,
|
|
114
|
+
body: request.body ? request.body : null,
|
|
115
|
+
remoteAddress,
|
|
116
|
+
ip: getRealIp(request.headers, remoteAddress)
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
status(code) {
|
|
120
|
+
statusCode = code
|
|
121
|
+
},
|
|
122
|
+
header(name, value) {
|
|
123
|
+
headers.set(name, value)
|
|
124
|
+
},
|
|
125
|
+
send(body: any) {
|
|
126
|
+
if (body === undefined) {
|
|
127
|
+
responseBody = ''
|
|
128
|
+
} else if (typeof body === 'string' || body instanceof Uint8Array) {
|
|
129
|
+
responseBody = body;
|
|
130
|
+
} else {
|
|
131
|
+
headers.set('content-type', 'application/json');
|
|
132
|
+
responseBody = (JSON.stringify(body));
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
text(text: string | Uint8Array) {
|
|
136
|
+
responseBody = text
|
|
137
|
+
},
|
|
138
|
+
json(json: any) {
|
|
139
|
+
headers.set('content-type', 'application/json')
|
|
140
|
+
responseBody = JSON.stringify(json)
|
|
141
|
+
},
|
|
142
|
+
type(contentType: string) {
|
|
143
|
+
headers.set('content-type', contentType)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if (responseBody instanceof Response) {
|
|
149
|
+
return responseBody;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return new Response(
|
|
153
|
+
typeof responseBody === 'object' && !(responseBody instanceof Uint8Array)
|
|
154
|
+
? JSON.stringify(responseBody)
|
|
155
|
+
: responseBody,
|
|
156
|
+
{status: statusCode, headers}
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
)
|
|
97
160
|
},
|
|
98
161
|
async close() {
|
|
99
|
-
|
|
100
|
-
// controller.abort();
|
|
101
|
-
// }
|
|
102
|
-
// Note: Deno.serve does not expose a direct stop; closing the signal aborts incoming connections.
|
|
162
|
+
await server?.shutdown()
|
|
103
163
|
}
|
|
104
|
-
}
|
|
164
|
+
}
|
|
105
165
|
}
|
|
106
166
|
}
|
|
@@ -4,12 +4,12 @@ import type {
|
|
|
4
4
|
RuntimeInterface,
|
|
5
5
|
RuntimeServerInterface,
|
|
6
6
|
RuntimeServerOptionsInterface
|
|
7
|
-
} from "../../types";
|
|
8
|
-
import {RuntimeType} from "../enums/runtime.enum";
|
|
9
|
-
import {nodeRuntime} from "./node/server";
|
|
10
|
-
import {bunRuntime} from "./bun/server";
|
|
11
|
-
import {denoRuntime} from "./deno/server";
|
|
12
|
-
// import {webRuntime} from "./web/server";
|
|
7
|
+
} from "../../types/index.ts";
|
|
8
|
+
import {RuntimeType} from "../enums/runtime.enum.ts";
|
|
9
|
+
import {nodeRuntime} from "./node/server.ts";
|
|
10
|
+
import {bunRuntime} from "./bun/server.ts";
|
|
11
|
+
import {denoRuntime} from "./deno/server.ts";
|
|
12
|
+
// import {webRuntime} from "./web/server.ts";
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export class Runtime implements RuntimeInterface {
|
|
@@ -22,13 +22,9 @@ export class Runtime implements RuntimeInterface {
|
|
|
22
22
|
return this.type === RuntimeType.Node;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
// get isWeb(): boolean {
|
|
30
|
-
// return this.type === RuntimeType.Web;
|
|
31
|
-
// }
|
|
25
|
+
get isDeno(): boolean {
|
|
26
|
+
return this.type === RuntimeType.Deno;
|
|
27
|
+
}
|
|
32
28
|
|
|
33
29
|
get isBun(): boolean {
|
|
34
30
|
return this.type === RuntimeType.Bun;
|
|
@@ -40,10 +36,8 @@ export class Runtime implements RuntimeInterface {
|
|
|
40
36
|
return nodeRuntime
|
|
41
37
|
case RuntimeType.Bun:
|
|
42
38
|
return bunRuntime
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// case RuntimeType.Web:
|
|
46
|
-
// return webRuntime
|
|
39
|
+
case RuntimeType.Deno:
|
|
40
|
+
return denoRuntime
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerResponse } from 'node:http'
|
|
2
|
-
import type { RuntimeReplyInterface } from '../../../types'
|
|
2
|
+
import type { RuntimeReplyInterface } from '../../../types/index.ts'
|
|
3
3
|
|
|
4
4
|
export class NodeReply implements RuntimeReplyInterface {
|
|
5
5
|
constructor(public res: ServerResponse) {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage } from 'node:http'
|
|
2
|
-
import type { RuntimeRequestInterface } from '../../../types'
|
|
3
|
-
import {getRealIp} from "../../utilities";
|
|
2
|
+
import type { RuntimeRequestInterface } from '../../../types/index.ts'
|
|
3
|
+
import {getRealIp} from "../../utilities/index.ts";
|
|
4
4
|
|
|
5
5
|
export class NodeRequest implements RuntimeRequestInterface {
|
|
6
6
|
constructor(public req: IncomingMessage) {
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
RuntimeRequestInterface,
|
|
6
6
|
RuntimeReplyInterface,
|
|
7
7
|
RuntimeServerOptionsInterface
|
|
8
|
-
} from '../../../types'
|
|
9
|
-
import { NodeRequest } from './request'
|
|
10
|
-
import { NodeReply } from './reply'
|
|
8
|
+
} from '../../../types/index.ts'
|
|
9
|
+
import { NodeRequest } from './request.ts'
|
|
10
|
+
import { NodeReply } from './reply.ts'
|
|
11
11
|
|
|
12
12
|
export const nodeRuntime: RuntimeAdapterInterface = {
|
|
13
13
|
createServer(handler, options?: RuntimeServerOptionsInterface) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// import {RuntimeAdapterInterface} from '../../../types'
|
|
1
|
+
// import {RuntimeAdapterInterface} from '../../../types/index.ts'
|
|
2
2
|
// import {Logger} from "@protorians/logger";
|
|
3
|
-
// import {getRealIp} from "../../utilities";
|
|
3
|
+
// import {getRealIp} from "../../utilities/index.ts";
|
|
4
4
|
//
|
|
5
5
|
// export const webRuntime: RuntimeAdapterInterface = {
|
|
6
6
|
// createServer(handler) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./callable.util"
|
|
2
|
-
export * from "./utilities.util"
|
|
3
|
-
export * from "./artifact.util"
|
|
4
|
-
export * from "./json.util"
|
|
5
|
-
export * from "./path.util"
|
|
6
|
-
export * from "./cookie.util"
|
|
7
|
-
export * from "./openapi.utils"
|
|
8
|
-
export * from "./ip.util"
|
|
9
|
-
export * from "./https.util"
|
|
10
|
-
export * from "./csrf.util"
|
|
1
|
+
export * from "./callable.util.ts"
|
|
2
|
+
export * from "./utilities.util.ts"
|
|
3
|
+
export * from "./artifact.util.ts"
|
|
4
|
+
export * from "./json.util.ts"
|
|
5
|
+
export * from "./path.util.ts"
|
|
6
|
+
export * from "./cookie.util.ts"
|
|
7
|
+
export * from "./openapi.utils.ts"
|
|
8
|
+
export * from "./ip.util.ts"
|
|
9
|
+
export * from "./https.util.ts"
|
|
10
|
+
export * from "./csrf.util.ts"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {ParamMetaInterface} from "../../types";
|
|
2
|
-
import {METADATA_KEYS, Parametrable} from "../index";
|
|
3
|
-
import {PluginScope} from "../../core";
|
|
4
|
-
import {RaitonConfig} from "../../core/config";
|
|
5
|
-
import {getSocketRegistry} from "../../core/socket";
|
|
6
|
-
import {getMcpServerRegistry} from "../../core/mcp";
|
|
7
|
-
import {RaitonThread} from "../../core/thread";
|
|
1
|
+
import type {ParamMetaInterface} from "../../types/index.ts";
|
|
2
|
+
import {METADATA_KEYS, Parametrable} from "../index.ts";
|
|
3
|
+
import {PluginScope} from "../../core/index.ts";
|
|
4
|
+
import {RaitonConfig} from "../../core/config/index.ts";
|
|
5
|
+
import {getSocketRegistry} from "../../core/socket/index.ts";
|
|
6
|
+
import {getMcpServerRegistry} from "../../core/mcp/index.ts";
|
|
7
|
+
import {RaitonThread} from "../../core/thread.ts";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Generate the OpenAPI specification object
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {HttpMethod} from "../framework";
|
|
2
|
-
import {HttpsConfigInput, HttpsConfigInterface} from "../framework/utilities/https.util";
|
|
1
|
+
import {HttpMethod} from "../framework/index.ts";
|
|
2
|
+
import {HttpsConfigInput, HttpsConfigInterface} from "../framework/utilities/https.util.ts";
|
|
3
3
|
|
|
4
4
|
export interface ApplicationConfigInterface {
|
|
5
5
|
workdir?: string;
|
package/source/types/builder.ts
CHANGED
package/source/types/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {HttpMethod, Parametrable} from "../framework/enums";
|
|
2
|
-
import {ContextInterface} from "./core";
|
|
3
|
-
import {MiddlewareCallable, MiddlewareType} from "./middleware";
|
|
1
|
+
import {HttpMethod, Parametrable} from "../framework/enums/index.ts";
|
|
2
|
+
import {ContextInterface} from "./core.ts";
|
|
3
|
+
import {MiddlewareCallable, MiddlewareType} from "./middleware.ts";
|
|
4
4
|
|
|
5
5
|
export interface ControllerMetaInterface {
|
|
6
6
|
prefix?: string;
|
package/source/types/core.ts
CHANGED
package/source/types/csrf.ts
CHANGED
package/source/types/guard.ts
CHANGED