cloudflare library

Cloudflare Workers adapters, typed bindings, and Fetch entrypoints.

The public types in this library keep Cloudflare's JavaScript objects behind a host-neutral Dart boundary. Application code can use the typed bindings without importing package:web or dart:js_interop.

Classes

CloudflareCache
The Cache API for a Cloudflare edge cache namespace.
CloudflareContainer
Low-level Container controls exposed by a Container-backed Durable Object.
CloudflareContainerBinding
A binding for a Cloudflare Container namespace.
CloudflareContainerExecOptions
Options used when executing a command in a running Container.
CloudflareContainerExecOutput
Buffered output returned by a Container process.
CloudflareContainerInstance
A request-facing Container instance.
CloudflareContainerProcess
A process started inside a Cloudflare Container.
CloudflareContainerStartOptions
Options used when starting a Container process.
CloudflareContainerTcpPort
A TCP port exposed by a Container.
CloudflareDurableObject
A Durable Object implementation constructed for a Worker request.
CloudflareDurableObjectId
A Durable Object identifier.
CloudflareDurableObjectNamespace
A Durable Object namespace binding.
CloudflareDurableObjectSqlResult
A SQLite statement result. Methods mirror the current Workers SQL API.
CloudflareDurableObjectSqlStorage
The synchronous SQLite API exposed by a SQLite-backed Durable Object.
CloudflareDurableObjectState
State available to a Durable Object instance.
CloudflareDurableObjectStorage
Legacy and SQLite-backed Durable Object storage.
CloudflareDurableObjectStore
A sharded, SQLite-backed Store implemented with Durable Objects.
CloudflareDurableObjectStoreObject
A SQLite-backed Durable Object that serves CloudflareDurableObjectStore.
CloudflareDurableObjectStub
A Durable Object request stub.
CloudflareEnvironment
A Cloudflare Worker environment binding set.
CloudflareExecutionContext
The request execution context supplied by a Cloudflare Worker.
CloudflareJobQueue
Publishes Routed jobs to one Cloudflare Queue binding.
CloudflareKvNamespace
A Cloudflare KV namespace binding.
CloudflareQueue
A Cloudflare Queue producer binding.
CloudflareQueueBatch
A batch delivered to a Cloudflare Queue consumer Worker.
CloudflareQueueDelivery
One message delivered to a Cloudflare Queue consumer Worker.
CloudflareQueueMessage
Configuration or result data used by the Cloudflare API.
CloudflareQueueMetrics
Configuration or result data used by the Cloudflare API.
CloudflareQueueSendResult
Configuration or result data used by the Cloudflare API.
CloudflareR2Bucket
An R2 object-storage bucket binding.
CloudflareR2Filesystem
A storage_fs filesystem backed by a native Cloudflare R2 binding.
CloudflareR2ListOptions
Configuration or result data used by the Cloudflare API.
CloudflareR2ListResult
Configuration or result data used by the Cloudflare API.
CloudflareR2Object
Metadata and body returned by an R2 bucket operation.
CloudflareR2PutOptions
Configuration or result data used by the Cloudflare API.
CloudflareRequest
A Fetch request represented without exposing the host's JavaScript types.
CloudflareResponse
A Fetch response represented without exposing the host's JavaScript types.
CloudflareScheduledEvent
A Cloudflare Cron Trigger invocation.
CloudflareScheduleStore
A durable schedule occurrence ledger backed by an atomic Store and lock.
CloudflareSecretsStoreBinding
An account-level secret exposed to a Worker through Secrets Store.
CloudflareServiceBinding
A Worker-to-Worker service binding.
CloudflareWebSocket
A WebSocket managed by the Cloudflare Durable Object hibernation API.
CloudflareWebSocketPair
The client/server WebSocket pair used to create a Fetch upgrade response.
CloudflareWorkflow
A Cloudflare Workflow binding.
CloudflareWorkflowCreateOptions
Options for creating a Workflow instance.
CloudflareWorkflowError
A Workflow error returned as part of instance status.
CloudflareWorkflowInstance
A running Workflow instance.
CloudflareWorkflowRestartOptions
Options for restarting a Workflow instance.
CloudflareWorkflowRollback
Rollback state returned as part of Workflow instance status.
CloudflareWorkflowStatus
The current status of a Workflow instance.
CloudflareWorkflowStepReference
Identifies a Workflow step when restarting an instance.
CloudflareWorkflowTerminateOptions
Options for terminating a Workflow instance.
FetchRequestView
Host-neutral view of a Fetch-style request.
FetchResponseView
Host-neutral response value produced for Fetch-style hosts.
FetchWebSocketUpgrade
Defines the public contract for this host integration.
RoutedNodeCapabilities
Capabilities declared by one host invocation.
RoutedNodeContext
Runtime-scoped host context carried through a Routed request.
RoutedNodeExtension
A typed lookup for host-owned request context values.
RoutedNodeLifecycleEvent
Host lifecycle event published through Routed's existing EventManager.
RoutedNodeRuntimeInfo
Common runtime metadata exposed by a host adapter.

