Merge branch 'nostrify' into 'main'

Switch NSpec to Nostrify, update imports

See merge request soapbox-pub/ditto!168
This commit is contained in:
Alex Gleason 2024-04-19 21:42:17 +00:00
commit 11e81f0000
41 changed files with 85 additions and 93 deletions

View File

@ -11,7 +11,11 @@
"nsec": "deno run scripts/nsec.ts"
},
"exclude": ["./public"],
"imports": { "@/": "./src/", "@soapbox/nspec": "jsr:@soapbox/nspec@^0.8.1", "~/fixtures/": "./fixtures/" },
"imports": {
"@/": "./src/",
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.9.7",
"~/fixtures/": "./fixtures/"
},
"lint": {
"include": ["src/", "scripts/"],
"rules": {

View File

@ -1,3 +1,5 @@
import { NostrEvent } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import '@/cron.ts';
import { type User } from '@/db/users.ts';
@ -10,7 +12,6 @@ import {
type HonoEnv,
logger,
type MiddlewareHandler,
type NostrEvent,
sentryMiddleware,
serveStatic,
} from '@/deps.ts';

View File

@ -1,4 +1,4 @@
import { NostrFilter } from '@soapbox/nspec';
import { NostrFilter } from '@nostrify/nostrify';
import { type AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { nip19, z } from '@/deps.ts';

View File

@ -1,6 +1,6 @@
import { NostrFilter } from '@soapbox/nspec';
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { AppController } from '@/app.ts';
import { nip19, type NostrEvent, z } from '@/deps.ts';
import { nip19, z } from '@/deps.ts';
import { booleanParamSchema } from '@/schema.ts';
import { nostrIdSchema } from '@/schemas/nostr.ts';
import { searchStore } from '@/storages.ts';

View File

@ -1,7 +1,8 @@
import { NIP05, NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { type AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { getUnattachedMediaByIds } from '@/db/unattached-media.ts';
import { ISO6391, NIP05, nip19, type NostrEvent, NostrFilter, z } from '@/deps.ts';
import { ISO6391, nip19, z } from '@/deps.ts';
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { addTag, deleteTag } from '@/tags.ts';

View File

@ -1,4 +1,4 @@
import { NostrFilter } from '@soapbox/nspec';
import { NostrFilter } from '@nostrify/nostrify';
import { type AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { Debug, z } from '@/deps.ts';

View File

@ -1,4 +1,4 @@
import { NostrFilter } from '@soapbox/nspec';
import { NostrFilter } from '@nostrify/nostrify';
import { type AppContext, type AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { z } from '@/deps.ts';

View File

@ -1,3 +1,4 @@
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { relayInfoController } from '@/controllers/nostr/relay-info.ts';
import { eventsDB } from '@/storages.ts';
import * as pipeline from '@/pipeline.ts';
@ -13,7 +14,6 @@ import {
import { Sub } from '@/subs.ts';
import type { AppController } from '@/app.ts';
import type { NostrEvent, NostrFilter } from '@/deps.ts';
/** Limit of initial events returned for a subscription. */
const FILTER_LIMIT = 100;

View File

@ -1,5 +1,6 @@
import { NostrFilter } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { Debug, type NostrFilter } from '@/deps.ts';
import { Debug } from '@/deps.ts';
import * as pipeline from '@/pipeline.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { eventsDB } from '@/storages.ts';

View File

@ -79,19 +79,6 @@ export { EventEmitter } from 'npm:tseep@^1.1.3';
export { default as stringifyStable } from 'npm:fast-stable-stringify@^1.0.0';
export { default as Debug } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.3.0/debug.ts';
export { Stickynotes } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.3.0/mod.ts';
export {
LNURL,
type LNURLDetails,
NCache,
NIP05,
type NostrEvent,
type NostrFilter,
type NostrSigner,
NSecSigner,
NSet,
type NStore,
type NStoreOpts,
} from 'https://gitlab.com/soapbox-pub/NSpec/-/raw/v0.3.0/mod.ts';
export type * as TypeFest from 'npm:type-fest@^4.3.0';

View File

@ -1,4 +1,5 @@
import { type NostrEvent, type NostrFilter, stringifyStable, z } from '@/deps.ts';
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { stringifyStable, z } from '@/deps.ts';
import { isReplaceableKind } from '@/kinds.ts';
import { nostrIdSchema } from '@/schemas/nostr.ts';

View File

@ -1,4 +1,5 @@
import { Debug, type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { Debug } from '@/deps.ts';
import { activeRelays, pool } from '@/pool.ts';
import { nostrNow } from '@/utils.ts';

View File

@ -1,4 +1,4 @@
import { type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
/** Ditto internal stats for the event's author. */
export interface AuthorStats {

View File

@ -1,6 +1,5 @@
import { type NostrEvent } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
/** Additional properties that may be added by Ditto to events. */
export type DittoRelation = Exclude<keyof DittoEvent, keyof NostrEvent>;

View File

@ -1,5 +1,6 @@
import { NostrEvent } from '@nostrify/nostrify';
import { type AppContext, type AppMiddleware } from '@/app.ts';
import { HTTPException, type NostrEvent } from '@/deps.ts';
import { HTTPException } from '@/deps.ts';
import {
buildAuthEventTemplate,
parseAuthRequest,

View File

@ -1,9 +1,9 @@
import { NSchema as n } from '@soapbox/nspec';
import { LNURL, NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { db } from '@/db.ts';
import { addRelays } from '@/db/relays.ts';
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
import { Debug, LNURL, type NostrEvent, sql } from '@/deps.ts';
import { Debug, sql } from '@/deps.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { isEphemeralKind } from '@/kinds.ts';
import { DVM } from '@/pipeline/DVM.ts';

View File

@ -1,4 +1,4 @@
import { NIP05, NostrEvent } from '@soapbox/nspec';
import { NIP05, NostrEvent } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import * as pipeline from '@/pipeline.ts';

View File

@ -1,6 +1,7 @@
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { eventsDB, optimizer } from '@/storages.ts';
import { Debug, type NostrEvent, type NostrFilter } from '@/deps.ts';
import { Debug } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { type DittoRelation } from '@/interfaces/DittoFilter.ts';
import { findReplyTag, getTagSet } from '@/tags.ts';

View File

@ -1,6 +1,7 @@
import { NostrEvent, NostrSigner, NSecSigner } from '@nostrify/nostrify';
import { type AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import { HTTPException, type NostrEvent, type NostrSigner, NSecSigner, Stickynotes } from '@/deps.ts';
import { HTTPException, Stickynotes } from '@/deps.ts';
import { connectResponseSchema } from '@/schemas/nostr.ts';
import { jsonSchema } from '@/schema.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';

View File

@ -1,5 +1,5 @@
import { NSecSigner } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { NSecSigner } from '@/deps.ts';
/** Sign events as the Ditto server. */
export class AdminSigner extends NSecSigner {

View File

@ -1,5 +1,6 @@
import { NostrEvent } from '@nostrify/nostrify';
import { type AuthorStatsRow, db, type DittoDB, type EventStatsRow } from '@/db.ts';
import { Debug, type InsertQueryBuilder, type NostrEvent } from '@/deps.ts';
import { Debug, type InsertQueryBuilder } from '@/deps.ts';
import { eventsDB } from '@/storages.ts';
import { findReplyTag } from '@/tags.ts';

View File

@ -1,6 +1,6 @@
import { NCache } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { db } from '@/db.ts';
import { NCache } from '@/deps.ts';
import * as pipeline from '@/pipeline.ts';
import { activeRelays, pool } from '@/pool.ts';
import { EventsDB } from '@/storages/events-db.ts';

View File

@ -1,7 +1,7 @@
import { NIP50, NostrFilter } from '@soapbox/nspec';
import { NIP50, NostrEvent, NostrFilter, NStore } from '@nostrify/nostrify';
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 { Debug, Kysely, type SelectQueryBuilder } from '@/deps.ts';
import { normalizeFilters } from '@/filter.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { isDittoInternalKind, isParameterizedReplaceableKind, isReplaceableKind } from '@/kinds.ts';
@ -66,7 +66,7 @@ class EventsDB implements NStore {
}
/** Insert an event (and its tags) into the database. */
async event(event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
async event(event: NostrEvent, _opts?: { signal?: AbortSignal }): Promise<void> {
event = purifyEvent(event);
this.#debug('EVENT', JSON.stringify(event));
@ -258,7 +258,7 @@ class EventsDB implements NStore {
}
/** Get events for filters from the database. */
async query(filters: NostrFilter[], opts: NStoreOpts = {}): Promise<DittoEvent[]> {
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<DittoEvent[]> {
filters = await this.expandFilters(filters);
if (opts.signal?.aborted) return Promise.resolve([]);
@ -328,7 +328,7 @@ class EventsDB implements NStore {
}
/** Delete events based on filters from the database. */
async remove(filters: NostrFilter[], _opts?: NStoreOpts): Promise<void> {
async remove(filters: NostrFilter[], _opts?: { signal?: AbortSignal }): Promise<void> {
if (!filters.length) return Promise.resolve();
this.#debug('DELETE', JSON.stringify(filters));
@ -336,7 +336,10 @@ class EventsDB implements NStore {
}
/** Get number of events that would be returned by filters. */
async count(filters: NostrFilter[], opts: NStoreOpts = {}): Promise<{ count: number; approximate: boolean }> {
async count(
filters: NostrFilter[],
opts: { signal?: AbortSignal } = {},
): Promise<{ count: number; approximate: boolean }> {
if (opts.signal?.aborted) return Promise.reject(abortError());
if (!filters.length) return Promise.resolve({ count: 0, approximate: false });

View File

@ -1,6 +1,6 @@
import { NostrEvent, NStore } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { db } from '@/db.ts';
import { type NostrEvent, type NStore } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { type DittoRelation } from '@/interfaces/DittoFilter.ts';

View File

@ -1,5 +1,5 @@
import { NostrFilter } from '@soapbox/nspec';
import { Debug, NSet, type NStore, type NStoreOpts } from '@/deps.ts';
import { NostrFilter, NSet, NStore } from '@nostrify/nostrify';
import { Debug } from '@/deps.ts';
import { normalizeFilters } from '@/filter.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { abortError } from '@/utils/abort.ts';
@ -23,7 +23,7 @@ class Optimizer implements NStore {
this.#client = opts.client;
}
async event(event: DittoEvent, opts?: NStoreOpts): Promise<void> {
async event(event: DittoEvent, opts?: { signal?: AbortSignal }): Promise<void> {
if (opts?.signal?.aborted) return Promise.reject(abortError());
await Promise.all([
@ -32,7 +32,7 @@ class Optimizer implements NStore {
]);
}
async query(filters: NostrFilter[], opts: NStoreOpts = {}): Promise<DittoEvent[]> {
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<DittoEvent[]> {
if (opts?.signal?.aborted) return Promise.reject(abortError());
filters = normalizeFilters(filters);

View File

@ -1,13 +1,5 @@
import {
Debug,
matchFilters,
type NostrEvent,
type NostrFilter,
NSet,
type NStore,
type NStoreOpts,
type RelayPoolWorker,
} from '@/deps.ts';
import { NostrEvent, NostrFilter, NSet, NStore } from '@nostrify/nostrify';
import { Debug, matchFilters, type RelayPoolWorker } from '@/deps.ts';
import { normalizeFilters } from '@/filter.ts';
import { purifyEvent } from '@/storages/hydrate.ts';
import { abortError } from '@/utils/abort.ts';
@ -36,7 +28,7 @@ class PoolStore implements NStore {
this.#publisher = opts.publisher;
}
async event(event: NostrEvent, opts: NStoreOpts = {}): Promise<void> {
async event(event: NostrEvent, opts: { signal?: AbortSignal } = {}): Promise<void> {
if (opts.signal?.aborted) return Promise.reject(abortError());
const relaySet = await getRelays(event.pubkey);
@ -51,7 +43,7 @@ class PoolStore implements NStore {
return Promise.resolve();
}
query(filters: NostrFilter[], opts: NStoreOpts = {}): Promise<NostrEvent[]> {
query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<NostrEvent[]> {
if (opts.signal?.aborted) return Promise.reject(abortError());
filters = normalizeFilters(filters);
@ -63,7 +55,7 @@ class PoolStore implements NStore {
const unsub = this.#pool.subscribe(
filters,
opts.relays ?? this.#relays,
this.#relays,
(event: NostrEvent | null) => {
if (event && matchFilters(filters, event)) {
this.#publisher.handleEvent(event, AbortSignal.timeout(1000)).catch(() => {});

View File

@ -1,4 +1,5 @@
import { Debug, EventEmitter, type NostrEvent, type NostrFilter, type NStore, type NStoreOpts } from '@/deps.ts';
import { NostrEvent, NostrFilter, NStore } from '@nostrify/nostrify';
import { Debug, EventEmitter } from '@/deps.ts';
import { eventToMicroFilter, getFilterId, isMicrofilter, type MicroFilter } from '@/filter.ts';
import { Time } from '@/utils/time.ts';
import { abortError } from '@/utils/abort.ts';
@ -110,7 +111,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: NostrEvent)
});
}
event(event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
event(event: NostrEvent, _opts?: { signal?: AbortSignal }): Promise<void> {
const filterId = getFilterId(eventToMicroFilter(event));
this.#queue = this.#queue.filter(([id]) => id !== filterId);
this.emit(filterId, event);
@ -122,7 +123,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: NostrEvent)
return this.#queue.some(([id]) => id === filterId);
}
query(filters: NostrFilter[], opts?: NStoreOpts): Promise<NostrEvent[]> {
query(filters: NostrFilter[], opts?: { signal?: AbortSignal }): Promise<NostrEvent[]> {
if (opts?.signal?.aborted) return Promise.reject(abortError());
this.#debug('REQ', JSON.stringify(filters));

View File

@ -1,5 +1,5 @@
import { NostrFilter, NRelay1 } from '@soapbox/nspec';
import { Debug, type NostrEvent, type NStore, type NStoreOpts } from '@/deps.ts';
import { NostrEvent, NostrFilter, NRelay1, NStore } from '@nostrify/nostrify';
import { Debug } from '@/deps.ts';
import { normalizeFilters } from '@/filter.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { hydrateEvents } from '@/storages/hydrate.ts';
@ -27,11 +27,11 @@ class SearchStore implements NStore {
}
}
event(_event: NostrEvent, _opts?: NStoreOpts): Promise<void> {
event(_event: NostrEvent, _opts?: { signal?: AbortSignal }): Promise<void> {
return Promise.reject(new Error('EVENT not implemented.'));
}
async query(filters: NostrFilter[], opts?: NStoreOpts): Promise<DittoEvent[]> {
async query(filters: NostrFilter[], opts?: { signal?: AbortSignal; limit?: number }): Promise<DittoEvent[]> {
filters = normalizeFilters(filters);
if (opts?.signal?.aborted) return Promise.reject(abortError());

View File

@ -1,4 +1,4 @@
import { NostrFilter } from '@soapbox/nspec';
import { NostrFilter } from '@nostrify/nostrify';
import { Debug } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { Subscription } from '@/subscription.ts';

View File

@ -1,5 +1,5 @@
import { NIP50, NostrFilter } from '@soapbox/nspec';
import { Machina, matchFilter, type NostrEvent } from '@/deps.ts';
import { NIP50, NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { Machina, matchFilter } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
class Subscription implements AsyncIterable<NostrEvent> {

View File

@ -1,4 +1,5 @@
import { type EventTemplate, getEventHash, nip19, type NostrEvent, z } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { type EventTemplate, getEventHash, nip19, z } from '@/deps.ts';
import { nostrIdSchema } from '@/schemas/nostr.ts';
/** Get the current time in Nostr format. */

View File

@ -1,16 +1,7 @@
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { type AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import {
type Context,
Debug,
EventTemplate,
HTTPException,
type NostrEvent,
NostrFilter,
parseFormData,
type TypeFest,
z,
} from '@/deps.ts';
import { type Context, Debug, EventTemplate, HTTPException, parseFormData, type TypeFest, z } from '@/deps.ts';
import * as pipeline from '@/pipeline.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { APISigner } from '@/signers/APISigner.ts';

View File

@ -1,4 +1,5 @@
import { Debug, LNURL, type LNURLDetails } from '@/deps.ts';
import { LNURL, LNURLDetails } from '@nostrify/nostrify';
import { Debug } from '@/deps.ts';
import { SimpleLRU } from '@/utils/SimpleLRU.ts';
import { Time } from '@/utils/time.ts';
import { fetchWorker } from '@/workers/fetch.ts';

View File

@ -1,4 +1,4 @@
import { type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { getAuthor } from '@/queries.ts';
import { bech32ToPubkey } from '@/utils.ts';
import { nip05Cache } from '@/utils/nip05.ts';

View File

@ -1,5 +1,6 @@
import { NIP05 } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { Debug, NIP05, nip19 } from '@/deps.ts';
import { Debug, nip19 } from '@/deps.ts';
import { SimpleLRU } from '@/utils/SimpleLRU.ts';
import { Time } from '@/utils/time.ts';
import { eventsDB } from '@/storages.ts';

View File

@ -1,4 +1,5 @@
import { type EventTemplate, nip13, type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { type EventTemplate, nip13 } from '@/deps.ts';
import { decode64Schema, jsonSchema } from '@/schema.ts';
import { signedEventSchema } from '@/schemas/nostr.ts';
import { eventAge, findTag, nostrNow, sha256 } from '@/utils.ts';

View File

@ -1,5 +1,5 @@
import { NostrFilter } from '@nostrify/nostrify';
import { AppContext } from '@/app.ts';
import { type NostrFilter } from '@/deps.ts';
import { eventsDB } from '@/storages.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';

View File

@ -2,7 +2,7 @@ import { Conf } from '@/config.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { getPublicKeyPem } from '@/utils/rsa.ts';
import type { NostrEvent } from '@/deps.ts';
import type { NostrEvent } from '@nostrify/nostrify';
import type { Actor } from '@/schemas/activitypub.ts';
/** Nostr metadata event to ActivityPub actor. */

View File

@ -1,4 +1,4 @@
import { type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { getAuthor } from '@/queries.ts';
import { nostrDate } from '@/utils.ts';
import { accountFromPubkey } from '@/views/mastodon/accounts.ts';

View File

@ -1,4 +1,5 @@
import { Comlink, type NostrEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { Comlink } from '@/deps.ts';
import type { VerifyWorker } from './verify.worker.ts';

View File

@ -1,4 +1,5 @@
import { Comlink, type NostrEvent, type VerifiedEvent, verifyEvent } from '@/deps.ts';
import { NostrEvent } from '@nostrify/nostrify';
import { Comlink, type VerifiedEvent, verifyEvent } from '@/deps.ts';
export const VerifyWorker = {
verifyEvent(event: NostrEvent): event is VerifiedEvent {