@supacloud/compiler 0.11.0 → 0.13.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 CHANGED
@@ -1,9 +1,95 @@
1
1
  # @supacloud/compiler
2
2
 
3
+ FA-derived direct-command RPC ownership, contract inspection and POST command
4
+ protocol migration are documented in `docs/fa-consumer-governance.md` in the
5
+ repository. `context <module> --json` reports `routeContracts` and standalone
6
+ command execution plans; these are declarations and obligations, not runtime proof.
7
+
3
8
  SupaCloud 应用静态编译器:读取 `@supacloud/app` 装饰器元数据的原生 TypeScript AST,构建 ApplicationGraph,做静态校验,并生成**无反射、无容器**的工厂代码与 manifest。
4
9
 
5
10
  本包不依赖 `@supacloud/app`:AST 只按装饰器名匹配(`Module`/`Injectable`/`Inject`/`Command`/`Query`/`Controller`/`Get`/`Post`/`Put`/`Patch`/`Delete`/`defineModule`/`InjectionToken`),不校验 import 来源。
6
11
 
12
+ ## Recommended GraphQL Query Contracts
13
+
14
+ **Database First is the only server-schema model.** Drizzle and SQL declarations
15
+ are migrated to PostgreSQL; `pg_graphql` reflects the actual database, and
16
+ `graphql-schema` exports the intended role's snapshot. Author queries/fragments,
17
+ not GraphQL resolver classes or a separate server SDL. `graphql.schema` accepts
18
+ only local `.graphql`, `.gql` or `.json` snapshots; executable sources, URLs and
19
+ schema-authoring options such as `autoSchemaFile`, `typePaths`, `resolvers` or
20
+ `mode` are rejected. Snapshot formats and TypedDocumentNode output are not
21
+ alternative authoring modes.
22
+
23
+ Do not edit exported snapshots. Change database declarations, apply migrations,
24
+ export again and compile. Offline compilation cannot attest a snapshot's origin;
25
+ `graphql-schema --check` against the intended database detects local/remote drift.
26
+ The starter's synthetic SDL is solely an offline test fixture, not a deployed
27
+ schema. Replace it with a database export before integration.
28
+
29
+ New `supacloud app init` projects preconfigure GraphQL query contracts and include
30
+ an offline example. Existing REST, Command-only and background-task projects
31
+ remain unchanged: general App/CLI configuration and `compileProject(options)`
32
+ only enable this pipeline when `graphql` is explicitly configured. Enabled
33
+ contracts always reject invalid queries and missing schemas, even with
34
+ `strict: false` or `--no-strict`. Choosing `graphql: false` (or `--no-graphql` for
35
+ one compiler run) disables adoption, not just validation of individual queries.
36
+ The platform extension is still opt-in; compilation changes no database grants,
37
+ extensions or production introspection settings.
38
+
39
+ ```ts
40
+ export default defineSupacloudConfig({
41
+ root: "src",
42
+ graphql: { schema: "graphql/schema.graphql" },
43
+ });
44
+ ```
45
+
46
+ The schema path is configuration-relative, query globs are source-root-relative.
47
+ Normal `compile`, `check`, `dev` and `context` handle the local snapshot and
48
+ queries offline. Invalid fields/variables, unnamed operations, mutations and
49
+ subscriptions produce structured diagnostics; failures preserve working output.
50
+ GraphQL.js and GraphQL Code Generator own parsing, validation and operation types.
51
+ Unknown custom scalars stay `unknown` unless explicitly mapped via `graphql.scalars`.
52
+
53
+ ```sh
54
+ supacloud-compiler graphql-schema --url https://your-project.example \
55
+ --key-env SUPACLOUD_PUBLISHABLE_KEY --token-env APP_USER_ACCESS_TOKEN
56
+ supacloud-compiler compile
57
+ supacloud-compiler check --json
58
+ ```
59
+
60
+ Export is explicit and requires introspection already enabled in the selected
61
+ development project. Flags name environment variables, not secrets. Use the
62
+ intended caller role, never a privileged service-role schema for browser queries.
63
+ After migrations, use the same export command with `--check --json` to detect
64
+ remote schema drift without overwriting the local snapshot (exit 1 on drift).
65
+ Refresh intentionally, then run compile/check and the application's typecheck
66
+ and role/RLS tests. This remote gate requires development introspection; offline
67
+ compilation does not require production introspection.
68
+
69
+ Set `graphql.typedDocuments: true` to additionally generate
70
+ `graphql.documents.ts` using the standard TypedDocumentNode Codegen plugin.
71
+ Consumers of that optional file must install `@graphql-typed-document-node/core`;
72
+ it provides `ResultOf` and `VariablesOf` for operation-level inference. The default
73
+ fetch client still needs no GraphQL runtime dependency.
74
+
75
+ ```ts
76
+ import { createGraphqlClient } from "./generated/graphql";
77
+ const queries = createGraphqlClient({
78
+ url: projectUrl,
79
+ publishableKey,
80
+ getAccessToken: readCurrentUserToken,
81
+ });
82
+ const result = await queries.ReviewList({ first: 20 });
83
+ ```
84
+
85
+ Method names and types come from named operations. The generated client is
86
+ dependency-free and refreshes identity per request; `getSdk(requester)` integrates
87
+ an existing transport. It rejects HTTP errors, GraphQL errors and malformed
88
+ response envelopes, but does not runtime-decode selected field values.
89
+ `graphql.manifest.json` records query locations and the schema hash; context packs
90
+ include colocated queries. RLS/grants, real database acceptance and query resource
91
+ limits remain deployment responsibilities. Business writes stay in Commands.
92
+
7
93
  ## 安装
