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

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
@@ -0,0 +1,52 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { releaseNamespace, releaseWorkerName } from '../release/index.js';
3
+ import { workerName } from './configuration.js';
4
+ export function admitDirectPlacement(artifact, worker, parameters) {
5
+ const name = workerName(parameters, worker.origin);
6
+ const release = config(artifact, 'wrangler.release.jsonc');
7
+ const gateway = config(artifact, 'wrangler.gateway.jsonc');
8
+ equal(release.name, releaseWorkerName(worker.revision));
9
+ equal(release.main, `./${worker.release.entrypoint}`);
10
+ equal(release.compatibility_date, worker.runtime.compatibilityDate);
11
+ equal(release.compatibility_flags, worker.runtime.compatibilityFlags);
12
+ equal(release.vars ?? {}, worker.bindings.vars);
13
+ equal(release.services ?? [], worker.bindings.services.map((binding) => ({
14
+ binding: binding.name,
15
+ service: binding.service,
16
+ })));
17
+ equal(record(release.secrets).required ?? [], worker.bindings.requiredSecrets);
18
+ const rules = Array.isArray(release.rules) ? release.rules : [];
19
+ equal(rules.flatMap((rule) => {
20
+ const globs = record(rule).globs;
21
+ return Array.isArray(globs) ? globs : [];
22
+ }), worker.release.modules
23
+ .filter((module) => module.path !== worker.release.entrypoint)
24
+ .map((module) => module.path));
25
+ equal(gateway.name, name);
26
+ equal(gateway.main, `./${worker.gateway.entrypoint}`);
27
+ equal(gateway.dispatch_namespaces, [{ binding: 'RELEASES', namespace: releaseNamespace(name) }]);
28
+ }
29
+ function config(artifact, path) {
30
+ const file = artifact.files.find((candidate) => candidate.path === path);
31
+ if (file === undefined)
32
+ throw new TypeError(`Direct Cloudflare artifact is missing ${path}.`);
33
+ try {
34
+ const value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(file.bytes()));
35
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
36
+ throw new Error();
37
+ return value;
38
+ }
39
+ catch (cause) {
40
+ throw new TypeError(`Direct Cloudflare artifact ${path} is invalid.`, { cause });
41
+ }
42
+ }
43
+ function record(input) {
44
+ return input !== null && typeof input === 'object' && !Array.isArray(input)
45
+ ? input
46
+ : {};
47
+ }
48
+ function equal(actual, expected) {
49
+ if (!isDeepStrictEqual(actual, expected)) {
50
+ throw new TypeError('Direct Cloudflare placement differs from its admitted Worker artifact.');
51
+ }
52
+ }
@@ -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
+ }
@@ -0,0 +1,8 @@
1
+ export declare function prepareGateway(input: {
2
+ readonly projectDir: string;
3
+ readonly directory: string;
4
+ readonly name: string;
5
+ readonly route?: string;
6
+ readonly namespace: string;
7
+ readonly revision: string;
8
+ }): Promise<Uint8Array>;
@@ -0,0 +1,32 @@
1
+ import { readFile, rm, writeFile } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ import { admitWorkerBundle } from '../bundle/admit.js';
4
+ import { generateWranglerConfig } from '../codegen/wrangler.js';
5
+ import { qualifyWorkerBundle } from '../qualification.js';
6
+ import { runWranglerBundle } from '../wrangler-cli.js';
7
+ import { generateGatewayEntry } from './source.js';
8
+ export async function prepareGateway(input) {
9
+ const gatewaySource = join(input.directory, 'gateway.gen.ts');
10
+ await writeFile(gatewaySource, generateGatewayEntry(input.revision));
11
+ const configPath = join(input.directory, 'wrangler.gateway.prepare.jsonc');
12
+ await writeFile(configPath, generateWranglerConfig({
13
+ workerName: input.name,
14
+ main: './gateway.gen.ts',
15
+ ...(input.route === undefined ? {} : { route: input.route }),
16
+ releases: { binding: 'RELEASES', namespace: input.namespace },
17
+ selfBinding: false,
18
+ }));
19
+ const output = join(input.directory, 'dist-gateway');
20
+ await rm(output, { recursive: true, force: true });
21
+ const emitted = await runWranglerBundle({
22
+ projectDir: input.projectDir,
23
+ configPath,
24
+ outDir: output,
25
+ });
26
+ await qualifyWorkerBundle({
27
+ metafilePath: emitted.metafilePath,
28
+ inputRoot: dirname(configPath),
29
+ });
30
+ await admitWorkerBundle(emitted.bundlePath);
31
+ return new Uint8Array(await readFile(emitted.bundlePath));
32
+ }
@@ -0,0 +1 @@
1
+ export declare function generateGatewayEntry(revision: string): string;
@@ -0,0 +1,7 @@
1
+ export function generateGatewayEntry(revision) {
2
+ return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
3
+ import { cloudflareGatewayEntry } from '@astrale-os/adapter-cloudflare/worker'
4
+
5
+ export default cloudflareGatewayEntry({ current: ${JSON.stringify(revision)} })
6
+ `;
7
+ }
@@ -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,38 @@
1
+ export type WorkerModuleKind = 'esm' | 'wasm' | 'text' | 'data';
2
+ export interface WorkerArtifactModule {
3
+ readonly path: string;
4
+ readonly kind: WorkerModuleKind;
5
+ bytes(): Uint8Array;
6
+ }
7
+ export interface WorkerArtifactExecutable {
8
+ readonly entrypoint: string;
9
+ readonly modules: readonly WorkerArtifactModule[];
10
+ }
11
+ export interface WorkerArtifact {
12
+ readonly origin: string;
13
+ readonly revision: string;
14
+ readonly release: WorkerArtifactExecutable;
15
+ readonly gateway: WorkerArtifactExecutable;
16
+ readonly runtime: {
17
+ readonly compatibilityDate: string;
18
+ readonly compatibilityFlags: readonly string[];
19
+ };
20
+ readonly bindings: {
21
+ readonly vars: Readonly<Record<string, string>>;
22
+ readonly services: readonly {
23
+ readonly name: string;
24
+ readonly service: string;
25
+ }[];
26
+ readonly requiredSecrets: readonly string[];
27
+ };
28
+ readonly assets?: {
29
+ readonly files: readonly {
30
+ readonly path: string;
31
+ readonly artifactPath: string;
32
+ readonly contentType?: string;
33
+ bytes(): Uint8Array;
34
+ }[];
35
+ readonly notFound: 'none' | '404-page' | 'single-page-application';
36
+ readonly runWorkerFirst: boolean;
37
+ };
38
+ }
@@ -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;