@hegeldev/hegel 0.1.0 → 0.1.2
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/dist/generators/combinators.d.ts +1 -1
- package/dist/generators/combinators.d.ts.map +1 -1
- package/dist/generators/combinators.js.map +1 -1
- package/dist/generators/strings.d.ts +2 -2
- package/dist/generators/strings.d.ts.map +1 -1
- package/package.json +7 -2
- package/dist/binary.d.ts +0 -27
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -50
- package/dist/binary.js.map +0 -1
- package/dist/collections.d.ts +0 -114
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -313
- package/dist/collections.js.map +0 -1
- package/dist/combinators.d.ts +0 -34
- package/dist/combinators.d.ts.map +0 -1
- package/dist/combinators.js +0 -152
- package/dist/combinators.js.map +0 -1
- package/dist/conformance.d.ts +0 -31
- package/dist/conformance.d.ts.map +0 -1
- package/dist/conformance.js +0 -60
- package/dist/conformance.js.map +0 -1
- package/dist/derive.d.ts +0 -225
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -296
- package/dist/derive.js.map +0 -1
- package/dist/embedded.d.ts +0 -38
- package/dist/embedded.d.ts.map +0 -1
- package/dist/embedded.js +0 -237
- package/dist/embedded.js.map +0 -1
- package/dist/floats.d.ts +0 -57
- package/dist/floats.d.ts.map +0 -1
- package/dist/floats.js +0 -100
- package/dist/floats.js.map +0 -1
- package/dist/formats.d.ts +0 -62
- package/dist/formats.d.ts.map +0 -1
- package/dist/formats.js +0 -164
- package/dist/formats.js.map +0 -1
- package/dist/generator.d.ts +0 -80
- package/dist/generator.d.ts.map +0 -1
- package/dist/generator.js +0 -128
- package/dist/generator.js.map +0 -1
- package/dist/generators/primitives.d.ts +0 -138
- package/dist/generators/primitives.d.ts.map +0 -1
- package/dist/generators/primitives.js +0 -240
- package/dist/generators/primitives.js.map +0 -1
- package/dist/generators.d.ts +0 -408
- package/dist/generators.d.ts.map +0 -1
- package/dist/generators.js +0 -898
- package/dist/generators.js.map +0 -1
- package/dist/install.d.ts +0 -6
- package/dist/install.d.ts.map +0 -1
- package/dist/install.js +0 -91
- package/dist/install.js.map +0 -1
- package/dist/integers.d.ts +0 -37
- package/dist/integers.d.ts.map +0 -1
- package/dist/integers.js +0 -63
- package/dist/integers.js.map +0 -1
- package/dist/labels.d.ts +0 -21
- package/dist/labels.d.ts.map +0 -1
- package/dist/labels.js +0 -20
- package/dist/labels.js.map +0 -1
- package/dist/objects.d.ts +0 -39
- package/dist/objects.d.ts.map +0 -1
- package/dist/objects.js +0 -98
- package/dist/objects.js.map +0 -1
- package/dist/primitives.d.ts +0 -14
- package/dist/primitives.d.ts.map +0 -1
- package/dist/primitives.js +0 -51
- package/dist/primitives.js.map +0 -1
- package/dist/spans.d.ts +0 -23
- package/dist/spans.d.ts.map +0 -1
- package/dist/spans.js +0 -51
- package/dist/spans.js.map +0 -1
- package/dist/strings.d.ts +0 -67
- package/dist/strings.d.ts.map +0 -1
- package/dist/strings.js +0 -107
- package/dist/strings.js.map +0 -1
package/dist/combinators.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { generateFromSchema } from "./connection.js";
|
|
2
|
-
import { BaseGenerator } from "./generator.js";
|
|
3
|
-
import { booleans } from "./primitives.js";
|
|
4
|
-
import { integers } from "./integers.js";
|
|
5
|
-
import { LABELS } from "./labels.js";
|
|
6
|
-
import { group } from "./spans.js";
|
|
7
|
-
/**
|
|
8
|
-
* Check if a value is a primitive type that can be represented in sampled_from schema.
|
|
9
|
-
*/
|
|
10
|
-
function isPrimitive(value) {
|
|
11
|
-
const type = typeof value;
|
|
12
|
-
return type === "string" || type === "number" || type === "boolean" || value === null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Generator that samples uniformly from a fixed collection.
|
|
16
|
-
*/
|
|
17
|
-
class SampledFromGenerator extends BaseGenerator {
|
|
18
|
-
elements;
|
|
19
|
-
constructor(elements) {
|
|
20
|
-
super();
|
|
21
|
-
this.elements = elements;
|
|
22
|
-
if (elements.length === 0) {
|
|
23
|
-
throw new Error("sampledFrom: cannot sample from empty array");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
generate() {
|
|
27
|
-
const schema = this.schema();
|
|
28
|
-
if (schema) {
|
|
29
|
-
return generateFromSchema(schema);
|
|
30
|
-
}
|
|
31
|
-
// Compositional fallback for non-primitive types
|
|
32
|
-
return group(LABELS.SAMPLED_FROM, () => {
|
|
33
|
-
const index = integers()
|
|
34
|
-
.min(0)
|
|
35
|
-
.max(this.elements.length - 1)
|
|
36
|
-
.generate();
|
|
37
|
-
return this.elements[index];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
schema() {
|
|
41
|
-
// Only use sampled_from schema for primitive types
|
|
42
|
-
if (this.elements.every(isPrimitive)) {
|
|
43
|
-
return { sampled_from: this.elements };
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Create a generator that samples uniformly from a fixed collection.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const colors = sampledFrom(["red", "green", "blue"]);
|
|
54
|
-
* const color: string = colors.generate();
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export function sampledFrom(elements) {
|
|
58
|
-
return new SampledFromGenerator(elements);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Generator that chooses from one of several generators.
|
|
62
|
-
*/
|
|
63
|
-
class OneOfGenerator extends BaseGenerator {
|
|
64
|
-
generators;
|
|
65
|
-
constructor(generators) {
|
|
66
|
-
super();
|
|
67
|
-
this.generators = generators;
|
|
68
|
-
if (generators.length === 0) {
|
|
69
|
-
throw new Error("oneOf: no generators provided");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
generate() {
|
|
73
|
-
const schema = this.schema();
|
|
74
|
-
if (schema) {
|
|
75
|
-
return generateFromSchema(schema);
|
|
76
|
-
}
|
|
77
|
-
// Compositional fallback
|
|
78
|
-
return group(LABELS.ONE_OF, () => {
|
|
79
|
-
const index = integers()
|
|
80
|
-
.min(0)
|
|
81
|
-
.max(this.generators.length - 1)
|
|
82
|
-
.generate();
|
|
83
|
-
return this.generators[index].generate();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
schema() {
|
|
87
|
-
const schemas = [];
|
|
88
|
-
for (const gen of this.generators) {
|
|
89
|
-
const s = gen.schema();
|
|
90
|
-
if (!s)
|
|
91
|
-
return null;
|
|
92
|
-
schemas.push(s);
|
|
93
|
-
}
|
|
94
|
-
return { one_of: schemas };
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create a generator that chooses from one of several generators.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const gen = oneOf(
|
|
103
|
-
* integers().min(0).max(10),
|
|
104
|
-
* integers().min(100).max(110)
|
|
105
|
-
* );
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export function oneOf(...generators) {
|
|
109
|
-
return new OneOfGenerator(generators);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Generator for optional values (T | null).
|
|
113
|
-
*/
|
|
114
|
-
class OptionalGenerator extends BaseGenerator {
|
|
115
|
-
inner;
|
|
116
|
-
constructor(inner) {
|
|
117
|
-
super();
|
|
118
|
-
this.inner = inner;
|
|
119
|
-
}
|
|
120
|
-
generate() {
|
|
121
|
-
const schema = this.schema();
|
|
122
|
-
if (schema) {
|
|
123
|
-
return generateFromSchema(schema);
|
|
124
|
-
}
|
|
125
|
-
// Compositional fallback
|
|
126
|
-
return group(LABELS.OPTIONAL, () => {
|
|
127
|
-
const isNull = booleans().generate();
|
|
128
|
-
return isNull ? null : this.inner.generate();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
schema() {
|
|
132
|
-
const innerSchema = this.inner.schema();
|
|
133
|
-
if (!innerSchema)
|
|
134
|
-
return null;
|
|
135
|
-
return {
|
|
136
|
-
one_of: [{ type: "null" }, innerSchema],
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Create a generator for optional values (T | null).
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* const gen = optional(integers());
|
|
146
|
-
* const value: number | null = gen.generate();
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export function optional(inner) {
|
|
150
|
-
return new OptionalGenerator(inner);
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=combinators.js.map
|
package/dist/combinators.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"combinators.js","sourceRoot":"","sources":["../src/combinators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAyB,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC;;GAEG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAA;IACzB,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;AACvF,CAAC;AAED;;GAEG;AACH,MAAM,oBAAwB,SAAQ,aAAgB;IACvB;IAA7B,YAA6B,QAAsB;QACjD,KAAK,EAAE,CAAA;QADoB,aAAQ,GAAR,QAAQ,CAAc;QAEjD,IAAI,QAAQ,C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AAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE;YACjC,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAA;YACpC,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;QAC9C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;QACvC,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAA;QAE7B,OAAO;YACL,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC;SACxC,CAAA;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAI,KAAmB;IAC7C,OAAO,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAA;AACrC,CAAC"}
|
package/dist/conformance.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conformance testing helpers for Hegel for TypeScript.
|
|
3
|
-
*
|
|
4
|
-
* Provides utilities used by conformance binary scripts to read test
|
|
5
|
-
* configuration from environment variables and write per-test-case metrics
|
|
6
|
-
* to the conformance metrics file.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Return the number of conformance test cases to run.
|
|
12
|
-
*
|
|
13
|
-
* Reads `CONFORMANCE_TEST_CASES` from the environment. Defaults to 50 if
|
|
14
|
-
* the variable is absent, empty, non-numeric, or non-positive.
|
|
15
|
-
*
|
|
16
|
-
* @returns Number of test cases (always ≥ 1).
|
|
17
|
-
*/
|
|
18
|
-
export declare function getTestCases(): number;
|
|
19
|
-
/**
|
|
20
|
-
* Append a JSON metrics line to the conformance metrics file.
|
|
21
|
-
*
|
|
22
|
-
* The metrics file path is read from the `CONFORMANCE_METRICS_FILE`
|
|
23
|
-
* environment variable. Panics (throws) if the variable is not set or the
|
|
24
|
-
* file cannot be written.
|
|
25
|
-
*
|
|
26
|
-
* @param metrics - Plain object to serialise as a single JSON line.
|
|
27
|
-
* @throws {Error} If `CONFORMANCE_METRICS_FILE` is not set.
|
|
28
|
-
* @throws {Error} If the file cannot be opened or written.
|
|
29
|
-
*/
|
|
30
|
-
export declare function writeMetrics(metrics: Record<string, unknown>): void;
|
|
31
|
-
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../src/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAcnE"}
|
package/dist/conformance.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conformance testing helpers for Hegel for TypeScript.
|
|
3
|
-
*
|
|
4
|
-
* Provides utilities used by conformance binary scripts to read test
|
|
5
|
-
* configuration from environment variables and write per-test-case metrics
|
|
6
|
-
* to the conformance metrics file.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import * as fs from "node:fs";
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// getTestCases
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
/**
|
|
15
|
-
* Return the number of conformance test cases to run.
|
|
16
|
-
*
|
|
17
|
-
* Reads `CONFORMANCE_TEST_CASES` from the environment. Defaults to 50 if
|
|
18
|
-
* the variable is absent, empty, non-numeric, or non-positive.
|
|
19
|
-
*
|
|
20
|
-
* @returns Number of test cases (always ≥ 1).
|
|
21
|
-
*/
|
|
22
|
-
export function getTestCases() {
|
|
23
|
-
const val = process.env["CONFORMANCE_TEST_CASES"];
|
|
24
|
-
if (!val)
|
|
25
|
-
return 50;
|
|
26
|
-
const n = parseInt(val, 10);
|
|
27
|
-
if (!Number.isFinite(n) || n <= 0)
|
|
28
|
-
return 50;
|
|
29
|
-
return n;
|
|
30
|
-
}
|
|
31
|
-
// ---------------------------------------------------------------------------
|
|
32
|
-
// writeMetrics
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
/**
|
|
35
|
-
* Append a JSON metrics line to the conformance metrics file.
|
|
36
|
-
*
|
|
37
|
-
* The metrics file path is read from the `CONFORMANCE_METRICS_FILE`
|
|
38
|
-
* environment variable. Panics (throws) if the variable is not set or the
|
|
39
|
-
* file cannot be written.
|
|
40
|
-
*
|
|
41
|
-
* @param metrics - Plain object to serialise as a single JSON line.
|
|
42
|
-
* @throws {Error} If `CONFORMANCE_METRICS_FILE` is not set.
|
|
43
|
-
* @throws {Error} If the file cannot be opened or written.
|
|
44
|
-
*/
|
|
45
|
-
export function writeMetrics(metrics) {
|
|
46
|
-
const path = process.env["CONFORMANCE_METRICS_FILE"];
|
|
47
|
-
if (!path) {
|
|
48
|
-
throw new Error("hegel: CONFORMANCE_METRICS_FILE env var not set");
|
|
49
|
-
}
|
|
50
|
-
// JSON.stringify does not escape U+0085 (NEL), U+2028 (LINE SEPARATOR),
|
|
51
|
-
// or U+2029 (PARAGRAPH SEPARATOR). Python's str.splitlines() splits on
|
|
52
|
-
// all three, breaking JSONL parsing. Escape them explicitly.
|
|
53
|
-
const json = JSON.stringify(metrics)
|
|
54
|
-
.replace(/\u0085/g, "\\u0085")
|
|
55
|
-
.replace(/\u2028/g, "\\u2028")
|
|
56
|
-
.replace(/\u2029/g, "\\u2029");
|
|
57
|
-
const line = json + "\n";
|
|
58
|
-
fs.appendFileSync(path, line, "utf8");
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=conformance.js.map
|
package/dist/conformance.js.map
DELET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ETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-directed generator derivation for the Hegel library.
|
|
3
|
-
*
|
|
4
|
-
* TypeScript erases interface and type information at compile time, but
|
|
5
|
-
* **classes** persist at runtime with real constructors and field names.
|
|
6
|
-
* This module uses TypeScript legacy decorators (`experimentalDecorators`)
|
|
7
|
-
* to associate generators with class fields. Users annotate their class
|
|
8
|
-
* with `@field(gen)` on each property, then call `deriveGenerator(MyClass)`
|
|
9
|
-
* to get a composite generator that builds instances by generating each
|
|
10
|
-
* field independently.
|
|
11
|
-
*
|
|
12
|
-
* For plain-object records (no class needed), use {@link recordGenerator}.
|
|
13
|
-
*
|
|
14
|
-
* For sum types (discriminated unions), {@link variantGenerator} builds
|
|
15
|
-
* a generator that picks a variant uniformly at random and produces an
|
|
16
|
-
* object with the discriminant tag and generated fields.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* class Point {
|
|
21
|
-
* \@field(floats(-100, 100))
|
|
22
|
-
* x!: number;
|
|
23
|
-
*
|
|
24
|
-
* \@field(floats(-100, 100))
|
|
25
|
-
* y!: number;
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* const gen = deriveGenerator(Point);
|
|
29
|
-
* // draw(gen) returns a Point instance with random x, y
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @packageDocumentation
|
|
33
|
-
*/
|
|
34
|
-
import { Generator } from "./generators/index.js";
|
|
35
|
-
import type { TestCaseData } from "./runner.js";
|
|
36
|
-
/**
|
|
37
|
-
* Metadata entry for a single field.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export interface FieldMeta {
|
|
41
|
-
/** The property name on the class instance. */
|
|
42
|
-
name: string | symbol;
|
|
43
|
-
/** The generator to use for this field. */
|
|
44
|
-
generator: Generator;
|
|
45
|
-
/** The order the decorator was applied (for deterministic iteration). */
|
|
46
|
-
order: number;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Type for class constructors in the metadata map.
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
type AnyConstructor = new (...args: any[]) => any;
|
|
53
|
-
/**
|
|
54
|
-
* Map from constructor → ordered list of field metadata.
|
|
55
|
-
* Each class that uses `@field(...)` gets an entry here.
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
export declare const _classFieldMeta: Map<AnyConstructor, FieldMeta[]>;
|
|
59
|
-
/**
|
|
60
|
-
* Reset the field order counter. Only for testing.
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
export declare function _resetFieldOrder(): void;
|
|
64
|
-
/**
|
|
65
|
-
* Decorator that associates a {@link Generator} with a class field.
|
|
66
|
-
*
|
|
67
|
-
* Use this on each field of a class before calling {@link deriveGenerator}.
|
|
68
|
-
* Fields are generated in decorator-application order (typically top to
|
|
69
|
-
* bottom in the class body).
|
|
70
|
-
*
|
|
71
|
-
* Requires `experimentalDecorators: true` in `tsconfig.json`.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* class User {
|
|
76
|
-
* \@field(text(1, 50))
|
|
77
|
-
* name!: string;
|
|
78
|
-
*
|
|
79
|
-
* \@field(integers(18, 120))
|
|
80
|
-
* age!: number;
|
|
81
|
-
* }
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* @param gen - The generator to use for this field's values.
|
|
85
|
-
*/
|
|
86
|
-
export declare function field<T>(gen: Generator<T>): PropertyDecorator;
|
|
87
|
-
/**
|
|
88
|
-
* A generator that produces instances of a class by generating each
|
|
89
|
-
* decorated field independently.
|
|
90
|
-
*
|
|
91
|
-
* Uses a FIXED_DICT span (label 10) to group the field generations,
|
|
92
|
-
* matching the Hegel protocol's semantic for record/struct types.
|
|
93
|
-
*
|
|
94
|
-
* @typeParam T - The class type being generated.
|
|
95
|
-
*/
|
|
96
|
-
export declare class DerivedGenerator<T> extends Generator<T> {
|
|
97
|
-
/** @internal */
|
|
98
|
-
readonly _ctor: new () => T;
|
|
99
|
-
/** @internal */
|
|
100
|
-
readonly _fields: ReadonlyArray<FieldMeta>;
|
|
101
|
-
constructor(ctor: new () => T, fields: FieldMeta[]);
|
|
102
|
-
doDraw(data: TestCaseData): Promise<T>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Derive a generator for a class from its `@field(...)` annotations.
|
|
106
|
-
*
|
|
107
|
-
* Reads the generator metadata registered by the {@link field} decorator
|
|
108
|
-
* and returns a {@link DerivedGenerator} that produces instances of the
|
|
109
|
-
* class with each field independently generated.
|
|
110
|
-
*
|
|
111
|
-
* @param ctor - The class constructor (must have a no-arg constructor).
|
|
112
|
-
* @throws {Error} If the class has no `@field` annotations.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```ts
|
|
116
|
-
* class Config {
|
|
117
|
-
* \@field(booleans()) debug!: boolean;
|
|
118
|
-
* \@field(integers(1, 65535)) port!: number;
|
|
119
|
-
* }
|
|
120
|
-
* const gen = deriveGenerator(Config);
|
|
121
|
-
* const cfg = await draw(gen); // Config { debug: true, port: 8080 }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
export declare function deriveGenerator<T>(ctor: new () => T): DerivedGenerator<T>;
|
|
125
|
-
/**
|
|
126
|
-
* A generator that produces plain objects from a schema mapping.
|
|
127
|
-
*
|
|
128
|
-
* Uses a FIXED_DICT span (label 10) internally.
|
|
129
|
-
*
|
|
130
|
-
* @typeParam T - The resulting object type.
|
|
131
|
-
*/
|
|
132
|
-
export declare class RecordDerivedGenerator<T> extends Generator<T> {
|
|
133
|
-
/** @internal */
|
|
134
|
-
readonly _entries: ReadonlyArray<[string, Generator]>;
|
|
135
|
-
constructor(entries: Array<[string, Generator]>);
|
|
136
|
-
doDraw(data: TestCaseData): Promise<T>;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Derive a generator for a plain-object record type from a schema mapping
|
|
140
|
-
* field names to generators.
|
|
141
|
-
*
|
|
142
|
-
* This is the "no-class" alternative: the user provides the structure
|
|
143
|
-
* explicitly as an object mapping field names to generators. The result
|
|
144
|
-
* is a generator that produces plain objects with the specified fields.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* const pointGen = recordGenerator({
|
|
149
|
-
* x: floats(-100, 100),
|
|
150
|
-
* y: floats(-100, 100),
|
|
151
|
-
* });
|
|
152
|
-
* const pt = await draw(pointGen); // { x: 42.5, y: -3.14 }
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @param schema - Mapping from field name to its generator.
|
|
156
|
-
* @throws {Error} If the schema has no fields.
|
|
157
|
-
*/
|
|
158
|
-
export declare function recordGenerator<S extends Record<string, Generator>>(schema: S): RecordDerivedGenerator<{
|
|
159
|
-
[K in keyof S]: S[K] extends Generator<infer V> ? V : never;
|
|
160
|
-
}>;
|
|
161
|
-
/**
|
|
162
|
-
* A single variant in a discriminated union.
|
|
163
|
-
*/
|
|
164
|
-
export interface VariantDef {
|
|
165
|
-
/** The discriminant value (e.g., "circle", "rectangle"). */
|
|
166
|
-
tag: string;
|
|
167
|
-
/**
|
|
168
|
-
* Generator for the variant's fields. When `null`, the variant has no
|
|
169
|
-
* extra data — the generator produces `{ type: tag }` only.
|
|
170
|
-
*/
|
|
171
|
-
fields: Generator | null;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* A generator that produces values of a discriminated union type.
|
|
175
|
-
*
|
|
176
|
-
* Picks a variant uniformly at random, generates its fields, and returns
|
|
177
|
-
* an object with the discriminant key set to the variant tag, plus the
|
|
178
|
-
* generated field values spread in. Uses an ENUM_VARIANT span (label 15)
|
|
179
|
-
* for each generated value.
|
|
180
|
-
*
|
|
181
|
-
* @typeParam T - The union type being generated.
|
|
182
|
-
*/
|
|
183
|
-
export declare class VariantGenerator<T> extends Generator<T> {
|
|
184
|
-
/** @internal */
|
|
185
|
-
readonly _variants: ReadonlyArray<VariantDef>;
|
|
186
|
-
/** @internal */
|
|
187
|
-
readonly _discriminant: string;
|
|
188
|
-
/** @internal */
|
|
189
|
-
private readonly _indexGen;
|
|
190
|
-
constructor(variants: VariantDef[], discriminant: string);
|
|
191
|
-
doDraw(data: TestCaseData): Promise<T>;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Derive a generator for a discriminated union (sum type).
|
|
195
|
-
*
|
|
196
|
-
* Takes a mapping from variant tag names to their field generators (or
|
|
197
|
-
* `null` for data-less variants). Returns a {@link VariantGenerator}
|
|
198
|
-
* that picks a variant uniformly at random and generates its fields.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```ts
|
|
202
|
-
* type Shape =
|
|
203
|
-
* | { type: "circle"; radius: number }
|
|
204
|
-
* | { type: "rectangle"; width: number; height: number };
|
|
205
|
-
*
|
|
206
|
-
* const shapeGen = variantGenerator<Shape>({
|
|
207
|
-
* circle: recordGenerator({ radius: floats(0.1, 100) }),
|
|
208
|
-
* rectangle: recordGenerator({
|
|
209
|
-
* width: floats(0.1, 100),
|
|
210
|
-
* height: floats(0.1, 100),
|
|
211
|
-
* }),
|
|
212
|
-
* });
|
|
213
|
-
*
|
|
214
|
-
* const shape = await draw(shapeGen);
|
|
215
|
-
* // { type: "circle", radius: 42.5 } or { type: "rectangle", width: 10, height: 20 }
|
|
216
|
-
* ```
|
|
217
|
-
*
|
|
218
|
-
* @param variants - Mapping from tag name to field generator (or `null`
|
|
219
|
-
* for data-less variants).
|
|
220
|
-
* @param discriminant - The discriminant property name. Defaults to `"type"`.
|
|
221
|
-
* @throws {Error} If fewer than 2 variants are provided.
|
|
222
|
-
*/
|
|
223
|
-
export declare function variantGenerator<T>(variants: Record<string, Generator | null>, discriminant?: string): VariantGenerator<T>;
|
|
224
|
-
export {};
|
|
225
|
-
//# sourceMappingURL=derive.d.ts.map
|
package/dist/derive.d.ts.map
DELETED
|
@@ -1 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