@checkdigit/memoize 1.1.0 → 2.0.0-PR.9-d626
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 +1 -1
- package/SECURITY.md +1 -1
- package/package.json +1 -75
- package/src/index.ts +1 -1
- package/src/memoize.ts +1 -1
- package/dist-cjs/index.cjs +0 -37
- package/dist-cjs/memoize.cjs +0 -83
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Memoize
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023 [Check Digit, LLC](https://checkdigit.com)
|
|
3
|
+
Copyright (c) 2023–2024 [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
package/package.json
CHANGED
|
@@ -1,75 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/memoize",
|
|
3
|
-
"version": "1.1.0",
|
|
4
|
-
"description": "Memoizing async functions with cache eviction on reject",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
"types": "./dist-types/index.d.ts",
|
|
8
|
-
"require": "./dist-cjs/index.cjs",
|
|
9
|
-
"import": "./dist-mjs/index.mjs",
|
|
10
|
-
"default": "./dist-mjs/index.mjs"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"src",
|
|
15
|
-
"dist-types",
|
|
16
|
-
"dist-cjs",
|
|
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-cjs/**/*.test.cjs",
|
|
23
|
-
"!dist-cjs/**/*.spec.cjs",
|
|
24
|
-
"!dist-mjs/**/*.test.mjs",
|
|
25
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
26
|
-
"SECURITY.md"
|
|
27
|
-
],
|
|
28
|
-
"prettier": "@checkdigit/prettier-config",
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=18"
|
|
31
|
-
},
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/checkdigit/memoize.git"
|
|
35
|
-
},
|
|
36
|
-
"author": "Check Digit, LLC",
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/checkdigit/memoize/issues"
|
|
40
|
-
},
|
|
41
|
-
"homepage": "https://github.com/checkdigit/memoize#readme",
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@checkdigit/eslint-config": "^8.1.0",
|
|
44
|
-
"@checkdigit/jest-config": "^3.0.0",
|
|
45
|
-
"@checkdigit/prettier-config": "^4.0.0",
|
|
46
|
-
"@checkdigit/typescript-config": "^4.0.0",
|
|
47
|
-
"@types/uuid": "^9.0.2",
|
|
48
|
-
"rimraf": "^5.0.1",
|
|
49
|
-
"uuid": "^9.0.0"
|
|
50
|
-
},
|
|
51
|
-
"eslintConfig": {
|
|
52
|
-
"extends": [
|
|
53
|
-
"@checkdigit/eslint-config"
|
|
54
|
-
]
|
|
55
|
-
},
|
|
56
|
-
"jest": {
|
|
57
|
-
"preset": "@checkdigit/jest-config"
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-cjs && npm run build:dist-esm",
|
|
61
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
|
62
|
-
"build:dist-cjs": "rimraf dist-cjs && npx builder --type=commonjs --sourceMap --outDir=dist-cjs",
|
|
63
|
-
"build:dist-esm": "rimraf dist-esm && npx builder --type=module --sourceMap --outDir=dist-mjs",
|
|
64
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
|
65
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
|
66
|
-
"lint:fix": "eslint --ignore-path .gitignore -f unix --ext .ts,.mts src --fix",
|
|
67
|
-
"lint": "eslint --ignore-path .gitignore -f unix --ext .ts,.mts src",
|
|
68
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style",
|
|
69
|
-
"ci:compile": "tsc --noEmit",
|
|
70
|
-
"ci:test": "jest --coverage=false",
|
|
71
|
-
"ci:coverage": "jest --coverage=true",
|
|
72
|
-
"ci:lint": "npm run lint",
|
|
73
|
-
"ci:style": "npm run prettier"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
1
|
+
{"name":"@checkdigit/memoize","version":"2.0.0-PR.9-d626","description":"Memoizing async functions with cache eviction on reject","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"type":"module","sideEffects":false,"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"],"prettier":"@checkdigit/prettier-config","engines":{"node":">=20.11"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/memoize.git"},"author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/memoize/issues"},"homepage":"https://github.com/checkdigit/memoize#readme","devDependencies":{"@checkdigit/eslint-config":"^9.2.0","@checkdigit/jest-config":"^6.0.0","@checkdigit/prettier-config":"^5.3.0","@checkdigit/typescript-config":"^7.0.1","@types/uuid":"^9.0.8","rimraf":"^5.0.5","uuid":"^9.0.1"},"eslintConfig":{"extends":["@checkdigit/eslint-config"]},"jest":{"preset":"@checkdigit/jest-config"},"scripts":{"prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","lint:fix":"eslint --ignore-path .gitignore . --fix","lint":"eslint --max-warnings 0 --ignore-path .gitignore .","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","ci:compile":"tsc --noEmit","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier"}}
|
package/src/index.ts
CHANGED
package/src/memoize.ts
CHANGED
package/dist-cjs/index.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
default: () => import_memoize.default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var import_memoize = __toESM(require("./memoize.cjs"));
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQVFBLHFCQUF3QjsiLAogICJuYW1lcyI6IFtdCn0K
|
package/dist-cjs/memoize.cjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/memoize.ts
|
|
21
|
-
var memoize_exports = {};
|
|
22
|
-
__export(memoize_exports, {
|
|
23
|
-
default: () => memoize_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(memoize_exports);
|
|
26
|
-
var memoize_default = (memoizableFunction) => {
|
|
27
|
-
const cache = /* @__PURE__ */ new Map();
|
|
28
|
-
const symbols = /* @__PURE__ */ new Map();
|
|
29
|
-
const seed = Math.random().toString();
|
|
30
|
-
return (...argumentList) => {
|
|
31
|
-
const keys = /* @__PURE__ */ new Set();
|
|
32
|
-
const converted = JSON.stringify(argumentList, (key, value2) => {
|
|
33
|
-
keys.add(key);
|
|
34
|
-
switch (typeof value2) {
|
|
35
|
-
case "bigint": {
|
|
36
|
-
return `${seed}:${value2}n`;
|
|
37
|
-
}
|
|
38
|
-
case "undefined": {
|
|
39
|
-
return `${seed}:undefined'`;
|
|
40
|
-
}
|
|
41
|
-
case "symbol": {
|
|
42
|
-
let symbolUniqueStringValue = symbols.get(value2);
|
|
43
|
-
if (symbolUniqueStringValue === void 0) {
|
|
44
|
-
symbolUniqueStringValue = `${seed}:symbol:${Math.random().toString()}`;
|
|
45
|
-
symbols.set(value2, symbolUniqueStringValue);
|
|
46
|
-
}
|
|
47
|
-
return symbolUniqueStringValue;
|
|
48
|
-
}
|
|
49
|
-
case "function": {
|
|
50
|
-
throw new TypeError("Function arguments cannot be memoized");
|
|
51
|
-
}
|
|
52
|
-
case "object": {
|
|
53
|
-
if (value2 === null) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(value2)) {
|
|
57
|
-
return value2;
|
|
58
|
-
}
|
|
59
|
-
if (value2.constructor === Object) {
|
|
60
|
-
return value2;
|
|
61
|
-
}
|
|
62
|
-
throw new TypeError(`Object argument cannot be memoized`);
|
|
63
|
-
}
|
|
64
|
-
case "number":
|
|
65
|
-
case "boolean":
|
|
66
|
-
case "string": {
|
|
67
|
-
return value2;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const cacheKey = JSON.stringify(JSON.parse(converted), [...keys].sort());
|
|
72
|
-
let value = cache.get(cacheKey);
|
|
73
|
-
if (value === void 0) {
|
|
74
|
-
value = memoizableFunction(...argumentList);
|
|
75
|
-
cache.set(cacheKey, value);
|
|
76
|
-
value.catch(() => {
|
|
77
|
-
cache.delete(cacheKey);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUErQkEsSUFBTyxrQkFBUSxDQUNiLHVCQUMwQztBQUMxQyxRQUFNLFFBQVEsb0JBQUksSUFBNkI7QUFDL0MsUUFBTSxVQUFVLG9CQUFJLElBQW9CO0FBR3hDLFFBQU0sT0FBTyxLQUFLLE9BQU8sRUFBRSxTQUFTO0FBRXBDLFNBQU8sSUFBSSxpQkFBaUI7QUFDMUIsVUFBTSxPQUFPLG9CQUFJLElBQXFCO0FBQ3RDLFVBQU0sWUFBWSxLQUFLLFVBQVUsY0FBYyxDQUFDLEtBQUtBLFdBQW9CO0FBRXZFLFdBQUssSUFBSSxHQUFHO0FBR1osY0FBU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