mirror of
https://github.com/wisplite/tether.git
synced 2026-05-01 06:22:41 -05:00
mutation proof of concept
client can now send mutations and server properly executes them TODO: implement query execution, add auth, add storage
This commit is contained in:
+15
-2
@@ -1,8 +1,21 @@
|
||||
import { TetherClient } from "tether-ts";
|
||||
import { createInterface } from "node:readline/promises";
|
||||
|
||||
const client = new TetherClient();
|
||||
client.connect("ws://localhost:8080/tether");
|
||||
|
||||
client.subscribe("messages", (message) => {
|
||||
client.subscribe("messages", { room: "1" }, (message) => {
|
||||
console.log("Received message", message);
|
||||
});
|
||||
});
|
||||
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
while (true) {
|
||||
const message = await rl.question("Enter a message");
|
||||
if (message) {
|
||||
client.sendMutation("createMessage", { room: "1", message: message });
|
||||
}
|
||||
}
|
||||
Generated
+36
-1
@@ -10,12 +10,47 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"tether-ts": "github:wisplite/tether-ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.19.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.17.tgz",
|
||||
"integrity": "sha512-wGdMcf+vPYM6jikpS/qhg6WiqSV/OhG+jeeHT/KlVqxYfD40iYJf9/AE1uQxVWFvU7MipKRkRv8NSHiCGgPr8Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tether-ts": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "git+ssh://git@github.com/wisplite/tether-ts.git#5202a7f844be4ad7f3a463352fe366c4718a2749",
|
||||
"resolved": "git+ssh://git@github.com/wisplite/tether-ts.git#8945de00ece92ce1e939a3ff70c5312f80e56dda",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"tether-ts": "github:wisplite/tether-ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["*.ts"]
|
||||
}
|
||||
+11
-5
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/google/uuid"
|
||||
"github.com/wisplite/tether"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -16,11 +17,11 @@ type User struct {
|
||||
}
|
||||
|
||||
type Messages struct {
|
||||
ID string `gorm:"primaryKey"`
|
||||
Message string
|
||||
SenderID string
|
||||
ReceiverID string
|
||||
CreatedAt time.Time
|
||||
ID string `gorm:"primaryKey"`
|
||||
Message string
|
||||
SenderID string
|
||||
RoomID string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -42,6 +43,11 @@ func main() {
|
||||
return nil
|
||||
})
|
||||
|
||||
engine.RegisterMutation("createMessage", func(ctx *tether.MutationCtx) error {
|
||||
ctx.DB.Create(&Messages{ID: uuid.NewString(), Message: ctx.Params["message"].(string), SenderID: ctx.AuthCtx.UserID, RoomID: ctx.Params["room"].(string)})
|
||||
return nil
|
||||
})
|
||||
|
||||
http.HandleFunc("/tether", engine.Handle)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user