raiton 6.6.0-beta.14 → 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 (155) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +16 -9
  3. package/build/bin/index.mjs +8170 -3997
  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/runtime.md +13 -3
  11. package/docs/user-guide/README.md +1 -0
  12. package/docs/user-guide/cache.md +79 -0
  13. package/docs/user-guide/cli.md +35 -3
  14. package/docs/user-guide/decorators/README.md +1 -0
  15. package/docs/user-guide/decorators/cache.md +79 -0
  16. package/docs/user-guide/runtime.md +2 -1
  17. package/package.json +8 -3
  18. package/source/bin/bootstrapper.ts +4 -4
  19. package/source/bin/cli-tools.ts +27 -3
  20. package/source/bin/cli.ts +2 -2
  21. package/source/bin/commands.registry.ts +17 -0
  22. package/source/bin/constants.ts +1 -0
  23. package/source/bin/index.ts +2 -2
  24. package/source/commands/artifact.command.ts +2 -2
  25. package/source/commands/build.command.ts +2 -2
  26. package/source/commands/develop.command.ts +4 -5
  27. package/source/commands/grafts.command.ts +1 -1
  28. package/source/commands/start.command.ts +2 -2
  29. package/source/core/application.ts +10 -10
  30. package/source/core/artifacts/artifact.ts +1 -1
  31. package/source/core/artifacts/index.ts +1 -1
  32. package/source/core/builder.ts +69 -15
  33. package/source/core/bytes.util.ts +1 -1
  34. package/source/core/commands.ts +24 -14
  35. package/source/core/config/config.ts +2 -2
  36. package/source/core/config/define.ts +2 -2
  37. package/source/core/config/index.ts +2 -2
  38. package/source/core/context.ts +1 -1
  39. package/source/core/controller/builder.ts +9 -9
  40. package/source/core/controller/compiler.ts +6 -6
  41. package/source/core/controller/index.ts +4 -4
  42. package/source/core/controller/metadata.ts +2 -2
  43. package/source/core/controller/tracker.ts +1 -1
  44. package/source/core/directories.ts +3 -2
  45. package/source/core/guards.ts +1 -1
  46. package/source/core/helpers/index.ts +1 -1
  47. package/source/core/hooks.ts +1 -1
  48. package/source/core/index.ts +16 -16
  49. package/source/core/injection/index.ts +1 -1
  50. package/source/core/injection/injection.ts +3 -3
  51. package/source/core/mcp/builder.ts +8 -8
  52. package/source/core/mcp/index.ts +3 -3
  53. package/source/core/mcp/metadata.ts +2 -2
  54. package/source/core/mcp/tracker.ts +1 -1
  55. package/source/core/middleware/compose.ts +2 -2
  56. package/source/core/middleware/index.ts +2 -2
  57. package/source/core/middleware/pipeline.ts +2 -2
  58. package/source/core/plugins/index.ts +2 -2
  59. package/source/core/plugins/plugin.ts +1 -1
  60. package/source/core/plugins/scope.ts +4 -4
  61. package/source/core/raiton.ts +1 -1
  62. package/source/core/router/handler.ts +30 -6
  63. package/source/core/router/handler.utils.ts +3 -3
  64. package/source/core/router/index.ts +4 -4
  65. package/source/core/router/matcher.ts +1 -1
  66. package/source/core/router/route.ts +1 -1
  67. package/source/core/router/router.ts +4 -4
  68. package/source/core/server.ts +1 -1
  69. package/source/core/socket/builder.ts +2 -2
  70. package/source/core/socket/index.ts +2 -2
  71. package/source/core/socket/metadata.ts +2 -2
  72. package/source/core/thread.ts +51 -22
  73. package/source/framework/artifacts.ts +5 -5
  74. package/source/framework/cache/cache.decorator.ts +35 -0
  75. package/source/framework/cache/cache.ts +197 -0
  76. package/source/framework/cache/etag.ts +174 -0
  77. package/source/framework/cache/index.ts +4 -0
  78. package/source/framework/cache/types.ts +111 -0
  79. package/source/framework/constants/decorators.constant.ts +2 -0
  80. package/source/framework/constants/index.ts +2 -2
  81. package/source/framework/decorators/access-guard.decorator.ts +2 -2
  82. package/source/framework/decorators/api-response.decorator.ts +1 -1
  83. package/source/framework/decorators/api.decorator.ts +1 -1
  84. package/source/framework/decorators/controllable.decorator.ts +3 -3
  85. package/source/framework/decorators/csrf-guard.decorator.ts +4 -4
  86. package/source/framework/decorators/csrf-token.decorator.ts +1 -1
  87. package/source/framework/decorators/guard.decorator.ts +4 -4
  88. package/source/framework/decorators/health-check.decorator.ts +3 -3
  89. package/source/framework/decorators/index.ts +14 -14
  90. package/source/framework/decorators/injection.decorator.ts +3 -3
  91. package/source/framework/decorators/mcp.decorator.ts +4 -4
  92. package/source/framework/decorators/middleware.decorator.ts +2 -2
  93. package/source/framework/decorators/parametrable.decorator.ts +2 -2
  94. package/source/framework/decorators/routable.decorator.ts +3 -3
  95. package/source/framework/decorators/route-interaction.decorator.ts +4 -4
  96. package/source/framework/decorators/socket.decorator.ts +3 -3
  97. package/source/framework/encryption.ts +2 -2
  98. package/source/framework/enums/index.ts +8 -8
  99. package/source/framework/enums/runtime.enum.ts +1 -2
  100. package/source/framework/env.ts +2 -2
  101. package/source/framework/exceptions/http-exception.ts +3 -3
  102. package/source/framework/exceptions/index.ts +2 -2
  103. package/source/framework/health-check.ts +4 -4
  104. package/source/framework/index.ts +18 -17
  105. package/source/framework/mcp/handler.ts +3 -3
  106. package/source/framework/mcp/index.ts +3 -3
  107. package/source/framework/mcp/protocol.ts +1 -1
  108. package/source/framework/mcp/streamable-http.ts +3 -3
  109. package/source/framework/parameter-bag.ts +2 -2
  110. package/source/framework/plugins/body-parser.plugin.ts +3 -3
  111. package/source/framework/plugins/index.ts +4 -4
  112. package/source/framework/plugins/mcp.plugin.ts +5 -5
  113. package/source/framework/plugins/openapi.plugin.ts +4 -4
  114. package/source/framework/plugins/security/body-limit.ts +3 -3
  115. package/source/framework/plugins/security/cors.ts +2 -2
  116. package/source/framework/plugins/security/csrf.ts +6 -6
  117. package/source/framework/plugins/security/headers.ts +2 -2
  118. package/source/framework/plugins/security/index.ts +6 -6
  119. package/source/framework/plugins/security/method-guard.ts +3 -3
  120. package/source/framework/plugins/security/rate-limit.ts +3 -3
  121. package/source/framework/repositories.ts +1 -1
  122. package/source/framework/responses/error.ts +2 -2
  123. package/source/framework/responses/helpers.ts +3 -3
  124. package/source/framework/responses/http-throwable.ts +3 -3
  125. package/source/framework/responses/http.ts +3 -3
  126. package/source/framework/responses/index.ts +4 -4
  127. package/source/framework/runtime/bun/server.ts +5 -5
  128. package/source/framework/runtime/deno/server.ts +156 -96
  129. package/source/framework/runtime/index.ts +11 -17
  130. package/source/framework/runtime/node/reply.ts +1 -1
  131. package/source/framework/runtime/node/request.ts +2 -2
  132. package/source/framework/runtime/node/server.ts +3 -3
  133. package/source/framework/runtime/web/server.ts +2 -2
  134. package/source/framework/services.ts +1 -1
  135. package/source/framework/utilities/csrf.util.ts +1 -1
  136. package/source/framework/utilities/index.ts +10 -10
  137. package/source/framework/utilities/openapi.utils.ts +7 -7
  138. package/source/framework/utilities/utilities.util.ts +1 -1
  139. package/source/types/application.ts +2 -2
  140. package/source/types/builder.ts +1 -1
  141. package/source/types/config.ts +1 -1
  142. package/source/types/controller.ts +3 -3
  143. package/source/types/core.ts +1 -1
  144. package/source/types/csrf.ts +1 -1
  145. package/source/types/guard.ts +1 -1
  146. package/source/types/http-responses.ts +1 -1
  147. package/source/types/index.ts +26 -26
  148. package/source/types/injection.ts +1 -1
  149. package/source/types/middleware.ts +1 -1
  150. package/source/types/plugin.ts +1 -1
  151. package/source/types/raiton.ts +1 -1
  152. package/source/types/responses.ts +2 -2
  153. package/source/types/router.ts +2 -2
  154. package/source/types/runtime.ts +3 -5
  155. package/source/types/thread.ts +4 -4
