@astrale-os/adapter-cloudflare 0.1.7 → 0.1.9
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/dist/assets-pack.d.ts +1 -1
- package/dist/assets-pack.js +1 -1
- package/dist/build.d.ts +15 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +15 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/dist/cloudflare.d.ts +15 -3
- package/dist/cloudflare.d.ts.map +1 -1
- package/dist/cloudflare.js +73 -21
- package/dist/cloudflare.js.map +1 -1
- package/dist/codegen/worker.d.ts +26 -6
- package/dist/codegen/worker.d.ts.map +1 -1
- package/dist/codegen/worker.js +70 -54
- package/dist/codegen/worker.js.map +1 -1
- package/dist/codegen/wrangler.d.ts +11 -2
- package/dist/codegen/wrangler.d.ts.map +1 -1
- package/dist/codegen/wrangler.js +11 -5
- package/dist/codegen/wrangler.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/params.d.ts +30 -30
- package/dist/params.d.ts.map +1 -1
- package/dist/parse-output.d.ts +1 -1
- package/dist/parse-output.js +1 -1
- package/package.json +6 -2
- package/src/assets-pack.ts +1 -1
- package/src/build.ts +15 -0
- package/src/client.ts +11 -1
- package/src/cloudflare.ts +77 -23
- package/src/codegen/worker.ts +79 -59
- package/src/codegen/wrangler.ts +15 -5
- package/src/index.ts +6 -3
- package/src/params.ts +32 -31
- package/src/parse-output.ts +1 -1
- package/template/.agents/skills/astrale-cli/SKILL.md +25 -11
- package/template/.agents/skills/astrale-domain/SKILL.md +60 -32
- package/template/.env.example +8 -0
- package/template/README.md +26 -10
- package/template/astrale.config.ts +22 -29
- package/template/client/README.md +2 -2
- package/template/client/src/styles.css +4 -1
- package/template/client/tsconfig.json +1 -1
- package/template/client/vite.config.ts +3 -3
- package/template/client/vitest.config.ts +1 -1
- package/template/core/keys.ts +28 -0
- package/template/{methods → core}/note.ts +42 -25
- package/template/deps.ts +25 -0
- package/template/domain.ts +33 -0
- package/template/env.ts +11 -0
- package/template/integrations/summary/heuristic.ts +25 -0
- package/template/integrations/summary/http.ts +69 -0
- package/template/integrations/summary/port.ts +21 -0
- package/template/integrations/summary/registry.ts +52 -0
- package/template/package.json +2 -3
- package/template/runtime/index.ts +62 -0
- package/template/schema/index.ts +2 -0
- package/template/schema/note.ts +5 -2
- package/template/tsconfig.json +13 -2
- package/template/views/note.ts +1 -1
- package/dist/astrale.d.ts +0 -27
- package/dist/astrale.d.ts.map +0 -1
- package/dist/astrale.js +0 -212
- package/dist/astrale.js.map +0 -1
- package/src/astrale.ts +0 -244
- package/template/methods/index.ts +0 -66
- package/template/schema/compiled.ts +0 -14
package/dist/assets-pack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pack a built client SPA (`
|
|
2
|
+
* Pack a built client SPA (the `CLIENT_DIST_DIR` build) into the host box's asset-archive
|
|
3
3
|
* format: `gzip(JSON [{ path, contentBase64 }])` — the exact shape
|
|
4
4
|
* `downloadAssets` on the box consumes (kernel/host workerd service layout).
|
|
5
5
|
*/
|
package/dist/assets-pack.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pack a built client SPA (`
|
|
2
|
+
* Pack a built client SPA (the `CLIENT_DIST_DIR` build) into the host box's asset-archive
|
|
3
3
|
* format: `gzip(JSON [{ path, contentBase64 }])` — the exact shape
|
|
4
4
|
* `downloadAssets` on the box consumes (kernel/host workerd service layout).
|
|
5
5
|
*/
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@astrale-os/adapter-cloudflare/build` — the shared Cloudflare-Workers build
|
|
3
|
+
* toolkit, exposed for sibling deploy adapters (e.g.
|
|
4
|
+
* `@astrale-os/adapter-astrale`).
|
|
5
|
+
*
|
|
6
|
+
* This is the "compile a `defineDomain` into a Cloudflare Workers bundle + run
|
|
7
|
+
* local dev" surface that every Cloudflare-Workers deploy strategy shares,
|
|
8
|
+
* regardless of WHERE the bundle ultimately ships. It is NOT part of the public
|
|
9
|
+
* adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
|
|
10
|
+
* build on so the codegen/bundling/dev logic lives in exactly one place.
|
|
11
|
+
*/
|
|
12
|
+
export { logTo, prepare } from './cloudflare';
|
|
13
|
+
export { buildClient, CLIENT_DIST_DIR } from './client';
|
|
14
|
+
export { runWranglerBundle, runWranglerDev } from './wrangler-cli';
|
|
15
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@astrale-os/adapter-cloudflare/build` — the shared Cloudflare-Workers build
|
|
3
|
+
* toolkit, exposed for sibling deploy adapters (e.g.
|
|
4
|
+
* `@astrale-os/adapter-astrale`).
|
|
5
|
+
*
|
|
6
|
+
* This is the "compile a `defineDomain` into a Cloudflare Workers bundle + run
|
|
7
|
+
* local dev" surface that every Cloudflare-Workers deploy strategy shares,
|
|
8
|
+
* regardless of WHERE the bundle ultimately ships. It is NOT part of the public
|
|
9
|
+
* adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
|
|
10
|
+
* build on so the codegen/bundling/dev logic lives in exactly one place.
|
|
11
|
+
*/
|
|
12
|
+
export { logTo, prepare } from './cloudflare';
|
|
13
|
+
export { buildClient, CLIENT_DIST_DIR } from './client';
|
|
14
|
+
export { runWranglerBundle, runWranglerDev } from './wrangler-cli';
|
|
15
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/client.d.ts
CHANGED
|
@@ -3,5 +3,14 @@
|
|
|
3
3
|
* has no `client/` or no resolvable Vite, we skip — the RPC surface and inline
|
|
4
4
|
* Views still work without a built SPA.
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Where the adapter expects the built client SPA to land, relative to the
|
|
8
|
+
* project root. This is a contract: the domain's Vite config MUST emit here
|
|
9
|
+
* (`build.outDir`), and the wrangler `assets.directory` binding + the managed
|
|
10
|
+
* deploy's asset reader both look here. Dot-prefixed so the build output sorts
|
|
11
|
+
* out of the way with the other generated dirs (`.astrale`) instead of
|
|
12
|
+
* polluting the middle of the project listing.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CLIENT_DIST_DIR = ".dist";
|
|
6
15
|
export declare function buildClient(clientDir: string, projectDir: string, onLog?: (line: string) => void): Promise<void>;
|
|
7
16
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,UAAU,CAAA;AAEtC,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { existsSync } from 'node:fs';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
|
+
/**
|
|
10
|
+
* Where the adapter expects the built client SPA to land, relative to the
|
|
11
|
+
* project root. This is a contract: the domain's Vite config MUST emit here
|
|
12
|
+
* (`build.outDir`), and the wrangler `assets.directory` binding + the managed
|
|
13
|
+
* deploy's asset reader both look here. Dot-prefixed so the build output sorts
|
|
14
|
+
* out of the way with the other generated dirs (`.astrale`) instead of
|
|
15
|
+
* polluting the middle of the project listing.
|
|
16
|
+
*/
|
|
17
|
+
export const CLIENT_DIST_DIR = '.dist';
|
|
9
18
|
export async function buildClient(clientDir, projectDir, onLog) {
|
|
10
19
|
const viteBin = [
|
|
11
20
|
join(clientDir, 'node_modules', '.bin', 'vite'),
|
|
@@ -13,7 +22,7 @@ export async function buildClient(clientDir, projectDir, onLog) {
|
|
|
13
22
|
].find((p) => existsSync(p));
|
|
14
23
|
if (!viteBin) {
|
|
15
24
|
// The project has a client/ but its deps aren't installed — wrangler would
|
|
16
|
-
// otherwise fail cryptically on the missing
|
|
25
|
+
// otherwise fail cryptically on the missing built-assets dir. Fail
|
|
17
26
|
// loud with the fix (the client is a workspace package — one install covers it).
|
|
18
27
|
throw new Error(`client build: vite not found in ${clientDir}. Run \`pnpm install\` at the project root ` +
|
|
19
28
|
`first (the client/ SPA is a workspace package).`);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,UAAkB,EAClB,KAA8B;IAE9B,MAAM,OAAO,GAAG;QACd,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;QAC/C,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC;KACjD,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,2EAA2E;QAC3E,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA;AAEtC,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,UAAkB,EAClB,KAA8B;IAE9B,MAAM,OAAO,GAAG;QACd,IAAI,CAAC,SAAS,EA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oBAAE,KAAK,EAAE,CAAC,IAAI,CAAC,CAAA;QACrE,CAAC,CAAA;QACD,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;QAC7D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* config (the dev never sees a `wrangler.jsonc`), builds the optional client
|
|
6
6
|
* SPA, and shells out to `wrangler`. `watch` → `wrangler dev` (local URL);
|
|
7
7
|
* `deploy` → `wrangler deploy` (workers.dev or a custom-domain URL); secrets →
|
|
8
|
-
* `wrangler secret bulk`. Both `watch` and `deploy` return the URL the
|
|
9
|
-
* prints and `astrale
|
|
8
|
+
* `wrangler secret bulk`. Both `watch` and `deploy` return the URL the CLI
|
|
9
|
+
* prints and `astrale domain install <url>` consumes.
|
|
10
10
|
*/
|
|
11
|
-
import type { DeployCtx, DomainAdapter, WatchCtx } from '@astrale-os/
|
|
11
|
+
import type { DeployCtx, DomainAdapter, WatchCtx } from '@astrale-os/sdk';
|
|
12
12
|
import type { CloudflareParams } from './params';
|
|
13
13
|
export declare function cloudflare(envs: Record<string, CloudflareParams>): DomainAdapter<CloudflareParams>;
|
|
14
14
|
export declare function prepare(params: CloudflareParams, ctx: WatchCtx | DeployCtx, mode: 'dev' | 'deploy'): Promise<{
|
|
@@ -18,5 +18,17 @@ export declare function prepare(params: CloudflareParams, ctx: WatchCtx | Deploy
|
|
|
18
18
|
workerName: string;
|
|
19
19
|
}>;
|
|
20
20
|
export declare function workerName(params: CloudflareParams, origin: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the instance-router config. ON by default (targets `admin-router`) so
|
|
23
|
+
* every adapter-deployed worker can reach other instances' hosts internally and
|
|
24
|
+
* verify cross-instance credentials without a 522; `false` disables it. The
|
|
25
|
+
* returned shape carries every value the worker- and wrangler-codegen need.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveRouter(ir: CloudflareParams['router']): {
|
|
28
|
+
binding: string;
|
|
29
|
+
service: string;
|
|
30
|
+
hostSuffix: string;
|
|
31
|
+
minLabels: number;
|
|
32
|
+
} | undefined;
|
|
21
33
|
export declare function logTo(): (line: string) => void;
|
|
22
34
|
//# sourceMappingURL=cloudflare.d.ts.map
|
package/dist/cloudflare.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAUhD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GACrC,aAAa,CAAC,gBAAgB,CAAC,CAmEjC;AAID,wBAAsB,OAAO,CAC3B,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,QAAQ,GAAG,SAAS,EACzB,IAAI,EAAE,KAAK,GAAG,QAAQ,GACrB,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAkGhG;AA8CD,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAsB3E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAC7B;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CASzF;AAED,wBAAgB,KAAK,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAE9C"}
|
package/dist/cloudflare.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* config (the dev never sees a `wrangler.jsonc`), builds the optional client
|
|
6
6
|
* SPA, and shells out to `wrangler`. `watch` → `wrangler dev` (local URL);
|
|
7
7
|
* `deploy` → `wrangler deploy` (workers.dev or a custom-domain URL); secrets →
|
|
8
|
-
* `wrangler secret bulk`. Both `watch` and `deploy` return the URL the
|
|
9
|
-
* prints and `astrale
|
|
8
|
+
* `wrangler secret bulk`. Both `watch` and `deploy` return the URL the CLI
|
|
9
|
+
* prints and `astrale domain install <url>` consumes.
|
|
10
10
|
*/
|
|
11
|
-
import { defineAdapter
|
|
12
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { defineAdapter } from '@astrale-os/sdk';
|
|
12
|
+
import { mkdir, rename, writeFile } from 'node:fs/promises';
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
import { buildClient } from './client';
|
|
15
15
|
import { ensureIdentity } from './codegen/identity';
|
|
@@ -39,6 +39,15 @@ export function cloudflare(envs) {
|
|
|
39
39
|
// front), not the local bind — print and spec-stamp that.
|
|
40
40
|
return { url: params.host ?? handle.url, stop: handle.stop };
|
|
41
41
|
},
|
|
42
|
+
// Config hot-regen: rewrite the generated files only — the running
|
|
43
|
+
// `wrangler dev` watches its `--config` (and the worker entry) and reloads
|
|
44
|
+
// them itself, so a `astrale.config.ts` edit lands without a restart.
|
|
45
|
+
// Mirrors `watch`'s prep exactly (codegen + client build), minus the spawn.
|
|
46
|
+
async regenerate(params, ctx) {
|
|
47
|
+
await prepare(params, ctx, 'dev');
|
|
48
|
+
if (ctx.clientDir)
|
|
49
|
+
await buildClient(ctx.clientDir, ctx.projectDir, logTo());
|
|
50
|
+
},
|
|
42
51
|
async deploy(params, ctx) {
|
|
43
52
|
const { configPath, fallbackConfigPath, workerName: name, } = await prepare(params, ctx, 'deploy');
|
|
44
53
|
if (ctx.clientDir)
|
|
@@ -60,7 +69,7 @@ export function cloudflare(envs) {
|
|
|
60
69
|
});
|
|
61
70
|
}
|
|
62
71
|
// A first deploy on a fresh `*.workers.dev` host can take ~30-60s to
|
|
63
|
-
// propagate; an `astrale
|
|
72
|
+
// propagate; an `astrale domain install <url>` issued right away would
|
|
64
73
|
// 404 (Cloudflare 1042). Block until the URL actually serves so the
|
|
65
74
|
// install line we print is immediately actionable.
|
|
66
75
|
await waitUntilLive(url, logTo());
|
|
@@ -77,20 +86,33 @@ export async function prepare(params, ctx, mode) {
|
|
|
77
86
|
await mkdir(astraleDir, { recursive: true });
|
|
78
87
|
await ensureIdentity(astraleDir, ctx.domain.origin);
|
|
79
88
|
const name = workerName(params, ctx.domain.origin);
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
// Instance-router service binding (on by default → admin-router): lets the
|
|
90
|
+
// worker reach other instances' hosts internally, so a cross-instance JWKS
|
|
91
|
+
// fetch doesn't 522. Resolved once, fed to BOTH codegens below.
|
|
92
|
+
const router = resolveRouter(params.router);
|
|
93
|
+
// Two distinct client signals: the WORKER's `/ui` hook is present whenever the
|
|
94
|
+
// domain declares a client (`ctx.domain.hasClient`) — including managed
|
|
95
|
+
// deploys, which ship the built assets separately and pass no `clientDir`; the
|
|
96
|
+
// wrangler `assets.directory` binding is wired only when there's a local dir to
|
|
97
|
+
// point at (`ctx.clientDir` — direct Cloudflare deploys + local dev).
|
|
98
|
+
const servesClient = ctx.domain.hasClient;
|
|
99
|
+
const bundleAssets = Boolean(ctx.clientDir);
|
|
100
|
+
await writeFileAtomic(join(astraleDir, 'worker.gen.ts'),
|
|
101
|
+
// Everything else — schema/methods/deps/views/functions/requires/postInstall —
|
|
102
|
+
// rides the `...domain` spread the generated entry imports from `../domain`;
|
|
103
|
+
// the only remaining build-time signal is whether to wire the /ui asset hook.
|
|
104
|
+
generateWorkerEntry({
|
|
88
105
|
origin: ctx.domain.origin,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
hasClient: servesClient,
|
|
107
|
+
...(router
|
|
108
|
+
? {
|
|
109
|
+
router: {
|
|
110
|
+
binding: router.binding,
|
|
111
|
+
hostSuffix: router.hostSuffix,
|
|
112
|
+
minLabels: router.minLabels,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
: {}),
|
|
94
116
|
}));
|
|
95
117
|
// Pin the worker's canonical serving URL (its `iss` identity) for routed
|
|
96
118
|
// deploys: a routed worker may ALSO be reachable via `*.workers.dev`, so
|
|
@@ -115,8 +137,12 @@ export async function prepare(params, ctx, mode) {
|
|
|
115
137
|
const baseConfig = {
|
|
116
138
|
workerName: name,
|
|
117
139
|
...(mode === 'deploy' && params.route ? { route: params.route } : {}),
|
|
118
|
-
hasClient,
|
|
140
|
+
hasClient: bundleAssets,
|
|
119
141
|
vars,
|
|
142
|
+
// Router service binding flows into BOTH the SELF and SELF-less fallback
|
|
143
|
+
// configs — the first-deploy two-pass must keep it. `admin-router` already
|
|
144
|
+
// exists, so unlike SELF it always resolves (no first-deploy chicken-egg).
|
|
145
|
+
...(router ? { router: { binding: router.binding, service: router.service } } : {}),
|
|
120
146
|
// Escape hatch: extra bindings (KV/R2/D1/queues/…) deep-merged on top. Same
|
|
121
147
|
// overlay in dev and deploy — it's infra, not env-specific plumbing — and it
|
|
122
148
|
// flows into both the SELF and the SELF-less fallback config below.
|
|
@@ -127,11 +153,11 @@ export async function prepare(params, ctx, mode) {
|
|
|
127
153
|
// worker can't (the script doesn't exist yet), so we also emit a SELF-less
|
|
128
154
|
// fallback config that `runWranglerDeploy` uses for a one-time two-pass deploy.
|
|
129
155
|
const configPath = join(astraleDir, 'wrangler.gen.jsonc');
|
|
130
|
-
await
|
|
156
|
+
await writeFileAtomic(configPath, generateWranglerConfig({ ...baseConfig, selfBinding: true }));
|
|
131
157
|
let fallbackConfigPath;
|
|
132
158
|
if (mode === 'deploy') {
|
|
133
159
|
fallbackConfigPath = join(astraleDir, 'wrangler.no-self.gen.jsonc');
|
|
134
|
-
await
|
|
160
|
+
await writeFileAtomic(fallbackConfigPath, generateWranglerConfig({ ...baseConfig, selfBinding: false }));
|
|
135
161
|
}
|
|
136
162
|
return {
|
|
137
163
|
configPath,
|
|
@@ -140,6 +166,15 @@ export async function prepare(params, ctx, mode) {
|
|
|
140
166
|
workerName: name,
|
|
141
167
|
};
|
|
142
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Write-then-rename: hot-regen rewrites these files while a live `wrangler dev`
|
|
171
|
+
* watches them — a plain `writeFile` can be read truncated mid-write.
|
|
172
|
+
*/
|
|
173
|
+
async function writeFileAtomic(path, content) {
|
|
174
|
+
const tmp = `${path}.tmp`;
|
|
175
|
+
await writeFile(tmp, content);
|
|
176
|
+
await rename(tmp, path);
|
|
177
|
+
}
|
|
143
178
|
/**
|
|
144
179
|
* Poll the deployed URL until the worker answers (anything but the Cloudflare
|
|
145
180
|
* 1042 "no script on this host" 404), or give up after `timeoutMs`. Resolves
|
|
@@ -191,6 +226,23 @@ export function workerName(params, origin) {
|
|
|
191
226
|
.slice(0, 54)
|
|
192
227
|
.replace(/^-+|-+$/g, '');
|
|
193
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Resolve the instance-router config. ON by default (targets `admin-router`) so
|
|
231
|
+
* every adapter-deployed worker can reach other instances' hosts internally and
|
|
232
|
+
* verify cross-instance credentials without a 522; `false` disables it. The
|
|
233
|
+
* returned shape carries every value the worker- and wrangler-codegen need.
|
|
234
|
+
*/
|
|
235
|
+
export function resolveRouter(ir) {
|
|
236
|
+
if (ir === false)
|
|
237
|
+
return undefined;
|
|
238
|
+
const cfg = ir ?? {};
|
|
239
|
+
return {
|
|
240
|
+
binding: cfg.binding ?? 'ROUTER',
|
|
241
|
+
service: cfg.service ?? 'admin-router',
|
|
242
|
+
hostSuffix: cfg.hostSuffix ?? '.astrale.ai',
|
|
243
|
+
minLabels: cfg.minLabels ?? 4,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
194
246
|
export function logTo() {
|
|
195
247
|
return (line) => process.stderr.write(`\x1b[2m ${line}\x1b[0m\n`);
|
|
196
248
|
}
|
package/dist/cloudflare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAA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AC,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YAC7E,MAAM,IAAI,KAAK,CACb,+CAA+C,MAAM,CAAC,UAAU,yBAAyB;gBACvF,yFAAyF;gBACzF,kCAAkC,CACrC,CAAA;QACH,CAAC;QACD,OAAO,MAAM,CAAC,UAAU,CAAA;IAC1B,CAAC;IACD,gFAAgF;IAChF,gFAAgF;IAChF,gCAAgC;IAChC,OAAO,MAAM;SACV,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;SACZ,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,EAA8B;IAE9B,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IAClC,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,CAAA;IACpB,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,QAAQ;QAChC,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,cAAc;QACtC,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,aAAa;QAC3C,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,CAAC;KAC9B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,OAAO,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,WAAW,CAAC,CAAA;AAC5E,CAAC"}
|
package/dist/codegen/worker.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Codegen for the Cloudflare Worker entry (`.astrale/worker.gen.ts`).
|
|
3
3
|
*
|
|
4
|
-
* The dev
|
|
5
|
-
* `export
|
|
4
|
+
* The dev wires the domain ONCE in a worker-safe `domain.ts`
|
|
5
|
+
* (`export const domain = defineDomain({ schema, methods, deps, views,
|
|
6
|
+
* functions, client })`) and binds it to an adapter in `astrale.config.ts`
|
|
7
|
+
* (`deploy(domain, cloudflare({ … }))`). This generates the
|
|
8
|
+
* `export default { fetch }` plumbing the adapter owns by importing that single
|
|
9
|
+
* `domain` and SPREADING it into `domainWorkerEntry` — so the author's folder
|
|
10
|
+
* layout is irrelevant (any internal organization works as long as `domain.ts`
|
|
11
|
+
* re-exports the wired definition) and the node-only deploy adapter, which lives
|
|
12
|
+
* in `astrale.config.ts`, never enters this worker bundle.
|
|
13
|
+
*
|
|
14
|
+
* Everything the entry needs — schema/methods/deps/views/functions/requires/
|
|
15
|
+
* postInstall — rides on the spread; the only build-time signal left is whether
|
|
16
|
+
* the domain serves a client SPA (`hasClient`), which gates the `/ui` asset hook
|
|
17
|
+
* and its import. Key properties:
|
|
6
18
|
*
|
|
7
19
|
* • Per-request `url` = the live serving origin (`scheme://host`). It is passed
|
|
8
20
|
* only to `createRemoteServer({ url })`; the SDK stamps every
|
|
@@ -21,11 +33,19 @@
|
|
|
21
33
|
*/
|
|
22
34
|
export interface WorkerCodegenOptions {
|
|
23
35
|
origin: string;
|
|
24
|
-
postInstall?: string;
|
|
25
|
-
requires: readonly string[];
|
|
26
|
-
hasViews: boolean;
|
|
27
|
-
hasFunctions: boolean;
|
|
28
36
|
hasClient: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* When set, the worker routes subrequests to platform INSTANCE hostnames
|
|
39
|
+
* through `<binding>` (a service binding to a router Worker) instead of the
|
|
40
|
+
* public edge — a same-zone Worker→Worker public fetch 522s, which otherwise
|
|
41
|
+
* blocks fetching an instance kernel's JWKS to verify a cross-instance
|
|
42
|
+
* credential.
|
|
43
|
+
*/
|
|
44
|
+
router?: {
|
|
45
|
+
binding: string;
|
|
46
|
+
hostSuffix: string;
|
|
47
|
+
minLabels: number;
|
|
48
|
+
};
|
|
29
49
|
}
|
|
30
50
|
export declare function generateWorkerEntry(opts: WorkerCodegenOptions): string;
|
|
31
51
|
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;CACpE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,CA6EtE"}
|
package/dist/codegen/worker.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Codegen for the Cloudflare Worker entry (`.astrale/worker.gen.ts`).
|
|
3
3
|
*
|
|
4
|
-
* The dev
|
|
5
|
-
* `export
|
|
4
|
+
* The dev wires the domain ONCE in a worker-safe `domain.ts`
|
|
5
|
+
* (`export const domain = defineDomain({ schema, methods, deps, views,
|
|
6
|
+
* functions, client })`) and binds it to an adapter in `astrale.config.ts`
|
|
7
|
+
* (`deploy(domain, cloudflare({ … }))`). This generates the
|
|
8
|
+
* `export default { fetch }` plumbing the adapter owns by importing that single
|
|
9
|
+
* `domain` and SPREADING it into `domainWorkerEntry` — so the author's folder
|
|
10
|
+
* layout is irrelevant (any internal organization works as long as `domain.ts`
|
|
11
|
+
* re-exports the wired definition) and the node-only deploy adapter, which lives
|
|
12
|
+
* in `astrale.config.ts`, never enters this worker bundle.
|
|
13
|
+
*
|
|
14
|
+
* Everything the entry needs — schema/methods/deps/views/functions/requires/
|
|
15
|
+
* postInstall — rides on the spread; the only build-time signal left is whether
|
|
16
|
+
* the domain serves a client SPA (`hasClient`), which gates the `/ui` asset hook
|
|
17
|
+
* and its import. Key properties:
|
|
6
18
|
*
|
|
7
19
|
* • Per-request `url` = the live serving origin (`scheme://host`). It is passed
|
|
8
20
|
* only to `createRemoteServer({ url })`; the SDK stamps every
|
|
@@ -20,73 +32,77 @@
|
|
|
20
32
|
* dev via `VIEW_DEV_URL`).
|
|
21
33
|
*/
|
|
22
34
|
export function generateWorkerEntry(opts) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
// The asset-serving hook is a library helper (`assets`), not inlined string
|
|
36
|
+
// logic — imported only when the domain declares a `client` binding.
|
|
37
|
+
const serverImport = opts.hasClient
|
|
38
|
+
? `import { assets, domainWorkerEntry } from '@astrale-os/sdk/server'`
|
|
39
|
+
: `import { domainWorkerEntry } from '@astrale-os/sdk/server'`;
|
|
40
|
+
const clientHook = opts.hasClient
|
|
41
|
+
? `
|
|
42
|
+
// Client assets under /ui/* — served from the ASSETS binding (or proxied to
|
|
43
|
+
// Vite in dev via VIEW_DEV_URL). The matching/stripping logic lives in the SDK helper.
|
|
44
|
+
before: assets({ binding: (env) => env.ASSETS, devProxy: (env) => env.VIEW_DEV_URL }),`
|
|
45
|
+
: '';
|
|
46
|
+
const router = opts.router;
|
|
47
|
+
// Service binding for instance-host subrequest routing (Env field + helper +
|
|
48
|
+
// routeSubrequest), wired only when the adapter's `router` is set.
|
|
49
|
+
const routerEnvField = router
|
|
50
|
+
? `
|
|
51
|
+
${router.binding}?: { fetch(request: Request): Promise<Response> }`
|
|
52
|
+
: '';
|
|
53
|
+
const routerHelper = router
|
|
54
|
+
? `
|
|
55
|
+
// A platform INSTANCE hostname (e.g. <slug>.<region>${router.hostSuffix}) is served
|
|
56
|
+
// by a router Worker on the SAME zone — a direct Worker→Worker public fetch 522s.
|
|
57
|
+
// Route those subrequests (e.g. fetching an instance kernel's JWKS to verify a
|
|
58
|
+
// cross-instance credential) through the ${router.binding} service binding instead.
|
|
59
|
+
function isInstanceHost(host) {
|
|
60
|
+
return host.endsWith('${router.hostSuffix}') && host.split('.').length >= ${router.minLabels}
|
|
61
|
+
}
|
|
62
|
+
`
|
|
63
|
+
: '';
|
|
64
|
+
const routerHook = router
|
|
65
|
+
? `
|
|
66
|
+
// Divert instance-host subrequests through ${router.binding} (CF 522s a same-zone
|
|
67
|
+
// Worker→Worker public fetch). No-op when the binding is absent.
|
|
68
|
+
routeSubrequest: (url, env) => (env.${router.binding} && isInstanceHost(url.hostname) ? env.${router.binding} : null),`
|
|
69
|
+
: '';
|
|
30
70
|
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
31
|
-
// Regenerated on every \`astrale-domain dev|deploy\`. Edit
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
71
|
+
// Regenerated on every \`astrale-domain dev|deploy\`. Edit your domain.ts (the
|
|
72
|
+
// wired \`defineDomain\`) and astrale.config.ts (the \`deploy(domain, …)\`).
|
|
73
|
+
// (origin: ${opts.origin})
|
|
74
|
+
${serverImport}
|
|
35
75
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
// The worker-safe domain definition — schema/methods/deps/views/functions plus
|
|
77
|
+
// origin/requires/postInstall — wired by the author in domain.ts. Spreading it
|
|
78
|
+
// keeps this entry layout-agnostic; the deploy adapter stays in astrale.config.ts.
|
|
79
|
+
import { domain } from '../domain'
|
|
39
80
|
import { PRIVATE_JWK } from './identity'
|
|
40
81
|
|
|
41
|
-
const REQUIRES = ${JSON.stringify(opts.requires)}
|
|
42
|
-
${postInstallLine}
|
|
43
|
-
|
|
44
82
|
interface Env {
|
|
45
83
|
WORKER_URL?: string
|
|
46
84
|
ASSETS?: { fetch(request: Request): Promise<Response> }
|
|
47
85
|
SELF?: { fetch(request: Request): Promise<Response> }
|
|
48
|
-
VIEW_DEV_URL?: string
|
|
86
|
+
VIEW_DEV_URL?: string${routerEnvField}
|
|
49
87
|
[key: string]: unknown
|
|
50
88
|
}
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
|
|
89
|
+
${routerHelper}
|
|
90
|
+
// \`domainWorkerEntry\` folds the runtime-domain compile + server build + the
|
|
91
|
+
// shared worker plumbing (JWKS self-resolution, SELF-binding routing, per-URL
|
|
92
|
+
// app cache, canonical iss resolution) into one declaration. \`deps\` (when the
|
|
93
|
+
// domain declares one) rides the spread and runs per cold isolate / serving URL.
|
|
94
|
+
export default domainWorkerEntry<Env>()({
|
|
95
|
+
...domain,
|
|
96
|
+
privateKey: PRIVATE_JWK,
|
|
55
97
|
// The worker's serving URL = its identity (iss). Prefer the adapter-injected
|
|
56
98
|
// WORKER_URL (pins one canonical host for routed deploys, so iss stays stable
|
|
57
99
|
// even when also reachable via *.workers.dev); fall back to the per-request
|
|
58
100
|
// host for dev / workers.dev-only (single-host → it IS the canonical URL).
|
|
101
|
+
// Behind a TLS-terminating proxy (cloudflared tunnel → wrangler dev) the SDK
|
|
102
|
+
// upgrades the fallback origin via X-Forwarded-Proto, so iss = the public
|
|
103
|
+
// https URL, not the raw http one workerd sees.
|
|
59
104
|
resolveUrl: (env, requestOrigin) => env.WORKER_URL ?? requestOrigin,
|
|
60
|
-
selfBinding: (env) => env.SELF
|
|
61
|
-
build: (url, env) => {
|
|
62
|
-
const domain = defineRemoteDomain()({
|
|
63
|
-
schema,
|
|
64
|
-
methods,
|
|
65
|
-
...(views ? { views } : {}),
|
|
66
|
-
...(functions ? { remoteFunctions: functions } : {}),
|
|
67
|
-
})
|
|
68
|
-
return {
|
|
69
|
-
domain,
|
|
70
|
-
deps: env,
|
|
71
|
-
url,
|
|
72
|
-
privateKey: PRIVATE_JWK,
|
|
73
|
-
...(POST_INSTALL ? { postInstall: POST_INSTALL } : {}),
|
|
74
|
-
...(REQUIRES.length ? { requires: REQUIRES } : {}),
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
// SPA under /ui/* (views with a client renderer).
|
|
78
|
-
before: (env, url, request) => {
|
|
79
|
-
if (env.ASSETS && (url.pathname === '/ui' || url.pathname.startsWith('/ui/'))) {
|
|
80
|
-
if (env.VIEW_DEV_URL) {
|
|
81
|
-
const devBase = env.VIEW_DEV_URL.replace(/\\/$/, '')
|
|
82
|
-
return fetch(new Request(\`\${devBase}\${url.pathname}\${url.search}\`, request))
|
|
83
|
-
}
|
|
84
|
-
const stripped = url.pathname.replace(/^\\/ui\\/?/, '/')
|
|
85
|
-
const rewritten = new URL(stripped + url.search, url.origin)
|
|
86
|
-
return env.ASSETS.fetch(new Request(rewritten, request))
|
|
87
|
-
}
|
|
88
|
-
return undefined
|
|
89
|
-
},
|
|
105
|
+
selfBinding: (env) => env.SELF,${routerHook}${clientHook}
|
|
90
106
|
})
|
|
91
107
|
`;
|
|
92
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAeH,MAAM,UAAU,mBAAmB,CAAC,IAA0B;IAC5D,4EAA4E;IAC5E,qEAAqE;IACrE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS;QACjC,CAAC,CAAC,oEAAoE;QACtE,CAAC,CAAC,4DAA4D,CAAA;IAEhE,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS;QAC/B,CAAC,CAAC;;;yFAGmF;QACrF,CAAC,CAAC,EAAE,CAAA;IAEN,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IAC1B,6EAA6E;IAC7E,mEAAmE;IACnE,MAAM,cAAc,GAAG,MAAM;QAC3B,CAAC,CAAC;IACF,MAAM,CAAC,OAAO,mDAAmD;QACjE,CAAC,CAAC,EAAE,CAAA;IACN,MAAM,YAAY,GAAG,MAAM;QACzB,CAAC,CAAC;uDACiD,MAAM,CAAC,UAAU;;;4CAG5B,MAAM,CAAC,OAAO;;0BAEhC,MAAM,CAAC,UAAU,mCAAmC,MAAM,CAAC,SAAS;;CAE7F;QACG,CAAC,CAAC,EAAE,CAAA;IACN,MAAM,UAAU,GAAG,MAAM;QACvB,CAAC,CAAC;gDAC0C,MAAM,CAAC,OAAO;;wCAEtB,MAAM,CAAC,OAAO,0CAA0C,MAAM,CAAC,OAAO,WAAW;QACrH,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO;;;cAGK,IAAI,CAAC,MAAM;EACvB,YAAY;;;;;;;;;;;;yBAYW,cAAc;;;EAGrC,YAAY;;;;;;;;;;;;;;;;mCAgBqB,UAAU,GAAG,UAAU;;CAEzD,CAAA;AACD,CAAC"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* `wrangler.jsonc` that used to be hand-copied into every domain — now an
|
|
4
4
|
* internal adapter detail the dev never sees.
|
|
5
5
|
*
|
|
6
|
-
* `main` is `./worker.gen.ts` (same dir). `assets.directory`
|
|
7
|
-
*
|
|
6
|
+
* `main` is `./worker.gen.ts` (same dir). `assets.directory` points at the
|
|
7
|
+
* project's Vite build (`CLIENT_DIST_DIR`). A `SELF` service binding enables autobinding
|
|
8
8
|
* (a handler calling back into its own domain). Custom-domain deploys attach a
|
|
9
9
|
* `custom_domain` route; otherwise the Worker ships to `*.workers.dev`.
|
|
10
10
|
*
|
|
@@ -21,6 +21,15 @@ export interface WranglerCodegenOptions {
|
|
|
21
21
|
vars?: Record<string, string>;
|
|
22
22
|
/** Add the SELF service binding (autobinding). */
|
|
23
23
|
selfBinding: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Add a service binding to a router Worker for instance-host subrequest
|
|
26
|
+
* routing (see `CloudflareParams.router`). Pairs with the worker
|
|
27
|
+
* entry's `routeSubrequest`.
|
|
28
|
+
*/
|
|
29
|
+
router?: {
|
|
30
|
+
binding: string;
|
|
31
|
+
service: string;
|
|
32
|
+
};
|
|
24
33
|
/**
|
|
25
34
|
* Raw wrangler config to deep-merge over the generated base — the escape
|
|
26
35
|
* hatch for extra bindings (KV, R2, D1, queues, service bindings, extra
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/codegen/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/codegen/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,SAAS,EAAE,OAAO,CAAA;IAClB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,kDAAkD;IAClD,WAAW,EAAE,OAAO,CAAA;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAID,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,MAAM,CAoC3E"}
|