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.
Files changed (62) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +37 -2
  3. package/build/bin/index.mjs +568 -275
  4. package/examples/user-controller.example.ts +53 -0
  5. package/package.json +6 -8
  6. package/source/bin/cli-tools.ts +2 -0
  7. package/source/commands/build.command.ts +2 -1
  8. package/source/commands/develop.command.ts +1 -0
  9. package/source/commands/start.command.ts +15 -10
  10. package/source/core/application.ts +40 -31
  11. package/source/core/artifacts/artifact.ts +10 -0
  12. package/source/core/artifacts/index.ts +1 -0
  13. package/source/core/artifacts/runner.ts +3 -0
  14. package/source/core/builder.ts +42 -13
  15. package/source/core/hooks.ts +0 -8
  16. package/source/core/index.ts +15 -15
  17. package/source/core/injection/injection.ts +7 -4
  18. package/source/core/middleware/pipeline.ts +2 -8
  19. package/source/core/plugins/scope.ts +18 -6
  20. package/source/core/router/handler.ts +24 -78
  21. package/source/core/router/handler.utils.ts +135 -0
  22. package/source/core/router/matcher.ts +13 -9
  23. package/source/core/router/router.ts +5 -1
  24. package/source/core/thread.ts +19 -16
  25. package/source/framework/artifacts.ts +7 -1
  26. package/source/framework/constants/decorators.constant.ts +7 -0
  27. package/source/framework/decorators/api-response.decorator.ts +127 -0
  28. package/source/framework/decorators/api.decorator.ts +185 -0
  29. package/source/framework/decorators/index.ts +4 -2
  30. package/source/framework/decorators/{parametrable.ts → parametrable.decorator.ts} +1 -1
  31. package/source/framework/encryption.ts +2 -1
  32. package/source/framework/enums/encrypted.enum.ts +2 -2
  33. package/source/framework/enums/http-parameters.enum.ts +1 -0
  34. package/source/framework/enums/runtime.enum.ts +2 -2
  35. package/source/framework/env.ts +2 -2
  36. package/source/framework/exceptions/http-exception.ts +1 -1
  37. package/source/framework/index.ts +1 -0
  38. package/source/framework/plugins/body-parser.plugin.ts +28 -11
  39. package/source/framework/plugins/index.ts +3 -2
  40. package/source/framework/plugins/openapi.plugin.ts +98 -0
  41. package/source/framework/plugins/security/cors.ts +59 -25
  42. package/source/framework/responses/helpers.ts +4 -3
  43. package/source/framework/responses/http-throwable.ts +2 -2
  44. package/source/framework/responses/http.ts +3 -3
  45. package/source/framework/runtime/bun/server.ts +6 -2
  46. package/source/framework/runtime/deno/server.ts +93 -42
  47. package/source/framework/runtime/index.ts +18 -13
  48. package/source/framework/runtime/node/reply.ts +37 -0
  49. package/source/framework/runtime/node/request.ts +47 -0
  50. package/source/framework/runtime/node/server.ts +5 -33
  51. package/source/framework/runtime/web/server.ts +73 -57
  52. package/source/framework/utilities/cookie.util.ts +11 -0
  53. package/source/framework/utilities/index.ts +3 -1
  54. package/source/framework/utilities/openapi.utils.ts +497 -0
  55. package/source/framework/view-model.ts +4 -0
  56. package/source/types/access-guards.ts +4 -0
  57. package/source/types/artifact.ts +42 -1
  58. package/source/types/builder.ts +6 -1
  59. package/source/types/http-responses.ts +8 -0
  60. package/source/types/runtime.ts +4 -2
  61. package/source/types/scheme.ts +153 -0
  62. 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: RuntimeRequestInterface = {
12
- method: req.method || 'GET',
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, RuntimeReplyInterface, RuntimeRequestInterface} from '../../../types'
2
-
3
- export const webRuntime: RuntimeAdapterInterface = {
4
- createServer(handler) {
5
- async function fetching(request: Request, handler: (req: RuntimeRequestInterface, reply: RuntimeReplyInterface) => Promise<void>): Promise<Response> {
6
- let responseBody: any
7
- let statusCode = 200
8
- const headers = new Headers()
9
-
10
- const runtimeReq: RuntimeRequestInterface = {
11
- method: request.method,
12
- url: request.url,
13
- headers: request.headers,
14
- body: request.body as any
15
- }
16
-
17
- const runtimeReply: RuntimeReplyInterface = {
18
- status(code) {
19
- statusCode = code
20
- },
21
- header(name, value) {
22
- headers.set(name, value)
23
- },
24
- send(body) {
25
- responseBody = body
26
- },
27
- text(text: string | Buffer) {
28
- responseBody = text
29
- },
30
- json(json: any) {
31
- responseBody = JSON.stringify(json)
32
- },
33
- }
34
-
35
- await handler(runtimeReq, runtimeReply)
36
-
37
- return new Response(
38
- typeof responseBody === 'object' && !(responseBody instanceof Uint8Array)
39
- ? JSON.stringify(responseBody)
40
- : responseBody,
41
- {status: statusCode, headers}
42
- )
43
- }
44
-
45
- return {
46
- async listen() {
47
- console.warn('Web runtime does not support listening')
48
- },
49
- async close() {
50
- console.warn('Web runtime does not support closing')
51
- },
52
- async handle(request: Request) {
53
- return fetching(request, handler)
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
+ }
@@ -2,4 +2,6 @@ export * from "./callable.util"
2
2
  export * from "./utilities.util"
3
3
  export * from "./artifact.util"
4
4
  export * from "./json.util"
5
- export * from "./path.util"
5
+ export * from "./path.util"
6
+ export * from "./cookie.util"
7
+ export * from "./openapi.utils"