-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wrangler): add inherit bindings support (#7385)
* feat(wrangler): add inherit bindings support * add test * add changeset * rename file to bindings
- Loading branch information
1 parent
8ee835d
commit 319dae2
Showing
13 changed files
with
224 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
The `x-provision` experimental flag now support inherit bindings in deploys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { Config } from "../config"; | ||
import type { CfWorkerInit } from "./worker"; | ||
|
||
/** | ||
* A symbol to inherit a binding from the deployed worker. | ||
*/ | ||
export const INHERIT_SYMBOL = Symbol.for("inherit_binding"); | ||
|
||
export function getBindings( | ||
config: Config | undefined, | ||
options?: { | ||
pages?: boolean; | ||
} | ||
): CfWorkerInit["bindings"] { | ||
return { | ||
kv_namespaces: config?.kv_namespaces?.map((kv) => ({ | ||
...kv, | ||
id: kv.id ?? INHERIT_SYMBOL, | ||
})), | ||
send_email: options?.pages ? undefined : config?.send_email, | ||
vars: config?.vars, | ||
wasm_modules: options?.pages ? undefined : config?.wasm_modules, | ||
browser: config?.browser, | ||
ai: config?.ai, | ||
version_metadata: config?.version_metadata, | ||
text_blobs: options?.pages ? undefined : config?.text_blobs, | ||
data_blobs: options?.pages ? undefined : config?.data_blobs, | ||
durable_objects: config?.durable_objects, | ||
workflows: config?.workflows, | ||
queues: config?.queues.producers?.map((producer) => { | ||
return { binding: producer.binding, queue_name: producer.queue }; | ||
}), | ||
r2_buckets: config?.r2_buckets?.map((r2) => ({ | ||
...r2, | ||
bucket_name: r2.bucket_name ?? INHERIT_SYMBOL, | ||
})), | ||
d1_databases: config?.d1_databases.map((d1) => ({ | ||
...d1, | ||
database_id: d1.database_id ?? INHERIT_SYMBOL, | ||
})), | ||
vectorize: config?.vectorize, | ||
hyperdrive: config?.hyperdrive, | ||
services: config?.services, | ||
analytics_engine_datasets: config?.analytics_engine_datasets, | ||
dispatch_namespaces: options?.pages | ||
? undefined | ||
: config?.dispatch_namespaces, | ||
mtls_certificates: config?.mtls_certificates, | ||
pipelines: options?.pages ? undefined : config?.pipelines, | ||
logfwdr: options?.pages ? undefined : config?.logfwdr, | ||
assets: options?.pages | ||
? undefined | ||
: config?.assets?.binding | ||
? { binding: config?.assets?.binding } | ||
: undefined, | ||
unsafe: options?.pages | ||
? undefined | ||
: { | ||
bindings: config?.unsafe.bindings, | ||
metadata: config?.unsafe.metadata, | ||
capnp: config?.unsafe.capnp, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.