cleanEvent -> dehydrateEvent
This commit is contained in:
parent
e847c86ff3
commit
b4735d1dd3
|
@ -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 };
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { type DittoDB } from '@/db.ts';
|
import { type DittoDB } from '@/db.ts';
|
||||||
import { Debug, Kysely, type NostrEvent, type NStore, type NStoreOpts, type SelectQueryBuilder } from '@/deps.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 { normalizeFilters } from '@/filter.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
||||||
import { isDittoInternalKind, isParameterizedReplaceableKind, isReplaceableKind } from '@/kinds.ts';
|
import { isDittoInternalKind, isParameterizedReplaceableKind, isReplaceableKind } from '@/kinds.ts';
|
||||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||||
|
import { dehydrateEvent } from '@/storages/hydrate.ts';
|
||||||
import { isNostrId, isURL } from '@/utils.ts';
|
import { isNostrId, isURL } from '@/utils.ts';
|
||||||
import { abortError } from '@/utils/abort.ts';
|
import { abortError } from '@/utils/abort.ts';
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class EventsDB implements NStore {
|
||||||
|
|
||||||
/** Insert an event (and its tags) into the database. */
|
/** Insert an event (and its tags) into the database. */
|
||||||
async event(event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
|
async event(event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
|
||||||
event = cleanEvent(event);
|
event = dehydrateEvent(event);
|
||||||
this.#debug('EVENT', JSON.stringify(event));
|
this.#debug('EVENT', JSON.stringify(event));
|
||||||
|
|
||||||
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {
|
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {
|
||||||
|
|
|
@ -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 DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
||||||
|
|
||||||
|
@ -25,4 +25,17 @@ async function hydrateEvents(opts: HydrateEventOpts): Promise<DittoEvent[]> {
|
||||||
return events;
|
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 };
|
||||||
|
|
|
@ -8,8 +8,8 @@ import {
|
||||||
type NStoreOpts,
|
type NStoreOpts,
|
||||||
type RelayPoolWorker,
|
type RelayPoolWorker,
|
||||||
} from '@/deps.ts';
|
} from '@/deps.ts';
|
||||||
import { cleanEvent } from '@/events.ts';
|
|
||||||
import { normalizeFilters } from '@/filter.ts';
|
import { normalizeFilters } from '@/filter.ts';
|
||||||
|
import { dehydrateEvent } from '@/storages/hydrate.ts';
|
||||||
import { abortError } from '@/utils/abort.ts';
|
import { abortError } from '@/utils/abort.ts';
|
||||||
|
|
||||||
interface PoolStoreOpts {
|
interface PoolStoreOpts {
|
||||||
|
@ -38,7 +38,7 @@ class PoolStore implements NStore {
|
||||||
if (opts.signal?.aborted) return Promise.reject(abortError());
|
if (opts.signal?.aborted) return Promise.reject(abortError());
|
||||||
const { relays = this.#relays } = opts;
|
const { relays = this.#relays } = opts;
|
||||||
|
|
||||||
event = cleanEvent(event);
|
event = dehydrateEvent(event);
|
||||||
this.#debug('EVENT', event);
|
this.#debug('EVENT', event);
|
||||||
|
|
||||||
this.#pool.publish(event, relays);
|
this.#pool.publish(event, relays);
|
||||||
|
|
Loading…
Reference in New Issue