@antithesishq/ bombadil/ actions #
Exports #
ActionDiscriminant #
The discriminant in A, like "Click"
or "Back".
type ActionDiscriminant<A> = A extends string ? A : keyof AActionGenerator #
A generator of action templates. Instances of this type is what you need to export from your specification module in order for Bombadil to register your generators.
class ActionGenerator<A> {
generate: () => Tree<A>;
constructor(generate: () => Tree<A>);
map<B>(f: (action: A) => B): ActionGenerator<B>;
filter<B extends A>(predicate: (action: A) => action is B): ActionGenerator<B>;
filter(predicate: (action: A) => boolean): ActionGenerator<A>;
when(condition: boolean | Cell<boolean> | (() => boolean)): ActionGenerator<A>;
flatMap<R extends readonly unknown[] | ActionGenerator<unknown>>(f: (action: A) => R): ActionGenerator<Flattened<R>>;
}ActionOfDiscriminant #
The actions in A of discriminant
D.
type ActionOfDiscriminant<
A,
D
> = Extract<A, D> | Extract<A, Record<D & string, unknown>>CharSet #
Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
namespace CharSet {
type Entry = {
Range: Range;
} | {
Literal: string;
};
namespace Entry {
function is<D extends "Range" | "Literal">(entry: Entry, discriminant: D): entry is Extract<Entry, Record<D, unknown>>;
}
type Entries = Entry[];
function fromRange(from: number, to: number): CharSet.Entries;
function fromLiterals(...literals: string[]): CharSet.Entries;
function union(...sets: CharSet.Entries[]): CharSet.Entries;
function is(generator: StringGenerator): generator is CharSetStringGenerator;
}Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
type Entries = Entry[]Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
function fromRange(from: number, to: number): CharSet.Entries;Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
function fromLiterals(...literals: string[]): CharSet.Entries;Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
function union(...sets: CharSet.Entries[]): CharSet.Entries;Encodes characther ranges or literal strings for use in action templates, where Bombadil will generate concrete strings based on the charsets.
function is(generator: StringGenerator): generator is CharSetStringGenerator;CharSetStringGenerator #
Generates a string based on one or more charsets.
type CharSetStringGenerator = {
CharSet: CharSet.Entries;
}Flattened #
The action type produced by a flatMap callback
returning R.
type Flattened<R> = R extends ActionGenerator<infer B> ? B : R extends readonly (infer B)[] ? B : neverRange #
type Range = number | [number, number]RegexpStringGenerator #
Generates a string based on a regular expression. Uses Rust regex semantics.
type RegexpStringGenerator = {
Regexp: string;
}StringGenerator #
Generates a string to be used as a parameter in an action.
type StringGenerator = "Email" | TextGenerator | CharSetStringGenerator | RegexpStringGeneratorTextGenerator #
Generates a random Unicode string within the given length range.
type TextGenerator = {
Text: Range;
}Tree #
type Tree<T> = {
value: T;
} | {
branches: [number, Tree<T>][];
}actions #
function actions<A>(generate: () => Tree<A> | A[]): ActionGenerator<A>;branch #
function branch<T>(branches: [number, Tree<T>][]): Tree<T>;isAction #
Checks whether the action has the given discriminant and narrows the type if so.
function isAction<
A extends string | object,
D extends ActionDiscriminant<A>
>(action: A, discriminant: D): action is ActionOfDiscriminant<A, D> & A;leaf #
function leaf<T>(value: T): Tree<T>;weighted #
function weighted<A>(value: [number, A | ActionGenerator<A>][]): ActionGenerator<A>;