@astrale-os/adapter-cloudflare 0.5.0-beta.3 → 0.5.0-beta.31

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.
Files changed (174) hide show
  1. package/README.md +11 -0
  2. package/dist/adapter.d.ts +17 -0
  3. package/dist/adapter.js +174 -0
  4. package/dist/build/artifact.d.ts +7 -0
  5. package/dist/build/artifact.js +150 -0
  6. package/dist/build/bundle/admit.d.ts +1 -0
  7. package/dist/build/bundle/admit.js +9 -0
  8. package/dist/build/closure.d.ts +2 -0
  9. package/dist/build/closure.js +22 -0
  10. package/dist/build/codegen/execution.d.ts +3 -0
  11. package/dist/build/codegen/execution.js +2 -0
  12. package/dist/build/codegen/gateway.d.ts +1 -0
  13. package/dist/build/codegen/gateway.js +1 -0
  14. package/dist/build/codegen/merge.d.ts +0 -1
  15. package/dist/build/codegen/merge.js +0 -1
  16. package/dist/build/codegen/wrangler.d.ts +15 -1
  17. package/dist/build/codegen/wrangler.js +35 -16
  18. package/dist/build/configuration/addressing.d.ts +2 -0
  19. package/dist/build/configuration/addressing.js +11 -0
  20. package/dist/build/configuration/router.d.ts +7 -0
  21. package/dist/build/configuration/router.js +11 -0
  22. package/dist/build/configuration/worker-name.d.ts +2 -0
  23. package/dist/build/configuration/worker-name.js +18 -0
  24. package/dist/build/configuration.d.ts +3 -0
  25. package/dist/build/configuration.js +3 -0
  26. package/dist/build/direct.d.ts +4 -0
  27. package/dist/build/direct.js +52 -0
  28. package/dist/build/frontend/routes.d.ts +2 -0
  29. package/dist/build/frontend/routes.js +11 -0
  30. package/dist/build/frontend-v1.d.ts +16 -0
  31. package/dist/build/frontend-v1.js +133 -0
  32. package/dist/build/gateway/prepare.d.ts +8 -0
  33. package/dist/build/gateway/prepare.js +32 -0
  34. package/dist/build/gateway/source.d.ts +1 -0
  35. package/dist/build/gateway/source.js +7 -0
  36. package/dist/build/index.d.ts +10 -16
  37. package/dist/build/index.js +9 -16
  38. package/dist/build/materialize.d.ts +4 -0
  39. package/dist/build/materialize.js +10 -0
  40. package/dist/build/metafile.d.ts +5 -0
  41. package/dist/build/metafile.js +14 -0
  42. package/dist/build/parse-output.d.ts +0 -1
  43. package/dist/build/parse-output.js +0 -1
  44. package/dist/build/qualification.d.ts +5 -0
  45. package/dist/build/qualification.js +7 -0
  46. package/dist/build/roots.d.ts +2 -0
  47. package/dist/build/roots.js +34 -0
  48. package/dist/build/worker/artifact.d.ts +38 -0
  49. package/dist/build/worker/artifact.js +1 -0
  50. package/dist/build/worker/artifact.load.d.ts +3 -0
  51. package/dist/build/worker/artifact.load.js +266 -0
  52. package/dist/build/worker/artifact.manifest.d.ts +46 -0
  53. package/dist/build/worker/artifact.manifest.js +84 -0
  54. package/dist/build/worker/artifact.paths.d.ts +4 -0
  55. package/dist/build/worker/artifact.paths.js +25 -0
  56. package/dist/build/worker/codegen/entry.d.ts +2 -0
  57. package/dist/build/worker/codegen/entry.js +28 -0
  58. package/dist/build/worker/codegen/service.d.ts +13 -0
  59. package/dist/build/worker/codegen/service.js +44 -0
  60. package/dist/build/worker/execution.prepare.d.ts +18 -0
  61. package/dist/build/worker/execution.prepare.js +102 -0
  62. package/dist/build/worker/index.d.ts +2 -0
  63. package/dist/build/worker/index.js +1 -0
  64. package/dist/build/worker/runtime.d.ts +10 -0
  65. package/dist/build/worker/runtime.js +35 -0
  66. package/dist/build/wrangler/bundle.d.ts +10 -0
  67. package/dist/build/wrangler/bundle.js +29 -0
  68. package/dist/build/wrangler/deploy.d.ts +23 -0
  69. package/dist/build/wrangler/deploy.js +35 -0
  70. package/dist/build/wrangler/development.d.ts +15 -0
  71. package/dist/build/wrangler/development.js +135 -0
  72. package/dist/build/wrangler/namespace.d.ts +10 -0
  73. package/dist/build/wrangler/namespace.js +26 -0
  74. package/dist/build/wrangler/process.d.ts +15 -0
  75. package/dist/build/wrangler/process.js +103 -0
  76. package/dist/build/wrangler/release.d.ts +11 -0
  77. package/dist/build/wrangler/release.js +27 -0
  78. package/dist/build/wrangler/secrets.d.ts +6 -0
  79. package/dist/build/wrangler/secrets.js +58 -0
  80. package/dist/build/wrangler/status.d.ts +14 -0
  81. package/dist/build/wrangler/status.js +56 -0
  82. package/dist/build/wrangler/type-generation.d.ts +6 -0
  83. package/dist/build/wrangler/type-generation.js +19 -0
  84. package/dist/build/wrangler-cli.d.ts +8 -86
  85. package/dist/build/wrangler-cli.js +8 -275
  86. package/dist/cloudflare.d.ts +1 -34
  87. package/dist/cloudflare.js +1 -205
  88. package/dist/deploy/deploy.d.ts +17 -0
  89. package/dist/deploy/deploy.js +234 -0
  90. package/dist/deploy/index.d.ts +1 -0
  91. package/dist/deploy/index.js +1 -0
  92. package/dist/identity/binding.d.ts +2 -0
  93. package/dist/identity/binding.js +2 -0
  94. package/dist/identity/material.d.ts +7 -0
  95. package/dist/identity/material.js +42 -0
  96. package/dist/identity/secret.d.ts +3 -0
  97. package/dist/identity/secret.js +7 -0
  98. package/dist/identity/source.d.ts +26 -0
  99. package/dist/identity/source.js +98 -0
  100. package/dist/index.d.ts +3 -4
  101. package/dist/index.js +3 -4
  102. package/dist/params.d.ts +18 -5
  103. package/dist/params.js +0 -1
  104. package/dist/release/index.d.ts +2 -0
  105. package/dist/release/index.js +2 -0
  106. package/dist/release/namespace.d.ts +2 -0
  107. package/dist/release/namespace.js +6 -0
  108. package/dist/release/target.d.ts +2 -0
  109. package/dist/release/target.js +9 -0
  110. package/dist/worker/entry.d.ts +38 -0
  111. package/dist/worker/entry.js +161 -0
  112. package/dist/worker/fetch.d.ts +11 -0
  113. package/dist/worker/fetch.js +31 -0
  114. package/dist/worker/gateway.d.ts +15 -0
  115. package/dist/worker/gateway.js +26 -0
  116. package/dist/worker/identity.d.ts +7 -0
  117. package/dist/worker/identity.js +23 -0
  118. package/dist/worker/index.d.ts +3 -59
  119. package/dist/worker/index.js +3 -209
  120. package/package.json +21 -18
  121. package/template/astrale.config.ts +19 -11
  122. package/dist/build/codegen/identity.d.ts +0 -10
  123. package/dist/build/codegen/identity.d.ts.map +0 -1
  124. package/dist/build/codegen/identity.js +0 -32
  125. package/dist/build/codegen/identity.js.map +0 -1
  126. package/dist/build/codegen/merge.d.ts.map +0 -1
  127. package/dist/build/codegen/merge.js.map +0 -1
  128. package/dist/build/codegen/worker.d.ts +0 -12
  129. package/dist/build/codegen/worker.d.ts.map +0 -1
  130. package/dist/build/codegen/worker.js +0 -40
  131. package/dist/build/codegen/worker.js.map +0 -1
  132. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  133. package/dist/build/codegen/wrangler.js.map +0 -1
  134. package/dist/build/frontend.d.ts +0 -26
  135. package/dist/build/frontend.d.ts.map +0 -1
  136. package/dist/build/frontend.js +0 -263
  137. package/dist/build/frontend.js.map +0 -1
  138. package/dist/build/index.d.ts.map +0 -1
  139. package/dist/build/index.js.map +0 -1
  140. package/dist/build/parse-output.d.ts.map +0 -1
  141. package/dist/build/parse-output.js.map +0 -1
  142. package/dist/build/prepare.d.ts +0 -18
  143. package/dist/build/prepare.d.ts.map +0 -1
  144. package/dist/build/prepare.js +0 -117
  145. package/dist/build/prepare.js.map +0 -1
  146. package/dist/build/worker.d.ts +0 -15
  147. package/dist/build/worker.d.ts.map +0 -1
  148. package/dist/build/worker.js +0 -21
  149. package/dist/build/worker.js.map +0 -1
  150. package/dist/build/wrangler-cli.d.ts.map +0 -1
  151. package/dist/build/wrangler-cli.js.map +0 -1
  152. package/dist/cloudflare.d.ts.map +0 -1
  153. package/dist/cloudflare.js.map +0 -1
  154. package/dist/index.d.ts.map +0 -1
  155. package/dist/index.js.map +0 -1
  156. package/dist/params.d.ts.map +0 -1
  157. package/dist/params.js.map +0 -1
  158. package/dist/worker/index.d.ts.map +0 -1
  159. package/dist/worker/index.js.map +0 -1
  160. package/src/build/codegen/identity.ts +0 -40
  161. package/src/build/codegen/merge.ts +0 -92
  162. package/src/build/codegen/worker.ts +0 -53
  163. package/src/build/codegen/wrangler.ts +0 -127
  164. package/src/build/frontend.ts +0 -324
  165. package/src/build/index.ts +0 -29
  166. package/src/build/parse-output.ts +0 -60
  167. package/src/build/prepare.ts +0 -161
  168. package/src/build/worker.ts +0 -37
  169. package/src/build/wrangler-cli.ts +0 -362
  170. package/src/cloudflare.ts +0 -251
  171. package/src/index.ts +0 -21
  172. package/src/params.ts +0 -92
  173. package/src/worker/index.ts +0 -312
  174. package/src/worker/tsconfig.json +0 -10
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@astrale-os/adapter-cloudflare`
2
+
3
+ Cloudflare Worker deployment adapter for Astrale Domains.
4
+
5
+ During the SDK beta program, install the beta package set explicitly:
6
+
7
+ ```bash
8
+ npm install @astrale-os/sdk@beta @astrale-os/adapter-cloudflare@beta
9
+ ```
10
+
11
+ Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
@@ -0,0 +1,17 @@
1
+ import type { Release } from '@astrale-os/sdk/deployment/release';
2
+ import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
3
+ import type { CloudflareParams } from './params.js';
4
+ import { artifact } from './build/artifact.js';
5
+ import { startFrontend } from './build/frontend-v1.js';
6
+ import { runWranglerDev } from './build/wrangler-cli.js';
7
+ import { type CloudflareDeployDependencies } from './deploy/index.js';
8
+ import { signingIdentity } from './identity/source.js';
9
+ export interface CloudflareDependencies extends CloudflareDeployDependencies {
10
+ readonly artifact: typeof artifact;
11
+ readonly runWranglerDev: typeof runWranglerDev;
12
+ readonly startFrontend: typeof startFrontend;
13
+ readonly signingIdentity: typeof signingIdentity;
14
+ }
15
+ export declare function cloudflare(environments: Readonly<Record<string, CloudflareParams>>): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
16
+ export declare function cloudflareWithDependencies(environments: Readonly<Record<string, CloudflareParams>>, dependencies: CloudflareDependencies): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
17
+ export declare function waitForReadiness(verify: typeof verifyReadiness, release: Release, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,174 @@
1
+ import { defineAdapter } from '@astrale-os/sdk/deployment/adapter';
2
+ import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { createRequire } from 'node:module';
5
+ import { join } from 'node:path';
6
+ import { artifact, materialize } from './build/artifact.js';
7
+ import { generateWranglerConfig } from './build/codegen/wrangler.js';
8
+ import { resolveRouter, workerName } from './build/configuration.js';
9
+ import { startFrontend } from './build/frontend-v1.js';
10
+ import { ensureWranglerDispatchNamespace, runWranglerDeploymentStatus, runWranglerDeploy, runWranglerDev, runWranglerReleaseDeploy, } from './build/wrangler-cli.js';
11
+ import { deployCloudflare } from './deploy/index.js';
12
+ import { signingIdentitySecrets } from './identity/secret.js';
13
+ import { signingIdentity } from './identity/source.js';
14
+ const packageVersion = createRequire(import.meta.url)('../package.json')
15
+ .version;
16
+ export function cloudflare(environments) {
17
+ return cloudflareWithDependencies(environments, {
18
+ artifact,
19
+ materialize,
20
+ ensureWranglerDispatchNamespace,
21
+ runWranglerDeploy,
22
+ runWranglerReleaseDeploy,
23
+ runWranglerDeploymentStatus,
24
+ runWranglerDev,
25
+ startFrontend,
26
+ signingIdentity,
27
+ waitForReadiness: (release, signal) => waitForReadiness(verifyReadiness, release, signal),
28
+ });
29
+ }
30
+ export function cloudflareWithDependencies(environments, dependencies) {
31
+ return defineAdapter({
32
+ name: 'cloudflare',
33
+ version: packageVersion,
34
+ environments,
35
+ prepare: dependencies.artifact,
36
+ async watch(parameters, context) {
37
+ const identity = await dependencies.signingIdentity({
38
+ projectDir: context.projectDir,
39
+ source: parameters.signingIdentity,
40
+ origin: context.artifact.build.schema.compiled.root.origin,
41
+ mode: 'local',
42
+ });
43
+ const secrets = signingIdentitySecrets(context.secrets, identity);
44
+ const directory = join(context.projectDir, '.astrale', 'runtime');
45
+ await dependencies.materialize(directory, context.artifact.files);
46
+ const frontend = await dependencies.startFrontend({
47
+ frontend: context.artifact.build.frontend,
48
+ projectDir: context.projectDir,
49
+ });
50
+ const name = workerName(parameters, context.artifact.build.schema.compiled.root.origin);
51
+ // A local workerd cannot reach the default deployed router Worker through a service
52
+ // binding. Keep it for remote isolates and explicit multi-Worker development; ordinary
53
+ // local execution falls back to the admitted fetch path when ROUTER is absent.
54
+ const router = parameters.remote === true || parameters.router !== undefined
55
+ ? resolveRouter(parameters.router)
56
+ : undefined;
57
+ const configPath = join(directory, 'wrangler.watch.jsonc');
58
+ await writeFile(configPath, generateWranglerConfig({
59
+ workerName: name,
60
+ main: `./${context.artifact.entrypoint}`,
61
+ vars: {
62
+ ...parameters.vars,
63
+ ...(parameters.host === undefined ? {} : { WORKER_URL: parameters.host }),
64
+ ...(frontend === undefined ? {} : { FRONTEND_DEV_URL: frontend.url }),
65
+ },
66
+ secretBindings: Object.keys(secrets).sort(),
67
+ ...(context.artifact.build.frontend?.source.kind === 'vite'
68
+ ? {
69
+ frontend: {
70
+ directory: './frontend',
71
+ routes: frontendRoutes(context.artifact),
72
+ dev: true,
73
+ },
74
+ }
75
+ : {}),
76
+ ...(router === undefined
77
+ ? {}
78
+ : { router: { binding: router.binding, service: router.service } }),
79
+ ...(parameters.wrangler === undefined ? {} : { wrangler: parameters.wrangler }),
80
+ selfBinding: true,
81
+ }));
82
+ let worker;
83
+ try {
84
+ worker = await dependencies.runWranglerDev({
85
+ projectDir: context.projectDir,
86
+ configPath,
87
+ port: parameters.port ?? 8787,
88
+ remote: parameters.remote ?? false,
89
+ secrets,
90
+ autoPickPort: parameters.port === undefined,
91
+ ...(parameters.host === undefined ? {} : { ip: '0.0.0.0' }),
92
+ onReload: context.onReload,
93
+ });
94
+ }
95
+ catch (cause) {
96
+ await frontend?.stop().catch(() => undefined);
97
+ throw cause;
98
+ }
99
+ return Object.freeze({
100
+ url: parameters.host ?? worker.url,
101
+ localUrl: worker.url,
102
+ async stop() {
103
+ const results = await Promise.allSettled([
104
+ worker.stop(),
105
+ frontend?.stop() ?? Promise.resolve(),
106
+ ]);
107
+ const failures = results.filter((result) => result.status === 'rejected');
108
+ if (failures.length === 1)
109
+ throw failures[0].reason;
110
+ if (failures.length > 1) {
111
+ throw new AggregateError(failures.map((failure) => failure.reason), 'Cloudflare development cleanup failed.');
112
+ }
113
+ },
114
+ });
115
+ },
116
+ deploy: (parameters, context) => deployCloudflare(parameters, context, dependencies),
117
+ secretsFile: (parameters) => parameters.secrets,
118
+ });
119
+ }
120
+ function frontendRoutes(artifact) {
121
+ const frontend = artifact.build.frontend;
122
+ if (frontend === undefined || frontend.source.kind !== 'vite')
123
+ return [];
124
+ return Object.freeze(frontend.routes
125
+ .flatMap((route) => frontend.source.kind === 'vite' && frontend.source.spa && route.path !== '/'
126
+ ? [route.path, `${route.path}/*`]
127
+ : route.path === '/'
128
+ ? ['/*']
129
+ : [route.path])
130
+ .sort());
131
+ }
132
+ export async function waitForReadiness(verify, release, signal) {
133
+ const deadline = Date.now() + 90_000;
134
+ let last;
135
+ while (Date.now() < deadline) {
136
+ throwIfAborted(signal);
137
+ try {
138
+ await verify(release, {
139
+ signal: signal === undefined
140
+ ? AbortSignal.timeout(5_000)
141
+ : AbortSignal.any([signal, AbortSignal.timeout(5_000)]),
142
+ });
143
+ return;
144
+ }
145
+ catch (cause) {
146
+ throwIfAborted(signal);
147
+ last = cause;
148
+ await pause(signal);
149
+ }
150
+ }
151
+ throw last instanceof Error ? last : new Error('Cloudflare Release did not become ready.');
152
+ }
153
+ function pause(signal) {
154
+ return new Promise((resolve, reject) => {
155
+ const timer = setTimeout(done, 1_000);
156
+ const abort = () => done(abortError(signal));
157
+ signal?.addEventListener('abort', abort, { once: true });
158
+ function done(cause) {
159
+ clearTimeout(timer);
160
+ signal?.removeEventListener('abort', abort);
161
+ if (cause === undefined)
162
+ resolve();
163
+ else
164
+ reject(cause);
165
+ }
166
+ });
167
+ }
168
+ function throwIfAborted(signal) {
169
+ if (signal?.aborted)
170
+ throw abortError(signal);
171
+ }
172
+ function abortError(signal) {
173
+ return signal?.reason instanceof Error ? signal.reason : new Error('Deployment interrupted.');
174
+ }
@@ -0,0 +1,7 @@
1
+ import type { ArtifactSource, PrepareContext } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { CloudflareParams } from '../params.js';
3
+ export { materialize } from './materialize.js';
4
+ /** Prepare one revision Service and its stateless gateway without provider mutation. */
5
+ export declare function artifact(params: CloudflareParams, context: PrepareContext): Promise<ArtifactSource>;
6
+ /** Prepare the complete portable Cloudflare Worker without direct Wrangler placement files. */
7
+ export declare function prepareWorkerArtifact(params: CloudflareParams, context: PrepareContext): Promise<ArtifactSource>;
@@ -0,0 +1,150 @@
1
+ import { addressing } from '@astrale-os/sdk/deployment/release';
2
+ import { mkdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { SIGNING_IDENTITY_BINDING } from '../identity/binding.js';
5
+ import { releaseNamespace, releaseWorkerName } from '../release/index.js';
6
+ import { generateWranglerConfig } from './codegen/wrangler.js';
7
+ import { deploymentAddressing, resolveRouter, workerName } from './configuration.js';
8
+ import { frontendFiles } from './frontend-v1.js';
9
+ import { frontendRoutes } from './frontend/routes.js';
10
+ import { prepareGateway } from './gateway/prepare.js';
11
+ import { encodeWorkerArtifactManifest, inferMediaType, workerContentDigest, WORKER_MANIFEST_PATH, } from './worker/artifact.manifest.js';
12
+ import { prepareExecution, RELEASE_ENTRY, RELEASE_SERVICE, runtimeVars, } from './worker/execution.prepare.js';
13
+ import { admitWorkerRuntimeConfiguration } from './worker/runtime.js';
14
+ export { materialize } from './materialize.js';
15
+ const encoder = new TextEncoder();
16
+ /** Prepare one revision Service and its stateless gateway without provider mutation. */
17
+ export async function artifact(params, context) {
18
+ return prepare(params, context, true);
19
+ }
20
+ /** Prepare the complete portable Cloudflare Worker without direct Wrangler placement files. */
21
+ export async function prepareWorkerArtifact(params, context) {
22
+ return prepare(params, context, false);
23
+ }
24
+ async function prepare(params, context, direct) {
25
+ const stateDirectory = join(context.projectDir, '.astrale');
26
+ const directory = join(stateDirectory, 'runtime');
27
+ await mkdir(directory, { recursive: true });
28
+ const router = resolveRouter(params.router);
29
+ const name = workerName(params, context.build.schema.compiled.root.origin);
30
+ const revision = context.build.schema.compiled.root.revision;
31
+ const namespace = releaseNamespace(name);
32
+ const target = releaseWorkerName(revision);
33
+ const configuredIssuer = deploymentAddressing(params);
34
+ const execution = await prepareExecution({
35
+ params,
36
+ context,
37
+ directory,
38
+ name,
39
+ direct,
40
+ configuredIssuer,
41
+ router,
42
+ });
43
+ const frontend = await frontendFiles({
44
+ frontend: context.build.frontend,
45
+ projectDir: context.projectDir,
46
+ });
47
+ const gatewayBundle = await prepareGateway({
48
+ projectDir: context.projectDir,
49
+ directory,
50
+ name,
51
+ ...(params.route === undefined ? {} : { route: params.route }),
52
+ namespace,
53
+ revision,
54
+ });
55
+ const releaseConfig = generateWranglerConfig({
56
+ workerName: target,
57
+ main: `./${RELEASE_ENTRY}`,
58
+ vars: runtimeVars(params, configuredIssuer),
59
+ secretBindings: [SIGNING_IDENTITY_BINDING],
60
+ modules: { baseDir: '.', globs: [RELEASE_SERVICE] },
61
+ ...(context.build.frontend?.source.kind === 'vite'
62
+ ? {
63
+ frontend: {
64
+ directory: './frontend',
65
+ routes: frontendRoutes(context.build.frontend),
66
+ dev: false,
67
+ },
68
+ }
69
+ : {}),
70
+ ...(router === undefined
71
+ ? {}
72
+ : { router: { binding: router.binding, service: router.service } }),
73
+ ...(params.wrangler === undefined ? {} : { wrangler: params.wrangler }),
74
+ selfBinding: false,
75
+ });
76
+ const gatewayConfig = generateWranglerConfig({
77
+ workerName: name,
78
+ main: './gateway/index.mjs',
79
+ ...(params.route === undefined ? {} : { route: params.route }),
80
+ releases: { binding: 'RELEASES', namespace },
81
+ selfBinding: false,
82
+ });
83
+ const runtime = admitWorkerRuntimeConfiguration(releaseConfig);
84
+ const manifest = encodeWorkerArtifactManifest({
85
+ origin: context.build.schema.compiled.root.origin,
86
+ revision,
87
+ release: {
88
+ entrypoint: RELEASE_ENTRY,
89
+ modules: [
90
+ { path: RELEASE_ENTRY, kind: 'esm', digest: workerContentDigest(execution.entry) },
91
+ { path: RELEASE_SERVICE, kind: 'esm', digest: workerContentDigest(execution.service) },
92
+ ],
93
+ },
94
+ gateway: {
95
+ entrypoint: 'gateway/index.mjs',
96
+ modules: [
97
+ { path: 'gateway/index.mjs', kind: 'esm', digest: workerContentDigest(gatewayBundle) },
98
+ ],
99
+ },
100
+ runtime: {
101
+ compatibilityDate: runtime.compatibilityDate,
102
+ compatibilityFlags: runtime.compatibilityFlags,
103
+ },
104
+ bindings: {
105
+ vars: runtime.vars,
106
+ services: runtime.services,
107
+ requiredSecrets: [SIGNING_IDENTITY_BINDING],
108
+ },
109
+ ...(frontend.length === 0
110
+ ? {}
111
+ : {
112
+ assets: {
113
+ files: frontend.map((file) => {
114
+ const contentType = file.mediaType ?? inferMediaType(file.path);
115
+ return {
116
+ path: `/${file.path}`,
117
+ artifactPath: `frontend/${file.path}`,
118
+ digest: workerContentDigest(file.bytes()),
119
+ ...(contentType === undefined ? {} : { contentType }),
120
+ };
121
+ }),
122
+ notFound: 'none',
123
+ runWorkerFirst: true,
124
+ },
125
+ }),
126
+ });
127
+ const files = [
128
+ { path: RELEASE_ENTRY, content: execution.entry },
129
+ { path: RELEASE_SERVICE, content: execution.service },
130
+ { path: 'gateway/index.mjs', content: gatewayBundle },
131
+ { path: WORKER_MANIFEST_PATH, content: manifest },
132
+ ...frontend.map((file) => ({
133
+ path: `frontend/${file.path}`,
134
+ content: file.bytes(),
135
+ })),
136
+ ...(direct
137
+ ? [
138
+ { path: 'wrangler.release.jsonc', content: encoder.encode(releaseConfig) },
139
+ { path: 'wrangler.gateway.jsonc', content: encoder.encode(gatewayConfig) },
140
+ ]
141
+ : []),
142
+ ];
143
+ return Object.freeze({
144
+ entrypoint: RELEASE_ENTRY,
145
+ files: Object.freeze(files),
146
+ addressing: configuredIssuer === undefined
147
+ ? Object.freeze({ kind: 'provider-assigned', claim: name })
148
+ : Object.freeze({ kind: 'configured', addressing: addressing(configuredIssuer) }),
149
+ });
150
+ }
@@ -0,0 +1 @@
1
+ export declare function admitWorkerBundle(path: string): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ export async function admitWorkerBundle(path) {
3
+ const loaded = (await import(`${pathToFileURL(path).href}?admit=${Date.now()}`));
4
+ if (loaded.default === null ||
5
+ typeof loaded.default !== 'object' ||
6
+ typeof Reflect.get(loaded.default, 'fetch') !== 'function') {
7
+ throw new TypeError('Generated Worker bundle does not export a Fetch handler.');
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ /** Prove emitted Worker reachability excludes authoring, compilation, and broad Core Schema owners. */
2
+ export declare function assertRuntimeClosure(metafilePath: string): Promise<void>;
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ export { generateExecutionEntry } from '../worker/codegen/entry.js';
2
+ export { generateExecutionService } from '../worker/codegen/service.js';
3
+ export type { ExecutionCodegenOptions } from '../worker/codegen/service.js';
@@ -0,0 +1,2 @@
1
+ export { generateExecutionEntry } from '../worker/codegen/entry.js';
2
+ export { generateExecutionService } from '../worker/codegen/service.js';
@@ -0,0 +1 @@
1
+ export { generateGatewayEntry } from '../gateway/source.js';
@@ -0,0 +1 @@
1
+ export { generateGatewayEntry } from '../gateway/source.js';
@@ -17,4 +17,3 @@
17
17
  * the caller (`generateWranglerConfig`), not here — this stays a generic merge.
18
18
  */
19
19
  export declare function deepMergeConfig(base: Record<string, unknown>, overlay: Record<string, unknown>): Record<string, unknown>;
20
- //# sourceMappingURL=merge.d.ts.map
@@ -88,4 +88,3 @@ function isPlainObject(v) {
88
88
  function isPrimitive(v) {
89
89
  return v === null || (typeof v !== 'object' && typeof v !== 'function');
90
90
  }
91
- //# sourceMappingURL=merge.js.map
@@ -13,17 +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
23
  readonly routes: readonly string[];
24
+ readonly dev: boolean;
22
25
  };
23
26
  /** Plain (non-secret) vars to bake in. */
24
27
  vars?: Record<string, string>;
28
+ /** Secret binding names required by generated Worker code. */
29
+ secretBindings?: readonly string[];
30
+ /** JavaScript modules retained outside the startup entry and loaded on demand. */
31
+ modules?: {
32
+ readonly baseDir: string;
33
+ readonly globs: readonly string[];
34
+ };
25
35
  /** Add the SELF service binding (autobinding). */
26
36
  selfBinding: boolean;
37
+ /** Bind the stable gateway to its private revision namespace. */
38
+ releases?: {
39
+ readonly binding: string;
40
+ readonly namespace: string;
41
+ };
27
42
  /**
28
43
  * Add a service binding to a router Worker for instance-host subrequest
29
44
  * routing (see `CloudflareParams.router`). Pairs with the worker
@@ -43,4 +58,3 @@ export interface WranglerCodegenOptions {
43
58
  wrangler?: Record<string, unknown>;
44
59
  }
45
60
  export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
46
- //# sourceMappingURL=wrangler.d.ts.map
@@ -12,12 +12,12 @@
12
12
  * (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
13
13
  */
14
14
  import { deepMergeConfig } from './merge.js';
15
- // Wrangler 4.121.0's pinned workerd accepts dates through 2026-08-11.
15
+ // Keep the generated date on the runtime baseline qualified with Wrangler 4.123.0.
16
16
  const COMPATIBILITY_DATE = '2026-08-11';
17
17
  export function generateWranglerConfig(opts) {
18
18
  const config = {
19
19
  name: opts.workerName,
20
- main: './worker.gen.ts',
20
+ main: opts.main ?? './worker.gen.ts',
21
21
  compatibility_date: COMPATIBILITY_DATE,
22
22
  compatibility_flags: ['nodejs_compat'],
23
23
  workers_dev: true,
@@ -31,19 +31,19 @@ export function generateWranglerConfig(opts) {
31
31
  config.assets = {
32
32
  directory: opts.frontend.directory,
33
33
  binding: 'ASSETS',
34
- run_worker_first: [
35
- '/invoke',
36
- '/invoke/*',
37
- '/install',
38
- '/install/*',
39
- '/health',
40
- '/health/*',
41
- '/meta',
42
- '/meta/*',
43
- '/.well-known',
44
- '/.well-known/*',
45
- ...opts.frontend.routes,
46
- ],
34
+ run_worker_first: opts.frontend.dev
35
+ ? true
36
+ : [
37
+ '/releases',
38
+ '/releases/*',
39
+ '/install',
40
+ '/install/*',
41
+ '/health',
42
+ '/health/*',
43
+ '/.well-known',
44
+ '/.well-known/*',
45
+ ...opts.frontend.routes,
46
+ ],
47
47
  };
48
48
  }
49
49
  const services = [];
@@ -57,6 +57,23 @@ export function generateWranglerConfig(opts) {
57
57
  if (opts.vars && Object.keys(opts.vars).length > 0) {
58
58
  config.vars = opts.vars;
59
59
  }
60
+ if (opts.secretBindings && opts.secretBindings.length > 0) {
61
+ config.secrets = { required: [...opts.secretBindings] };
62
+ }
63
+ if (opts.modules !== undefined) {
64
+ config.find_additional_modules = true;
65
+ config.base_dir = opts.modules.baseDir;
66
+ config.rules = [
67
+ {
68
+ type: 'ESModule',
69
+ globs: [...opts.modules.globs],
70
+ fallthrough: true,
71
+ },
72
+ ];
73
+ }
74
+ if (opts.releases !== undefined) {
75
+ config.dispatch_namespaces = [opts.releases];
76
+ }
60
77
  const merged = opts.wrangler ? mergeUserConfig(config, opts.wrangler) : config;
61
78
  return JSON.stringify(merged, null, 2) + '\n';
62
79
  }
@@ -68,6 +85,9 @@ const ADAPTER_OWNED_KEYS = [
68
85
  'routes',
69
86
  'compatibility_date',
70
87
  'version_metadata',
88
+ 'secrets',
89
+ 'find_additional_modules',
90
+ 'base_dir',
71
91
  ];
72
92
  /**
73
93
  * Deep-merge the dev's raw wrangler overlay over the generated config, after
@@ -83,4 +103,3 @@ function mergeUserConfig(base, user) {
83
103
  }
84
104
  return deepMergeConfig(base, user);
85
105
  }
86
- //# sourceMappingURL=wrangler.js.map
@@ -0,0 +1,2 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function deploymentAddressing(parameters: CloudflareParams): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { addressing } from '@astrale-os/sdk/deployment/release';
2
+ export function deploymentAddressing(parameters) {
3
+ const routed = parameters.route === undefined ? undefined : addressing(`https://${parameters.route}`).issuer;
4
+ if (parameters.addressing === undefined)
5
+ return routed;
6
+ const configured = addressing(parameters.addressing).issuer;
7
+ if (routed !== undefined && configured !== routed) {
8
+ throw new TypeError('Cloudflare route and addressing identify different origins.');
9
+ }
10
+ return configured;
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function resolveRouter(input: CloudflareParams['router']): {
3
+ readonly binding: string;
4
+ readonly service: string;
5
+ readonly hostSuffix: string;
6
+ readonly minLabels: number;
7
+ } | undefined;
@@ -0,0 +1,11 @@
1
+ export function resolveRouter(input) {
2
+ if (input === false)
3
+ return undefined;
4
+ const value = input ?? {};
5
+ return Object.freeze({
6
+ binding: value.binding ?? 'ROUTER',
7
+ service: value.service ?? 'admin-router',
8
+ hostSuffix: value.hostSuffix ?? '.astrale.ai',
9
+ minLabels: value.minLabels ?? 4,
10
+ });
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function workerName(parameters: CloudflareParams, origin: string): string;
@@ -0,0 +1,18 @@
1
+ import { createHash } from 'node:crypto';
2
+ const WORKER_NAME = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u;
3
+ export function workerName(parameters, origin) {
4
+ if (parameters.workerName !== undefined) {
5
+ if (!WORKER_NAME.test(parameters.workerName) || parameters.workerName.length > 63) {
6
+ throw new TypeError('Cloudflare workerName is invalid.');
7
+ }
8
+ return parameters.workerName;
9
+ }
10
+ const readable = origin
11
+ .toLowerCase()
12
+ .replace(/[^a-z0-9]+/gu, '-')
13
+ .slice(0, 12)
14
+ .replace(/^-+|-+$/gu, '') || 'domain';
15
+ const hexadecimal = createHash('sha256').update(origin).digest('hex');
16
+ const identity = BigInt(`0x${hexadecimal}`).toString(36).padStart(50, '0');
17
+ return `${readable}-${identity}`;
18
+ }
@@ -0,0 +1,3 @@
1
+ export { deploymentAddressing } from './configuration/addressing.js';
2
+ export { resolveRouter } from './configuration/router.js';
3
+ export { workerName } from './configuration/worker-name.js';
@@ -0,0 +1,3 @@
1
+ export { deploymentAddressing } from './configuration/addressing.js';
2
+ export { resolveRouter } from './configuration/router.js';
3
+ export { workerName } from './configuration/worker-name.js';
@@ -0,0 +1,4 @@
1
+ import type { PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { CloudflareParams } from '../params.js';
3
+ import type { WorkerArtifact } from './worker/index.js';
4
+ export declare function admitDirectPlacement(artifact: PreparedArtifact, worker: WorkerArtifact, parameters: CloudflareParams): void;