raiton 3.0.1 → 3.1.0

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 (93) hide show
  1. package/CHANGELOG.md +15 -15
  2. package/README.md +1 -1
  3. package/build/bin/index.mjs +240 -2
  4. package/package.json +3 -4
  5. package/scripts/update-version.ts +5 -5
  6. package/source/bin/bootstrapper.ts +3 -3
  7. package/source/bin/cli-tools.ts +1 -1
  8. package/source/bin/cli.ts +1 -1
  9. package/source/commands/artifact.command.ts +3 -3
  10. package/source/commands/build.command.ts +3 -3
  11. package/source/commands/develop.command.ts +3 -3
  12. package/source/commands/grafts.command.ts +1 -1
  13. package/source/commands/start.command.ts +3 -3
  14. package/source/core/application.ts +23 -18
  15. package/source/core/builder.ts +8 -8
  16. package/source/core/bytes.util.ts +2 -2
  17. package/source/core/config/config.ts +8 -8
  18. package/source/core/config/define.ts +4 -4
  19. package/source/core/context.ts +1 -1
  20. package/source/core/controller/builder.ts +6 -6
  21. package/source/core/controller/compiler.ts +5 -5
  22. package/source/core/controller/metadata.ts +2 -2
  23. package/source/core/directories.ts +1 -1
  24. package/source/core/guards.ts +43 -0
  25. package/source/core/hooks.ts +4 -4
  26. package/source/core/injection/injection.ts +8 -7
  27. package/source/core/middleware/compose.ts +2 -2
  28. package/source/core/middleware/pipeline.ts +2 -2
  29. package/source/core/plugins/plugin.ts +3 -3
  30. package/source/core/plugins/scope.ts +3 -3
  31. package/source/core/raiton.ts +2 -2
  32. package/source/core/router/handler.ts +7 -7
  33. package/source/core/router/matcher.ts +1 -1
  34. package/source/core/router/route.ts +3 -3
  35. package/source/core/router/router.ts +5 -5
  36. package/source/core/server.ts +3 -3
  37. package/source/core/thread.ts +14 -13
  38. package/source/sdk/artifacts.ts +5 -5
  39. package/source/sdk/decorators/controllable.decorator.ts +3 -3
  40. package/source/sdk/decorators/guard.decorator.ts +23 -0
  41. package/source/sdk/decorators/index.ts +2 -1
  42. package/source/sdk/decorators/injection.decorator.ts +4 -4
  43. package/source/sdk/decorators/middleware.decorator.ts +2 -2
  44. package/source/sdk/decorators/parametrable.ts +3 -3
  45. package/source/sdk/decorators/routable.decorator.ts +3 -3
  46. package/source/sdk/encryption.ts +15 -15
  47. package/source/sdk/env.ts +5 -5
  48. package/source/sdk/exceptions/http-exception.ts +3 -3
  49. package/source/sdk/parameter-bag.ts +1 -1
  50. package/source/sdk/plugins/body-parser.plugin.ts +5 -5
  51. package/source/sdk/plugins/security/body-limit.ts +3 -3
  52. package/source/sdk/plugins/security/cors.ts +3 -3
  53. package/source/sdk/plugins/security/headers.ts +3 -3
  54. package/source/sdk/plugins/security/method-guard.ts +3 -3
  55. package/source/sdk/plugins/security/rate-limit.ts +3 -3
  56. package/source/sdk/repositories.ts +1 -1
  57. package/source/sdk/responses/error.ts +2 -2
  58. package/source/sdk/responses/helpers.ts +3 -3
  59. package/source/sdk/responses/http-throwable.ts +3 -3
  60. package/source/sdk/responses/http.ts +3 -3
  61. package/source/sdk/runtime/bun/server.ts +1 -1
  62. package/source/sdk/runtime/deno/server.ts +1 -1
  63. package/source/sdk/runtime/index.ts +6 -6
  64. package/source/sdk/runtime/node/server.ts +1 -1
  65. package/source/sdk/runtime/web/server.ts +1 -1
  66. package/source/sdk/utilities/utilities.util.ts +2 -2
  67. package/source/types/application.ts +5 -5
  68. package/source/types/artifact.ts +2 -43
  69. package/source/types/builder.ts +5 -5
  70. package/source/types/config.ts +3 -3
  71. package/source/types/controller.ts +6 -6
  72. package/source/types/contruct.ts +1 -1
  73. package/source/types/core.ts +3 -5
  74. package/source/types/directory.ts +1 -1
  75. package/source/types/encryption.ts +21 -12
  76. package/source/types/generic.ts +2 -2
  77. package/source/types/guard.ts +12 -0
  78. package/source/types/index.ts +1 -3
  79. package/source/types/injection.ts +2 -2
  80. package/source/types/lifecycle.ts +3 -3
  81. package/source/types/middleware.ts +5 -5
  82. package/source/types/plugin.ts +4 -6
  83. package/source/types/raiton.ts +3 -3
  84. package/source/types/responses.ts +10 -7
  85. package/source/types/router.ts +5 -5
  86. package/source/types/runtime.ts +1 -1
  87. package/source/types/server.ts +3 -3
  88. package/source/types/thread.ts +7 -7
  89. package/source/types/utilities.ts +1 -1
  90. package/source/types/values.ts +2 -2
  91. package/source/types/access-guards.ts +0 -4
  92. package/source/types/http-responses.ts +0 -8
  93. package/source/types/scheme.ts +0 -153
