Skip to content

Commit f4b7c05

Browse files
committed
chore: Add cache manager functions and tests
1 parent 569112e commit f4b7c05

File tree

7 files changed

+183
-3062
lines changed

7 files changed

+183
-3062
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

bun.lockb

-97.4 KB
Binary file not shown.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
"module": "index.ts",
55
"type": "module",
66
"devDependencies": {
7-
"@codedependant/semantic-release-docker": "^5.0.3",
87
"@semantic-release/changelog": "^6.0.3",
98
"@semantic-release/commit-analyzer": "^13.0.0",
109
"@semantic-release/git": "^10.0.1",
11-
"@semantic-release/github": "^10.3.2",
10+
"@semantic-release/github": "^10.3.3",
1211
"@semantic-release/npm": "^12.0.1",
1312
"@semantic-release/release-notes-generator": "^14.0.1",
1413
"@types/lodash": "^4.17.7",
1514
"bun-types": "latest",
16-
"jest": "^29.7.0",
17-
"vitest": "^2.0.5",
15+
"cache-manager-ioredis-yet": "^2.1.1",
1816
"xo": "^0.59.3"
1917
},
2018
"peerDependencies": {
@@ -25,8 +23,6 @@
2523
},
2624
"dependencies": {
2725
"cache-manager": "^5.7.6",
28-
"cache-manager-ioredis-yet": "^2.1.1",
29-
"cache-manager-redis-store": "^3.0.1",
3026
"eslint-plugin-th-rules": "^1.13.4",
3127
"lodash": "^4.17.21",
3228
"reflect-metadata": "^0.2.2"

src/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {type ArgumentPaths, type AnyFunction} from './paths.d';
2+
3+
export type CachedFunctionOptions<F extends AnyFunction> = {
4+
selector: ArgumentPaths<F>;
5+
};

src/index.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
console.log('test');
1+
2+
import type {CachedFunctionOptions} from './index.d';
3+
import type {AnyFunction} from './paths.d';
4+
5+
export function cachedFunction<F extends AnyFunction>(function_: F, options: CachedFunctionOptions<F>) {
6+
console.log(options);
7+
return function_;
8+
}
9+
10+
/** TEST */
11+
type Person = {
12+
name: string;
13+
age: number;
14+
address: {
15+
city: string;
16+
zip: number;
17+
};
18+
};
19+
20+
const person: Person = {
21+
name: 'John Doe',
22+
age: 30,
23+
address: {
24+
city: 'New York',
25+
zip: 10_001,
26+
},
27+
};
28+
29+
cachedFunction((person: Person) => person.name, {
30+
selector: person => person.name,
31+
});

src/paths.d.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
4+
import _ from 'lodash';
5+
6+
/**
7+
* Represents a type that can either be a single value of type T or an array of type T.
8+
*
9+
* @typeParam T - The type of the value(s) that can be stored in the SingleOrArray.
10+
*/
11+
export type SingleOrArray<T> = T | T[];
12+
13+
/**
14+
* Represents any function that takes any number of arguments and returns any value.
15+
*/
16+
export type AnyFunction = (...arguments_: any[]) => any;
17+
18+
/**
19+
* Represents the type for generating paths of a given object.
20+
*
21+
* @template T - The type of the object.
22+
*/
23+
export type Paths<T> = T extends Record<string, unknown>
24+
? {[K in keyof T]: `${Exclude<K, symbol>}${'' | `.${Paths<T[K]>}`}`}[keyof T]
25+
: T extends Array<infer U>
26+
? Paths<U> extends string
27+
? `${number}` | `${number}.${Paths<U>}`
28+
: never
29+
: never;
30+
31+
/**
32+
* Represents the paths of the arguments of a given function type.
33+
* @template F - The function type.
34+
* @typeparam F - The function type.
35+
* @typeparam Paths - The paths of the arguments of the function type.
36+
*/
37+
export type ArgumentPaths1<F extends AnyFunction> = SingleOrArray<Paths<Parameters<F>>>;
38+
39+
/**
40+
* Represents a function that takes arguments of type `Parameters<F>` and returns `ArgumentPaths1<F>`.
41+
*/
42+
export type ArgumentPaths2<F extends AnyFunction> = (...arguments_: Parameters<F>) => ArgumentPaths1<F>;
43+
44+
/**
45+
* Represents the argument paths for a given function type.
46+
* @template F - The function type.
47+
*/
48+
export type ArgumentPaths<F extends AnyFunction> = ArgumentPaths1<F> | ArgumentPaths2<F>;

0 commit comments

Comments
 (0)