Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
diogob committed Jun 27, 2024
1 parent 7a9261b commit ff1c99f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.0.0",
"version": "3.1.0",
"tasks": {
"test": "deno test --allow-env --allow-net src",
"publish": "deno task build-npm && cd npm/ && npm publish",
Expand Down
7 changes: 6 additions & 1 deletion deno.lock

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

8 changes: 5 additions & 3 deletions src/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import * as Future from './deps.ts'
function toComposable<R>(
df: DomainFunction<R>,
): Future.Composable<(input?: unknown, environment?: unknown) => R> {
return (async (input?: unknown, environment?: unknown) => {
const callable = (async (input?: unknown, environment?: unknown) => {
const result = await df(input, environment)
return result.success
? Future.success(result.data)
Expand All @@ -45,10 +45,12 @@ function toComposable<R>(
(e) => new Future.InputError(e.message, e.path),
),
...result.environmentErrors.map(
(e) => new Future.EnvironmentError(e.message, e.path),
(e) => new Future.ContextError(e.message, e.path),
),
] as Error[])
}) as Future.Composable<(input?: unknown, environment?: unknown) => R>
callable.kind = 'composable' as const
return callable
}

/**
Expand Down Expand Up @@ -105,7 +107,7 @@ function fromComposable<R>(
previous.inputErrors.push(
schemaError(current.message, current.path.join('.')),
)
} else if (current instanceof Future.EnvironmentError) {
} else if (current instanceof Future.EnvironmentError || current instanceof Future.ContextError) {
previous.environmentErrors.push(
schemaError(current.message, current.path.join('.')),
)
Expand Down
2 changes: 1 addition & 1 deletion src/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'npm:composable-functions@^4.0.0'
export * from 'npm:composable-functions@^4.2.0'
2 changes: 1 addition & 1 deletion src/domain-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const df = all(a, b, c)
function all<Fns extends DomainFunction[]>(
...fns: Fns
): DomainFunction<UnpackAll<Fns>> {
return fromComposable(Future.all(...fns.map(toComposable))) as DomainFunction<
return fromComposable(Future.all(...fns.map(toComposable) as [Future.Composable])) as DomainFunction<
UnpackAll<Fns>
>
}
Expand Down

0 comments on commit ff1c99f

Please sign in to comment.