@astrale-os/adapter-cloudflare 0.5.0-beta.13 → 0.5.0-beta.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1506 -0
- package/README.md +46 -2
- package/dist/adapter.d.ts +14 -0
- package/dist/adapter.js +82 -0
- package/dist/build/artifact.d.ts +7 -0
- package/dist/build/artifact.js +165 -0
- package/dist/build/bundle/admit.d.ts +1 -0
- package/dist/build/bundle/admit.js +9 -0
- package/dist/build/closure.d.ts +2 -0
- package/dist/build/closure.js +22 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +12 -3
- package/dist/build/codegen/wrangler.js +26 -18
- package/dist/build/configuration/addressing.d.ts +2 -0
- package/dist/build/configuration/addressing.js +11 -0
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +11 -0
- package/dist/build/configuration/worker-name.d.ts +2 -0
- package/dist/build/configuration/worker-name.js +18 -0
- package/dist/build/configuration.d.ts +5 -0
- package/dist/build/configuration.js +5 -0
- package/dist/build/direct.d.ts +4 -0
- package/dist/build/direct.js +90 -0
- package/dist/build/frontend/files.d.ts +9 -0
- package/dist/build/frontend/files.js +33 -0
- package/dist/build/frontend/readiness.d.ts +10 -0
- package/dist/build/frontend/readiness.js +21 -0
- package/dist/build/frontend/revision.d.ts +5 -0
- package/dist/build/frontend/revision.js +14 -0
- package/dist/build/frontend/vite.d.ts +8 -0
- package/dist/build/frontend/vite.js +32 -0
- package/dist/build/frontend/vite.process.d.ts +7 -0
- package/dist/build/frontend/vite.process.js +65 -0
- package/dist/build/frontend/vite.runner.d.ts +1 -0
- package/dist/build/frontend/vite.runner.js +120 -0
- package/dist/build/index.d.ts +9 -16
- package/dist/build/index.js +8 -16
- package/dist/build/materialize.d.ts +4 -0
- package/dist/build/materialize.js +10 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -0
- package/dist/build/worker/artifact.d.ts +40 -0
- package/dist/build/worker/artifact.js +1 -0
- package/dist/build/worker/artifact.load.d.ts +3 -0
- package/dist/build/worker/artifact.load.js +308 -0
- package/dist/build/worker/artifact.manifest.d.ts +48 -0
- package/dist/build/worker/artifact.manifest.js +87 -0
- package/dist/build/worker/artifact.paths.d.ts +4 -0
- package/dist/build/worker/artifact.paths.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +2 -0
- package/dist/build/worker/codegen/entry.js +28 -0
- package/dist/build/worker/codegen/service.d.ts +19 -0
- package/dist/build/worker/codegen/service.js +53 -0
- package/dist/build/worker/execution.prepare.d.ts +19 -0
- package/dist/build/worker/execution.prepare.js +115 -0
- package/dist/build/worker/index.d.ts +2 -0
- package/dist/build/worker/index.js +1 -0
- package/dist/build/worker/modules.d.ts +11 -0
- package/dist/build/worker/modules.js +26 -0
- package/dist/build/worker/runtime.d.ts +10 -0
- package/dist/build/worker/runtime.js +35 -0
- package/dist/build/worker/specifier.d.ts +1 -0
- package/dist/build/worker/specifier.js +5 -0
- package/dist/cloudflare.d.ts +1 -45
- package/dist/cloudflare.js +1 -202
- package/dist/deploy/deploy.d.ts +17 -0
- package/dist/deploy/deploy.js +221 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.js +1 -0
- package/dist/deploy/output.d.ts +2 -0
- package/dist/deploy/output.js +10 -0
- package/dist/deploy/readiness.d.ts +5 -0
- package/dist/deploy/readiness.js +18 -0
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +3 -0
- package/dist/identity/material.d.ts +7 -0
- package/dist/identity/material.js +42 -0
- package/dist/identity/secret.d.ts +3 -0
- package/dist/identity/secret.js +7 -0
- package/dist/identity/source.d.ts +26 -0
- package/dist/identity/source.js +127 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.js +10 -9
- package/dist/params.d.ts +40 -36
- package/dist/params.js +0 -1
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -0
- package/dist/release/index.js +2 -0
- package/dist/release/staged-worker-name.d.ts +3 -0
- package/dist/release/staged-worker-name.js +10 -0
- package/dist/worker/entry.d.ts +48 -0
- package/dist/worker/entry.js +157 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +46 -0
- package/dist/worker/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +2 -61
- package/dist/worker/index.js +2 -218
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +28 -0
- package/dist/wrangler/deploy.d.ts +24 -0
- package/dist/wrangler/deploy.js +44 -0
- package/dist/wrangler/index.d.ts +5 -0
- package/dist/wrangler/index.js +5 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +102 -0
- package/dist/wrangler/rollout.d.ts +27 -0
- package/dist/wrangler/rollout.js +75 -0
- package/dist/wrangler/secrets.d.ts +2 -0
- package/dist/wrangler/secrets.js +24 -0
- package/dist/wrangler/status.d.ts +18 -0
- package/dist/wrangler/status.js +75 -0
- package/dist/wrangler/triggers.d.ts +5 -0
- package/dist/wrangler/triggers.js +12 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/dist/wrangler/versions.d.ts +13 -0
- package/dist/wrangler/versions.js +38 -0
- package/package.json +34 -19
- package/template/astrale.config.ts +30 -31
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -27
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -252
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -138
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts +0 -88
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -283
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/fetch.d.ts.map +0 -1
- package/dist/worker/fetch.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -128
- package/src/build/frontend.ts +0 -298
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -189
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -372
- package/src/cloudflare.ts +0 -275
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/fetch.ts +0 -46
- package/src/worker/index.ts +0 -332
- package/src/worker/tsconfig.json +0 -10
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { SIGNING_IDENTITY_BINDING } from '../../identity/binding.js';
|
|
4
|
+
import { runWranglerBundle } from '../../wrangler/bundle.js';
|
|
5
|
+
import { admitWorkerBundle } from '../bundle/admit.js';
|
|
6
|
+
import { generateExecutionEntry, generateExecutionService } from '../codegen/execution.js';
|
|
7
|
+
import { generateWranglerConfig } from '../codegen/wrangler.js';
|
|
8
|
+
import { workerInvocationTimeout, workerRequestLimit } from '../configuration.js';
|
|
9
|
+
import { qualifyWorkerBundle } from '../qualification.js';
|
|
10
|
+
import { workerModuleSpecifier } from './specifier.js';
|
|
11
|
+
export const RELEASE_ENTRY = 'bundle/index.mjs';
|
|
12
|
+
export const RELEASE_SERVICE = 'bundle/service.mjs';
|
|
13
|
+
export async function prepareExecution(input) {
|
|
14
|
+
const runtimePath = resolve(input.context.projectDir, input.context.runtime.reference.path);
|
|
15
|
+
const runtimeSpecifier = moduleSpecifier(relative(input.directory, runtimePath));
|
|
16
|
+
const workerSpecifier = workerModuleSpecifier();
|
|
17
|
+
const maximumRequestBytes = workerRequestLimit(input.params.maximumRequestBytes);
|
|
18
|
+
const invocationTimeoutMs = workerInvocationTimeout(input.params.invocationTimeoutMs);
|
|
19
|
+
const serviceSource = generateExecutionService({
|
|
20
|
+
origin: input.context.build.schema.compiled.root.origin,
|
|
21
|
+
runtimeSpecifier,
|
|
22
|
+
workerSpecifier,
|
|
23
|
+
build: input.context.build,
|
|
24
|
+
...(input.frontendRevision === undefined ? {} : { frontendRevision: input.frontendRevision }),
|
|
25
|
+
...(maximumRequestBytes === undefined ? {} : { maximumRequestBytes }),
|
|
26
|
+
...(invocationTimeoutMs === undefined ? {} : { invocationTimeoutMs }),
|
|
27
|
+
...(input.params.tokenExchange === undefined
|
|
28
|
+
? {}
|
|
29
|
+
: { tokenExchange: input.params.tokenExchange }),
|
|
30
|
+
...(input.configuredIssuer === undefined && input.direct
|
|
31
|
+
? { providerAssignedWorker: input.name }
|
|
32
|
+
: {}),
|
|
33
|
+
...(input.router === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: {
|
|
36
|
+
router: {
|
|
37
|
+
binding: input.router.binding,
|
|
38
|
+
hostSuffix: input.router.hostSuffix,
|
|
39
|
+
minLabels: input.router.minLabels,
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
const serviceSourcePath = join(input.directory, 'service.gen.ts');
|
|
44
|
+
await writeFile(serviceSourcePath, serviceSource);
|
|
45
|
+
const serviceConfigPath = join(input.directory, 'wrangler.service.prepare.jsonc');
|
|
46
|
+
await writeFile(serviceConfigPath, generateWranglerConfig({
|
|
47
|
+
workerName: input.name,
|
|
48
|
+
main: './service.gen.ts',
|
|
49
|
+
vars: runtimeVars(input.params, input.configuredIssuer),
|
|
50
|
+
secretBindings: [SIGNING_IDENTITY_BINDING],
|
|
51
|
+
...(input.router === undefined
|
|
52
|
+
? {}
|
|
53
|
+
: { router: { binding: input.router.binding, service: input.router.service } }),
|
|
54
|
+
...(input.params.wrangler === undefined ? {} : { wrangler: input.params.wrangler }),
|
|
55
|
+
selfBinding: false,
|
|
56
|
+
}));
|
|
57
|
+
const serviceOutput = join(input.directory, 'dist-service');
|
|
58
|
+
await rm(serviceOutput, { recursive: true, force: true });
|
|
59
|
+
const emittedService = await runWranglerBundle({
|
|
60
|
+
projectDir: input.context.projectDir,
|
|
61
|
+
configPath: serviceConfigPath,
|
|
62
|
+
outDir: serviceOutput,
|
|
63
|
+
signal: input.context.signal,
|
|
64
|
+
});
|
|
65
|
+
await qualifyWorkerBundle({
|
|
66
|
+
metafilePath: emittedService.metafilePath,
|
|
67
|
+
inputRoot: dirname(serviceConfigPath),
|
|
68
|
+
});
|
|
69
|
+
await admitWorkerBundle(emittedService.bundlePath);
|
|
70
|
+
const service = new Uint8Array(await readFile(emittedService.bundlePath));
|
|
71
|
+
await mkdir(dirname(join(input.directory, RELEASE_SERVICE)), { recursive: true });
|
|
72
|
+
await writeFile(join(input.directory, RELEASE_SERVICE), service);
|
|
73
|
+
const sourcePath = join(input.directory, 'worker.gen.ts');
|
|
74
|
+
await writeFile(sourcePath, generateExecutionEntry('./service.mjs', workerSpecifier));
|
|
75
|
+
const configPath = join(input.directory, 'wrangler.prepare.jsonc');
|
|
76
|
+
await writeFile(configPath, generateWranglerConfig({
|
|
77
|
+
workerName: input.name,
|
|
78
|
+
...(input.params.route === undefined ? {} : { route: input.params.route }),
|
|
79
|
+
vars: runtimeVars(input.params, input.configuredIssuer),
|
|
80
|
+
secretBindings: [SIGNING_IDENTITY_BINDING],
|
|
81
|
+
modules: { baseDir: '.', rules: [{ type: 'ESModule', globs: [RELEASE_SERVICE] }] },
|
|
82
|
+
...(input.router === undefined
|
|
83
|
+
? {}
|
|
84
|
+
: { router: { binding: input.router.binding, service: input.router.service } }),
|
|
85
|
+
...(input.params.wrangler === undefined ? {} : { wrangler: input.params.wrangler }),
|
|
86
|
+
selfBinding: false,
|
|
87
|
+
}));
|
|
88
|
+
const output = join(input.directory, 'dist-prepare');
|
|
89
|
+
await rm(output, { recursive: true, force: true });
|
|
90
|
+
const emitted = await runWranglerBundle({
|
|
91
|
+
projectDir: input.context.projectDir,
|
|
92
|
+
configPath,
|
|
93
|
+
outDir: output,
|
|
94
|
+
signal: input.context.signal,
|
|
95
|
+
});
|
|
96
|
+
await qualifyWorkerBundle({
|
|
97
|
+
metafilePath: emitted.metafilePath,
|
|
98
|
+
inputRoot: dirname(configPath),
|
|
99
|
+
});
|
|
100
|
+
await admitWorkerBundle(emitted.bundlePath);
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
entry: new Uint8Array(await readFile(emitted.bundlePath)),
|
|
103
|
+
service,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
export function runtimeVars(params, configuredIssuer) {
|
|
107
|
+
return {
|
|
108
|
+
...params.vars,
|
|
109
|
+
...(configuredIssuer === undefined ? {} : { WORKER_URL: configuredIssuer }),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function moduleSpecifier(input) {
|
|
113
|
+
const normalized = input.split('\\').join('/');
|
|
114
|
+
return normalized.startsWith('.') ? normalized : `./${normalized}`;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadWorkerArtifact } from './artifact.load.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WorkerArtifact } from './artifact.js';
|
|
2
|
+
type WranglerModuleType = 'ESModule' | 'CompiledWasm' | 'Text' | 'Data';
|
|
3
|
+
/** Project one admitted Worker module inventory into Wrangler's relative module discovery. */
|
|
4
|
+
export declare function workerModules(worker: WorkerArtifact['release']): {
|
|
5
|
+
readonly baseDir: string;
|
|
6
|
+
readonly rules: readonly {
|
|
7
|
+
readonly type: WranglerModuleType;
|
|
8
|
+
readonly globs: readonly string[];
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
/** Project one admitted Worker module inventory into Wrangler's relative module discovery. */
|
|
9
|
+
export function workerModules(worker) {
|
|
10
|
+
const directory = posix.dirname(worker.entrypoint);
|
|
11
|
+
const groups = new Map();
|
|
12
|
+
for (const module of worker.modules) {
|
|
13
|
+
if (module.path === worker.entrypoint)
|
|
14
|
+
continue;
|
|
15
|
+
const relative = posix.relative(directory, module.path);
|
|
16
|
+
if (relative === '' || relative === '..' || relative.startsWith('../')) {
|
|
17
|
+
throw new TypeError('Cloudflare Worker module escapes its entrypoint directory.');
|
|
18
|
+
}
|
|
19
|
+
const type = TYPES[module.kind];
|
|
20
|
+
const globs = groups.get(type) ?? [];
|
|
21
|
+
globs.push(relative);
|
|
22
|
+
groups.set(type, globs);
|
|
23
|
+
}
|
|
24
|
+
const rules = [...groups].map(([type, globs]) => Object.freeze({ type, globs: Object.freeze(globs) }));
|
|
25
|
+
return Object.freeze({ baseDir: `./${directory}`, rules: Object.freeze(rules) });
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface WorkerRuntimeConfiguration {
|
|
2
|
+
readonly compatibilityDate: string;
|
|
3
|
+
readonly compatibilityFlags: readonly string[];
|
|
4
|
+
readonly vars: Readonly<Record<string, string>>;
|
|
5
|
+
readonly services: readonly {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly service: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
export declare function admitWorkerRuntimeConfiguration(input: string): WorkerRuntimeConfiguration;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function admitWorkerRuntimeConfiguration(input) {
|
|
2
|
+
const value = JSON.parse(input);
|
|
3
|
+
const compatibilityDate = value.compatibility_date;
|
|
4
|
+
const compatibilityFlags = value.compatibility_flags;
|
|
5
|
+
const vars = value.vars ?? {};
|
|
6
|
+
const services = value.services ?? [];
|
|
7
|
+
if (typeof compatibilityDate !== 'string' ||
|
|
8
|
+
!Array.isArray(compatibilityFlags) ||
|
|
9
|
+
compatibilityFlags.some((flag) => typeof flag !== 'string') ||
|
|
10
|
+
vars === null ||
|
|
11
|
+
typeof vars !== 'object' ||
|
|
12
|
+
Array.isArray(vars) ||
|
|
13
|
+
Object.values(vars).some((item) => typeof item !== 'string') ||
|
|
14
|
+
!Array.isArray(services)) {
|
|
15
|
+
invalidRuntime();
|
|
16
|
+
}
|
|
17
|
+
const admittedServices = services.map((input) => {
|
|
18
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input))
|
|
19
|
+
invalidRuntime();
|
|
20
|
+
const binding = Reflect.get(input, 'binding');
|
|
21
|
+
const service = Reflect.get(input, 'service');
|
|
22
|
+
if (typeof binding !== 'string' || typeof service !== 'string')
|
|
23
|
+
invalidRuntime();
|
|
24
|
+
return Object.freeze({ name: binding, service });
|
|
25
|
+
});
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
compatibilityDate,
|
|
28
|
+
compatibilityFlags: Object.freeze([...compatibilityFlags]),
|
|
29
|
+
vars: Object.freeze({ ...vars }),
|
|
30
|
+
services: Object.freeze(admittedServices),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function invalidRuntime() {
|
|
34
|
+
throw new TypeError('Generated Cloudflare runtime configuration is invalid.');
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function workerModuleSpecifier(): string;
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,45 +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 { DeployFetch } from '@astrale-os/sdk/deployment';
|
|
13
|
-
import { deployCheck } from '@astrale-os/sdk/deployment';
|
|
14
|
-
import type { CloudflareParams } from './params.js';
|
|
15
|
-
import { bulkPutSecrets, buildCloudflareWorker, buildFrontend, logTo, prepare, runWranglerDeploy, runWranglerDev, runWranglerTypes, startFrontendDev } from './build/index.js';
|
|
16
|
-
export declare function cloudflare(envs: Record<string, CloudflareParams>): DomainAdapter<CloudflareParams>;
|
|
17
|
-
interface CloudflareAdapterDependencies {
|
|
18
|
-
readonly bulkPutSecrets: typeof bulkPutSecrets;
|
|
19
|
-
readonly buildCloudflareWorker: typeof buildCloudflareWorker;
|
|
20
|
-
readonly buildFrontend: typeof buildFrontend;
|
|
21
|
-
readonly logTo: typeof logTo;
|
|
22
|
-
readonly prepare: typeof prepare;
|
|
23
|
-
readonly runWranglerDeploy: typeof runWranglerDeploy;
|
|
24
|
-
readonly runWranglerDev: typeof runWranglerDev;
|
|
25
|
-
readonly runWranglerTypes: typeof runWranglerTypes;
|
|
26
|
-
readonly startFrontendDev: typeof startFrontendDev;
|
|
27
|
-
readonly waitUntilLive: typeof waitUntilLive;
|
|
28
|
-
}
|
|
29
|
-
/** Exact orchestration seam used by adapter-level deployment qualification. */
|
|
30
|
-
export declare function cloudflareWithDependencies(envs: Record<string, CloudflareParams>, dependencies: CloudflareAdapterDependencies): DomainAdapter<CloudflareParams>;
|
|
31
|
-
/**
|
|
32
|
-
* Poll until the deployed Worker exposes one complete canonical deployment chain.
|
|
33
|
-
*/
|
|
34
|
-
export declare function waitUntilLive(url: string, onLog: (line: string) => void, expectations: {
|
|
35
|
-
readonly expectedOrigin: Parameters<typeof deployCheck>[0]['expectedOrigin'];
|
|
36
|
-
readonly expectedRevision: Parameters<typeof deployCheck>[0]['expectedRevision'];
|
|
37
|
-
readonly expectedDeploymentVersion?: string;
|
|
38
|
-
readonly fetch?: DeployFetch;
|
|
39
|
-
readonly timeoutMs?: number;
|
|
40
|
-
readonly fetchTimeoutMs?: number;
|
|
41
|
-
readonly retryMs?: number;
|
|
42
|
-
readonly sleep?: (ms: number) => Promise<void>;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
export {};
|
|
45
|
-
//# sourceMappingURL=cloudflare.d.ts.map
|
|
1
|
+
export { cloudflare } from './adapter.js';
|
package/dist/cloudflare.js
CHANGED
|
@@ -1,202 +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 { deployCheck } from '@astrale-os/sdk/deployment';
|
|
13
|
-
import { resolve } from 'node:path';
|
|
14
|
-
import { bulkPutSecrets, buildCloudflareWorker, buildFrontend, logTo, prepare, runWranglerDeploy, runWranglerDev, runWranglerTypes, startFrontendDev, } from './build/index.js';
|
|
15
|
-
export function cloudflare(envs) {
|
|
16
|
-
return cloudflareWithDependencies(envs, {
|
|
17
|
-
bulkPutSecrets,
|
|
18
|
-
buildCloudflareWorker,
|
|
19
|
-
buildFrontend,
|
|
20
|
-
logTo,
|
|
21
|
-
prepare,
|
|
22
|
-
runWranglerDeploy,
|
|
23
|
-
runWranglerDev,
|
|
24
|
-
runWranglerTypes,
|
|
25
|
-
startFrontendDev,
|
|
26
|
-
waitUntilLive,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/** Exact orchestration seam used by adapter-level deployment qualification. */
|
|
30
|
-
export function cloudflareWithDependencies(envs, dependencies) {
|
|
31
|
-
const frontendDevUrls = new Map();
|
|
32
|
-
return defineAdapter({
|
|
33
|
-
name: 'cloudflare',
|
|
34
|
-
envs,
|
|
35
|
-
async build(params, ctx) {
|
|
36
|
-
await dependencies.buildCloudflareWorker({
|
|
37
|
-
params,
|
|
38
|
-
context: ctx,
|
|
39
|
-
onLog: dependencies.logTo(),
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
async watch(params, ctx) {
|
|
43
|
-
const onLog = dependencies.logTo();
|
|
44
|
-
const projectKey = resolve(ctx.projectDir);
|
|
45
|
-
let frontendDev;
|
|
46
|
-
let handle;
|
|
47
|
-
try {
|
|
48
|
-
frontendDev = await dependencies.startFrontendDev({
|
|
49
|
-
definition: ctx.definition,
|
|
50
|
-
projectDir: ctx.projectDir,
|
|
51
|
-
onLog,
|
|
52
|
-
});
|
|
53
|
-
if (frontendDev !== undefined)
|
|
54
|
-
frontendDevUrls.set(projectKey, frontendDev.url);
|
|
55
|
-
const { configPath, port } = await dependencies.prepare(params, ctx, 'dev', undefined, frontendDev?.url);
|
|
56
|
-
handle = await dependencies.runWranglerDev({
|
|
57
|
-
projectDir: ctx.projectDir,
|
|
58
|
-
configPath,
|
|
59
|
-
port,
|
|
60
|
-
remote: Boolean(params.remote),
|
|
61
|
-
autoPickPort: params.port === undefined,
|
|
62
|
-
...(params.host ? { ip: '0.0.0.0' } : {}),
|
|
63
|
-
onReload: ctx.onReload,
|
|
64
|
-
onLog,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
frontendDevUrls.delete(projectKey);
|
|
69
|
-
try {
|
|
70
|
-
await frontendDev?.stop();
|
|
71
|
-
}
|
|
72
|
-
catch (cleanupError) {
|
|
73
|
-
throw new AggregateError([error, cleanupError], 'cloudflare development startup failed and Vite cleanup also failed');
|
|
74
|
-
}
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
if (handle === undefined)
|
|
78
|
-
throw new Error('cloudflare local Worker failed to start');
|
|
79
|
-
// With --host the actionable URL is the PUBLIC one (the tunnel/proxy
|
|
80
|
-
// front), not the local bind — print and spec-stamp that.
|
|
81
|
-
return {
|
|
82
|
-
url: params.host ?? handle.url,
|
|
83
|
-
localUrl: handle.url,
|
|
84
|
-
async stop() {
|
|
85
|
-
const errors = [];
|
|
86
|
-
frontendDevUrls.delete(projectKey);
|
|
87
|
-
try {
|
|
88
|
-
await frontendDev?.stop();
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
errors.push(error);
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
await handle.stop();
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
errors.push(error);
|
|
98
|
-
}
|
|
99
|
-
if (errors.length === 1)
|
|
100
|
-
throw errors[0];
|
|
101
|
-
if (errors.length > 1) {
|
|
102
|
-
throw new AggregateError(errors, 'cloudflare development cleanup failed');
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
// Config hot-regen rewrites generated files only. Wrangler reloads its config and entry;
|
|
108
|
-
// the author-owned Vite process keeps its own source/config watch lifecycle.
|
|
109
|
-
async regenerate(params, ctx) {
|
|
110
|
-
const { configPath } = await dependencies.prepare(params, ctx, 'dev', undefined, frontendDevUrls.get(resolve(ctx.projectDir)));
|
|
111
|
-
await dependencies.runWranglerTypes({
|
|
112
|
-
projectDir: ctx.projectDir,
|
|
113
|
-
configPath,
|
|
114
|
-
onLog: dependencies.logTo(),
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
async deploy(params, ctx) {
|
|
118
|
-
const frontend = await dependencies.buildFrontend({
|
|
119
|
-
definition: ctx.definition,
|
|
120
|
-
projectDir: ctx.projectDir,
|
|
121
|
-
onLog: dependencies.logTo(),
|
|
122
|
-
});
|
|
123
|
-
const { configPath, fallbackConfigPath, workerName: name, } = await dependencies.prepare(params, ctx, 'deploy', frontend);
|
|
124
|
-
const { url, deploymentVersion } = await dependencies.runWranglerDeploy({
|
|
125
|
-
projectDir: ctx.projectDir,
|
|
126
|
-
configPath,
|
|
127
|
-
workerName: name,
|
|
128
|
-
...(fallbackConfigPath ? { fallbackConfigPath } : {}),
|
|
129
|
-
...(params.route ? { route: params.route } : {}),
|
|
130
|
-
onLog: dependencies.logTo(),
|
|
131
|
-
});
|
|
132
|
-
if (Object.keys(ctx.secrets).length > 0) {
|
|
133
|
-
await dependencies.bulkPutSecrets({
|
|
134
|
-
projectDir: ctx.projectDir,
|
|
135
|
-
configPath,
|
|
136
|
-
secrets: ctx.secrets,
|
|
137
|
-
onLog: dependencies.logTo(),
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
// A first deploy on a fresh `*.workers.dev` host can take ~30-60s to
|
|
141
|
-
// propagate; an `astrale domain install <url>` issued right away would
|
|
142
|
-
// 404 (Cloudflare 1042). Block until the URL actually serves so the
|
|
143
|
-
// install line we print is immediately actionable.
|
|
144
|
-
await dependencies.waitUntilLive(url, dependencies.logTo(), {
|
|
145
|
-
expectedOrigin: ctx.definition.schema.origin,
|
|
146
|
-
expectedRevision: ctx.definition.domain.$.revision,
|
|
147
|
-
...(deploymentVersion === undefined
|
|
148
|
-
? {}
|
|
149
|
-
: { expectedDeploymentVersion: deploymentVersion }),
|
|
150
|
-
});
|
|
151
|
-
return { url };
|
|
152
|
-
},
|
|
153
|
-
secretsFile(params) {
|
|
154
|
-
return params.secrets;
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Poll until the deployed Worker exposes one complete canonical deployment chain.
|
|
160
|
-
*/
|
|
161
|
-
export async function waitUntilLive(url, onLog, expectations) {
|
|
162
|
-
const timeoutMs = expectations.timeoutMs ?? 90_000;
|
|
163
|
-
const fetchTimeoutMs = expectations.fetchTimeoutMs ?? 5_000;
|
|
164
|
-
const retryMs = expectations.retryMs ?? 3_000;
|
|
165
|
-
const sleep = expectations.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
166
|
-
const deadline = Date.now() + timeoutMs;
|
|
167
|
-
let waited = false;
|
|
168
|
-
let lastReason = 'not checked';
|
|
169
|
-
for (;;) {
|
|
170
|
-
try {
|
|
171
|
-
const deployed = await deployCheck({
|
|
172
|
-
url,
|
|
173
|
-
expectedOrigin: expectations.expectedOrigin,
|
|
174
|
-
expectedRevision: expectations.expectedRevision,
|
|
175
|
-
signal: AbortSignal.timeout(fetchTimeoutMs),
|
|
176
|
-
...(expectations.fetch === undefined ? {} : { fetch: expectations.fetch }),
|
|
177
|
-
log: () => undefined,
|
|
178
|
-
});
|
|
179
|
-
const actualDeploymentVersion = new URL(deployed.schema.bundle.href).searchParams.get('deployment');
|
|
180
|
-
if (expectations.expectedDeploymentVersion === undefined ||
|
|
181
|
-
actualDeploymentVersion === expectations.expectedDeploymentVersion) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
lastReason =
|
|
185
|
-
`bundle deployment=${JSON.stringify(actualDeploymentVersion)} ` +
|
|
186
|
-
`expected=${JSON.stringify(expectations.expectedDeploymentVersion)}`;
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
lastReason = error instanceof Error ? error.message : String(error);
|
|
190
|
-
}
|
|
191
|
-
if (Date.now() >= deadline) {
|
|
192
|
-
throw new Error(`deployed Worker did not expose a valid Publication chain within ` +
|
|
193
|
-
`${Math.round(timeoutMs / 1000)}s; last check: ${lastReason}`);
|
|
194
|
-
}
|
|
195
|
-
if (!waited) {
|
|
196
|
-
waited = true;
|
|
197
|
-
onLog('waiting for the URL to go live (first deploys can take ~30-60s)…');
|
|
198
|
-
}
|
|
199
|
-
await sleep(Math.min(retryMs, Math.max(0, deadline - Date.now())));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
//# sourceMappingURL=cloudflare.js.map
|
|
1
|
+
export { cloudflare } from './adapter.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DeployContext, DeployResult } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { Release } from '@astrale-os/sdk/deployment/release';
|
|
3
|
+
import type { materialize } from '../build/artifact.js';
|
|
4
|
+
import type { WorkerArtifact } from '../build/worker/artifact.js';
|
|
5
|
+
import type { signingIdentity } from '../identity/source.js';
|
|
6
|
+
import type { CloudflareParams } from '../params.js';
|
|
7
|
+
import type { runWranglerRollout } from '../wrangler/rollout.js';
|
|
8
|
+
import type { runWranglerDeploymentStatus } from '../wrangler/status.js';
|
|
9
|
+
export interface CloudflareDeployDependencies {
|
|
10
|
+
readonly materialize: typeof materialize;
|
|
11
|
+
readonly runWranglerRollout: typeof runWranglerRollout;
|
|
12
|
+
readonly runWranglerDeploymentStatus: typeof runWranglerDeploymentStatus;
|
|
13
|
+
readonly waitForReadiness: (release: Release, signal: AbortSignal, version: string, worker: WorkerArtifact, workerName?: string) => Promise<void>;
|
|
14
|
+
readonly signingIdentity: typeof signingIdentity;
|
|
15
|
+
}
|
|
16
|
+
/** Deploy one stable Worker target and verify its exact serving implementation. */
|
|
17
|
+
export declare function deployCloudflare(parameters: CloudflareParams, context: DeployContext, dependencies: CloudflareDeployDependencies): Promise<DeployResult>;
|