raiton 5.7.0-beta.5 → 5.9.5-beta.16

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 (46) hide show
  1. package/build/bin/index.mjs +92 -6
  2. package/docs/README.md +131 -0
  3. package/docs/cli/README.md +81 -0
  4. package/docs/cli/commands.md +167 -0
  5. package/docs/cli/hmr.md +121 -0
  6. package/docs/core/README.md +67 -0
  7. package/docs/core/application.md +149 -0
  8. package/docs/core/builder-thread.md +231 -0
  9. package/docs/core/config.md +124 -0
  10. package/docs/core/controller.md +120 -0
  11. package/docs/core/injection.md +226 -0
  12. package/docs/core/middleware.md +172 -0
  13. package/docs/core/plugin-scope.md +171 -0
  14. package/docs/core/router.md +122 -0
  15. package/docs/framework/README.md +96 -0
  16. package/docs/framework/base-classes.md +214 -0
  17. package/docs/framework/decorators/README.md +60 -0
  18. package/docs/framework/decorators/controllable.md +151 -0
  19. package/docs/framework/decorators/injection.md +186 -0
  20. package/docs/framework/decorators/middleware.md +167 -0
  21. package/docs/framework/decorators/openapi.md +254 -0
  22. package/docs/framework/decorators/parametrable.md +248 -0
  23. package/docs/framework/decorators/socket.md +152 -0
  24. package/docs/framework/encryption.md +183 -0
  25. package/docs/framework/env.md +88 -0
  26. package/docs/framework/plugins/README.md +50 -0
  27. package/docs/framework/plugins/body-parser.md +138 -0
  28. package/docs/framework/plugins/openapi.md +217 -0
  29. package/docs/framework/plugins/security.md +159 -0
  30. package/docs/framework/responses.md +180 -0
  31. package/docs/framework/runtime.md +138 -0
  32. package/docs/types/README.md +206 -0
  33. package/package.json +1 -1
  34. package/scripts/update-version.ts +1 -0
  35. package/source/core/application.ts +30 -5
  36. package/source/core/artifacts/artifact.ts +1 -1
  37. package/source/core/router/handler.ts +5 -9
  38. package/source/core/router/handler.utils.ts +1 -2
  39. package/source/framework/constants/decorators.constant.ts +2 -0
  40. package/source/framework/decorators/index.ts +2 -1
  41. package/source/framework/decorators/route-interaction.decorator.ts +188 -0
  42. package/source/framework/decorators/socket.decorator.ts +4 -4
  43. package/source/framework/exceptions/http-exception.ts +17 -0
  44. package/source/types/router.ts +5 -0
  45. package/source/types/thread.ts +4 -1
  46. package/examples/user-controller.example.ts +0 -53
@@ -4799,7 +4799,7 @@ var require_bcrypt = __commonJS((exports, module) => {
4799
4799
  });
4800
4800
 
4801
4801
  // source/bin/index.ts
4802
- var import_reflect_metadata8 = __toESM(require_Reflect(), 1);
4802
+ var import_reflect_metadata9 = __toESM(require_Reflect(), 1);
4803
4803
 
4804
4804
  // node_modules/commander/esm.mjs
4805
4805
  var import__ = __toESM(require_commander(), 1);
@@ -4817,7 +4817,7 @@ var {
4817
4817
  Help
4818
4818
  } = import__.default;
4819
4819
  // package.json
4820
- var version = "5.7.0-beta.5";
4820
+ var version = "5.9.5-beta.16";
4821
4821
 
4822
4822
  // source/bin/cli.ts
4823
4823
  var CLI = new Command;
@@ -6260,7 +6260,8 @@ var METADATA_KEYS = {
6260
6260
  API_ENUMS: Symbol("api:enums"),
6261
6261
  API_TAGS: Symbol("api:tags"),
6262
6262
  API_OPERATION: Symbol("api:operation"),
6263
- API_SECURITY: Symbol("api:security")
6263
+ API_SECURITY: Symbol("api:security"),
6264
+ ROUTE_INTERACTION: Symbol("route:interaction")
6264
6265
  };
6265
6266
  // source/framework/responses/http.ts
