-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge toolchain in to monorepo
- Loading branch information
1 parent
94ff2d8
commit 6498eb7
Showing
182 changed files
with
15,659 additions
and
607 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,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); |
This file contains 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,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 | ||
|
This file contains 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,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 | ||
|
This file contains 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,4 @@ | ||
#!/bin/sh | ||
|
||
npx source-map-cli resolve .rivet/backend/output.js $1 $2 | ||
|
This file contains 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,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(); | ||
} | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"scripts": { | ||
"fetch_counter": { | ||
"public": true | ||
} | ||
}, | ||
"errors": {}, | ||
"actors": { | ||
"counter": {} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/basic/modules/actors_test/scripts/fetch_counter.ts
This file contains 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,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", | ||
{}, | ||
); | ||
} |
This file contains 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,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); | ||
} | ||
}); | ||
|
This file contains 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,4 @@ | ||
export interface Config { | ||
foo: string; | ||
bar: number; | ||
} |
This file contains 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,6 @@ | ||
{ | ||
"scripts": { | ||
"read_config": {} | ||
}, | ||
"errors": {} | ||
} |
This file contains 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,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, | ||
}; | ||
} |
This file contains 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,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); | ||
}); |
This file contains 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,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" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/basic/modules/foo/db/migrations/1724448780_minor_winter_soldier.sql
This file contains 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,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 | ||
); |
1 change: 1 addition & 0 deletions
1
examples/basic/modules/foo/db/migrations/1724448812_fine_rage.sql
This file contains 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 @@ | ||
ALTER TABLE "module_foo"."table6" RENAME TO "table7"; |
1 change: 1 addition & 0 deletions
1
examples/basic/modules/foo/db/migrations/1724448902_sleepy_purple_man.sql
This file contains 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 @@ | ||
ALTER TABLE "module_foo"."table7" RENAME TO "table8"; |
76 changes: 76 additions & 0 deletions
76
examples/basic/modules/foo/db/migrations/meta/1724448780_snapshot.json
This file contains 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 @@ | ||
{ | ||
"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": {} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
examples/basic/modules/foo/db/migrations/meta/1724448812_snapshot.json
This file contains 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 @@ | ||
{ | ||
"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": {} | ||
} | ||
} |
Oops, something went wrong.