@astrale-os/adapter-cloudflare 0.5.0-beta.226 → 0.5.0-beta.227
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 +7 -0
- package/dist/build/bundler.d.ts +2 -0
- package/dist/build/bundler.js +8 -1
- package/dist/build/material.js +5 -5
- package/dist/build/worker/codegen/service.d.ts +1 -1
- package/dist/build/worker/codegen/service.js +4 -5
- package/dist/build/worker/execution.prepare.d.ts +2 -0
- package/dist/build/worker/execution.prepare.js +5 -3
- package/dist/namespace/deploy-release.js +1 -0
- package/dist/namespace/readiness.d.ts +2 -0
- package/dist/namespace/readiness.js +5 -1
- package/dist/worker/entry.d.ts +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -241,6 +241,13 @@ import { writeFile } from 'node:fs/promises'
|
|
|
241
241
|
await writeFile('src/build-material.gen.ts', generateBuildMaterialModule(build))
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
+
Standard and custom generated Workers embed one Brotli-compressed Schema Bundle. The Release
|
|
245
|
+
identifies the canonical JSON by its existing size, digest and URL. Its canonical GET still returns
|
|
246
|
+
those exact bytes. When the compressed representation is smaller, the Release response also links
|
|
247
|
+
to an immutable `.br` artifact. Both routes support their own ETag and conditional GET.
|
|
248
|
+
The loader accepts historical v1 material. The synchronous `build.schema.bundle.bytes()` accessor
|
|
249
|
+
and the explicit `material(build)` export both produce canonical bytes.
|
|
250
|
+
|
|
244
251
|
The generated TypeScript module exports `loadBuildMaterial()`. Call it from the
|
|
245
252
|
`load` callback of `generatedCloudflareWorkerEntry` alongside the Domain's Runtime.
|
|
246
253
|
That callback loads deterministic local modules once per entrypoint. Concurrent execution and
|
package/dist/build/bundler.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Bundle, BundleContext, Bundler } from '@astrale-os/sdk/deployment/adapter';
|
|
2
2
|
import type { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
3
|
+
import type { ArtifactRef } from '@astrale-os/sdk/release';
|
|
3
4
|
import type { ReleaseModule } from './worker/execution.prepare.js';
|
|
4
5
|
/**
|
|
5
6
|
* Environment-free bytes of one generated Worker: its entry, the modules it loads (the execution
|
|
6
7
|
* Service, the deferred workflow engine and their WASM) and its frontend.
|
|
7
8
|
*/
|
|
8
9
|
export interface WorkerBytes {
|
|
10
|
+
readonly compactBundle?: ArtifactRef;
|
|
9
11
|
readonly entry: Uint8Array;
|
|
10
12
|
readonly modules: readonly ReleaseModule[];
|
|
11
13
|
readonly frontend: readonly frontendBuild.FrontendFile[];
|
package/dist/build/bundler.js
CHANGED
|
@@ -17,6 +17,7 @@ export const cloudflareWorkerBundler = Object.freeze({
|
|
|
17
17
|
const worker = await bundleWorker(context);
|
|
18
18
|
return Object.freeze({
|
|
19
19
|
entrypoint: RELEASE_ENTRY,
|
|
20
|
+
...(worker.compactBundle === undefined ? {} : { compactBundle: worker.compactBundle }),
|
|
20
21
|
files: Object.freeze([
|
|
21
22
|
{ path: RELEASE_ENTRY, content: worker.entry },
|
|
22
23
|
...worker.modules.map(({ path, content }) => ({ path, content })),
|
|
@@ -49,7 +50,12 @@ export async function bundleWorker(context) {
|
|
|
49
50
|
...(frontend.length === 0 ? {} : { frontendRevision: frontendRevision(frontend) }),
|
|
50
51
|
...(addressed.length === 0 ? {} : { frontendAddressed: addressed }),
|
|
51
52
|
});
|
|
52
|
-
return Object.freeze({
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
entry: modules.entry,
|
|
55
|
+
modules: modules.modules,
|
|
56
|
+
frontend,
|
|
57
|
+
compactBundle: modules.compactBundle,
|
|
58
|
+
});
|
|
53
59
|
}
|
|
54
60
|
finally {
|
|
55
61
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -90,6 +96,7 @@ export function bundledWorker(bundle, build) {
|
|
|
90
96
|
}
|
|
91
97
|
return Object.freeze({
|
|
92
98
|
entry,
|
|
99
|
+
...(bundle.compactBundle === undefined ? {} : { compactBundle: bundle.compactBundle }),
|
|
93
100
|
modules: Object.freeze(modules),
|
|
94
101
|
frontend: Object.freeze(frontend),
|
|
95
102
|
});
|
package/dist/build/material.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generatedCompactMaterial } from '@astrale-os/sdk/deployment/build/compact';
|
|
2
2
|
import { sharedLiteral, verifySharedLiteral } from './worker/codegen/literal.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generate a TypeScript module exporting `loadBuildMaterial()` for a custom Worker entrypoint.
|
|
@@ -9,17 +9,17 @@ import { sharedLiteral, verifySharedLiteral } from './worker/codegen/literal.js'
|
|
|
9
9
|
* compression dependency is needed by the generated module at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export function generateBuildMaterialModule(build) {
|
|
12
|
-
const generated =
|
|
12
|
+
const generated = generatedCompactMaterial(build);
|
|
13
13
|
const literal = sharedLiteral(generated);
|
|
14
14
|
verifySharedLiteral(literal, generated);
|
|
15
15
|
// An empty shared array otherwise has an implicit any[] type in strict TypeScript consumers.
|
|
16
16
|
const declarations = literal.declarations.map((line) => ` ${line.replace(/ = \[\]$/, ': readonly [] = []')}`);
|
|
17
17
|
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
18
|
-
import type {
|
|
18
|
+
import type { GeneratedCompactBuildMaterial } from '@astrale-os/sdk/deployment/build'
|
|
19
19
|
|
|
20
|
-
export function loadBuildMaterial():
|
|
20
|
+
export function loadBuildMaterial(): GeneratedCompactBuildMaterial {
|
|
21
21
|
${declarations.join('\n')}
|
|
22
|
-
return ${literal.expression} as unknown as
|
|
22
|
+
return ${literal.expression} as unknown as GeneratedCompactBuildMaterial
|
|
23
23
|
}
|
|
24
24
|
`;
|
|
25
25
|
}
|
|
@@ -11,4 +11,4 @@ export interface ExecutionCodegenOptions {
|
|
|
11
11
|
readonly durable?: boolean;
|
|
12
12
|
readonly restateSpecifier?: string;
|
|
13
13
|
}
|
|
14
|
-
export declare function generateExecutionService(options: ExecutionCodegenOptions): string;
|
|
14
|
+
export declare function generateExecutionService(options: ExecutionCodegenOptions, generated?: import("@astrale-os/sdk/deployment/build").GeneratedCompactBuildMaterial): string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generatedCompactMaterial } from '@astrale-os/sdk/deployment/build/compact';
|
|
2
2
|
import { sharedLiteral, verifySharedLiteral } from './literal.js';
|
|
3
|
-
export function generateExecutionService(options) {
|
|
3
|
+
export function generateExecutionService(options, generated = generatedCompactMaterial(options.build)) {
|
|
4
4
|
const workerSpecifier = options.workerSpecifier ?? '@astrale-os/adapter-cloudflare/worker';
|
|
5
|
-
const generated = generatedMaterial(options.build);
|
|
6
5
|
// JSON has no references, so a flat literal repeats every repeated subtree. A compiled Domain
|
|
7
6
|
// is dominated by pattern automata, of which a few expressions account for dozens of identical
|
|
8
7
|
// copies, so sharing them cuts what the isolate allocates and seals by an order of magnitude.
|
|
@@ -23,7 +22,7 @@ const RESTATE_SPECIFIER = ${JSON.stringify(options.restateSpecifier ?? './restat
|
|
|
23
22
|
// checkout characters into esbuild's minifier histogram, making identical Services differ.
|
|
24
23
|
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
25
24
|
// Domain origin: ${options.origin}
|
|
26
|
-
import type { BuildMaterial,
|
|
25
|
+
import type { BuildMaterial, GeneratedCompactBuildMaterial } from '@astrale-os/sdk/deployment/build'
|
|
27
26
|
|
|
28
27
|
import { generatedCloudflareWorkerEntry, type CloudflareAdapterBindings } from ${JSON.stringify(workerSpecifier)}
|
|
29
28
|
import { decodeSigningIdentity, deploymentSettings, runtimeBindings } from ${JSON.stringify(workerSpecifier)}
|
|
@@ -38,7 +37,7 @@ export default generatedCloudflareWorkerEntry<WorkerEnv, RuntimeEnv>()({
|
|
|
38
37
|
${frontend}${options.frontendRevision === undefined ? '' : ` frontendRevision: ${JSON.stringify(options.frontendRevision)},\n`}${options.frontendAddressed === undefined ? '' : ` frontendAddressed: ${JSON.stringify(options.frontendAddressed)},\n`} load: async () => {
|
|
39
38
|
${materialDeclarations} return {
|
|
40
39
|
runtime: (await import(${JSON.stringify(options.runtimeSpecifier)})).default,
|
|
41
|
-
material: ${material.expression} as unknown as
|
|
40
|
+
material: ${material.expression} as unknown as GeneratedCompactBuildMaterial,
|
|
42
41
|
}
|
|
43
42
|
},
|
|
44
43
|
privateKey: (env) => decodeSigningIdentity(env.ASTRALE_SIGNING_IDENTITY),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BundleContext } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { ArtifactRef } from '@astrale-os/sdk/release';
|
|
2
3
|
export declare const RELEASE_ENTRY = "bundle/index.mjs";
|
|
3
4
|
export declare const RELEASE_SERVICE = "bundle/service.mjs";
|
|
4
5
|
export declare const RELEASE_RESTATE = "bundle/restate.mjs";
|
|
@@ -16,5 +17,6 @@ export declare function prepareExecution(input: {
|
|
|
16
17
|
}): Promise<{
|
|
17
18
|
readonly entry: Uint8Array;
|
|
18
19
|
readonly modules: readonly ReleaseModule[];
|
|
20
|
+
readonly compactBundle: ArtifactRef;
|
|
19
21
|
}>;
|
|
20
22
|
export declare function declaresDurable(build: BundleContext['build']): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generatedCompactMaterial } from '@astrale-os/sdk/deployment/build/compact';
|
|
2
2
|
import { DURABLE_ENGINE_EXPORTS } from '@astrale-os/sdk/execution';
|
|
3
3
|
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
@@ -22,6 +22,7 @@ export async function prepareExecution(input) {
|
|
|
22
22
|
const runtimePath = resolve(input.context.projectDir, input.context.runtime.reference.path);
|
|
23
23
|
const runtimeSpecifier = moduleSpecifier(relative(input.directory, runtimePath));
|
|
24
24
|
const workerSpecifier = workerModuleSpecifier();
|
|
25
|
+
const generated = generatedCompactMaterial(input.context.build);
|
|
25
26
|
const serviceSource = generateExecutionService({
|
|
26
27
|
origin: input.context.build.schema.compiled.root.origin,
|
|
27
28
|
runtimeSpecifier,
|
|
@@ -34,7 +35,7 @@ export async function prepareExecution(input) {
|
|
|
34
35
|
...(input.frontendAddressed === undefined
|
|
35
36
|
? {}
|
|
36
37
|
: { frontendAddressed: input.frontendAddressed }),
|
|
37
|
-
});
|
|
38
|
+
}, generated);
|
|
38
39
|
const modules = [];
|
|
39
40
|
const bundle = async (name, path, source, admit) => {
|
|
40
41
|
const sourcePath = join(input.directory, `${name}.gen.ts`);
|
|
@@ -80,7 +81,7 @@ export async function prepareExecution(input) {
|
|
|
80
81
|
`export { ${DURABLE_ENGINE_EXPORTS.join(', ')} } from ${JSON.stringify(restateModuleSpecifier())}\nexport default {}\n`, admitDurableEngineBundle);
|
|
81
82
|
}
|
|
82
83
|
const sourcePath = join(input.directory, 'worker.gen.ts');
|
|
83
|
-
const frontend =
|
|
84
|
+
const frontend = input.context.build.frontend;
|
|
84
85
|
await writeFile(sourcePath, generateExecutionEntry('./service.mjs', {
|
|
85
86
|
frontSpecifier: frontModuleSpecifier(),
|
|
86
87
|
...(frontend === undefined ? {} : { frontend }),
|
|
@@ -112,6 +113,7 @@ export async function prepareExecution(input) {
|
|
|
112
113
|
return Object.freeze({
|
|
113
114
|
entry: new Uint8Array(await readFile(emitted.bundlePath)),
|
|
114
115
|
modules: Object.freeze(modules),
|
|
116
|
+
compactBundle: generated.material.schema.bundle.stored.ref,
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
119
|
function moduleSpecifier(input) {
|
|
@@ -143,6 +143,7 @@ class NamespaceDeployment {
|
|
|
143
143
|
try {
|
|
144
144
|
await waitForNamespaceReadiness({
|
|
145
145
|
release: this.context.release,
|
|
146
|
+
bundle: this.context.bundle,
|
|
146
147
|
version: deployed.version,
|
|
147
148
|
timeoutMs: deployed.activated ? ACTIVATION_READINESS_MS : ROTATION_READINESS_MS,
|
|
148
149
|
signal: this.context.signal,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Bundle } from '@astrale-os/sdk/deployment/adapter';
|
|
1
2
|
import type { Release } from '@astrale-os/sdk/deployment/release';
|
|
2
3
|
/**
|
|
3
4
|
* How long a deployment this deploy activated may take to serve: the dispatcher reads the label's
|
|
@@ -19,6 +20,7 @@ export declare const ROTATION_READINESS_MS = 30000;
|
|
|
19
20
|
export declare function waitForNamespaceReadiness(input: {
|
|
20
21
|
/** The sealed release the deployment must serve at its URL. */
|
|
21
22
|
readonly release: Release;
|
|
23
|
+
readonly bundle?: Bundle;
|
|
22
24
|
/** The provider version that must answer, in the UUID form the Worker reports. */
|
|
23
25
|
readonly version: string;
|
|
24
26
|
readonly timeoutMs: number;
|
|
@@ -24,7 +24,11 @@ export async function waitForNamespaceReadiness(input) {
|
|
|
24
24
|
fetcher: publicFetcher(input.fetch),
|
|
25
25
|
timeoutMs: input.timeoutMs,
|
|
26
26
|
signal: input.signal,
|
|
27
|
-
check: (fetch, signal) => verifyReadiness(input.release, {
|
|
27
|
+
check: (fetch, signal) => verifyReadiness(input.release, {
|
|
28
|
+
fetch,
|
|
29
|
+
signal,
|
|
30
|
+
...(input.bundle === undefined ? {} : { bundle: input.bundle }),
|
|
31
|
+
}).then(() => { }),
|
|
28
32
|
...(input.pause === undefined ? {} : { pause: input.pause }),
|
|
29
33
|
...(input.now === undefined ? {} : { now: input.now }),
|
|
30
34
|
});
|
package/dist/worker/entry.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { JsonWebKey } from '@astrale-os/sdk/auth';
|
|
2
|
-
import type { BuildMaterial, GeneratedBuildMaterial } from '@astrale-os/sdk/deployment/build/material';
|
|
2
|
+
import type { BuildMaterial, CompactBuildMaterial, GeneratedBuildMaterial, GeneratedCompactBuildMaterial } from '@astrale-os/sdk/deployment/build/material';
|
|
3
3
|
import type { DurableServingProvider, ExecutionContext } from '@astrale-os/sdk/execution';
|
|
4
4
|
import type { Runtime } from '@astrale-os/sdk/runtime';
|
|
5
5
|
import type { DurableWorkerOptions } from '../params.js';
|
|
6
6
|
import type { CloudflareAdapterBindings, CloudflareFrontDoorConfig, Fetcher } from './front.js';
|
|
7
7
|
import type { CloudflareWorkerSettings } from './settings.js';
|
|
8
8
|
export type { CloudflareAdapterBindings, Fetcher } from './front.js';
|
|
9
|
-
export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings extends CloudflareAdapterBindings, Environment, Material = BuildMaterial> extends CloudflareFrontDoorConfig, CloudflareWorkerSettings<Bindings> {
|
|
9
|
+
export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings extends CloudflareAdapterBindings, Environment, Material = BuildMaterial | CompactBuildMaterial> extends CloudflareFrontDoorConfig, CloudflareWorkerSettings<Bindings> {
|
|
10
10
|
/**
|
|
11
11
|
* Load the exact local Runtime and Build once per entrypoint, after the isolate has accepted a
|
|
12
12
|
* request or execution is prepared. Concurrent callers share the result, including a rejection;
|
|
@@ -32,7 +32,7 @@ export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings e
|
|
|
32
32
|
/** Resolve the engine for this durable request with the deployment's captured options. */
|
|
33
33
|
readonly durable?: (bindings: Bindings, request: Request, options?: DurableWorkerOptions) => ReturnType<DurableServingProvider>;
|
|
34
34
|
}
|
|
35
|
-
export interface CloudflareWorkerSource<RuntimeValue extends Runtime, Material = BuildMaterial> {
|
|
35
|
+
export interface CloudflareWorkerSource<RuntimeValue extends Runtime, Material = BuildMaterial | CompactBuildMaterial> {
|
|
36
36
|
readonly runtime: RuntimeValue;
|
|
37
37
|
readonly material: Material;
|
|
38
38
|
}
|
|
@@ -42,6 +42,6 @@ export interface CloudflareWorker<Bindings> {
|
|
|
42
42
|
prepare?(): Promise<void>;
|
|
43
43
|
}
|
|
44
44
|
/** Compose one installed Domain implementation at its immutable deployment URL. */
|
|
45
|
-
export declare function cloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, BuildMaterial>) => CloudflareWorker<Bindings>;
|
|
45
|
+
export declare function cloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, BuildMaterial | CompactBuildMaterial>) => CloudflareWorker<Bindings>;
|
|
46
46
|
/** Compose generated execution code whose exact Build material carries build-owner evidence. */
|
|
47
|
-
export declare function generatedCloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, GeneratedBuildMaterial>) => CloudflareWorker<Bindings>;
|
|
47
|
+
export declare function generatedCloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, GeneratedBuildMaterial | GeneratedCompactBuildMaterial>) => CloudflareWorker<Bindings>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/adapter-cloudflare",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.227",
|
|
4
4
|
"description": "Deploy an Astrale Domain through Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"registry": "https://registry.npmjs.org/"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@astrale-os/sdk": "0.6.0-beta.
|
|
64
|
+
"@astrale-os/sdk": "0.6.0-beta.72",
|
|
65
65
|
"@noble/hashes": "2.3.0",
|
|
66
66
|
"@restatedev/restate-sdk-cloudflare-workers": "1.17.0",
|
|
67
67
|
"hono": "^4.13.11",
|