raiton 6.5.0-beta.13 → 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.
Files changed (166) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +16 -9
  3. package/build/bin/index.mjs +10288 -6059
  4. package/deno.json +4 -1
  5. package/docs/contributors/framework/README.md +2 -0
  6. package/docs/contributors/framework/cache/README.md +55 -0
  7. package/docs/contributors/framework/cache/cache.md +86 -0
  8. package/docs/contributors/framework/cache/etag.md +82 -0
  9. package/docs/contributors/framework/decorators/README.md +1 -0
  10. package/docs/contributors/framework/plugins/csrf.md +277 -0
  11. package/docs/contributors/framework/plugins/security.md +40 -6
  12. package/docs/contributors/framework/runtime.md +13 -3
  13. package/docs/user-guide/README.md +8 -4
  14. package/docs/user-guide/best-practices.md +1 -0
  15. package/docs/user-guide/cache.md +79 -0
  16. package/docs/user-guide/cli.md +35 -3
  17. package/docs/user-guide/csrf.md +557 -0
  18. package/docs/user-guide/decorators/README.md +3 -0
  19. package/docs/user-guide/decorators/cache.md +79 -0
  20. package/docs/user-guide/decorators/health-check.md +125 -0
  21. package/docs/user-guide/health-check.md +117 -0
  22. package/docs/user-guide/runtime.md +2 -1
  23. package/docs/user-guide/security.md +8 -2
  24. package/package.json +8 -3
  25. package/source/bin/bootstrapper.ts +4 -4
  26. package/source/bin/cli-tools.ts +27 -3
  27. package/source/bin/cli.ts +2 -2
  28. package/source/bin/commands.registry.ts +17 -0
  29. package/source/bin/constants.ts +1 -0
  30. package/source/bin/index.ts +2 -2
  31. package/source/commands/artifact.command.ts +2 -2
  32. package/source/commands/build.command.ts +2 -2
  33. package/source/commands/develop.command.ts +4 -5
  34. package/source/commands/grafts.command.ts +1 -1
  35. package/source/commands/start.command.ts +2 -2
  36. package/source/core/application.ts +10 -10
  37. package/source/core/artifacts/artifact.ts +1 -1
  38. package/source/core/artifacts/index.ts +1 -1
  39. package/source/core/builder.ts +69 -15
  40. package/source/core/bytes.util.ts +1 -1
  41. package/source/core/commands.ts +24 -14
  42. package/source/core/config/config.ts +2 -2
  43. package/source/core/config/define.ts +2 -2
  44. package/source/core/config/index.ts +2 -2
  45. package/source/core/context.ts +1 -1
  46. package/source/core/controller/builder.ts +31 -8
  47. package/source/core/controller/compiler.ts +6 -6
  48. package/source/core/controller/index.ts +4 -4
  49. package/source/core/controller/metadata.ts +2 -2
  50. package/source/core/controller/tracker.ts +1 -1
  51. package/source/core/directories.ts +3 -2
  52. package/source/core/guards.ts +1 -1
  53. package/source/core/helpers/index.ts +1 -1
  54. package/source/core/hooks.ts +1 -1
  55. package/source/core/index.ts +16 -16
  56. package/source/core/injection/index.ts +1 -1
  57. package/source/core/injection/injection.ts +3 -3
  58. package/source/core/mcp/builder.ts +8 -8
  59. package/source/core/mcp/index.ts +3 -3
  60. package/source/core/mcp/metadata.ts +2 -2
  61. package/source/core/mcp/tracker.ts +1 -1
  62. package/source/core/middleware/compose.ts +2 -2
  63. package/source/core/middleware/index.ts +2 -2
  64. package/source/core/middleware/pipeline.ts +2 -2
  65. package/source/core/plugins/index.ts +2 -2
  66. package/source/core/plugins/plugin.ts +1 -1
  67. package/source/core/plugins/scope.ts +4 -4
  68. package/source/core/raiton.ts +1 -1
  69. package/source/core/router/handler.ts +30 -6
  70. package/source/core/router/handler.utils.ts +3 -3
  71. package/source/core/router/index.ts +4 -4
  72. package/source/core/router/matcher.ts +1 -1
  73. package/source/core/router/route.ts +1 -1
  74. package/source/core/router/router.ts +4 -4
  75. package/source/core/server.ts +1 -1
  76. package/source/core/socket/builder.ts +2 -2
  77. package/source/core/socket/index.ts +2 -2
  78. package/source/core/socket/metadata.ts +2 -2
  79. package/source/core/thread.ts +53 -20
  80. package/source/framework/artifacts.ts +8 -5
  81. package/source/framework/cache/cache.decorator.ts +35 -0
  82. package/source/framework/cache/cache.ts +197 -0
  83. package/source/framework/cache/etag.ts +174 -0
  84. package/source/framework/cache/index.ts +4 -0
  85. package/source/framework/cache/types.ts +111 -0
  86. package/source/framework/constants/decorators.constant.ts +4 -0
  87. package/source/framework/constants/index.ts +2 -2
  88. package/source/framework/decorators/access-guard.decorator.ts +2 -2
  89. package/source/framework/decorators/api-response.decorator.ts +1 -1
  90. package/source/framework/decorators/api.decorator.ts +1 -1
  91. package/source/framework/decorators/controllable.decorator.ts +3 -3
  92. package/source/framework/decorators/csrf-guard.decorator.ts +60 -0
  93. package/source/framework/decorators/csrf-token.decorator.ts +20 -0
  94. package/source/framework/decorators/guard.decorator.ts +4 -4
  95. package/source/framework/decorators/health-check.decorator.ts +50 -0
  96. package/source/framework/decorators/index.ts +14 -11
  97. package/source/framework/decorators/injection.decorator.ts +3 -3
  98. package/source/framework/decorators/mcp.decorator.ts +4 -4
  99. package/source/framework/decorators/middleware.decorator.ts +2 -2
  100. package/source/framework/decorators/parametrable.decorator.ts +2 -2
  101. package/source/framework/decorators/routable.decorator.ts +3 -3
  102. package/source/framework/decorators/route-interaction.decorator.ts +4 -4
  103. package/source/framework/decorators/socket.decorator.ts +3 -3
  104. package/source/framework/encryption.ts +2 -2
  105. package/source/framework/enums/csrf.enum.ts +4 -0
  106. package/source/framework/enums/index.ts +8 -7
  107. package/source/framework/enums/runtime.enum.ts +1 -2
  108. package/source/framework/env.ts +2 -2
  109. package/source/framework/exceptions/http-exception.ts +3 -3
  110. package/source/framework/exceptions/index.ts +2 -2
  111. package/source/framework/health-check.ts +137 -0
  112. package/source/framework/index.ts +18 -16
  113. package/source/framework/mcp/handler.ts +3 -3
  114. package/source/framework/mcp/index.ts +3 -3
  115. package/source/framework/mcp/protocol.ts +1 -1
  116. package/source/framework/mcp/streamable-http.ts +3 -3
  117. package/source/framework/parameter-bag.ts +2 -2
  118. package/source/framework/plugins/body-parser.plugin.ts +3 -3
  119. package/source/framework/plugins/index.ts +4 -4
  120. package/source/framework/plugins/mcp.plugin.ts +5 -5
  121. package/source/framework/plugins/openapi.plugin.ts +4 -4
  122. package/source/framework/plugins/security/body-limit.ts +3 -3
  123. package/source/framework/plugins/security/cors.ts +2 -2
  124. package/source/framework/plugins/security/csrf.ts +145 -0
  125. package/source/framework/plugins/security/headers.ts +2 -2
  126. package/source/framework/plugins/security/index.ts +7 -5
  127. package/source/framework/plugins/security/method-guard.ts +3 -3
  128. package/source/framework/plugins/security/rate-limit.ts +3 -3
  129. package/source/framework/repositories.ts +1 -1
  130. package/source/framework/responses/error.ts +2 -2
  131. package/source/framework/responses/helpers.ts +3 -3
  132. package/source/framework/responses/http-throwable.ts +3 -3
  133. package/source/framework/responses/http.ts +3 -3
  134. package/source/framework/responses/index.ts +4 -4
  135. package/source/framework/runtime/bun/server.ts +5 -5
  136. package/source/framework/runtime/deno/server.ts +156 -96
  137. package/source/framework/runtime/index.ts +11 -17
  138. package/source/framework/runtime/node/reply.ts +1 -1
  139. package/source/framework/runtime/node/request.ts +2 -2
  140. package/source/framework/runtime/node/server.ts +3 -3
  141. package/source/framework/runtime/web/server.ts +2 -2
  142. package/source/framework/services.ts +1 -1
  143. package/source/framework/utilities/artifact.util.ts +4 -0
  144. package/source/framework/utilities/csrf.util.ts +162 -0
  145. package/source/framework/utilities/index.ts +10 -9
  146. package/source/framework/utilities/openapi.utils.ts +7 -7
  147. package/source/framework/utilities/utilities.util.ts +1 -1
  148. package/source/types/application.ts +2 -2
  149. package/source/types/builder.ts +1 -1
  150. package/source/types/config.ts +1 -1
  151. package/source/types/controller.ts +3 -3
  152. package/source/types/core.ts +1 -1
  153. package/source/types/csrf.ts +38 -0
  154. package/source/types/guard.ts +1 -1
  155. package/source/types/http-responses.ts +1 -1
  156. package/source/types/index.ts +26 -25
  157. package/source/types/injection.ts +1 -1
  158. package/source/types/middleware.ts +1 -1
  159. package/source/types/plugin.ts +1 -1
  160. package/source/types/raiton.ts +1 -1
  161. package/source/types/responses.ts +2 -2
  162. package/source/types/router.ts +2 -2
  163. package/source/types/runtime.ts +3 -5
  164. package/source/types/thread.ts +4 -4
  165. /package/source/framework/utilities/{https.ts → https.util.ts} +0 -0
  166. /package/source/framework/utilities/{url.ts → url.util.ts} +0 -0
