@checkdigit/memoize 1.1.0-PR.4-dcc8 → 2.0.0-PR.9-d49e

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 CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  The MIT License
3
3
 
4
- Copyright (c) 2023 Check Digit, LLC
4
+ Copyright (c) 2023-2024 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 [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
@@ -6,7 +6,7 @@ These versions of @checkdigit/memoize are currently being supported with securit
6
6
 
7
7
  | Version | Supported |
8
8
  | ------- | ------------------ |
9
- | > 1.x | :white_check_mark: |
9
+ | > 2.x | :white_check_mark: |
10
10
 
11
11
  ## Reporting a Vulnerability
12
12
 
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@checkdigit/memoize","version":"1.1.0-PR.4-dcc8","description":"Memoizing async functions with cache eviction on reject","exports":{".":{"types":"./dist-types/index.d.ts","require":"./dist-cjs/index.cjs","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-cjs","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-cjs/**/*.test.cjs","!dist-cjs/**/*.spec.cjs","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"prettier":"@checkdigit/prettier-config","engines":{"node":">=18"},"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":"^8.1.0","@checkdigit/jest-config":"^3.0.0","@checkdigit/prettier-config":"^4.0.0","@checkdigit/typescript-config":"^4.0.0","@types/uuid":"^9.0.2","rimraf":"^5.0.1","uuid":"^9.0.0"},"eslintConfig":{"extends":["@checkdigit/eslint-config"]},"jest":{"preset":"@checkdigit/jest-config"},"scripts":{"prepublishOnly":"npm run build:dist-types && npm run build:dist-cjs && npm run build:dist-esm","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","build:dist-cjs":"rimraf dist-cjs && npx builder --type=commonjs --sourceMap --outDir=dist-cjs","build:dist-esm":"rimraf dist-esm && npx builder --type=module --sourceMap --outDir=dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","lint:fix":"eslint --ignore-path .gitignore -f unix --ext .ts,.mts src --fix","lint":"eslint --ignore-path .gitignore -f unix --ext .ts,.mts src","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"jest --coverage=false","ci:coverage":"jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier"}}
1
+ {"name":"@checkdigit/memoize","version":"2.0.0-PR.9-d49e","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"}},"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
@@ -1,7 +1,7 @@
1
1
  // index.ts
2
2
 
3
3
  /*
4
- * Copyright (c) 2023 Check Digit, LLC
4
+ * Copyright (c) 2023-2024 Check Digit, LLC
5
5
  *
6
6
  * This code is licensed under the MIT license (see LICENSE.txt for details).
7
7
  */
package/src/memoize.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // memoize.ts
2
2
 
3
3
  /*
4
- * Copyright (c) 2023 Check Digit, LLC
4
+ * Copyright (c) 2023-2024 Check Digit, LLC
5
5
  *
6
6
  * This code is licensed under the MIT license (see LICENSE.txt for details).
7
7
  */
@@ -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
@@ -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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUErQkEsSUFBTyxrQkFBUSxDQUNiLHVCQUMwQztBQUMxQyxRQUFNLFFBQVEsb0JBQUksSUFBNkI7QUFDL0MsUUFBTSxVQUFVLG9CQUFJLElBQW9CO0FBR3hDLFFBQU0sT0FBTyxLQUFLLE9BQU8sRUFBRSxTQUFTO0FBRXBDLFNBQU8sSUFBSSxpQkFBaUI7QUFDMUIsVUFBTSxPQUFPLG9CQUFJLElBQXFCO0FBQ3RDLFVBQU0sWUFBWSxLQUFLLFVBQVUsY0FBYyxDQUFDLEtBQUtBLFdBQW9CO0FBRXZFLFdBQUssSUFBSSxHQUFHO0FBR1osY0FBUSxPQUFPQSxRQUFPO0FBQUEsUUFDcEIsS0FBSyxVQUFVO0FBQ2IsaUJBQU8sR0FBRyxJQUFJLElBQUlBLE1BQUs7QUFBQSxRQUN6QjtBQUFBLFFBRUEsS0FBSyxhQUFhO0FBQ2hCLGlCQUFPLEdBQUcsSUFBSTtBQUFBLFFBQ2hCO0FBQUEsUUFFQSxLQUFLLFVBQVU7QUFDYixjQUFJLDBCQUEwQixRQUFRLElBQUlBLE1BQUs7QUFDL0MsY0FBSSw0QkFBNEIsUUFBVztBQUN6QyxzQ0FBMEIsR0FBRyxJQUFJLFdBQVcsS0FBSyxPQUFPLEVBQUUsU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