@graffy/cache 0.16.19 → 0.16.20-alpha.10

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 (3) hide show
  1. package/index.cjs +9 -18
  2. package/index.mjs +9 -18
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -22,29 +22,23 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
22
22
  common.merge(state, result);
23
23
  }
24
24
  store.on("read", [], async (query, options, next) => {
25
- if (options.skipCache)
26
- return next(query);
25
+ if (options.skipCache) return next(query);
27
26
  const earliest = Date.now() - maxAge;
28
27
  const result = [];
29
28
  let miss = false;
30
29
  if (optimisticState.length) {
31
30
  const { known, unknown } = common.slice(optimisticState, query);
32
- if (known)
33
- common.merge(result, known);
34
- if (!unknown)
35
- return result;
31
+ if (known) common.merge(result, known);
32
+ if (!unknown) return result;
36
33
  query = unknown;
37
34
  }
38
35
  for (let i = 0; i < layers.length; i++) {
39
36
  const [fetchTime, state] = layers[i];
40
- if (fetchTime < earliest)
41
- break;
37
+ if (fetchTime < earliest) break;
42
38
  const { known, unknown } = common.slice(state, query);
43
- if (known)
44
- common.merge(result, known);
39
+ if (known) common.merge(result, known);
45
40
  query = unknown;
46
- if (!query)
47
- break;
41
+ if (!query) break;
48
42
  miss = true;
49
43
  }
50
44
  if (query) {
@@ -52,14 +46,12 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
52
46
  const nextValue = await next(query);
53
47
  common.merge(result, nextValue);
54
48
  }
55
- if (miss)
56
- addToCache(result);
49
+ if (miss) addToCache(result);
57
50
  return result;
58
51
  });
59
52
  store.on("watch", [], (query, options, next) => {
60
53
  const nextStream = next(query);
61
- if (options.skipCache)
62
- return nextStream;
54
+ if (options.skipCache) return nextStream;
63
55
  const optiStream = watcher.watch([]);
64
56
  const nextStreamCopy = stream.mapStream(nextStream, (change) => {
65
57
  addToCache(change);
@@ -68,8 +60,7 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
68
60
  return common.mergeStreams(optiStream, nextStreamCopy);
69
61
  });
70
62
  store.on("write", [], async (change, options, next) => {
71
- if (!options.optimism)
72
- return next(change);
63
+ if (!options.optimism) return next(change);
73
64
  optimisticChanges.add(change);
74
65
  common.merge(optimisticState, change);
75
66
  watcher.write(change);
package/index.mjs CHANGED
@@ -21,29 +21,23 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
21
21
  merge(state, result);
22
22
  }
23
23
  store.on("read", [], async (query, options, next) => {
24
- if (options.skipCache)
25
- return next(query);
24
+ if (options.skipCache) return next(query);
26
25
  const earliest = Date.now() - maxAge;
27
26
  const result = [];
28
27
  let miss = false;
29
28
  if (optimisticState.length) {
30
29
  const { known, unknown } = slice(optimisticState, query);
31
- if (known)
32
- merge(result, known);
33
- if (!unknown)
34
- return result;
30
+ if (known) merge(result, known);
31
+ if (!unknown) return result;
35
32
  query = unknown;
36
33
  }
37
34
  for (let i = 0; i < layers.length; i++) {
38
35
  const [fetchTime, state] = layers[i];
39
- if (fetchTime < earliest)
40
- break;
36
+ if (fetchTime < earliest) break;
41
37
  const { known, unknown } = slice(state, query);
42
- if (known)
43
- merge(result, known);
38
+ if (known) merge(result, known);
44
39
  query = unknown;
45
- if (!query)
46
- break;
40
+ if (!query) break;
47
41
  miss = true;
48
42
  }
49
43
  if (query) {
@@ -51,14 +45,12 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
51
45
  const nextValue = await next(query);
52
46
  merge(result, nextValue);
53
47
  }
54
- if (miss)
55
- addToCache(result);
48
+ if (miss) addToCache(result);
56
49
  return result;
57
50
  });
58
51
  store.on("watch", [], (query, options, next) => {
59
52
  const nextStream = next(query);
60
- if (options.skipCache)
61
- return nextStream;
53
+ if (options.skipCache) return nextStream;
62
54
  const optiStream = watcher.watch([]);
63
55
  const nextStreamCopy = mapStream(nextStream, (change) => {
64
56
  addToCache(change);
@@ -67,8 +59,7 @@ function index({ maxAge = DEFAULT_MAX_AGE } = {}) {
67
59
  return mergeStreams(optiStream, nextStreamCopy);
68
60
  });
69
61
  store.on("write", [], async (change, options, next) => {
70
- if (!options.optimism)
71
- return next(change);
62
+ if (!options.optimism) return next(change);
72
63
  optimisticChanges.add(change);
73
64
  merge(optimisticState, change);
74
65
  watcher.write(change);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/cache",
3
3
  "description": "Graffy module providing in-memory caching.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.19",
5
+ "version": "0.16.20-alpha.10",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
- "@graffy/common": "0.16.19",
20
- "@graffy/stream": "0.16.19"
19
+ "@graffy/common": "0.16.20-alpha.10",
20
+ "@graffy/stream": "0.16.20-alpha.10"
21
21
  }
22
22
  }