Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/counter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "counter",
"version": "2.0.9",
"name": "example-counter",
"version": "2.0.8",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions examples/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.actorcore
node_modules
39 changes: 39 additions & 0 deletions examples/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Deno Example for RivetKit

Example project demonstrating basic actor state management and RPC calls with [RivetKit](https://rivetkit.org) using Deno runtime.

[Learn More →](https://github.com/rivet-dev/rivetkit)

[Discord](https://rivet.dev/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-dev/rivetkit/issues)

## Getting Started

### Prerequisites

- Deno

### Installation

```sh
git clone https://github.com/rivet-dev/rivetkit
cd rivetkit/examples/deno
pnpm install
```

**Notice:** We use `pnpm install` here as Deno offers compatability with package.json via npm/pnpm. Some packages used in rivetkit are simpler to install with npm/pnpm.

### Development

```sh
deno task dev
```

Run the connect script to interact with the counter:

```sh
deno task connect
```

## License

Apache 2.0
15 changes: 15 additions & 0 deletions examples/deno/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"tasks": {
"dev": "deno run --allow-env --allow-sys --allow-read --allow-ffi --allow-net src/server.ts",
"check-types": "deno check",
"test": "deno test --allow-env --allow-sys --allow-read --allow-ffi --allow-net",
"connect": "deno run --allow-env --allow-sys --allow-read --allow-ffi --allow-net scripts/connect.ts"
},
"imports": {
"os": "node:os",
"path": "node:path",
"fs": "node:fs",
"fs/promises": "node:fs/promises",
"crypto": "node:crypto"
}
}
21 changes: 21 additions & 0 deletions examples/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"//": "This package.json is required, once is released with updated engine-runner packages, it can be converted to deno.json",
"name": "example-deno",
"version": "2.0.6",
"private": true,
"type": "module",
"scripts": {
"dev": "deno run --allow-all src/server.ts",
"check-types": "deno check",
"connect": "deno run --allow-all scripts/connect.ts"
},
"devDependencies": {
"@types/deno": "^2.3.0",
"@types/node": "^24.5.2"
},
"stableVersion": "0.8.0",
"dependencies": {
"hono": "4.9.8",
"rivetkit": "workspace:*"
}
}
17 changes: 17 additions & 0 deletions examples/deno/scripts/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createClient } from "rivetkit/client";
import type { Registry } from "../src/registry.ts";

async function main() {
const client = createClient<Registry>("http://localhost:8080");

const counter = client.counter.getOrCreate().connect();

for (let i = 0; i < 5; i++) {
const out = await counter.increment(5);
console.log("RPC:", out);

await new Promise((resolve) => setTimeout(resolve, 1000));
}
}

main();
23 changes: 23 additions & 0 deletions examples/deno/src/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { actor, setup } from "rivetkit";

const counter = actor({
state: {
count: 0,
},
actions: {
increment: (c, x: number) => {
c.state.count += x;
c.broadcast("newCount", c.state.count);
return c.state.count;
},
getCount: (c) => {
return c.state.count;
},
},
});

export const registry = setup({
use: { counter },
});

export type Registry = typeof registry;
12 changes: 12 additions & 0 deletions examples/deno/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { upgradeWebSocket } from "hono/deno";
import { registry } from "./registry.ts";

const { fetch } = registry.start({
// Deno requires using Deno.serve
disableServer: true,
// Specify Deno-specific upgradeWebSocket
getUpgradeWebSocket: () => upgradeWebSocket,
});

// Start server
Deno.serve({ port: 8080 }, fetch);
43 changes: 43 additions & 0 deletions examples/deno/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "esnext",
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": ["deno.ns", "esnext", "DOM"],
/* Specify what JSX code is generated. */
"jsx": "react-jsx",

/* Specify what module code is generated. */
"module": "esnext",
/* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "bundler",
/* Specify type package names to be included without being referenced in a source file. */
"types": ["node"],
/* Enable importing .json files */
"resolveJsonModule": true,

/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
"allowJs": true,
/* Enable error reporting in type-checked JavaScript files. */
"checkJs": false,

/* Disable emitting files from a compilation. */
"noEmit": true,

/* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true,
/* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,

/* Enable all strict type-checking options. */
"strict": true,

/* Skip type checking all .d.ts files. */
"skipLibCheck": true
},
"include": ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/rivetkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@
"invariant": "^2.2.4",
"nanoevents": "^9.1.0",
"on-change": "^5.0.1",
"pino": "^9.5.0",
"p-retry": "^6.2.1",
"pino": "^9.5.0",
"zod": "^3.25.76"
},
"devDependencies": {
Expand Down
Loading