Skip to content

Commit

Permalink
fix: update fp-ts deprecated functions (#334)
Browse files Browse the repository at this point in the history
* fix: update deprecated fp-ts functions

* fix: remaining fp-ts deprecations and incorrect RTE usage
  • Loading branch information
angeloashmore authored Apr 21, 2021
1 parent b235879 commit db21c73
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 75 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '14'
- uses: bahmutov/npm-install@v1

- name: Install Yarn
run: npm install -g yarn

- run: yarn install
- run: yarn build
- run: yarn test

- name: Uninstall Yarn
if: always()
run: npm uninstall -g yarn
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { onClientEntry } from './on-client-entry'
// export { wrapRootElement } from './wrap-root-element'
1 change: 0 additions & 1 deletion packages/gatsby-plugin-prismic-previews/src/gatsby-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
*/

export { onRenderBody } from './on-render-body'
// export { wrapRootElement } from './wrap-root-element'
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ export const onClientEntry: NonNullable<
) =>
// We don't care about the output of the program so we won't be doing
// anything with the result.
await RTE.run(onClientEntryProgram, { pluginOptions })
await onClientEntryProgram({ pluginOptions })()
51 changes: 29 additions & 22 deletions packages/gatsby-plugin-prismic-previews/src/on-post-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as TE from 'fp-ts/TaskEither'
import * as A from 'fp-ts/Array'
import * as E from 'fp-ts/Either'
import * as T from 'fp-ts/Task'
import { constVoid, pipe } from 'fp-ts/function'
import { createNodeHelpers, NodeHelpers } from 'gatsby-node-helpers'

