Skip to content

Commit

Permalink
chore: Organize imports to avoid lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavoguichard committed Jun 19, 2024
1 parent a93bb7d commit 95c3038
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/environment/combinators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Composable, UnpackData } from '../types.ts'
import * as A from '../combinators.ts'
import { composable, fromSuccess } from '../constructors.ts'
import { BranchReturn, PipeReturn, SequenceReturn } from './types.ts'
import type { BranchReturn, PipeReturn, SequenceReturn } from './types.ts'

function applyEnvironmentToList<
Fns extends Array<(input: unknown, environment: unknown) => unknown>,
Expand Down
46 changes: 8 additions & 38 deletions src/environment/tests/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
withSchema,
} from '../../index.ts'
import type { Composable, ComposableWithSchema } from '../../index.ts'
import { Internal } from '../../internal/types.ts'
import type { Internal } from '../../internal/types.ts'

describe('pipe', () => {
it('should compose functions from left-to-right', async () => {
Expand All @@ -19,12 +19,7 @@ describe('pipe', () => {
const b = withSchema(z.object({ id: z.number() }))(({ id }) => id - 1)

const c = environment.pipe(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

assertEquals(await c({ id: 1 }), success(2))
})
Expand All @@ -42,12 +37,7 @@ describe('pipe', () => {
)(({ inp }, { env }) => inp + env)

const c = environment.pipe(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

assertEquals(await c(undefined, { env: 1 }), success(4))
})
Expand All @@ -66,12 +56,7 @@ describe('pipe', () => {
)(({ inp }, { env }) => inp + env)

const c = environment.pipe(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

assertEquals(
await c(undefined, {}),
Expand All @@ -94,12 +79,7 @@ describe('pipe', () => {
)(({ inp }, { env }) => inp + env)

const c = environment.pipe(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

assertEquals(
await c({ inp: 'some invalid input' }, { env: 1 }),
Expand Down Expand Up @@ -136,12 +116,7 @@ describe('pipe', () => {
)

const d = environment.pipe(a, b, c)
type _R = Expect<
Equal<
typeof d,
ComposableWithSchema<boolean>
>
>
type _R = Expect<Equal<typeof d, ComposableWithSchema<boolean>>>

assertEquals(await d({ aNumber: 1 }), success(false))
})
Expand All @@ -157,10 +132,7 @@ describe('pipe', () => {
const res = await fn(1, 2)

type _FN = Expect<
Equal<
typeof fn,
Internal.FailToCompose<undefined, boolean>
>
Equal<typeof fn, Internal.FailToCompose<undefined, boolean>>
>
})

Expand All @@ -174,9 +146,7 @@ describe('pipe', () => {
// @ts-expect-error composition will fail
const res = await fn(1, 2)

type _FN = Expect<
Equal<typeof fn, Internal.FailToCompose<number, string>>
>
type _FN = Expect<Equal<typeof fn, Internal.FailToCompose<number, string>>>
})

it('compose using environment when piped functions requires a second parameter', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/environment/tests/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// deno-lint-ignore-file no-namespace

import { Internal } from '../../internal/types.ts'
import { Composable } from '../../types.ts'
import * as Subject from '../types.ts'
import type { Internal } from '../../internal/types.ts'
import type { Composable } from '../../types.ts'
import type * as Subject from '../types.ts'

namespace CommonEnvironment {
type testNoEmptyArgumentList = Expect<
Expand Down
4 changes: 2 additions & 2 deletions src/environment/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Internal } from '../internal/types.ts'
import {
import type { Internal } from '../internal/types.ts'
import type {
Composable,
PipeReturn as BasePipeReturn,
SequenceReturn as BaseSequenceReturn,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// deno-lint-ignore-file no-namespace ban-ts-comment
import { assertEquals, describe, it } from '../tests/prelude.ts'
import { Internal } from './types.ts'
import type { Internal } from './types.ts'

namespace UnionToTuple {
type WithStringUnion = Expect<
Expand Down
19 changes: 4 additions & 15 deletions src/tests/all.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { assertEquals, assertIsError, describe, it, z } from './prelude.ts'
import {
all,
Composable,
composable,
ComposableWithSchema,
failure,
InputError,
success,
withSchema,
} from '../index.ts'
import type { Composable, ComposableWithSchema } from '../types.ts'
import { assertEquals, assertIsError, describe, it, z } from './prelude.ts'

const voidFn = composable(() => {})
const toString = withSchema(z.unknown(), z.any())(String)
Expand Down Expand Up @@ -37,12 +36,7 @@ describe('all', () => {
const b = withSchema(z.object({ id: z.string() }))(({ id }) => id)

const c = all(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<[number, string]>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<[number, string]>>>

assertEquals(
await c({ id: 1 }),
Expand All @@ -69,12 +63,7 @@ describe('all', () => {
const b = withSchema(z.object({ id: z.string() }))(({ id }) => id)

const c = all(a, b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<[string, string]>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<[string, string]>>>

assertEquals(
await c({ id: 1 }),
Expand Down
21 changes: 5 additions & 16 deletions src/tests/branch.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { assertEquals, assertIsError, describe, it, z } from './prelude.ts'
import { branch } from '../combinators.ts'
import {
composable,
failure,
InputError,
success,
UnpackData,
withSchema,
} from '../index.ts'
import { Composable, ComposableWithSchema } from '../types.ts'
import { branch } from '../combinators.ts'
import type { Composable, ComposableWithSchema, UnpackData } from '../types.ts'
import { assertEquals, assertIsError, describe, it, z } from './prelude.ts'

describe('branch', () => {
it('should pipe a composable with arbitrary types', async () => {
Expand Down Expand Up @@ -71,12 +70,7 @@ describe('branch', () => {
}))
const b = composable(({ id }: { id: number }) => id - 1)
const c = branch(a, () => b)
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

assertEquals(
await c({ id: '1' }),
Expand Down Expand Up @@ -108,12 +102,7 @@ describe('branch', () => {
// deno-lint-ignore no-unreachable
return b
})
type _R = Expect<
Equal<
typeof c,
ComposableWithSchema<number>
>
>
type _R = Expect<Equal<typeof c, ComposableWithSchema<number>>>

const {
errors: [err],
Expand Down
13 changes: 4 additions & 9 deletions src/tests/pipe.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals, describe, it } from './prelude.ts'
import type { Composable, Result } from '../index.ts'
import { composable, pipe, success } from '../index.ts'
import { Internal } from '../internal/types.ts'
import type { Internal } from '../internal/types.ts'
import { assertEquals, describe, it } from './prelude.ts'

const toString = composable((a: unknown) => `${a}`)
const add = composable((a: number, b: number) => a + b)
Expand Down Expand Up @@ -61,10 +61,7 @@ describe('pipe', () => {
const res = await fn(1, 2)

type _FN = Expect<
Equal<
typeof fn,
Internal.FailToCompose<undefined, number>
>
Equal<typeof fn, Internal.FailToCompose<undefined, number>>
>
})

Expand All @@ -73,9 +70,7 @@ describe('pipe', () => {
// @ts-expect-error alwaysThrow won't type-check the composition since its return type is never and toString expects an unknown parameter
const res = await fn(1, 2)

type _FN = Expect<
Equal<typeof fn, Internal.FailToCompose<never, unknown>>
>
type _FN = Expect<Equal<typeof fn, Internal.FailToCompose<never, unknown>>>
type _R = Expect<Equal<typeof res, Result<string>>>

assertEquals(res.success, false)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
serializeError,
success,
} from '../index.ts'
import { SerializableError } from '../types.ts'
import type { SerializableError } from '../types.ts'
import { serialize } from '../index.ts'
import { SerializableResult } from '../types.ts'
import type { SerializableResult } from '../types.ts'

describe('serializeError', () => {
it('serializes an error into a payload friendly format', () => {
Expand Down

0 comments on commit 95c3038

Please sign in to comment.