Delete src/nostr directory

This commit is contained in:
Alex Gleason 2023-04-29 15:49:22 -05:00
parent b33a3a21fc
commit 6341987088
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
9 changed files with 38 additions and 39 deletions

View File

@ -1,6 +1,6 @@
import { type AppContext } from '@/app.ts';
import { validator, z } from '@/deps.ts';
import { type Event } from '@/nostr/event.ts';
import { type Event } from '@/event.ts';
import publish from '../publisher.ts';
import { toStatus } from '../transmute.ts';

View File

@ -1,5 +1,5 @@
import { Author, RelayPool } from '@/deps.ts';
import { type Event, type SignedEvent } from '@/nostr/event.ts';
import { type Event, type SignedEvent } from '@/event.ts';
import { poolRelays } from './config.ts';

View File

@ -1,5 +1,5 @@
import { gossipDB } from '@/db.ts';
import { type Event } from '@/nostr/event.ts';
import { type Event } from '@/event.ts';
import { getAuthorRelays } from './gossip.ts';

View File

@ -1,32 +0,0 @@
import { z } from '@/deps.ts';
import { type Event } from '../event.ts';
const optionalString = z.string().optional().catch(undefined);
const metaContentSchema = z.object({
name: optionalString,
about: optionalString,
picture: optionalString,
banner: optionalString,
nip05: optionalString,
lud16: optionalString,
});
/** Author metadata from Event<0>. */
type MetaContent = z.infer<typeof metaContentSchema>;
/**
* Get (and validate) data from a kind 0 event.
* https://github.com/nostr-protocol/nips/blob/master/01.md
*/
function parseContent(event: Event<0>): MetaContent {
try {
const json = JSON.parse(event.content);
return metaContentSchema.parse(json);
} catch (_e) {
return {};
}
}
export { type MetaContent, metaContentSchema, parseContent };

View File

@ -1,5 +1,5 @@
import { getEventHash, getSignature } from '@/deps.ts';
import { type Event } from '@/nostr/event.ts';
import { type Event } from '@/event.ts';
import { pool } from './client.ts';
import { publishRelays } from './config.ts';

View File

@ -1,5 +1,9 @@
import { z } from '@/deps.ts';
import type { Event } from './event.ts';
const optionalString = z.string().optional().catch(undefined);
const jsonSchema = z.string().transform((value, ctx) => {
try {
return JSON.parse(value);
@ -9,6 +13,33 @@ const jsonSchema = z.string().transform((value, ctx) => {
}
});
const metaContentSchema = z.object({
name: optionalString,
about: optionalString,
picture: optionalString,
banner: optionalString,
nip05: optionalString,
lud16: optionalString,
});
/** Author metadata from Event<0>. */
type MetaContent = z.infer<typeof metaContentSchema>;
/**
* Get (and validate) data from a kind 0 event.
* https://github.com/nostr-protocol/nips/blob/master/01.md
*/
function parseContent(event: Event<0>): MetaContent {
try {
const json = JSON.parse(event.content);
return metaContentSchema.parse(json);
} catch (_e) {
return {};
}
}
export { type MetaContent, metaContentSchema, parseContent };
/** Alias for `safeParse`, but instead of returning a success object it returns the value (or undefined on fail). */
function parseValue<T>(schema: z.ZodType<T>, value: unknown): T | undefined {
const result = schema.safeParse(value);

View File

@ -1,6 +1,6 @@
import { nip19 } from '@/deps.ts';
import { type Event } from '@/nostr/event.ts';
import { type MetaContent, parseContent } from '@/nostr/events/kind-0.ts';
import { type Event } from '@/event.ts';
import { type MetaContent, parseContent } from '@/schema.ts';
import { LOCAL_DOMAIN } from './config.ts';
import { fetchUser } from './client.ts';

View File

@ -1,5 +1,5 @@
import { Context, getPublicKey } from '@/deps.ts';
import { type Event } from '@/nostr/event.ts';
import { type Event } from '@/event.ts';
/** Get the current time in Nostr format. */
const nostrNow = () => Math.floor(new Date().getTime() / 1000);