cloudflare

MoonBit bindings for Cloudflare Workers APIs (KV, D1, R2, Durable Objects, etc.)

cloudflare
workers
kv
d1
r2
durable-objects
moon add mizchi/cloudflare@0.1.11
Download zip
Author
Version
0.1.11
License
MIT
Last updated
20 hours ago
Downloads
1K

Dependencies

README

#cloudflare.mbt

MoonBit bindings for Cloudflare Workers APIs

#Features

  • KV (Workers KV): Key-value storage
  • D1: Serverless SQL database
  • R2: Object storage
  • Durable Objects: Stateful serverless objects
  • Queues: Message queues

#Installation

This package depends on mizchi/js. Make sure to add both dependencies to your moon.mod.json:

{ "deps": { "mizchi/js": "0.8.2", "mizchi/cloudflare": "0.1.0" } }

#Usage

See examples in examples/cfw/ directory.

#Development

# Install dependencies pnpm install # Run development server pnpm dev # Run tests pnpm test

#Testing

Tests are located in e2e/cloudflare/ and use Vitest with @cloudflare/vitest-pool-workers.

#License

MIT

#Cloudflare Workers Bindings for MoonBit

This package provides type-safe MoonBit bindings for Cloudflare Workers platform services.

#Cloudflare Services Support Status

ServicePackageStatusNote
Core Platform
Workers Runtimemizchi/js/cloudflare๐Ÿงช TestedBasic runtime bindings
Environment Contextmizchi/js/cloudflare๐Ÿงช TestedEnv/ExecutionContext
Storage Services
KV (Key-Value)mizchi/js/cloudflare๐Ÿงช TestedGet/Put/Delete/List
D1 (SQL Database)mizchi/js/cloudflare๐Ÿงช TestedQueries/Prepared/Batch
R2 (Object Storage)mizchi/js/cloudflare๐Ÿงช TestedObjects/Multipart/Metadata
Durable Objectsmizchi/js/cloudflare๐Ÿงช TestedStorage/Alarms/State
Compute & Network
Workers AI-๐Ÿ“… PlannedAI model inference
Vectorize-๐Ÿ“… PlannedVector database
Queuesmizchi/js/cloudflare๐Ÿค– AI GeneratedMessage queues
Workers Analytics Engine-๐Ÿ“… PlannedAnalytics data
Hyperdrive-๐Ÿ“… PlannedDatabase acceleration
Email Workers-๐Ÿ“… PlannedEmail handling
Browser Rendering-๐Ÿ“… PlannedPuppeteer API
Security & Auth
Access-๐Ÿ“… PlannedIdentity management
Turnstile-๐Ÿ“… PlannedCAPTCHA alternative

#Status Legend

  • ๐Ÿงช Tested: Comprehensive test coverage with Miniflare/Vitest
  • ๐Ÿค– AI Generated: FFI bindings created, needs testing
  • ๐Ÿ“… Planned: Scheduled for future implementation


#Installation

Add to your moon.pkg.json:

{ "import": [ "mizchi/js", "mizchi/js/web/url", "mizchi/js/web/http", "mizchi/js/web/worker", "mizchi/js/cloudflare" ] }

#Supported Services

#KV (Key-Value Storage)

Cloudflare KV is a global, low-latency key-value data store.

Basic Usage:

// Get a value
let value = kv.get("my-key").await()

// Put a value
kv.put("my-key", "my-value").await()

// Delete a value
kv.delete("my-key").await()

// List keys
let result = kv.list().await()

Advanced Operations:

// Get with options
let value = kv.get(
"my-key",
type_?=Some("json"),
cacheTtl?=Some(60)
).await()

// Get as JSON
let json_data = kv.get_json("my-data").await()

// Put with metadata and TTL
kv.put(
"my-key",
"my-value",
expirationTtl?=Some(3600),
metadata?=Some(js({"version": 1}))
).await()

// List with filtering
let result = kv.list(
prefix?=Some("user:"),
limit?=Some(100)
).await()

#D1 (SQL Database)

Cloudflare D1 is a serverless SQL database.

Basic Usage:

// Prepare and execute a query
let stmt = db.prepare("SELECT * FROM users WHERE id = ?")
let result = stmt.bind1(js(1)).all().await()

// Direct execution
let result = db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)").await()

// Batch operations
let stmts = [
db.prepare("INSERT INTO users VALUES (?, ?)").bind2(js(1), js("Alice")),
db.prepare("INSERT INTO users VALUES (?, ?)").bind2(js(2), js("Bob"))
]
let results = db.batch(stmts).await()

Query Results:

// Get first row
let first = stmt.first().unwrap()

// Get specific column from first row
let name = stmt.first_col("name").await()

// Get all rows
let result = stmt.all().unwrap()
let rows = result.get_results()

// Raw results as arrays
let raw = stmt.raw().unwrap()

#R2 (Object Storage)

Cloudflare R2 is an S3-compatible object storage service.

Basic Usage:

// Put an object
let obj = bucket.put("file.txt", js("Hello, World!")).await()

// Get an object
let obj = bucket.get("file.txt").await()
match obj {
Some(o) => {
let text = o.text().await()
// Use text...
}
None => ()
}

// Delete an object
bucket.delete("file.txt").await()

// List objects
let objects = bucket.list().await()

Advanced Operations:

// Put with metadata
let http_meta = R2HttpMetadata::{
contentType: Some("text/plain"),
contentLanguage: Some("en"),
cacheControl: Some("max-age=3600"),
contentDisposition: None,
contentEncoding: None,
cacheExpiry: None
}
bucket.put(
"file.txt",
js("content"),
httpMetadata?=Some(http_meta),
customMetadata?=Some(js({"author": "Alice"}))
).await()

// Conditional get
let cond = R2Conditional::{
etagMatches: Some("abc123"),
etagDoesNotMatch: None,
uploadedBefore: None,
uploadedAfter: None
}
let obj = bucket.get(
"file.txt",
onlyIf?=Some(cond)
).await()

// List with filtering
let result = bucket.list(
limit?=Some(1000),
prefix?=Some("images/"),
delimiter?=Some("/"),
include_?=Some(["httpMetadata", "customMetadata"])
).await()

// Multipart upload
let upload = bucket.create_multipart_upload("large-file.bin").await()
let part1 = upload.upload_part(1, js(data1)).await()
let part2 = upload.upload_part(2, js(data2)).await()
let obj = upload.complete([part1, part2]).await()

#Durable Objects

Durable Objects provide strongly consistent coordination primitives.

Namespace Operations:

// Get by name (deterministic ID)
let stub = namespace.get_by_name("my-object")

// Get by unique ID
let id = namespace.new_unique_id()
let stub = namespace.get(id)

// Get with jurisdiction
let id = namespace.new_unique_id(jurisdiction?=Some("eu"))

Calling Durable Objects:

// Fetch request
let response = stub.fetch_url("/api/endpoint").await()

// Fetch with init options
let init = js({"method": "POST", "body": "data"})
let response = stub.fetch_url_with_init("/api/endpoint", init).await()

Inside a Durable Object:

// Access storage
let storage = state.storage()

// Get/Put/Delete
let value = storage.get("counter").await()
storage.put("counter", js(42)).await()
storage.delete("key").await()

// List keys
let entries = storage.list(
prefix?=Some("user:"),
limit?=Some(100)
).await()

// Transactions
let closure = js(/* transaction function */)
let result = storage.transaction(closure).await()

// Alarms
storage.set_alarm(timestamp).await()
let alarm_time = storage.get_alarm().await()
storage.delete_alarm().await()

// Wait until
state.wait_until(promise)

// Block concurrency
let callback = js(/* async function */)
state.block_concurrency_while(callback).await()

Storage Options:

// Get with options
let value = storage.get(
"key",
allowConcurrency?=Some(true),
noCache?=Some(false)
).await()

