-
Notifications
You must be signed in to change notification settings - Fork 10k
Actors library alpha changelog #23206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44e5466
Actors library alpha changelog
vy-ton 6a83071
address comments
vy-ton eb0af02
try escaping special character
vy-ton b64937a
try fix mapping entry
vy-ton 927b151
remove escaping
vy-ton 4d13ac0
gemini told me to add double quotes
vy-ton 9469d2a
grammar fix
vy-ton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/content/changelog/durable-objects/2025-06-25-actors-package-alpha.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| title: @cloudflare/actors library: SDK for Durable Objects in alpha | ||
| description: @cloudflare/actors library with Durable Objects helpers and patterns. | ||
| products: | ||
| - durable-objects | ||
| - workers | ||
| date: 2025-06-25T06:00:00Z | ||
| --- | ||
|
|
||
| [@cloudflare/actors](https://www.npmjs.com/package/@cloudflare/actors) package is in alpha and provides a SDK for Durable Objects, in addition to Durable Objects [Workers API](https://developers.cloudflare.com/durable-objects/api/base/). "Actors" originates from the [actor programming model](/durable-objects/what-are-durable-objects/#actor-programming-model), which is a close analogy for Durable Objects. | ||
|
|
||
| For alpha, `/actors` library includes: | ||
vy-ton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * Storage helpers for using embeddeded, per-object SQLite storage, including SQL schema migrations and query template literals | ||
| * Alarm helpers for scheduling multiple alarms provided a date, delay in seconds, or cron expression | ||
| * `Actor` class for using Durable Objects with a defined pattern | ||
|
|
||
| Storage and alarm helper methods can be combined with [any Javascript class](https://github.com/cloudflare/actors?tab=readme-ov-file#storage--alarms-with-durableobject-class) that defines your Durable Object, i.e, ones that extend `DurableObject` including the `Actor` class. | ||
|
|
||
| ```js | ||
| import { Storage } from "@cloudflare/actors/storage"; | ||
|
|
||
| export class ChatRoom extends DurableObject<Env> { | ||
| storage: Storage; | ||
|
|
||
| constructor(ctx: DurableObjectState, env: Env) { | ||
| super(ctx, env) | ||
| this.storage = new Storage(ctx.storage); | ||
| this.storage.migrations = [{ | ||
| idMonotonicInc: 1, | ||
| description: "Create users table", | ||
| sql: "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY)" | ||
| }] | ||
| } | ||
| async fetch(request: Request): Promise<Response> { | ||
| // Run migrations before executing SQL query | ||
| await this.storage.runMigrations(); | ||
|
|
||
| // Query with SQL template | ||
| let userId = new URL(request.url).searchParams.get("userId"); | ||
| const query = this.storage.sql`SELECT * FROM users WHERE id = ${userId};` | ||
| return new Response(`${JSON.stringify(query)}`); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `/actors` library introduces the `Actor` class pattern. `Actor` lets you access Durable Objects without writing the Worker that communicates with your Durable Object (the Worker is created for you). By default, requests are routed to a Durable Object named "default". | ||
vy-ton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```js | ||
| export class MyActor extends Actor<Env> { | ||
| async fetch(request: Request): Promise<Response> { | ||
| return new Response('Hello, World!') | ||
| } | ||
| } | ||
|
|
||
| export default handler(MyActor); | ||
| ``` | ||
|
|
||
| You can [route](/durable-objects/get-started/#3-instantiate-and-communicate-with-a-durable-object) to different Durable Objects by name within your `Actor` class using [`nameFromRequest`](https://github.com/cloudflare/actors?tab=readme-ov-file#actor-with-custom-name). | ||
|
|
||
| ```js | ||
| export class MyActor extends Actor<Env> { | ||
| static nameFromRequest(request: Request): string { | ||
| let url = new URL(request.url); | ||
| return url.searchParams.get("userId") ?? "foo"; | ||
| } | ||
|
|
||
| async fetch(request: Request): Promise<Response> { | ||
| return new Response(`Actor identifier (Durable Object name): ${this.identifier}`); | ||
| } | ||
| } | ||
|
|
||
| export default handler(MyActor); | ||
| ``` | ||
|
|
||
| For more examples, check out the library [README](https://github.com/cloudflare/actors?tab=readme-ov-file#getting-started). `/actors` library is a place for more helpers and built-in patterns, e.g. retry handling and websocket helpers, to reduce development overhead for common Durable Objects functionality. Please share feedback and what more you would like to see on our [Discord channel](https://discord.com/channels/595317990191398933/773219443911819284). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package -> library
alpha -> beta?
communicate value + "why"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done with some rewording, websocket focus to come in Q3