@supacloud/compiler 0.14.0 → 0.17.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/DELIVERY.md ADDED
@@ -0,0 +1,223 @@
1
+ # Local Delivery Planning And Builds
2
+
3
+ `supacloud-compiler plan --json` is a read-only first step toward automated app
4
+ delivery. It uses the existing source analysis and compiler checks, then groups
5
+ HTTP routes and declared Jobs into deterministic target previews.
6
+
7
+ `supacloud-compiler build-delivery --json` additionally builds independent local
8
+ module factory bundles. It does **not** configure queues or gateways, verify remote
9
+ hosts, deploy functions, or run an unattended AI repair loop.
10
+ Existing compile/check/dev output remains unchanged.
11
+
12
+ ## Zero-Configuration HTTP
13
+
14
+ ```sh
15
+ supacloud-compiler plan --json
16
+ ```
17
+
18
+ All discovered HTTP routes default to `api`. Module imports contribute dependencies,
19
+ not route ownership. A dependency module's own routes remain with their own explicit
20
+ owner or the default API; they are not copied into the importing target.
21
+ All discovered routes remain exposed in the plan. To make a module private, remove
22
+ its route declarations; simply omitting a module from target configuration does not
23
+ hide its routes.
24
+
25
+ Declared Jobs default to `jobs`, require a durable queue declaration, and default
26
+ to process isolation. A Job declaration does not rewrite a synchronous HTTP route.
27
+ If these runtime declarations are absent, planning returns errors with no plan.
28
+
29
+ ## Explicit Boundaries
30
+
31
+ Add an optional `delivery` section to the existing configuration:
32
+
33
+ ```ts
34
+ import { defineSupacloudConfig } from "@supacloud/compiler";
35
+
36
+ export default defineSupacloudConfig({
37
+ delivery: {
38
+ version: 1,
39
+ targets: [
40
+ { name: "orders", kind: "api", modules: ["orders"] },
41
+ {
42
+ name: "payment-hooks",
43
+ kind: "webhook",
44
+ modules: ["payments"],
45
+ isolation: "process",
46
+ capabilities: ["payments.verify"],
47
+ },
48
+ ],
49
+ runtime: {
50
+ processIsolation: true,
51
+ durableQueue: true,
52
+ capabilities: ["payments.verify"],
53
+ },
54
+ },
55
+ });
56
+ ```
57
+
58
+ The names in `modules` are declared module names, not class names or paths.
59
+ Targets select all routes or all jobs belonging to those modules, depending on
60
+ their kind. HTTP and Job ownership are independent, so one module can contribute
61
+ HTTP to `api` and Jobs to `jobs`. Two HTTP targets cannot both own the same module.
62
+ `api` and `jobs` are reserved for their matching workload kinds.
63
+
64
+ No unused explicit target is accepted. Unknown modules, duplicate ownership,
65
+ unresolved imports, cyclic dependencies, duplicate job names, and conflicting
66
+ method/path patterns reject the plan. Parameter-name aliases such as `/:id` and
67
+ `/:key` do not establish different route identities.
68
+
69
+ `runtime` is a declaration only, not host attestation. `capabilities` contains
70
+ adapter/credential boundary references, never values. Declaring a webhook target
71
+ does not implement signature verification or authorize public ingress. The runtime
72
+ and deployment layers must still verify these requirements before activation.
73
+ Changing `isolation` to `shared` is an explicit relaxation requiring user review.
74
+
75
+ For an AI-generated JSON declaration instead of editing executable config:
76
+
77
+ ```sh
78
+ supacloud-compiler plan --delivery delivery.json --json
79
+ ```
80
+
81
+ `delivery.json` contains the `delivery` object above, not the outer project config.
82
+ It replaces, rather than merges with, `config.delivery`. The executable project
83
+ config is still loaded normally. Invalid configuration is rejected, not echoed.
84
+ `--write` and unknown plan arguments fail. Successful output exits 0; failures exit 1.
85
+
86
+ ## Programmatic Contract
87
+
88
+ ```ts
89
+ import {
90
+ compileOptionsFromConfig,
91
+ loadSupacloudConfig,
92
+ planDeliveryProject,
93
+ parseDeliveryPlanResult,
94
+ } from "@supacloud/compiler";
95
+
96
+ const config = await loadSupacloudConfig();
97
+ const result = await planDeliveryProject(compileOptionsFromConfig(config), config.delivery);
98
+ if (result.ok) {
99
+ for (const target of result.plan.targets) {
100
+ console.log(target.name, target.routes, target.requirements);
101
+ }
102
+ }
103
+
104
+ // File/message data must be validated, not asserted as DeliveryPlanResult.
105
+ const received: unknown = JSON.parse(JSON.stringify(result));
106
+ const validated = parseDeliveryPlanResult(received);
107
+ console.log(validated.ok);
108
+ ```
109
+
110
+ Exported TypeBox schemas are the source of both runtime validation and static types:
111
+ `DeliveryOptionsSchema`, `DeliveryTargetSchema`, `DeliveryPlanSchema`,
112
+ `DeliveryPlanResultSchema`. `createDeliveryPlan` accepts a trusted compiler graph;
113
+ it is not a deserializer for arbitrary external graph JSON.
114
+
115
+ ## Local Builds
116
+
117
+ ```sh
118
+ supacloud-compiler build-delivery --json
119
+ supacloud-compiler build-delivery --delivery delivery.json --json
120
+ ```
121
+
122
+ Requires Bun and a project `tsconfig.json`. The configured output directory must
123
+ be project-local and must not contain the application source root. Output uses
124
+ the dedicated `<outDir>/delivery` namespace:
125
+
126
+ ```text
127
+ delivery/
128
+ owner.json
129
+ delivery.manifest.json
130
+ objects/<objectId>/
131
+ generated/application.ts
132
+ bundle/index.js
133
+ bundle/package.json
134
+ bundle/app.manifest.json
135
+ bundle/target.json
136
+ bundle/assets/...
137
+ ```
138
+
139
+ `bundle/index.js` exports `createCompiledModules`. Move the whole `bundle` directory,
140
+ not just its entrypoint. The generated TypeScript is inspection output and still
141
+ references application sources; the bundle does not require those source files.
142
+ This is **not** a default HTTP handler or a ready-to-deploy Function. A compatible
143
+ host must supply HTTP composition, trusted identity, database/governance adapters,
144
+ and durable Job execution. Route mappings are local metadata, not applied gateway
145
+ configuration. All results continue to report `deploymentReady: false`.
146
+
147
+ Optional build settings live in the same validated `delivery` declaration:
148
+
149
+ ```json
150
+ {
151
+ "version": 1,
152
+ "build": {
153
+ "minify": true,
154
+ "environmentContract": "app-env-v1",
155
+ "assets": [
156
+ { "target": "api", "source": "templates/report.html", "path": "report.html" }
157
+ ]
158
+ }
159
+ }
160
+ ```
161
+
162
+ Asset `source` is relative to configured source root; `path` is relative to
163
+ `bundle/assets`. Only explicit relative paths are accepted. Missing assets, path
164
+ traversal, duplicate destinations, and symlinks reject the build. Environment
165
+ contracts are references, not secret values. Environment values are not inlined.
166
+ Code doing runtime filesystem reads must use declared assets and the host's
167
+ documented asset-location convention; automatic discovery is not provided.
168
+ Computed `import()` and direct computed `require()` calls are rejected. This is
169
+ not a sandbox for arbitrary JavaScript, eval, or filesystem access.
170
+
171
+ Each target includes its conservative module dependency closure, while route and
172
+ Job descriptors remain exclusive to their owner. Provider pruning is disabled to
173
+ preserve Job and lifecycle dependencies. Package imports are bundled; only Bun
174
+ and Node builtin imports may remain external. Native/platform-dependent packages
175
+ still need destination-platform validation.
176
+
177
+ Every invocation reruns compiler checks, TypeScript diagnostics, and bundling for
178
+ **all** targets. The generator's type-check project includes application source
179
+ and target-generated files, preserving configured checks and widening only the
180
+ emit-path `rootDir` to the project directory. This does not replace application
181
+ tests or full release checks. Refresh GraphQL artifacts through normal `compile`
182
+ before building when GraphQL drift is reported.
183
+
184
+ `inputDigest` includes generated source, captured bundled inputs, compiler and Bun
185
+ identity, configuration/lockfile hashes, target build options, explicit assets,
186
+ and environment-contract reference. Shared dependency changes invalidate dependent
187
+ targets; configuration changes conservatively invalidate more targets. Unchanged
188
+ immutable artifacts are reused without touching their files. This is **artifact
189
+ reuse, not skipped bundler work**.
190
+
191
+ Success exposes `manifest`, `bundledTargets`, `changedTargets`, `unchangedTargets`,
192
+ `removedTargets`, and `written`. An unchanged build has `written: []`.
193
+ `manifest.objects` records per-file size and SHA-256 plus the object identity.
194
+ Use `parseDeliveryBuildResult` / `parseDeliveryBuildManifest` for received JSON;
195
+ matching hashes are integrity checks, not authorization or authenticity proofs.
196
+
197
+ An exclusive lock protects the owned output directory. Existing unowned output,
198
+ invalid manifests, and modified immutable objects are rejected without overwrites.
199
+ Only an atomic replacement of `delivery.manifest.json` activates a local build.
200
+ Failures preserve the previous active pointer; inactive objects can remain after
201
+ an interrupted publication. Removed target objects are retained for inspection,
202
+ not automatically garbage-collected. Inspect stale locks after confirming no
203
+ writer is active; the builder never removes them automatically.
204
+
205
+ ## Planning Evidence And Limits
206
+
207
+ - Every result has `written: []`. A failure has `ok: false` and `plan: null`.
208
+ - Success has `deploymentReady: false`. No planning result authorizes deployment.
209
+ - `topologyDigest` hashes canonical target topology, requirements, and declared
210
+ readiness. It excludes business source contents, toolchain, lockfile, credentials,
211
+ migrations, and full runtime contracts. It is **not** an artifact hash, cache key,
212
+ approval token, or proof that a received plan is authentic.
213
+ - Dependencies are a conservative module closure, not provider-level tree shaking.
214
+ External token inventory is conservative within that closure.
215
+ - `planDeliveryProject` runs existing compiler analysis/governance/contract gates
216
+ using supplied compile options. Artifact drift is intentionally ignored so a
217
+ new project can be planned before generation. Existing artifacts are not rewritten.
218
+ - Compiler analysis is not a complete TypeScript type check. Run the application's
219
+ type checker, tests, full integration/build gates, and host verification before
220
+ release. Do not weaken those gates to make a plan succeed.
221
+ - This version does not reconcile old deployment topology, validate all possible
222
+ router-specific pattern overlaps, or attest queue adapters. Deployment remains
223
+ a separate, explicitly authorized step.
package/README.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @supacloud/compiler
2
2
 