// Put with options
storage.put(
"key",
js(value),
allowConcurrency?=Some(true),
allowUnconfirmed?=Some(false),
noCache?=Some(false)
).await()

#Type Conversions

All bindings use @js.Val for JavaScript interop:

// Convert to Val
let num = js(42)
let str = js("hello")
let bool = js(true)
let obj = js({"key": "value"})

// Cast from Val
let number : Int = val.cast()
let text : String = val.cast()

#Error Handling

Most operations return Promise[T] types. Use MoonBit's async/await:

// With error handling
let result = try {
let value = kv.get("key", None).await()
Ok(value)
} catch {
e => Err(e)
}

#Testing

This package includes comprehensive tests using vitest and @cloudflare/vitest-pool-workers.

#Running Tests

# Run all tests pnpm test # Run only Cloudflare tests pnpm test:cloudflare # Watch mode pnpm test:watch pnpm test:cloudflare:watch

#Test Setup

The tests use Miniflare to simulate the Cloudflare Workers environment locally. Configuration is in:

  • vitest.config.ts - Vitest configuration with workers pool
  • wrangler.toml - Cloudflare Workers configuration

#Test Coverage

Each service has comprehensive test coverage:

KV Tests (test/cloudflare/kv.test.ts):
  • Basic get/put/delete operations
  • Different data types (text, JSON, ArrayBuffer)
  • Metadata storage and retrieval
  • Expiration and TTL
  • List operations with prefix, limit, cursor
  • Cache control
  • Edge cases (unicode, large values, empty strings)

D1 Tests (test/cloudflare/d1.test.ts):
  • CREATE, INSERT, SELECT, UPDATE, DELETE statements
  • Prepared statements with parameter binding
  • Query results (all, first, raw)
  • Batch operations with transactions
  • Metadata (duration, rows affected, last insert ID)
  • Error handling (syntax errors, constraints)
  • Complex queries (ORDER BY, LIMIT, aggregate functions)

R2 Tests (test/cloudflare/r2.test.ts):
  • Basic put/get/delete/head operations
  • Different content types (text, JSON, Blob, ArrayBuffer)
  • HTTP metadata (content-type, cache-control, etc.)
  • Custom metadata
  • Object properties (key, size, etag, version)
  • Conditional gets (etag matching)
  • Range requests
  • List operations with prefix, delimiter, pagination
  • Multiple deletes
  • Multipart uploads (create, upload parts, complete, abort)
  • Edge cases (unicode, large objects, special characters)

Durable Objects Tests (test/cloudflare/durable-objects.test.ts):
  • ID generation (unique, from name, from string)
  • ID comparison and properties
  • Stub creation and communication
  • Storage operations (put, get, delete)
  • State persistence across requests
  • Alarms (set, get, trigger)
  • Concurrent request handling
  • Edge cases (unicode keys, large values)
  • Jurisdiction options

#Writing New Tests

To add new tests, create a file in test/cloudflare/ and use the standard vitest API:

import { env } from 'cloudflare:test'; import { describe, it, expect } from 'vitest'; describe('My Feature', () => { it('should work correctly', async () => { const kv = env.TEST_KV as KVNamespace; await kv.put('key', 'value'); const result = await kv.get('key'); expect(result).toBe('value'); }); });

#References

#
CloudflareFetchHandler

CloudflareFetchHandler is a type alias for Cloudflare Worker fetch handler

#
D1Error

pub suberror D1Error {
D1Error(String)
}
D1 Error type for database operations
impl Show for D1Error

#
AlarmInfo

#external
pub type AlarmInfo

Information passed to the alarm() handler Contains retry information for handling alarm failures

#
AlarmInfo::as_any

#
AlarmInfo::is_retry

fn AlarmInfo::is_retry(self : AlarmInfo) -> Bool

Check if this alarm invocation is a retry Returns true if retryCount > 0

#
AlarmInfo::retry_count

fn AlarmInfo::retry_count(self : AlarmInfo) -> Int

Get the number of times this alarm has been retried Starts at 0 for the first attempt

#
CloudflareContext

#external
pub type CloudflareContext

#
CloudflareContext::as_any

#
CloudflareContext::passThroughOnException

#alias(pass_through_exception)
fn CloudflareContext::passThroughOnException(self : CloudflareContext) -> Unit

#
CloudflareContext::waitUntil

#alias(wait_until)
fn CloudflareContext::waitUntil(self : CloudflareContext, promise :
Promise
[Unit]) -> Unit

#
CloudflareEnv

#external
pub type CloudflareEnv

#
CloudflareEnv::as_any

#
CloudflareRequest

pub(all) struct CloudflareRequest {
cf : CloudflareContext
url : String
}

#
CloudflareRequest::as_any

#
ContentOptions

pub(all) struct ContentOptions {
html : Bool
}

Content options for HTML insertion

#
ContentOptions::html_mode

fn ContentOptions::html_mode() -> ContentOptions

HTML content options

#
ContentOptions::text

Default content options (text mode)

#
ContentOptions::to_js

Convert ContentOptions to JavaScript object

#
D1Database

#external
pub type D1Database

#
D1Database::as_any

#
D1Database::batch

async fn D1Database::batch(self : D1Database, statements : Array[D1PreparedStatement]) -> Array[D1Result] raise D1Error

Batch execute multiple prepared statements in a transaction

#
D1Database::dump

async fn D1Database::dump(self : D1Database) -> Bytes raise D1Error

Dump the entire database (returns ArrayBuffer as Bytes)

#
D1Database::exec

async fn D1Database::exec(self : D1Database, query : String) -> D1ExecResult raise D1Error

