@quenty/memoize 1.6.0 → 1.6.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.6.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/memoize@1.6.0...@quenty/memoize@1.6.1) (2025-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/memoize@1.5.1...@quenty/memoize@1.6.0) (2025-02-18)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/memoize
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/memoize",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Memoization library",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,12 +25,12 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/loader": "^10.8.0",
29
- "@quenty/lrucache": "^1.6.0",
30
- "@quenty/tuple": "^1.5.0"
28
+ "@quenty/loader": "^10.8.1",
29
+ "@quenty/lrucache": "^1.6.1",
30
+ "@quenty/tuple": "^1.5.1"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "184a407d8d7366c39009444c3c9a7023cb176471"
35
+ "gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
36
36
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class MemorizeUtils
3
4
  ]=]
@@ -7,27 +8,32 @@ local require = require(script.Parent.loader).load(script)
7
8
  local LRUCache = require("LRUCache")
8
9
  local Tuple = require("Tuple")
9
10
  local TupleLookup = require("TupleLookup")
11
+ local TypeUtils = require("TypeUtils")
10
12
 
11
13
  local MemorizeUtils = {}
12
14
 
15
+ export type CacheConfig = {
16
+ maxSize: number,
17
+ }
18
+
13
19
  --[=[
14
20
  Memoizes a function with a max size
15
21
 
16
22
  @param func function
17
23
  @param cacheConfig CacheConfig
18
24
  ]=]
19
- function MemorizeUtils.memoize(func, cacheConfig)
25
+ function MemorizeUtils.memoize<T..., U...>(func: (T...) -> U..., cacheConfig: CacheConfig?): (T...) -> U...
20
26
  assert(type(func) == "function", "Bad func")
21
27
  assert(MemorizeUtils.isCacheConfig(cacheConfig) or cacheConfig == nil, "Bad cacheConfig")
22
28
 
23
- cacheConfig = cacheConfig or MemorizeUtils.createCacheConfig()
29
+ local config = cacheConfig or MemorizeUtils.createCacheConfig()
24
30
 
25
31
  local tupleLookup = TupleLookup.new()
26
- local cache = LRUCache.new(cacheConfig.maxSize)
32
+ local cache = LRUCache.new(config.maxSize)
27
33
 
28
- return function(...)
34
+ return function(...: T...): U...
29
35
  -- O(n)
30
- local params = tupleLookup:ToTuple(...)
36
+ local params = tupleLookup:ToTuple(TypeUtils.anyValue(...))
31
37
 
32
38
  local found = cache:get(params)
33
39
  if found then
@@ -47,7 +53,7 @@ end
47
53
  @param value any
48
54
  @return boolean
49
55
  ]=]
50
- function MemorizeUtils.isCacheConfig(value)
56
+ function MemorizeUtils.isCacheConfig(value: any): boolean
51
57
  return type(value) == "table" and type(value.maxSize) == "number"
52
58
  end
53
59
 
@@ -57,13 +63,12 @@ end
57
63
  @param cacheConfig table | nil
58
64
  @return CacheConfig
59
65
  ]=]
60
- function MemorizeUtils.createCacheConfig(cacheConfig)
66
+ function MemorizeUtils.createCacheConfig(cacheConfig: CacheConfig?): CacheConfig
61
67
  assert(MemorizeUtils.isCacheConfig(cacheConfig) or cacheConfig == nil, "Bad cacheConfig")
62
68
 
63
- cacheConfig = cacheConfig or {}
64
69
 
65
70
  return {
66
- maxSize = cacheConfig.maxSize or 128;
71
+ maxSize = if cacheConfig and cacheConfig.maxSize then cacheConfig.maxSize else 128;
67
72
  }
68
73
  end
69
74