Skip to content

Commit

Permalink
Let's get Relayed!
Browse files Browse the repository at this point in the history
  • Loading branch information
BlowaterNostr committed Mar 31, 2024
1 parent a6c9150 commit f92837b
Show file tree
Hide file tree
Showing 21 changed files with 1,130 additions and 111 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: test

on:
push:
branches: ["main"]
pull_request:
branches: ["*"]

permissions:
contents: read

jobs:
test:
timeout-minutes: 1
runs-on: ubuntu-latest
strategy:
matrix:
deno-version: [1.41.0]

steps:
- name: Setup repo
uses: actions/checkout@v3
with:
submodules: 'true'

- name: Setup Deno
uses: denoland/setup-deno@v1

- name: Run tests
run: deno task test
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# npm dependencies
node_modules/
.DS_Store
deploy/default.ts
*cov_profile*
coverage
test.sqlite
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "nostr.ts"]
path = nostr.ts
url = https://github.com/BlowaterNostr/nostr.ts
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"deno.enable": true,
"deno.lint": false
"editor.indentSize": "tabSize"
}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Relayed

## Local Development

To begin, install Deno by following the instructions at https://deno.land/manual/getting_started/installation.

Next, create a file named `deploy/default.ts`:

```bash
cp deploy/default.example.ts deploy/defalut.ts
```

After that, launch the project with the command:

```bash
deno task start
```

Finally, open your browser and go to `http://localhost:8000/api` to access the GraphQL playground.

### Use GraphQL Playground

To begin, click the `Re-fetch GraphQL schema` button to retrieve the schema.

In the Headers section, include `{"password":"123456"}` for identity verification.

You can now utilize the GraphQL Playground to communicate with the server.

### Client Connection

Relay url is `ws://localhost:8000`.

### Database

If you are using MacOS, the directory might be `~/Library/Caches/deno/location_data`.
43 changes: 41 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
{
"tasks": {
"run": "deno run --allow-net --allow-env --unstable deploy/default.ts",
"test": "deno test --allow-net --unstable --allow-read --allow-write --coverage test.ts"
},
"lint": {
"rules": {
"tags": [
"fresh",
"recommended"
],
"exclude": ["require-await", "require-yield", "no-unused-vars"]
}
},
"exclude": [
"**/_fresh/*"
],
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"@preact/signals": "https://esm.sh/*@preact/[email protected]",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"tailwindcss": "npm:[email protected]",
"tailwindcss/": "npm:/[email protected]/",
"tailwindcss/plugin": "npm:/[email protected]/plugin.js",
"$std/": "https://deno.land/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact",
"lib": [
"deno.unstable"
],
"noImplicitAny": false
},
"nodeModulesDir": true,
"fmt": {
"indentWidth": 4
}
"indentWidth": 4,
"lineWidth": 110,
"exclude": ["cov_profile", "coverage"]
},
"lock": false
}
11 changes: 0 additions & 11 deletions deno.lock

This file was deleted.

9 changes: 9 additions & 0 deletions deploy/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { run } from "../main.tsx";

run({
port: 8080,
default_policy: {
allowed_kinds: "all", // or none,
},
password: Deno.env.get("relayed_pw"),
});
43 changes: 43 additions & 0 deletions graphql-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { gql } from "https://deno.land/x/[email protected]/mod.ts";

export const typeDefs = gql`
type Query {
events(pubkey: String, offset: Int, limit: Int): Events
event(id: String): Event
policies: [Policy]
}
type Mutation {
add_block(kind: Int, pubkey: String, ): Policy!
remove_block(kind: Int, pubkey: String, ): Policy!
add_allow(kind: Int, pubkey: String, ): Policy!
remove_allow(kind: Int, pubkey: String, ): Policy!
set_policy(kind: Int, read: Boolean, write: Boolean): Policy!
}
type Events {
count: Int!
data: [Event]
}
type Event {
id: String!
content: String!
pubkey: PublicKey!
kind: Int!
created_at: Int!
sig: String!
tags: [String!]!
}
type PublicKey {
hex: String!
bech32: String!
events: [Event!]!
}
type Policy {
kind: Int!
read: Boolean!
write: Boolean!
allow: [String!]!
block: [String!]!
}
`;
97 changes: 0 additions & 97 deletions main.ts

This file was deleted.

Loading

0 comments on commit f92837b

Please sign in to comment.