raiton 6.6.0-beta.14 → 6.8.1-beta.17
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 +30 -0
- package/README.md +16 -9
- package/build/bin/index.mjs +9150 -3911
- package/deno.json +4 -1
- package/docs/contributors/README.md +1 -0
- package/docs/contributors/core/README.md +8 -0
- package/docs/contributors/core/scheduler.md +113 -0
- 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 +5 -0
- package/docs/contributors/framework/decorators/scheduler.md +83 -0
- package/docs/contributors/framework/runtime.md +13 -3
- package/docs/user-guide/README.md +9 -5
- package/docs/user-guide/cache.md +79 -0
- package/docs/user-guide/cli.md +35 -3
- package/docs/user-guide/decorators/README.md +3 -0
- package/docs/user-guide/decorators/cache.md +79 -0
- package/docs/user-guide/decorators/mcp.md +2 -2
- package/docs/user-guide/decorators/scheduler.md +75 -0
- package/docs/user-guide/mcp.md +2 -2
- package/docs/user-guide/runtime.md +2 -1
- package/docs/user-guide/scheduler.md +229 -0
- package/package.json +9 -4
- 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 +81 -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 +16 -10
- 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 +17 -16
- package/source/core/injection/index.ts +1 -1
- package/source/core/injection/injection.ts +7 -4
- 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/scheduler/builder.ts +25 -0
- package/source/core/scheduler/cron.ts +400 -0
- package/source/core/scheduler/duration.ts +42 -0
- package/source/core/scheduler/index.ts +6 -0
- package/source/core/scheduler/manager.ts +542 -0
- package/source/core/scheduler/metadata.ts +53 -0
- package/source/core/scheduler/queue/backend.ts +142 -0
- package/source/core/scheduler/queue/index.ts +3 -0
- package/source/core/scheduler/queue/rabbitmq.backend.ts +124 -0
- package/source/core/scheduler/queue/redis.backend.ts +144 -0
- 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 +55 -22
- package/source/framework/artifacts.ts +32 -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 +4 -4
- package/source/framework/decorators/csrf-token.decorator.ts +1 -1
- package/source/framework/decorators/guard.decorator.ts +4 -4
- package/source/framework/decorators/health-check.decorator.ts +3 -3
- package/source/framework/decorators/index.ts +15 -14
- 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/scheduler.decorator.ts +139 -0
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +2 -2
- package/source/framework/enums/index.ts +9 -8
- package/source/framework/enums/runtime.enum.ts +1 -2
- package/source/framework/enums/scheduler.enum.ts +23 -0
- 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 +4 -4
- package/source/framework/index.ts +18 -17
- 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 +6 -6
- package/source/framework/plugins/security/headers.ts +2 -2
- package/source/framework/plugins/security/index.ts +6 -6
- 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 +1 -1
- package/source/framework/utilities/index.ts +10 -10
- 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 +1 -1
- package/source/types/guard.ts +1 -1
- package/source/types/http-responses.ts +1 -1
- package/source/types/index.ts +27 -26
- 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 +2 -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/scheduler.ts +180 -0
- package/source/types/thread.ts +4 -4
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)
|
|
@@ -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)
|
|
@@ -23,12 +24,14 @@ Cette section regroupe les décorateurs que vous utilisez pour définir vos cont
|
|
|
23
24
|
- [guard.md](guard.md)
|
|
24
25
|
- [health-check.md](health-check.md)
|
|
25
26
|
- [mcp.md](mcp.md)
|
|
27
|
+
- [scheduler.md](scheduler.md)
|
|
26
28
|
|
|
27
29
|
## Comment lire cette section
|
|
28
30
|
|
|
29
31
|
- commencez par `controllable.md` et `routes.md`
|
|
30
32
|
- utilisez ensuite `parameters.md`, `injection.md` et `middleware.md`
|
|
31
33
|
- documentez vos endpoints temps réel et IA avec `socket.md` et `mcp.md`
|
|
34
|
+
- planifiez des tâches avec `scheduler.md`
|
|
32
35
|
- qualifiez un endpoint de santé avec `health-check.md`
|
|
33
36
|
- terminez par les décorateurs OpenAPI si vous documentez votre API
|
|
34
37
|
|
|
@@ -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)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@McpServer()` et décorateurs MCP
|
|
2
2
|
|
|
3
|
-
> **Navigation :** [← guard](guard.md) | [
|
|
3
|
+
> **Navigation :** [← guard](guard.md) | [scheduler →](scheduler.md)
|
|
4
4
|
|
|
5
5
|
Les décorateurs MCP servent à définir un serveur **Model Context Protocol** : outils, prompts et ressources accessibles aux clients IA.
|
|
6
6
|
|
|
@@ -67,4 +67,4 @@ export class MathServer {
|
|
|
67
67
|
|
|
68
68
|
---
|
|
69
69
|
|
|
70
|
-
[← guard](guard.md) | [
|
|
70
|
+
[← guard](guard.md) | [scheduler →](scheduler.md)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# `@Scheduler()` et décorateurs de tâches
|
|
2
|
+
|
|
3
|
+
> **Navigation :** [← mcp](mcp.md) | [README →](README.md)
|
|
4
|
+
|
|
5
|
+
Les décorateurs de scheduler servent à déclarer des jobs planifiés et des tâches nommées, exécutés par le `SchedulerManager`.
|
|
6
|
+
|
|
7
|
+
## Décorateurs concernés
|
|
8
|
+
|
|
9
|
+
- `@Scheduler()`
|
|
10
|
+
- `@Cron()`
|
|
11
|
+
- `@Every()` (alias `@Interval()`)
|
|
12
|
+
- `@Timeout()`
|
|
13
|
+
- `@Task()`
|
|
14
|
+
|
|
15
|
+
## Pourquoi utilisé
|
|
16
|
+
|
|
17
|
+
- planifier des travaux récurrents ou différés de façon déclarative
|
|
18
|
+
- déclarer des tâches exécutables à la demande ou via une file d’attente
|
|
19
|
+
- garder une structure proche des contrôleurs et réutiliser l’injection
|
|
20
|
+
|
|
21
|
+
## Comment l’utiliser
|
|
22
|
+
|
|
23
|
+
- marquez la classe avec `@Scheduler({ name, queue })`
|
|
24
|
+
- planifiez une méthode avec `@Cron("0 3 * * *")`, `@Every("5m")` ou `@Timeout("30s")`
|
|
25
|
+
- déclarez une tâche nommée avec `@Task("name", { consume: true })`
|
|
26
|
+
- le scheduler démarre automatiquement au lancement de l’application
|
|
27
|
+
|
|
28
|
+
## Exemple
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Scheduler, Cron, Every, Task } from "raiton/framework"
|
|
32
|
+
import type { TaskContextInterface } from "raiton/types"
|
|
33
|
+
|
|
34
|
+
@Scheduler({ name: "jobs", queue: "default" })
|
|
35
|
+
export class JobsScheduler {
|
|
36
|
+
@Cron("*/10 * * * * *", { name: "poll" })
|
|
37
|
+
async poll(ctx: TaskContextInterface) {
|
|
38
|
+
// toutes les 10 secondes
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Every("1m", { name: "metrics" })
|
|
42
|
+
async metrics() {
|
|
43
|
+
// toutes les minutes
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Task("report:generate", { consume: true, retries: 3 })
|
|
47
|
+
async generate(ctx: TaskContextInterface<{ id: string }>) {
|
|
48
|
+
// tâche nommée, dispatchable et consommable
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Options
|
|
54
|
+
|
|
55
|
+
Toutes les décorateurs de méthode acceptent `name`, `queue`, `timezone`, `singleton`, `concurrency`, `retries`, `retryDelay`, `timeout`, `catchUp`, `enabled`, `consume`, `priority` et `data`.
|
|
56
|
+
|
|
57
|
+
- `@Cron(expression, options)` — `expression` est une expression cron 5 ou 6 champs (ou une macro `@daily`, `@hourly`…)
|
|
58
|
+
- `@Every(interval, options)` — `interval` est un nombre (ms) ou une durée `"5s"`, `"1m30s"`, `"2h"`
|
|
59
|
+
- `@Timeout(delay, options)` — `delay` est un nombre (ms) ou une durée `"30s"`
|
|
60
|
+
- `@Task(name, options)` — `name` est le nom unique de la tâche
|
|
61
|
+
|
|
62
|
+
## Avantages
|
|
63
|
+
|
|
64
|
+
- API déclarative et lisible
|
|
65
|
+
- options riches (retries, timeout, concurrence, singleton)
|
|
66
|
+
- cohérente avec les contrôleurs, sockets et serveurs MCP
|
|
67
|
+
|
|
68
|
+
## Inconvénients
|
|
69
|
+
|
|
70
|
+
- l’exécution planifiée dépend du processus en cours (pas de persistance sans backend externe)
|
|
71
|
+
- les retries et le timeout s’appliquent par exécution, pas par file
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
[← mcp](mcp.md) | [README →](README.md)
|
package/docs/user-guide/mcp.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MCP (Model Context Protocol)
|
|
2
2
|
|
|
3
|
-
> **Navigation :** [← sockets](sockets.md) | [
|
|
3
|
+
> **Navigation :** [← sockets](sockets.md) | [scheduler →](scheduler.md)
|
|
4
4
|
|
|
5
5
|
Raiton permet de créer un serveur **MCP (Model Context Protocol)** facilement, avec des décorateurs, et de le faire coexister avec le serveur HTTP et les sockets sur le même processus et le même port.
|
|
6
6
|
|
|
@@ -117,4 +117,4 @@ Les serveurs MCP sont documentés dans le contrat OpenAPI généré, avec une ex
|
|
|
117
117
|
|
|
118
118
|
---
|
|
119
119
|
|
|
120
|
-
[← sockets](sockets.md) | [
|
|
120
|
+
[← sockets](sockets.md) | [scheduler →](scheduler.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
|
|
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
|
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Scheduler (tâches planifiées et files d’attente)
|
|
2
|
+
|
|
3
|
+
> **Navigation :** [← mcp](mcp.md) | [types →](types.md)
|
|
4
|
+
|
|
5
|
+
Raiton fournit un **task scheduler** intégré, décrit par des décorateurs, pour exécuter des tâches à intervalle régulier, à heure fixe (cron) ou via des **files d’attente** (mémoire, Redis, RabbitMQ…).
|
|
6
|
+
|
|
7
|
+
## De quoi s’agit-il
|
|
8
|
+
|
|
9
|
+
Le scheduler permet de :
|
|
10
|
+
|
|
11
|
+
- planifier des jobs **cron** (`@Cron`), **périodiques** (`@Every`) ou **différés** (`@Timeout`)
|
|
12
|
+
- déclarer des **tâches nommées** (`@Task`) exécutables à la demande
|
|
13
|
+
- distribuer et consommer ces tâches via une **file d’attente** pluggable
|
|
14
|
+
- bénéficier de la même découverte d’artifacts, du HMR et de l’injection de dépendances que le reste du framework
|
|
15
|
+
|
|
16
|
+
## Pourquoi utilisé
|
|
17
|
+
|
|
18
|
+
- exécuter des travaux récurrents : nettoyage, synchronisation, rapports, agrégation
|
|
19
|
+
- découpler la production d’un travail de son exécution (producteur / consommateur)
|
|
20
|
+
- répartir la charge entre plusieurs instances en branchant Redis ou RabbitMQ
|
|
21
|
+
- garder une API déclarative et typée, sans dépendance externe par défaut
|
|
22
|
+
|
|
23
|
+
## Comment l’utiliser
|
|
24
|
+
|
|
25
|
+
1. Créez un fichier artifact `*.scheduler.ts` (ou `*.task.ts`, `*.cron.ts`, `*.job.ts`)
|
|
26
|
+
2. Déclarez une classe avec `@Scheduler()`
|
|
27
|
+
3. Ajoutez des méthodes avec `@Cron`, `@Every`, `@Timeout` ou `@Task`
|
|
28
|
+
4. Le scheduler démarre automatiquement au lancement de l’application
|
|
29
|
+
|
|
30
|
+
## Exemple
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Scheduler, Cron, Every, Task } from "raiton/framework"
|
|
34
|
+
import type { TaskContextInterface } from "raiton/types"
|
|
35
|
+
|
|
36
|
+
@Scheduler({ name: "maintenance", queue: "default" })
|
|
37
|
+
export class MaintenanceScheduler {
|
|
38
|
+
@Cron("0 3 * * *", { name: "daily-cleanup", timezone: "Europe/Paris" })
|
|
39
|
+
async cleanup(ctx: TaskContextInterface) {
|
|
40
|
+
// exécuté chaque jour à 03:00 (heure de Paris)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Every("5m", { name: "heartbeat", immediate: true })
|
|
44
|
+
async heartbeat() {
|
|
45
|
+
// exécuté immédiatement, puis toutes les 5 minutes
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Timeout("30s", { name: "warmup" })
|
|
49
|
+
async warmup() {
|
|
50
|
+
// exécuté une seule fois, 30 secondes après le démarrage
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Task("email:welcome", { queue: "emails", consume: true, retries: 3, concurrency: 5 })
|
|
54
|
+
async welcome(ctx: TaskContextInterface<{ to: string }>) {
|
|
55
|
+
// tâche nommée, consommée depuis la file "emails"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Aucun enregistrement supplémentaire n’est nécessaire : le scanner détecte l’artifact, compile la classe et enregistre les jobs dans le `SchedulerManager`.
|
|
61
|
+
|
|
62
|
+
## Les tâches nommées
|
|
63
|
+
|
|
64
|
+
Une méthode `@Task("name")` est une tâche que vous pouvez déclencher de plusieurs façons :
|
|
65
|
+
|
|
66
|
+
### Exécution immédiate (in-process)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { SchedulerManager } from "raiton/core"
|
|
70
|
+
|
|
71
|
+
const result = await SchedulerManager.current.dispatch("email:welcome", { to: "a@b.c" })
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Mise en file d’attente
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
await SchedulerManager.current.enqueue("email:welcome", { to: "a@b.c" }, { priority: "high" })
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Le message est poussé sur la file associée (ici `"emails"`). Si la tâche a `consume: true`, un worker la récupère automatiquement dans le processus ; sinon, n’importe quel autre processus branché sur le même backend la traitera.
|
|
81
|
+
|
|
82
|
+
### Alias
|
|
83
|
+
|
|
84
|
+
- `trigger(name, payload)` équivaut à `dispatch(name, payload)`
|
|
85
|
+
|
|
86
|
+
## Options des tâches
|
|
87
|
+
|
|
88
|
+
Toutes les options sont optionnelles et disponibles sur `@Cron`, `@Every`, `@Timeout` et `@Task` :
|
|
89
|
+
|
|
90
|
+
| Option | Défaut | Description |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `name` | dérivé | Nom unique du job |
|
|
93
|
+
| `queue` | `"default"` | File d’attente cible |
|
|
94
|
+
| `timezone` | `"UTC"` | Fuseau horaire des expressions cron |
|
|
95
|
+
| `singleton` | `true` | Empêche deux exécutions simultanées du même job |
|
|
96
|
+
| `concurrency` | `1` | Nombre de messages consommés en parallèle (workers) |
|
|
97
|
+
| `retries` | `0` | Nombre de nouvelles tentatives après échec |
|
|
98
|
+
| `retryDelay` | `0` | Délai entre tentatives (ms ou `(attempt) => ms`) |
|
|
99
|
+
| `timeout` | — | Délai max (ms) avant échec de l’exécution |
|
|
100
|
+
| `catchUp` | `false` | Rejoue un tick manqué après une exécution en cours |
|
|
101
|
+
| `enabled` | `true` | Active ou désactive le job |
|
|
102
|
+
| `consume` | `false` | Consomme la file en tant que worker |
|
|
103
|
+
| `immediate` | `false` | (`@Every` uniquement) exécute une fois au démarrage |
|
|
104
|
+
| `priority` | `"normal"` | Priorité du message (`lowest` à `highest`) |
|
|
105
|
+
| `data` | — | Données statiques transmises au contexte |
|
|
106
|
+
|
|
107
|
+
## Le contexte d’exécution
|
|
108
|
+
|
|
109
|
+
Chaque handler reçoit un `TaskContextInterface` :
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
interface TaskContextInterface<T = any> {
|
|
113
|
+
id: string
|
|
114
|
+
name: string
|
|
115
|
+
queue?: string
|
|
116
|
+
payload?: T
|
|
117
|
+
data?: any
|
|
118
|
+
trigger: "cron" | "interval" | "timeout" | "task"
|
|
119
|
+
attempt: number
|
|
120
|
+
scheduledAt: Date
|
|
121
|
+
startedAt: Date
|
|
122
|
+
scheduler: SchedulerControlInterface
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Expressions cron
|
|
127
|
+
|
|
128
|
+
Le parseur supporte le format **5 champs** (`minute heure jour mois jour-de-semaine`) et **6 champs** (`seconde minute heure jour mois jour-de-semaine`) :
|
|
129
|
+
|
|
130
|
+
- `*` (tout), `?` (tout, pour jour/`dow`)
|
|
131
|
+
- listes `1,15,45`, plages `1-5`, pas `*/5` ou `1-5/2`
|
|
132
|
+
- noms de mois `JAN`–`DEC` et de jours `SUN`–`SAT`
|
|
133
|
+
- macros `@yearly`, `@monthly`, `@weekly`, `@daily`, `@hourly`, `@minutely`, `@secondly`
|
|
134
|
+
|
|
135
|
+
Exemples :
|
|
136
|
+
|
|
137
|
+
- `"0 3 * * *"` — chaque jour à 03:00
|
|
138
|
+
- `"*/5 * * * * *"` — toutes les 5 secondes
|
|
139
|
+
- `"30 9 * * 1-5"` — du lundi au vendredi à 09:30
|
|
140
|
+
|
|
141
|
+
## Files d’attente et backends
|
|
142
|
+
|
|
143
|
+
Le backend par défaut est une **file en mémoire**. Pour utiliser un broker externe, enregistrez un backend :
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { SchedulerManager, RedisQueueBackend, RabbitMqQueueBackend } from "raiton/core"
|
|
147
|
+
|
|
148
|
+
// Redis (nécessite `bun add redis`)
|
|
149
|
+
SchedulerManager.current.registerBackend("redis", new RedisQueueBackend({ url: "redis://localhost:6379" }))
|
|
150
|
+
// RabbitMQ (nécessite `bun add amqplib`)
|
|
151
|
+
SchedulerManager.current.registerBackend("rabbitmq", new RabbitMqQueueBackend({ url: "amqp://localhost" }))
|
|
152
|
+
|
|
153
|
+
// Route une file vers un backend précis
|
|
154
|
+
SchedulerManager.current.mapQueue("emails", "redis")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Les paquets `redis` et `amqplib` ne sont chargés qu’à la première connexion : le framework reste utilisable sans eux.
|
|
158
|
+
|
|
159
|
+
### Backend personnalisé
|
|
160
|
+
|
|
161
|
+
Implémentez l’interface `QueueBackendInterface` et enregistrez votre backend :
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { SchedulerManager } from "raiton/core"
|
|
165
|
+
import type { QueueBackendInterface } from "raiton/types"
|
|
166
|
+
|
|
167
|
+
class MyBackend implements QueueBackendInterface {
|
|
168
|
+
readonly name = "my-broker"
|
|
169
|
+
async connect() { /* ... */ }
|
|
170
|
+
async disconnect() { /* ... */ }
|
|
171
|
+
async enqueue(queue, message) { /* ... */ return message.id }
|
|
172
|
+
async dequeue(queue, options) { /* ... */ return [] }
|
|
173
|
+
async acknowledge(queue, receipt) { /* ... */ }
|
|
174
|
+
async reject(queue, receipt, requeue) { /* ... */ }
|
|
175
|
+
async length(queue) { /* ... */ return 0 }
|
|
176
|
+
async purge(queue) { /* ... */ }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
SchedulerManager.current.mapQueue("jobs", "my-broker")
|
|
180
|
+
SchedulerManager.current.registerBackend("my-broker", new MyBackend())
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Contrôle du scheduler
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { SchedulerManager } from "raiton/core"
|
|
187
|
+
|
|
188
|
+
const mgr = SchedulerManager.current
|
|
189
|
+
|
|
190
|
+
mgr.pause("daily-cleanup") // suspend un job
|
|
191
|
+
mgr.resume("daily-cleanup") // le reprend
|
|
192
|
+
mgr.cancel("daily-cleanup") // le supprime
|
|
193
|
+
|
|
194
|
+
const jobs = mgr.getJobs() // état détaillé de tous les jobs
|
|
195
|
+
const info = mgr.getJob("daily-cleanup") // { nextRun, lastRun, runCount, failCount, running, ... }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Configuration globale
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
SchedulerManager.current.configure({
|
|
202
|
+
enabled: true,
|
|
203
|
+
timezone: "UTC",
|
|
204
|
+
defaultQueue: "default",
|
|
205
|
+
maxConcurrentJobs: 100,
|
|
206
|
+
backend: new RedisQueueBackend({ url: "redis://localhost:6379" }),
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## HMR
|
|
211
|
+
|
|
212
|
+
Les artifacts `*.scheduler.ts` (et variantes) bénéficient du **hot reload** : une modification recharge les jobs sans redémarrer le process.
|
|
213
|
+
|
|
214
|
+
## Avantages
|
|
215
|
+
|
|
216
|
+
- API déclarative, typée et sans dépendance externe par défaut
|
|
217
|
+
- backends interchangeables (mémoire, Redis, RabbitMQ, sur mesure)
|
|
218
|
+
- réutilise l’injection de dépendances et le cycle de vie du framework
|
|
219
|
+
- HMR et découverte d’artifacts homogènes avec le reste de Raiton
|
|
220
|
+
|
|
221
|
+
## Inconvénients
|
|
222
|
+
|
|
223
|
+
- la file en mémoire est locale au processus (pas de persistance)
|
|
224
|
+
- le support Redis/RabbitMQ exige d’installer le paquet correspondant
|
|
225
|
+
- pas de file « dead-letter » dédiée : un échec définitif est simplement abandonné
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
[← mcp](mcp.md) | [types →](types.md)
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raiton",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.1-beta.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading
|
|
6
|
+
"description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading",
|
|
7
7
|
"main": "./source/core/index.ts",
|
|
8
8
|
"module": "./source/core/index.ts",
|
|
9
9
|
"types": "./source/core/index.d.ts",
|
|
@@ -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
|
-
"
|
|
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(
|
|
14
|
+
return cli.parse(CliTools.argv)
|
|
15
15
|
}
|
package/source/bin/cli-tools.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="deno" />
|
|
2
2
|
import {spawn} from 'node:child_process';
|
|
3
|
-
import
|
|
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
|
-
|
|
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
|
|
2
|
+
import pkg from '../../package.json' with {type: "json"};
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const CLI = new Command();
|
|
@@ -7,6 +7,6 @@ const CLI = new Command();
|
|
|
7
7
|
CLI
|
|
8
8
|
.name('raiton')
|
|
9
9
|
.description('Protorians Raiton framework for backend microservice')
|
|
10
|
-
.version(version);
|
|
10
|
+
.version(pkg.version);
|
|
11
11
|
|
|
12
12
|
export default CLI;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ArtifactCommand from "../commands/artifact.command.ts";
|
|
2
|
+
import BuildCommand from "../commands/build.command.ts";
|
|
3
|
+
import DevelopCommand from "../commands/develop.command.ts";
|
|
4
|
+
import GraftsCommand from "../commands/grafts.command.ts";
|
|
5
|
+
import StartCommand from "../commands/start.command.ts";
|
|
6
|
+
import type {Command} from "commander";
|
|
7
|
+
import type {RaitonCommand} from "../core/index.ts";
|
|
8
|
+
|
|
9
|
+
export type RaitonCommandConstructor = new (cli: Command, workdir: string, appdir: string) => RaitonCommand;
|
|
10
|
+
|
|
11
|
+
export const RaitonCommandsRegistry: RaitonCommandConstructor[] = [
|
|
12
|
+
ArtifactCommand,
|
|
13
|
+
BuildCommand,
|
|
14
|
+
DevelopCommand,
|
|
15
|
+
GraftsCommand,
|
|
16
|
+
StartCommand,
|
|
17
|
+
];
|
package/source/bin/constants.ts
CHANGED
package/source/bin/index.ts
CHANGED