lib0
Version:
isomorphic utility functions
182 lines • 9.09 kB
TypeScript
/**
* The composite template produced by {@link pipe}: holds the threaded stage templates; `init()`
* materializes each into a {@link PipeTransformer}.
*
* @template {DeltaConf} [IN=any]
* @template {DeltaConf} [OUT=any]
* @extends {Template<IN, OUT>}
*/
export class Pipe<IN extends DeltaConf = any, OUT extends DeltaConf = any> extends Template<IN, OUT> {
/**
* @param {DSchema<IN>} $in
* @param {DSchema<OUT>} $out
* @param {Template<any,any>[]} stages the threaded stage templates (A→B order)
*/
constructor($in: DSchema<IN>, $out: DSchema<OUT>, stages: Template<any, any>[]);
stages: Template<any, any>[];
}
/**
* @extends {Transformer<any,any>}
*/
export class PipeTransformer extends Transformer<any, any> {
/**
* @param {DSchema<any>} $in
* @param {DSchema<any>} $out
* @param {Transformer<any,any>[]} ts the per-stage transformers (materialized, A→B order)
*/
constructor($in: DSchema<any>, $out: DSchema<any>, ts: Transformer<any, any>[]);
/**
* @type {Transformer<any,any>[]}
*/
ts: Transformer<any, any>[];
}
/**
* Chain transformers, threading the input schema left→right so each stage is typed against the
* previous stage's output. `pipe($d, $d1 => …, $d2 => …)` infers the end-to-end output type
* automatically; each stage is a `($schema) => Template` factory. Returns a reusable {@link Pipe}
* template — call `.init()` for the transformer.
*
* Order is directional: an `applyA` change flows through the stages **left→right** (the leftmost maps
* the A-side first), an `applyB` change flows **right→left**. So list stages in A→B order — e.g.
* `pipe($d, $d1 => children($d1, …), $d2 => rename($d2, 'ul'))` maps an A-side change with `children`
* then `rename`. Reversing the order silently produces wrong results (there is no init-time check).
*
* The overloads cover up to a fixed arity; longer typed pipes nest
* (`pipe($d, …, $dk => pipe($dk, …more))`).
*
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @returns {Pipe<In, O1>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>): Pipe<In, O1>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @returns {Pipe<In, O2>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>): Pipe<In, O2>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @returns {Pipe<In, O3>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>): Pipe<In, O3>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @template {DeltaConf} O4
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
* @returns {Pipe<In, O4>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf, O4 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>, f4: (d: DSchema<O3>) => Template<O3, O4>): Pipe<In, O4>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @template {DeltaConf} O4
* @template {DeltaConf} O5
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
* @returns {Pipe<In, O5>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf, O4 extends DeltaConf, O5 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>, f4: (d: DSchema<O3>) => Template<O3, O4>, f5: (d: DSchema<O4>) => Template<O4, O5>): Pipe<In, O5>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @template {DeltaConf} O4
* @template {DeltaConf} O5
* @template {DeltaConf} O6
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
* @returns {Pipe<In, O6>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf, O4 extends DeltaConf, O5 extends DeltaConf, O6 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>, f4: (d: DSchema<O3>) => Template<O3, O4>, f5: (d: DSchema<O4>) => Template<O4, O5>, f6: (d: DSchema<O5>) => Template<O5, O6>): Pipe<In, O6>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @template {DeltaConf} O4
* @template {DeltaConf} O5
* @template {DeltaConf} O6
* @template {DeltaConf} O7
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
* @param {(d: DSchema<O6>) => Template<O6, O7>} f7
* @returns {Pipe<In, O7>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf, O4 extends DeltaConf, O5 extends DeltaConf, O6 extends DeltaConf, O7 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>, f4: (d: DSchema<O3>) => Template<O3, O4>, f5: (d: DSchema<O4>) => Template<O4, O5>, f6: (d: DSchema<O5>) => Template<O5, O6>, f7: (d: DSchema<O6>) => Template<O6, O7>): Pipe<In, O7>;
/**
* @template {DeltaConf} In
* @template {DeltaConf} O1
* @template {DeltaConf} O2
* @template {DeltaConf} O3
* @template {DeltaConf} O4
* @template {DeltaConf} O5
* @template {DeltaConf} O6
* @template {DeltaConf} O7
* @template {DeltaConf} O8
* @overload
* @param {DSchema<In>} $in
* @param {(d: DSchema<In>) => Template<In, O1>} f1
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
* @param {(d: DSchema<O6>) => Template<O6, O7>} f7
* @param {(d: DSchema<O7>) => Template<O7, O8>} f8
* @returns {Pipe<In, O8>}
*/
export function pipe<In extends DeltaConf, O1 extends DeltaConf, O2 extends DeltaConf, O3 extends DeltaConf, O4 extends DeltaConf, O5 extends DeltaConf, O6 extends DeltaConf, O7 extends DeltaConf, O8 extends DeltaConf>($in: DSchema<In>, f1: (d: DSchema<In>) => Template<In, O1>, f2: (d: DSchema<O1>) => Template<O1, O2>, f3: (d: DSchema<O2>) => Template<O2, O3>, f4: (d: DSchema<O3>) => Template<O3, O4>, f5: (d: DSchema<O4>) => Template<O4, O5>, f6: (d: DSchema<O5>) => Template<O5, O6>, f7: (d: DSchema<O6>) => Template<O6, O7>, f8: (d: DSchema<O7>) => Template<O7, O8>): Pipe<In, O8>;
export type DeltaConf = import("../delta.js").DeltaConf;
/**
* A delta schema for a given conf — `Schema<Delta<C>>`. Local alias to keep the overload signatures
* readable; defined via inline `import()` so no value import is needed.
*/
export type DSchema<C extends DeltaConf> = import("../../schema.js").Schema<import("../delta.js").Delta<C>>;
import { Template } from './core.js';
import { Transformer } from './core.js';
//# sourceMappingURL=pipe.d.ts.map