Skip to content

waygraph / MapBuilder

Class: MapBuilder<Out, Names, P, A> ​

Defined in: src/engine/flow/map-builder.ts:89

The flow builder behind engine.map() - see map()'s own doc comment for why this exists. Each step method is scoped to exactly the Block kind its name promises, checked at RUNTIME against the __waygraphKind/__waygraphSalt markers defineNavBlock/definePageBlock/ defineExpectBlock/defineMethodBlock already set (the same markers graph.ts and map-check.ts trust) - not just a type hint, since a hand-rolled object can satisfy the TypeScript Block<In,Out> shape without ever going through a real factory. Each call also typechecks the accumulated Checkpoint chain (a step's In must equal the previous step's Out) - this is what "no teleporting" means: there is no method on this builder that can skip from one Checkpoint to an unrelated one without a real, kind-correct Block in between.

The chain is the flow: there is no closing call. A MapBuilder runs, lists its Blocks, nests (.flow(sub)) and branches as a Flow, built from its steps the first time it's used that way.

Type Parameters ​

Out ​

Out extends Checkpoint<string>

Names ​

Names extends string = never

P ​

P extends PaneAt = Record<never, never>

A ​

A extends string = never

Implements ​

Accessors ​

config ​

Get Signature ​

get config(): EngineConfig

Defined in: src/engine/flow/map-builder.ts:448

The engine config the Flow was built with (how it launches a browser); running one of its steps on its own uses it too.

Returns ​

EngineConfig

The engine config the Flow was built with (how it launches a browser); running one of its steps on its own uses it too.

Implementation of ​

Flow.config


demoPace ​

Get Signature ​

get demoPace(): DemoPace | undefined

Defined in: src/engine/flow/map-builder.ts:454

Demo pacing for this Flow's episode (map({ demoPace })). run() ignores; step/demo applies per Block in the episode.

Returns ​

DemoPace | undefined

Demo pacing for this Flow's episode (map({ demoPace })). run() ignores; step/demo applies per Block in the episode.

Implementation of ​

Flow.demoPace


device ​

Get Signature ​

get device(): ResolvedDevice | undefined

Defined in: src/engine/flow/map-builder.ts:469

map({ device }): the device this flow plays on (waygraph run, demo, test --flows).

Returns ​

ResolvedDevice | undefined

map({ device }): the device this flow plays on (waygraph run, demo, test --flows).

Implementation of ​

Flow.device


exclusive ​

Get Signature ​

get exclusive(): boolean | undefined

Defined in: src/engine/flow/map-builder.ts:472

map({ exclusive: true }): under waygraph test --flows it runs alone, after every other flow.

Returns ​

boolean | undefined

map({ exclusive: true }): under waygraph test --flows it runs alone, after every other flow.

Implementation of ​

Flow.exclusive


expectedFailureReason ​

Get Signature ​

get expectedFailureReason(): string | undefined

Defined in: src/engine/flow/map-builder.ts:451

