Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pablof7z committed Jun 21, 2024
1 parent d45d4e1 commit ed80f68
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 27 deletions.
4 changes: 3 additions & 1 deletion ndk/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export interface NDKCacheAdapter {
/**
* Fetches all unpublished events.
*/
getUnpublishedEvents?(): Promise<{ event: NDKEvent, relays?: WebSocket["url"][], lastTryAt?: number }[]>;
getUnpublishedEvents?(): Promise<
{ event: NDKEvent; relays?: WebSocket["url"][]; lastTryAt?: number }[]
>;

/**
* Removes an unpublished event.
Expand Down
1 change: 0 additions & 1 deletion ndk/src/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ export class NDKEvent extends EventEmitter {
return relays;
}


/**
* Generates tags for users, notes, and other events tagged in content.
* Will also generate random "d" tag for parameterized replaceable events where needed.
Expand Down
15 changes: 11 additions & 4 deletions ndk/src/events/kinds/NDKRelayList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NDKRelayList extends NDKEvent {
if (ndk.cacheAdapter?.locking) {
const cachedList = await ndk.fetchEvents(
{ kinds: [3, 10002], authors: pubkeys },
{ cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE },
{ cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE }
);

// get list of relay lists from cache
Expand Down Expand Up @@ -80,8 +80,15 @@ export class NDKRelayList extends NDKEvent {
// Get from relays the missing pubkeys
const sub = ndk.subscribe(
{ kinds: [3, 10002], authors: pubkeys },
{ closeOnEose: true, pool, groupable: true, cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY, subId: 'ndk-relay-list-fetch' },
relaySet, false
{
closeOnEose: true,
pool,
groupable: true,
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY,
subId: "ndk-relay-list-fetch",
},
relaySet,
false
);

/* Collect most recent version of events */
Expand Down Expand Up @@ -112,7 +119,7 @@ export class NDKRelayList extends NDKEvent {

if (list) relayLists.set(pubkey, list);
}

resolve(relayLists);
});

Expand Down
2 changes: 1 addition & 1 deletion ndk/src/events/kinds/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NDKKind } from "./index.js";

/**
* Represents a NIP-23 article.
*
*
* @group Kind Wrapper
*/
export class NDKArticle extends NDKEvent {
Expand Down
2 changes: 1 addition & 1 deletion ndk/src/events/kinds/classified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface NDKClassifiedPriceTag {

/**
* Represents a NIP-99 Classified Listing.
*
*
* @group Kind Wrapper
*/
export class NDKClassified extends NDKEvent {
Expand Down
30 changes: 16 additions & 14 deletions ndk/src/events/kinds/drafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { NDKKind } from "./index.js";
/**
* NIP-37 drafts.
* @group Kind Wrapper
*
*
* @example
* const myArticle = new NDKArticle();
* myArticle.content = "This is my artic"
*
*
* const draft = new NDKDraft();
* draft.event = myArticle;
* draft.publish();
Expand Down Expand Up @@ -44,17 +44,15 @@ export class NDKDraft extends NDKEvent {
* Event that is to be saved.
*/
set event(e: NDKEvent | NostrEvent) {
if (e instanceof NDKEvent)
this._event = e.rawEvent();
else
this._event = e;
if (e instanceof NDKEvent) this._event = e.rawEvent();
else this._event = e;

this.prepareEvent();
}

/**
* Gets the event.
* @param param0
* @param param0
* @returns NDKEvent of the draft event or null if the draft event has been deleted (emptied).
*/
async getEvent(signer?: NDKSigner) {
Expand Down Expand Up @@ -83,21 +81,25 @@ export class NDKDraft extends NDKEvent {
private prepareEvent() {
if (!this._event) throw new Error("No event has been provided");
this.removeTag("k");
if (this._event.kind) this.tags.push(["k", this._event.kind.toString()])
if (this._event.kind) this.tags.push(["k", this._event.kind.toString()]);

this.content = JSON.stringify(this._event);
}

/**
* Generates draft event.
*
*
* @param signer: Optional signer to encrypt with
* @param publish: Whether to publish, optionally specifying relaySet to publish to
*/
async save({signer, publish, relaySet}: {
signer?: NDKSigner,
publish?: boolean,
relaySet?: NDKRelaySet
async save({
signer,
publish,
relaySet,
}: {
signer?: NDKSigner;
publish?: boolean;
relaySet?: NDKRelaySet;
}) {
signer ??= this.ndk?.signer;
if (!signer) throw new Error("No signer available");
Expand All @@ -110,4 +112,4 @@ export class NDKDraft extends NDKEvent {

return this.publish(relaySet);
}
}
}
2 changes: 1 addition & 1 deletion ndk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export { type NDKEventSerialized, deserialize, serialize } from "./events/serial
export { NDK as default, NDKConstructorParams } from "./ndk/index.js";
export { NDKZapInvoice, zapInvoiceFromEvent } from "./zap/invoice.js";
export * from "./zap/index.js";
export * from "./utils/normalize-url.js";
export * from "./utils/normalize-url.js";
8 changes: 6 additions & 2 deletions ndk/src/ndk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ export class NDK extends EventEmitter<{
* @param error The error that caused the event to fail to publish
* @param relays The relays that the event was attempted to be published to
*/
"event:publish-failed": (event: NDKEvent, error: NDKPublishError, relays: WebSocket["url"][]) => void;
"event:publish-failed": (
event: NDKEvent,
error: NDKPublishError,
relays: WebSocket["url"][]
) => void;
}> {
public explicitRelayUrls?: WebSocket["url"][];
public pool: NDKPool;
Expand Down Expand Up @@ -461,7 +465,7 @@ export class NDK extends EventEmitter<{
}

if (autoStart) {
setTimeout(() => subscription.start(), 0);
setTimeout(() => subscription.start(), 0);
}

return subscription;
Expand Down
7 changes: 5 additions & 2 deletions ndk/src/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ export class NDKUser {
* @param storeProfileEvent {boolean} Whether to store the profile event or not
* @returns User Profile
*/
public async fetchProfile(opts?: NDKSubscriptionOptions, storeProfileEvent: boolean = false): Promise<NDKUserProfile | null> {
public async fetchProfile(
opts?: NDKSubscriptionOptions,
storeProfileEvent: boolean = false
): Promise<NDKUserProfile | null> {
if (!this.ndk) throw new Error("NDK not set");

if (!this.profile) this.profile = {};
Expand Down Expand Up @@ -265,7 +268,7 @@ export class NDKUser {

// return the most recent profile
this.profile = profileFromEvent(sortedSetMetadataEvents[0]);

if (storeProfileEvent) {
// Store the event as a stringified JSON
this.profile.profileEvent = JSON.stringify(sortedSetMetadataEvents[0]);
Expand Down

0 comments on commit ed80f68

Please sign in to comment.