Package dev.gmitch215.bytebox
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.
| Declared | First | Second |
|---|---|---|
kv() | KV | KV_2 |
d1() | DB | DB_2 |
r2() | BLOB | BLOB_2 |
durableObject(Counter.class) | DO_COUNTER | DO_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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA binding that is present, waiting to be typed. -
Method Summary
Modifier and TypeMethodDescriptiondefault Aiai()Returns the Workers AI binding namedAI.default AiSearchaiSearch()Returns the AI Search binding namedAI_SEARCH.default AiSearchdefault AnalyticsEngineReturns the Analytics Engine dataset namedANALYTICS.default Fetcherassets()Returns the static assets binding namedASSETS.default Fetcherbrowser()Returns the Browser Rendering binding namedBROWSER.default Containerdefault D1Databased1()Returns the D1 database namedDB.default D1Databasedefault DispatchNamespacedispatch()Returns the dispatch namespace namedDISPATCH.default DurableObjectNamespacedurableObject(String name) default EmailSenderemail()Returns the email sending binding namedEMAIL.default EmailSenderReads one binding by name, whatever its type.default booleanReturns whether a binding is declared.default HyperdriveReturns the Hyperdrive configuration namedHYPERDRIVE.default Hyperdrivehyperdrive(String name) default Imagesimages()Returns the Images binding namedIMAGES.default KVNamespacekv()Returns the KV namespace namedKV.default KVNamespacedefault Fetchermtls()Returns the mTLS binding namedMTLS.default Pipelinepipeline()Returns the Pipeline namedPIPELINE.default Queuequeue()Returns the Queue producer namedQUEUE.default Queuedefault R2Bucketr2()Returns the R2 bucket namedBLOB.default R2Bucketdefault RateLimitReturns the rate limiter namedRATELIMIT.default RateLimitdefault SecretsStoresecret()Returns the Secrets Store secret namedSECRETS.default SecretsStoredefault Fetcherservice()Returns the service binding namedSERVICE.default Fetcherdefault StringReads a plain variable or secret.default StringReads a variable, falling back when it is absent.default VectorizeReturns the Vectorize index namedVECTORIZE.default Vectorizedefault VersionMetadataversion()Returns the version metadata binding namedCF_VERSION_METADATA.default Workflowworkflow()Returns the Workflow namedWORKFLOW.default WorkflowMethods inherited from interface org.teavm.jso.JSObject
cast
-
Method Details
-
get
Reads one binding by name, whatever its type.- Parameters:
name- the binding name- Returns:
- the binding, or
nullwhen it is not declared
-
var
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
nullwhen it is not declared
-
var
Reads a variable, falling back when it is absent.- Parameters:
name- the variable namefallback- the value to use when it is absent- Returns:
- the value, or the fallback
-
has
Returns whether a binding is declared.- Returns:
- whether a binding is declared
-
kv
Returns the KV namespace namedKV.- Returns:
- the KV namespace named
KV
-
kv
- Parameters:
name- the binding name- Returns:
- the KV namespace with that name
-
d1
Returns the D1 database namedDB.- Returns:
- the D1 database named
DB
-
d1
- Parameters:
name- the binding name- Returns:
- the D1 database with that name
-
r2
Returns the R2 bucket namedBLOB.- Returns:
- the R2 bucket named
BLOB
-
r2
- Parameters:
name- the binding name- Returns:
- the R2 bucket with that name
-
ai
Returns the Workers AI binding namedAI.- Returns:
- the Workers AI binding named
AI
-
queue
Returns the Queue producer namedQUEUE.- Returns:
- the Queue producer named
QUEUE
-
queue
- Parameters:
name- the binding name- Returns:
- the Queue producer with that name
-
durableObject
- Parameters:
name- the binding name,DO_followed by the class's simple name upper-snaked- Returns:
- the Durable Object namespace with that name
-
service
Returns the service binding namedSERVICE.- Returns:
- the service binding named
SERVICE
-
service
- Parameters:
name- the binding name- Returns:
- the service binding with that name
-
assets
Returns the static assets binding namedASSETS.- Returns:
- the static assets binding named
ASSETS
-
mtls
Returns the mTLS binding namedMTLS.- Returns:
- the mTLS binding named
MTLS
-
browser
Returns the Browser Rendering binding namedBROWSER.- Returns:
- the Browser Rendering binding named
BROWSER
-
vectorize
Returns the Vectorize index namedVECTORIZE.- Returns:
- the Vectorize index named
VECTORIZE
-
vectorize
- Parameters:
name- the binding name- Returns:
- the Vectorize index with that name
-
hyperdrive
Returns the Hyperdrive configuration namedHYPERDRIVE.- Returns:
- the Hyperdrive configuration named
HYPERDRIVE
-
hyperdrive
- Parameters:
name- the binding name- Returns:
- the Hyperdrive configuration with that name
-
analytics
Returns the Analytics Engine dataset namedANALYTICS.- Returns:
- the Analytics Engine dataset named
ANALYTICS
-
email
Returns the email sending binding namedEMAIL.- Returns:
- the email sending binding named
EMAIL
-
email
- Parameters:
name- the binding name- Returns:
- the email sending binding with that name
-
images
Returns the Images binding namedIMAGES.- Returns:
- the Images binding named
IMAGES
-
workflow
Returns the Workflow namedWORKFLOW.- Returns:
- the Workflow named
WORKFLOW
-
workflow
- Parameters:
name- the binding name- Returns:
- the Workflow with that name
-
rateLimit
Returns the rate limiter namedRATELIMIT.- Returns:
- the rate limiter named
RATELIMIT
-
rateLimit
- Parameters:
name- the binding name- Returns:
- the rate limiter with that name
-
version
Returns the version metadata binding namedCF_VERSION_METADATA.- Returns:
- the version metadata binding named
CF_VERSION_METADATA
-
secret
Returns the Secrets Store secret namedSECRETS.- Returns:
- the Secrets Store secret named
SECRETS
-
secret
- Parameters:
name- the binding name- Returns:
- the Secrets Store secret with that name
-
pipeline
Returns the Pipeline namedPIPELINE.- Returns:
- the Pipeline named
PIPELINE
-
dispatch
Returns the dispatch namespace namedDISPATCH.- Returns:
- the dispatch namespace named
DISPATCH
-
container
- Parameters:
name- the binding name- Returns:
- the container binding with that name
-
aiSearch
Returns the AI Search binding namedAI_SEARCH.- Returns:
- the AI Search binding named
AI_SEARCH
-
aiSearch
- Parameters:
name- the binding name- Returns:
- the AI Search binding with that name
-