diff --git a/resolvers/nip11.ts b/resolvers/nip11.ts index 64f6aaf..68edb3f 100644 --- a/resolvers/nip11.ts +++ b/resolvers/nip11.ts @@ -1,20 +1,19 @@ import { PublicKey } from "../_libs.ts"; -export type RelayInformationStringify = { +type RelayInfomationBase = { name?: string; description?: string; - pubkey?: string; contact?: string; icon?: string; } +export type RelayInformationStringify = { + pubkey?: string; +} & RelayInfomationBase; + export type RelayInformationParsed = { - name?: string; - description?: string; pubkey?: PublicKey; - contact?: string; - icon?: string; -} +} & RelayInfomationBase; export type RelayInformation = { name?: string; @@ -77,18 +76,18 @@ export class RelayInformationStore { export function informationPubkeyParse(info: RelayInformationStringify): RelayInformationParsed | Error { if (!info.pubkey) { - return { name: info.name, description: info.description, contact: info.contact, icon: info.icon }; + return info as RelayInfomationBase; } const pubkey = PublicKey.FromString(info.pubkey); if (pubkey instanceof Error) { return pubkey; } - return { ...info, pubkey }; + return { ...info, pubkey }; } export function informationPubkeyStringify(info: RelayInformationParsed): RelayInformationStringify { if (!info.pubkey) { - return { name: info.name, description: info.description, contact: info.contact, icon: info.icon }; + return info as RelayInfomationBase; } return { ...info, pubkey: info.pubkey.hex }; } diff --git a/test.ts b/test.ts index 5349bc3..2cfb382 100644 --- a/test.ts +++ b/test.ts @@ -244,9 +244,9 @@ Deno.test("NIP-11: Relay Information Document", async (t) => { const json = await queryGql(relay, query); assertEquals(json.data.relayInformation, { name: "Nostr Relay2", - icon: undefined, - contact: undefined, - description: undefined, + icon: null, + contact: null, + description: null, pubkey: test_ctx.publicKey, ...not_modifiable_information, }); @@ -260,9 +260,9 @@ Deno.test("NIP-11: Relay Information Document", async (t) => { const json = await queryGql(relay, query, variables); assertEquals(json.data.set_relay_information, { name: "Nostr Relay3", - icon: undefined, - contact: undefined, - description: undefined, + icon: null, + contact: null, + description: null, pubkey: test_ctx.publicKey, ...not_modifiable_information, });