@supacloud/compiler 0.3.1 → 0.4.1

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/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * ApplicationGraph:编译器从源码 AST 构建出的静态应用图。
3
- * 运行期不反射、无容器,所有信息都在该结构与生成代码中显式给出。
2
+ * ApplicationGraph: Static application graph built by the compiler from source AST.
3
+ * No runtime reflection or container; all metadata is explicitly represented here and in generated code.
4
4
  */
5
5
  export type Scope = "application" | "request" | "job";
6
6
  export type ProviderKind = "class" | "value" | "factory" | "existing";
@@ -13,7 +13,7 @@ export interface Diagnostic {
13
13
  line?: number;
14
14
  }
15
15
  export interface ProviderNode {
16
- /** token 名(InjectionToken 变量名或类名)。 */
16
+ /** Token name (InjectionToken variable name or class name). */
17
17
  token: string;
18
18
  tokenKind: TokenKind;
19
19
  kind: ProviderKind;
@@ -22,16 +22,16 @@ export interface ProviderNode {
22
22
  useFactoryName?: string;
23
23
  useExisting?: string;
24
24
  scope: Scope;
25
- /** token 名,构造/工厂参数顺序。 */
25
+ /** Token names in constructor/factory parameter order. */
26
26
  deps: string[];
27
27
  exported: boolean;
28
28
  file: string;
29
29
  line: number;
30
- /** useClass/useFactory/useValue 符号的模块相对路径(供生成 import)。 */
30
+ /** Relative module path of useClass/useFactory/useValue symbol (for import generation). */
31
31
  importPath?: string;
32
32
  }
33
33
  export interface RouteNode {
34
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
34
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
35
35
  path: string;
36
36
  handler: string;
37
37
  body?: string;
@@ -49,7 +49,7 @@ export interface ControllerNode {
49
49
  routes: RouteNode[];
50
50
  file: string;
51
51
  importPath: string;
52
- /** 路由 schema 符号名 → 模块相对路径(供生成 import)。 */
52
+ /** Route schema symbol name -> relative module path (for import generation). */
53
53
  schemaImports?: Record<string, string>;
54
54
  }
55
55
  export interface CommandNode {
@@ -65,60 +65,114 @@ export interface QueryNode {
65
65
  name: string;
66
66
  }
67
67
  export interface ModuleNode {
68
- /** @Module({ name }) 或 defineModule 的 name。 */
68
+ /** Name from @Module({ name }) or defineModule. */
69
69
  name: string;
70
70
  className: string;
71
- /** 模块标签(如 ['scope:case', 'type:feature']),用于架构边界治理。 */
71
+ /** Module tags (e.g. ['scope:case', 'type:feature']) for architecture boundary governance. */
72
72
  tags?: string[];
73
73
  file: string;
74
74
  line: number;
75
- /** 被 import 模块的 name。 */
75
+ /** Names of imported modules. */
76
76
  imports: string[];
77
77
  providers: ProviderNode[];
78
78
  controllers: ControllerNode[];
79
79
  commands: CommandNode[];
80
80
  queries: QueryNode[];
81
- /** 导出的 token 名。 */
81
+ /** Exported token names. */
82
82
  exports: string[];
83
83
  }
84
84
  export interface ApplicationGraph {
85
85
  modules: ModuleNode[];
86
- /** 被依赖但无任何模块提供的 token 名(平台注入)。 */
86
+ /** Depended token names provided by platform injection rather than any module. */
87
87
  externalTokens: string[];
88
88
  /**
89
- * 分析阶段产生的诊断(如 missing-deps),由 compileProject 合并进结果。
90
- * 不写入 app.manifest.json。
89
+ * Diagnostics produced during analysis (e.g. missing-deps), merged by compileProject.
90
+ * Omitted from app.manifest.json.
91
91
  */
92
92
  diagnostics?: Diagnostic[];
93
93
  /**
94
- * InjectionToken 变量名 → 字符串 name(如 REQUEST_CONTEXT →
95
- * "supacloud.request-context"),供代码生成识别内置上下文 token。
96
- * 不写入 app.manifest.json。
94
+ * InjectionToken variable name -> string name (e.g. REQUEST_CONTEXT ->
95
+ * "supacloud.request-context"), used during code generation to identify built-in context tokens.
96
+ * Omitted from app.manifest.json.
97
97
  */
98
98
  tokenNames?: Record<string, string>;
99
99
  }
100
100
  export interface CompileOptions {
101
- /** 项目根(含 tsconfig)。 */
101
+ /** Project root directory (containing tsconfig). */
102
102
  rootDir: string;
103
- /** glob,默认 ['**\/*.module.ts', '**\/*.ts']。 */
103
+ /** Glob patterns, defaults to ['**\/*.module.ts', '**\/*.ts']. */
104
104
  include?: string[];
105
- /** 生成目录(如 <rootDir>/generated)。 */
105
+ /** Output directory (e.g. <rootDir>/generated). */
106
106
  outDir: string;
107
- /** warn 级诊断升级为 error。 */
107
+ /** Upgrade warn-level diagnostics to error. */
108
108
  strict?: boolean;
109
- /** 模块边界与架构治理规则(受 Nx enforce-module-boundaries 启发)。 */
109
+ /** Built-in architecture boundary preset (for example, 'modular-monolith'). */
110
+ moduleBoundaryPreset?: ModuleBoundaryPresetName;
111
+ /** Module boundary and architecture governance rules inspired by Nx enforce-module-boundaries. */
110
112
  moduleBoundaries?: ModuleBoundaryRule[];
113
+ /** Allow routes to bind directly to @Command (defaults to true). */
114
+ allowRouteCommandBindings?: boolean;
115
+ /** Runtime Command executor capabilities used to validate declared governance metadata. */
116
+ commandCapabilities?: CommandExecutionCapabilities;
117
+ /** Disallow controllers from directly injecting DB clients (enforces presentation layer separation). */
118
+ disallowControllerDirectDb?: boolean;
119
+ /** Detect modules declared in the project that are unreachable from any root module. */
120
+ detectOrphanModules?: boolean;
111
121
  }
112
122
  export interface ModuleBoundaryRule {
113
- /** 源模块标签模式或标签(如 'type:ui', 'scope:case', '*')。 */
123
+ /** Source module tag pattern or tag (for example, 'type:ui', 'scope:case', or '*'). */
114
124
  sourceTag: string;
115
- /** 源模块仅允许依赖具有这些标签的模块。 */
125
+ /** Tags allowed for modules imported by the source module. */
116
126
  onlyDependOnLibsWithTags?: string[];
117
- /** 源模块禁止依赖具有这些标签的模块。 */
127
+ /** Tags forbidden for modules imported by the source module. */
118
128
  bannedDependenciesWithTags?: string[];
119
129
  }
130
+ /** Names of built-in module boundary presets. */
131
+ export type ModuleBoundaryPresetName = "modular-monolith" | "feature-slices" | "vertical-slices" | "angular-enterprise" | "angular" | "clean-architecture" | "domain-driven";
132
+ export interface ModuleBoundaryProfile {
133
+ name: ModuleBoundaryPresetName;
134
+ description: string;
135
+ rules: ModuleBoundaryRule[];
136
+ }
137
+ export interface ValidateOptions {
138
+ strict?: boolean;
139
+ moduleBoundaryPreset?: ModuleBoundaryPresetName;
140
+ moduleBoundaries?: ModuleBoundaryRule[];
141
+ /** Allow routes to bind directly to @Command (defaults to true). */
142
+ allowRouteCommandBindings?: boolean;
143
+ /** Runtime Command executor capabilities used to validate declared governance metadata. */
144
+ commandCapabilities?: CommandExecutionCapabilities;
145
+ /** Disallow controllers from directly injecting DB clients. */
146
+ disallowControllerDirectDb?: boolean;
147
+ /** Detect modules declared in the project that are unreachable from any root module. */
148
+ detectOrphanModules?: boolean;
149
+ }
150
+ /** Runtime capabilities declared by the Command executor. */
151
+ export interface CommandExecutionCapabilities {
152
+ /** Whether runtime permission checks are supported. */
153
+ permission?: boolean;
154
+ /** Whether runtime audit persistence is supported. */
155
+ audit?: boolean;
156
+ /** Whether idempotency receipts are supported. */
157
+ idempotency?: boolean;
158
+ /**
159
+ * Transaction execution capability:
160
+ * - true: full transaction boundaries are supported;
161
+ * - 'rpc-only': application-level transactions are unavailable and multi-table writes must use one DB RPC (warn);
162
+ * - false: transaction support is disabled (error).
163
+ */
164
+ transaction?: boolean | "rpc-only";
165
+ }
120
166
  export interface CompileResult {
121
167
  diagnostics: Diagnostic[];
122
168
  graph: ApplicationGraph;
123
169
  written: string[];
124
170
  }
171
+ export interface CheckProjectResult {
172
+ /** Whether generated artifacts exactly match the files on disk. */
173
+ upToDate: boolean;
174
+ /** Relative paths of missing or mismatched artifacts. */
175
+ mismatches: string[];
176
+ diagnostics: Diagnostic[];
177
+ graph: ApplicationGraph;
178
+ }
package/dist/util.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  /**
2
- * token 名 → services 对象的 key。
3
- * CASE_REPOSITORY → caseRepository、LOGGER → logger(常量命名转 camelCase),
4
- * CaseService → caseService(PascalCase 首字母小写)。
2
+ * Token name -> key in services object.
3
+ * CASE_REPOSITORY -> caseRepository, LOGGER -> logger (convert CONSTANT_CASE to camelCase),
4
+ * CaseService -> caseService (lowercase first letter of PascalCase).
5
5
  */
6
6
  export declare function camelName(token: string): string;
7
- /** 计算 from 目录到 to 文件的相对 import 路径(去扩展名,保证 ./ 或 ../ 前缀)。 */
7
+ /** Computes relative import path from fromDir to toFile (stripping extension, ensuring ./ or ../ prefix). */
8
8
  export declare function relativeImportPath(fromDir: string, toFile: string): string;
9
- /** 内置上下文 token 的字符串 name(与 @supacloud/app 的 REQUEST_CONTEXT/JOB_CONTEXT 对齐)。 */
9
+ /** String names of built-in context tokens (aligned with REQUEST_CONTEXT/JOB_CONTEXT in @supacloud/app). */
10
10
  export declare const REQUEST_CONTEXT_TOKEN_NAME = "supacloud.request-context";
11
11
  export declare const JOB_CONTEXT_TOKEN_NAME = "supacloud.job-context";
12
- /** 判断 token 是否为内置 request 上下文(变量名 REQUEST_CONTEXT 或 token name 匹配)。 */
12
+ /** Determines whether token is built-in request context (variable name REQUEST_CONTEXT or matching token name). */
13
13
  export declare function isRequestContextToken(token: string, tokenNames?: Record<string, string>): boolean;
14
- /** 判断 token 是否为内置 job 上下文。 */
14
+ /** Determines whether token is built-in job context. */
15
15
  export declare function isJobContextToken(token: string, tokenNames?: Record<string, string>): boolean;
@@ -1,9 +1,6 @@
1
- import type { ApplicationGraph, Diagnostic, ModuleBoundaryRule } from "./types";
1
+ import type { ApplicationGraph, Diagnostic, ValidateOptions } from "./types";
2
2
  /**
3
- * 校验 ApplicationGraph,产出诊断列表。
4
- * strict 时 warn 级诊断升级为 error。
3
+ * Validates ApplicationGraph and produces diagnostics list.
4
+ * In strict mode, warn-level diagnostics are promoted to error.
5
5
  */
6
- export declare function validateGraph(graph: ApplicationGraph, options?: boolean | {
7
- strict?: boolean;
8
- moduleBoundaries?: ModuleBoundaryRule[];
9
- }): Diagnostic[];
6
+ export declare function validateGraph(graph: ApplicationGraph, options?: boolean | ValidateOptions): Diagnostic[];
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@supacloud/compiler",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
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",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "supacloud-compiler": "./dist/cli.js"
11
+ },
9
12
  "exports": {
10
13
  ".": {
11
14
  "types": "./dist/index.d.ts",
@@ -19,7 +22,7 @@
19
22
  ],
20
23
  "scripts": {
21
24
  "build": "bun run clean && bun run build:js && bun run build:types",
22
- "build:js": "bun build src/index.ts --outdir dist --target node --external ts-morph",
25
+ "build:js": "bun build src/index.ts src/cli.ts --outdir dist --target node --external ts-morph",
23
26
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
24
27
  "clean": "rm -rf dist",
25
28
  "prepublishOnly": "bun run build",