@gorgonjs/gorgon 1.4.1 → 1.5.1

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/.eslintrc CHANGED
@@ -1,71 +1,29 @@
1
1
  {
2
2
  "rules": {
3
3
  "accessor-pairs": 0,
4
- "array-bracket-spacing": 0,
5
- "arrow-body-style": 0,
6
- "arrow-parens": ["error", "as-needed"],
7
- "arrow-spacing": 0,
8
4
  "block-scoped-var": 0,
9
- "block-spacing": 0,
10
- "brace-style": [
11
- 2,
12
- "1tbs",
13
- {
14
- "allowSingleLine": true
15
- }
16
- ],
17
5
  "callback-return": 0,
18
6
  "camelcase": 2,
19
- "comma-dangle": [
20
- 1,
21
- "always-multiline"
22
- ],
23
- "comma-spacing": 0,
24
- "comma-style": 0,
25
7
  "complexity": 0,
26
- "computed-property-spacing": 0,
27
8
  "consistent-return": 0,
28
9
  "consistent-this": 0,
29
10
  "constructor-super": 0,
30
- "curly": [
31
- 2,
32
- "all"
33
- ],
11
+ "curly": [2, "all"],
34
12
  "default-case": 2,
35
- "dot-location": [
36
- 2,
37
- "property"
38
- ],
13
+ "dot-location": [2, "property"],
39
14
  "dot-notation": 0,
40
15
  "eol-last": 0,
41
16
  "eqeqeq": 2,
42
17
  "func-names": 0,
43
18
  "func-style": 0,
44
- "generator-star-spacing": 0,
45
19
  "global-require": 0,
46
20
  "guard-for-in": 2,
47
21
  "handle-callback-err": 0,
48
22
  "id-length": 0,
49
23
  "id-match": 0,
50
24
  "indent": 0,
51
- "indent-legacy": [
52
- 2,
53
- 2,
54
- {"SwitchCase": 1}
55
- ],
25
+ "indent-legacy": [2, 2, { "SwitchCase": 1 }],
56
26
  "init-declarations": 0,
57
- "key-spacing": [
58
- 2,
59
- {
60
- "beforeColon": false,
61
- "afterColon": true
62
- }
63
- ],
64
- "linebreak-style": [
65
- 2,
66
- "unix"
67
- ],
68
- "lines-around-comment": 0,
69
27
  "max-depth": 0,
70
28
  "max-len": [
71
29
  2,
@@ -87,7 +45,6 @@
87
45
  }
88
46
  ],
89
47
  "new-parens": 0,
90
- "newline-after-var": 2,
91
48
  "no-alert": 0,
92
49
  "no-array-constructor": 2,
93
50
  "no-arrow-condition": 0,
@@ -127,13 +84,9 @@
127
84
  "no-implicit-coercion": 0,
128
85
  "no-implied-eval": 0,
129
86
  "no-inline-comments": 0,
130
- "no-inner-declarations": [
131
- 2,
132
- "functions"
133
- ],
87
+ "no-inner-declarations": [2, "functions"],
134
88
  "no-invalid-regexp": 0,
135
89
  "no-invalid-this": 0,
136
- "no-irregular-whitespace": 0,
137
90
  "no-iterator": 0,
138
91
  "no-label-var": 0,
139
92
  "no-labels": 0,
@@ -142,7 +95,6 @@
142
95
  "no-loop-func": 2,
143
96
  "no-magic-numbers": 0,
144
97
  "no-mixed-requires": 0,
145
- "no-mixed-spaces-and-tabs": 2,
146
98
  "no-multi-spaces": 0,
147
99
  "no-multi-str": 2,
148
100
  "no-multiple-empty-lines": 0,
@@ -174,13 +126,11 @@
174
126
  "no-sequences": 0,
175
127
  "no-shadow": 0,
176
128
  "no-shadow-restricted-names": 0,
177
- "no-spaced-func": 2,
178
129
  "no-sparse-arrays": 0,
179
130
  "no-sync": 0,
180
131
  "no-ternary": 0,
181
132
  "no-this-before-super": 0,
182
133
  "no-throw-literal": 0,
183
- "no-trailing-spaces": 2,
184
134
  "no-undef": 2,
185
135
  "no-undef-init": 0,
186
136
  "no-undefined": 0,
@@ -197,17 +147,9 @@
197
147
  "no-void": 0,
198
148
  "no-warning-comments": 0,
199
149
  "no-with": 2,
200
- "object-curly-spacing": [
201
- 2,
202
- "never"
203
- ],
204
150
  "object-shorthand": 0,
205
151
  "one-var": 0,
206
152
  "operator-assignment": 0,
207
- "operator-linebreak": [
208
- 2,
209
- "after"
210
- ],
211
153
  "padded-blocks": 0,
212
154
  "prefer-arrow-callback": 0,
213
155
  "prefer-const": 1,
@@ -225,30 +167,8 @@
225
167
  "radix": 0,
226
168
  "require-jsdoc": 0,
227
169
  "require-yield": 0,
228
- "semi-spacing": 0,
229
170
  "sort-vars": 0,
230
- "space-after-keywords": 0,
231
- "space-before-blocks": [
232
- 2,
233
- "always"
234
- ],
235
- "space-before-function-paren": [
236
- 2,
237
- "never"
238
- ],
239
- "space-before-keywords": 0,
240
- "space-in-parens": [
241
- 2,
242
- "never"
243
- ],
244
- "space-infix-ops": 2,
245
- "space-return-throw-case": 0,
246
- "space-unary-ops": 0,
247
- "spaced-comment": 0,
248
- "strict": [
249
- 2,
250
- "global"
251
- ],
171
+ "strict": [2, "global"],
252
172
  "use-isnan": 0,
253
173
  "valid-jsdoc": 2,
254
174
  "valid-typeof": 0,
package/CHANGELOG.md CHANGED
@@ -7,16 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.5.0] - 2023-09-11
11
+
12
+ ### Added
13
+
14
+ - Added a hook system to the cache
15
+
10
16
  ## [1.4.0] - 2022-11-19
