raiton 4.0.0 → 5.4.0-beta.2
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 +37 -0
- package/README.md +37 -2
- package/build/bin/index.mjs +568 -275
- package/examples/user-controller.example.ts +53 -0
- package/package.json +6 -8
- package/source/bin/cli-tools.ts +2 -0
- package/source/commands/build.command.ts +2 -1
- package/source/commands/develop.command.ts +1 -0
- package/source/commands/start.command.ts +15 -10
- package/source/core/application.ts +40 -31
- package/source/core/artifacts/artifact.ts +10 -0
- package/source/core/artifacts/index.ts +1 -0
- package/source/core/artifacts/runner.ts +3 -0
- package/source/core/builder.ts +42 -13
- package/source/core/hooks.ts +0 -8
- package/source/core/index.ts +15 -15
- package/source/core/injection/injection.ts +7 -4
- package/source/core/middleware/pipeline.ts +2 -8
- package/source/core/plugins/scope.ts +18 -6
- package/source/core/router/handler.ts +24 -78
- package/source/core/router/handler.utils.ts +135 -0
- package/source/core/router/matcher.ts +13 -9
- package/source/core/router/router.ts +5 -1
- package/source/core/thread.ts +19 -16
- package/source/framework/artifacts.ts +7 -1
- package/source/framework/constants/decorators.constant.ts +7 -0
- package/source/framework/decorators/api-response.decorator.ts +127 -0
- package/source/framework/decorators/api.decorator.ts +185 -0
- package/source/framework/decorators/index.ts +4 -2
- package/source/framework/decorators/{parametrable.ts → parametrable.decorator.ts} +1 -1
- package/source/framework/encryption.ts +2 -1
- package/source/framework/enums/encrypted.enum.ts +2 -2
- package/source/framework/enums/http-parameters.enum.ts +1 -0
- package/source/framework/enums/runtime.enum.ts +2 -2
- package/source/framework/env.ts +2 -2
- package/source/framework/exceptions/http-exception.ts +1 -1
- package/source/framework/index.ts +1 -0
- package/source/framework/plugins/body-parser.plugin.ts +28 -11
- package/source/framework/plugins/index.ts +3 -2
- package/source/framework/plugins/openapi.plugin.ts +98 -0
- package/source/framework/plugins/security/cors.ts +59 -25
- package/source/framework/responses/helpers.ts +4 -3
- package/source/framework/responses/http-throwable.ts +2 -2
- package/source/framework/responses/http.ts +3 -3
- package/source/framework/runtime/bun/server.ts +6 -2
- package/source/framework/runtime/deno/server.ts +93 -42
- package/source/framework/runtime/index.ts +18 -13
- package/source/framework/runtime/node/reply.ts +37 -0
- package/source/framework/runtime/node/request.ts +47 -0
- package/source/framework/runtime/node/server.ts +5 -33
- package/source/framework/runtime/web/server.ts +73 -57
- package/source/framework/utilities/cookie.util.ts +11 -0
- package/source/framework/utilities/index.ts +3 -1
- package/source/framework/utilities/openapi.utils.ts +497 -0
- package/source/framework/view-model.ts +4 -0
- package/source/types/access-guards.ts +4 -0
- package/source/types/artifact.ts +42 -1
- package/source/types/builder.ts +6 -1
- package/source/types/http-responses.ts +8 -0
- package/source/types/runtime.ts +4 -2
- package/source/types/scheme.ts +153 -0
- package/source/types/thread.ts +3 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http'
|
|
2
|
+
import type { RuntimeRequestInterface } from '../../../types'
|
|
3
|
+
|
|
4
|
+
export class NodeRequest implements RuntimeRequestInterface {
|
|
5
|
+
constructor(public req: IncomingMessage) {
|
|
6
|
+
// copy or wrap
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get method(): string {
|
|
10
|
+
return this.req.method ?? 'GET'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get url(): string {
|
|
14
|
+
return this.req.url ?? '/'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get headers(): Headers {
|
|
18
|
+
return new Headers(this.req.headers as Record<string, string>)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get body(): any {
|
|
22
|
+
// In Node, the request body is a stream; we leave it as the request object itself for simplicity
|
|
23
|
+
return this.req
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get query(): Record<string, any> | undefined {
|
|
27
|
+
// Not implemented; middleware can parse query string from url
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get params(): Record<string, any> | undefined {
|
|
32
|
+
// Not implemented; route params filled by router
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get file(): any {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get files(): any {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get remoteAddress(): string | undefined {
|
|
45
|
+
return this.req.socket?.remoteAddress
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -4,42 +4,14 @@ import {
|
|
|
4
4
|
RuntimeRequestInterface,
|
|
5
5
|
RuntimeReplyInterface
|
|
6
6
|
} from '../../../types'
|
|
7
|
+
import { NodeRequest } from './request'
|
|
8
|
+
import { NodeReply } from './reply'
|
|
7
9
|
|
|
8
10
|
export const nodeRuntime: RuntimeAdapterInterface = {
|
|
9
11
|
createServer(handler) {
|
|
10
12
|
const server = http.createServer(async (req, res) => {
|
|
11
|
-
const runtimeReq:
|
|
12
|
-
|
|
13
|
-
url: req.url || '/',
|
|
14
|
-
headers: new Headers(req.headers as any),
|
|
15
|
-
body: req as any,
|
|
16
|
-
remoteAddress: req.socket.remoteAddress
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const runtimeReply: RuntimeReplyInterface = {
|
|
20
|
-
status(code) {
|
|
21
|
-
res.statusCode = code
|
|
22
|
-
},
|
|
23
|
-
header(name, value) {
|
|
24
|
-
res.setHeader(name, value)
|
|
25
|
-
},
|
|
26
|
-
send(body: any) {
|
|
27
|
-
if (body === undefined) {
|
|
28
|
-
res.end()
|
|
29
|
-
} else if (typeof body === 'string' || Buffer.isBuffer(body)) {
|
|
30
|
-
res.end(body)
|
|
31
|
-
} else {
|
|
32
|
-
res.setHeader('content-type', 'application/json')
|
|
33
|
-
res.end(JSON.stringify(body))
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
text(text: string|Buffer) {
|
|
37
|
-
res.end(text)
|
|
38
|
-
},
|
|
39
|
-
json(json: any) {
|
|
40
|
-
res.end(JSON.stringify(json))
|
|
41
|
-
},
|
|
42
|
-
}
|
|
13
|
+
const runtimeReq: any = new NodeRequest(req)
|
|
14
|
+
const runtimeReply: RuntimeReplyInterface = new NodeReply(res)
|
|
43
15
|
|
|
44
16
|
await handler(runtimeReq, runtimeReply)
|
|
45
17
|
})
|
|
@@ -57,4 +29,4 @@ export const nodeRuntime: RuntimeAdapterInterface = {
|
|
|
57
29
|
}
|
|
58
30
|
}
|
|
59
31
|
}
|
|
60
|
-
}
|
|
32
|
+
}
|
|
@@ -1,57 +1,73 @@
|
|
|
1
|
-
import {RuntimeAdapterInterface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
1
|
+
// import {RuntimeAdapterInterface} from '../../../types'
|
|
2
|
+
// import {Logger} from "@protorians/logger";
|
|
3
|
+
//
|
|
4
|
+
// export const webRuntime: RuntimeAdapterInterface = {
|
|
5
|
+
// createServer(handler) {
|
|
6
|
+
// let responseBody: any
|
|
7
|
+
// let statusCode = 200
|
|
8
|
+
// const headers = new Headers()
|
|
9
|
+
//
|
|
10
|
+
// const fetching = async (request: Request, handler: any) => {
|
|
11
|
+
// // Reset for each request
|
|
12
|
+
// responseBody = undefined
|
|
13
|
+
// statusCode = 200
|
|
14
|
+
// // headers.clear()
|
|
15
|
+
//
|
|
16
|
+
// await handler(
|
|
17
|
+
// {
|
|
18
|
+
// method: request.method,
|
|
19
|
+
// url: request.url,
|
|
20
|
+
// headers: request.headers,
|
|
21
|
+
// body: request.body ? request.body : null
|
|
22
|
+
// },
|
|
23
|
+
// {
|
|
24
|
+
// status(code) {
|
|
25
|
+
// statusCode = code
|
|
26
|
+
// },
|
|
27
|
+
// header(name, value) {
|
|
28
|
+
// headers.set(name, value)
|
|
29
|
+
// },
|
|
30
|
+
// send(body: any) {
|
|
31
|
+
// if (body === undefined) {
|
|
32
|
+
// responseBody = ''
|
|
33
|
+
// } else if (typeof body === 'string' || body instanceof Uint8Array) {
|
|
34
|
+
// responseBody = body
|
|
35
|
+
// } else {
|
|
36
|
+
// headers.set('content-type', 'application/json')
|
|
37
|
+
// responseBody = JSON.stringify(body)
|
|
38
|
+
// }
|
|
39
|
+
// },
|
|
40
|
+
// text(text: string | Buffer) {
|
|
41
|
+
// responseBody = text
|
|
42
|
+
// },
|
|
43
|
+
// json(json: any) {
|
|
44
|
+
// headers.set('content-type', 'application/json')
|
|
45
|
+
// responseBody = JSON.stringify(json)
|
|
46
|
+
// },
|
|
47
|
+
// type(contentType: string) {
|
|
48
|
+
// headers.set('content-type', contentType)
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
51
|
+
// )
|
|
52
|
+
//
|
|
53
|
+
// return new Response(
|
|
54
|
+
// typeof responseBody === 'object' && !(responseBody instanceof Uint8Array)
|
|
55
|
+
// ? JSON.stringify(responseBody)
|
|
56
|
+
// : responseBody,
|
|
57
|
+
// {status: statusCode, headers}
|
|
58
|
+
// )
|
|
59
|
+
// }
|
|
60
|
+
//
|
|
61
|
+
// return {
|
|
62
|
+
// async listen() {
|
|
63
|
+
// console.warn('Web runtime does not support listening')
|
|
64
|
+
// },
|
|
65
|
+
// async close() {
|
|
66
|
+
// console.warn('Web runtime does not support closing')
|
|
67
|
+
// },
|
|
68
|
+
// async handle(request: Request) {
|
|
69
|
+
// return fetching(request, handler)
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseCookie(cookieHeader: string | null): Record<string, string> {
|
|
2
|
+
const cookies: Record<string, string> = {};
|
|
3
|
+
if (!cookieHeader) return cookies;
|
|
4
|
+
cookieHeader.split(';').forEach(part => {
|
|
5
|
+
const [key, ...valueParts] = part.trim().split('=');
|
|
6
|
+
if (key) {
|
|
7
|
+
cookies[key] = valueParts.join('=');
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return cookies;
|
|
11
|
+
}
|