@envelop/parser-cache 4.3.1 → 4.4.0-alpha-35741fe.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,22 +2,16 @@
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; }
5
+ const core = require('@envelop/core');
6
6
 
7
- const graphql = require('graphql');
8
- const lru = _interopDefault(require('tiny-lru'));
9
-
10
- const DEFAULT_MAX = 1000;
11
- const DEFAULT_TTL = 3600000;
12
7
  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);
8
+ const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : core.getInMemoryLRUCache();
9
+ const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : core.getInMemoryLRUCache();
17
10
  return {
18
11
  onParse({ params, setParsedDocument }) {
12
+ var _a;
19
13
  const { source } = params;
20
- const key = source instanceof graphql.Source ? source.body : source;
14
+ const key = core.isSourceObject(source) ? source.body : (_a = params.source) === null || _a === void 0 ? void 0 : _a.toString();
21
15
  const cachedError = errorCache.get(key);
22
16
  if (cachedError !== undefined) {
23
17
  throw cachedError;
@@ -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,17 +1,13 @@
1
- import { Source } from 'graphql';
2
- import lru from 'tiny-lru';
1
+ import { getInMemoryLRUCache, isSourceObject } from '@envelop/core';
3
2
 
4
- const DEFAULT_MAX = 1000;
5
- const DEFAULT_TTL = 3600000;
6
3
  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);
4
+ const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : getInMemoryLRUCache();
5
+ const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : getInMemoryLRUCache();
11
6
  return {
12
7
  onParse({ params, setParsedDocument }) {
8
+ var _a;
13
9
  const { source } = params;
14
- const key = source instanceof Source ? source.body : source;
10
+ const key = isSourceObject(source) ? source.body : (_a = params.source) === null || _a === void 0 ? void 0 : _a.toString();
15
11
  const cachedError = errorCache.get(key);
16
12
  if (cachedError !== undefined) {
17
13
  throw cachedError;
@@ -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.1",
3
+ "version": "4.4.0-alpha-35741fe.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^2.3.1",
6
+ "@envelop/core": "2.4.0-alpha-35741fe.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",