Skip to content

Commit

Permalink
fix: use module-aware fp-ts imports
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Mar 21, 2021
1 parent 14592b6 commit 156019c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 42 deletions.
12 changes: 6 additions & 6 deletions src/builders.ts
@@ -1,10 +1,10 @@
import { FixedObject, FluidObject } from 'gatsby-image'
import * as A from 'fp-ts/lib/Array'
import * as O from 'fp-ts/lib/Option'
import * as R from 'fp-ts/lib/Record'
import { eqNumber } from 'fp-ts/lib/Eq'
import { ordNumber } from 'fp-ts/lib/Ord'
import { pipe } from 'fp-ts/lib/pipeable'
import * as A from 'fp-ts/Array'
import * as O from 'fp-ts/Option'
import * as R from 'fp-ts/Record'
import { eqNumber } from 'fp-ts/Eq'
import { ordNumber } from 'fp-ts/Ord'
import { pipe } from 'fp-ts/pipeable'

import { ImgixUrlParams, ImgixFixedArgs, ImgixFluidArgs } from './types'
import {
Expand Down
6 changes: 3 additions & 3 deletions src/createImgixBase64FieldConfig.ts
@@ -1,9 +1,9 @@
import * as gatsby from 'gatsby'
import { ComposeFieldConfigAsObject } from 'graphql-compose'
import { FixedObject, FluidObject } from 'gatsby-image'
import * as T from 'fp-ts/lib/Task'
import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import { pipe } from 'fp-ts/pipeable'

import { fetchImgixBase64Url, ImgixSourceDataResolver } from './shared'
import { taskEitherFromSourceDataResolver } from './utils'
Expand Down
6 changes: 3 additions & 3 deletions src/createImgixFixedFieldConfig.ts
@@ -1,9 +1,9 @@
import * as gatsby from 'gatsby'
import { FixedObject } from 'gatsby-image'
import { ComposeFieldConfigAsObject } from 'graphql-compose'
import * as T from 'fp-ts/lib/Task'
import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import { pipe } from 'fp-ts/pipeable'

import { ImgixFixedArgs, ImgixUrlParams } from './types'
import { DEFAULT_FIXED_TYPE_NAME } from './createImgixFixedType'
Expand Down
6 changes: 3 additions & 3 deletions src/createImgixFluidFieldConfig.ts
@@ -1,9 +1,9 @@
import * as gatsby from 'gatsby'
import { FluidObject } from 'gatsby-image'
import { ComposeFieldConfigAsObject } from 'graphql-compose'
import * as T from 'fp-ts/lib/Task'
import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import { pipe } from 'fp-ts/function'

import { ImgixFluidArgs, ImgixUrlParams } from './types'
import { DEFAULT_FLUID_TYPE_NAME } from './createImgixFluidType'
Expand Down
6 changes: 3 additions & 3 deletions src/createImgixUrlFieldConfig.ts
@@ -1,7 +1,7 @@
import { ComposeFieldConfigAsObject } from 'graphql-compose'
import * as T from 'fp-ts/lib/Task'
import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import { pipe } from 'fp-ts/function'

import { buildImgixUrl } from './builders'
import { ImgixSourceDataResolver } from './shared'
Expand Down
11 changes: 5 additions & 6 deletions src/shared.ts
@@ -1,8 +1,7 @@
import { GatsbyCache } from 'gatsby'
import * as TE from 'fp-ts/lib/TaskEither'
import { TaskEither } from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/pipeable'
import { sequenceT } from 'fp-ts/lib/Apply'
import * as Ap from 'fp-ts/Apply'
import * as TE from 'fp-ts/TaskEither'
import { pipe } from 'fp-ts/function'

import { ImgixMetadata } from './types'
import { buildImgixUrl } from './builders'
Expand Down Expand Up @@ -49,15 +48,15 @@ export const fetchImgixBase64Url = (cache: GatsbyCache) => (
),
)

const sequenceTTE = sequenceT(TE.taskEither)
const sequenceTTE = Ap.sequenceT(TE.taskEither)

