@astrale-os/adapter-cloudflare 0.5.0-beta.7 → 0.5.0-beta.71

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/CHANGELOG.md +887 -0
  2. package/README.md +25 -0
  3. package/dist/adapter.d.ts +17 -0
  4. package/dist/adapter.js +177 -0
  5. package/dist/build/artifact.d.ts +7 -0
  6. package/dist/build/artifact.js +163 -0
  7. package/dist/build/bundle/admit.d.ts +1 -0
  8. package/dist/build/bundle/admit.js +9 -0
  9. package/dist/build/closure.d.ts +2 -0
  10. package/dist/build/closure.js +22 -0
  11. package/dist/build/codegen/execution.d.ts +3 -0
  12. package/dist/build/codegen/execution.js +2 -0
  13. package/dist/build/codegen/merge.d.ts +0 -1
  14. package/dist/build/codegen/merge.js +0 -1
  15. package/dist/build/codegen/wrangler.d.ts +13 -1
  16. package/dist/build/codegen/wrangler.js +32 -17
  17. package/dist/build/configuration/addressing.d.ts +2 -0
  18. package/dist/build/configuration/addressing.js +11 -0
  19. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  20. package/dist/build/configuration/invocation-timeout.js +9 -0
  21. package/dist/build/configuration/request-limit.d.ts +2 -0
  22. package/dist/build/configuration/request-limit.js +9 -0
  23. package/dist/build/configuration/router.d.ts +7 -0
  24. package/dist/build/configuration/router.js +11 -0
  25. package/dist/build/configuration/worker-name.d.ts +2 -0
  26. package/dist/build/configuration/worker-name.js +18 -0
  27. package/dist/build/configuration.d.ts +5 -0
  28. package/dist/build/configuration.js +5 -0
  29. package/dist/build/direct.d.ts +4 -0
  30. package/dist/build/direct.js +93 -0
  31. package/dist/build/frontend/routes.d.ts +2 -0
  32. package/dist/build/frontend/routes.js +11 -0
  33. package/dist/build/frontend-v1.d.ts +16 -0
  34. package/dist/build/frontend-v1.js +133 -0
  35. package/dist/build/index.d.ts +10 -16
  36. package/dist/build/index.js +9 -16
  37. package/dist/build/materialize.d.ts +4 -0
  38. package/dist/build/materialize.js +10 -0
  39. package/dist/build/metafile.d.ts +5 -0
  40. package/dist/build/metafile.js +14 -0
  41. package/dist/build/parse-output.d.ts +0 -1
  42. package/dist/build/parse-output.js +0 -1
  43. package/dist/build/qualification.d.ts +5 -0
  44. package/dist/build/qualification.js +7 -0
  45. package/dist/build/roots.d.ts +2 -0
  46. package/dist/build/roots.js +34 -0
  47. package/dist/build/worker/artifact.d.ts +40 -0
  48. package/dist/build/worker/artifact.js +1 -0
  49. package/dist/build/worker/artifact.load.d.ts +3 -0
  50. package/dist/build/worker/artifact.load.js +308 -0
  51. package/dist/build/worker/artifact.manifest.d.ts +48 -0
  52. package/dist/build/worker/artifact.manifest.js +87 -0
  53. package/dist/build/worker/artifact.paths.d.ts +4 -0
  54. package/dist/build/worker/artifact.paths.js +25 -0
  55. package/dist/build/worker/codegen/entry.d.ts +2 -0
  56. package/dist/build/worker/codegen/entry.js +28 -0
  57. package/dist/build/worker/codegen/service.d.ts +16 -0
  58. package/dist/build/worker/codegen/service.js +52 -0
  59. package/dist/build/worker/execution.prepare.d.ts +18 -0
  60. package/dist/build/worker/execution.prepare.js +109 -0
  61. package/dist/build/worker/index.d.ts +2 -0
  62. package/dist/build/worker/index.js +1 -0
  63. package/dist/build/worker/modules.d.ts +11 -0
  64. package/dist/build/worker/modules.js +26 -0
  65. package/dist/build/worker/runtime.d.ts +10 -0
  66. package/dist/build/worker/runtime.js +35 -0
  67. package/dist/build/worker/specifier.d.ts +1 -0
  68. package/dist/build/worker/specifier.js +5 -0
  69. package/dist/build/wrangler/bundle.d.ts +10 -0
  70. package/dist/build/wrangler/bundle.js +29 -0
  71. package/dist/build/wrangler/deploy.d.ts +24 -0
  72. package/dist/build/wrangler/deploy.js +44 -0
  73. package/dist/build/wrangler/development.d.ts +17 -0
  74. package/dist/build/wrangler/development.js +136 -0
  75. package/dist/build/wrangler/process.d.ts +17 -0
  76. package/dist/build/wrangler/process.js +115 -0
  77. package/dist/build/wrangler/secrets.d.ts +6 -0
  78. package/dist/build/wrangler/secrets.js +58 -0
  79. package/dist/build/wrangler/status.d.ts +14 -0
  80. package/dist/build/wrangler/status.js +56 -0
  81. package/dist/build/wrangler/type-generation.d.ts +6 -0
  82. package/dist/build/wrangler/type-generation.js +19 -0
  83. package/dist/build/wrangler-cli.d.ts +6 -86
  84. package/dist/build/wrangler-cli.js +6 -275
  85. package/dist/cloudflare.d.ts +1 -34
  86. package/dist/cloudflare.js +1 -205
  87. package/dist/deploy/deploy.d.ts +15 -0
  88. package/dist/deploy/deploy.js +204 -0
  89. package/dist/deploy/index.d.ts +1 -0
  90. package/dist/deploy/index.js +1 -0
  91. package/dist/identity/binding.d.ts +2 -0
  92. package/dist/identity/binding.js +2 -0
  93. package/dist/identity/material.d.ts +7 -0
  94. package/dist/identity/material.js +42 -0
  95. package/dist/identity/secret.d.ts +3 -0
  96. package/dist/identity/secret.js +7 -0
  97. package/dist/identity/source.d.ts +26 -0
  98. package/dist/identity/source.js +98 -0
  99. package/dist/index.d.ts +3 -4
  100. package/dist/index.js +3 -4
  101. package/dist/params.d.ts +30 -5
  102. package/dist/params.js +0 -1
  103. package/dist/release/deployment.d.ts +44 -0
  104. package/dist/release/deployment.js +141 -0
  105. package/dist/release/index.d.ts +2 -0
  106. package/dist/release/index.js +2 -0
  107. package/dist/release/staged-worker-name.d.ts +3 -0
  108. package/dist/release/staged-worker-name.js +10 -0
  109. package/dist/worker/entry.d.ts +43 -0
  110. package/dist/worker/entry.js +181 -0
  111. package/dist/worker/fetch.d.ts +0 -1
  112. package/dist/worker/fetch.js +0 -1
  113. package/dist/worker/identity.d.ts +7 -0
  114. package/dist/worker/identity.js +23 -0
  115. package/dist/worker/index.d.ts +2 -61
  116. package/dist/worker/index.js +2 -216
  117. package/package.json +30 -19
  118. package/template/astrale.config.ts +19 -11
  119. package/dist/build/codegen/identity.d.ts +0 -10
  120. package/dist/build/codegen/identity.d.ts.map +0 -1
  121. package/dist/build/codegen/identity.js +0 -32
  122. package/dist/build/codegen/identity.js.map +0 -1
  123. package/dist/build/codegen/merge.d.ts.map +0 -1
  124. package/dist/build/codegen/merge.js.map +0 -1
  125. package/dist/build/codegen/worker.d.ts +0 -12
  126. package/dist/build/codegen/worker.d.ts.map +0 -1
  127. package/dist/build/codegen/worker.js +0 -40
  128. package/dist/build/codegen/worker.js.map +0 -1
  129. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  130. package/dist/build/codegen/wrangler.js.map +0 -1
  131. package/dist/build/frontend.d.ts +0 -26
  132. package/dist/build/frontend.d.ts.map +0 -1
  133. package/dist/build/frontend.js +0 -263
  134. package/dist/build/frontend.js.map +0 -1
  135. package/dist/build/index.d.ts.map +0 -1
  136. package/dist/build/index.js.map +0 -1
  137. package/dist/build/parse-output.d.ts.map +0 -1
  138. package/dist/build/parse-output.js.map +0 -1
  139. package/dist/build/prepare.d.ts +0 -18
  140. package/dist/build/prepare.d.ts.map +0 -1
  141. package/dist/build/prepare.js +0 -117
  142. package/dist/build/prepare.js.map +0 -1
  143. package/dist/build/worker.d.ts +0 -15
  144. package/dist/build/worker.d.ts.map +0 -1
  145. package/dist/build/worker.js +0 -21
  146. package/dist/build/worker.js.map +0 -1
  147. package/dist/build/wrangler-cli.d.ts.map +0 -1
  148. package/dist/build/wrangler-cli.js.map +0 -1
  149. package/dist/cloudflare.d.ts.map +0 -1
  150. package/dist/cloudflare.js.map +0 -1
  151. package/dist/index.d.ts.map +0 -1
  152. package/dist/index.js.map +0 -1
  153. package/dist/params.d.ts.map +0 -1
  154. package/dist/params.js.map +0 -1
  155. package/dist/worker/fetch.d.ts.map +0 -1
  156. package/dist/worker/fetch.js.map +0 -1
  157. package/dist/worker/index.d.ts.map +0 -1
  158. package/dist/worker/index.js.map +0 -1
  159. package/src/build/codegen/identity.ts +0 -40
  160. package/src/build/codegen/merge.ts +0 -92
  161. package/src/build/codegen/worker.ts +0 -53
  162. package/src/build/codegen/wrangler.ts +0 -127
  163. package/src/build/frontend.ts +0 -324
  164. package/src/build/index.ts +0 -29
  165. package/src/build/parse-output.ts +0 -60
  166. package/src/build/prepare.ts +0 -161
  167. package/src/build/worker.ts +0 -37
  168. package/src/build/wrangler-cli.ts +0 -362
  169. package/src/cloudflare.ts +0 -251
  170. package/src/index.ts +0 -21
  171. package/src/params.ts +0 -92
  172. package/src/worker/fetch.ts +0 -46
  173. package/src/worker/index.ts +0 -329
  174. package/src/worker/tsconfig.json +0 -10
