@envelop/response-cache-redis 0.5.0-alpha-c0cc559.0 → 0.5.0-alpha-e9434aa.0

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 ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./redis-cache.js"), exports);
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,12 +1,11 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultBuildRedisOperationResultCacheKey = exports.defaultBuildRedisEntityId = exports.createRedisCache = void 0;
5
4
  const createRedisCache = (params) => {
6
5
  var _a, _b;
7
6
  const store = params.redis;
8
- const buildRedisEntityId = (_a = params === null || params === void 0 ? void 0 : params.buildRedisEntityId) !== null && _a !== void 0 ? _a : defaultBuildRedisEntityId;
9
- const buildRedisOperationResultCacheKey = (_b = params === null || params === void 0 ? void 0 : params.buildRedisOperationResultCacheKey) !== null && _b !== void 0 ? _b : defaultBuildRedisOperationResultCacheKey;
7
+ const buildRedisEntityId = (_a = params === null || params === void 0 ? void 0 : params.buildRedisEntityId) !== null && _a !== void 0 ? _a : exports.defaultBuildRedisEntityId;
8
+ const buildRedisOperationResultCacheKey = (_b = params === null || params === void 0 ? void 0 : params.buildRedisOperationResultCacheKey) !== null && _b !== void 0 ? _b : exports.defaultBuildRedisOperationResultCacheKey;
10
9
  async function buildEntityInvalidationsKeys(entity) {
11
10
  const keysToInvalidate = [entity];
12
11
  // find the responseIds for the entity
@@ -76,9 +75,8 @@ const createRedisCache = (params) => {
76
75
  },
77
76
  };
78
77
  };
79
- const defaultBuildRedisEntityId = (typename, id) => `${typename}:${id}`;
80
- const defaultBuildRedisOperationResultCacheKey = responseId => `operations:${responseId}`;
81
-
82
78
  exports.createRedisCache = createRedisCache;
79
+ const defaultBuildRedisEntityId = (typename, id) => `${typename}:${id}`;
83
80
  exports.defaultBuildRedisEntityId = defaultBuildRedisEntityId;
81
+ const defaultBuildRedisOperationResultCacheKey = responseId => `operations:${responseId}`;
84
82
  exports.defaultBuildRedisOperationResultCacheKey = defaultBuildRedisOperationResultCacheKey;
package/esm/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./redis-cache.js"), exports);
@@ -1,8 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultBuildRedisOperationResultCacheKey = exports.defaultBuildRedisEntityId = exports.createRedisCache = void 0;
1
4
  const createRedisCache = (params) => {
2
5
  var _a, _b;
3
6
  const store = params.redis;
4
- const buildRedisEntityId = (_a = params === null || params === void 0 ? void 0 : params.buildRedisEntityId) !== null && _a !== void 0 ? _a : defaultBuildRedisEntityId;
5
- const buildRedisOperationResultCacheKey = (_b = params === null || params === void 0 ? void 0 : params.buildRedisOperationResultCacheKey) !== null && _b !== void 0 ? _b : defaultBuildRedisOperationResultCacheKey;
7
+ const buildRedisEntityId = (_a = params === null || params === void 0 ? void 0 : params.buildRedisEntityId) !== null && _a !== void 0 ? _a : exports.defaultBuildRedisEntityId;
8
+ const buildRedisOperationResultCacheKey = (_b = params === null || params === void 0 ? void 0 : params.buildRedisOperationResultCacheKey) !== null && _b !== void 0 ? _b : exports.defaultBuildRedisOperationResultCacheKey;
6
9
  async function buildEntityInvalidationsKeys(entity) {
7
10
  const keysToInvalidate = [entity];
8
11
  // find the responseIds for the entity
@@ -72,7 +75,8 @@ const createRedisCache = (params) => {
72
75
  },
73
76
  };
74
77
  };
78
+ exports.createRedisCache = createRedisCache;
75
79
  const defaultBuildRedisEntityId = (typename, id) => `${typename}:${id}`;
80
+ exports.defaultBuildRedisEntityId = defaultBuildRedisEntityId;
76
81
  const defaultBuildRedisOperationResultCacheKey = responseId => `operations:${responseId}`;
