@envelop/validation-cache 4.4.0-alpha-e9434aa.0 → 4.4.0-alpha-731c100.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.
Files changed (2) hide show
  1. package/esm/index.js +5 -12
  2. package/package.json +2 -2
package/esm/index.js CHANGED
@@ -1,16 +1,10 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useValidationCache = void 0;
7
- const graphql_1 = require("graphql");
8
- const tiny_lru_1 = __importDefault(require("tiny-lru"));
1
+ import { print } from 'graphql';
2
+ import lru from 'tiny-lru';
9
3
  const DEFAULT_MAX = 1000;
10
4
  const DEFAULT_TTL = 3600000;
11
5
  const rawDocumentSymbol = Symbol('rawDocument');
12
- const useValidationCache = (pluginOptions = {}) => {
13
- const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : (0, tiny_lru_1.default)(DEFAULT_MAX, DEFAULT_TTL);
6
+ export const useValidationCache = (pluginOptions = {}) => {
7
+ const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL);
14
8
  return {
15
9
  onSchemaChange() {
16
10
  resultCache.clear();
@@ -20,7 +14,7 @@ const useValidationCache = (pluginOptions = {}) => {
20
14
  },
21
15
  onValidate({ params, context, setResult }) {
22
16
  var _a;
23
- const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : (0, graphql_1.print)(params.documentAST);
17
+ const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : print(params.documentAST);
24
18
  const cachedResult = resultCache.get(key);
25
19
  if (cachedResult !== undefined) {
26
20
  setResult(cachedResult);
@@ -31,4 +25,3 @@ const useValidationCache = (pluginOptions = {}) => {
31
25
  },
32
26
  };
33
27
  };
34
- exports.useValidationCache = useValidationCache;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/validation-cache",
3
- "version": "4.4.0-alpha-e9434aa.0",
3
+ "version": "4.4.0-alpha-731c100.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-e9434aa.0",
6
+ "@envelop/core": "2.4.0-alpha-731c100.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {