Skip to content

Commit

Permalink
chore: add prettier to pipeline checks and include .ts files (TanStac…
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo authored Apr 29, 2021
1 parent 7d9c9f8 commit 9686426
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 58 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
],
"scripts": {
"test": "is-ci \"test:ci\" \"test:dev\"",
"test:dev": "npm run test:types && npm run test:eslint && jest --watch",
"test:ci": "npm run test:types && npm run test:eslint && jest",
"test:dev": "npm run test:types && npm run test:format && npm run test:eslint && jest --watch",
"test:ci": "npm run test:types && npm run test:format && npm run test:eslint && jest",
"test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
"test:format": "yarn prettier --check",
"test:types": "tsc",
"test:eslint": "eslint --ext .ts,.tsx ./src",
"build": "yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:types",
Expand All @@ -38,8 +39,9 @@
"watch:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -w -c && rollup-plugin-visualizer stats-react.json",
"watch:types": "rimraf ./types && tsc --watch --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r --silent && replace 'export type' 'export' ./types -r --silent",
"now-build": "yarn && cd www && yarn && yarn build",
"prettier": "prettier \"{.,src,src/**,example/src,example/src/**,types}/*.{md,js,jsx,ts,tsx,json}\"",
"start": "yarn watch",
"format": "prettier {.,src,src/**,example/src,example/src/**,types}/*.{md,js,jsx,tsx,json} --write",
"format": "yarn prettier --write",
"stats": "open ./stats.html"
},
"files": [
Expand Down Expand Up @@ -108,7 +110,7 @@
"eslint-plugin-standard": "^4.0.1",
"is-ci-cli": "^2.1.1",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"prettier": "2.2.1",
"react": "^16.13.0",
"react-dom": "^16.13.1",
"react-error-boundary": "^2.2.2",
Expand Down
2 changes: 1 addition & 1 deletion src/core/focusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FocusManager extends Subscribable {
if (this.removeEventListener) {
this.removeEventListener()
}
this.removeEventListener = setup((focused) => {
this.removeEventListener = setup(focused => {
if (typeof focused === 'boolean') {
this.setFocused(focused)
} else {
Expand Down
7 changes: 1 addition & 6 deletions src/core/mutationCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ export class MutationCache extends Subscribable<MutationCacheListener> {
return this.mutations
}

find<
TData = unknown,
TError = unknown,
TVariables = any,
TContext = unknown
>(
find<TData = unknown, TError = unknown, TVariables = any, TContext = unknown>(
filters: MutationFilters
): Mutation<TData, TError, TVariables, TContext> | undefined {
if (typeof filters.exact === 'undefined') {
Expand Down
88 changes: 72 additions & 16 deletions src/core/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,39 @@ export class QueryClient {
return promise
}

fetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
fetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<TData>
fetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
fetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
queryKey: TQueryKey,
options?: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<TData>
fetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
fetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
queryKey: TQueryKey,
queryFn: QueryFunction<TQueryFnData, TQueryKey>,
options?: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<TData>
fetchQuery<TQueryFnData, TError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
fetchQuery<
TQueryFnData,
TError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
arg1: TQueryKey | FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg2?:
| QueryFunction<TQueryFnData, TQueryKey>
Expand All @@ -286,21 +306,43 @@ export class QueryClient {
: Promise.resolve(query.state.data as TData)
}

prefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
prefetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
prefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
prefetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
queryKey: TQueryKey,
options?: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
prefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
prefetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
queryKey: TQueryKey,
queryFn: QueryFunction<TQueryFnData, TQueryKey>,
options?: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
prefetchQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
prefetchQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
arg1: TQueryKey | FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg2?: QueryFunction<TQueryFnData, TQueryKey> | FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg2?:
| QueryFunction<TQueryFnData, TQueryKey>
| FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg3?: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void> {
return this.fetchQuery(arg1 as any, arg2 as any, arg3)
Expand Down Expand Up @@ -335,8 +377,15 @@ export class QueryClient {
queryFn: QueryFunction<TQueryFnData, TQueryKey>,
options?: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<InfiniteData<TData>>
fetchInfiniteQuery<TQueryFnData, TError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
arg1: TQueryKey | FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
fetchInfiniteQuery<
TQueryFnData,
TError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
arg1:
| TQueryKey
| FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg2?:
| QueryFunction<TQueryFnData, TQueryKey>
| FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
Expand All @@ -356,15 +405,15 @@ export class QueryClient {
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
>(
options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
prefetchInfiniteQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
>(
queryKey: TQueryKey,
options?: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
Expand All @@ -373,13 +422,20 @@ export class QueryClient {
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
>(
queryKey: TQueryKey,
queryFn: QueryFunction<TQueryFnData, TQueryKey>,
options?: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): Promise<void>
prefetchInfiniteQuery<TQueryFnData, TError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
arg1: TQueryKey | FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
prefetchInfiniteQuery<
TQueryFnData,
TError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
arg1:
| TQueryKey
| FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
arg2?:
| QueryFunction<TQueryFnData, TQueryKey>
| FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
Expand Down
40 changes: 24 additions & 16 deletions src/core/tests/queryClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,13 @@ describe('queryClient', () => {
type StrictQueryKey = ['strict', string]
const key: StrictQueryKey = ['strict', queryKey()]

const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () => (
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
Promise.resolve('data')
)

await expect(
queryClient.fetchQuery<StrictData, any, StrictData, StrictQueryKey>(
key,
fetchFn,
fetchFn
)
).resolves.toEqual('data')
})
Expand Down Expand Up @@ -309,15 +308,16 @@ describe('queryClient', () => {
pageParams: [undefined],
}

const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () => (
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
Promise.resolve(data.pages[0])
)

await expect(
queryClient.fetchInfiniteQuery<StrictData, any, StrictData, StrictQueryKey>(
key,
fetchFn,
)
queryClient.fetchInfiniteQuery<
StrictData,
any,
StrictData,
StrictQueryKey
>(key, fetchFn)
).resolves.toEqual(data)
})

Expand Down Expand Up @@ -345,11 +345,15 @@ describe('queryClient', () => {
type StrictQueryKey = ['strict', string]
const key: StrictQueryKey = ['strict', queryKey()]

const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () => (
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
Promise.resolve('data')
)

await queryClient.prefetchInfiniteQuery<StrictData, any, StrictData, StrictQueryKey>(key, fetchFn)
await queryClient.prefetchInfiniteQuery<
StrictData,
any,
StrictData,
StrictQueryKey
>(key, fetchFn)

const result = queryClient.getQueryData(key)

Expand Down Expand Up @@ -381,13 +385,17 @@ describe('queryClient', () => {
type StrictQueryKey = ['strict', string]
const key: StrictQueryKey = ['strict', queryKey()]

const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () => (
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
Promise.resolve('data')
)

await queryClient.prefetchQuery<StrictData, any, StrictData, StrictQueryKey>(key, fetchFn);
await queryClient.prefetchQuery<
StrictData,
any,
StrictData,
StrictQueryKey
>(key, fetchFn)

const result = queryClient.getQueryData(key);
const result = queryClient.getQueryData(key)

expect(result).toEqual('data')
})
Expand Down
6 changes: 2 additions & 4 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ export interface InfiniteQueryObserverOptions<
TData = TQueryFnData,
TQueryData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>
extends QueryObserverOptions<
> extends QueryObserverOptions<
TQueryFnData,
TError,
InfiniteData<TData>,
Expand All @@ -225,8 +224,7 @@ export interface FetchInfiniteQueryOptions<
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>
extends FetchQueryOptions<
> extends FetchQueryOptions<
TQueryFnData,
TError,
InfiniteData<TData>,
Expand Down
8 changes: 7 additions & 1 deletion src/persistQueryClient-experimental/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { QueryClient } from '../core'
import { getLogger } from '../core/logger'
import { dehydrate, DehydratedState, DehydrateOptions, HydrateOptions, hydrate } from '../hydration'
import {
dehydrate,
DehydratedState,
DehydrateOptions,
HydrateOptions,
hydrate,
} from '../hydration'
import { Promisable } from 'type-fest'

export interface Persistor {
Expand Down
9 changes: 3 additions & 6 deletions src/react/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export interface UseBaseQueryOptions<
TData = TQueryFnData,
TQueryData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>
extends QueryObserverOptions<
> extends QueryObserverOptions<
TQueryFnData,
TError,
TData,
Expand All @@ -31,8 +30,7 @@ export interface UseQueryOptions<
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>
extends UseBaseQueryOptions<
> extends UseBaseQueryOptions<
TQueryFnData,
TError,
TData,
Expand All @@ -46,8 +44,7 @@ export interface UseInfiniteQueryOptions<
TData = TQueryFnData,
TQueryData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>
extends InfiniteQueryObserverOptions<
> extends InfiniteQueryObserverOptions<
TQueryFnData,
TError,
TData,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6460,10 +6460,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
prettier@2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==

pretty-bytes@^5.3.0:
version "5.3.0"
Expand Down

0 comments on commit 9686426

Please sign in to comment.