@checkdigit/memoize 2.0.0 → 3.0.0-PR.11-c714
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 +1 -1
- package/README.md +5 -5
- package/SECURITY.md +1 -1
- package/dist-mjs/memoize.mjs +1 -1
- package/dist-types/index.d.ts +1 -1
- package/package.json +1 -72
- package/src/index.ts +2 -2
- package/src/memoize.ts +6 -1
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-2025 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
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Memoize
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023–
|
|
3
|
+
Copyright (c) 2023–2025 [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
|
|
@@ -9,15 +9,15 @@ arguments, unless the promise ultimately rejects.
|
|
|
9
9
|
If the promise is rejected, it will be removed from the memoize cache.
|
|
10
10
|
This allows the function to be retried.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Install
|
|
13
13
|
|
|
14
|
-
```
|
|
14
|
+
```shell
|
|
15
15
|
$ npm install @checkdigit/memoize
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Use
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```ts
|
|
21
21
|
import memoize from '@checkdigit/memoize';
|
|
22
22
|
|
|
23
23
|
async function doIt(parameter: number): Promise<number> {
|
package/SECURITY.md
CHANGED
package/dist-mjs/memoize.mjs
CHANGED
|
@@ -59,4 +59,4 @@ var memoize_default = (memoizableFunction) => {
|
|
|
59
59
|
export {
|
|
60
60
|
memoize_default as default
|
|
61
61
|
};
|
|
62
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
62
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBK0JBLElBQU8sa0JBQVEsQ0FDYix1QkFDMEM7QUFDMUMsUUFBTSxRQUFRLG9CQUFJLElBQTZCO0FBQy9DLFFBQU0sVUFBVSxvQkFBSSxJQUFvQjtBQUl4QyxRQUFNLE9BQU8sS0FBSyxPQUFPLEVBQUUsU0FBUztBQUVwQyxTQUFPLElBQUksaUJBQWlCO0FBQzFCLFVBQU0sT0FBTyxvQkFBSSxJQUFxQjtBQUV0QyxVQUFNLFlBQVksS0FBSyxVQUFVLGNBQWMsQ0FBQyxLQUFLQSxXQUFvQjtBQUV2RSxXQUFLLElBQUksR0FBRztBQUdaLGNBQVEsT0FBT0EsUUFBTztBQUFBLFFBQ3BCLEtBQUssVUFBVTtBQUNiLGlCQUFPLEdBQUcsSUFBSSxJQUFJQSxNQUFLO0FBQUEsUUFDekI7QUFBQSxRQUVBLEtBQUssYUFBYTtBQUNoQixpQkFBTyxHQUFHLElBQUk7QUFBQSxRQUNoQjtBQUFBLFFBRUEsS0FBSyxVQUFVO0FBQ2IsY0FBSSwwQkFBMEIsUUFBUSxJQUFJQSxNQUFLO0FBQy9DLGNBQUksNEJBQTRCLFFBQVc7QUFFekMsc0NBQTBCLEdBQUcsSUFBSSxXQUFXLEtBQUssT0FBTyxFQUFFLFNBQVMsQ0FBQztBQUNwRSxvQkFBUSxJQUFJQSxRQUFPLHVCQUF1QjtBQUFBLFVBQzVDO0FBQ0EsaUJBQU87QUFBQSxRQUNUO0FBQUEsUUFFQSxLQUFLLFlBQVk7QUFDZixnQkFBTSxJQUFJLFVBQVUsdUNBQXVDO0FBQUEsUUFDN0Q7QUFBQSxRQUVBLEtBQUssVUFBVTtBQUNiLGNBQUlBLFdBQVUsTUFBTTtBQUNsQixtQkFBTztBQUFBLFVBQ1Q7QUFFQSxjQUFJLE1BQU0sUUFBUUEsTUFBSyxHQUFHO0FBQ3hCLG1CQUFPQTtBQUFBLFVBQ1Q7QUFFQSxjQUFJQSxPQUFNLGdCQUFnQixRQUFRO0FBQ2hDLG1CQUFPQTtBQUFBLFVBQ1Q7QUFDQSxnQkFBTSxJQUFJLFVBQVUsb0NBQW9DO0FBQUEsUUFDMUQ7QUFBQSxRQUVBLEtBQUs7QUFBQSxRQUNMLEtBQUs7QUFBQSxRQUNMLEtBQUssVUFBVTtBQUNiLGlCQUFPQTtBQUFBLFFBQ1Q7QUFBQSxNQUNGO0FBQUEsSUFDRixDQUFDO0FBSUQsVUFBTSxXQUFXLEtBQUssVUFBVSxLQUFLLE1BQU0sU0FBUyxHQUFHLENBQUMsR0FBRyxJQUFJLEVBQUUsS0FBSyxDQUFDO0FBRXZFLFFBQUksUUFBUSxNQUFNLElBQUksUUFBUTtBQUM5QixRQUFJLFVBQVUsUUFBVztBQUN2QixjQUFRLG1CQUFtQixHQUFHLFlBQVk7QUFDMUMsWUFBTSxJQUFJLFVBQVUsS0FBSztBQUV6QixZQUFNLE1BQU0sTUFBTTtBQUVoQixjQUFNLE9BQU8sUUFBUTtBQUFBLE1BQ3ZCLENBQUM7QUFBQSxJQUNIO0FBQ0EsV0FBTztBQUFBLEVBQ1Q7QUFDRjsiLAogICJuYW1lcyI6IFsidmFsdWUiXQp9Cg==
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './memoize';
|
|
1
|
+
export { default } from './memoize.ts';
|
package/package.json
CHANGED
|
@@ -1,72 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/memoize",
|
|
3
|
-
"version": "2.0.0",
|
|
4
|
-
"description": "Memoizing async functions with cache eviction on reject",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
"types": "./dist-types/index.d.ts",
|
|
8
|
-
"import": "./dist-mjs/index.mjs",
|
|
9
|
-
"default": "./dist-mjs/index.mjs"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"sideEffects": false,
|
|
14
|
-
"files": [
|
|
15
|
-
"src",
|
|
16
|
-
"dist-types",
|
|
17
|
-
"dist-mjs",
|
|
18
|
-
"!src/**/*.test.ts",
|
|
19
|
-
"!src/**/*.spec.ts",
|
|
20
|
-
"!dist-types/**/*.test.d.ts",
|
|
21
|
-
"!dist-types/**/*.spec.d.ts",
|
|
22
|
-
"!dist-mjs/**/*.test.mjs",
|
|
23
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
24
|
-
"SECURITY.md"
|
|
25
|
-
],
|
|
26
|
-
"prettier": "@checkdigit/prettier-config",
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=20.11"
|
|
29
|
-
},
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/checkdigit/memoize.git"
|
|
33
|
-
},
|
|
34
|
-
"author": "Check Digit, LLC",
|
|
35
|
-
"license": "MIT",
|
|
36
|
-
"bugs": {
|
|
37
|
-
"url": "https://github.com/checkdigit/memoize/issues"
|
|
38
|
-
},
|
|
39
|
-
"homepage": "https://github.com/checkdigit/memoize#readme",
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@checkdigit/eslint-config": "^9.2.0",
|
|
42
|
-
"@checkdigit/jest-config": "^6.0.0",
|
|
43
|
-
"@checkdigit/prettier-config": "^5.3.0",
|
|
44
|
-
"@checkdigit/typescript-config": "^7.0.1",
|
|
45
|
-
"@types/uuid": "^9.0.8",
|
|
46
|
-
"rimraf": "^5.0.5",
|
|
47
|
-
"uuid": "^9.0.1"
|
|
48
|
-
},
|
|
49
|
-
"eslintConfig": {
|
|
50
|
-
"extends": [
|
|
51
|
-
"@checkdigit/eslint-config"
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
"jest": {
|
|
55
|
-
"preset": "@checkdigit/jest-config"
|
|
56
|
-
},
|
|
57
|
-
"scripts": {
|
|
58
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
59
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
|
60
|
-
"build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
61
|
-
"lint:fix": "eslint --ignore-path .gitignore . --fix",
|
|
62
|
-
"lint": "eslint --max-warnings 0 --ignore-path .gitignore .",
|
|
63
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
|
64
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
|
65
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style",
|
|
66
|
-
"ci:compile": "tsc --noEmit",
|
|
67
|
-
"ci:test": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false",
|
|
68
|
-
"ci:coverage": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true",
|
|
69
|
-
"ci:lint": "npm run lint",
|
|
70
|
-
"ci:style": "npm run prettier"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
{"name":"@checkdigit/memoize","version":"3.0.0-PR.11-c714","description":"Memoizing async functions with cache eviction on reject","homepage":"https://github.com/checkdigit/memoize#readme","bugs":{"url":"https://github.com/checkdigit/memoize/issues"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/memoize.git"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"rimraf coverage && mkdir coverage && node --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\"","coverage":"node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"","lint":"eslint --max-warnings 0 .","lint:fix":"eslint . --fix","prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","devDependencies":{"@checkdigit/eslint-config":"^11.0.5","@checkdigit/prettier-config":"^6.1.0","@checkdigit/typescript-config":"^9.0.0","rimraf":"^6.0.1","uuid":"^11.0.5"},"engines":{"node":">=22.11"}}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2023-
|
|
4
|
+
* Copyright (c) 2023-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export { default } from './memoize';
|
|
9
|
+
export { default } from './memoize.ts';
|
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-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
@@ -36,10 +36,12 @@ export default <Arguments extends Argument[], Return>(
|
|
|
36
36
|
const symbols = new Map<symbol, string>();
|
|
37
37
|
|
|
38
38
|
// use a random seed so the cache key remains unique when serializing BigInts and undefined into strings
|
|
39
|
+
// eslint-disable-next-line sonarjs/pseudo-random
|
|
39
40
|
const seed = Math.random().toString();
|
|
40
41
|
|
|
41
42
|
return (...argumentList) => {
|
|
42
43
|
const keys = new Set<string | number>();
|
|
44
|
+
// eslint-disable-next-line sonarjs/function-return-type
|
|
43
45
|
const converted = JSON.stringify(argumentList, (key, value: Argument) => {
|
|
44
46
|
// create a set of all object keys used in the argument list
|
|
45
47
|
keys.add(key);
|
|
@@ -57,6 +59,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
57
59
|
case 'symbol': {
|
|
58
60
|
let symbolUniqueStringValue = symbols.get(value);
|
|
59
61
|
if (symbolUniqueStringValue === undefined) {
|
|
62
|
+
// eslint-disable-next-line sonarjs/pseudo-random
|
|
60
63
|
symbolUniqueStringValue = `${seed}:symbol:${Math.random().toString()}`;
|
|
61
64
|
symbols.set(value, symbolUniqueStringValue);
|
|
62
65
|
}
|
|
@@ -91,12 +94,14 @@ export default <Arguments extends Argument[], Return>(
|
|
|
91
94
|
});
|
|
92
95
|
|
|
93
96
|
// create a cache key so that e.g. [{ a: 1, b: 2 }] and [{ b: 2, a: 1 }] map to the same cache entry
|
|
97
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort
|
|
94
98
|
const cacheKey = JSON.stringify(JSON.parse(converted), [...keys].sort());
|
|
95
99
|
|
|
96
100
|
let value = cache.get(cacheKey);
|
|
97
101
|
if (value === undefined) {
|
|
98
102
|
value = memoizableFunction(...argumentList);
|
|
99
103
|
cache.set(cacheKey, value);
|
|
104
|
+
// eslint-disable-next-line @checkdigit/no-promise-instance-method
|
|
100
105
|
value.catch(() => {
|
|
101
106
|
// on a reject, evict key from cache
|
|
102
107
|
cache.delete(cacheKey);
|