Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
bob2402 committed Apr 6, 2024
1 parent 62daaaf commit 7e25588
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 47 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ You can now utilize the GraphQL Playground to communicate with the server.

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

### Join our community
wss://relayed.deno.dev
### Join our community

wss://relayed.deno.dev
2 changes: 1 addition & 1 deletion deploy/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const relay = await run({
allowed_kinds: "all", // or none,
},
password: Deno.env.get("relayed_pw"),
information: {
default_information: {
name: "Relayed Example",
description: "A lightweight relay written in Deno.",
pubkey: "",
Expand Down
2 changes: 1 addition & 1 deletion graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const typeDefs = gql`
add_allow(kind: Int, pubkey: String, ): Policy!
remove_allow(kind: Int, pubkey: String, ): Policy!
set_policy(kind: Int, read: Boolean, write: Boolean): Policy!
set_relay_information(name: String, description: String, pubkey: String, contact: String, supported_nips: [Int], software: String, version: String, icon: String): RelayInformation!
set_relay_information(name: String, description: String, pubkey: String, contact: String, icon: String): RelayInformation!
}
type Events {
Expand Down
6 changes: 3 additions & 3 deletions main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function run(args: {
port: number;
admin?: PublicKey;
password?: string;
information: RelayInformation;
default_information?: RelayInformation;
default_policy: DefaultPolicy;
kv?: Deno.Kv;
}): Promise<Error | Relay> {
Expand All @@ -58,7 +58,7 @@ export async function run(args: {
args.kv = await Deno.openKv();
}

const { port, default_policy, information } = args;
const { port, default_policy, default_information } = args;

let resolve_hostname;
const hostname = new Promise<string>((resolve) => {
Expand All @@ -69,9 +69,9 @@ export async function run(args: {
const policyStore = new PolicyStore(default_policy, args.kv, await get_all_policies());
const get_relay_information = Information(args.kv);
const relayInformationStore = new RelayInformationStore(
information,
args.kv,
await get_relay_information(),
default_information,
);

const eventStore = await EventStore.New(args.kv);
Expand Down
30 changes: 6 additions & 24 deletions resolvers/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ export class RelayInformationStore {
};

constructor(
default_information: RelayInformation,
private kv: Deno.Kv,
initial_information: RelayInformation | null,
default_information?: RelayInformation,
) {
if (initial_information == null) {
this.information = {
...this.information,
...default_information,
};
} else {
this.information = {
...this.information,
...initial_information,
};
}
this.information = {
...default_information,
...initial_information,
...this.information,
};
}

resolveRelayInformation = async (): Promise<RelayInformation> => {
Expand All @@ -51,9 +45,6 @@ export class RelayInformationStore {
description?: string;
pubkey?: string;
contact?: string;
supported_nips?: number[];
software?: string;
version?: string;
icon?: string;
} | RelayInformation,
) => {
Expand All @@ -70,15 +61,6 @@ export class RelayInformationStore {
if (args.contact != undefined) {
information.contact = args.contact;
}
if (args.supported_nips != undefined) {
information.supported_nips = args.supported_nips;
}
if (args.software != undefined) {
information.software = args.software;
}
if (args.version != undefined) {
information.version = args.version;
}
if (args.icon != undefined) {
information.icon = args.icon;
}
Expand Down
20 changes: 4 additions & 16 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ Deno.test("main", async (t) => {
default_policy: {
allowed_kinds: "none",
},
information: {
name: "Nostr Relay",
},
kv: await Deno.openKv("test.sqlite"),
}) as Relay;

Expand Down Expand Up @@ -132,7 +129,8 @@ Deno.test("main", async (t) => {
await relay.shutdown();
});

Deno.test("relay information", async (t) => {
// https://github.com/nostr-protocol/nips/blob/master/11.md
Deno.test("NIP-11: Relay Information Document", async (t) => {
try {
await Deno.remove("test.sqlite");
} catch (e) {}
Expand All @@ -142,7 +140,7 @@ Deno.test("relay information", async (t) => {
default_policy: {
allowed_kinds: "none",
},
information: {
default_information: {
name: "Nostr Relay",
},
kv: await Deno.openKv("test.sqlite"),
Expand All @@ -155,7 +153,7 @@ Deno.test("relay information", async (t) => {
assertEquals(information.name, "Nostr Relay");
});

await t.step("set relay name", async () => {
await t.step("set relay information", async () => {
await relay.set_relay_information({
name: "Nostr Relay2",
});
Expand All @@ -164,16 +162,6 @@ Deno.test("relay information", async (t) => {
assertEquals(information2.name, "Nostr Relay2");
});

await t.step("set relay supports nips", async () => {
await relay.set_relay_information({
supported_nips: [1, 2, 3],
});

const information2 = await relay.get_relay_information();
assertEquals(information2.name, "Nostr Relay2");
assertEquals(information2.supported_nips, [1, 2, 3]);
});

await relay.shutdown();
});

Expand Down

0 comments on commit 7e25588

Please sign in to comment.