@nostr-dev-kit/ndk-cache-redis
Advanced tools
Comparing version
{ | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"outDir": "../dist/cjs" /* Redirect output structure to the directory. */ | ||
} | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"outDir": "../dist/cjs" /* Redirect output structure to the directory. */ | ||
} | ||
} |
{ | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"outDir": "../dist/esm" /* Redirect output structure to the directory. */ | ||
} | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"outDir": "../dist/esm" /* Redirect output structure to the directory. */ | ||
} | ||
} |
{ | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"declaration": true /* Generates corresponding '.d.ts' file. */, | ||
"emitDeclarationOnly": true, | ||
"outDir": "../dist/types" /* Redirect output structure to the directory. */ | ||
} | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"declaration": true /* Generates corresponding '.d.ts' file. */, | ||
"emitDeclarationOnly": true, | ||
"outDir": "../dist/types" /* Redirect output structure to the directory. */ | ||
} | ||
} |
{ | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"declaration": false /* Generates corresponding '.d.ts' file. */ | ||
} | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"declaration": false /* Generates corresponding '.d.ts' file. */ | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
import { NDKCacheAdapter, NDKFilter } from '@nostr-dev-kit/ndk'; | ||
import { NDKSubscription, NDKEvent } from '@nostr-dev-kit/ndk'; | ||
import Redis from 'ioredis'; | ||
import _debug from 'debug'; | ||
import type { NDKCacheAdapter, NDKFilter } from "@nostr-dev-kit/ndk"; | ||
import { NDKEvent, type NDKSubscription } from "@nostr-dev-kit/ndk"; | ||
import _debug from "debug"; | ||
import Redis from "ioredis"; | ||
interface RedisAdapterOptions { | ||
@@ -6,0 +6,0 @@ /** |
@@ -7,4 +7,4 @@ "use strict"; | ||
const ndk_1 = require("@nostr-dev-kit/ndk"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const ioredis_1 = __importDefault(require("ioredis")); | ||
const debug_1 = __importDefault(require("debug")); | ||
class RedisAdapter { | ||
@@ -17,3 +17,3 @@ redis; | ||
this.redis = new ioredis_1.default(); | ||
this.debug = opts.debug || (0, debug_1.default)('ndk:redis-adapter'); | ||
this.debug = opts.debug || (0, debug_1.default)("ndk:redis-adapter"); | ||
this.locking = true; | ||
@@ -24,3 +24,3 @@ this.expirationTime = opts.expirationTime || 3600; | ||
const { filter } = subscription; | ||
this.debug('query', filter); | ||
this.debug("query", filter); | ||
// if this filter uses both authors and kinds, then we need to query for each combination of author and kind | ||
@@ -42,3 +42,3 @@ // and then combine the results | ||
const ndkEvent = new ndk_1.NDKEvent(subscription.ndk, JSON.parse(event)); | ||
this.debug('hit', ndkEvent.id); | ||
this.debug("hit", ndkEvent.id); | ||
subscription.eventReceived(ndkEvent, undefined, true); | ||
@@ -53,3 +53,3 @@ } | ||
const key = `${nostrEvent.pubkey}:${nostrEvent.kind}`; | ||
this.debug('setEvent', { nostrEvent, key }); | ||
this.debug("setEvent", { nostrEvent, key }); | ||
return new Promise((resolve) => { | ||
@@ -60,4 +60,4 @@ // store in redis the event with an expiration of 1 minute | ||
Promise.all([ | ||
this.redis.set(event.id, JSON.stringify(nostrEvent), 'EX', this.expirationTime), | ||
this.redis.hset(key, 'event', event.id), | ||
this.redis.set(event.id, JSON.stringify(nostrEvent), "EX", this.expirationTime), | ||
this.redis.hset(key, "event", event.id), | ||
this.redis.expire(key, this.expirationTime), | ||
@@ -64,0 +64,0 @@ ]).then(() => resolve()); |
@@ -1,5 +0,5 @@ | ||
import { NDKCacheAdapter, NDKFilter } from '@nostr-dev-kit/ndk'; | ||
import { NDKSubscription, NDKEvent } from '@nostr-dev-kit/ndk'; | ||
import Redis from 'ioredis'; | ||
import _debug from 'debug'; | ||
import type { NDKCacheAdapter, NDKFilter } from "@nostr-dev-kit/ndk"; | ||
import { NDKEvent, type NDKSubscription } from "@nostr-dev-kit/ndk"; | ||
import _debug from "debug"; | ||
import Redis from "ioredis"; | ||
interface RedisAdapterOptions { | ||
@@ -6,0 +6,0 @@ /** |
@@ -1,5 +0,5 @@ | ||
import { NDKCacheAdapter, NDKFilter } from '@nostr-dev-kit/ndk'; | ||
import { NDKSubscription, NDKEvent } from '@nostr-dev-kit/ndk'; | ||
import Redis from 'ioredis'; | ||
import _debug from 'debug'; | ||
import type { NDKCacheAdapter, NDKFilter } from "@nostr-dev-kit/ndk"; | ||
import { NDKEvent, type NDKSubscription } from "@nostr-dev-kit/ndk"; | ||
import _debug from "debug"; | ||
import Redis from "ioredis"; | ||
interface RedisAdapterOptions { | ||
@@ -6,0 +6,0 @@ /** |
{ | ||
"name": "@nostr-dev-kit/ndk-cache-redis", | ||
"version": "1.8.0", | ||
"version": "2.0.5", | ||
"description": "NDK cache adapter for redis.", | ||
@@ -22,18 +22,14 @@ "main": "dist/cjs/index.js", | ||
"homepage": "https://github.com/nostr-dev-kit/ndk-cache-redis#readme", | ||
"dependencies": { | ||
"debug": "^4.3.4", | ||
"ioredis": "^5.3.1", | ||
"@nostr-dev-kit/ndk": "2.0.5" | ||
}, | ||
"devDependencies": { | ||
"@nostr-dev-kit/tsconfig": "*", | ||
"@types/debug": "^4.1.7", | ||
"@types/node": "^18.15.11", | ||
"@typescript-eslint/eslint-plugin": "^5.57.0", | ||
"@typescript-eslint/parser": "^5.57.0", | ||
"eslint": "^8.37.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"typescript": "^5.1.6" | ||
"tsup": "^7.2.0", | ||
"@nostr-dev-kit/eslint-config-custom": "0.0.0", | ||
"@nostr-dev-kit/tsconfig": "0.0.0" | ||
}, | ||
"dependencies": { | ||
"@nostr-dev-kit/ndk": "*", | ||
"debug": "^4.3.4", | ||
"ioredis": "^5.3.1" | ||
}, | ||
"scripts": { | ||
@@ -45,4 +41,5 @@ "dev": "node tools/cleanup esm && tsc -w -p config/tsconfig.esm.json", | ||
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json", | ||
"lint": "eslint src/**/*.ts" | ||
"lint": "prettier --check . && eslint .", | ||
"format": "prettier --write ." | ||
} | ||
} |
@@ -17,4 +17,6 @@ # ndk-cache-redis | ||
### Add as a cache adapter | ||
```ts | ||
import NDKRedisCacheAdapter from '@nostr-dev-kit/ndk-cache-redis'; | ||
import NDKRedisCacheAdapter from "@nostr-dev-kit/ndk-cache-redis"; | ||
const cacheAdapter = new NDKRedisCacheAdapter(); | ||
@@ -21,0 +23,0 @@ const ndk = new NDK({ cacheAdapter }); |
@@ -1,5 +0,5 @@ | ||
import { NDKCacheAdapter, NDKFilter } from '@nostr-dev-kit/ndk'; | ||
import { NDKSubscription, NDKEvent } from '@nostr-dev-kit/ndk'; | ||
import Redis from 'ioredis'; | ||
import _debug from 'debug'; | ||
import type { NDKCacheAdapter, NDKFilter } from "@nostr-dev-kit/ndk"; | ||
import { NDKEvent, type NDKSubscription } from "@nostr-dev-kit/ndk"; | ||
import _debug from "debug"; | ||
import Redis from "ioredis"; | ||
@@ -16,2 +16,6 @@ interface RedisAdapterOptions { | ||
expirationTime?: number; | ||
/** | ||
* Redis instance connection path | ||
*/ | ||
path?: string | ||
} | ||
@@ -26,4 +30,4 @@ | ||
constructor(opts: RedisAdapterOptions = {}) { | ||
this.redis = new Redis(); | ||
this.debug = opts.debug || _debug('ndk:redis-adapter'); | ||
this.redis = opts.path ? new Redis(opts.path) : new Redis(); | ||
this.debug = opts.debug || _debug("ndk:redis-adapter"); | ||
this.locking = true; | ||
@@ -36,3 +40,3 @@ this.expirationTime = opts.expirationTime || 3600; | ||
this.debug('query', filter); | ||
this.debug("query", filter); | ||
@@ -59,3 +63,3 @@ // if this filter uses both authors and kinds, then we need to query for each combination of author and kind | ||
const ndkEvent = new NDKEvent(subscription.ndk, JSON.parse(event)); | ||
this.debug('hit', ndkEvent.id); | ||
this.debug("hit", ndkEvent.id); | ||
subscription.eventReceived(ndkEvent, undefined, true); | ||
@@ -72,3 +76,3 @@ } | ||
this.debug('setEvent', {nostrEvent, key}); | ||
this.debug("setEvent", { nostrEvent, key }); | ||
@@ -80,4 +84,4 @@ return new Promise((resolve) => { | ||
Promise.all([ | ||
this.redis.set(event.id, JSON.stringify(nostrEvent), 'EX', this.expirationTime), | ||
this.redis.hset(key, 'event', event.id), | ||
this.redis.set(event.id, JSON.stringify(nostrEvent), "EX", this.expirationTime), | ||
this.redis.hset(key, "event", event.id), | ||
this.redis.expire(key, this.expirationTime), | ||
@@ -87,2 +91,2 @@ ]).then(() => resolve()); | ||
} | ||
} | ||
} |
{ | ||
"extends": "@nostr-dev-kit/tsconfig/ndk-cache-redis.json", | ||
"include": ["src/**/*"], | ||
"exclude": ["dist", "build", "node_modules"] | ||
"extends": "@nostr-dev-kit/tsconfig/ndk-cache-redis.json", | ||
"include": ["src/**/*"], | ||
"exclude": ["dist", "build", "node_modules"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
16635
0.58%5
-44.44%1
-50%28
7.69%20
-4.76%240
-10.45%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated