@hegeldev/hegel 0.1.0
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/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/binary.d.ts +27 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +50 -0
- package/dist/binary.js.map +1 -0
- package/dist/collections.d.ts +114 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +313 -0
- package/dist/collections.js.map +1 -0
- package/dist/combinators.d.ts +34 -0
- package/dist/combinators.d.ts.map +1 -0
- package/dist/combinators.js +152 -0
- package/dist/combinators.js.map +1 -0
- package/dist/conformance.d.ts +31 -0
- package/dist/conformance.d.ts.map +1 -0
- package/dist/conformance.js +60 -0
- package/dist/conformance.js.map +1 -0
- package/dist/connection.d.ts +82 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +231 -0
- package/dist/connection.js.map +1 -0
- package/dist/crc32.d.ts +13 -0
- package/dist/crc32.d.ts.map +1 -0
- package/dist/crc32.js +30 -0
- package/dist/crc32.js.map +1 -0
- package/dist/derive.d.ts +225 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +296 -0
- package/dist/derive.js.map +1 -0
- package/dist/embedded.d.ts +38 -0
- package/dist/embedded.d.ts.map +1 -0
- package/dist/embedded.js +237 -0
- package/dist/embedded.js.map +1 -0
- package/dist/floats.d.ts +57 -0
- package/dist/floats.d.ts.map +1 -0
- package/dist/floats.js +100 -0
- package/dist/floats.js.map +1 -0
- package/dist/formats.d.ts +62 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/formats.js +164 -0
- package/dist/formats.js.map +1 -0
- package/dist/generator.d.ts +80 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +128 -0
- package/dist/generator.js.map +1 -0
- package/dist/generators/collections.d.ts +20 -0
- package/dist/generators/collections.d.ts.map +1 -0
- package/dist/generators/collections.js +209 -0
- package/dist/generators/collections.js.map +1 -0
- package/dist/generators/combinators.d.ts +15 -0
- package/dist/generators/combinators.d.ts.map +1 -0
- package/dist/generators/combinators.js +143 -0
- package/dist/generators/combinators.js.map +1 -0
- package/dist/generators/compose.d.ts +27 -0
- package/dist/generators/compose.d.ts.map +1 -0
- package/dist/generators/compose.js +82 -0
- package/dist/generators/compose.js.map +1 -0
- package/dist/generators/core.d.ts +53 -0
- package/dist/generators/core.d.ts.map +1 -0
- package/dist/generators/core.js +134 -0
- package/dist/generators/core.js.map +1 -0
- package/dist/generators/index.d.ts +18 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +15 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/numeric.d.ts +40 -0
- package/dist/generators/numeric.d.ts.map +1 -0
- package/dist/generators/numeric.js +128 -0
- package/dist/generators/numeric.js.map +1 -0
- package/dist/generators/primitives.d.ts +138 -0
- package/dist/generators/primitives.d.ts.map +1 -0
- package/dist/generators/primitives.js +240 -0
- package/dist/generators/primitives.js.map +1 -0
- package/dist/generators/strings.d.ts +73 -0
- package/dist/generators/strings.d.ts.map +1 -0
- package/dist/generators/strings.js +215 -0
- package/dist/generators/strings.js.map +1 -0
- package/dist/generators/tuples.d.ts +11 -0
- package/dist/generators/tuples.d.ts.map +1 -0
- package/dist/generators/tuples.js +43 -0
- package/dist/generators/tuples.js.map +1 -0
- package/dist/generators.d.ts +408 -0
- package/dist/generators.d.ts.map +1 -0
- package/dist/generators.js +898 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +6 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +91 -0
- package/dist/install.js.map +1 -0
- package/dist/integers.d.ts +37 -0
- package/dist/integers.d.ts.map +1 -0
- package/dist/integers.js +63 -0
- package/dist/integers.js.map +1 -0
- package/dist/labels.d.ts +21 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +20 -0
- package/dist/labels.js.map +1 -0
- package/dist/objects.d.ts +39 -0
- package/dist/objects.d.ts.map +1 -0
- package/dist/objects.js +98 -0
- package/dist/objects.js.map +1 -0
- package/dist/primitives.d.ts +14 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +51 -0
- package/dist/primitives.js.map +1 -0
- package/dist/protocol.d.ts +25 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +77 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runner.d.ts +115 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +455 -0
- package/dist/runner.js.map +1 -0
- package/dist/session.d.ts +19 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +157 -0
- package/dist/session.js.map +1 -0
- package/dist/spans.d.ts +23 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +51 -0
- package/dist/spans.js.map +1 -0
- package/dist/strings.d.ts +67 -0
- package/dist/strings.d.ts.map +1 -0
- package/dist/strings.js +107 -0
- package/dist/strings.js.map +1 -0
- package/dist/testCase.d.ts +118 -0
- package/dist/testCase.d.ts.map +1 -0
- package/dist/testCase.js +186 -0
- package/dist/testCase.js.map +1 -0
- package/dist/uv-install.sh +2226 -0
- package/dist/uv.d.ts +20 -0
- package/dist/uv.d.ts.map +1 -0
- package/dist/uv.js +103 -0
- package/dist/uv.js.map +1 -0
- package/dist/wtf8.d.ts +16 -0
- package/dist/wtf8.d.ts.map +1 -0
- package/dist/wtf8.js +52 -0
- package/dist/wtf8.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generator infrastructure for the Hegel SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Generator} abstract class, {@link BasicGenerator},
|
|
5
|
+
* composite generators (Mapped, FlatMapped, Filtered), collection protocol,
|
|
6
|
+
* span helpers, and the initial set of generators.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import type { TestCaseData } from "./runner.js";
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all generators.
|
|
13
|
+
*
|
|
14
|
+
* Subclasses implement `doDraw` to produce a value. The {@link map},
|
|
15
|
+
* {@link flatMap}, and {@link filter} combinators produce new generators.
|
|
16
|
+
*
|
|
17
|
+
* {@link BasicGenerator} is special: its {@link BasicGenerator.map} preserves
|
|
18
|
+
* the schema (stays basic), enabling the server to see the original schema for
|
|
19
|
+
* better shrinking.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class Generator<T = unknown> {
|
|
22
|
+
/** @internal */
|
|
23
|
+
abstract doDraw(data: TestCaseData): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Transform each generated value with `f`.
|
|
26
|
+
*
|
|
27
|
+
* On a {@link BasicGenerator} this stays basic (preserves schema).
|
|
28
|
+
* On any other generator it returns a MappedGenerator.
|
|
29
|
+
*/
|
|
30
|
+
map<U>(f: (value: T) => U): Generator<U>;
|
|
31
|
+
/**
|
|
32
|
+
* Dependent generation: generate a value then use it to choose a second generator.
|
|
33
|
+
*/
|
|
34
|
+
flatMap<U>(f: (value: T) => Generator<U>): Generator<U>;
|
|
35
|
+
/**
|
|
36
|
+
* Filter generated values. Tries up to 3 times before giving up.
|
|
37
|
+
*
|
|
38
|
+
* Prefer narrow schemas over filters when possible — filters slow shrinking.
|
|
39
|
+
*/
|
|
40
|
+
filter(predicate: (value: T) => boolean): Generator<T>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A generator backed by a raw schema sent to the server.
|
|
44
|
+
*
|
|
45
|
+
* `map()` on a BasicGenerator **preserves the schema** — it composes the
|
|
46
|
+
* transform client-side so the server still sees the original schema. This is
|
|
47
|
+
* the key optimization: the server can shrink within the original schema space.
|
|
48
|
+
*/
|
|
49
|
+
export declare class BasicGenerator<T = unknown> extends Generator<T> {
|
|
50
|
+
/** @internal */
|
|
51
|
+
readonly _rawSchema: Record<string, unknown>;
|
|
52
|
+
/** @internal */
|
|
53
|
+
readonly _transform: ((raw: unknown) => T) | null;
|
|
54
|
+
constructor(rawSchema: Record<string, unknown>, transform?: ((raw: unknown) => T) | null);
|
|
55
|
+
/** The raw schema sent to the server. */
|
|
56
|
+
schema(): Record<string, unknown>;
|
|
57
|
+
/** @internal */
|
|
58
|
+
doDraw(data: TestCaseData): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Transform values while **preserving the schema**.
|
|
61
|
+
*
|
|
62
|
+
* If this generator already has a transform `t`, the new transform is
|
|
63
|
+
* `f(t(raw))`. This keeps the generator basic (server sees original schema).
|
|
64
|
+
*/
|
|
65
|
+
map<U>(f: (value: T) => U): BasicGenerator<U>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A generator that applies a transform to values from another generator.
|
|
69
|
+
* Uses a MAPPED span so the server can track the transformation.
|
|
70
|
+
*/
|
|
71
|
+
export declare class MappedGenerator<T, U> extends Generator<U> {
|
|
72
|
+
private readonly _source;
|
|
73
|
+
private readonly _f;
|
|
74
|
+
constructor(source: Generator<T>, f: (value: T) => U);
|
|
75
|
+
doDraw(data: TestCaseData): Promise<U>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A generator for dependent generation.
|
|
79
|
+
* Generates a first value, uses it to choose a second generator, then generates from that.
|
|
80
|
+
*/
|
|
81
|
+
export declare class FlatMappedGenerator<T, U> extends Generator<U> {
|
|
82
|
+
private readonly _source;
|
|
83
|
+
private readonly _f;
|
|
84
|
+
constructor(source: Generator<T>, f: (value: T) => Generator<U>);
|
|
85
|
+
doDraw(data: TestCaseData): Promise<U>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A generator that filters values from another generator.
|
|
89
|
+
*
|
|
90
|
+
* Tries up to 3 times. Each failed attempt discards the span.
|
|
91
|
+
* After all attempts fail, calls `assume(false)` to mark the test case as invalid.
|
|
92
|
+
*/
|
|
93
|
+
export declare class FilteredGenerator<T> extends Generator<T> {
|
|
94
|
+
private readonly _source;
|
|
95
|
+
private readonly _predicate;
|
|
96
|
+
constructor(source: Generator<T>, predicate: (value: T) => boolean);
|
|
97
|
+
doDraw(data: TestCaseData): Promise<T>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Run `fn` inside a span with the given label.
|
|
101
|
+
*
|
|
102
|
+
* Starts the span before calling `fn`, then stops it (with `discard=false`)
|
|
103
|
+
* after `fn` returns. Returns the value returned by `fn`.
|
|
104
|
+
*
|
|
105
|
+
* @param label - Span label constant (see `Labels`).
|
|
106
|
+
* @param fn - Function to run inside the span.
|
|
107
|
+
*/
|
|
108
|
+
export declare function group<T>(label: number, fn: () => T | Promise<T>, data: TestCaseData): Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Run `fn` inside a discardable span.
|
|
111
|
+
*
|
|
112
|
+
* If `fn` throws, stops the span with `discard=true`. Otherwise stops with
|
|
113
|
+
* `discard=false`. The exception (if any) is re-thrown.
|
|
114
|
+
*
|
|
115
|
+
* @param label - Span label constant (see `Labels`).
|
|
116
|
+
* @param fn - Function to run inside the span.
|
|
117
|
+
*/
|
|
118
|
+
export declare function discardableGroup<T>(label: number, fn: () => T | Promise<T>, data: TestCaseData): Promise<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Server-managed collection for generating variable-length sequences.
|
|
121
|
+
*
|
|
122
|
+
* The server decides how many elements to generate based on the configured
|
|
123
|
+
* size constraints. Call `more()` in a loop; when it returns false, the
|
|
124
|
+
* collection is done. Call `reject()` to discard the most recently
|
|
125
|
+
* generated element.
|
|
126
|
+
*
|
|
127
|
+
* StopTest errors from any collection command propagate as {@link DataExhausted}
|
|
128
|
+
* (same as in `generateFromSchema`).
|
|
129
|
+
*/
|
|
130
|
+
export declare class Collection {
|
|
131
|
+
private _baseName;
|
|
132
|
+
private _serverName;
|
|
133
|
+
private _serverNameResolved;
|
|
134
|
+
private _finished;
|
|
135
|
+
/** Minimum number of elements. */
|
|
136
|
+
readonly minSize: number;
|
|
137
|
+
/** Maximum number of elements (null = unlimited). */
|
|
138
|
+
readonly maxSize: number | null;
|
|
139
|
+
constructor(name: string | null, minSize?: number, maxSize?: number | null);
|
|
140
|
+
/**
|
|
141
|
+
* Get (or lazily initialize) the server-side collection name.
|
|
142
|
+
* Sends `new_collection` on first call.
|
|
143
|
+
*/
|
|
144
|
+
private _getServerName;
|
|
145
|
+
/** @internal */
|
|
146
|
+
more(data: TestCaseData): Promise<boolean>;
|
|
147
|
+
/** @internal */
|
|
148
|
+
reject(data: TestCaseData, why?: string | null): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generate integers.
|
|
152
|
+
*
|
|
153
|
+
* @param minValue - Minimum value (inclusive), or null for unbounded.
|
|
154
|
+
* @param maxValue - Maximum value (inclusive), or null for unbounded.
|
|
155
|
+
*/
|
|
156
|
+
export declare function integers(minValue?: number | null, maxValue?: number | null): BasicGenerator<number>;
|
|
157
|
+
/**
|
|
158
|
+
* Generate floating-point numbers.
|
|
159
|
+
*
|
|
160
|
+
* By default, allows NaN and infinity unless a range is given. When a min or
|
|
161
|
+
* max is provided the defaults tighten: NaN becomes disallowed, and infinity
|
|
162
|
+
* is disallowed on the bounded side.
|
|
163
|
+
*
|
|
164
|
+
* @param minValue - Minimum value (inclusive), or null for unbounded.
|
|
165
|
+
* @param maxValue - Maximum value (inclusive), or null for unbounded.
|
|
166
|
+
* @param allowNan - Whether to allow NaN. Defaults to true only when both bounds are absent.
|
|
167
|
+
* @param allowInfinity - Whether to allow ±Infinity. Defaults to true when at least one bound is absent.
|
|
168
|
+
* @param excludeMin - Whether to exclude the minimum value (open interval on the left).
|
|
169
|
+
* @param excludeMax - Whether to exclude the maximum value (open interval on the right).
|
|
170
|
+
*/
|
|
171
|
+
export declare function floats(minValue?: number | null, maxValue?: number | null, allowNan?: boolean | null, allowInfinity?: boolean | null, excludeMin?: boolean, excludeMax?: boolean): BasicGenerator<number>;
|
|
172
|
+
/**
|
|
173
|
+
* Generate booleans.
|
|
174
|
+
*
|
|
175
|
+
* @param p - Probability of generating `true`. Defaults to 0.5.
|
|
176
|
+
*/
|
|
177
|
+
export declare function booleans(p?: number): BasicGenerator<boolean>;
|
|
178
|
+
/**
|
|
179
|
+
* Generate text strings.
|
|
180
|
+
*
|
|
181
|
+
* @param minSize - Minimum number of Unicode codepoints. Defaults to 0.
|
|
182
|
+
* @param maxSize - Maximum number of Unicode codepoints, or null for unbounded.
|
|
183
|
+
*/
|
|
184
|
+
export declare function text(minSize?: number, maxSize?: number | null): BasicGenerator<string>;
|
|
185
|
+
/**
|
|
186
|
+
* Generate binary data (byte strings).
|
|
187
|
+
*
|
|
188
|
+
* The server returns CBOR byte strings which are decoded directly as
|
|
189
|
+
* `Uint8Array`. No transform is needed.
|
|
190
|
+
*
|
|
191
|
+
* @param minSize - Minimum byte length. Defaults to 0.
|
|
192
|
+
* @param maxSize - Maximum byte length, or null for unbounded.
|
|
193
|
+
*/
|
|
194
|
+
export declare function binary(minSize?: number, maxSize?: number | null): BasicGenerator<Uint8Array>;
|
|
195
|
+
/**
|
|
196
|
+
* Always return the same constant value, ignoring the server's suggestion.
|
|
197
|
+
*
|
|
198
|
+
* @param value - The constant to always return.
|
|
199
|
+
*/
|
|
200
|
+
export declare function just<T>(value: T): BasicGenerator<T>;
|
|
201
|
+
/**
|
|
202
|
+
* Pick uniformly at random from a list of values.
|
|
203
|
+
*
|
|
204
|
+
* The server generates an integer index; the transform maps it to the
|
|
205
|
+
* corresponding element of `values`.
|
|
206
|
+
*
|
|
207
|
+
* @param values - The list to sample from. Must be non-empty.
|
|
208
|
+
* @throws {Error} If `values` is empty.
|
|
209
|
+
*/
|
|
210
|
+
export declare function sampledFrom<T>(values: readonly T[]): BasicGenerator<T>;
|
|
211
|
+
/**
|
|
212
|
+
* Generate strings matching a regular expression pattern.
|
|
213
|
+
*
|
|
214
|
+
* @param pattern - The regex pattern to match.
|
|
215
|
+
* @param fullmatch - If true (default), the entire string must match the pattern.
|
|
216
|
+
* If false, a substring match is sufficient.
|
|
217
|
+
*/
|
|
218
|
+
export declare function fromRegex(pattern: string, fullmatch?: boolean): BasicGenerator<string>;
|
|
219
|
+
/**
|
|
220
|
+
* Generate email addresses.
|
|
221
|
+
*
|
|
222
|
+
* Each generated value is a valid email address string containing '@'.
|
|
223
|
+
*/
|
|
224
|
+
export declare function emails(): BasicGenerator<string>;
|
|
225
|
+
/**
|
|
226
|
+
* Generate URLs.
|
|
227
|
+
*
|
|
228
|
+
* Each generated value is a valid URL string starting with "http://" or "https://".
|
|
229
|
+
*/
|
|
230
|
+
export declare function urls(): BasicGenerator<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Generate domain names.
|
|
233
|
+
*
|
|
234
|
+
* @param maxLength - Optional maximum length for generated domain names.
|
|
235
|
+
*/
|
|
236
|
+
export declare function domains(maxLength?: number | null): BasicGenerator<string>;
|
|
237
|
+
/**
|
|
238
|
+
* Generate dates.
|
|
239
|
+
*
|
|
240
|
+
* Each generated value is an ISO 8601 date string in YYYY-MM-DD format.
|
|
241
|
+
*/
|
|
242
|
+
export declare function dates(): BasicGenerator<string>;
|
|
243
|
+
/**
|
|
244
|
+
* Generate times.
|
|
245
|
+
*
|
|
246
|
+
* Each generated value is a time string containing ':'.
|
|
247
|
+
*/
|
|
248
|
+
export declare function times(): BasicGenerator<string>;
|
|
249
|
+
/**
|
|
250
|
+
* Generate datetimes.
|
|
251
|
+
*
|
|
252
|
+
* Each generated value is a datetime string containing 'T'.
|
|
253
|
+
*/
|
|
254
|
+
export declare function datetimes(): BasicGenerator<string>;
|
|
255
|
+
/**
|
|
256
|
+
* A tuple generator for elements that are not all basic.
|
|
257
|
+
*
|
|
258
|
+
* Generates each element in sequence inside a TUPLE span (label 7).
|
|
259
|
+
* Used when at least one element cannot be represented as a basic schema.
|
|
260
|
+
*/
|
|
261
|
+
export declare class CompositeTupleGenerator<T extends unknown[]> extends Generator<T> {
|
|
262
|
+
private readonly _elements;
|
|
263
|
+
constructor(elements: {
|
|
264
|
+
[K in keyof T]: Generator<T[K]>;
|
|
265
|
+
});
|
|
266
|
+
doDraw(data: TestCaseData): Promise<T>;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Generate a 2-tuple (pair).
|
|
270
|
+
*
|
|
271
|
+
* If both elements are {@link BasicGenerator}s, returns a BasicGenerator with
|
|
272
|
+
* a tuple schema so the server can see and shrink both components. Otherwise
|
|
273
|
+
* returns a CompositeTupleGenerator that generates each element inside
|
|
274
|
+
* a TUPLE span.
|
|
275
|
+
*
|
|
276
|
+
* @param g1 - Generator for the first element.
|
|
277
|
+
* @param g2 - Generator for the second element.
|
|
278
|
+
*/
|
|
279
|
+
export declare function tuples2<A, B>(g1: Generator<A>, g2: Generator<B>): Generator<[A, B]>;
|
|
280
|
+
/**
|
|
281
|
+
* Generate a 3-tuple.
|
|
282
|
+
*
|
|
283
|
+
* If all elements are {@link BasicGenerator}s, returns a BasicGenerator with
|
|
284
|
+
* a tuple schema. Otherwise returns a CompositeTupleGenerator.
|
|
285
|
+
*
|
|
286
|
+
* @param g1 - Generator for the first element.
|
|
287
|
+
* @param g2 - Generator for the second element.
|
|
288
|
+
* @param g3 - Generator for the third element.
|
|
289
|
+
*/
|
|
290
|
+
export declare function tuples3<A, B, C>(g1: Generator<A>, g2: Generator<B>, g3: Generator<C>): Generator<[A, B, C]>;
|
|
291
|
+
/**
|
|
292
|
+
* Generate a 4-tuple.
|
|
293
|
+
*
|
|
294
|
+
* If all elements are {@link BasicGenerator}s, returns a BasicGenerator with
|
|
295
|
+
* a tuple schema. Otherwise returns a CompositeTupleGenerator.
|
|
296
|
+
*
|
|
297
|
+
* @param g1 - Generator for the first element.
|
|
298
|
+
* @param g2 - Generator for the second element.
|
|
299
|
+
* @param g3 - Generator for the third element.
|
|
300
|
+
* @param g4 - Generator for the fourth element.
|
|
301
|
+
*/
|
|
302
|
+
export declare function tuples4<A, B, C, D>(g1: Generator<A>, g2: Generator<B>, g3: Generator<C>, g4: Generator<D>): Generator<[A, B, C, D]>;
|
|
303
|
+
/**
|
|
304
|
+
* A list generator for elements that are not basic (e.g., filtered or mapped
|
|
305
|
+
* through a non-basic path). Uses the collection protocol in a LIST span.
|
|
306
|
+
*
|
|
307
|
+
* @typeParam T - The element type.
|
|
308
|
+
*/
|
|
309
|
+
export declare class CompositeListGenerator<T = unknown> extends Generator<T[]> {
|
|
310
|
+
private readonly _elements;
|
|
311
|
+
private readonly _minSize;
|
|
312
|
+
private readonly _maxSize;
|
|
313
|
+
constructor(elements: Generator<T>, minSize?: number, maxSize?: number | null);
|
|
314
|
+
doDraw(data: TestCaseData): Promise<T[]>;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Generate lists of elements.
|
|
318
|
+
*
|
|
319
|
+
* When `elements` is a {@link BasicGenerator}, the list schema is sent to the
|
|
320
|
+
* server directly (optimal shrinking). If the element generator has a transform,
|
|
321
|
+
* a list-level transform is composed that applies it to each item. When elements
|
|
322
|
+
* is a composite generator (e.g., filtered or mapped), the collection protocol
|
|
323
|
+
* is used in a LIST span via CompositeListGenerator.
|
|
324
|
+
*
|
|
325
|
+
* @param elements - Generator for list elements.
|
|
326
|
+
* @param minSize - Minimum list length. Defaults to 0.
|
|
327
|
+
* @param maxSize - Maximum list length, or null for unbounded.
|
|
328
|
+
*/
|
|
329
|
+
export declare function lists<T>(elements: Generator<T>, minSize?: number, maxSize?: number | null): Generator<T[]>;
|
|
330
|
+
/**
|
|
331
|
+
* A one_of generator for generators that cannot be represented as a single schema
|
|
332
|
+
* (i.e., when at least one branch is not a {@link BasicGenerator}).
|
|
333
|
+
*
|
|
334
|
+
* Generates an integer index then delegates to the selected generator. Wrapped
|
|
335
|
+
* in a ONE_OF span (label `Labels.ONE_OF`) so the server tracks the choice.
|
|
336
|
+
*/
|
|
337
|
+
export declare class CompositeOneOfGenerator<T = unknown> extends Generator<T> {
|
|
338
|
+
/** @internal */
|
|
339
|
+
readonly _generators: Generator<T>[];
|
|
340
|
+
constructor(generators: Generator<T>[]);
|
|
341
|
+
doDraw(data: TestCaseData): Promise<T>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Choose uniformly between two or more generators.
|
|
345
|
+
*
|
|
346
|
+
* There are three implementation paths depending on the inputs:
|
|
347
|
+
*
|
|
348
|
+
* - **Path 1** — all branches are {@link BasicGenerator} with no transform:
|
|
349
|
+
* returns a `BasicGenerator` with `{"one_of": [...schemas]}`.
|
|
350
|
+
* - **Path 2** — all branches are {@link BasicGenerator} but some have transforms:
|
|
351
|
+
* returns a `BasicGenerator` using tagged-tuple schemas so each branch can
|
|
352
|
+
* carry its own transform.
|
|
353
|
+
* - **Path 3** — any branch is not a `BasicGenerator`:
|
|
354
|
+
* returns a CompositeOneOfGenerator that generates an index then
|
|
355
|
+
* delegates to the selected generator inside a ONE_OF span.
|
|
356
|
+
*
|
|
357
|
+
* @param generators - Two or more generators to choose between.
|
|
358
|
+
* @throws {Error} If fewer than 2 generators are provided.
|
|
359
|
+
*/
|
|
360
|
+
export declare function oneOf<T>(...generators: Generator<T>[]): Generator<T>;
|
|
361
|
+
/**
|
|
362
|
+
* Optionally generate a value — returns `null` or a value from `element`.
|
|
363
|
+
*
|
|
364
|
+
* Equivalent to `oneOf(just(null), element)`.
|
|
365
|
+
*
|
|
366
|
+
* @param element - Generator for the non-null case.
|
|
367
|
+
*/
|
|
368
|
+
export declare function optional<T>(element: Generator<T>): Generator<T | null>;
|
|
369
|
+
/**
|
|
370
|
+
* Generate IP addresses.
|
|
371
|
+
*
|
|
372
|
+
* @param version - IP version: `4` for IPv4, `6` for IPv6, or `null` (default)
|
|
373
|
+
* to generate both versions mixed.
|
|
374
|
+
*/
|
|
375
|
+
export declare function ipAddresses(version?: 4 | 6 | null): Generator<string>;
|
|
376
|
+
/**
|
|
377
|
+
* A dict generator for keys or values that are not basic (have no server schema).
|
|
378
|
+
*
|
|
379
|
+
* Uses the MAP span (label 5) for the whole dict and MAP_ENTRY spans (label 6)
|
|
380
|
+
* for each key-value pair. The server decides the size via generateFromSchema.
|
|
381
|
+
*/
|
|
382
|
+
export declare class CompositeDictGenerator<K, V> extends Generator<Map<K, V>> {
|
|
383
|
+
/** @internal */
|
|
384
|
+
readonly _keys: Generator<K>;
|
|
385
|
+
/** @internal */
|
|
386
|
+
readonly _values: Generator<V>;
|
|
387
|
+
/** @internal */
|
|
388
|
+
readonly _minSize: number;
|
|
389
|
+
/** @internal */
|
|
390
|
+
readonly _maxSize: number | null;
|
|
391
|
+
constructor(keys: Generator<K>, values: Generator<V>, minSize: number, maxSize: number | null);
|
|
392
|
+
doDraw(data: TestCaseData): Promise<Map<K, V>>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Generate dictionaries with keys and values from the given generators.
|
|
396
|
+
*
|
|
397
|
+
* When both `keys` and `values` are {@link BasicGenerator}s, the server handles
|
|
398
|
+
* the full dict generation (basic path) and the result is a plain
|
|
399
|
+
* `Record<string, unknown>`. Otherwise a CompositeDictGenerator is used
|
|
400
|
+
* (non-basic path) which returns a `Map<K, V>`.
|
|
401
|
+
*
|
|
402
|
+
* @param keys - Generator for dictionary keys.
|
|
403
|
+
* @param values - Generator for dictionary values.
|
|
404
|
+
* @param minSize - Minimum number of entries. Defaults to 0.
|
|
405
|
+
* @param maxSize - Maximum number of entries, or null for unbounded.
|
|
406
|
+
*/
|
|
407
|
+
export declare function dicts<K, V>(keys: Generator<K>, values: Generator<V>, minSize?: number, maxSize?: number | null): Generator<Record<string, unknown>> | Generator<Map<K, V>>;
|
|
408
|
+
//# sourceMappingURL=generators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD;;;;;;;;;GASG;AACH,8BAAsB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