@graphql-mesh/cache-upstash-redis 0.0.1-alpha-20250131090929-a30bb9a75b98ce99d6636ae9ffda520197be4687
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +42 -0
- package/cjs/package.json +1 -0
- package/esm/index.js +39 -0
- package/package.json +48 -0
- package/typings/index.d.cts +16 -0
- package/typings/index.d.ts +16 -0
package/cjs/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
4
|
+
const redis_1 = require("@upstash/redis");
|
|
5
|
+
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
6
|
+
class UpstashRedisCache {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.abortCtrl = new AbortController();
|
|
9
|
+
this.redis = new redis_1.Redis({
|
|
10
|
+
url: cross_helpers_1.process.env.UPSTASH_REDIS_REST_URL,
|
|
11
|
+
token: cross_helpers_1.process.env.UPSTASH_REDIS_REST_TOKEN,
|
|
12
|
+
enableAutoPipelining: true,
|
|
13
|
+
signal: this.abortCtrl.signal,
|
|
14
|
+
latencyLogging: !!cross_helpers_1.process.env.DEBUG,
|
|
15
|
+
...config,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
get(key) {
|
|
19
|
+
return this.redis.get(key);
|
|
20
|
+
}
|
|
21
|
+
async set(key, value, options) {
|
|
22
|
+
if (options?.ttl) {
|
|
23
|
+
await this.redis.set(key, value, {
|
|
24
|
+
px: options.ttl * 1000,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await this.redis.set(key, value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async delete(key) {
|
|
32
|
+
const num = await this.redis.del(key);
|
|
33
|
+
return num > 0;
|
|
34
|
+
}
|
|
35
|
+
getKeysByPrefix(prefix) {
|
|
36
|
+
return this.redis.keys(prefix + '*');
|
|
37
|
+
}
|
|
38
|
+
[disposablestack_1.DisposableSymbols.dispose]() {
|
|
39
|
+
return this.abortCtrl.abort();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = UpstashRedisCache;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { process } from '@graphql-mesh/cross-helpers';
|
|
2
|
+
import { Redis } from '@upstash/redis';
|
|
3
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
|
+
export default class UpstashRedisCache {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.abortCtrl = new AbortController();
|
|
7
|
+
this.redis = new Redis({
|
|
8
|
+
url: process.env.UPSTASH_REDIS_REST_URL,
|
|
9
|
+
token: process.env.UPSTASH_REDIS_REST_TOKEN,
|
|
10
|
+
enableAutoPipelining: true,
|
|
11
|
+
signal: this.abortCtrl.signal,
|
|
12
|
+
latencyLogging: !!process.env.DEBUG,
|
|
13
|
+
...config,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
return this.redis.get(key);
|
|
18
|
+
}
|
|
19
|
+
async set(key, value, options) {
|
|
20
|
+
if (options?.ttl) {
|
|
21
|
+
await this.redis.set(key, value, {
|
|
22
|
+
px: options.ttl * 1000,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
await this.redis.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async delete(key) {
|
|
30
|
+
const num = await this.redis.del(key);
|
|
31
|
+
return num > 0;
|
|
32
|
+
}
|
|
33
|
+
getKeysByPrefix(prefix) {
|
|
34
|
+
return this.redis.keys(prefix + '*');
|
|
35
|
+
}
|
|
36
|
+
[DisposableSymbols.dispose]() {
|
|
37
|
+
return this.abortCtrl.abort();
|
|
38
|
+
}
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-mesh/cache-upstash-redis",
|
|
3
|
+
"version": "0.0.1-alpha-20250131090929-a30bb9a75b98ce99d6636ae9ffda520197be4687",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "*"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@graphql-mesh/cross-helpers": "^0.4.9",
|
|
10
|
+
"@graphql-mesh/types": "^0.103.12",
|
|
11
|
+
"@upstash/redis": "^1.34.3",
|
|
12
|
+
"@whatwg-node/disposablestack": "^0.0.5",
|
|
13
|
+
"tslib": "^2.4.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "ardatan/graphql-mesh",
|
|
18
|
+
"directory": "packages/cache/upstash-redis"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18.0.0"
|
|
23
|
+
},
|
|
24
|
+
"main": "cjs/index.js",
|
|
25
|
+
"module": "esm/index.js",
|
|
26
|
+
"typings": "typings/index.d.ts",
|
|
27
|
+
"typescript": {
|
|
28
|
+
"definition": "typings/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./typings/index.d.cts",
|
|
35
|
+
"default": "./cjs/index.js"
|
|
36
|
+
},
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
},
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./typings/index.d.ts",
|
|
43
|
+
"default": "./esm/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KeyValueCache } from '@graphql-mesh/types';
|
|
2
|
+
import type { MaybePromise } from '@graphql-tools/utils';
|
|
3
|
+
import { type RedisConfigNodejs } from '@upstash/redis';
|
|
4
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
5
|
+
export default class UpstashRedisCache implements KeyValueCache {
|
|
6
|
+
private redis;
|
|
7
|
+
private abortCtrl;
|
|
8
|
+
constructor(config?: Partial<RedisConfigNodejs>);
|
|
9
|
+
get<T>(key: string): Promise<T>;
|
|
10
|
+
set<T>(key: string, value: T, options?: {
|
|
11
|
+
ttl?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<boolean>;
|
|
14
|
+
getKeysByPrefix(prefix: string): MaybePromise<string[]>;
|
|
15
|
+
[DisposableSymbols.dispose](): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KeyValueCache } from '@graphql-mesh/types';
|
|
2
|
+
import type { MaybePromise } from '@graphql-tools/utils';
|
|
3
|
+
import { type RedisConfigNodejs } from '@upstash/redis';
|
|
4
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
5
|
+
export default class UpstashRedisCache implements KeyValueCache {
|
|
6
|
+
private redis;
|
|
7
|
+
private abortCtrl;
|
|
8
|
+
constructor(config?: Partial<RedisConfigNodejs>);
|
|
9
|
+
get<T>(key: string): Promise<T>;
|
|
10
|
+
set<T>(key: string, value: T, options?: {
|
|
11
|
+
ttl?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<boolean>;
|
|
14
|
+
getKeysByPrefix(prefix: string): MaybePromise<string[]>;
|
|
15
|
+
[DisposableSymbols.dispose](): void;
|
|
16
|
+
}
|