Expand Down Expand Up @@ -83,27 +83,34 @@ const onPostBootstrapProgram: RTE.ReaderTaskEither<
// not the Promise-returning method.
export const onPostBootstrap: NonNullable<
gatsby.GatsbyNode['onPostBootstrap']
> = (gatsbyContext, pluginOptions: PluginOptions, callback) =>
RTE.run(onPostBootstrapProgram, {
getNodesByType: gatsbyContext.getNodesByType,
reportVerbose: gatsbyContext.reporter.verbose,
repositoryName: pluginOptions.repositoryName,
nodeHelpers: createNodeHelpers({
typePrefix: [GLOBAL_TYPE_PREFIX, pluginOptions.typePrefix]
.filter(Boolean)
.join(' '),
fieldPrefix: GLOBAL_TYPE_PREFIX,
createNodeId: gatsbyContext.createNodeId,
createContentDigest: gatsbyContext.createContentDigest,
> = async (gatsbyContext, pluginOptions: PluginOptions, callback) =>
await pipe(
onPostBootstrapProgram({
getNodesByType: gatsbyContext.getNodesByType,
reportVerbose: gatsbyContext.reporter.verbose,
repositoryName: pluginOptions.repositoryName,
nodeHelpers: createNodeHelpers({
typePrefix: [GLOBAL_TYPE_PREFIX, pluginOptions.typePrefix]
.filter(Boolean)
.join(' '),
fieldPrefix: GLOBAL_TYPE_PREFIX,
createNodeId: gatsbyContext.createNodeId,
createContentDigest: gatsbyContext.createContentDigest,
}),
writeTypePathsToFilesystem: pluginOptions.writeTypePathsToFilesystem,
}),
writeTypePathsToFilesystem: pluginOptions.writeTypePathsToFilesystem,
}).then(
E.fold(
TE.fold(
(error) =>
reportPanic(error.message)({
repositoryName: pluginOptions.repositoryName,
reportPanic: gatsbyContext.reporter.panic,
})(),
() => (callback ? callback(null) : void 0),
pipe(
reportPanic(error.message)({
repositoryName: pluginOptions.repositoryName,
reportPanic: gatsbyContext.reporter.panic,
}),
TE.fold(
() => T.of(void 0),
() => T.of(void 0),
),
),
() => (callback ? T.fromIO(() => callback(null)) : T.of(void 0)),
),
)
)()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from 'react'
import * as prismic from 'ts-prismic'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as RE from 'fp-ts/ReaderEither'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
import * as IO from 'fp-ts/IO'
import * as A from 'fp-ts/Array'
import * as R from 'fp-ts/Record'
Expand Down Expand Up @@ -112,7 +113,7 @@ interface UsePrismicPreviewBootstrapProgramEnv {
): PrismicTypePathType | undefined
}

const usePrismicPreviewBootstrapProgram: RTE.ReaderTaskEither<
const previewBootstrapProgram: RTE.ReaderTaskEither<
UsePrismicPreviewBootstrapProgramEnv,
Error,
void
Expand Down Expand Up @@ -284,8 +285,8 @@ export const usePrismicPreviewBootstrap = (
}, [contextState])

const bootstrapPreview = React.useCallback(async (): Promise<void> => {
pipe(
await RTE.run(usePrismicPreviewBootstrapProgram, {
await pipe(
previewBootstrapProgram({
setActiveRepositoryName: (repositoryName: string) => () =>
contextDispatch({
type: PrismicContextActionType.SetActiveRepositoryName,
Expand Down Expand Up @@ -335,15 +336,17 @@ export const usePrismicPreviewBootstrap = (
createContentDigest: (input: string | UnknownRecord) =>
md5(JSON.stringify(input)),
}),
E.fold(
TE.fold(
(error) =>
localDispatch({
type: UsePrismicPreviewBootstrapActionType.Fail,
payload: error,
}),
constVoid,
T.fromIO(() =>
localDispatch({
type: UsePrismicPreviewBootstrapActionType.Fail,
payload: error,
}),
),
() => T.of(void 0),
),
)
)()
}, [
config,
contextState.pluginOptionsStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as prismic from 'ts-prismic'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as TE from 'fp-ts/TaskEither'
import * as E from 'fp-ts/Either'
import * as T from 'fp-ts/Task'
import * as A from 'fp-ts/Array'
import * as R from 'fp-ts/Record'
import * as IO from 'fp-ts/IO'
Expand Down Expand Up @@ -89,7 +89,7 @@ interface UsePrismicPreviewResolverProgramEnv {
config: UsePrismicPreviewResolverConfig
}

const usePrismicPreviewResolverProgram: RTE.ReaderTaskEither<
const previewResolverProgram: RTE.ReaderTaskEither<
UsePrismicPreviewResolverProgramEnv,
Error,
void
Expand Down Expand Up @@ -215,8 +215,8 @@ export const usePrismicPreviewResolver = (
)

const resolvePreview = React.useCallback(async (): Promise<void> => {
pipe(
await RTE.run(usePrismicPreviewResolverProgram, {
await pipe(
previewResolverProgram({
setActiveRepositoryName: (repositoryName: string) => () =>
contextDispatch({
type: PrismicContextActionType.SetActiveRepositoryName,
Expand All @@ -235,15 +235,17 @@ export const usePrismicPreviewResolver = (
// TODO: This may cause infinite rerenders.
config,
}),
E.fold(
TE.fold(
(error) =>
localDispatch({
type: UsePrismicPreviewResolverActionType.Fail,
payload: error,
}),
constVoid,
T.fromIO(() =>
localDispatch({
type: UsePrismicPreviewResolverActionType.Fail,
payload: error,
}),
),
() => T.of(void 0),
),
)
)()
}, [config, contextDispatch, contextState.pluginOptionsStore])

return React.useMemo(() => [localState, resolvePreview] as const, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as gatsby from 'gatsby'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as R from 'fp-ts/Record'
import * as A from 'fp-ts/Array'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
import { pipe, constVoid } from 'fp-ts/function'

import { createAllDocumentTypesType } from './lib/createAllDocumentTypesType'
Expand Down Expand Up @@ -75,7 +76,7 @@ const createCustomTypes: RTE.ReaderTaskEither<
> = pipe(
RTE.asks((deps: Dependencies) => deps.pluginOptions.schemas),
RTE.map(R.mapWithIndex(createCustomType)),
RTE.chain(R.sequence(RTE.readerTaskEither)),
RTE.chain(R.sequence(RTE.ApplicativeSeq)),
RTE.map(R.collect((_, value) => value)),
)

Expand Down Expand Up @@ -105,10 +106,9 @@ export const createSchemaCustomization: NonNullable<
gatsbyContext: gatsby.CreateSchemaCustomizationArgs,
pluginOptions: PluginOptions,
) =>
pipe(
await RTE.run(
createSchemaCustomizationProgram,
await pipe(
createSchemaCustomizationProgram(
buildDependencies(gatsbyContext, pluginOptions),
),
E.fold(throwError, constVoid),
)
TE.fold(throwError, () => T.of(void 0)),
)()
6 changes: 4 additions & 2 deletions packages/gatsby-source-prismic/src/lib/buildFieldConfigMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const buildFieldConfigMap = (
> =>
pipe(
fieldSchemas,
R.mapWithIndex((name, schema) => toFieldConfig(A.snoc(path, name), schema)),
R.sequence(RTE.readerTaskEither),
R.mapWithIndex((name, schema) =>
toFieldConfig(pipe(path, A.append(name)), schema),
),
R.sequence(RTE.ApplicativeSeq),
)
4 changes: 2 additions & 2 deletions packages/gatsby-source-prismic/src/on-webhook-api-update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as A from 'fp-ts/Array'
import * as Eq from 'fp-ts/Eq'
import * as s from 'fp-ts/string'
import { pipe, constVoid } from 'fp-ts/function'

import { Dependencies, PrismicWebhookBodyApiUpdate } from './types'
Expand Down Expand Up @@ -80,7 +80,7 @@ export const onWebhookApiUpdate = (
RTE.bind('documentIdsToDelete', (scope) =>
pipe(
scope.documentIds,
A.difference(Eq.eqString)(scope.documentIdsToUpdate),
A.difference(s.Eq)(scope.documentIdsToUpdate),
(ids) => RTE.right(ids),
),
),
Expand Down
17 changes: 9 additions & 8 deletions packages/gatsby-source-prismic/src/plugin-options-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as gatsbyFs from 'gatsby-source-filesystem'
import * as prismic from 'ts-prismic'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as TE from 'fp-ts/TaskEither'
import * as E from 'fp-ts/Either'
import * as T from 'fp-ts/Task'
import * as A from 'fp-ts/Array'
import * as R from 'fp-ts/Record'
import * as Eq from 'fp-ts/Eq'
import * as s from 'fp-ts/string'
import { constVoid, pipe } from 'fp-ts/function'
import got from 'got'

Expand Down Expand Up @@ -71,7 +71,7 @@ const externalValidationProgram = (
pipe(
scope.repository.types,
R.keys,
A.difference(Eq.eqString)(scope.schemaTypes),
A.difference(s.Eq)(scope.schemaTypes),
(missingSchemas) => RTE.right(missingSchemas),
),
),
Expand Down Expand Up @@ -126,11 +126,12 @@ export const pluginOptionsSchema: NonNullable<
),
})
.oxor('fetchLinks', 'graphQuery')
.external(async (pluginOptions: PluginOptions) =>
pipe(
await RTE.run(externalValidationProgram(Joi), { pluginOptions }),
E.fold(throwError, constVoid),
),
.external(
async (pluginOptions: PluginOptions) =>
await pipe(
externalValidationProgram(Joi)({ pluginOptions }),
TE.fold(throwError, () => T.of(void 0)),
)(),
)

return schema
Expand Down
14 changes: 6 additions & 8 deletions packages/gatsby-source-prismic/src/source-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as gatsby from 'gatsby'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
import { constVoid, pipe } from 'fp-ts/function'

import { sourceNodesForAllDocuments } from './lib/sourceNodesForAllDocuments'
Expand Down Expand Up @@ -43,10 +44,7 @@ export const sourceNodes: NonNullable<
gatsbyContext: gatsby.SourceNodesArgs,
pluginOptions: PluginOptions,
) =>
pipe(
await RTE.run(
sourceNodesProgram,
buildDependencies(gatsbyContext, pluginOptions),
),
E.fold(throwError, constVoid),
)
await pipe(
sourceNodesProgram(buildDependencies(gatsbyContext, pluginOptions)),
TE.fold(throwError, () => T.of(void 0)),
)()

0 comments on commit db21c73

Please sign in to comment.