1 | import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
|
2 | /**
|
3 | * Constraints to be applied on {@link record}
|
4 | * @remarks Since 0.0.12
|
5 | * @public
|
6 | */
|
7 | export declare type RecordConstraints<T = unknown> = {
|
8 | /**
|
9 | * List keys that should never be deleted.
|
10 | *
|
11 | * Remark:
|
12 | * You might need to use an explicit typing in case you need to declare symbols as required (not needed when required keys are simple strings).
|
13 | * With something like `{ requiredKeys: [mySymbol1, 'a'] as [typeof mySymbol1, 'a'] }` when both `mySymbol1` and `a` are required.
|
14 | *
|
15 | * Warning: Cannot be used in conjunction with withDeletedKeys.
|
16 | *
|
17 | * @remarks Since 2.11.0
|
18 | */
|
19 | requiredKeys?: T[];
|
20 | } | {
|
21 | /**
|
22 | * Allow to remove keys from the generated record.
|
23 | * Warning: Cannot be used in conjunction with requiredKeys.
|
24 | * Prefer: `requiredKeys: []` over `withDeletedKeys: true`
|
25 | * @remarks Since 1.0.0
|
26 | */
|
27 | withDeletedKeys?: boolean;
|
28 | };
|
29 | /**
|
30 | * Infer the type of the Arbitrary produced by record
|
31 | * given the type of the source arbitrary and constraints to be applied
|
32 | *
|
33 | * @remarks Since 2.2.0
|
34 | * @public
|
35 | */
|
36 | export declare type RecordValue<T, TConstraints = {}> = TConstraints extends {
|
37 | withDeletedKeys: boolean;
|
38 | requiredKeys: any[];
|
39 | } ? never : TConstraints extends {
|
40 | withDeletedKeys: true;
|
41 | } ? Partial<T> : TConstraints extends {
|
42 | requiredKeys: (infer TKeys)[];
|
43 | } ? Partial<T> & Pick<T, TKeys & keyof T> : T;
|
44 | /**
|
45 | * For records following the `recordModel` schema
|
46 | *
|
47 | * @example
|
48 | * ```typescript
|
49 | * record({ x: someArbitraryInt, y: someArbitraryInt }): Arbitrary<{x:number,y:number}>
|
50 | * // merge two integer arbitraries to produce a {x, y} record
|
51 | * ```
|
52 | *
|
53 | * @param recordModel - Schema of the record
|
54 | *
|
55 | * @remarks Since 0.0.12
|
56 | * @public
|
57 | */
|
58 | declare function record<T>(recordModel: {
|
59 | [K in keyof T]: Arbitrary<T[K]>;
|
60 | }): Arbitrary<RecordValue<{
|
61 | [K in keyof T]: T[K];
|
62 | }>>;
|
63 | /**
|
64 | * For records following the `recordModel` schema
|
65 | *
|
66 | * @example
|
67 | * ```typescript
|
68 | * record({ x: someArbitraryInt, y: someArbitraryInt }, {withDeletedKeys: true}): Arbitrary<{x?:number,y?:number}>
|
69 | * // merge two integer arbitraries to produce a {x, y}, {x}, {y} or {} record
|
70 | * ```
|
71 | *
|
72 | * @param recordModel - Schema of the record
|
73 | * @param constraints - Contraints on the generated record
|
74 | *
|
75 | * @remarks Since 0.0.12
|
76 | * @public
|
77 | */
|
78 | declare function record<T, TConstraints extends RecordConstraints<keyof T>>(recordModel: {
|
79 | [K in keyof T]: Arbitrary<T[K]>;
|
80 | }, constraints: TConstraints): Arbitrary<RecordValue<{
|
81 | [K in keyof T]: T[K];
|
82 | }, TConstraints>>;
|
83 | export { record };
|