@supacloud/compiler 0.9.0 → 0.10.0
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/README.md +5 -0
- package/dist/cli.js +12 -5
- package/dist/index.js +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,11 @@ bun add @supacloud/compiler
|
|
|
12
12
|
|
|
13
13
|
## 零配置项目
|
|
14
14
|
|
|
15
|
+
需要完整运行入口时,使用 `supacloud-cli app init --root ./orders --name orders`。
|
|
16
|
+
模板将本包放在 `devDependencies`,预置状态规格、治理能力、类型检查和本地测试。
|
|
17
|
+
编译产物的 HTTP method / scope 保留字面量联合类型,可直接传给 Elysia 适配器;
|
|
18
|
+
跨运行时依赖字典使用构造器/工厂参数类型连接,局部依赖保留类型推断和错误检查。
|
|
19
|
+
|
|
15
20
|
在项目根目录执行:
|
|
16
21
|
|
|
17
22
|
```bash
|
package/dist/cli.js
CHANGED
|
@@ -2264,7 +2264,7 @@ import { access, mkdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
|
2264
2264
|
import { join as join2 } from "node:path";
|
|
2265
2265
|
var HEADER = "// GENERATED BY @supacloud/compiler — do not edit";
|
|
2266
2266
|
var INTERFACES = `export interface CompiledRoute {
|
|
2267
|
-
method:
|
|
2267
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
2268
2268
|
path: string;
|
|
2269
2269
|
handler: string;
|
|
2270
2270
|
body?: unknown;
|
|
@@ -2335,7 +2335,7 @@ export type CompiledAspect = (
|
|
|
2335
2335
|
export interface CompiledController {
|
|
2336
2336
|
path: string;
|
|
2337
2337
|
serviceKey: string;
|
|
2338
|
-
scope:
|
|
2338
|
+
scope: "application" | "request" | "job";
|
|
2339
2339
|
routes: CompiledRoute[];
|
|
2340
2340
|
}
|
|
2341
2341
|
|
|
@@ -2949,7 +2949,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
2949
2949
|
switch (provider.kind) {
|
|
2950
2950
|
case "class": {
|
|
2951
2951
|
const useClass = this.imports.add(provider.useClass ?? provider.token, provider.importPath, provider.importModule);
|
|
2952
|
-
const args = provider.deps.map((dep) => this.
|
|
2952
|
+
const args = provider.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(provider, dep), `ConstructorParameters<typeof ${useClass}>[${index}]`)).join(", ");
|
|
2953
2953
|
const local = this.localVar(isMulti ? provider.useClass ?? `${provider.token}Item` : provider.token, kind);
|
|
2954
2954
|
return {
|
|
2955
2955
|
constLine: `const ${local} = ${this.instantiate(useClass, args, kind, provider.functionalInjects)};`,
|
|
@@ -2970,7 +2970,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
2970
2970
|
return { constLine, key, expr: local2 };
|
|
2971
2971
|
}
|
|
2972
2972
|
const factory = this.imports.add(provider.useFactoryName ?? "", provider.importPath, provider.importModule);
|
|
2973
|
-
const args = provider.deps.map((dep) => this.
|
|
2973
|
+
const args = provider.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(provider, dep), `Parameters<typeof ${factory}>[${index}]`)).join(", ");
|
|
2974
2974
|
const local = this.localVar(isMulti ? provider.useFactoryName ?? `${provider.token}Item` : provider.token, kind);
|
|
2975
2975
|
return { constLine: `const ${local} = ${factory}(${args});`, key, expr: local };
|
|
2976
2976
|
}
|
|
@@ -2984,7 +2984,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
2984
2984
|
}
|
|
2985
2985
|
emitController(controller, kind) {
|
|
2986
2986
|
const className = this.imports.add(controller.className, controller.importPath);
|
|
2987
|
-
const args = controller.deps.map((dep) => this.
|
|
2987
|
+
const args = controller.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(controller, dep), `ConstructorParameters<typeof ${className}>[${index}]`)).join(", ");
|
|
2988
2988
|
const key = camelName(controller.className);
|
|
2989
2989
|
const local = this.localVar(controller.className, kind);
|
|
2990
2990
|
return {
|
|
@@ -3042,6 +3042,13 @@ ${indent(item, 2)}`).join(",")}
|
|
|
3042
3042
|
host: "hostDeps" in node ? node.hostDeps?.includes(token) ?? false : false
|
|
3043
3043
|
};
|
|
3044
3044
|
}
|
|
3045
|
+
typedDepExpr(token, kind, options, type) {
|
|
3046
|
+
const expression = this.depExpr(token, kind, options);
|
|
3047
|
+
const localProvider = this.module.providers.find((provider) => this.locals[kind].get(provider.token) === expression);
|
|
3048
|
+
if (expression === "undefined" || localProvider && !(localProvider.kind === "factory" && !localProvider.useFactoryName))
|
|
3049
|
+
return expression;
|
|
3050
|
+
return `${expression} as ${type}`;
|
|
3051
|
+
}
|
|
3045
3052
|
depExpr(token, kind, options = {}) {
|
|
3046
3053
|
const isOptional = options.optional ?? false;
|
|
3047
3054
|
const isSelf = options.self ?? false;
|
package/dist/index.js
CHANGED
|
@@ -2545,7 +2545,7 @@ import { access, mkdir, rename as rename2, unlink as unlink2, writeFile as write
|
|
|
2545
2545
|
import { join as join2 } from "node:path";
|
|
2546
2546
|
var HEADER = "// GENERATED BY @supacloud/compiler — do not edit";
|
|
2547
2547
|
var INTERFACES = `export interface CompiledRoute {
|
|
2548
|
-
method:
|
|
2548
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
2549
2549
|
path: string;
|
|
2550
2550
|
handler: string;
|
|
2551
2551
|
body?: unknown;
|
|
@@ -2616,7 +2616,7 @@ export type CompiledAspect = (
|
|
|
2616
2616
|
export interface CompiledController {
|
|
2617
2617
|
path: string;
|
|
2618
2618
|
serviceKey: string;
|
|
2619
|
-
scope:
|
|
2619
|
+
scope: "application" | "request" | "job";
|
|
2620
2620
|
routes: CompiledRoute[];
|
|
2621
2621
|
}
|
|
2622
2622
|
|
|
@@ -3230,7 +3230,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
3230
3230
|
switch (provider.kind) {
|
|
3231
3231
|
case "class": {
|
|
3232
3232
|
const useClass = this.imports.add(provider.useClass ?? provider.token, provider.importPath, provider.importModule);
|
|
3233
|
-
const args = provider.deps.map((dep) => this.
|
|
3233
|
+
const args = provider.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(provider, dep), `ConstructorParameters<typeof ${useClass}>[${index}]`)).join(", ");
|
|
3234
3234
|
const local = this.localVar(isMulti ? provider.useClass ?? `${provider.token}Item` : provider.token, kind);
|
|
3235
3235
|
return {
|
|
3236
3236
|
constLine: `const ${local} = ${this.instantiate(useClass, args, kind, provider.functionalInjects)};`,
|
|
@@ -3251,7 +3251,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
3251
3251
|
return { constLine, key, expr: local2 };
|
|
3252
3252
|
}
|
|
3253
3253
|
const factory2 = this.imports.add(provider.useFactoryName ?? "", provider.importPath, provider.importModule);
|
|
3254
|
-
const args = provider.deps.map((dep) => this.
|
|
3254
|
+
const args = provider.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(provider, dep), `Parameters<typeof ${factory2}>[${index}]`)).join(", ");
|
|
3255
3255
|
const local = this.localVar(isMulti ? provider.useFactoryName ?? `${provider.token}Item` : provider.token, kind);
|
|
3256
3256
|
return { constLine: `const ${local} = ${factory2}(${args});`, key, expr: local };
|
|
3257
3257
|
}
|
|
@@ -3265,7 +3265,7 @@ ${indent(item, 2)}`).join(",")}
|
|
|
3265
3265
|
}
|
|
3266
3266
|
emitController(controller, kind) {
|
|
3267
3267
|
const className = this.imports.add(controller.className, controller.importPath);
|
|
3268
|
-
const args = controller.deps.map((dep) => this.
|
|
3268
|
+
const args = controller.deps.map((dep, index) => this.typedDepExpr(dep, kind, this.depOptions(controller, dep), `ConstructorParameters<typeof ${className}>[${index}]`)).join(", ");
|
|
3269
3269
|
const key = camelName(controller.className);
|
|
3270
3270
|
const local = this.localVar(controller.className, kind);
|
|
3271
3271
|
return {
|
|
@@ -3323,6 +3323,13 @@ ${indent(item, 2)}`).join(",")}
|
|
|
3323
3323
|
host: "hostDeps" in node ? node.hostDeps?.includes(token) ?? false : false
|
|
3324
3324
|
};
|
|
3325
3325
|
}
|
|
3326
|
+
typedDepExpr(token, kind, options, type) {
|
|
3327
|
+
const expression = this.depExpr(token, kind, options);
|
|
3328
|
+
const localProvider = this.module.providers.find((provider) => this.locals[kind].get(provider.token) === expression);
|
|
3329
|
+
if (expression === "undefined" || localProvider && !(localProvider.kind === "factory" && !localProvider.useFactoryName))
|
|
3330
|
+
return expression;
|
|
3331
|
+
return `${expression} as ${type}`;
|
|
3332
|
+
}
|
|
3326
3333
|
depExpr(token, kind, options = {}) {
|
|
3327
3334
|
const isOptional = options.optional ?? false;
|
|
3328
3335
|
const isSelf = options.self ?? false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Static compiler for @supacloud/app metadata: builds the application graph from AST, validates it, and generates reflection-free factory code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|