Enums

CloudflareContainerStreamMode
Controls whether a Container process stream is captured. Controls how a Container process stream is handled.
CloudflareQueueContentType
The serialization format used for a queued message body.
RoutedNodeEntryModel
Whether a host owns a long-lived listener or invokes a fetch export.
RoutedNodeLifecyclePhase
Lifecycle phases emitted by a routed_node host.
RoutedNodeRuntime
Runtime families supported by routed_node.

Constants

cloudflareCapabilities → const RoutedNodeCapabilities
Capabilities advertised by the Cloudflare Workers Fetch adapter.
cloudflareDurableObjectRegistryName → const String
Name of the JavaScript registry consumed by a Worker module wrapper.

Functions

cloudflareCache({String? name}) Future<CloudflareCache>
Returns the Cloudflare Cache API namespace.
cloudflareEnvironmentOf(EngineContext context) CloudflareEnvironment?
Returns the Worker environment associated with context, when present.
cloudflareExecutionContextOf(EngineContext context) CloudflareExecutionContext?
Returns the Worker execution context associated with context, when present.
cloudflareRequestOf(EngineContext context) CloudflareRequest?
Returns the native Fetch request associated with context, when present.
cloudflareTextBinding(CloudflareEnvironment environment, String name) String
Reads a text or secret Worker binding without exposing JavaScript interop.
cloudflareWebSocketPair() CloudflareWebSocketPair
Creates a Cloudflare WebSocket pair on a JavaScript Worker runtime.
createCloudflareRequest(String url, {String method = 'GET', Map<String, String> headers = const <String, String>{}, Object? body}) CloudflareRequest
Performs the createCloudflareRequest operation.
defineCloudflareDurableObjects(Map<String, CloudflareDurableObjectFactory> factories) → void
Registers Durable Object factories for a JavaScript Worker module wrapper.
defineCloudflareFetch(Object engine) → void
Installs the Cloudflare Fetch bootstrap function.
defineCloudflareFetchAsync(Future<Engine> engine) → void
Installs a Cloudflare Fetch export from an asynchronously-built engine.
defineCloudflareFetchFactoryAsync(Future<Engine> factory()) → void
Installs a Cloudflare Fetch entry whose engine is initialized lazily per Worker isolate, on the first request.
defineCloudflareFetchFactoryWithEnvironmentAsync(Future<Engine> factory(CloudflareEnvironment environment)) → void
Installs a lazy Cloudflare Fetch entry whose engine is built with the Worker environment and its typed D1, KV, R2, or secret bindings.
defineCloudflareJobsQueueExportFactoryWithEnvironmentAsync(Future<JobConsumer> factory(CloudflareEnvironment environment)) → void
Installs the standard Cloudflare Queue export for Routed jobs.
defineCloudflareQueueExport(CloudflareQueueHandler handler) → Never
VM stub for a JavaScript Worker Queue consumer export.
defineCloudflareScheduledExport(CloudflareScheduledHandler handler) → Never
VM stub for a JavaScript Worker Cron Trigger export.
defineCloudflareSchedulerExportFactoryWithEnvironmentAsync(Future<RoutedScheduler> factory(CloudflareEnvironment environment)) → void
Installs a Cloudflare Cron Trigger that evaluates a Routed scheduler.
defineFetchExport(String runtime, Engine engine, {required RoutedNodeCapabilities capabilities, String name = '__routed_fetch__'}) → Never
VM stub for JavaScript Fetch exports.
defineFetchExportAsync(String runtime, Future<Engine> engineFuture, {required RoutedNodeCapabilities capabilities, String name = '__routed_fetch__'}) → Never
VM stub for asynchronous JavaScript Fetch exports.
defineFetchExportFactoryAsync(String runtime, Future<Engine> engineFactory(), {required RoutedNodeCapabilities capabilities, String name = '__routed_fetch__'}) → Never
VM stub for lazy asynchronous JavaScript Fetch exports.
defineFetchExportFactoryWithEnvironmentAsync(String runtime, Future<Engine> engineFactory(Object? environment), {required RoutedNodeCapabilities capabilities, String name = '__routed_fetch__'}) → Never
VM stub for a lazy Fetch export that receives the host environment.
dispatchFetchConnection(Engine engine, FetchRequestView request, ResponseAdapter response, {required RoutedNodeRuntimeInfo runtime, Uri? baseUri, Future<FetchWebSocketUpgrade> acceptWebSocket()?}) Future<void>
Dispatches a Fetch-style request through the streaming adapter path.
dispatchFetchExchange(Engine engine, FetchRequestView request, {required RoutedNodeRuntimeInfo runtime, Uri? baseUri}) Future<FetchResponseView>
Dispatches a Fetch-style request through Routed's buffered portable path.
openCloudflareD1(CloudflareEnvironment environment, {String binding = 'DB', String name = 'default', ModelRegistry? registry, ScopeRegistry? scopeRegistry, Map<String, ValueCodec> codecs = const {}, bool logging = false, String? database, String tablePrefix = '', String? defaultSchema, String carbonTimezone = 'UTC', String carbonLocale = 'en_US', bool enableNamedTimezones = false, List<DriverExtension> driverExtensions = const [], List<QueryInterceptor> interceptors = const []}) Future<OrmDatabase>
Opens an Ormed database from a native Cloudflare D1 binding.
portableRequestFromFetch(FetchRequestView request, {Uri? baseUri}) → PortableRequest
Converts a Fetch-style request into the core portable request contract.
processCloudflareJobBatch(CloudflareQueueBatch batch, JobConsumer consumer) Future<void>
Runs a Routed consumer against one Cloudflare Queue delivery batch.
processCloudflareScheduleTick(CloudflareScheduledEvent event, RoutedScheduler scheduler) Future<ScheduleTickReport>
Runs a Routed scheduler from one Cloudflare scheduled invocation.
publishRoutedNodeLifecycle(Engine engine, RoutedNodeLifecycleEvent event) → void
Publishes a host lifecycle event when the engine has an EventManager.