package/deno.json CHANGED
@@ -4,6 +4,9 @@
4
4
  "@/": "./source/"
5
5
  },
6
6
  "tasks": {
7
- "start": "deno run --allow-all source/bin/bootstrapper.ts"
7
+ "dev": "deno run --allow-all --watch source/bin/index.ts dev",
8
+ "build": "deno run --allow-all source/bin/index.ts build",
9
+ "start": "deno run --allow-all source/bin/index.ts start",
10
+ "compile": "deno compile --no-check --allow-all --output build/bin/raiton source/bin/index.ts"
8
11
  }
9
12
  }
@@ -14,6 +14,7 @@ Le dossier `source/framework/` regroupe les briques publiques du framework: déc
14
14
  | [env.md](env.md) | Variables d’environnement |
15
15
  | [base-classes.md](base-classes.md) | DTO, ViewModel, services, repositories, bag de paramètres |
16
16
  | [decorators/](decorators/README.md) | Décorateurs du framework |
17
+ | [cache/](cache/README.md) | ETag et cache de routes |
17
18
  | [plugins/](plugins/README.md) | Body parser, OpenAPI, sécurité |
18
19
 
19
20
  ## Ce que fournit ce module
@@ -38,6 +39,7 @@ framework/
38
39
  ├── parameter-bag.ts
