limited-cache 2.0.0 → 2.1.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 +13 -1
- package/CODE_OF_CONDUCT.md +103 -47
- package/{CONTRIBUTING.md → CONTRIBUTING.template.md} +4 -2
- package/README.md +2 -2
- package/dist/core/LimitedCache.d.ts +4 -3
- package/dist/core/LimitedCache.d.ts.map +1 -0
- package/dist/core/LimitedCache.js +29 -0
- package/dist/core/LimitedCache.js.map +1 -0
- package/dist/core/LimitedCacheObject.d.ts +5 -4
- package/dist/core/LimitedCacheObject.d.ts.map +1 -0
- package/dist/core/LimitedCacheObject.js +52 -0
- package/dist/core/LimitedCacheObject.js.map +1 -0
- package/dist/core/builtIns.d.ts +12 -11
- package/dist/core/builtIns.d.ts.map +1 -0
- package/dist/core/builtIns.js +5 -0
- package/dist/core/builtIns.js.map +1 -0
- package/dist/core/defaultOptions.d.ts +6 -5
- package/dist/core/defaultOptions.d.ts.map +1 -0
- package/dist/core/defaultOptions.js +14 -0
- package/dist/core/defaultOptions.js.map +1 -0
- package/dist/core/limitedCacheUtil.d.ts +13 -12
- package/dist/core/limitedCacheUtil.d.ts.map +1 -0
- package/dist/core/limitedCacheUtil.js +14 -0
- package/dist/core/limitedCacheUtil.js.map +1 -0
- package/dist/core/lowLevelFunctions.d.ts +14 -13
- package/dist/core/lowLevelFunctions.d.ts.map +1 -0
- package/dist/core/lowLevelFunctions.js +240 -0
- package/dist/core/lowLevelFunctions.js.map +1 -0
- package/dist/index.cjs +388 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +58 -60
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -74
- package/src/__tests__/LimitedCache.test.ts +8 -8
- package/src/__tests__/LimitedCacheObject.test.ts +9 -7
- package/src/__tests__/lowLevelFunctions.test.ts +20 -16
- package/src/__tests__/scenarios/keys.test.ts +2 -2
- package/src/__tests__/scenarios/maxCacheSize.test.ts +4 -4
- package/src/__tests__/scenarios/maxCacheTime.test.ts +3 -3
- package/src/__tests__/scenarios/values.test.ts +2 -2
- package/src/__tests__/typeChecks/LimitedCacheObjectTypes.test.ts +5 -3
- package/src/__tests__/typeChecks/LimitedCacheTypes.test.ts +5 -3
- package/src/__tests__/typeChecks/lowLevelFunctionsTypes.test.ts +5 -3
- package/src/core/LimitedCache.ts +2 -2
- package/src/core/LimitedCacheObject.ts +3 -3
- package/src/core/defaultOptions.ts +1 -1
- package/src/core/limitedCacheUtil.ts +1 -1
- package/src/core/lowLevelFunctions.ts +8 -8
- package/src/index.ts +6 -6
- package/dist/limited-cache.cjs.development.js +0 -469
- package/dist/limited-cache.cjs.development.js.map +0 -1
- package/dist/limited-cache.cjs.production.min.js +0 -2
- package/dist/limited-cache.cjs.production.min.js.map +0 -1
- package/dist/limited-cache.esm.js +0 -448
- package/dist/limited-cache.esm.js.map +0 -1
- package/legacy-types/ts3.x/dist/core/LimitedCache.d.ts +0 -3
- package/legacy-types/ts3.x/dist/core/LimitedCacheObject.d.ts +0 -4
- package/legacy-types/ts3.x/dist/core/builtIns.d.ts +0 -11
- package/legacy-types/ts3.x/dist/core/defaultOptions.d.ts +0 -5
- package/legacy-types/ts3.x/dist/core/limitedCacheUtil.d.ts +0 -12
- package/legacy-types/ts3.x/dist/core/lowLevelFunctions.d.ts +0 -13
- package/legacy-types/ts3.x/dist/index.d.ts +0 -6
- package/legacy-types/ts3.x/dist/types.d.ts +0 -60
package/dist/types.d.ts
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
|
-
export
|
|
2
|
-
export interface LimitedCacheOptionsFull {
|
|
3
|
-
/** Items will be removed to keep the cache within the maxCacheSize limit */
|
|
4
|
-
maxCacheSize: number;
|
|
5
|
-
/** Items will be removed and never returned if they were set more than maxCacheTime milliseconds ago */
|
|
6
|
-
maxCacheTime: number;
|
|
7
|
-
/** (dev only) A warning will be emitted if an item rotates out of the cache before this many milliseconds have passed, to indicate the size is too small */
|
|
8
|
-
warnIfItemPurgedBeforeTime: number;
|
|
9
|
-
/** (private) Internal cleanup of old keys will be performed after this many operations */
|
|
10
|
-
opLimit: number;
|
|
11
|
-
/** (private) Internal optimization to adjust how much searching will be done to find expired items, to avoid being O(n) */
|
|
12
|
-
scanLimit: number;
|
|
13
|
-
}
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export interface LimitedCacheInstance<ItemType = DefaultItemType> {
|
|
17
|
-
/** Return the requested item, if it has not expired */
|
|
18
|
-
get: (cacheKey: string) => ItemType | undefined;
|
|
19
|
-
/** Return all non-expired items */
|
|
20
|
-
getAll: () => Record<string, ItemType>;
|
|
21
|
-
/** Indicate whether or not the requested item is present and has not expired */
|
|
22
|
-
has: (cacheKey: string) => boolean;
|
|
23
|
-
/** Add the item to the cache, or update its timestamp if it already exists */
|
|
24
|
-
set: (cacheKey: string, item: ItemType) => ItemType;
|
|
25
|
-
/** Remove the requested item from the cache, if necessary */
|
|
26
|
-
remove: (cacheKey: string) => true;
|
|
27
|
-
/** Remove all items and all timestamps from the cache */
|
|
28
|
-
reset: () => LimitedCacheMeta<ItemType>;
|
|
29
|
-
/** Return a serializable representation of the cache internals, suitable for long-term storage */
|
|
30
|
-
getCacheMeta: () => LimitedCacheMeta<ItemType>;
|
|
31
|
-
/** Return the cache's current values for all options */
|
|
32
|
-
getOptions: () => LimitedCacheOptionsFull;
|
|
33
|
-
/** Update one or more of the cache's options */
|
|
34
|
-
setOptions: (newOptions: LimitedCacheOptions) => LimitedCacheOptionsReadonly;
|
|
35
|
-
/** Reduces cache size by cleaning up old keys and expired items */
|
|
36
|
-
doMaintenance: () => LimitedCacheMeta<ItemType>;
|
|
37
|
-
}
|
|
38
|
-
export interface LimitedCacheObjectInstance<ItemType = DefaultItemType> {
|
|
39
|
-
[key: string]: ItemType;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A serializable representation of the cache internals, suitable for long-term storage
|
|
43
|
-
*/
|
|
44
|
-
export interface LimitedCacheMeta<ItemType = DefaultItemType> {
|
|
45
|
-
/** Schema version: old versions will be upgraded if possible, or a warning will be emitted if not */
|
|
46
|
-
limitedCacheMetaVersion: number;
|
|
47
|
-
/** Options to control cache size, time, and behavior */
|
|
48
|
-
options: LimitedCacheOptionsReadonly;
|
|
49
|
-
/** The values in the cache, stored by key. Will include old keys not yet garbage collected */
|
|
50
|
-
cache: Record<string, ItemType | undefined>;
|
|
51
|
-
/** List of keys that have been set, in chronological order. Used to find cache items most likely to be expired */
|
|
52
|
-
keyList: Array<string>;
|
|
53
|
-
/** The [setTime, expirationTime] for each key that has been set. Removed on unset. */
|
|
54
|
-
keyInfo: Record<string, [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
opsLeft: number;
|
|
60
|
-
}
|
|
1
|
+
export type DefaultItemType = any;
|
|
2
|
+
export interface LimitedCacheOptionsFull {
|
|
3
|
+
/** Items will be removed to keep the cache within the maxCacheSize limit */
|
|
4
|
+
maxCacheSize: number;
|
|
5
|
+
/** Items will be removed and never returned if they were set more than maxCacheTime milliseconds ago */
|
|
6
|
+
maxCacheTime: number;
|
|
7
|
+
/** (dev only) A warning will be emitted if an item rotates out of the cache before this many milliseconds have passed, to indicate the size is too small */
|
|
8
|
+
warnIfItemPurgedBeforeTime: number;
|
|
9
|
+
/** (private) Internal cleanup of old keys will be performed after this many operations */
|
|
10
|
+
opLimit: number;
|
|
11
|
+
/** (private) Internal optimization to adjust how much searching will be done to find expired items, to avoid being O(n) */
|
|
12
|
+
scanLimit: number;
|
|
13
|
+
}
|
|
14
|
+
export type LimitedCacheOptions = Partial<LimitedCacheOptionsFull> | null;
|
|
15
|
+
export type LimitedCacheOptionsReadonly = Readonly<LimitedCacheOptionsFull>;
|
|
16
|
+
export interface LimitedCacheInstance<ItemType = DefaultItemType> {
|
|
17
|
+
/** Return the requested item, if it has not expired */
|
|
18
|
+
get: (cacheKey: string) => ItemType | undefined;
|
|
19
|
+
/** Return all non-expired items */
|
|
20
|
+
getAll: () => Record<string, ItemType>;
|
|
21
|
+
/** Indicate whether or not the requested item is present and has not expired */
|
|
22
|
+
has: (cacheKey: string) => boolean;
|
|
23
|
+
/** Add the item to the cache, or update its timestamp if it already exists */
|
|
24
|
+
set: (cacheKey: string, item: ItemType) => ItemType;
|
|
25
|
+
/** Remove the requested item from the cache, if necessary */
|
|
26
|
+
remove: (cacheKey: string) => true;
|
|
27
|
+
/** Remove all items and all timestamps from the cache */
|
|
28
|
+
reset: () => LimitedCacheMeta<ItemType>;
|
|
29
|
+
/** Return a serializable representation of the cache internals, suitable for long-term storage */
|
|
30
|
+
getCacheMeta: () => LimitedCacheMeta<ItemType>;
|
|
31
|
+
/** Return the cache's current values for all options */
|
|
32
|
+
getOptions: () => LimitedCacheOptionsFull;
|
|
33
|
+
/** Update one or more of the cache's options */
|
|
34
|
+
setOptions: (newOptions: LimitedCacheOptions) => LimitedCacheOptionsReadonly;
|
|
35
|
+
/** Reduces cache size by cleaning up old keys and expired items */
|
|
36
|
+
doMaintenance: () => LimitedCacheMeta<ItemType>;
|
|
37
|
+
}
|
|
38
|
+
export interface LimitedCacheObjectInstance<ItemType = DefaultItemType> {
|
|
39
|
+
[key: string]: ItemType;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A serializable representation of the cache internals, suitable for long-term storage
|
|
43
|
+
*/
|
|
44
|
+
export interface LimitedCacheMeta<ItemType = DefaultItemType> {
|
|
45
|
+
/** Schema version: old versions will be upgraded if possible, or a warning will be emitted if not */
|
|
46
|
+
limitedCacheMetaVersion: number;
|
|
47
|
+
/** Options to control cache size, time, and behavior */
|
|
48
|
+
options: LimitedCacheOptionsReadonly;
|
|
49
|
+
/** The values in the cache, stored by key. Will include old keys not yet garbage collected */
|
|
50
|
+
cache: Record<string, ItemType | undefined>;
|
|
51
|
+
/** List of keys that have been set, in chronological order. Used to find cache items most likely to be expired */
|
|
52
|
+
keyList: Array<string>;
|
|
53
|
+
/** The [setTime, expirationTime] for each key that has been set. Removed on unset. */
|
|
54
|
+
keyInfo: Record<string, [number, number] | undefined>;
|
|
55
|
+
/** Number of operations remaining until internal cleanup of old keys is performed. Based on options.opLimit */
|
|
56
|
+
opsLeft: number;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC,MAAM,WAAW,uBAAuB;IACtC,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,wGAAwG;IACxG,YAAY,EAAE,MAAM,CAAC;IAErB,4JAA4J;IAC5J,0BAA0B,EAAE,MAAM,CAAC;IACnC,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,2HAA2H;IAC3H,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;AAC1E,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC,uBAAuB,CAAC,CAAC;AAE5E,MAAM,WAAW,oBAAoB,CAAC,QAAQ,GAAG,eAAe;IAC9D,uDAAuD;IACvD,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;IAChD,mCAAmC;IACnC,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvC,gFAAgF;IAChF,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,8EAA8E;IAC9E,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,QAAQ,CAAC;IACpD,6DAA6D;IAC7D,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,yDAAyD;IACzD,KAAK,EAAE,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,kGAAkG;IAClG,YAAY,EAAE,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC/C,wDAAwD;IACxD,UAAU,EAAE,MAAM,uBAAuB,CAAC;IAC1C,gDAAgD;IAChD,UAAU,EAAE,CAAC,UAAU,EAAE,mBAAmB,KAAK,2BAA2B,CAAC;IAC7E,mEAAmE;IACnE,aAAa,EAAE,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,0BAA0B,CAAC,QAAQ,GAAG,eAAe;IACpE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,eAAe;IAC1D,qGAAqG;IACrG,uBAAuB,EAAE,MAAM,CAAC;IAChC,wDAAwD;IACxD,OAAO,EAAE,2BAA2B,CAAC;IACrC,8FAA8F;IAC9F,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;IAC5C,kHAAkH;IAClH,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,+GAA+G;IAC/G,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "limited-cache",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A minimal JS cache: like using an object, except it won't grow forever",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"limited cache",
|
|
@@ -14,104 +14,112 @@
|
|
|
14
14
|
"autoexpire"
|
|
15
15
|
],
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"homepage": "https://github.com/spautz/limited-cache#readme",
|
|
17
|
+
"homepage": "https://github.com/spautz/limited-cache/tree/main/packages/limited-cache#readme",
|
|
18
18
|
"bugs": "https://github.com/spautz/limited-cache/issues",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/spautz/limited-cache.git"
|
|
21
|
+
"url": "git+https://github.com/spautz/limited-cache.git",
|
|
22
|
+
"directory": "packages/limited-cache"
|
|
22
23
|
},
|
|
23
24
|
"author": {
|
|
24
25
|
"name": "Steven Pautz",
|
|
25
|
-
"url": "
|
|
26
|
+
"url": "https://github.com/spautz"
|
|
26
27
|
},
|
|
27
28
|
"publishConfig": {
|
|
28
29
|
"access": "public",
|
|
30
|
+
"provenance": true,
|
|
29
31
|
"tag": "next"
|
|
30
32
|
},
|
|
31
33
|
"files": [
|
|
32
34
|
"dist/",
|
|
35
|
+
"docs/",
|
|
33
36
|
"legacy-types/",
|
|
34
37
|
"src/",
|
|
35
38
|
"LICENSE",
|
|
36
39
|
"*.md"
|
|
37
40
|
],
|
|
38
|
-
"source": "src/index.ts",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"____ LIFECYCLE HOOKS _______________________________________________": "",
|
|
50
|
-
"prepare": "yon run build && husky install",
|
|
51
|
-
"prerelease": "yon run build:clean",
|
|
52
|
-
"prepublishOnly": "yarn run dev:readonly && yarn run build",
|
|
53
|
-
"____ INTEGRATION ___________________________________________________": "",
|
|
54
|
-
"clean": "yon run build:clean && yon run test:clean && rimraf ./node_modules/.cache/ *.log",
|
|
55
|
-
"dev": "yon run format && yon run types && yon run lint",
|
|
56
|
-
"dev:readonly": "yon run format:verify && yon run types && yon run lint",
|
|
57
|
-
"all": "yon run clean && yon run dev && yon run test:coverage && yon run build",
|
|
58
|
-
"all:readonly": "yon run dev:readonly && yon run test:coverage",
|
|
59
|
-
"____ ALIASES _______________________________________________________": "",
|
|
60
|
-
"test": "yon run test:coverage",
|
|
61
|
-
"____ INDIVIDUAL COMMANDS ___________________________________________": "",
|
|
62
|
-
"build": "yon run build:clean && yon run build:main && yon run build:verify && yon run build:types",
|
|
63
|
-
"build:clean": "rimraf ./dist ./legacy-types",
|
|
64
|
-
"build:main": "tsdx build",
|
|
65
|
-
"build:types": "yon run build:types:3.x && yon run build:types:4.x",
|
|
66
|
-
"build:types:3.x": "downlevel-dts ./dist ./legacy-types/ts3.x/dist --to=3.0",
|
|
67
|
-
"build:types:4.x": "downlevel-dts ./dist ./dist --to=4.0",
|
|
68
|
-
"build:verify": "node ./scripts/verify-build.js",
|
|
69
|
-
"build:watch": "tsdx watch",
|
|
70
|
-
"format": "prettier --write \"**/*.*\"",
|
|
71
|
-
"format:verify": "prettier --list-different \"**/*.*\"",
|
|
72
|
-
"lint": "tsdx lint . --max-warnings 0",
|
|
73
|
-
"lint-staged": "lint-staged",
|
|
74
|
-
"release:changelog": "standard-version --skip.commit --skip.tag --release-as ",
|
|
75
|
-
"release:tag": "standard-version --commit-all --sign --skip.changelog --release-as ",
|
|
76
|
-
"test:clean": "rimraf ./coverage",
|
|
77
|
-
"test:coverage": "yon run test:clean && tsdx test --coverage",
|
|
78
|
-
"test:nowatch": "yon run test:clean && tsdx test",
|
|
79
|
-
"test:watch": "yon run test:clean && tsdx test --watch",
|
|
80
|
-
"test:watchcoverage": "yon run test:clean && tsdx test --watchAll --coverage",
|
|
81
|
-
"types": "tsc --noEmit --p tsconfig.json"
|
|
41
|
+
"source": "./src/index.ts",
|
|
42
|
+
"type": "module",
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "./dist/index.js",
|
|
46
|
+
"require": "./dist/index.cjs",
|
|
47
|
+
"types": "./dist/index.d.ts"
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
82
50
|
},
|
|
51
|
+
"main": "./dist/index.cjs",
|
|
52
|
+
"module": "./dist/index.js",
|
|
53
|
+
"jsnext:main": "./dist/index.js",
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"sideEffects": false,
|
|
83
56
|
"dependencies": {},
|
|
84
57
|
"devDependencies": {
|
|
85
|
-
"@types/
|
|
86
|
-
"@types/node": "16.11.4",
|
|
87
|
-
"downlevel-dts": "0.7.0",
|
|
88
|
-
"husky": "7.0.4",
|
|
89
|
-
"lint-staged": "11.2.3",
|
|
90
|
-
"rimraf": "3.0.2",
|
|
91
|
-
"standard-version": "9.3.2",
|
|
92
|
-
"tsdx": "0.14.1",
|
|
93
|
-
"typescript": "4.4.4",
|
|
94
|
-
"yarn-or-npm": "3.0.1"
|
|
95
|
-
},
|
|
96
|
-
"resolutions": {
|
|
97
|
-
"**/@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
98
|
-
"**/@typescript-eslint/parser": "^4.33.0"
|
|
58
|
+
"@types/node": "20.1.1"
|
|
99
59
|
},
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
60
|
+
"peerDependencies": {},
|
|
61
|
+
"size-limit": [
|
|
62
|
+
{
|
|
63
|
+
"path": "dist/index.js",
|
|
64
|
+
"import": "{}",
|
|
65
|
+
"limit": "20 B"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"path": "dist/index.js",
|
|
69
|
+
"limit": "2 kB"
|
|
108
70
|
}
|
|
109
|
-
|
|
71
|
+
],
|
|
110
72
|
"typesVersions": {
|
|
111
|
-
"<4": {
|
|
73
|
+
"<4.0": {
|
|
112
74
|
"*": [
|
|
113
|
-
"legacy-types/ts3.
|
|
75
|
+
"legacy-types/ts3.5/index.d.ts"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"<4.5": {
|
|
79
|
+
"*": [
|
|
80
|
+
"legacy-types/ts4.0/index.d.ts"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
"<4.7": {
|
|
84
|
+
"*": [
|
|
85
|
+
"legacy-types/ts4.5/index.d.ts"
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"*": {
|
|
89
|
+
"*": [
|
|
90
|
+
"dist/index.d.ts"
|
|
114
91
|
]
|
|
115
92
|
}
|
|
93
|
+
},
|
|
94
|
+
"scripts": {
|
|
95
|
+
"____ HOOKS _________________________________________________________": "",
|
|
96
|
+
"____ INTEGRATION ___________________________________________________": "",
|
|
97
|
+
"clean": "pnpm run build:clean && pnpm run test:clean && rimraf --glob ./node_modules/.cache *.log",
|
|
98
|
+
"all": "pnpm run format && pnpm run typecheck && pnpm run lint:fix && pnpm run test:coverage && pnpm run build",
|
|
99
|
+
"all:readonly": "pnpm run format:verify && pnpm run typecheck && pnpm run lint && pnpm run test:quick",
|
|
100
|
+
"all:quick": "pnpm run format && pnpm run typecheck && pnpm run lint:fix",
|
|
101
|
+
"all:ci": "pnpm run format:verify && pnpm run typecheck && pnpm run lint && pnpm run test:ci && pnpm run build",
|
|
102
|
+
"____ INDIVIDUAL COMMANDS ___________________________________________": "",
|
|
103
|
+
"build": "pnpm run build:main && pnpm run sizecheck && pnpm run build:legacytypes",
|
|
104
|
+
"build:clean": "rimraf ./dist ./legacy-types",
|
|
105
|
+
"build:main": "pnpm run build:clean && tsup src/index.ts --format cjs && tsc -p ./tsconfig.build.json",
|
|
106
|
+
"build:legacytypes": "pnpm run build:legacytypes:3.5 && pnpm run build:legacytypes:4.0 && pnpm run build:legacytypes:4.5",
|
|
107
|
+
"build:legacytypes:3.5": "downlevel-dts ./dist ./legacy-types/ts3.5 --to=3.5",
|
|
108
|
+
"build:legacytypes:4.0": "downlevel-dts ./dist ./legacy-types/ts4.0 --to=4.0",
|
|
109
|
+
"build:legacytypes:4.5": "downlevel-dts ./dist ./legacy-types/ts4.5 --to=4.5",
|
|
110
|
+
"build:watch": "pnpm run build:clean && tsup src/index.ts --format esm,cjs --dts --watch",
|
|
111
|
+
"format": "prettier --write .",
|
|
112
|
+
"format:verify": "prettier --list-different .",
|
|
113
|
+
"lint": "eslint . --max-warnings 0",
|
|
114
|
+
"lint:fix": "eslint . --max-warnings 0 --fix",
|
|
115
|
+
"sizecheck": "size-limit",
|
|
116
|
+
"test": "pnpm run test:coverage",
|
|
117
|
+
"test:clean": "rimraf ./coverage",
|
|
118
|
+
"test:ci": "pnpm run test:clean && vitest run --coverage",
|
|
119
|
+
"test:coverage": "pnpm run test:clean && vitest run --coverage",
|
|
120
|
+
"test:quick": "pnpm run test:clean && vitest run --coverage=false",
|
|
121
|
+
"test:watch": "pnpm run test:clean && vitest watch --coverage=false",
|
|
122
|
+
"test:watchcoverage": "pnpm run test:clean && vitest watch --coverage",
|
|
123
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit"
|
|
116
124
|
}
|
|
117
|
-
}
|
|
125
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultOptions } from '../core/defaultOptions';
|
|
3
|
-
import { LimitedCache } from '../core/LimitedCache';
|
|
4
|
-
import { LimitedCacheInstance } from '../types';
|
|
1
|
+
import { describe, beforeEach, expect, it } from 'vitest';
|
|
2
|
+
import { defaultOptions } from '../core/defaultOptions.js';
|
|
3
|
+
import { LimitedCache } from '../core/LimitedCache.js';
|
|
4
|
+
import { LimitedCacheInstance } from '../types.js';
|
|
5
5
|
|
|
6
6
|
describe('LimitedCache', () => {
|
|
7
7
|
it('initializes without options', () => {
|
|
@@ -23,9 +23,9 @@ describe('LimitedCache', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
describe('works as a standard cache', () => {
|
|
26
|
-
let myCache: LimitedCacheInstance<
|
|
26
|
+
let myCache: LimitedCacheInstance<number | undefined>;
|
|
27
27
|
beforeEach(() => {
|
|
28
|
-
myCache = LimitedCache<
|
|
28
|
+
myCache = LimitedCache<number | undefined>();
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it('has: when missing', () => {
|
|
@@ -115,9 +115,9 @@ describe('LimitedCache', () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
describe('provides functions for managing options and meta', () => {
|
|
118
|
-
let myCache: LimitedCacheInstance<
|
|
118
|
+
let myCache: LimitedCacheInstance<unknown>;
|
|
119
119
|
beforeEach(() => {
|
|
120
|
-
myCache = LimitedCache<
|
|
120
|
+
myCache = LimitedCache<unknown>();
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
it('getCacheMeta', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultOptions } from '../core/defaultOptions';
|
|
3
|
-
import { LimitedCacheObject, getCacheMetaFromObject } from '../core/LimitedCacheObject';
|
|
4
|
-
import { LimitedCacheObjectInstance } from '../types';
|
|
1
|
+
import { describe, beforeEach, expect, it } from 'vitest';
|
|
2
|
+
import { defaultOptions } from '../core/defaultOptions.js';
|
|
3
|
+
import { LimitedCacheObject, getCacheMetaFromObject } from '../core/LimitedCacheObject.js';
|
|
4
|
+
import { LimitedCacheObjectInstance } from '../types.js';
|
|
5
5
|
|
|
6
6
|
describe('LimitedCacheObject', () => {
|
|
7
7
|
it('initializes without options', () => {
|
|
@@ -23,9 +23,9 @@ describe('LimitedCacheObject', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
describe('look like a standard object', () => {
|
|
26
|
-
let myCache: LimitedCacheObjectInstance<
|
|
26
|
+
let myCache: LimitedCacheObjectInstance<number>;
|
|
27
27
|
beforeEach(() => {
|
|
28
|
-
myCache = LimitedCacheObject<
|
|
28
|
+
myCache = LimitedCacheObject<number>();
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it('has: when missing, via prototype hasOwnProperty', () => {
|
|
@@ -34,6 +34,7 @@ describe('LimitedCacheObject', () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
it('has: when missing, via local hasOwnProperty', () => {
|
|
37
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
37
38
|
const result = myCache.hasOwnProperty('asdf');
|
|
38
39
|
expect(result).toEqual(false);
|
|
39
40
|
});
|
|
@@ -53,6 +54,7 @@ describe('LimitedCacheObject', () => {
|
|
|
53
54
|
it('has: when present, via local hasOwnProperty', () => {
|
|
54
55
|
myCache.abc = 123;
|
|
55
56
|
|
|
57
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
56
58
|
const result = myCache.hasOwnProperty('abc');
|
|
57
59
|
expect(result).toEqual(true);
|
|
58
60
|
});
|
|
@@ -132,7 +134,7 @@ describe('LimitedCacheObject', () => {
|
|
|
132
134
|
});
|
|
133
135
|
});
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
it('offers a way to get the cacheMeta', () => {
|
|
136
138
|
const myCache = LimitedCacheObject<number>();
|
|
137
139
|
const result = getCacheMetaFromObject(myCache);
|
|
138
140
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultOptions } from '../core/defaultOptions';
|
|
1
|
+
import { describe, beforeEach, expect, it, vitest } from 'vitest';
|
|
2
|
+
import { defaultOptions } from '../core/defaultOptions.js';
|
|
3
3
|
import {
|
|
4
4
|
isCacheMeta,
|
|
5
5
|
upgradeCacheMeta,
|
|
@@ -10,22 +10,26 @@ import {
|
|
|
10
10
|
lowLevelSet,
|
|
11
11
|
lowLevelRemove,
|
|
12
12
|
lowLevelReset,
|
|
13
|
-
} from '../core/lowLevelFunctions';
|
|
14
|
-
import { LimitedCacheMeta } from '../types';
|
|
13
|
+
} from '../core/lowLevelFunctions.js';
|
|
14
|
+
import { LimitedCacheMeta } from '../types.js';
|
|
15
15
|
|
|
16
16
|
describe('lowLevelFunctions', () => {
|
|
17
17
|
describe('isCacheMeta', () => {
|
|
18
18
|
it('accepts cacheMeta shapes', () => {
|
|
19
19
|
expect(
|
|
20
|
-
// @ts-expect-error
|
|
21
20
|
isCacheMeta({
|
|
22
21
|
limitedCacheMetaVersion: 123,
|
|
22
|
+
options: defaultOptions,
|
|
23
|
+
cache: {},
|
|
24
|
+
keyList: [],
|
|
25
|
+
keyInfo: {},
|
|
26
|
+
opsLeft: 100,
|
|
23
27
|
}),
|
|
24
28
|
).toBe(true);
|
|
25
29
|
});
|
|
26
30
|
it('rejects invalid cacheMeta shapes', () => {
|
|
27
31
|
expect(
|
|
28
|
-
// @ts-expect-error
|
|
32
|
+
// @ts-expect-error Invalid cacheMeta shape
|
|
29
33
|
isCacheMeta({
|
|
30
34
|
cache: {},
|
|
31
35
|
}),
|
|
@@ -35,7 +39,7 @@ describe('lowLevelFunctions', () => {
|
|
|
35
39
|
|
|
36
40
|
describe('upgradeCacheMeta', () => {
|
|
37
41
|
it('warns and upgrades if given an older, incompatible cacheMeta', () => {
|
|
38
|
-
const consoleWarnSpy =
|
|
42
|
+
const consoleWarnSpy = vitest.spyOn(console, 'warn').mockReturnValueOnce();
|
|
39
43
|
|
|
40
44
|
const cacheMeta = lowLevelInit();
|
|
41
45
|
cacheMeta.limitedCacheMetaVersion = 1;
|
|
@@ -49,7 +53,7 @@ describe('lowLevelFunctions', () => {
|
|
|
49
53
|
|
|
50
54
|
it('throws if given an invalid cacheMeta', () => {
|
|
51
55
|
expect(() => {
|
|
52
|
-
// @ts-expect-error
|
|
56
|
+
// @ts-expect-error Invalid cacheMeta shape
|
|
53
57
|
upgradeCacheMeta({
|
|
54
58
|
cache: {},
|
|
55
59
|
});
|
|
@@ -59,7 +63,7 @@ describe('lowLevelFunctions', () => {
|
|
|
59
63
|
|
|
60
64
|
describe('lowLevelInit', () => {
|
|
61
65
|
beforeEach(() => {
|
|
62
|
-
|
|
66
|
+
vitest.restoreAllMocks();
|
|
63
67
|
});
|
|
64
68
|
|
|
65
69
|
it('clones the default options', () => {
|
|
@@ -109,7 +113,7 @@ describe('lowLevelFunctions', () => {
|
|
|
109
113
|
});
|
|
110
114
|
|
|
111
115
|
it('warns and upgrades if given an older, incompatible cacheMeta', () => {
|
|
112
|
-
const consoleWarnSpy =
|
|
116
|
+
const consoleWarnSpy = vitest.spyOn(console, 'warn').mockReturnValueOnce();
|
|
113
117
|
|
|
114
118
|
const existingCacheMeta = lowLevelInit();
|
|
115
119
|
existingCacheMeta.limitedCacheMetaVersion = 1;
|
|
@@ -126,7 +130,7 @@ describe('lowLevelFunctions', () => {
|
|
|
126
130
|
describe('lowLevelHas', () => {
|
|
127
131
|
let myCacheMeta: LimitedCacheMeta;
|
|
128
132
|
beforeEach(() => {
|
|
129
|
-
|
|
133
|
+
vitest.restoreAllMocks();
|
|
130
134
|
myCacheMeta = lowLevelInit({
|
|
131
135
|
maxCacheTime: 1000,
|
|
132
136
|
});
|
|
@@ -157,7 +161,7 @@ describe('lowLevelFunctions', () => {
|
|
|
157
161
|
describe('lowLevelGetOne', () => {
|
|
158
162
|
let myCacheMeta: LimitedCacheMeta;
|
|
159
163
|
beforeEach(() => {
|
|
160
|
-
|
|
164
|
+
vitest.restoreAllMocks();
|
|
161
165
|
myCacheMeta = lowLevelInit({
|
|
162
166
|
maxCacheTime: 1000,
|
|
163
167
|
});
|
|
@@ -192,7 +196,7 @@ describe('lowLevelFunctions', () => {
|
|
|
192
196
|
describe('lowLevelGetAll', () => {
|
|
193
197
|
let myCacheMeta: LimitedCacheMeta;
|
|
194
198
|
beforeEach(() => {
|
|
195
|
-
|
|
199
|
+
vitest.restoreAllMocks();
|
|
196
200
|
myCacheMeta = lowLevelInit({
|
|
197
201
|
maxCacheTime: 1000,
|
|
198
202
|
});
|
|
@@ -243,7 +247,7 @@ describe('lowLevelFunctions', () => {
|
|
|
243
247
|
describe('lowLevelSet', () => {
|
|
244
248
|
let myCacheMeta: LimitedCacheMeta;
|
|
245
249
|
beforeEach(() => {
|
|
246
|
-
|
|
250
|
+
vitest.restoreAllMocks();
|
|
247
251
|
myCacheMeta = lowLevelInit({
|
|
248
252
|
maxCacheTime: 1000,
|
|
249
253
|
});
|
|
@@ -383,7 +387,7 @@ describe('lowLevelFunctions', () => {
|
|
|
383
387
|
describe('lowLevelRemove', () => {
|
|
384
388
|
let myCacheMeta: LimitedCacheMeta;
|
|
385
389
|
beforeEach(() => {
|
|
386
|
-
|
|
390
|
+
vitest.restoreAllMocks();
|
|
387
391
|
myCacheMeta = lowLevelInit();
|
|
388
392
|
myCacheMeta = lowLevelSet(myCacheMeta, 'abc', 123);
|
|
389
393
|
});
|
|
@@ -412,7 +416,7 @@ describe('lowLevelFunctions', () => {
|
|
|
412
416
|
describe('lowLevelReset', () => {
|
|
413
417
|
let myCacheMeta: LimitedCacheMeta;
|
|
414
418
|
beforeEach(() => {
|
|
415
|
-
|
|
419
|
+
vitest.restoreAllMocks();
|
|
416
420
|
myCacheMeta = lowLevelInit();
|
|
417
421
|
myCacheMeta = lowLevelSet(myCacheMeta, 'abc', 123);
|
|
418
422
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { limitedCacheUtil, LimitedCacheMeta } from '../../index';
|
|
1
|
+
import { describe, beforeEach, expect, it } from 'vitest';
|
|
2
|
+
import { limitedCacheUtil, LimitedCacheMeta } from '../../index.js';
|
|
3
3
|
|
|
4
4
|
describe('key names', () => {
|
|
5
5
|
let myCacheMeta: LimitedCacheMeta;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { LimitedCache, LimitedCacheInstance } from '../../index';
|
|
1
|
+
import { describe, beforeEach, expect, it, vitest } from 'vitest';
|
|
2
|
+
import { LimitedCache, LimitedCacheInstance } from '../../index.js';
|
|
3
3
|
|
|
4
4
|
// To avoid race conditions or timing issues, since some expect() checks can take 10+ ms when busy,
|
|
5
5
|
// we use a long cache timeout even for 'immediate' expiration, and use delays slightly longer than that
|
|
@@ -10,7 +10,7 @@ const timeoutPromise = (): Promise<null> =>
|
|
|
10
10
|
describe('maxCacheSize scenarios', () => {
|
|
11
11
|
let myCache: LimitedCacheInstance;
|
|
12
12
|
beforeEach(() => {
|
|
13
|
-
|
|
13
|
+
vitest.restoreAllMocks();
|
|
14
14
|
myCache = LimitedCache({
|
|
15
15
|
maxCacheSize: 20,
|
|
16
16
|
maxCacheTime: Number.MAX_SAFE_INTEGER,
|
|
@@ -103,7 +103,7 @@ describe('maxCacheSize scenarios', () => {
|
|
|
103
103
|
warnIfItemPurgedBeforeTime: 1000,
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
const consoleWarnSpy =
|
|
106
|
+
const consoleWarnSpy = vitest.spyOn(console, 'warn').mockReturnValueOnce();
|
|
107
107
|
|
|
108
108
|
for (let n = 1; n <= 5; n++) {
|
|
109
109
|
myCache.set(`n=${n}`, n);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { LimitedCacheObject, LimitedCacheObjectInstance } from '../../index';
|
|
1
|
+
import { describe, beforeEach, expect, it, vitest } from 'vitest';
|
|
2
|
+
import { LimitedCacheObject, LimitedCacheObjectInstance } from '../../index.js';
|
|
3
3
|
|
|
4
4
|
// To avoid race conditions or timing issues, since some expect() checks can take 10+ ms when busy,
|
|
5
5
|
// we use a long cache timeout even for 'immediate' expiration, and use delays slightly longer than that
|
|
@@ -10,7 +10,7 @@ const timeoutPromise = (): Promise<null> =>
|
|
|
10
10
|
describe('maxCacheTime scenarios', () => {
|
|
11
11
|
let myCache: LimitedCacheObjectInstance;
|
|
12
12
|
beforeEach(() => {
|
|
13
|
-
|
|
13
|
+
vitest.restoreAllMocks();
|
|
14
14
|
myCache = LimitedCacheObject({
|
|
15
15
|
maxCacheTime: CACHE_TIMEOUT,
|
|
16
16
|
maxCacheSize: Number.MAX_SAFE_INTEGER,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { limitedCacheUtil, LimitedCacheMeta } from '../../index';
|
|
1
|
+
import { describe, beforeEach, expect, it } from 'vitest';
|
|
2
|
+
import { limitedCacheUtil, LimitedCacheMeta } from '../../index.js';
|
|
3
3
|
|
|
4
4
|
describe('value types', () => {
|
|
5
5
|
let myCacheMeta: LimitedCacheMeta;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { LimitedCacheObject } from '../../index.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* This is not a source file or test file.
|
|
@@ -59,9 +61,9 @@ value = arrayCache.number as number;
|
|
|
59
61
|
// @ts-expect-error Invalid type
|
|
60
62
|
value = arrayCache.string as string;
|
|
61
63
|
|
|
62
|
-
// Fake test, to make
|
|
64
|
+
// Fake test, to make Vitest happy
|
|
63
65
|
describe('fake typeCheck test', () => {
|
|
64
|
-
it
|
|
66
|
+
it('does nothing', () => null);
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
// Fake export, to make the linter happy
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { LimitedCache } from '../../index.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* This is not a source file or test file.
|
|
@@ -59,9 +61,9 @@ value = arrayCache.get('number') as number;
|
|
|
59
61
|
// @ts-expect-error Invalid type
|
|
60
62
|
value = arrayCache.get('string') as string;
|
|
61
63
|
|
|
62
|
-
// Fake test, to make
|
|
64
|
+
// Fake test, to make Vitest happy
|
|
63
65
|
describe('fake typeCheck test', () => {
|
|
64
|
-
it
|
|
66
|
+
it('does nothing', () => null);
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
// Fake export, to make the linter happy
|