Skip to content
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

chore: merge toolchain in to monorepo #1501

Closed
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
1,499 changes: 1,239 additions & 260 deletions Cargo.lock

Large diffs are not rendered by default.

1,193 changes: 604 additions & 589 deletions Cargo.toml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ignore = [
[licenses]
allow = [
"Apache-2.0",
"0BSD",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
Expand Down
44 changes: 44 additions & 0 deletions examples/actor-layer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Without Rivet actor class

const portStr = Deno.env.get("PORT_http") ?? Deno.env.get("HTTP_PORT");
if (!portStr) throw "Missing port";
const port = parseInt(portStr);
if (!isFinite(port)) throw "Invalid port";

const server = Deno.serve({
handler,
port,
hostname: "0.0.0.0",
});

await server.finished;

async function handler(req: Request) {
console.log("Received request");

let newCount = (await Rivet.kv.get("count") ?? 0) + 1;
await Rivet.kv.put("count", newCount);

return new Response(newCount.toString());
}

// With Rivet actor class

import { Actor } from "@rivet-gg/rivet";

interface State {
count: number;
}

class Counter extends Actor<State> {
initialize(): State {
return { count: 0 };
}

async onRequest(req) {
this.count += 1;
return new Response(this.count.toString());
}
}

Rivet.run(Counter);
5 changes: 5 additions & 0 deletions examples/basic/clean_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

(cd ../.. && docker build -f cli.Dockerfile -t opengb .) && docker run --privileged -it --add-host=host.docker.internal:host-gateway -e DATABASE_URL=postgres://postgres:postgres@host.docker.internal:5432/postgres?sslmode=disable -e VERBOSE=1 -v ./:/backend -w /backend opengb dev
# (cd ../.. && deno task cli:install) && opengb clean && opengb dev

5 changes: 5 additions & 0 deletions examples/basic/fetch_count.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# curl -X POST -d '{"key":"test"}' 'http://localhost:6420/modules/actors_test/scripts/fetch_counter/call'
curl -X POST -d '{"key":"test"}' 'https://test-game-cir.backend.rivet.gg/modules/actors_test/scripts/fetch_counter/call' | jq

4 changes: 4 additions & 0 deletions examples/basic/lookup_sourcemap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

npx source-map-cli resolve .rivet/backend/output.js $1 $2

38 changes: 38 additions & 0 deletions examples/basic/modules/actors_test/actors/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ActorBase, ActorContext, Empty } from "../module.gen.ts";

interface Input {
}

interface State {
count: number;
lastTick: number;
}

export interface FetchResponse {
count: number;
lastTick: number;
schedule: any;
}

export const TICK_INTERVAL = 200;

export class Actor extends ActorBase<Input, State> {
public initialize(_input: Input): State {
this.schedule.after(TICK_INTERVAL, "tick", undefined);
return { count: 0, lastTick: 0 };
}

async rpcFetchCount(_ctx: ActorContext, _req: Empty): Promise<FetchResponse> {
return {
count: this.state.count,
lastTick: this.state.lastTick,
schedule: await this.schedule.__inspect(),
};
}

private tick(ctx: ActorContext) {
this.schedule.after(TICK_INTERVAL, "tick", undefined);
this.state.count += 1;
this.state.lastTick = Date.now();
}
}
11 changes: 11 additions & 0 deletions examples/basic/modules/actors_test/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"fetch_counter": {
"public": true
}
},
"errors": {},
"actors": {
"counter": {}
}
}
18 changes: 18 additions & 0 deletions examples/basic/modules/actors_test/scripts/fetch_counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ScriptContext, Empty } from "../module.gen.ts";
import { FetchResponse } from "../actors/counter.ts";

export interface Request {
key: string;
}

export type Response = FetchResponse;

export async function run(ctx: ScriptContext, req: Request): Promise<Response> {
return await ctx.actors.counter
.getOrCreateAndCall<undefined, Empty, FetchResponse>(
req.key,
undefined,
"rpcFetchCount",
{},
);
}
16 changes: 16 additions & 0 deletions examples/basic/modules/actors_test/tests/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test, TestContext } from "../module.gen.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/mod.ts";
import { delay } from "jsr:@std/async";
import { TICK_INTERVAL } from "../actors/counter.ts";

test("counter", async (ctx: TestContext) => {
const key = `${Math.floor(Math.random() * 100000)}`;

for (let i = 0; i < 5; i++) {
const res = await ctx.modules.actorsTest.fetchCounter({ key });
assertEquals(res.count, i);

await delay(TICK_INTERVAL);
}
});

4 changes: 4 additions & 0 deletions examples/basic/modules/config_test/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Config {
foo: string;
bar: number;
}
6 changes: 6 additions & 0 deletions examples/basic/modules/config_test/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scripts": {
"read_config": {}
},
"errors": {}
}
20 changes: 20 additions & 0 deletions examples/basic/modules/config_test/scripts/read_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";

export interface Request {
}

export interface Response {
config: {
foo: string;
bar: number;
};
}

export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
return {
config: ctx.config,
};
}
8 changes: 8 additions & 0 deletions examples/basic/modules/config_test/tests/read_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, TestContext } from "../module.gen.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/mod.ts";

test("e2e", async (ctx: TestContext) => {
const res = await ctx.call("config_test", "read_config", {}) as any;
assertEquals(res.config.foo, "hello world");
assertEquals(res.config.bar, 1234);
});
21 changes: 21 additions & 0 deletions examples/basic/modules/deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is auto-generated by the Rivet (https://rivet.gg) build system.
//
// Do not edit this file directly.

{
"lint": {
"rules": {
"exclude": [
"no-empty-interface",
"no-explicit-any",
"require-await"
]
}
},
"fmt": {
"useTabs": true
},
"imports": {
"cloudflare:workers": "npm:@cloudflare/workers-types"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE SCHEMA "module_foo";
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "module_foo"."db_entry" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"test2" text,
"test3" text,
"test5" boolean
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "module_foo"."table6" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"hello2" text
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "module_foo"."table6" RENAME TO "table7";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "module_foo"."table7" RENAME TO "table8";
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"id": "23839314-5d54-47b8-a9a0-a1048bd2676d",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"module_foo.db_entry": {
"name": "db_entry",
"schema": "module_foo",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"test2": {
"name": "test2",
"type": "text",
"primaryKey": false,
"notNull": false
},
"test3": {
"name": "test3",
"type": "text",
"primaryKey": false,
"notNull": false
},
"test5": {
"name": "test5",
"type": "boolean",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"module_foo.table6": {
"name": "table6",
"schema": "module_foo",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"hello2": {
"name": "hello2",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {
"module_foo": "module_foo"
},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"id": "9ed1e095-c1ca-4c43-afdc-37f39cd2c9fc",
"prevId": "23839314-5d54-47b8-a9a0-a1048bd2676d",
"version": "7",
"dialect": "postgresql",
"tables": {
"module_foo.db_entry": {
"name": "db_entry",
"schema": "module_foo",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"test2": {
"name": "test2",
"type": "text",
"primaryKey": false,
"notNull": false
},
"test3": {
"name": "test3",
"type": "text",
"primaryKey": false,
"notNull": false
},
"test5": {
"name": "test5",
"type": "boolean",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"module_foo.table7": {
"name": "table7",
"schema": "module_foo",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"hello2": {
"name": "hello2",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {
"module_foo": "module_foo"
},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading
Loading