@nostr-dev-kit/ndk-cache-redis
Advanced tools
Comparing version 2.1.17 to 2.1.18
# @nostr-dev-kit/ndk-cache-redis | ||
## 2.1.18 | ||
### Patch Changes | ||
- Updated dependencies [d6cfa8a] | ||
- Updated dependencies [d6cfa8a] | ||
- Updated dependencies [d6cfa8a] | ||
- Updated dependencies [722345b] | ||
- @nostr-dev-kit/ndk@2.10.1 | ||
## 2.1.17 | ||
@@ -4,0 +14,0 @@ |
{ | ||
"name": "@nostr-dev-kit/ndk-cache-redis", | ||
"version": "2.1.17", | ||
"version": "2.1.18", | ||
"description": "NDK cache adapter for redis.", | ||
@@ -37,3 +37,3 @@ "main": "./dist/index.js", | ||
"typescript": "^5.4.4", | ||
"@nostr-dev-kit/ndk": "2.10.0" | ||
"@nostr-dev-kit/ndk": "2.10.1" | ||
}, | ||
@@ -48,4 +48,4 @@ "devDependencies": { | ||
"tsup": "^7.2.0", | ||
"@nostr-dev-kit/eslint-config-custom": "0.0.0", | ||
"@nostr-dev-kit/tsconfig": "0.0.0" | ||
"@nostr-dev-kit/tsconfig": "0.0.0", | ||
"@nostr-dev-kit/eslint-config-custom": "0.0.0" | ||
}, | ||
@@ -52,0 +52,0 @@ "scripts": { |
@@ -1,10 +0,11 @@ | ||
import NDK, { | ||
NDKEvent, | ||
NDKKind, | ||
NDKPrivateKeySigner, | ||
NDKSubscription, | ||
type NostrEvent, | ||
import NDK, { | ||
NDKEvent, | ||
NDKKind, | ||
NDKPrivateKeySigner, | ||
NDKSubscription, | ||
type NostrEvent, | ||
type NDKUser, | ||
NDKSubscriptionCacheUsage, | ||
NDKRelay } from "@nostr-dev-kit/ndk"; | ||
NDKSubscriptionCacheUsage, | ||
NDKRelay, | ||
} from "@nostr-dev-kit/ndk"; | ||
import NDKRedisCacheAdapter from "."; | ||
@@ -16,3 +17,3 @@ import Redis from "ioredis"; | ||
cacheAdapter: new NDKRedisCacheAdapter(), | ||
signer | ||
signer, | ||
}); | ||
@@ -31,3 +32,3 @@ const redis = new Redis(); | ||
kind: NDKKind.Text, | ||
content: "hello, world" | ||
content: "hello, world", | ||
} as NostrEvent); | ||
@@ -43,6 +44,10 @@ await event.sign(); | ||
it("stores the event", async () => { | ||
const sub = new NDKSubscription(ndk, { | ||
authors: [user.pubkey], | ||
kinds: [NDKKind.Text], | ||
}, { cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE, closeOnEose: true }); | ||
const sub = new NDKSubscription( | ||
ndk, | ||
{ | ||
authors: [user.pubkey], | ||
kinds: [NDKKind.Text], | ||
}, | ||
{ cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE, closeOnEose: true } | ||
); | ||
const event = await storeEvent(sub); | ||
@@ -57,6 +62,10 @@ | ||
it("finds the event", async () => { | ||
const sub = new NDKSubscription(ndk, { | ||
authors: [user.pubkey], | ||
kinds: [NDKKind.Text], | ||
}, { cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE, closeOnEose: true }); | ||
const sub = new NDKSubscription( | ||
ndk, | ||
{ | ||
authors: [user.pubkey], | ||
kinds: [NDKKind.Text], | ||
}, | ||
{ cacheUsage: NDKSubscriptionCacheUsage.ONLY_CACHE, closeOnEose: true } | ||
); | ||
const event = await storeEvent(sub); | ||
@@ -78,2 +87,2 @@ | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
} |
@@ -20,5 +20,5 @@ import type { NDKCacheAdapter, NDKFilter, NostrEvent, ProfilePointer } from "@nostr-dev-kit/ndk"; | ||
/** | ||
* Redis instance connection path | ||
*/ | ||
path?: string | ||
* Redis instance connection path | ||
*/ | ||
path?: string; | ||
} | ||
@@ -43,4 +43,4 @@ | ||
public async query(subscription: NDKSubscription): Promise<void> { | ||
this.debug('query redis status', this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
this.debug("query redis status", this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
await Promise.all( | ||
@@ -57,13 +57,20 @@ subscription.filters.map((filter) => this.processFilter(filter, subscription)) | ||
return new Promise((resolve) => { | ||
Promise.all(eventIds.map(async (eventId) => { | ||
const event = await this.redis.get(eventId); | ||
if (!event) return; | ||
Promise.all( | ||
eventIds.map(async (eventId) => { | ||
const event = await this.redis.get(eventId); | ||
if (!event) return; | ||
const parsedEvent = JSON.parse(event); | ||
const relayUrl = parsedEvent.relay; | ||
delete parsedEvent.relay; | ||
const relay = subscription.ndk.pool.getRelay(relayUrl, false) || new NDKRelay(relayUrl); | ||
const parsedEvent = JSON.parse(event); | ||
const relayUrl = parsedEvent.relay; | ||
delete parsedEvent.relay; | ||
const relay = | ||
subscription.ndk.pool.getRelay(relayUrl, false) || new NDKRelay(relayUrl); | ||
subscription.eventReceived(new NDKEvent(subscription.ndk, parsedEvent), relay, true); | ||
})).then(() => { | ||
subscription.eventReceived( | ||
new NDKEvent(subscription.ndk, parsedEvent), | ||
relay, | ||
true | ||
); | ||
}) | ||
).then(() => { | ||
resolve(); | ||
@@ -79,3 +86,7 @@ }); | ||
private async storeEventWithFilter(event: NostrEvent, filter: NDKFilter, relay: NDKRelay): Promise<void> { | ||
private async storeEventWithFilter( | ||
event: NostrEvent, | ||
filter: NDKFilter, | ||
relay: NDKRelay | ||
): Promise<void> { | ||
const filterString = JSON.stringify(filter); | ||
@@ -116,6 +127,5 @@ | ||
public async setEvent(event: NDKEvent, filters: NDKFilter[], relay: NDKRelay): Promise<void> { | ||
this.debug('setEvent redis status', this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
this.debug("setEvent redis status", this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
const rawEvent = event.rawEvent(); | ||
@@ -140,4 +150,4 @@ | ||
public async loadNip05?(nip05: string): Promise<ProfilePointer | null> { | ||
this.debug('loadNip05 redis status', this.redis.status); | ||
if (this.redis.status !== "connect") return null; | ||
this.debug("loadNip05 redis status", this.redis.status); | ||
if (this.redis.status !== "connect") return null; | ||
const profile = await this.redis.get(this.nip05Key(nip05)); | ||
@@ -148,10 +158,5 @@ return profile ? JSON.parse(profile) : null; | ||
public saveNip05?(nip05: string, profile: ProfilePointer): void { | ||
this.debug('saveNip05 redis status', this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
this.redis.set( | ||
this.nip05Key(nip05), | ||
JSON.stringify(profile), | ||
"EX", | ||
this.expirationTime, | ||
); | ||
this.debug("saveNip05 redis status", this.redis.status); | ||
if (this.redis.status !== "connect") return; | ||
this.redis.set(this.nip05Key(nip05), JSON.stringify(profile), "EX", this.expirationTime); | ||
} | ||
@@ -158,0 +163,0 @@ |
Sorry, the diff of this file is not supported yet
17067
217
10
+ Added@nostr-dev-kit/ndk@2.10.1(transitive)
- Removed@nostr-dev-kit/ndk@2.10.0(transitive)
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
Updated@nostr-dev-kit/ndk@2.10.1