@astrale-os/adapter-cloudflare 0.5.0-beta.22 → 0.5.0-beta.220
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 +246 -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 +21 -0
- package/dist/build/bundler.js +96 -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 +57 -0
- package/dist/build/worker/execution.prepare.d.ts +20 -0
- package/dist/build/worker/execution.prepare.js +129 -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 +144 -0
- package/dist/hosting/client.js +491 -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 +90 -0
- package/dist/hosting/kv.js +207 -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 +82 -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 +4 -0
- package/dist/hosting/time.js +20 -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 +386 -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 +30 -0
- package/dist/namespace/readiness.js +31 -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 +10 -0
- package/dist/wrangler/bundle.js +27 -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,30 @@
|
|
|
1
|
+
import type { Release } from '@astrale-os/sdk/deployment/release';
|
|
2
|
+
/**
|
|
3
|
+
* How long a deployment this deploy activated may take to serve: the dispatcher reads the label's
|
|
4
|
+
* new `record:<label>` from Workers KV, which propagates within about a minute.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ACTIVATION_READINESS_MS = 120000;
|
|
7
|
+
/**
|
|
8
|
+
* How long an already active deployment may take to serve the version an in-place secret write
|
|
9
|
+
* minted: Cloudflare serves it after about 4 s (OPS-2 X1).
|
|
10
|
+
*/
|
|
11
|
+
export declare const ROTATION_READINESS_MS = 30000;
|
|
12
|
+
/**
|
|
13
|
+
* Wait until the deployment serves exactly its sealed release at its public URL, through the
|
|
14
|
+
* dispatcher (so after activation), from exactly the provider version this deploy made: its
|
|
15
|
+
* `release.json` (release and build digests), its Bundle and its issuer documents, each answered
|
|
16
|
+
* with `X-Astrale-Worker-Version` equal to that version. Bounded and cancellable; HTTPS
|
|
17
|
+
* verification is never weakened.
|
|
18
|
+
*/
|
|
19
|
+
export declare function waitForNamespaceReadiness(input: {
|
|
20
|
+
/** The sealed release the deployment must serve at its URL. */
|
|
21
|
+
readonly release: Release;
|
|
22
|
+
/** The provider version that must answer, in the UUID form the Worker reports. */
|
|
23
|
+
readonly version: string;
|
|
24
|
+
readonly timeoutMs: number;
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
readonly fetch: typeof fetch;
|
|
27
|
+
/** Wait between attempts, and the clock the deadline is read on; replaceable in tests. */
|
|
28
|
+
readonly pause?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
29
|
+
readonly now?: () => number;
|
|
30
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
|
|
2
|
+
import { publicFetcher, waitForReadiness } from '../hosting/readiness.js';
|
|
3
|
+
/**
|
|
4
|
+
* How long a deployment this deploy activated may take to serve: the dispatcher reads the label's
|
|
5
|
+
* new `record:<label>` from Workers KV, which propagates within about a minute.
|
|
6
|
+
*/
|
|
7
|
+
export const ACTIVATION_READINESS_MS = 120_000;
|
|
8
|
+
/**
|
|
9
|
+
* How long an already active deployment may take to serve the version an in-place secret write
|
|
10
|
+
* minted: Cloudflare serves it after about 4 s (OPS-2 X1).
|
|
11
|
+
*/
|
|
12
|
+
export const ROTATION_READINESS_MS = 30_000;
|
|
13
|
+
/**
|
|
14
|
+
* Wait until the deployment serves exactly its sealed release at its public URL, through the
|
|
15
|
+
* dispatcher (so after activation), from exactly the provider version this deploy made: its
|
|
16
|
+
* `release.json` (release and build digests), its Bundle and its issuer documents, each answered
|
|
17
|
+
* with `X-Astrale-Worker-Version` equal to that version. Bounded and cancellable; HTTPS
|
|
18
|
+
* verification is never weakened.
|
|
19
|
+
*/
|
|
20
|
+
export async function waitForNamespaceReadiness(input) {
|
|
21
|
+
await waitForReadiness({
|
|
22
|
+
url: new URL(input.release.url).origin,
|
|
23
|
+
version: input.version,
|
|
24
|
+
fetcher: publicFetcher(input.fetch),
|
|
25
|
+
timeoutMs: input.timeoutMs,
|
|
26
|
+
signal: input.signal,
|
|
27
|
+
check: (fetch, signal) => verifyReadiness(input.release, { fetch, signal }).then(() => { }),
|
|
28
|
+
...(input.pause === undefined ? {} : { pause: input.pause }),
|
|
29
|
+
...(input.now === undefined ? {} : { now: input.now }),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DeploymentRecordV1 } from '@astrale-os/sdk/deployment/address';
|
|
2
|
+
import type { WorkerRecord } from '@astrale-os/sdk/deployment/worker';
|
|
3
|
+
/**
|
|
4
|
+
* The `DeploymentRecordV1` a label published, admitted as that label's own; anything else under a
|
|
5
|
+
* namespace label (no record, another media type, a record of another script) is refused as
|
|
6
|
+
* `record-invalid`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function publishedRecord(stored: WorkerRecord | null, label: string): DeploymentRecordV1;
|
|
9
|
+
/**
|
|
10
|
+
* Whether two records declare the same deployment: same origin, environment, release, build,
|
|
11
|
+
* Schema revision, configuration and script. Only the commit may differ: a redeploy of identical
|
|
12
|
+
* bytes and configuration from another commit is the same deployment, whose record keeps the
|
|
13
|
+
* commit it was first activated from. This is namespace mode's re-publication rule; the kit itself
|
|
14
|
+
* only ever keeps the same bytes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sameRelease(left: DeploymentRecordV1, right: DeploymentRecordV1): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A published record as a listing returns it, unadmitted: its JSON value (JSON `null` included),
|
|
19
|
+
* its text when it is not JSON, `null` when the label publishes no record.
|
|
20
|
+
*/
|
|
21
|
+
export declare function listedRecord(stored: WorkerRecord | null): unknown;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { decodeDeploymentRecord } from '@astrale-os/sdk/deployment/address';
|
|
2
|
+
import { HostingRefusal } from '../hosting/refusal.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `DeploymentRecordV1` a label published, admitted as that label's own; anything else under a
|
|
5
|
+
* namespace label (no record, another media type, a record of another script) is refused as
|
|
6
|
+
* `record-invalid`.
|
|
7
|
+
*/
|
|
8
|
+
export function publishedRecord(stored, label) {
|
|
9
|
+
let record;
|
|
10
|
+
try {
|
|
11
|
+
if (stored === null)
|
|
12
|
+
throw new TypeError('The deployment publishes no record.');
|
|
13
|
+
record = decodeDeploymentRecord(stored);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new HostingRefusal('record-invalid', `The record of ${label} is not a DeploymentRecordV1.`);
|
|
17
|
+
}
|
|
18
|
+
if (record.providerScript !== label) {
|
|
19
|
+
throw new HostingRefusal('record-invalid', `The record published under ${label} names the script ${record.providerScript}.`);
|
|
20
|
+
}
|
|
21
|
+
return record;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether two records declare the same deployment: same origin, environment, release, build,
|
|
25
|
+
* Schema revision, configuration and script. Only the commit may differ: a redeploy of identical
|
|
26
|
+
* bytes and configuration from another commit is the same deployment, whose record keeps the
|
|
27
|
+
* commit it was first activated from. This is namespace mode's re-publication rule; the kit itself
|
|
28
|
+
* only ever keeps the same bytes.
|
|
29
|
+
*/
|
|
30
|
+
export function sameRelease(left, right) {
|
|
31
|
+
return (left.origin === right.origin &&
|
|
32
|
+
left.environment === right.environment &&
|
|
33
|
+
left.releaseDigest === right.releaseDigest &&
|
|
34
|
+
left.buildDigest === right.buildDigest &&
|
|
35
|
+
left.schemaRevision === right.schemaRevision &&
|
|
36
|
+
left.configuration === right.configuration &&
|
|
37
|
+
left.providerScript === right.providerScript);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A published record as a listing returns it, unadmitted: its JSON value (JSON `null` included),
|
|
41
|
+
* its text when it is not JSON, `null` when the label publishes no record.
|
|
42
|
+
*/
|
|
43
|
+
export function listedRecord(stored) {
|
|
44
|
+
if (stored === null)
|
|
45
|
+
return null;
|
|
46
|
+
const text = new TextDecoder().decode(stored.bytes);
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(text);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/params.d.ts
CHANGED
|
@@ -1,104 +1,88 @@
|
|
|
1
|
+
import type { DurableServing, ExchangeOptions } from '@astrale-os/sdk/execution';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Three deployment shapes fall out of which fields are set:
|
|
9
|
-
* • dev (local) — `watch()` runs `wrangler dev`; URL = http://localhost:<port>
|
|
10
|
-
* • dev-remote — `deploy()` with no `route`; URL = https://<name>.<sub>.workers.dev
|
|
11
|
-
* • remote (custom) — `deploy()` with `route`; URL = https://<route>
|
|
3
|
+
* The platform dispatch namespace an Environment deploys into. Each Release
|
|
4
|
+
* becomes one immutable script named by its deployment label, answering at
|
|
5
|
+
* `https://<label>.<routingDomain>` through the platform dispatcher; nothing is ever replaced in
|
|
6
|
+
* place. Only the platform deploys there (Shell, Services and the other platform Domains), so its
|
|
7
|
+
* lines are readable.
|
|
12
8
|
*/
|
|
9
|
+
export interface CloudflareNamespace {
|
|
10
|
+
/** The dispatch namespace, e.g. `'astrale-platform'`. Its routing KV is found from this name. */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** The DNS name the platform dispatcher answers under, e.g. `'platform.astrale.ai'`. */
|
|
13
|
+
readonly routingDomain: string;
|
|
14
|
+
/**
|
|
15
|
+
* The Cloudflare account that holds the namespace. Default: `CLOUDFLARE_ACCOUNT_ID`. The API
|
|
16
|
+
* token is always read from `CLOUDFLARE_API_TOKEN`, never from the configuration.
|
|
17
|
+
*/
|
|
18
|
+
readonly account?: string;
|
|
19
|
+
}
|
|
20
|
+
/** One immutable-deployment Environment in a Cloudflare dispatch namespace. */
|
|
13
21
|
export interface CloudflareParams {
|
|
22
|
+
readonly namespace: CloudflareNamespace;
|
|
23
|
+
/** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
|
|
24
|
+
readonly secrets?: string;
|
|
25
|
+
/** Extra plain (non-secret) vars to inject as Worker vars. */
|
|
26
|
+
readonly vars?: Record<string, string>;
|
|
14
27
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
28
|
+
* Maximum encoded invocation request bytes retained by the Worker Server.
|
|
29
|
+
* Defaults to 1 MiB and is capped at 16 MiB. Increase only from measured
|
|
30
|
+
* application traffic; Release and Bundle delivery have separate limits. A streamed
|
|
31
|
+
* binary request is not retained: it is capped by the largest `maximumBytes` among
|
|
32
|
+
* the Domain's binary Functions instead.
|
|
18
33
|
*/
|
|
19
|
-
readonly
|
|
34
|
+
readonly maximumRequestBytes?: number;
|
|
20
35
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
36
|
+
* Maximum wall-clock lifetime of one invocation, including Workflow steps and
|
|
37
|
+
* returned streams. Defaults to 30 seconds. Increase this for intentionally
|
|
38
|
+
* long provider orchestration while retaining a finite application budget. A binary
|
|
39
|
+
* request of a Domain with binary Functions lives up to 30 minutes, or this budget
|
|
40
|
+
* when it is longer.
|
|
25
41
|
*/
|
|
26
|
-
readonly
|
|
27
|
-
/** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
|
|
28
|
-
readonly secrets?: string;
|
|
42
|
+
readonly invocationTimeoutMs?: number;
|
|
29
43
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* installed Domain identity. Local watch generates `.astrale/identity.json`
|
|
33
|
-
* once when this field is omitted.
|
|
44
|
+
* Configure the caller-only Domain token exchange lifetime, or disable exchange.
|
|
45
|
+
* The default maximum is 30 minutes; production and CI environments may select a shorter bound.
|
|
34
46
|
*/
|
|
35
|
-
readonly
|
|
36
|
-
/** Local dev port for `wrangler dev`. Default 8787. */
|
|
37
|
-
readonly port?: number;
|
|
47
|
+
readonly tokenExchange?: ExchangeOptions | false;
|
|
38
48
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* Usually injected by `pnpm dev --host <url>` rather than written here.
|
|
49
|
+
* What a Worker serving durable Workflows declares to the workflow engine, as `serve({ durable })`
|
|
50
|
+
* does: run retention, retry before pausing and the deadline of each Step. Canonical callbacks
|
|
51
|
+
* discover engine keys from their Kernel. The options are frozen into each
|
|
52
|
+
* deployment's configuration (`settings.durableOptions`), so another value is another deployment
|
|
53
|
+
* (AM-175).
|
|
45
54
|
*/
|
|
46
|
-
readonly
|
|
47
|
-
/** Override the Worker name. Default: derived from the domain origin. */
|
|
48
|
-
readonly workerName?: string;
|
|
49
|
-
/** Run `wrangler dev --remote` (edge isolate) instead of local workerd. */
|
|
50
|
-
readonly remote?: boolean;
|
|
51
|
-
/** Extra plain (non-secret) vars to inject as Worker vars. */
|
|
52
|
-
readonly vars?: Record<string, string>;
|
|
55
|
+
readonly durable?: DurableWorkerOptions;
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Hyperdrive, etc.
|
|
58
|
-
*
|
|
59
|
-
* wrangler: {
|
|
60
|
-
* kv_namespaces: [{ binding: 'CACHE', id: '<kv-id>' }],
|
|
61
|
-
* r2_buckets: [{ binding: 'FILES', bucket_name: 'my-bucket' }],
|
|
62
|
-
* }
|
|
63
|
-
*
|
|
64
|
-
* The merge is additive: arrays concat (so your `services` keep the adapter's
|
|
65
|
-
* `SELF` binding and your `compatibility_flags` keep `nodejs_compat`); new
|
|
66
|
-
* keys are added as-is. The adapter-owned keys `name`, `main`, `assets`,
|
|
67
|
-
* `routes` are rejected — use `workerName` and `route` instead. Avoid
|
|
68
|
-
* the reserved binding names `SELF` and `ASSETS`. Durable Objects need extra
|
|
69
|
-
* worker-entry codegen and aren't supported through this field yet.
|
|
57
|
+
* Extra frozen Worker configuration. Accepts only services, dispatch_namespaces and
|
|
58
|
+
* compatibility_flags; an immutable deployment runs no cron of its own. Bundle-shaping
|
|
59
|
+
* options and the platform namespace are refused.
|
|
70
60
|
*/
|
|
71
61
|
readonly wrangler?: Record<string, unknown>;
|
|
72
62
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* worker can't fetch an instance kernel's JWKS to verify an inbound credential
|
|
77
|
-
* from that instance, and every cross-instance call (install hooks, delegated
|
|
78
|
-
* GUI calls, and traffic initiated from a Shell-handshaken View) fails with
|
|
79
|
-
* `2002 Credential verification failed`. Point it at a router Worker that
|
|
80
|
-
* reaches those hosts internally (Astrale: `admin-router`).
|
|
63
|
+
* Optional private routing through a service binding. By default, subrequests use
|
|
64
|
+
* their public URLs; generated Workers enable `global_fetch_strictly_public` so
|
|
65
|
+
* same-zone Worker calls honor public routes too.
|
|
81
66
|
*
|
|
82
|
-
* Wires
|
|
83
|
-
*
|
|
84
|
-
*
|
|
67
|
+
* Wires both halves the SDK needs: the `ROUTER` service binding in the
|
|
68
|
+
* deployment's wrangler config, and the host suffix and label rule bound in
|
|
69
|
+
* `ASTRALE_SETTINGS`, which the Worker applies to divert matching hosts
|
|
70
|
+
* through that binding.
|
|
85
71
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* router), or an object to override the target / binding name / host match.
|
|
72
|
+
* Opt in only when the selected router owns every hostname matched by the
|
|
73
|
+
* suffix/label predicate. A shared DNS suffix is not proof of router ownership:
|
|
74
|
+
* standalone Domain deployments may share it with managed instances.
|
|
90
75
|
*
|
|
91
|
-
* router: false
|
|
92
|
-
* router: { service: 'my-router' } //
|
|
76
|
+
* router: false // explicit public routing (the default)
|
|
77
|
+
* router: { service: 'my-router' } // opt into a private router
|
|
93
78
|
*/
|
|
94
79
|
readonly router?: false | {
|
|
95
80
|
/** Router Worker the binding targets. Default `'admin-router'`. */
|
|
96
81
|
readonly service?: string;
|
|
97
|
-
/** Service-binding name the worker reads. Default `'ROUTER'`. */
|
|
98
|
-
readonly binding?: string;
|
|
99
82
|
/** Host suffix that marks an instance host. Default `'.astrale.ai'`. */
|
|
100
83
|
readonly hostSuffix?: string;
|
|
101
84
|
/** Min dot-separated label count for an instance host. Default `4` (`<slug>.<region>.astrale.ai`). */
|
|
102
85
|
readonly minLabels?: number;
|
|
103
86
|
};
|
|
104
87
|
}
|
|
88
|
+
export type DurableWorkerOptions = Pick<DurableServing, 'retentionMs' | 'retry' | 'stepTimeoutMs'>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BuildManifestV1 } from '@astrale-os/sdk/deployment/build/manifest';
|
|
2
|
+
/**
|
|
3
|
+
* The bundler of every generated Cloudflare Worker, whichever adapter deploys it. Its version names
|
|
4
|
+
* the upload layout below, not a package release: a Services host recomputes the same build digest
|
|
5
|
+
* from the same bytes whatever SDK it runs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CLOUDFLARE_WORKER_BUNDLER: Readonly<{
|
|
8
|
+
id: "cloudflare-worker";
|
|
9
|
+
version: "1";
|
|
10
|
+
}>;
|
|
11
|
+
/** Portable Worker upload: what Services receives, and what a dispatch namespace upload carries. */
|
|
12
|
+
export interface WorkerUpload {
|
|
13
|
+
readonly origin: string;
|
|
14
|
+
readonly revision: BuildManifestV1['schema']['revision'];
|
|
15
|
+
/** Digest of the Domain Schema bundle. */
|
|
16
|
+
readonly bundle: BuildManifestV1['schema']['bundle'];
|
|
17
|
+
readonly entry: string;
|
|
18
|
+
readonly modules: readonly {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly bytes: Uint8Array;
|
|
21
|
+
}[];
|
|
22
|
+
/** Static assets by their absolute Worker asset path (`/index.html`). */
|
|
23
|
+
readonly assets?: readonly {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly bytes: Uint8Array;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The one build manifest of a Worker upload, computed on the exact upload the deploy sends; the
|
|
30
|
+
* SDK, Services and namespace mode all identify Worker code through it. Modules keep their uploaded
|
|
31
|
+
* name; a static asset `/<path>` is the file `assets/<path>`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function workerBuildManifest(upload: WorkerUpload): BuildManifestV1;
|
|
34
|
+
/** The build-manifest file of one Worker asset path. */
|
|
35
|
+
export declare function workerAssetFile(path: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { buildManifest } from '@astrale-os/sdk/deployment/build/manifest';
|
|
2
|
+
/**
|
|
3
|
+
* The bundler of every generated Cloudflare Worker, whichever adapter deploys it. Its version names
|
|
4
|
+
* the upload layout below, not a package release: a Services host recomputes the same build digest
|
|
5
|
+
* from the same bytes whatever SDK it runs.
|
|
6
|
+
*/
|
|
7
|
+
export const CLOUDFLARE_WORKER_BUNDLER = Object.freeze({
|
|
8
|
+
id: 'cloudflare-worker',
|
|
9
|
+
version: '1',
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The one build manifest of a Worker upload, computed on the exact upload the deploy sends; the
|
|
13
|
+
* SDK, Services and namespace mode all identify Worker code through it. Modules keep their uploaded
|
|
14
|
+
* name; a static asset `/<path>` is the file `assets/<path>`.
|
|
15
|
+
*/
|
|
16
|
+
export function workerBuildManifest(upload) {
|
|
17
|
+
if (upload === null || typeof upload !== 'object' || !Array.isArray(upload.modules)) {
|
|
18
|
+
throw new TypeError('Worker upload is invalid.');
|
|
19
|
+
}
|
|
20
|
+
if (upload.assets !== undefined && !Array.isArray(upload.assets)) {
|
|
21
|
+
throw new TypeError('Worker upload assets are invalid.');
|
|
22
|
+
}
|
|
23
|
+
return buildManifest({
|
|
24
|
+
origin: upload.origin,
|
|
25
|
+
revision: upload.revision,
|
|
26
|
+
bundle: upload.bundle,
|
|
27
|
+
bundler: CLOUDFLARE_WORKER_BUNDLER,
|
|
28
|
+
entrypoint: upload.entry,
|
|
29
|
+
files: [
|
|
30
|
+
...upload.modules.map((module) => ({ path: module.name, content: module.bytes })),
|
|
31
|
+
...(upload.assets ?? []).map((asset) => ({
|
|
32
|
+
path: workerAssetFile(asset.path),
|
|
33
|
+
content: asset.bytes,
|
|
34
|
+
})),
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** The build-manifest file of one Worker asset path. */
|
|
39
|
+
export function workerAssetFile(path) {
|
|
40
|
+
if (typeof path !== 'string' || !path.startsWith('/')) {
|
|
41
|
+
throw new TypeError('Worker asset path must be absolute.');
|
|
42
|
+
}
|
|
43
|
+
return `assets${path}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare const WORKER_DEPLOYMENT_ID: unique symbol;
|
|
2
|
+
/** Provider-local identity for one immutable staged Cloudflare implementation. */
|
|
3
|
+
export type WorkerDeploymentId = `sha256:${string}` & {
|
|
4
|
+
readonly [WORKER_DEPLOYMENT_ID]: true;
|
|
5
|
+
};
|
|
6
|
+
export interface WorkerDeploymentInput {
|
|
7
|
+
readonly release: {
|
|
8
|
+
readonly entrypoint: string;
|
|
9
|
+
readonly modules: readonly {
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly kind: 'esm' | 'wasm' | 'text' | 'data';
|
|
12
|
+
readonly content: Uint8Array;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
readonly runtime: {
|
|
16
|
+
readonly compatibilityDate: string;
|
|
17
|
+
readonly compatibilityFlags: readonly string[];
|
|
18
|
+
};
|
|
19
|
+
readonly bindings: {
|
|
20
|
+
readonly vars: Readonly<Record<string, string>>;
|
|
21
|
+
readonly services: readonly {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly service: string;
|
|
24
|
+
}[];
|
|
25
|
+
readonly requiredSecrets: readonly string[];
|
|
26
|
+
};
|
|
27
|
+
readonly assets?: {
|
|
28
|
+
readonly files: readonly {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly content: Uint8Array;
|
|
31
|
+
readonly contentType?: string;
|
|
32
|
+
}[];
|
|
33
|
+
readonly notFound: 'none' | '404-page' | 'single-page-application';
|
|
34
|
+
readonly runWorkerFirst: boolean;
|
|
35
|
+
readonly htmlHandling?: 'none';
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Canonical provider material used only for staging, promotion, rollback, and cleanup. */
|
|
39
|
+
export declare function workerDeploymentMaterial(input: WorkerDeploymentInput): Uint8Array;
|
|
40
|
+
/** Identify one immutable Cloudflare implementation without changing SDK or Publication identity. */
|
|
41
|
+
export declare function workerDeployment(input: WorkerDeploymentInput): WorkerDeploymentId;
|
|
42
|
+
/** Admit a serialized provider deployment identity at a Cloudflare boundary. */
|
|
43
|
+
export declare function acceptWorkerDeployment(input: unknown): WorkerDeploymentId;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
2
|
+
const DEPLOYMENT = /^sha256:[0-9a-f]{64}$/u;
|
|
3
|
+
/** Canonical provider material used only for staging, promotion, rollback, and cleanup. */
|
|
4
|
+
export function workerDeploymentMaterial(input) {
|
|
5
|
+
const release = executable(input.release);
|
|
6
|
+
const compatibilityFlags = uniqueStrings(input.runtime.compatibilityFlags, 'compatibility flag');
|
|
7
|
+
const vars = Object.fromEntries(Object.entries(input.bindings.vars)
|
|
8
|
+
.map(([name, value]) => {
|
|
9
|
+
stable(name, 'Variable binding name');
|
|
10
|
+
if (typeof value !== 'string')
|
|
11
|
+
invalid();
|
|
12
|
+
return [name, value];
|
|
13
|
+
})
|
|
14
|
+
.sort(([left], [right]) => compare(left, right)));
|
|
15
|
+
const services = [...input.bindings.services]
|
|
16
|
+
.map((binding) => ({
|
|
17
|
+
name: stable(binding.name, 'Service binding name'),
|
|
18
|
+
service: stable(binding.service, 'Service binding target'),
|
|
19
|
+
}))
|
|
20
|
+
.sort((left, right) => compare(left.name, right.name));
|
|
21
|
+
unique(services.map((binding) => binding.name), 'Service binding name');
|
|
22
|
+
const requiredSecrets = uniqueStrings(input.bindings.requiredSecrets, 'required secret');
|
|
23
|
+
unique([...Object.keys(vars), ...services.map((binding) => binding.name), ...requiredSecrets], 'Worker binding name');
|
|
24
|
+
const assets = input.assets === undefined ? undefined : canonicalAssets(input.assets);
|
|
25
|
+
return new TextEncoder().encode(`${JSON.stringify({
|
|
26
|
+
format: 'astrale.cloudflare.deployment',
|
|
27
|
+
version: 1,
|
|
28
|
+
release,
|
|
29
|
+
runtime: {
|
|
30
|
+
compatibilityDate: stable(input.runtime.compatibilityDate, 'compatibility date'),
|
|
31
|
+
compatibilityFlags,
|
|
32
|
+
},
|
|
33
|
+
bindings: { vars, services, requiredSecrets },
|
|
34
|
+
...(assets === undefined ? {} : { assets }),
|
|
35
|
+
})}\n`);
|
|
36
|
+
}
|
|
37
|
+
/** Identify one immutable Cloudflare implementation without changing SDK or Publication identity. */
|
|
38
|
+
export function workerDeployment(input) {
|
|
39
|
+
let hexadecimal = '';
|
|
40
|
+
for (const byte of sha256(workerDeploymentMaterial(input))) {
|
|
41
|
+
hexadecimal += byte.toString(16).padStart(2, '0');
|
|
42
|
+
}
|
|
43
|
+
return `sha256:${hexadecimal}`;
|
|
44
|
+
}
|
|
45
|
+
/** Admit a serialized provider deployment identity at a Cloudflare boundary. */
|
|
46
|
+
export function acceptWorkerDeployment(input) {
|
|
47
|
+
if (typeof input !== 'string' || !DEPLOYMENT.test(input)) {
|
|
48
|
+
throw new TypeError('Cloudflare Worker deployment identity is invalid.');
|
|
49
|
+
}
|
|
50
|
+
return input;
|
|
51
|
+
}
|
|
52
|
+
function executable(input) {
|
|
53
|
+
const entrypoint = stablePath(input.entrypoint, 'Worker release entrypoint');
|
|
54
|
+
const modules = input.modules
|
|
55
|
+
.map((module) => ({
|
|
56
|
+
path: stablePath(module.path, 'Worker release module path'),
|
|
57
|
+
kind: module.kind,
|
|
58
|
+
digest: content(module.content),
|
|
59
|
+
}))
|
|
60
|
+
.sort((left, right) => compare(left.path, right.path));
|
|
61
|
+
unique(modules.map((module) => module.path), 'Worker release module path');
|
|
62
|
+
if (!modules.some((module) => module.path === entrypoint && module.kind === 'esm')) {
|
|
63
|
+
throw new TypeError('Worker release entrypoint must be an ES module in its module set.');
|
|
64
|
+
}
|
|
65
|
+
return { entrypoint, modules };
|
|
66
|
+
}
|
|
67
|
+
function canonicalAssets(input) {
|
|
68
|
+
const files = input.files
|
|
69
|
+
.map((file) => ({
|
|
70
|
+
path: stableAssetPath(file.path),
|
|
71
|
+
digest: content(file.content),
|
|
72
|
+
...(file.contentType === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: { contentType: stable(file.contentType, 'Worker asset content type') }),
|
|
75
|
+
}))
|
|
76
|
+
.sort((left, right) => compare(left.path, right.path));
|
|
77
|
+
unique(files.map((file) => file.path), 'Worker asset path');
|
|
78
|
+
if (!['none', '404-page', 'single-page-application'].includes(input.notFound))
|
|
79
|
+
invalid();
|
|
80
|
+
if (input.htmlHandling !== undefined && input.htmlHandling !== 'none')
|
|
81
|
+
invalid();
|
|
82
|
+
return {
|
|
83
|
+
files,
|
|
84
|
+
notFound: input.notFound,
|
|
85
|
+
runWorkerFirst: input.runWorkerFirst,
|
|
86
|
+
htmlHandling: input.htmlHandling ?? 'none',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function uniqueStrings(input, label) {
|
|
90
|
+
const values = input.map((value) => stable(value, label)).sort(compare);
|
|
91
|
+
unique(values, label);
|
|
92
|
+
return values;
|
|
93
|
+
}
|
|
94
|
+
function unique(values, label) {
|
|
95
|
+
if (new Set(values).size !== values.length) {
|
|
96
|
+
throw new TypeError(`${label} must be unique.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function content(value) {
|
|
100
|
+
if (!(value instanceof Uint8Array))
|
|
101
|
+
invalid();
|
|
102
|
+
let hexadecimal = '';
|
|
103
|
+
for (const byte of sha256(value))
|
|
104
|
+
hexadecimal += byte.toString(16).padStart(2, '0');
|
|
105
|
+
return `sha256:${hexadecimal}`;
|
|
106
|
+
}
|
|
107
|
+
function stablePath(value, label) {
|
|
108
|
+
const admitted = stable(value, label);
|
|
109
|
+
if (admitted.startsWith('/') ||
|
|
110
|
+
admitted.includes('\\') ||
|
|
111
|
+
admitted.split('/').some((part) => part.length === 0 || part === '.' || part === '..')) {
|
|
112
|
+
invalid();
|
|
113
|
+
}
|
|
114
|
+
return admitted;
|
|
115
|
+
}
|
|
116
|
+
function stableAssetPath(value) {
|
|
117
|
+
const admitted = stable(value, 'Worker asset path');
|
|
118
|
+
if (!admitted.startsWith('/') ||
|
|
119
|
+
admitted.includes('\\') ||
|
|
120
|
+
admitted.includes('?') ||
|
|
121
|
+
admitted.includes('#') ||
|
|
122
|
+
admitted
|
|
123
|
+
.slice(1)
|
|
124
|
+
.split('/')
|
|
125
|
+
.some((part) => part.length === 0 || part === '.' || part === '..')) {
|
|
126
|
+
invalid();
|
|
127
|
+
}
|
|
128
|
+
return admitted;
|
|
129
|
+
}
|
|
130
|
+
function stable(value, label) {
|
|
131
|
+
if (typeof value !== 'string' || value.length === 0 || value.trim() !== value) {
|
|
132
|
+
throw new TypeError(`${label} must be stable non-empty text.`);
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function compare(left, right) {
|
|
137
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
138
|
+
}
|
|
139
|
+
function invalid() {
|
|
140
|
+
throw new TypeError('Cloudflare Worker deployment material is invalid.');
|
|
141
|
+
}
|
package/dist/release/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { CLOUDFLARE_WORKER_BUNDLER, workerBuildManifest, type WorkerUpload } from './build.js';
|
|
2
|
+
export { acceptWorkerDeployment, workerDeployment, workerDeploymentMaterial, type WorkerDeploymentId, type WorkerDeploymentInput, } from './deployment.js';
|
package/dist/release/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { CLOUDFLARE_WORKER_BUNDLER, workerBuildManifest } from './build.js';
|
|
2
|
+
export { acceptWorkerDeployment, workerDeployment, workerDeploymentMaterial, } from './deployment.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Build } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
/**
|
|
3
|
+
* Lifetime of one streamed binary request, upload included: the Kernel's own Server gives a blob
|
|
4
|
+
* upload the same 30 minutes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const BINARY_REQUEST_TIMEOUT_MS: number;
|
|
7
|
+
/** Longest wait for the next chunk of a binary body while the Action reads it, as the Kernel's. */
|
|
8
|
+
export declare const BINARY_REQUEST_IDLE_TIMEOUT_MS = 60000;
|
|
9
|
+
/** The Kernel Server limits a Worker serves binary requests under. */
|
|
10
|
+
export interface BinaryRequestLimits {
|
|
11
|
+
readonly maximumBinaryRequestBytes: number;
|
|
12
|
+
readonly binaryRequestTimeoutMs: number;
|
|
13
|
+
readonly binaryRequestIdleTimeoutMs: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The streamed binary request budget of one Build: the largest `maximumBytes` among the binary
|
|
17
|
+
* Functions its Domain declares, so the deployment admits every body one of them accepts and
|
|
18
|
+
* admission still holds each Function to its own. A Build without a binary Function keeps the
|
|
19
|
+
* Kernel Server defaults: `maximumRequestBytes` and `invocationTimeoutMs`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function binaryRequestLimits(build: Pick<Build, 'schema'>, invocationTimeoutMs: number): BinaryRequestLimits | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifetime of one streamed binary request, upload included: the Kernel's own Server gives a blob
|
|
3
|
+
* upload the same 30 minutes.
|
|
4
|
+
*/
|
|
5
|
+
export const BINARY_REQUEST_TIMEOUT_MS = 30 * 60_000;
|
|
6
|
+
/** Longest wait for the next chunk of a binary body while the Action reads it, as the Kernel's. */
|
|
7
|
+
export const BINARY_REQUEST_IDLE_TIMEOUT_MS = 60_000;
|
|
8
|
+
/**
|
|
9
|
+
* The streamed binary request budget of one Build: the largest `maximumBytes` among the binary
|
|
10
|
+
* Functions its Domain declares, so the deployment admits every body one of them accepts and
|
|
11
|
+
* admission still holds each Function to its own. A Build without a binary Function keeps the
|
|
12
|
+
* Kernel Server defaults: `maximumRequestBytes` and `invocationTimeoutMs`.
|
|
13
|
+
*/
|
|
14
|
+
export function binaryRequestLimits(build, invocationTimeoutMs) {
|
|
15
|
+
const compiled = build.schema.compiled;
|
|
16
|
+
const root = compiled.closure.find(({ origin }) => origin === compiled.root.origin);
|
|
17
|
+
let maximumBytes;
|
|
18
|
+
for (const definition of root?.definitions.functions ?? []) {
|
|
19
|
+
if (typeof definition.input === 'number')
|
|
20
|
+
continue;
|
|
21
|
+
maximumBytes = Math.max(maximumBytes ?? 0, definition.input.maximumBytes);
|
|
22
|
+
}
|
|
23
|
+
if (maximumBytes === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
maximumBinaryRequestBytes: maximumBytes,
|
|
27
|
+
// A deployment that already grants every invocation longer keeps that budget for uploads.
|
|
28
|
+
binaryRequestTimeoutMs: Math.max(invocationTimeoutMs, BINARY_REQUEST_TIMEOUT_MS),
|
|
29
|
+
binaryRequestIdleTimeoutMs: BINARY_REQUEST_IDLE_TIMEOUT_MS,
|
|
30
|
+
});
|
|
31
|
+
}
|