@envelop/validation-cache 4.4.0-alpha-8a8cd36.0 → 4.5.0-alpha-98c6b00.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/README.md +5 -5
- package/cjs/index.js +14 -3
- package/esm/index.js +14 -3
- package/package.json +3 -3
- package/typings/index.d.ts +14 -1
package/README.md
CHANGED
|
@@ -13,17 +13,17 @@ yarn add @envelop/validation-cache
|
|
|
13
13
|
## Usage Example
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { envelop } from '@envelop/core'
|
|
17
|
-
import { useValidationCache } from '@envelop/validation-cache'
|
|
16
|
+
import { envelop } from '@envelop/core'
|
|
17
|
+
import { useValidationCache } from '@envelop/validation-cache'
|
|
18
18
|
|
|
19
19
|
const getEnveloped = envelop({
|
|
20
20
|
plugins: [
|
|
21
21
|
// ... other plugins ...
|
|
22
22
|
useValidationCache({
|
|
23
23
|
// options goes here
|
|
24
|
-
})
|
|
25
|
-
]
|
|
26
|
-
})
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### API Reference
|
package/cjs/index.js
CHANGED
|
@@ -3,15 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useValidationCache = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const
|
|
6
|
+
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
7
7
|
const DEFAULT_MAX = 1000;
|
|
8
8
|
const DEFAULT_TTL = 3600000;
|
|
9
9
|
const rawDocumentSymbol = Symbol('rawDocument');
|
|
10
10
|
const useValidationCache = (pluginOptions = {}) => {
|
|
11
|
-
const resultCache = typeof pluginOptions.cache !== 'undefined'
|
|
11
|
+
const resultCache = typeof pluginOptions.cache !== 'undefined'
|
|
12
|
+
? pluginOptions.cache
|
|
13
|
+
: new lru_cache_1.default({
|
|
14
|
+
max: DEFAULT_MAX,
|
|
15
|
+
maxAge: DEFAULT_TTL,
|
|
16
|
+
});
|
|
12
17
|
return {
|
|
13
18
|
onSchemaChange() {
|
|
14
|
-
|
|
19
|
+
var _a, _b;
|
|
20
|
+
if (resultCache.reset) {
|
|
21
|
+
(_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache);
|
|
22
|
+
}
|
|
23
|
+
else if ('clear' in resultCache) {
|
|
24
|
+
(_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache);
|
|
25
|
+
}
|
|
15
26
|
},
|
|
16
27
|
onParse({ params, extendContext }) {
|
|
17
28
|
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { print } from 'graphql';
|
|
2
|
-
import
|
|
2
|
+
import LRU from 'lru-cache';
|
|
3
3
|
const DEFAULT_MAX = 1000;
|
|
4
4
|
const DEFAULT_TTL = 3600000;
|
|
5
5
|
const rawDocumentSymbol = Symbol('rawDocument');
|
|
6
6
|
export const useValidationCache = (pluginOptions = {}) => {
|
|
7
|
-
const resultCache = typeof pluginOptions.cache !== 'undefined'
|
|
7
|
+
const resultCache = typeof pluginOptions.cache !== 'undefined'
|
|
8
|
+
? pluginOptions.cache
|
|
9
|
+
: new LRU({
|
|
10
|
+
max: DEFAULT_MAX,
|
|
11
|
+
maxAge: DEFAULT_TTL,
|
|
12
|
+
});
|
|
8
13
|
return {
|
|
9
14
|
onSchemaChange() {
|
|
10
|
-
|
|
15
|
+
var _a, _b;
|
|
16
|
+
if (resultCache.reset) {
|
|
17
|
+
(_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache);
|
|
18
|
+
}
|
|
19
|
+
else if ('clear' in resultCache) {
|
|
20
|
+
(_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache);
|
|
21
|
+
}
|
|
11
22
|
},
|
|
12
23
|
onParse({ params, extendContext }) {
|
|
13
24
|
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/validation-cache",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0-alpha-98c6b00.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0
|
|
6
|
+
"@envelop/core": "^2.4.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
10
|
+
"lru-cache": "^6.0.0"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
package/typings/index.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/core';
|
|
2
2
|
import { GraphQLError } from 'graphql';
|
|
3
3
|
export interface ValidationCache {
|
|
4
|
+
/**
|
|
5
|
+
* Get a result from the validation cache.
|
|
6
|
+
*/
|
|
4
7
|
get(key: string): readonly GraphQLError[] | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Set a result to the validation cache.
|
|
10
|
+
*/
|
|
5
11
|
set(key: string, value: readonly GraphQLError[]): void;
|
|
6
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Provide a `reset` implementation instead.
|
|
14
|
+
*/
|
|
15
|
+
clear?(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Reset the cache by clearing all entries.
|
|
18
|
+
*/
|
|
19
|
+
reset?(): void;
|
|
7
20
|
}
|
|
8
21
|
export declare type ValidationCacheOptions = {
|
|
9
22
|
cache?: ValidationCache;
|