Typedefs

CloudflareD1Database = D1DatabaseBinding
Cloudflare D1 database binding, provided by package:ormed_d1.
CloudflareD1DatabaseSession = D1DatabaseSessionBinding
Cloudflare D1 session binding, provided by package:ormed_d1.
CloudflareD1ExecResult = D1ExecResult
Cloudflare D1 exec result, provided by package:ormed_d1.
CloudflareD1Meta = D1Meta
Cloudflare D1 metadata, provided by package:ormed_d1.
CloudflareD1PreparedStatement = D1PreparedStatementBinding
Cloudflare D1 prepared statement, provided by package:ormed_d1.
CloudflareD1Result<T> = D1Result<T>
Cloudflare D1 result, provided by package:ormed_d1.
CloudflareD1RowDecoder<T> = D1RowDecoder<T>
Cloudflare's D1 row decoder, provided by package:ormed_d1.
CloudflareDurableObjectFactory = CloudflareDurableObject Function(CloudflareDurableObjectState state, CloudflareEnvironment env)
Constructs a Durable Object from the state and environment supplied by Cloudflare.
CloudflareJsonDecoder<T> = T Function(Object? value)
Decodes a JSON value received from a Cloudflare request or response.
CloudflareQueueHandler = FutureOr<void> Function(CloudflareQueueBatch batch, CloudflareEnvironment environment, CloudflareExecutionContext context)
Callback invoked for one Cloudflare Queue batch.
CloudflareScheduledHandler = FutureOr<void> Function(CloudflareScheduledEvent event, CloudflareEnvironment environment, CloudflareExecutionContext context)
Callback invoked by a Cloudflare Cron Trigger.
CloudflareWorkerBinding = CloudflareServiceBinding
A Worker service binding, named after Cloudflare's Worker terminology.