@envelop/parser-cache 4.3.0 → 4.4.0-alpha-0969daf.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/index.d.ts CHANGED
@@ -1,14 +1,9 @@
1
- import { Plugin } from '@envelop/core';
1
+ import { Plugin, BasicCache } from '@envelop/core';
2
2
  import { DocumentNode } from 'graphql';
3
- interface Cache<T> {
4
- get(key: string): T | undefined;
5
- set(key: string, value: T): void;
6
- }
7
- export declare type DocumentCache = Cache<DocumentNode>;
8
- export declare type ErrorCache = Cache<Error>;
3
+ export declare type DocumentCache = BasicCache<DocumentNode>;
4
+ export declare type ErrorCache = BasicCache<Error>;
9
5
  export declare type ParserCacheOptions = {
10
6
  documentCache?: DocumentCache;
11
7
  errorCache?: ErrorCache;
12
8
  };
13
9
  export declare const useParserCache: (pluginOptions?: ParserCacheOptions) => Plugin;
14
- export {};
package/index.js CHANGED
@@ -2,18 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
5
+ const core = require('@envelop/core');
7
6
  const graphql = require('graphql');
8
- const lru = _interopDefault(require('tiny-lru'));
9
7
 
10
- const DEFAULT_MAX = 1000;
11
- const DEFAULT_TTL = 3600000;
12
8
  const useParserCache = (pluginOptions = {}) => {
13
- const documentCache = typeof pluginOptions.documentCache !== 'undefined'
14
- ? pluginOptions.documentCache
15
- : lru(DEFAULT_MAX, DEFAULT_TTL);
16
- const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : lru(DEFAULT_MAX, DEFAULT_TTL);
9
+ const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : core.getInMemoryLRUCache();
10
+ const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : core.getInMemoryLRUCache();
17
11
  return {
18
12
  onParse({ params, setParsedDocument }) {
19
13
  const { source } = params;
@@ -25,6 +19,7 @@ const useParserCache = (pluginOptions = {}) => {
25
19
  const cachedDocument = documentCache.get(key);
26
20
  if (cachedDocument !== undefined) {
27
21
  setParsedDocument(cachedDocument);
22
+ return;
28
23
  }
29
24
  return ({ result }) => {
30
25
  if (result instanceof Error) {
package/index.mjs CHANGED
@@ -1,13 +1,9 @@
1
+ import { getInMemoryLRUCache } from '@envelop/core';
1
2
  import { Source } from 'graphql';
2
- import lru from 'tiny-lru';
3
3
 
4
- const DEFAULT_MAX = 1000;
5
- const DEFAULT_TTL = 3600000;
6
4
  const useParserCache = (pluginOptions = {}) => {
7
- const documentCache = typeof pluginOptions.documentCache !== 'undefined'
8
- ? pluginOptions.documentCache
9
- : lru(DEFAULT_MAX, DEFAULT_TTL);
10
- const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : lru(DEFAULT_MAX, DEFAULT_TTL);
5
+ const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : getInMemoryLRUCache();
6
+ const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : getInMemoryLRUCache();
11
7
  return {
12
8
  onParse({ params, setParsedDocument }) {
13
9
  const { source } = params;
@@ -19,6 +15,7 @@ const useParserCache = (pluginOptions = {}) => {
19
15
  const cachedDocument = documentCache.get(key);
20
16
  if (cachedDocument !== undefined) {
21
17
  setParsedDocument(cachedDocument);
18
+ return;
22
19
  }
23
20
  return ({ result }) => {
24
21
  if (result instanceof Error) {
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@envelop/parser-cache",
3
- "version": "4.3.0",
3
+ "version": "4.4.0-alpha-0969daf.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^2.3.0",
6
+ "@envelop/core": "2.4.0-alpha-0969daf.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
- "dependencies": {
10
- "tiny-lru": "7.0.6"
11
- },
12
9
  "repository": {
13
10
  "type": "git",
14
11
  "url": "https://github.com/dotansimha/envelop.git",