Conversation
|
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-wrangler-7098You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7098/npm-package-wrangler-7098Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-wrangler-7098 dev path/to/script.jsAdditional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-create-cloudflare-7098 --no-auto-updatenpm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-kv-asset-handler-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-miniflare-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-pages-shared-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-vitest-pool-workers-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workers-editor-shared-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workers-shared-7098npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workflows-shared-7098Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
| const EXTERNAL_SERVICE_RECEIVER_SCRIPT = ` | ||
| \n;; ${/* this script needs to be concatenated with the user's script :( -- use this to avoid ASI syntax errors*/ ""} | ||
| import { WorkerEntrypoint as __Wrangler__LocalOnly__WorkerEntrypoint } from "cloudflare:workers"; | ||
| export class ${EXTERNAL_SERVICE_RECEIVER_NAME} extends __Wrangler__LocalOnly__WorkerEntrypoint { | ||
| async proxyMethod({ bindingName, doId, method, args }) { | ||
| const ns = this.env[bindingName]; | ||
| const stub = ns.get(ns.idFromString(doId)); | ||
| return stub[method](...args); | ||
| } | ||
| } | ||
| `; |
There was a problem hiding this comment.
This script is added to the user's script – not a separate service as the previous implementation did – so we can bind to it as a regular external entrypoint
This may sound scary but I've taken care to use long+clear names to avoid clashing with user variables in scope and that explain their purpose so if a user ever does discover them they will understand its: (a) injected by wrangler and (b) in local code only, not deployed code
There was a problem hiding this comment.
We could avoid this if we could introduce a concept to the dev registry of an entrypoint within a worker[1] within a worker[2]
[1] miniflare subworker
[2] dev registry worker (user worker)
| // redeclare internal durable object bindings for use by __Wrangler__LocalOnly__ExternalDurableObjectsReceiver | ||
| ...internalObjects.map(({ class_name, script_name }) => { | ||
| const useSQLite = classNameToUseSQLite.get(class_name); | ||
| const bindingName = getIdentifier( | ||
| `__Wrangler__LocalOnly__DurableObject__${class_name}` | ||
| ); | ||
| return [ | ||
| bindingName, | ||
| { | ||
| className: class_name, | ||
| useSQLite, | ||
| script_name, | ||
| }, | ||
| ]; | ||
| }), |
There was a problem hiding this comment.
These bindings are also added to the user's worker and on their env object but, again, I've taken care to make long+clear names for the same reasons as above
| // A lot of the fixture tests are extremely flaky because of the dev registry | ||
| // Retry tests by default so that only real errors are reported | ||
| retry: 2, | ||
| retry: 0, |
There was a problem hiding this comment.
Is this temporary? If not then perhaps update the comment?
There was a problem hiding this comment.
Temporary. Will undo
|
Closing in favour of #7251 |
Fixes #5918
Support Durable Object RPC across multiple wrangler instances
Only supports RPC method calls right now. RPC property access is coming shortly (in this PR)
The entire implementation is in src/dev/miniflare.ts