Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pablof7z committed Jul 31, 2024
1 parent 1a181a4 commit 79d2333
Show file tree
Hide file tree
Showing 52 changed files with 177 additions and 146 deletions.
2 changes: 1 addition & 1 deletion docs/internals/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This is an important aspect to consider:
> `NDKSubscription` have a different lifecycle than `NDKRelaySubscription`. For example, a subscription that is set to close after EOSE might still be active within the `NDKSubscription` lifecycle, but it might have been already been closed within the `NDKRelaySubscription` lifecycle.
## NDKRelaySubscription
Most NDK subscriptions (at least by default) are set to be executed with a grouping delay. Will cover what this looks like in practice later, but for now, let's understand than when the `NDKRelaySubscriptionManager` receives an order, it might not execute it right away.
Most NDK subscriptions (by default) are set to be executed with a grouping delay. Will cover what this looks like in practice later, but for now, let's understand than when the `NDKRelaySubscriptionManager` receives an order, it might not execute it right away.

Once the filter is executed

Expand Down
2 changes: 1 addition & 1 deletion ndk/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NDKRelay } from "../relay/index.js";
import type { NDKFilter, NDKSubscription } from "../subscription/index.js";
import type { Hexpubkey, ProfilePointer } from "../user/index.js";
import type { NDKUserProfile } from "../user/profile.js";
import { NDKLnUrlData } from "../zapper/index.js";
import type { NDKLnUrlData } from "../zapper/index.js";

