@checkdigit/memoize 3.0.0 → 3.1.0-PR.13-800f
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/dist-mjs/memoize.mjs +2 -2
- package/dist-types/memoize.d.ts +1 -1
- package/package.json +1 -63
- package/src/memoize.ts +8 -2
package/dist-mjs/memoize.mjs
CHANGED
|
@@ -23,7 +23,7 @@ var memoize_default = (memoizableFunction) => {
|
|
|
23
23
|
return symbolUniqueStringValue;
|
|
24
24
|
}
|
|
25
25
|
case "function": {
|
|
26
|
-
|
|
26
|
+
return `${seed}:function:${value2.toString()}n`;
|
|
27
27
|
}
|
|
28
28
|
case "object": {
|
|
29
29
|
if (value2 === null) {
|
|
@@ -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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBbUNBLElBQU8sa0JBQVEsQ0FDYix1QkFDMEM7QUFDMUMsUUFBTSxRQUFRLG9CQUFJLElBQTZCO0FBQy9DLFFBQU0sVUFBVSxvQkFBSSxJQUFvQjtBQUl4QyxRQUFNLE9BQU8sT0FBTyxXQUFXO0FBRS9CLFNBQU8sSUFBSSxpQkFBaUI7QUFDMUIsVUFBTSxPQUFPLG9CQUFJLElBQXFCO0FBRXRDLFVBQU0sWUFBWSxLQUFLLFVBQVUsY0FBYyxDQUFDLEtBQUtBLFdBQW9CO0FBRXZFLFdBQUssSUFBSSxHQUFHO0FBR1osY0FBUSxPQUFPQSxRQUFPO0FBQUEsUUFDcEIsS0FBSyxVQUFVO0FBQ2IsaUJBQU8sR0FBRyxJQUFJLElBQUlBLE1BQUs7QUFBQSxRQUN6QjtB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UFBTSxJQUFJLFVBQVUsS0FBSztBQUV6QixZQUFNLE1BQU0sTUFBTTtBQUVoQixjQUFNLE9BQU8sUUFBUTtBQUFBLE1BQ3ZCLENBQUM7QUFBQSxJQUNIO0FBQ0EsV0FBTztBQUFBLEVBQ1Q7QUFDRjsiLAogICJuYW1lcyI6IFsidmFsdWUiXQp9Cg==
|
package/dist-types/memoize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Argument = string | symbol | bigint | number | boolean | null | undefined | Date | URL | Argument[] | {
|
|
1
|
+
export type Argument = string | symbol | bigint | number | boolean | null | undefined | Date | Function | URL | Argument[] | {
|
|
2
2
|
[key: string]: Argument;
|
|
3
3
|
};
|
|
4
4
|
export type MemoizableFunction<Arguments extends Argument[], Return> = (...argumentList: Arguments) => Promise<Return>;
|
package/package.json
CHANGED
|
@@ -1,63 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/memoize",
|
|
3
|
-
"version": "3.0.0",
|
|
4
|
-
"description": "Memoizing async functions with cache eviction on reject",
|
|
5
|
-
"homepage": "https://github.com/checkdigit/memoize#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/checkdigit/memoize/issues"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/checkdigit/memoize.git"
|
|
12
|
-
},
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "Check Digit, LLC",
|
|
15
|
-
"sideEffects": false,
|
|
16
|
-
"type": "module",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"types": "./dist-types/index.d.ts",
|
|
20
|
-
"import": "./dist-mjs/index.mjs",
|
|
21
|
-
"default": "./dist-mjs/index.mjs"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"src",
|
|
26
|
-
"dist-types",
|
|
27
|
-
"dist-mjs",
|
|
28
|
-
"!src/**/*.test.ts",
|
|
29
|
-
"!src/**/*.spec.ts",
|
|
30
|
-
"!dist-types/**/*.test.d.ts",
|
|
31
|
-
"!dist-types/**/*.spec.d.ts",
|
|
32
|
-
"!dist-mjs/**/*.test.mjs",
|
|
33
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
34
|
-
"SECURITY.md"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
38
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
|
39
|
-
"ci:compile": "tsc --noEmit",
|
|
40
|
-
"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\"",
|
|
41
|
-
"ci:lint": "npm run lint",
|
|
42
|
-
"ci:style": "npm run prettier",
|
|
43
|
-
"ci:test": "node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\"",
|
|
44
|
-
"coverage": "node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"",
|
|
45
|
-
"lint": "eslint --max-warnings 0 .",
|
|
46
|
-
"lint:fix": "eslint . --fix",
|
|
47
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
48
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
|
49
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
|
50
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
|
|
51
|
-
},
|
|
52
|
-
"prettier": "@checkdigit/prettier-config",
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@checkdigit/eslint-config": "^11.0.5",
|
|
55
|
-
"@checkdigit/prettier-config": "^6.1.0",
|
|
56
|
-
"@checkdigit/typescript-config": "^9.0.0",
|
|
57
|
-
"rimraf": "^6.0.1",
|
|
58
|
-
"uuid": "^11.0.5"
|
|
59
|
-
},
|
|
60
|
-
"engines": {
|
|
61
|
-
"node": ">=22.11"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
{"name":"@checkdigit/memoize","version":"3.1.0-PR.13-800f","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.2.5","@checkdigit/prettier-config":"^7.0.0","@checkdigit/typescript-config":"^9.1.1","rimraf":"^6.0.1"},"engines":{"node":">=22.14"}}
|
package/src/memoize.ts
CHANGED
|
@@ -16,11 +16,15 @@ export type Argument =
|
|
|
16
16
|
| null
|
|
17
17
|
| undefined
|
|
18
18
|
| Date
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
20
|
+
| Function
|
|
19
21
|
| URL
|
|
20
22
|
| Argument[]
|
|
21
23
|
| { [key: string]: Argument };
|
|
22
24
|
|
|
23
|
-
export type MemoizableFunction<Arguments extends Argument[], Return> = (
|
|
25
|
+
export type MemoizableFunction<Arguments extends Argument[], Return> = (
|
|
26
|
+
...argumentList: Arguments
|
|
27
|
+
) => Promise<Return>;
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Memoize an async function. The promise is cached, not the value. This guarantees the underlying function is
|
|
@@ -36,6 +40,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
36
40
|
const symbols = new Map<symbol, string>();
|
|
37
41
|
|
|
38
42
|
// use a random seed so the cache key remains unique when serializing BigInts and undefined into strings
|
|
43
|
+
// eslint-disable-next-line @checkdigit/no-random-v4-uuid
|
|
39
44
|
const seed = crypto.randomUUID();
|
|
40
45
|
|
|
41
46
|
return (...argumentList) => {
|
|
@@ -58,6 +63,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
58
63
|
case 'symbol': {
|
|
59
64
|
let symbolUniqueStringValue = symbols.get(value);
|
|
60
65
|
if (symbolUniqueStringValue === undefined) {
|
|
66
|
+
// eslint-disable-next-line @checkdigit/no-random-v4-uuid
|
|
61
67
|
symbolUniqueStringValue = `${seed}:symbol:${crypto.randomUUID()}`;
|
|
62
68
|
symbols.set(value, symbolUniqueStringValue);
|
|
63
69
|
}
|
|
@@ -65,7 +71,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
case 'function': {
|
|
68
|
-
|
|
74
|
+
return `${seed}:function:${value.toString()}n`;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
case 'object': {
|