8
94
 
9
95
  ```bash
@@ -185,6 +271,7 @@ IDE 和 AI agent 做状态机漂移检查。
185
271
  | `unsupported-provider-helper` | warn(strict 时 error) | functional provider 的动态参数无法安全展开为静态 factory |
186
272
  | `dynamic-aspect-reference` | error | aspects 不是显式数组字面量,或包含 spread/表达式/字符串 pointcut |
187
273
  | `invalid-aspect-reference` | error | aspect 不是可静态解析的函数声明、箭头函数或函数表达式 |
274
+ | `invalid-command-mode` | error | transaction/idempotency 必须显式为 `"required"` 或 `"none"`,不允许拼写错误或动态值悄悄关闭治理(SC4012) |
188
275
  | `missing-deps` | warn(strict 时 error) | 构造/工厂依赖无法静态解析 |
189
276
  | `generated-any` | warn(strict 时 error) | 生成的 TypeScript 产物包含 `any` |
190
277
  | `source-any` | warn(strict 时 error) | 未被排除的生产源码包含显式 `any` |
@@ -211,7 +298,7 @@ supacloud-compiler check --root ./app --out ./app/generated --strict
211
298
  supacloud-compiler dev --root . --out ./generated
212
299
  ```
213
300
 
214
- 开发模式默认对源码变化做 100ms 防抖,并只监听 TypeScript 文件。编译器会复用进程内的源码快照:相同输入直接命中缓存;只改动普通实现文件时复用既有依赖图和生成物;只有 SupaCloud 元数据、模块声明或依赖相关文件变化时才重建图。编译失败时不会覆盖最后一次成功的 `application.ts` 和 `app.manifest.json`;修复错误后会自动生成新产物。`--debounce <ms>` 可调整防抖时间。
301
+ 开发模式默认对源码变化做 100ms 防抖,监听 TypeScript 文件;启用 GraphQL 后,还监听查询文件和配置的 Schema 快照。编译器会复用进程内的源码快照:相同输入直接命中缓存;只改动普通实现文件时复用既有依赖图和生成物;只有 SupaCloud 元数据、模块声明或依赖相关文件变化时才重建图。编译失败时不会覆盖最后一次成功的 `application.ts` 和 `app.manifest.json`;修复错误后会自动生成新产物。`--debounce <ms>` 可调整防抖时间。
215
302
 
216
303
  ## 图谱与诊断
217
304
 
@@ -238,6 +325,20 @@ supacloud-compiler context case --root ./app --json
238
325
  `supacloud-compiler fix ./fix.json --dry-run` 调用;CLI 默认预览,需显式
239
326
  使用 `--write` 才写盘。写盘前会重新解析 AST,
240
327
  前置条件不满足时拒绝修改,并通过临时文件原子替换。
328
+ CLI 修复的 `targetFile` 相对于配置的源码根目录解析,也可以用 `--root` 显式指定;
329
+ JSON 修复文件本身仍相对于当前工作目录读取。
330
+
331
+ 上下游分别沿单一方向遍历,不会经过共享基础模块再扩散到无关兄弟业务。
332
+ 上下文包还包含准确的切面源文件、校验诊断和 `executionPlans`;`explain <module>`
333
+ 也展示静态执行计划。计划描述标准命令治理;自定义 executor 的内部实现和短路行为
334
+ 仍需运行时追踪验证。成功审计在 handler 返回后执行,而非 handler 之前。
335
+
336
+ 例如 `@Command({ transaction: "requried" })` 会报告 `invalid-command-mode`,
337
+ 并输出 `set_command_mode` 修复建议。必须显式给 fix 的 `value` 选择 `"required"`
338
+ 或 `"none"` 才能预览或写入;不会推断较弱权限。若诊断后的源表达式变化,修复拒绝写盘。
339
+
340
+ `compileProject()` 现在默认在存在 error 时保留已有产物。仅诊断/迁移工具可以显式
341
+ 设置 `writeOnError: true` 导出错误版本;这些产物不应被部署或视为可执行成功产物。
241
342
 
242
343
  ## 编译基准
243
344