raiton 5.9.4-beta.15 → 5.9.7-beta.18
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.
- package/build/bin/index.mjs +3 -1
- package/docs/README.md +136 -0
- package/docs/cli/README.md +81 -0
- package/docs/cli/commands.md +167 -0
- package/docs/cli/hmr.md +121 -0
- package/docs/core/README.md +67 -0
- package/docs/core/application.md +149 -0
- package/docs/core/builder-thread.md +231 -0
- package/docs/core/config.md +124 -0
- package/docs/core/controller.md +120 -0
- package/docs/core/injection.md +226 -0
- package/docs/core/middleware.md +172 -0
- package/docs/core/plugin-scope.md +171 -0
- package/docs/core/router.md +122 -0
- package/docs/framework/README.md +96 -0
- package/docs/framework/base-classes.md +214 -0
- package/docs/framework/decorators/README.md +60 -0
- package/docs/framework/decorators/controllable.md +151 -0
- package/docs/framework/decorators/injection.md +186 -0
- package/docs/framework/decorators/middleware.md +167 -0
- package/docs/framework/decorators/openapi.md +254 -0
- package/docs/framework/decorators/parametrable.md +248 -0
- package/docs/framework/decorators/socket.md +152 -0
- package/docs/framework/encryption.md +183 -0
- package/docs/framework/env.md +88 -0
- package/docs/framework/plugins/README.md +50 -0
- package/docs/framework/plugins/body-parser.md +138 -0
- package/docs/framework/plugins/openapi.md +217 -0
- package/docs/framework/plugins/security.md +159 -0
- package/docs/framework/responses.md +180 -0
- package/docs/framework/runtime.md +138 -0
- package/docs/types/README.md +206 -0
- package/package.json +1 -1
- package/source/core/application.ts +2 -0
- package/source/core/router/handler.ts +2 -0
- package/source/framework/decorators/route-interaction.decorator.ts +1 -1
package/build/bin/index.mjs
CHANGED
|
@@ -4817,7 +4817,7 @@ var {
|
|
|
4817
4817
|
Help
|
|
4818
4818
|
} = import__.default;
|
|
4819
4819
|
// package.json
|
|
4820
|
-
var version = "5.9.
|
|
4820
|
+
var version = "5.9.7-beta.18";
|
|
4821
4821
|
|
|
4822
4822
|
// source/bin/cli.ts
|
|
4823
4823
|
var CLI = new Command;
|
|
@@ -7529,6 +7529,7 @@ class Application {
|
|
|
7529
7529
|
}
|
|
7530
7530
|
context.reply.send(responses2);
|
|
7531
7531
|
} catch (e) {
|
|
7532
|
+
Logger.info(`${req2.method} ${req2.url}`);
|
|
7532
7533
|
Logger.error("Failed to execute handle", e.message ?? e);
|
|
7533
7534
|
if (this.config.develop) {
|
|
7534
7535
|
console.error(e);
|
|
@@ -7541,6 +7542,7 @@ class Application {
|
|
|
7541
7542
|
await this.root.middleware.run(ctx, handler2);
|
|
7542
7543
|
await this.root.hooks.run("onResponse", ctx);
|
|
7543
7544
|
} catch (err) {
|
|
7545
|
+
Logger.info(`${req.method} ${req.url}`);
|
|
7544
7546
|
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
7545
7547
|
Logger.error(`Server error`, err.message ?? err);
|
|
7546
7548
|
ctx.reply.status(err.statusCode ?? 500);
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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
|
|
122
|
+
|
|
123
|
+
### Fonctionnalités
|
|
124
|
+
Il faut toujours prioriser sur l'existant des fonctionnalités existantes avant de créer de nouvelles fonctionnalités.
|
|
125
|
+
|
|
126
|
+
### Commits
|
|
127
|
+
|
|
128
|
+
| Préfixe | Domaine |
|
|
129
|
+
|---------|---------|
|
|
130
|
+
| `core:` | Noyau (Application, Router, DI, etc.) |
|
|
131
|
+
| `framework:` | Décorateurs, runtime, plugins |
|
|
132
|
+
| `cli:` | Ligne de commande |
|
|
133
|
+
| `docs:` | Documentation |
|
|
134
|
+
| `types:` | Définitions de types |
|
|
135
|
+
| `fix:` | Correction de bug |
|
|
136
|
+
| `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)
|
package/docs/cli/hmr.md
ADDED
|
@@ -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)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Module Core (`source/core/`)
|
|
2
|
+
|
|
3
|
+
Le noyau de Raiton gère le cycle de vie de l'application, le routage, le middleware, l'injection de dépendances, les plugins et la configuration.
|
|
4
|
+
|
|
5
|
+
> **Navigation :** [← docs/](../README.md) | [↑ Index](../README.md) | [application.md →](application.md)
|
|
6
|
+
|
|
7
|
+
## Table des matières
|
|
8
|
+
|
|
9
|
+
| Fichier | Description |
|
|
10
|
+
|---------|-------------|
|
|
11
|
+
| [application.md](application.md) | Classe `Application` — configuration, routes, middleware |
|
|
12
|
+
| [router.md](router.md) | Système de routage — `Router`, `RouteMatcher` |
|
|
13
|
+
| [middleware.md](middleware.md) | Pipeline middleware — `MiddlewarePipeline` |
|
|
14
|
+
| [controller.md](controller.md) | Contrôleurs — `ControllerBuilder`, compilation |
|
|
15
|
+
| [injection.md](injection.md) | Injection de dépendances — `Injection`, scopes |
|
|
16
|
+
| [plugin-scope.md](plugin-scope.md) | Système de plugins — `PluginScope` |
|
|
17
|
+
| [config.md](config.md) | Configuration — `RaitonConfig` |
|
|
18
|
+
| [builder-thread.md](builder-thread.md) | Build et thread — `RaitonBuilder`, `RaitonThread` |
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
core/
|
|
22
|
+
├── application.ts → Application — point d'entrée de l'app HTTP
|
|
23
|
+
├── builder.ts → RaitonBuilder — build, serve, HMR
|
|
24
|
+
├── thread.ts → RaitonThread — cycle de vie, serveur
|
|
25
|
+
├── context.ts → RequestContext — état de la requête
|
|
26
|
+
├── raiton.ts → Ration — signaux, thread (statique)
|
|
27
|
+
├── server.ts → Server — config serveur (singleton)
|
|
28
|
+
├── hooks.ts → HookStore — hooks de cycle de vie
|
|
29
|
+
├── guards.ts → RaitonGuards — registre de guards
|
|
30
|
+
├── commands.ts → RaitonCommands — moissonnage de commandes
|
|
31
|
+
├── command.ts → RaitonCommand — classe de base CLI
|
|
32
|
+
├── directories.ts → RaitonDirectories — chemins de travail
|
|
33
|
+
├── bytes.util.ts → parseBytes, formatBytes
|
|
34
|
+
├── process.util.ts → until (attente conditionnelle)
|
|
35
|
+
├── config/
|
|
36
|
+
│ ├── config.ts → RaitonConfig — chargeur de config
|
|
37
|
+
│ └── define.ts → defineConfig — builder depuis package.json
|
|
38
|
+
├── controller/
|
|
39
|
+
│ ├── metadata.ts → getControllerMetadata
|
|
40
|
+
│ ├── compiler.ts → compileController
|
|
41
|
+
│ └── builder.ts → ControllerBuilder
|
|
42
|
+
├── router/
|
|
43
|
+
│ ├── router.ts → Router
|
|
44
|
+
│ ├── route.ts → Route
|
|
45
|
+
│ ├── matcher.ts → RouteMatcher
|
|
46
|
+
│ ├── handler.ts → createHandler
|
|
47
|
+
│ └── handler.utils.ts → collecte d'arguments, validation
|
|
48
|
+
├── middleware/
|
|
49
|
+
│ ├── compose.ts → middlewareCompose (Koa-style)
|
|
50
|
+
│ └── pipeline.ts → MiddlewarePipeline
|
|
51
|
+
├── plugins/
|
|
52
|
+
│ ├── plugin.ts → definePlugin
|
|
53
|
+
│ └── scope.ts → PluginScope
|
|
54
|
+
├── injection/
|
|
55
|
+
│ └── injection.ts → Injection (conteneur DI)
|
|
56
|
+
├── socket/
|
|
57
|
+
│ └── metadata.ts → getSocketMetadata
|
|
58
|
+
├── artifacts/
|
|
59
|
+
│ ├── artifact.ts → Artifact
|
|
60
|
+
│ └── runner.ts → artifactRunner (stub)
|
|
61
|
+
└── helpers/
|
|
62
|
+
└── raiton.ts → helper raiton (stub)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
[← docs/](../README.md) | [↑ Index](../README.md) | [application.md →](application.md)
|