raiton 4.0.0 → 5.5.0-beta.3

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 +54 -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 +219 -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
@@ -3,6 +3,7 @@ export enum Parametrable {
3
3
  BODY = "body",
4
4
  QUERY = "query",
5
5
  HEADER = "header",
6
+ COOKIE = "cookie",
6
7
  REQ = "req",
7
8
  REPLY = "reply",
8
9
  UPLOAD_FILE = "upload",
@@ -1,6 +1,6 @@
1
1
  export enum RuntimeType {
2
2
  Node = "node",
3
- Deno = "deno",
3
+ // Deno = "deno",
4
4
  Bun = "bun",
5
- Web = "web"
5
+ // Web = "web"
6
6
  }
@@ -1,8 +1,8 @@
1
1
  import {GenericValueType} from "../types/generic";
2
2
  import {getType} from "./utilities";
3
3
 
4
- export function env<T>(key: string, type?: GenericValueType): T | undefined {
5
- const value = process.env[key];
4
+ export function env<T>(key: string, defaultValue?: string, type?: GenericValueType): T | undefined {
5
+ const value = process.env[key] || defaultValue;
6
6
  type = type || getType(value) as GenericValueType;
7
7
 
8
8
  if (value) {
@@ -16,7 +16,7 @@ export class HttpException extends Error {
16
16
  message: this.message,
17
17
  statusCode: this.statusCode,
18
18
  error: true,
19
- stack: Raiton.thread?.builder?.options?.development
19
+ stack: Raiton.thread?.builder?.options?.serve
20
20
  ? this.stack?.split('\n').map(e => e.trim())
21
21
  : undefined
22
22
  }
@@ -8,6 +8,7 @@ export * from "./runtime/index"
8
8
  export * from "./exceptions/index"
9
9
  export * from "./controllers"
10
10
  export * from "./data-transfer-object"
11
+ export * from "./view-model"
11
12
  export * from "./encryption"
12
13
  export * from "./parameter-bag"
13
14
  export * from "./repositories"
@@ -8,21 +8,29 @@ export function bodyParserPlugin(): PluginInterface {
8
8
  name: 'body-parser-plugin',
9
9
  setup: (scope) => {
10
10
  scope.use(async ({context, next}: MiddlewareParametersInterface) => {
11
- const contentType = context.req.headers.get('content-type') || '';
11
+ readQueryBody(context);
12
12
 
13
- if (context.req.body && !context.state.bodyParsed) {
13
+ const isGetOrHead = ['GET', 'HEAD'].includes(context.req.method.toUpperCase());
14
+
15
+ if (isGetOrHead) {
16
+ context.req.body = context.req.query;
17
+ }
18
+
19
+ const hasBody = context.req.body !== undefined && context.req.body !== null;
20
+
21
+ if (hasBody && !context.state.bodyParsed && !isGetOrHead) {
14
22
  try {
23
+ const contentType = context.req.headers.get('content-type') || '';
15
24
  const rawBody = await readRawBody(context.req.body);
16
- context.req.body = rawBody as unknown as any;
17
25
  const bodyString = decode(rawBody);
18
26
 
19
- readQueryBody(context);
20
- await readMultipartBody(context, contentType);
27
+ await readMultipartBody(context, contentType, rawBody);
21
28
  readJsonBody(context, contentType, bodyString);
22
29
  readUrlEncodedBody(context, contentType, bodyString);
23
30
  readTextBody(context, contentType, bodyString);
24
31
 
25
32
  if (!context.state.bodyParsed) {
33
+ context.req.body = rawBody as any;
26
34
  context.state.bodyParsed = true;
27
35
  }
28
36
 
@@ -37,22 +45,20 @@ export function bodyParserPlugin(): PluginInterface {
37
45
  };
38
46
  }
39
47
 
40
- function readJsonBody(ctx: RequestContext, contentType: string, body: any) {
48
+ function readJsonBody(ctx: RequestContext, contentType: string, body: string) {
41
49
  if (contentType.includes('application/json')) {
42
- ctx.req.body = tryParseJson(body) || {} as unknown as any;
50
+ ctx.req.body = tryParseJson(body) || {};
43
51
  ctx.state.bodyParsed = true;
44
52
  }
45
53
  }
46
54
 
47
- async function readMultipartBody(ctx: RequestContext, contentType: string) {
55
+ async function readMultipartBody(ctx: RequestContext, contentType: string, rawBody: any) {
48
56
  if (contentType.includes('multipart/form-data')) {
49
- const body = ctx.req.body;
50
-
51
57
  try {
52
58
  const tempRequest = new Request(ctx.req.url, {
53
59
  method: ctx.req.method,
54
60
  headers: ctx.req.headers,
55
- body: body as any
61
+ body: rawBody
56
62
  });
57
63
 
58
64
  const formData = await tempRequest.formData();
@@ -104,6 +110,7 @@ function readTextBody(ctx: RequestContext, contentType: string, body: string) {
104
110
  }
105
111
 
106
112
  function readQueryBody(ctx: RequestContext) {
113
+
107
114
  const searchParams = new URLSearchParams(ctx.req.url.split('?')[1] || '');
108
115
  const record = {} as Record<string, any>;
109
116
  searchParams.forEach((value, key) => record[key] = value);
@@ -111,6 +118,16 @@ function readQueryBody(ctx: RequestContext) {
111
118
  }
112
119
 
113
120
  async function readRawBody(body: any): Promise<Uint8Array | string> {
121
+ if (!body) return new Uint8Array(0);
122
+
123
+ if (body instanceof Uint8Array || typeof body === 'string') {
124
+ return body;
125
+ }
126
+
127
+ if (typeof body === 'object' && !('on' in body) && !(body instanceof ReadableStream)) {
128
+ return JSON.stringify(body);
129
+ }
130
+
114
131
  if (body instanceof ReadableStream) {
115
132
  const reader = body.getReader();
116
133
  const chunks: Uint8Array[] = [];
@@ -1,2 +1,3 @@
1
- export * from "./body-parser.plugin"
2
- export * from "./security/index"
1
+ export * from "./body-parser.plugin";
2
+ export * from "./security/index";
3
+ export * from "./openapi.plugin";
@@ -0,0 +1,98 @@
1
+ import type {PluginInterface} from "../../types";
2
+ import type {ContextInterface} from "../../types/core";
3
+ import {PluginScope} from "../../core";
4
+ import {Logger} from "@protorians/logger";
5
+ import {generateOpenApiSpec} from "../utilities/openapi.utils";
6
+
7
+ /**
8
+ * OpenAPI plugin options
9
+ */
10
+ export interface OpenApiOptions {
11
+ /**
12
+ * The base route for the documentation UI (e.g., '/docs')
13
+ * @default '/docs'
14
+ */
15
+ route?: string;
16
+
17
+ /**
18
+ * The HTML string page
19
+ */
20
+ ui?: (config: Omit<OpenApiOptions, 'ui'>, context: ContextInterface) => string;
21
+
22
+ /**
23
+ * The endpoint for the raw JSON OpenAPI spec (e.g., '/docs/json')
24
+ * If set to false, disables the JSON endpoint.
25
+ * @default '/docs/json'
26
+ */
27
+ endpoint?: string | false;
28
+ /**
29
+ * Title of the API
30
+ * @default 'API'
31
+ */
32
+ title?: string;
33
+ /**
34
+ * Version of the API
35
+ * @default '1.0.0'
36
+ */
37
+ version?: string;
38
+ /**
39
+ * Description of the API
40
+ * @default ''
41
+ */
42
+ description?: string;
43
+ /**
44
+ * Terms of service URL
45
+ */
46
+ termsOfService?: string;
47
+ /**
48
+ * Contact information
49
+ */
50
+ contact?: {
51
+ name?: string;
52
+ url?: string;
53
+ email?: string;
54
+ };
55
+ /**
56
+ * License information
57
+ */
58
+ license?: {
59
+ name?: string;
60
+ url?: string;
61
+ };
62
+ }
63
+
64
+ export function openApiPlugin(options: OpenApiOptions = {}): PluginInterface {
65
+ const opts = {
66
+ endpoint: '/docs/json',
67
+ title: 'API',
68
+ version: '1.0.0',
69
+ description: '',
70
+ termsOfService: undefined,
71
+ contact: undefined,
72
+ license: undefined,
73
+ ...options
74
+ };
75
+
76
+ return {
77
+ name: 'openapi-plugin',
78
+ setup: (scope: PluginScope) => {
79
+
80
+ if (opts.route && opts.ui) {
81
+ scope.get(opts.route, async ({reply, req, ...context}: ContextInterface) => {
82
+ const optionsWithoutUi = {...opts, ui: undefined}
83
+ const html = opts.ui?.(optionsWithoutUi, {reply, req, ...context});
84
+ reply.type('text/html');
85
+ reply.send(html || 'No Ui function defined');
86
+ });
87
+ }
88
+
89
+ if (opts.endpoint) {
90
+ scope.get(opts.endpoint, async ({reply}: ContextInterface) => {
91
+ const spec = await generateOpenApiSpec(scope, opts);
92
+ reply.type('application/json');
93
+ return spec
94
+ });
95
+ }
96
+ }
97
+ };
98
+ }
@@ -1,44 +1,78 @@
1
1
  import {definePlugin} from "../../../core/plugins";
2
- import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
2
+ import {MiddlewareParametersInterface} from "../../../types";
3
+ import {Logger} from "@protorians/logger";
3
4
 
4
5
  export interface CorsOptions {
5
- origin?: string | string[]
6
+ origin?: string | string[] | boolean | ((origin: string) => boolean | Promise<boolean>)
6
7
  methods?: string[]
7
8
  headers?: string[]
9
+ credentials?: boolean
10
+ maxAge?: number
11
+ exposeHeaders?: string[]
8
12
  }
9
13
 
10
- export const secureCors = (opts: CorsOptions = {}) =>
11
- definePlugin((scope) => {
12
- scope.use(async ({context, next}: MiddlewareParametersInterface) => {
13
- const origin = context.req.headers.get('origin')
14
-
15
- if (opts.origin) {
16
- const allowed = Array.isArray(opts.origin)
17
- ? opts.origin.includes(origin!)
18
- : opts.origin === origin
19
-
20
- if (allowed) {
21
- context.reply.header('Access-Control-Allow-Origin', origin!)
22
- }
23
- } else {
24
- context.reply.header('Access-Control-Allow-Origin', '*')
14
+ export const secureCors = (opts: CorsOptions = {}) => {
15
+
16
+ return (async ({context, next}: MiddlewareParametersInterface) => {
17
+ const origin = context.req.headers.get('origin')
18
+
19
+ if (origin) {
20
+ context.reply.header('Vary', 'Origin')
21
+ }
22
+
23
+ let allowedOrigin: string | null = null
24
+
25
+ if (opts.origin === undefined || opts.origin === '*') {
26
+ allowedOrigin = '*'
27
+ } else if (opts.origin === true) {
28
+ allowedOrigin = origin || '*'
29
+ } else if (typeof opts.origin === 'function') {
30
+ if (origin && await opts.origin(origin)) {
31
+ allowedOrigin = origin
32
+ }
33
+ } else if (Array.isArray(opts.origin)) {
34
+ if (origin && opts.origin.includes(origin)) {
35
+ allowedOrigin = origin
36
+ }
37
+ } else if (typeof opts.origin === 'string') {
38
+ if (opts.origin === origin) {
39
+ allowedOrigin = origin
40
+ } else if (opts.origin === '*') {
41
+ allowedOrigin = '*'
25
42
  }
43
+ }
26
44
 
45
+ if (allowedOrigin) {
46
+ context.reply.header('Access-Control-Allow-Origin', allowedOrigin)
47
+ }
48
+
49
+ if (opts.credentials) {
50
+ context.reply.header('Access-Control-Allow-Credentials', 'true')
51
+ }
52
+
53
+ if (opts.exposeHeaders) {
54
+ context.reply.header('Access-Control-Expose-Headers', opts.exposeHeaders.join(','))
55
+ }
56
+
57
+ if (context.req.method === 'OPTIONS') {
27
58
  context.reply.header(
28
59
  'Access-Control-Allow-Methods',
29
- (opts.methods ?? ['GET', 'POST', 'PUT', 'DELETE']).join(',')
60
+ (opts.methods ?? ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).join(',')
30
61
  )
31
62
 
32
63
  context.reply.header(
33
64
  'Access-Control-Allow-Headers',
34
- (opts.headers ?? ['Content-Type', 'Authorization']).join(',')
65
+ (opts.headers ?? ['Content-Type', 'Authorization', 'X-Requested-With']).join(',')
35
66
  )
36
67
 
37
- if (context.req.method === 'OPTIONS') {
38
- context.reply.status(204)
39
- return context.send(null)
68
+ if (opts.maxAge) {
69
+ context.reply.header('Access-Control-Max-Age', opts.maxAge.toString())
40
70
  }
41
71
 
42
- await next()
43
- })
44
- }, 'cors')
72
+ context.reply.status(204)
73
+ return context.send(null)
74
+ }
75
+
76
+ await next()
77
+ })
78
+ }
@@ -5,16 +5,17 @@ import {Raiton} from "../../core";
5
5
 
6
6
  export function RaitonResponses(
7
7
  message: string,
8
- data: HttpResponseInterface,
8
+ data: any,
9
+ // data: HttpResponseInterface<any> | null,
9
10
  statusCode: HttpStatus,
10
11
  metadata?: Omit<HttpResponseInterface<any>, 'data' | 'message' | 'statusCode'>
11
12
  ) {
12
13
 
13
14
  if (metadata) {
14
- metadata.error = typeof data.error === 'boolean' ? data.error : false
15
+ metadata.error = typeof data?.error === 'boolean' ? data?.error : false
15
16
  metadata.errorStack = (metadata.errorStack instanceof Error)
16
17
  ? metadata.errorStack
17
- : (Raiton.thread?.builder?.options?.development
18
+ : (Raiton.thread?.builder?.options?.serve
18
19
  ? (Array.isArray(metadata.errorStack) ? metadata.errorStack : [])
19
20
  : undefined)
20
21
  }
@@ -5,7 +5,7 @@ import {Raiton} from "../../core";
5
5
 
6
6
  export class ThrowableResponse extends Error {
7
7
  constructor(
8
- public input: string | HttpResponseInterface,
8
+ public input: string | HttpResponseInterface<any>,
9
9
  public statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
10
10
  ) {
11
11
  super(typeof input === 'string' ? input : input.message);
@@ -19,7 +19,7 @@ export class ThrowableResponse extends Error {
19
19
  data: (typeof this.input === 'object') ? this.input.data : undefined,
20
20
  error: (typeof this.input === 'object') ? this.input.error : false,
21
21
  stack: stack instanceof Error ?
22
- (Raiton.thread?.builder?.options?.development
22
+ (Raiton.thread?.builder?.options?.serve
23
23
  ? this.stack?.split('\n').map(e => e.trim())
24
24
  : undefined)
25
25
  : stack
@@ -4,7 +4,7 @@ import {ThrowableResponse} from ".";
4
4
 
5
5
 
6
6
  export class HttpResponse {
7
- public static push(response: Partial<HttpResponseInterface>): void {
7
+ public static push(response: Partial<HttpResponseInterface<any>>): void {
8
8
  throw new ThrowableResponse({
9
9
  statusCode: response.statusCode || HttpStatus.BAD_REQUEST,
10
10
  message: response.message || 'No response message provided',
@@ -14,7 +14,7 @@ export class HttpResponse {
14
14
  })
15
15
  }
16
16
 
17
- constructor(public readonly response: HttpResponseInterface) {
17
+ constructor(public readonly response: HttpResponseInterface<any>) {
18
18
  }
19
19
 
20
20
  status(statusCode: HttpStatus): this {
@@ -42,7 +42,7 @@ export class HttpResponse {
42
42
  return this;
43
43
  }
44
44
 
45
- render(): HttpResponseInterface {
45
+ render(): HttpResponseInterface<any> {
46
46
  return (new ThrowableResponse({...this.response})).render()
47
47
  }
48
48
  }
@@ -1,4 +1,5 @@
1
1
  import {RuntimeAdapterInterface} from '../../../types'
2
+ import {Logger} from "@protorians/logger";
2
3
 
3
4
  export const bunRuntime: RuntimeAdapterInterface = {
4
5
  createServer(handler) {
@@ -23,7 +24,7 @@ export const bunRuntime: RuntimeAdapterInterface = {
23
24
  method: request.method,
24
25
  url: request.url,
25
26
  headers: request.headers as any,
26
- body: request.body as any
27
+ body: request.body ? request.body : null
27
28
  },
28
29
  {
29
30
  status(code) {
@@ -49,6 +50,9 @@ export const bunRuntime: RuntimeAdapterInterface = {
49
50
  headers.set('content-type', 'application/json')
50
51
  responseBody = JSON.stringify(json)
51
52
  },
53
+ type(contentType: string) {
54
+ headers.set('content-type', contentType)
55
+ }
52
56
  }
53
57
  )
54
58
 
@@ -70,4 +74,4 @@ export const bunRuntime: RuntimeAdapterInterface = {
70
74
  }
71
75
  }
72
76
  }
73
- }
77
+ }
@@ -1,53 +1,104 @@
1
- import {RuntimeAdapterInterface} from '../../../types'
1
+ import {RuntimeAdapterInterface, RuntimeRequestInterface, RuntimeReplyInterface} from '../../../types'
2
+ import {Logger} from "@protorians/logger";
2
3
 
4
+ // class DenoRequest implements RuntimeRequestInterface {
5
+ // constructor(private req: Request) {}
6
+ // get method(): string { return this.req.method; }
7
+ // get url(): string { return this.req.url; }
8
+ // get headers(): Headers { return new Headers(this.req.headers); }
9
+ // get body(): any { return this.req.body; }
10
+ // get query(): Record<string, any> | undefined { return undefined; }
11
+ // get params(): Record<string, any> | undefined { return undefined; }
12
+ // get file(): any { return undefined; }
13
+ // get files(): any { return undefined; }
14
+ // get remoteAddress(): string | undefined { return undefined; }
15
+ // }
16
+
17
+ // class DenoReply implements RuntimeReplyInterface {
18
+ // private statusCode: number = 200;
19
+ // private headers: Headers = new Headers();
20
+ // private body: BodyInit | null = null;
21
+ //
22
+ // status(code: number): void { this.statusCode = code; }
23
+ // header(name: string, value: string): void { this.headers.set(name, value); }
24
+ // send(body: any): void {
25
+ // if (body === undefined) {
26
+ // this.body = null;
27
+ // } else if (typeof body === 'string' || body instanceof Uint8Array) {
28
+ // this.body = body;
29
+ // } else {
30
+ // if (!this.headers.has('content-type')) {
31
+ // this.headers.set('content-type', 'application/json');
32
+ // }
33
+ // this.body = JSON.stringify(body);
34
+ // }
35
+ // }
36
+ // text(text: string | Buffer): void {
37
+ // // Accept string, Uint8Array, or any other value (including Buffer-like)
38
+ // if (typeof text === 'string' || text instanceof Uint8Array) {
39
+ // this.body = text;
40
+ // } else {
41
+ // // Fallback: treat as JSON string
42
+ // this.body = JSON.stringify(text);
43
+ // }
44
+ // }
45
+ // json(json: any): void {
46
+ // this.headers.set('content-type', 'application/json');
47
+ // this.body = JSON.stringify(json);
48
+ // }
49
+ // type(contentType: string): void {
50
+ // this.headers.set('content-type', contentType);
51
+ // }
52
+ // toResponse(): Response {
53
+ // let bodyToSend: BodyInit = '';
54
+ // if (this.body instanceof Uint8Array) {
55
+ // bodyToSend = this.body;
56
+ // } else if (typeof this.body === 'string') {
57
+ // bodyToSend = this.body;
58
+ // } else if (this.body === null) {
59
+ // bodyToSend = '';
60
+ // } else {
61
+ // // fallback: treat as JSON
62
+ // bodyToSend = JSON.stringify(this.body);
63
+ // }
64
+ // return new Response(bodyToSend, { status: this.statusCode, headers: this.headers });
65
+ // }
66
+ // }
67
+
68
+ /**
69
+ * @alpha Not ready
70
+ */
3
71
  export const denoRuntime: RuntimeAdapterInterface = {
4
72
  createServer(handler) {
5
- let controller: AbortController
73
+ let controller: AbortController | null = null;
6
74
 
7
75
  return {
8
76
  async listen(port, hostname) {
9
- if (typeof Deno === 'undefined') throw new Error(
10
- 'Deno is not installed, please run `deno install -A -f --unstable https://deno.land/x/raiton/cli.ts`'
11
- )
12
-
13
- controller = new AbortController()
14
- Deno.serve({port, hostname, signal: controller.signal}, async (req: any) => {
15
- let body: any
16
- let status = 200
17
- const headers = new Headers()
18
-
19
- await handler(
20
- {
21
- method: req.method,
22
- url: req.url,
23
- headers: req.headers,
24
- body: req.body
25
- },
26
- {
27
- status(code) {
28
- status = code
29
- },
30
- header(name, value) {
31
- headers.set(name, value)
32
- },
33
- send(value: any) {
34
- body = value
35
- },
36
- text(text: string | Buffer) {
37
- body = text
38
- },
39
- json(json: any) {
40
- body = JSON.stringify(json)
41
- },
42
- }
43
- )
77
+ // controller = new AbortController();
78
+ //
79
+ // const server = Deno.serve({
80
+ // port: Number(port),
81
+ // hostname,
82
+ // signal: controller.signal,
83
+ // handler: async (reqEvent) => {
84
+ // const denoReq = new DenoRequest(reqEvent.request);
85
+ // const denoRes = new DenoReply();
86
+ //
87
+ // await handler(denoReq, denoRes);
88
+ //
89
+ // const resp = denoRes.toResponse();
90
+ // await reqEvent.respondWith(resp);
91
+ // }
92
+ // });
44
93
 
45
- return new Response(body, {status, headers})
46
- })
94
+ // Server will run until close() is called
47
95
  },
48
96
  async close() {
49
- controller.abort()
97
+ // if (controller) {
98
+ // controller.abort();
99
+ // }
100
+ // Note: Deno.serve does not expose a direct stop; closing the signal aborts incoming connections.
50
101
  }
51
- }
102
+ };
52
103
  }
53
- }
104
+ }
@@ -1,9 +1,14 @@
1
- import type {RuntimeAdapterInterface, RuntimeHandlerCallable, RuntimeInterface, RuntimeServerInterface} from "../../types";
1
+ import type {
2
+ RuntimeAdapterInterface,
3
+ RuntimeHandlerCallable,
4
+ RuntimeInterface,
5
+ RuntimeServerInterface
6
+ } from "../../types";
2
7
  import {RuntimeType} from "../enums/runtime.enum";
3
8
  import {nodeRuntime} from "./node/server";
4
9
  import {bunRuntime} from "./bun/server";
5
10
  import {denoRuntime} from "./deno/server";
6
- import {webRuntime} from "./web/server";
11
+ // import {webRuntime} from "./web/server";
7
12
 
8
13
 
9
14
  export class Runtime implements RuntimeInterface {
@@ -16,13 +21,13 @@ export class Runtime implements RuntimeInterface {
16
21
  return this.type === RuntimeType.Node;
17
22
  }
18
23
 
19
- get isDeno(): boolean {
20
- return this.type === RuntimeType.Deno;
21
- }
22
-
23
- get isWeb(): boolean {
24
- return this.type === RuntimeType.Web;
25
- }
24
+ // get isDeno(): boolean {
25
+ // return this.type === RuntimeType.Deno;
26
+ // }
27
+ //
28
+ // get isWeb(): boolean {
29
+ // return this.type === RuntimeType.Web;
30
+ // }
26
31
 
27
32
  get isBun(): boolean {
28
33
  return this.type === RuntimeType.Bun;
@@ -34,10 +39,10 @@ export class Runtime implements RuntimeInterface {
34
39
  return nodeRuntime
35
40
  case RuntimeType.Bun:
36
41
  return bunRuntime
37
- case RuntimeType.Deno:
38
- return denoRuntime
39
- case RuntimeType.Web:
40
- return webRuntime
42
+ // case RuntimeType.Deno:
43
+ // return denoRuntime
44
+ // case RuntimeType.Web:
45
+ // return webRuntime
41
46
  }
42
47
  }
43
48