@graphql-mesh/cache-redis 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/{index.js → cjs/index.js} +16 -18
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +8 -10
- package/package.json +27 -20
- package/typings/index.d.ts +11 -0
- /package/{index.d.ts → typings/index.d.cts} +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const RedisMock = _interopDefault(require('ioredis-mock'));
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
|
|
5
|
+
const ioredis_mock_1 = tslib_1.__importDefault(require("ioredis-mock"));
|
|
6
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
7
|
+
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
10
8
|
function interpolateStrWithEnv(str) {
|
|
11
|
-
return
|
|
9
|
+
return string_interpolation_1.stringInterpolator.parse(str, { env: cross_helpers_1.process.env });
|
|
12
10
|
}
|
|
13
11
|
class RedisCache {
|
|
14
12
|
constructor(options) {
|
|
13
|
+
var _a, _b, _c;
|
|
15
14
|
if (options.url) {
|
|
16
15
|
const redisUrl = new URL(interpolateStrWithEnv(options.url));
|
|
17
16
|
redisUrl.searchParams.set('lazyConnect', 'true');
|
|
@@ -20,14 +19,14 @@ class RedisCache {
|
|
|
20
19
|
if (!['redis:', 'rediss:'].includes(redisUrl.protocol)) {
|
|
21
20
|
throw new Error('Redis URL must use either redis:// or rediss://');
|
|
22
21
|
}
|
|
23
|
-
this.client = new
|
|
22
|
+
this.client = new ioredis_1.default(redisUrl === null || redisUrl === void 0 ? void 0 : redisUrl.toString());
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
|
-
const parsedHost = interpolateStrWithEnv(options.host);
|
|
27
|
-
const parsedPort = interpolateStrWithEnv(options.port);
|
|
28
|
-
const parsedPassword = interpolateStrWithEnv(options.password);
|
|
25
|
+
const parsedHost = interpolateStrWithEnv((_a = options.host) === null || _a === void 0 ? void 0 : _a.toString());
|
|
26
|
+
const parsedPort = interpolateStrWithEnv((_b = options.port) === null || _b === void 0 ? void 0 : _b.toString());
|
|
27
|
+
const parsedPassword = interpolateStrWithEnv((_c = options.password) === null || _c === void 0 ? void 0 : _c.toString());
|
|
29
28
|
if (parsedHost) {
|
|
30
|
-
this.client = new
|
|
29
|
+
this.client = new ioredis_1.default({
|
|
31
30
|
host: parsedHost,
|
|
32
31
|
port: parseInt(parsedPort),
|
|
33
32
|
password: parsedPassword,
|
|
@@ -37,7 +36,7 @@ class RedisCache {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
else {
|
|
40
|
-
this.client = new
|
|
39
|
+
this.client = new ioredis_mock_1.default();
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
const id = options.pubsub.subscribe('destroy', () => {
|
|
@@ -75,5 +74,4 @@ class RedisCache {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
|
|
79
|
-
module.exports = RedisCache;
|
|
77
|
+
exports.default = RedisCache;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
3
|
-
import { process } from '@graphql-mesh/cross-helpers';
|
|
4
2
|
import RedisMock from 'ioredis-mock';
|
|
5
|
-
|
|
3
|
+
import { process } from '@graphql-mesh/cross-helpers';
|
|
4
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
6
5
|
function interpolateStrWithEnv(str) {
|
|
7
6
|
return stringInterpolator.parse(str, { env: process.env });
|
|
8
7
|
}
|
|
9
|
-
class RedisCache {
|
|
8
|
+
export default class RedisCache {
|
|
10
9
|
constructor(options) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
11
|
if (options.url) {
|
|
12
12
|
const redisUrl = new URL(interpolateStrWithEnv(options.url));
|
|
13
13
|
redisUrl.searchParams.set('lazyConnect', 'true');
|
|
@@ -16,12 +16,12 @@ class RedisCache {
|
|
|
16
16
|
if (!['redis:', 'rediss:'].includes(redisUrl.protocol)) {
|
|
17
17
|
throw new Error('Redis URL must use either redis:// or rediss://');
|
|
18
18
|
}
|
|
19
|
-
this.client = new Redis(redisUrl.toString());
|
|
19
|
+
this.client = new Redis(redisUrl === null || redisUrl === void 0 ? void 0 : redisUrl.toString());
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
const parsedHost = interpolateStrWithEnv(options.host);
|
|
23
|
-
const parsedPort = interpolateStrWithEnv(options.port);
|
|
24
|
-
const parsedPassword = interpolateStrWithEnv(options.password);
|
|
22
|
+
const parsedHost = interpolateStrWithEnv((_a = options.host) === null || _a === void 0 ? void 0 : _a.toString());
|
|
23
|
+
const parsedPort = interpolateStrWithEnv((_b = options.port) === null || _b === void 0 ? void 0 : _b.toString());
|
|
24
|
+
const parsedPassword = interpolateStrWithEnv((_c = options.password) === null || _c === void 0 ? void 0 : _c.toString());
|
|
25
25
|
if (parsedHost) {
|
|
26
26
|
this.client = new Redis({
|
|
27
27
|
host: parsedHost,
|
|
@@ -71,5 +71,3 @@ class RedisCache {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
export default RedisCache;
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/cache-redis",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
7
|
-
"@graphql-mesh/
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/cross-helpers": "^0.3.4",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
9
|
+
"graphql": "*",
|
|
10
|
+
"tslib": "^2.4.0"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
11
|
-
"@graphql-mesh/
|
|
12
|
-
"
|
|
13
|
-
"ioredis": "
|
|
14
|
-
"ioredis-mock": "8.2.2",
|
|
15
|
-
"tslib": "^2.4.0"
|
|
13
|
+
"@graphql-mesh/string-interpolation": "0.4.4",
|
|
14
|
+
"ioredis": "5.3.2",
|
|
15
|
+
"ioredis-mock": "8.7.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -20,21 +20,28 @@
|
|
|
20
20
|
"directory": "packages/cache/redis"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"main": "index.js",
|
|
24
|
-
"module": "index.
|
|
25
|
-
"typings": "index.d.ts",
|
|
23
|
+
"main": "cjs/index.js",
|
|
24
|
+
"module": "esm/index.js",
|
|
25
|
+
"typings": "typings/index.d.ts",
|
|
26
26
|
"typescript": {
|
|
27
|
-
"definition": "index.d.ts"
|
|
27
|
+
"definition": "typings/index.d.ts"
|
|
28
28
|
},
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./typings/index.d.cts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
}
|
|
37
44
|
},
|
|
38
45
|
"./package.json": "./package.json"
|
|
39
46
|
}
|
|
40
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KeyValueCache, KeyValueCacheSetOptions, MeshPubSub, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
export default class RedisCache<V = string> implements KeyValueCache<V> {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(options: YamlConfig.Cache['redis'] & {
|
|
5
|
+
pubsub: MeshPubSub;
|
|
6
|
+
});
|
|
7
|
+
set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise<void>;
|
|
8
|
+
get(key: string): Promise<V | undefined>;
|
|
9
|
+
getKeysByPrefix(prefix: string): Promise<string[]>;
|
|
10
|
+
delete(key: string): Promise<boolean>;
|
|
11
|
+
}
|
|
File without changes
|