@@ -1,17 +1,18 @@
1
- import {RaitonConfig} from "./config";
1
+ import {RaitonConfig} from "./config/index.ts";
2
2
  import path from "node:path";
3
- import {RaitonDirectories} from "./directories";
3
+ import {RaitonDirectories} from "./directories.ts";
4
4
  import fs, {WatchEventType} from "node:fs";
5
- import type {BuilderConfigInterface, BuilderInterface, ThreadInterface,} from "../types";
6
- import {RaitonThread} from "./thread";
7
- import {Raiton} from "./raiton";
8
- import {ControllerBuilder} from "./controller";
5
+ import type {BuilderConfigInterface, BuilderInterface, ThreadInterface,} from "../types/index.ts";
6
+ import {RaitonThread} from "./thread.ts";
7
+ import {Raiton} from "./raiton.ts";
8
+ import {ControllerBuilder} from "./controller/index.ts";
9
9
  import {watch} from "fs";
10
10
  import {LBadge, Logger} from "@protorians/logger";
11
- import {Throwable} from "../framework/exceptions";
12
- import {Artifacts, HMR_CHANNELS, HmrChannel} from "../framework/artifacts";
11
+ import {Throwable} from "../framework/exceptions/index.ts";
12
+ import {Artifacts, HMR_CHANNELS, HmrChannel} from "../framework/artifacts.ts";
13
13
  import {build} from "esbuild";
