@astrale-os/adapter-cloudflare 0.1.1 → 0.1.3
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/astrale.d.ts +27 -0
- package/dist/astrale.d.ts.map +1 -0
- package/dist/astrale.js +163 -0
- package/dist/astrale.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +43 -0
- package/dist/client.js.map +1 -0
- package/dist/cloudflare.d.ts +22 -0
- package/dist/cloudflare.d.ts.map +1 -0
- package/dist/cloudflare.js +186 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/codegen/identity.d.ts +10 -0
- package/dist/codegen/identity.d.ts.map +1 -0
- package/dist/codegen/identity.js +32 -0
- package/dist/codegen/identity.js.map +1 -0
- package/dist/codegen/merge.d.ts +20 -0
- package/dist/codegen/merge.d.ts.map +1 -0
- package/dist/codegen/merge.js +91 -0
- package/dist/codegen/merge.js.map +1 -0
- package/dist/codegen/worker.d.ts +31 -0
- package/dist/codegen/worker.d.ts.map +1 -0
- package/dist/codegen/worker.js +93 -0
- package/dist/codegen/worker.js.map +1 -0
- package/dist/codegen/wrangler.d.ts +34 -0
- package/dist/codegen/wrangler.d.ts.map +1 -0
- package/dist/codegen/wrangler.js +61 -0
- package/dist/codegen/wrangler.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/params.d.ts +69 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/params.js +2 -0
- package/dist/params.js.map +1 -0
- package/dist/parse-output.d.ts +25 -0
- package/dist/parse-output.d.ts.map +1 -0
- package/dist/parse-output.js +53 -0
- package/dist/parse-output.js.map +1 -0
- package/dist/wrangler-cli.d.ts +74 -0
- package/dist/wrangler-cli.d.ts.map +1 -0
- package/dist/wrangler-cli.js +201 -0
- package/dist/wrangler-cli.js.map +1 -0
- package/package.json +2 -2
- package/src/astrale.ts +194 -0
- package/src/cloudflare.ts +2 -2
- package/src/index.ts +2 -1
- package/src/params.ts +20 -0
- package/src/wrangler-cli.ts +26 -1
- package/template/astrale.config.ts +9 -0
- package/template/package.json +10 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-merge for the generated wrangler config. `base` is what the adapter
|
|
3
|
+
* generates; `overlay` is the dev's `params.wrangler` escape hatch. The merge
|
|
4
|
+
* is additive so a dev can declare extra bindings without losing the adapter's
|
|
5
|
+
* invariants:
|
|
6
|
+
* - plain objects → recurse
|
|
7
|
+
* - arrays → concat, de-duplicating BOTH primitive members and
|
|
8
|
+
* object bindings by an identity key (`binding` /
|
|
9
|
+
* `pattern` / `queue` / `name`, else structural value),
|
|
10
|
+
* with the overlay entry overriding a base entry of the
|
|
11
|
+
* same identity. So a dev overlay that re-declares the
|
|
12
|
+
* adapter's `SELF` service (or any binding) replaces it
|
|
13
|
+
* instead of emitting a duplicate wrangler rejects.
|
|
14
|
+
* - scalars / new keys → overlay wins
|
|
15
|
+
*
|
|
16
|
+
* Protecting the load-bearing keys (`main`, `assets`, …) is policy enforced by
|
|
17
|
+
* the caller (`generateWranglerConfig`), not here — this stays a generic merge.
|
|
18
|
+
*/
|
|
19
|
+
export function deepMergeConfig(base, overlay) {
|
|
20
|
+
const out = { ...base };
|
|
21
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
22
|
+
const prev = out[key];
|
|
23
|
+
if (isPlainObject(prev) && isPlainObject(value)) {
|
|
24
|
+
out[key] = deepMergeConfig(prev, value);
|
|
25
|
+
}
|
|
26
|
+
else if (Array.isArray(prev) && Array.isArray(value)) {
|
|
27
|
+
out[key] = mergeArrays(prev, value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
out[key] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Concat two arrays, de-duplicating by identity. Primitives dedup by value;
|
|
37
|
+
* objects dedup by an identity key (`binding`/`pattern`/`queue`/`name`, else
|
|
38
|
+
* their structural JSON) with the later (overlay) entry overriding an earlier
|
|
39
|
+
* (base) one at the base entry's position. This stops a re-declared object
|
|
40
|
+
* binding (e.g. a second `SELF` service) from producing a duplicate that
|
|
41
|
+
* wrangler rejects, while still appending genuinely distinct bindings.
|
|
42
|
+
*/
|
|
43
|
+
function mergeArrays(a, b) {
|
|
44
|
+
const out = [];
|
|
45
|
+
const seenPrimitives = new Set();
|
|
46
|
+
const indexByKey = new Map();
|
|
47
|
+
for (const item of [...a, ...b]) {
|
|
48
|
+
if (isPrimitive(item)) {
|
|
49
|
+
if (seenPrimitives.has(item))
|
|
50
|
+
continue;
|
|
51
|
+
seenPrimitives.add(item);
|
|
52
|
+
out.push(item);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const key = identityKey(item);
|
|
56
|
+
const existing = indexByKey.get(key);
|
|
57
|
+
if (existing !== undefined) {
|
|
58
|
+
out[existing] = item; // overlay (later) overrides the base entry in place
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
indexByKey.set(key, out.length);
|
|
62
|
+
out.push(item);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Stable identity for an array's object member: the first recognized wrangler
|
|
68
|
+
* binding field (`binding` for services/KV/R2/D1/queue producers, `pattern` for
|
|
69
|
+
* routes, `queue` for consumers, `name` as a generic fallback), else the member's
|
|
70
|
+
* full structural JSON so identical objects dedup but distinct ones all survive.
|
|
71
|
+
*/
|
|
72
|
+
function identityKey(item) {
|
|
73
|
+
const rec = item;
|
|
74
|
+
for (const field of ['binding', 'pattern', 'queue', 'name']) {
|
|
75
|
+
if (typeof rec[field] === 'string')
|
|
76
|
+
return `${field}:${rec[field]}`;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return `json:${JSON.stringify(item)}`;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return `ref:${String(item)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function isPlainObject(v) {
|
|
86
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
87
|
+
}
|
|
88
|
+
function isPrimitive(v) {
|
|
89
|
+
return v === null || (typeof v !== 'object' && typeof v !== 'function');
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/codegen/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA6B,EAC7B,OAAgC;IAEhC,MAAM,GAAG,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAA;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACrB,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACzC,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAClB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,CAAY,EAAE,CAAY;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,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AACjE,CAAC;AAED,SAAS,WAAW,CAAC,CAAU;IAC7B,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,UAAU,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen for the Cloudflare Worker entry (`.astrale/worker.gen.ts`).
|
|
3
|
+
*
|
|
4
|
+
* The dev writes only schema/methods/views/functions; this generates the
|
|
5
|
+
* `export default { fetch }` plumbing the adapter owns. Key properties:
|
|
6
|
+
*
|
|
7
|
+
* • Per-request `url` = the live serving origin (`scheme://host`). It is passed
|
|
8
|
+
* only to `createRemoteServer({ url })`; the SDK stamps every
|
|
9
|
+
* `binding.remoteUrl` from that single value at spec-build time — so deployed
|
|
10
|
+
* Function nodes point back at THIS worker with zero hardcoded URLs.
|
|
11
|
+
* • Self-issued JWKS: a Worker can't fetch its own hostname; the verifier
|
|
12
|
+
* resolves a credential whose `iss` is this worker from the in-memory key,
|
|
13
|
+
* so no self-fetch is attempted (the worker's JWKS is served as a normal
|
|
14
|
+
* route by createRemoteServer).
|
|
15
|
+
* • Self-binding (autobinding): when a handler calls back into its OWN domain
|
|
16
|
+
* (`ctx.callRemote`), the redirect resolves to this worker's own host — a
|
|
17
|
+
* forbidden same-host subrequest. We route those through the `SELF` service
|
|
18
|
+
* binding instead.
|
|
19
|
+
* • SPA: `/ui/*` is served from the `ASSETS` binding (or proxied to Vite in
|
|
20
|
+
* dev via `VIEW_DEV_URL`).
|
|
21
|
+
*/
|
|
22
|
+
export interface WorkerCodegenOptions {
|
|
23
|
+
origin: string;
|
|
24
|
+
postInstall?: string;
|
|
25
|
+
requires: readonly string[];
|
|
26
|
+
hasViews: boolean;
|
|
27
|
+
hasFunctions: boolean;
|
|
28
|
+
hasClient: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function generateWorkerEntry(opts: WorkerCodegenOptions): string;
|
|
31
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IAC3B,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,CAyEtE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen for the Cloudflare Worker entry (`.astrale/worker.gen.ts`).
|
|
3
|
+
*
|
|
4
|
+
* The dev writes only schema/methods/views/functions; this generates the
|
|
5
|
+
* `export default { fetch }` plumbing the adapter owns. Key properties:
|
|
6
|
+
*
|
|
7
|
+
* • Per-request `url` = the live serving origin (`scheme://host`). It is passed
|
|
8
|
+
* only to `createRemoteServer({ url })`; the SDK stamps every
|
|
9
|
+
* `binding.remoteUrl` from that single value at spec-build time — so deployed
|
|
10
|
+
* Function nodes point back at THIS worker with zero hardcoded URLs.
|
|
11
|
+
* • Self-issued JWKS: a Worker can't fetch its own hostname; the verifier
|
|
12
|
+
* resolves a credential whose `iss` is this worker from the in-memory key,
|
|
13
|
+
* so no self-fetch is attempted (the worker's JWKS is served as a normal
|
|
14
|
+
* route by createRemoteServer).
|
|
15
|
+
* • Self-binding (autobinding): when a handler calls back into its OWN domain
|
|
16
|
+
* (`ctx.callRemote`), the redirect resolves to this worker's own host — a
|
|
17
|
+
* forbidden same-host subrequest. We route those through the `SELF` service
|
|
18
|
+
* binding instead.
|
|
19
|
+
* • SPA: `/ui/*` is served from the `ASSETS` binding (or proxied to Vite in
|
|
20
|
+
* dev via `VIEW_DEV_URL`).
|
|
21
|
+
*/
|
|
22
|
+
export function generateWorkerEntry(opts) {
|
|
23
|
+
const optionalImports = [
|
|
24
|
+
opts.hasViews ? `import { views } from '../views'` : `const views = undefined`,
|
|
25
|
+
opts.hasFunctions ? `import { functions } from '../functions'` : `const functions = undefined`,
|
|
26
|
+
].join('\n');
|
|
27
|
+
const postInstallLine = opts.postInstall !== undefined
|
|
28
|
+
? `const POST_INSTALL = ${JSON.stringify(opts.postInstall)}`
|
|
29
|
+
: `const POST_INSTALL = undefined`;
|
|
30
|
+
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
31
|
+
// Regenerated on every \`astrale-domain dev|deploy\`. Edit schema/methods/views
|
|
32
|
+
// instead. (origin: ${opts.origin})
|
|
33
|
+
import { defineRemoteDomain } from '@astrale-os/sdk'
|
|
34
|
+
import { createWorkerEntry } from '@astrale-os/sdk/server'
|
|
35
|
+
|
|
36
|
+
import { schema } from '../schema'
|
|
37
|
+
import { methods } from '../methods'
|
|
38
|
+
${optionalImports}
|
|
39
|
+
import { PRIVATE_JWK } from './identity'
|
|
40
|
+
|
|
41
|
+
const REQUIRES = ${JSON.stringify(opts.requires)}
|
|
42
|
+
${postInstallLine}
|
|
43
|
+
|
|
44
|
+
interface Env {
|
|
45
|
+
WORKER_URL?: string
|
|
46
|
+
ASSETS?: { fetch(request: Request): Promise<Response> }
|
|
47
|
+
SELF?: { fetch(request: Request): Promise<Response> }
|
|
48
|
+
VIEW_DEV_URL?: string
|
|
49
|
+
[key: string]: unknown
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// All the shared worker plumbing — JWKS self-fetch shim, SELF-binding routing,
|
|
53
|
+
// per-URL app cache, canonical iss resolution — lives in createWorkerEntry.
|
|
54
|
+
export default createWorkerEntry<Env>({
|
|
55
|
+
// The worker's serving URL = its identity (iss). Prefer the adapter-injected
|
|
56
|
+
// WORKER_URL (pins one canonical host for routed deploys, so iss stays stable
|
|
57
|
+
// even when also reachable via *.workers.dev); fall back to the per-request
|
|
58
|
+
// host for dev / workers.dev-only (single-host → it IS the canonical URL).
|
|
59
|
+
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
|
+
},
|
|
90
|
+
})
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/codegen/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH,MAAM,UAAU,mBAAmB,CAAC,IAA0B;IAC5D,MAAM,eAAe,GAAG;QACtB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,yBAAyB;QAC9E,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,0CAA0C,CAAC,CAAC,CAAC,6BAA6B;KAC/F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEZ,MAAM,eAAe,GACnB,IAAI,CAAC,WAAW,KAAK,SAAS;QAC5B,CAAC,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;QAC5D,CAAC,CAAC,gCAAgC,CAAA;IAEtC,OAAO;;uBAEc,IAAI,CAAC,MAAM;;;;;;EAMhC,eAAe;;;mBAGE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;EAC9C,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDhB,CAAA;AACD,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen for the Worker config (`.astrale/wrangler.gen.jsonc`). This is the
|
|
3
|
+
* `wrangler.jsonc` that used to be hand-copied into every domain — now an
|
|
4
|
+
* internal adapter detail the dev never sees.
|
|
5
|
+
*
|
|
6
|
+
* `main` is `./worker.gen.ts` (same dir). `assets.directory` is `../dist-client`
|
|
7
|
+
* (the project's Vite build). A `SELF` service binding enables autobinding
|
|
8
|
+
* (a handler calling back into its own domain). Custom-domain deploys attach a
|
|
9
|
+
* `custom_domain` route; otherwise the Worker ships to `*.workers.dev`.
|
|
10
|
+
*
|
|
11
|
+
* A dev's `params.wrangler` escape hatch is deep-merged on top of this base
|
|
12
|
+
* (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
|
|
13
|
+
*/
|
|
14
|
+
export interface WranglerCodegenOptions {
|
|
15
|
+
workerName: string;
|
|
16
|
+
/** Full custom hostname for a routed deploy (e.g. 'crm.acme.dev'). */
|
|
17
|
+
route?: string;
|
|
18
|
+
/** Whether the project has a built client SPA to serve under /ui/*. */
|
|
19
|
+
hasClient: boolean;
|
|
20
|
+
/** Plain (non-secret) vars to bake in. */
|
|
21
|
+
vars?: Record<string, string>;
|
|
22
|
+
/** Add the SELF service binding (autobinding). */
|
|
23
|
+
selfBinding: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Raw wrangler config to deep-merge over the generated base — the escape
|
|
26
|
+
* hatch for extra bindings (KV, R2, D1, queues, service bindings, extra
|
|
27
|
+
* `compatibility_flags`, cron `triggers`, …). Arrays concat; new keys are
|
|
28
|
+
* added as-is. The adapter-owned keys `name`, `main`, `assets`, `routes` are
|
|
29
|
+
* rejected (throws) — use `workerName` / `route` instead.
|
|
30
|
+
*/
|
|
31
|
+
wrangler?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
|
|
34
|
+
//# sourceMappingURL=wrangler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/codegen/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,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;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAID,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,MAAM,CAiC3E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen for the Worker config (`.astrale/wrangler.gen.jsonc`). This is the
|
|
3
|
+
* `wrangler.jsonc` that used to be hand-copied into every domain — now an
|
|
4
|
+
* internal adapter detail the dev never sees.
|
|
5
|
+
*
|
|
6
|
+
* `main` is `./worker.gen.ts` (same dir). `assets.directory` is `../dist-client`
|
|
7
|
+
* (the project's Vite build). A `SELF` service binding enables autobinding
|
|
8
|
+
* (a handler calling back into its own domain). Custom-domain deploys attach a
|
|
9
|
+
* `custom_domain` route; otherwise the Worker ships to `*.workers.dev`.
|
|
10
|
+
*
|
|
11
|
+
* A dev's `params.wrangler` escape hatch is deep-merged on top of this base
|
|
12
|
+
* (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
|
|
13
|
+
*/
|
|
14
|
+
import { deepMergeConfig } from './merge';
|
|
15
|
+
const COMPATIBILITY_DATE = '2025-03-01';
|
|
16
|
+
export function generateWranglerConfig(opts) {
|
|
17
|
+
const config = {
|
|
18
|
+
name: opts.workerName,
|
|
19
|
+
main: './worker.gen.ts',
|
|
20
|
+
compatibility_date: COMPATIBILITY_DATE,
|
|
21
|
+
compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],
|
|
22
|
+
workers_dev: true,
|
|
23
|
+
observability: { enabled: true },
|
|
24
|
+
};
|
|
25
|
+
if (opts.route) {
|
|
26
|
+
config.routes = [{ pattern: opts.route, custom_domain: true }];
|
|
27
|
+
}
|
|
28
|
+
if (opts.hasClient) {
|
|
29
|
+
config.assets = {
|
|
30
|
+
directory: '../dist-client',
|
|
31
|
+
binding: 'ASSETS',
|
|
32
|
+
not_found_handling: 'single-page-application',
|
|
33
|
+
run_worker_first: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (opts.selfBinding) {
|
|
37
|
+
config.services = [{ binding: 'SELF', service: opts.workerName }];
|
|
38
|
+
}
|
|
39
|
+
if (opts.vars && Object.keys(opts.vars).length > 0) {
|
|
40
|
+
config.vars = opts.vars;
|
|
41
|
+
}
|
|
42
|
+
const merged = opts.wrangler ? mergeUserConfig(config, opts.wrangler) : config;
|
|
43
|
+
return JSON.stringify(merged, null, 2) + '\n';
|
|
44
|
+
}
|
|
45
|
+
/** Keys the adapter owns and won't let `params.wrangler` clobber. */
|
|
46
|
+
const ADAPTER_OWNED_KEYS = ['name', 'main', 'assets', 'routes'];
|
|
47
|
+
/**
|
|
48
|
+
* Deep-merge the dev's raw wrangler overlay over the generated config, after
|
|
49
|
+
* refusing any attempt to override an adapter-owned key. Throwing (rather than
|
|
50
|
+
* silently dropping) keeps a stray `main` from breaking the Worker unnoticed.
|
|
51
|
+
*/
|
|
52
|
+
function mergeUserConfig(base, user) {
|
|
53
|
+
const collisions = ADAPTER_OWNED_KEYS.filter((k) => k in user);
|
|
54
|
+
if (collisions.length > 0) {
|
|
55
|
+
throw new Error(`wrangler: cannot override adapter-managed key(s): ${collisions.join(', ')}. ` +
|
|
56
|
+
'Use `workerName` for the worker name and `route` for routing; ' +
|
|
57
|
+
'`main` and `assets` are generated by the adapter.');
|
|
58
|
+
}
|
|
59
|
+
return deepMergeConfig(base, user);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=wrangler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/codegen/wrangler.ts"],"names":[],"mappings":"AAAA;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AC,CAAC,CAAC,CAAC,MAAM,CAAA;IAC9E,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAA;AAC/C,CAAC;AAED,qEAAqE;AACrE,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAE/D;;;;GAIG;AACH,SAAS,eAAe,CACtB,IAA6B,EAC7B,IAA6B;IAE7B,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAA;IAC9D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qDAAqD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC5E,gEAAgE;YAChE,mDAAmD,CACtD,CAAA;IACH,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACpC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@astrale-os/adapter-cloudflare` — deploy an Astrale domain as a standalone
|
|
3
|
+
* Cloudflare Worker.
|
|
4
|
+
*
|
|
5
|
+
* import { cloudflare } from '@astrale-os/adapter-cloudflare'
|
|
6
|
+
*
|
|
7
|
+
* adapter: cloudflare({
|
|
8
|
+
* dev: { secrets: '.env.dev' },
|
|
9
|
+
* prod: { route: 'crm.acme.dev', secrets: '.env.prod' },
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* `dev` runs `wrangler dev` locally; an env with no `route` ships to
|
|
13
|
+
* `*.workers.dev`; an env with a `route` ships to that custom domain.
|
|
14
|
+
*/
|
|
15
|
+
export { astrale } from './astrale';
|
|
16
|
+
export { cloudflare } from './cloudflare';
|
|
17
|
+
export type { AstraleParams, CloudflareParams } from './params';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@astrale-os/adapter-cloudflare` — deploy an Astrale domain as a standalone
|
|
3
|
+
* Cloudflare Worker.
|
|
4
|
+
*
|
|
5
|
+
* import { cloudflare } from '@astrale-os/adapter-cloudflare'
|
|
6
|
+
*
|
|
7
|
+
* adapter: cloudflare({
|
|
8
|
+
* dev: { secrets: '.env.dev' },
|
|
9
|
+
* prod: { route: 'crm.acme.dev', secrets: '.env.prod' },
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* `dev` runs `wrangler dev` locally; an env with no `route` ships to
|
|
13
|
+
* `*.workers.dev`; an env with a `route` ships to that custom domain.
|
|
14
|
+
*/
|
|
15
|
+
export { astrale } from './astrale';
|
|
16
|
+
export { cloudflare } from './cloudflare';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/params.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `CloudflareParams` — the provider-typed config for the Cloudflare adapter.
|
|
3
|
+
*
|
|
4
|
+
* One type covers every env; per-env differences are just optional fields. The
|
|
5
|
+
* same `{ dev, prod, canary, … }` map a developer writes in `astrale.config.ts`
|
|
6
|
+
* is `Record<string, CloudflareParams>`.
|
|
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>
|
|
12
|
+
*/
|
|
13
|
+
export interface CloudflareParams {
|
|
14
|
+
/**
|
|
15
|
+
* Custom route / hostname for a routed deploy, e.g. `'crm.acme.dev'`. Omit to
|
|
16
|
+
* deploy to `*.workers.dev`. Ignored by local `wrangler dev` (URL is
|
|
17
|
+
* localhost) but still used as the placeholder base domain there.
|
|
18
|
+
*/
|
|
19
|
+
route?: string;
|
|
20
|
+
/** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
|
|
21
|
+
secrets?: string;
|
|
22
|
+
/** Local dev port for `wrangler dev`. Default 8787. */
|
|
23
|
+
port?: number;
|
|
24
|
+
/** Override the Worker name. Default: derived from the domain origin. */
|
|
25
|
+
workerName?: string;
|
|
26
|
+
/** Run `wrangler dev --remote` (edge isolate) instead of local workerd. */
|
|
27
|
+
remote?: boolean;
|
|
28
|
+
/** Extra plain (non-secret) vars to inject as Worker vars. */
|
|
29
|
+
vars?: Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Escape hatch: raw wrangler config deep-merged over the generated base. Use
|
|
32
|
+
* it to declare extra bindings the adapter has no typed field for — KV, R2,
|
|
33
|
+
* D1, queues, service bindings, extra `compatibility_flags`, cron `triggers`,
|
|
34
|
+
* Hyperdrive, etc.
|
|
35
|
+
*
|
|
36
|
+
* wrangler: {
|
|
37
|
+
* kv_namespaces: [{ binding: 'CACHE', id: '<kv-id>' }],
|
|
38
|
+
* r2_buckets: [{ binding: 'FILES', bucket_name: 'my-bucket' }],
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* The merge is additive: arrays concat (so your `services` keep the adapter's
|
|
42
|
+
* `SELF` binding and your `compatibility_flags` keep `nodejs_compat`); new
|
|
43
|
+
* keys are added as-is. The adapter-owned keys `name`, `main`, `assets`,
|
|
44
|
+
* `routes` are rejected — use `workerName` and `route` instead. Avoid
|
|
45
|
+
* the reserved binding names `SELF` and `ASSETS`. Durable Objects need extra
|
|
46
|
+
* worker-entry codegen and aren't supported through this field yet.
|
|
47
|
+
*/
|
|
48
|
+
wrangler?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
/** Params for the Astrale-managed adapter (`astrale(envs)`). */
|
|
51
|
+
export interface AstraleParams {
|
|
52
|
+
/** Target instance slug the domain installs onto (e.g. `'bryan-e2e5'`). */
|
|
53
|
+
instance: string;
|
|
54
|
+
/** Catalog package name. Default: the origin's first DNS label. */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** Admin kernel URL the publish calls target. Default the platform admin. */
|
|
57
|
+
adminUrl?: string;
|
|
58
|
+
/** Routing region of the `.svc` service URL. Default `'eu'`. */
|
|
59
|
+
region?: string;
|
|
60
|
+
/** CLI identity (`--as`) for the publish calls. Default: the CLI's active identity. */
|
|
61
|
+
identity?: string;
|
|
62
|
+
/** Gitignored secrets file — injected ONLY into local `watch` (managed services receive no secrets yet). */
|
|
63
|
+
secrets?: string;
|
|
64
|
+
/** Local dev port for `wrangler dev`. Default 8787. */
|
|
65
|
+
port?: number;
|
|
66
|
+
/** Extra plain vars for local `watch`. */
|
|
67
|
+
vars?: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4GAA4G;IAC5G,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9B"}
|
package/dist/params.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 instance 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
|
+
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
24
|
+
export declare function normalizeLocal(url: string, port: number): string;
|
|
25
|
+
//# sourceMappingURL=parse-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-output.d.ts","sourceRoot":"","sources":["../src/parse-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW/E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI/E;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAShE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Local dev URL from `wrangler dev` output, normalized to an origin on the given
|
|
10
|
+
* port. Returns `undefined` when the output hasn't reported readiness yet.
|
|
11
|
+
*
|
|
12
|
+
* The fallback (when no explicit "Ready on" line) only accepts a localhost URL
|
|
13
|
+
* on the EXPECTED port — wrangler may print unrelated localhost URLs (e.g. an
|
|
14
|
+
* inspector/devtools endpoint on a different port) before readiness, and taking
|
|
15
|
+
* one of those would point `astrale instance install <url>` at a dead endpoint.
|
|
16
|
+
*/
|
|
17
|
+
export function parseDevReadyUrl(text, port) {
|
|
18
|
+
const ready = READY_RE.exec(text);
|
|
19
|
+
if (ready)
|
|
20
|
+
return normalizeLocal(ready[1], port);
|
|
21
|
+
// `port` is a number, so it's safe to interpolate into the pattern. The
|
|
22
|
+
// negative lookahead stops `:8787` from matching inside `:87870`.
|
|
23
|
+
const localhostOnPort = new RegExp(`(https?://(?:localhost|127\\.0\\.0\\.1):${port})(?![0-9])`, 'i');
|
|
24
|
+
const m = localhostOnPort.exec(text);
|
|
25
|
+
return m ? normalizeLocal(m[1], port) : undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Authoritative public URL from `wrangler deploy` output. A custom-domain
|
|
29
|
+
* `route` wins (the deploy attaches it); otherwise the printed `*.workers.dev`
|
|
30
|
+
* URL. Returns `undefined` when neither is available (caller surfaces the raw
|
|
31
|
+
* output).
|
|
32
|
+
*/
|
|
33
|
+
export function parseDeployUrl(text, route) {
|
|
34
|
+
if (route)
|
|
35
|
+
return `https://${route.replace(/\/.*$/, '')}`;
|
|
36
|
+
const m = WORKERS_DEV_RE.exec(text);
|
|
37
|
+
return m ? m[1] : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
40
|
+
export function normalizeLocal(url, port) {
|
|
41
|
+
try {
|
|
42
|
+
const u = new URL(url);
|
|
43
|
+
if (u.hostname === '0.0.0.0')
|
|
44
|
+
u.hostname = 'localhost';
|
|
45
|
+
if (!u.port)
|
|
46
|
+
u.port = String(port);
|
|
47
|
+
return u.origin;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return `http://localhost:${port}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=parse-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-output.js","sourceRoot":"","sources":["../src/parse-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,QAAQ,GAAG,yDAAyD,CAAA;AAC1E,MAAM,cAAc,GAAG,mCAAmC,CAAA;AAE1D;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAY;IACzD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjC,IAAI,KAAK;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAA;IACjD,wEAAwE;IACxE,kEAAkE;IAClE,MAAM,eAAe,GAAG,IAAI,MAAM,CAChC,2CAA2C,IAAI,YAAY,EAC3D,GAAG,CACJ,CAAA;IACD,MAAM,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,KAAc;IACzD,IAAI,KAAK;QAAE,OAAO,WAAW,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAA;IACzD,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7B,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,IAAY;IACtD,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;YAAE,CAAC,CAAC,QAAQ,GAAG,WAAW,CAAA;QACtD,IAAI,CAAC,CAAC,CAAC,IAAI;YAAE,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,OAAO,CAAC,CAAC,MAAM,CAAA;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,oBAAoB,IAAI,EAAE,CAAA;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
export interface DevHandle {
|
|
10
|
+
url: string;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function runWranglerDev(args: {
|
|
14
|
+
projectDir: string;
|
|
15
|
+
configPath: string;
|
|
16
|
+
port: number;
|
|
17
|
+
remote: boolean;
|
|
18
|
+
onReload: () => void;
|
|
19
|
+
onLog?: (line: string) => void;
|
|
20
|
+
}): Promise<DevHandle>;
|
|
21
|
+
export interface DeployArgs {
|
|
22
|
+
configPath: string;
|
|
23
|
+
/** SELF-less config for the first-deploy two-pass (see `deployWithSelfFallback`). */
|
|
24
|
+
fallbackConfigPath?: string;
|
|
25
|
+
/** The worker's own name, to scope the self-binding-missing detection. */
|
|
26
|
+
workerName?: string;
|
|
27
|
+
route?: string;
|
|
28
|
+
onLog?: (line: string) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function runWranglerDeploy(args: DeployArgs & {
|
|
31
|
+
projectDir: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
url: string;
|
|
34
|
+
raw: string;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Deploy with a one-time SELF-binding first-deploy recovery. A fresh worker that
|
|
38
|
+
* declares a `services: SELF` binding can't deploy (its own script doesn't exist
|
|
39
|
+
* yet); on THAT specific failure we deploy the SELF-less fallback to create the
|
|
40
|
+
* script, then redeploy WITH SELF so autobinding works. Steady state (every
|
|
41
|
+
* deploy after the first) is a single pass. The `deploy` runner is injected so
|
|
42
|
+
* the orchestration is unit-testable without shelling out.
|
|
43
|
+
*/
|
|
44
|
+
export declare function deployWithSelfFallback(deploy: (configPath: string) => Promise<{
|
|
45
|
+
code: number;
|
|
46
|
+
out: string;
|
|
47
|
+
}>, args: DeployArgs): Promise<{
|
|
48
|
+
url: string;
|
|
49
|
+
raw: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* True when wrangler failed specifically because the worker's OWN `SELF` service
|
|
53
|
+
* binding can't resolve yet (first deploy of a fresh script). Requires the
|
|
54
|
+
* worker name so an unrelated missing-service error doesn't trigger the two-pass.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isSelfBindingMissing(out: string, workerName?: string): boolean;
|
|
57
|
+
export declare function bulkPutSecrets(args: {
|
|
58
|
+
projectDir: string;
|
|
59
|
+
configPath: string;
|
|
60
|
+
secrets: Record<string, string>;
|
|
61
|
+
onLog?: (line: string) => void;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Build the single-module worker bundle WITHOUT deploying — `wrangler deploy
|
|
65
|
+
* --dry-run --outdir` (no Cloudflare auth required). Returns the path of the
|
|
66
|
+
* bundled .js module (the managed adapter publishes its bytes).
|
|
67
|
+
*/
|
|
68
|
+
export declare function runWranglerBundle(args: {
|
|
69
|
+
projectDir: string;
|
|
70
|
+
configPath: string;
|
|
71
|
+
outDir: string;
|
|
72
|
+
onLog?: (line: string) => void;
|
|
73
|
+
}): Promise<string>;
|
|
74
|
+
//# sourceMappingURL=wrangler-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler-cli.d.ts","sourceRoot":"","sources":["../src/wrangler-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE;IACzC,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC/B,GAAG,OAAO,CAAC,SAAS,CAAC,CAkErB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,qFAAqF;IACrF,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,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