registry.ts
1 /** 2 * Dynamic registry for pipeline steps. 3 * Allows core and third-party plugins to register custom YAML operations. 4 */ 5 6 import type { IPage } from '../types.js'; 7 8 // Import core steps 9 import { stepNavigate, stepClick, stepType, stepWait, stepPress, stepSnapshot, stepEvaluate } from './steps/browser.js'; 10 import { stepFetch } from './steps/fetch.js'; 11 import { stepSelect, stepMap, stepFilter, stepSort, stepLimit } from './steps/transform.js'; 12 import { stepIntercept } from './steps/intercept.js'; 13 import { stepTap } from './steps/tap.js'; 14 import { stepDownload } from './steps/download.js'; 15 16 /** 17 * Step handler: all pipeline steps conform to this generic interface. 18 * TData is the type of the `data` state flowing into the step. 19 * TResult is the expected return type. 20 */ 21 export type StepHandler<TData = unknown, TResult = unknown, TParams = unknown> = ( 22 page: IPage | null, 23 params: TParams, 24 data: TData, 25 args: Record<string, unknown> 26 ) => Promise<TResult>; 27 28 const _stepRegistry = new Map<string, StepHandler>(); 29 30 /** 31 * Get a registered step handler by name. 32 */ 33 export function getStep(name: string): StepHandler | undefined { 34 return _stepRegistry.get(name); 35 } 36 37 /** 38 * Register a new custom step handler for the YAML pipeline. 39 */ 40 export function registerStep(name: string, handler: StepHandler): void { 41 _stepRegistry.set(name, handler); 42 } 43 44 // ------------------------------------------------------------- 45 // Auto-Register Core Steps 46 // ------------------------------------------------------------- 47 registerStep('navigate', stepNavigate); 48 registerStep('fetch', stepFetch); 49 registerStep('select', stepSelect); 50 registerStep('evaluate', stepEvaluate); 51 registerStep('snapshot', stepSnapshot); 52 registerStep('click', stepClick); 53 registerStep('type', stepType); 54 registerStep('wait', stepWait); 55 registerStep('press', stepPress); 56 registerStep('map', stepMap); 57 registerStep('filter', stepFilter); 58 registerStep('sort', stepSort); 59 registerStep('limit', stepLimit); 60 registerStep('intercept', stepIntercept); 61 registerStep('tap', stepTap); 62 registerStep('download', stepDownload);