@graphql-mesh/cache-localforage 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf

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.
@@ -1,10 +1,7 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- const utils = require('@graphql-mesh/utils');
6
- const LocalForage = _interopDefault(require('localforage'));
7
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInMemoryLRUDriver = void 0;
4
+ const utils_1 = require("@graphql-mesh/utils");
8
5
  function nextTick() {
9
6
  // Make sure this is scheduled for next tick because LRU Cache is synchronous
10
7
  // This helps for testing multiple Mesh instances pointing to the same cache
@@ -15,7 +12,7 @@ function createInMemoryLRUDriver(ttl) {
15
12
  return {
16
13
  _driver: 'INMEMORY_LRU',
17
14
  _initStorage(options) {
18
- lru = utils.createLruCache(options.size, ttl);
15
+ lru = (0, utils_1.createLruCache)(options.size, ttl);
19
16
  },
20
17
  async getItem(key, callback) {
21
18
  try {
@@ -144,38 +141,4 @@ function createInMemoryLRUDriver(ttl) {
144
141
  },
145
142
  };
146
143
  }
147
-
148
- LocalForage.defineDriver(createInMemoryLRUDriver()).catch(err => console.error('Failed at defining InMemoryLRU driver', err));
149
- class LocalforageCache {
150
- constructor(config) {
151
- const driverNames = (config === null || config === void 0 ? void 0 : config.driver) || ['INDEXEDDB', 'WEBSQL', 'LOCALSTORAGE', 'INMEMORY_LRU'];
152
- this.localforage = LocalForage.createInstance({
153
- name: (config === null || config === void 0 ? void 0 : config.name) || 'graphql-mesh-cache',
154
- storeName: (config === null || config === void 0 ? void 0 : config.storeName) || 'graphql-mesh-cache-store',
155
- driver: driverNames.map(driverName => { var _a; return (_a = LocalForage[driverName]) !== null && _a !== void 0 ? _a : driverName; }),
156
- });
157
- }
158
- async get(key) {
159
- const expiresAt = await this.localforage.getItem(`${key}.expiresAt`);
160
- if (expiresAt && Date.now() > expiresAt) {
161
- await this.localforage.removeItem(key);
162
- }
163
- return this.localforage.getItem(key.toString());
164
- }
165
- async getKeysByPrefix(prefix) {
166
- const keys = await this.localforage.keys();
167
- return keys.filter(key => key.startsWith(prefix));
168
- }
169
- async set(key, value, options) {
170
- const jobs = [this.localforage.setItem(key, value)];
171
- if (options === null || options === void 0 ? void 0 : options.ttl) {
172
- jobs.push(this.localforage.setItem(`${key}.expiresAt`, Date.now() + options.ttl * 1000));
173
- }
174
- await Promise.all(jobs);
175
- }
176
- delete(key) {
177
- return this.localforage.removeItem(key);
178
- }
179
- }
180
-
181
- module.exports = LocalforageCache;
144
+ exports.createInMemoryLRUDriver = createInMemoryLRUDriver;
package/cjs/index.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const localforage_1 = tslib_1.__importDefault(require("localforage"));
5
+ const InMemoryLRUDriver_js_1 = require("./InMemoryLRUDriver.js");
6
+ localforage_1.default.defineDriver((0, InMemoryLRUDriver_js_1.createInMemoryLRUDriver)()).catch(err => console.error('Failed at defining InMemoryLRU driver', err));
7
+ class LocalforageCache {
8
+ constructor(config) {
9
+ const driverNames = (config === null || config === void 0 ? void 0 : config.driver) || ['INDEXEDDB', 'WEBSQL', 'LOCALSTORAGE', 'INMEMORY_LRU'];
10
+ this.localforage = localforage_1.default.createInstance({
11
+ name: (config === null || config === void 0 ? void 0 : config.name) || 'graphql-mesh-cache',
12
+ storeName: (config === null || config === void 0 ? void 0 : config.storeName) || 'graphql-mesh-cache-store',
13
+ // @ts-expect-error - Weird error
14
+ driver: driverNames.map(driverName => { var _a; return (_a = localforage_1.default[driverName]) !== null && _a !== void 0 ? _a : driverName; }),
15
+ size: config === null || config === void 0 ? void 0 : config.size,
16
+ version: config === null || config === void 0 ? void 0 : config.version,
17
+ description: config === null || config === void 0 ? void 0 : config.description,
18
+ });
19
+ }
20
+ async get(key) {
21
+ const expiresAt = await this.localforage.getItem(`${key}.expiresAt`);
22
+ if (expiresAt && Date.now() > expiresAt) {
23
+ await this.localforage.removeItem(key);
24
+ }
25
+ return this.localforage.getItem(key.toString());
26
+ }
27
+ async getKeysByPrefix(prefix) {
28
+ const keys = await this.localforage.keys();
29
+ return keys.filter(key => key.startsWith(prefix));
30
+ }
31
+ async set(key, value, options) {
32
+ const jobs = [this.localforage.setItem(key, value)];
33
+ if (options === null || options === void 0 ? void 0 : options.ttl) {
34
+ jobs.push(this.localforage.setItem(`${key}.expiresAt`, Date.now() + options.ttl * 1000));
35
+ }
36
+ await Promise.all(jobs);
37
+ }
38
+ delete(key) {
39
+ return this.localforage.removeItem(key);
40
+ }
41
+ }
42
+ exports.default = LocalforageCache;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,12 +1,10 @@
1
1
  import { createLruCache } from '@graphql-mesh/utils';
2
- import LocalForage from 'localforage';
3
-
4
2
  function nextTick() {
5
3
  // Make sure this is scheduled for next tick because LRU Cache is synchronous
6
4
  // This helps for testing multiple Mesh instances pointing to the same cache
7
5
  return new Promise(resolve => setTimeout(resolve));
8
6
  }
9
- function createInMemoryLRUDriver(ttl) {
7
+ export function createInMemoryLRUDriver(ttl) {
10
8
  let lru;
11
9
  return {
12
10
  _driver: 'INMEMORY_LRU',
@@ -140,38 +138,3 @@ function createInMemoryLRUDriver(ttl) {
140
138
  },
141
139
  };
142
140
  }
143
-
144
- LocalForage.defineDriver(createInMemoryLRUDriver()).catch(err => console.error('Failed at defining InMemoryLRU driver', err));
145
- class LocalforageCache {
146
- constructor(config) {
147
- const driverNames = (config === null || config === void 0 ? void 0 : config.driver) || ['INDEXEDDB', 'WEBSQL', 'LOCALSTORAGE', 'INMEMORY_LRU'];
148
- this.localforage = LocalForage.createInstance({
149
- name: (config === null || config === void 0 ? void 0 : config.name) || 'graphql-mesh-cache',
150
- storeName: (config === null || config === void 0 ? void 0 : config.storeName) || 'graphql-mesh-cache-store',
151
- driver: driverNames.map(driverName => { var _a; return (_a = LocalForage[driverName]) !== null && _a !== void 0 ? _a : driverName; }),
152
- });
153
- }
154
- async get(key) {
155
- const expiresAt = await this.localforage.getItem(`${key}.expiresAt`);
156
- if (expiresAt && Date.now() > expiresAt) {
157
- await this.localforage.removeItem(key);
158
- }
159
- return this.localforage.getItem(key.toString());
160
- }
161
- async getKeysByPrefix(prefix) {
162
- const keys = await this.localforage.keys();
163
- return keys.filter(key => key.startsWith(prefix));
164
- }
165
- async set(key, value, options) {
166
- const jobs = [this.localforage.setItem(key, value)];
167
- if (options === null || options === void 0 ? void 0 : options.ttl) {
168
- jobs.push(this.localforage.setItem(`${key}.expiresAt`, Date.now() + options.ttl * 1000));
169
- }
170
- await Promise.all(jobs);
171
- }
172
- delete(key) {
173
- return this.localforage.removeItem(key);
174
- }
175
- }
176
-
177
- export default LocalforageCache;
package/esm/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import LocalForage from 'localforage';
2
+ import { createInMemoryLRUDriver } from './InMemoryLRUDriver.js';
3
+ LocalForage.defineDriver(createInMemoryLRUDriver()).catch(err => console.error('Failed at defining InMemoryLRU driver', err));
4
+ export default class LocalforageCache {
5
+ constructor(config) {
6
+ const driverNames = (config === null || config === void 0 ? void 0 : config.driver) || ['INDEXEDDB', 'WEBSQL', 'LOCALSTORAGE', 'INMEMORY_LRU'];
7
+ this.localforage = LocalForage.createInstance({
8
+ name: (config === null || config === void 0 ? void 0 : config.name) || 'graphql-mesh-cache',
9
+ storeName: (config === null || config === void 0 ? void 0 : config.storeName) || 'graphql-mesh-cache-store',
10
+ // @ts-expect-error - Weird error
11
+ driver: driverNames.map(driverName => { var _a; return (_a = LocalForage[driverName]) !== null && _a !== void 0 ? _a : driverName; }),
12
+ size: config === null || config === void 0 ? void 0 : config.size,
13
+ version: config === null || config === void 0 ? void 0 : config.version,
14
+ description: config === null || config === void 0 ? void 0 : config.description,
15
+ });
16
+ }
17
+ async get(key) {
18
+ const expiresAt = await this.localforage.getItem(`${key}.expiresAt`);
19
+ if (expiresAt && Date.now() > expiresAt) {
20
+ await this.localforage.removeItem(key);
21
+ }
22
+ return this.localforage.getItem(key.toString());
23
+ }
24
+ async getKeysByPrefix(prefix) {
25
+ const keys = await this.localforage.keys();
26
+ return keys.filter(key => key.startsWith(prefix));
27
+ }
28
+ async set(key, value, options) {
29
+ const jobs = [this.localforage.setItem(key, value)];
30
+ if (options === null || options === void 0 ? void 0 : options.ttl) {
31
+ jobs.push(this.localforage.setItem(`${key}.expiresAt`, Date.now() + options.ttl * 1000));
32
+ }
33
+ await Promise.all(jobs);
34
+ }
35
+ delete(key) {
36
+ return this.localforage.removeItem(key);
37
+ }
38
+ }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-mesh/cache-localforage",
3
- "version": "1.0.0-alpha-20220804093904-8e2e41f7f",
3
+ "version": "1.0.0-alpha-20230420220344-25b6b92bf",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-20220804093904-8e2e41f7f",
7
- "@graphql-mesh/utils": "1.0.0-alpha-20220804093904-8e2e41f7f",
8
- "graphql": "*"
6
+ "@graphql-mesh/types": "1.0.0-alpha-20230420220344-25b6b92bf",
7
+ "@graphql-mesh/utils": "1.0.0-alpha-20230420220344-25b6b92bf",
8
+ "graphql": "*",
9
+ "tslib": "^2.4.0"
9
10
  },
10
11
  "dependencies": {
11
- "localforage": "1.10.0",
12
- "tslib": "^2.4.0"
12
+ "localforage": "1.10.0"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -17,21 +17,28 @@
17
17
  "directory": "packages/cache/localforage"
18
18
  },
19
19
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
22
- "typings": "index.d.ts",
20
+ "main": "cjs/index.js",
21
+ "module": "esm/index.js",
22
+ "typings": "typings/index.d.ts",
23
23
  "typescript": {
24
- "definition": "index.d.ts"
24
+ "definition": "typings/index.d.ts"
25
25
  },
26
+ "type": "module",
26
27
  "exports": {
27
28
  ".": {
28
- "require": "./index.js",
29
- "import": "./index.mjs"
30
- },
31
- "./*": {
32
- "require": "./*.js",
33
- "import": "./*.mjs"
29
+ "require": {
30
+ "types": "./typings/index.d.cts",
31
+ "default": "./cjs/index.js"
32
+ },
33
+ "import": {
34
+ "types": "./typings/index.d.ts",
35
+ "default": "./esm/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./typings/index.d.ts",
39
+ "default": "./esm/index.js"
40
+ }
34
41
  },
35
42
  "./package.json": "./package.json"
36
43
  }
37
- }
44
+ }
@@ -0,0 +1 @@
1
+ export declare function createInMemoryLRUDriver(ttl?: number): LocalForageDriver;
@@ -0,0 +1,9 @@
1
+ import { KeyValueCache, KeyValueCacheSetOptions, YamlConfig } from '@graphql-mesh/types';
2
+ export default class LocalforageCache<V = any> implements KeyValueCache<V> {
3
+ private localforage;
4
+ constructor(config?: YamlConfig.LocalforageConfig);
5
+ get(key: string): Promise<V>;
6
+ getKeysByPrefix(prefix: string): Promise<string[]>;
7
+ set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise<void>;
8
+ delete(key: string): Promise<void>;
9
+ }
File without changes