77
-
78
- export { createRedisCache, defaultBuildRedisEntityId, defaultBuildRedisOperationResultCacheKey };
82
+ exports.defaultBuildRedisOperationResultCacheKey = defaultBuildRedisOperationResultCacheKey;
package/package.json CHANGED
@@ -1,33 +1,55 @@
1
1
  {
2
2
  "name": "@envelop/response-cache-redis",
3
- "version": "0.5.0-alpha-c0cc559.0",
3
+ "version": "0.5.0-alpha-e9434aa.0",
4
4
  "sideEffects": false,
5
+ "peerDependencies": {},
5
6
  "dependencies": {
6
- "@envelop/response-cache": "2.4.0-alpha-c0cc559.0",
7
+ "@envelop/response-cache": "2.4.0-alpha-e9434aa.0",
7
8
  "ioredis": "^4.27.9"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
11
- "url": "https://github.com/dotansimha/envelop.git",
12
+ "url": "https://github.com/n1ru4l/envelop.git",
12
13
  "directory": "packages/plugins/response-cache-redis"
13
14
  },
14
15
  "author": "David Thyresson <dthyresson@gmail.com>",
15
16
  "license": "MIT",
16
- "main": "index.js",
17
- "module": "index.mjs",
18
- "typings": "index.d.ts",
17
+ "main": "cjs/index.js",
18
+ "module": "esm/index.js",
19
+ "typings": "typings/index.d.ts",
19
20
  "typescript": {
20
- "definition": "index.d.ts"
21
+ "definition": "typings/index.d.ts"
21
22
  },
23
+ "type": "module",
22
24
  "exports": {
23
25
  ".": {
24
- "require": "./index.js",
25
- "import": "./index.mjs"
26
+ "require": {
27
+ "types": "./typings/index.d.ts",
28
+ "default": "./cjs/index.js"
29
+ },
30
+ "import": {
31
+ "types": "./typings/index.d.ts",
32
+ "default": "./esm/index.js"
33
+ },
34
+ "default": {
35
+ "types": "./typings/index.d.ts",
36
+ "default": "./esm/index.js"
37
+ }
26
38
  },
27
39
  "./*": {
28
- "require": "./*.js",
29
- "import": "./*.mjs"
40
+ "require": {
41
+ "types": "./typings/*.d.ts",
42
+ "default": "./cjs/*.js"
43
+ },
44
+ "import": {
45
+ "types": "./typings/*.d.ts",
46
+ "default": "./esm/*.js"
47
+ },
48
+ "default": {
49
+ "types": "./typings/*.d.ts",
50
+ "default": "./esm/*.js"
51
+ }
30
52
  },
31
53
  "./package.json": "./package.json"
32
54
  }
33
- }
55
+ }
@@ -0,0 +1 @@
1
+ export * from './redis-cache.js';
File without changes
package/README.md DELETED
@@ -1,89 +0,0 @@
1
- ## `@envelop/response-cache-redis`
2
-
3
- - Supports redis cache for `@envelop/response-cache` plugin
4
- - Suitable for serveless deployments where the LRU In-Memory Cache is not possible
5
-
6
- [Check out the GraphQL Response Cache Guide for more information](https://envelop.dev/docs/guides/adding-a-graphql-response-cache)
7
-
8
- ## Getting Started
9
-
10
- ```bash
11
- yarn add @envelop/response-cache
12
- yarn add @envelop/response-cache-redis
13
- ```
14
-
15
- ## Usage Example
16
-
17
- In order to use the Redis cache, you need to:
18
-
19
- - Create a Redis database
20
- - Collect the connection settings (or its connection string), e.g., `host`, `port`, `username`, `password`, `tls`, etc.
21
- - Create and configure a [Redis client](https://github.com/luin/ioredis) with your [connection settings](https://github.com/luin/ioredis/blob/master/API.md#Redis) and any [additional options](https://github.com/luin/ioredis/blob/master/API.md#new_Redis_new)
22
- - Create an instance of the Redis Cache and set to the `useResponseCache` plugin options
23
-
24
- ```ts
25
-
26
- import { envelop } from '@envelop/core';
27
- import { useResponseCache } from '@envelop/response-cache';
28
- import { createRedisCache } from '@envelop/response-cache-redis';
29
-
30
- import Redis from 'ioredis';
31
-
32
- /**
33
- * For additional Redis options to create the ioredis client
34
- * @see: https://github.com/luin/ioredis/blob/master/API.md#new_Redis_new
35
- *
36
- **/
37
- const redis = new Redis({
38
- host: 'my-redis-db.example.com',
39
- port: '30652',
40
- password: '1234567890',
41
- });
42
-
43
- // or, you can also specify connection options as a redis:// URL or rediss:// URL when using TLS encryption
44
- const redis = new Redis(("rediss://:1234567890@my-redis-db.example.com':30652");
45
-
46
- const cache = createRedisCache({ redis });
47
-
48
- const getEnveloped = envelop({
49
- plugins: [
50
- // ... other plugins ...
51
- useResponseCache({ cache }),
52
- ],
53
- });
54
- ```
55
-
56
- ### Invalidate Cache based on custom logic
57
-
58
- ```ts
59
- import { envelop } from '@envelop/core';
60
- import { useResponseCache } from '@envelop/response-cache';
61
- import { createRedisCache } from '@envelop/response-cache-redis';
62
-
63
- import { emitter } from './eventEmitter';
64
-
65
- // we create our cache instance, which allows calling all methods on it
66
- const redis = new Redis(("rediss://:1234567890@my-redis-db.example.com':30652");
67
-
68
- const cache = createRedisCache({ redis });
69
-
70
- const getEnveloped = envelop({
71
- plugins: [
72
- // ... other plugins ...
73
- useResponseCache({
74
- ttl: 2000,
75
- // we pass the cache instance to the request.
76
- cache,
77
- }),
78
- ],
79
- });
80
-
81
- emitter.on('invalidate', resource => {
82
- cache.invalidate([
83
- {
84
- typename: resource.type,
85
- id: resource.id,
86
- },
87
- ]);
88
- });
89
- ```
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './redis-cache';