6266
6267
  class HttpResponse {
@@ -6494,6 +6495,41 @@ class Router {
6494
6495
  return Array.from(this.matcher.routes.values());
6495
6496
  }
6496
6497
  }
6498
+ // source/framework/exceptions/http-exception.ts
6499
+ class HttpException extends Error {
6500
+ statusCode;
6501
+ errorCode;
6502
+ constructor(error2, statusCode = 500 /* INTERNAL_SERVER_ERROR */, errorCode = undefined) {
6503
+ super(typeof error2 === "string" ? error2 : error2.message);
6504
+ this.statusCode = statusCode;
6505
+ this.errorCode = errorCode;
6506
+ }
6507
+ setStatus(statusCode) {
6508
+ this.statusCode = statusCode;
6509
+ return this;
6510
+ }
6511
+ setErrorCode(code) {
6512
+ this.errorCode = code;
6513
+ return this;
6514
+ }
6515
+ setMessage(error2) {
6516
+ this.message = typeof error2 === "string" ? error2 : error2.message;
6517
+ return this;
6518
+ }
6519
+ render() {
6520
+ return {
6521
+ message: this.message,
6522
+ statusCode: this.statusCode,
6523
+ errorCode: this.errorCode,
6524
+ error: true,
6525
+ stack: Raiton.thread?.builder?.options?.serve ? this.stack?.split(`
6526
+ `).map((e) => e.trim()) : undefined
6527
+ };
6528
+ }
6529
+ toString() {
6530
+ return `HttpException: ${this.message} with status code ${this.statusCode}`;
6531
+ }
6532
+ }
6497
6533
  // source/framework/exceptions/throwable.ts
