Skip to content

Planner

Defined in: plan/planner.ts:214

Fluent builder for constructing execution plans.

Planner is a mutable, single-use builder. The typical workflow is:

  1. Create a new Planner
  2. Chain method calls to define the pipeline
  3. Call compile() to produce an immutable Plan
const plan = new Planner()
.in(loadFile('config.json'))
.mapIn(parseJson())
.emit((out, $) => out
.add('host', $.get('host').string())
.add('port', $.get('port').number())
)
.compile()
const result = await run(plan, { readFile: fs.readFile })
// result.value: { host: string, port: number }

In = never

Current input type flowing through the pipeline

Out = { }

Current accumulated output type

new Planner<In, Out>(): Planner<In, Out>

Planner<In, Out>

compile(): Plan<Out>

Defined in: plan/planner.ts:420

Compile the planner into an immutable execution plan.

Must be called after at least one emit() to define the output. The returned Plan is immutable and can be executed multiple times.

Plan<Out>

Compiled Plan ready for execution

Error if called without emit() (no output defined)

const plan = new Planner()
.in(load({ name: 'test' }))
.emit((out, $) => out.add('result', $.get('name').string()))
.compile()
// Execute the plan
const result = await run(plan)

emit<B>(builder): Planner<In, B>

Defined in: plan/planner.ts:321

Declaratively emit values to the output using a builder pattern.

Multiple emit() calls can be chained to accumulate values from different inputs.

B

(out, $) => EmitBuilder<B>

Planner<In, B>

new Planner()
.in(loadFile('config.json'))
.mapIn(parseJson())
.emit((out, $) => out
.add('host', $.get('host').string())
.add('port', $.get('port').number())
.addLiteral('version', '1.0.0')
)
.in(loadFile('users.json'))
.mapIn(parseJson())
.emit((out, $) => out
.add('users', $.get('data').array(u => u.get('name').string()))
)
.compile()

in<T>(input): Planner<DataSpecProxy<T>, Out>

Defined in: plan/planner.ts:243

Define the input source for the pipeline.

T

The type produced by this input

DirectInput<T>

Input specification (FileInput, FilesInput, DirectInput, or SourcesInput)

Planner<DataSpecProxy<T>, Out>

This planner for chaining

new Planner()
.in(loadFile('data.json')) // Load from file
.in(load({ key: 'value' })) // Or use inline data
.in(sources({ a: load(1) })) // Or combine multiple sources

in<T>(input): Planner<SpecBuilder, Out>

Defined in: plan/planner.ts:244

Define the input source for the pipeline.

T extends Record<string, unknown>

The type produced by this input

SourcesInput<T>

Input specification (FileInput, FilesInput, DirectInput, or SourcesInput)

Planner<SpecBuilder, Out>

This planner for chaining

new Planner()
.in(loadFile('data.json')) // Load from file
.in(load({ key: 'value' })) // Or use inline data
.in(sources({ a: load(1) })) // Or combine multiple sources

in<T>(input): Planner<SpecBuilder, Out>

Defined in: plan/planner.ts:245

Define the input source for the pipeline.

T

The type produced by this input

Input<T>

Input specification (FileInput, FilesInput, DirectInput, or SourcesInput)

Planner<SpecBuilder, Out>

This planner for chaining

new Planner()
.in(loadFile('data.json')) // Load from file
.in(load({ key: 'value' })) // Or use inline data
.in(sources({ a: load(1) })) // Or combine multiple sources

mapIn<SB>(transform): Planner<SB, Out>

Defined in: plan/planner.ts:277

Apply a transform to the current input.

SB

TypedTransformAst<SB>

Transform AST specification

Planner<SB, Out>

This planner for chaining

Error if called before in()

new Planner()
.in(loadFile('data.json'))
.mapIn(parseJson()) // Apply JSON parsing transform

mapIn(transform): Planner<SpecBuilder, Out>

Defined in: plan/planner.ts:278

Apply a transform to the current input.

TransformAst

Transform AST specification

Planner<SpecBuilder, Out>

This planner for chaining

Error if called before in()

new Planner()
.in(loadFile('data.json'))
.mapIn(parseJson()) // Apply JSON parsing transform

mapOut<NewOut>(builder): Planner<In, NewOut>

Defined in: plan/planner.ts:368

Apply structural transformations to the output after extraction.

Each .mapOut() call adds a new AST node that transforms the accumulated output. Multiple .mapOut() calls chain sequentially.

NewOut = unknown

(out) => OutputTransformBuilder<NewOut>

Planner<In, NewOut>

new Planner()
.in(load({ items: [{cat: 'A', v: 1}, {cat: 'B', v: 2}] }))
.emit((out, $) => out.add('items', $.get('items').array(i => ({
kind: 'object',
properties: { cat: i.get('cat').string(), v: i.get('v').number() }
}))))
.mapOut($ => $.groupBy('items', 'cat'))
.compile()

static merge<T>(…plans): Plan<MergeOutputs<T>>

Defined in: plan/planner.ts:460

Merge multiple plans into a single plan with combined output. Later plans take precedence in case of key conflicts.

T extends Plan<unknown>[]

T

Plan<MergeOutputs<T>>

const configPlan = new Planner()
.in(load('config.json'))
.mapIn(parseJson())
.emit((out, $) => out.add('host', $.get('host').string()))
.compile()
const usersPlan = new Planner()
.in(load('users.json'))
.mapIn(parseJson())
.emit((out, $) => out.add('users', $.get('data').strings()))
.compile()
const combined = Planner.merge(configPlan, usersPlan)
// Result type: { host: string } & { users: string[] }

static mergeAs<T>(plans): Plan<{ [K in string | number | symbol]: T[K] extends Plan<O> ? O : never }>

Defined in: plan/planner.ts:476

Merge multiple plans with each plan’s output nested under a key.

T extends Record<string, Plan<unknown>>

T

Plan<{ [K in string | number | symbol]: T[K] extends Plan<O> ? O : never }>

const combined = Planner.mergeAs({
config: configPlan,
users: usersPlan,
})
// Result type: { config: { host: string }, users: { users: string[] } }