Interface Env

All Superinterfaces:
org.teavm.jso.JSObject

public interface Env extends org.teavm.jso.JSObject
The bindings declared in the Wrangler configuration, addressed by their binding names.

Each accessor takes the default name the plugin assigns, so a project that declared one of each never writes a name down. Declaring a type twice appends a number, and the second binding is reached by naming it.

Default binding names
DeclaredFirstSecond
kv()KVKV_2
d1()DBDB_2
r2()BLOBBLOB_2
durableObject(Counter.class)DO_COUNTERDO_COUNTER_2

Variables and secrets are readable during module evaluation, because they are values already present on the object. Anything that performs I/O is not: Cloudflare Workers forbid I/O outside a request context, so a KV read or a service call at module scope fails however it is spelled.

 public Response fetch(Request request, Env env, ExecutionCtx ctx) {
 	String cached = env.kv().get(request.getUrl());
 	if (cached != null) return Bytebox.response(cached);
 	String fresh = render(env.d1());
 	env.kv().put(request.getUrl(), fresh, 3600);
 	return Bytebox.response(fresh);
 }
Since:
1.0.0
  • Method Details

    • get

      TSObject get(String name)
      Reads one binding by name, whatever its type.
      Parameters:
      name - the binding name
      Returns:
      the binding, or null when it is not declared
    • var

      default String var(String name)
      Reads a plain variable or secret.

      Both are strings on this object and are indistinguishable from here, which is deliberate: whether a value is a secret is a property of how it was uploaded, not of how it is read.

      Parameters:
      name - the variable name
      Returns:
      the value, or null when it is not declared
    • var

      default String var(String name, String fallback)
      Reads a variable, falling back when it is absent.
      Parameters:
      name - the variable name
      fallback - the value to use when it is absent
      Returns:
      the value, or the fallback
    • has

      default boolean has(String name)
      Returns whether a binding is declared.
      Returns:
      whether a binding is declared
    • kv

      default KVNamespace kv()
      Returns the KV namespace named KV.
      Returns:
      the KV namespace named KV
    • kv

      default KVNamespace kv(String name)
      Parameters:
      name - the binding name
      Returns:
      the KV namespace with that name
    • d1

      default D1Database d1()
      Returns the D1 database named DB.
      Returns:
      the D1 database named DB
    • d1

      default D1Database d1(String name)
      Parameters:
      name - the binding name
      Returns:
      the D1 database with that name
    • r2

      default R2Bucket r2()
      Returns the R2 bucket named BLOB.
      Returns:
      the R2 bucket named BLOB
    • r2

      default R2Bucket r2(String name)
      Parameters:
      name - the binding name
      Returns:
      the R2 bucket with that name
    • ai

      default Ai ai()
      Returns the Workers AI binding named AI.
      Returns:
      the Workers AI binding named AI
    • queue

      default Queue queue()
      Returns the Queue producer named QUEUE.
      Returns:
      the Queue producer named QUEUE
    • queue

      default Queue queue(String name)
      Parameters:
      name - the binding name
      Returns:
      the Queue producer with that name
    • durableObject

      default DurableObjectNamespace durableObject(String name)
      Parameters:
      name - the binding name, DO_ followed by the class's simple name upper-snaked
      Returns:
      the Durable Object namespace with that name
    • service

      default Fetcher service()
      Returns the service binding named SERVICE.
      Returns:
      the service binding named SERVICE
    • service

      default Fetcher service(String name)
      Parameters:
      name - the binding name
      Returns:
      the service binding with that name
    • assets

      default Fetcher assets()
      Returns the static assets binding named ASSETS.
      Returns:
      the static assets binding named ASSETS
    • mtls

      default Fetcher mtls()
      Returns the mTLS binding named MTLS.
      Returns:
      the mTLS binding named MTLS
    • browser

      default Fetcher browser()
      Returns the Browser Rendering binding named BROWSER.
      Returns:
      the Browser Rendering binding named BROWSER
    • vectorize

      default Vectorize vectorize()
      Returns the Vectorize index named VECTORIZE.
      Returns:
      the Vectorize index named VECTORIZE
    • vectorize

      default Vectorize vectorize(String name)
      Parameters:
      name - the binding name
      Returns:
      the Vectorize index with that name
    • hyperdrive

      default Hyperdrive hyperdrive()
      Returns the Hyperdrive configuration named HYPERDRIVE.
      Returns:
      the Hyperdrive configuration named HYPERDRIVE
    • hyperdrive

      default Hyperdrive hyperdrive(String name)
      Parameters:
      name - the binding name
      Returns:
      the Hyperdrive configuration with that name
    • analytics

      default AnalyticsEngine analytics()
      Returns the Analytics Engine dataset named ANALYTICS.
      Returns:
      the Analytics Engine dataset named ANALYTICS
    • email

      default EmailSender email()
      Returns the email sending binding named EMAIL.
      Returns:
      the email sending binding named EMAIL
    • email

      default EmailSender email(String name)
      Parameters:
      name - the binding name
      Returns:
      the email sending binding with that name
    • images

      default Images images()
      Returns the Images binding named IMAGES.
      Returns:
      the Images binding named IMAGES
    • workflow

      default Workflow workflow()
      Returns the Workflow named WORKFLOW.
      Returns:
      the Workflow named WORKFLOW
    • workflow

      default Workflow workflow(String name)
      Parameters:
      name - the binding name
      Returns:
      the Workflow with that name
    • rateLimit

      default RateLimit rateLimit()
      Returns the rate limiter named RATELIMIT.
      Returns:
      the rate limiter named RATELIMIT
    • rateLimit

      default RateLimit rateLimit(String name)
      Parameters:
      name - the binding name
      Returns:
      the rate limiter with that name
    • version

      default VersionMetadata version()
      Returns the version metadata binding named CF_VERSION_METADATA.
      Returns:
      the version metadata binding named CF_VERSION_METADATA
    • secret

      default SecretsStore secret()
      Returns the Secrets Store secret named SECRETS.
      Returns:
      the Secrets Store secret named SECRETS
    • secret

      default SecretsStore secret(String name)
      Parameters:
      name - the binding name
      Returns:
      the Secrets Store secret with that name
    • pipeline

      default Pipeline pipeline()
      Returns the Pipeline named PIPELINE.
      Returns:
      the Pipeline named PIPELINE
    • dispatch

      default DispatchNamespace dispatch()
      Returns the dispatch namespace named DISPATCH.
      Returns:
      the dispatch namespace named DISPATCH
    • container

      default Container container(String name)
      Parameters:
      name - the binding name
      Returns:
      the container binding with that name
    • aiSearch

      default AiSearch aiSearch()
      Returns the AI Search binding named AI_SEARCH.
      Returns:
      the AI Search binding named AI_SEARCH
    • aiSearch

      default AiSearch aiSearch(String name)
      Parameters:
      name - the binding name
      Returns:
      the AI Search binding with that name