export const resolveDimensions = <TSource>(
source: TSource,
resolveWidth: ImgixSourceDataResolver<TSource, number>,
resolveHeight: ImgixSourceDataResolver<TSource, number>,
cache: GatsbyCache,
secureUrlToken?: string,
) => (url: string): TaskEither<Error, [number, number]> =>
) => (url: string): TE.TaskEither<Error, [number, number]> =>
pipe(
sequenceTTE(
taskEitherFromSourceDataResolver(resolveWidth)(source),
Expand Down
33 changes: 15 additions & 18 deletions src/utils.ts
@@ -1,16 +1,13 @@
import _fetch, { Response } from 'node-fetch'
import { GatsbyCache, Reporter } from 'gatsby'
import md5 from 'md5'
import * as A from 'fp-ts/lib/Array'
import * as O from 'fp-ts/lib/Option'
import * as R from 'fp-ts/lib/Record'
import * as TE from 'fp-ts/lib/TaskEither'
import { Option } from 'fp-ts/lib/Option'
import { Semigroup, getObjectSemigroup } from 'fp-ts/lib/Semigroup'
import { Task } from 'fp-ts/lib/Task'
import { TaskEither } from 'fp-ts/lib/TaskEither'
import { flow } from 'fp-ts/lib/function'
import { pipe } from 'fp-ts/lib/pipeable'
import * as A from 'fp-ts/Array'
import * as O from 'fp-ts/Option'
import * as R from 'fp-ts/Record'
import * as S from 'fp-ts/Semigroup'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import { flow, pipe } from 'fp-ts/function'

import { ImgixUrlParams } from './types'
import { ImgixSourceDataResolver } from './shared'
Expand Down Expand Up @@ -49,13 +46,13 @@ export const ns = (namespace = '', str: string): string => `${namespace}${str}`
export const getFromCache = <A>(
key: string,
cache: GatsbyCache,
): Task<Option<A>> => (): Promise<Option<A>> =>
): T.Task<O.Option<A>> => (): Promise<O.Option<A>> =>
cache.get(key).then((value?: A) => O.fromNullable(value))

// setToCache :: Cache -> String -> Task Option String
export const setToCache = <A>(key: string, cache: GatsbyCache) => (
value: A,
): Task<A> => (): Promise<A> => cache.set(key, value).then(() => value)
): T.Task<A> => (): Promise<A> => cache.set(key, value).then(() => value)

// getFromCacheOr :: Cache, () => TaskEither A B -> String -> TaskEither A B
export const getFromCacheOr = <A, B>(
Expand All @@ -78,14 +75,14 @@ export const getFromCacheOr = <A, B>(
)

// fetch :: String -> TaskEither Error Response
export const fetch = (url: string): TaskEither<Error, Response> =>
export const fetch = (url: string): TE.TaskEither<Error, Response> =>
TE.tryCatch(
() => _fetch(url),
(reason) => new Error(String(reason)),
)

// fetchJSON :: String -> TaskEither Error String
export const fetchJSON = <A>(url: string): TaskEither<Error, A> =>
export const fetchJSON = <A>(url: string): TE.TaskEither<Error, A> =>
pipe(
url,
fetch,
Expand Down Expand Up @@ -124,9 +121,9 @@ export const deleteURLSearchParam = (key: string) => (url: string): string => {
return u.toString()
}

export const semigroupImgixUrlParams = getObjectSemigroup<ImgixUrlParams>()
export const semigroupImgixUrlParams = S.getObjectSemigroup<ImgixUrlParams>()

const semigroupURLSearchParams: Semigroup<URLSearchParams> = {
const semigroupURLSearchParams: S.Semigroup<URLSearchParams> = {
concat: (x, y) => {
const product = new URLSearchParams(x.toString())
y.forEach((value, key) => {
Expand Down Expand Up @@ -181,7 +178,7 @@ export const createURLSignature = (secureUrlToken: string) => (
export const buildBase64URL = (contentType: string, base64: string): string =>
`data:${contentType};base64,${base64}`

export const signURL = (secureUrlToken: Option<string>) => (
export const signURL = (secureUrlToken: O.Option<string>) => (
url: string,
): string =>
pipe(
Expand All @@ -203,7 +200,7 @@ export const join = <A>(separator?: string) => (arr: A[]): string =>
export const taskEitherFromSourceDataResolver = <TSource, TData>(
resolver: ImgixSourceDataResolver<TSource, TData>,
predicate?: (data: TData | null) => boolean,
) => (source: TSource): TaskEither<Error, TData> =>
) => (source: TSource): TE.TaskEither<Error, TData> =>
TE.tryCatch(
() =>
Promise.resolve(resolver(source)).then((data) => {
Expand Down

0 comments on commit 156019c

Please sign in to comment.