@checkdigit/memoize 3.1.0 → 4.0.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/LICENSE.txt +2 -2
- package/README.md +1 -1
- package/SECURITY.md +3 -2
- package/dist-mjs/memoize.mjs +6 -2
- package/package.json +12 -13
- package/src/index.ts +1 -1
- package/src/memoize.ts +8 -5
package/LICENSE.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
The MIT License
|
|
3
3
|
|
|
4
|
-
Copyright (c) 2023-
|
|
4
|
+
Copyright (c) 2023-2026 Check Digit, LLC
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
19
19
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
20
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
21
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
-
THE SOFTWARE.
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Memoize
|
|
2
2
|
|
|
3
|
-
Copyright
|
|
3
|
+
Copyright © 2023-2026 [Check Digit, LLC](https://checkdigit.com)
|
|
4
4
|
|
|
5
5
|
`@checkdigit/memoize` memoizes async functions, with cache eviction on reject.
|
|
6
6
|
The resulting promise is cached, guaranteeing the underlying function is called at most once for a given set of
|
package/SECURITY.md
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Supported Versions
|
|
4
4
|
|
|
5
|
-
These versions of
|
|
5
|
+
These versions of `@checkdigit/memoize` are currently being supported with security updates.
|
|
6
6
|
|
|
7
7
|
| Version | Supported |
|
|
8
8
|
| ------- | ------------------ |
|
|
9
|
-
| \>=
|
|
9
|
+
| \>= 4.0 | :white_check_mark: |
|
|
10
|
+
| \< 4.0 | :x: |
|
|
10
11
|
|
|
11
12
|
## Reporting a Vulnerability
|
|
12
13
|
|
package/dist-mjs/memoize.mjs
CHANGED
|
@@ -44,7 +44,11 @@ var memoize_default = (memoizableFunction) => {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const cacheKey = JSON.stringify(
|
|
47
|
+
const cacheKey = JSON.stringify(
|
|
48
|
+
JSON.parse(converted),
|
|
49
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort, unicorn/require-array-sort-compare -- preserve the default UTF-16 code-unit ordering
|
|
50
|
+
[...keys].toSorted()
|
|
51
|
+
);
|
|
48
52
|
let value = cache.get(cacheKey);
|
|
49
53
|
if (value === void 0) {
|
|
50
54
|
value = memoizableFunction(...argumentList);
|
|
@@ -59,4 +63,4 @@ var memoize_default = (memoizableFunction) => {
|
|
|
59
63
|
export {
|
|
60
64
|
memoize_default as default
|
|
61
65
|
};
|
|
62
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
66
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBZ0NBLElBQU8sa0JBQVEsQ0FDYix1QkFDMEM7QUFDMUMsUUFBTSxRQUFRLG9CQUFJLElBQTZCO0FBQy9DLFFBQU0sVUFBVSxvQkFBSSxJQUFvQjtBQUl4QyxRQUFNLE9BQU8sT0FBTyxXQUFXO0FBRS9CLFNBQU8sSUFBSSxpQkFBaUI7QUFDMUIsVUFBTSxPQUFPLG9CQUFJLElBQVk7QUFFN0IsVUFBTSxZQUFZLEtBQUssVUFBVSxjQUFjLENBQ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UE7QUFBQSxNQUVwQixDQUFDLEdBQUcsSUFBSSxFQUFFLFNBQVM7QUFBQSxJQUNyQjtBQUVBLFFBQUksUUFBUSxNQUFNLElBQUksUUFBUTtBQUM5QixRQUFJLFVBQVUsUUFBVztBQUN2QixjQUFRLG1CQUFtQixHQUFHLFlBQVk7QUFDMUMsWUFBTSxJQUFJLFVBQVUsS0FBSztBQUV6QixZQUFNLE1BQU0sTUFBTTtBQUVoQixjQUFNLE9BQU8sUUFBUTtBQUFBLE1BQ3ZCLENBQUM7QUFBQSxJQUNIO0FBQ0EsV0FBTztBQUFBLEVBQ1Q7QUFDRjsiLAogICJuYW1lcyI6IFsidmFsdWUiXQp9Cg==
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkdigit/memoize",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Memoizing async functions with cache eviction on reject",
|
|
5
5
|
"homepage": "https://github.com/checkdigit/memoize#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,29 +34,28 @@
|
|
|
34
34
|
"SECURITY.md"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build:dist-mjs": "
|
|
38
|
-
"build:dist-types": "
|
|
37
|
+
"build:dist-mjs": "node -e \"require('node:fs').rmSync('dist-mjs', { recursive: true, force: true })\" && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
38
|
+
"build:dist-types": "node -e \"require('node:fs').rmSync('dist-types', { recursive: true, force: true })\" && npx builder --type=types --outDir=dist-types",
|
|
39
39
|
"ci:compile": "tsc --noEmit",
|
|
40
|
-
"ci:coverage": "
|
|
40
|
+
"ci:coverage": "node -e \"const fs = require('node:fs'); fs.rmSync('coverage', { recursive: true, force: true }); fs.mkdirSync('coverage')\" && node --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"",
|
|
41
41
|
"ci:lint": "npm run lint",
|
|
42
42
|
"ci:style": "npm run prettier",
|
|
43
|
-
"ci:test": "node --
|
|
44
|
-
"coverage": "node --
|
|
43
|
+
"ci:test": "node --pending-deprecation --throw-deprecation --test-timeout 600000 --test \"src/**/*.spec.ts\"",
|
|
44
|
+
"coverage": "node --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"",
|
|
45
45
|
"lint": "eslint --max-warnings 0 .",
|
|
46
46
|
"lint:fix": "eslint . --fix",
|
|
47
47
|
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
48
|
-
"prettier": "prettier
|
|
49
|
-
"prettier:fix": "prettier
|
|
48
|
+
"prettier": "prettier . --check",
|
|
49
|
+
"prettier:fix": "prettier . --write",
|
|
50
50
|
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
|
|
51
51
|
},
|
|
52
52
|
"prettier": "@checkdigit/prettier-config",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@checkdigit/eslint-config": "^
|
|
55
|
-
"@checkdigit/prettier-config": "^
|
|
56
|
-
"@checkdigit/typescript-config": "^
|
|
57
|
-
"rimraf": "^6.0.1"
|
|
54
|
+
"@checkdigit/eslint-config": "^12.1.0",
|
|
55
|
+
"@checkdigit/prettier-config": "^8.1.1",
|
|
56
|
+
"@checkdigit/typescript-config": "^10.2.1"
|
|
58
57
|
},
|
|
59
58
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
59
|
+
"node": ">=24.18.0"
|
|
61
60
|
}
|
|
62
61
|
}
|
package/src/index.ts
CHANGED
package/src/memoize.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// memoize.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2023-
|
|
4
|
+
* Copyright (c) 2023-2026 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
@@ -41,7 +41,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
41
41
|
const seed = crypto.randomUUID();
|
|
42
42
|
|
|
43
43
|
return (...argumentList) => {
|
|
44
|
-
const keys = new Set<string
|
|
44
|
+
const keys = new Set<string>();
|
|
45
45
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
46
46
|
const converted = JSON.stringify(argumentList, (key, value: Argument) => {
|
|
47
47
|
// create a set of all object keys used in the argument list
|
|
@@ -95,14 +95,17 @@ export default <Arguments extends Argument[], Return>(
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
// create a cache key so that e.g. [{ a: 1, b: 2 }] and [{ b: 2, a: 1 }] map to the same cache entry
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const cacheKey = JSON.stringify(
|
|
99
|
+
JSON.parse(converted),
|
|
100
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort, unicorn/require-array-sort-compare -- preserve the default UTF-16 code-unit ordering
|
|
101
|
+
[...keys].toSorted(),
|
|
102
|
+
);
|
|
100
103
|
|
|
101
104
|
let value = cache.get(cacheKey);
|
|
102
105
|
if (value === undefined) {
|
|
103
106
|
value = memoizableFunction(...argumentList);
|
|
104
107
|
cache.set(cacheKey, value);
|
|
105
|
-
// eslint-disable-next-line @checkdigit/no-promise-instance-method
|
|
108
|
+
// eslint-disable-next-line @checkdigit/no-promise-instance-method, unicorn/prefer-await -- preserve the cached promise's identity
|
|
106
109
|
value.catch(() => {
|
|
107
110
|
// on a reject, evict key from cache
|
|
108
111
|
cache.delete(cacheKey);
|