@gorgonjs/gorgon 1.5.1 → 1.6.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/README.md +2 -2
- package/package.json +18 -5
- package/skills/core/SKILL.md +336 -0
- package/skills/react/SKILL.md +242 -0
- package/.eslintrc +0 -198
- package/CHANGELOG.md +0 -49
- package/__tests__/basic.test.ts +0 -180
- package/__tests__/clearmany.test.ts +0 -97
- package/__tests__/concurrency.test.ts +0 -50
- package/__tests__/datePolicy.test.ts +0 -20
- package/__tests__/debug.test.ts +0 -50
- package/__tests__/hooks.test.ts +0 -181
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -433
- package/coverage/coverage-final.json +0 -3
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -131
- package/coverage/library/index.html +0 -116
- package/coverage/library/index.ts.html +0 -1036
- package/coverage/library/provider/index.html +0 -116
- package/coverage/library/provider/memory.ts.html +0 -379
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/index.ts +0 -317
- package/provider/memory.ts +0 -98
- package/tsconfig.json +0 -11
- package/vite.config.js +0 -19
package/.eslintrc
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"rules": {
|
|
3
|
-
"accessor-pairs": 0,
|
|
4
|
-
"block-scoped-var": 0,
|
|
5
|
-
"callback-return": 0,
|
|
6
|
-
"camelcase": 2,
|
|
7
|
-
"complexity": 0,
|
|
8
|
-
"consistent-return": 0,
|
|
9
|
-
"consistent-this": 0,
|
|
10
|
-
"constructor-super": 0,
|
|
11
|
-
"curly": [2, "all"],
|
|
12
|
-
"default-case": 2,
|
|
13
|
-
"dot-location": [2, "property"],
|
|
14
|
-
"dot-notation": 0,
|
|
15
|
-
"eol-last": 0,
|
|
16
|
-
"eqeqeq": 2,
|
|
17
|
-
"func-names": 0,
|
|
18
|
-
"func-style": 0,
|
|
19
|
-
"global-require": 0,
|
|
20
|
-
"guard-for-in": 2,
|
|
21
|
-
"handle-callback-err": 0,
|
|
22
|
-
"id-length": 0,
|
|
23
|
-
"id-match": 0,
|
|
24
|
-
"indent": 0,
|
|
25
|
-
"indent-legacy": [2, 2, { "SwitchCase": 1 }],
|
|
26
|
-
"init-declarations": 0,
|
|
27
|
-
"max-depth": 0,
|
|
28
|
-
"max-len": [
|
|
29
|
-
2,
|
|
30
|
-
160,
|
|
31
|
-
4,
|
|
32
|
-
{
|
|
33
|
-
"ignoreComments": true,
|
|
34
|
-
"ignoreUrls": true,
|
|
35
|
-
"ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\("
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"max-nested-callbacks": 0,
|
|
39
|
-
"max-params": 0,
|
|
40
|
-
"max-statements": 0,
|
|
41
|
-
"new-cap": [
|
|
42
|
-
2,
|
|
43
|
-
{
|
|
44
|
-
"capIsNew": false
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
"new-parens": 0,
|
|
48
|
-
"no-alert": 0,
|
|
49
|
-
"no-array-constructor": 2,
|
|
50
|
-
"no-arrow-condition": 0,
|
|
51
|
-
"no-bitwise": 0,
|
|
52
|
-
"no-caller": 0,
|
|
53
|
-
"no-case-declarations": 0,
|
|
54
|
-
"no-catch-shadow": 0,
|
|
55
|
-
"no-class-assign": 0,
|
|
56
|
-
"no-cond-assign": 0,
|
|
57
|
-
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
|
|
58
|
-
"no-const-assign": 0,
|
|
59
|
-
"no-constant-condition": 0,
|
|
60
|
-
"no-continue": 0,
|
|
61
|
-
"no-control-regex": 0,
|
|
62
|
-
"no-debugger": 0,
|
|
63
|
-
"no-delete-var": 0,
|
|
64
|
-
"no-div-regex": 0,
|
|
65
|
-
"no-dupe-args": 0,
|
|
66
|
-
"no-dupe-class-members": 0,
|
|
67
|
-
"no-dupe-keys": 0,
|
|
68
|
-
"no-duplicate-case": 0,
|
|
69
|
-
"no-else-return": 0,
|
|
70
|
-
"no-empty": 0,
|
|
71
|
-
"no-empty-character-class": 0,
|
|
72
|
-
"no-empty-label": 0,
|
|
73
|
-
"no-empty-pattern": 0,
|
|
74
|
-
"no-eq-null": 0,
|
|
75
|
-
"no-eval": 2,
|
|
76
|
-
"no-ex-assign": 0,
|
|
77
|
-
"no-extend-native": 2,
|
|
78
|
-
"no-extra-bind": 0,
|
|
79
|
-
"no-extra-boolean-cast": 0,
|
|
80
|
-
"no-extra-parens": 2,
|
|
81
|
-
"no-fallthrough": 0,
|
|
82
|
-
"no-floating-decimal": 0,
|
|
83
|
-
"no-func-assign": 0,
|
|
84
|
-
"no-implicit-coercion": 0,
|
|
85
|
-
"no-implied-eval": 0,
|
|
86
|
-
"no-inline-comments": 0,
|
|
87
|
-
"no-inner-declarations": [2, "functions"],
|
|
88
|
-
"no-invalid-regexp": 0,
|
|
89
|
-
"no-invalid-this": 0,
|
|
90
|
-
"no-iterator": 0,
|
|
91
|
-
"no-label-var": 0,
|
|
92
|
-
"no-labels": 0,
|
|
93
|
-
"no-lone-blocks": 0,
|
|
94
|
-
"no-lonely-if": 0,
|
|
95
|
-
"no-loop-func": 2,
|
|
96
|
-
"no-magic-numbers": 0,
|
|
97
|
-
"no-mixed-requires": 0,
|
|
98
|
-
"no-multi-spaces": 0,
|
|
99
|
-
"no-multi-str": 2,
|
|
100
|
-
"no-multiple-empty-lines": 0,
|
|
101
|
-
"no-native-reassign": 0,
|
|
102
|
-
"no-negated-condition": 0,
|
|
103
|
-
"no-negated-in-lhs": 0,
|
|
104
|
-
"no-nested-ternary": 0,
|
|
105
|
-
"no-new": 0,
|
|
106
|
-
"no-new-func": 0,
|
|
107
|
-
"no-new-object": 2,
|
|
108
|
-
"no-new-require": 0,
|
|
109
|
-
"no-new-wrappers": 0,
|
|
110
|
-
"no-obj-calls": 0,
|
|
111
|
-
"no-octal": 0,
|
|
112
|
-
"no-octal-escape": 0,
|
|
113
|
-
"no-param-reassign": 0,
|
|
114
|
-
"no-path-concat": 0,
|
|
115
|
-
"no-plusplus": 0,
|
|
116
|
-
"no-process-env": 0,
|
|
117
|
-
"no-process-exit": 0,
|
|
118
|
-
"no-proto": 0,
|
|
119
|
-
"no-redeclare": 0,
|
|
120
|
-
"no-regex-spaces": 0,
|
|
121
|
-
"no-restricted-modules": 0,
|
|
122
|
-
"no-restricted-syntax": 0,
|
|
123
|
-
"no-return-assign": 0,
|
|
124
|
-
"no-script-url": 0,
|
|
125
|
-
"no-self-compare": 0,
|
|
126
|
-
"no-sequences": 0,
|
|
127
|
-
"no-shadow": 0,
|
|
128
|
-
"no-shadow-restricted-names": 0,
|
|
129
|
-
"no-sparse-arrays": 0,
|
|
130
|
-
"no-sync": 0,
|
|
131
|
-
"no-ternary": 0,
|
|
132
|
-
"no-this-before-super": 0,
|
|
133
|
-
"no-throw-literal": 0,
|
|
134
|
-
"no-undef": 2,
|
|
135
|
-
"no-undef-init": 0,
|
|
136
|
-
"no-undefined": 0,
|
|
137
|
-
"no-underscore-dangle": 0,
|
|
138
|
-
"no-unexpected-multiline": 0,
|
|
139
|
-
"no-unneeded-ternary": 0,
|
|
140
|
-
"no-unreachable": 0,
|
|
141
|
-
"no-unused-expressions": 0,
|
|
142
|
-
"no-unused-vars": 0,
|
|
143
|
-
"no-use-before-define": 0,
|
|
144
|
-
"no-useless-call": 0,
|
|
145
|
-
"no-useless-concat": 0,
|
|
146
|
-
"no-var": 0,
|
|
147
|
-
"no-void": 0,
|
|
148
|
-
"no-warning-comments": 0,
|
|
149
|
-
"no-with": 2,
|
|
150
|
-
"object-shorthand": 0,
|
|
151
|
-
"one-var": 0,
|
|
152
|
-
"operator-assignment": 0,
|
|
153
|
-
"padded-blocks": 0,
|
|
154
|
-
"prefer-arrow-callback": 0,
|
|
155
|
-
"prefer-const": 1,
|
|
156
|
-
"prefer-reflect": 0,
|
|
157
|
-
"prefer-spread": 0,
|
|
158
|
-
"prefer-template": 0,
|
|
159
|
-
"quote-props": 0,
|
|
160
|
-
"quotes": [
|
|
161
|
-
2,
|
|
162
|
-
"single",
|
|
163
|
-
{
|
|
164
|
-
"allowTemplateLiterals": true
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
"radix": 0,
|
|
168
|
-
"require-jsdoc": 0,
|
|
169
|
-
"require-yield": 0,
|
|
170
|
-
"sort-vars": 0,
|
|
171
|
-
"strict": [2, "global"],
|
|
172
|
-
"use-isnan": 0,
|
|
173
|
-
"valid-jsdoc": 2,
|
|
174
|
-
"valid-typeof": 0,
|
|
175
|
-
"vars-on-top": 0,
|
|
176
|
-
"wrap-iife": 0,
|
|
177
|
-
"wrap-regex": 0,
|
|
178
|
-
"yoda": 0
|
|
179
|
-
},
|
|
180
|
-
"env": {
|
|
181
|
-
"es6": true,
|
|
182
|
-
"es2021": true,
|
|
183
|
-
"browser": true,
|
|
184
|
-
"commonjs": true,
|
|
185
|
-
"node": true,
|
|
186
|
-
"jest": true
|
|
187
|
-
},
|
|
188
|
-
"parserOptions": {
|
|
189
|
-
"ecmaFeatures": {
|
|
190
|
-
"modules": true
|
|
191
|
-
},
|
|
192
|
-
"requireConfigFile": false,
|
|
193
|
-
"sourceType": "module",
|
|
194
|
-
"ecmaVersion": 12
|
|
195
|
-
},
|
|
196
|
-
"parser": "@typescript-eslint/parser",
|
|
197
|
-
"plugins": ["@typescript-eslint"]
|
|
198
|
-
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [Unreleased]
|
|
9
|
-
|
|
10
|
-
## [1.5.0] - 2023-09-11
|
|
11
|
-
|
|
12
|
-
### Added
|
|
13
|
-
|
|
14
|
-
- Added a hook system to the cache
|
|
15
|
-
|
|
16
|
-
## [1.4.0] - 2022-11-19
|
|
17
|
-
|
|
18
|
-
### Added
|
|
19
|
-
|
|
20
|
-
- added a file provider at @gorgon/file-provider
|
|
21
|
-
|
|
22
|
-
### Fixed
|
|
23
|
-
|
|
24
|
-
- fixed a bug where when you cached something permanently (false) with the non default cache it would use the default provider
|
|
25
|
-
|
|
26
|
-
## [1.3.1] - 2022-11-14
|
|
27
|
-
|
|
28
|
-
### Added
|
|
29
|
-
|
|
30
|
-
- added more library type support for older require syntax
|
|
31
|
-
|
|
32
|
-
## [1.3.0] - 2022-11-13
|
|
33
|
-
|
|
34
|
-
### Added
|
|
35
|
-
|
|
36
|
-
- changed build system to get smaller packages
|
|
37
|
-
|
|
38
|
-
## [1.2.1] - 2022-11-13
|
|
39
|
-
|
|
40
|
-
### Fixed
|
|
41
|
-
|
|
42
|
-
- debug now actually outputs some console logs
|
|
43
|
-
|
|
44
|
-
## [1.2.0] - 2022-11-12
|
|
45
|
-
|
|
46
|
-
### Added
|
|
47
|
-
|
|
48
|
-
- initial release to the public; migrated from @mikevalstar/gorgon
|
|
49
|
-
- code is based off of medusa.js
|
package/__tests__/basic.test.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterAll } from 'vitest';
|
|
2
|
-
import Gorgon from '../index';
|
|
3
|
-
|
|
4
|
-
describe('settings', () => {
|
|
5
|
-
afterAll(() => {
|
|
6
|
-
Gorgon.settings({ debug: false });
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('returns default settings', () => {
|
|
10
|
-
const retSettigns = Gorgon.settings();
|
|
11
|
-
|
|
12
|
-
expect(retSettigns.debug).toEqual(false);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('can set debug mode', () => {
|
|
16
|
-
const retSettigns = Gorgon.settings({
|
|
17
|
-
debug: true,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
expect(retSettigns.debug).toEqual(true);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('basic storage', () => {
|
|
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
|
-
);
|
|
33
|
-
|
|
34
|
-
return expect(res).toEqual('success');
|
|
35
|
-
});
|
|
36
|
-
|
|
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
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(res).toEqual('success');
|
|
47
|
-
|
|
48
|
-
const res2 = await Gorgon.get(
|
|
49
|
-
'sample2',
|
|
50
|
-
async () => {
|
|
51
|
-
return 'failure';
|
|
52
|
-
},
|
|
53
|
-
1000,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
return expect(res2).toEqual('success');
|
|
57
|
-
});
|
|
58
|
-
|
|
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
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(res).toEqual('success');
|
|
69
|
-
|
|
70
|
-
const res2 = await Gorgon.overwrite(
|
|
71
|
-
'sample6',
|
|
72
|
-
async () => {
|
|
73
|
-
return 'success2';
|
|
74
|
-
},
|
|
75
|
-
1000,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(res).toEqual('success');
|
|
79
|
-
expect(res2).toEqual('success2');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('cache expires', async () => {
|
|
83
|
-
const res = await Gorgon.get(
|
|
84
|
-
'sample3',
|
|
85
|
-
async () => {
|
|
86
|
-
return 'failure';
|
|
87
|
-
},
|
|
88
|
-
1000,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(res).toEqual('failure');
|
|
92
|
-
|
|
93
|
-
// await a time of 1.5 seconds
|
|
94
|
-
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
95
|
-
|
|
96
|
-
const res2 = await Gorgon.get(
|
|
97
|
-
'sample3',
|
|
98
|
-
async () => {
|
|
99
|
-
return 'success';
|
|
100
|
-
},
|
|
101
|
-
1000,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(res2).toEqual('success');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('throws and does not cache', async () => {
|
|
108
|
-
try {
|
|
109
|
-
const res = await Gorgon.get(
|
|
110
|
-
'sample4',
|
|
111
|
-
async () => {
|
|
112
|
-
throw 'failure';
|
|
113
|
-
},
|
|
114
|
-
1000,
|
|
115
|
-
);
|
|
116
|
-
} catch (e) {
|
|
117
|
-
expect(e).toEqual('failure');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const res2 = await Gorgon.get(
|
|
121
|
-
'sample4',
|
|
122
|
-
async () => {
|
|
123
|
-
return 'success';
|
|
124
|
-
},
|
|
125
|
-
1000,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
expect(res2).toEqual('success');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('clears all cache items', async () => {
|
|
132
|
-
const res = await Gorgon.get(
|
|
133
|
-
'sample5',
|
|
134
|
-
async () => {
|
|
135
|
-
return 'failure';
|
|
136
|
-
},
|
|
137
|
-
1000,
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
await Gorgon.clear();
|
|
141
|
-
|
|
142
|
-
const res2 = await Gorgon.get(
|
|
143
|
-
'sample5',
|
|
144
|
-
async () => {
|
|
145
|
-
return 'success';
|
|
146
|
-
},
|
|
147
|
-
1000,
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
expect(res2).toEqual('success');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('clears a single item that has a permenant cache', async () => {
|
|
154
|
-
const res = await Gorgon.get('sample9', async () => {
|
|
155
|
-
return 'success';
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
expect(res).toEqual('success');
|
|
159
|
-
|
|
160
|
-
const res2 = await Gorgon.get('sample10', async () => {
|
|
161
|
-
return 'failure';
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
expect(res2).toEqual('failure');
|
|
165
|
-
|
|
166
|
-
await Gorgon.clear('sample10');
|
|
167
|
-
|
|
168
|
-
const res3 = await Gorgon.get('sample9', async () => {
|
|
169
|
-
return 'failure';
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
expect(res3).toEqual('success');
|
|
173
|
-
|
|
174
|
-
const res4 = await Gorgon.get('sample10', async () => {
|
|
175
|
-
return 'success2';
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
expect(res4).toEqual('success2');
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import Gorgon from '../index';
|
|
3
|
-
|
|
4
|
-
describe('Clear many from storage', () => {
|
|
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
|
-
);
|
|
13
|
-
|
|
14
|
-
expect(res).toEqual('success');
|
|
15
|
-
|
|
16
|
-
const res2 = await Gorgon.get(
|
|
17
|
-
'clearmany2',
|
|
18
|
-
async () => {
|
|
19
|
-
return 'success';
|
|
20
|
-
},
|
|
21
|
-
1000,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
expect(res2).toEqual('success');
|
|
25
|
-
|
|
26
|
-
await Gorgon.clear('clearmany*');
|
|
27
|
-
|
|
28
|
-
const res3 = await Gorgon.get(
|
|
29
|
-
'clearmany1',
|
|
30
|
-
async () => {
|
|
31
|
-
return 'success2';
|
|
32
|
-
},
|
|
33
|
-
1000,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
expect(res3).toEqual('success2');
|
|
37
|
-
|
|
38
|
-
const res4 = await Gorgon.get(
|
|
39
|
-
'clearmany2',
|
|
40
|
-
async () => {
|
|
41
|
-
return 'success2';
|
|
42
|
-
},
|
|
43
|
-
1000,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(res4).toEqual('success2');
|
|
47
|
-
});
|
|
48
|
-
|
|
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
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(res).toEqual('success');
|
|
59
|
-
|
|
60
|
-
const res2 = await Gorgon.get(
|
|
61
|
-
'clearall2',
|
|
62
|
-
async () => {
|
|
63
|
-
return 'success';
|
|
64
|
-
},
|
|
65
|
-
1000,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(res2).toEqual('success');
|
|
69
|
-
|
|
70
|
-
await Gorgon.clearAll();
|
|
71
|
-
|
|
72
|
-
const res3 = await Gorgon.get(
|
|
73
|
-
'clearall1',
|
|
74
|
-
async () => {
|
|
75
|
-
return 'success2';
|
|
76
|
-
},
|
|
77
|
-
1000,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expect(res3).toEqual('success2');
|
|
81
|
-
|
|
82
|
-
const res4 = await Gorgon.get(
|
|
83
|
-
'clearall2',
|
|
84
|
-
async () => {
|
|
85
|
-
return 'success2';
|
|
86
|
-
},
|
|
87
|
-
1000,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(res4).toEqual('success2');
|
|
91
|
-
|
|
92
|
-
Gorgon.clearAll();
|
|
93
|
-
|
|
94
|
-
const keys = await Gorgon.providers['memory'].keys();
|
|
95
|
-
expect(keys.length).toEqual(0);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import Gorgon from '../index';
|
|
3
|
-
|
|
4
|
-
Gorgon.settings({ retry: 10 });
|
|
5
|
-
|
|
6
|
-
vi.useRealTimers();
|
|
7
|
-
|
|
8
|
-
describe('concurrency', () => {
|
|
9
|
-
it('Only calls the function once, when the call is slow', async () => {
|
|
10
|
-
let calledCount = 0;
|
|
11
|
-
|
|
12
|
-
const incrementor = async () => {
|
|
13
|
-
return new Promise((resolve: (value: boolean) => void) => {
|
|
14
|
-
setTimeout(() => {
|
|
15
|
-
calledCount += 1;
|
|
16
|
-
resolve(true);
|
|
17
|
-
}, 200);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const res = Gorgon.get('concur1', incrementor, 50);
|
|
22
|
-
const res2 = await Gorgon.get('concur1', incrementor, 50);
|
|
23
|
-
|
|
24
|
-
return expect(calledCount).toEqual(1);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('Only calls the function once, but rejects both', async () => {
|
|
28
|
-
let calledCount = 0;
|
|
29
|
-
|
|
30
|
-
const incrementor = async () => {
|
|
31
|
-
return new Promise((resolve, rej) => {
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
calledCount += 1;
|
|
34
|
-
rej(true);
|
|
35
|
-
}, 200);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const res = Gorgon.get('concur2', incrementor, 50).catch((e) => {
|
|
41
|
-
// error
|
|
42
|
-
});
|
|
43
|
-
const res2 = await Gorgon.get('concur2', incrementor, 50);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
// error?
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return expect(calledCount).toEqual(1);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import Gorgon from '../index';
|
|
3
|
-
|
|
4
|
-
describe('basic storage - date policy', () => {
|
|
5
|
-
it('gets the results of a promise, Date Policy', async () => {
|
|
6
|
-
var x = new Date();
|
|
7
|
-
|
|
8
|
-
x = new Date(x.getTime() + 1000 * 1000);
|
|
9
|
-
|
|
10
|
-
const res = await Gorgon.get(
|
|
11
|
-
'datepolicy1',
|
|
12
|
-
async () => {
|
|
13
|
-
return 'success';
|
|
14
|
-
},
|
|
15
|
-
x,
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
return expect(res).toEqual('success');
|
|
19
|
-
});
|
|
20
|
-
});
|
package/__tests__/debug.test.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
|
|
2
|
-
import Gorgon from '../index';
|
|
3
|
-
|
|
4
|
-
describe('basic storage - date policy', () => {
|
|
5
|
-
beforeAll(() => {
|
|
6
|
-
Gorgon.settings({ debug: true });
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
afterAll(() => {
|
|
10
|
-
Gorgon.settings({ debug: false });
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('gets the results of a promise, console.info happens twice', async () => {
|
|
14
|
-
const consoleSpy = vi.spyOn(console, 'info');
|
|
15
|
-
|
|
16
|
-
const res = await Gorgon.get(
|
|
17
|
-
'debug1',
|
|
18
|
-
async () => {
|
|
19
|
-
return 'success';
|
|
20
|
-
},
|
|
21
|
-
1,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
expect(consoleSpy).toHaveBeenCalledTimes(2);
|
|
25
|
-
return expect(consoleSpy).toHaveBeenLastCalledWith('[Gorgon] Cache resolved, resolved item for: debug1', 'success');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('gets the results of a promise, then places a resolver in the queue, console.info happens 4 times', async () => {
|
|
29
|
-
const consoleSpy = vi.spyOn(console, 'info');
|
|
30
|
-
|
|
31
|
-
const res = Gorgon.get(
|
|
32
|
-
'debug2',
|
|
33
|
-
async () => {
|
|
34
|
-
return 'success';
|
|
35
|
-
},
|
|
36
|
-
1000,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const res2 = await Gorgon.get(
|
|
40
|
-
'debug2',
|
|
41
|
-
async () => {
|
|
42
|
-
return 'success';
|
|
43
|
-
},
|
|
44
|
-
1000,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(consoleSpy).toHaveBeenCalledTimes(4);
|
|
48
|
-
return expect(consoleSpy).toHaveBeenLastCalledWith('[Gorgon] Cache queue resolved for: debug2', 'success');
|
|
49
|
-
});
|
|
50
|
-
});
|