@@ -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,5 @@
1
+ export { deploymentAddressing } from './configuration/addressing.js';
2
+ export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
3
+ export { workerRequestLimit } from './configuration/request-limit.js';
4
+ export { resolveRouter } from './configuration/router.js';
5
+ export { workerName } from './configuration/worker-name.js';
@@ -0,0 +1,5 @@
1
+ export { deploymentAddressing } from './configuration/addressing.js';
2
+ export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
3
+ export { workerRequestLimit } from './configuration/request-limit.js';
4
+ export { resolveRouter } from './configuration/router.js';
5
+ 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;
@@ -0,0 +1,93 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { generateWranglerConfig } from './codegen/wrangler.js';
3
+ import { resolveRouter, workerName } from './configuration.js';
4
+ import { frontendRoutes } from './frontend/routes.js';
5
+ import { workerModules } from './worker/modules.js';
6
+ export function admitDirectPlacement(artifact, worker, parameters) {
7
+ const name = workerName(parameters, worker.origin);
8
+ const release = config(artifact, 'wrangler.jsonc');
9
+ const router = resolveRouter(parameters.router);
10
+ const frontend = artifact.build.frontend;
11
+ const hasViteFrontend = frontend?.source.kind === 'vite';
12
+ equal(worker.assets !== undefined, hasViteFrontend);
13
+ if (worker.assets !== undefined) {
14
+ equal(worker.assets.notFound, 'none');
15
+ equal(worker.assets.runWorkerFirst, true);
16
+ }
17
+ equal(release, generated({
18
+ workerName: name,
19
+ main: `./${worker.release.entrypoint}`,
20
+ ...(parameters.route === undefined ? {} : { route: parameters.route }),
21
+ vars: worker.bindings.vars,
22
+ secretBindings: worker.bindings.requiredSecrets,
23
+ modules: directModules(worker.release),
24
+ ...(hasViteFrontend
25
+ ? {
26
+ frontend: {
27
+ directory: './frontend',
28
+ routes: frontendRoutes(frontend),
29
+ dev: false,
30
+ },
31
+ }
32
+ : {}),
33
+ ...(router === undefined
34
+ ? {}
35
+ : { router: { binding: router.binding, service: router.service } }),
36
+ ...(parameters.wrangler === undefined ? {} : { wrangler: parameters.wrangler }),
37
+ selfBinding: false,
38
+ }));
39
+ equal(release.compatibility_date, worker.runtime.compatibilityDate);
40
+ equalStringCollection(release.compatibility_flags, worker.runtime.compatibilityFlags);
41
+ equal(release.services ?? [], worker.bindings.services.map(serviceBinding));
42
+ equal(record(release.assets).html_handling, worker.assets?.htmlHandling);
43
+ }
44
+ function directModules(worker) {
45
+ try {
46
+ return workerModules(worker);
47
+ }
48
+ catch {
49
+ mismatch();
50
+ }
51
+ }
52
+ function generated(input) {
53
+ return JSON.parse(generateWranglerConfig(input));
54
+ }
55
+ function config(artifact, path) {
56
+ const file = artifact.files.find((candidate) => candidate.path === path);
57
+ if (file === undefined)
58
+ throw new TypeError(`Direct Cloudflare artifact is missing ${path}.`);
59
+ try {
60
+ const value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(file.bytes()));
61
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
62
+ throw new Error();
63
+ return value;
64
+ }
65
+ catch (cause) {
66
+ throw new TypeError(`Direct Cloudflare artifact ${path} is invalid.`, { cause });
67
+ }
68
+ }
69
+ function serviceBinding(binding) {
70
+ return { binding: binding.name, service: binding.service };
71
+ }
72
+ function record(input) {
73
+ return input !== null && typeof input === 'object' && !Array.isArray(input)
74
+ ? input
75
+ : {};
76
+ }
77
+ function equal(actual, expected) {
78
+ if (!isDeepStrictEqual(actual, expected)) {
79
+ throw new TypeError('Direct Cloudflare placement differs from its admitted Worker artifact.', {
80
+ cause: { actual, expected },
81
+ });
82
+ }
83
+ }
84
+ function equalStringCollection(actual, expected) {
85
+ if (!Array.isArray(actual) ||
86
+ actual.some((value) => typeof value !== 'string') ||
87
+ !isDeepStrictEqual([...actual].sort(), [...expected].sort())) {
88
+ mismatch();
89
+ }
90
+ }
91
+ function mismatch() {
92
+ throw new TypeError('Direct Cloudflare placement differs from its admitted Worker artifact.');
93
+ }
@@ -0,0 +1,2 @@
1
+ import type { PrepareContext } from '@astrale-os/sdk/deployment/adapter';
2
+ export declare function frontendRoutes(frontend: NonNullable<PrepareContext['build']['frontend']>): readonly string[];
@@ -0,0 +1,11 @@
1
+ export function frontendRoutes(frontend) {
2
+ if (frontend.source.kind !== 'vite')
3
+ return [];
4
+ return Object.freeze(frontend.routes
5
+ .flatMap((route) => frontend.source.kind === 'vite' && frontend.source.spa && route.path !== '/'
6
+ ? [route.path, `${route.path}/*`]
7
+ : route.path === '/'
8
+ ? ['/*']
9
+ : [route.path])
10
+ .sort());
11
+ }
@@ -0,0 +1,16 @@
1
+ import type { Build } from '@astrale-os/sdk/deployment/build';
2
+ import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
3
+ export interface FrontendDevHandle {
4
+ readonly url: string;
5
+ stop(): Promise<void>;
6
+ }
7
+ export declare function frontendFiles(input: {
8
+ readonly frontend: Build['frontend'];
9
+ readonly projectDir: string;
10
+ readonly onLog?: (line: string) => void;
11
+ }): Promise<readonly frontendBuild.FrontendFile[]>;
12
+ export declare function startFrontend(input: {
13
+ readonly frontend: Build['frontend'];
14
+ readonly projectDir: string;
15
+ readonly onLog?: (line: string) => void;
16
+ }): Promise<FrontendDevHandle | undefined>;
@@ -0,0 +1,133 @@
1
+ import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
2
+ import { spawn } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+ import { readFile, readdir, rm } from 'node:fs/promises';
5
+ import { createServer } from 'node:net';
6
+ import { join } from 'node:path';
7
+ export async function frontendFiles(input) {
8
+ const frontend = input.frontend;
9
+ if (frontend === undefined)
10
+ return [];
11
+ if (frontend.source.kind === 'external')
12
+ return frontendBuild.files(frontend, []);
13
+ const output = join(input.projectDir, '.astrale', 'frontend-build');
14
+ await rm(output, { recursive: true, force: true });
15
+ await run(viteCommand(input.projectDir), [
16
+ 'build',
17
+ '--outDir',
18
+ output,
19
+ '--emptyOutDir',
20
+ ...(frontend.source.config === undefined ? [] : ['--config', frontend.source.config]),
21
+ ], input.projectDir, input.onLog);
22
+ return frontendBuild.files(frontend, await readFiles(output));
23
+ }
24
+ export async function startFrontend(input) {
25
+ const frontend = input.frontend;
26
+ if (frontend === undefined || frontend.source.kind !== 'vite')
27
+ return undefined;
28
+ const port = await ephemeralPort();
29
+ const child = spawn(viteCommand(input.projectDir), [
30
+ '--host',
31
+ '127.0.0.1',
32
+ '--port',
33
+ String(port),
34
+ '--strictPort',
35
+ ...(frontend.source.config === undefined ? [] : ['--config', frontend.source.config]),
36
+ ], { cwd: input.projectDir, stdio: ['ignore', 'pipe', 'pipe'] });
37
+ const output = [];
38
+ const collect = (buffer) => {
39
+ for (const line of buffer.toString().split('\n')) {
40
+ if (line.trim() === '')
41
+ continue;
42
+ output.push(line);
43
+ if (output.length > 40)
44
+ output.shift();
45
+ input.onLog?.(line);
46
+ }
47
+ };
48
+ child.stdout?.on('data', collect);
49
+ child.stderr?.on('data', collect);
50
+ const url = `http://127.0.0.1:${port}`;
51
+ try {
52
+ await ready(url, child, output);
53
+ }
54
+ catch (cause) {
55
+ await stop(child);
56
+ throw cause;
57
+ }
58
+ return Object.freeze({ url, stop: () => stop(child) });
59
+ }
60
+ async function readFiles(root, current = '') {
61
+ const entries = await readdir(join(root, current), { withFileTypes: true });
62
+ const files = [];
63
+ for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
64
+ const path = current === '' ? entry.name : `${current}/${entry.name}`;
65
+ if (entry.isDirectory())
66
+ files.push(...(await readFiles(root, path)));
67
+ else if (entry.isFile()) {
68
+ files.push({ path, content: new Uint8Array(await readFile(join(root, path))) });
69
+ }
70
+ }
71
+ return files;
72
+ }
73
+ function viteCommand(projectDir) {
74
+ const command = join(projectDir, 'node_modules', '.bin', 'vite');
75
+ if (!existsSync(command))
76
+ throw new TypeError('Vite frontend requires a project-local vite binary.');
77
+ return command;
78
+ }
79
+ function run(command, args, cwd, onLog) {
80
+ return new Promise((resolve, reject) => {
81
+ const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
82
+ let output = '';
83
+ const collect = (buffer) => {
84
+ const value = buffer.toString();
85
+ output += value;
86
+ for (const line of value.split('\n'))
87
+ if (line.trim() !== '')
88
+ onLog?.(line);
89
+ };
90
+ child.stdout?.on('data', collect);
91
+ child.stderr?.on('data', collect);
92
+ child.on('error', reject);
93
+ child.on('exit', (code) => code === 0
94
+ ? resolve()
95
+ : reject(new Error(`Vite failed (code ${code ?? 1}):\n${output.slice(-1500)}`)));
96
+ });
97
+ }
98
+ function ephemeralPort() {
99
+ return new Promise((resolve, reject) => {
100
+ const server = createServer();
101
+ server.once('error', reject);
102
+ server.listen(0, '127.0.0.1', () => {
103
+ const address = server.address();
104
+ const port = typeof address === 'object' && address !== null ? address.port : 0;
105
+ server.close((cause) => (cause === undefined ? resolve(port) : reject(cause)));
106
+ });
107
+ });
108
+ }
109
+ async function ready(url, child, output) {
110
+ const deadline = Date.now() + 15_000;
111
+ while (Date.now() < deadline) {
112
+ if (child.exitCode !== null) {
113
+ throw new Error(`Vite exited before readiness (code ${child.exitCode}).\n${output.join('\n')}`);
114
+ }
115
+ try {
116
+ const response = await fetch(url, { signal: AbortSignal.timeout(500) });
117
+ await response.body?.cancel();
118
+ return;
119
+ }
120
+ catch {
121
+ await new Promise((resolve) => setTimeout(resolve, 50));
122
+ }
123
+ }
124
+ throw new Error(`Vite did not become ready at ${url}.`);
125
+ }
126
+ function stop(child) {
127
+ if (child.exitCode !== null || child.killed)
128
+ return Promise.resolve();
129
+ return new Promise((resolve) => {
130
+ child.once('exit', () => resolve());
131
+ child.kill('SIGTERM');
132
+ });
133
+ }
@@ -1,16 +1,10 @@
1
- /**
2
- * `@astrale-os/adapter-cloudflare/build` — the shared Cloudflare-Workers build
3
- * toolkit, exposed for sibling deploy adapters (e.g.
4
- * `@astrale-os/adapter-astrale`).
5
- *
6
- * This is the "compile a `defineDomain` into a Cloudflare Workers bundle + run
7
- * local dev" surface that every Cloudflare-Workers deploy strategy shares,
8
- * regardless of WHERE the bundle ultimately ships. It is NOT part of the public
9
- * adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
10
- * build on so the codegen/bundling/dev logic lives in exactly one place.
11
- */
12
- export { buildFrontend, FRONTEND_STAGE_DIR, watchFrontend, type FrontendWatchHandle, type FrontendWatchSubscribe, type FrontendWatchSubscription, } from './frontend.js';
13
- export { logTo, prepare } from './prepare.js';
14
- export { buildCloudflareWorker, type CloudflareWorkerBuild } from './worker.js';
15
- export { bulkPutSecrets, runWranglerBundle, runWranglerDeploy, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
16
- //# sourceMappingURL=index.d.ts.map
1
+ export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
2
+ export { loadWorkerArtifact } from './worker/index.js';
3
+ export type { WorkerArtifact } from './worker/index.js';
4
+ export { resolveRouter, workerName } from './configuration.js';
5
+ export { frontendFiles, startFrontend, type FrontendDevHandle } from './frontend-v1.js';
6
+ export { qualifyWorkerBundle } from './qualification.js';
7
+ export { assertSingletonRuntimeRoots } from './roots.js';
8
+ export { signingIdentity } from '../identity/source.js';
9
+ export { signingIdentitySecrets } from '../identity/secret.js';
10
+ export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
@@ -1,16 +1,9 @@
1
- /**
2
- * `@astrale-os/adapter-cloudflare/build` — the shared Cloudflare-Workers build
3
- * toolkit, exposed for sibling deploy adapters (e.g.
4
- * `@astrale-os/adapter-astrale`).
5
- *
6
- * This is the "compile a `defineDomain` into a Cloudflare Workers bundle + run
7
- * local dev" surface that every Cloudflare-Workers deploy strategy shares,
8
- * regardless of WHERE the bundle ultimately ships. It is NOT part of the public
9
- * adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
10
- * build on so the codegen/bundling/dev logic lives in exactly one place.
11
- */
12
- export { buildFrontend, FRONTEND_STAGE_DIR, watchFrontend, } from './frontend.js';
13
- export { logTo, prepare } from './prepare.js';
14
- export { buildCloudflareWorker } from './worker.js';
15
- export { bulkPutSecrets, runWranglerBundle, runWranglerDeploy, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
16
- //# sourceMappingURL=index.js.map
1
+ export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
2
+ export { loadWorkerArtifact } from './worker/index.js';
3
+ export { resolveRouter, workerName } from './configuration.js';
4
+ export { frontendFiles, startFrontend } from './frontend-v1.js';
5
+ export { qualifyWorkerBundle } from './qualification.js';
6
+ export { assertSingletonRuntimeRoots } from './roots.js';
7
+ export { signingIdentity } from '../identity/source.js';
8
+ export { signingIdentitySecrets } from '../identity/secret.js';
9
+ export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
@@ -0,0 +1,4 @@
1
+ export declare function materialize(root: string, files: readonly {
2
+ readonly path: string;
3
+ bytes(): Uint8Array;
4
+ }[]): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import { mkdir, rm, writeFile } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ export async function materialize(root, files) {
4
+ await rm(root, { recursive: true, force: true });
5
+ for (const file of files) {
6
+ const path = join(root, file.path);
7
+ await mkdir(dirname(path), { recursive: true });
8
+ await writeFile(path, file.bytes());
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ export interface WranglerMetafile {
2
+ readonly inputs: Readonly<Record<string, unknown>>;
3
+ }
4
+ /** Decode Wrangler's emitted esbuild graph at the provider-tooling boundary. */
5
+ export declare function readWranglerMetafile(path: string): Promise<WranglerMetafile>;
@@ -0,0 +1,14 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ /** Decode Wrangler's emitted esbuild graph at the provider-tooling boundary. */
3
+ export async function readWranglerMetafile(path) {
4
+ const source = await readFile(path, 'utf8');
5
+ const value = JSON.parse(source);
6
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
7
+ throw new TypeError('Wrangler metafile is not an object.');
8
+ }
9
+ const inputs = Reflect.get(value, 'inputs');
10
+ if (inputs === null || typeof inputs !== 'object' || Array.isArray(inputs)) {
11
+ throw new TypeError('Wrangler metafile has no input graph.');
12
+ }
13
+ return Object.freeze({ inputs: inputs });
14
+ }
@@ -24,4 +24,3 @@ export declare function parseDeployUrl(text: string, route?: string): string | u
24
24
  export declare function parseDeployVersionId(text: string): string | undefined;
25
25
  /** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
26
26
  export declare function normalizeLocal(url: string, port: number): string;
27
- //# sourceMappingURL=parse-output.d.ts.map
@@ -55,4 +55,3 @@ export function normalizeLocal(url, port) {
55
55
  return `http://localhost:${port}`;
56
56
  }
57
57
  }
58
- //# sourceMappingURL=parse-output.js.map
@@ -0,0 +1,5 @@
1
+ /** Qualify Wrangler's emitted module, not generated source or an inferred graph. */
2
+ export declare function qualifyWorkerBundle(evidence: {
3
+ readonly metafilePath: string;
4
+ readonly inputRoot: string;
5
+ }): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { assertRuntimeClosure } from './closure.js';
2
+ import { assertSingletonRuntimeRoots } from './roots.js';
3
+ /** Qualify Wrangler's emitted module, not generated source or an inferred graph. */
4
+ export async function qualifyWorkerBundle(evidence) {
5
+ await assertRuntimeClosure(evidence.metafilePath);
6
+ await assertSingletonRuntimeRoots(evidence.metafilePath, evidence.inputRoot);
7
+ }
@@ -0,0 +1,2 @@
1
+ /** Prove that Wrangler emitted at most one physical root per runtime package. */
2
+ export declare function assertSingletonRuntimeRoots(metafilePath: string, inputRoot: string): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { readWranglerMetafile } from './metafile.js';
4
+ const RUNTIME_PACKAGES = [
5
+ '@astrale-os/adapter-cloudflare',
6
+ '@astrale-os/sdk',
7
+ '@astrale-os/kernel-core',
8
+ '@astrale-os/kernel-dsl',
9
+ '@astrale-os/kernel-ports',
10
+ '@astrale-os/kernel-protocol',
11
+ '@astrale-os/kernel-server',
12
+ '@astrale-os/kernel-client',
13
+ ];
14
+ /** Prove that Wrangler emitted at most one physical root per runtime package. */
15
+ export async function assertSingletonRuntimeRoots(metafilePath, inputRoot) {
16
+ const metafile = await readWranglerMetafile(metafilePath);
17
+ for (const name of RUNTIME_PACKAGES) {
18
+ const roots = new Set();
19
+ for (const input of Object.keys(metafile.inputs)) {
20
+ const root = packageRoot(input, name);
21
+ if (root !== undefined)
22
+ roots.add(await realpath(resolve(inputRoot, root)));
23
+ }
24
+ if (roots.size > 1) {
25
+ throw new Error(`Cloudflare Worker contains duplicate physical ${name} roots: ${[...roots].join(', ')}.`);
26
+ }
27
+ }
28
+ }
29
+ function packageRoot(input, name) {
30
+ const normalized = input.replaceAll('\\', '/');
31
+ const marker = `node_modules/${name}/`;
32
+ const index = normalized.lastIndexOf(marker);
33
+ return index < 0 ? undefined : normalized.slice(0, index + marker.length - 1);
34
+ }
@@ -0,0 +1,40 @@
1
+ import type { WorkerDeploymentId } from '../../release/deployment.js';
2
+ export type WorkerModuleKind = 'esm' | 'wasm' | 'text' | 'data';
3
+ export interface WorkerArtifactModule {
4
+ readonly path: string;
5
+ readonly kind: WorkerModuleKind;
6
+ bytes(): Uint8Array;
7
+ }
8
+ export interface WorkerArtifactExecutable {
9
+ readonly entrypoint: string;
10
+ readonly modules: readonly WorkerArtifactModule[];
11
+ }
12
+ export interface WorkerArtifact {
13
+ readonly origin: string;
14
+ readonly revision: string;
15
+ readonly deployment: WorkerDeploymentId;
16
+ readonly release: WorkerArtifactExecutable;
17
+ readonly runtime: {
18
+ readonly compatibilityDate: string;
19
+ readonly compatibilityFlags: readonly string[];
20
+ };
21
+ readonly bindings: {
22
+ readonly vars: Readonly<Record<string, string>>;
23
+ readonly services: readonly {
24
+ readonly name: string;
25
+ readonly service: string;
26
+ }[];
27
+ readonly requiredSecrets: readonly string[];
28
+ };
29
+ readonly assets?: {
30
+ readonly files: readonly {
31
+ readonly path: string;
32
+ readonly artifactPath: string;
33
+ readonly contentType?: string;
34
+ bytes(): Uint8Array;
35
+ }[];
36
+ readonly notFound: 'none' | '404-page' | 'single-page-application';
37
+ readonly runWorkerFirst: boolean;
38
+ readonly htmlHandling?: 'none';
39
+ };
40
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { WorkerArtifact } from './artifact.js';
3
+ export declare function loadWorkerArtifact(artifact: PreparedArtifact): WorkerArtifact;