Execute a SQL statement directly (for statements that don't return data)

#
D1Database::prepare

fn D1Database::prepare(self : D1Database, query : String) -> D1PreparedStatement

Prepare a SQL statement

#
D1ExecResult

#external
pub type D1ExecResult

Result of exec operation (external type)

#
D1ExecResult::as_any

#
D1ExecResult::count

fn D1ExecResult::count(self : D1ExecResult) -> Int

Number of statements executed

#
D1ExecResult::duration

fn D1ExecResult::duration(self : D1ExecResult) -> Double

Total duration in milliseconds

#
D1Meta

#external
pub type D1Meta

Metadata about query execution (external type)

#
D1Meta::as_any

fn D1Meta::as_any(self : D1Meta) ->
Any

#
D1Meta::changed_db

fn D1Meta::changed_db(self : D1Meta) -> Bool?

Whether database was changed

#
D1Meta::changes

fn D1Meta::changes(self : D1Meta) -> Int?

Number of rows changed

#
D1Meta::duration

fn D1Meta::duration(self : D1Meta) -> Double?

Query duration in milliseconds

#
D1Meta::last_row_id

fn D1Meta::last_row_id(self : D1Meta) -> Int?

Last inserted row ID

#
D1Meta::rows_read

fn D1Meta::rows_read(self : D1Meta) -> Int?

Number of rows read

#
D1Meta::rows_written

fn D1Meta::rows_written(self : D1Meta) -> Int?

Number of rows written

#
D1Meta::size_after

fn D1Meta::size_after(self : D1Meta) -> Int?

Database size after query

#
D1PreparedStatement

#external
pub type D1PreparedStatement

Prepared statement type

#
D1PreparedStatement::all

Execute the statement and return all rows

#
D1PreparedStatement::as_any

#
D1PreparedStatement::bind

Bind parameters to a prepared statement Note: This wraps parameters in an array and spreads them to match Cloudflare's API

#
D1PreparedStatement::bind1

Bind a single parameter

#
D1PreparedStatement::bind2

Bind two parameters

#
D1PreparedStatement::bind3

Bind three parameters

#
D1PreparedStatement::first

Execute the statement and return first row

#
D1PreparedStatement::first_col

async fn D1PreparedStatement::first_col(self : D1PreparedStatement, col_name : String) ->
Any
? raise D1Error

Execute the statement and return first column value

#
D1PreparedStatement::raw

async fn D1PreparedStatement::raw(self : D1PreparedStatement, columnNames? : Bool) -> Array[
Any
] raise D1Error

Execute and return raw results

#
D1PreparedStatement::run

Execute the statement (for INSERT, UPDATE, DELETE)

#
D1Result

#alias(D1ResultSet)
#external
pub type D1Result

Result of a D1 query (external type to properly handle JS object properties)

#
D1Result::as_any

#
D1Result::error

fn D1Result::error(self : D1Result) -> String?

Get the error message if any

#
D1Result::get_results

fn D1Result::get_results(self : D1Result) -> Array[
Any
]

Get results from D1Result

Note: The returned array is a snapshot and should be treated as immutable.

#
D1Result::meta

fn D1Result::meta(self : D1Result) -> D1Meta?

Get the query metadata

#
D1Result::results_raw

fn D1Result::results_raw(self : D1Result) ->
Any

Get results from D1Result as a raw JS array

#
D1Result::success

fn D1Result::success(self : D1Result) -> Bool

Check if the query was successful

#
Doctype

#external
pub type Doctype

Doctype - represents the DOCTYPE declaration

#
Doctype::as_any

fn Doctype::as_any(self : Doctype) ->
Any

#
Doctype::name

fn Doctype::name(self : Doctype) -> String?

Get the doctype name (e.g., "html")

#
Doctype::public_id

fn Doctype::public_id(self : Doctype) -> String?

Get the public ID

#
Doctype::system_id

fn Doctype::system_id(self : Doctype) -> String?

Get the system ID

#
DocumentEnd

#external
pub type DocumentEnd

DocumentEnd - represents the end of the document

#
DocumentEnd::append

fn DocumentEnd::append(self : DocumentEnd, content : String, options : ContentOptions) -> DocumentEnd

Append content at the end of the document

#
DocumentEnd::append_text

fn DocumentEnd::append_text(self : DocumentEnd, content : String) -> DocumentEnd

Append content at the end of the document (text mode)

#
DocumentEnd::as_any

#
DocumentHandler

pub(all) struct DocumentHandler {
doctype : (Doctype) -> Unit?
comments : (HTMLComment) -> Unit?
text : (TextChunk) -> Unit?
end : (DocumentEnd) -> Unit?
}

Document handler callbacks

#
DocumentHandler::to_js

Convert DocumentHandler to JavaScript object

#
DurableObjectGetAlarmOptions

pub(all) struct DurableObjectGetAlarmOptions {
allowConcurrency : Bool?
}

Options for getAlarm

#
DurableObjectGetAlarmOptions::to_js

#
DurableObjectGetOptions

pub(all) struct DurableObjectGetOptions {
allowConcurrency : Bool?
noCache : Bool?
}

Options for get operations

#
DurableObjectGetOptions::to_js

#
DurableObjectId

pub(all) struct DurableObjectId {
name : String?
}

Durable Object ID

#
DurableObjectId::as_any

#
DurableObjectId::equals

fn DurableObjectId::equals(self : DurableObjectId, other : DurableObjectId) -> Bool

Check if two IDs are equal

#
DurableObjectId::to_string

fn DurableObjectId::to_string(self : DurableObjectId) -> String

Convert ID to string

#
DurableObjectIdOptions

pub(all) struct DurableObjectIdOptions {
jurisdiction : String?
}

Options for creating Durable Object IDs

#
DurableObjectIdOptions::to_js

#
DurableObjectListOptions

pub(all) struct DurableObjectListOptions {
start : String?
startAfter : String?
end : String?
prefix : String?
reverse : Bool?
limit : Int?
allowConcurrency : Bool?
noCache : Bool?
}

Options for list operations

#
DurableObjectListOptions::to_js

#
DurableObjectNamespace

#external
pub type DurableObjectNamespace

#
DurableObjectNamespace::as_any

#
DurableObjectNamespace::get

Get a Durable Object stub by ID

#
DurableObjectNamespace::get_by_id_string

fn DurableObjectNamespace::get_by_id_string(self : DurableObjectNamespace, id : String) -> DurableObjectStub

Get a Durable Object stub by ID string

#
DurableObjectNamespace::get_by_name

fn DurableObjectNamespace::get_by_name(self : DurableObjectNamespace, name : String) -> DurableObjectStub

Get a Durable Object stub by name

#
DurableObjectNamespace::id_from_name

fn DurableObjectNamespace::id_from_name(self : DurableObjectNamespace, name : String) -> DurableObjectId

Create an ID from a name (deterministic)

#
DurableObjectNamespace::id_from_string

fn DurableObjectNamespace::id_from_string(self : DurableObjectNamespace, id : String) -> DurableObjectId

Create an ID from a string

#
DurableObjectNamespace::new_unique_id

Create a new unique ID

#
DurableObjectNamespace::new_unique_id_with_options

fn DurableObjectNamespace::new_unique_id_with_options(self : DurableObjectNamespace, options : DurableObjectIdOptions) -> DurableObjectId

Create a new unique ID with options

#
DurableObjectPutOptions

pub(all) struct DurableObjectPutOptions {
allowConcurrency : Bool?
allowUnconfirmed : Bool?
noCache : Bool?
}

Options for put/delete operations

#
DurableObjectPutOptions::to_js

#
DurableObjectSetAlarmOptions

pub(all) struct DurableObjectSetAlarmOptions {
allowConcurrency : Bool?
allowUnconfirmed : Bool?
}

Options for setAlarm/deleteAlarm

#
DurableObjectSetAlarmOptions::to_js

#
DurableObjectState

pub(all) struct DurableObjectState {
id : DurableObjectId
storage : DurableObjectStorage
}

Durable Object State (available inside DO class)

#
DurableObjectState::as_any

#
DurableObjectState::block_concurrency_while

async fn DurableObjectState::block_concurrency_while(self : DurableObjectState, callback :
Any
) -> Unit

Block concurrent requests until callback completes

#
DurableObjectState::wait_until

fn DurableObjectState::wait_until(self : DurableObjectState, promise :
Any
) -> Unit

Wait until a promise completes before confirming writes

#
DurableObjectStorage

#external
pub type DurableObjectStorage

Durable Object Storage

#
DurableObjectStorage::as_any

#
DurableObjectStorage::delete

async fn DurableObjectStorage::delete(self : DurableObjectStorage, key : String) -> Bool

Delete a key from storage

#
DurableObjectStorage::delete_alarm

async fn DurableObjectStorage::delete_alarm(self : DurableObjectStorage) -> Unit

Delete the alarm

#
DurableObjectStorage::delete_alarm_with_options

async fn DurableObjectStorage::delete_alarm_with_options(self : DurableObjectStorage, options : DurableObjectSetAlarmOptions) -> Unit

Delete alarm with options

#
DurableObjectStorage::delete_all

async fn DurableObjectStorage::delete_all(self : DurableObjectStorage) -> Unit

Delete all keys in storage

#
DurableObjectStorage::delete_all_with_options

async fn DurableObjectStorage::delete_all_with_options(self : DurableObjectStorage, options : DurableObjectPutOptions) -> Unit

Delete all keys with options

#
DurableObjectStorage::delete_multiple

async fn DurableObjectStorage::delete_multiple(self : DurableObjectStorage, keys : Array[String]) -> Int

Delete multiple keys from storage

#
DurableObjectStorage::delete_multiple_with_options

async fn DurableObjectStorage::delete_multiple_with_options(self : DurableObjectStorage, keys : Array[String], options : DurableObjectPutOptions) -> Int

Delete multiple keys with options

#
DurableObjectStorage::delete_with_options

async fn DurableObjectStorage::delete_with_options(self : DurableObjectStorage, key : String, options : DurableObjectPutOptions) -> Bool

Delete a key with options

#
DurableObjectStorage::get

async fn DurableObjectStorage::get(self : DurableObjectStorage, key : String) ->
Any
?

Get a value from storage

#
DurableObjectStorage::get_alarm

async fn DurableObjectStorage::get_alarm(self : DurableObjectStorage) -> Int?

Get current alarm time

#
DurableObjectStorage::get_alarm_with_options

async fn DurableObjectStorage::get_alarm_with_options(self : DurableObjectStorage, options : DurableObjectGetAlarmOptions) -> Int?

Get alarm with options

#
DurableObjectStorage::get_multiple

async fn DurableObjectStorage::get_multiple(self : DurableObjectStorage, keys : Array[String]) ->
Any

Get multiple values from storage

#
DurableObjectStorage::get_multiple_with_options

async fn DurableObjectStorage::get_multiple_with_options(self : DurableObjectStorage, keys : Array[String], options : DurableObjectGetOptions) ->
Any

Get multiple values with options

#
DurableObjectStorage::get_with_options

async fn DurableObjectStorage::get_with_options(self : DurableObjectStorage, key : String, options : DurableObjectGetOptions) ->
Any
?

Get a value with options

#
DurableObjectStorage::list

List keys in storage

#
DurableObjectStorage::list_with_options

List keys with options

#
DurableObjectStorage::put

async fn DurableObjectStorage::put(self : DurableObjectStorage, key : String, value :
Any
) -> Unit

Put a value into storage

#
DurableObjectStorage::put_multiple

async fn DurableObjectStorage::put_multiple(self : DurableObjectStorage, entries :
Any
) -> Unit

Put multiple values into storage

#
DurableObjectStorage::put_multiple_with_options

async fn DurableObjectStorage::put_multiple_with_options(self : DurableObjectStorage, entries :
Any
, options : DurableObjectPutOptions) -> Unit

Put multiple values with options

#
DurableObjectStorage::put_with_options

async fn DurableObjectStorage::put_with_options(self : DurableObjectStorage, key : String, value :
Any
, options : DurableObjectPutOptions) -> Unit

Put a value with options

#
DurableObjectStorage::set_alarm

async fn DurableObjectStorage::set_alarm(self : DurableObjectStorage, scheduled_time : Int) -> Unit

Set an alarm

#
DurableObjectStorage::set_alarm_with_options

async fn DurableObjectStorage::set_alarm_with_options(self : DurableObjectStorage, scheduled_time : Int, options : DurableObjectSetAlarmOptions) -> Unit

Set alarm with options

#
DurableObjectStorage::sql

Get the SQLite storage interface Use this to execute SQL queries directly on the Durable Object's database

#
DurableObjectStorage::sync

async fn DurableObjectStorage::sync(self : DurableObjectStorage) -> Unit

Sync storage to disk

#
DurableObjectStorage::transaction

Execute a transaction

#
DurableObjectStub

pub(all) struct DurableObjectStub {
id : DurableObjectId
name : String?
}

Durable Object Stub (client interface)

#
DurableObjectStub::as_any

#
DurableObjectStub::fetch

Send a fetch request to the Durable Object

#
DurableObjectStub::fetch_url

async fn DurableObjectStub::fetch_url(self : DurableObjectStub, url : String) ->
Any

Send a fetch request by URL

#
DurableObjectStub::fetch_url_with_init

async fn DurableObjectStub::fetch_url_with_init(self : DurableObjectStub, url : String, init :
Any
) ->
Any

Send a fetch request by URL with init options

#
DurableObjectStub::fetch_with_init

Send a fetch request with init options

#
DurableObjectTransaction

#external
pub type DurableObjectTransaction

Transaction context

#
DurableObjectTransaction::as_any

#
DurableObjectTransaction::delete

async fn DurableObjectTransaction::delete(self : DurableObjectTransaction, key : String) -> Bool

Delete a key in transaction

#
DurableObjectTransaction::delete_alarm

async fn DurableObjectTransaction::delete_alarm(self : DurableObjectTransaction) -> Unit

Delete alarm in transaction

#
DurableObjectTransaction::delete_all

async fn DurableObjectTransaction::delete_all(self : DurableObjectTransaction) -> Unit

Delete all keys in transaction

#
DurableObjectTransaction::delete_multiple

async fn DurableObjectTransaction::delete_multiple(self : DurableObjectTransaction, keys : Array[String]) -> Int

Delete multiple keys in transaction

#
DurableObjectTransaction::get

Get a value in transaction

#
DurableObjectTransaction::get_alarm

async fn DurableObjectTransaction::get_alarm(self : DurableObjectTransaction) -> Int?

Get alarm in transaction

#
DurableObjectTransaction::get_multiple

async fn DurableObjectTransaction::get_multiple(self : DurableObjectTransaction, keys : Array[String]) ->
Any

Get multiple values in transaction

#
DurableObjectTransaction::list

List keys in transaction

#
DurableObjectTransaction::list_with_options

List keys with options in transaction

#
DurableObjectTransaction::put

async fn DurableObjectTransaction::put(self : DurableObjectTransaction, key : String, value :
Any
) -> Unit

Put a value in transaction

#
DurableObjectTransaction::put_multiple

async fn DurableObjectTransaction::put_multiple(self : DurableObjectTransaction, entries :
Any
) -> Unit

Put multiple values in transaction

#
DurableObjectTransaction::rollback

Rollback the transaction

#
DurableObjectTransaction::set_alarm

async fn DurableObjectTransaction::set_alarm(self : DurableObjectTransaction, scheduled_time : Int) -> Unit

Set alarm in transaction

#
Element

#external
pub type Element

Element - represents an HTML element

#
Element::after

fn Element::after(self : Element, content : String, options : ContentOptions) -> Element

Insert content after the element

#
Element::after_text

fn Element::after_text(self : Element, content : String) -> Element

Insert content after the element (text mode)

#
Element::append

fn Element::append(self : Element, content : String, options : ContentOptions) -> Element

Append content to the element

#
Element::append_text

fn Element::append_text(self : Element, content : String) -> Element

Append content to the element (text mode)

#
Element::as_any

fn Element::as_any(self : Element) ->
Any

#
Element::before

fn Element::before(self : Element, content : String, options : ContentOptions) -> Element

Insert content before the element

#
Element::before_text

fn Element::before_text(self : Element, content : String) -> Element

Insert content before the element (text mode)

#
Element::get_attribute

fn Element::get_attribute(self : Element, name : String) -> String?

Get an attribute value

#
Element::has_attribute

fn Element::has_attribute(self : Element, name : String) -> Bool

Check if element has an attribute

#
Element::namespace_uri

fn Element::namespace_uri(self : Element) -> String

Get the namespace URI

#
Element::on_end_tag

fn Element::on_end_tag(self : Element, handler : (EndTag) -> Unit) -> Unit

Register a handler for the end tag

#
Element::prepend

fn Element::prepend(self : Element, content : String, options : ContentOptions) -> Element

Prepend content to the element

#
Element::prepend_text

fn Element::prepend_text(self : Element, content : String) -> Element

Prepend content to the element (text mode)

#
Element::remove

fn Element::remove(self : Element) -> Element

Remove the element and its content

#
Element::remove_and_keep_content

fn Element::remove_and_keep_content(self : Element) -> Element

Remove the element but keep its content

#
Element::remove_attribute

fn Element::remove_attribute(self : Element, name : String) -> Element

Remove an attribute

#
Element::removed

fn Element::removed(self : Element) -> Bool

Check if element was removed

#
Element::replace

fn Element::replace(self : Element, content : String, options : ContentOptions) -> Element

Replace the element with content

#
Element::replace_text

fn Element::replace_text(self : Element, content : String) -> Element

Replace the element with content (text mode)

#
Element::set_attribute

fn Element::set_attribute(self : Element, name : String, value : String) -> Element

Set an attribute

#
Element::set_inner_content

fn Element::set_inner_content(self : Element, content : String, options : ContentOptions) -> Element

Set the inner content of the element

#
Element::set_inner_content_text

fn Element::set_inner_content_text(self : Element, content : String) -> Element

Set the inner content of the element (text mode)

#
Element::set_tag_name

fn Element::set_tag_name(self : Element, name : String) -> Unit

Set the tag name

#
Element::tag_name

fn Element::tag_name(self : Element) -> String

Get the tag name

#
ElementHandler

pub(all) struct ElementHandler {
element : (Element) -> Unit?
comments : (HTMLComment) -> Unit?
text : (TextChunk) -> Unit?
}

Element handler callbacks

#
ElementHandler::comments_only

fn ElementHandler::comments_only(f : (HTMLComment) -> Unit) -> ElementHandler

Create a comments-only handler

#
ElementHandler::element_only

fn ElementHandler::element_only(f : (Element) -> Unit) -> ElementHandler

Create an element-only handler

#
ElementHandler::text_only

fn ElementHandler::text_only(f : (TextChunk) -> Unit) -> ElementHandler

Create a text-only handler

#
ElementHandler::to_js

Convert ElementHandler to JavaScript object

#
EndTag

#external
pub type EndTag

EndTag - represents an element's end tag

#
EndTag::after

fn EndTag::after(self : EndTag, content : String, options : ContentOptions) -> EndTag

Insert content after the end tag

#
EndTag::after_text

fn EndTag::after_text(self : EndTag, content : String) -> EndTag

Insert content after the end tag (text mode)

#
EndTag::as_any

fn EndTag::as_any(self : EndTag) ->
Any

#
EndTag::before

fn EndTag::before(self : EndTag, content : String, options : ContentOptions) -> EndTag

Insert content before the end tag

#
EndTag::before_text

fn EndTag::before_text(self : EndTag, content : String) -> EndTag

Insert content before the end tag (text mode)

#
EndTag::name

fn EndTag::name(self : EndTag) -> String

Get the tag name

#
EndTag::remove

fn EndTag::remove(self : EndTag) -> EndTag

Remove the end tag

#
EndTag::set_name

fn EndTag::set_name(self : EndTag, name : String) -> Unit

Set the tag name

#
HTMLComment

#external
pub type HTMLComment

HTMLComment - represents an HTML comment

#
HTMLComment::after

fn HTMLComment::after(self : HTMLComment, content : String, options : ContentOptions) -> HTMLComment

Insert content after the comment

#
HTMLComment::after_text

fn HTMLComment::after_text(self : HTMLComment, content : String) -> HTMLComment

Insert content after the comment (text mode)

#
HTMLComment::as_any

#
HTMLComment::before

fn HTMLComment::before(self : HTMLComment, content : String, options : ContentOptions) -> HTMLComment

Insert content before the comment

#
HTMLComment::before_text

fn HTMLComment::before_text(self : HTMLComment, content : String) -> HTMLComment

Insert content before the comment (text mode)

#
HTMLComment::remove

fn HTMLComment::remove(self : HTMLComment) -> HTMLComment

Remove the comment

#
HTMLComment::removed

fn HTMLComment::removed(self : HTMLComment) -> Bool

Check if comment was removed

#
HTMLComment::replace

fn HTMLComment::replace(self : HTMLComment, content : String, options : ContentOptions) -> HTMLComment

Replace the comment with content

#
HTMLComment::replace_text

fn HTMLComment::replace_text(self : HTMLComment, content : String) -> HTMLComment

Replace the comment with content (text mode)

#
HTMLComment::set_text

fn HTMLComment::set_text(self : HTMLComment, text : String) -> Unit

Set the comment text

#
HTMLComment::text

fn HTMLComment::text(self : HTMLComment) -> String

Get the comment text

#
HTMLRewriter

#external
pub type HTMLRewriter

HTMLRewriter - enables HTML parsing and transformation

#
HTMLRewriter::as_any

#
HTMLRewriter::new

Create a new HTMLRewriter

#
HTMLRewriter::on

fn HTMLRewriter::on(self : HTMLRewriter, selector : String, handler : ElementHandler) -> HTMLRewriter

Attach an element handler to matching CSS selector

#
HTMLRewriter::on_document

fn HTMLRewriter::on_document(self : HTMLRewriter, handler : DocumentHandler) -> HTMLRewriter

Attach a document handler

#
HTMLRewriter::transform

Transform a Response

#
InstanceStatus

#external
pub type InstanceStatus

InstanceStatus - status information for a workflow instance

#
InstanceStatus::as_any

#
InstanceStatus::error

Get the error information if any

#
InstanceStatus::is_complete

fn InstanceStatus::is_complete(self : InstanceStatus) -> Bool

Check if instance is complete

#
InstanceStatus::is_errored

fn InstanceStatus::is_errored(self : InstanceStatus) -> Bool

Check if instance has errored

#
InstanceStatus::is_paused

fn InstanceStatus::is_paused(self : InstanceStatus) -> Bool

Check if instance is paused

#
InstanceStatus::is_queued

fn InstanceStatus::is_queued(self : InstanceStatus) -> Bool

Check if instance is queued

#
InstanceStatus::is_running

fn InstanceStatus::is_running(self : InstanceStatus) -> Bool

Check if instance is running

#
InstanceStatus::is_terminated

fn InstanceStatus::is_terminated(self : InstanceStatus) -> Bool

Check if instance is terminated

#
InstanceStatus::is_waiting

fn InstanceStatus::is_waiting(self : InstanceStatus) -> Bool

Check if instance is waiting (sleeping or waiting for event)

#
InstanceStatus::is_waiting_for_pause

fn InstanceStatus::is_waiting_for_pause(self : InstanceStatus) -> Bool

Check if instance is waiting for pause

#
InstanceStatus::output

Get the output if complete

#
InstanceStatus::status

fn InstanceStatus::status(self : InstanceStatus) -> String

Get the status string

#
KVKey

pub(all) struct KVKey {
name : String
expiration : Int?
metadata :
Any
?
}

Key information in list result

#
KVKey::as_any

fn KVKey::as_any(self : KVKey) ->
Any

#
KVListResult

pub(all) struct KVListResult {
keys : Array[KVKey]
list_complete : Bool
cursor : String?
}

Result of KV list operation

#
KVListResult::as_any

#
KVNamespace

#external
pub type KVNamespace

#
KVNamespace::as_any

#
KVNamespace::delete

async fn KVNamespace::delete(self : KVNamespace, key : String) -> Unit

Delete a key from KV store

#
KVNamespace::get

async fn KVNamespace::get(self : KVNamespace, key : String, type_? : String, cacheTtl? : Int) -> String?

Get a value from KV store Returns null if key doesn't exist

#
KVNamespace::get_array_buffer

async fn KVNamespace::get_array_buffer(self : KVNamespace, key : String) ->
Any
?

Get a value as ArrayBuffer

#
KVNamespace::get_json

async fn KVNamespace::get_json(self : KVNamespace, key : String) ->
Any
?

Get a value as JSON

#
KVNamespace::get_stream

async fn KVNamespace::get_stream(self : KVNamespace, key : String) ->
Any
?

Get a value as stream

#
KVNamespace::get_with_metadata

async fn KVNamespace::get_with_metadata(self : KVNamespace, key : String, type_? : String, cacheTtl? : Int) -> KVValueWithMetadata

Get value with metadata

#
KVNamespace::list

async fn KVNamespace::list(self : KVNamespace, prefix? : String, limit? : Int, cursor? : String) -> KVListResult

List keys in the KV namespace

#
KVNamespace::put

async fn KVNamespace::put(self : KVNamespace, key : String, value : String, expiration? : Int, expirationTtl? : Int, metadata? :
Any
) -> Unit

Put a value into KV store

#
KVNamespace::put_with_metadata

async fn KVNamespace::put_with_metadata(self : KVNamespace, key : String, value : String, metadata :
Any
) -> Unit

Put a value with metadata

#
KVValueWithMetadata

pub(all) struct KVValueWithMetadata {
value :
Any
?
metadata :
Any
?
}

Value with metadata from getWithMetadata

#
KVValueWithMetadata::as_any

#
Miniflare

#external
pub type Miniflare

Miniflare instance type

#
Miniflare::as_any

#
Miniflare::dispose

async fn Miniflare::dispose(self : Miniflare) -> Unit

Dispose of Miniflare instance

#
Miniflare::get_d1_database

async fn Miniflare::get_d1_database(self : Miniflare, binding_name : String) -> D1Database

Get D1 database from Miniflare instance

#
Miniflare::get_kv_namespace

async fn Miniflare::get_kv_namespace(self : Miniflare, binding_name : String) -> KVNamespace

Get KV namespace from Miniflare instance

#
Miniflare::get_r2_bucket

async fn Miniflare::get_r2_bucket(self : Miniflare, binding_name : String) -> R2Bucket

Get R2 bucket from Miniflare instance

#
Miniflare::new

async fn Miniflare::new(options : MiniflareOptions) -> Miniflare

Create a new Miniflare instance (async due to ESM dynamic import)

#
Miniflare::ready

async fn Miniflare::ready(self : Miniflare) -> Unit

Wait for Miniflare to be ready

#
MiniflareOptions

pub(all) struct MiniflareOptions {
script : String?
modules : Bool
d1Databases : Array[String]?
r2Buckets : Array[String]?
kvNamespaces : Array[String]?
}

Miniflare options for creating a new instance

#
MiniflareOptions::default

Create default MiniflareOptions

#
R2Bucket

#external
pub type R2Bucket

#
R2Bucket::as_any

#
R2Bucket::create_multipart_upload

async fn R2Bucket::create_multipart_upload(self : R2Bucket, key : String, httpMetadata? : R2HttpMetadata, customMetadata? :
Any
, md5? : String, sha1? : String, sha256? : String, sha384? : String, sha512? : String) -> R2MultipartUpload

Create a multipart upload

#
R2Bucket::delete

async fn R2Bucket::delete(self : R2Bucket, key : String) -> Unit

Delete an object from R2

#
R2Bucket::delete_multiple

async fn R2Bucket::delete_multiple(self : R2Bucket, keys : Array[String]) -> Unit

Delete multiple objects from R2

#
R2Bucket::get

async fn R2Bucket::get(self : R2Bucket, key : String, onlyIf? : R2Conditional, range? : R2Range) -> R2Object?

Get an object from R2

#
R2Bucket::head

async fn R2Bucket::head(self : R2Bucket, key : String) -> R2Object?

Get object metadata without body

#
R2Bucket::list

async fn R2Bucket::list(self : R2Bucket, limit? : Int, prefix? : String, cursor? : String, delimiter? : String, startAfter? : String, include_? : Array[String]) -> R2Objects

List objects in the bucket

#
R2Bucket::put

async fn R2Bucket::put(self : R2Bucket, key : String, value :
Any
, httpMetadata? : R2HttpMetadata, customMetadata? :
Any
, md5? : String, sha1? : String, sha256? : String, sha384? : String, sha512? : String) -> R2Object

Put an object into R2

#
R2Bucket::resume_multipart_upload

fn R2Bucket::resume_multipart_upload(self : R2Bucket, key : String, upload_id : String) -> R2MultipartUpload

Resume a multipart upload

#
R2Conditional

pub(all) struct R2Conditional {
etagMatches : String?
etagDoesNotMatch : String?
uploadedBefore :
Date
?
uploadedAfter :
Date
?
}

Conditional options for R2 operations

#
R2HttpMetadata

pub(all) struct R2HttpMetadata {
contentType : String?
contentLanguage : String?
contentDisposition : String?
contentEncoding : String?
cacheControl : String?
cacheExpiry :
Date
?
}

HTTP metadata for R2 objects

#
R2HttpMetadata::as_any

#
R2MultipartUpload

#external
pub type R2MultipartUpload

R2 Multipart Upload

#
R2MultipartUpload::abort

async fn R2MultipartUpload::abort(self : R2MultipartUpload) -> Unit

Abort the multipart upload

#
R2MultipartUpload::as_any

#
R2MultipartUpload::complete

async fn R2MultipartUpload::complete(self : R2MultipartUpload, parts : Array[R2UploadedPart]) -> R2Object

Complete the multipart upload

#
R2MultipartUpload::key

fn R2MultipartUpload::key(self : R2MultipartUpload) -> String

Get upload key

#
R2MultipartUpload::uploadId

fn R2MultipartUpload::uploadId(self : R2MultipartUpload) -> String

Get upload ID

#
R2MultipartUpload::upload_part

async fn R2MultipartUpload::upload_part(self : R2MultipartUpload, part_number : Int, value :
Any
) -> R2UploadedPart

Upload a part

#
R2Object

#external
pub type R2Object

R2 Object type

#
R2Object::array_buffer

Get object body as ArrayBuffer

#
R2Object::as_any

#
R2Object::blob

Get object body as blob

#
R2Object::body

Get object body as ReadableStream

#
R2Object::body_used

fn R2Object::body_used(self : R2Object) -> Bool

Get object body used status

#
R2Object::custom_metadata

fn R2Object::custom_metadata(self : R2Object) ->
Any

Get object custom metadata

#
R2Object::etag

fn R2Object::etag(self : R2Object) -> String

Get object etag

#
R2Object::http_metadata

fn R2Object::http_metadata(self : R2Object) ->
Any

Get object HTTP metadata

#
R2Object::json

async fn R2Object::json(self : R2Object) ->
Any

Get object body as JSON

#
R2Object::key

fn R2Object::key(self : R2Object) -> String

Get object key

#
R2Object::size

fn R2Object::size(self : R2Object) -> Int

Get object size

#
R2Object::text

async fn R2Object::text(self : R2Object) -> String

Get object body as text

#
R2Object::uploaded

fn R2Object::uploaded(self : R2Object) ->
Any

Get object uploaded time

#
R2Object::version

fn R2Object::version(self : R2Object) -> String

Get object version

#
R2Object::write_http_metadata

fn R2Object::write_http_metadata(self : R2Object, headers :
Any
) -> Unit

Write object to a writable stream

#
R2Objects

#external
pub type R2Objects

Result of list operation (external type to properly handle JS object properties)

#
R2Objects::as_any

#
R2Objects::cursor

fn R2Objects::cursor(self : R2Objects) -> String?

Get the cursor for pagination

#
R2Objects::delimited_prefixes

fn R2Objects::delimited_prefixes(self : R2Objects) -> Array[String]

Get the delimited prefixes

#
R2Objects::objects

fn R2Objects::objects(self : R2Objects) -> Array[R2Object]

Get the objects array

#
R2Objects::truncated

fn R2Objects::truncated(self : R2Objects) -> Bool

Check if the list is truncated

#
R2Range

pub(all) struct R2Range {
offset : Int?
length : Int?
suffix : Int?
}

Range options for R2 get operations

#
R2UploadedPart

pub(all) struct R2UploadedPart {
partNumber : Int
etag : String
}

Uploaded part information

#
R2UploadedPart::as_any

#
SqlStorage

#external
pub type SqlStorage

SQLite Storage - provides SQL interface for Durable Object storage Accessed via storage.sql

#
SqlStorage::as_any

#
SqlStorage::database_size

fn SqlStorage::database_size(self : SqlStorage) -> Int

Get the current database size in bytes

#
SqlStorage::exec

fn SqlStorage::exec(self : SqlStorage, query : String, bindings : Array[
Any
]) -> SqlStorageCursor

Execute a SQL query with optional parameter bindings Returns a cursor for iterating over results

#
SqlStorage::exec1

fn SqlStorage::exec1(self : SqlStorage, query : String, p1 :
Any
) -> SqlStorageCursor

Execute a SQL query with a single binding

#
SqlStorage::exec2

Execute a SQL query with two bindings

#
SqlStorage::exec3

Execute a SQL query with three bindings

#
SqlStorage::exec_raw

fn SqlStorage::exec_raw(self : SqlStorage, query : String) -> SqlStorageCursor

Execute a SQL query without bindings

#
SqlStorageCursor

#external
pub type SqlStorageCursor

SQLite Storage Cursor - iterator over query results

#
SqlStorageCursor::as_any

#
SqlStorageCursor::column_names

fn SqlStorageCursor::column_names(self : SqlStorageCursor) -> Array[String]

Get column names in order

#
SqlStorageCursor::next

Get the next row from the cursor Returns {done: bool, value: row} iterator result

#
SqlStorageCursor::one

Get exactly one row from the cursor Throws an error if the result set doesn't contain exactly one row

#
SqlStorageCursor::raw

Get a raw iterator that returns rows as arrays instead of objects

#
SqlStorageCursor::rows_read

fn SqlStorageCursor::rows_read(self : SqlStorageCursor) -> Int

Get the number of rows read so far

#
SqlStorageCursor::rows_written

fn SqlStorageCursor::rows_written(self : SqlStorageCursor) -> Int

Get the number of rows written so far

#
SqlStorageCursor::to_array

Convert all remaining cursor values to an array of row objects

#
SqlStorageIteratorResult

#external
pub type SqlStorageIteratorResult

Iterator result from SqlStorageCursor::next()

#
SqlStorageIteratorResult::as_any

#
SqlStorageIteratorResult::done

Check if the iterator is done

#
SqlStorageIteratorResult::value

Get the value (row) from the iterator result

#
TextChunk

#external
pub type TextChunk

TextChunk - represents a text node chunk

#
TextChunk::after

fn TextChunk::after(self : TextChunk, content : String, options : ContentOptions) -> TextChunk

Insert content after the text

#
TextChunk::after_text

fn TextChunk::after_text(self : TextChunk, content : String) -> TextChunk

Insert content after the text (text mode)

#
TextChunk::as_any

#
TextChunk::before

fn TextChunk::before(self : TextChunk, content : String, options : ContentOptions) -> TextChunk

Insert content before the text

#
TextChunk::before_text

fn TextChunk::before_text(self : TextChunk, content : String) -> TextChunk

Insert content before the text (text mode)

#
TextChunk::last_in_text_node

fn TextChunk::last_in_text_node(self : TextChunk) -> Bool

Check if this is the last chunk in the text node

#
TextChunk::remove

fn TextChunk::remove(self : TextChunk) -> TextChunk

Remove the text

#
TextChunk::removed

fn TextChunk::removed(self : TextChunk) -> Bool

Check if text was removed

#
TextChunk::replace

fn TextChunk::replace(self : TextChunk, content : String, options : ContentOptions) -> TextChunk

Replace the text with content

#
TextChunk::replace_text

fn TextChunk::replace_text(self : TextChunk, content : String) -> TextChunk

Replace the text with content (text mode)

#
TextChunk::text

fn TextChunk::text(self : TextChunk) -> String

Get the text content

#
VectorizeIndex

#external
pub type VectorizeIndex

VectorizeIndex - represents a Vectorize index binding

#
VectorizeIndex::as_any

#
VectorizeIndex::delete_by_ids

async fn VectorizeIndex::delete_by_ids(self : VectorizeIndex, ids : Array[String]) -> VectorizeMutationResult

Delete vectors by their IDs

#
VectorizeIndex::describe

async fn VectorizeIndex::describe(self : VectorizeIndex) -> VectorizeIndexInfo

Describe the index configuration

#
VectorizeIndex::get_by_ids

async fn VectorizeIndex::get_by_ids(self : VectorizeIndex, ids : Array[String]) -> Array[VectorizeVector]

Get vectors by their IDs

#
VectorizeIndex::insert

Insert vectors into the index Vectors with existing IDs will be ignored (use upsert to overwrite)

#
VectorizeIndex::query

async fn VectorizeIndex::query(self : VectorizeIndex, vector : Array[Double], options : VectorizeQueryOptions) -> VectorizeMatches

Query the index with a vector

#
VectorizeIndex::query_simple

async fn VectorizeIndex::query_simple(self : VectorizeIndex, vector : Array[Double]) -> VectorizeMatches

Query the index with a vector (no options)

#
VectorizeIndex::upsert

Upsert vectors into the index Vectors with existing IDs will be completely overwritten

#
VectorizeIndexInfo

#external
pub type VectorizeIndexInfo

Index configuration information

#
VectorizeIndexInfo::as_any

#
VectorizeIndexInfo::dimensions

fn VectorizeIndexInfo::dimensions(self : VectorizeIndexInfo) -> Int

Get the number of dimensions

#
VectorizeIndexInfo::metric

fn VectorizeIndexInfo::metric(self : VectorizeIndexInfo) -> String

Get the distance metric (e.g., "cosine", "euclidean", "dot-product")

#
VectorizeIndexInfo::vector_count

fn VectorizeIndexInfo::vector_count(self : VectorizeIndexInfo) -> Int

Get the total number of vectors in the index

#
VectorizeMatch

#external
pub type VectorizeMatch

A single match result

#
VectorizeMatch::as_any

#
VectorizeMatch::id

fn VectorizeMatch::id(self : VectorizeMatch) -> String

Get the vector ID

#
VectorizeMatch::metadata

Get the metadata (if returnMetadata was set)

#
VectorizeMatch::ns

fn VectorizeMatch::ns(self : VectorizeMatch) -> String?

Get the namespace

#
VectorizeMatch::score

fn VectorizeMatch::score(self : VectorizeMatch) -> Double

Get the similarity score

#
VectorizeMatch::values

fn VectorizeMatch::values(self : VectorizeMatch) -> Array[Double]?

Get the vector values (if returnValues was true)

#
VectorizeMatches

#external
pub type VectorizeMatches

Query result containing matched vectors

#
VectorizeMatches::as_any

#
VectorizeMatches::count

fn VectorizeMatches::count(self : VectorizeMatches) -> Int

Get the count of matches

#
VectorizeMatches::matches

Get the matched vectors

#
VectorizeMutationResult

#external
pub type VectorizeMutationResult

Result of mutation operations (insert, upsert, delete)

#
VectorizeMutationResult::as_any

#
VectorizeMutationResult::count

Get the count of affected vectors

#
VectorizeMutationResult::ids

Get the IDs of affected vectors

#
VectorizeMutationResult::mutation_id

fn VectorizeMutationResult::mutation_id(self : VectorizeMutationResult) -> String

Get the mutation ID

#
VectorizeQueryOptions

pub(all) struct VectorizeQueryOptions {
topK : Int?
returnValues : Bool?
returnMetadata : VectorizeReturnMetadata?
ns : String?
filter :
Any
?
}

Query options for Vectorize

#
VectorizeQueryOptions::default

Default query options

#
VectorizeQueryOptions::to_js

Convert VectorizeQueryOptions to JavaScript object

#
VectorizeReturnMetadata

pub(all) enum VectorizeReturnMetadata {
None_
Indexed
All
}

Metadata return options

#
VectorizeReturnMetadata::to_string

fn VectorizeReturnMetadata::to_string(self : VectorizeReturnMetadata) -> String

#
VectorizeVector

pub(all) struct VectorizeVector {
id : String
values : Array[Double]
ns : String?
metadata :
Any
?
}

Vector representation for Vectorize

#
VectorizeVector::from_js

Create VectorizeVector from JavaScript object

#
VectorizeVector::to_js

Convert VectorizeVector to JavaScript object

#
WaitForEventOptions

pub(all) struct WaitForEventOptions {
event : String
timeout : String?
}

Options for waitForEvent

#
WaitForEventOptions::new

fn WaitForEventOptions::new(event : String) -> WaitForEventOptions

Create wait options with just event type

#
WaitForEventOptions::to_js

Convert WaitForEventOptions to JavaScript object

#
WaitForEventOptions::with_timeout

fn WaitForEventOptions::with_timeout(event : String, timeout : String) -> WaitForEventOptions

Create wait options with event and timeout

#
Workflow

#external
pub type Workflow

Workflow - represents a Workflow binding

#
Workflow::as_any

#
Workflow::create

async fn Workflow::create(self : Workflow, options : WorkflowInstanceCreateOptions) -> WorkflowInstance

Create a new workflow instance

#
Workflow::create_batch

async fn Workflow::create_batch(self : Workflow, batch : Array[WorkflowInstanceCreateOptions]) -> Array[WorkflowInstance]

Create multiple workflow instances (up to 100)

#
Workflow::create_default

async fn Workflow::create_default(self : Workflow) -> WorkflowInstance

Create a new workflow instance with default options

#
Workflow::create_with_id

async fn Workflow::create_with_id(self : Workflow, id : String) -> WorkflowInstance

Create a new workflow instance with just an ID

#
Workflow::get

async fn Workflow::get(self : Workflow, id : String) -> WorkflowInstance

Get an existing workflow instance by ID

#
WorkflowError

#external
pub type WorkflowError

WorkflowError - error information from a workflow

#
WorkflowError::as_any

#
WorkflowError::message

fn WorkflowError::message(self : WorkflowError) -> String

Get the error message

#
WorkflowError::name

fn WorkflowError::name(self : WorkflowError) -> String

Get the error name

#
WorkflowEvent

#external
pub type WorkflowEvent

WorkflowEvent - the event object passed to a workflow's run method

#
WorkflowEvent::as_any

#
WorkflowEvent::instance_id

fn WorkflowEvent::instance_id(self : WorkflowEvent) -> String

Get the instance ID

#
WorkflowEvent::payload

Get the payload data

#
WorkflowEvent::timestamp

Get the timestamp when the instance was created

#
WorkflowEventPayload

#external
pub type WorkflowEventPayload

WorkflowEventPayload - payload received from waitForEvent

#
WorkflowEventPayload::as_any

#
WorkflowEventPayload::event_type

fn WorkflowEventPayload::event_type(self : WorkflowEventPayload) -> String

Get the event type

#
WorkflowEventPayload::payload

Get the payload data

#
WorkflowEventPayload::timestamp

Get the timestamp

#
WorkflowInstance

#external
pub type WorkflowInstance

WorkflowInstance - represents a running workflow instance

#
WorkflowInstance::as_any

#
WorkflowInstance::id

fn WorkflowInstance::id(self : WorkflowInstance) -> String

Get the instance ID

#
WorkflowInstance::pause

async fn WorkflowInstance::pause(self : WorkflowInstance) -> Unit

Pause the workflow instance

#
WorkflowInstance::restart

async fn WorkflowInstance::restart(self : WorkflowInstance) -> Unit

Restart the workflow instance

#
WorkflowInstance::resume_

async fn WorkflowInstance::resume_(self : WorkflowInstance) -> Unit

Resume a paused workflow instance

#
WorkflowInstance::send_event

async fn WorkflowInstance::send_event(self : WorkflowInstance, event_type : String, payload :
Any
) -> Unit

Send an event to the workflow instance

#
WorkflowInstance::send_event_simple

async fn WorkflowInstance::send_event_simple(self : WorkflowInstance, event_type : String) -> Unit

Send an event without payload

#
WorkflowInstance::status

Get the current status of the instance

#
WorkflowInstance::terminate

async fn WorkflowInstance::terminate(self : WorkflowInstance) -> Unit

Terminate the workflow instance

#
WorkflowInstanceCreateOptions

pub(all) struct WorkflowInstanceCreateOptions {
id : String?
params :
Any
?
}

Options for creating a workflow instance

#
WorkflowInstanceCreateOptions::to_js

Convert WorkflowInstanceCreateOptions to JavaScript object

#
WorkflowInstanceCreateOptions::with_id

Create options with just an ID

#
WorkflowInstanceCreateOptions::with_id_and_params

Create options with ID and params

#
WorkflowInstanceCreateOptions::with_params

Create options with just params (auto-generated ID)

#
WorkflowRetryConfig

pub(all) struct WorkflowRetryConfig {
limit : Int
delay : String
backoff : String
}

Retry configuration for workflow steps

#
WorkflowRetryConfig::constant

fn WorkflowRetryConfig::constant(limit : Int, delay : String) -> WorkflowRetryConfig

Create constant backoff retry config

#
WorkflowRetryConfig::exponential

fn WorkflowRetryConfig::exponential(limit : Int, delay : String) -> WorkflowRetryConfig

Create exponential backoff retry config

#
WorkflowRetryConfig::to_js

Convert WorkflowRetryConfig to JavaScript object

#
WorkflowStep

#external
pub type WorkflowStep

WorkflowStep - provides step operations within a workflow

#
WorkflowStep::as_any

#
WorkflowStep::do_

async fn WorkflowStep::do_(self : WorkflowStep, name : String, callback : async () ->
Any
) ->
Any

Execute a durable step with automatic retries

#
WorkflowStep::do_with_config

async fn WorkflowStep::do_with_config(self : WorkflowStep, name : String, config : WorkflowStepConfig, callback : async () ->
Any
) ->
Any

Execute a durable step with configuration

#
WorkflowStep::sleep

async fn WorkflowStep::sleep(self : WorkflowStep, name : String, duration : String) -> Unit

Sleep for a specified duration

#
WorkflowStep::sleep_until

async fn WorkflowStep::sleep_until(self : WorkflowStep, name : String, timestamp :
Any
) -> Unit

Sleep until a specific timestamp

#
WorkflowStep::wait_for_event

async fn WorkflowStep::wait_for_event(self : WorkflowStep, name : String, options : WaitForEventOptions) -> WorkflowEventPayload

Wait for an external event

#
WorkflowStepConfig

pub(all) struct WorkflowStepConfig {
retries : WorkflowRetryConfig?
timeout : String?
}

Configuration for workflow step retry behavior

#
WorkflowStepConfig::new

fn WorkflowStepConfig::new(retries : WorkflowRetryConfig, timeout : String) -> WorkflowStepConfig

Create step config with both retries and timeout

#
WorkflowStepConfig::to_js

Convert WorkflowStepConfig to JavaScript object

#
WorkflowStepConfig::with_retries

Create step config with retries

#
WorkflowStepConfig::with_timeout

fn WorkflowStepConfig::with_timeout(timeout : String) -> WorkflowStepConfig

Create step config with just timeout

#
get_test_d1

fn get_test_d1() -> D1Database?

Get D1 database from global test environment (set by miniflare test harness)

#
get_test_d1_exn

fn get_test_d1_exn() -> D1Database

Get D1 database from global test environment, panic if not available

#
js_number_to_int

fn js_number_to_int(value :
Any
) -> Int

Convert a JavaScript number from D1 result to MoonBit Int (32-bit)

#
js_number_to_int64

fn js_number_to_int64(value :
Any
) -> Int64

Convert a JavaScript number from D1 result to MoonBit Int64 D1 returns SQLite INTEGER as JavaScript numbers, but MoonBit Int64 uses { hi, lo } representation in JS target.

#
non_retryable_error

fn non_retryable_error(message : String) ->
Any

NonRetryableError - when thrown inside step.do(), stops retries

#
non_retryable_error_with_name

fn non_retryable_error_with_name(message : String, name : String) ->
Any

NonRetryableError with custom name

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

ยฉ 2026 mooncakes.io