You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/development-testing/index.mdx
+108-1Lines changed: 108 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,8 @@ import {
17
17
InlineBadge,
18
18
CardGrid,
19
19
Card,
20
+
Type,
21
+
TypeScriptExample,
20
22
} from"~/components";
21
23
22
24
Cloudflare Workers offers three distinct development modes to build, run, and test your Worker code before deploying to production. Choose from [fully **local development**](/workers/development-testing/#local-development) with simulated resources, [**hybrid development**](/workers/development-testing/#hybrid-development) that combines local execution with remote resource connections, or [legacy **remote development**](/workers/development-testing/#remote-development-legacy) that runs entirely on Cloudflare's infrastructure.
@@ -320,7 +322,112 @@ If you have use-cases for connecting to any of the remote resources above, pleas
320
322
321
323
### API
322
324
323
-
TO-DO
325
+
Wrangler provides programmatic utilities to help tooling authors support hybrid development sessions when running Workers code with [Miniflare](/workers/testing/miniflare/).
326
+
327
+
Key APIs include:
328
+
329
+
-[`experimental_startMixedModeSession`](#experimental_startmixedmodesession) - starts a hybrid development session that allows interaction with remote bindings
330
+
-[`unstable_convertConfigBindingsToStartWorkerBindings`](#unstable_convertconfigbindingstostartworkerbindings) - utility for converting binding definitions
331
+
-[`experimental_maybeStartOrUpdateMixedModeSession`](#experimental_maybestartorupdatemixedmodesession) - convenience function to easily start or update a hybrid session
332
+
333
+
#### `experimental_startMixedModeSession`
334
+
335
+
This function starts a hybrid development session for a given set of bindings. It accepts options to control session behavior, including an `auth` option with your Cloudflare account ID and API token for remote binding access.
336
+
337
+
It returns an object with:
338
+
339
+
-`ready` <Typetext="Promise<void>" />: Resolves when the session is ready.
340
+
-`dispose` <Typetext="() => Promise<void>" />: Stops the session.
The `unstable_readConfig` utility returns an `Unstable_Config` object which includes the definition of the bindings included in the configuration file. These bindings definitions
347
+
are however not directly compatible with `experimental_startMixedModeSession`. It can be quite convenient to however read the binding declarations with `unstable_readConfig` and then
348
+
pass them to `experimental_startMixedModeSession`, so for this wrangler exposes `unstable_convertConfigBindingsToStartWorkerBindings` which is a simple utility to convert
349
+
the bindings in an `Unstable_Config` object into a structure that can be passed to `experimental_startMixedModeSession`.
350
+
351
+
<Asidetype="note">
352
+
This type conversion is temporary. In the future, the types will be unified so
This wrapper simplifies hybrid session management. It takes:
360
+
361
+
- The path to your Wrangler config, or an object with remote bindings.
362
+
- The current hybrid session details (or `null` if none).
363
+
364
+
It returns:
365
+
366
+
-`null` if no hybrid session is needed.
367
+
- An object with the hybrid session details if started or updated.
368
+
369
+
The function:
370
+
371
+
- based on the first argument prepares the input arguments for the hybrid session
372
+
- if there are no remote bindings to be used (nor a pre-existing hybrid session) it returns null, signaling that no hybrid session is needed
373
+
- if the details of an existing hybrid session have been provided it updates the hybrid session accordingly
374
+
- otherwise if starts a new hybrid session
375
+
- returns the hybrid session details (that can later be passed as the second argument to `experimental_maybeStartOrUpdateMixedModeSession`)
376
+
377
+
#### Example
378
+
379
+
Here's a basic example of using Miniflare with `experimental_maybeStartOrUpdateMixedModeSession` to provide a hybrid dev session. This example uses a single hardcoded KV binding.
0 commit comments