39
40
  ├── artifacts.ts
40
41
  ├── env.ts
42
+ ├── cache/
41
43
  ├── decorators/
42
44
  ├── plugins/
43
45
  ├── runtime/
@@ -0,0 +1,55 @@
1
+ # Module Cache & ETag
2
+
3
+ **Fichiers :** `source/framework/cache/`
4
+ **Import :** `import { Cache, etag, Etagger, CacheManager } from "raiton/framework"`
5
+
6
+ > **Navigation :** [← framework/](../README.md) | [↑ framework/](../README.md) | [etag.md →](etag.md)
7
+
8
+ Le module `cache/` regroupe deux mécanismes complémentaires de performance HTTP :
9
+ les **ETag** (validation) et le **cache de routes** (expiration).
10
+
11
+ ## Table des matières
12
+
13
+ | Fichier | Description |
14
+ |---------|-------------|
15
+ | [etag.md](etag.md) | Gestion complète et personnalisable des ETag |
16
+ | [cache.md](cache.md) | Cache de réponses sur les routes via décorateur |
17
+
18
+ ## Vue d'ensemble des exports
19
+
20
+ ```text
21
+ cache/
22
+ ├── index.ts → Réexporte le module
23
+ ├── types.ts → Options ETag & Cache
24
+ ├── etag.ts → Etagger (manager) + etag() (middleware)
25
+ ├── cache.ts → MemoryCacheStore + CacheManager + createCacheMiddleware
26
+ └── cache.decorator.ts → @Cache (décorateur de route)
27
+ ```
28
+
29
+ ## Les deux stratégies
30
+
31
+ | Mécanisme | Objectif | Déclencheur | Coût du handler |
32
+ |-----------|----------|-------------|-----------------|
33
+ | `etag()` / `Etagger` | Validation (`304 Not Modified`) | En-tête `If-None-Match` | Exécuté |
34
+ | `@Cache()` | Expiration (« fresh », pas d'exécution) | TTL | Évité |
35
+
36
+ Les deux mécanismes s'empilent : un `@Cache()` réduit le travail du handler,
37
+ tandis qu'un `etag()` en amont (global) permet au client de valider sa copie.
38
+
39
+ ## Activation
40
+
41
+ L'ETag et le cache **ne sont pas activés par défaut** — contrairement aux
42
+ en-têtes de sécurité — afin de ne pas modifier le comportement des applications
43
+ existantes. Le développeur les branche explicitement.
44
+
45
+ ```typescript
46
+ import { etag } from "raiton/framework"
47
+
48
+ const app = new Application({ port: 3000 })
49
+
50
+ app.use(etag({ weak: false, cacheControl: { maxAge: 60 } }))
51
+ ```
52
+
53
+ ---
54
+
55
+ [← framework/](../README.md) | [↑ framework/](../README.md) | [etag.md →](etag.md)
@@ -0,0 +1,86 @@
1
+ # Cache de routes — `@Cache()`, `CacheManager`
2
+
3
+ **Fichiers :** `source/framework/cache/cache.ts`, `source/framework/cache/cache.decorator.ts`
4
+ **Import :** `import { Cache, CacheManager, MemoryCacheStore } from "raiton/framework"`
5
+
6
+ > **Navigation :** [← etag.md](etag.md) | [↑ README](README.md) | [framework/](../README.md)
7
+
8
+ Le cache de routes évite complètement d'exécuter le handler tant que la réponse
9
+ est **fraîche** (dans la fenêtre de TTL). C'est une stratégie d'**expiration**,
10
+ à distinguer de la **validation** apportée par les ETag.
11
+
12
+ ## `@Cache(options)` — décorateur de route
13
+
14
+ ```typescript
15
+ import { Controllable, Get, Cache } from "raiton/framework"
16
+
17
+ @Controllable("/products")
18
+ export class ProductController {
19
+ @Get("/featured")
20
+ @Cache({ ttl: 60_000 })
21
+ featured() {
22
+ return this.products.findFeatured()
23
+ }
24
+ }
25
+ ```
26
+
27
+ Le décorateur enregistre un middleware sur la route. Tant que l'entrée est
28
+ fraîche, la réponse est servie depuis le store **sans** appeler le handler.
29
+ À expiration, le handler s'exécute à nouveau et la réponse est stockée.
30
+
31
+ ## `CacheOptions`
32
+
33
+ | Option | Type | défaut | Description |
34
+ |--------|------|--------|-------------|
35
+ | `ttl` | `number` | `60_000` | durée de validité (ms) |
36
+ | `enabled` | `boolean` | `true` | active le cache de la route |
37
+ | `maxEntries` | `number` | `1000` | taille max du store en mémoire |
38
+ | `key` | `(context, route?) => string` | méthode + pathname + params | clé personnalisée |
39
+ | `vary` | `string[]` | `[]` | en-têtes participant à la clé (segmentation) |
40
+ | `methods` | `string[]` | `['GET', 'HEAD']` | méthodes HTTP mises en cache |
41
+
42
+ ### Segmenter par en-tête
43
+
44
+ ```typescript
45
+ @Cache({ ttl: 30_000, vary: ["accept-language"] })
46
+ list() { /* ... */ }
47
+ ```
48
+
49
+ Deux langues différentes produiront deux entrées de cache distinctes.
50
+
51
+ ## `CacheManager` — configuration globale
52
+
53
+ Comme les autres managers du framework, `CacheManager` configure le comportement
54
+ par défaut et le store partagé.
55
+
56
+ ```typescript
57
+ CacheManager.configure({ ttl: 30_000, maxEntries: 5000 })
58
+ CacheManager.setStore(redisStore) // store alternatif, p.ex. Redis
59
+ CacheManager.clear() // vide le cache
60
+ ```
61
+
62
+ ## `MemoryCacheStore` & `CacheStore`
63
+
64
+ Le store par défaut est un `MemoryCacheStore` borné (TTL + taille max). Un store
65
+ alternatif doit implémenter l'interface `CacheStore` :
66
+
67
+ ```typescript
68
+ interface CacheStore {
69
+ get<T>(key: string): CacheEntry<T> | undefined
70
+ set<T>(key: string, entry: CacheEntry<T>, ttl?: number): void
71
+ has(key: string): boolean
72
+ delete(key: string): boolean
73
+ clear(): void
74
+ size(): number
75
+ }
76
+ ```
77
+
78
+ ## Combinaison avec les ETag
79
+
80
+ Le middleware `etag()` (global) s'exécute avant le middleware `@Cache()` (route).
81
+ Sur une réponse servie depuis le cache, l'ETag est calculé sur le corps mis en
82
+ cache : le client peut donc **valider** une réponse déjà **fraîche**.
83
+
84
+ ---
85
+
86
+ [← etag.md](etag.md) | [↑ README](README.md) | [framework/](../README.md)
@@ -0,0 +1,82 @@
1
+ # ETag — `Etagger`, `etag()`
2
+
3
+ **Fichiers :** `source/framework/cache/etag.ts`
4
+ **Import :** `import { Etagger, etag, defaultEtagger } from "raiton/framework"`
5
+
6
+ > **Navigation :** [← README](README.md) | [↑ README](README.md) | [cache.md →](cache.md)
7
+
8
+ Système **complet et personnalisable** de gestion des ETag. Il permet de :
9
+
10
+ - calculer un ETag stable depuis le corps sérialisé de la réponse (hachage FNV-1a par défaut) ;
11
+ - répondre `304 Not Modified` quand le client déclare posséder la représentation (`If-None-Match`) ;
12
+ - choisir un ETag **fort** ou **faible** (`W/"..."`) ;
13
+ - remplacer l'algorithme de hachage par un algorithme **personnalisé** ;
14
+ - piloter l'en-tête `Cache-Control` automatiquement ;
15
+ - exclure certaines requêtes/réponses du calcul.
16
+
17
+ ## `etag(options?)` — middleware prêt à l'emploi
18
+
19
+ ```typescript
20
+ app.use(etag({
21
+ weak: false,
22
+ cacheControl: { maxAge: 60 },
23
+ }))
24
+ ```
25
+
26
+ Le middleware intercepte `context.reply.send`, calcule l'ETag du corps,
27
+ pose l'en-tête `ETag`, applique `Cache-Control` et, si `If-None-Match` matche,
28
+ répond `304` sans corps.
29
+
30
+ ## `ETagOptions`
31
+
32
+ | Option | Type | défaut | Description |
33
+ |--------|------|--------|-------------|
34
+ | `enabled` | `boolean` | `true` | active la génération |
35
+ | `weak` | `boolean` | `false` | ETag faible (`W/"..."`) |
36
+ | `algorithm` | `(body: string) => string \| Promise<string>` | FNV-1a | hasher personnalisé |
37
+ | `cacheControl` | `boolean \| { ... }` | `false` | en-têtes `Cache-Control` automatiques |
38
+ | `headerName` | `string` | `'ETag'` | nom de l'en-tête de réponse |
39
+ | `skip` | `(context, body) => boolean` | – | exclure une requête/réponse |
40
+
41
+ ### `cacheControl`
42
+
43
+ - `true` → `no-cache`
44
+ - `{ public: true, maxAge: 60 }` → `public, max-age=60`
45
+ - `{ noStore: true }` → `private, no-store`
46
+
47
+ ## `Etagger` — utilisation programmatique
48
+
49
+ ```typescript
50
+ const etagger = new Etagger({ weak: true, cacheControl: { maxAge: 300 } })
51
+
52
+ const { tag, body, notModified } = await etagger.evaluate(context, payload)
53
+ if (notModified) {
54
+ context.reply.status(304)
55
+ context.reply.send(null)
56
+ } else {
57
+ context.reply.send(body)
58
+ }
59
+ ```
60
+
61
+ ### API de `Etagger`
62
+
63
+ | Méthode | Description |
64
+ |---------|-------------|
65
+ | `generate(body)` | calcule la valeur d'ETag (`"..."` ou `W/"..."`) |
66
+ | `matches(clientTags, tag)` | teste `If-None-Match` (`*` accepté) |
67
+ | `evaluate(context, body)` | applique en-têtes + décision 304, renvoie `{ tag, body, notModified }` |
68
+ | `static apply(context, body, options?)` | raccourci un seul appel |
69
+
70
+ ## Exemple — hachage personnalisé
71
+
72
+ ```typescript
73
+ app.use(etag({ algorithm: async (body) => {
74
+ const bytes = new TextEncoder().encode(body)
75
+ const digest = await crypto.subtle.digest("SHA-1", bytes)
76
+ return [...new Uint8Array(digest)].map(b => b.toString(16).padStart(2, "0")).join("")
77
+ }}))
78
+ ```
79
+
80
+ ---
81
+
82
+ [← README](README.md) | [↑ README](README.md) | [cache.md →](cache.md)
@@ -28,6 +28,7 @@ Les décorateurs utilisent `reflect-metadata` et `experimentalDecorators: true`
28
28
  | `@Injectable` | Classe | Enregistrement DI | [Voir](injection.md) |
29
29
  | `@Inject` | Constructeur/propriété | Injection de dépendance | [Voir](injection.md) |
30
30
  | `@Middleware` | Classe/méthode | Middleware sur contrôleur/route | [Voir](middleware.md) |
31
+ | `@Cache` | Méthode | Cache de réponse de route | [Voir](../cache/cache.md) |
31
32
  | `@Socket` | Classe | Handler socket | [Voir](socket.md) |
32
33
  | `@OnSocket*` | Méthode | Événement socket | [Voir](socket.md) |
33
34
  | `@ApiTags` | Classe/méthode | Tag OpenAPI | [Voir](openapi.md) |
@@ -14,6 +14,7 @@ class Runtime {
14
14
  constructor(public readonly type: RuntimeType)
15
15
 
16
16
  get isNode(): boolean
17
+ get isDeno(): boolean
17
18
  get isBun(): boolean
18
19
 
19
20
  adapter(): RuntimeAdapterInterface
@@ -25,11 +26,15 @@ class Runtime {
25
26
 
26
27
  ```typescript
27
28
  // Détection automatique (dans RaitonThread.setup) :
28
- const defaultRuntime = typeof Bun !== 'undefined' ? RuntimeType.Bun : RuntimeType.Node
29
+ // Bun si présent, sinon Deno si présent, sinon Node
30
+ const defaultRuntime = isBunUsed
31
+ ? RuntimeType.Bun
32
+ : (isDenoUsed ? RuntimeType.Deno : RuntimeType.Node)
29
33
 
30
34
  // Manuel :
31
35
  const runtime = new Runtime(RuntimeType.Bun)
32
36
  const runtime = new Runtime(RuntimeType.Node)
37
+ const runtime = new Runtime(RuntimeType.Deno)
33
38
  ```
34
39
 
35
40
  ### Création du serveur
@@ -77,11 +82,16 @@ node/
77
82
  - `NodeRequest` : wrapper autour de `IncomingMessage` avec interface `RequestInterface`
78
83
  - `NodeReply` : wrapper autour de `ServerResponse` avec interface `ReplyInterface`
79
84
 
80
- ### `denoRuntime` (stub)
85
+ ### `denoRuntime` (Deno.serve)
81
86
 
82
87
  **Fichier :** `source/framework/runtime/deno/server.ts`
83
88
 
84
- Non implémenté — stub uniquement.
89
+ Utilise `Deno.serve()` et `Deno.upgradeWebSocket()` pour les sockets.
90
+
91
+ - **Serveur** : `Deno.serve({ port, hostname })`
92
+ - **Requêtes** : Native `Request` / `Response`
93
+ - **Sockets** : `Deno.upgradeWebSocket()`
94
+ - **Recommandé** pour une production stable et rapide sur Deno
85
95
 
86
96
  ## Interface `RuntimeAdapterInterface`
87
97
 
@@ -19,6 +19,7 @@ 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`) |
22
23
  | [health-check.md](health-check.md) | Endpoint de contrôle et vérifications de santé |
23
24
  | [https.md](https.md) | HTTPS, certificats et environnements |
24
25
  | [openapi/README.md](openapi/README.md) | Générer et documenter l'API |
@@ -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)
@@ -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)
@@ -11,6 +11,7 @@ Cette section regroupe les décorateurs que vous utilisez pour définir vos cont
11
11
  - [parameters.md](parameters.md)
12
12
  - [injection.md](injection.md)
13
13
  - [middleware.md](middleware.md)
14
+ - [cache.md](cache.md)
14
15
  - [socket.md](socket.md)
15
16
  - [api-tags.md](api-tags.md)
16
17
  - [api-operation.md](api-operation.md)
@@ -0,0 +1,79 @@
1
+ # `@Cache()`
2
+
3
+ > **Navigation :** [← middleware](middleware.md) | [health-check →](health-check.md)
4
+
5
+ `@Cache()` met en cache la réponse d'une route pendant une durée de vie (`ttl`).
6
+ Tant qu'une entrée est fraîche, le handler **n'est pas re-exécuté** : la réponse
7
+ est servie depuis le cache.
8
+
9
+ ## Pourquoi l'utiliser
10
+
11
+ - alléger des endpoints coûteux (lectures DB, calculs, appels externes)
12
+ - réduire la latence perçue sur les données peu volatiles
13
+ - économiser les ressources serveur sur les pics de lecture
14
+
15
+ ## Comment l'utiliser
16
+
17
+ - placez `@Cache(options)` sur la méthode d'un contrôleur, après le décorateur de route
18
+ - définissez un `ttl` adapté à la volatilité de vos données
19
+ - segmentez éventuellement le cache avec `vary`
20
+
21
+ ## Exemple
22
+
23
+ ```typescript
24
+ import { Controllable, Get, Cache } from "raiton/framework"
25
+
26
+ @Controllable("/products")
27
+ export class ProductController {
28
+ @Get("/featured")
29
+ @Cache({ ttl: 60_000 })
30
+ featured() {
31
+ // coûteux : n'est exécuté qu'une fois par minute
32
+ return this.catalogue.featured()
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## Options
38
+
39
+ | Option | Type | défaut | Description |
40
+ |--------|------|--------|-------------|
41
+ | `ttl` | `number` | `60000` | durée de validité (ms) |
42
+ | `enabled` | `boolean` | `true` | désactiver le cache de la route |
43
+ | `key` | `(context, route?) => string` | auto | clé personnalisée |
44
+ | `vary` | `string[]` | `[]` | en-têtes participant à la clé |
45
+ | `methods` | `string[]` | `['GET', 'HEAD']` | méthodes mises en cache |
46
+
47
+ ### Exemple avec `vary`
48
+
49
+ ```typescript
50
+ @Get("/")
51
+ @Cache({ ttl: 30_000, vary: ["accept-language"] })
52
+ list() { /* ... */ }
53
+ ```
54
+
55
+ ## Configuration globale
56
+
57
+ Utilisez `CacheManager` pour les réglages par défaut ou un store alternatif.
58
+
59
+ ```typescript
60
+ import { CacheManager } from "raiton/framework"
61
+
62
+ CacheManager.configure({ ttl: 30_000, maxEntries: 5000 })
63
+ ```
64
+
65
+ ## Avantages
66
+
67
+ - simple : un décorateur, aucun code de cache à écrire
68
+ - personnalisable (TTL, clé, vary, store)
69
+ - se combine avec les ETag pour la validation
70
+
71
+ ## Inconvénients
72
+
73
+ - un `ttl` trop long peut servir des données obsolètes
74
+ - le cache est en mémoire par défaut (non partagé entre processus)
75
+ - à n'utiliser que sur des données compatibles avec un léger retard
76
+
77
+ ---
78
+
79
+ [← middleware](middleware.md) | [health-check →](health-check.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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raiton",
3
- "version": "6.6.0-beta.14",
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;