struct-fakerator 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/package.json +8 -2
- package/src/create_generator_fn.test.ts +15 -0
- package/src/create_generator_fn.ts +124 -38
- package/.babelrc +0 -5
- package/dist/index.d.mts +0 -87
- package/dist/index.d.ts +0 -87
- package/dist/index.js +0 -5820
- package/dist/index.mjs +0 -5782
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "struct-fakerator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
8
14
|
"scripts": {
|
|
9
15
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
10
16
|
"test": "vitest src"
|
|
@@ -18,7 +24,7 @@
|
|
|
18
24
|
"@faker-js/faker": "^8.4.1",
|
|
19
25
|
"tsup": "^8.1.0",
|
|
20
26
|
"typescript": "^5.5.3",
|
|
21
|
-
"vitest": "^
|
|
27
|
+
"vitest": "^2.0.3"
|
|
22
28
|
},
|
|
23
29
|
"dependencies": {
|
|
24
30
|
"zod": "^3.23.8"
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
createObjectConfig,
|
|
15
15
|
createArrayConfig,
|
|
16
16
|
} from "./create_config";
|
|
17
|
+
import type { ObjectConfig } from "./type";
|
|
17
18
|
|
|
18
19
|
describe("createValueGenerator", () => {
|
|
19
20
|
test("normal", () => {
|
|
@@ -155,6 +156,20 @@ describe("createGeneratorByType", () => {
|
|
|
155
156
|
});
|
|
156
157
|
});
|
|
157
158
|
|
|
159
|
+
test("test error config", () => {
|
|
160
|
+
const config = {
|
|
161
|
+
type: "obj",
|
|
162
|
+
content: {
|
|
163
|
+
name: {
|
|
164
|
+
type: "123",
|
|
165
|
+
generateFn: "John",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
} as ObjectConfig<unknown>;
|
|
169
|
+
|
|
170
|
+
expect(() => createGeneratorByType(config)).toThrowError();
|
|
171
|
+
});
|
|
172
|
+
|
|
158
173
|
test("with custom type match", () => {
|
|
159
174
|
const createIntValueConfig = (option) => createValueConfig(() => 50);
|
|
160
175
|
const createEmailValueConfig = (option) =>
|
|
@@ -17,7 +17,6 @@ import type {
|
|
|
17
17
|
Result,
|
|
18
18
|
BoundedSeriesConfig,
|
|
19
19
|
} from "./type";
|
|
20
|
-
import { createObjectConfig, createValueConfig } from "./create_config";
|
|
21
20
|
|
|
22
21
|
type AllConfig<T> =
|
|
23
22
|
| ValueConfig<T>
|
|
@@ -31,33 +30,60 @@ type AllConfig<T> =
|
|
|
31
30
|
| TupleConfig<T, T, T, T, T>
|
|
32
31
|
| BoundedSeriesConfig;
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const _createValueGenerator = <R = unknown>(
|
|
34
|
+
config: ValueConfig<unknown>,
|
|
35
|
+
path: string,
|
|
36
|
+
): (() => R) => {
|
|
37
|
+
try {
|
|
38
|
+
valueConfigScheme.parse(config);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
throw new Error(`config path: ${path}.value\n${err}`);
|
|
41
|
+
}
|
|
37
42
|
|
|
38
43
|
return config.generateFn as () => R;
|
|
39
44
|
};
|
|
45
|
+
export const createValueGenerator = <R = unknown>(
|
|
46
|
+
config: ValueConfig<unknown>,
|
|
47
|
+
): (() => R) => _createValueGenerator(config, "*");
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
// =================== generator fn ====================
|
|
50
|
+
|
|
51
|
+
const _createSelectionGenerator = <T extends SelectionConfig<unknown>>(
|
|
42
52
|
config: T,
|
|
53
|
+
path: string,
|
|
43
54
|
): (() => Result<T>) => {
|
|
44
|
-
|
|
55
|
+
try {
|
|
56
|
+
selectionConfigScheme.parse(config);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
throw new Error(`config path: ${path}.select\n${err}`);
|
|
59
|
+
}
|
|
45
60
|
|
|
46
61
|
const { items } = config;
|
|
47
62
|
|
|
48
63
|
return (() => items[faker.number.int(items.length - 1)]) as () => Result<T>;
|
|
49
64
|
};
|
|
50
65
|
|
|
51
|
-
export const
|
|
66
|
+
export const createSelectionGenerator = <T extends SelectionConfig<unknown>>(
|
|
52
67
|
config: T,
|
|
53
|
-
|
|
68
|
+
): (() => Result<T>) => _createSelectionGenerator(config, "*");
|
|
69
|
+
|
|
70
|
+
// =================== generator fn ====================
|
|
71
|
+
|
|
72
|
+
const _createObjectGenerator = <T extends ObjectConfig<unknown>>(
|
|
73
|
+
config: T,
|
|
74
|
+
path: string,
|
|
75
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
54
76
|
): (() => Result<T>) => {
|
|
55
|
-
|
|
77
|
+
try {
|
|
78
|
+
objConfigScheme.parse(config);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
throw new Error(`config path: ${path}.obj\n ${err}`);
|
|
81
|
+
}
|
|
56
82
|
|
|
57
83
|
const keyWithFns: [string, () => Result<AllConfig<unknown>>][] =
|
|
58
84
|
Object.entries(config.content as object).map(([key, subConfig]) => [
|
|
59
85
|
key,
|
|
60
|
-
|
|
86
|
+
_createGeneratorByType(subConfig, `${path}.obj[${key}]`, customTypeMatch),
|
|
61
87
|
]);
|
|
62
88
|
|
|
63
89
|
return () => {
|
|
@@ -68,23 +94,41 @@ export const createObjectGenerator = <T extends ObjectConfig<unknown>>(
|
|
|
68
94
|
return result as Result<T>;
|
|
69
95
|
};
|
|
70
96
|
};
|
|
97
|
+
export const createObjectGenerator = <T extends ObjectConfig<unknown>>(
|
|
98
|
+
config: T,
|
|
99
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
100
|
+
): (() => Result<T>) => _createObjectGenerator(config, "*", customTypeMatch);
|
|
71
101
|
|
|
72
|
-
|
|
102
|
+
// =================== generator fn ====================
|
|
103
|
+
|
|
104
|
+
const _createArrayGenerator = <T extends ArrayConfig<unknown>>(
|
|
73
105
|
config: T,
|
|
74
|
-
|
|
106
|
+
path: string,
|
|
107
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
75
108
|
): (() => Result<T>) => {
|
|
76
|
-
|
|
109
|
+
try {
|
|
110
|
+
arrayConfigScheme.parse(config);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
throw new Error(`config path: ${path}.arr\n ${err}`);
|
|
113
|
+
}
|
|
77
114
|
|
|
78
|
-
const itemGeneratorFn =
|
|
115
|
+
const itemGeneratorFn = _createGeneratorByType(
|
|
79
116
|
config.item as AllConfig<unknown>,
|
|
117
|
+
`${path}.arr`,
|
|
80
118
|
customTypeMatch,
|
|
81
119
|
);
|
|
82
120
|
|
|
83
121
|
return () =>
|
|
84
122
|
Array.from({ length: config.len ?? 0 }, itemGeneratorFn) as Result<T>;
|
|
85
123
|
};
|
|
124
|
+
export const createArrayGenerator = <T extends ArrayConfig<unknown>>(
|
|
125
|
+
config: T,
|
|
126
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
127
|
+
): (() => Result<T>) => _createArrayGenerator(config, "*", customTypeMatch);
|
|
86
128
|
|
|
87
|
-
|
|
129
|
+
// =================== generator fn ====================
|
|
130
|
+
|
|
131
|
+
const _createTupleGenerator = <
|
|
88
132
|
T extends
|
|
89
133
|
| TupleConfig<unknown, unknown, unknown, unknown, unknown>
|
|
90
134
|
| TupleConfig<unknown, unknown, unknown, unknown>
|
|
@@ -93,21 +137,48 @@ export const createTupleGenerator = <
|
|
|
93
137
|
| TupleConfig<unknown>,
|
|
94
138
|
>(
|
|
95
139
|
config: T,
|
|
96
|
-
|
|
140
|
+
path: string,
|
|
141
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
97
142
|
): (() => Result<T>) => {
|
|
98
|
-
|
|
143
|
+
try {
|
|
144
|
+
tupleConfigScheme.parse(config);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
throw new Error(`config path: ${path}.tuple\n ${err}`);
|
|
147
|
+
}
|
|
99
148
|
|
|
100
|
-
const itemsFns = config.configItems.map((configItem) =>
|
|
101
|
-
|
|
149
|
+
const itemsFns = config.configItems.map((configItem, index) =>
|
|
150
|
+
_createGeneratorByType(
|
|
151
|
+
configItem as AllConfig<unknown>,
|
|
152
|
+
`${path}.tuple[${index}]`,
|
|
153
|
+
customTypeMatch,
|
|
154
|
+
),
|
|
102
155
|
);
|
|
103
156
|
|
|
104
157
|
return () => itemsFns.map((generateFn) => generateFn()) as Result<T>;
|
|
105
158
|
};
|
|
159
|
+
export const createTupleGenerator = <
|
|
160
|
+
T extends
|
|
161
|
+
| TupleConfig<unknown, unknown, unknown, unknown, unknown>
|
|
162
|
+
| TupleConfig<unknown, unknown, unknown, unknown>
|
|
163
|
+
| TupleConfig<unknown, unknown, unknown>
|
|
164
|
+
| TupleConfig<unknown, unknown>
|
|
165
|
+
| TupleConfig<unknown>,
|
|
166
|
+
>(
|
|
167
|
+
config: T,
|
|
168
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
169
|
+
): (() => Result<T>) => _createTupleGenerator(config, "*", customTypeMatch);
|
|
106
170
|
|
|
107
|
-
|
|
171
|
+
// =================== generator fn ====================
|
|
172
|
+
|
|
173
|
+
const _createBoundedSeriesGenerator = <T extends BoundedSeriesConfig>(
|
|
108
174
|
config: T,
|
|
175
|
+
path: string,
|
|
109
176
|
): (() => Result<T>) => {
|
|
110
|
-
|
|
177
|
+
try {
|
|
178
|
+
boundedSeriesScheme.parse(config);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw new Error(`config path: ${path}.boundedSeries\n ${err}`);
|
|
181
|
+
}
|
|
111
182
|
|
|
112
183
|
const { upperLimit, lowerLimit, createInitValue, count } = config;
|
|
113
184
|
|
|
@@ -124,37 +195,52 @@ export const createBoundedSeriesGenerator = <T extends BoundedSeriesConfig>(
|
|
|
124
195
|
return boundedSeries as Result<T>;
|
|
125
196
|
};
|
|
126
197
|
};
|
|
198
|
+
export const createBoundedSeriesGenerator = <T extends BoundedSeriesConfig>(
|
|
199
|
+
config: T,
|
|
200
|
+
): (() => Result<T>) => _createBoundedSeriesGenerator(config, "*");
|
|
127
201
|
|
|
128
|
-
|
|
202
|
+
// =================== generator fn ====================
|
|
203
|
+
|
|
204
|
+
const _createGeneratorByType = <T extends AllConfig<unknown>>(
|
|
129
205
|
config: T,
|
|
130
|
-
|
|
206
|
+
path: string,
|
|
207
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
131
208
|
): (() => Result<T>) => {
|
|
132
209
|
switch (config.type) {
|
|
133
210
|
case "obj":
|
|
134
|
-
return
|
|
211
|
+
return _createObjectGenerator(
|
|
212
|
+
config,
|
|
213
|
+
path,
|
|
214
|
+
customTypeMatch,
|
|
215
|
+
) as () => Result<T>;
|
|
135
216
|
case "arr":
|
|
136
|
-
return
|
|
217
|
+
return _createArrayGenerator(
|
|
218
|
+
config,
|
|
219
|
+
path,
|
|
220
|
+
customTypeMatch,
|
|
221
|
+
) as () => Result<T>;
|
|
137
222
|
case "tuple":
|
|
138
|
-
return
|
|
223
|
+
return _createTupleGenerator(
|
|
224
|
+
config,
|
|
225
|
+
path,
|
|
226
|
+
customTypeMatch,
|
|
227
|
+
) as () => Result<T>;
|
|
139
228
|
case "select":
|
|
140
|
-
return
|
|
229
|
+
return _createSelectionGenerator(config, path) as () => Result<T>;
|
|
141
230
|
case "value":
|
|
142
|
-
return
|
|
231
|
+
return _createValueGenerator(config, path);
|
|
143
232
|
case "bounded_series":
|
|
144
|
-
return
|
|
233
|
+
return _createBoundedSeriesGenerator(config, path) as () => Result<T>;
|
|
145
234
|
default: {
|
|
146
235
|
if (customTypeMatch) {
|
|
147
|
-
return createValueGenerator(customTypeMatch(config));
|
|
236
|
+
return createValueGenerator(customTypeMatch(config, path));
|
|
148
237
|
}
|
|
149
|
-
throw Error(`
|
|
238
|
+
throw new Error(`path: ${path}\nconfig type is not supported`);
|
|
150
239
|
}
|
|
151
240
|
}
|
|
152
241
|
};
|
|
153
242
|
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const fn = createGeneratorByType(config);
|
|
243
|
+
export const createGeneratorByType = <T extends AllConfig<unknown>>(
|
|
244
|
+
config: T,
|
|
245
|
+
customTypeMatch?: (config: unknown, path?: string) => ValueConfig<unknown>,
|
|
246
|
+
): (() => Result<T>) => _createGeneratorByType(config, "*", customTypeMatch);
|
package/dist/index.d.mts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
type ValueConfig<T> = {
|
|
2
|
-
type: "value";
|
|
3
|
-
generateFn: () => T;
|
|
4
|
-
};
|
|
5
|
-
type SelectionConfig<T> = {
|
|
6
|
-
type: "select";
|
|
7
|
-
items: T[];
|
|
8
|
-
};
|
|
9
|
-
type BoundedSeriesConfig = {
|
|
10
|
-
type: "bounded_series";
|
|
11
|
-
upperLimit: number;
|
|
12
|
-
lowerLimit: number;
|
|
13
|
-
createInitValue: () => number;
|
|
14
|
-
count: number;
|
|
15
|
-
};
|
|
16
|
-
type ArrayConfig<T> = {
|
|
17
|
-
type: "arr";
|
|
18
|
-
item: T;
|
|
19
|
-
len: number;
|
|
20
|
-
};
|
|
21
|
-
type ObjectConfig<T> = {
|
|
22
|
-
type: "obj";
|
|
23
|
-
content: T;
|
|
24
|
-
};
|
|
25
|
-
type TupleConfig<A, B = undefined, C = undefined, D = undefined, E = undefined> = {
|
|
26
|
-
type: "tuple";
|
|
27
|
-
configItems: E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [A] : [A, B] : [A, B, C] : [A, B, C, D] : [A, B, C, D, E];
|
|
28
|
-
};
|
|
29
|
-
type Result<T> = T extends ValueConfig<infer U> ? U : T extends SelectionConfig<infer S> ? S : T extends BoundedSeriesConfig ? number[] : T extends ArrayConfig<infer W> ? Array<Result<W>> : T extends ObjectConfig<infer O> ? {
|
|
30
|
-
[K in keyof O]: Result<O[K]>;
|
|
31
|
-
} : T extends TupleConfig<infer A, infer B, infer C, infer D, infer E> ? E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [Result<A>] : [Result<A>, Result<B>] : [Result<A>, Result<B>, Result<C>] : [Result<A>, Result<B>, Result<C>, Result<D>] : [Result<A>, Result<B>, Result<C>, Result<D>, Result<E>] : never;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* value
|
|
35
|
-
* @param {function} generateFn - The function used to generate the value.
|
|
36
|
-
* @return {ValueConfig} The configuration object with the type "value" and the provided generate function.
|
|
37
|
-
*/
|
|
38
|
-
declare const createValueConfig: <T>(generateFn: () => T) => ValueConfig<T>;
|
|
39
|
-
/**
|
|
40
|
-
* selection
|
|
41
|
-
* @param {Array} items - The array of items to choose from.
|
|
42
|
-
* @return {SelectionConfig} The configuration object with the type "select" and the provided items.
|
|
43
|
-
*/
|
|
44
|
-
declare const createSelectionConfig: <T>(items: T[]) => SelectionConfig<T>;
|
|
45
|
-
/**
|
|
46
|
-
* object
|
|
47
|
-
* @param {object} content
|
|
48
|
-
* @return {ObjectConfig}
|
|
49
|
-
*/
|
|
50
|
-
declare const createObjectConfig: <T extends object>(content: T) => ObjectConfig<T>;
|
|
51
|
-
/**
|
|
52
|
-
* array
|
|
53
|
-
* @param {object} item
|
|
54
|
-
* @param {number} len
|
|
55
|
-
* @return {ArrayConfig}
|
|
56
|
-
*/
|
|
57
|
-
declare const createArrayConfig: <T>(item: T, len: number) => ArrayConfig<T>;
|
|
58
|
-
/**
|
|
59
|
-
* tuple
|
|
60
|
-
* @param {Array} configItems
|
|
61
|
-
* @return {TupleConfig}
|
|
62
|
-
*/
|
|
63
|
-
interface CreateTupleConfig {
|
|
64
|
-
<A, B, C, D, E>(configItems: [A, B, C, D, E]): TupleConfig<A, B, C, D, E>;
|
|
65
|
-
<A, B, C, D>(configItems: [A, B, C, D]): TupleConfig<A, B, C, D>;
|
|
66
|
-
<A, B, C>(configItems: [A, B, C]): TupleConfig<A, B, C>;
|
|
67
|
-
<A, B>(configItems: [A, B]): TupleConfig<A, B>;
|
|
68
|
-
<A>(configItems: [A]): TupleConfig<A>;
|
|
69
|
-
}
|
|
70
|
-
declare const createTupleConfig: CreateTupleConfig;
|
|
71
|
-
/**
|
|
72
|
-
* bounded series
|
|
73
|
-
* @param {{ upperLimit: number, lowerLimit: number, createInitValue: () => number, count: number }} config
|
|
74
|
-
* @return {BoundedSeriesConfig}
|
|
75
|
-
*/
|
|
76
|
-
declare const createBoundedSeriesConfig: (config: Omit<BoundedSeriesConfig, "type">) => BoundedSeriesConfig;
|
|
77
|
-
|
|
78
|
-
type AllConfig<T> = ValueConfig<T> | SelectionConfig<T> | ArrayConfig<T> | ObjectConfig<T> | TupleConfig<T> | TupleConfig<T, T> | TupleConfig<T, T, T> | TupleConfig<T, T, T, T> | TupleConfig<T, T, T, T, T> | BoundedSeriesConfig;
|
|
79
|
-
declare const createValueGenerator: <R = unknown>(config: any) => (() => R);
|
|
80
|
-
declare const createSelectionGenerator: <T extends SelectionConfig<unknown>>(config: T) => (() => Result<T>);
|
|
81
|
-
declare const createObjectGenerator: <T extends ObjectConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
82
|
-
declare const createArrayGenerator: <T extends ArrayConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
83
|
-
declare const createTupleGenerator: <T extends TupleConfig<unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown> | TupleConfig<unknown, unknown> | TupleConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
84
|
-
declare const createBoundedSeriesGenerator: <T extends BoundedSeriesConfig>(config: T) => (() => Result<T>);
|
|
85
|
-
declare const createGeneratorByType: <T extends AllConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
86
|
-
|
|
87
|
-
export { type ArrayConfig, type BoundedSeriesConfig, type ObjectConfig, type Result, type SelectionConfig, type TupleConfig, type ValueConfig, createArrayConfig, createArrayGenerator, createBoundedSeriesConfig, createBoundedSeriesGenerator, createGeneratorByType, createObjectConfig, createObjectGenerator, createSelectionConfig, createSelectionGenerator, createTupleConfig, createTupleGenerator, createValueConfig, createValueGenerator };
|
package/dist/index.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
type ValueConfig<T> = {
|
|
2
|
-
type: "value";
|
|
3
|
-
generateFn: () => T;
|
|
4
|
-
};
|
|
5
|
-
type SelectionConfig<T> = {
|
|
6
|
-
type: "select";
|
|
7
|
-
items: T[];
|
|
8
|
-
};
|
|
9
|
-
type BoundedSeriesConfig = {
|
|
10
|
-
type: "bounded_series";
|
|
11
|
-
upperLimit: number;
|
|
12
|
-
lowerLimit: number;
|
|
13
|
-
createInitValue: () => number;
|
|
14
|
-
count: number;
|
|
15
|
-
};
|
|
16
|
-
type ArrayConfig<T> = {
|
|
17
|
-
type: "arr";
|
|
18
|
-
item: T;
|
|
19
|
-
len: number;
|
|
20
|
-
};
|
|
21
|
-
type ObjectConfig<T> = {
|
|
22
|
-
type: "obj";
|
|
23
|
-
content: T;
|
|
24
|
-
};
|
|
25
|
-
type TupleConfig<A, B = undefined, C = undefined, D = undefined, E = undefined> = {
|
|
26
|
-
type: "tuple";
|
|
27
|
-
configItems: E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [A] : [A, B] : [A, B, C] : [A, B, C, D] : [A, B, C, D, E];
|
|
28
|
-
};
|
|
29
|
-
type Result<T> = T extends ValueConfig<infer U> ? U : T extends SelectionConfig<infer S> ? S : T extends BoundedSeriesConfig ? number[] : T extends ArrayConfig<infer W> ? Array<Result<W>> : T extends ObjectConfig<infer O> ? {
|
|
30
|
-
[K in keyof O]: Result<O[K]>;
|
|
31
|
-
} : T extends TupleConfig<infer A, infer B, infer C, infer D, infer E> ? E extends undefined ? D extends undefined ? C extends undefined ? B extends undefined ? [Result<A>] : [Result<A>, Result<B>] : [Result<A>, Result<B>, Result<C>] : [Result<A>, Result<B>, Result<C>, Result<D>] : [Result<A>, Result<B>, Result<C>, Result<D>, Result<E>] : never;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* value
|
|
35
|
-
* @param {function} generateFn - The function used to generate the value.
|
|
36
|
-
* @return {ValueConfig} The configuration object with the type "value" and the provided generate function.
|
|
37
|
-
*/
|
|
38
|
-
declare const createValueConfig: <T>(generateFn: () => T) => ValueConfig<T>;
|
|
39
|
-
/**
|
|
40
|
-
* selection
|
|
41
|
-
* @param {Array} items - The array of items to choose from.
|
|
42
|
-
* @return {SelectionConfig} The configuration object with the type "select" and the provided items.
|
|
43
|
-
*/
|
|
44
|
-
declare const createSelectionConfig: <T>(items: T[]) => SelectionConfig<T>;
|
|
45
|
-
/**
|
|
46
|
-
* object
|
|
47
|
-
* @param {object} content
|
|
48
|
-
* @return {ObjectConfig}
|
|
49
|
-
*/
|
|
50
|
-
declare const createObjectConfig: <T extends object>(content: T) => ObjectConfig<T>;
|
|
51
|
-
/**
|
|
52
|
-
* array
|
|
53
|
-
* @param {object} item
|
|
54
|
-
* @param {number} len
|
|
55
|
-
* @return {ArrayConfig}
|
|
56
|
-
*/
|
|
57
|
-
declare const createArrayConfig: <T>(item: T, len: number) => ArrayConfig<T>;
|
|
58
|
-
/**
|
|
59
|
-
* tuple
|
|
60
|
-
* @param {Array} configItems
|
|
61
|
-
* @return {TupleConfig}
|
|
62
|
-
*/
|
|
63
|
-
interface CreateTupleConfig {
|
|
64
|
-
<A, B, C, D, E>(configItems: [A, B, C, D, E]): TupleConfig<A, B, C, D, E>;
|
|
65
|
-
<A, B, C, D>(configItems: [A, B, C, D]): TupleConfig<A, B, C, D>;
|
|
66
|
-
<A, B, C>(configItems: [A, B, C]): TupleConfig<A, B, C>;
|
|
67
|
-
<A, B>(configItems: [A, B]): TupleConfig<A, B>;
|
|
68
|
-
<A>(configItems: [A]): TupleConfig<A>;
|
|
69
|
-
}
|
|
70
|
-
declare const createTupleConfig: CreateTupleConfig;
|
|
71
|
-
/**
|
|
72
|
-
* bounded series
|
|
73
|
-
* @param {{ upperLimit: number, lowerLimit: number, createInitValue: () => number, count: number }} config
|
|
74
|
-
* @return {BoundedSeriesConfig}
|
|
75
|
-
*/
|
|
76
|
-
declare const createBoundedSeriesConfig: (config: Omit<BoundedSeriesConfig, "type">) => BoundedSeriesConfig;
|
|
77
|
-
|
|
78
|
-
type AllConfig<T> = ValueConfig<T> | SelectionConfig<T> | ArrayConfig<T> | ObjectConfig<T> | TupleConfig<T> | TupleConfig<T, T> | TupleConfig<T, T, T> | TupleConfig<T, T, T, T> | TupleConfig<T, T, T, T, T> | BoundedSeriesConfig;
|
|
79
|
-
declare const createValueGenerator: <R = unknown>(config: any) => (() => R);
|
|
80
|
-
declare const createSelectionGenerator: <T extends SelectionConfig<unknown>>(config: T) => (() => Result<T>);
|
|
81
|
-
declare const createObjectGenerator: <T extends ObjectConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
82
|
-
declare const createArrayGenerator: <T extends ArrayConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
83
|
-
declare const createTupleGenerator: <T extends TupleConfig<unknown, unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown, unknown> | TupleConfig<unknown, unknown, unknown> | TupleConfig<unknown, unknown> | TupleConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
84
|
-
declare const createBoundedSeriesGenerator: <T extends BoundedSeriesConfig>(config: T) => (() => Result<T>);
|
|
85
|
-
declare const createGeneratorByType: <T extends AllConfig<unknown>>(config: T, customTypeMatch?: (config: unknown) => ValueConfig<unknown>) => (() => Result<T>);
|
|
86
|
-
|
|
87
|
-
export { type ArrayConfig, type BoundedSeriesConfig, type ObjectConfig, type Result, type SelectionConfig, type TupleConfig, type ValueConfig, createArrayConfig, createArrayGenerator, createBoundedSeriesConfig, createBoundedSeriesGenerator, createGeneratorByType, createObjectConfig, createObjectGenerator, createSelectionConfig, createSelectionGenerator, createTupleConfig, createTupleGenerator, createValueConfig, createValueGenerator };
|