Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "base" types - JSR doesn't work well with it #37

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pedrokehl/caminho",
"version": "1.4.1",
"version": "1.4.2",
"exports": "./src/index.ts",
"exclude": [".github/*", "benchmark/*", "test/*", ".eslintrc"]
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
38 changes: 31 additions & 7 deletions src/from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/operators/batch.ts
Original file line number Diff line number Diff line change
@@ -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<unknown[]>
batch: {
/**
Expand All @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions src/operators/pipe.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>
}

Expand Down
18 changes: 0 additions & 18 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ export interface Caminho {
run(initialBag?: ValueBag): Promise<undefined>
}

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

Expand Down
Loading