-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement automatic self-referential bindings via ctx.exports. #3447
base: main
Are you sure you want to change the base?
Conversation
3089e76
to
e228c36
Compare
The generated output of Full Type Diffdiff -r bazel-bin/types/definitions/experimental/index.d.ts types/generated-snapshot/experimental/index.d.ts
568d567
< exports: any;
diff -r bazel-bin/types/definitions/experimental/index.ts types/generated-snapshot/experimental/index.ts
573d572
< exports: any; |
I think we need to extend the typedefs for type ExportBindings<T> = {
[K in keyof T]: T[K] extends typeof DurableObject
? DurableObjectNamespace<InstanceType<T[K]>>
: T[K] extends typeof WorkerEntrypoint
? Service<InstanceType<T[K]>>
: never;
}
export abstract class WorkerEntrypoint<Env = unknown, Exports extends Record<string, unknown>>
implements Rpc.WorkerEntrypointBranded
{
[Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
protected ctx: ExecutionContext<ExportBindings<Exports>>;
// ... Similar change required for Usage:
Can bump this to a second PR when we make this non-experimental, if you like? I just wanted to jot down the definition of Edit: I just realised we're going to need a type param for |
f0d4f70
to
bdae24f
Compare
@jasnell Sorry to always assign you on everything but when I looked at the history of the files I'm modifying it's basically all me and you! |
bdae24f
to
02177f0
Compare
(Added a test for |
(Added commit to add |
fc4398e
to
9de75d7
Compare
For every top-level export, `ctx.exports` will contain a corresponding property which acts as a binding to that export. If the export is a simple object or `WorkerEntrypoint`, then the `ctx.exports` property is a service binding. If the export is a Durable Object class (and it has been configured with storage), the `ctx.exports` property is a DO namespace binding. So you can do: `ctx.exports.MyEntrypoint.someRpc()` And it calls `someRpc()` on the entrypoint named `MyEntrypoint`, as if you had called it over a service binding. This is marked experimental for now since it won't work on the edge until further changes are made to our control plane.
9de75d7
to
33cf70d
Compare
For every top-level export,
ctx.exports
will contain a corresponding property which acts as a binding to that export. If the export is a simple object orWorkerEntrypoint
, then thectx.exports
property is a service binding. If the export is a Durable Object class (and it has been configured with storage), thectx.exports
property is a DO namespace binding.So you can do:
ctx.exports.MyEntrypoint.someRpc()
And it calls
someRpc()
on the entrypoint namedMyEntrypoint
, as if you had called it over a service binding.This is marked experimental for now since it won't work on the edge until further changes are made to our control plane.