export interface NDKCacheAdapter {
/**
Expand Down
4 changes: 2 additions & 2 deletions ndk/src/dvm/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NDKEvent, NostrEvent } from "../events";
import type { NDKEvent, NostrEvent } from "../events";
import { type NDKUser } from "../user";
import { NDKKind } from "../events/kinds";
import { NDKSubscription } from "../subscription";
import type { NDKSubscription } from "../subscription";
import { NDKDVMRequest } from "../events/kinds/dvm/request";
import { NDKDVMJobFeedback } from "../events/kinds/dvm";

Expand Down
6 changes: 3 additions & 3 deletions ndk/src/events/fetch-tagged-event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NDKEvent } from ".";
import { NDKSubscriptionOptions } from "../subscription";
import type { NDKEvent } from ".";
import type { NDKSubscriptionOptions } from "../subscription";
import { getReplyTag, getRootTag } from "../thread";

export async function fetchTaggedEvent(
Expand All @@ -18,7 +18,7 @@ export async function fetchTaggedEvent(
let relay; //= hint !== "" ? this.ndk.pool.getRelay(hint) : undefined;

// if we have a relay, attempt to use that first
let event = await this.ndk.fetchEvent(id, {}, relay);
const event = await this.ndk.fetchEvent(id, {}, relay);

return event;
}
Expand Down
2 changes: 1 addition & 1 deletion ndk/src/events/kinds/article.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NDK } from "../../ndk/index.js";
import { ContentTag } from "../content-tagger.js";
import type { ContentTag } from "../content-tagger.js";
import { NDKEvent, type NostrEvent } from "../index.js";
import { NDKKind } from "./index.js";

Expand Down
9 changes: 5 additions & 4 deletions ndk/src/events/kinds/drafts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NDK } from "../../ndk/index.js";
import { NDKRelaySet } from "../../relay/sets/index.js";
import { NDKSigner } from "../../signers/index.js";
import { NDKEvent, NostrEvent } from "../index.js";
import type { NDK } from "../../ndk/index.js";
import type { NDKRelaySet } from "../../relay/sets/index.js";
import type { NDKSigner } from "../../signers/index.js";
import type { NostrEvent } from "../index.js";
import { NDKEvent } from "../index.js";
import { NDKKind } from "./index.js";

/**
Expand Down
7 changes: 4 additions & 3 deletions ndk/src/events/kinds/dvm/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { NDK } from "../../../ndk/index.js";
import { NDKSigner } from "../../../signers/index.js";
import { NDKUser } from "../../../user/index.js";
import type { NDKSigner } from "../../../signers/index.js";
import type { NDKUser } from "../../../user/index.js";
import type { NDKTag, NostrEvent } from "../../index.js";
import { NDKEvent } from "../../index.js";
import { NDKDVMJobFeedback, NDKDvmJobFeedbackStatus } from "./feedback.js";
import type { NDKDvmJobFeedbackStatus } from "./feedback.js";
import { NDKDVMJobFeedback } from "./feedback.js";
// import type { NDKDvmJobFeedbackStatus } from "./NDKDVMJobFeedback.js";
// import { NDKDVMJobFeedback } from "./NDKDVMJobFeedback.js";
// import { NDKDVMJobResult } from "./NDKDVMJobResult.js";
Expand Down
5 changes: 3 additions & 2 deletions ndk/src/events/kinds/nutzap/mint-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NDK } from "../../../ndk/index.js";
import type { NDK } from "../../../ndk/index.js";
import { NDKRelaySet } from "../../../relay/sets/index.js";
import { NDKEvent, NostrEvent } from "../../index.js";
import type { NostrEvent } from "../../index.js";
import { NDKEvent } from "../../index.js";
import { NDKKind } from "../index.js";

export class NDKCashuMintList extends NDKEvent {
Expand Down
11 changes: 6 additions & 5 deletions ndk/src/events/kinds/simple-group/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NDKKind } from "..";
import { NDKEvent, NDKTag, NostrEvent } from "../..";
import { NDK } from "../../../ndk";
import { NDKRelaySet } from "../../../relay/sets";
import { NDKSigner } from "../../../signers";
import { Hexpubkey, NDKUser } from "../../../user";
import type { NDKTag, NostrEvent } from "../..";
import { NDKEvent } from "../..";
import type { NDK } from "../../../ndk";
import type { NDKRelaySet } from "../../../relay/sets";
import type { NDKSigner } from "../../../signers";
import type { Hexpubkey, NDKUser } from "../../../user";
import { NDKSimpleGroupMemberList } from "./member-list";
import { NDKSimpleGroupMetadata } from "./meta-data";

Expand Down
11 changes: 6 additions & 5 deletions ndk/src/events/kinds/simple-group/member-list.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NDKKind } from "../index.js";
import { NDKEvent, NostrEvent } from "../../index.js";
import { NDK } from "../../../ndk/index.js";
import { NDKRelaySet } from "../../../relay/sets/index.js";
import { NDKRelay } from "../../../relay/index.js";
import { Hexpubkey } from "../../../user/index.js";
import type { NostrEvent } from "../../index.js";
import { NDKEvent } from "../../index.js";
import type { NDK } from "../../../ndk/index.js";
import type { NDKRelaySet } from "../../../relay/sets/index.js";
import type { NDKRelay } from "../../../relay/index.js";
import type { Hexpubkey } from "../../../user/index.js";

export class NDKSimpleGroupMemberList extends NDKEvent {
public relaySet: NDKRelaySet | undefined;
Expand Down
5 changes: 3 additions & 2 deletions ndk/src/events/kinds/simple-group/meta-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NDKKind } from "../index.js";
import { NDKEvent, NostrEvent } from "../../index.js";
import { NDK } from "../../../ndk/index.js";
import type { NostrEvent } from "../../index.js";
import { NDKEvent } from "../../index.js";
import type { NDK } from "../../../ndk/index.js";

export class NDKSimpleGroupMetadata extends NDKEvent {
static kind = NDKKind.GroupMetadata;
Expand Down
2 changes: 1 addition & 1 deletion ndk/src/events/kinds/subscriptions/amount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NDKTag } from "../..";
import type { NDKTag } from "../..";

export type NDKIntervalFrequency = "daily" | "weekly" | "monthly" | "quarterly" | "yearly";

Expand Down
7 changes: 4 additions & 3 deletions ndk/src/events/kinds/subscriptions/receipt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import debug from "debug";
import { NDKKind } from "..";
import { NDKEvent, NDKTag, NostrEvent } from "../..";
import { NDK } from "../../../ndk";
import { NDKSubscriptionStart } from "./subscription-start";
import type { NostrEvent } from "../..";
import { NDKEvent, NDKTag } from "../..";
import type { NDK } from "../../../ndk";
import type { NDKSubscriptionStart } from "./subscription-start";
import { NDKUser } from "../../../user";

type ValidPeriod = { start: Date; end: Date };
Expand Down
8 changes: 5 additions & 3 deletions ndk/src/events/kinds/subscriptions/subscription-start.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import debug from "debug";
import { NDKKind } from "..";
import { NDKEvent, NostrEvent } from "../..";
import { NDK } from "../../../ndk";
import type { NostrEvent } from "../..";
import { NDKEvent } from "../..";
import type { NDK } from "../../../ndk";
import { NDKUser } from "../../../user";
import { NDKSubscriptionAmount, newAmount, parseTagToSubscriptionAmount } from "./amount.js";
import type { NDKSubscriptionAmount} from "./amount.js";
import { newAmount, parseTagToSubscriptionAmount } from "./amount.js";
import { NDKSubscriptionTier } from "./tier";

/**
Expand Down
5 changes: 3 additions & 2 deletions ndk/src/events/kinds/subscriptions/tier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { type NostrEvent } from "../../index.js";
import type { NDKEvent, NDKTag } from "../../index.js";
import { NDKKind } from "../index.js";
import { NDKArticle } from "../article.js";
import {
import type {
NDKIntervalFrequency,
NDKSubscriptionAmount,
NDKSubscriptionAmount} from "./amount.js";
import {
newAmount,
parseTagToSubscriptionAmount,
} from "./amount.js";
Expand Down
7 changes: 4 additions & 3 deletions ndk/src/events/kinds/video.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NDKKind } from ".";
import { NDKEvent, NostrEvent } from "..";
import { NDK } from "../../ndk";
import { ContentTag } from "../content-tagger";
import type { NostrEvent } from "..";
import { NDKEvent } from "..";
import type { NDK } from "../../ndk";
import type { ContentTag } from "../content-tagger";

/**
* Represents a horizontal or vertical video.
Expand Down
4 changes: 2 additions & 2 deletions ndk/src/events/signature.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NDKEvent, NDKEventId } from "./index.js";
import type { NDKEvent, NDKEventId } from "./index.js";

let worker: Worker | undefined;

let processingQueue: Record<
const processingQueue: Record<
NDKEventId,
{ event: NDKEvent; resolves: ((result: boolean) => void)[] }
> = {};
Expand Down
12 changes: 6 additions & 6 deletions ndk/src/ndk/active-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NDK } from "./index.js";
import { NDKRelayList } from "../events/kinds/NDKRelayList.js";
import { NDKUser } from "../user/index.js";
import type { NDK } from "./index.js";
import type { NDKRelayList } from "../events/kinds/NDKRelayList.js";
import type { NDKUser } from "../user/index.js";
import createDebug from "debug";
import { NDKFilter } from "../subscription/index.js";
import type { NDKFilter } from "../subscription/index.js";
import { NDKKind } from "../events/kinds/index.js";
import { NDKEvent } from "../events/index.js";
import type { NDKEvent } from "../events/index.js";
import NDKList from "../events/kinds/lists/index.js";
import { NDKRelay } from "../relay/index.js";
import { getRelayListForUser } from "../utils/get-users-relay-list.js";
Expand Down Expand Up @@ -63,7 +63,7 @@ async function setActiveUserConnected(this: NDK, user: NDKUser) {
false
);

let events: Map<NDKKind, NDKEvent> = new Map();
const events: Map<NDKKind, NDKEvent> = new Map();

// Collect most recent version of these events
sub.on("event", (event) => {
Expand Down
3 changes: 2 additions & 1 deletion ndk/src/ndk/fetch-event-from-tag.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NDK } from ".";
import { NDKEvent } from "../events";
import { NDKSubscriptionCacheUsage, NDKSubscriptionOptions } from "../subscription";
import type { NDKSubscriptionOptions } from "../subscription";
import { NDKSubscriptionCacheUsage } from "../subscription";

const ndk = new NDK();

Expand Down
24 changes: 12 additions & 12 deletions ndk/src/ndk/fetch-event-from-tag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NDK } from ".";
import { NDKEvent, NDKTag } from "../events";
import type { NDK } from ".";
import type { NDKEvent, NDKTag } from "../events";
import { getRelaysForSync } from "../outbox/write";
import { NDKRelaySet } from "../relay/sets";
import { calculateRelaySetsFromFilters } from "../relay/sets/calculate";
import { NDKSubscriptionOptions } from "../subscription";
import type { NDKSubscriptionOptions } from "../subscription";

/**
* Options on how to handle when a relay hint doesn't respond
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function fetchEventFromTag(
if (authorRelays && authorRelays.size > 0) {
d("fetching event from author relays %o", Array.from(authorRelays));
const relaySet = NDKRelaySet.fromRelayUrls(Array.from(authorRelays), this);
let event = await this.fetchEvent(id, subOpts, relaySet);
const event = await this.fetchEvent(id, subOpts, relaySet);
if (event) return event;
} else {
d("no author relays found for %s", originalEvent.pubkey, originalEvent);
Expand All @@ -102,12 +102,12 @@ export async function fetchEventFromTag(
// Attempt without relay hint on whatever NDK calculates
const relaySet = calculateRelaySetsFromFilters(this, [{ ids: [id] }], this.pool);
d("fetching event without relay hint", relaySet);
let event = await this.fetchEvent(id, subOpts);
const event = await this.fetchEvent(id, subOpts);
if (event) return event;

// If we didn't get the event, try to fetch in the relay hint
if (hint && hint !== "") {
let event = await this.fetchEvent(
const event = await this.fetchEvent(
id,
subOpts,
this.pool.getRelay(hint, true, true, [{ ids: [id] }])
Expand All @@ -117,7 +117,7 @@ export async function fetchEventFromTag(

let result: NDKEvent | null | undefined = undefined;

let relay = isValidHint(hint)
const relay = isValidHint(hint)
? this.pool.getRelay(hint, false, true, [{ ids: [id] }])
: undefined;

Expand All @@ -133,11 +133,11 @@ export async function fetchEventFromTag(
/**
* Fallback fetch promise.
*/
let fallbackFetchPromise = new Promise<NDKEvent | null>(async (resolve) => {
let fallbackRelaySet = fallback.relaySet;
const fallbackFetchPromise = new Promise<NDKEvent | null>(async (resolve) => {
const fallbackRelaySet = fallback.relaySet;

let timeout = fallback.timeout ?? 1500;
let timeoutPromise = new Promise<void>((resolve) => setTimeout(resolve, timeout));
const timeout = fallback.timeout ?? 1500;
const timeoutPromise = new Promise<void>((resolve) => setTimeout(resolve, timeout));

// if this is a timeout fallback, we need to wait for the timeout to resolve
if (fallback.type === "timeout") await timeoutPromise;
Expand All @@ -146,7 +146,7 @@ export async function fetchEventFromTag(
resolve(result);
} else {
d("fallback fetch triggered");
let fallbackEvent = await this.fetchEvent(id, subOpts, fallbackRelaySet);
const fallbackEvent = await this.fetchEvent(id, subOpts, fallbackRelaySet);
resolve(fallbackEvent);
}
});
Expand Down
17 changes: 10 additions & 7 deletions ndk/src/ndk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { EventEmitter } from "tseep";

import type { NDKCacheAdapter } from "../cache/index.js";
import dedupEvent from "../events/dedup.js";
import { NDKEvent, NDKEventId, NDKTag } from "../events/index.js";
import type { NDKEventId, NDKTag } from "../events/index.js";
import { NDKEvent } from "../events/index.js";
import { OutboxTracker } from "../outbox/tracker.js";
import { NDKRelay } from "../relay/index.js";
import { NDKPool } from "../relay/pool/index.js";
import { NDKRelaySet, NDKPublishError } from "../relay/sets/index.js";
import type { NDKPublishError } from "../relay/sets/index.js";
import { NDKRelaySet } from "../relay/sets/index.js";
import { correctRelaySet } from "../relay/sets/utils.js";
import type { NDKSigner } from "../signers/index.js";
import type { NDKFilter, NDKSubscriptionOptions } from "../subscription/index.js";
Expand All @@ -16,22 +18,23 @@ import { filterFromId, isNip33AValue, relaysFromBech32 } from "../subscription/u
import type { Hexpubkey, NDKUserParams, ProfilePointer } from "../user/index.js";
import { NDKUser } from "../user/index.js";
import { fetchEventFromTag } from "./fetch-event-from-tag.js";
import { NDKAuthPolicy } from "../relay/auth-policies.js";
import type { NDKAuthPolicy } from "../relay/auth-policies.js";
import { Nip96 } from "../media/index.js";
import { NDKNwc } from "../nwc/index.js";
import { Queue } from "./queue/index.js";
import { signatureVerificationInit } from "../events/signature.js";
import { NDKSubscriptionManager } from "../subscription/manager.js";
import { setActiveUser } from "./active-user.js";
import {
import type {
LnPaymentInfo,
NDKLnUrlData,
NDKZapConfirmation,
NDKZapDetails,
NDKZapper,
NutPaymentInfo,
NutPaymentInfo} from "../zapper/index.js";
import {
NDKZapper
} from "../zapper/index.js";
import { NostrEvent } from "nostr-tools";
import type { NostrEvent } from "nostr-tools";

export type NDKValidationRatioFn = (
relay: NDKRelay,
Expand Down
2 changes: 1 addition & 1 deletion ndk/src/nwc/get_info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NDKNWcCommands, NDKNwc, NDKNwcResponse } from ".";
import type { NDKNWcCommands, NDKNwc, NDKNwcResponse } from ".";

export interface GetInfoResponse {
alias?: string;
Expand Down
6 changes: 3 additions & 3 deletions ndk/src/outbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NDK } from "../ndk";
import { NDKRelay } from "../relay";
import { Hexpubkey } from "../user";
import type { NDK } from "../ndk";
import type { NDKRelay } from "../relay";
import type { Hexpubkey } from "../user";
import { getTopRelaysForAuthors } from "./relay-ranking";
import { getRelaysForSync } from "./write";

Expand Down
4 changes: 2 additions & 2 deletions ndk/src/outbox/read/with-authors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { chooseRelayCombinationForPubkeys, getAllRelaysForAllPubkeys } from "..";
import { NDK } from "../../ndk";
import type { NDK } from "../../ndk";
import { NDKRelay } from "../../relay";
import { NDKPool } from "../../relay/pool";
import { Hexpubkey } from "../../user";
import type { Hexpubkey } from "../../user";
import { getTopRelaysForAuthors } from "../relay-ranking";
import { getWriteRelaysFor, getRelaysForSync } from "../write";

Expand Down
6 changes: 3 additions & 3 deletions ndk/src/outbox/relay-ranking.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NDK } from "../ndk";
import { Hexpubkey } from "../user";
import type { NDK } from "../ndk";
import type { Hexpubkey } from "../user";
import { getRelaysForSync } from "./write";

export function getTopRelaysForAuthors(ndk: NDK, authors: Hexpubkey[]): WebSocket["url"][] {
Expand All @@ -21,7 +21,7 @@ export function getTopRelaysForAuthors(ndk: NDK, authors: Hexpubkey[]): WebSocke
*/

// Sort the relays by the number of authors that write to them
let sortedRelays = Array.from(relaysWithCount.entries()).sort((a, b) => b[1] - a[1]);
const sortedRelays = Array.from(relaysWithCount.entries()).sort((a, b) => b[1] - a[1]);

return sortedRelays.map((entry) => entry[0]);
}
Loading

0 comments on commit 79d2333

Please sign in to comment.