@astrale-os/adapter-cloudflare 0.5.0-beta.2 → 0.5.0-beta.200

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 (249) hide show
  1. package/README.md +256 -0
  2. package/dist/adapter.d.ts +11 -0
  3. package/dist/adapter.js +54 -0
  4. package/dist/build/bundle/admit.d.ts +3 -0
  5. package/dist/build/bundle/admit.js +47 -0
  6. package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
  7. package/dist/build/bundle/compiled-wasm-loader.js +21 -0
  8. package/dist/build/bundler.d.ts +21 -0
  9. package/dist/build/bundler.js +96 -0
  10. package/dist/build/closure.d.ts +5 -0
  11. package/dist/build/closure.js +28 -0
  12. package/dist/build/codegen/execution.d.ts +3 -0
  13. package/dist/build/codegen/execution.js +2 -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 +32 -5
  17. package/dist/build/codegen/wrangler.js +77 -21
  18. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  19. package/dist/build/configuration/invocation-timeout.js +9 -0
  20. package/dist/build/configuration/request-limit.d.ts +2 -0
  21. package/dist/build/configuration/request-limit.js +9 -0
  22. package/dist/build/configuration/router.d.ts +7 -0
  23. package/dist/build/configuration/router.js +17 -0
  24. package/dist/build/configuration/settings.d.ts +6 -0
  25. package/dist/build/configuration/settings.js +40 -0
  26. package/dist/build/configuration.d.ts +4 -0
  27. package/dist/build/configuration.js +4 -0
  28. package/dist/build/frontend/files.d.ts +19 -0
  29. package/dist/build/frontend/files.js +99 -0
  30. package/dist/build/frontend/readiness.d.ts +16 -0
  31. package/dist/build/frontend/readiness.js +21 -0
  32. package/dist/build/frontend/revision.d.ts +5 -0
  33. package/dist/build/frontend/revision.js +14 -0
  34. package/dist/build/frontend/vite.d.ts +14 -0
  35. package/dist/build/frontend/vite.js +42 -0
  36. package/dist/build/frontend/vite.process.d.ts +7 -0
  37. package/dist/build/frontend/vite.process.js +65 -0
  38. package/dist/build/frontend/vite.runner.d.ts +1 -0
  39. package/dist/build/frontend/vite.runner.js +155 -0
  40. package/dist/build/index.d.ts +12 -16
  41. package/dist/build/index.js +12 -16
  42. package/dist/build/material.d.ts +10 -0
  43. package/dist/build/material.js +25 -0
  44. package/dist/build/metafile.d.ts +5 -0
  45. package/dist/build/metafile.js +14 -0
  46. package/dist/build/qualification.d.ts +5 -0
  47. package/dist/build/qualification.js +7 -0
  48. package/dist/build/roots.d.ts +2 -0
  49. package/dist/build/roots.js +34 -0
  50. package/dist/build/worker/codegen/entry.d.ts +9 -0
  51. package/dist/build/worker/codegen/entry.js +65 -0
  52. package/dist/build/worker/codegen/literal.d.ts +28 -0
  53. package/dist/build/worker/codegen/literal.js +136 -0
  54. package/dist/build/worker/codegen/service.d.ts +14 -0
  55. package/dist/build/worker/codegen/service.js +57 -0
  56. package/dist/build/worker/execution.prepare.d.ts +20 -0
  57. package/dist/build/worker/execution.prepare.js +129 -0
  58. package/dist/build/worker/media-type.d.ts +1 -0
  59. package/dist/build/worker/media-type.js +20 -0
  60. package/dist/build/worker/modules.d.ts +20 -0
  61. package/dist/build/worker/modules.js +32 -0
  62. package/dist/build/worker/specifier.d.ts +5 -0
  63. package/dist/build/worker/specifier.js +15 -0
  64. package/dist/build/worker/upload.d.ts +23 -0
  65. package/dist/build/worker/upload.js +42 -0
  66. package/dist/cloudflare.d.ts +1 -34
  67. package/dist/cloudflare.js +1 -205
  68. package/dist/hosting/activation.d.ts +38 -0
  69. package/dist/hosting/activation.js +109 -0
  70. package/dist/hosting/assets.d.ts +14 -0
  71. package/dist/hosting/assets.js +53 -0
  72. package/dist/hosting/bounded.d.ts +10 -0
  73. package/dist/hosting/bounded.js +32 -0
  74. package/dist/hosting/bytes.d.ts +6 -0
  75. package/dist/hosting/bytes.js +25 -0
  76. package/dist/hosting/client.d.ts +144 -0
  77. package/dist/hosting/client.js +491 -0
  78. package/dist/hosting/dispatcher/cron.d.mts +10 -0
  79. package/dist/hosting/dispatcher/cron.mjs +135 -0
  80. package/dist/hosting/dispatcher/deployments.d.mts +26 -0
  81. package/dist/hosting/dispatcher/deployments.mjs +158 -0
  82. package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
  83. package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
  84. package/dist/hosting/dispatcher/env.d.mts +51 -0
  85. package/dist/hosting/dispatcher/failure.d.mts +4 -0
  86. package/dist/hosting/dispatcher/failure.mjs +15 -0
  87. package/dist/hosting/dispatcher/index.d.mts +4 -0
  88. package/dist/hosting/dispatcher/index.mjs +8 -0
  89. package/dist/hosting/dispatcher/modules.d.ts +24 -0
  90. package/dist/hosting/dispatcher/modules.js +55 -0
  91. package/dist/hosting/dispatcher/services.d.mts +23 -0
  92. package/dist/hosting/dispatcher/services.mjs +202 -0
  93. package/dist/hosting/identity.d.ts +15 -0
  94. package/dist/hosting/identity.js +36 -0
  95. package/dist/hosting/index.d.ts +34 -0
  96. package/dist/hosting/index.js +32 -0
  97. package/dist/hosting/kv.d.ts +90 -0
  98. package/dist/hosting/kv.js +207 -0
  99. package/dist/hosting/listing.d.ts +34 -0
  100. package/dist/hosting/listing.js +50 -0
  101. package/dist/hosting/names.d.ts +16 -0
  102. package/dist/hosting/names.js +28 -0
  103. package/dist/hosting/provision/account.d.ts +11 -0
  104. package/dist/hosting/provision/account.js +86 -0
  105. package/dist/hosting/provision/dispatcher.d.ts +42 -0
  106. package/dist/hosting/provision/dispatcher.js +99 -0
  107. package/dist/hosting/provision/ingress.d.ts +12 -0
  108. package/dist/hosting/provision/ingress.js +31 -0
  109. package/dist/hosting/provision/plan.d.ts +143 -0
  110. package/dist/hosting/provision/plan.js +246 -0
  111. package/dist/hosting/provision/routing.d.ts +82 -0
  112. package/dist/hosting/provision/routing.js +226 -0
  113. package/dist/hosting/readiness.d.ts +53 -0
  114. package/dist/hosting/readiness.js +82 -0
  115. package/dist/hosting/refusal.d.ts +28 -0
  116. package/dist/hosting/refusal.js +13 -0
  117. package/dist/hosting/retirement.d.ts +70 -0
  118. package/dist/hosting/retirement.js +107 -0
  119. package/dist/hosting/retry-after.d.ts +6 -0
  120. package/dist/hosting/retry-after.js +55 -0
  121. package/dist/hosting/script.d.ts +186 -0
  122. package/dist/hosting/script.js +324 -0
  123. package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
  124. package/dist/hosting/testing/fake-cloudflare.js +757 -0
  125. package/dist/hosting/testing/index.d.ts +6 -0
  126. package/dist/hosting/testing/index.js +6 -0
  127. package/dist/hosting/time.d.ts +4 -0
  128. package/dist/hosting/time.js +20 -0
  129. package/dist/identity/binding.d.ts +2 -0
  130. package/dist/identity/binding.js +2 -0
  131. package/dist/identity/material.d.ts +6 -0
  132. package/dist/identity/material.js +29 -0
  133. package/dist/index.d.ts +14 -13
  134. package/dist/index.js +13 -12
  135. package/dist/namespace/configure.d.ts +22 -0
  136. package/dist/namespace/configure.js +199 -0
  137. package/dist/namespace/coordinates.d.ts +15 -0
  138. package/dist/namespace/coordinates.js +49 -0
  139. package/dist/namespace/deploy-release.d.ts +53 -0
  140. package/dist/namespace/deploy-release.js +389 -0
  141. package/dist/namespace/hosting.d.ts +29 -0
  142. package/dist/namespace/hosting.js +120 -0
  143. package/dist/namespace/index.d.ts +12 -0
  144. package/dist/namespace/index.js +12 -0
  145. package/dist/namespace/list.d.ts +18 -0
  146. package/dist/namespace/list.js +63 -0
  147. package/dist/namespace/readiness.d.ts +30 -0
  148. package/dist/namespace/readiness.js +31 -0
  149. package/dist/namespace/record.d.ts +21 -0
  150. package/dist/namespace/record.js +53 -0
  151. package/dist/params.d.ts +63 -66
  152. package/dist/params.js +0 -1
  153. package/dist/release/build.d.ts +35 -0
  154. package/dist/release/build.js +44 -0
  155. package/dist/release/deployment.d.ts +44 -0
  156. package/dist/release/deployment.js +141 -0
  157. package/dist/release/index.d.ts +2 -0
  158. package/dist/release/index.js +2 -0
  159. package/dist/worker/binary.d.ts +21 -0
  160. package/dist/worker/binary.js +31 -0
  161. package/dist/worker/build-digest.d.ts +10 -0
  162. package/dist/worker/build-digest.js +22 -0
  163. package/dist/worker/cache.d.ts +28 -0
  164. package/dist/worker/cache.js +70 -0
  165. package/dist/worker/durable.d.ts +3 -0
  166. package/dist/worker/durable.js +5 -0
  167. package/dist/worker/entry.d.ts +47 -0
  168. package/dist/worker/entry.js +135 -0
  169. package/dist/worker/fetch.d.ts +11 -0
  170. package/dist/worker/fetch.js +31 -0
  171. package/dist/worker/front.d.ts +56 -0
  172. package/dist/worker/front.js +59 -0
  173. package/dist/worker/frontend.d.ts +4 -0
  174. package/dist/worker/frontend.js +83 -0
  175. package/dist/worker/identity.d.ts +7 -0
  176. package/dist/worker/identity.js +23 -0
  177. package/dist/worker/index.d.ts +6 -48
  178. package/dist/worker/index.js +6 -186
  179. package/dist/worker/restate.d.ts +6 -0
  180. package/dist/worker/restate.js +6 -0
  181. package/dist/worker/settings.d.ts +47 -0
  182. package/dist/worker/settings.js +163 -0
  183. package/dist/wrangler/bundle.d.ts +10 -0
  184. package/dist/wrangler/bundle.js +27 -0
  185. package/dist/wrangler/index.d.ts +3 -0
  186. package/dist/wrangler/index.js +3 -0
  187. package/dist/wrangler/process.d.ts +15 -0
  188. package/dist/wrangler/process.js +113 -0
  189. package/dist/wrangler/type-generation.d.ts +6 -0
  190. package/dist/wrangler/type-generation.js +19 -0
  191. package/package.json +47 -22
  192. package/template/astrale.config.ts +43 -29
  193. package/dist/build/codegen/identity.d.ts +0 -10
  194. package/dist/build/codegen/identity.d.ts.map +0 -1
  195. package/dist/build/codegen/identity.js +0 -32
  196. package/dist/build/codegen/identity.js.map +0 -1
  197. package/dist/build/codegen/merge.d.ts.map +0 -1
  198. package/dist/build/codegen/merge.js.map +0 -1
  199. package/dist/build/codegen/worker.d.ts +0 -12
  200. package/dist/build/codegen/worker.d.ts.map +0 -1
  201. package/dist/build/codegen/worker.js +0 -40
  202. package/dist/build/codegen/worker.js.map +0 -1
  203. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  204. package/dist/build/codegen/wrangler.js.map +0 -1
  205. package/dist/build/frontend.d.ts +0 -26
  206. package/dist/build/frontend.d.ts.map +0 -1
  207. package/dist/build/frontend.js +0 -263
  208. package/dist/build/frontend.js.map +0 -1
  209. package/dist/build/index.d.ts.map +0 -1
  210. package/dist/build/index.js.map +0 -1
  211. package/dist/build/parse-output.d.ts +0 -27
  212. package/dist/build/parse-output.d.ts.map +0 -1
  213. package/dist/build/parse-output.js +0 -58
  214. package/dist/build/parse-output.js.map +0 -1
  215. package/dist/build/prepare.d.ts +0 -18
  216. package/dist/build/prepare.d.ts.map +0 -1
  217. package/dist/build/prepare.js +0 -117
  218. package/dist/build/prepare.js.map +0 -1
  219. package/dist/build/worker.d.ts +0 -15
  220. package/dist/build/worker.d.ts.map +0 -1
  221. package/dist/build/worker.js +0 -21
  222. package/dist/build/worker.js.map +0 -1
  223. package/dist/build/wrangler-cli.d.ts +0 -86
  224. package/dist/build/wrangler-cli.d.ts.map +0 -1
  225. package/dist/build/wrangler-cli.js +0 -275
  226. package/dist/build/wrangler-cli.js.map +0 -1
  227. package/dist/cloudflare.d.ts.map +0 -1
  228. package/dist/cloudflare.js.map +0 -1
  229. package/dist/index.d.ts.map +0 -1
  230. package/dist/index.js.map +0 -1
  231. package/dist/params.d.ts.map +0 -1
  232. package/dist/params.js.map +0 -1
  233. package/dist/worker/index.d.ts.map +0 -1
  234. package/dist/worker/index.js.map +0 -1
  235. package/src/build/codegen/identity.ts +0 -40
  236. package/src/build/codegen/merge.ts +0 -92
  237. package/src/build/codegen/worker.ts +0 -53
  238. package/src/build/codegen/wrangler.ts +0 -127
  239. package/src/build/frontend.ts +0 -324
  240. package/src/build/index.ts +0 -29
  241. package/src/build/parse-output.ts +0 -60
  242. package/src/build/prepare.ts +0 -161
  243. package/src/build/worker.ts +0 -37
  244. package/src/build/wrangler-cli.ts +0 -362
  245. package/src/cloudflare.ts +0 -251
  246. package/src/index.ts +0 -21
  247. package/src/params.ts +0 -92
  248. package/src/worker/index.ts +0 -276
  249. package/src/worker/tsconfig.json +0 -10
