cleanEvent -> dehydrateEvent

This commit is contained in:
Alex Gleason 2024-01-24 15:46:45 -06:00
parent e847c86ff3
commit b4735d1dd3
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 19 additions and 22 deletions

View File

@ -1,16 +0,0 @@
import { type NostrEvent } from '@/deps.ts';
/** Return a normalized event without any non-standard keys. */
function cleanEvent(event: NostrEvent): NostrEvent {
return {
id: event.id,
pubkey: event.pubkey,
kind: event.kind,
content: event.content,
tags: event.tags,
sig: event.sig,
created_at: event.created_at,
};
}
export { cleanEvent };

View File

@ -1,12 +1,12 @@
import { Conf } from '@/config.ts';
import { type DittoDB } from '@/db.ts';
import { Debug, Kysely, type NostrEvent, type NStore, type NStoreOpts, type SelectQueryBuilder } from '@/deps.ts';
import { cleanEvent } from '@/events.ts';
import { normalizeFilters } from '@/filter.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
import { isDittoInternalKind, isParameterizedReplaceableKind, isReplaceableKind } from '@/kinds.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { dehydrateEvent } from '@/storages/hydrate.ts';
import { isNostrId, isURL } from '@/utils.ts';
import { abortError } from '@/utils/abort.ts';
@ -65,7 +65,7 @@ class EventsDB implements NStore {
/** Insert an event (and its tags) into the database. */
async event(event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
event = cleanEvent(event);
event = dehydrateEvent(event);
this.#debug('EVENT', JSON.stringify(event));
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {

View File

@ -1,4 +1,4 @@
import { type NStore } from '@/deps.ts';
import { type NostrEvent, type NStore } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
@ -25,4 +25,17 @@ async function hydrateEvents(opts: HydrateEventOpts): Promise<DittoEvent[]> {
return events;
}
export { hydrateEvents };
/** Return a normalized event without any non-standard keys. */
function dehydrateEvent(event: DittoEvent): NostrEvent {
return {
id: event.id,
pubkey: event.pubkey,
kind: event.kind,
content: event.content,
tags: event.tags,
sig: event.sig,
created_at: event.created_at,
};
}
export { dehydrateEvent, hydrateEvents };

View File

@ -8,8 +8,8 @@ import {
type NStoreOpts,
type RelayPoolWorker,
} from '@/deps.ts';
import { cleanEvent } from '@/events.ts';
import { normalizeFilters } from '@/filter.ts';
import { dehydrateEvent } from '@/storages/hydrate.ts';
import { abortError } from '@/utils/abort.ts';
interface PoolStoreOpts {
@ -38,7 +38,7 @@ class PoolStore implements NStore {
if (opts.signal?.aborted) return Promise.reject(abortError());
const { relays = this.#relays } = opts;
event = cleanEvent(event);
event = dehydrateEvent(event);
this.#debug('EVENT', event);
this.#pool.publish(event, relays);