3
+ ## Local Delivery
4
+
5
+ `supacloud-compiler plan --json` previews workload targets and route ownership.
6
+ `supacloud-compiler build-delivery --json` creates independent local factory bundles
7
+ and an atomic inspection manifest, reusing unchanged artifacts without deployment.
8
+ See [local delivery](./DELIVERY.md) for configuration, contracts, and limitations.
9
+
10
+ ## Persistent Execution Policy
11
+
12
+ Set `commandCapabilities.requirePersistentAdapters: true` to require named adapters
13
+ with explicit `database`/`external` boundaries, permission, audit and idempotency.
14
+ Database commands require transactional capability and `transaction: "required"`.
15
+ External adapters cannot satisfy a required database transaction: use durable
16
+ intent and read-only reconciliation instead.
17
+
18
+ `command-persistence-required` and `command-external-transaction` diagnostics include
19
+ recovery suggestions and participate in JSON output and the existing no-write-on-error
20
+ gate. These checks validate declared policy, not the implementation of a custom
21
+ adapter. See [configuration and migration](../../docs/command-migration.md).
22
+
3
23
  FA-derived direct-command RPC ownership, contract inspection and POST command
4
24
  protocol migration are documented in `docs/fa-consumer-governance.md` in the
5
25
  repository. `context <module> --json` reports `routeContracts` and standalone
@@ -0,0 +1,10 @@
1
+ export interface CompilerBenchmarkResult {
2
+ fixtureFiles: number;
3
+ coldCompileMs: number;
4
+ incrementalCompileMs: number;
5
+ dependencyInvalidationMs: number;
6
+ generatedBytes: number;
7
+ reusedModules: string[];
8
+ reanalyzedModules: string[];
9
+ }
10
+ export declare function runCompilerBenchmark(): Promise<CompilerBenchmarkResult>;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};