@astrale-os/adapter-cloudflare 0.5.0-beta.22 → 0.5.0-beta.221
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
|
@@ -1,45 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* deploy
|
|
4
|
-
* adapter for the `astrale-domain` CLI. This is a NODE-only module: it imports
|
|
5
|
-
* the adapter (wrangler + filesystem). The generated worker never imports this
|
|
6
|
-
* file — it imports `runtime.ts` directly — so the adapter stays out of the bundle.
|
|
2
|
+
* One Project definition, with explicit software-factory Environments.
|
|
7
3
|
*
|
|
8
|
-
*
|
|
4
|
+
* Every Environment deploys into a Workers for Platforms dispatch namespace
|
|
5
|
+
* (namespace mode), on your own Cloudflare account and domain once
|
|
6
|
+
* `astrale-domain cloudflare init <environment>` provisioned it, or on a platform
|
|
7
|
+
* namespace you are given. `astrale-domain deploy <environment>` makes one immutable
|
|
8
|
+
* deployment of this release, at its own URL under the namespace's routing
|
|
9
|
+
* domain, with a signing key generated for it, and prints that URL. A deploy
|
|
10
|
+
* never installs the Domain: install the URL it prints with
|
|
11
|
+
* `astrale domain install <url> -i <instance>`. Redeploying the same
|
|
12
|
+
* release reuses its deployment; a changed secrets file is then rewritten in
|
|
13
|
+
* place on that deployment only.
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
15
|
+
* `CLOUDFLARE_API_TOKEN` must edit the namespace's scripts and its routing KV,
|
|
16
|
+
* and `CLOUDFLARE_ACCOUNT_ID` names the account that holds it unless
|
|
17
|
+
* `namespace.account` does. Neither token nor secret is written here.
|
|
13
18
|
*/
|
|
14
19
|
import { cloudflare } from '@astrale-os/adapter-cloudflare'
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
// publishes the same bundle THROUGH the platform and installs it on your
|
|
18
|
-
// instance (auth = your `astrale auth login` session):
|
|
19
|
-
//
|
|
20
|
-
// import { astrale } from '@astrale-os/adapter-astrale'
|
|
21
|
-
// export default deploy({ application, entrypoint: runtime('./runtime.ts'), adapter: astrale({
|
|
22
|
-
// dev: { secrets: '.env.dev' }, // local wrangler dev
|
|
23
|
-
// prod: { instance: '<your-instance-slug>' }, // managed deploy
|
|
24
|
-
// }) })
|
|
20
|
+
import { defineProject } from '@astrale-os/sdk/project'
|
|
21
|
+
import { dataset, tests } from '@astrale-os/sdk/testing'
|
|
25
22
|
|
|
26
|
-
import {
|
|
23
|
+
import { domain } from './domain.js'
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The dispatch namespace and the DNS name its dispatcher answers under. Replace
|
|
27
|
+
* both placeholders, then provision them once on your account with
|
|
28
|
+
* `astrale-domain cloudflare init production` (a domain on Cloudflare dedicated
|
|
29
|
+
* to the deployments, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`). A deploy
|
|
30
|
+
* finds the namespace's routing KV from its name and refuses, before any
|
|
31
|
+
* effect, a namespace without one.
|
|
32
|
+
*/
|
|
33
|
+
const namespace = { name: 'your-platform-namespace', routingDomain: 'deployments.example.dev' }
|
|
34
|
+
|
|
35
|
+
export default defineProject({
|
|
36
|
+
domain,
|
|
37
|
+
|
|
38
|
+
environments: {
|
|
39
|
+
development: {
|
|
40
|
+
deployment: cloudflare({ namespace, secrets: '.env.dev' }),
|
|
41
41
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
|
|
43
|
+
production: {
|
|
44
|
+
deployment: cloudflare({ namespace }),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Test resources belong to the Project. CI selects an Environment and named
|
|
49
|
+
// suite when a test execution needs a live deployment.
|
|
50
|
+
tests: tests({ datasets: [dataset('./tests/datasets/demo.ts')] }),
|
|
45
51
|
})
|
package/dist/build/artifact.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ArtifactSource, PrepareContext } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
-
import type { CloudflareParams } from '../params.js';
|
|
3
|
-
/** Prepare one revision Service and its stateless gateway without provider mutation. */
|
|
4
|
-
export declare function artifact(params: CloudflareParams, context: PrepareContext): Promise<ArtifactSource>;
|
|
5
|
-
export declare function materialize(root: string, files: readonly {
|
|
6
|
-
readonly path: string;
|
|
7
|
-
bytes(): Uint8Array;
|
|
8
|
-
}[]): Promise<void>;
|
package/dist/build/artifact.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { material } from '@astrale-os/sdk/deployment/build';
|
|
2
|
-
import { addressing } from '@astrale-os/sdk/deployment/release';
|
|
3
|
-
import { readFile, writeFile, mkdir, rm } from 'node:fs/promises';
|
|
4
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
5
|
-
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { SIGNING_IDENTITY_BINDING } from '../identity/binding.js';
|
|
7
|
-
import { releaseNamespace, releaseWorkerName } from '../release/index.js';
|
|
8
|
-
import { generateExecutionEntry } from './codegen/execution.js';
|
|
9
|
-
import { generateGatewayEntry } from './codegen/gateway.js';
|
|
10
|
-
import { generateWranglerConfig } from './codegen/wrangler.js';
|
|
11
|
-
import { deploymentAddressing, resolveRouter, workerName } from './configuration.js';
|
|
12
|
-
import { frontendFiles } from './frontend-v1.js';
|
|
13
|
-
import { qualifyWorkerBundle } from './qualification.js';
|
|
14
|
-
import { runWranglerBundle } from './wrangler-cli.js';
|
|
15
|
-
const encoder = new TextEncoder();
|
|
16
|
-
/** Prepare one revision Service and its stateless gateway without provider mutation. */
|
|
17
|
-
export async function artifact(params, context) {
|
|
18
|
-
const stateDirectory = join(context.projectDir, '.astrale');
|
|
19
|
-
const directory = join(stateDirectory, 'runtime');
|
|
20
|
-
await mkdir(directory, { recursive: true });
|
|
21
|
-
const runtimePath = resolve(context.projectDir, context.runtime.reference.path);
|
|
22
|
-
const runtimeSpecifier = moduleSpecifier(relative(directory, runtimePath));
|
|
23
|
-
const router = resolveRouter(params.router);
|
|
24
|
-
const name = workerName(params, context.build.schema.compiled.root.origin);
|
|
25
|
-
const revision = context.build.schema.compiled.root.revision;
|
|
26
|
-
const namespace = releaseNamespace(name);
|
|
27
|
-
const target = releaseWorkerName(revision);
|
|
28
|
-
const configuredIssuer = deploymentAddressing(params);
|
|
29
|
-
const source = generateExecutionEntry({
|
|
30
|
-
origin: context.build.schema.compiled.root.origin,
|
|
31
|
-
runtimeSpecifier,
|
|
32
|
-
material: material(context.build),
|
|
33
|
-
...(configuredIssuer === undefined ? { providerAssignedWorker: name } : {}),
|
|
34
|
-
...(router === undefined
|
|
35
|
-
? {}
|
|
36
|
-
: {
|
|
37
|
-
router: {
|
|
38
|
-
binding: router.binding,
|
|
39
|
-
hostSuffix: router.hostSuffix,
|
|
40
|
-
minLabels: router.minLabels,
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
const sourcePath = join(directory, 'worker.gen.ts');
|
|
45
|
-
await writeFile(sourcePath, source);
|
|
46
|
-
const configPath = join(directory, 'wrangler.prepare.jsonc');
|
|
47
|
-
await writeFile(configPath, generateWranglerConfig({
|
|
48
|
-
workerName: name,
|
|
49
|
-
...(params.route === undefined ? {} : { route: params.route }),
|
|
50
|
-
vars: {
|
|
51
|
-
...params.vars,
|
|
52
|
-
...(configuredIssuer === undefined ? {} : { WORKER_URL: configuredIssuer }),
|
|
53
|
-
},
|
|
54
|
-
secretBindings: [SIGNING_IDENTITY_BINDING],
|
|
55
|
-
...(router === undefined
|
|
56
|
-
? {}
|
|
57
|
-
: { router: { binding: router.binding, service: router.service } }),
|
|
58
|
-
...(params.wrangler === undefined ? {} : { wrangler: params.wrangler }),
|
|
59
|
-
selfBinding: false,
|
|
60
|
-
}));
|
|
61
|
-
const output = join(directory, 'dist-prepare');
|
|
62
|
-
await rm(output, { recursive: true, force: true });
|
|
63
|
-
const emitted = await runWranglerBundle({
|
|
64
|
-
projectDir: context.projectDir,
|
|
65
|
-
configPath,
|
|
66
|
-
outDir: output,
|
|
67
|
-
});
|
|
68
|
-
const frontend = await frontendFiles({
|
|
69
|
-
frontend: context.build.frontend,
|
|
70
|
-
projectDir: context.projectDir,
|
|
71
|
-
});
|
|
72
|
-
await qualifyWorkerBundle({
|
|
73
|
-
metafilePath: emitted.metafilePath,
|
|
74
|
-
inputRoot: dirname(configPath),
|
|
75
|
-
});
|
|
76
|
-
await admitBundle(emitted.bundlePath);
|
|
77
|
-
const bundle = await readFile(emitted.bundlePath);
|
|
78
|
-
const gatewaySource = join(directory, 'gateway.gen.ts');
|
|
79
|
-
await writeFile(gatewaySource, generateGatewayEntry(revision));
|
|
80
|
-
const gatewayPrepareConfig = join(directory, 'wrangler.gateway.prepare.jsonc');
|
|
81
|
-
await writeFile(gatewayPrepareConfig, generateWranglerConfig({
|
|
82
|
-
workerName: name,
|
|
83
|
-
main: './gateway.gen.ts',
|
|
84
|
-
...(params.route === undefined ? {} : { route: params.route }),
|
|
85
|
-
releases: { binding: 'RELEASES', namespace },
|
|
86
|
-
selfBinding: false,
|
|
87
|
-
}));
|
|
88
|
-
const gatewayOutput = join(directory, 'dist-gateway');
|
|
89
|
-
await rm(gatewayOutput, { recursive: true, force: true });
|
|
90
|
-
const gateway = await runWranglerBundle({
|
|
91
|
-
projectDir: context.projectDir,
|
|
92
|
-
configPath: gatewayPrepareConfig,
|
|
93
|
-
outDir: gatewayOutput,
|
|
94
|
-
});
|
|
95
|
-
await qualifyWorkerBundle({
|
|
96
|
-
metafilePath: gateway.metafilePath,
|
|
97
|
-
inputRoot: dirname(gatewayPrepareConfig),
|
|
98
|
-
});
|
|
99
|
-
await admitBundle(gateway.bundlePath);
|
|
100
|
-
const gatewayBundle = await readFile(gateway.bundlePath);
|
|
101
|
-
const releaseConfig = generateWranglerConfig({
|
|
102
|
-
workerName: target,
|
|
103
|
-
main: './bundle/index.mjs',
|
|
104
|
-
vars: {
|
|
105
|
-
...params.vars,
|
|
106
|
-
...(configuredIssuer === undefined ? {} : { WORKER_URL: configuredIssuer }),
|
|
107
|
-
},
|
|
108
|
-
secretBindings: [SIGNING_IDENTITY_BINDING],
|
|
109
|
-
...(context.build.frontend?.source.kind === 'vite'
|
|
110
|
-
? {
|
|
111
|
-
frontend: {
|
|
112
|
-
directory: './frontend',
|
|
113
|
-
routes: frontendRoutes(context.build.frontend),
|
|
114
|
-
dev: false,
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
: {}),
|
|
118
|
-
...(router === undefined
|
|
119
|
-
? {}
|
|
120
|
-
: { router: { binding: router.binding, service: router.service } }),
|
|
121
|
-
...(params.wrangler === undefined ? {} : { wrangler: params.wrangler }),
|
|
122
|
-
selfBinding: false,
|
|
123
|
-
});
|
|
124
|
-
const gatewayConfig = generateWranglerConfig({
|
|
125
|
-
workerName: name,
|
|
126
|
-
main: './gateway/index.mjs',
|
|
127
|
-
...(params.route === undefined ? {} : { route: params.route }),
|
|
128
|
-
releases: { binding: 'RELEASES', namespace },
|
|
129
|
-
selfBinding: false,
|
|
130
|
-
});
|
|
131
|
-
const files = [
|
|
132
|
-
{ path: 'wrangler.release.jsonc', content: encoder.encode(releaseConfig) },
|
|
133
|
-
{ path: 'wrangler.gateway.jsonc', content: encoder.encode(gatewayConfig) },
|
|
134
|
-
{ path: 'bundle/index.mjs', content: new Uint8Array(bundle) },
|
|
135
|
-
{ path: 'gateway/index.mjs', content: new Uint8Array(gatewayBundle) },
|
|
136
|
-
...frontend.map((file) => ({
|
|
137
|
-
path: `frontend/${file.path}`,
|
|
138
|
-
content: file.bytes(),
|
|
139
|
-
})),
|
|
140
|
-
];
|
|
141
|
-
return Object.freeze({
|
|
142
|
-
entrypoint: 'bundle/index.mjs',
|
|
143
|
-
files: Object.freeze(files),
|
|
144
|
-
addressing: configuredIssuer === undefined
|
|
145
|
-
? Object.freeze({ kind: 'provider-assigned', claim: name })
|
|
146
|
-
: Object.freeze({ kind: 'configured', addressing: addressing(configuredIssuer) }),
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
async function admitBundle(path) {
|
|
150
|
-
const loaded = (await import(`${pathToFileURL(path).href}?admit=${Date.now()}`));
|
|
151
|
-
if (loaded.default === null ||
|
|
152
|
-
typeof loaded.default !== 'object' ||
|
|
153
|
-
typeof Reflect.get(loaded.default, 'fetch') !== 'function') {
|
|
154
|
-
throw new TypeError('Generated Worker bundle does not export a Fetch handler.');
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function frontendRoutes(frontend) {
|
|
158
|
-
if (frontend.source.kind !== 'vite')
|
|
159
|
-
return [];
|
|
160
|
-
return Object.freeze(frontend.routes
|
|
161
|
-
.flatMap((route) => frontend.source.kind === 'vite' && frontend.source.spa && route.path !== '/'
|
|
162
|
-
? [route.path, `${route.path}/*`]
|
|
163
|
-
: route.path === '/'
|
|
164
|
-
? ['/*']
|
|
165
|
-
: [route.path])
|
|
166
|
-
.sort());
|
|
167
|
-
}
|
|
168
|
-
export async function materialize(root, files) {
|
|
169
|
-
await rm(root, { recursive: true, force: true });
|
|
170
|
-
for (const file of files) {
|
|
171
|
-
const path = join(root, file.path);
|
|
172
|
-
await mkdir(dirname(path), { recursive: true });
|
|
173
|
-
await writeFile(path, file.bytes());
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
function moduleSpecifier(input) {
|
|
177
|
-
const normalized = input.split('\\').join('/');
|
|
178
|
-
return normalized.startsWith('.') ? normalized : `./${normalized}`;
|
|
179
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateGatewayEntry(revision: string): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export function generateGatewayEntry(revision) {
|
|
2
|
-
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
3
|
-
import { cloudflareGatewayEntry } from '@astrale-os/adapter-cloudflare/worker'
|
|
4
|
-
|
|
5
|
-
export default cloudflareGatewayEntry({ current: ${JSON.stringify(revision)} })
|
|
6
|
-
`;
|
|
7
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Build } from '@astrale-os/sdk/deployment/build';
|
|
2
|
-
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
3
|
-
export interface FrontendDevHandle {
|
|
4
|
-
readonly url: string;
|
|
5
|
-
stop(): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export declare function frontendFiles(input: {
|
|
8
|
-
readonly frontend: Build['frontend'];
|
|
9
|
-
readonly projectDir: string;
|
|
10
|
-
readonly onLog?: (line: string) => void;
|
|
11
|
-
}): Promise<readonly frontendBuild.FrontendFile[]>;
|
|
12
|
-
export declare function startFrontend(input: {
|
|
13
|
-
readonly frontend: Build['frontend'];
|
|
14
|
-
readonly projectDir: string;
|
|
15
|
-
readonly onLog?: (line: string) => void;
|
|
16
|
-
}): Promise<FrontendDevHandle | undefined>;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { readFile, readdir, rm } from 'node:fs/promises';
|
|
5
|
-
import { createServer } from 'node:net';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
export async function frontendFiles(input) {
|
|
8
|
-
const frontend = input.frontend;
|
|
9
|
-
if (frontend === undefined)
|
|
10
|
-
return [];
|
|
11
|
-
if (frontend.source.kind === 'external')
|
|
12
|
-
return frontendBuild.files(frontend, []);
|
|
13
|
-
const output = join(input.projectDir, '.astrale', 'frontend-build');
|
|
14
|
-
await rm(output, { recursive: true, force: true });
|
|
15
|
-
await run(viteCommand(input.projectDir), [
|
|
16
|
-
'build',
|
|
17
|
-
'--outDir',
|
|
18
|
-
output,
|
|
19
|
-
'--emptyOutDir',
|
|
20
|
-
...(frontend.source.config === undefined ? [] : ['--config', frontend.source.config]),
|
|
21
|
-
], input.projectDir, input.onLog);
|
|
22
|
-
return frontendBuild.files(frontend, await readFiles(output));
|
|
23
|
-
}
|
|
24
|
-
export async function startFrontend(input) {
|
|
25
|
-
const frontend = input.frontend;
|
|
26
|
-
if (frontend === undefined || frontend.source.kind !== 'vite')
|
|
27
|
-
return undefined;
|
|
28
|
-
const port = await ephemeralPort();
|
|
29
|
-
const child = spawn(viteCommand(input.projectDir), [
|
|
30
|
-
'--host',
|
|
31
|
-
'127.0.0.1',
|
|
32
|
-
'--port',
|
|
33
|
-
String(port),
|
|
34
|
-
'--strictPort',
|
|
35
|
-
...(frontend.source.config === undefined ? [] : ['--config', frontend.source.config]),
|
|
36
|
-
], { cwd: input.projectDir, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
37
|
-
const output = [];
|
|
38
|
-
const collect = (buffer) => {
|
|
39
|
-
for (const line of buffer.toString().split('\n')) {
|
|
40
|
-
if (line.trim() === '')
|
|
41
|
-
continue;
|
|
42
|
-
output.push(line);
|
|
43
|
-
if (output.length > 40)
|
|
44
|
-
output.shift();
|
|
45
|
-
input.onLog?.(line);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
child.stdout?.on('data', collect);
|
|
49
|
-
child.stderr?.on('data', collect);
|
|
50
|
-
const url = `http://127.0.0.1:${port}`;
|
|
51
|
-
try {
|
|
52
|
-
await ready(url, child, output);
|
|
53
|
-
}
|
|
54
|
-
catch (cause) {
|
|
55
|
-
await stop(child);
|
|
56
|
-
throw cause;
|
|
57
|
-
}
|
|
58
|
-
return Object.freeze({ url, stop: () => stop(child) });
|
|
59
|
-
}
|
|
60
|
-
async function readFiles(root, current = '') {
|
|
61
|
-
const entries = await readdir(join(root, current), { withFileTypes: true });
|
|
62
|
-
const files = [];
|
|
63
|
-
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
64
|
-
const path = current === '' ? entry.name : `${current}/${entry.name}`;
|
|
65
|
-
if (entry.isDirectory())
|
|
66
|
-
files.push(...(await readFiles(root, path)));
|
|
67
|
-
else if (entry.isFile()) {
|
|
68
|
-
files.push({ path, content: new Uint8Array(await readFile(join(root, path))) });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return files;
|
|
72
|
-
}
|
|
73
|
-
function viteCommand(projectDir) {
|
|
74
|
-
const command = join(projectDir, 'node_modules', '.bin', 'vite');
|
|
75
|
-
if (!existsSync(command))
|
|
76
|
-
throw new TypeError('Vite frontend requires a project-local vite binary.');
|
|
77
|
-
return command;
|
|
78
|
-
}
|
|
79
|
-
function run(command, args, cwd, onLog) {
|
|
80
|
-
return new Promise((resolve, reject) => {
|
|
81
|
-
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
82
|
-
let output = '';
|
|
83
|
-
const collect = (buffer) => {
|
|
84
|
-
const value = buffer.toString();
|
|
85
|
-
output += value;
|
|
86
|
-
for (const line of value.split('\n'))
|
|
87
|
-
if (line.trim() !== '')
|
|
88
|
-
onLog?.(line);
|
|
89
|
-
};
|
|
90
|
-
child.stdout?.on('data', collect);
|
|
91
|
-
child.stderr?.on('data', collect);
|
|
92
|
-
child.on('error', reject);
|
|
93
|
-
child.on('exit', (code) => code === 0
|
|
94
|
-
? resolve()
|
|
95
|
-
: reject(new Error(`Vite failed (code ${code ?? 1}):\n${output.slice(-1500)}`)));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function ephemeralPort() {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
const server = createServer();
|
|
101
|
-
server.once('error', reject);
|
|
102
|
-
server.listen(0, '127.0.0.1', () => {
|
|
103
|
-
const address = server.address();
|
|
104
|
-
const port = typeof address === 'object' && address !== null ? address.port : 0;
|
|
105
|
-
server.close((cause) => (cause === undefined ? resolve(port) : reject(cause)));
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async function ready(url, child, output) {
|
|
110
|
-
const deadline = Date.now() + 15_000;
|
|
111
|
-
while (Date.now() < deadline) {
|
|
112
|
-
if (child.exitCode !== null) {
|
|
113
|
-
throw new Error(`Vite exited before readiness (code ${child.exitCode}).\n${output.join('\n')}`);
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
const response = await fetch(url, { signal: AbortSignal.timeout(500) });
|
|
117
|
-
await response.body?.cancel();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
throw new Error(`Vite did not become ready at ${url}.`);
|
|
125
|
-
}
|
|
126
|
-
function stop(child) {
|
|
127
|
-
if (child.exitCode !== null || child.killed)
|
|
128
|
-
return Promise.resolve();
|
|
129
|
-
return new Promise((resolve) => {
|
|
130
|
-
child.once('exit', () => resolve());
|
|
131
|
-
child.kill('SIGTERM');
|
|
132
|
-
});
|
|
133
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure parsers for `wrangler` stdout. Kept separate from the process-spawning in
|
|
3
|
-
* `wrangler-cli.ts` so the brittle bit — scraping wrangler's human output — is
|
|
4
|
-
* unit-testable against captured fixtures without shelling out.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Local dev URL from `wrangler dev` output, normalized to an origin on the given
|
|
8
|
-
* port. Returns `undefined` when the output hasn't reported readiness yet.
|
|
9
|
-
*
|
|
10
|
-
* The fallback (when no explicit "Ready on" line) only accepts a localhost URL
|
|
11
|
-
* on the EXPECTED port — wrangler may print unrelated localhost URLs (e.g. an
|
|
12
|
-
* inspector/devtools endpoint on a different port) before readiness, and taking
|
|
13
|
-
* one of those would point `astrale domain install <url>` at a dead endpoint.
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseDevReadyUrl(text: string, port: number): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Authoritative public URL from `wrangler deploy` output. A custom-domain
|
|
18
|
-
* `route` wins (the deploy attaches it); otherwise the printed `*.workers.dev`
|
|
19
|
-
* URL. Returns `undefined` when neither is available (caller surfaces the raw
|
|
20
|
-
* output).
|
|
21
|
-
*/
|
|
22
|
-
export declare function parseDeployUrl(text: string, route?: string): string | undefined;
|
|
23
|
-
/** Cloudflare version published by the final Wrangler deploy pass. */
|
|
24
|
-
export declare function parseDeployVersionId(text: string): string | undefined;
|
|
25
|
-
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
26
|
-
export declare function normalizeLocal(url: string, port: number): string;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure parsers for `wrangler` stdout. Kept separate from the process-spawning in
|
|
3
|
-
* `wrangler-cli.ts` so the brittle bit — scraping wrangler's human output — is
|
|
4
|
-
* unit-testable against captured fixtures without shelling out.
|
|
5
|
-
*/
|
|
6
|
-
const READY_RE = /(?:Ready on|Listening on|⎔.*?at)\s+(https?:\/\/[^\s]+)/i;
|
|
7
|
-
const WORKERS_DEV_RE = /(https:\/\/[^\s]+\.workers\.dev)/i;
|
|
8
|
-
const VERSION_ID_RE = /(?:Current\s+)?Version ID:\s*([a-z0-9_-]+)/i;
|
|
9
|
-
/**
|
|
10
|
-
* Local dev URL from `wrangler dev` output, normalized to an origin on the given
|
|
11
|
-
* port. Returns `undefined` when the output hasn't reported readiness yet.
|
|
12
|
-
*
|
|
13
|
-
* The fallback (when no explicit "Ready on" line) only accepts a localhost URL
|
|
14
|
-
* on the EXPECTED port — wrangler may print unrelated localhost URLs (e.g. an
|
|
15
|
-
* inspector/devtools endpoint on a different port) before readiness, and taking
|
|
16
|
-
* one of those would point `astrale domain install <url>` at a dead endpoint.
|
|
17
|
-
*/
|
|
18
|
-
export function parseDevReadyUrl(text, port) {
|
|
19
|
-
const ready = READY_RE.exec(text);
|
|
20
|
-
if (ready)
|
|
21
|
-
return normalizeLocal(ready[1], port);
|
|
22
|
-
// `port` is a number, so it's safe to interpolate into the pattern. The
|
|
23
|
-
// negative lookahead stops `:8787` from matching inside `:87870`.
|
|
24
|
-
const localhostOnPort = new RegExp(`(https?://(?:localhost|127\\.0\\.0\\.1):${port})(?![0-9])`, 'i');
|
|
25
|
-
const m = localhostOnPort.exec(text);
|
|
26
|
-
return m ? normalizeLocal(m[1], port) : undefined;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Authoritative public URL from `wrangler deploy` output. A custom-domain
|
|
30
|
-
* `route` wins (the deploy attaches it); otherwise the printed `*.workers.dev`
|
|
31
|
-
* URL. Returns `undefined` when neither is available (caller surfaces the raw
|
|
32
|
-
* output).
|
|
33
|
-
*/
|
|
34
|
-
export function parseDeployUrl(text, route) {
|
|
35
|
-
if (route)
|
|
36
|
-
return `https://${route.replace(/\/.*$/, '')}`;
|
|
37
|
-
const m = WORKERS_DEV_RE.exec(text);
|
|
38
|
-
return m ? m[1] : undefined;
|
|
39
|
-
}
|
|
40
|
-
/** Cloudflare version published by the final Wrangler deploy pass. */
|
|
41
|
-
export function parseDeployVersionId(text) {
|
|
42
|
-
return VERSION_ID_RE.exec(text)?.[1];
|
|
43
|
-
}
|
|
44
|
-
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
45
|
-
export function normalizeLocal(url, port) {
|
|
46
|
-
try {
|
|
47
|
-
const u = new URL(url);
|
|
48
|
-
if (u.hostname === '0.0.0.0')
|
|
49
|
-
u.hostname = 'localhost';
|
|
50
|
-
if (!u.port)
|
|
51
|
-
u.port = String(port);
|
|
52
|
-
return u.origin;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return `http://localhost:${port}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin wrapper around the `wrangler` binary — the only place the adapter shells
|
|
3
|
-
* out. `watch` runs `wrangler dev` (local workerd) and resolves once the worker
|
|
4
|
-
* reports its local URL; `deploy` runs `wrangler deploy` and parses the
|
|
5
|
-
* authoritative public URL from the output; secrets go through `wrangler secret
|
|
6
|
-
* bulk`. The wrangler binary is resolved from the project's `node_modules/.bin`,
|
|
7
|
-
* falling back to `npx wrangler`.
|
|
8
|
-
*/
|
|
9
|
-
/** Keep Wrangler CLI diagnostic logs inside the generated project state. */
|
|
10
|
-
export declare function wranglerProcessEnv(projectDir: string): NodeJS.ProcessEnv;
|
|
11
|
-
export interface DevHandle {
|
|
12
|
-
url: string;
|
|
13
|
-
stop(): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export declare function runWranglerDev(args: {
|
|
16
|
-
projectDir: string;
|
|
17
|
-
configPath: string;
|
|
18
|
-
port: number;
|
|
19
|
-
remote: boolean;
|
|
20
|
-
/** Bind address — '0.0.0.0' for tunneled/proxied dev (`--host`). Default loopback. */
|
|
21
|
-
ip?: string;
|
|
22
|
-
/** When the port was NOT explicitly chosen, dodge a taken one automatically. */
|
|
23
|
-
autoPickPort?: boolean;
|
|
24
|
-
/** Secret bindings loaded through Wrangler's dotenv boundary, never config vars. */
|
|
25
|
-
secrets: Readonly<Record<string, string>>;
|
|
26
|
-
onReload: () => void;
|
|
27
|
-
onLog?: (line: string) => void;
|
|
28
|
-
}): Promise<DevHandle>;
|
|
29
|
-
export interface DeployArgs {
|
|
30
|
-
configPath: string;
|
|
31
|
-
route?: string;
|
|
32
|
-
onLog?: (line: string) => void;
|
|
33
|
-
}
|
|
34
|
-
export declare class WranglerDeployError extends Error {
|
|
35
|
-
readonly applied?: {
|
|
36
|
-
readonly url?: string;
|
|
37
|
-
readonly deploymentVersion?: string;
|
|
38
|
-
};
|
|
39
|
-
constructor(message: string, applied?: {
|
|
40
|
-
readonly url?: string;
|
|
41
|
-
readonly deploymentVersion?: string;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
export declare function runWranglerDeploy(args: DeployArgs & {
|
|
45
|
-
projectDir: string;
|
|
46
|
-
}): Promise<{
|
|
47
|
-
url?: string;
|
|
48
|
-
raw: string;
|
|
49
|
-
deploymentVersion: string;
|
|
50
|
-
}>;
|
|
51
|
-
/** Upload one Schema-revision Worker without assigning it a public route. */
|
|
52
|
-
export declare function runWranglerReleaseDeploy(args: {
|
|
53
|
-
readonly projectDir: string;
|
|
54
|
-
readonly configPath: string;
|
|
55
|
-
readonly namespace: string;
|
|
56
|
-
readonly secrets: Readonly<Record<string, string>>;
|
|
57
|
-
readonly onLog?: (line: string) => void;
|
|
58
|
-
}): Promise<{
|
|
59
|
-
readonly raw: string;
|
|
60
|
-
readonly deploymentVersion: string;
|
|
61
|
-
}>;
|
|
62
|
-
export declare class WranglerDispatchNamespaceError extends Error {
|
|
63
|
-
readonly effect: 'none' | 'unknown';
|
|
64
|
-
constructor(message: string, effect: 'none' | 'unknown');
|
|
65
|
-
}
|
|
66
|
-
/** Establish the private dispatch namespace without advancing the public gateway. */
|
|
67
|
-
export declare function ensureWranglerDispatchNamespace(args: {
|
|
68
|
-
readonly projectDir: string;
|
|
69
|
-
readonly namespace: string;
|
|
70
|
-
readonly onLog?: (line: string) => void;
|
|
71
|
-
}): Promise<void>;
|
|
72
|
-
export declare function runWranglerDeploymentStatus(args: {
|
|
73
|
-
readonly projectDir: string;
|
|
74
|
-
readonly configPath: string;
|
|
75
|
-
readonly workerName: string;
|
|
76
|
-
}): Promise<WranglerDeploymentStatus>;
|
|
77
|
-
export interface WranglerDeploymentStatus {
|
|
78
|
-
readonly deployment: string;
|
|
79
|
-
readonly versions: readonly {
|
|
80
|
-
readonly version: string;
|
|
81
|
-
readonly percentage: number;
|
|
82
|
-
}[];
|
|
83
|
-
}
|
|
84
|
-
/** Admit Wrangler's current-deployment JSON before it becomes provider evidence. */
|
|
85
|
-
export declare function admitWranglerDeploymentStatus(output: string): WranglerDeploymentStatus;
|
|
86
|
-
/**
|
|
87
|
-
* Build the single-module worker bundle WITHOUT deploying — `wrangler deploy
|
|
88
|
-
* --dry-run --outdir` (no Cloudflare auth required). Returns the path of the
|
|
89
|
-
* bundled .js module (the managed adapter publishes its bytes).
|
|
90
|
-
*/
|
|
91
|
-
export declare function runWranglerBundle(args: {
|
|
92
|
-
projectDir: string;
|
|
93
|
-
configPath: string;
|
|
94
|
-
outDir: string;
|
|
95
|
-
onLog?: (line: string) => void;
|
|
96
|
-
}): Promise<{
|
|
97
|
-
readonly bundlePath: string;
|
|
98
|
-
readonly metafilePath: string;
|
|
99
|
-
}>;
|
|
100
|
-
/** Generate the exact binding and runtime types selected by the generated config. */
|
|
101
|
-
export declare function runWranglerTypes(args: {
|
|
102
|
-
readonly projectDir: string;
|
|
103
|
-
readonly configPath: string;
|
|
104
|
-
readonly onLog?: (line: string) => void;
|
|
105
|
-
}): Promise<string>;
|