@@ -1,18 +1,18 @@
1
- import {RequestContext} from "@/core/context";
1
+ import {RequestContext} from "../core/context";
2
2
 
3
3
 
4
- export type NextCallable = () => Promise<void>
4
+ export type MiddlewareNextCallable = () => Promise<void>
5
5
 
6
6
  export interface MiddlewareSetupInterface {
7
7
  setup: any,
8
8
  name: string;
9
9
  }
10
10
 
11
- export interface MiddlewareParameters {
11
+ export interface MiddlewareParametersInterface {
12
12
  context: RequestContext;
13
- next: NextCallable;
13
+ next: MiddlewareNextCallable;
14
14
  }
15
15
 
16
- export type MiddlewareCallable = (parameters: MiddlewareParameters) => Promise<any> | void
16
+ export type MiddlewareCallable = (parameters: MiddlewareParametersInterface) => Promise<any> | void
17
17
 
18
18
  export type MiddlewareType = MiddlewareCallable | MiddlewareSetupInterface
@@ -1,10 +1,8 @@
1
- import {PluginScope} from "@/core/plugins/scope";
1
+ import {PluginScope} from "../core/plugins/scope";
2
2
 
3
- export type PluginFn = (
4
- scope: PluginScope
5
- ) => Promise<void> | void
3
+ export type PluginCallable = (scope: PluginScope) => Promise<void> | void
6
4
 
7
- export interface Plugin {
5
+ export interface PluginInterface {
8
6
  name?: string
9
- setup: PluginFn
7
+ setup: PluginCallable
10
8
  }
@@ -1,7 +1,7 @@
1
- import {BuilderHMRDeclaration} from "@/types/builder";
1
+ import {BuilderHMRDeclarationInterface} from "./builder";
2
2
 
3
- export interface RaitonSignalMap {
3
+ export interface RaitonSignalMapInterface {
4
4
  ready?: undefined;
5
5
  errors: any;
6
- 'hmr:controller': BuilderHMRDeclaration;
6
+ 'hmr:controller': BuilderHMRDeclarationInterface;
7
7
  }
@@ -1,16 +1,11 @@
1
- import {HttpStatus} from "@/sdk/enums/http-status.enum";
1
+ import {HttpStatus} from "../sdk/enums/http-status.enum";
2
+ import {ParseableEntriesType, ParseableType} from "./parseable";
2
3
 
3
4
  export interface HttpResponseBaseInterface {
4
5
  message: string;
5
6
  statusCode?: HttpStatus;
6
7
  }
7
8
 
8
- export interface HttpResponseInterface<T = any> extends HttpResponseBaseInterface{
9
- error?: boolean;
10
- errorStack?: Error | ErrorResponseInterface[];
11
- data?: T
12
- }
13
-
14
9
  export interface ErrorResponseInterface {
15
10
  id: string;
16
11
  message?: string;
@@ -18,3 +13,11 @@ export interface ErrorResponseInterface {
18
13
  statusCode?: HttpStatus;
19
14
  error?: Error
20
15
  }
16
+
17
+ export interface HttpResponseInterface<T extends ParseableType> extends ParseableEntriesType {
18
+ statusCode: number,
19
+ message?: string,
20
+ data?: T,
21
+ error?: any,
22
+ errorStack?: Error | ErrorResponseInterface[];
23
+ }
@@ -1,11 +1,11 @@
1
- import {RequestContext} from "@/core/context";
2
- import {HttpMethod} from "@/sdk";
1
+ import {RequestContext} from "../core/context";
2
+ import {HttpMethod} from "../sdk";
3
3
 
4
- export type RouteHandler = (ctx: RequestContext) => Promise<any> | any
4
+ export type RouteHandlerCallable = (ctx: RequestContext) => Promise<any> | any
5
5
 
6
- export interface RouteDefinition {
6
+ export interface RouteDefinitionInterface {
7
7
  method: HttpMethod
8
8
  path: string
9
9
  version?: string
10
- handler: RouteHandler
10
+ handler: RouteHandlerCallable
11
11
  }
@@ -1,4 +1,4 @@
1
- import {RuntimeType} from "@/sdk/enums/runtime.enum";
1
+ import {RuntimeType} from "../sdk/enums/runtime.enum";
2
2
 
3
3
  export interface RuntimeServerInterface {
4
4
  listen(port: number, hostname?: string): Promise<void>
@@ -1,10 +1,10 @@
1
1
  export interface ServerInterface {
2
- readonly options: ServerOptions;
2
+ readonly options: ServerOptionsInterface;
3
3
 
4
- option<K extends keyof ServerOptions>(key: K): ServerOptions[K];
4
+ option<K extends keyof ServerOptionsInterface>(key: K): ServerOptionsInterface[K];
5
5
  }
6
6
 
7
- export interface ServerOptions {
7
+ export interface ServerOptionsInterface {
8
8
  os?: string;
9
9
  arch?: string;
10
10
  ip?: string;
@@ -1,9 +1,9 @@
1
- import {BuilderInterface} from "@/types/builder";
2
- import {RuntimeAdapterInterface} from "@/types/runtime";
3
- import {ApplicationInterface} from "@/types/application";
4
- import {RuntimeType} from "@/sdk/enums/runtime.enum";
1
+ import {BuilderInterface} from "./builder";
2
+ import {RuntimeAdapterInterface} from "./runtime";
3
+ import {ApplicationInterface} from "./application";
4
+ import {RuntimeType} from "../sdk/enums/runtime.enum";
5
5
 
6
- export interface ThreadSetupOptions {
6
+ export interface ThreadSetupOptionsInterface {
7
7
  application: ApplicationInterface;
8
8
  runtime?: RuntimeType
9
9
  }
@@ -14,7 +14,7 @@ export interface ThreadInterface {
14
14
  readonly appDir: string;
15
15
  readonly builder: BuilderInterface;
16
16
 
17
- setup(options: ThreadSetupOptions): this
17
+ setup(options: ThreadSetupOptionsInterface): this
18
18
 
19
19
  run(): Promise<this>;
20
20
 
@@ -28,4 +28,4 @@ export interface ThreadInterface {
28
28
  }
29
29
 
30
30
 
31
- export interface ThreadOptions{}
31
+ export interface ThreadOptionsInterface {}
@@ -1,4 +1,4 @@
1
- export interface FileSizeFormated {
1
+ export interface FileSizeFormatedInterface {
2
2
  size: number;
3
3
  unit: string;
4
4
  }
@@ -1,3 +1,3 @@
1
1
 
2
- export type IString = string | Object | null | undefined;
3
- export type IStringable = IString | IString[] | Promise<IString | IString[]>;
2
+ export type StringType = string | Object | null | undefined;
3
+ export type StringableType = StringType | StringType[] | Promise<StringType | StringType[]>;
@@ -1,4 +0,0 @@
1
- export interface IAccessGuardDeclaration {
2
- credential?: boolean;
3
- capabilities?: string[];
4
- }
@@ -1,8 +0,0 @@
1
- import {ParseableEntriesType, ParseableType} from "./parseable";
2
-
3
- export interface IHttpResponse<T extends ParseableType> extends ParseableEntriesType {
4
- statusCode: number,
5
- message?: string,
6
- data?: T,
7
- error?: any,
8
- }
@@ -1,153 +0,0 @@
1
- import {TObject, TProperties, TSchema} from "@sinclair/typebox";
2
-
3
-
4
- export interface ISchemePropertyOptions {
5
- optional?: boolean;
6
- }
7
-
8
- /**
9
- * The `ISchematic` interface provides a structured contract for managing and constructing schemas
10
- * that define the shape of request bodies, parameters, query strings, and response structures.
11
- * It allows dynamic assignment of schema properties and the retrieval of constructed schema configurations.
12
- *
13
- * @template TBody The schema type defining the request body.
14
- * @template TParams The schema type defining the request parameters.
15
- * @template TQuery The schema type defining the query string.
16
- * @template TResponse The schema type defining the response structure, indexed by HTTP status codes.
17
- */
18
- export interface IScheme<
19
- TBody extends TSchema | undefined = undefined,
20
- TParams extends TSchema | undefined = undefined,
21
- TQuery extends TSchema | undefined = undefined,
22
- TResponse extends Record<number, TSchema> | undefined = undefined
23
- > {
24
- /**
25
- * Retrieves the value of the `$body` property.
26
- *
27
- * @return {TBody | undefined} The body content of type `TBody` or `undefined` if not set.
28
- */
29
- get $body(): TBody | undefined;
30
-
31
- /**
32
- * Updates the body of the request with a specified key-value pair.
33
- *
34
- * @param {string} key - The key to be added or updated in the body of the request.
35
- * @param {TProperties} value - The value associated with the specified key.
36
- * @return {this} The current instance to allow method chaining.
37
- */
38
- body(key: string, value: TProperties): this;
39
-
40
- /**
41
- * Retrieves the current value of `$params`.
42
- *
43
- * This method returns the parameter(s) associated with the instance.
44
- * It may return undefined if no parameters are set.
45
- *
46
- * @return {TParams | undefined} The current parameters or undefined if none are set.
47
- */
48
- get $params(): TParams | undefined;
49
-
50
- /**
51
- * Assigns a key-value pair to the parameters of the current instance.
52
- *
53
- * @param {string} key - The key for the parameter to be set.
54
- * @param {TProperties} value - The value associated with the specified key.
55
- * @return {this} The current instance with the updated parameter.
56
- */
57
- params(key: string, value: TProperties): this;
58
-
59
- /**
60
- * Retrieves the query string associated with the current object.
61
- *
62
- * @return {TQuery | undefined} The query string if defined, otherwise undefined.
63
- */
64
- get $querystring(): TQuery | undefined;
65
-
66
- /**
67
- * Updates or sets a query string parameter with the specified key and value.
68
- * If the query string already contains the key, its value will be updated.
69
- *
70
- * @param {string} key - The key of the query string parameter to be updated or added.
71
- * @param {TProperties} value - The value to be set for the specified query string key.
72
- * @return {this} The current instance to allow for method chaining.
73
- */
74
- querystring(key: string, value: TProperties): this;
75
-
76
- /**
77
- * Retrieves the response object associated with the instance.
78
- *
79
- * @return {TResponse | undefined} The response object if it exists, otherwise undefined.
80
- */
81
- get $response(): TResponse | undefined;
82
-
83
- /**
84
- * Stores a key-value pair in the response object and returns the current instance for chaining.
85
- *
86
- * @param {number} key - The unique identifier for the value to be stored.
87
- * @param {TProperties} value - The value to store associated with the provided key.
88
- * @return {this} Returns the current instance to allow method chaining.
89
- */
90
- response(key: number, value: TProperties): this;
91
-
92
- /**
93
- * Provides the schema options for handling the request and response structure.
94
- *
95
- * @return {ISchemeOptions<TBody, TParams, TQuery, TResponse>} The schema options defining the types for body, params, query, and response.
96
- */
97
- schema(): ISchemeOptions<TBody, TParams, TQuery, TResponse>;
98
- }
99
-
100
- /**
101
- * Interface representing the schema configuration for various aspects of a request-response process.
102
- *
103
- * @template TBody Represents the schema for the request body. Defaults to undefined if not specified.
104
- * @template TParams Represents the schema for request parameters. Defaults to undefined if not specified.
105
- * @template TQuery Represents the schema for query string parameters. Defaults to undefined if not specified.
106
- * @template TResponse Represents the schema for response objects, mapped by status codes. Defaults to undefined if not specified.
107
- *
108
- * @property {TBody} [body] Optional schema definition for the request body.
109
- * @property {TParams} [params] Optional schema definition for the request parameters.
110
- * @property {TQuery} [querystring] Optional schema definition for query string parameters.
111
- * @property {TResponse} [response] Optional schema definition for response objects, associated with HTTP status codes.
112
- */
113
- export interface ISchemeConfig<
114
- TBody extends TSchema | undefined = undefined,
115
- TParams extends TSchema | undefined = undefined,
116
- TQuery extends TSchema | undefined = undefined,
117
- TResponse extends Record<number, TSchema> | undefined = undefined
118
- > {
119
- body?: TBody;
120
- params?: TParams;
121
- querystring?: TQuery;
122
- response?: TResponse;
123
- }
124
-
125
- /**
126
- * Interface representing schema options for defining request and response payloads
127
- * in a structured and strongly-typed manner.
128
- *
129
- * @template TBody - The type of the schema for the request body, or undefined if not applicable.
130
- * @template TParams - The type of the schema for the request parameters, or undefined if not applicable.
131
- * @template TQuery - The type of the schema for the query string, or undefined if not applicable.
132
- * @template TResponse - A record of HTTP status codes to their respective response schemas, or undefined if not applicable.
133
- *
134
- * @property body - Represents the schema definition for the request body.
135
- * This is an optional property and only applies if TBody is specified.
136
- * @property params - Represents the schema definition for the request parameters.
137
- * This is an optional property and only applies if TParams is specified.
138
- * @property querystring - Represents the schema definition for the query string.
139
- * This is an optional property and only applies if TQuery is specified.
140
- * @property response - Represents the schema definition for the response body, mapped by status code.
141
- * This is an optional property and only applies if TResponse is specified.
142
- */
143
- export interface ISchemeOptions<
144
- TBody extends TSchema | undefined = undefined,
145
- TParams extends TSchema | undefined = undefined,
146
- TQuery extends TSchema | undefined = undefined,
147
- TResponse extends Record<number, TSchema> | undefined = undefined
148
- > {
149
- body?: TObject<NonNullable<TBody>> | undefined;
150
- params?: TObject<NonNullable<TParams>> | undefined;
151
- querystring?: TObject<NonNullable<TQuery>> | undefined;
152
- response?: TObject<NonNullable<TResponse>> | undefined;
153
- }