11
17
 
12
18
  ### Added
19
+
13
20
  - added a file provider at @gorgon/file-provider
21
+
14
22
  ### Fixed
23
+
15
24
  - fixed a bug where when you cached something permanently (false) with the non default cache it would use the default provider
16
25
 
17
26
  ## [1.3.1] - 2022-11-14
18
27
 
19
28
  ### Added
29
+
20
30
  - added more library type support for older require syntax
21
31
 
22
32
  ## [1.3.0] - 2022-11-13
@@ -34,5 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
34
44
  ## [1.2.0] - 2022-11-12
35
45
 
36
46
  ### Added
47
+
37
48
  - initial release to the public; migrated from @mikevalstar/gorgon
38
49
  - code is based off of medusa.js
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Gorgon
2
2
  ![coverage](https://img.shields.io/badge/coverage-97%25-brightgreen)
3
- ![size](https://img.shields.io/badge/size-4.03KB-brightgreen)
4
- ![version](https://img.shields.io/badge/version-1.4.0-blue)
3
+ ![size](https://img.shields.io/badge/size-5.67KB-brightgreen)
4
+ ![version](https://img.shields.io/badge/version-1.5.0-blue)
5
5
  ![license](https://img.shields.io/badge/license-MIT-blue)
6
6
 
7
7
  A typescript async based caching library for node or the browser.
@@ -2,143 +2,162 @@ import { describe, it, expect, afterAll } from 'vitest';
2
2
  import Gorgon from '../index';
3
3
 
4
4
  describe('settings', () => {
5
-
6
5
  afterAll(() => {
7
- Gorgon.settings({debug: false});
6
+ Gorgon.settings({ debug: false });
8
7
  });
9
8
 
10
9
  it('returns default settings', () => {
11
-
12
10
  const retSettigns = Gorgon.settings();
13
11
 
14
12
  expect(retSettigns.debug).toEqual(false);
15
-
16
13
  });
17
14
 
18
15
  it('can set debug mode', () => {
19
-
20
16
  const retSettigns = Gorgon.settings({
21
17
  debug: true,
22
18
  });
23
19
 
24
20
  expect(retSettigns.debug).toEqual(true);
25
-
26
21
  });
27
-
28
22
  });
29
23
 
30
24
  describe('basic storage', () => {
31
-
32
- it('gets the results of a promise', async() => {
33
-
34
- const res = await Gorgon.get('sample1', async() => {
35
- return 'success';
36
- }, 1000);
25
+ it('gets the results of a promise', async () => {
26
+ const res = await Gorgon.get(
27
+ 'sample1',
28
+ async () => {
29
+ return 'success';
30
+ },
31
+ 1000,
32
+ );
37
33
 
38
34
  return expect(res).toEqual('success');
39
-
40
35
  });
41
36
 
42
-
43
- it('returns old value, not new value for promise', async() => {
44
-
45
- const res = await Gorgon.get('sample2', async() => {
46
- return 'success';
47
- }, 1000);
37
+ it('returns old value, not new value for promise', async () => {
38
+ const res = await Gorgon.get(
39
+ 'sample2',
40
+ async () => {
41
+ return 'success';
42
+ },
43
+ 1000,
44
+ );
48
45
 
49
46
  expect(res).toEqual('success');
50
47
 
51
- const res2 = await Gorgon.get('sample2', async() => {
52
- return 'failure';
53
- }, 1000);
48
+ const res2 = await Gorgon.get(
49
+ 'sample2',
50
+ async () => {
51
+ return 'failure';
52
+ },
53
+ 1000,
54
+ );
54
55
 
55
56
  return expect(res2).toEqual('success');
56
-
57
57
  });
58
58
 
59
- it('overwtires the current cache item', async() => {
60
-
61
- const res = await Gorgon.get('sample6', async() => {
62
- return 'success';
63
- }, 1000);
59
+ it('overwtires the current cache item', async () => {
60
+ const res = await Gorgon.get(
61
+ 'sample6',
62
+ async () => {
63
+ return 'success';
64
+ },
65
+ 1000,
66
+ );
64
67
 
65
68
  expect(res).toEqual('success');
66
69
 
67
- const res2 = await Gorgon.overwrite('sample6', async() => {
68
- return 'success2';
69
- }, 1000);
70
-
70
+ const res2 = await Gorgon.overwrite(
71
+ 'sample6',
72
+ async () => {
73
+ return 'success2';
74
+ },
75
+ 1000,
76
+ );
71
77
 
72
78
  expect(res).toEqual('success');
73
79
  expect(res2).toEqual('success2');
74
-
75
80
  });
76
81
 
77
- it('cache expires', async() => {
78
-
79
- const res = await Gorgon.get('sample3', async() => {
80
- return 'failure';
81
- }, 1000);
82
+ it('cache expires', async () => {
83
+ const res = await Gorgon.get(
84
+ 'sample3',
85
+ async () => {
86
+ return 'failure';
87
+ },
88
+ 1000,
89
+ );
82
90
 
83
91
  expect(res).toEqual('failure');
84
92
 
85
93
  // await a time of 1.5 seconds
86
- await new Promise(resolve => setTimeout(resolve, 1500));
94
+ await new Promise((resolve) => setTimeout(resolve, 1500));
87
95
 
88
- const res2 = await Gorgon.get('sample3', async() => {
89
- return 'success';
90
- }, 1000);
96
+ const res2 = await Gorgon.get(
97
+ 'sample3',
98
+ async () => {
99
+ return 'success';
100
+ },
101
+ 1000,
102
+ );
91
103
 
92
104
  expect(res2).toEqual('success');
93
-
94
105
  });
95
106
 
96
-
97
- it('throws and does not cache', async() => {
98
-
107
+ it('throws and does not cache', async () => {
99
108
  try {
100
- const res = await Gorgon.get('sample4', async() => {
101
- throw 'failure';
102
- }, 1000);
103
- }catch(e) {
109
+ const res = await Gorgon.get(
110
+ 'sample4',
111
+ async () => {
112
+ throw 'failure';
113
+ },
114
+ 1000,
115
+ );
116
+ } catch (e) {
104
117
  expect(e).toEqual('failure');
105
118
  }
106
119
 
107
- const res2 = await Gorgon.get('sample4', async() => {
108
- return 'success';
109
- }, 1000);
120
+ const res2 = await Gorgon.get(
121
+ 'sample4',
122
+ async () => {
123
+ return 'success';
124
+ },
125
+ 1000,
126
+ );
110
127
 
111
128
  expect(res2).toEqual('success');
112
-
113
129
  });
114
130
 
115
-
116
- it('clears all cache items', async() => {
117
-
118
- const res = await Gorgon.get('sample5', async() => {
119
- return 'failure';
120
- }, 1000);
131
+ it('clears all cache items', async () => {
132
+ const res = await Gorgon.get(
133
+ 'sample5',
134
+ async () => {
135
+ return 'failure';
136
+ },
137
+ 1000,
138
+ );
121
139
 
122
140
  await Gorgon.clear();
123
141
 
124
- const res2 = await Gorgon.get('sample5', async() => {
125
- return 'success';
126
- }, 1000);
142
+ const res2 = await Gorgon.get(
143
+ 'sample5',
144
+ async () => {
145
+ return 'success';
146
+ },
147
+ 1000,
148
+ );
127
149
 
128
150
  expect(res2).toEqual('success');
129
-
130
151
  });
131
152
 
132
-
133
- it('clears a single item that has a permenant cache', async() => {
134
-
135
- const res = await Gorgon.get('sample9', async() => {
153
+ it('clears a single item that has a permenant cache', async () => {
154
+ const res = await Gorgon.get('sample9', async () => {
136
155
  return 'success';
137
156
  });
138
157
 
139
158
  expect(res).toEqual('success');
140
159
 
141
- const res2 = await Gorgon.get('sample10', async() => {
160
+ const res2 = await Gorgon.get('sample10', async () => {
142
161
  return 'failure';
143
162
  });
144
163
 
@@ -146,18 +165,16 @@ describe('basic storage', () => {
146
165
 
147
166
  await Gorgon.clear('sample10');
148
167
 
149
- const res3 = await Gorgon.get('sample9', async() => {
168
+ const res3 = await Gorgon.get('sample9', async () => {
150
169
  return 'failure';
151
170
  });
152
171
 
153
172
  expect(res3).toEqual('success');
154
173
 
155
- const res4 = await Gorgon.get('sample10', async() => {
174
+ const res4 = await Gorgon.get('sample10', async () => {
156
175
  return 'success2';
157
176
  });
158
177
 
159
178
  expect(res4).toEqual('success2');
160
-
161
179
  });
162
-
163
180
  });
@@ -2,63 +2,90 @@ import { describe, it, expect } from 'vitest';
2
2
  import Gorgon from '../index';
3
3
 
4
4
  describe('Clear many from storage', () => {
5
-
6
- it('clears many based on wildcard', async() => {
7
-
8
- const res = await Gorgon.get('clearmany1', async() => {
9
- return 'success';
10
- }, 1000);
5
+ it('clears many based on wildcard', async () => {
6
+ const res = await Gorgon.get(
7
+ 'clearmany1',
8
+ async () => {
9
+ return 'success';
10
+ },
11
+ 1000,
12
+ );
11
13
 
12
14
  expect(res).toEqual('success');
13
15
 
14
- const res2 = await Gorgon.get('clearmany2', async() => {
15
- return 'success';
16
- }, 1000);
16
+ const res2 = await Gorgon.get(
17
+ 'clearmany2',
18
+ async () => {
19
+ return 'success';
20
+ },
21
+ 1000,
22
+ );
17
23
 
18
24
  expect(res2).toEqual('success');
19
25
 
20
26
  await Gorgon.clear('clearmany*');
21
27
 
22
- const res3 = await Gorgon.get('clearmany1', async() => {
23
- return 'success2';
24
- }, 1000);
28
+ const res3 = await Gorgon.get(
29
+ 'clearmany1',
30
+ async () => {
31
+ return 'success2';
32
+ },
33
+ 1000,
34
+ );
25
35
 
26
36
  expect(res3).toEqual('success2');
27
37
 
28
- const res4 = await Gorgon.get('clearmany2', async() => {
29
- return 'success2';
30
- }, 1000);
38
+ const res4 = await Gorgon.get(
39
+ 'clearmany2',
40
+ async () => {
41
+ return 'success2';
42
+ },
43
+ 1000,
44
+ );
31
45
 
32
46
  expect(res4).toEqual('success2');
33
-
34
-
35
47
  });
36
48
 
37
- it('clears every item in the cache', async() => {
38
-
39
- const res = await Gorgon.get('clearall1', async() => {
40
- return 'success';
41
- }, 1000);
49
+ it('clears every item in the cache', async () => {
50
+ const res = await Gorgon.get(
51
+ 'clearall1',
52
+ async () => {
53
+ return 'success';
54
+ },
55
+ 1000,
56
+ );
42
57
 
43
58
  expect(res).toEqual('success');
44
59
 
45
- const res2 = await Gorgon.get('clearall2', async() => {
46
- return 'success';
47
- }, 1000);
60
+ const res2 = await Gorgon.get(
61
+ 'clearall2',
62
+ async () => {
63
+ return 'success';
64
+ },
65
+ 1000,
66
+ );
48
67
 
49
68
  expect(res2).toEqual('success');
50
69
 
51
70
  await Gorgon.clearAll();
52
71
 
53
- const res3 = await Gorgon.get('clearall1', async() => {
54
- return 'success2';
55
- }, 1000);
72
+ const res3 = await Gorgon.get(
73
+ 'clearall1',
74
+ async () => {
75
+ return 'success2';
76
+ },
77
+ 1000,
78
+ );
56
79
 
57
80
  expect(res3).toEqual('success2');
58
81
 
59
- const res4 = await Gorgon.get('clearall2', async() => {
60
- return 'success2';
61
- }, 1000);
82
+ const res4 = await Gorgon.get(
83
+ 'clearall2',
84
+ async () => {
85
+ return 'success2';
86
+ },
87
+ 1000,
88
+ );
62
89
 
63
90
  expect(res4).toEqual('success2');
64
91
 
@@ -66,7 +93,5 @@ describe('Clear many from storage', () => {
66
93
 
67
94
  const keys = await Gorgon.providers['memory'].keys();
68
95
  expect(keys.length).toEqual(0);
69
-
70
96
  });
71
-
72
97
  });
@@ -1,19 +1,17 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import Gorgon from '../index';
3
3
 
4
- Gorgon.settings({retry: 10});
4
+ Gorgon.settings({ retry: 10 });
5
5
 
6
6
  vi.useRealTimers();
7
7
 
8
8
  describe('concurrency', () => {
9
-
10
- it('Only calls the function once, when the call is slow', async() => {
11
-
9
+ it('Only calls the function once, when the call is slow', async () => {
12
10
  let calledCount = 0;
13
11
 
14
- const incrementor = async() => {
12
+ const incrementor = async () => {
15
13
  return new Promise((resolve: (value: boolean) => void) => {
16
- setTimeout(()=> {
14
+ setTimeout(() => {
17
15
  calledCount += 1;
18
16
  resolve(true);
19
17
  }, 200);
@@ -24,33 +22,29 @@ describe('concurrency', () => {
24
22
  const res2 = await Gorgon.get('concur1', incrementor, 50);
25
23
 
26
24
  return expect(calledCount).toEqual(1);
27
-
28
25
  });
29
26
 
30
- it('Only calls the function once, but rejects both', async() => {
31
-
27
+ it('Only calls the function once, but rejects both', async () => {
32
28
  let calledCount = 0;
33
29
 
34
- const incrementor = async() => {
30
+ const incrementor = async () => {
35
31
  return new Promise((resolve, rej) => {
36
- setTimeout(()=> {
32
+ setTimeout(() => {
37
33
  calledCount += 1;
38
34
  rej(true);
39
35
  }, 200);
40
36
  });
41
37
  };
42
38
 
43
- try{
44
- const res = Gorgon.get('concur2', incrementor, 50).catch(e => {
39
+ try {
40
+ const res = Gorgon.get('concur2', incrementor, 50).catch((e) => {
45
41
  // error
46
42
  });
47
43
  const res2 = await Gorgon.get('concur2', incrementor, 50);
48
- }catch(e) {
44
+ } catch (e) {
49
45
  // error?
50
46
  }
51
47
 
52
48
  return expect(calledCount).toEqual(1);
53
-
54
49
  });
55
-
56
50
  });
@@ -2,19 +2,19 @@ import { describe, it, expect } from 'vitest';
2
2
  import Gorgon from '../index';
3
3
 
4
4
  describe('basic storage - date policy', () => {
5
-
6
- it('gets the results of a promise, Date Policy', async() => {
7
-
5
+ it('gets the results of a promise, Date Policy', async () => {
8
6
  var x = new Date();
9
7
 
10
8
  x = new Date(x.getTime() + 1000 * 1000);
11
9
 
12
- const res = await Gorgon.get('datepolicy1', async() => {
13
- return 'success';
14
- }, x);
10
+ const res = await Gorgon.get(
11
+ 'datepolicy1',
12
+ async () => {
13
+ return 'success';
14
+ },
15
+ x,
16
+ );
15
17
 
16
18
  return expect(res).toEqual('success');
17
-
18
19
  });
19
-
20
20
  });