@envelop/validation-cache
Advanced tools
Comparing version 4.4.0 to 4.5.0-alpha-18632d3.0
@@ -6,3 +6,3 @@ "use strict"; | ||
const graphql_1 = require("graphql"); | ||
const tiny_lru_1 = tslib_1.__importDefault(require("tiny-lru")); | ||
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache")); | ||
const DEFAULT_MAX = 1000; | ||
@@ -12,6 +12,17 @@ const DEFAULT_TTL = 3600000; | ||
const useValidationCache = (pluginOptions = {}) => { | ||
const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : (0, tiny_lru_1.default)(DEFAULT_MAX, DEFAULT_TTL); | ||
const resultCache = typeof pluginOptions.cache !== 'undefined' | ||
? pluginOptions.cache | ||
: new lru_cache_1.default({ | ||
max: DEFAULT_MAX, | ||
maxAge: DEFAULT_TTL, | ||
}); | ||
return { | ||
onSchemaChange() { | ||
resultCache.clear(); | ||
var _a, _b; | ||
if (resultCache.reset) { | ||
(_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache); | ||
} | ||
else if ('clear' in resultCache) { | ||
(_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache); | ||
} | ||
}, | ||
@@ -18,0 +29,0 @@ onParse({ params, extendContext }) { |
import { print } from 'graphql'; | ||
import lru from 'tiny-lru'; | ||
import LRU from 'lru-cache'; | ||
const DEFAULT_MAX = 1000; | ||
@@ -7,6 +7,17 @@ const DEFAULT_TTL = 3600000; | ||
export const useValidationCache = (pluginOptions = {}) => { | ||
const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL); | ||
const resultCache = typeof pluginOptions.cache !== 'undefined' | ||
? pluginOptions.cache | ||
: new LRU({ | ||
max: DEFAULT_MAX, | ||
maxAge: DEFAULT_TTL, | ||
}); | ||
return { | ||
onSchemaChange() { | ||
resultCache.clear(); | ||
var _a, _b; | ||
if (resultCache.reset) { | ||
(_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache); | ||
} | ||
else if ('clear' in resultCache) { | ||
(_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache); | ||
} | ||
}, | ||
@@ -13,0 +24,0 @@ onParse({ params, extendContext }) { |
{ | ||
"name": "@envelop/validation-cache", | ||
"version": "4.4.0", | ||
"version": "4.5.0-alpha-18632d3.0", | ||
"sideEffects": false, | ||
@@ -10,3 +10,3 @@ "peerDependencies": { | ||
"dependencies": { | ||
"tiny-lru": "7.0.6" | ||
"lru-cache": "^6.0.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "repository": { |
@@ -16,4 +16,4 @@ ## `@envelop/validation-cache` | ||
```ts | ||
import { envelop } from '@envelop/core'; | ||
import { useValidationCache } from '@envelop/validation-cache'; | ||
import { envelop } from '@envelop/core' | ||
import { useValidationCache } from '@envelop/validation-cache' | ||
@@ -25,5 +25,5 @@ const getEnveloped = envelop({ | ||
// options goes here | ||
}), | ||
], | ||
}); | ||
}) | ||
] | ||
}) | ||
``` | ||
@@ -30,0 +30,0 @@ |
import { Plugin } from '@envelop/core'; | ||
import { GraphQLError } from 'graphql'; | ||
export interface ValidationCache { | ||
/** | ||
* Get a result from the validation cache. | ||
*/ | ||
get(key: string): readonly GraphQLError[] | undefined; | ||
/** | ||
* Set a result to the validation cache. | ||
*/ | ||
set(key: string, value: readonly GraphQLError[]): void; | ||
clear(): void; | ||
/** | ||
* @deprecated Provide a `reset` implementation instead. | ||
*/ | ||
clear?(): void; | ||
/** | ||
* Reset the cache by clearing all entries. | ||
*/ | ||
reset?(): void; | ||
} | ||
@@ -8,0 +21,0 @@ export declare type ValidationCacheOptions = { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5857
105
59
60
2
+ Addedlru-cache@^6.0.0
+ Addedlru-cache@6.0.0(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedtiny-lru@7.0.6
- Removedtiny-lru@7.0.6(transitive)