@astrale-os/adapter-cloudflare 0.5.0-beta.17 → 0.5.0-beta.170
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 +230 -2
- package/dist/adapter.d.ts +24 -0
- package/dist/adapter.js +59 -0
- package/dist/build/bundle/admit.d.ts +3 -0
- package/dist/build/bundle/admit.js +46 -0
- package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
- package/dist/build/bundle/compiled-wasm-loader.js +21 -0
- package/dist/build/bundler.d.ts +21 -0
- package/dist/build/bundler.js +96 -0
- package/dist/build/closure.d.ts +2 -0
- package/dist/build/closure.js +22 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +32 -6
- package/dist/build/codegen/wrangler.js +77 -21
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +11 -0
- package/dist/build/configuration/settings.d.ts +6 -0
- package/dist/build/configuration/settings.js +42 -0
- package/dist/build/configuration.d.ts +4 -0
- package/dist/build/configuration.js +4 -0
- package/dist/build/frontend/files.d.ts +19 -0
- package/dist/build/frontend/files.js +99 -0
- package/dist/build/frontend/readiness.d.ts +10 -0
- package/dist/build/frontend/readiness.js +21 -0
- package/dist/build/frontend/revision.d.ts +5 -0
- package/dist/build/frontend/revision.js +14 -0
- package/dist/build/frontend/vite.d.ts +14 -0
- package/dist/build/frontend/vite.js +42 -0
- package/dist/build/frontend/vite.process.d.ts +7 -0
- package/dist/build/frontend/vite.process.js +65 -0
- package/dist/build/frontend/vite.runner.d.ts +1 -0
- package/dist/build/frontend/vite.runner.js +155 -0
- package/dist/build/index.d.ts +16 -14
- package/dist/build/index.js +15 -14
- package/dist/build/material.d.ts +10 -0
- package/dist/build/material.js +25 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -0
- package/dist/build/worker/artifact.d.ts +40 -0
- package/dist/build/worker/artifact.js +1 -0
- package/dist/build/worker/artifact.load.d.ts +3 -0
- package/dist/build/worker/artifact.load.js +308 -0
- package/dist/build/worker/artifact.manifest.d.ts +48 -0
- package/dist/build/worker/artifact.manifest.js +87 -0
- package/dist/build/worker/artifact.paths.d.ts +4 -0
- package/dist/build/worker/artifact.paths.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +10 -0
- package/dist/build/worker/codegen/entry.js +65 -0
- package/dist/build/worker/codegen/literal.d.ts +28 -0
- package/dist/build/worker/codegen/literal.js +136 -0
- package/dist/build/worker/codegen/service.d.ts +14 -0
- package/dist/build/worker/codegen/service.js +58 -0
- package/dist/build/worker/execution.prepare.d.ts +20 -0
- package/dist/build/worker/execution.prepare.js +129 -0
- package/dist/build/worker/index.d.ts +2 -0
- package/dist/build/worker/index.js +1 -0
- package/dist/build/worker/modules.d.ts +17 -0
- package/dist/build/worker/modules.js +32 -0
- package/dist/build/worker/runtime.d.ts +10 -0
- package/dist/build/worker/runtime.js +35 -0
- package/dist/build/worker/specifier.d.ts +5 -0
- package/dist/build/worker/specifier.js +15 -0
- package/dist/build/worker/upload.d.ts +39 -0
- package/dist/build/worker/upload.js +80 -0
- package/dist/cloudflare.d.ts +1 -45
- package/dist/cloudflare.js +1 -202
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/material.d.ts +7 -0
- package/dist/identity/material.js +42 -0
- package/dist/index.d.ts +16 -13
- package/dist/index.js +15 -12
- package/dist/legacy/direct/addressing.d.ts +2 -0
- package/dist/legacy/direct/addressing.js +17 -0
- package/dist/legacy/direct/deploy.d.ts +17 -0
- package/dist/legacy/direct/deploy.js +243 -0
- package/dist/legacy/direct/identity/index.d.ts +11 -0
- package/dist/legacy/direct/identity/index.js +11 -0
- package/dist/legacy/direct/identity/secret.d.ts +3 -0
- package/dist/legacy/direct/identity/secret.js +7 -0
- package/dist/legacy/direct/identity/source.d.ts +26 -0
- package/dist/legacy/direct/identity/source.js +127 -0
- package/dist/legacy/direct/index.d.ts +27 -0
- package/dist/legacy/direct/index.js +27 -0
- package/dist/legacy/direct/materialize.d.ts +4 -0
- package/dist/legacy/direct/materialize.js +10 -0
- package/dist/legacy/direct/placement.d.ts +4 -0
- package/dist/legacy/direct/placement.js +91 -0
- package/dist/legacy/direct/prepare.d.ts +7 -0
- package/dist/legacy/direct/prepare.js +158 -0
- package/dist/legacy/direct/readiness.d.ts +34 -0
- package/dist/legacy/direct/readiness.js +95 -0
- package/dist/legacy/direct/vars.d.ts +27 -0
- package/dist/legacy/direct/vars.js +53 -0
- package/dist/legacy/direct/worker-name.d.ts +2 -0
- package/dist/legacy/direct/worker-name.js +18 -0
- package/dist/legacy/direct/worker.d.ts +37 -0
- package/dist/legacy/direct/worker.js +58 -0
- package/dist/legacy/direct/wrangler/deploy.d.ts +24 -0
- package/dist/legacy/direct/wrangler/deploy.js +44 -0
- package/dist/legacy/direct/wrangler/output.d.ts +2 -0
- package/dist/legacy/direct/wrangler/output.js +10 -0
- package/dist/legacy/direct/wrangler/rollout.d.ts +27 -0
- package/dist/legacy/direct/wrangler/rollout.js +75 -0
- package/dist/legacy/direct/wrangler/secrets.d.ts +2 -0
- package/dist/legacy/direct/wrangler/secrets.js +24 -0
- package/dist/legacy/direct/wrangler/status.d.ts +18 -0
- package/dist/legacy/direct/wrangler/status.js +75 -0
- package/dist/legacy/direct/wrangler/triggers.d.ts +5 -0
- package/dist/legacy/direct/wrangler/triggers.js +12 -0
- package/dist/legacy/direct/wrangler/versions.d.ts +13 -0
- package/dist/legacy/direct/wrangler/versions.js +38 -0
- package/dist/namespace/api.d.ts +71 -0
- package/dist/namespace/api.js +265 -0
- package/dist/namespace/calls.d.ts +29 -0
- package/dist/namespace/calls.js +104 -0
- package/dist/namespace/configure.d.ts +26 -0
- package/dist/namespace/configure.js +199 -0
- package/dist/namespace/coordinates.d.ts +44 -0
- package/dist/namespace/coordinates.js +99 -0
- package/dist/namespace/deploy-release.d.ts +56 -0
- package/dist/namespace/deploy-release.js +403 -0
- package/dist/namespace/index.d.ts +15 -0
- package/dist/namespace/index.js +15 -0
- package/dist/namespace/list.d.ts +33 -0
- package/dist/namespace/list.js +139 -0
- package/dist/namespace/readiness.d.ts +40 -0
- package/dist/namespace/readiness.js +81 -0
- package/dist/namespace/routing.d.ts +55 -0
- package/dist/namespace/routing.js +165 -0
- package/dist/namespace/script.d.ts +106 -0
- package/dist/namespace/script.js +278 -0
- package/dist/params.d.ts +118 -40
- package/dist/params.js +0 -1
- package/dist/release/build.d.ts +35 -0
- package/dist/release/build.js +44 -0
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +3 -0
- package/dist/release/index.js +3 -0
- package/dist/release/staged-worker-name.d.ts +3 -0
- package/dist/release/staged-worker-name.js +10 -0
- package/dist/worker/build-digest.d.ts +16 -0
- package/dist/worker/build-digest.js +34 -0
- package/dist/worker/durable.d.ts +11 -0
- package/dist/worker/durable.js +24 -0
- package/dist/worker/entry.d.ts +36 -0
- package/dist/worker/entry.js +138 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/front.d.ts +75 -0
- package/dist/worker/front.js +64 -0
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +83 -0
- package/dist/worker/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +6 -61
- package/dist/worker/index.js +6 -221
- package/dist/worker/restate.d.ts +6 -0
- package/dist/worker/restate.js +6 -0
- package/dist/worker/settings.d.ts +48 -0
- package/dist/worker/settings.js +161 -0
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +27 -0
- package/dist/wrangler/index.d.ts +3 -0
- package/dist/wrangler/index.js +3 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +102 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +45 -20
- package/template/astrale.config.ts +29 -30
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -27
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -252
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -138
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts +0 -88
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -283
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/fetch.d.ts.map +0 -1
- package/dist/worker/fetch.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -128
- package/src/build/frontend.ts +0 -298
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -189
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -372
- package/src/cloudflare.ts +0 -275
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/fetch.ts +0 -46
- package/src/worker/index.ts +0 -335
- package/src/worker/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -2,10 +2,238 @@
|
|
|
2
2
|
|
|
3
3
|
Cloudflare Worker deployment adapter for Astrale Domains.
|
|
4
4
|
|
|
5
|
-
During the SDK beta program, install the beta
|
|
5
|
+
During the SDK beta program, install the beta package set explicitly:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @astrale-os/sdk@beta @astrale-os/adapter-cloudflare@beta
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Bare installs return to stable releases when the
|
|
11
|
+
Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
|
|
12
|
+
|
|
13
|
+
One `cloudflare()` value configures one Project Environment, in one of two modes. With
|
|
14
|
+
`namespace`, each release becomes one immutable deployment in a platform dispatch namespace. Without
|
|
15
|
+
it, the Environment is on the legacy direct mode: one stable Worker, replaced in place by each
|
|
16
|
+
deploy. A deploy never installs: install the URL it prints with
|
|
17
|
+
`astrale domain install <url> --direct -i <instance>`.
|
|
18
|
+
|
|
19
|
+
Generated Worker modules are minified by default, including separately loaded runtime modules.
|
|
20
|
+
The Environment's `wrangler` overlay cannot change minification: every Environment of one source
|
|
21
|
+
must emit the same JavaScript bytes. `cloudflare({ wrangler: { minify: false } })` is rejected.
|
|
22
|
+
|
|
23
|
+
## Namespace mode
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
production: {
|
|
27
|
+
deployment: cloudflare({
|
|
28
|
+
namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
|
|
29
|
+
secrets: '.env.production',
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Only the platform deploys there (Shell, Services and the other platform Domains), so every line is
|
|
35
|
+
readable. `astrale-domain deploy <environment>` uploads one script named by the deployment label,
|
|
36
|
+
create-only (`If-None-Match: *`), which answers at `https://<label>.<routingDomain>` through the
|
|
37
|
+
platform dispatcher. Nothing is ever replaced in place: another build or configuration is another
|
|
38
|
+
label.
|
|
39
|
+
|
|
40
|
+
- **Credentials.** `CLOUDFLARE_API_TOKEN` must edit the namespace's scripts and the values of its
|
|
41
|
+
routing KV; the account is `namespace.account`, else `CLOUDFLARE_ACCOUNT_ID`. Neither is ever
|
|
42
|
+
written to the configuration.
|
|
43
|
+
- **Routing KV.** The deploy finds the namespace's routing KV by its title,
|
|
44
|
+
`astrale-deployment-routing-<first 16 bytes of sha256(name), in hexadecimal>`, which the platform
|
|
45
|
+
provisioning creates. A namespace without it is refused before any effect.
|
|
46
|
+
- **Bindings.** Each new deployment binds `WORKER_URL`, `ASTRALE_BUILD_DIGEST`, `ASTRALE_SETTINGS`
|
|
47
|
+
(the router as `ROUTER`), the author's `vars`, the service bindings of `wrangler.services`, the
|
|
48
|
+
router, its version metadata, and as `secret_text` exactly the Environment's secrets and
|
|
49
|
+
`ASTRALE_SIGNING_IDENTITY`, a key generated for that deployment and kept nowhere else. Its tags
|
|
50
|
+
name its artifact (build digest), line and key; never `astrale-service`, which is Services'.
|
|
51
|
+
- **Activation.** The deploy writes `summary:<label>` (owner `platform`, state `active`, retention
|
|
52
|
+
`preview`, the activation instant), then `record:<label>`, whose presence makes the dispatcher
|
|
53
|
+
route the label. Neither ever holds a provider version or a secret digest. Readiness then waits,
|
|
54
|
+
bounded, until the URL serves the sealed release from the provider version the upload created.
|
|
55
|
+
- **Reuse.** A redeploy of the same release finds the script under its label. It is reused only
|
|
56
|
+
when its artifact and line tags and its record name this build and configuration (or, when an
|
|
57
|
+
interrupted deploy left it unactivated, when it binds exactly this configuration). Then only that
|
|
58
|
+
script's declared secrets are rewritten in place, and readiness waits for the version the
|
|
59
|
+
rewrite minted. Anything else is a `deployment-conflict`, refused with nothing written; no other
|
|
60
|
+
deployment is ever touched.
|
|
61
|
+
- **Retention.** `retain` (called once a Publication commits) marks the summary `published`, which
|
|
62
|
+
the platform's preview expiry never retires. A label the platform withdrew (`retirement:<label>`)
|
|
63
|
+
answers `DEPLOYMENT_RETIRED` at the dispatcher and is refused by every later deploy.
|
|
64
|
+
- **Listing.** `astrale-domain list` lists the Environment's deployments from the routing KV, and
|
|
65
|
+
writes nothing: one row per `summary:<label>` of the Environment's line, with its record as
|
|
66
|
+
`record:<label>` stores it (a record the SDK refuses is listed with `record: null` and the
|
|
67
|
+
refusal), and the call target `{ kind: 'namespace', namespace, script }` that the platform's
|
|
68
|
+
per-script tooling takes, such as its in-place secret rotation. A summary without its record is
|
|
69
|
+
`deploying` (not activated), and an active one whose label carries the tombstone is `retiring`.
|
|
70
|
+
Nothing on the namespace records last calls: they come from its calls dataset,
|
|
71
|
+
`astrale_deployment_calls_<the same hexadecimal>`, through the Analytics Engine SQL API, and an
|
|
72
|
+
active preview expires 30 days after the later of its activation and its last call. The token
|
|
73
|
+
then also needs Account Analytics Read; without it, the deployments are listed without last calls
|
|
74
|
+
or expiries.
|
|
75
|
+
- **Refused.** A direct-mode parameter beside `namespace` (`route`, `workerName`, `identityIssuer`,
|
|
76
|
+
`addressing`, `signingIdentity`), a `router.binding` other than `ROUTER`, and any `wrangler` key
|
|
77
|
+
but `services`, `dispatch_namespaces` and `compatibility_flags`, `triggers` first: an immutable
|
|
78
|
+
deployment runs no cron of its own. A `dispatch_namespaces` entry is exactly
|
|
79
|
+
`{ binding, namespace }`; it is frozen into the configuration (`bindings.dispatchNamespaces`), so
|
|
80
|
+
into the label, bound at the create-only upload, and never names the platform namespace the
|
|
81
|
+
deployment lives in (AM-174). Which namespaces a deployment may bind is its host's to decide.
|
|
82
|
+
`durable` is frozen into the configuration (`settings.durableOptions`, AM-175), so into the
|
|
83
|
+
label, and bound in `ASTRALE_SETTINGS`: a durable run stays on the deployment that started it.
|
|
84
|
+
`astrale-domain dev` serves only direct-mode Environments.
|
|
85
|
+
|
|
86
|
+
## Legacy direct mode
|
|
87
|
+
|
|
88
|
+
Deprecated: replaced by namespace mode, and deleted with the legacy deploy path (D10) once no
|
|
89
|
+
configuration on any repository's main selects direct mode. Its consumers until they move: the
|
|
90
|
+
domains configurations of ai-gateway, closing, grc, integrations and issues; domains organization,
|
|
91
|
+
whose `prod` binds an EU-jurisdiction R2 bucket that namespace mode does not admit yet; the Services
|
|
92
|
+
`beta`, `prod` and `development` environments and its frozen `admin-beta`; the Shell and its frozen
|
|
93
|
+
`legacy-v3`; and ui:domain.
|
|
94
|
+
|
|
95
|
+
`astrale-domain dev <environment>` builds locally and deploys each admitted Worker and frontend
|
|
96
|
+
update remotely through the same path as `deploy`; it starts no local Worker, Vite server, or
|
|
97
|
+
tunnel. Omitting `route` uses the observed stable `*.workers.dev` issuer.
|
|
98
|
+
|
|
99
|
+
One watcher serializes its own updates. For an existing Worker, it uploads a candidate, reconciles
|
|
100
|
+
configured triggers, and stages the candidate at 0% while the previous version retains 100% of normal
|
|
101
|
+
HTTP traffic. Exact-version probes verify Publication, Bundle, and serving identity before promotion;
|
|
102
|
+
serving the Publication also initializes the Domain Runtime. After promotion, normal requests
|
|
103
|
+
must prove that exact version again. A failed candidate remains at 0% and can be replaced on retry.
|
|
104
|
+
Bundled View routes must also serve the prepared browser-file generation before readiness passes.
|
|
105
|
+
This covers frontend-only changes without changing the Schema or reinstalling the Domain. HTML is
|
|
106
|
+
revalidated on every use and transient asset misses are not cached; ordinary successful asset
|
|
107
|
+
responses keep their cache policy. Frontend files are answered by the Worker's small startup module
|
|
108
|
+
without loading the execution Service, which each such file starts loading in the background for the
|
|
109
|
+
calls the View makes next.
|
|
110
|
+
The first deployment uses ordinary Worker provisioning because no previous version exists to retain.
|
|
111
|
+
An existing traffic-split rollout must be resolved before this single-version workflow can continue.
|
|
112
|
+
|
|
113
|
+
A direct Cloudflare target shared across machines must still have one external writer, normally a
|
|
114
|
+
CI/CD concurrency group. Live deployment checks detect competing changes but are not an atomic
|
|
115
|
+
compare-and-swap or distributed lock. Use separate Worker targets for uncoordinated development.
|
|
116
|
+
Routes, custom domains, schedules, and other non-versioned provider settings are reconciled through
|
|
117
|
+
Wrangler before candidate probing; they can remain changed after a failed attempt. Candidate readiness
|
|
118
|
+
protects the HTTP implementation, not an atomic rollback of external resources or trigger settings.
|
|
119
|
+
|
|
120
|
+
## Frontend files
|
|
121
|
+
|
|
122
|
+
The Worker runs before Workers Static Assets on every request and owns frontend response headers
|
|
123
|
+
and routing, for `cloudflare()` and `astrale()` deployments alike. Frontend preparation therefore
|
|
124
|
+
refuses a built frontend whose root contains `_headers`, `_redirects`, or `.assetsignore`, in any
|
|
125
|
+
letter case, as a file or a directory. Wrangler would apply them as asset configuration in a direct
|
|
126
|
+
deployment, while a managed deployment would serve them as public files. The refusal happens while
|
|
127
|
+
the artifact is prepared, before any provider change. Vite copies its public directory (`public/`
|
|
128
|
+
by default) to that root: remove them there, or stop the plugin that emits them. The same names
|
|
129
|
+
below the root, such as `docs/_headers`, remain ordinary files.
|
|
130
|
+
|
|
131
|
+
The Worker is also the only server-side code, so preparation likewise refuses a root name starting
|
|
132
|
+
with `_worker.js`, the name of a Cloudflare Pages worker script: a `_worker.js` file or directory,
|
|
133
|
+
or a sibling such as `_worker.js.map`. Wrangler refuses to upload these as assets, since they may
|
|
134
|
+
hold server-side code, so a direct deployment would fail at upload, while a managed deployment would
|
|
135
|
+
publish them. Unlike the names above, the match is case-sensitive, as Wrangler's is: `_Worker.js`
|
|
136
|
+
and a nested `docs/_worker.js` remain ordinary files. Remove such a file from the public directory,
|
|
137
|
+
or rename it if it is a browser script.
|
|
138
|
+
|
|
139
|
+
## Provider-local staging
|
|
140
|
+
|
|
141
|
+
Managed Cloudflare providers may stage immutable implementation candidates without exposing their
|
|
142
|
+
identity to Publications or installed Kernels:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { stagedWorkerName } from '@astrale-os/adapter-cloudflare/release'
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
This subpath is runtime-safe. `stagedWorkerName(providerDeployment)` addresses one private staged
|
|
149
|
+
candidate. The public Worker name and `/invoke` endpoint remain stable across compatible
|
|
150
|
+
implementation and Schema updates. Provider staging identity never enters Release, Publication,
|
|
151
|
+
Kernel routing, or graph identity.
|
|
152
|
+
|
|
153
|
+
## Deployment bindings
|
|
154
|
+
|
|
155
|
+
The bundled Worker carries no Environment value, so every Environment of one source bundles the
|
|
156
|
+
same bytes. Each deployment binds its own values as plain Worker bindings:
|
|
157
|
+
|
|
158
|
+
| Binding | Value |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| `WORKER_URL` | serving origin of the deployment |
|
|
161
|
+
| `ASTRALE_SETTINGS` | canonical JSON of `{ invocationTimeoutMs, maximumRequestBytes, router, tokenExchange }`, defaults resolved, with optional `durableOptions` |
|
|
162
|
+
| `ASTRALE_BUILD_DIGEST` | build digest the host recomputed from the uploaded bytes, bound only by hosts that deploy immutable Workers; never by a stable Worker |
|
|
163
|
+
| `IDENTITY_ISS`, `ASTRALE_PROVIDER_ASSIGNED_WORKER` | **legacy direct mode only** (deprecated): a stable issuer behind another route, and the workers.dev claim |
|
|
164
|
+
|
|
165
|
+
These names are adapter-owned: preparation refuses an author var, or a `wrangler.vars` entry, that
|
|
166
|
+
takes one, and deployment refuses a secret that does. A host that deploys the Worker itself encodes
|
|
167
|
+
the settings with `encodeWorkerSettings` from `@astrale-os/adapter-cloudflare/worker`. A generated
|
|
168
|
+
Worker refuses execution without `ASTRALE_SETTINGS`.
|
|
169
|
+
|
|
170
|
+
`ASTRALE_BUILD_DIGEST` selects what the Worker serves. Bound, the Worker is an immutable deployment:
|
|
171
|
+
it seals the `DomainRelease` v4 of its code at its `WORKER_URL`, which is its issuer, and serves it
|
|
172
|
+
at `/.well-known/astrale/release.json` beside its frozen v3 projection at `domain.json`; it admits
|
|
173
|
+
only routing that names that exact release or projection. Unbound, it is a stable Worker and serves
|
|
174
|
+
exactly the v3 Publication of today, answering 404 at `release.json`. The Worker refuses execution,
|
|
175
|
+
instead of falling back to v3, when the digest is malformed, when it is bound without `WORKER_URL`,
|
|
176
|
+
or beside a direct-mode binding or a configured `identityIssuer`.
|
|
177
|
+
|
|
178
|
+
The two direct-mode bindings are deprecated. Their replacement is an immutable deployment, whose
|
|
179
|
+
host binds `WORKER_URL` to the deployment URL, which is also its issuer (namespace mode). They are
|
|
180
|
+
deleted with direct mode, once the Shell, Services, Issues, domains and ui configurations deploy in
|
|
181
|
+
namespace mode and no installation pins a direct Worker.
|
|
182
|
+
|
|
183
|
+
The `wrangler` overlay reaches the deployment configuration, never the bundle. Preparation refuses
|
|
184
|
+
an overlay key the bundler reads (`alias`, `build`, `define`, `jsx_factory`, `jsx_fragment`,
|
|
185
|
+
`keep_names`, `minify`, `no_bundle`, `node_compat`, `preserve_file_names`, `rules`, `tsconfig`,
|
|
186
|
+
`upload_source_maps`) and a compatibility flag it reads (Node.js, `navigator`, fetch iterable
|
|
187
|
+
typing, Python) beyond the adapter's own `nodejs_compat`.
|
|
188
|
+
|
|
189
|
+
## Build digest
|
|
190
|
+
|
|
191
|
+
`cloudflare()` and `astrale()` bundle through one bundler, `cloudflare-worker` version `1`, so
|
|
192
|
+
every Environment of either adapter shares one build: `astrale-domain build` prints its build
|
|
193
|
+
digest, and `deploy` places that same Bundle. Two installed versions of this package are two
|
|
194
|
+
copies of the bundler: when their code differs, `build` prints one build digest per copy and warns
|
|
195
|
+
until the adapter versions are aligned.
|
|
196
|
+
|
|
197
|
+
Services receives the placed modules as they are, so there the digest names the bytes the
|
|
198
|
+
deployment runs. Direct mode runs `wrangler deploy`, which bundles the placed modules again: there
|
|
199
|
+
the digest names the portable Worker the deployment was made from, not the bytes Cloudflare runs.
|
|
200
|
+
A host that receives a Worker upload recomputes the digest from the exact upload with the same
|
|
201
|
+
function:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { workerBuildManifest } from '@astrale-os/adapter-cloudflare/release'
|
|
205
|
+
import { buildDigest } from '@astrale-os/sdk/deployment/build/manifest'
|
|
206
|
+
|
|
207
|
+
const digest = buildDigest(workerBuildManifest({ origin, revision, bundle, entry, modules, assets }))
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Modules keep their uploaded name and an asset `/<path>` is the file `assets/<path>`. The bundler
|
|
211
|
+
version names this layout, not a package release. Both subpaths are runtime-safe.
|
|
212
|
+
|
|
213
|
+
## Material for a custom Worker entrypoint
|
|
214
|
+
|
|
215
|
+
Workers with provider-specific routes or environment initialization can reuse the adapter's
|
|
216
|
+
material emission without adopting the entire generated entrypoint:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { generateBuildMaterialModule } from '@astrale-os/adapter-cloudflare/build'
|
|
220
|
+
import { writeFile } from 'node:fs/promises'
|
|
221
|
+
|
|
222
|
+
// build is an admitted Build returned by compile(domain).
|
|
223
|
+
await writeFile('src/build-material.gen.ts', generateBuildMaterialModule(build))
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The generated TypeScript module exports `loadBuildMaterial()`. Call it from the
|
|
227
|
+
`load` callback of `generatedCloudflareWorkerEntry` alongside the Domain's Runtime.
|
|
228
|
+
Such an entrypoint states its execution settings (`invocationTimeoutMs`, `maximumRequestBytes`,
|
|
229
|
+
`tokenExchange`, `routeSubrequest`, `identityIssuer`) in its configuration, or reads them from its
|
|
230
|
+
deployment bindings with `settings: deploymentSettings`; one Worker never takes both.
|
|
231
|
+
It constructs the same verified, deduplicated material as the adapter's generated Service;
|
|
232
|
+
allocation is deferred until the factory is called and the SDK deep-freezes it before use.
|
|
233
|
+
The generated file needs only a type import from the SDK. Keep its compiler and runtime SDK
|
|
234
|
+
versions aligned, and regenerate it when either the Domain or that SDK version changes.
|
|
235
|
+
|
|
236
|
+
Such an entrypoint can keep the same fast frontend path by answering from
|
|
237
|
+
`cloudflareFrontDoor()` (`@astrale-os/adapter-cloudflare/worker/front`, which reaches no SDK
|
|
238
|
+
runtime module) before importing its Service, and calling that Service's `prepare()` through
|
|
239
|
+
`waitUntil` when the front door served a frontend file.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Deployment } from '@astrale-os/sdk/deployment';
|
|
2
|
+
import type { Adapter } from '@astrale-os/sdk/deployment/adapter';
|
|
3
|
+
import type { CloudflareDeployDependencies } from './legacy/direct/index.js';
|
|
4
|
+
import type { NamespaceDependencies } from './namespace/index.js';
|
|
5
|
+
import type { CloudflareParams } from './params.js';
|
|
6
|
+
import { artifact, signingIdentity } from './legacy/direct/index.js';
|
|
7
|
+
export { waitForReadiness, type ReadinessCheck } from './legacy/direct/index.js';
|
|
8
|
+
export type { NamespaceDependencies } from './namespace/index.js';
|
|
9
|
+
export interface CloudflareDependencies extends CloudflareDeployDependencies {
|
|
10
|
+
readonly artifact: typeof artifact;
|
|
11
|
+
readonly signingIdentity: typeof signingIdentity;
|
|
12
|
+
/** The effects of namespace mode. Default: `fetch`, `process.env`, a new key, the clock. */
|
|
13
|
+
readonly namespace?: NamespaceDependencies;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Deploy one Project Environment through Cloudflare Workers.
|
|
17
|
+
*
|
|
18
|
+
* With `namespace`, each release becomes one immutable deployment in that platform dispatch
|
|
19
|
+
* namespace (adapter interface v2), and `astrale-domain list` lists them. Without it, the
|
|
20
|
+
* Environment stays on the legacy direct mode: one stable Worker replaced in place by each deploy
|
|
21
|
+
* (CT33).
|
|
22
|
+
*/
|
|
23
|
+
export declare function cloudflare(parameters?: CloudflareParams): Deployment<CloudflareParams, Adapter<CloudflareParams>>;
|
|
24
|
+
export declare function cloudflareWithDependencies(parameters: CloudflareParams, dependencies: CloudflareDependencies): Deployment<CloudflareParams, Adapter<CloudflareParams>>;
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineAdapter, defineDeployment } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { cloudflareWorkerBundler } from './build/bundler.js';
|
|
4
|
+
import { createSigningIdentity } from './identity/material.js';
|
|
5
|
+
import { artifact, deployCloudflare, directReadiness, materialize, runWranglerDeploymentStatus, runWranglerRollout, signingIdentity, } from './legacy/direct/index.js';
|
|
6
|
+
import { admitNamespace, configureNamespace, deployNamespaceRelease, listNamespaceDeployments, placeNamespace, retainNamespaceDeployment, } from './namespace/index.js';
|
|
7
|
+
export { waitForReadiness } from './legacy/direct/index.js';
|
|
8
|
+
const packageVersion = createRequire(import.meta.url)('../package.json')
|
|
9
|
+
.version;
|
|
10
|
+
/**
|
|
11
|
+
* Deploy one Project Environment through Cloudflare Workers.
|
|
12
|
+
*
|
|
13
|
+
* With `namespace`, each release becomes one immutable deployment in that platform dispatch
|
|
14
|
+
* namespace (adapter interface v2), and `astrale-domain list` lists them. Without it, the
|
|
15
|
+
* Environment stays on the legacy direct mode: one stable Worker replaced in place by each deploy
|
|
16
|
+
* (CT33).
|
|
17
|
+
*/
|
|
18
|
+
export function cloudflare(parameters = {}) {
|
|
19
|
+
return cloudflareWithDependencies(parameters, {
|
|
20
|
+
artifact,
|
|
21
|
+
materialize,
|
|
22
|
+
runWranglerRollout,
|
|
23
|
+
runWranglerDeploymentStatus,
|
|
24
|
+
signingIdentity,
|
|
25
|
+
waitForReadiness: directReadiness,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function cloudflareWithDependencies(parameters, dependencies) {
|
|
29
|
+
const namespace = dependencies.namespace ?? platformNamespaceDependencies();
|
|
30
|
+
const adapter = defineAdapter({
|
|
31
|
+
name: 'cloudflare',
|
|
32
|
+
version: packageVersion,
|
|
33
|
+
bundler: cloudflareWorkerBundler,
|
|
34
|
+
admit: admitCloudflare,
|
|
35
|
+
configure: configureNamespace,
|
|
36
|
+
placement: async (parameters) => placeNamespace(parameters),
|
|
37
|
+
deployRelease: (parameters, context) => deployNamespaceRelease(parameters, context, namespace),
|
|
38
|
+
list: (parameters, context) => listNamespaceDeployments(parameters, context, namespace),
|
|
39
|
+
retain: (parameters, context) => retainNamespaceDeployment(parameters, context, namespace),
|
|
40
|
+
// Legacy direct mode (CT33 `legacy-direct`), deleted with it (D10).
|
|
41
|
+
prepare: dependencies.artifact,
|
|
42
|
+
deploy: (parameters, context) => deployCloudflare(parameters, context, dependencies),
|
|
43
|
+
secretsFile: (parameters) => parameters.secrets,
|
|
44
|
+
});
|
|
45
|
+
return defineDeployment(adapter, parameters);
|
|
46
|
+
}
|
|
47
|
+
/** Refuse a malformed `namespace` when the Project is defined, before any build. */
|
|
48
|
+
function admitCloudflare(parameters) {
|
|
49
|
+
if (parameters.namespace !== undefined)
|
|
50
|
+
admitNamespace(parameters.namespace);
|
|
51
|
+
}
|
|
52
|
+
function platformNamespaceDependencies() {
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
fetch: (input, init) => fetch(input, init),
|
|
55
|
+
environment: process.env,
|
|
56
|
+
createSigningIdentity,
|
|
57
|
+
now: () => new Date(),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as nodeModule from 'node:module';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { compiledWasmLoader, compiledWasmSource } from './compiled-wasm-loader.js';
|
|
4
|
+
let compiledWasm = false;
|
|
5
|
+
/**
|
|
6
|
+
* Import a WebAssembly module as Workers do for `CompiledWasm`: its default export is the compiled
|
|
7
|
+
* `WebAssembly.Module`, instantiated by the importing code. The CLI admits bundles under Bun; Node
|
|
8
|
+
* serves programmatic builds.
|
|
9
|
+
*/
|
|
10
|
+
function admitCompiledWasm() {
|
|
11
|
+
if (compiledWasm)
|
|
12
|
+
return;
|
|
13
|
+
if (process.versions.bun !== undefined) {
|
|
14
|
+
;
|
|
15
|
+
Reflect.get(globalThis, 'Bun').plugin({
|
|
16
|
+
name: 'astrale-compiled-wasm',
|
|
17
|
+
setup(build) {
|
|
18
|
+
build.onLoad({ filter: /\.wasm$/ }, ({ path }) => ({
|
|
19
|
+
loader: 'js',
|
|
20
|
+
contents: compiledWasmSource(JSON.stringify(path)),
|
|
21
|
+
}));
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
compiledWasm = true;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
nodeModule.register(compiledWasmLoader);
|
|
28
|
+
compiledWasm = true;
|
|
29
|
+
}
|
|
30
|
+
export async function admitWorkerBundle(path) {
|
|
31
|
+
admitCompiledWasm();
|
|
32
|
+
const loaded = (await import(`${pathToFileURL(path).href}?admit=${Date.now()}`));
|
|
33
|
+
if (loaded.default === null ||
|
|
34
|
+
typeof loaded.default !== 'object' ||
|
|
35
|
+
typeof Reflect.get(loaded.default, 'fetch') !== 'function') {
|
|
36
|
+
throw new TypeError('Generated Worker bundle does not export a Fetch handler.');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Admit the separately emitted engine's actual platform exports, including its compiled WASM. */
|
|
40
|
+
export async function admitDurableEngineBundle(path) {
|
|
41
|
+
admitCompiledWasm();
|
|
42
|
+
const engine = (await import(`${pathToFileURL(path).href}?admit=${Date.now()}`));
|
|
43
|
+
if (['createEndpointHandler', 'workflow', 'TerminalError', 'CancelledError'].some((key) => typeof engine[key] !== 'function')) {
|
|
44
|
+
throw new TypeError('Generated durable engine bundle does not export the platform Fetch entrypoint.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Workers expose CompiledWasm imports as modules, rather than instantiated exports. */
|
|
2
|
+
export declare function compiledWasmSource(file: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Async hooks run in a separate Node thread. A self-contained ESM hook admits both emitted JS and
|
|
5
|
+
* source builds under tsx without requiring that thread to resolve or transpile our source files.
|
|
6
|
+
* The emitted import source is shared with Bun.
|
|
7
|
+
*/
|
|
8
|
+
export declare const compiledWasmLoader: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const SOURCE_PREFIX = "import { readFileSync } from 'node:fs'\nexport default new WebAssembly.Module(readFileSync(";
|
|
2
|
+
const SOURCE_SUFFIX = '))\n';
|
|
3
|
+
/** Workers expose CompiledWasm imports as modules, rather than instantiated exports. */
|
|
4
|
+
export function compiledWasmSource(file) {
|
|
5
|
+
return `${SOURCE_PREFIX}${file}${SOURCE_SUFFIX}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Async hooks run in a separate Node thread. A self-contained ESM hook admits both emitted JS and
|
|
9
|
+
* source builds under tsx without requiring that thread to resolve or transpile our source files.
|
|
10
|
+
* The emitted import source is shared with Bun.
|
|
11
|
+
*/
|
|
12
|
+
export const compiledWasmLoader = `data:text/javascript,${encodeURIComponent(`
|
|
13
|
+
export function load(url, context, nextLoad) {
|
|
14
|
+
if (!url.startsWith('file:') || !url.endsWith('.wasm')) return nextLoad(url, context);
|
|
15
|
+
return {
|
|
16
|
+
format: 'module',
|
|
17
|
+
shortCircuit: true,
|
|
18
|
+
source: ${JSON.stringify(SOURCE_PREFIX)} + 'new URL(' + JSON.stringify(url) + ')' + ${JSON.stringify(SOURCE_SUFFIX)},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
`)}`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Bundle, BundleContext, Bundler } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
3
|
+
import type { ReleaseModule } from './worker/execution.prepare.js';
|
|
4
|
+
/**
|
|
5
|
+
* Environment-free bytes of one generated Worker: its entry, the modules it loads (the execution
|
|
6
|
+
* Service, the deferred workflow engine and their WASM) and its frontend.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkerBytes {
|
|
9
|
+
readonly entry: Uint8Array;
|
|
10
|
+
readonly modules: readonly ReleaseModule[];
|
|
11
|
+
readonly frontend: readonly frontendBuild.FrontendFile[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Bundles every generated Cloudflare Worker, for adapter-cloudflare and adapter-astrale alike. It
|
|
15
|
+
* reads no Environment: settings, address, issuer and key are bound at deploy.
|
|
16
|
+
*/
|
|
17
|
+
export declare const cloudflareWorkerBundler: Bundler;
|
|
18
|
+
/** Bundle the Worker modules and build the frontend they serve, in one scratch directory. */
|
|
19
|
+
export declare function bundleWorker(context: BundleContext): Promise<WorkerBytes>;
|
|
20
|
+
/** Read back the Worker bytes of a Bundle this bundler produced for the same Build. */
|
|
21
|
+
export declare function bundledWorker(bundle: Bundle, build: Bundle['build']): WorkerBytes;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CLOUDFLARE_WORKER_BUNDLER, workerAssetFile } from '../release/build.js';
|
|
4
|
+
import { frontendFiles } from './frontend/files.js';
|
|
5
|
+
import { frontendRevision } from './frontend/revision.js';
|
|
6
|
+
import { prepareExecution, RELEASE_ENTRY, RELEASE_SERVICE } from './worker/execution.prepare.js';
|
|
7
|
+
/** Worker modules live beside the entry; WASM is the only non-ESM kind preparation emits. */
|
|
8
|
+
const MODULE_DIRECTORY = 'bundle/';
|
|
9
|
+
/**
|
|
10
|
+
* Bundles every generated Cloudflare Worker, for adapter-cloudflare and adapter-astrale alike. It
|
|
11
|
+
* reads no Environment: settings, address, issuer and key are bound at deploy.
|
|
12
|
+
*/
|
|
13
|
+
export const cloudflareWorkerBundler = Object.freeze({
|
|
14
|
+
id: CLOUDFLARE_WORKER_BUNDLER.id,
|
|
15
|
+
version: CLOUDFLARE_WORKER_BUNDLER.version,
|
|
16
|
+
async bundle(context) {
|
|
17
|
+
const worker = await bundleWorker(context);
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
entrypoint: RELEASE_ENTRY,
|
|
20
|
+
files: Object.freeze([
|
|
21
|
+
{ path: RELEASE_ENTRY, content: worker.entry },
|
|
22
|
+
...worker.modules.map(({ path, content }) => ({ path, content })),
|
|
23
|
+
...worker.frontend.map((file) => ({
|
|
24
|
+
path: workerAssetFile(`/${file.path}`),
|
|
25
|
+
content: file.bytes(),
|
|
26
|
+
})),
|
|
27
|
+
]),
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
/** Bundle the Worker modules and build the frontend they serve, in one scratch directory. */
|
|
32
|
+
export async function bundleWorker(context) {
|
|
33
|
+
const stateDirectory = join(context.projectDir, '.astrale');
|
|
34
|
+
await mkdir(stateDirectory, { recursive: true });
|
|
35
|
+
const directory = await mkdtemp(join(stateDirectory, 'prepare-'));
|
|
36
|
+
try {
|
|
37
|
+
// `frontend` is the served file list; `addressed` rides alongside it into the Worker, where it
|
|
38
|
+
// decides which of those files a browser may retain.
|
|
39
|
+
const { files: frontend, addressed } = await frontendFiles({
|
|
40
|
+
frontend: context.build.frontend,
|
|
41
|
+
projectDir: context.projectDir,
|
|
42
|
+
output: join(directory, 'frontend'),
|
|
43
|
+
recordSource: context.recordSource,
|
|
44
|
+
signal: context.signal,
|
|
45
|
+
});
|
|
46
|
+
const modules = await prepareExecution({
|
|
47
|
+
context,
|
|
48
|
+
directory,
|
|
49
|
+
...(frontend.length === 0 ? {} : { frontendRevision: frontendRevision(frontend) }),
|
|
50
|
+
...(addressed.length === 0 ? {} : { frontendAddressed: addressed }),
|
|
51
|
+
});
|
|
52
|
+
return Object.freeze({ entry: modules.entry, modules: modules.modules, frontend });
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await rm(directory, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Read back the Worker bytes of a Bundle this bundler produced for the same Build. */
|
|
59
|
+
export function bundledWorker(bundle, build) {
|
|
60
|
+
const { id, version } = bundle.manifest.bundler;
|
|
61
|
+
if (bundle.build !== build ||
|
|
62
|
+
id !== CLOUDFLARE_WORKER_BUNDLER.id ||
|
|
63
|
+
version !== CLOUDFLARE_WORKER_BUNDLER.version ||
|
|
64
|
+
bundle.entrypoint !== RELEASE_ENTRY) {
|
|
65
|
+
throw new TypeError('Cloudflare preparation requires the Bundle of its Worker bundler.');
|
|
66
|
+
}
|
|
67
|
+
let entry;
|
|
68
|
+
const modules = [];
|
|
69
|
+
const frontend = [];
|
|
70
|
+
for (const file of bundle.files) {
|
|
71
|
+
if (file.path === RELEASE_ENTRY)
|
|
72
|
+
entry = file.bytes();
|
|
73
|
+
else if (file.path.startsWith(MODULE_DIRECTORY) && /\.(?:mjs|wasm)$/u.test(file.path)) {
|
|
74
|
+
modules.push(Object.freeze({
|
|
75
|
+
path: file.path,
|
|
76
|
+
kind: file.path.endsWith('.wasm') ? 'wasm' : 'esm',
|
|
77
|
+
content: file.bytes(),
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
else if (file.path.startsWith('assets/')) {
|
|
81
|
+
const content = file.bytes();
|
|
82
|
+
frontend.push(Object.freeze({ path: file.path.slice('assets/'.length), bytes: () => content.slice() }));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new TypeError(`Cloudflare Worker Bundle file ${file.path} is not a Worker file.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (entry === undefined || !modules.some((module) => module.path === RELEASE_SERVICE)) {
|
|
89
|
+
throw new TypeError('Cloudflare Worker Bundle lacks its execution modules.');
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
entry,
|
|
93
|
+
modules: Object.freeze(modules),
|
|
94
|
+
frontend: Object.freeze(frontend),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readWranglerMetafile } from './metafile.js';
|
|
2
|
+
const FORBIDDEN_RUNTIME_INPUTS = [
|
|
3
|
+
'/v1/builder/',
|
|
4
|
+
'/v1/compiled/compiler/',
|
|
5
|
+
'/node_modules/ajv/',
|
|
6
|
+
'/node_modules/re2js/',
|
|
7
|
+
'/kernel-core/domain/',
|
|
8
|
+
'/core/domain/',
|
|
9
|
+
'/kernel-core/schema/index.',
|
|
10
|
+
'/core/schema/index.',
|
|
11
|
+
];
|
|
12
|
+
/** Prove emitted Worker reachability excludes authoring, compilation, and broad Core Schema owners. */
|
|
13
|
+
export async function assertRuntimeClosure(metafilePath) {
|
|
14
|
+
const metafile = await readWranglerMetafile(metafilePath);
|
|
15
|
+
const forbidden = Object.keys(metafile.inputs).filter((input) => {
|
|
16
|
+
const normalized = `/${input.replaceAll('\\', '/')}`.replace(/(\/node_modules\/@astrale-os\/kernel-[^/]+)\/dist\//gu, '$1/');
|
|
17
|
+
return FORBIDDEN_RUNTIME_INPUTS.some((fragment) => normalized.includes(fragment));
|
|
18
|
+
});
|
|
19
|
+
if (forbidden.length > 0) {
|
|
20
|
+
throw new Error(`Cloudflare Worker reaches build-side modules: ${forbidden.sort().join(', ')}.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -13,22 +13,32 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export interface WranglerCodegenOptions {
|
|
15
15
|
workerName: string;
|
|
16
|
+
/** Provider-ready entrypoint relative to the generated config. */
|
|
17
|
+
main?: string;
|
|
16
18
|
/** Full custom hostname for a routed deploy (e.g. 'crm.acme.dev'). */
|
|
17
19
|
route?: string;
|
|
18
20
|
/** Exact materialized local frontend; absence means no ASSETS binding. */
|
|
19
21
|
frontend?: {
|
|
20
22
|
readonly directory: string;
|
|
21
|
-
readonly routes: readonly string[];
|
|
22
|
-
readonly dev: boolean;
|
|
23
23
|
};
|
|
24
24
|
/** Plain (non-secret) vars to bake in. */
|
|
25
25
|
vars?: Record<string, string>;
|
|
26
|
+
/** Secret binding names required by generated Worker code. */
|
|
27
|
+
secretBindings?: readonly string[];
|
|
28
|
+
/** Modules retained outside the startup entry and loaded on demand. */
|
|
29
|
+
modules?: {
|
|
30
|
+
readonly baseDir: string;
|
|
31
|
+
readonly rules: readonly {
|
|
32
|
+
readonly type: 'ESModule' | 'CompiledWasm' | 'Text' | 'Data';
|
|
33
|
+
readonly globs: readonly string[];
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
26
36
|
/** Add the SELF service binding (autobinding). */
|
|
27
37
|
selfBinding: boolean;
|
|
28
38
|
/**
|
|
29
39
|
* Add a service binding to a router Worker for instance-host subrequest
|
|
30
|
-
* routing (see `CloudflareParams.router`). Pairs with the
|
|
31
|
-
*
|
|
40
|
+
* routing (see `CloudflareParams.router`). Pairs with the router rule bound
|
|
41
|
+
* in `ASTRALE_SETTINGS`.
|
|
32
42
|
*/
|
|
33
43
|
router?: {
|
|
34
44
|
binding: string;
|
|
@@ -39,9 +49,25 @@ export interface WranglerCodegenOptions {
|
|
|
39
49
|
* hatch for extra bindings (KV, R2, D1, queues, service bindings, extra
|
|
40
50
|
* `compatibility_flags`, cron `triggers`, …). Arrays concat; new keys are
|
|
41
51
|
* added as-is. The adapter-owned keys `name`, `main`, `assets`, `routes` are
|
|
42
|
-
* rejected (throws) — use `workerName` / `route` instead
|
|
52
|
+
* rejected (throws) — use `workerName` / `route` instead — and so are the keys
|
|
53
|
+
* and compatibility flags Wrangler's bundler reads.
|
|
43
54
|
*/
|
|
44
55
|
wrangler?: Record<string, unknown>;
|
|
45
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The Workers runtime every generated Worker runs on, wherever it is deployed: its compatibility
|
|
59
|
+
* date, kept on the runtime baseline qualified with Wrangler 4.123.0, and its compatibility flags.
|
|
60
|
+
* Domain execution calls its Kernel through the invocation's public issuer, so Cloudflare must route
|
|
61
|
+
* same-zone callbacks through the public front door instead of bypassing Worker routes
|
|
62
|
+
* (`global_fetch_strictly_public`). An immutable deployment freezes it into its configuration.
|
|
63
|
+
*/
|
|
64
|
+
export declare const GENERATED_WORKER_RUNTIME: Readonly<{
|
|
65
|
+
compatibilityDate: "2026-08-11";
|
|
66
|
+
compatibilityFlags: readonly string[];
|
|
67
|
+
}>;
|
|
46
68
|
export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
|
|
47
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Whether a compatibility flag shapes the bundle (Wrangler's bundler reads it), so that no
|
|
71
|
+
* Environment may add it: bundling takes no Environment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isBundlingCompatibilityFlag(flag: string): boolean;
|