| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | import { Runnable } from '../../../../src/index.js';
|
| |
|
| |
|
| |
|
| |
|
| | |
| | |
| |
|
| | class MultiplierRunnable extends Runnable {
|
| | constructor(factor) {
|
| | super();
|
| | this.factor = factor;
|
| | }
|
| |
|
| | async _call(input, config) {
|
| | if (typeof input !== 'number') {
|
| | throw new Error('Input must be a number');
|
| | }
|
| | return input * this.factor;
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | class ObjectWrapperRunnable extends Runnable {
|
| | async _call(input, config) {
|
| |
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | class JsonStringifyRunnable extends Runnable {
|
| | async _call(input, config) {
|
| |
|
| | }
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | function createPipeline(factor = 3) {
|
| |
|
| |
|
| |
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | async function runTests() {
|
| | console.log('π§ͺ Testing Pipeline Composition...\n');
|
| |
|
| | try {
|
| |
|
| | console.log('Test 1: Basic pipeline (multiply β wrap β stringify)');
|
| | const pipeline = createPipeline(3);
|
| | const result1 = await pipeline.invoke(5);
|
| | console.log(` Input: 5`);
|
| | console.log(` Output: ${result1}`);
|
| | console.assert(result1 === '{"result":15}', `Expected '{"result":15}', got '${result1}'`);
|
| | console.log('β
Pipeline works!\n');
|
| |
|
| |
|
| | console.log('Test 2: Different factor');
|
| | const pipeline2 = createPipeline(10);
|
| | const result2 = await pipeline2.invoke(4);
|
| | console.log(` Input: 4`);
|
| | console.log(` Output: ${result2}`);
|
| | console.assert(result2 === '{"result":40}', `Expected '{"result":40}', got '${result2}'`);
|
| | console.log('β
Works with different factors!\n');
|
| |
|
| |
|
| | console.log('Test 3: Batch processing through pipeline');
|
| | const pipeline3 = createPipeline(2);
|
| | const results3 = await pipeline3.batch([1, 2, 3]);
|
| | console.log(` Inputs: [1, 2, 3]`);
|
| | console.log(` Outputs: [${results3.join(', ')}]`);
|
| | console.assert(results3[0] === '{"result":2}', 'First result should be correct');
|
| | console.assert(results3[1] === '{"result":4}', 'Second result should be correct');
|
| | console.assert(results3[2] === '{"result":6}', 'Third result should be correct');
|
| | console.log('β
Batch processing works!\n');
|
| |
|
| |
|
| | console.log('Test 4: Testing individual components');
|
| | const multiplier = new MultiplierRunnable(5);
|
| | const wrapper = new ObjectWrapperRunnable();
|
| | const stringifier = new JsonStringifyRunnable();
|
| |
|
| | const step1 = await multiplier.invoke(3);
|
| | console.log(` After multiply: ${step1}`);
|
| | console.assert(step1 === 15, 'Multiplier should work');
|
| |
|
| | const step2 = await wrapper.invoke(step1);
|
| | console.log(` After wrap: ${JSON.stringify(step2)}`);
|
| | console.assert(step2.result === 15, 'Wrapper should work');
|
| |
|
| | const step3 = await stringifier.invoke(step2);
|
| | console.log(` After stringify: ${step3}`);
|
| | console.assert(step3 === '{"result":15}', 'Stringifier should work');
|
| | console.log('β
All components work individually!\n');
|
| |
|
| | console.log('π All tests passed!');
|
| | console.log('\nπ‘ You successfully composed multiple Runnables into a pipeline!');
|
| | } catch (error) {
|
| | console.error('β Test failed:', error.message);
|
| | console.error(error.stack);
|
| | }
|
| | }
|
| |
|
| |
|
| | if (import.meta.url === `file://${process.argv[1]}`) {
|
| | runTests();
|
| | }
|
| |
|
| | export {
|
| | MultiplierRunnable,
|
| | ObjectWrapperRunnable,
|
| | JsonStringifyRunnable,
|
| | createPipeline
|
| | }; |