@astrale-os/adapter-cloudflare 0.5.0-beta.23 → 0.5.0-beta.230
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/README.md +258 -0
- package/dist/adapter.d.ts +9 -15
- package/dist/adapter.js +43 -129
- package/dist/build/bundle/admit.d.ts +3 -0
- package/dist/build/bundle/admit.js +47 -0
- package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
- package/dist/build/bundle/compiled-wasm-loader.js +21 -0
- package/dist/build/bundler.d.ts +23 -0
- package/dist/build/bundler.js +103 -0
- package/dist/build/closure.d.ts +4 -1
- package/dist/build/closure.js +7 -1
- package/dist/build/codegen/execution.d.ts +3 -13
- package/dist/build/codegen/execution.js +2 -44
- package/dist/build/codegen/wrangler.d.ts +28 -10
- package/dist/build/codegen/wrangler.js +71 -21
- 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 +17 -0
- package/dist/build/configuration/settings.d.ts +6 -0
- package/dist/build/configuration/settings.js +40 -0
- package/dist/build/configuration.d.ts +4 -9
- package/dist/build/configuration.js +4 -40
- package/dist/build/frontend/files.d.ts +19 -0
- package/dist/build/frontend/files.js +99 -0
- package/dist/build/frontend/readiness.d.ts +16 -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 +14 -0
- package/dist/build/frontend/vite.js +42 -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 +155 -0
- package/dist/build/index.d.ts +10 -6
- package/dist/build/index.js +10 -6
- package/dist/build/material.d.ts +10 -0
- package/dist/build/material.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +9 -0
- package/dist/build/worker/codegen/entry.js +65 -0
- package/dist/build/worker/codegen/literal.d.ts +28 -0
- package/dist/build/worker/codegen/literal.js +136 -0
- package/dist/build/worker/codegen/service.d.ts +14 -0
- package/dist/build/worker/codegen/service.js +56 -0
- package/dist/build/worker/execution.prepare.d.ts +22 -0
- package/dist/build/worker/execution.prepare.js +131 -0
- package/dist/build/worker/media-type.d.ts +1 -0
- package/dist/build/worker/media-type.js +20 -0
- package/dist/build/worker/modules.d.ts +20 -0
- package/dist/build/worker/modules.js +32 -0
- package/dist/build/worker/specifier.d.ts +5 -0
- package/dist/build/worker/specifier.js +15 -0
- package/dist/build/worker/upload.d.ts +23 -0
- package/dist/build/worker/upload.js +42 -0
- package/dist/hosting/activation.d.ts +46 -0
- package/dist/hosting/activation.js +127 -0
- package/dist/hosting/assets.d.ts +14 -0
- package/dist/hosting/assets.js +53 -0
- package/dist/hosting/bounded.d.ts +10 -0
- package/dist/hosting/bounded.js +32 -0
- package/dist/hosting/bytes.d.ts +6 -0
- package/dist/hosting/bytes.js +25 -0
- package/dist/hosting/client.d.ts +153 -0
- package/dist/hosting/client.js +516 -0
- package/dist/hosting/dispatcher/cron.d.mts +10 -0
- package/dist/hosting/dispatcher/cron.mjs +135 -0
- package/dist/hosting/dispatcher/deployments.d.mts +26 -0
- package/dist/hosting/dispatcher/deployments.mjs +158 -0
- package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
- package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
- package/dist/hosting/dispatcher/env.d.mts +51 -0
- package/dist/hosting/dispatcher/failure.d.mts +4 -0
- package/dist/hosting/dispatcher/failure.mjs +15 -0
- package/dist/hosting/dispatcher/index.d.mts +4 -0
- package/dist/hosting/dispatcher/index.mjs +8 -0
- package/dist/hosting/dispatcher/modules.d.ts +24 -0
- package/dist/hosting/dispatcher/modules.js +55 -0
- package/dist/hosting/dispatcher/services.d.mts +23 -0
- package/dist/hosting/dispatcher/services.mjs +202 -0
- package/dist/hosting/identity.d.ts +15 -0
- package/dist/hosting/identity.js +36 -0
- package/dist/hosting/index.d.ts +34 -0
- package/dist/hosting/index.js +32 -0
- package/dist/hosting/kv.d.ts +106 -0
- package/dist/hosting/kv.js +235 -0
- package/dist/hosting/listing.d.ts +34 -0
- package/dist/hosting/listing.js +49 -0
- package/dist/hosting/names.d.ts +16 -0
- package/dist/hosting/names.js +28 -0
- package/dist/hosting/provision/account.d.ts +11 -0
- package/dist/hosting/provision/account.js +86 -0
- package/dist/hosting/provision/dispatcher.d.ts +42 -0
- package/dist/hosting/provision/dispatcher.js +99 -0
- package/dist/hosting/provision/ingress.d.ts +12 -0
- package/dist/hosting/provision/ingress.js +31 -0
- package/dist/hosting/provision/plan.d.ts +143 -0
- package/dist/hosting/provision/plan.js +246 -0
- package/dist/hosting/provision/routing.d.ts +82 -0
- package/dist/hosting/provision/routing.js +226 -0
- package/dist/hosting/readiness.d.ts +53 -0
- package/dist/hosting/readiness.js +79 -0
- package/dist/hosting/refusal.d.ts +28 -0
- package/dist/hosting/refusal.js +13 -0
- package/dist/hosting/retirement.d.ts +68 -0
- package/dist/hosting/retirement.js +99 -0
- package/dist/hosting/retry-after.d.ts +6 -0
- package/dist/hosting/retry-after.js +55 -0
- package/dist/hosting/script.d.ts +186 -0
- package/dist/hosting/script.js +324 -0
- package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
- package/dist/hosting/testing/fake-cloudflare.js +757 -0
- package/dist/hosting/testing/index.d.ts +6 -0
- package/dist/hosting/testing/index.js +6 -0
- package/dist/hosting/time.d.ts +25 -0
- package/dist/hosting/time.js +48 -0
- package/dist/identity/binding.d.ts +1 -1
- package/dist/identity/binding.js +1 -1
- package/dist/identity/material.d.ts +1 -2
- package/dist/identity/material.js +5 -18
- package/dist/index.d.ts +14 -12
- package/dist/index.js +13 -11
- package/dist/namespace/configure.d.ts +22 -0
- package/dist/namespace/configure.js +199 -0
- package/dist/namespace/coordinates.d.ts +15 -0
- package/dist/namespace/coordinates.js +49 -0
- package/dist/namespace/deploy-release.d.ts +53 -0
- package/dist/namespace/deploy-release.js +387 -0
- package/dist/namespace/hosting.d.ts +29 -0
- package/dist/namespace/hosting.js +120 -0
- package/dist/namespace/index.d.ts +12 -0
- package/dist/namespace/index.js +12 -0
- package/dist/namespace/list.d.ts +18 -0
- package/dist/namespace/list.js +63 -0
- package/dist/namespace/readiness.d.ts +32 -0
- package/dist/namespace/readiness.js +35 -0
- package/dist/namespace/record.d.ts +21 -0
- package/dist/namespace/record.js +53 -0
- package/dist/params.d.ts +60 -76
- package/dist/release/build.d.ts +35 -0
- package/dist/release/build.js +44 -0
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -2
- package/dist/release/index.js +2 -2
- package/dist/worker/binary.d.ts +21 -0
- package/dist/worker/binary.js +31 -0
- package/dist/worker/build-digest.d.ts +10 -0
- package/dist/worker/build-digest.js +22 -0
- package/dist/worker/cache.d.ts +28 -0
- package/dist/worker/cache.js +70 -0
- package/dist/worker/durable.d.ts +3 -0
- package/dist/worker/durable.js +5 -0
- package/dist/worker/entry.d.ts +38 -25
- package/dist/worker/entry.js +87 -109
- package/dist/worker/front.d.ts +56 -0
- package/dist/worker/front.js +59 -0
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +83 -0
- package/dist/worker/index.d.ts +4 -1
- package/dist/worker/index.js +4 -1
- package/dist/worker/restate.d.ts +6 -0
- package/dist/worker/restate.js +6 -0
- package/dist/worker/settings.d.ts +47 -0
- package/dist/worker/settings.js +163 -0
- package/dist/wrangler/bundle.d.ts +18 -0
- package/dist/wrangler/bundle.js +36 -0
- package/dist/wrangler/index.d.ts +3 -0
- package/dist/wrangler/index.js +3 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +113 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +36 -14
- package/template/astrale.config.ts +42 -36
- package/dist/build/artifact.d.ts +0 -8
- package/dist/build/artifact.js +0 -179
- package/dist/build/codegen/gateway.d.ts +0 -1
- package/dist/build/codegen/gateway.js +0 -7
- package/dist/build/frontend-v1.d.ts +0 -16
- package/dist/build/frontend-v1.js +0 -133
- package/dist/build/parse-output.d.ts +0 -26
- package/dist/build/parse-output.js +0 -57
- package/dist/build/wrangler-cli.d.ts +0 -105
- package/dist/build/wrangler-cli.js +0 -448
- package/dist/deploy/deploy.d.ts +0 -17
- package/dist/deploy/deploy.js +0 -207
- package/dist/deploy/index.d.ts +0 -1
- package/dist/deploy/index.js +0 -1
- package/dist/identity/secret.d.ts +0 -3
- package/dist/identity/secret.js +0 -7
- package/dist/identity/source.d.ts +0 -26
- package/dist/identity/source.js +0 -98
- package/dist/release/namespace.d.ts +0 -2
- package/dist/release/namespace.js +0 -6
- package/dist/release/target.d.ts +0 -2
- package/dist/release/target.js +0 -9
- package/dist/worker/gateway.d.ts +0 -15
- package/dist/worker/gateway.js +0 -26
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CLOUDFLARE_WORKER_BUNDLER, workerAssetFile } from '../release/build.js';
|
|
4
|
+
import { frontendFiles } from './frontend/files.js';
|
|
5
|
+
import { frontendRevision } from './frontend/revision.js';
|
|
6
|
+
import { prepareExecution, RELEASE_ENTRY, RELEASE_SERVICE } from './worker/execution.prepare.js';
|
|
7
|
+
/** Worker modules live beside the entry; WASM is the only non-ESM kind preparation emits. */
|
|
8
|
+
const MODULE_DIRECTORY = 'bundle/';
|
|
9
|
+
/**
|
|
10
|
+
* Bundles every generated Cloudflare Worker, for adapter-cloudflare and adapter-astrale alike. It
|
|
11
|
+
* reads no Environment: settings, address, issuer and key are bound at deploy.
|
|
12
|
+
*/
|
|
13
|
+
export const cloudflareWorkerBundler = Object.freeze({
|
|
14
|
+
id: CLOUDFLARE_WORKER_BUNDLER.id,
|
|
15
|
+
version: CLOUDFLARE_WORKER_BUNDLER.version,
|
|
16
|
+
async bundle(context) {
|
|
17
|
+
const worker = await bundleWorker(context);
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
entrypoint: RELEASE_ENTRY,
|
|
20
|
+
...(worker.compactBundle === undefined ? {} : { compactBundle: worker.compactBundle }),
|
|
21
|
+
files: Object.freeze([
|
|
22
|
+
{ path: RELEASE_ENTRY, content: worker.entry },
|
|
23
|
+
...worker.modules.map(({ path, content }) => ({ path, content })),
|
|
24
|
+
...worker.frontend.map((file) => ({
|
|
25
|
+
path: workerAssetFile(`/${file.path}`),
|
|
26
|
+
content: file.bytes(),
|
|
27
|
+
})),
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
/** Bundle the Worker modules and build the frontend they serve, in one scratch directory. */
|
|
33
|
+
export async function bundleWorker(context) {
|
|
34
|
+
const stateDirectory = join(context.projectDir, '.astrale');
|
|
35
|
+
await mkdir(stateDirectory, { recursive: true });
|
|
36
|
+
const directory = await mkdtemp(join(stateDirectory, 'prepare-'));
|
|
37
|
+
try {
|
|
38
|
+
// `frontend` is the served file list; `addressed` rides alongside it into the Worker, where it
|
|
39
|
+
// decides which of those files a browser may retain.
|
|
40
|
+
const { files: frontend, addressed } = await frontendFiles({
|
|
41
|
+
frontend: context.build.frontend,
|
|
42
|
+
projectDir: context.projectDir,
|
|
43
|
+
output: join(directory, 'frontend'),
|
|
44
|
+
recordSource: context.recordSource,
|
|
45
|
+
signal: context.signal,
|
|
46
|
+
});
|
|
47
|
+
const modules = await prepareExecution({
|
|
48
|
+
context,
|
|
49
|
+
directory,
|
|
50
|
+
...(frontend.length === 0 ? {} : { frontendRevision: frontendRevision(frontend) }),
|
|
51
|
+
...(addressed.length === 0 ? {} : { frontendAddressed: addressed }),
|
|
52
|
+
});
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
entry: modules.entry,
|
|
55
|
+
modules: modules.modules,
|
|
56
|
+
frontend,
|
|
57
|
+
compactBundle: modules.compactBundle,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await rm(directory, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Read back the Worker bytes of a Bundle this bundler produced for the same Build. */
|
|
65
|
+
export function bundledWorker(bundle, build) {
|
|
66
|
+
const { id, version } = bundle.manifest.bundler;
|
|
67
|
+
if (bundle.build !== build ||
|
|
68
|
+
id !== CLOUDFLARE_WORKER_BUNDLER.id ||
|
|
69
|
+
version !== CLOUDFLARE_WORKER_BUNDLER.version ||
|
|
70
|
+
bundle.entrypoint !== RELEASE_ENTRY) {
|
|
71
|
+
throw new TypeError('Cloudflare preparation requires the Bundle of its Worker bundler.');
|
|
72
|
+
}
|
|
73
|
+
let entry;
|
|
74
|
+
const modules = [];
|
|
75
|
+
const frontend = [];
|
|
76
|
+
for (const file of bundle.files) {
|
|
77
|
+
if (file.path === RELEASE_ENTRY)
|
|
78
|
+
entry = file.bytes();
|
|
79
|
+
else if (file.path.startsWith(MODULE_DIRECTORY) && /\.(?:mjs|wasm)$/u.test(file.path)) {
|
|
80
|
+
modules.push(Object.freeze({
|
|
81
|
+
path: file.path,
|
|
82
|
+
kind: file.path.endsWith('.wasm') ? 'wasm' : 'esm',
|
|
83
|
+
content: file.bytes(),
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
else if (file.path.startsWith('assets/')) {
|
|
87
|
+
const content = file.bytes();
|
|
88
|
+
frontend.push(Object.freeze({ path: file.path.slice('assets/'.length), bytes: () => content.slice() }));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new TypeError(`Cloudflare Worker Bundle file ${file.path} is not a Worker file.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (entry === undefined || !modules.some((module) => module.path === RELEASE_SERVICE)) {
|
|
95
|
+
throw new TypeError('Cloudflare Worker Bundle lacks its execution modules.');
|
|
96
|
+
}
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
entry,
|
|
99
|
+
...(bundle.compactBundle === undefined ? {} : { compactBundle: bundle.compactBundle }),
|
|
100
|
+
modules: Object.freeze(modules),
|
|
101
|
+
frontend: Object.freeze(frontend),
|
|
102
|
+
});
|
|
103
|
+
}
|
package/dist/build/closure.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Prove emitted Worker reachability excludes authoring tooling, compilation, and broad Core Schema
|
|
3
|
+
* owners.
|
|
4
|
+
*/
|
|
2
5
|
export declare function assertRuntimeClosure(metafilePath: string): Promise<void>;
|
package/dist/build/closure.js
CHANGED
|
@@ -8,8 +8,14 @@ const FORBIDDEN_RUNTIME_INPUTS = [
|
|
|
8
8
|
'/core/domain/',
|
|
9
9
|
'/kernel-core/schema/index.',
|
|
10
10
|
'/core/schema/index.',
|
|
11
|
+
// SDK authoring tooling (CLI, lint, packaging) and the scaffold generator.
|
|
12
|
+
'/@astrale-os/sdk/dist/tooling/',
|
|
13
|
+
'/create-astrale-domain/',
|
|
11
14
|
];
|
|
12
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Prove emitted Worker reachability excludes authoring tooling, compilation, and broad Core Schema
|
|
17
|
+
* owners.
|
|
18
|
+
*/
|
|
13
19
|
export async function assertRuntimeClosure(metafilePath) {
|
|
14
20
|
const metafile = await readWranglerMetafile(metafilePath);
|
|
15
21
|
const forbidden = Object.keys(metafile.inputs).filter((input) => {
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
readonly runtimeSpecifier: string;
|
|
5
|
-
readonly material: BuildMaterial;
|
|
6
|
-
readonly providerAssignedWorker?: string;
|
|
7
|
-
readonly router?: {
|
|
8
|
-
readonly binding: string;
|
|
9
|
-
readonly hostSuffix: string;
|
|
10
|
-
readonly minLabels: number;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export declare function generateExecutionEntry(options: ExecutionCodegenOptions): string;
|
|
1
|
+
export { generateExecutionEntry } from '../worker/codegen/entry.js';
|
|
2
|
+
export { generateExecutionService } from '../worker/codegen/service.js';
|
|
3
|
+
export type { ExecutionCodegenOptions } from '../worker/codegen/service.js';
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
const routerPredicate = router === undefined
|
|
4
|
-
? ''
|
|
5
|
-
: `
|
|
6
|
-
function isInstanceHost(host: string): boolean {
|
|
7
|
-
return host.endsWith(${JSON.stringify(router.hostSuffix)}) && host.split('.').length >= ${router.minLabels}
|
|
8
|
-
}
|
|
9
|
-
`;
|
|
10
|
-
const routeSubrequest = router === undefined
|
|
11
|
-
? ''
|
|
12
|
-
: `
|
|
13
|
-
routeSubrequest: (url, env) => {
|
|
14
|
-
const labels = url.hostname.split('.')
|
|
15
|
-
if (env.DISPATCHER && labels[1] === 'svc') return env.DISPATCHER.get(labels[0]!)
|
|
16
|
-
if (env.${router.binding} && isInstanceHost(url.hostname)) return env.${router.binding}
|
|
17
|
-
return null
|
|
18
|
-
},`;
|
|
19
|
-
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
20
|
-
// Domain origin: ${options.origin}
|
|
21
|
-
import type { BuildMaterial } from '@astrale-os/sdk/deployment/build'
|
|
22
|
-
import type { CloudflareAdapterBindings } from '@astrale-os/adapter-cloudflare/worker'
|
|
23
|
-
|
|
24
|
-
import { cloudflareWorkerEntry } from '@astrale-os/adapter-cloudflare/worker'
|
|
25
|
-
import runtime from ${JSON.stringify(options.runtimeSpecifier)}
|
|
26
|
-
import { decodeSigningIdentity, runtimeBindings } from '@astrale-os/adapter-cloudflare/worker'
|
|
27
|
-
|
|
28
|
-
type WorkerEnv = CloudflareEnv & CloudflareAdapterBindings & {
|
|
29
|
-
readonly ASTRALE_SIGNING_IDENTITY: string
|
|
30
|
-
}
|
|
31
|
-
type RuntimeEnv = Omit<WorkerEnv, 'ASTRALE_SIGNING_IDENTITY'>
|
|
32
|
-
const MATERIAL = ${JSON.stringify(options.material)} as const satisfies BuildMaterial
|
|
33
|
-
${routerPredicate}
|
|
34
|
-
export default cloudflareWorkerEntry<WorkerEnv, RuntimeEnv>()({
|
|
35
|
-
runtime,
|
|
36
|
-
material: MATERIAL,
|
|
37
|
-
privateKey: (env) => decodeSigningIdentity(env.ASTRALE_SIGNING_IDENTITY),
|
|
38
|
-
resolveEnvironment: runtimeBindings,
|
|
39
|
-
resolveUrl: (env, requestOrigin) => env.WORKER_URL ?? env.IDENTITY_ISS ?? requestOrigin,
|
|
40
|
-
${options.providerAssignedWorker === undefined ? '' : `providerAssignedWorker: ${JSON.stringify(options.providerAssignedWorker)},`}
|
|
41
|
-
selfBinding: (env) => env.SELF,${routeSubrequest}
|
|
42
|
-
})
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
1
|
+
export { generateExecutionEntry } from '../worker/codegen/entry.js';
|
|
2
|
+
export { generateExecutionService } from '../worker/codegen/service.js';
|
|
@@ -20,24 +20,25 @@ export interface WranglerCodegenOptions {
|
|
|
20
20
|
/** Exact materialized local frontend; absence means no ASSETS binding. */
|
|
21
21
|
frontend?: {
|
|
22
22
|
readonly directory: string;
|
|
23
|
-
readonly routes: readonly string[];
|
|
24
|
-
readonly dev: boolean;
|
|
25
23
|
};
|
|
26
24
|
/** Plain (non-secret) vars to bake in. */
|
|
27
25
|
vars?: Record<string, string>;
|
|
28
26
|
/** Secret binding names required by generated Worker code. */
|
|
29
27
|
secretBindings?: readonly string[];
|
|
28
|
+
/** Modules retained outside the startup entry and loaded on demand. */
|
|
29
|
+
modules?: {
|
|
30
|
+
readonly baseDir: string;
|
|
31
|
+
readonly rules: readonly {
|
|
32
|
+
readonly type: 'ESModule' | 'CompiledWasm' | 'Text' | 'Data';
|
|
33
|
+
readonly globs: readonly string[];
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
30
36
|
/** Add the SELF service binding (autobinding). */
|
|
31
37
|
selfBinding: boolean;
|
|
32
|
-
/** Bind the stable gateway to its private revision namespace. */
|
|
33
|
-
releases?: {
|
|
34
|
-
readonly binding: string;
|
|
35
|
-
readonly namespace: string;
|
|
36
|
-
};
|
|
37
38
|
/**
|
|
38
39
|
* Add a service binding to a router Worker for instance-host subrequest
|
|
39
|
-
* routing (see `CloudflareParams.router`). Pairs with the
|
|
40
|
-
*
|
|
40
|
+
* routing (see `CloudflareParams.router`). Pairs with the router rule bound
|
|
41
|
+
* in `ASTRALE_SETTINGS`.
|
|
41
42
|
*/
|
|
42
43
|
router?: {
|
|
43
44
|
binding: string;
|
|
@@ -48,8 +49,25 @@ export interface WranglerCodegenOptions {
|
|
|
48
49
|
* hatch for extra bindings (KV, R2, D1, queues, service bindings, extra
|
|
49
50
|
* `compatibility_flags`, cron `triggers`, …). Arrays concat; new keys are
|
|
50
51
|
* added as-is. The adapter-owned keys `name`, `main`, `assets`, `routes` are
|
|
51
|
-
* rejected (throws) — use `workerName` / `route` instead
|
|
52
|
+
* rejected (throws) — use `workerName` / `route` instead — and so are the keys
|
|
53
|
+
* and compatibility flags Wrangler's bundler reads.
|
|
52
54
|
*/
|
|
53
55
|
wrangler?: Record<string, unknown>;
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The Workers runtime every generated Worker runs on, wherever it is deployed: its compatibility
|
|
59
|
+
* date, kept on the runtime baseline qualified with Wrangler 4.123.0, and its compatibility flags.
|
|
60
|
+
* Domain execution calls its Kernel through the invocation's public issuer, so Cloudflare must route
|
|
61
|
+
* same-zone callbacks through the public front door instead of bypassing Worker routes
|
|
62
|
+
* (`global_fetch_strictly_public`). An immutable deployment freezes it into its configuration.
|
|
63
|
+
*/
|
|
64
|
+
export declare const GENERATED_WORKER_RUNTIME: Readonly<{
|
|
65
|
+
compatibilityDate: "2026-08-11";
|
|
66
|
+
compatibilityFlags: readonly string[];
|
|
67
|
+
}>;
|
|
55
68
|
export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
|
|
69
|
+
/**
|
|
70
|
+
* Whether a compatibility flag shapes the bundle (Wrangler's bundler reads it), so that no
|
|
71
|
+
* Environment may add it: bundling takes no Environment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isBundlingCompatibilityFlag(flag: string): boolean;
|
|
@@ -12,17 +12,27 @@
|
|
|
12
12
|
* (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
|
|
13
13
|
*/
|
|
14
14
|
import { deepMergeConfig } from './merge.js';
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The Workers runtime every generated Worker runs on, wherever it is deployed: its compatibility
|
|
17
|
+
* date, kept on the runtime baseline qualified with Wrangler 4.123.0, and its compatibility flags.
|
|
18
|
+
* Domain execution calls its Kernel through the invocation's public issuer, so Cloudflare must route
|
|
19
|
+
* same-zone callbacks through the public front door instead of bypassing Worker routes
|
|
20
|
+
* (`global_fetch_strictly_public`). An immutable deployment freezes it into its configuration.
|
|
21
|
+
*/
|
|
22
|
+
export const GENERATED_WORKER_RUNTIME = Object.freeze({
|
|
23
|
+
compatibilityDate: '2026-08-11',
|
|
24
|
+
compatibilityFlags: Object.freeze(['nodejs_compat', 'global_fetch_strictly_public']),
|
|
25
|
+
});
|
|
17
26
|
export function generateWranglerConfig(opts) {
|
|
18
27
|
const config = {
|
|
19
28
|
name: opts.workerName,
|
|
20
29
|
main: opts.main ?? './worker.gen.ts',
|
|
21
|
-
compatibility_date:
|
|
22
|
-
compatibility_flags: [
|
|
23
|
-
workers_dev:
|
|
30
|
+
compatibility_date: GENERATED_WORKER_RUNTIME.compatibilityDate,
|
|
31
|
+
compatibility_flags: [...GENERATED_WORKER_RUNTIME.compatibilityFlags],
|
|
32
|
+
workers_dev: opts.route === undefined,
|
|
24
33
|
version_metadata: { binding: 'ASTRALE_VERSION_METADATA' },
|
|
25
34
|
observability: { enabled: true },
|
|
35
|
+
minify: true,
|
|
26
36
|
};
|
|
27
37
|
if (opts.route) {
|
|
28
38
|
config.routes = [{ pattern: opts.route, custom_domain: true }];
|
|
@@ -31,19 +41,10 @@ export function generateWranglerConfig(opts) {
|
|
|
31
41
|
config.assets = {
|
|
32
42
|
directory: opts.frontend.directory,
|
|
33
43
|
binding: 'ASSETS',
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'/releases/*',
|
|
39
|
-
'/install',
|
|
40
|
-
'/install/*',
|
|
41
|
-
'/health',
|
|
42
|
-
'/health/*',
|
|
43
|
-
'/.well-known',
|
|
44
|
-
'/.well-known/*',
|
|
45
|
-
...opts.frontend.routes,
|
|
46
|
-
],
|
|
44
|
+
html_handling: 'none',
|
|
45
|
+
// Match the portable Worker artifact: frontend routing and sandbox-safe asset
|
|
46
|
+
// response headers are owned by the Worker for both deployment adapters.
|
|
47
|
+
run_worker_first: true,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
const services = [];
|
|
@@ -60,8 +61,14 @@ export function generateWranglerConfig(opts) {
|
|
|
60
61
|
if (opts.secretBindings && opts.secretBindings.length > 0) {
|
|
61
62
|
config.secrets = { required: [...opts.secretBindings] };
|
|
62
63
|
}
|
|
63
|
-
if (opts.
|
|
64
|
-
config.
|
|
64
|
+
if (opts.modules !== undefined) {
|
|
65
|
+
config.find_additional_modules = true;
|
|
66
|
+
config.base_dir = opts.modules.baseDir;
|
|
67
|
+
config.rules = opts.modules.rules.map((rule) => ({
|
|
68
|
+
type: rule.type,
|
|
69
|
+
globs: [...rule.globs],
|
|
70
|
+
fallthrough: true,
|
|
71
|
+
}));
|
|
65
72
|
}
|
|
66
73
|
const merged = opts.wrangler ? mergeUserConfig(config, opts.wrangler) : config;
|
|
67
74
|
return JSON.stringify(merged, null, 2) + '\n';
|
|
@@ -73,12 +80,43 @@ const ADAPTER_OWNED_KEYS = [
|
|
|
73
80
|
'assets',
|
|
74
81
|
'routes',
|
|
75
82
|
'compatibility_date',
|
|
83
|
+
'workers_dev',
|
|
76
84
|
'version_metadata',
|
|
77
85
|
'secrets',
|
|
86
|
+
'find_additional_modules',
|
|
87
|
+
'base_dir',
|
|
88
|
+
];
|
|
89
|
+
/**
|
|
90
|
+
* Keys Wrangler's bundler reads. Bundling sees the adapter base configuration only, so that every
|
|
91
|
+
* Environment of one source bundles the same bytes; an Environment's overlay never sets these.
|
|
92
|
+
*/
|
|
93
|
+
const BUNDLING_KEYS = [
|
|
94
|
+
'alias',
|
|
95
|
+
'build',
|
|
96
|
+
'define',
|
|
97
|
+
'jsx_factory',
|
|
98
|
+
'jsx_fragment',
|
|
99
|
+
'keep_names',
|
|
100
|
+
'minify',
|
|
101
|
+
'no_bundle',
|
|
102
|
+
'node_compat',
|
|
103
|
+
'preserve_file_names',
|
|
104
|
+
'rules',
|
|
105
|
+
'tsconfig',
|
|
106
|
+
'upload_source_maps',
|
|
78
107
|
];
|
|
108
|
+
/** Compatibility flags Wrangler's bundler reads: Node.js polyfills, `navigator`, fetch typing, Python. */
|
|
109
|
+
const BUNDLING_FLAG = /nodejs|navigator|fetch_iterable_type_support|python_workers/u;
|
|
110
|
+
/**
|
|
111
|
+
* Whether a compatibility flag shapes the bundle (Wrangler's bundler reads it), so that no
|
|
112
|
+
* Environment may add it: bundling takes no Environment.
|
|
113
|
+
*/
|
|
114
|
+
export function isBundlingCompatibilityFlag(flag) {
|
|
115
|
+
return BUNDLING_FLAG.test(flag);
|
|
116
|
+
}
|
|
79
117
|
/**
|
|
80
118
|
* Deep-merge the dev's raw wrangler overlay over the generated config, after
|
|
81
|
-
* refusing any attempt to override an adapter-owned key. Throwing (rather than
|
|
119
|
+
* refusing any attempt to override an adapter-owned key or a bundler input. Throwing (rather than
|
|
82
120
|
* silently dropping) keeps a stray `main` from breaking the Worker unnoticed.
|
|
83
121
|
*/
|
|
84
122
|
function mergeUserConfig(base, user) {
|
|
@@ -88,5 +126,17 @@ function mergeUserConfig(base, user) {
|
|
|
88
126
|
'Use `workerName` for the worker name and `route` for routing; ' +
|
|
89
127
|
'`main` and `assets` are generated by the adapter.');
|
|
90
128
|
}
|
|
129
|
+
const baseFlags = Array.isArray(base.compatibility_flags) ? base.compatibility_flags : [];
|
|
130
|
+
const bundling = [
|
|
131
|
+
...BUNDLING_KEYS.filter((k) => k in user),
|
|
132
|
+
...(Array.isArray(user.compatibility_flags) ? user.compatibility_flags : [])
|
|
133
|
+
.filter((flag) => typeof flag === 'string' && BUNDLING_FLAG.test(flag))
|
|
134
|
+
.filter((flag) => !baseFlags.includes(flag))
|
|
135
|
+
.map((flag) => `compatibility_flags ${String(flag)}`),
|
|
136
|
+
];
|
|
137
|
+
if (bundling.length > 0) {
|
|
138
|
+
throw new Error(`wrangler: ${bundling.join(', ')} shape(s) the bundle, which takes no Environment. ` +
|
|
139
|
+
'Bundling uses the adapter base configuration only.');
|
|
140
|
+
}
|
|
91
141
|
return deepMergeConfig(base, user);
|
|
92
142
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MAXIMUM_INVOCATION_TIMEOUT_MS } from '../../worker/settings.js';
|
|
2
|
+
export function workerInvocationTimeout(value) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > MAXIMUM_INVOCATION_TIMEOUT_MS) {
|
|
6
|
+
throw new TypeError('Cloudflare invocationTimeoutMs must be a positive integer within the platform timer range.');
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MAXIMUM_REQUEST_BYTES } from '../../worker/settings.js';
|
|
2
|
+
export function workerRequestLimit(value) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > MAXIMUM_REQUEST_BYTES) {
|
|
6
|
+
throw new TypeError('Cloudflare maximumRequestBytes must be a positive integer at most 16 MiB.');
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CloudflareParams } from '../../params.js';
|
|
2
|
+
export declare function resolveRouter(input: CloudflareParams['router']): {
|
|
3
|
+
readonly binding: string;
|
|
4
|
+
readonly service: string;
|
|
5
|
+
readonly hostSuffix: string;
|
|
6
|
+
readonly minLabels: number;
|
|
7
|
+
} | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function resolveRouter(input) {
|
|
2
|
+
if (input === false || input === undefined)
|
|
3
|
+
return undefined;
|
|
4
|
+
if (input === null ||
|
|
5
|
+
typeof input !== 'object' ||
|
|
6
|
+
Array.isArray(input) ||
|
|
7
|
+
Reflect.ownKeys(input).some((key) => !['service', 'hostSuffix', 'minLabels'].includes(String(key)))) {
|
|
8
|
+
throw new TypeError('Cloudflare router parameters contain unknown fields.');
|
|
9
|
+
}
|
|
10
|
+
const value = input;
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
binding: 'ROUTER',
|
|
13
|
+
service: value.service ?? 'admin-router',
|
|
14
|
+
hostSuffix: value.hostSuffix ?? '.astrale.ai',
|
|
15
|
+
minLabels: value.minLabels ?? 4,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CloudflareParams } from '../../params.js';
|
|
2
|
+
import type { WorkerSettings } from '../../worker/settings.js';
|
|
3
|
+
/** Whether a binding name is one the adapter owns, so no author var or secret may take it. */
|
|
4
|
+
export declare function isAdapterVar(name: string): boolean;
|
|
5
|
+
/** Resolve one Environment's execution settings, defaults included, as its deployment binds them. */
|
|
6
|
+
export declare function workerSettings(parameters: Pick<CloudflareParams, 'durable' | 'maximumRequestBytes' | 'invocationTimeoutMs' | 'tokenExchange' | 'router'>): WorkerSettings;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { maximumExchangeTtl } from '@astrale-os/sdk/execution';
|
|
2
|
+
import { BUILD_DIGEST_BINDING } from '../../worker/build-digest.js';
|
|
3
|
+
import { captureDurableOptions, DEFAULT_INVOCATION_TIMEOUT_MS, DEFAULT_MAXIMUM_REQUEST_BYTES, SETTINGS_BINDING, } from '../../worker/settings.js';
|
|
4
|
+
import { workerInvocationTimeout } from './invocation-timeout.js';
|
|
5
|
+
import { workerRequestLimit } from './request-limit.js';
|
|
6
|
+
import { resolveRouter } from './router.js';
|
|
7
|
+
/**
|
|
8
|
+
* Plain bindings the adapter owns on a deployment, bound or not; no author var or secret takes
|
|
9
|
+
* these names.
|
|
10
|
+
*/
|
|
11
|
+
const ADAPTER_VARS = new Set([
|
|
12
|
+
'WORKER_URL',
|
|
13
|
+
BUILD_DIGEST_BINDING,
|
|
14
|
+
SETTINGS_BINDING,
|
|
15
|
+
]);
|
|
16
|
+
/** Whether a binding name is one the adapter owns, so no author var or secret may take it. */
|
|
17
|
+
export function isAdapterVar(name) {
|
|
18
|
+
return ADAPTER_VARS.has(name);
|
|
19
|
+
}
|
|
20
|
+
/** Resolve one Environment's execution settings, defaults included, as its deployment binds them. */
|
|
21
|
+
export function workerSettings(parameters) {
|
|
22
|
+
const router = resolveRouter(parameters.router);
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
...(parameters.durable === undefined
|
|
25
|
+
? {}
|
|
26
|
+
: { durableOptions: captureDurableOptions(parameters.durable) }),
|
|
27
|
+
maximumRequestBytes: workerRequestLimit(parameters.maximumRequestBytes) ?? DEFAULT_MAXIMUM_REQUEST_BYTES,
|
|
28
|
+
invocationTimeoutMs: workerInvocationTimeout(parameters.invocationTimeoutMs) ?? DEFAULT_INVOCATION_TIMEOUT_MS,
|
|
29
|
+
tokenExchange: parameters.tokenExchange === false
|
|
30
|
+
? false
|
|
31
|
+
: Object.freeze({ maximumLifetimeSeconds: maximumExchangeTtl(parameters.tokenExchange) }),
|
|
32
|
+
router: router === undefined
|
|
33
|
+
? false
|
|
34
|
+
: Object.freeze({
|
|
35
|
+
binding: router.binding,
|
|
36
|
+
hostSuffix: router.hostSuffix,
|
|
37
|
+
minLabels: router.minLabels,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
readonly binding: string;
|
|
6
|
-
readonly service: string;
|
|
7
|
-
readonly hostSuffix: string;
|
|
8
|
-
readonly minLabels: number;
|
|
9
|
-
} | undefined;
|
|
1
|
+
export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
|
|
2
|
+
export { workerRequestLimit } from './configuration/request-limit.js';
|
|
3
|
+
export { resolveRouter } from './configuration/router.js';
|
|
4
|
+
export { isAdapterVar, workerSettings } from './configuration/settings.js';
|
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
const routed = parameters.route === undefined ? undefined : addressing(`https://${parameters.route}`).issuer;
|
|
6
|
-
if (parameters.addressing === undefined)
|
|
7
|
-
return routed;
|
|
8
|
-
const configured = addressing(parameters.addressing).issuer;
|
|
9
|
-
if (routed !== undefined && configured !== routed) {
|
|
10
|
-
throw new TypeError('Cloudflare route and addressing identify different origins.');
|
|
11
|
-
}
|
|
12
|
-
return configured;
|
|
13
|
-
}
|
|
14
|
-
export function workerName(parameters, origin) {
|
|
15
|
-
if (parameters.workerName !== undefined) {
|
|
16
|
-
if (!WORKER_NAME.test(parameters.workerName) || parameters.workerName.length > 63) {
|
|
17
|
-
throw new TypeError('Cloudflare workerName is invalid.');
|
|
18
|
-
}
|
|
19
|
-
return parameters.workerName;
|
|
20
|
-
}
|
|
21
|
-
const readable = origin
|
|
22
|
-
.toLowerCase()
|
|
23
|
-
.replace(/[^a-z0-9]+/gu, '-')
|
|
24
|
-
.slice(0, 12)
|
|
25
|
-
.replace(/^-+|-+$/gu, '') || 'domain';
|
|
26
|
-
const hexadecimal = createHash('sha256').update(origin).digest('hex');
|
|
27
|
-
const identity = BigInt(`0x${hexadecimal}`).toString(36).padStart(50, '0');
|
|
28
|
-
return `${readable}-${identity}`;
|
|
29
|
-
}
|
|
30
|
-
export function resolveRouter(input) {
|
|
31
|
-
if (input === false)
|
|
32
|
-
return undefined;
|
|
33
|
-
const value = input ?? {};
|
|
34
|
-
return Object.freeze({
|
|
35
|
-
binding: value.binding ?? 'ROUTER',
|
|
36
|
-
service: value.service ?? 'admin-router',
|
|
37
|
-
hostSuffix: value.hostSuffix ?? '.astrale.ai',
|
|
38
|
-
minLabels: value.minLabels ?? 4,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
1
|
+
export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
|
|
2
|
+
export { workerRequestLimit } from './configuration/request-limit.js';
|
|
3
|
+
export { resolveRouter } from './configuration/router.js';
|
|
4
|
+
export { isAdapterVar, workerSettings } from './configuration/settings.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Build } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
3
|
+
/** The served frontend, and which of its files a browser may keep without revalidating. */
|
|
4
|
+
export interface FrontendOutput {
|
|
5
|
+
readonly files: readonly frontendBuild.FrontendFile[];
|
|
6
|
+
/**
|
|
7
|
+
* Served paths the bundler content-addressed, so their bytes can never change under a given name.
|
|
8
|
+
* A frontend Astrale does not build leaves this empty, which is what keeps the absence of evidence
|
|
9
|
+
* indistinguishable from evidence of mutability.
|
|
10
|
+
*/
|
|
11
|
+
readonly addressed: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function frontendFiles(input: {
|
|
14
|
+
readonly frontend: Build['frontend'];
|
|
15
|
+
readonly projectDir: string;
|
|
16
|
+
readonly output: string;
|
|
17
|
+
readonly recordSource?: (path: string) => void;
|
|
18
|
+
readonly signal: AbortSignal;
|
|
19
|
+
}): Promise<FrontendOutput>;
|