diff --git a/jsr.json b/jsr.json index e78011b..d9ed530 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@pedrokehl/caminho", - "version": "1.4.1", + "version": "1.4.2", "exports": "./src/index.ts", "exclude": [".github/*", "benchmark/*", "test/*", ".eslintrc"] } diff --git a/package-lock.json b/package-lock.json index 9960d46..0dba8fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "caminho", - "version": "1.4.1", + "version": "1.4.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "caminho", - "version": "1.4.1", + "version": "1.4.2", "license": "ISC", "dependencies": { "rxjs": "^7.8.1" diff --git a/package.json b/package.json index 8855e52..dd59aa9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "caminho", - "version": "1.4.1", + "version": "1.4.2", "description": "Caminho means path, a new path to your data processing.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/from.ts b/src/from.ts index 68cdc71..dc46de3 100644 --- a/src/from.ts +++ b/src/from.ts @@ -2,7 +2,7 @@ import { getAsyncGeneratorFromArray, getAsyncGeneratorFromFn } from './utils/get import { Caminho } from './Caminho' import type { CaminhoOptions, ValueBag } from './types' -type BaseFrom = { +export type FromGeneratorParams = { /** * The name of the property to be assigned to the cumulate context. * The value of the property is the returned value from the step. @@ -12,9 +12,6 @@ type BaseFrom = { * Name of the step, useful when logging the steps */ name?: string -} - -export type FromGeneratorParams = BaseFrom & { /** * AsyncGenerator that will provide the values for the flow * It receives the initial values passed to the .run() method @@ -30,7 +27,16 @@ export function fromGenerator(fromParams: FromGeneratorParams, caminhoOptions?: return new Caminho(fromParams, caminhoOptions) } -export type fromValueParams = BaseFrom & { +export type fromValueParams = { + /** + * The name of the property to be assigned to the cumulate context. + * The value of the property is the returned value from the step. + */ + provides: string + /** + * Name of the step, useful when logging the steps + */ + name?: string /** * Single item to bootstrap the new flow */ @@ -47,7 +53,16 @@ export function fromValue(fromValueParams: fromValueParams, caminhoOptions?: Cam return new Caminho({ fn: generator, name, provides }, caminhoOptions) } -export type FromArrayParams = BaseFrom & { +export type FromArrayParams = { + /** + * The name of the property to be assigned to the cumulate context. + * The value of the property is the returned value from the step. + */ + provides: string + /** + * Name of the step, useful when logging the steps + */ + name?: string /** * Array of items to execute the new flow */ @@ -64,7 +79,16 @@ export function fromArray(fromArrayParams: FromArrayParams, caminhoOptions?: Cam return new Caminho({ fn: generator, name, provides }, caminhoOptions) } -export type FromFnParams = BaseFrom & { +export type FromFnParams = { + /** + * The name of the property to be assigned to the cumulate context. + * The value of the property is the returned value from the step. + */ + provides: string + /** + * Name of the step, useful when logging the steps + */ + name?: string /** * Async function that will provide one value for the flow * It receives the initialBag passed to the .run() method diff --git a/src/operators/batch.ts b/src/operators/batch.ts index 043ed65..e3fd699 100644 --- a/src/operators/batch.ts +++ b/src/operators/batch.ts @@ -1,10 +1,27 @@ import { Observable, bufferTime, filter, mergeAll, mergeMap } from 'rxjs' -import type { BasePipe, Loggers, ValueBag } from '../types' +import type { Loggers, ValueBag } from '../types' import { OperatorApplier } from './helpers/operatorHelpers' import { getNewValueBag } from '../utils/valueBag' -export type BatchParams = BasePipe & { +export type BatchParams = { + /** + * The name of the property to be assigned to the cumulate context. + * The value of the property is the returned value from the step. + * Keep in mind that the order of the returned values must be the same order you received the values + * so it gets properly assigned to the context + */ + provides?: string + /** + * Name of the step, useful when logging the steps + */ + name?: string + /** + * Concurrency is unlimited by default, it means a step can be run concurrently as many times as the flow produces + * You can limit the concurrency by using the `maxConcurrency` property. + * This is useful for example when you are calling an API that can't handle too many concurrent requests. + */ + maxConcurrency?: number fn: (valueBag: ValueBag[]) => unknown[] | Promise batch: { /** @@ -16,13 +33,6 @@ export type BatchParams = BasePipe & { */ timeoutMs: number } - /** - * The name of the property to be assigned to the cumulate context. - * The value of the property is the returned value from the step. - * Keep in mind that the order of the returned values must be the same order you received the values - * so it gets properly assigned to the context - */ - provides?: string } export function batch(params: BatchParams, loggers: Loggers): OperatorApplier { diff --git a/src/operators/pipe.ts b/src/operators/pipe.ts index e49389a..bdb4f33 100644 --- a/src/operators/pipe.ts +++ b/src/operators/pipe.ts @@ -1,9 +1,24 @@ import { mergeMap } from 'rxjs' -import type { ValueBag, Loggers, BasePipe } from '../types' +import type { ValueBag, Loggers } from '../types' import { OperatorApplier } from './helpers/operatorHelpers' import { getNewValueBag } from '../utils/valueBag' -export type PipeParams = BasePipe & { +export type PipeParams = { + /** + * The name of the property to be assigned to the cumulate context. + * The value of the property is the returned value from the step. + */ + provides?: string + /** + * Name of the step, useful when logging the steps + */ + name?: string + /** + * Concurrency is unlimited by default, it means a step can be run concurrently as many times as the flow produces + * You can limit the concurrency by using the `maxConcurrency` property. + * This is useful for example when you are calling an API that can't handle too many concurrent requests. + */ + maxConcurrency?: number fn: (valueBag: ValueBag) => unknown | Promise } diff --git a/src/types.ts b/src/types.ts index 2c9eb0a..f748805 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,24 +23,6 @@ export interface Caminho { run(initialBag?: ValueBag): Promise } -export type BasePipe = { - /** - * The name of the property to be assigned to the cumulate context. - * The value of the property is the returned value from the step. - */ - provides?: string - /** - * Name of the step, useful when logging the steps - */ - name?: string - /** - * Concurrency is unlimited by default, it means a step can be run concurrently as many times as the flow produces - * You can limit the concurrency by using the `maxConcurrency` property. - * This is useful for example when you are calling an API that can't handle too many concurrent requests. - */ - maxConcurrency?: number -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any export type ValueBag = any