effector-refetch-codemod
v0.3.0
Published
Codemod: migrate farfetched (@farfetched/core and contract adapters) usage to effector-refetch — rewrites imports safely, folds retry/cache/concurrency/timeout operators into the inline query/mutation config, and annotates incompatible shapes with TODO co
Downloads
313
Maintainers
Readme
effector-refetch-codemod
Migrate farfetched (@farfetched/core) usage to
effector-refetch.
npx effector-refetch-codemod "src/**/*.{ts,tsx}"
npx effector-refetch-codemod "src/**/*.ts" --dry # preview, write nothingWhat it does
Rewrites imports:
@farfetched/core→effector-refetch— but only for names that exist there. Names with no equivalent (declareParams,attachOperation, …) stay on the original import with a// TODO(effector-refetch-codemod)comment instead of becoming broken imports.Rewrites the contract adapter packages:
@farfetched/zod/@farfetched/io-ts/@farfetched/runtypes/@farfetched/superstruct/@farfetched/typed-contracts→ main-entryzodContract/ioTsContract/runtypesContract/superstructContract/typedContract(aliased where names differ, so call sites don't change).Folds the standalone operators —
retry/cache/concurrency/timeout(translating farfetched's{ after }shape) — into the inline config ofcreateQuery,createMutation,createJsonQueryandcreateJsonMutation, and removes the now-unused operator imports. A conflicting inline option is overwritten (the operator ran later — last wins, matching farfetched's runtime). Lane keys fold as the object formconcurrency: { strategy, key }.// before import { createQuery, retry, cache, concurrency } from '@farfetched/core'; const userQuery = createQuery({ effect: fetchUserFx }); retry(userQuery, { times: 3 }); cache(userQuery, { staleAfter: 60_000 }); concurrency(userQuery, { strategy: 'TAKE_LATEST' }); // after import { createQuery } from 'effector-refetch'; const userQuery = createQuery({ effect: fetchUserFx, retry: { times: 3 }, cache: { staleAfter: 60_000 }, concurrency: 'TAKE_LATEST', });Rewrites
applyBarrier(q, { barrier })to the positionalapplyBarrier(q, barrier).Migrates the
createJsonQuery/createJsonMutationshape: dropsparams: declareParams<T>()(leaving a TODO pointing at thecreateJsonQuery<T, Response>generics), hoistsresponse.mapData/response.validateto the top level (supported inline since 0.17), and flags remainingresponsefields (status, sourced{ source, fn }forms) for hand-migration. Unknown imports that end up unreferenced (a droppeddeclareParams) are removed outright.Migrates
@farfetched/atomic-router: achainRoute({ route, ...startChain(q) })whose result is unused becomesattachToRoute({ route, query })(imports cleaned up,attachToRouteadded);freshChainrewrites too, with a note to pair the query withcache({ staleAfter }). A chained route that is used gates its opening on the query settling —attachToRoutehas no such gate, so those calls are kept and annotated instead.Annotates instead of silently migrating shapes that differ between the libraries:
update(q, { on, by })(here it'supdate({ query, on, fn })),keepFresh(q, { automatically }),createBarrier({ active }),retry({ otherwise, mapParams }),concurrency({ abortAll }), and farfetchedTimestrings ('5min'→ milliseconds number).
connectQuery keeps the same API — only its import is rewritten. Operators applied to a query
the codemod can't resolve statically (e.g. imported from another module) are left untouched, so
review the diff (grep for TODO(effector-refetch-codemod)) and run your formatter afterwards.
