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.
- package/CHANGELOG.md +31 -0
- package/README.md +16 -9
- package/build/bin/index.mjs +10288 -6059
- package/deno.json +4 -1
- package/docs/contributors/framework/README.md +2 -0
- package/docs/contributors/framework/cache/README.md +55 -0
- package/docs/contributors/framework/cache/cache.md +86 -0
- package/docs/contributors/framework/cache/etag.md +82 -0
- package/docs/contributors/framework/decorators/README.md +1 -0
- package/docs/contributors/framework/plugins/csrf.md +277 -0
- package/docs/contributors/framework/plugins/security.md +40 -6
- package/docs/contributors/framework/runtime.md +13 -3
- package/docs/user-guide/README.md +8 -4
- package/docs/user-guide/best-practices.md +1 -0
- package/docs/user-guide/cache.md +79 -0
- package/docs/user-guide/cli.md +35 -3
- package/docs/user-guide/csrf.md +557 -0
- package/docs/user-guide/decorators/README.md +3 -0
- package/docs/user-guide/decorators/cache.md +79 -0
- package/docs/user-guide/decorators/health-check.md +125 -0
- package/docs/user-guide/health-check.md +117 -0
- package/docs/user-guide/runtime.md +2 -1
- package/docs/user-guide/security.md +8 -2
- package/package.json +8 -3
- package/source/bin/bootstrapper.ts +4 -4
- package/source/bin/cli-tools.ts +27 -3
- package/source/bin/cli.ts +2 -2
- package/source/bin/commands.registry.ts +17 -0
- package/source/bin/constants.ts +1 -0
- package/source/bin/index.ts +2 -2
- package/source/commands/artifact.command.ts +2 -2
- package/source/commands/build.command.ts +2 -2
- package/source/commands/develop.command.ts +4 -5
- package/source/commands/grafts.command.ts +1 -1
- package/source/commands/start.command.ts +2 -2
- package/source/core/application.ts +10 -10
- package/source/core/artifacts/artifact.ts +1 -1
- package/source/core/artifacts/index.ts +1 -1
- package/source/core/builder.ts +69 -15
- package/source/core/bytes.util.ts +1 -1
- package/source/core/commands.ts +24 -14
- package/source/core/config/config.ts +2 -2
- package/source/core/config/define.ts +2 -2
- package/source/core/config/index.ts +2 -2
- package/source/core/context.ts +1 -1
- package/source/core/controller/builder.ts +31 -8
- package/source/core/controller/compiler.ts +6 -6
- package/source/core/controller/index.ts +4 -4
- package/source/core/controller/metadata.ts +2 -2
- package/source/core/controller/tracker.ts +1 -1
- package/source/core/directories.ts +3 -2
- package/source/core/guards.ts +1 -1
- package/source/core/helpers/index.ts +1 -1
- package/source/core/hooks.ts +1 -1
- package/source/core/index.ts +16 -16
- package/source/core/injection/index.ts +1 -1
- package/source/core/injection/injection.ts +3 -3
- package/source/core/mcp/builder.ts +8 -8
- package/source/core/mcp/index.ts +3 -3
- package/source/core/mcp/metadata.ts +2 -2
- package/source/core/mcp/tracker.ts +1 -1
- package/source/core/middleware/compose.ts +2 -2
- package/source/core/middleware/index.ts +2 -2
- package/source/core/middleware/pipeline.ts +2 -2
- package/source/core/plugins/index.ts +2 -2
- package/source/core/plugins/plugin.ts +1 -1
- package/source/core/plugins/scope.ts +4 -4
- package/source/core/raiton.ts +1 -1
- package/source/core/router/handler.ts +30 -6
- package/source/core/router/handler.utils.ts +3 -3
- package/source/core/router/index.ts +4 -4
- package/source/core/router/matcher.ts +1 -1
- package/source/core/router/route.ts +1 -1
- package/source/core/router/router.ts +4 -4
- package/source/core/server.ts +1 -1
- package/source/core/socket/builder.ts +2 -2
- package/source/core/socket/index.ts +2 -2
- package/source/core/socket/metadata.ts +2 -2
- package/source/core/thread.ts +53 -20
- package/source/framework/artifacts.ts +8 -5
- package/source/framework/cache/cache.decorator.ts +35 -0
- package/source/framework/cache/cache.ts +197 -0
- package/source/framework/cache/etag.ts +174 -0
- package/source/framework/cache/index.ts +4 -0
- package/source/framework/cache/types.ts +111 -0
- package/source/framework/constants/decorators.constant.ts +4 -0
- package/source/framework/constants/index.ts +2 -2
- package/source/framework/decorators/access-guard.decorator.ts +2 -2
- package/source/framework/decorators/api-response.decorator.ts +1 -1
- package/source/framework/decorators/api.decorator.ts +1 -1
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +60 -0
- package/source/framework/decorators/csrf-token.decorator.ts +20 -0
- package/source/framework/decorators/guard.decorator.ts +4 -4
- package/source/framework/decorators/health-check.decorator.ts +50 -0
- package/source/framework/decorators/index.ts +14 -11
- package/source/framework/decorators/injection.decorator.ts +3 -3
- package/source/framework/decorators/mcp.decorator.ts +4 -4
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -2
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +4 -4
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +2 -2
- package/source/framework/enums/csrf.enum.ts +4 -0
- package/source/framework/enums/index.ts +8 -7
- package/source/framework/enums/runtime.enum.ts +1 -2
- package/source/framework/env.ts +2 -2
- package/source/framework/exceptions/http-exception.ts +3 -3
- package/source/framework/exceptions/index.ts +2 -2
- package/source/framework/health-check.ts +137 -0
- package/source/framework/index.ts +18 -16
- package/source/framework/mcp/handler.ts +3 -3
- package/source/framework/mcp/index.ts +3 -3
- package/source/framework/mcp/protocol.ts +1 -1
- package/source/framework/mcp/streamable-http.ts +3 -3
- package/source/framework/parameter-bag.ts +2 -2
- package/source/framework/plugins/body-parser.plugin.ts +3 -3
- package/source/framework/plugins/index.ts +4 -4
- package/source/framework/plugins/mcp.plugin.ts +5 -5
- package/source/framework/plugins/openapi.plugin.ts +4 -4
- package/source/framework/plugins/security/body-limit.ts +3 -3
- package/source/framework/plugins/security/cors.ts +2 -2
- package/source/framework/plugins/security/csrf.ts +145 -0
- package/source/framework/plugins/security/headers.ts +2 -2
- package/source/framework/plugins/security/index.ts +7 -5
- package/source/framework/plugins/security/method-guard.ts +3 -3
- package/source/framework/plugins/security/rate-limit.ts +3 -3
- package/source/framework/repositories.ts +1 -1
- package/source/framework/responses/error.ts +2 -2
- package/source/framework/responses/helpers.ts +3 -3
- package/source/framework/responses/http-throwable.ts +3 -3
- package/source/framework/responses/http.ts +3 -3
- package/source/framework/responses/index.ts +4 -4
- package/source/framework/runtime/bun/server.ts +5 -5
- package/source/framework/runtime/deno/server.ts +156 -96
- package/source/framework/runtime/index.ts +11 -17
- package/source/framework/runtime/node/reply.ts +1 -1
- package/source/framework/runtime/node/request.ts +2 -2
- package/source/framework/runtime/node/server.ts +3 -3
- package/source/framework/runtime/web/server.ts +2 -2
- package/source/framework/services.ts +1 -1
- package/source/framework/utilities/artifact.util.ts +4 -0
- package/source/framework/utilities/csrf.util.ts +162 -0
- package/source/framework/utilities/index.ts +10 -9
- package/source/framework/utilities/openapi.utils.ts +7 -7
- package/source/framework/utilities/utilities.util.ts +1 -1
- package/source/types/application.ts +2 -2
- package/source/types/builder.ts +1 -1
- package/source/types/config.ts +1 -1
- package/source/types/controller.ts +3 -3
- package/source/types/core.ts +1 -1
- package/source/types/csrf.ts +38 -0
- package/source/types/guard.ts +1 -1
- package/source/types/http-responses.ts +1 -1
- package/source/types/index.ts +26 -25
- package/source/types/injection.ts +1 -1
- package/source/types/middleware.ts +1 -1
- package/source/types/plugin.ts +1 -1
- package/source/types/raiton.ts +1 -1
- package/source/types/responses.ts +2 -2
- package/source/types/router.ts +2 -2
- package/source/types/runtime.ts +3 -5
- package/source/types/thread.ts +4 -4
- /package/source/framework/utilities/{https.ts → https.util.ts} +0 -0
- /package/source/framework/utilities/{url.ts → url.util.ts} +0 -0
|
@@ -19,6 +19,8 @@ Ce dossier décrit comment utiliser Raiton pour créer un serveur d'API.
|
|
|
19
19
|
| [responses.md](responses.md) | Structurer les réponses et les erreurs |
|
|
20
20
|
| [body-parser.md](body-parser.md) | Lire JSON, formulaires et fichiers |
|
|
21
21
|
| [security.md](security.md) | Sécurité HTTP, CORS, rate-limit, body-limit |
|
|
22
|
+
| [cache.md](cache.md) | ETag (validation) et cache de routes (`@Cache`) |
|
|
23
|
+
| [health-check.md](health-check.md) | Endpoint de contrôle et vérifications de santé |
|
|
22
24
|
| [https.md](https.md) | HTTPS, certificats et environnements |
|
|
23
25
|
| [openapi/README.md](openapi/README.md) | Générer et documenter l'API |
|
|
24
26
|
| [sockets.md](sockets.md) | Déclarer et gérer les sockets |
|
|
@@ -48,10 +50,11 @@ Ce dossier décrit comment utiliser Raiton pour créer un serveur d'API.
|
|
|
48
50
|
15. lire [openapi/README.md](openapi/README.md)
|
|
49
51
|
16. lire [sockets.md](sockets.md)
|
|
50
52
|
17. lire [mcp.md](mcp.md)
|
|
51
|
-
18. lire [
|
|
52
|
-
19. lire [
|
|
53
|
-
20. lire [
|
|
54
|
-
21. lire [
|
|
53
|
+
18. lire [health-check.md](health-check.md)
|
|
54
|
+
19. lire [types.md](types.md)
|
|
55
|
+
20. lire [tutorial.md](tutorial.md)
|
|
56
|
+
21. lire [plugins.md](plugins.md)
|
|
57
|
+
22. lire [cli.md](cli.md)
|
|
55
58
|
|
|
56
59
|
## Ce que couvre ce guide
|
|
57
60
|
|
|
@@ -62,6 +65,7 @@ Ce dossier décrit comment utiliser Raiton pour créer un serveur d'API.
|
|
|
62
65
|
- l'injection de services
|
|
63
66
|
- les plugins de sécurité et de documentation
|
|
64
67
|
- le protocole HTTPS et la gestion des certificats
|
|
68
|
+
- les endpoints et vérifications de santé (health-check)
|
|
65
69
|
- le cycle local `dev` / `build` / `start`
|
|
66
70
|
|
|
67
71
|
> **Navigation :** [← docs/](../README.md) | [← contributeurs](../contributors/README.md)
|
|
@@ -12,6 +12,7 @@ Dans un projet Raiton, gardez ces règles simples :
|
|
|
12
12
|
- activez les plugins de sécurité dès que l’API est exposée publiquement
|
|
13
13
|
- centralisez les conventions par domaine
|
|
14
14
|
- utilisez une structure modulaire quand plusieurs fonctionnalités métier cohabitent
|
|
15
|
+
- importez les interfaces et types avec `import type` (ou `import {type X}` en inline pour un mélange) quand ils ne servent qu’à la compilation : avec Bun et `emitDecoratorMetadata`, un import de valeur d’un symbole type-only lève `SyntaxError: Export named '…' not found` au démarrage — laissez les entités/classes runtime en import de valeur
|
|
15
16
|
|
|
16
17
|
## Exemple de découpage
|
|
17
18
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Cache & ETag
|
|
2
|
+
|
|
3
|
+
> **Navigation :** [← security](security.md) | [health-check →](health-check.md)
|
|
4
|
+
|
|
5
|
+
Raiton fournit deux mécanismes de performance HTTP complémentaires :
|
|
6
|
+
|
|
7
|
+
- **ETag** (validation) : le client valide sa copie et reçoit `304 Not Modified`.
|
|
8
|
+
- **Cache de routes** (expiration) : le handler n'est pas ré-exécuté tant que
|
|
9
|
+
la réponse est fraîche.
|
|
10
|
+
|
|
11
|
+
## ETag — validation avec `etag()`
|
|
12
|
+
|
|
13
|
+
Branchez le middleware `etag()` sur votre application. Il calcule un ETag de
|
|
14
|
+
chaque réponse, pose l'en-tête `ETag` et répond `304` si le client le possède
|
|
15
|
+
déjà (`If-None-Match`).
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Application } from "raiton/core"
|
|
19
|
+
import { etag } from "raiton/framework"
|
|
20
|
+
|
|
21
|
+
const app = new Application({ port: 3000 })
|
|
22
|
+
|
|
23
|
+
app.use(etag({
|
|
24
|
+
weak: false,
|
|
25
|
+
cacheControl: { maxAge: 60, public: true },
|
|
26
|
+
}))
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Personnaliser
|
|
30
|
+
|
|
31
|
+
`etag()` accepte un algorithme de hachage, le marqueur faible, le nom d'en-tête
|
|
32
|
+
et un prédicat d'exclusion :
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
app.use(etag({
|
|
36
|
+
weak: true,
|
|
37
|
+
algorithm: async (body) =>
|
|
38
|
+
crypto.createHash("sha1").update(body).digest("hex"),
|
|
39
|
+
skip: (ctx) => ctx.req.method !== "GET",
|
|
40
|
+
}))
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Cache de routes — `@Cache()`
|
|
44
|
+
|
|
45
|
+
Mettez en cache la réponse d'une route pendant un `ttl` sans ré-exécuter le
|
|
46
|
+
handler :
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Controllable, Get, Cache } from "raiton/framework"
|
|
50
|
+
|
|
51
|
+
@Controllable("/products")
|
|
52
|
+
export class ProductController {
|
|
53
|
+
@Get("/featured")
|
|
54
|
+
@Cache({ ttl: 60_000, vary: ["accept-language"] })
|
|
55
|
+
featured() {
|
|
56
|
+
return this.catalogue.featured()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Configurez globalement les défauts et le store :
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { CacheManager } from "raiton/framework"
|
|
65
|
+
|
|
66
|
+
CacheManager.configure({ ttl: 30_000, maxEntries: 5000 })
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Les deux ensemble
|
|
70
|
+
|
|
71
|
+
Un `@Cache()` global (ou par route) réduit le travail du handler, et un `etag()`
|
|
72
|
+
en amont permet au client de valider sa copie — y compris les réponses servies
|
|
73
|
+
depuis le cache.
|
|
74
|
+
|
|
75
|
+
> Pour le détail de toutes les options : voir le [décorateur `@Cache`](decorators/cache.md).
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
[← security](security.md) | [health-check →](health-check.md)
|
package/docs/user-guide/cli.md
CHANGED
|
@@ -10,17 +10,30 @@ Le CLI couvre le cycle standard de développement d’une application Raiton.
|
|
|
10
10
|
- vérifier le comportement pendant l’implémentation
|
|
11
11
|
- produire une version compilée pour la livraison ou le déploiement
|
|
12
12
|
|
|
13
|
+
Raiton fonctionne sur les trois runtimes majeurs : **Bun**, **Node.js** et **Deno**.
|
|
14
|
+
|
|
13
15
|
```bash
|
|
16
|
+
# Bun — exécution TypeScript native (aucune compilation requise)
|
|
14
17
|
bun raiton dev
|
|
15
18
|
bun raiton build
|
|
16
19
|
bun raiton start
|
|
20
|
+
|
|
21
|
+
# Node.js — le CLI est fourni sous forme de bundle JS (build/bin/index.mjs)
|
|
22
|
+
node build/bin/index.mjs dev
|
|
23
|
+
node build/bin/index.mjs start
|
|
24
|
+
|
|
25
|
+
# Deno — exécution TypeScript native, tâches déclarées dans deno.json
|
|
26
|
+
deno task dev
|
|
27
|
+
deno task build
|
|
28
|
+
deno task start
|
|
29
|
+
deno task compile # génère un binaire autonome (build/bin/raiton)
|
|
17
30
|
```
|
|
18
31
|
|
|
19
32
|
## Commandes principales
|
|
20
33
|
|
|
21
|
-
- `dev` lance le projet avec hot reloading
|
|
34
|
+
- `dev` lance le projet avec hot reloading (HMR)
|
|
22
35
|
- `build` génère un artefact exécutable
|
|
23
|
-
- `start` démarre l’application compilée
|
|
36
|
+
- `start` démarre l’application compilée (sans HMR)
|
|
24
37
|
|
|
25
38
|
## Commandes utiles
|
|
26
39
|
|
|
@@ -35,6 +48,25 @@ Quand vous faites évoluer l’application, gardez l’ordre suivant :
|
|
|
35
48
|
- vérifier le comportement
|
|
36
49
|
- lancer `bun raiton build` avant livraison
|
|
37
50
|
|
|
51
|
+
## Mode dev vs mode prod
|
|
52
|
+
|
|
53
|
+
Le mode dev utilise le système de HMR embarqué : le builder observe le
|
|
54
|
+
répertoire source et recompile les artefacts (contrôleurs, services,
|
|
55
|
+
middlewares, sockets, hooks, MCP) sans redémarrer le processus.
|
|
56
|
+
|
|
57
|
+
Le mode `start` démarre l’application sans HMR :
|
|
58
|
+
- sur **Bun** et **Deno**, le bootstrapper TypeScript est importé directement
|
|
59
|
+
- sur **Node.js**, l’application est compilée (esbuild) vers `.raiton/server/main.mjs`
|
|
60
|
+
puis exécutée
|
|
61
|
+
|
|
62
|
+
## Runtimes
|
|
63
|
+
|
|
64
|
+
| Runtime | Exécution TS native | Dev (HMR) | Prod (bundle) |
|
|
65
|
+
| --- | --- | --- | --- |
|
|
66
|
+
| Bun | Oui | `bun raiton dev` | `bun raiton start` |
|
|
67
|
+
| Node.js | Non (bundle JS requis) | `node build/bin/index.mjs dev` | `node build/bin/index.mjs start` |
|
|
68
|
+
| Deno | Oui | `deno task dev` | `deno task start` / `deno task compile` |
|
|
69
|
+
|
|
38
70
|
## Avantages
|
|
39
71
|
|
|
40
72
|
- flux simple et prévisible
|
|
@@ -48,4 +80,4 @@ Quand vous faites évoluer l’application, gardez l’ordre suivant :
|
|
|
48
80
|
|
|
49
81
|
---
|
|
50
82
|
|
|
51
|
-
[← plugins](plugins.md) | [best-practices →](best-practices.md)
|
|
83
|
+
[← plugins](plugins.md) | [best-practices →](best-practices.md)
|