Skip to content

Commit

Permalink
feat(core): increase number of steps in pipe (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier-Redondo authored Jul 13, 2023
1 parent 56a570c commit 2526406
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/bautajs-core/src/decorators/__tests__/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ describe('pipe tests', () => {
expect(pipeline(null, ctx, {} as BautaJSInstance)).toStrictEqual(expected);
});

test('should allow for up to 16 steps in a pipeline', async () => {
const expected = "Let's sing: LA LA LA LA LA LA LA LA LA LA LA LA LA LA LA ";
const firstValue = 'LA ';
const myStep = (prev: string) => `${prev}${firstValue}`;

const pipeline = pipe(
() => "Let's sing: ",
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep,
myStep
);
const ctx = createContext({});

expect(pipeline(null, ctx, {} as BautaJSInstance)).toStrictEqual(expected);
});

test('should allow pipelines on pipe method', async () => {
const expected = 'this will be showed';
const pipeline1 = pipe(() => expected);
Expand Down
254 changes: 254 additions & 0 deletions packages/bautajs-core/src/decorators/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,33 @@ function compose<T, R>(
export function pipe<ValueType, ReturnType>(
f1: Pipeline.StepFunction<ValueType, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<ValueType, ResultValue1, ReturnType>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<ValueType, ResultValue1, ResultValue2, ReturnType>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ReturnType>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ReturnType>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
Expand All @@ -66,6 +71,7 @@ export function pipe<
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
Expand All @@ -84,6 +90,7 @@ export function pipe<
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
Expand All @@ -104,6 +111,7 @@ export function pipe<
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
Expand All @@ -127,6 +135,252 @@ export function pipe<
f9: Pipeline.StepFunction<ResultValue8, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ResultValue12,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ResultValue12>,
f13: Pipeline.StepFunction<ResultValue12, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ResultValue12,
ResultValue13,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ResultValue12>,
f13: Pipeline.StepFunction<ResultValue12, ResultValue13>,
f14: Pipeline.StepFunction<ResultValue13, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ResultValue12,
ResultValue13,
ResultValue14,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ResultValue12>,
f13: Pipeline.StepFunction<ResultValue12, ResultValue13>,
f14: Pipeline.StepFunction<ResultValue13, ResultValue14>,
f15: Pipeline.StepFunction<ResultValue14, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

export function pipe<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ResultValue9,
ResultValue10,
ResultValue11,
ResultValue12,
ResultValue13,
ResultValue14,
ResultValue15,
ReturnType
>(
f1: Pipeline.StepFunction<ValueType, ResultValue1>,
f2: Pipeline.StepFunction<ResultValue1, ResultValue2>,
f3: Pipeline.StepFunction<ResultValue2, ResultValue3>,
f4: Pipeline.StepFunction<ResultValue3, ResultValue4>,
f5: Pipeline.StepFunction<ResultValue4, ResultValue5>,
f6: Pipeline.StepFunction<ResultValue5, ResultValue6>,
f7: Pipeline.StepFunction<ResultValue6, ResultValue7>,
f8: Pipeline.StepFunction<ResultValue7, ResultValue8>,
f9: Pipeline.StepFunction<ResultValue8, ResultValue9>,
f10: Pipeline.StepFunction<ResultValue9, ResultValue10>,
f11: Pipeline.StepFunction<ResultValue10, ResultValue11>,
f12: Pipeline.StepFunction<ResultValue11, ResultValue12>,
f13: Pipeline.StepFunction<ResultValue12, ResultValue13>,
f14: Pipeline.StepFunction<ResultValue13, ResultValue14>,
f15: Pipeline.StepFunction<ResultValue14, ResultValue15>,
f16: Pipeline.StepFunction<ResultValue15, ReturnType>
): Pipeline.PipelineFunction<ValueType, ReturnType>;

/**
* Create a pipeline of Pipeline.StepFunctions executing one after the other.
* @export
Expand Down

0 comments on commit 2526406

Please sign in to comment.