@checkdigit/memoize 2.0.0 → 3.0.0-PR.11-f005

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-2024 Check Digit, LLC
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–2024 [Check Digit, LLC](https://checkdigit.com)
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
- ### Install
12
+ ## Install
13
13
 
14
- ```
14
+ ```shell
15
15
  $ npm install @checkdigit/memoize
16
16
  ```
17
17
 
18
- ### Use
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
@@ -6,7 +6,7 @@ These versions of @checkdigit/memoize are currently being supported with securit
6
6
 
7
7
  | Version | Supported |
8
8
  | ------- | ------------------ |
9
- | > 2.x | :white_check_mark: |
9
+ | \>= 3.x | :white_check_mark: |
10
10
 
11
11
  ## Reporting a Vulnerability
12
12
 
@@ -2,7 +2,7 @@
2
2
  var memoize_default = (memoizableFunction) => {
3
3
  const cache = /* @__PURE__ */ new Map();
4
4
  const symbols = /* @__PURE__ */ new Map();
5
- const seed = Math.random().toString();
5
+ const seed = crypto.randomUUID();
6
6
  return (...argumentList) => {
7
7
  const keys = /* @__PURE__ */ new Set();
8
8
  const converted = JSON.stringify(argumentList, (key, value2) => {
@@ -17,7 +17,7 @@ var memoize_default = (memoizableFunction) => {
17
17
  case "symbol": {
18
18
  let symbolUniqueStringValue = symbols.get(value2);
19
19
  if (symbolUniqueStringValue === void 0) {
20
- symbolUniqueStringValue = `${seed}:symbol:${Math.random().toString()}`;
20
+ symbolUniqueStringValue = `${seed}:symbol:${crypto.randomUUID()}`;
21
21
  symbols.set(value2, symbolUniqueStringValue);
22
22
  }
23
23
  return symbolUniqueStringValue;
@@ -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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBK0JBLElBQU8sa0JBQVEsQ0FDYix1QkFDMEM7QUFDMUMsUUFBTSxRQUFRLG9CQUFJLElBQTZCO0FBQy9DLFFBQU0sVUFBVSxvQkFBSSxJQUFvQjtBQUd4QyxRQUFNLE9BQU8sS0FBSyxPQUFPLEVBQUUsU0FBUztBQUVwQyxTQUFPLElBQUksaUJBQWlCO0FBQzFCLFVBQU0sT0FBTyxvQkFBSSxJQUFxQjtBQUN0QyxVQUFNLFlBQVksS0FBSyxVQUFVLGNBQWMsQ0FBQyxLQUFLQSxXQUFvQjtBQUV2RSxXQUFLLElBQUksR0FBRztBQUdaLGNBQVEsT0FBT0EsUUFBTztBQUFBLFFBQ3BCLEtBQUssVUFBVTtBQUNiLGlCQUFPLEdBQUcsSUFBSSxJQUFJQSxNQUFLO0FBQUEsUUFDekI7QUFBQSxRQUVBLEtBQUssYUFBYTtBQUNoQixpQkFBTyxHQUFHLElBQUk7QUFBQSxRQUNoQjtBQUFBLFFBRUEsS0FBSyxVQUFVO0FBQ2IsY0FBSSwwQkFBMEIsUUFBUSxJQUFJQS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87QUFBQSxVQUNUO0FBRUEsY0FBSSxNQUFNLFFBQVFBLE1BQUssR0FBRztBQUN4QixtQkFBT0E7QUFBQSxVQUNUO0FBRUEsY0FBSUEsT0FBTSxnQkFBZ0IsUUFBUTtBQUNoQyxtQkFBT0E7QUFBQSxVQUNUO0FBQ0EsZ0JBQU0sSUFBSSxVQUFVLG9DQUFvQztBQUFBLFFBQzFEO0FBQUEsUUFFQSxLQUFLO0FBQUEsUUFDTCxLQUFLO0FBQUEsUUFDTCxLQUFLLFVBQVU7QUFDYixpQkFBT0E7QUFBQSxRQUNUO0FBQUEsTUFDRjtBQUFBLElBQ0YsQ0FBQztBQUlELFVBQU0sV0FBVyxLQUFLLFVBQVUsS0FBSyxNQUFNLFNBQVMsR0FBRyxDQUFDLEdBQUcsSUFBSSxFQUFFLEtBQUssQ0FBQztBQUV2RSxRQUFJLFFBQVEsTUFBTSxJQUFJLFFBQVE7QUFDOUIsUUFBSSxVQUFVLFFBQVc7QUFDdkIsY0FBUSxtQkFBbUIsR0FBRyxZQUFZO0FBQzFDLFlBQU0sSUFBSSxVQUFVLEtBQUs7QUFFekIsWUFBTSxNQUFNLE1BQU07QUFFaEIsY0FBTSxPQUFPLFFBQVE7QUFBQSxNQUN2QixDQUFDO0FBQUEsSUFDSDtBQUNBLFdBQU87QUFBQSxFQUNUO0FBQ0Y7IiwKICAibmFtZXMiOiBbInZhbHVlIl0KfQo=
@@ -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-f005","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-2024 Check Digit, LLC
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-2024 Check Digit, LLC
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,11 @@ 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
- const seed = Math.random().toString();
39
+ const seed = crypto.randomUUID();
40
40
 
41
41
  return (...argumentList) => {
42
42
  const keys = new Set<string | number>();
43
+ // eslint-disable-next-line sonarjs/function-return-type
43
44
  const converted = JSON.stringify(argumentList, (key, value: Argument) => {
44
45
  // create a set of all object keys used in the argument list
45
46
  keys.add(key);
@@ -57,7 +58,7 @@ export default <Arguments extends Argument[], Return>(
57
58
  case 'symbol': {
58
59
  let symbolUniqueStringValue = symbols.get(value);
59
60
  if (symbolUniqueStringValue === undefined) {
60
- symbolUniqueStringValue = `${seed}:symbol:${Math.random().toString()}`;
61
+ symbolUniqueStringValue = `${seed}:symbol:${crypto.randomUUID()}`;
61
62
  symbols.set(value, symbolUniqueStringValue);
62
63
  }
63
64
  return symbolUniqueStringValue;
@@ -91,12 +92,14 @@ export default <Arguments extends Argument[], Return>(
91
92
  });
92
93
 
93
94
  // create a cache key so that e.g. [{ a: 1, b: 2 }] and [{ b: 2, a: 1 }] map to the same cache entry
95
+ // eslint-disable-next-line sonarjs/no-alphabetical-sort
94
96
  const cacheKey = JSON.stringify(JSON.parse(converted), [...keys].sort());
95
97
 
96
98
  let value = cache.get(cacheKey);
97
99
  if (value === undefined) {
98
100
  value = memoizableFunction(...argumentList);
99
101
  cache.set(cacheKey, value);
102
+ // eslint-disable-next-line @checkdigit/no-promise-instance-method
100
103
  value.catch(() => {
101
104
  // on a reject, evict key from cache
102
105
  cache.delete(cacheKey);