Skip to content

Commit 2554a81

Browse files
committed
feat: improve types
1 parent e1b7fd1 commit 2554a81

29 files changed

Lines changed: 1388 additions & 1711 deletions

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ Welcome to DeepCover, the ultimate tool for maximizing your test coverage! 🌟
2929
### Playground
3030

3131
- [ ] Add in browser playground
32+
33+
### Heads up
34+
35+
- VSCode built-in TypeScript SDK has stricter limits; To avoid excessive depth errors, use `node_modules` SDK

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default [
7777
'import/no-dynamic-require': 'error',
7878
'import/newline-after-import': 'error',
7979
'import/first': 'error',
80-
'import/exports-last': 'error',
80+
'import/exports-last': 'off',
8181
},
8282
},
8383
];

package-lock.json

Lines changed: 953 additions & 1212 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
"scripts": {
88
"start": "node --import @swc-node/register/esm-register",
99
"test": "vitest --watch",
10-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
10+
"lint": "eslint \"packages/**/{src,apps,libs,test}/**/*.ts\" --fix",
1111
"eslint:inspect": "npx @eslint/config-inspector"
1212
},
1313
"author": "ebrahimmfadae@gmail.com",
1414
"license": "MIT",
1515
"devDependencies": {
16-
"@eslint/js": "^9.24.0",
17-
"@swc-node/register": "^1.10.10",
18-
"@types/node": "^22.9.0",
19-
"@vitest/coverage-v8": "^3.1.1",
20-
"eslint-config-prettier": "^10.1.2",
21-
"eslint-plugin-import": "^2.31.0",
22-
"eslint-plugin-prettier": "^5.2.6",
23-
"globals": "^15.12.0",
24-
"prettier": "^3.5.3",
25-
"typescript": "^5.8.3",
26-
"typescript-eslint": "^8.30.1",
16+
"@eslint/js": "^9.38.0",
17+
"@swc-node/register": "^1.11.1",
18+
"@types/node": "^24.9.2",
19+
"@vitest/coverage-v8": "^4.0.5",
20+
"eslint-config-prettier": "^10.1.8",
21+
"eslint-plugin-import": "^2.32.0",
22+
"eslint-plugin-prettier": "^5.5.4",
23+
"globals": "^16.4.0",
24+
"prettier": "^3.6.2",
25+
"typescript": "^5.9.3",
26+
"typescript-eslint": "^8.46.2",
2727
"unplugin-swc": "^1.5.1",
28-
"vitest": "^3.1.1"
28+
"vitest": "^4.0.5"
2929
},
3030
"workspaces": [
3131
"packages/*"

packages/deepcover/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deepcover",
3-
"version": "0.1.0-alpha.6",
3+
"version": "0.1.0-alpha.7",
44
"description": "",
55
"type": "module",
66
"scripts": {
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
export type Structure = 'array' | 'pojo' | 'mixed' | 'primitive';
22
export type Permutation<T = unknown> = Iterable<T>;
33
export type UnwrapPermutation<T extends Permutation> = T extends Permutation<infer U> ? U : never;
4-
export type PermutationGenerator<out T extends Permutation = Permutation> = {
5-
readonly size: number;
6-
readonly originalInputArg: unknown;
4+
export interface PermutationPatch {
5+
readonly size: bigint;
6+
readonly originalInputArg?: unknown;
77
readonly type: string;
88
readonly structure: Structure;
99
/**
1010
* Modifiers are like meta-data that are used only by consumers
1111
* All modifiers should be idempotent
1212
* All modifiers are meant to be used by top level structures
1313
*/
14-
readonly modifiers: string[];
14+
readonly modifiers: readonly string[];
1515
readonly permutationPaths: readonly string[];
1616
readonly primitivePermutationPaths: readonly string[];
17-
extract: (paths: readonly string[]) => PermutationGenerator;
18-
exclude: (paths: readonly string[]) => PermutationGenerator;
19-
generatorAt: (path: string) => PermutationGenerator;
20-
override: (v: PermutationGenerator) => PermutationGenerator;
17+
readonly extract: (paths: readonly string[]) => PermutationGenerator;
18+
readonly exclude: (paths: readonly string[]) => PermutationGenerator;
19+
readonly generatorAt: (path: string) => PermutationGenerator;
20+
readonly override: (v: PermutationGenerator) => PermutationGenerator;
21+
}
22+
export interface PermutationGenerator<out T extends Permutation = Permutation>
23+
extends PermutationPatch {
2124
(): T;
22-
};
25+
}
2326
export type UnwrapPermutationGenerator<T extends PermutationGenerator> =
2427
T extends PermutationGenerator<infer P> ? P : never;
Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
1-
import type {
2-
PermutationGenerator,
3-
UnwrapPermutationGenerator,
4-
} from '#src/permutation/definitions';
1+
import type { PermutationGenerator } from '#src/permutation/definitions';
2+
import type { CleanPatch, Clean } from '#src/permutation/modifiers/clean.types';
53

6-
export type CleanGenerator<out T extends PermutationGenerator = PermutationGenerator> =
7-
() => Iterable<UnwrapPermutationGenerator<T>>;
8-
9-
export type CleanPatch<T extends PermutationGenerator = PermutationGenerator> = {
10-
readonly size: T['size'];
11-
readonly modifiers: [];
12-
readonly originalInputArg: T;
13-
readonly type: T['type'];
14-
readonly structure: T['structure'];
15-
readonly permutationPaths: readonly string[];
16-
readonly primitivePermutationPaths: readonly string[];
17-
extract: (paths: readonly string[]) => PermutationGenerator;
18-
exclude: (paths: readonly string[]) => PermutationGenerator;
19-
generatorAt: (path: string) => PermutationGenerator;
20-
override: (v: PermutationGenerator) => PermutationGenerator;
21-
};
22-
23-
export function clean<const T extends PermutationGenerator>(
24-
input: T,
25-
): CleanGenerator<T> & CleanPatch {
26-
if (isClean(input)) return input as CleanGenerator<T> & CleanPatch;
27-
const modifiers = [] as [];
4+
export function clean<const T extends PermutationGenerator>(input: T): Clean<T> {
5+
if (isClean(input)) return input as unknown as Clean<T>;
286
return Object.assign(
297
function* () {
308
yield* input();
31-
} as CleanGenerator<T>,
9+
},
3210
{
3311
get size() {
3412
return input.size;
3513
},
3614
get modifiers() {
37-
return modifiers;
15+
return [] as readonly never[];
3816
},
3917
get originalInputArg() {
40-
return input.originalInputArg as PermutationGenerator;
18+
return input.originalInputArg as T;
4119
},
4220
get type() {
4321
return input.type;
@@ -63,10 +41,10 @@ export function clean<const T extends PermutationGenerator>(
6341
override(v) {
6442
return input.override(v);
6543
},
66-
} satisfies CleanPatch & ThisType<CleanGenerator<T> & CleanPatch>,
67-
) as CleanGenerator<T> & CleanPatch;
44+
} satisfies CleanPatch<T> & ThisType<T>,
45+
) as Clean<T>;
6846
}
6947

70-
export function isClean(v: PermutationGenerator): v is CleanGenerator & CleanPatch {
48+
export function isClean(v: PermutationGenerator): v is Clean {
7149
return v.modifiers.length === 0;
7250
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type {
2+
PermutationGenerator,
3+
PermutationPatch,
4+
UnwrapPermutationGenerator,
5+
} from '#src/permutation/definitions';
6+
7+
export type CleanGenerator<out T extends PermutationGenerator> = () => Iterable<
8+
UnwrapPermutationGenerator<T>
9+
>;
10+
11+
export interface CleanPatch<T extends PermutationGenerator> extends PermutationPatch {
12+
readonly size: T['size'];
13+
readonly modifiers: readonly never[];
14+
readonly originalInputArg: T;
15+
readonly type: T['type'];
16+
readonly structure: T['structure'];
17+
readonly permutationPaths: readonly string[];
18+
readonly primitivePermutationPaths: readonly string[];
19+
readonly extract: (paths: readonly string[]) => PermutationGenerator;
20+
readonly exclude: (paths: readonly string[]) => PermutationGenerator;
21+
readonly generatorAt: (path: string) => PermutationGenerator;
22+
readonly override: (v: PermutationGenerator) => PermutationGenerator;
23+
}
24+
25+
export interface Clean<T extends PermutationGenerator = PermutationGenerator>
26+
extends CleanGenerator<T>,
27+
CleanPatch<T> {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from '#src/permutation/modifiers/optional';
1+
export { optional } from '#src/permutation/modifiers/optional';
Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,18 @@
1+
import type { PermutationGenerator } from '#src/permutation/definitions';
12
import type {
2-
PermutationGenerator,
3-
UnwrapPermutation,
4-
UnwrapPermutationGenerator,
5-
} from '#src/permutation/definitions';
3+
AppendModifier,
4+
Optional,
5+
OptionalPatch,
6+
} from '#src/permutation/modifiers/optional.types';
67
import { merge } from '#src/permutation/utils';
7-
import type { CastAsPermutationGenerator } from '#src/utils/casting';
88

9-
type UnwrapValue<T> = UnwrapPermutation<UnwrapPermutationGenerator<CastAsPermutationGenerator<T>>>;
10-
11-
export type OptionalGenerator<out T extends PermutationGenerator = PermutationGenerator> =
12-
() => Iterable<UnwrapValue<T>>;
13-
14-
export type OptionalPatch<T extends PermutationGenerator = PermutationGenerator> = {
15-
readonly size: T['size'];
16-
readonly modifiers: 'optional' extends T['modifiers'][number]
17-
? T['modifiers']
18-
: ['optional', ...T['modifiers']];
19-
readonly originalInputArg: T;
20-
readonly type: T['type'];
21-
readonly structure: T['structure'];
22-
readonly permutationPaths: readonly string[];
23-
readonly primitivePermutationPaths: readonly string[];
24-
extract: (paths: readonly string[]) => PermutationGenerator;
25-
exclude: (paths: readonly string[]) => PermutationGenerator;
26-
generatorAt: (path: string) => PermutationGenerator;
27-
override: (v: PermutationGenerator) => PermutationGenerator;
28-
};
29-
30-
export function optional<const T extends PermutationGenerator>(
31-
input: T,
32-
): OptionalGenerator<T> & OptionalPatch<T> {
33-
if (isOptional(input)) return input as unknown as OptionalGenerator<T> & OptionalPatch<T>;
34-
const modifiers = ['optional', ...input.modifiers];
9+
export function optional<const T extends PermutationGenerator>(input: T): Optional<T> {
10+
if (isOptional(input)) return input as unknown as Optional<T>;
11+
const modifiers = ['optional', ...input.modifiers] as AppendModifier<T['modifiers']>;
3512
return Object.assign(
3613
function* () {
3714
yield* input();
38-
} as OptionalGenerator<T>,
15+
},
3916
{
4017
get size() {
4118
return input.size;
@@ -44,7 +21,7 @@ export function optional<const T extends PermutationGenerator>(
4421
return modifiers;
4522
},
4623
get originalInputArg() {
47-
return input.originalInputArg as PermutationGenerator;
24+
return input.originalInputArg as T;
4825
},
4926
get type() {
5027
return input.type;
@@ -70,10 +47,10 @@ export function optional<const T extends PermutationGenerator>(
7047
override(v) {
7148
return merge(this, v);
7249
},
73-
} satisfies OptionalPatch & ThisType<OptionalGenerator<T> & OptionalPatch<T>>,
74-
) as OptionalGenerator<T> & OptionalPatch<T>;
50+
} satisfies OptionalPatch<T> & ThisType<Optional<T>>,
51+
) as Optional<T>;
7552
}
7653

77-
export function isOptional(v: PermutationGenerator): v is OptionalGenerator & OptionalPatch {
54+
export function isOptional(v: PermutationGenerator): v is Optional {
7855
return v.modifiers.includes('optional');
7956
}

0 commit comments

Comments
 (0)