@ghostry/fabricator 0.0.13 → 0.0.15
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/esm/Bound.js +74 -1
- package/dist/esm/Distribution/index.js +103 -2
- package/dist/esm/Enumeration/Enumerate.js +10 -5
- package/dist/esm/Enumeration/Plan.js +2 -2
- package/dist/esm/Error/index.js +96 -27
- package/dist/esm/Fabricator/Constructor.js +7 -5
- package/dist/esm/Instance/Core.js +3 -0
- package/dist/esm/Primitive/array/Admits.js +18 -0
- package/dist/esm/Primitive/array/Fabricator.js +20 -2
- package/dist/esm/Primitive/array/Registry.js +32 -0
- package/dist/esm/Primitive/array/Schema.js +8 -0
- package/dist/esm/Primitive/bigint/Admits.js +11 -0
- package/dist/esm/Primitive/bigint/Fabricator.js +16 -23
- package/dist/esm/Primitive/bigint/Registry.js +17 -6
- package/dist/esm/Primitive/bigint/Schema.js +8 -0
- package/dist/esm/Primitive/date/Admits.js +22 -0
- package/dist/esm/Primitive/date/Defaults.js +27 -1
- package/dist/esm/Primitive/date/Fabricator.js +32 -34
- package/dist/esm/Primitive/date/Registry.js +80 -13
- package/dist/esm/Primitive/date/Schema.js +8 -0
- package/dist/esm/Primitive/enum/Fabricator.js +14 -2
- package/dist/esm/Primitive/enum/Registry.js +38 -25
- package/dist/esm/Primitive/index.js +1 -0
- package/dist/esm/Primitive/number/Admits.js +27 -0
- package/dist/esm/Primitive/number/Fabricator.js +18 -9
- package/dist/esm/Primitive/number/Registry.js +55 -4
- package/dist/esm/Primitive/number/Schema.js +10 -3
- package/dist/esm/Primitive/object/Fabricator.js +2 -0
- package/dist/esm/Primitive/record/Admits.js +42 -0
- package/dist/esm/Primitive/record/Fabricator.js +49 -19
- package/dist/esm/Primitive/record/Registry.js +29 -0
- package/dist/esm/Primitive/record/Schema.js +8 -0
- package/dist/esm/Primitive/recursive/Fabricator.js +3 -2
- package/dist/esm/Primitive/recursive/Terminate.js +16 -2
- package/dist/esm/Primitive/string/Admits.js +26 -0
- package/dist/esm/Primitive/string/Capacity.js +81 -0
- package/dist/esm/Primitive/string/Fabricator.js +23 -43
- package/dist/esm/Primitive/string/Registry.js +31 -9
- package/dist/esm/Primitive/string/Schema.js +10 -3
- package/dist/esm/Primitive/string/Sources.js +41 -0
- package/dist/esm/Primitive/unique/Registry.js +22 -0
- package/dist/esm/Primitive/unique/index.js +2 -0
- package/dist/esm/Types.js +2 -1
- package/dist/esm/Unique/Capacity.js +85 -0
- package/dist/esm/Unique/Distinct.js +187 -0
- package/dist/esm/Unique/Key.js +70 -0
- package/dist/esm/Unique/Override.js +23 -0
- package/dist/esm/Unique/Strategy.js +173 -0
- package/dist/esm/internal.js +1 -0
- package/dist/types/Adapter/Core.d.ts +2 -2
- package/dist/types/Adapter/Types.d.ts +1 -1
- package/dist/types/Bound.d.ts +67 -1
- package/dist/types/Distribution/index.d.ts +83 -1
- package/dist/types/Enumeration/Enumerate.d.ts +3 -3
- package/dist/types/Enumeration/Plan.d.ts +1 -1
- package/dist/types/Enumeration/Types.d.ts +14 -5
- package/dist/types/Error/index.d.ts +283 -0
- package/dist/types/Fabricator/Constructor.d.ts +9 -5
- package/dist/types/Fabricator/Fabricate.d.ts +5 -5
- package/dist/types/Fabricator/Types.d.ts +19 -6
- package/dist/types/Harnessing/Core.d.ts +3 -3
- package/dist/types/Harnessing/Salt.d.ts +1 -1
- package/dist/types/Harnessing/Types.d.ts +2 -2
- package/dist/types/Instance/Core.d.ts +4 -4
- package/dist/types/Instance/Stack/Async.d.ts +1 -1
- package/dist/types/Instance/Stack/Sync.d.ts +1 -1
- package/dist/types/Instance/Stack/Visible.d.ts +2 -2
- package/dist/types/Instance/Types.d.ts +19 -5
- package/dist/types/Primitive/always/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/always/Registry.d.ts +2 -2
- package/dist/types/Primitive/always/Schema.d.ts +4 -4
- package/dist/types/Primitive/always/Types.d.ts +2 -2
- package/dist/types/Primitive/always/index.d.ts +5 -5
- package/dist/types/Primitive/array/Admits.d.ts +7 -0
- package/dist/types/Primitive/array/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/array/Registry.d.ts +40 -3
- package/dist/types/Primitive/array/Schema.d.ts +10 -5
- package/dist/types/Primitive/array/Types.d.ts +37 -5
- package/dist/types/Primitive/array/index.d.ts +5 -5
- package/dist/types/Primitive/bigint/Admits.d.ts +7 -0
- package/dist/types/Primitive/bigint/Fabricator.d.ts +8 -6
- package/dist/types/Primitive/bigint/Registry.d.ts +24 -4
- package/dist/types/Primitive/bigint/Schema.d.ts +13 -5
- package/dist/types/Primitive/bigint/Types.d.ts +30 -6
- package/dist/types/Primitive/bigint/index.d.ts +5 -5
- package/dist/types/Primitive/boolean/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/boolean/Registry.d.ts +2 -2
- package/dist/types/Primitive/boolean/Schema.d.ts +5 -5
- package/dist/types/Primitive/boolean/Types.d.ts +3 -3
- package/dist/types/Primitive/boolean/index.d.ts +6 -6
- package/dist/types/Primitive/choice/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/choice/Registry.d.ts +2 -2
- package/dist/types/Primitive/choice/Schema.d.ts +5 -5
- package/dist/types/Primitive/choice/Types.d.ts +4 -4
- package/dist/types/Primitive/choice/index.d.ts +5 -5
- package/dist/types/Primitive/date/Admits.d.ts +7 -0
- package/dist/types/Primitive/date/Defaults.d.ts +22 -1
- package/dist/types/Primitive/date/Fabricator.d.ts +8 -6
- package/dist/types/Primitive/date/Registry.d.ts +49 -13
- package/dist/types/Primitive/date/Schema.d.ts +14 -5
- package/dist/types/Primitive/date/Types.d.ts +57 -8
- package/dist/types/Primitive/date/index.d.ts +5 -5
- package/dist/types/Primitive/derive/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/derive/Registry.d.ts +2 -2
- package/dist/types/Primitive/derive/Schema.d.ts +6 -6
- package/dist/types/Primitive/derive/Types.d.ts +6 -6
- package/dist/types/Primitive/derive/index.d.ts +5 -5
- package/dist/types/Primitive/enum/Fabricator.d.ts +8 -6
- package/dist/types/Primitive/enum/Registry.d.ts +22 -2
- package/dist/types/Primitive/enum/Schema.d.ts +5 -5
- package/dist/types/Primitive/enum/Types.d.ts +8 -3
- package/dist/types/Primitive/enum/index.d.ts +5 -5
- package/dist/types/Primitive/index.d.ts +28 -27
- package/dist/types/Primitive/namespace.d.ts +21 -21
- package/dist/types/Primitive/null/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/null/Registry.d.ts +1 -1
- package/dist/types/Primitive/null/Schema.d.ts +4 -4
- package/dist/types/Primitive/null/Types.d.ts +2 -2
- package/dist/types/Primitive/null/index.d.ts +5 -5
- package/dist/types/Primitive/nullable/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/nullable/Registry.d.ts +2 -2
- package/dist/types/Primitive/nullable/Schema.d.ts +6 -6
- package/dist/types/Primitive/nullable/Types.d.ts +5 -5
- package/dist/types/Primitive/nullable/index.d.ts +6 -6
- package/dist/types/Primitive/nullish/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/nullish/Registry.d.ts +2 -2
- package/dist/types/Primitive/nullish/Schema.d.ts +6 -6
- package/dist/types/Primitive/nullish/Types.d.ts +5 -5
- package/dist/types/Primitive/nullish/index.d.ts +6 -6
- package/dist/types/Primitive/number/Admits.d.ts +9 -0
- package/dist/types/Primitive/number/Defaults.d.ts +1 -1
- package/dist/types/Primitive/number/Fabricator.d.ts +8 -6
- package/dist/types/Primitive/number/Registry.d.ts +45 -4
- package/dist/types/Primitive/number/Schema.d.ts +14 -6
- package/dist/types/Primitive/number/Types.d.ts +36 -14
- package/dist/types/Primitive/number/index.d.ts +5 -5
- package/dist/types/Primitive/object/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/object/Registry.d.ts +4 -4
- package/dist/types/Primitive/object/Schema.d.ts +8 -8
- package/dist/types/Primitive/object/Types.d.ts +6 -6
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/object/compute/Registry.d.ts +2 -2
- package/dist/types/Primitive/object/compute/Schema.d.ts +7 -7
- package/dist/types/Primitive/object/compute/Types.d.ts +3 -3
- package/dist/types/Primitive/object/compute/index.d.ts +5 -5
- package/dist/types/Primitive/object/index.d.ts +8 -8
- package/dist/types/Primitive/object/omit/Registry.d.ts +2 -2
- package/dist/types/Primitive/object/omit/index.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/object/omittable/Registry.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Schema.d.ts +6 -6
- package/dist/types/Primitive/object/omittable/Types.d.ts +5 -5
- package/dist/types/Primitive/object/omittable/index.d.ts +6 -6
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/object/optional/Registry.d.ts +2 -2
- package/dist/types/Primitive/object/optional/Schema.d.ts +6 -6
- package/dist/types/Primitive/object/optional/Types.d.ts +5 -5
- package/dist/types/Primitive/object/optional/index.d.ts +6 -6
- package/dist/types/Primitive/object/pick/Registry.d.ts +2 -2
- package/dist/types/Primitive/object/pick/index.d.ts +2 -2
- package/dist/types/Primitive/opaque/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/opaque/Registry.d.ts +2 -2
- package/dist/types/Primitive/opaque/Schema.d.ts +4 -4
- package/dist/types/Primitive/opaque/Types.d.ts +3 -3
- package/dist/types/Primitive/opaque/index.d.ts +5 -5
- package/dist/types/Primitive/record/Admits.d.ts +18 -0
- package/dist/types/Primitive/record/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/record/Registry.d.ts +20 -3
- package/dist/types/Primitive/record/Schema.d.ts +12 -5
- package/dist/types/Primitive/record/Types.d.ts +64 -10
- package/dist/types/Primitive/record/index.d.ts +5 -5
- package/dist/types/Primitive/recursive/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/recursive/Registry.d.ts +4 -4
- package/dist/types/Primitive/recursive/Schema.d.ts +4 -4
- package/dist/types/Primitive/recursive/Terminate.d.ts +8 -1
- package/dist/types/Primitive/recursive/Types.d.ts +3 -3
- package/dist/types/Primitive/recursive/index.d.ts +6 -6
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +5 -5
- package/dist/types/Primitive/recursive/self/Registry.d.ts +1 -1
- package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
- package/dist/types/Primitive/recursive/self/Types.d.ts +2 -2
- package/dist/types/Primitive/recursive/self/index.d.ts +5 -5
- package/dist/types/Primitive/string/Admits.d.ts +8 -0
- package/dist/types/Primitive/string/Capacity.d.ts +36 -0
- package/dist/types/Primitive/string/Constants.d.ts +1 -1
- package/dist/types/Primitive/string/Fabricator.d.ts +8 -6
- package/dist/types/Primitive/string/Registry.d.ts +29 -8
- package/dist/types/Primitive/string/Schema.d.ts +32 -6
- package/dist/types/Primitive/string/Sources.d.ts +16 -0
- package/dist/types/Primitive/string/Types.d.ts +39 -19
- package/dist/types/Primitive/string/index.d.ts +6 -6
- package/dist/types/Primitive/symbol/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/symbol/Registry.d.ts +2 -2
- package/dist/types/Primitive/symbol/Schema.d.ts +5 -5
- package/dist/types/Primitive/symbol/Types.d.ts +3 -3
- package/dist/types/Primitive/symbol/index.d.ts +5 -5
- package/dist/types/Primitive/tuple/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/tuple/Registry.d.ts +2 -2
- package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
- package/dist/types/Primitive/tuple/Types.d.ts +4 -4
- package/dist/types/Primitive/tuple/index.d.ts +5 -5
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/undefinable/Registry.d.ts +2 -2
- package/dist/types/Primitive/undefinable/Schema.d.ts +6 -6
- package/dist/types/Primitive/undefinable/Types.d.ts +5 -5
- package/dist/types/Primitive/undefinable/index.d.ts +6 -6
- package/dist/types/Primitive/undefined/Fabricator.d.ts +6 -6
- package/dist/types/Primitive/undefined/Registry.d.ts +1 -1
- package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +2 -2
- package/dist/types/Primitive/undefined/index.d.ts +5 -5
- package/dist/types/Primitive/unique/Registry.d.ts +39 -0
- package/dist/types/Primitive/unique/index.d.ts +2 -0
- package/dist/types/Random/Generator/sfc32.d.ts +1 -1
- package/dist/types/Random/Types.d.ts +1 -1
- package/dist/types/Random/index.d.ts +1 -1
- package/dist/types/Schema/Core.d.ts +5 -5
- package/dist/types/Schema/Registry.d.ts +3 -3
- package/dist/types/Schema/Satisfies.d.ts +3 -3
- package/dist/types/Schema/Types.d.ts +5 -5
- package/dist/types/Types.d.ts +11 -2
- package/dist/types/Unique/Capacity.d.ts +29 -0
- package/dist/types/Unique/Distinct.d.ts +95 -0
- package/dist/types/Unique/Key.d.ts +29 -0
- package/dist/types/Unique/Override.d.ts +16 -0
- package/dist/types/Unique/Strategy.d.ts +135 -0
- package/dist/types/Utility/Core.d.ts +2 -2
- package/dist/types/Utility/DeepMerge.d.ts +2 -2
- package/dist/types/Utility/ShallowMerge.d.ts +2 -2
- package/dist/types/adapting.d.ts +3 -3
- package/dist/types/harnessing.d.ts +2 -2
- package/dist/types/index.d.ts +40 -27
- package/dist/types/internal.d.ts +16 -15
- package/package.json +2 -2
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* stands on its own: a consumer reading only `.message` should not need a field
|
|
13
13
|
* to understand the failure. Fields are for programmatic access, and for detail
|
|
14
14
|
* too bulky to inline.
|
|
15
|
+
*
|
|
16
|
+
* A `name` is the package and the class,
|
|
17
|
+
* `"@ghostry/fabricator:UnknownFieldError"`, so it identifies an error where
|
|
18
|
+
* `instanceof` cannot: across two installed copies of this package, or after
|
|
19
|
+
* the error is serialized. `:`, not `/`, which would read as a subpath export.
|
|
20
|
+
* A package extending {@link FabricatorError} prefixes its own errors with its
|
|
21
|
+
* own name.
|
|
15
22
|
*/
|
|
16
23
|
/**
|
|
17
24
|
* Base error class from which more specific errors inherit.
|
|
@@ -101,6 +108,46 @@ export declare namespace FabricatorError {
|
|
|
101
108
|
*/
|
|
102
109
|
path: ReadonlyArray<string>);
|
|
103
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* `T.recursive(body).whereby({ depth })` with no `terminal`, when the derived
|
|
113
|
+
* terminal must empty a collection of `self` that states a minimum above 0.
|
|
114
|
+
* Every branch ends at the depth limit with that collection empty, and an
|
|
115
|
+
* adapter states the minimum as written, so no finite tree could pass the
|
|
116
|
+
* validation it builds. Thrown at `.whereby()`. `.admits({ length: { min: 0 }
|
|
117
|
+
* })` on the collection keeps drawing at least the minimum below the limit
|
|
118
|
+
* while stating none for the adapter.
|
|
119
|
+
*/
|
|
120
|
+
class UnsatisfiableRecursiveBoundError extends FabricatorError {
|
|
121
|
+
/**
|
|
122
|
+
* Structural path from the recursive body to the collection, as field
|
|
123
|
+
* names / slot indices.
|
|
124
|
+
*/
|
|
125
|
+
readonly path: ReadonlyArray<string>;
|
|
126
|
+
/**
|
|
127
|
+
* The collection's bound — `"length"` for an array, `"size"` for a
|
|
128
|
+
* record.
|
|
129
|
+
*/
|
|
130
|
+
readonly key: "length" | "size";
|
|
131
|
+
/**
|
|
132
|
+
* The smallest count the collection states, as an inclusive integer.
|
|
133
|
+
*/
|
|
134
|
+
readonly min: number;
|
|
135
|
+
constructor(
|
|
136
|
+
/**
|
|
137
|
+
* Structural path from the recursive body to the collection, as field
|
|
138
|
+
* names / slot indices.
|
|
139
|
+
*/
|
|
140
|
+
path: ReadonlyArray<string>,
|
|
141
|
+
/**
|
|
142
|
+
* The collection's bound — `"length"` for an array, `"size"` for a
|
|
143
|
+
* record.
|
|
144
|
+
*/
|
|
145
|
+
key: "length" | "size",
|
|
146
|
+
/**
|
|
147
|
+
* The smallest count the collection states, as an inclusive integer.
|
|
148
|
+
*/
|
|
149
|
+
min: number);
|
|
150
|
+
}
|
|
104
151
|
/**
|
|
105
152
|
* A walk reached a node whose `[Kind]` it has no case for — a Schema built by
|
|
106
153
|
* hand or cast past the type system, or a kind added to `Primitive/index.ts`
|
|
@@ -469,6 +516,102 @@ export declare namespace FabricatorError {
|
|
|
469
516
|
readonly exclusive: boolean;
|
|
470
517
|
});
|
|
471
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* A bound given as a `number` that does not convert exactly to its kind's
|
|
521
|
+
* type — a fractional or unsafe integer for a `bigint`, an instant `Date`
|
|
522
|
+
* cannot hold — or a non-finite value where an end must be finite.
|
|
523
|
+
*/
|
|
524
|
+
class InvalidBoundError extends FabricatorError {
|
|
525
|
+
/**
|
|
526
|
+
* What was called, e.g. `"T.bigint.whereby"` or `".admits on a bigint
|
|
527
|
+
* schema"`.
|
|
528
|
+
*/
|
|
529
|
+
readonly label: string;
|
|
530
|
+
/**
|
|
531
|
+
* Which end was rejected.
|
|
532
|
+
*/
|
|
533
|
+
readonly end: "min" | "max";
|
|
534
|
+
/**
|
|
535
|
+
* The rejected value, as given.
|
|
536
|
+
*/
|
|
537
|
+
readonly value: number;
|
|
538
|
+
/**
|
|
539
|
+
* What the end accepts, in words — e.g. `"a safe integer or a bigint"`.
|
|
540
|
+
*/
|
|
541
|
+
readonly expected: string;
|
|
542
|
+
constructor(
|
|
543
|
+
/**
|
|
544
|
+
* What was called, e.g. `"T.bigint.whereby"` or `".admits on a bigint
|
|
545
|
+
* schema"`.
|
|
546
|
+
*/
|
|
547
|
+
label: string,
|
|
548
|
+
/**
|
|
549
|
+
* Which end was rejected.
|
|
550
|
+
*/
|
|
551
|
+
end: "min" | "max",
|
|
552
|
+
/**
|
|
553
|
+
* The rejected value, as given.
|
|
554
|
+
*/
|
|
555
|
+
value: number,
|
|
556
|
+
/**
|
|
557
|
+
* What the end accepts, in words — e.g. `"a safe integer or a bigint"`.
|
|
558
|
+
*/
|
|
559
|
+
expected: string);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* `.admits(...)` names an end that excludes values the schema fabricates.
|
|
563
|
+
* Admitted ends may only widen the fabricated range — a fabricated value must
|
|
564
|
+
* pass the validation an adapter builds from them.
|
|
565
|
+
*/
|
|
566
|
+
class AdmitsExcludesDrawError extends FabricatorError {
|
|
567
|
+
/**
|
|
568
|
+
* What was called, e.g. `".admits on a string schema"`.
|
|
569
|
+
*/
|
|
570
|
+
readonly label: string;
|
|
571
|
+
/**
|
|
572
|
+
* The rejected end's path, e.g. `"length.max"` or `"min"`.
|
|
573
|
+
*/
|
|
574
|
+
readonly end: string;
|
|
575
|
+
/**
|
|
576
|
+
* The admitted end, canonical as stored.
|
|
577
|
+
*/
|
|
578
|
+
readonly admitted: {
|
|
579
|
+
readonly value: unknown;
|
|
580
|
+
readonly exclusive: boolean;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* The fabricated end it excludes values from; absent when that end is
|
|
584
|
+
* drawn against the kind's unbounded cap, which only no limit admits.
|
|
585
|
+
*/
|
|
586
|
+
readonly fabricated: {
|
|
587
|
+
readonly value: unknown;
|
|
588
|
+
readonly exclusive: boolean;
|
|
589
|
+
} | undefined;
|
|
590
|
+
constructor(
|
|
591
|
+
/**
|
|
592
|
+
* What was called, e.g. `".admits on a string schema"`.
|
|
593
|
+
*/
|
|
594
|
+
label: string,
|
|
595
|
+
/**
|
|
596
|
+
* The rejected end's path, e.g. `"length.max"` or `"min"`.
|
|
597
|
+
*/
|
|
598
|
+
end: string,
|
|
599
|
+
/**
|
|
600
|
+
* The admitted end, canonical as stored.
|
|
601
|
+
*/
|
|
602
|
+
admitted: {
|
|
603
|
+
readonly value: unknown;
|
|
604
|
+
readonly exclusive: boolean;
|
|
605
|
+
},
|
|
606
|
+
/**
|
|
607
|
+
* The fabricated end it excludes values from; absent when that end is
|
|
608
|
+
* drawn against the kind's unbounded cap, which only no limit admits.
|
|
609
|
+
*/
|
|
610
|
+
fabricated: {
|
|
611
|
+
readonly value: unknown;
|
|
612
|
+
readonly exclusive: boolean;
|
|
613
|
+
} | undefined);
|
|
614
|
+
}
|
|
472
615
|
/**
|
|
473
616
|
* A distribution's bounds fall outside its own domain — a `logarithmic`
|
|
474
617
|
* distribution's density is proportional to `1/x`, so it is undefined at or
|
|
@@ -648,4 +791,144 @@ export declare namespace FabricatorError {
|
|
|
648
791
|
class HarnessingProviderError extends FabricatorError {
|
|
649
792
|
constructor();
|
|
650
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
* Where a unique leaf that ran out sits directly inside a plain collection —
|
|
796
|
+
* the element of a `T.array` or the key of a `T.record`. Such a leaf stays
|
|
797
|
+
* distinct across every value the collection makes, which is easy to mistake
|
|
798
|
+
* for distinct within one, so the message names `T.unique.array`/
|
|
799
|
+
* `T.unique.record`.
|
|
800
|
+
*/
|
|
801
|
+
type UniqueWithin = "array" | "record";
|
|
802
|
+
/**
|
|
803
|
+
* A `T.unique.*` leaf asked for one more value than its domain holds. Thrown
|
|
804
|
+
* on draw n + 1 of an n-value domain whatever the salt, since a domain with a
|
|
805
|
+
* known size is counted rather than searched (`Unique/Distinct.ts`).
|
|
806
|
+
*/
|
|
807
|
+
class UniqueExhaustedError extends FabricatorError {
|
|
808
|
+
/**
|
|
809
|
+
* The `[Kind]` of the exhausted schema.
|
|
810
|
+
*/
|
|
811
|
+
readonly kind: string;
|
|
812
|
+
/**
|
|
813
|
+
* How many distinct values the domain holds — every one of them already
|
|
814
|
+
* produced or claimed.
|
|
815
|
+
*/
|
|
816
|
+
readonly capacity: bigint;
|
|
817
|
+
/**
|
|
818
|
+
* The plain collection the leaf sits directly inside, when it does.
|
|
819
|
+
*/
|
|
820
|
+
readonly collection?: UniqueWithin | undefined;
|
|
821
|
+
constructor(
|
|
822
|
+
/**
|
|
823
|
+
* The `[Kind]` of the exhausted schema.
|
|
824
|
+
*/
|
|
825
|
+
kind: string,
|
|
826
|
+
/**
|
|
827
|
+
* How many distinct values the domain holds — every one of them already
|
|
828
|
+
* produced or claimed.
|
|
829
|
+
*/
|
|
830
|
+
capacity: bigint,
|
|
831
|
+
/**
|
|
832
|
+
* The plain collection the leaf sits directly inside, when it does.
|
|
833
|
+
*/
|
|
834
|
+
collection?: UniqueWithin | undefined);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* A unique draw over a domain of unknown size kept landing on values it had
|
|
838
|
+
* already produced, and forfeited after its redraws ran out rather than loop
|
|
839
|
+
* forever. Either the domain is used up, or it is skewed enough that its
|
|
840
|
+
* remaining values are rare — a higher `redraws` is for the second case.
|
|
841
|
+
*/
|
|
842
|
+
class UniqueRedrawsError extends FabricatorError {
|
|
843
|
+
/**
|
|
844
|
+
* The registry entry or call site, e.g. `"T.unique.array"`.
|
|
845
|
+
*/
|
|
846
|
+
readonly label: string;
|
|
847
|
+
/**
|
|
848
|
+
* How many redraws the draw was allowed after its first, each of which
|
|
849
|
+
* also repeated a value already produced.
|
|
850
|
+
*/
|
|
851
|
+
readonly redraws: number;
|
|
852
|
+
/**
|
|
853
|
+
* How many distinct values the scope had produced when it gave up.
|
|
854
|
+
*/
|
|
855
|
+
readonly produced: number;
|
|
856
|
+
/**
|
|
857
|
+
* The plain collection a unique leaf sits directly inside, when it does.
|
|
858
|
+
*/
|
|
859
|
+
readonly collection?: UniqueWithin | undefined;
|
|
860
|
+
constructor(
|
|
861
|
+
/**
|
|
862
|
+
* The registry entry or call site, e.g. `"T.unique.array"`.
|
|
863
|
+
*/
|
|
864
|
+
label: string,
|
|
865
|
+
/**
|
|
866
|
+
* How many redraws the draw was allowed after its first, each of which
|
|
867
|
+
* also repeated a value already produced.
|
|
868
|
+
*/
|
|
869
|
+
redraws: number,
|
|
870
|
+
/**
|
|
871
|
+
* How many distinct values the scope had produced when it gave up.
|
|
872
|
+
*/
|
|
873
|
+
produced: number,
|
|
874
|
+
/**
|
|
875
|
+
* The plain collection a unique leaf sits directly inside, when it does.
|
|
876
|
+
*/
|
|
877
|
+
collection?: UniqueWithin | undefined);
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* A unique collection could draw more members than its member schema has
|
|
881
|
+
* distinct values. Thrown at construction, so the draw that would run out
|
|
882
|
+
* never depends on the salt.
|
|
883
|
+
*/
|
|
884
|
+
class UniqueCapacityError extends FabricatorError {
|
|
885
|
+
/**
|
|
886
|
+
* The registry entry, e.g. `"T.unique.array"`.
|
|
887
|
+
*/
|
|
888
|
+
readonly label: string;
|
|
889
|
+
/**
|
|
890
|
+
* How many distinct values the member schema has.
|
|
891
|
+
*/
|
|
892
|
+
readonly capacity: bigint;
|
|
893
|
+
/**
|
|
894
|
+
* The largest member count the collection may draw.
|
|
895
|
+
*/
|
|
896
|
+
readonly requested: number;
|
|
897
|
+
constructor(
|
|
898
|
+
/**
|
|
899
|
+
* The registry entry, e.g. `"T.unique.array"`.
|
|
900
|
+
*/
|
|
901
|
+
label: string,
|
|
902
|
+
/**
|
|
903
|
+
* How many distinct values the member schema has.
|
|
904
|
+
*/
|
|
905
|
+
capacity: bigint,
|
|
906
|
+
/**
|
|
907
|
+
* The largest member count the collection may draw.
|
|
908
|
+
*/
|
|
909
|
+
requested: number);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* `redraws` on a unique builder is not a whole number from `0` up, so it
|
|
913
|
+
* could never be a count of retries.
|
|
914
|
+
*/
|
|
915
|
+
class InvalidRedrawsError extends FabricatorError {
|
|
916
|
+
/**
|
|
917
|
+
* The registry entry, e.g. `"T.unique.array.whereby"`.
|
|
918
|
+
*/
|
|
919
|
+
readonly label: string;
|
|
920
|
+
/**
|
|
921
|
+
* The rejected value.
|
|
922
|
+
*/
|
|
923
|
+
readonly redraws: number;
|
|
924
|
+
constructor(
|
|
925
|
+
/**
|
|
926
|
+
* The registry entry, e.g. `"T.unique.array.whereby"`.
|
|
927
|
+
*/
|
|
928
|
+
label: string,
|
|
929
|
+
/**
|
|
930
|
+
* The rejected value.
|
|
931
|
+
*/
|
|
932
|
+
redraws: number);
|
|
933
|
+
}
|
|
651
934
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Ancestry, Stack } from "../Instance/Types";
|
|
2
|
-
import type { ConstructorOptions, RandomSource } from "../Random/Types";
|
|
3
|
-
import { type Buildable } from "../Types";
|
|
4
|
-
import { type AsFabricator } from "./Types";
|
|
1
|
+
import type { Ancestry, Stack } from "../Instance/Types.ts";
|
|
2
|
+
import type { ConstructorOptions, RandomSource } from "../Random/Types.ts";
|
|
3
|
+
import { type Buildable } from "../Types.ts";
|
|
4
|
+
import { type AsFabricator, type Exhaustion } from "./Types.ts";
|
|
5
5
|
/**
|
|
6
6
|
* The type of `construct()` itself, as handed back by `Constructor` — kept
|
|
7
7
|
* separate so `initialize`'s return type (`src/index.ts`) can name it without
|
|
@@ -40,5 +40,9 @@ export type Constructor = {
|
|
|
40
40
|
* should resolve "now" against. `toConstructionContext` reads it straight off
|
|
41
41
|
* the resolved construction trace rather than threading a second value
|
|
42
42
|
* alongside `source`.
|
|
43
|
+
*
|
|
44
|
+
* `exhaustion` is how this constructor's `T.unique.*` leaves treat running out
|
|
45
|
+
* (`Fabricator/Types.ts`'s `Exhaustion`); only `Enumeration/Enumerate.ts`
|
|
46
|
+
* passes anything but the default.
|
|
43
47
|
*/
|
|
44
|
-
export declare function Constructor(source: RandomSource, stack: Stack, ancestry: Ancestry): Constructor;
|
|
48
|
+
export declare function Constructor(source: RandomSource, stack: Stack, ancestry: Ancestry, exhaustion?: Exhaustion): Constructor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Ancestry, Stack } from "../Instance/Types";
|
|
2
|
-
import type { RandomSource } from "../Random/Types";
|
|
3
|
-
import type { AnySchema, Fabricated } from "../Schema/Types";
|
|
4
|
-
import type { Constructor } from "./Constructor";
|
|
5
|
-
import type { NaiveFabricator } from "./Types";
|
|
1
|
+
import type { Ancestry, Stack } from "../Instance/Types.ts";
|
|
2
|
+
import type { RandomSource } from "../Random/Types.ts";
|
|
3
|
+
import type { AnySchema, Fabricated } from "../Schema/Types.ts";
|
|
4
|
+
import type { Constructor } from "./Constructor.ts";
|
|
5
|
+
import type { NaiveFabricator } from "./Types.ts";
|
|
6
6
|
/**
|
|
7
7
|
* `new Fabricator(schema).fabricate()` in one call, without a build per call:
|
|
8
8
|
* the first call with a given schema in a given scope builds, and every later
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Adaptations, AdaptationsOf } from "../Adapter/Types";
|
|
2
|
-
import type { Primitive, Kind as SchemaKind } from "../Primitive";
|
|
3
|
-
import type { Algorithm, RandomSource, Salt, Trace } from "../Random/Types";
|
|
4
|
-
import type { Fabricated } from "../Schema/Types";
|
|
5
|
-
import type { Adaptation, Kind, Meta, Produced, Produces } from "../Types";
|
|
6
|
-
import type { PlainObject } from "../Utility/Types";
|
|
1
|
+
import type { Adaptations, AdaptationsOf } from "../Adapter/Types.ts";
|
|
2
|
+
import type { Primitive, Kind as SchemaKind } from "../Primitive/index.ts";
|
|
3
|
+
import type { Algorithm, RandomSource, Salt, Trace } from "../Random/Types.ts";
|
|
4
|
+
import type { Fabricated } from "../Schema/Types.ts";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../Types.ts";
|
|
6
|
+
import type { PlainObject } from "../Utility/Types.ts";
|
|
7
7
|
/**
|
|
8
8
|
* Threaded through `Constructor.ts`'s `make` for every dispatch of one `new
|
|
9
9
|
* Fabricator(...)` construction — every branch forwards it (extending `path`,
|
|
@@ -47,7 +47,19 @@ export type ConstructionContext = {
|
|
|
47
47
|
algorithm: Algorithm;
|
|
48
48
|
fork: (salt: Salt) => RandomSource;
|
|
49
49
|
self?: (() => unknown) | undefined;
|
|
50
|
+
exhaustion: Exhaustion;
|
|
50
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* What a `T.unique.*` leaf does once its values run out. `"throw"` everywhere
|
|
54
|
+
* except `combinatorial`/`coverage`, whose builds pass `"cycle"`
|
|
55
|
+
* (`Enumeration/Enumerate.ts`): an enumeration is a testing schedule over its
|
|
56
|
+
* axes, and a unique leaf with fewer values than the schedule has instances
|
|
57
|
+
* starts a fresh round rather than failing the schedule partway. Carried on the
|
|
58
|
+
* construction rather than the Schema, so the same Schema throws when built
|
|
59
|
+
* anywhere else. Unique collections are unaffected: cycling inside one array
|
|
60
|
+
* would repeat a member within one value.
|
|
61
|
+
*/
|
|
62
|
+
export type Exhaustion = "throw" | "cycle";
|
|
51
63
|
/**
|
|
52
64
|
* What every kind's `Fabricator(...)` receives in place of a repeated `(schema,
|
|
53
65
|
* algorithm, trace)` positional list — `Constructor.ts`'s `make` builds one per
|
|
@@ -68,6 +80,7 @@ export type FabricatorContext<$Schema> = {
|
|
|
68
80
|
schema: $Schema;
|
|
69
81
|
algorithm: Algorithm;
|
|
70
82
|
trace: Trace;
|
|
83
|
+
exhaustion: Exhaustion;
|
|
71
84
|
};
|
|
72
85
|
/**
|
|
73
86
|
* The most basic interface for a typed Fabricator. No type introspection is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Instance } from "../Instance/Types";
|
|
2
|
-
import type { PlainObject } from "../Utility/Types";
|
|
3
|
-
import type { FabricatorTestContext, Integration } from "./Types";
|
|
1
|
+
import type { Instance } from "../Instance/Types.ts";
|
|
2
|
+
import type { PlainObject } from "../Utility/Types.ts";
|
|
3
|
+
import type { FabricatorTestContext, Integration } from "./Types.ts";
|
|
4
4
|
/**
|
|
5
5
|
* Decorate an existing `Instance` as a `@ghostry/harness` integration. The
|
|
6
6
|
* whole of it is `context.scope().wrap({ salt: layer(saltFor(identity)) })` —
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Instance } from "../Instance/Types";
|
|
2
|
-
import type { PlainObject } from "../Utility/Types";
|
|
1
|
+
import type { Instance } from "../Instance/Types.ts";
|
|
2
|
+
import type { PlainObject } from "../Utility/Types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* What identifies one registered test or suite — the material a salt is derived
|
|
5
5
|
* from. Named to match how this codebase already talks about the concept:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type FabricatorCache } from "../Fabricator/Fabricate";
|
|
2
|
-
import type { RandomSource } from "../Random/Types";
|
|
3
|
-
import type { PlainObject } from "../Utility/Types";
|
|
4
|
-
import type { Ancestry, Config, Instance, Overlay, Stack } from "./Types";
|
|
1
|
+
import { type FabricatorCache } from "../Fabricator/Fabricate.ts";
|
|
2
|
+
import type { RandomSource } from "../Random/Types.ts";
|
|
3
|
+
import type { PlainObject } from "../Utility/Types.ts";
|
|
4
|
+
import type { Ancestry, Config, Instance, Overlay, Stack } from "./Types.ts";
|
|
5
5
|
/**
|
|
6
6
|
* `combinatorial`'s default limit — `2**10`, so it admits ten independent
|
|
7
7
|
* binary axes before requiring the caller to raise it explicitly. Each
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RandomSource } from "../../Random/Types";
|
|
2
|
-
import type { Ancestry, Frame, Stack } from "../Types";
|
|
1
|
+
import type { RandomSource } from "../../Random/Types.ts";
|
|
2
|
+
import type { Ancestry, Frame, Stack } from "../Types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* The frames in `frames` that `ancestry` may resolve against, outermost first —
|
|
5
5
|
* the single definition of {@link Stack.visible}'s rule, which both carriers
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
1
|
+
import type { Capacity } from "../Unique/Capacity.ts";
|
|
2
|
+
import type { Enumerable, Limits } from "../Enumeration/Types.ts";
|
|
3
|
+
import type { Constructor } from "../Fabricator/Constructor.ts";
|
|
4
|
+
import type { Fabricate } from "../Fabricator/Fabricate.ts";
|
|
5
|
+
import type { Algorithm, Layered, RandomSource, Salt } from "../Random/Types.ts";
|
|
6
|
+
import type { PlainObject } from "../Utility/Types.ts";
|
|
6
7
|
/**
|
|
7
8
|
* A fully resolved instance configuration — every field present, nothing left
|
|
8
9
|
* to default. `Overlay` is what `fork` accepts; `overlay()`
|
|
@@ -286,6 +287,19 @@ export interface Instance<$Registry extends PlainObject> extends Pick<RandomSour
|
|
|
286
287
|
* it carries no limit.
|
|
287
288
|
*/
|
|
288
289
|
coverage: Enumerable;
|
|
290
|
+
/**
|
|
291
|
+
* How many times one built Fabricator of `schema` can `fabricate()` before a
|
|
292
|
+
* `T.unique.*` leaf runs out, or `undefined` when no leaf has a known limit.
|
|
293
|
+
* For a fresh Fabricator, so it does not count what an existing one has
|
|
294
|
+
* drawn. Builds nothing, so it shifts no later draw. A `date` leaf's
|
|
295
|
+
* `past`/`future` end is read against the built Fabricator's clock when one
|
|
296
|
+
* is passed, otherwise against `context.clock`. See `Unique/Capacity.ts` for
|
|
297
|
+
* what it counts.
|
|
298
|
+
*
|
|
299
|
+
* Compare it with `coverage(schema).size` or `combinatorial(schema).size` to
|
|
300
|
+
* know whether every enumerated instance can hold distinct values.
|
|
301
|
+
*/
|
|
302
|
+
capacity: Capacity;
|
|
289
303
|
/**
|
|
290
304
|
* Derive a new instance laid over this one: anything the overlay names
|
|
291
305
|
* overrides, anything it omits inherits. A bare `salt` replaces this
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
-
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
|
-
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
-
import { Schema } from "./Schema";
|
|
6
|
-
import type { Fabricated, Meta as ThisMeta, Value } from "./Types";
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types.ts";
|
|
2
|
+
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types.ts";
|
|
3
|
+
import type { Trace } from "../../Random/Types.ts";
|
|
4
|
+
import { Kind, Meta, type Adaptation } from "../../Types.ts";
|
|
5
|
+
import { Schema } from "./Schema.ts";
|
|
6
|
+
import type { Fabricated, Meta as ThisMeta, Value } from "./Types.ts";
|
|
7
7
|
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema> ? Fabricated<$Schema[typeof Meta]["value"]> : never;
|
|
8
8
|
export type Fabricator<$Schema extends {
|
|
9
9
|
[Meta]: ThisMeta;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Schema } from "./Schema";
|
|
2
|
-
import type { Value } from "./Types";
|
|
1
|
+
import { Schema } from "./Schema.ts";
|
|
2
|
+
import type { Value } from "./Types.ts";
|
|
3
3
|
export default function <const $Value extends Value>(value: $Value): Schema<$Value>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type AdaptationEntry } from "../../Adapter/Core";
|
|
2
|
-
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
|
-
import { type SatisfiesThis } from "../../Schema/Satisfies";
|
|
4
|
-
import type { Core, Fabricated, Value } from "./Types";
|
|
1
|
+
import { type AdaptationEntry } from "../../Adapter/Core.ts";
|
|
2
|
+
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types.ts";
|
|
3
|
+
import { type SatisfiesThis } from "../../Schema/Satisfies.ts";
|
|
4
|
+
import type { Core, Fabricated, Value } from "./Types.ts";
|
|
5
5
|
/**
|
|
6
6
|
* A fixed value, so unlike every other kind there is no `.as()` — nothing left
|
|
7
7
|
* to override about producing it. `adapt` still applies: what a value _means_
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types.ts";
|
|
2
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Any value at all. Deliberately unconstrained: fabricating a fixed value needs
|
|
5
5
|
* nothing of it. A `string | number | boolean` cap would be TypeBox's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./Types";
|
|
2
|
-
export * from "./Schema";
|
|
3
|
-
export * from "./Fabricator";
|
|
4
|
-
export * from "./Registry";
|
|
5
|
-
export { default } from "./Registry";
|
|
1
|
+
export * from "./Types.ts";
|
|
2
|
+
export * from "./Schema.ts";
|
|
3
|
+
export * from "./Fabricator.ts";
|
|
4
|
+
export * from "./Registry.ts";
|
|
5
|
+
export { default } from "./Registry.ts";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Admits, InputAdmits, Meta } from "./Types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `.admits(...)` against what is admitted already: `meta.admits`, or by
|
|
4
|
+
* default the drawn `length` — what an adapter states without one. Under
|
|
5
|
+
* `.as(produce)` nothing is drawn, so nothing is checked.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toAdmits(meta: Meta, input: InputAdmits): Admits;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
-
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
|
-
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Children, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
-
import { Schema } from "./Schema";
|
|
6
|
-
import type { Definition, Fabricated, Meta as ThisMeta } from "./Types";
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types.ts";
|
|
2
|
+
import type { Fabricator as BaseFabricator, FabricatorContext, NaiveFabricator } from "../../Fabricator/Types.ts";
|
|
3
|
+
import type { Trace } from "../../Random/Types.ts";
|
|
4
|
+
import { Children, Kind, Meta, type Adaptation } from "../../Types.ts";
|
|
5
|
+
import { Schema } from "./Schema.ts";
|
|
6
|
+
import type { Definition, Fabricated, Meta as ThisMeta } from "./Types.ts";
|
|
7
7
|
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema extends {
|
|
8
8
|
[Meta]: ThisMeta;
|
|
9
9
|
}> ? Fabricated<$Schema[typeof Meta]["definition"]> : never;
|
|
@@ -19,4 +19,4 @@ export type Fabricator<$Schema extends {
|
|
|
19
19
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
20
20
|
schema: Schema<$Schema[typeof Meta]["definition"], AdaptationsOf<$Schema>>;
|
|
21
21
|
};
|
|
22
|
-
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, element:
|
|
22
|
+
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, element: BaseFabricator<any>): Fabricator<Schema<$Definition>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Produce } from "../../Random/Types";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { Produce } from "../../Random/Types.ts";
|
|
2
|
+
import type { Fabricated as FabricatedBy } from "../../Schema/Types.ts";
|
|
3
|
+
import { Schema } from "./Schema.ts";
|
|
4
|
+
import type { Definition, Fabricated, InputUniqueWhereby, InputWhereby } from "./Types.ts";
|
|
4
5
|
type ThisRegistry<$Definition extends Definition> = {
|
|
5
6
|
/**
|
|
6
7
|
* An array of `definition`, repeated `length` times. `length` is a bare `N`
|
|
@@ -19,4 +20,40 @@ type ThisRegistry<$Definition extends Definition> = {
|
|
|
19
20
|
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition>;
|
|
20
21
|
};
|
|
21
22
|
export default function <const $Definition extends Definition>(definition: $Definition): ThisRegistry<$Definition>;
|
|
23
|
+
type UniqueRegistry<$Definition extends Definition> = {
|
|
24
|
+
/**
|
|
25
|
+
* An array of `definition` whose members are distinct within each array,
|
|
26
|
+
* repeated `length` times as `T.array`'s is. A member drawn from a finite set
|
|
27
|
+
* (`T.enum`, `T.boolean`, a uniform integer range, a bigint range) is drawn
|
|
28
|
+
* without replacement, and a `length` that could exceed that set is rejected
|
|
29
|
+
* here, at construction. Any other member is redrawn while it repeats one
|
|
30
|
+
* already in the array, up to `redraws` times in a row.
|
|
31
|
+
*
|
|
32
|
+
* Members compare as plain data: by value, `Date` by time, arrays and plain
|
|
33
|
+
* objects by content. Other objects compare by identity; `.by(...)` says what
|
|
34
|
+
* should be distinct instead.
|
|
35
|
+
*/
|
|
36
|
+
whereby: (whereby: InputUniqueWhereby) => Schema<$Definition>;
|
|
37
|
+
/**
|
|
38
|
+
* Make members distinct by `key(member)` rather than by the whole member —
|
|
39
|
+
* `.by((user) => user.email)`.
|
|
40
|
+
*
|
|
41
|
+
* Members are always redrawn while their key repeats, even from a finite set
|
|
42
|
+
* that would otherwise be drawn without replacement. A projection can map
|
|
43
|
+
* different members to one key — `["Ann", "Anne", "Bob"]` by first letter has
|
|
44
|
+
* three members but two keys — so the member set's size says nothing about
|
|
45
|
+
* how many distinct keys exist. There is no capacity check at construction,
|
|
46
|
+
* and running out surfaces as `UniqueRedrawsError` once `redraws` consecutive
|
|
47
|
+
* draws repeat a key.
|
|
48
|
+
*/
|
|
49
|
+
by: (key: (element: FabricatedBy<$Definition>) => unknown) => {
|
|
50
|
+
whereby: (whereby: InputUniqueWhereby) => Schema<$Definition>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* `T.unique.array`, assembled into the namespace by `Primitive/unique`. No
|
|
55
|
+
* `as`: a producer replaces the draw, so it would discard the one thing this
|
|
56
|
+
* builder adds.
|
|
57
|
+
*/
|
|
58
|
+
export declare function unique<const $Definition extends Definition>(definition: $Definition): UniqueRegistry<$Definition>;
|
|
22
59
|
export {};
|