raiton 6.11.0-beta.29 → 6.12.0-beta.31
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 +22 -0
- package/benchmarks/README.md +3 -3
- package/build/bin/index.mjs +2329 -361
- package/build/types/core/artifact-mount.d.ts +19 -0
- package/build/types/core/bridge/classifier.d.ts +30 -0
- package/build/types/core/bridge/definition.d.ts +10 -0
- package/build/types/core/bridge/diagnostics.d.ts +43 -0
- package/build/types/core/bridge/index.d.ts +8 -0
- package/build/types/core/bridge/loader.d.ts +75 -0
- package/build/types/core/bridge/packages.d.ts +27 -0
- package/build/types/core/bridge/paths.d.ts +37 -0
- package/build/types/core/bridge/registry.d.ts +50 -0
- package/build/types/core/bridge/resolver.d.ts +32 -0
- package/build/types/core/builder.d.ts +8 -1
- package/build/types/core/controller/builder.d.ts +9 -0
- package/build/types/core/controller/compiler.d.ts +8 -1
- package/build/types/core/controller/tracker.d.ts +10 -3
- package/build/types/core/hooks.d.ts +2 -0
- package/build/types/core/index.d.ts +1 -0
- package/build/types/core/injection/injection.d.ts +24 -0
- package/build/types/core/middleware/pipeline.d.ts +12 -1
- package/build/types/core/scheduler/manager.d.ts +5 -0
- package/build/types/framework/artifacts.d.ts +5 -0
- package/build/types/framework/constants/decorators.constant.d.ts +8 -0
- package/build/types/manifest/schema.d.ts +77 -0
- package/build/types/types/artifact.d.ts +16 -0
- package/build/types/types/bridge.d.ts +109 -0
- package/build/types/types/index.d.ts +1 -0
- package/docs/AGENTS.md +1 -1
- package/docs/CLAUDE.md +1 -1
- package/docs/generated/config-schema.json +26 -0
- package/docs/generated/manifest-schema.json +110 -0
- package/docs/generated/manifest.json +1 -1
- package/docs/llms-full.txt +176 -2
- package/docs/llms.txt +1 -1
- package/docs/user-guide/README.md +1 -0
- package/docs/user-guide/artifact-bridge.md +170 -0
- package/package.json +1 -1
- package/source/bin/project-utils.ts +9 -0
- package/source/commands/artifact.command.ts +24 -9
- package/source/commands/build.command.ts +3 -1
- package/source/commands/docs.command.ts +1 -0
- package/source/commands/doctor.command.ts +53 -1
- package/source/commands/inspect.command.ts +3 -0
- package/source/commands/start.command.ts +3 -1
- package/source/commands/why.command.ts +4 -0
- package/source/core/artifact-mount.ts +126 -0
- package/source/core/bridge/classifier.ts +112 -0
- package/source/core/bridge/definition.ts +35 -0
- package/source/core/bridge/diagnostics.ts +175 -0
- package/source/core/bridge/index.ts +8 -0
- package/source/core/bridge/loader.ts +914 -0
- package/source/core/bridge/packages.ts +196 -0
- package/source/core/bridge/paths.ts +152 -0
- package/source/core/bridge/registry.ts +177 -0
- package/source/core/bridge/resolver.ts +183 -0
- package/source/core/builder.ts +146 -7
- package/source/core/config/schema.ts +54 -9
- package/source/core/controller/builder.ts +49 -31
- package/source/core/controller/compiler.ts +13 -4
- package/source/core/controller/tracker.ts +29 -7
- package/source/core/hooks.ts +5 -0
- package/source/core/index.ts +2 -1
- package/source/core/injection/injection.ts +67 -0
- package/source/core/middleware/pipeline.ts +33 -2
- package/source/core/scheduler/manager.ts +15 -0
- package/source/core/thread.ts +21 -0
- package/source/framework/artifacts.ts +10 -0
- package/source/framework/constants/decorators.constant.ts +35 -27
- package/source/manifest/manifest.ts +46 -0
- package/source/manifest/schema.ts +48 -0
- package/source/types/artifact.ts +16 -0
- package/source/types/bridge.ts +136 -0
- package/source/types/index.ts +1 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Artifact Bridge
|
|
2
|
+
|
|
3
|
+
Le bridge d'artefacts permet de monter du code que le scan par suffixe ne peut
|
|
4
|
+
pas découvrir : artefacts fournis par des packages npm, fichiers locaux hors
|
|
5
|
+
convention, middleware et hooks applicatifs.
|
|
6
|
+
|
|
7
|
+
> Le bridge est **optionnel**. Sans `artifacts.bridge.ts`, le comportement de
|
|
8
|
+
> l'application est strictement identique au scan par suffixe.
|
|
9
|
+
|
|
10
|
+
## Fichier
|
|
11
|
+
|
|
12
|
+
Par défaut, Raiton découvre `artifacts.bridge.ts` dans le `rootDir` du projet
|
|
13
|
+
(`source/` par défaut).
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// source/artifacts.bridge.ts
|
|
17
|
+
import {defineArtifactBridge} from "raiton/core";
|
|
18
|
+
|
|
19
|
+
import {UsersController} from "@acme/users";
|
|
20
|
+
import {AuthMiddleware} from "@acme/auth";
|
|
21
|
+
import {auditHook} from "./hooks/audit.ts";
|
|
22
|
+
import {LegacyController} from "./legacy/handlers.ts";
|
|
23
|
+
|
|
24
|
+
export default defineArtifactBridge({
|
|
25
|
+
artifacts: [
|
|
26
|
+
// Classes déjà importées (forme recommandée)
|
|
27
|
+
UsersController,
|
|
28
|
+
|
|
29
|
+
// Modules : tous les exports décorés sont inspectés
|
|
30
|
+
"@acme/analytics",
|
|
31
|
+
"@acme/legacy/dist/index.js",
|
|
32
|
+
|
|
33
|
+
// Fichier local hors convention
|
|
34
|
+
"./legacy/handlers.ts",
|
|
35
|
+
|
|
36
|
+
// Middleware applicatif
|
|
37
|
+
{middleware: AuthMiddleware, name: "acme-auth"},
|
|
38
|
+
|
|
39
|
+
// Hook applicatif
|
|
40
|
+
{hook: "onRequest", handler: auditHook, name: "acme-audit"},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Le bridge ne remplace pas `main.ts` : le bootstrap, la configuration et les
|
|
46
|
+
plugins restent dans `main.ts`.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// raiton.config.ts
|
|
52
|
+
export default {
|
|
53
|
+
rootDir: "./source",
|
|
54
|
+
artifacts: {
|
|
55
|
+
// Chemin explicite, relatif au workdir ou au rootDir.
|
|
56
|
+
// `false` désactive complètement le bridge.
|
|
57
|
+
bridge: "./artifacts.bridge.ts",
|
|
58
|
+
// Découverte des dépendances directes auto-descriptives (défaut : true).
|
|
59
|
+
packages: true,
|
|
60
|
+
// Restriction optionnelle à certains packages.
|
|
61
|
+
packageAllowlist: ["@acme/users"],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Types d'entrées
|
|
67
|
+
|
|
68
|
+
| Entrée | Résultat |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `UsersController` | Classification par métadonnées de décorateurs |
|
|
71
|
+
| `"@acme/users"` | Import du module, inspection de tous les exports nommés et `default` |
|
|
72
|
+
| `"./legacy/handlers.ts"` | Fichier local hors convention |
|
|
73
|
+
| `{middleware, name?, order?}` | Middleware global, après les middleware intégrés |
|
|
74
|
+
| `{hook, handler, name?}` | Hook global (`onRequest`, `preParsing`, `preHandler`, `onSend`, `onResponse`) |
|
|
75
|
+
| `{plugin}` | Délégation à `application.register(plugin)` |
|
|
76
|
+
|
|
77
|
+
Une fonction sans métadonnée et sans descripteur est ambiguë : elle est rejetée
|
|
78
|
+
avec `BRIDGE_ARTIFACT_AMBIGUOUS`.
|
|
79
|
+
|
|
80
|
+
## Packages auto-descriptifs
|
|
81
|
+
|
|
82
|
+
Une dépendance **directe** peut déclarer ses artefacts :
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"name": "@acme/users",
|
|
87
|
+
"peerDependencies": {"raiton": "^6"},
|
|
88
|
+
"raiton": {
|
|
89
|
+
"artifacts": [
|
|
90
|
+
"./dist/users.controller.js",
|
|
91
|
+
"./dist/users.service.js"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Ou exposer un module bridge :
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"raiton": {
|
|
102
|
+
"artifacts": "./dist/artifacts.bridge.js"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Contrat de package :
|
|
108
|
+
|
|
109
|
+
- déclarer `raiton` en `peerDependency`, jamais l'embarquer ;
|
|
110
|
+
- ne pas livrer une copie imbriquée de Raiton ;
|
|
111
|
+
- livrer du JavaScript exécutable par le runtime cible ;
|
|
112
|
+
- importer `reflect-metadata` une seule fois au niveau de l'application.
|
|
113
|
+
|
|
114
|
+
Les dépendances transitives ne sont pas découvertes. Il n'y a aucun scan
|
|
115
|
+
récursif de `node_modules`.
|
|
116
|
+
|
|
117
|
+
## CLI
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
raiton artifact --dump --json # origine scan/bridge, type, package, fichier
|
|
121
|
+
raiton inspect --json # section `bridge` du manifeste
|
|
122
|
+
raiton why GET /users # origine de la route
|
|
123
|
+
raiton doctor # diagnostics du bridge
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`build`, `dev` et `start` chargent le bridge automatiquement. Sur Node.js, le
|
|
127
|
+
bridge est compilé dans `.raiton/server/artifacts.bridge.mjs` ; `raiton build`
|
|
128
|
+
doit être exécuté avant `raiton start`.
|
|
129
|
+
|
|
130
|
+
## Rechargement à chaud
|
|
131
|
+
|
|
132
|
+
- Bun et Deno : le fichier bridge est surveillé ; ajouts, retraits et
|
|
133
|
+
modifications sont réconciliés sans redémarrage complet.
|
|
134
|
+
- Node.js : le redémarrage contrôlé existant est utilisé.
|
|
135
|
+
- Les modules de packages externes ne sont pas surveillés : redémarrez après
|
|
136
|
+
leur mise à jour.
|
|
137
|
+
|
|
138
|
+
Le rechargement ne retire que les artefacts possédés par le bridge. Les routes,
|
|
139
|
+
instances, middleware et hooks découverts par le scan local restent intacts.
|
|
140
|
+
|
|
141
|
+
## Diagnostics
|
|
142
|
+
|
|
143
|
+
Tous les codes sont stables et pointent vers ce guide :
|
|
144
|
+
|
|
145
|
+
| Code | Cause |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `BRIDGE_FILE_NOT_FOUND` | Chemin configuré introuvable |
|
|
148
|
+
| `BRIDGE_FILE_INVALID_EXPORT` | Export par défaut absent ou invalide |
|
|
149
|
+
| `BRIDGE_IMPORT_FAILED` | Exception à l'import |
|
|
150
|
+
| `BRIDGE_MODULE_NOT_FOUND` | Spécificateur non résolvable |
|
|
151
|
+
| `BRIDGE_ENTRY_INVALID` | Entrée non supportée |
|
|
152
|
+
| `BRIDGE_ARTIFACT_NOT_FOUND` | Module sans artefact décoré |
|
|
153
|
+
| `BRIDGE_ARTIFACT_AMBIGUOUS` | Fonction sans métadonnée ni descripteur |
|
|
154
|
+
| `BRIDGE_NAME_COLLISION` | Deux classes partagent le même nom DI |
|
|
155
|
+
| `BRIDGE_ABI_MISMATCH` | Copie de Raiton incompatible dans un package |
|
|
156
|
+
| `BRIDGE_RUNTIME_UNSUPPORTED` | Entrée TypeScript sur un runtime qui ne la lit pas |
|
|
157
|
+
| `BRIDGE_NOT_BUNDLED` | Bridge non compilé pour Node.js |
|
|
158
|
+
| `BRIDGE_PACKAGE_FIELD_INVALID` | `package.json#raiton.artifacts` invalide |
|
|
159
|
+
| `BRIDGE_HOOK_UNKNOWN` | Hook non supporté |
|
|
160
|
+
|
|
161
|
+
Les codes `BRIDGE_ARTIFACT_DUPLICATE` et `BRIDGE_DUPLICATE_MOUNT` sont
|
|
162
|
+
informatifs : le premier artefact rencontré est conservé.
|
|
163
|
+
|
|
164
|
+
## Performance
|
|
165
|
+
|
|
166
|
+
Le bridge absent ne coûte que quelques vérifications d'existence. Les entrées
|
|
167
|
+
constituent une allowlist explicite ; aucun glob non borné ni scan récursif de
|
|
168
|
+
`node_modules` n'est exécuté. Le chargement d'un bridge de 50 entrées doit rester
|
|
169
|
+
sous le budget de démarrage documenté par la spec 001, hors import des modules
|
|
170
|
+
externes.
|
package/package.json
CHANGED
|
@@ -26,6 +26,15 @@ export async function loadProject(workdir: string, json = false): Promise<Intros
|
|
|
26
26
|
: await introspectProject(workdir);
|
|
27
27
|
} catch (error: any) {
|
|
28
28
|
if (error instanceof CliError) throw error;
|
|
29
|
+
if (error?.code && String(error.code).startsWith("BRIDGE_")) {
|
|
30
|
+
throw new CliError(error.message ?? String(error), {
|
|
31
|
+
code: error.code,
|
|
32
|
+
hint: error.diagnostic?.action ?? "Fix the bridge declaration, then retry.",
|
|
33
|
+
docsUrl: error.diagnostic?.docsUrl,
|
|
34
|
+
location: error.diagnostic?.location,
|
|
35
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
29
38
|
throw new CliError(error?.message ?? String(error), {
|
|
30
39
|
code: "INTROSPECTION_FAILED",
|
|
31
40
|
hint: "Fix the bootstrapper or configuration, then run `raiton doctor`.",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {RaitonCommand} from "../core/command.ts";
|
|
2
2
|
import {CLI_JSON_SCHEMA_VERSION, fail, print} from "../bin/cli-output.ts";
|
|
3
3
|
import {RaitonConfig} from "../core/config/config.ts";
|
|
4
|
-
import {
|
|
4
|
+
import {loadProject} from "../bin/project-utils.ts";
|
|
5
|
+
import {ArtifactRegistry} from "../core/bridge/registry.ts";
|
|
5
6
|
|
|
6
7
|
interface ArtifactOptions {
|
|
7
8
|
dump?: boolean;
|
|
@@ -17,27 +18,41 @@ export default class ArtifactCommand extends RaitonCommand {
|
|
|
17
18
|
.command("artifact")
|
|
18
19
|
.alias("art")
|
|
19
20
|
.description(this.description)
|
|
20
|
-
.option("--dump", "Dump artifacts
|
|
21
|
+
.option("--dump", "Dump artifacts and their origin (scan or bridge)")
|
|
21
22
|
.option("--json", "Emit a machine-readable list on stdout")
|
|
22
23
|
.action((options: ArtifactOptions) => this.run(options).catch(error => fail(error, options.json)));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
private async run(options: ArtifactOptions): Promise<void> {
|
|
26
27
|
await RaitonConfig.sync(this.workdir, {force: true});
|
|
27
|
-
const manifest =
|
|
28
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
29
|
+
const artifacts = ArtifactRegistry.describeArtifacts(this.workdir);
|
|
28
30
|
|
|
29
31
|
if (options.json) {
|
|
30
|
-
print({
|
|
32
|
+
print({
|
|
33
|
+
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
34
|
+
artifacts,
|
|
35
|
+
types: manifest.artifacts,
|
|
36
|
+
...(manifest.bridge ? {bridge: manifest.bridge} : {}),
|
|
37
|
+
}, true);
|
|
31
38
|
return;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
if (!
|
|
35
|
-
print("No artifact detected. Use documented suffixes such as `.controller.ts` or
|
|
41
|
+
if (!artifacts.length) {
|
|
42
|
+
print("No artifact detected. Use documented suffixes such as `.controller.ts` or declare entries in `artifacts.bridge.ts`.");
|
|
36
43
|
return;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
print(`Detected
|
|
40
|
-
for (const artifact of
|
|
41
|
-
|
|
46
|
+
print(`Detected artifacts (${artifacts.length}):`);
|
|
47
|
+
for (const artifact of artifacts) {
|
|
48
|
+
const location = artifact.package
|
|
49
|
+
? `package ${artifact.package}`
|
|
50
|
+
: (artifact.file ?? "");
|
|
51
|
+
print(` - ${artifact.name} [${artifact.kind}] origin=${artifact.origin}${location ? ` ${location}` : ""}`);
|
|
52
|
+
}
|
|
53
|
+
if (manifest.bridge) {
|
|
54
|
+
print(`Bridge: ${manifest.bridge.file ?? "none"} (${manifest.bridge.artifacts.length} artifact(s), ${manifest.bridge.unresolved.length} unresolved)`);
|
|
55
|
+
}
|
|
56
|
+
print("Create one with `raiton generate <type> <name>` or declare it in `artifacts.bridge.ts`.");
|
|
42
57
|
}
|
|
43
58
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {RaitonCommand, RaitonBuilder} from "../core/index.ts";
|
|
2
2
|
import {LBadge, Logger} from "@protorians/logger";
|
|
3
3
|
import type {BuildCommandOptionsInterface} from "../types/index.ts";
|
|
4
|
+
import {fail} from "../bin/cli-output.ts";
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
export default class BuildCommand extends RaitonCommand {
|
|
@@ -14,7 +15,8 @@ export default class BuildCommand extends RaitonCommand {
|
|
|
14
15
|
.description("Build the application")
|
|
15
16
|
.option("--develop, -d", "Build in development mode")
|
|
16
17
|
.option("--bootstrap, -b", "Bootstrap the application")
|
|
17
|
-
.action(
|
|
18
|
+
.action((options: BuildCommandOptionsInterface) =>
|
|
19
|
+
this.run(options).catch(error => fail(error)));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
protected async run(options: BuildCommandOptionsInterface): Promise<void> {
|
|
@@ -7,6 +7,8 @@ import {RaitonConfig} from "../core/config/config.ts";
|
|
|
7
7
|
import {errorDocsUrl} from "../framework/errors/catalog.ts";
|
|
8
8
|
import {loadProject} from "../bin/project-utils.ts";
|
|
9
9
|
import {isBunUsed, isDenoUsed} from "../bin/constants.ts";
|
|
10
|
+
import {BridgeLoader} from "../core/bridge/loader.ts";
|
|
11
|
+
import type {BridgeDiagnostic} from "../types/bridge.ts";
|
|
10
12
|
|
|
11
13
|
type Severity = "error" | "warning" | "info";
|
|
12
14
|
|
|
@@ -124,6 +126,20 @@ export default class DoctorCommand extends RaitonCommand {
|
|
|
124
126
|
add("CONFIG_FIELD", "error", `Configuration: ${configError.field} ${configError.message}`, "Fix the field in raiton.config.*.", "user-guide/config.md", RaitonConfig.source ?? undefined);
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
// Bridge diagnostics are non-throwing so doctor can report every issue
|
|
130
|
+
// instead of stopping at the first invalid declaration.
|
|
131
|
+
const bridgeDiagnostics: BridgeDiagnostic[] = BridgeLoader.diagnose(this.workdir);
|
|
132
|
+
for (const diagnostic of bridgeDiagnostics) {
|
|
133
|
+
issues.push({
|
|
134
|
+
code: diagnostic.code,
|
|
135
|
+
severity: diagnostic.severity,
|
|
136
|
+
message: diagnostic.message,
|
|
137
|
+
action: diagnostic.action,
|
|
138
|
+
docsUrl: diagnostic.docsUrl,
|
|
139
|
+
location: diagnostic.location,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
127
143
|
const root = path.resolve(this.workdir, RaitonConfig.get("rootDir") || "./");
|
|
128
144
|
if (!fs.existsSync(root)) {
|
|
129
145
|
add("SOURCE_MISSING", "error", `Source directory not found: ${path.relative(this.workdir, root)}`, "Create the directory or fix rootDir.", "user-guide/config.md", root);
|
|
@@ -158,6 +174,30 @@ export default class DoctorCommand extends RaitonCommand {
|
|
|
158
174
|
// Project-level introspection: decorators, routes, MCP and env coverage.
|
|
159
175
|
try {
|
|
160
176
|
const {manifest} = await loadProject(this.workdir, true);
|
|
177
|
+
|
|
178
|
+
if (BridgeLoader.state.loaded) {
|
|
179
|
+
const state = BridgeLoader.state;
|
|
180
|
+
add(
|
|
181
|
+
"BRIDGE_LOADED",
|
|
182
|
+
"info",
|
|
183
|
+
`Bridge loaded: ${state.artifacts.length} artifact(s), ${state.packages.length} package(s)`,
|
|
184
|
+
"No action required.",
|
|
185
|
+
"user-guide/artifact-bridge.md",
|
|
186
|
+
state.sourceFile ?? undefined,
|
|
187
|
+
);
|
|
188
|
+
for (const diagnostic of state.diagnostics) {
|
|
189
|
+
if (issues.some(issue => issue.code === diagnostic.code && issue.message === diagnostic.message)) continue;
|
|
190
|
+
issues.push({
|
|
191
|
+
code: diagnostic.code,
|
|
192
|
+
severity: diagnostic.severity,
|
|
193
|
+
message: diagnostic.message,
|
|
194
|
+
action: diagnostic.action,
|
|
195
|
+
docsUrl: diagnostic.docsUrl,
|
|
196
|
+
location: diagnostic.location,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
161
201
|
const envIssue = await this.fixEnv(manifest.env, options.fix, fixed);
|
|
162
202
|
if (envIssue) add(...envIssue);
|
|
163
203
|
|
|
@@ -185,7 +225,19 @@ export default class DoctorCommand extends RaitonCommand {
|
|
|
185
225
|
}
|
|
186
226
|
}
|
|
187
227
|
} catch (error: any) {
|
|
188
|
-
if (error?.code
|
|
228
|
+
if (error?.code && String(error.code).startsWith("BRIDGE_")) {
|
|
229
|
+
const message = error.message;
|
|
230
|
+
if (!issues.some(issue => issue.code === error.code && issue.message === message)) {
|
|
231
|
+
issues.push({
|
|
232
|
+
code: error.code,
|
|
233
|
+
severity: "error",
|
|
234
|
+
message,
|
|
235
|
+
action: error.diagnostic?.action ?? error.hint ?? "Fix the bridge declaration and retry.",
|
|
236
|
+
docsUrl: error.diagnostic?.docsUrl ?? error.docsUrl ?? errorDocsUrl("user-guide/artifact-bridge.md"),
|
|
237
|
+
location: error.diagnostic?.location ?? error.location,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
} else if (error?.code !== "PREREQUISITE_MISSING") {
|
|
189
241
|
add("INTROSPECTION_FAILED", "error", `Could not inspect the project: ${error.message}`, "Fix the bootstrapper, then run `raiton doctor` again.", "user-guide/cli.md");
|
|
190
242
|
}
|
|
191
243
|
}
|
|
@@ -97,6 +97,9 @@ export default class InspectCommand extends RaitonCommand {
|
|
|
97
97
|
} else {
|
|
98
98
|
print(`Manifest ${manifest.schemaVersion} · ${manifest.framework.name} ${manifest.framework.version}`);
|
|
99
99
|
print(`Routes: ${manifest.routes.length} · artifacts: ${manifest.artifacts.length} · MCP servers: ${manifest.mcp.length}`);
|
|
100
|
+
if (manifest.bridge) {
|
|
101
|
+
print(`Bridge: ${manifest.bridge.file ?? "none"} · loaded: ${manifest.bridge.loaded} · entries: ${manifest.bridge.artifacts.length} · unresolved: ${manifest.bridge.unresolved.length}`);
|
|
102
|
+
}
|
|
100
103
|
if (manifest.routes.length) {
|
|
101
104
|
for (const route of manifest.routes) {
|
|
102
105
|
print(` ${route.method.padEnd(6)} ${route.path} → ${route.controller}.${route.handler} (${route.file}:${route.line})`);
|
|
@@ -3,6 +3,7 @@ import {RaitonBuilder, RaitonCommand} from "../core/index.ts";
|
|
|
3
3
|
import {ChildProcess} from 'node:child_process';
|
|
4
4
|
import {LBadge, Logger} from "@protorians/logger";
|
|
5
5
|
import {StartCommandOptionsInterface} from "../types/index.ts";
|
|
6
|
+
import {fail} from "../bin/cli-output.ts";
|
|
6
7
|
|
|
7
8
|
export default class StartCommand extends RaitonCommand {
|
|
8
9
|
public readonly name: string = 'start';
|
|
@@ -16,7 +17,8 @@ export default class StartCommand extends RaitonCommand {
|
|
|
16
17
|
.alias("run")
|
|
17
18
|
.description("Start the application in production mode")
|
|
18
19
|
.option("--develop, -d", "Build in development mode")
|
|
19
|
-
.action(
|
|
20
|
+
.action((options: StartCommandOptionsInterface) =>
|
|
21
|
+
this.run(options).catch(error => fail(error)));
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
protected async run(options: StartCommandOptionsInterface): Promise<void> {
|
|
@@ -41,6 +41,8 @@ export default class WhyCommand extends RaitonCommand {
|
|
|
41
41
|
handler: route.handler,
|
|
42
42
|
decorator: `@${route.method.charAt(0)}${route.method.slice(1).toLowerCase()}("${route.path}")`,
|
|
43
43
|
artifact: route.controller === "Application" ? "application" : "controller",
|
|
44
|
+
origin: route.origin ?? "scan",
|
|
45
|
+
...(route.package ? {package: route.package} : {}),
|
|
44
46
|
input: route.input,
|
|
45
47
|
output: route.output,
|
|
46
48
|
};
|
|
@@ -55,6 +57,8 @@ export default class WhyCommand extends RaitonCommand {
|
|
|
55
57
|
print(` controller: ${origin.controller}.${origin.handler}`);
|
|
56
58
|
print(` decorator: ${origin.decorator}`);
|
|
57
59
|
print(` artifact: ${origin.artifact}`);
|
|
60
|
+
print(` origin: ${origin.origin}`);
|
|
61
|
+
if (origin.package) print(` package: ${origin.package}`);
|
|
58
62
|
if (origin.input) print(` input: ${origin.input}`);
|
|
59
63
|
if (origin.output) print(` output: ${origin.output}`);
|
|
60
64
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type {ApplicationInterface} from "../types/application.ts";
|
|
2
|
+
import type {ArtifactKind, ArtifactOrigin} from "../types/bridge.ts";
|
|
3
|
+
import type {ConstructorType} from "../types/contruct.ts";
|
|
4
|
+
import type {ArtifactClassification} from "../framework/artifacts.ts";
|
|
5
|
+
import {Injection} from "./injection/injection.ts";
|
|
6
|
+
import {compileController} from "./controller/compiler.ts";
|
|
7
|
+
import {ControllerRouteTracker} from "./controller/tracker.ts";
|
|
8
|
+
import {compileSocket} from "./socket/builder.ts";
|
|
9
|
+
import {compileMcp} from "./mcp/builder.ts";
|
|
10
|
+
import {compileScheduler} from "./scheduler/builder.ts";
|
|
11
|
+
import {ArtifactRegistry, artifactKey, type MountedArtifactRecord} from "./bridge/registry.ts";
|
|
12
|
+
import {BridgeError} from "./bridge/diagnostics.ts";
|
|
13
|
+
|
|
14
|
+
export function kindForClassification(classification: ArtifactClassification): ArtifactKind {
|
|
15
|
+
switch (classification.channel) {
|
|
16
|
+
case "hmr:controller":
|
|
17
|
+
return "controller";
|
|
18
|
+
case "hmr:socket":
|
|
19
|
+
return "socket";
|
|
20
|
+
case "hmr:mcp":
|
|
21
|
+
return "mcp";
|
|
22
|
+
case "hmr:scheduler":
|
|
23
|
+
return "scheduler";
|
|
24
|
+
default:
|
|
25
|
+
return "di";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isMountableClassification(classification: ArtifactClassification | null | undefined): boolean {
|
|
30
|
+
return Boolean(classification) && [
|
|
31
|
+
"hmr:controller",
|
|
32
|
+
"hmr:socket",
|
|
33
|
+
"hmr:mcp",
|
|
34
|
+
"hmr:scheduler",
|
|
35
|
+
].includes(classification!.channel);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MountArtifactOptions {
|
|
39
|
+
origin: ArtifactOrigin;
|
|
40
|
+
file?: string;
|
|
41
|
+
package?: string;
|
|
42
|
+
/** Reject a DI name collision instead of silently keeping the existing class. */
|
|
43
|
+
strictInjectables?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reuse the existing compilers to mount an already imported artifact. This is
|
|
48
|
+
* the single path shared by the suffix scan and the artifact bridge.
|
|
49
|
+
*/
|
|
50
|
+
export async function mountArtifact(
|
|
51
|
+
construct: ConstructorType,
|
|
52
|
+
kind: ArtifactKind,
|
|
53
|
+
application: ApplicationInterface,
|
|
54
|
+
options: MountArtifactOptions,
|
|
55
|
+
): Promise<MountedArtifactRecord> {
|
|
56
|
+
const name = construct.name || (construct as any).constructor?.name || "AnonymousArtifact";
|
|
57
|
+
|
|
58
|
+
if (kind === "di") {
|
|
59
|
+
const adopted = Injection.adopt(construct);
|
|
60
|
+
if (adopted.status === "collision" && options.strictInjectables) {
|
|
61
|
+
const previousFile = adopted.existing
|
|
62
|
+
? Injection.getArtifactPath(adopted.name)
|
|
63
|
+
: undefined;
|
|
64
|
+
throw new BridgeError("BRIDGE_NAME_COLLISION", {
|
|
65
|
+
message: `Injection name "${adopted.name}" is already used by another class`,
|
|
66
|
+
action: "Rename one of the classes or declare a unique name with @Injectable(lifetime, \"vendor:name\").",
|
|
67
|
+
location: options.file ?? previousFile,
|
|
68
|
+
entry: name,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (options.file) Injection.registerArtifactPath(adopted.name || name, options.file);
|
|
72
|
+
const record: MountedArtifactRecord = {
|
|
73
|
+
key: artifactKey({kind, name: adopted.name || name, file: options.file, package: options.package}),
|
|
74
|
+
name: adopted.name || name,
|
|
75
|
+
kind,
|
|
76
|
+
origin: options.origin,
|
|
77
|
+
construct,
|
|
78
|
+
...(options.file ? {file: options.file} : {}),
|
|
79
|
+
...(options.package ? {package: options.package} : {}),
|
|
80
|
+
};
|
|
81
|
+
return ArtifactRegistry.add(record);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const adopted = Injection.adopt(construct);
|
|
85
|
+
if (adopted.status === "collision" && options.strictInjectables) {
|
|
86
|
+
throw new BridgeError("BRIDGE_NAME_COLLISION", {
|
|
87
|
+
message: `Injection name "${adopted.name}" is already used by another class`,
|
|
88
|
+
action: "Rename one of the classes or declare a unique name with @Injectable(lifetime, \"vendor:name\").",
|
|
89
|
+
location: options.file,
|
|
90
|
+
entry: name,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (options.file) Injection.registerArtifactPath(name, options.file);
|
|
94
|
+
|
|
95
|
+
let routes: any[] | undefined;
|
|
96
|
+
|
|
97
|
+
if (kind === "controller") {
|
|
98
|
+
compileController(construct, application, {
|
|
99
|
+
origin: options.origin === "scan" ? "scan" : "bridge",
|
|
100
|
+
...(options.origin === "scan" ? {} : {trackerKey: `bridge:${name}`}),
|
|
101
|
+
});
|
|
102
|
+
routes = ControllerRouteTracker.getRoutes(
|
|
103
|
+
name,
|
|
104
|
+
options.origin === "scan" ? "scan" : "bridge",
|
|
105
|
+
options.origin === "scan" ? undefined : `bridge:${name}`,
|
|
106
|
+
);
|
|
107
|
+
} else if (kind === "socket") {
|
|
108
|
+
compileSocket(construct);
|
|
109
|
+
} else if (kind === "mcp") {
|
|
110
|
+
compileMcp(construct);
|
|
111
|
+
} else if (kind === "scheduler") {
|
|
112
|
+
compileScheduler(construct);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const record: MountedArtifactRecord = {
|
|
116
|
+
key: artifactKey({kind, name, file: options.file, package: options.package}),
|
|
117
|
+
name,
|
|
118
|
+
kind,
|
|
119
|
+
origin: options.origin,
|
|
120
|
+
construct,
|
|
121
|
+
...(options.file ? {file: options.file} : {}),
|
|
122
|
+
...(options.package ? {package: options.package} : {}),
|
|
123
|
+
...(routes ? {routes} : {}),
|
|
124
|
+
};
|
|
125
|
+
return ArtifactRegistry.add(record);
|
|
126
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {METADATA_KEYS} from "../../framework/constants/decorators.constant.ts";
|
|
2
|
+
import type {ArtifactKind, ArtifactBridgeDefinition} from "../../types/bridge.ts";
|
|
3
|
+
import type {ConstructorType} from "../../types/contruct.ts";
|
|
4
|
+
|
|
5
|
+
export type ClassifiedConstruct = {
|
|
6
|
+
construct: ConstructorType;
|
|
7
|
+
name: string;
|
|
8
|
+
kind: ArtifactKind;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function isClass(value: unknown): value is ConstructorType {
|
|
12
|
+
if (typeof value !== "function") return false;
|
|
13
|
+
if (!/^\s*class[\s{]/.test(Function.prototype.toString.call(value))) return false;
|
|
14
|
+
try {
|
|
15
|
+
Reflect.construct(Object, [], value);
|
|
16
|
+
return true;
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function metadataOf(key: symbol, construct: any): any {
|
|
23
|
+
const prototype = construct?.prototype;
|
|
24
|
+
return (prototype ? Reflect.getMetadata(key, prototype) : undefined)
|
|
25
|
+
?? Reflect.getMetadata(key, construct);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasControllerMetadata(construct: any): boolean {
|
|
29
|
+
const metadata = metadataOf(METADATA_KEYS.CONTROLLERS, construct);
|
|
30
|
+
return Boolean(metadata)
|
|
31
|
+
&& (Array.isArray(metadata.routes) || Object.prototype.hasOwnProperty.call(metadata, "prefix"));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Classify a class from decorator metadata only. Suffix classification remains
|
|
36
|
+
* authoritative for scanned files; this function is used by the bridge and by
|
|
37
|
+
* multi-artifact module resolution.
|
|
38
|
+
*/
|
|
39
|
+
export function classifyConstruct(construct: unknown): ClassifiedConstruct | null {
|
|
40
|
+
if (typeof construct !== "function") return null;
|
|
41
|
+
const name = (construct as any).name || (construct as any).constructor?.name;
|
|
42
|
+
if (!name) return null;
|
|
43
|
+
|
|
44
|
+
if (hasControllerMetadata(construct)) {
|
|
45
|
+
return {construct: construct as ConstructorType, name, kind: "controller"};
|
|
46
|
+
}
|
|
47
|
+
if (metadataOf(METADATA_KEYS.SOCKETS, construct)) {
|
|
48
|
+
return {construct: construct as ConstructorType, name, kind: "socket"};
|
|
49
|
+
}
|
|
50
|
+
if (metadataOf(METADATA_KEYS.MCP, construct)) {
|
|
51
|
+
return {construct: construct as ConstructorType, name, kind: "mcp"};
|
|
52
|
+
}
|
|
53
|
+
if (metadataOf(METADATA_KEYS.SCHEDULER, construct)) {
|
|
54
|
+
return {construct: construct as ConstructorType, name, kind: "scheduler"};
|
|
55
|
+
}
|
|
56
|
+
if (metadataOf(METADATA_KEYS.CONTAINER, construct)) {
|
|
57
|
+
return {construct: construct as ConstructorType, name, kind: "di"};
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isBridgeDefinition(value: unknown): value is ArtifactBridgeDefinition {
|
|
63
|
+
return Boolean(value)
|
|
64
|
+
&& typeof value === "object"
|
|
65
|
+
&& Array.isArray((value as any).artifacts);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function moduleExports(imported: any): any[] {
|
|
69
|
+
if (!imported || typeof imported !== "object") return [imported];
|
|
70
|
+
const values = Object.values(imported);
|
|
71
|
+
if ("default" in imported && !values.includes(imported.default)) values.push(imported.default);
|
|
72
|
+
return values;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ResolveArtifactsOptions {
|
|
76
|
+
kinds?: ArtifactKind[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ResolvedModuleArtifact {
|
|
80
|
+
name: string;
|
|
81
|
+
kind: ArtifactKind;
|
|
82
|
+
construct: ConstructorType;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Plural counterpart of `resolveArtifact()`: inspect every named export and
|
|
87
|
+
* the default export, keep all decorated classes and deduplicate by identity.
|
|
88
|
+
*/
|
|
89
|
+
export function resolveArtifacts(
|
|
90
|
+
imported: any,
|
|
91
|
+
options: ResolveArtifactsOptions = {},
|
|
92
|
+
): ResolvedModuleArtifact[] {
|
|
93
|
+
const kinds = options.kinds ? new Set(options.kinds) : null;
|
|
94
|
+
const output: ResolvedModuleArtifact[] = [];
|
|
95
|
+
const seen = new Set<unknown>();
|
|
96
|
+
|
|
97
|
+
for (const candidate of moduleExports(imported)) {
|
|
98
|
+
if (seen.has(candidate)) continue;
|
|
99
|
+
seen.add(candidate);
|
|
100
|
+
const classified = classifyConstruct(candidate);
|
|
101
|
+
if (!classified) continue;
|
|
102
|
+
if (kinds && !kinds.has(classified.kind)) continue;
|
|
103
|
+
output.push(classified);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return output;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function exportNames(imported: any): string[] {
|
|
110
|
+
if (!imported || typeof imported !== "object") return [];
|
|
111
|
+
return Object.keys(imported);
|
|
112
|
+
}
|