@@ -0,0 +1,20 @@
1
+ import type { BundleContext } from '@astrale-os/sdk/deployment/adapter';
2
+ export declare const RELEASE_ENTRY = "bundle/index.mjs";
3
+ export declare const RELEASE_SERVICE = "bundle/service.mjs";
4
+ export declare const RELEASE_RESTATE = "bundle/restate.mjs";
5
+ /** A deployed module retained outside the startup bundle. */
6
+ export interface ReleaseModule {
7
+ readonly kind: 'esm' | 'wasm';
8
+ readonly path: string;
9
+ readonly content: Uint8Array;
10
+ }
11
+ export declare function prepareExecution(input: {
12
+ readonly context: BundleContext;
13
+ readonly directory: string;
14
+ readonly frontendRevision?: string;
15
+ readonly frontendAddressed?: readonly string[];
16
+ }): Promise<{
17
+ readonly entry: Uint8Array;
18
+ readonly modules: readonly ReleaseModule[];
19
+ }>;
20
+ export declare function declaresDurable(build: BundleContext['build']): boolean;
@@ -0,0 +1,129 @@
1
+ import { generatedMaterial } from '@astrale-os/sdk/deployment/build';
2
+ import { DURABLE_ENGINE_EXPORTS } from '@astrale-os/sdk/execution';
3
+ import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
4
+ import { dirname, join, relative, resolve } from 'node:path';
5
+ import { SIGNING_IDENTITY_BINDING } from '../../identity/binding.js';
6
+ import { runWranglerBundle } from '../../wrangler/bundle.js';
7
+ import { admitDurableEngineBundle, admitWorkerBundle } from '../bundle/admit.js';
8
+ import { generateExecutionEntry, generateExecutionService } from '../codegen/execution.js';
9
+ import { generateWranglerConfig } from '../codegen/wrangler.js';
10
+ import { qualifyWorkerBundle } from '../qualification.js';
11
+ import { workerModules } from './modules.js';
12
+ import { frontModuleSpecifier, restateModuleSpecifier, workerModuleSpecifier } from './specifier.js';
13
+ export const RELEASE_ENTRY = 'bundle/index.mjs';
14
+ export const RELEASE_SERVICE = 'bundle/service.mjs';
15
+ export const RELEASE_RESTATE = 'bundle/restate.mjs';
16
+ /**
17
+ * Bundling sees the adapter base configuration only: no Environment, route, var, router or
18
+ * `wrangler` overlay reaches the bytes, so every Environment of one source bundles identically.
19
+ */
20
+ const BUNDLE_WORKER_NAME = 'astrale-domain';
21
+ export async function prepareExecution(input) {
22
+ const runtimePath = resolve(input.context.projectDir, input.context.runtime.reference.path);
23
+ const runtimeSpecifier = moduleSpecifier(relative(input.directory, runtimePath));
24
+ const workerSpecifier = workerModuleSpecifier();
25
+ const serviceSource = generateExecutionService({
26
+ origin: input.context.build.schema.compiled.root.origin,
27
+ runtimeSpecifier,
28
+ workerSpecifier,
29
+ build: input.context.build,
30
+ ...(declaresDurable(input.context.build)
31
+ ? { durable: true, restateSpecifier: './restate.mjs' }
32
+ : {}),
33
+ ...(input.frontendRevision === undefined ? {} : { frontendRevision: input.frontendRevision }),
34
+ ...(input.frontendAddressed === undefined
35
+ ? {}
36
+ : { frontendAddressed: input.frontendAddressed }),
37
+ });
38
+ const modules = [];
39
+ const bundle = async (name, path, source, admit) => {
40
+ const sourcePath = join(input.directory, `${name}.gen.ts`);
41
+ await writeFile(sourcePath, source);
42
+ const configPath = join(input.directory, `wrangler.${name}.prepare.jsonc`);
43
+ await writeFile(configPath, generateWranglerConfig({
44
+ workerName: BUNDLE_WORKER_NAME,
45
+ main: `./${name}.gen.ts`,
46
+ secretBindings: [SIGNING_IDENTITY_BINDING],
47
+ selfBinding: false,
48
+ }));
49
+ const output = join(input.directory, `dist-${name}`);
50
+ await rm(output, { recursive: true, force: true });
51
+ const emitted = await runWranglerBundle({
52
+ projectDir: input.context.projectDir,
53
+ configPath,
54
+ outDir: output,
55
+ signal: input.context.signal,
56
+ });
57
+ await qualifyWorkerBundle({
58
+ metafilePath: emitted.metafilePath,
59
+ inputRoot: dirname(configPath),
60
+ });
61
+ await admit(emitted.bundlePath);
62
+ const content = new Uint8Array(await readFile(emitted.bundlePath));
63
+ await mkdir(dirname(join(input.directory, path)), { recursive: true });
64
+ await writeFile(join(input.directory, path), content);
65
+ modules.push(Object.freeze({ path, kind: 'esm', content }));
66
+ // Imported WASM modules are emitted beside their owner under content-hashed names.
67
+ for (const file of (await readdir(output)).filter((name) => name.endsWith('.wasm')).sort()) {
68
+ const wasmPath = `${dirname(path)}/${file}`;
69
+ const content = new Uint8Array(await readFile(join(output, file)));
70
+ await writeFile(join(input.directory, wasmPath), content);
71
+ if (!modules.some((module) => module.path === wasmPath)) {
72
+ modules.push(Object.freeze({ path: wasmPath, kind: 'wasm', content }));
73
+ }
74
+ }
75
+ };
76
+ await bundle('service', RELEASE_SERVICE, serviceSource, admitWorkerBundle);
77
+ if (declaresDurable(input.context.build)) {
78
+ await bundle('restate', RELEASE_RESTATE,
79
+ // Wrangler requires a default export to classify an independently bundled ESM entry.
80
+ `export { ${DURABLE_ENGINE_EXPORTS.join(', ')} } from ${JSON.stringify(restateModuleSpecifier())}\nexport default {}\n`, admitDurableEngineBundle);
81
+ }
82
+ const sourcePath = join(input.directory, 'worker.gen.ts');
83
+ const frontend = generatedMaterial(input.context.build).material.frontend;
84
+ await writeFile(sourcePath, generateExecutionEntry('./service.mjs', {
85
+ frontSpecifier: frontModuleSpecifier(),
86
+ ...(frontend === undefined ? {} : { frontend }),
87
+ ...(input.frontendRevision === undefined ? {} : { frontendRevision: input.frontendRevision }),
88
+ ...(input.frontendAddressed === undefined
89
+ ? {}
90
+ : { frontendAddressed: input.frontendAddressed }),
91
+ }));
92
+ const configPath = join(input.directory, 'wrangler.prepare.jsonc');
93
+ await writeFile(configPath, generateWranglerConfig({
94
+ workerName: BUNDLE_WORKER_NAME,
95
+ secretBindings: [SIGNING_IDENTITY_BINDING],
96
+ modules: workerModules({ entrypoint: 'worker.gen.ts', modules }),
97
+ selfBinding: false,
98
+ }));
99
+ const output = join(input.directory, 'dist-prepare');
100
+ await rm(output, { recursive: true, force: true });
101
+ const emitted = await runWranglerBundle({
102
+ projectDir: input.context.projectDir,
103
+ configPath,
104
+ outDir: output,
105
+ signal: input.context.signal,
106
+ });
107
+ await qualifyWorkerBundle({
108
+ metafilePath: emitted.metafilePath,
109
+ inputRoot: dirname(configPath),
110
+ });
111
+ await admitWorkerBundle(emitted.bundlePath);
112
+ return Object.freeze({
113
+ entry: new Uint8Array(await readFile(emitted.bundlePath)),
114
+ modules: Object.freeze(modules),
115
+ });
116
+ }
117
+ function moduleSpecifier(input) {
118
+ const normalized = input.split('\\').join('/');
119
+ return normalized.startsWith('.') ? normalized : `./${normalized}`;
120
+ }
121
+ export function declaresDurable(build) {
122
+ const compiled = build.schema.compiled;
123
+ const root = compiled.closure.find(({ origin }) => origin === compiled.root.origin);
124
+ if (root === undefined)
125
+ return false;
126
+ return (root.definitions.functions.some((definition) => definition.execution?.durable === true) ||
127
+ root.definitions.classes.some((definition) => 'methods' in definition &&
128
+ definition.methods.some((method) => method.execution?.durable === true)));
129
+ }
@@ -0,0 +1 @@
1
+ export declare function inferMediaType(path: string): string | undefined;
@@ -0,0 +1,20 @@
1
+ export function inferMediaType(path) {
2
+ const extension = path.split('.').at(-1)?.toLowerCase();
3
+ return extension === undefined ? undefined : MEDIA_TYPES[extension];
4
+ }
5
+ const MEDIA_TYPES = Object.freeze({
6
+ html: 'text/html; charset=utf-8',
7
+ js: 'text/javascript; charset=utf-8',
8
+ mjs: 'text/javascript; charset=utf-8',
9
+ css: 'text/css; charset=utf-8',
10
+ json: 'application/json; charset=utf-8',
11
+ svg: 'image/svg+xml',
12
+ png: 'image/png',
13
+ jpg: 'image/jpeg',
14
+ jpeg: 'image/jpeg',
15
+ webp: 'image/webp',
16
+ ico: 'image/x-icon',
17
+ woff: 'font/woff',
18
+ woff2: 'font/woff2',
19
+ wasm: 'application/wasm',
20
+ });
@@ -0,0 +1,20 @@
1
+ import type { WorkerModuleKind } from '@astrale-os/sdk/deployment/worker';
2
+ type WranglerModuleType = 'ESModule' | 'CompiledWasm' | 'Text' | 'Data';
3
+ /**
4
+ * Project one admitted Worker module inventory into Wrangler's relative module discovery. Rules
5
+ * follow module kinds, so the projection does not depend on the inventory's order.
6
+ */
7
+ export declare function workerModules(worker: {
8
+ readonly entrypoint: string;
9
+ readonly modules: readonly {
10
+ readonly path: string;
11
+ readonly kind: WorkerModuleKind;
12
+ }[];
13
+ }): {
14
+ readonly baseDir: string;
15
+ readonly rules: readonly {
16
+ readonly type: WranglerModuleType;
17
+ readonly globs: readonly string[];
18
+ }[];
19
+ };
20
+ export {};
@@ -0,0 +1,32 @@
1
+ import { posix } from 'node:path';
2
+ const TYPES = Object.freeze({
3
+ esm: 'ESModule',
4
+ wasm: 'CompiledWasm',
5
+ text: 'Text',
6
+ data: 'Data',
7
+ });
8
+ /**
9
+ * Project one admitted Worker module inventory into Wrangler's relative module discovery. Rules
10
+ * follow module kinds, so the projection does not depend on the inventory's order.
11
+ */
12
+ export function workerModules(worker) {
13
+ const directory = posix.dirname(worker.entrypoint);
14
+ const groups = new Map();
15
+ for (const module of worker.modules) {
16
+ if (module.path === worker.entrypoint)
17
+ continue;
18
+ const relative = posix.relative(directory, module.path);
19
+ if (relative === '' || relative === '..' || relative.startsWith('../')) {
20
+ throw new TypeError('Cloudflare Worker module escapes its entrypoint directory.');
21
+ }
22
+ const type = TYPES[module.kind];
23
+ const globs = groups.get(type) ?? [];
24
+ globs.push(relative);
25
+ groups.set(type, globs);
26
+ }
27
+ const rules = Object.values(TYPES).flatMap((type) => {
28
+ const globs = groups.get(type);
29
+ return globs === undefined ? [] : [Object.freeze({ type, globs: Object.freeze(globs) })];
30
+ });
31
+ return Object.freeze({ baseDir: `./${directory}`, rules: Object.freeze(rules) });
32
+ }
@@ -0,0 +1,5 @@
1
+ export declare function workerModuleSpecifier(): string;
2
+ /** The isolate-startup module, which must stay free of the execution Service's dependencies. */
3
+ export declare function frontModuleSpecifier(): string;
4
+ /** The engine's Workers build, resolved from this adapter so a Domain needs no engine dependency. */
5
+ export declare function restateModuleSpecifier(): string;
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ const workerModule = import.meta.resolve('@astrale-os/adapter-cloudflare/worker');
3
+ const restateModule = import.meta.resolve('@astrale-os/adapter-cloudflare/worker/restate');
4
+ const frontModule = import.meta.resolve('@astrale-os/adapter-cloudflare/worker/front');
5
+ export function workerModuleSpecifier() {
6
+ return fileURLToPath(workerModule);
7
+ }
8
+ /** The isolate-startup module, which must stay free of the execution Service's dependencies. */
9
+ export function frontModuleSpecifier() {
10
+ return fileURLToPath(frontModule);
11
+ }
12
+ /** The engine's Workers build, resolved from this adapter so a Domain needs no engine dependency. */
13
+ export function restateModuleSpecifier() {
14
+ return fileURLToPath(restateModule);
15
+ }
@@ -0,0 +1,23 @@
1
+ import type { Bundle } from '@astrale-os/sdk/deployment/adapter';
2
+ import { type WorkerUpload } from '../../release/build.js';
3
+ /**
4
+ * The portable upload of one Bundle of the Cloudflare Worker bundler, as an immutable deployment's
5
+ * host receives it: the entry and the modules it loads (ES modules and their WASM), and the
6
+ * frontend as Worker assets with the media type their extension names. Its build digest is the Bundle's own, so the host that
7
+ * recomputes it from these bytes finds exactly the build the release names; any other Bundle is
8
+ * refused.
9
+ */
10
+ export declare function bundleUpload(bundle: Bundle): BundleUpload;
11
+ /** The Worker upload of one Bundle, with each module's kind and each asset's media type. */
12
+ export interface BundleUpload extends WorkerUpload {
13
+ readonly modules: readonly {
14
+ readonly name: string;
15
+ readonly kind: 'esm' | 'wasm';
16
+ readonly bytes: Uint8Array;
17
+ }[];
18
+ readonly assets?: readonly {
19
+ readonly path: string;
20
+ readonly bytes: Uint8Array;
21
+ readonly contentType?: string;
22
+ }[];
23
+ }
@@ -0,0 +1,42 @@
1
+ import { buildDigest } from '@astrale-os/sdk/deployment/build/manifest';
2
+ import { workerBuildManifest } from '../../release/build.js';
3
+ import { bundledWorker } from '../bundler.js';
4
+ import { RELEASE_ENTRY } from './execution.prepare.js';
5
+ import { inferMediaType } from './media-type.js';
6
+ /**
7
+ * The portable upload of one Bundle of the Cloudflare Worker bundler, as an immutable deployment's
8
+ * host receives it: the entry and the modules it loads (ES modules and their WASM), and the
9
+ * frontend as Worker assets with the media type their extension names. Its build digest is the Bundle's own, so the host that
10
+ * recomputes it from these bytes finds exactly the build the release names; any other Bundle is
11
+ * refused.
12
+ */
13
+ export function bundleUpload(bundle) {
14
+ const worker = bundledWorker(bundle, bundle.build);
15
+ const root = bundle.build.schema.compiled.root;
16
+ const upload = Object.freeze({
17
+ origin: root.origin,
18
+ revision: root.revision,
19
+ bundle: bundle.manifest.schema.bundle,
20
+ entry: RELEASE_ENTRY,
21
+ modules: Object.freeze([
22
+ Object.freeze({ name: RELEASE_ENTRY, kind: 'esm', bytes: worker.entry }),
23
+ ...worker.modules.map((module) => Object.freeze({ name: module.path, kind: module.kind, bytes: module.content })),
24
+ ]),
25
+ ...(worker.frontend.length === 0
26
+ ? {}
27
+ : {
28
+ assets: Object.freeze(worker.frontend.map((file) => {
29
+ const contentType = inferMediaType(file.path);
30
+ return Object.freeze({
31
+ path: `/${file.path}`,
32
+ bytes: file.bytes(),
33
+ ...(contentType === undefined ? {} : { contentType }),
34
+ });
35
+ })),
36
+ }),
37
+ });
38
+ if (buildDigest(workerBuildManifest(upload)) !== bundle.digest) {
39
+ throw new TypeError('Worker upload of the Bundle does not reproduce its build digest.');
40
+ }
41
+ return upload;
42
+ }
@@ -1,34 +1 @@
1
- /**
2
- * `cloudflare(envs)` — the Cloudflare deployment adapter.
3
- *
4
- * Owns everything target-specific: it codegens the Worker entry + wrangler
5
- * config (the dev never sees a `wrangler.jsonc`), materializes the optional frontend
6
- * SPA, and shells out to `wrangler`. `watch` → `wrangler dev` (local URL);
7
- * `deploy` → `wrangler deploy` (workers.dev or a custom-domain URL); secrets →
8
- * `wrangler secret bulk`. Both `watch` and `deploy` return the URL the CLI
9
- * prints and `astrale domain install <url>` consumes.
10
- */
11
- import type { DomainAdapter } from '@astrale-os/sdk';
12
- import type { CloudflareParams } from './params.js';
13
- import { bulkPutSecrets, buildCloudflareWorker, buildFrontend, logTo, prepare, runWranglerDeploy, runWranglerDev, runWranglerTypes, watchFrontend } from './build/index.js';
14
- export declare function cloudflare(envs: Record<string, CloudflareParams>): DomainAdapter<CloudflareParams>;
15
- interface CloudflareAdapterDependencies {
16
- readonly bulkPutSecrets: typeof bulkPutSecrets;
17
- readonly buildCloudflareWorker: typeof buildCloudflareWorker;
18
- readonly buildFrontend: typeof buildFrontend;
19
- readonly logTo: typeof logTo;
20
- readonly prepare: typeof prepare;
21
- readonly runWranglerDeploy: typeof runWranglerDeploy;
22
- readonly runWranglerDev: typeof runWranglerDev;
23
- readonly runWranglerTypes: typeof runWranglerTypes;
24
- readonly watchFrontend: typeof watchFrontend;
25
- readonly waitUntilLive: typeof waitUntilLive;
26
- }
27
- /** Exact orchestration seam used by adapter-level deployment qualification. */
28
- export declare function cloudflareWithDependencies(envs: Record<string, CloudflareParams>, dependencies: CloudflareAdapterDependencies): DomainAdapter<CloudflareParams>;
29
- /**
30
- * Poll until the deployed Worker health endpoint returns exactly 200.
31
- */
32
- declare function waitUntilLive(url: string, onLog: (line: string) => void, expectedDeploymentVersion?: string, timeoutMs?: number): Promise<void>;
33
- export {};
34
- //# sourceMappingURL=cloudflare.d.ts.map
1
+ export { cloudflare } from './adapter.js';
@@ -1,205 +1 @@
1
- /**
2
- * `cloudflare(envs)` — the Cloudflare deployment adapter.
3
- *
4
- * Owns everything target-specific: it codegens the Worker entry + wrangler
5
- * config (the dev never sees a `wrangler.jsonc`), materializes the optional frontend
6
- * SPA, and shells out to `wrangler`. `watch` → `wrangler dev` (local URL);
7
- * `deploy` → `wrangler deploy` (workers.dev or a custom-domain URL); secrets →
8
- * `wrangler secret bulk`. Both `watch` and `deploy` return the URL the CLI
9
- * prints and `astrale domain install <url>` consumes.
10
- */
11
- import { defineAdapter } from '@astrale-os/sdk';
12
- import { bulkPutSecrets, buildCloudflareWorker, buildFrontend, logTo, prepare, runWranglerDeploy, runWranglerDev, runWranglerTypes, watchFrontend, } from './build/index.js';
13
- export function cloudflare(envs) {
14
- return cloudflareWithDependencies(envs, {
15
- bulkPutSecrets,
16
- buildCloudflareWorker,
17
- buildFrontend,
18
- logTo,
19
- prepare,
20
- runWranglerDeploy,
21
- runWranglerDev,
22
- runWranglerTypes,
23
- watchFrontend,
24
- waitUntilLive,
25
- });
26
- }
27
- /** Exact orchestration seam used by adapter-level deployment qualification. */
28
- export function cloudflareWithDependencies(envs, dependencies) {
29
- return defineAdapter({
30
- name: 'cloudflare',
31
- envs,
32
- async build(params, ctx) {
33
- await dependencies.buildCloudflareWorker({
34
- params,
35
- context: ctx,
36
- onLog: dependencies.logTo(),
37
- });
38
- },
39
- async watch(params, ctx) {
40
- const onLog = dependencies.logTo();
41
- const frontend = await dependencies.buildFrontend({
42
- definition: ctx.definition,
43
- projectDir: ctx.projectDir,
44
- onLog,
45
- });
46
- const { configPath, port } = await dependencies.prepare(params, ctx, 'dev', frontend);
47
- const handle = await dependencies.runWranglerDev({
48
- projectDir: ctx.projectDir,
49
- configPath,
50
- port,
51
- remote: Boolean(params.remote),
52
- autoPickPort: params.port === undefined,
53
- ...(params.host ? { ip: '0.0.0.0' } : {}),
54
- onReload: ctx.onReload,
55
- onLog,
56
- });
57
- let frontendWatch;
58
- try {
59
- frontendWatch = dependencies.watchFrontend({
60
- definition: ctx.definition,
61
- projectDir: ctx.projectDir,
62
- onLog,
63
- // Routes and source recipes are immutable for this watch generation.
64
- // Wrangler already observes the atomically swapped asset stage, so a
65
- // source rebuild needs no config regeneration.
66
- onRebuild: ctx.onReload,
67
- });
68
- }
69
- catch (error) {
70
- try {
71
- await handle.stop();
72
- }
73
- catch (cleanupError) {
74
- throw new AggregateError([error, cleanupError], 'cloudflare frontend watcher startup failed and Wrangler cleanup also failed');
75
- }
76
- throw error;
77
- }
78
- // With --host the actionable URL is the PUBLIC one (the tunnel/proxy
79
- // front), not the local bind — print and spec-stamp that.
80
- return {
81
- url: params.host ?? handle.url,
82
- async stop() {
83
- const errors = [];
84
- try {
85
- await frontendWatch?.stop();
86
- }
87
- catch (error) {
88
- errors.push(error);
89
- }
90
- try {
91
- await handle.stop();
92
- }
93
- catch (error) {
94
- errors.push(error);
95
- }
96
- if (errors.length === 1)
97
- throw errors[0];
98
- if (errors.length > 1) {
99
- throw new AggregateError(errors, 'cloudflare development cleanup failed');
100
- }
101
- },
102
- };
103
- },
104
- // Config hot-regen: rewrite the generated files only — the running
105
- // `wrangler dev` watches its `--config` (and the worker entry) and reloads
106
- // them itself, so a `astrale.config.ts` edit lands without a restart.
107
- // Mirrors `watch`'s prep exactly (codegen + frontend build), minus the spawn.
108
- async regenerate(params, ctx) {
109
- const frontend = await dependencies.buildFrontend({
110
- definition: ctx.definition,
111
- projectDir: ctx.projectDir,
112
- onLog: dependencies.logTo(),
113
- });
114
- const { configPath } = await dependencies.prepare(params, ctx, 'dev', frontend);
115
- await dependencies.runWranglerTypes({
116
- projectDir: ctx.projectDir,
117
- configPath,
118
- onLog: dependencies.logTo(),
119
- });
120
- },
121
- async deploy(params, ctx) {
122
- const frontend = await dependencies.buildFrontend({
123
- definition: ctx.definition,
124
- projectDir: ctx.projectDir,
125
- onLog: dependencies.logTo(),
126
- });
127
- const { configPath, fallbackConfigPath, workerName: name, } = await dependencies.prepare(params, ctx, 'deploy', frontend);
128
- const { url, deploymentVersion } = await dependencies.runWranglerDeploy({
129
- projectDir: ctx.projectDir,
130
- configPath,
131
- workerName: name,
132
- ...(fallbackConfigPath ? { fallbackConfigPath } : {}),
133
- ...(params.route ? { route: params.route } : {}),
134
- onLog: dependencies.logTo(),
135
- });
136
- if (Object.keys(ctx.secrets).length > 0) {
137
- await dependencies.bulkPutSecrets({
138
- projectDir: ctx.projectDir,
139
- configPath,
140
- secrets: ctx.secrets,
141
- onLog: dependencies.logTo(),
142
- });
143
- }
144
- // A first deploy on a fresh `*.workers.dev` host can take ~30-60s to
145
- // propagate; an `astrale domain install <url>` issued right away would
146
- // 404 (Cloudflare 1042). Block until the URL actually serves so the
147
- // install line we print is immediately actionable.
148
- await dependencies.waitUntilLive(url, dependencies.logTo(), deploymentVersion);
149
- return { url };
150
- },
151
- secretsFile(params) {
152
- return params.secrets;
153
- },
154
- });
155
- }
156
- /**
157
- * Poll until the deployed Worker health endpoint returns exactly 200.
158
- */
159
- async function waitUntilLive(url, onLog, expectedDeploymentVersion, timeoutMs = 90_000) {
160
- const probe = new URL('/health', url);
161
- const metadata = new URL('/meta', url);
162
- const deadline = Date.now() + timeoutMs;
163
- let waited = false;
164
- let lastStatus;
165
- let lastDeploymentVersion;
166
- for (;;) {
167
- try {
168
- const res = await fetch(probe, { redirect: 'manual' });
169
- lastStatus = res.status;
170
- await res.body?.cancel();
171
- if (res.status === 200) {
172
- if (expectedDeploymentVersion === undefined)
173
- return;
174
- const meta = await fetch(metadata, { redirect: 'manual' });
175
- if (meta.status === 200) {
176
- const body = (await meta.json());
177
- lastDeploymentVersion =
178
- typeof body.deploymentVersion === 'string' ? body.deploymentVersion : undefined;
179
- if (lastDeploymentVersion === expectedDeploymentVersion)
180
- return;
181
- }
182
- else {
183
- await meta.body?.cancel();
184
- }
185
- }
186
- }
187
- catch {
188
- // Network hiccup — treat like "not live yet" and keep polling.
189
- }
190
- if (Date.now() >= deadline) {
191
- throw new Error(`deployed Worker health did not reach HTTP 200 within ${Math.round(timeoutMs / 1000)}s` +
192
- (lastStatus === undefined ? '' : ` (last status ${lastStatus})`) +
193
- (expectedDeploymentVersion === undefined
194
- ? ''
195
- : `; deployment version ${JSON.stringify(lastDeploymentVersion)} ` +
196
- `did not reach ${JSON.stringify(expectedDeploymentVersion)}`));
197
- }
198
- if (!waited) {
199
- waited = true;
200
- onLog('waiting for the URL to go live (first deploys can take ~30-60s)…');
201
- }
202
- await new Promise((r) => setTimeout(r, 3000));
203
- }
204
- }
205
- //# sourceMappingURL=cloudflare.js.map
1
+ export { cloudflare } from './adapter.js';
@@ -0,0 +1,38 @@
1
+ import type { WorkerRecord } from '@astrale-os/sdk/deployment/worker';
2
+ import type { RoutingKv } from './kv.js';
3
+ /**
4
+ * Activate one deployment: write `record:<label>`, which the dispatcher reads to route the label,
5
+ * with the record its deployer publishes (opaque bytes and their media type, served verbatim at
6
+ * `/.well-known/astrale/deployment.json`), or `null` for a deployment that publishes none. A
7
+ * record never changes once published: one already there is kept and answered when it is the same
8
+ * record (same media type, same bytes, or both none), and refused (`deployment-conflict`)
9
+ * otherwise, without any write.
10
+ */
11
+ export declare function activateDeployment(kv: RoutingKv, label: string, record: WorkerRecord | null): Promise<WorkerRecord | null>;
12
+ /**
13
+ * The record a label was activated with: the record, `null` when the deployment publishes none,
14
+ * or undefined when the label is not activated. A value whose metadata is not exactly
15
+ * `{"contentType":<media type or null>}` (none at all included) is no record the kit writes, and
16
+ * is refused (`record-invalid`) rather than read as any record.
17
+ */
18
+ export declare function readRecord(kv: RoutingKv, label: string): Promise<WorkerRecord | null | undefined>;
19
+ /** Whether two activations publish the same record (or both none). */
20
+ export declare function sameRecord(left: WorkerRecord | null, right: WorkerRecord | null): boolean;
21
+ /**
22
+ * Point a name (a deployment line) at the deployment its URL `https://<name>.<routing domain>`
23
+ * serves: `current:<name>` = `label`, or no deployment when `label` is null (the key is deleted).
24
+ * The label must be one of the name's own. Writing the same value again writes nothing, so a rerun
25
+ * converges.
26
+ */
27
+ export declare function promoteDeployment(kv: RoutingKv, name: string, label: string | null): Promise<void>;
28
+ /** The deployment a name serves now, or null. */
29
+ export declare function readCurrent(kv: RoutingKv, name: string): Promise<string | null>;
30
+ /**
31
+ * Replace a name's crons with canonical UTC crons (`cron:<name>`), or delete them when the set is
32
+ * empty. A set that is not canonical is refused (`schedules-invalid`) before anything is written.
33
+ * The dispatcher fires a due cron on the name's current deployment, once its upload bound a
34
+ * `cron` trigger.
35
+ */
36
+ export declare function replaceSchedules(kv: RoutingKv, name: string, crons: readonly string[]): Promise<readonly string[]>;
37
+ /** A name's crons: empty when it has none; a stored set that is not canonical is refused. */
38
+ export declare function readSchedules(kv: RoutingKv, name: string): Promise<readonly string[]>;