6498
6534
  class Throwable extends Error {
6499
6535
  statusCode;
@@ -6950,6 +6986,32 @@ class RaitonGuards {
6950
6986
  var import_reflect_metadata6 = __toESM(require_Reflect2(), 1);
6951
6987
  // source/framework/decorators/api.decorator.ts
6952
6988
  var import_reflect_metadata7 = __toESM(require_Reflect2(), 1);
6989
+ // source/framework/decorators/route-interaction.decorator.ts
6990
+ var import_reflect_metadata8 = __toESM(require_Reflect2(), 1);
6991
+ class RouteInteractionsRegistry {
6992
+ static interactions = new Map;
6993
+ static subscribers = new Set;
6994
+ static subscribe(target, propertyKey) {
6995
+ this.subscribers.add({ target, propertyKey });
6996
+ return this;
6997
+ }
6998
+ static register(fullPath, descriptor) {
6999
+ this.interactions.set(fullPath, descriptor);
7000
+ return this;
7001
+ }
7002
+ static get(fullPath) {
7003
+ return this.interactions.get(fullPath);
7004
+ }
7005
+ static getAll() {
7006
+ return new Map(this.interactions);
7007
+ }
7008
+ static clear() {
7009
+ this.interactions.clear();
7010
+ }
7011
+ static has(fullPath) {
7012
+ return this.interactions.has(fullPath);
7013
+ }
7014
+ }
6953
7015
  // source/core/hooks.ts
6954
7016
  class HookStore {
6955
7017
  hooks = new Map;
@@ -7459,16 +7521,40 @@ class Application {
7459
7521
  try {
7460
7522
  context.params = route2.parameters;
7461
7523
  let responses2 = await route2.handler(context);
7524
+ if (responses2 instanceof ThrowableResponse) {
7525
+ context.reply.status(responses2.statusCode ?? 500);
7526
+ }
7527
+ if (responses2 instanceof HttpException) {
7528
+ context.reply.status(responses2.statusCode ?? 500);
7529
+ }
7462
7530
  context.reply.send(responses2);
7463
7531
  } catch (e) {
7464
- Logger.error("Failed to handle request", e.message ?? e);
7532
+ Logger.info(`${req2.method} ${req2.url}`);
7533
+ Logger.error("Failed to execute handle", e.message ?? e);
7465
7534
  if (this.config.develop) {
7466
7535
  console.error(e);
7467
7536
  }
7537
+ context.reply.status(500);
7538
+ context.reply.send({ error: true, statusCode: 500, data: null });
7468
7539
  }
7469
7540
  };
7470
- await this.root.middleware.run(ctx, handler2);
7471
- await this.root.hooks.run("onResponse", ctx);
7541
+ try {
7542
+ await this.root.middleware.run(ctx, handler2);
7543
+ await this.root.hooks.run("onResponse", ctx);
7544
+ } catch (err) {
7545
+ Logger.info(`${req.method} ${req.url}`);
7546
+ if (err instanceof HttpException || err instanceof ThrowableResponse) {
7547
+ Logger.error(`Server error`, err.message ?? err);
7548
+ ctx.reply.status(err.statusCode ?? 500);
7549
+ return ctx.reply.send(err.render());
7550
+ }
7551
+ ctx.reply.send({
7552
+ statusCode: 500,
7553
+ error: true,
7554
+ message: err.message ?? err,
7555
+ data: null
7556
+ });
7557
+ }
7472
7558
  }
7473
7559
  }
7474
7560
  // source/bin/cli-tools.ts
package/docs/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # Raiton — Documentation Développeur
2
+
3
+ Framework backend TypeScript modulaire avec injection de dépendances, plugins, contrôleurs, middleware et hot-reloading. Optimisé pour **Bun**, compatible **Node.js** et **Deno**.
4
+
5
+ ```
6
+ Version: 5.9.4-beta.15 | Runtime: Bun (recommandé), Node.js, Deno | Licence: MIT
7
+ ```
8
+
9
+ ## Navigation
10
+
11
+ | Section | Description |
12
+ |---------|-------------|
13
+ | [core/](core/README.md) | Noyau : Application, Router, Middleware, DI, Plugins, Config |
14
+ | [framework/](framework/README.md) | Décorateurs, Runtime, Réponses, Encryption, Plugins intégrés |
15
+ | [cli/](cli/README.md) | CLI, commandes develop/build/start, HMR |
16
+ | [types/](types/README.md) | Système de types et interfaces |
17
+
18
+ ## Structure de la documentation
19
+
20
+ ```
21
+ docs/
22
+ ├── README.md ← Ce fichier
23
+ ├── core/ ← Module noyau
24
+ │ ├── README.md ← Sommaire core/
25
+ │ ├── application.md ← Classe Application
26
+ │ ├── router.md ← Router, Route, RouteMatcher
27
+ │ ├── middleware.md ← Pipeline middleware
28
+ │ ├── controller.md ← ControllerBuilder, compilation
29
+ │ ├── injection.md ← Injection de dépendances
30
+ │ ├── plugin-scope.md ← Système de plugins
31
+ │ ├── config.md ← Configuration
32
+ │ └── builder-thread.md ← Build, thread, cycle de vie
33
+ ├── framework/ ← Module framework
34
+ │ ├── README.md ← Sommaire framework/
35
+ │ ├── runtime.md ← Adaptateurs Bun/Node/Deno
36
+ │ ├── responses.md ← Réponses et exceptions
37
+ │ ├── encryption.md ← Hachage et chiffrement
38
+ │ ├── env.md ← Variables d'environnement
39
+ │ ├── base-classes.md ← DTO, ViewModel, Service, Repository
40
+ │ ├── decorators/ ← Décorateurs
41
+ │ │ ├── README.md ← Sommaire décorateurs
42
+ │ │ ├── controllable.md ← @Controllable, @Get, @Post...
43
+ │ │ ├── parametrable.md ← @Param, @Query, @Body...
44
+ │ │ ├── injection.md ← @Injectable, @Inject
45
+ │ │ ├── middleware.md ← @Middleware
46
+ │ │ ├── socket.md ← @Socket, événements socket
47
+ │ │ └── openapi.md ← Décorateurs OpenAPI
48
+ │ └── plugins/ ← Plugins intégrés
49
+ │ ├── README.md ← Sommaire plugins
50
+ │ ├── body-parser.md ← Body parser
51
+ │ ├── openapi.md ← Plugin OpenAPI
52
+ │ └── security.md ← CORS, headers, rate-limit...
53
+ ├── cli/ ← CLI
54
+ │ ├── README.md ← Sommaire CLI
55
+ │ ├── commands.md ← Commandes disponibles
56
+ │ └── hmr.md ← Hot Module Replacement
57
+ └── types/ ← Types
58
+ └── README.md ← 29 fichiers de types
59
+ ```
60
+
61
+ ## Table des matières
62
+
63
+ - [Démarrage rapide](#démarrage-rapide)
64
+ - [Points d'entrée (package.json exports)](#points-dentrée-packagejson-exports)
65
+ - [Conventions de commits](#conventions-de-commits)
66
+
67
+ ## Démarrage rapide
68
+
69
+ ```bash
70
+ # Installation
71
+ bun add raiton reflect-metadata
72
+ ```
73
+
74
+ ```typescript
75
+ // source/controllers/hello.controller.ts
76
+ import { Controllable, Get, Param } from "raiton/framework"
77
+
78
+ @Controllable("/hello")
79
+ export class HelloController {
80
+ @Get("/")
81
+ index() {
82
+ return { message: "Bonjour de Raiton !" }
83
+ }
84
+
85
+ @Get("/:name")
86
+ greet(@Param("name") name?: string) {
87
+ return { message: `Bonjour, ${name} !` }
88
+ }
89
+ }
90
+
91
+ // source/main.ts (bootstrapper)
92
+ import "reflect-metadata"
93
+ import { ThreadInterface } from "raiton/types"
94
+ import { Application } from "raiton/core"
95
+ import { HelloController } from "./controllers/hello.controller"
96
+
97
+ export default async function (thread: ThreadInterface) {
98
+ const app = new Application({ port: 3000, prefix: "/api" })
99
+ app.register({ setup: (s) => s.get("/hello", (c) => c.reply.send("Hello")))
100
+ return await thread.setup({ application: app }).run()
101
+ }
102
+ ```
103
+
104
+ ```bash
105
+ # Lancer en développement
106
+ bun raiton dev
107
+ ```
108
+
109
+ ## Points d'entrée (package.json exports)
110
+
111
+ | Import | Chemin |
112
+ |--------|--------|
113
+ | `raiton` ou `raiton/core` | `source/core/index.ts` |
114
+ | `raiton/core/*` | `source/core/*.ts` |
115
+ | `raiton/framework` | `source/framework/index.ts` |
116
+ | `raiton/framework/*` | `source/framework/*.ts` |
117
+ | `raiton/types` | `source/types/index.ts` |
118
+ | `raiton/types/*` | `source/types/*.ts` |
119
+ | `raiton/commands/*` | `source/commands/*.ts` |
120
+
121
+ ## Conventions de commits
122
+
123
+ | Préfixe | Domaine |
124
+ |---------|---------|
125
+ | `core:` | Noyau (Application, Router, DI, etc.) |
126
+ | `framework:` | Décorateurs, runtime, plugins |
127
+ | `cli:` | Ligne de commande |
128
+ | `docs:` | Documentation |
129
+ | `types:` | Définitions de types |
130
+ | `fix:` | Correction de bug |
131
+ | `chore:` | Maintenance |
@@ -0,0 +1,81 @@
1
+ # CLI (Interface en Ligne de Commande)
2
+
3
+ **Fichiers :** `source/bin/`, `source/commands/`
4
+ **Import CLI :** `bun raiton <commande>`
5
+
6
+ > **Navigation :** [← docs/](../README.md) | [↑ Index](../README.md) | [commands.md →](commands.md)
7
+
8
+ ## Table des matières
9
+
10
+ | Fichier | Description |
11
+ |---------|-------------|
12
+ | [commands.md](commands.md) | Détail des commandes `develop`, `build`, `start`, `artifact`, `grafts` |
13
+ | [hmr.md](hmr.md) | Fonctionnement du Hot Module Replacement |
14
+
15
+ ## Commandes disponibles
16
+
17
+ | Commande | Alias | Description |
18
+ |----------|-------|-------------|
19
+ | `develop` | `dev` | Mode développement avec Hot Reload |
20
+ | `build` | `b` | Compilation TypeScript vers JavaScript |
21
+ | `start` | `run` | Démarrage en production |
22
+ | `artifact` | `art` | Gestion des artifacts |
23
+ | `grafts` | - | Génération de typings |
24
+
25
+ ```bash
26
+ # Aide
27
+ bun raiton --help
28
+
29
+ # Version
30
+ bun raiton --version
31
+ ```
32
+
33
+ ## Structure des fichiers CLI
34
+
35
+ ```
36
+ bin/
37
+ ├── index.ts ← Point d'entrée (shebang)
38
+ ├── cli.ts ← Définition Commander
39
+ ├── bootstrapper.ts ← Initialisation
40
+ ├── cli-tools.ts ← Utilitaires cross-runtime
41
+ └── constants.ts ← Détection de runtime
42
+
43
+ commands/
44
+ ├── start.command.ts ← start/run
45
+ ├── develop.command.ts ← develop/dev
46
+ ├── build.command.ts ← build/b
47
+ ├── artifact.command.ts ← artifact/art
48
+ └── grafts.command.ts ← grafts
49
+ ```
50
+
51
+ ## Flux de démarrage
52
+
53
+ ```typescript
54
+ // source/bin/index.ts
55
+ import "reflect-metadata"
56
+ import CLI from "./cli"
57
+ import { bootstrapper } from "./bootstrapper"
58
+
59
+ bootstrapper(CLI)
60
+ ```
61
+
62
+ ```typescript
63
+ // source/bin/bootstrapper.ts
64
+ bootstrapper(CLI) {
65
+ 1. Récupère le répertoire de travail (workdir + appdir)
66
+ 2. RaitonCommands.harvest() → scanne les commandes du projet
67
+ 3. RaitonConfig.sync(workdir) → charge la configuration
68
+ 4. CLI.parse(process.argv) → exécute la commande
69
+ }
70
+ ```
71
+
72
+ ## Documentation détaillée
73
+
74
+ | Fichier | Description |
75
+ |---------|-------------|
76
+ | `commands.md` | Détail de chaque commande avec exemples |
77
+ | `hmr.md` | Fonctionnement du Hot Module Replacement |
78
+
79
+ ---
80
+
81
+ [← docs/](../README.md) | [↑ Index](../README.md) | [commands.md →](commands.md)
@@ -0,0 +1,167 @@
1
+ # Commandes CLI
2
+
3
+ **Fichiers :** `source/commands/`
4
+ **Commandes intégrées :** 5 commandes
5
+
6
+ > **Navigation :** [← cli/](README.md) | [↑ cli/](README.md) | [hmr.md →](hmr.md)
7
+
8
+ ## `develop` / `dev`
9
+
10
+ Mode développement avec Hot Module Replacement.
11
+
12
+ ```bash
13
+ bun raiton develop
14
+ bun raiton dev # alias
15
+ ```
16
+
17
+ **Flux d'exécution :**
18
+
19
+ ```typescript
20
+ // Ce qu'il se passe :
21
+ const builder = new RaitonBuilder(process.cwd(), {
22
+ serve: true, // Démarre le serveur HTTP
23
+ hmr: true, // Active le hot reload
24
+ })
25
+
26
+ await builder.prepare()
27
+ // → Résout les chemins (source, out, bootstrapper)
28
+ // → Active le watcher HMR
29
+
30
+ await builder.boot()
31
+ // → Importe le bootstrapper (main.ts)
32
+ // → Crée RaitonThread
33
+ // → thread.setup({application})
34
+ // → thread.run()
35
+ // → ControllerBuilder.scan()
36
+ // → HTTP Server listen()
37
+ // → Watcher HMR actif
38
+ ```
39
+
40
+ **Caractéristiques :**
41
+ - Watcher sur le dossier source (récursif)
42
+ - Recompilation à chaud des contrôleurs modifiés
43
+ - Rechargement des artifacts
44
+ - Logs de requêtes en temps réel
45
+
46
+ ```bash
47
+ # Exemple de sortie
48
+ [HMR] activated
49
+ [INFO] Local access: http://localhost:3000/
50
+ [INFO] LAN access: http://192.168.1.42:3000/
51
+ ```
52
+
53
+ ## `build` / `b`
54
+
55
+ Compile l'application TypeScript.
56
+
57
+ ```bash
58
+ bun raiton build
59
+ bun raiton b # alias
60
+ bun raiton build --develop # Mode dev avec debug
61
+ bun raiton build --bootstrap # Inclut le fichier bootstrap
62
+ ```
63
+
64
+ **Flux d'exécution :**
65
+
66
+ ```typescript
67
+ const builder = new RaitonBuilder(process.cwd(), {
68
+ serve: false,
69
+ hmr: false,
70
+ })
71
+
72
+ await builder.boot()
73
+ // → Importe le bootstrapper
74
+ // → Initialise les contrôleurs
75
+ // → builder.build(thread)
76
+ // → execSync(`npx tsc -p tsconfig.json --outDir ${out} --noEmit`)
77
+ ```
78
+
79
+ **Résultat :**
80
+ - Compilation dans `.raiton/server/` (configurable)
81
+ - Utilise `tsconfig.json` du projet
82
+ - Génère les fichiers `.js` et `.d.ts`
83
+
84
+ ## `start` / `run`
85
+
86
+ Démarre l'application en production.
87
+
88
+ ```bash
89
+ bun raiton start
90
+ bun raiton run # alias
91
+ bun raiton start --develop # Mode debug
92
+ ```
93
+
94
+ **Flux d'exécution :**
95
+
96
+ ```bash
97
+ # Équivalent à :
98
+ bun run build/bin/index.mjs
99
+ ```
100
+
101
+ **Caractéristiques :**
102
+ - Pas de HMR
103
+ - Performance optimale
104
+ - Utilise le build précédemment généré
105
+
106
+ ## `artifact` / `art`
107
+
108
+ Gestion des artifacts.
109
+
110
+ ```bash
111
+ bun raiton artifact --dump # Affiche les artifacts
112
+ bun raiton artifact --create # Crée un artifact
113
+ bun raiton artifact --remove # Supprime un artifact
114
+ bun raiton artifact --clear # Vide tous les artifacts
115
+ ```
116
+
117
+ **Note :** Cette commande est actuellement en développement (stub).
118
+
119
+ ## `grafts`
120
+
121
+ Génération de typings.
122
+
123
+ ```bash
124
+ bun raiton grafts
125
+ ```
126
+
127
+ **Note :** Cette commande est actuellement en développement (stub).
128
+
129
+ ## Commandes personnalisées du projet
130
+
131
+ Vous pouvez ajouter vos propres commandes en créant des fichiers `*.command.*` dans le dossier `commands/` de votre projet :
132
+
133
+ ```bash
134
+ # Exemple : commands/seed.command.ts
135
+ export default {
136
+ name: "seed",
137
+ description: "Peuple la base de données",
138
+ run: async () => {
139
+ console.log("Seeding...")
140
+ },
141
+ }
142
+ ```
143
+
144
+ Ces commandes sont automatiquement détectées par `RaitonCommands.harvest()`.
145
+
146
+ ## Scripts npm
147
+
148
+ ```json
149
+ {
150
+ "scripts": {
151
+ "dev": "bun run --hot source/bin/index.ts",
152
+ "start": "bun run build/bin/index.mjs",
153
+ "build": "bun build source/bin/index.ts --target=node --format=esm --outfile=build/bin/index.mjs"
154
+ }
155
+ }
156
+ ```
157
+
158
+ ```bash
159
+ # Équivalents via npm scripts
160
+ npm run dev # → bun raiton dev
161
+ npm run build # → build via bun bundle
162
+ npm run start # → bun raiton start
163
+ ```
164
+
165
+ ---
166
+
167
+ [← cli/](README.md) | [↑ cli/](README.md) | [hmr.md →](hmr.md)
@@ -0,0 +1,121 @@
1
+ # Hot Module Replacement (HMR)
2
+
3
+ **Fichier :** `source/core/builder.ts`
4
+ **Mécanisme :** Watcher `fs.watch()` + signaux + rechargement dynamique
5
+
6
+ > **Navigation :** [← commands.md](commands.md) | [↑ cli/](README.md)
7
+
8
+ Le HMR permet de modifier le code source sans redémarrer le serveur. Activé uniquement en mode `develop`.
9
+
10
+ ## Fonctionnement
11
+
12
+ ```
13
+ Modification d'un fichier .ts
14
+ │
15
+ v
16
+ Watcher (fs.watch, recursive)
17
+ │
18
+ v
19
+ builder.parse(filename)
20
+ │
21
+ ├── isControllerArtifact(filename)
22
+ │ → dispatch 'hmr:controller'
23
+ │ → ControllerBuilder.build({filename, version, timestamp})
24
+ │ → Réimporte et recompile le contrôleur
25
+ │ → Remplace la route dans le router
26
+ │
27
+ └── Artifacts.is(filename)
28
+ → Artifacts.reload(module, filename)
29
+ → Met à jour le registre des artifacts
30
+ ```
31
+
32
+ ## Watcher
33
+
34
+ ```typescript
35
+ // source/core/builder.ts
36
+ protected watching(): this {
37
+ this._watcher = watch(this._source, { recursive: true }, (event, relativePath) => {
38
+ if (this._source && relativePath) {
39
+ this.parse(path.join(this._source, relativePath))
40
+ }
41
+ })
42
+ return this
43
+ }
44
+ ```
45
+
46
+ Le watcher utilise `fs.watch()` de Node.js avec l'option `recursive: true`.
47
+
48
+ ## Signal HMR
49
+
50
+ ```typescript
51
+ // Réception du signal (dans builder.prepare())
52
+ if (this.options.hmr && this.options.serve) {
53
+ Raiton.signals.listen('hmr:controller', async ({filename, version, timestamp}) => {
54
+ await ControllerBuilder.build({filename, version, timestamp})
55
+ })
56
+ }
57
+ ```
58
+
59
+ Le signal `hmr:controller` est dispatché via `Raiton.signals` (EventBus de `@protorians/events-bus`).
60
+
61
+ ## Rechargement avec cache busting
62
+
63
+ Pour éviter le cache des modules ES, un paramètre de version et timestamp est ajouté à l'URL d'import :
64
+
65
+ ```typescript
66
+ protected async parse(filename: string) {
67
+ const payload = {
68
+ filename,
69
+ timestamp: Date.now(),
70
+ version: this._compiledVersionNumber++,
71
+ type,
72
+ }
73
+
74
+ if (isControllerArtifact(filename)) {
75
+ Raiton.signals.dispatch('hmr:controller', payload)
76
+ }
77
+
78
+ if (Artifacts.is(filename))
79
+ Artifacts.reload(
80
+ await import(`${filename}?v=${payload.version}&t=${payload.timestamp}`),
81
+ filename
82
+ )
83
+ }
84
+ ```
85
+
86
+ **Versionning :** `this._compiledVersionNumber` est incrémenté à chaque modification.
87
+
88
+ ## Ce qui est rechargé à chaud
89
+
90
+ | Type de fichier | Comportement |
91
+ |----------------|-------------|
92
+ | `*.controller.ts` | Recompilation du contrôleur, remplacement de ses routes |
93
+ | Artifacts connus (service, socket) | Rechargement du module dans le registre |
94
+ | Autres fichiers | Ignorés (ne déclenchent pas de rechargement) |
95
+
96
+ ## Exemple
97
+
98
+ ```bash
99
+ # Terminal 1 : démarrage en mode dev
100
+ $ bun raiton dev
101
+ [HMR] activated
102
+ [INFO] Local access: http://localhost:3000/
103
+
104
+ # Terminal 2 : modification d'un fichier
105
+ $ echo " @Get('/new') newRoute() { return 'ajouté à chaud' }" >> source/controllers/user.controller.ts
106
+
107
+ # Terminal 1 (automatique) :
108
+ [HMR] activated
109
+ # La nouvelle route est disponible sans redémarrage
110
+ ```
111
+
112
+ ## Limitations
113
+
114
+ - Le HMR ne recharge que les **contrôleurs** et les **artifacts enregistrés**
115
+ - Les modifications de **configuration** (`raiton.config.json`) nécessitent un redémarrage
116
+ - Les modifications de **middlewares globaux** (`app.use()`) nécessitent un redémarrage
117
+ - Le HMR dépend de `fs.watch` — peut ne pas fonctionner sur certains systèmes de fichiers distants (NFS, Docker volumes sur macOS)
118
+
119
+ ---
120
+
121
+ [← commands.md](commands.md) | [↑ cli/](README.md)