From 156019c3f275da399bbdde971bf594fd5afa3fa9 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Sat, 20 Mar 2021 19:08:17 -1000 Subject: [PATCH] fix: use module-aware fp-ts imports --- src/builders.ts | 12 +++++------ src/createImgixBase64FieldConfig.ts | 6 +++--- src/createImgixFixedFieldConfig.ts | 6 +++--- src/createImgixFluidFieldConfig.ts | 6 +++--- src/createImgixUrlFieldConfig.ts | 6 +++--- src/shared.ts | 11 +++++----- src/utils.ts | 33 +++++++++++++---------------- 7 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/builders.ts b/src/builders.ts index 9dd50cc..57cba6b 100644 --- a/src/builders.ts +++ b/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 { diff --git a/src/createImgixBase64FieldConfig.ts b/src/createImgixBase64FieldConfig.ts index e57a942..4a04587 100644 --- a/src/createImgixBase64FieldConfig.ts +++ b/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' diff --git a/src/createImgixFixedFieldConfig.ts b/src/createImgixFixedFieldConfig.ts index 55ea723..ac6c0a5 100644 --- a/src/createImgixFixedFieldConfig.ts +++ b/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' diff --git a/src/createImgixFluidFieldConfig.ts b/src/createImgixFluidFieldConfig.ts index 90d8160..e34404a 100644 --- a/src/createImgixFluidFieldConfig.ts +++ b/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' diff --git a/src/createImgixUrlFieldConfig.ts b/src/createImgixUrlFieldConfig.ts index 1d64a87..5ce1681 100644 --- a/src/createImgixUrlFieldConfig.ts +++ b/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' diff --git a/src/shared.ts b/src/shared.ts index 8aae52b..812ab91 100644 --- a/src/shared.ts +++ b/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' @@ -49,7 +48,7 @@ export const fetchImgixBase64Url = (cache: GatsbyCache) => ( ), ) -const sequenceTTE = sequenceT(TE.taskEither) +const sequenceTTE = Ap.sequenceT(TE.taskEither) export const resolveDimensions = ( source: TSource, @@ -57,7 +56,7 @@ export const resolveDimensions = ( resolveHeight: ImgixSourceDataResolver, cache: GatsbyCache, secureUrlToken?: string, -) => (url: string): TaskEither => +) => (url: string): TE.TaskEither => pipe( sequenceTTE( taskEitherFromSourceDataResolver(resolveWidth)(source), diff --git a/src/utils.ts b/src/utils.ts index 705d322..a689e15 100644 --- a/src/utils.ts +++ b/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' @@ -49,13 +46,13 @@ export const ns = (namespace = '', str: string): string => `${namespace}${str}` export const getFromCache = ( key: string, cache: GatsbyCache, -): Task> => (): Promise> => +): T.Task> => (): Promise> => cache.get(key).then((value?: A) => O.fromNullable(value)) // setToCache :: Cache -> String -> Task Option String export const setToCache = (key: string, cache: GatsbyCache) => ( value: A, -): Task => (): Promise => cache.set(key, value).then(() => value) +): T.Task => (): Promise => cache.set(key, value).then(() => value) // getFromCacheOr :: Cache, () => TaskEither A B -> String -> TaskEither A B export const getFromCacheOr = ( @@ -78,14 +75,14 @@ export const getFromCacheOr = ( ) // fetch :: String -> TaskEither Error Response -export const fetch = (url: string): TaskEither => +export const fetch = (url: string): TE.TaskEither => TE.tryCatch( () => _fetch(url), (reason) => new Error(String(reason)), ) // fetchJSON :: String -> TaskEither Error String -export const fetchJSON = (url: string): TaskEither => +export const fetchJSON = (url: string): TE.TaskEither => pipe( url, fetch, @@ -124,9 +121,9 @@ export const deleteURLSearchParam = (key: string) => (url: string): string => { return u.toString() } -export const semigroupImgixUrlParams = getObjectSemigroup() +export const semigroupImgixUrlParams = S.getObjectSemigroup() -const semigroupURLSearchParams: Semigroup = { +const semigroupURLSearchParams: S.Semigroup = { concat: (x, y) => { const product = new URLSearchParams(x.toString()) y.forEach((value, key) => { @@ -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) => ( +export const signURL = (secureUrlToken: O.Option) => ( url: string, ): string => pipe( @@ -203,7 +200,7 @@ export const join = (separator?: string) => (arr: A[]): string => export const taskEitherFromSourceDataResolver = ( resolver: ImgixSourceDataResolver, predicate?: (data: TData | null) => boolean, -) => (source: TSource): TaskEither => +) => (source: TSource): TE.TaskEither => TE.tryCatch( () => Promise.resolve(resolver(source)).then((data) => {