14
14
  import {execSync, spawn, spawnSync} from "node:child_process";
15
+ import {isNodeUsed} from "../bin/constants.ts";
15
16
 
16
17
  export class RaitonBuilder implements BuilderInterface {
17
18
  protected _source: string | null = null;
@@ -55,6 +56,14 @@ export class RaitonBuilder implements BuilderInterface {
55
56
  const classification = Artifacts.classify(filename)
56
57
  if (!classification) return
57
58
 
59
+ // Sur Node, le rechargement d'artefacts TypeScript en mémoire n'est pas
60
+ // possible (import() natif des fichiers .ts). On bascule alors sur le
61
+ // redémarrage de processus via IPC RESTART géré par la commande `develop`.
62
+ if (isNodeUsed) {
63
+ Raiton.thread?.restart()
64
+ return
65
+ }
66
+
58
67
  const payload = {
59
68
  filename,
60
69
  timestamp: Date.now(),
@@ -102,7 +111,7 @@ export class RaitonBuilder implements BuilderInterface {
102
111
 
103
112
 
104
113
  this._bootstrapper = path.join(this._source, RaitonDirectories.bootstrapFile)
105
- this._bootstrapperFile = path.join(RaitonDirectories.server('./'), RaitonDirectories.bootstrapFile)
114
+ this._bootstrapperFile = path.join(RaitonDirectories.server(this.workdir), RaitonDirectories.compiledBootstrapFile)
106
115
 
107
116
  return this;
108
117
 
@@ -198,24 +207,69 @@ export class RaitonBuilder implements BuilderInterface {
198
207
 
199
208
  const source = path.relative(this.workdir, this._source)
200
209
  const output = path.relative(this.workdir, this._out)
201
- const tsconfig = 'tsconfig.json'
202
- // const tsconfig = path.join(path.relative(this._source, this.workdir), 'tsconfig.json')
203
210
 
204
211
  Logger.log(LBadge.notice('Building'), 'application');
205
212
  Logger.log(LBadge.info('Source'), source);
206
213
  Logger.log(LBadge.info('Output'), output);
207
214
 
208
- execSync(`cd ${this.workdir} && npx tsc -p ${tsconfig} --outDir ${output} --noEmit`, {stdio: 'inherit'})
215
+ await this.typecheck()
216
+ await this.compile()
217
+
218
+ return this;
219
+ }
220
+
221
+ protected async typecheck(): Promise<this> {
222
+ const tsconfigPath = path.join(this.workdir, 'tsconfig.json')
223
+ if (!fs.existsSync(tsconfigPath)) return this
224
+
225
+ try {
226
+ execSync(`cd ${this.workdir} && npx tsc -p tsconfig.json --noEmit`, {stdio: 'inherit'})
227
+ } catch (e: any) {
228
+ Logger.warn('TypeScript check reported errors', e?.message ?? e)
229
+ }
230
+
231
+ return this;
232
+ }
233
+
234
+ protected async compile(): Promise<this> {
235
+ if (!this._source) throw new Error('Application source not found');
236
+ if (!this._out) throw new Error('Application output not found');
237
+ if (!this.bootstrapper) throw new Error('Bootstrapper not found')
238
+
239
+ const outfile = this.bootstrapperFile
240
+ if (!outfile) throw new Error('Bootstrapper file not found')
241
+
242
+ await build({
243
+ entryPoints: [this.bootstrapper],
244
+ bundle: true,
245
+ platform: 'node',
246
+ format: 'esm',
247
+ target: 'node20',
248
+ outfile,
249
+ sourcemap: true,
250
+ packages: 'external',
251
+ external: ['@protorians/*', 'argon2', 'bcrypt'],
252
+ })
209
253
 
210
254
  return this;
211
255
  }
212
256
 
213
257
  public async boot(): Promise<any> {
214
258
  if (!this.bootstrapper) throw new Error('Bootstrapper not found')
215
- if (!fs.existsSync(this.bootstrapper))
216
- throw new Error(`Bootstrapper file "${this.bootstrapper}" does not exists`)
217
259
 
218
- const bootstrapper = await import(this.bootstrapper);
260
+ let entry = this.bootstrapper
261
+
262
+ if (isNodeUsed) {
263
+ const compiled = this.bootstrapperFile
264
+ if (!compiled) throw new Error('Bootstrapper file not found')
265
+ if (!fs.existsSync(compiled)) await this.compile()
266
+ entry = compiled
267
+ }
268
+
269
+ if (!fs.existsSync(entry))
270
+ throw new Error(`Bootstrapper file "${entry}" does not exists`)
271
+
272
+ const bootstrapper = await import(entry);
219
273
  if (!('default' in bootstrapper))
220
274
  throw new Error('Bootstrapper not supported! Please export to "default"')
221
275
 
@@ -1,4 +1,4 @@
1
- import {FileSizeFormatedInterface} from "../types";
1
+ import {FileSizeFormatedInterface} from "../types/index.ts";
2
2
 
3
3
  export function parseBytes(bytes: number, decimals = 2): FileSizeFormatedInterface {
4
4
  if (bytes === 0) return {size: 0, unit: "o"};
@@ -1,5 +1,5 @@
1
1
  import {Command} from "commander";
2
- import {RaitonCommand} from "./command";
2
+ import {RaitonCommand} from "./command.ts";
3
3
  import fs from 'node:fs';
4
4
  import path from "node:path";
5
5
  import {Logger} from "@protorians/logger";
@@ -17,28 +17,38 @@ export class RaitonCommands {
17
17
 
18
18
  public async harvest(): Promise<void> {
19
19
  const dir = path.join(this.appdir, 'commands');
20
-
21
- if (!fs.existsSync(dir)) {
22
- return;
23
- }
24
20
 
25
- const files = fs.readdirSync(dir);
21
+ if (fs.existsSync(dir)) {
22
+ const files = fs.readdirSync(dir);
23
+
24
+ for (const file of files) {
25
+ if (file.startsWith('~')) continue;
26
+ if (file.endsWith('.d.ts')) continue;
27
+ if (!file.includes('.command.')) continue;
28
+
29
+ const filepath = path.join(dir, file);
30
+ const mod = await import(filepath);
31
+
32
+ const capability = new mod.default(this.cli, this.workdir, this.appdir)
26
33
 
27
- for (const file of files) {
28
- if (file.startsWith('~')) continue;
29
- if (file.endsWith('.d.ts')) continue;
30
- if (!file.includes('.command.')) continue;
34
+ if (!(capability instanceof RaitonCommand)) continue;
31
35
 
32
- const filepath = path.join(dir, file);
33
- const mod = await import(filepath);
36
+ capability.register();
37
+ this.stack.add(capability);
38
+ }
34
39
 
35
- const capability = new mod.default(this.cli, this.workdir, this.appdir)
40
+ return;
41
+ }
42
+
43
+ const {RaitonCommandsRegistry} = await import("../bin/commands.registry.ts");
44
+
45
+ for (const constructor of RaitonCommandsRegistry) {
46
+ const capability = new constructor(this.cli, this.workdir, this.appdir)
36
47
 
37
48
  if (!(capability instanceof RaitonCommand)) continue;
38
49
 
39
50
  capability.register();
40
51
  this.stack.add(capability);
41
52
  }
42
-
43
53
  }
44
54
  }
@@ -1,8 +1,8 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
- import {ConfigurableInterface} from "../../types";
3
+ import {ConfigurableInterface} from "../../types/index.ts";
4
4
  import {Logger} from "@protorians/logger";
5
- import {Raiton} from "../raiton";
5
+ import {Raiton} from "../raiton.ts";
6
6
 
7
7
  export class RaitonConfig {
8
8
  static readonly current: Map<keyof ConfigurableInterface, ConfigurableInterface[keyof ConfigurableInterface]> = new Map();
@@ -1,5 +1,5 @@
1
- import {ConfigurableInterface} from "../../types/config";
2
- import {JsonUtil} from "../../framework/utilities";
1
+ import {ConfigurableInterface} from "../../types/config.ts";
2
+ import {JsonUtil} from "../../framework/utilities/index.ts";
3
3
 
4
4
  export async function defineConfig(config?: ConfigurableInterface) {
5
5
  const workdir = process.cwd();
@@ -1,2 +1,2 @@
1
- export * from "./config"
2
- export * from "./define"
1
+ export * from "./config.ts"
2
+ export * from "./define.ts"
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  RuntimeRequestInterface,
3
3
  RuntimeReplyInterface
4
- } from '../types'
4
+ } from '../types/index.ts'
5
5
 
6
6
  export class RequestContext {
7
7
  public state: Record<string, any> = {}
@@ -1,14 +1,15 @@
1
1
  import fs from "node:fs";
2
- import {BuilderHMRDeclarationInterface} from "../../types";
2
+ import {BuilderHMRDeclarationInterface} from "../../types/index.ts";
3
3
  import {LBadge, Logger} from "@protorians/logger";
4
- import {compileController} from "./compiler";
5
- import {compileSocket} from "../socket/builder";
6
- import {compileMcp} from "../mcp/builder";
7
- import {RaitonThread} from "../thread";
8
- import {Injection} from "../injection";
9
- import {isControllerArtifact, isSocketArtifact, isMcpArtifact} from "../../framework";
4
+ import {compileController} from "./compiler.ts";
5
+ import {compileSocket} from "../socket/builder.ts";
6
+ import {compileMcp} from "../mcp/builder.ts";
7
+ import {RaitonThread} from "../thread.ts";
8
+ import {Injection} from "../injection/index.ts";
9
+ import {isControllerArtifact, isSocketArtifact, isMcpArtifact} from "../../framework/index.ts";
10
+ import {Artifacts} from "../../framework/artifacts.ts";
10
11
  import path from "node:path";
11
- import {ControllerRouteTracker} from "./tracker";
12
+ import {ControllerRouteTracker} from "./tracker.ts";
12
13
 
13
14
  export class ControllerBuilder {
14
15
 
@@ -16,6 +17,14 @@ export class ControllerBuilder {
16
17
  const files = fs.readdirSync(workdir, {recursive: true})
17
18
  .map(file => file.toString());
18
19
  const output: any[] = []
20
+ const timestamp = Date.now()
21
+
22
+ for (const file of files) {
23
+ const filename = path.join(workdir, file);
24
+ const classification = Artifacts.classify(filename);
25
+ if (classification?.channel !== 'hmr:di') continue;
26
+ await this.loadDiArtifact(filename, 1, timestamp);
27
+ }
19
28
 
20
29
  for (const file of files) {
21
30
  output.push(await this.build<any>({filename: path.join(workdir, file), version: 1, timestamp: Date.now()}))
@@ -24,6 +33,20 @@ export class ControllerBuilder {
24
33
  return output.filter(f => typeof f !== 'undefined');
25
34
  }
26
35
 
36
+ static async loadDiArtifact(filename: string, version = 1, timestamp = Date.now()): Promise<void> {
37
+ const imported = await import(`${filename}?v=${version || 1}&t=${timestamp || Date.now()}`)
38
+
39
+ for (const mod of Object.values(imported)) {
40
+ const name = (mod && typeof mod === 'object' && 'name' in mod) ? mod.name : (
41
+ typeof mod === 'function' ? mod.name ?? mod.constructor.name : undefined
42
+ );
43
+
44
+ if (typeof name === 'string' && Injection.has(name)) {
45
+ Injection.registerArtifactPath(name, filename)
46
+ }
47
+ }
48
+ }
49
+
27
50
  static async build<T>({filename, version, timestamp}: BuilderHMRDeclarationInterface): Promise<T | undefined> {
28
51
  const isController = isControllerArtifact(filename);
29
52
  const isSocket = isSocketArtifact(filename);
@@ -1,9 +1,9 @@
1
- import {ApplicationInterface} from "../../types/application";
2
- import {getControllerMetadata} from "..";
3
- import {createHandler} from "../router";
4
- import {Injection} from "../injection";
5
- import {ControllerMetaInterface} from "../../types";
6
- import {ControllerRouteTracker} from "./tracker";
1
+ import {ApplicationInterface} from "../../types/application.ts";
2
+ import {getControllerMetadata} from "../index.ts";
3
+ import {createHandler} from "../router/index.ts";
4
+ import {Injection} from "../injection/index.ts";
5
+ import {ControllerMetaInterface} from "../../types/index.ts";
6
+ import {ControllerRouteTracker} from "./tracker.ts";
7
7
 
8
8
  export function compileController(
9
9
  ControllerClass: any,
@@ -1,4 +1,4 @@
1
- export * from "./metadata"
2
- export * from "./compiler"
3
- export * from "./builder"
4
- export * from "./tracker"
1
+ export * from "./metadata.ts"
2
+ export * from "./compiler.ts"
3
+ export * from "./builder.ts"
4
+ export * from "./tracker.ts"
@@ -1,5 +1,5 @@
1
- import {ControllerMetaInterface} from "../../types";
2
- import {METADATA_KEYS} from "../../framework";
1
+ import {ControllerMetaInterface} from "../../types/index.ts";
2
+ import {METADATA_KEYS} from "../../framework/index.ts";
3
3
  import "reflect-metadata";
4
4
 
5
5
  export function getControllerMetadata(target: any): ControllerMetaInterface {
@@ -1,4 +1,4 @@
1
- import {Route} from "../router"
1
+ import {Route} from "../router/index.ts"
2
2
 
3
3
  const controllerRouteMap = new Map<string, Route[]>()
4
4
 
@@ -1,11 +1,12 @@
1
1
  import path from "node:path";
2
- import {RaitonConfig} from "./config";
3
- import {Raiton} from "./raiton";
2
+ import {RaitonConfig} from "./config/index.ts";
3
+ import {Raiton} from "./raiton.ts";
4
4
 
5
5
 
6
6
  export class RaitonDirectories {
7
7
  public static readonly index = `.${Raiton.identifier}`;
8
8
  public static readonly bootstrapFile = 'main.ts';
9
+ public static readonly compiledBootstrapFile = 'main.mjs';
9
10
  // public static readonly bootstrapFile = 'main.js';
10
11
 
11
12
  public static caches(workdir: string): string {
@@ -1,4 +1,4 @@
1
- import {GuardDeclaration} from "../types";
1
+ import {GuardDeclaration} from "../types/index.ts";
2
2
  import {Logger} from "@protorians/logger";
3
3
 
4
4
  export class RaitonGuards {
@@ -1 +1 @@
1
- export * from './raiton';
1
+ export * from './raiton.ts';
@@ -1,4 +1,4 @@
1
- import {HookNameType, HookHandlerCallable} from '../types'
1
+ import {HookNameType, HookHandlerCallable} from '../types/index.ts'
2
2
 
3
3
  export class HookStore {
4
4
  private hooks = new Map<HookNameType, HookHandlerCallable[]>()
@@ -1,16 +1,16 @@
1
- export * from "./config";
2
- export * from "./process.util";
3
- export * from "./builder";
4
- export * from "./bytes.util";
5
- export * from "./commands";
6
- export * from "./command";
7
- export * from "./directories";
8
- export * from "./raiton";
9
- export * from "./thread";
10
- export * from "./application";
11
- export * from "./controller";
12
- export * from "./socket";
13
- export * from "./mcp";
14
- export * from "./plugins";
15
- export * from "./middleware";
16
- export * from "./router";
1
+ export * from "./config/index.ts";
2
+ export * from "./process.util.ts";
3
+ export * from "./builder.ts";
4
+ export * from "./bytes.util.ts";
5
+ export * from "./commands.ts";
6
+ export * from "./command.ts";
7
+ export * from "./directories.ts";
8
+ export * from "./raiton.ts";
9
+ export * from "./thread.ts";
10
+ export * from "./application.ts";
11
+ export * from "./controller/index.ts";
12
+ export * from "./socket/index.ts";
13
+ export * from "./mcp/index.ts";
14
+ export * from "./plugins/index.ts";
15
+ export * from "./middleware/index.ts";
16
+ export * from "./router/index.ts";
@@ -1 +1 @@
1
- export * from './injection';
1
+ export * from './injection.ts';
@@ -1,9 +1,9 @@
1
1
  import "reflect-metadata";
2
- import type {ConstructorType, ContainerDefinitionInterface} from "../../types";
2
+ import type {ConstructorType, ContainerDefinitionInterface} from "../../types/index.ts";
3
3
  import {LifetimeEnum, TextUtility} from "@protorians/core";
4
4
  import {Logger} from "@protorians/logger";
5
- import {METADATA_KEYS} from "../../framework/constants";
6
- import {Throwable} from "../../framework/exceptions";
5
+ import {METADATA_KEYS} from "../../framework/constants/index.ts";
6
+ import {Throwable} from "../../framework/exceptions/index.ts";
7
7
 
8
8
  const camelCase = TextUtility.camelCase;
9
9
 
@@ -1,11 +1,11 @@
1
- import {registerMcpServer, unregisterMcpServer, getMcpServerMetadata} from "./metadata";
2
- import {Injection} from "../injection";
3
- import {McpServerRegistrationInterface} from "../../types";
4
- import {McpRouteTracker} from "./tracker";
5
- import {RaitonThread} from "../thread";
6
- import {HttpMethod} from "../../framework/enums";
7
- import {mcpHandleGet, mcpHandlePost, isMcpJsonRpc, SESSION_HEADER} from "../../framework/mcp/streamable-http";
8
- import type {ContextInterface} from "../../types/core";
1
+ import {registerMcpServer, unregisterMcpServer, getMcpServerMetadata} from "./metadata.ts";
2
+ import {Injection} from "../injection/index.ts";
3
+ import {McpServerRegistrationInterface} from "../../types/index.ts";
4
+ import {McpRouteTracker} from "./tracker.ts";
5
+ import {RaitonThread} from "../thread.ts";
6
+ import {HttpMethod} from "../../framework/enums/index.ts";
7
+ import {mcpHandleGet, mcpHandlePost, isMcpJsonRpc, SESSION_HEADER} from "../../framework/mcp/streamable-http.ts";
8
+ import type {ContextInterface} from "../../types/core.ts";
9
9
 
10
10
  export function compileMcp(McpServerClass: any): McpServerRegistrationInterface | undefined {
11
11
  const metadata = getMcpServerMetadata(McpServerClass.prototype || McpServerClass)
@@ -1,3 +1,3 @@
1
- export * from "./metadata"
2
- export * from "./builder"
3
- export * from "./tracker"
1
+ export * from "./metadata.ts"
2
+ export * from "./builder.ts"
3
+ export * from "./tracker.ts"
@@ -1,5 +1,5 @@
1
- import {McpServerMetaInterface, McpServerRegistrationInterface} from "../../types";
2
- import {METADATA_KEYS} from "../../framework/constants";
1
+ import {McpServerMetaInterface, McpServerRegistrationInterface} from "../../types/index.ts";
2
+ import {METADATA_KEYS} from "../../framework/constants/index.ts";
3
3
  import "reflect-metadata";
4
4
 
5
5
  const registry = new Map<string, McpServerRegistrationInterface>();
@@ -1,4 +1,4 @@
1
- import {Route} from "../router"
1
+ import {Route} from "../router/index.ts"
2
2
 
3
3
  const mcpRouteMap = new Map<string, Route[]>()
4
4
 
@@ -1,5 +1,5 @@
1
- import {MiddlewareType} from '../../types'
2
- import {Throwable} from "../../framework/exceptions";
1
+ import {MiddlewareType} from '../../types/index.ts'
2
+ import {Throwable} from "../../framework/exceptions/index.ts";
3
3
 
4
4
  export function middlewareCompose(middlewares: MiddlewareType[]) {
5
5
  return function (request: any) {
@@ -1,2 +1,2 @@
1
- export * from "./compose"
2
- export * from "./pipeline"
1
+ export * from "./compose.ts"
2
+ export * from "./pipeline.ts"
@@ -1,5 +1,5 @@
1
- import { MiddlewareType } from '../../types'
2
- import { middlewareCompose } from '..'
1
+ import { MiddlewareType } from '../../types/index.ts'
2
+ import { middlewareCompose } from '../index.ts'
3
3
 
4
4
  export class MiddlewarePipeline {
5
5
  private stack: MiddlewareType[] = []
@@ -1,2 +1,2 @@
1
- export * from "./scope"
2
- export * from "./plugin"
1
+ export * from "./scope.ts"
2
+ export * from "./plugin.ts"
@@ -1,4 +1,4 @@
1
- import { PluginInterface, PluginCallable } from '../../types'
1
+ import { PluginInterface, PluginCallable } from '../../types/index.ts'
2
2
 
3
3
  export function definePlugin(
4
4
  setup: PluginCallable,
@@ -1,7 +1,7 @@
1
- import {HookStore} from '../hooks'
2
- import {MiddlewarePipeline} from '../middleware'
3
- import {Route, Router} from '../router'
4
- import {HttpMethod} from "../../framework/enums";
1
+ import {HookStore} from '../hooks.ts'
2
+ import {MiddlewarePipeline} from '../middleware/index.ts'
3
+ import {Route, Router} from '../router/index.ts'
4
+ import {HttpMethod} from "../../framework/enums/index.ts";
5
5
 
6
6
  export class PluginScope {
7
7
  public hooks: HookStore
@@ -1,4 +1,4 @@
1
- import {RaitonSignalMapInterface, ThreadInterface} from "../types";
1
+ import {RaitonSignalMapInterface, ThreadInterface} from "../types/index.ts";
2
2
  import {ISignalStack, Signal} from "@protorians/core";
3
3
 
4
4
 
@@ -1,21 +1,40 @@
1
- import {ControllerMetaInterface, RouteMetaInterface} from "../../types";
1
+ import {ControllerMetaInterface, RouteMetaInterface} from "../../types/index.ts";
2
2
  import {Logger} from "@protorians/logger";
3
- import {Raiton} from "..";
4
- import {HttpException} from "../../framework/exceptions";
5
- import {ThrowableResponse} from "../../framework/responses/http-throwable";
6
- import {collectRouteArguments, validateDtoArguments, validateResponse, runMiddlewares} from "./handler.utils";
7
- import {RaitonResponses, HttpStatus} from "../../framework";
3
+ import {Raiton} from "../index.ts";
4
+ import {HttpException} from "../../framework/exceptions/index.ts";
5
+ import {ThrowableResponse} from "../../framework/responses/http-throwable.ts";
6
+ import {collectRouteArguments, validateDtoArguments, validateResponse, runMiddlewares} from "./handler.utils.ts";
7
+ import {RouteCache, getCacheMetadata} from "../../framework/cache/index.ts";
8
+ import {RaitonResponses, HttpStatus} from "../../framework/index.ts";
8
9
 
9
10
  export function createHandler(
10
11
  instance: any,
11
12
  routeMeta: RouteMetaInterface,
12
13
  controllerMeta: ControllerMetaInterface,
13
14
  ) {
15
+ const cacheOptions = getCacheMetadata(instance, routeMeta.propertyKey);
16
+ const routeCache = cacheOptions ? new RouteCache(routeMeta.path, cacheOptions) : undefined;
17
+
14
18
  const handler = async (ctx: any) => {
15
19
  const isDevelopment = Raiton.thread?.builder?.options?.serve || false;
16
20
  const handlerName = `${instance.constructor.name}.${routeMeta.propertyKey}`
17
21
 
18
22
  try {
23
+ const cacheKey = (routeCache && routeCache.enabled && routeCache.matchesMethod(ctx.req?.method))
24
+ ? await routeCache.key(ctx)
25
+ : undefined;
26
+
27
+ if (cacheKey) {
28
+ const cached = await routeCache!.get(ctx, cacheKey);
29
+ if (cached) {
30
+ ctx.reply.status(cached.status);
31
+ for (const [name, value] of Object.entries(cached.headers)) {
32
+ ctx.reply.header(name, value);
33
+ }
34
+ return cached.body;
35
+ }
36
+ }
37
+
19
38
  const args = collectRouteArguments(instance, routeMeta, ctx);
20
39
  const middlewares = [...controllerMeta.middlewares['@'] || [], ...controllerMeta.middlewares[routeMeta.propertyKey] || []];
21
40
  await runMiddlewares(middlewares, ctx);
@@ -23,6 +42,11 @@ export function createHandler(
23
42
  let responses = instance[routeMeta.propertyKey](...args);
24
43
  if (responses instanceof Promise) responses = await responses;
25
44
  await validateResponse(responses, instance, routeMeta);
45
+
46
+ if (cacheKey && !(responses instanceof ThrowableResponse)) {
47
+ await routeCache!.set(ctx, responses, 200, {}, cacheKey);
48
+ }
49
+
26
50
  return responses;
27
51
  } catch (err: any) {
28
52
 
@@ -1,7 +1,7 @@
1
- import {MiddlewareCallable, ParamMetaInterface, RouteMetaInterface} from "../../types";
2
- import {middlewareCompose} from "../../core";
1
+ import {MiddlewareCallable, ParamMetaInterface, RouteMetaInterface} from "../../types/index.ts";
2
+ import {middlewareCompose} from "../index.ts";
3
3
  import {validate} from "class-validator";
4
- import {DataTransferObject, METADATA_KEYS, Parametrable, parseCookie, Throwable, ViewModel} from "../../framework";
4
+ import {DataTransferObject, METADATA_KEYS, Parametrable, parseCookie, Throwable, ViewModel} from "../../framework/index.ts";
5
5
 
6
6
  /**
7
7
  * Helper function for collecting arguments from route parameters
@@ -1,4 +1,4 @@
1
- export * from "./route"
2
- export * from "./matcher"
3
- export * from "./router"
4
- export * from "./handler"
1
+ export * from "./route.ts"
2
+ export * from "./matcher.ts"
3
+ export * from "./router.ts"
4
+ export * from "./handler.ts"
@@ -1,4 +1,4 @@
1
- import {Route} from '.'
1
+ import {Route} from './index.ts'
2
2
 
3
3
  export class RouteMatcher {
4
4
  protected _routes = new Map<string, Route>()
@@ -1,4 +1,4 @@
1
- import type {RouteDefinitionInterface} from '../../types/router'
1
+ import type {RouteDefinitionInterface} from '../../types/router.ts'
2
2
 
3
3
  export class Route {
4
4
  method: string
@@ -1,7 +1,7 @@
1
- import {RouteHandlerCallable} from '../../types'
2
- import {HttpMethod} from "../../framework/enums";
3
- import {Route} from './route'
4
- import {RouteMatcher} from './matcher'
1
+ import {RouteHandlerCallable} from '../../types/index.ts'
2
+ import {HttpMethod} from "../../framework/enums/index.ts";
3
+ import {Route} from './route.ts'
4
+ import {RouteMatcher} from './matcher.ts'
5
5
 
6
6
  export class Router {
7
7
  private matcher = new RouteMatcher()