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
@@ -0,0 +1,125 @@
1
+ # `@HealthCheck()`
2
+
3
+ > **Navigation :** [← route-interaction](route-interaction.md) | [README →](README.md)
4
+
5
+ `@HealthCheck()` qualifie un endpoint de contrôleur comme **health-check**. Il marque la méthode avec des métadonnées (`path`, `tags`, `summary`, …) et, combiné à un décorateur de route (`@Get`, `@Post`, …), enregistre le endpoint personnalisé.
6
+
7
+ Si vous ne définissez **aucun** health-check, Raiton en fournit un **par défaut** sur `GET /health`.
8
+
9
+ ## Pourquoi utilisé
10
+
11
+ - exposer un point de contrôle pour les sondes d'infrastructure (load balancer, orchestrateur, « liveness » / « readiness »)
12
+ - centraliser les vérifications de dépendances (base de données, cache, services externes)
13
+ - qualifier clairement une méthode comme endpoint de santé dans le code
14
+
15
+ ## Comment l'utiliser
16
+
17
+ - placez `@HealthCheck()` sur la méthode d'un contrôleur
18
+ - combinez-le avec un décorateur de route pour définir le chemin réel
19
+ - personnalisez la réponse globale avec `HealthCheckManager.configure(...)`
20
+ - ajoutez des vérifications personnalisées avec `checks`
21
+
22
+ ## Exemple
23
+
24
+ ```typescript
25
+ import { Controllable, Get, HealthCheck, HttpStatus, RaitonResponses } from "raiton/framework"
26
+
27
+ @Controllable()
28
+ export class HealthController {
29
+ @Get("/health")
30
+ @HealthCheck({ summary: "État de l'application" })
31
+ check() {
32
+ return RaitonResponses(
33
+ "Service is healthy",
34
+ { status: "healthy" },
35
+ HttpStatus.OK,
36
+ { error: false }
37
+ )
38
+ }
39
+ }
40
+ ```
41
+
42
+ ## Health-check par défaut
43
+
44
+ Si aucun contrôleur ne définit de health-check, Raiton enregistre automatiquement `GET /health` après le scan des contrôleurs. Il renvoie :
45
+
46
+ ```json
47
+ {
48
+ "statusCode": 200,
49
+ "message": "Service is healthy",
50
+ "data": {
51
+ "status": "healthy",
52
+ "timestamp": "2026-09-03T12:00:00.000Z",
53
+ "uptime": 42.1,
54
+ "version": "0.0.0"
55
+ }
56
+ }
57
+ ```
58
+
59
+ Dès que vous définissez votre propre endpoint sur le même chemin, le défaut est remplacé.
60
+
61
+ ## Options de `@HealthCheck()`
62
+
63
+ | Option | Type | défaut | Description |
64
+ | ------ | ---- | ------ | ----------- |
65
+ | `path` | `string` | `/health` | chemin du endpoint |
66
+ | `tags` | `string[]` | `['Health']` | tags pour la documentation |
67
+ | `summary` | `string` | – | résumé du endpoint |
68
+ | `description` | `string` | – | description détaillée |
69
+ | `excludeFromDocs` | `boolean` | `false` | exclure de la documentation |
70
+
71
+ ## Configuration globale
72
+
73
+ `HealthCheckManager` permet de configurer le comportement par défaut.
74
+
75
+ ```typescript
76
+ import { HealthCheckManager, HttpStatus } from "raiton/framework"
77
+
78
+ HealthCheckManager.configure({
79
+ path: "/health",
80
+ response: {
81
+ statusCode: HttpStatus.OK,
82
+ message: "All systems operational"
83
+ }
84
+ })
85
+ ```
86
+
87
+ ### Vérifications personnalisées
88
+
89
+ ```typescript
90
+ HealthCheckManager.configure({
91
+ checks: [
92
+ {
93
+ name: "database",
94
+ check: async () => {
95
+ // testez votre connexion
96
+ return { status: "healthy" as const }
97
+ }
98
+ },
99
+ {
100
+ name: "cache",
101
+ check: async () => ({ status: "degraded" as const, message: "cache partiellement disponible" })
102
+ }
103
+ ]
104
+ })
105
+ ```
106
+
107
+ Les résultats des vérifications sont agrégés dans `data.checks`. Le statut global est :
108
+ - `unhealthy` si au moins une vérification échoue (code `503 Service Unavailable`)
109
+ - `degraded` sinon
110
+ - `healthy` par défaut (code `200`)
111
+
112
+ ## Avantages
113
+
114
+ - aucun code à écrire pour disposer d'un point de contrôle
115
+ - personnalisable par contrôleur ou globalement
116
+ - se combine naturellement avec les routes existantes
117
+
118
+ ## Inconvénients
119
+
120
+ - le health-check par défaut reste minimal (uptime/version) tant que vous n'ajoutez pas de `checks`
121
+ - le statut global dépend de la qualité de vos vérifications
122
+
123
+ ---
124
+
125
+ [← route-interaction](route-interaction.md) | [README →](README.md)
@@ -0,0 +1,117 @@
1
+ # Health-check
2
+
3
+ > **Navigation :** [← security](security.md) | [https →](https.md)
4
+
5
+ Les health-checks permettent d'exposer un endpoint de contrôle pour les sondes d'infrastructure (load balancer, orchestrateur, « liveness » / « readiness »). Raiton fournit un endpoint **par défaut** et vous permet de le **personnaliser** grâce à `@HealthCheck()` et `HealthCheckManager`.
6
+
7
+ ## Endpoint par défaut
8
+
9
+ Sans aucune configuration, Raiton enregistre automatiquement `GET /health` **après** le scan des contrôleurs.
10
+
11
+ ```json
12
+ {
13
+ "statusCode": 200,
14
+ "message": "Service is healthy",
15
+ "data": {
16
+ "status": "healthy",
17
+ "timestamp": "2026-09-03T12:00:00.000Z",
18
+ "uptime": 42.1,
19
+ "version": "0.0.0"
20
+ }
21
+ }
22
+ ```
23
+
24
+ Dès que vous définissez votre propre health-check, le défaut est remplacé.
25
+
26
+ ## Définir un health-check personnalisé
27
+
28
+ Utilisez `@HealthCheck()` sur une méthode combinée à un décorateur de route.
29
+
30
+ ```typescript
31
+ import { Controllable, Get, HealthCheck, HttpStatus, RaitonResponses } from "raiton/framework"
32
+
33
+ @Controllable()
34
+ export class HealthController {
35
+ @Get("/health")
36
+ @HealthCheck({ summary: "État de l'application" })
37
+ check() {
38
+ return RaitonResponses(
39
+ "Service is healthy",
40
+ { status: "healthy" },
41
+ HttpStatus.OK,
42
+ { error: false }
43
+ )
44
+ }
45
+ }
46
+ ```
47
+
48
+ Vous pouvez renvoyer un code `503 Service Unavailable` dans le cas où l'application est en mauvaise santé.
49
+
50
+ ## Configurer le comportement par défaut
51
+
52
+ `HealthCheckManager.configure(...)` agit sur le health-check par défaut (et sur les sauts de middleware applicables).
53
+
54
+ ```typescript
55
+ import { HealthCheckManager, HttpStatus } from "raiton/framework"
56
+
57
+ HealthCheckManager.configure({
58
+ path: "/health",
59
+ response: {
60
+ statusCode: HttpStatus.OK,
61
+ message: "All systems operational"
62
+ }
63
+ })
64
+ ```
65
+
66
+ ### Vérifications personnalisées
67
+
68
+ Ajoutez des vérifications de dépendances pour enrichir la réponse.
69
+
70
+ ```typescript
71
+ HealthCheckManager.configure({
72
+ checks: [
73
+ {
74
+ name: "database",
75
+ check: async () => {
76
+ // testez votre connexion
77
+ return { status: "healthy" as const }
78
+ }
79
+ },
80
+ {
81
+ name: "cache",
82
+ check: async () => ({ status: "degraded" as const, message: "cache partiellement disponible" })
83
+ }
84
+ ]
85
+ })
86
+ ```
87
+
88
+ Les résultats sont agrégés dans `data.checks`. Le statut global est :
89
+ - `unhealthy` si au moins une vérification échoue (code `503`)
90
+ - `degraded` sinon
91
+ - `healthy` par défaut (code `200`)
92
+
93
+ ### Handler entièrement personnalisé
94
+
95
+ `registerCustomHandler` remplace entièrement la logique de réponse du health-check par défaut.
96
+
97
+ ```typescript
98
+ HealthCheckManager.registerCustomHandler((ctx) => {
99
+ return { ok: true, memory: process.memoryUsage() }
100
+ })
101
+ ```
102
+
103
+ ## Types et options
104
+
105
+ - `HealthCheckManager.configure(config)` : `path`, `response` (`statusCode`, `message`), `checks`.
106
+ - `@HealthCheck(options)` : `path`, `tags`, `summary`, `description`, `excludeFromDocs`.
107
+ - `HealthCheckCheck` : `{ name, check }` où `check` renvoie `{ status, message? }`.
108
+
109
+ ## Bon usage
110
+
111
+ - garder le endpoint de santé léger et sans logique métier lourde
112
+ - utiliser `checks` pour les dépendances critiques (base de données, cache)
113
+ - renvoyer `503` quand l'application ne peut plus traiter de requêtes
114
+
115
+ ---
116
+
117
+ [← security](security.md) | [https →](https.md)
@@ -21,13 +21,14 @@ return await thread.setup({
21
21
  ## Pourquoi utilisé
22
22
 
23
23
  - choisir explicitement l’environnement d’exécution
24
- - garder un point d’entrée unique pour Bun et Node
24
+ - garder un point d’entrée unique pour Bun, Node et Deno
25
25
 
26
26
  ## Comment l’utiliser
27
27
 
28
28
  - laissez Raiton détecter le runtime si vous ne souhaitez rien imposer
29
29
  - forcez `RuntimeType.Bun` si vous ciblez Bun en priorité
30
30
  - utilisez `RuntimeType.Node` si vous visez un exécutable Node
31
+ - utilisez `RuntimeType.Deno` si vous exécutez l’application avec Deno
31
32
 
32
33
  ## Avantages
33
34
 
@@ -1,6 +1,6 @@
1
1
  # Sécurité
2
2
 
3
- > **Navigation :** [← body-parser](body-parser.md) | [https →](https.md)
3
+ > **Navigation :** [← body-parser](body-parser.md) | [csrf →](csrf.md)
4
4
 
5
5
  Les plugins de sécurité servent à protéger une API exposée publiquement.
6
6
 
@@ -8,6 +8,7 @@ Les plugins de sécurité servent à protéger une API exposée publiquement.
8
8
 
9
9
  - `Security.headers()`
10
10
  - `Security.cors()`
11
+ - `Security.csrf()` — [Documentation complète](csrf.md)
11
12
  - `Security.rateLimit()`
12
13
  - `Security.bodyLimit()`
13
14
  - `Security.methodGuard()`
@@ -19,6 +20,7 @@ app.register({
19
20
  plugins: [
20
21
  Security.headers(),
21
22
  Security.cors({ origin: "*" }),
23
+ Security.csrf({ mode: CSRFModeEnum.DOUBLE_SUBMIT, secret: process.env.CSRF_SECRET }),
22
24
  Security.rateLimit({ max: 100, windowMs: 60000 }),
23
25
  Security.bodyLimit(1_000_000)
24
26
  ]
@@ -30,17 +32,21 @@ app.register({
30
32
  - réduire les abus
31
33
  - contrôler les origines autorisées
32
34
  - limiter la taille des payloads
35
+ - protéger contre les attaques CSRF (Cross-Site Request Forgery)
33
36
 
34
37
  ## Avantages
35
38
 
36
39
  - facile à activer
37
40
  - couvre plusieurs protections de base
41
+ - CSRF supporte le mode stateless (double-submit) et stateful (synchronizer)
42
+ - détection automatique des clients mobile/desktop
38
43
 
39
44
  ## Inconvénients
40
45
 
41
46
  - `rateLimit()` est en mémoire, donc non distribué
42
47
  - `cors()` doit être configuré selon le contexte réel
48
+ - `csrf()` nécessite une configuration côté client pour les navigateurs
43
49
 
44
50
  ---
45
51
 
46
- [← body-parser](body-parser.md) | [https →](https.md)
52
+ [← body-parser](body-parser.md) | [csrf →](csrf.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raiton",
3
- "version": "6.5.0-beta.13",
3
+ "version": "6.7.0-beta.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading.",
@@ -37,9 +37,14 @@
37
37
  "./types/*": "./source/types/*.ts"
38
38
  },
39
39
  "scripts": {
40
- "dev": "bun run --hot source/bin/index.ts",
41
- "start": "bun run build/bin/index.mjs",
40
+ "dev": "bun run --hot source/bin/index.ts dev",
41
+ "dev:node": "node build/bin/index.mjs dev",
42
+ "dev:deno": "deno task dev",
42
43
  "build": "bun build source/bin/index.ts --target=node --format=esm --outfile=build/bin/index.mjs",
44
+ "start": "bun run source/bin/index.ts start",
45
+ "start:node": "node build/bin/index.mjs start",
46
+ "start:deno": "deno task start",
47
+ "compile:deno": "deno task compile",
43
48
  "version": "bun run scripts/update-version.ts",
44
49
  "postinstall": "bun run scripts/postinstall.js",
45
50
  "prepublishOnly": "npm run build"
@@ -1,7 +1,7 @@
1
1
  import {Command} from 'commander';
2
- import {RaitonCommands, RaitonConfig} from "../core";
3
- import {getPackageRoot} from "../framework";
4
- import {CliTools} from "./cli-tools";
2
+ import {RaitonCommands, RaitonConfig} from "../core/index.ts";
3
+ import {getPackageRoot} from "../framework/index.ts";
4
+ import {CliTools} from "./cli-tools.ts";
5
5
 
6
6
 
7
7
  export default async function bootstrapper(cli: Command) {
@@ -11,5 +11,5 @@ export default async function bootstrapper(cli: Command) {
11
11
 
12
12
  await RaitonConfig.sync(workdir);
13
13
  await capabilities.harvest();
14
- return cli.parse(process.argv)
14
+ return cli.parse(CliTools.argv)
15
15
  }
@@ -1,6 +1,8 @@
1
1
  /// <reference types="deno" />
2
2
  import {spawn} from 'node:child_process';
3
- import {isBunUsed, isDenoUsed} from "./constants";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import {isBunUsed, isDenoUsed, isNodeUsed} from "./constants.ts";
4
6
 
5
7
 
6
8
  export class CliTools {
@@ -8,6 +10,20 @@ export class CliTools {
8
10
  return `${isDenoUsed ? (globalThis as any).Deno.cwd() : process.cwd()}`;
9
11
  }
10
12
 
13
+ /**
14
+ * Resolve the runtime-appropriate CLI entry point.
15
+ * - Node: `build/bin/index.mjs` (compiled bundle)
16
+ * - Bun / Deno: `bin/index.ts` (native TypeScript execution)
17
+ */
18
+ static cliEntry(appdir: string): string {
19
+ if (isNodeUsed) {
20
+ const built = path.join(appdir, 'build', 'bin', 'index.mjs');
21
+ if (fs.existsSync(built)) return built;
22
+ return path.join(appdir, 'bin', 'index.mjs');
23
+ }
24
+ return path.join(appdir, 'bin', 'index.ts');
25
+ }
26
+
11
27
  static set cwd(value: string) {
12
28
  if (isDenoUsed) {
13
29
  (globalThis as any).Deno.chdir(value);
@@ -18,7 +34,7 @@ export class CliTools {
18
34
 
19
35
  static get argv() {
20
36
  if (isBunUsed) return (globalThis as any).Bun.argv;
21
- if (isDenoUsed) return (globalThis as any).Deno.args;
37
+ if (isDenoUsed) return [globalThis, 'run', ...(globalThis as any).Deno.args];
22
38
  return process.argv;
23
39
  }
24
40
 
@@ -62,7 +78,15 @@ export class CliTools {
62
78
  const cmdArgs = typeof command == 'string' ? args : [...command.slice(1), ...args];
63
79
 
64
80
  if (cmd.endsWith('.ts')) {
65
- return spawn('node', ['--loader', 'ts-node/register', cmd, ...cmdArgs], options);
81
+ const entry = CliTools.cliEntry(path.resolve(cmd, '..', '..'));
82
+ if (fs.existsSync(entry)) {
83
+ return spawn('node', [entry, ...cmdArgs], options);
84
+ }
85
+ return spawn('node', [cmd, ...cmdArgs], options);
86
+ }
87
+
88
+ if (cmd.endsWith('.mjs') || cmd.endsWith('.js') || cmd.endsWith('.cjs')) {
89
+ return spawn('node', [cmd, ...cmdArgs], options);
66
90
  }
67
91
 
68
92
  return spawn(cmd, cmdArgs, options);
package/source/bin/cli.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {Command} from "commander";
2
- import {version} from '../../package.json';
2
+ import pkg from '../../package.json' with {type: "json"};
3
3
 
4
4
 
5
5
  const CLI = new Command();
@@ -7,6 +7,6 @@ const CLI = new Command();
7
7
  CLI
8
8
  .name('raiton')
9
9
  .description('Protorians Raiton framework for backend microservice')
10
- .version(version);
10
+ .version(pkg.version);
11
11
 
12
12
  export default CLI;
@@ -0,0 +1,17 @@
1
+ import ArtifactCommand from "../commands/artifact.command.ts";
2
+ import BuildCommand from "../commands/build.command.ts";
3
+ import DevelopCommand from "../commands/develop.command.ts";
4
+ import GraftsCommand from "../commands/grafts.command.ts";
5
+ import StartCommand from "../commands/start.command.ts";
6
+ import type {Command} from "commander";
7
+ import type {RaitonCommand} from "../core/index.ts";
8
+
9
+ export type RaitonCommandConstructor = new (cli: Command, workdir: string, appdir: string) => RaitonCommand;
10
+
11
+ export const RaitonCommandsRegistry: RaitonCommandConstructor[] = [
12
+ ArtifactCommand,
13
+ BuildCommand,
14
+ DevelopCommand,
15
+ GraftsCommand,
16
+ StartCommand,
17
+ ];
@@ -1,5 +1,6 @@
1
1
  export const isBunUsed = typeof (globalThis as any).Bun !== "undefined";
2
2
  export const isDenoUsed = typeof (globalThis as any).Deno !== "undefined";
3
+ export const isNodeUsed = !isBunUsed && !isDenoUsed;
3
4
 
4
5
  declare const Bun: any;
5
6
  declare const Deno: any;
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  import "reflect-metadata"
3
- import CLI from "./cli";
4
- import bootstrapper from "./bootstrapper";
3
+ import CLI from "./cli.ts";
4
+ import bootstrapper from "./bootstrapper.ts";
5
5
 
6
6
  bootstrapper(CLI)
@@ -1,6 +1,6 @@
1
- import {RaitonCommand, RaitonBuilder} from "../core";
1
+ import {RaitonCommand, RaitonBuilder} from "../core/index.ts";
2
2
  import {Logger} from "@protorians/logger";
3
- import type {BuildCommandOptionsInterface} from "../types";
3
+ import type {BuildCommandOptionsInterface} from "../types/index.ts";
4
4
 
5
5
 
6
6
  export default class ArtifactCommand extends RaitonCommand {
@@ -1,6 +1,6 @@
1
- import {RaitonCommand, RaitonBuilder} from "../core";
1
+ import {RaitonCommand, RaitonBuilder} from "../core/index.ts";
2
2
  import {LBadge, Logger} from "@protorians/logger";
3
- import type {BuildCommandOptionsInterface} from "../types";
3
+ import type {BuildCommandOptionsInterface} from "../types/index.ts";
4
4
 
5
5
 
6
6
  export default class BuildCommand extends RaitonCommand {
@@ -1,10 +1,9 @@
1
1
  /// <reference types="deno" />
2
- import {Raiton, RaitonCommand} from "../core";
2
+ import {Raiton, RaitonCommand} from "../core/index.ts";
3
3
  import {ChildProcess, ChildProcessWithoutNullStreams} from 'node:child_process';
4
4
  import {Logger} from "@protorians/logger";
5
- import {EventMessageEnum} from "../framework";
6
- import {CliTools} from "../bin/cli-tools";
7
- import path from "node:path";
5
+ import {EventMessageEnum} from "../framework/index.ts";
6
+ import {CliTools} from "../bin/cli-tools.ts";
8
7
 
9
8
  export default class DevelopCommand extends RaitonCommand {
10
9
  public readonly name: string = 'develop';
@@ -32,7 +31,7 @@ export default class DevelopCommand extends RaitonCommand {
32
31
  protected async run(): Promise<void> {
33
32
  // Logger.info('Workdir', this.workdir);
34
33
 
35
- const entryPoint = path.join(this.appdir, 'bin/index.ts');
34
+ const entryPoint = CliTools.cliEntry(this.appdir);
36
35
  this.child = CliTools.spawn(entryPoint, ['build', '-d'], {
37
36
  stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
38
37
  cwd: this.workdir
@@ -1,4 +1,4 @@
1
- import {RaitonCommand} from "../core";
1
+ import {RaitonCommand} from "../core/index.ts";
2
2
 
3
3
 
4
4
  export default class GraftsCommand extends RaitonCommand {
@@ -1,8 +1,8 @@
1
1
  /// <reference types="deno" />
2
- import {RaitonBuilder, RaitonCommand} from "../core";
2
+ import {RaitonBuilder, RaitonCommand} from "../core/index.ts";
3
3
  import {ChildProcess} from 'node:child_process';
4
4
  import {LBadge, Logger} from "@protorians/logger";
5
- import {StartCommandOptionsInterface} from "../types";
5
+ import {StartCommandOptionsInterface} from "../types/index.ts";
6
6
 
7
7
  export default class StartCommand extends RaitonCommand {
8
8
  public readonly name: string = 'start';
@@ -1,14 +1,14 @@
1
- import {Security, bodyParserPlugin} from "../framework/plugins";
2
- import {PluginScope} from './plugins/scope'
3
- import {RequestContext} from './context'
4
- import {ApplicationConfigInterface, ApplicationInterface} from "../types/application";
5
- import {HttpException, HttpMethod, ThrowableResponse, RaitonResponses, HttpStatus} from "../framework";
6
- import {RouteHandlerCallable} from "../types";
1
+ import {Security, bodyParserPlugin} from "../framework/plugins/index.ts";
2
+ import {PluginScope} from './plugins/scope.ts'
3
+ import {RequestContext} from './context.ts'
4
+ import {ApplicationConfigInterface, ApplicationInterface} from "../types/application.ts";
5
+ import {HttpException, HttpMethod, ThrowableResponse, RaitonResponses, HttpStatus} from "../framework/index.ts";
6
+ import {RouteHandlerCallable} from "../types/index.ts";
7
7
  import {Logger} from "@protorians/logger";
8
- import {RaitonConfig} from "./config";
9
- import {Artifacts} from "../framework/artifacts";
10
- import {Injection} from "./injection";
11
- import {HttpsConfigInterface, resolveHttpsConfig} from "../framework/utilities/https";
8
+ import {RaitonConfig} from "./config/index.ts";
9
+ import {Artifacts} from "../framework/artifacts.ts";
10
+ import {Injection} from "./injection/index.ts";
11
+ import {HttpsConfigInterface, resolveHttpsConfig} from "../framework/utilities/https.util.ts";
12
12
 
13
13
  export class Application implements ApplicationInterface {
14
14
  private root: PluginScope
@@ -1,4 +1,4 @@
1
- import {RaitonConfig} from "../config/config";
1
+ import {RaitonConfig} from "../config/config.ts";
2
2
 
3
3
  export class Artifact {
4
4
 
@@ -1 +1 @@
1
- export * from "./artifact";
1
+ export * from "./artifact.ts";