map({ expectedFailure }) - a display hint for a step-through overlay: this Flow is DESIGNED to throw (e.g. a blocked user's login attempt genuinely failing), not a bug in the demo itself. run() never reads this - the Flow still throws exactly as it would otherwise; only the overlay's error panel reads it, to show an informational "this is the point" panel instead of an alarming one indistinguishable from a real break.

Returns ​

string | undefined

map({ expectedFailure }) - a display hint for a step-through overlay: this Flow is DESIGNED to throw (e.g. a blocked user's login attempt genuinely failing), not a bug in the demo itself. run() never reads this - the Flow still throws exactly as it would otherwise; only the overlay's error panel reads it, to show an informational "this is the point" panel instead of an alarming one indistinguishable from a real break.

Implementation of ​

Flow.expectedFailureReason


highlightStyle ​

Get Signature ​

get highlightStyle(): HighlightStyleDefaults | undefined

Defined in: src/engine/flow/map-builder.ts:460

Default highlight size/weight/tone for this Flow's episode (map({ highlightStyle })). Per-slot stub/fixture values win. run() ignores.

Returns ​

HighlightStyleDefaults | undefined

Default highlight size/weight/tone for this Flow's episode (map({ highlightStyle })). Per-slot stub/fixture values win. run() ignores.

Implementation of ​

Flow.highlightStyle


input ​

Get Signature ​

get input(): MemKey<unknown> | undefined

Defined in: src/engine/flow/map-builder.ts:466

map({ input: CaseKey }): the MemKey this flow takes as its input - one flow for many cases instead of one export per case. Required like any requires key; given by --input (an array runs the flow once per item), --data, a mem stub, or .flow(sub, { input }).

Returns ​

MemKey<unknown> | undefined

map({ input: CaseKey }): the MemKey this flow takes as its input - one flow for many cases instead of one export per case. Required like any requires key; given by --input (an array runs the flow once per item), --data, a mem stub, or .flow(sub, { input }).

Implementation of ​

Flow.input


memStub ​

Get Signature ​

get memStub(): boolean | undefined

Defined in: src/engine/flow/map-builder.ts:463

map({ memStub: true }) (or new Engine({ memStub: true })): a key the flow requires and mem doesn't have comes from its mem stub (registerMemStub) instead of failing preflight. run() fills them first; the CLI does the same.

Returns ​

boolean | undefined

map({ memStub: true }) (or new Engine({ memStub: true })): a key the flow requires and mem doesn't have comes from its mem stub (registerMemStub) instead of failing preflight. run() fills them first; the CLI does the same.

Implementation of ​

Flow.memStub


meta ​

Get Signature ​

get meta(): FlowMeta<string> | undefined

Defined in: src/engine/flow/map-builder.ts:457

What the flow says about itself (map({ title, description, labels, ticket, owner })).

Returns ​

FlowMeta<string> | undefined

What the flow says about itself (map({ title, description, labels, ticket, owner })).

Implementation of ​

Flow.meta


resetSession ​

Get Signature ​

get resetSession(): boolean

Defined in: src/engine/flow/map-builder.ts:445

map({ sessionReset: true }): this Flow wants a fresh browser session when it runs after another one (nested with .flow(sub) or chained on the CLI). run() itself never reads it.

Returns ​

boolean

map({ sessionReset: true }): this Flow wants a fresh browser session when it runs after another one (nested with .flow(sub) or chained on the CLI). run() itself never reads it.

Implementation of ​

Flow.resetSession

Methods ​

blocks() ​

blocks(): readonly BlockInfo[]

Defined in: src/engine/flow/map-builder.ts:484

The flow's Blocks; none for a chain with no step yet (a base other flows extend).

Returns ​

readonly BlockInfo[]

Implementation of ​

Flow.blocks


branch() ​

branch<Routes>(routes): Flow<{ [K in string]: Routes[K] extends (m: never) => Flow<R> ? R : Extract<Out, Checkpoint<K>> }[keyof Routes & string]>

Defined in: src/engine/flow/map-builder.ts:390

Branch: run everything added so far, then continue into whichever routes[tag] matches the Checkpoint it landed on - same page, context and mem. routes must cover every tag of Out (a missing one is a compile error); null ends the flow on that tag. Each route is a function handed a builder already on that tag's Checkpoint.

Runs only as run(context, mem[, options]): the page must survive across the branch, and run(mem, config) closes its own browser first. A route's first Block still sees input.__state === "__start__" in act(): read page and mem, not input.

Type Parameters ​

Routes ​

Routes extends { [K in string]: ((m: MapBuilder<Extract<Out, Checkpoint<K>>>) => Flow<Checkpoint<string>>) | null }

Parameters ​

routes ​

Routes

Returns ​

Flow<{ [K in string]: Routes[K] extends (m: never) => Flow<R> ? R : Extract<Out, Checkpoint<K>> }[keyof Routes & string]>

Example ​

ts
map({ homeOrigin }).gotoPage(NavCartBlock).branch({
  ItemInCart: (m) => m.method(RemoveFromCartBlock),
  InventoryPage: (m) => m.method(AddToCartBlock),
});

close() ​

close<K>(given): MapBuilder<Out, Names, Omit<P, K>, A>

Defined in: src/engine/flow/map-builder.ts:218

Closes another pane: its page (and its browser context, with every pane sharing it) goes, and the flow goes on in the pane it's in; on a demo's stage the others take its room, from two side by side back to one screen. .in() it again later and it opens afresh (signed in again).

Type Parameters ​

K ​

K extends string

Parameters ​

given ​

Pane<K>

Returns ​

MapBuilder<Out, Names, Omit<P, K>, A>

Example ​

ts
.in(Admin_).method(Requests.do.approve).in(Planner_).close(Admin_).gotoPage(Registry.nav)

ffEnd() ​

ffEnd(): MapBuilder<Out, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:160

Close the current fast-forward window and append one FFCompose step. Throws if empty or if ffStart was never opened.

Returns ​

MapBuilder<Out, Names, P, A>


ffStart() ​

ffStart(name?): MapBuilder<Out, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:148

Open a fast-forward window - steps until ffEnd collapse into one opaque fastForwardComposeBlock (blitz theater). Kind/salt checks still run on each inner step as it is added.

Parameters ​

name? ​

string

Returns ​

MapBuilder<Out, Names, P, A>


finally() ​

finally(block): MapBuilder<Out, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:367

A cleanup step: it runs after the flow's steps, whether they passed or failed, and its own failure is reported without failing the flow - deleting what the flow created, usually with an API Block. Several run in the order given. Doesn't move the flow: the next step still starts where the last one landed.

Parameters ​

block ​

SomeDefinedBlock

Returns ​

MapBuilder<Out, Names, P, A>

Example ​

ts
engine.map().gotoPage(NavSignupBlock).method(SubmitSignupBlock).finally(DeleteTestUserApiBlock)

flow() ​

flow<NextOut>(sub, opts?): MapBuilder<NextOut, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:332

Runs another flow's steps inline here, in the same page, browser and mem. This is how flows nest: map().flow(loginFlow).flow(viewerFlow, { reset: true }). With { reset: true } cookies and storage are cleared right before the sub-flow's first step; expect: [...] is what this flow expects once the sub-flow is done (on its last step).

Type Parameters ​

NextOut ​

NextOut extends Checkpoint<string>

Parameters ​

sub ​

Flow<NextOut>

opts? ​

MapFlowOpts & object

Returns ​

MapBuilder<NextOut, Names, P, A>


gotoExternal() ​

gotoExternal<NextOut, Lands>(block, opts?): MapBuilder<Lands, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:261

Appends a genuinely cross-origin navigation step (e.g. (external)/ Blocks in the Waygraph Map convention: mailpit, maildrop.cc) - same kind requirement as gotoPage, plus the inverse homeOrigin check. Compile-time: NavBlock or PageBlock only. { ff: true }: fast-forward this one step inline - see appendStep's own comment.

Type Parameters ​

NextOut ​

NextOut extends Checkpoint<string>

Lands ​

Lands extends Checkpoint<string> = NextOut

Parameters ​

block ​

(NavBlock<NextOut> | PageBlock<NextOut>) & object

opts? ​

MapStepOpts<Lands>

Returns ​

MapBuilder<Lands, Names, P, A>


gotoPage() ​

gotoPage<NextOut, Lands>(block, opts?): MapBuilder<Lands, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:245

Appends an internal navigation/page-arrival step - requires a Block from defineNavBlock/defineMemNavBlock/definePageBlock. Throws if given anything else, including a homeOrigin-mismatched static url. Compile-time: NavBlock or PageBlock only (not Assert/Method). { ff: true }: fast-forward this one step inline - see appendStep's own comment.

Type Parameters ​

NextOut ​

NextOut extends Checkpoint<string>

Lands ​

Lands extends Checkpoint<string> = NextOut

Parameters ​

block ​

(NavBlock<NextOut> | PageBlock<NextOut>) & object

opts? ​

MapStepOpts<Lands>

Returns ​

MapBuilder<Lands, Names, P, A>


in() ​

in<K>(given): MapBuilder<K extends keyof P ? P[K] : Checkpoint<"__start__">, Names, Omit<P, A> & Record<A, Out>, K>

Defined in: src/engine/flow/map-builder.ts:134

The steps after it act in pane (one of map({ panes })), until the next .in(): on that pane's page, from where it last landed. Each pane keeps its own page, so a step is checked against where its pane is.

Type Parameters ​

K ​

K extends string

Parameters ​

given ​

Pane<K>

Returns ​

MapBuilder<K extends keyof P ? P[K] : Checkpoint<"__start__">, Names, Omit<P, A> & Record<A, Out>, K>

Example ​

ts
const Planner_ = pane("planner", { as: Planner }); const Admin_ = pane("admin", { as: Admin });
  engine.map({ panes: [Planner_, Admin_] })
  .in(Planner_).gotoPage(Registry.nav).method(Registry.do.requestRepair)
  .in(Admin_).gotoPage(Requests.nav).method(Requests.do.approve)

method() ​

method<NextOut, Lands>(block, opts?): MapBuilder<Lands, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:277

Appends a non-navigating page action (submit, upload, add/remove an instance) - requires a Block from defineMethodBlock (or defineApiBlock). Compile-time: MethodBlock only. Runtime also rejects an Expect Block (it carries method salt from the factory internals): an expectation goes in a step's expect: [...], not in a step of its own. { ff: true }: fast-forward this one step inline - see appendStep's own comment.

Type Parameters ​

NextOut ​

NextOut extends Checkpoint<string>

Lands ​

Lands extends Checkpoint<string> = NextOut

Parameters ​

block ​

Omit<DefinedBlock<Out, NextOut>, "stub" | "stubBefore" | "stubOnError" | "withVerify" | "modVerify" | "modVerifyAll"> & object & object

opts? ​

Omit<MapStepOpts<Lands>, "when"> & WhenOpt<Out, NextOut>

Returns ​

MapBuilder<Lands, Names, P, A>


modBlockVerify() ​

modBlockVerify(...args): Flow<Out>

Defined in: src/engine/flow/map-builder.ts:490

Replaces one Trait inside the given Block's verify list - same rules as modVerify. Throws if no Block in this Flow matches, or if that Block has no verify trait at the given name/index.

Parameters ​

args ​

...[block: string | number | SomeBlock, nameOrIndex: string | number, newCheck: Trait | ((page, mem) => Promise<boolean | TraitResult>)]

Returns ​

Flow<Out>

Example ​

ts
checkoutFlow.modBlockVerify(LoginBlock, "url-matches", Trait.url({ pathname: "/inventory.html" }))

Implementation of ​

Flow.modBlockVerify


on() ​

on<D>(page, steps): MapBuilder<Out, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:293

Several Methods of the page the flow is on, written as one call. Each is still its own step: its own name in the run log, its own .with({ expect, settle, ... }), .stub(...). The chain offers the page's Methods that stay on it.

Type Parameters ​

D ​

D extends object

Parameters ​

page ​
checkpoint ​

Out

do ​

D

steps ​

(chain) => unknown

Returns ​

MapBuilder<Out, Names, P, A>

Example ​

ts
.on(Lines, (p) => p.typeSearch("<b>x</b>").with({ settle: true, expect: [Lines.check("only marked", ({ rows }) => ...)] }).submit())

run() ​

Call Signature ​

run(context, mem): Promise<Out>

Defined in: src/engine/flow/map-builder.ts:475

Parameters ​
context ​

BrowserContext

mem ​

MemPage

Returns ​

Promise<Out>

Implementation of ​

Flow.run

Call Signature ​

run(context, mem, options): Promise<{ page: Page; result: Out; }>

Defined in: src/engine/flow/map-builder.ts:476

options.closeOnFinish: false hands the driven page back instead of closing it - use this overload (a literal false, not a boolean) to get the { result, page } shape typed correctly.

Parameters ​
context ​

BrowserContext

mem ​

MemPage

options ​

RunGraphOptions & object

Returns ​

Promise<{ page: Page; result: Out; }>

Example ​
ts
const { result, page } = await loginFlow.run(context, mem, { closeOnFinish: false });
Implementation of ​

Flow.run

Call Signature ​

run(context, mem, options?): Promise<Out>

Defined in: src/engine/flow/map-builder.ts:477

options.page drives that already-open page instead of opening a new one - see RunGraphOptions.

Parameters ​
context ​

BrowserContext

mem ​

MemPage

options? ​

RunGraphOptions

Returns ​

Promise<Out>

Example ​
ts
await loginFlow.run(context, mem, { page: existingPage });
Implementation of ​

Flow.run

Call Signature ​

run(mem, config?): Promise<Out>

Defined in: src/engine/flow/map-builder.ts:478

Parameters ​
mem ​

MemPage

config? ​

EngineConfig

Returns ​

Promise<Out>

Implementation of ​

Flow.run


set() ​

set<T>(key, value): MapBuilder<Out, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:309

Sets a mem key for the steps after it: a value, or one worked out from mem when the step runs. The next Block reads it as it reads any key, so one Block covers the cases that differ only by what it is given; a key set here is no longer one the run must supply.

Type Parameters ​

T ​

T

Parameters ​

key ​

MemKey<T>

value ​

Expected<T>

Returns ​

MapBuilder<Out, Names, P, A>

Example ​

ts
.set(ShopKeys.search, (mem) => mem.get(ShopKeys.selectedItem).name).method(TypeSearchBlock)

steps() ​

steps<NextOut>(part): MapBuilder<NextOut, Names, P, A>

Defined in: src/engine/flow/map-builder.ts:319

Plays a part made with steps: the same steps wherever a flow is on the part's Checkpoint. Typed like any step - a part from another Checkpoint doesn't fit.

Type Parameters ​

NextOut ​

NextOut extends Checkpoint<string>

Parameters ​

part ​

Steps<Out, NextOut>

Returns ​

MapBuilder<NextOut, Names, P, A>

Example ​

ts
const addToCart = steps(Inventory, (m) => m.method(AddItemBlock, { expect: [ExpectBadgeBlock] })); map().gotoPage(NavInventoryBlock).steps(addToCart)

withBlockVerify() ​

withBlockVerify(...args): Flow<Out>

Defined in: src/engine/flow/map-builder.ts:487

Replaces the given Block's whole verify list, wherever it sits in this Flow - same rules as withVerify. Throws if no Block in this Flow matches.

Parameters ​

args ​

...[block: string | number | SomeBlock, verify: Trait[] | ((out) => Trait[])]

Returns ​

Flow<Out>

Examples ​

ts
checkoutFlow.withBlockVerify(LoginBlock, [])
ts
checkoutFlow.withBlockVerify("login", [])
ts
checkoutFlow.withBlockVerify(0, [])

Implementation of ​

Flow.withBlockVerify

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed