Skip to content

Commit

Permalink
pkg: Update prettier to v3.1.0 (#2880)
Browse files Browse the repository at this point in the history
* pkg: Update `prettier` to v3.1.0

* internal: Update formatting

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Nathaniel Tucker <[email protected]>
  • Loading branch information
renovate[bot] and ntucker authored Nov 13, 2023
1 parent 743292f commit 9aa8b60
Show file tree
Hide file tree
Showing 61 changed files with 850 additions and 955 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"nock": "13.3.1",
"node-fetch": "^3.3.0",
"npm-run-all": "^4.1.5",
"prettier": "3.0.3",
"prettier": "3.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.6",
Expand Down Expand Up @@ -120,7 +120,8 @@
"printWidth": 80,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid"
"arrowParens": "avoid",
"experimentalTernaries": true
},
"eslintConfig": {
"extends": [
Expand Down
69 changes: 33 additions & 36 deletions packages/core/src/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ export default class Controller<
>(
endpoint: E,
...args: readonly [...Parameters<E>]
): E['schema'] extends undefined | null
? ReturnType<E>
: Promise<Denormalize<E['schema']>> => {
): E['schema'] extends undefined | null ? ReturnType<E>
: Promise<Denormalize<E['schema']>> => {
const action = createFetch(endpoint, {
args,
});
Expand All @@ -128,9 +127,8 @@ export default class Controller<
>(
endpoint: E,
...args: readonly [...Parameters<E>]
): E['schema'] extends undefined | null
? ReturnType<E> | ResolveType<E>
: Promise<Denormalize<E['schema']>> | Denormalize<E['schema']> => {
): E['schema'] extends undefined | null ? ReturnType<E> | ResolveType<E>
: Promise<Denormalize<E['schema']>> | Denormalize<E['schema']> => {
const { data, expiresAt, expiryStatus } = this.getResponse(
endpoint,
...args,
Expand All @@ -149,13 +147,13 @@ export default class Controller<
endpoint: E,
...args: readonly [...Parameters<E>] | readonly [null]
): Promise<void> =>
args[0] !== null
? this.dispatch(
createInvalidate(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();
args[0] !== null ?
this.dispatch(
createInvalidate(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();

/**
* Forces refetching and suspense on useSuspense on all matching endpoint result keys.
Expand Down Expand Up @@ -261,13 +259,13 @@ export default class Controller<
endpoint: E,
...args: readonly [...Parameters<E>] | readonly [null]
): Promise<void> =>
args[0] !== null
? this.dispatch(
createSubscription(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();
args[0] !== null ?
this.dispatch(
createSubscription(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();

/**
* Marks completion of subscription to a given Endpoint.
Expand All @@ -283,13 +281,13 @@ export default class Controller<
endpoint: E,
...args: readonly [...Parameters<E>] | readonly [null]
): Promise<void> =>
args[0] !== null
? this.dispatch(
createUnsubscription(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();
args[0] !== null ?
this.dispatch(
createUnsubscription(endpoint, {
args: args as readonly [...Parameters<E>],
}),
)
: Promise.resolve();

/*************** More ***************/

Expand Down Expand Up @@ -386,10 +384,9 @@ export default class Controller<
if (!endpoint.schema || !schemaHasEntity(endpoint.schema)) {
return {
data: results,
expiryStatus: meta?.invalidated
? ExpiryStatus.Invalid
: cacheResults && !endpoint.invalidIfStale
? ExpiryStatus.Valid
expiryStatus:
meta?.invalidated ? ExpiryStatus.Invalid
: cacheResults && !endpoint.invalidIfStale ? ExpiryStatus.Valid
: ExpiryStatus.InvalidIfStale,
expiresAt: expiresAt || 0,
} as {
Expand Down Expand Up @@ -423,11 +420,11 @@ export default class Controller<
// we don't track the difference between stale or fresh because that is tied to triggering
// conditions
const expiryStatus =
meta?.invalidated || (invalidDenormalize && !meta?.error)
? ExpiryStatus.Invalid
: invalidDenormalize || endpoint.invalidIfStale || invalidResults
? ExpiryStatus.InvalidIfStale
: ExpiryStatus.Valid;
meta?.invalidated || (invalidDenormalize && !meta?.error) ?
ExpiryStatus.Invalid
: invalidDenormalize || endpoint.invalidIfStale || invalidResults ?
ExpiryStatus.InvalidIfStale
: ExpiryStatus.Valid;

return { data, expiryStatus, expiresAt };
};
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/controller/createSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export default function createSet<
error?: boolean;
},
): SetAction<E> {
const expiryLength: number = error
? endpoint.errorExpiryLength ?? 1000
const expiryLength: number =
error ?
endpoint.errorExpiryLength ?? 1000
: endpoint.dataExpiryLength ?? 60000;
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/controller/ensurePojo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export const ensurePojo =
// FormData doesn't exist in node
/* istanbul ignore else we don't run coverage when we test node*/
typeof FormData !== 'undefined'
? (body: any) =>
body instanceof FormData
? Object.fromEntries((body as any).entries())
: body
: /* istanbul ignore next */
(body: any) => body;
typeof FormData !== 'undefined' ?
(body: any) =>
body instanceof FormData ?
Object.fromEntries((body as any).entries())
: body
: /* istanbul ignore next */ (body: any) => body;
export default ensurePojo;
6 changes: 2 additions & 4 deletions packages/core/src/controller/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import type {
ResolveType,
} from '@data-client/normalizr';

export type ResultEntry<E extends EndpointInterface> = E['schema'] extends
| undefined
| null
? ResolveType<E>
export type ResultEntry<E extends EndpointInterface> =
E['schema'] extends undefined | null ? ResolveType<E>
: Normalize<E['schema']>;

export type EndpointUpdateFunction<
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/manager/DevtoolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ if (process.env.NODE_ENV !== 'production') {
serialize: {
options: undefined,
/* istanbul ignore next */
replacer: HASINTL
? (key: string | number | symbol, value: unknown) => {
replacer:
HASINTL ?
(key: string | number | symbol, value: unknown) => {
if (
typeof value === 'number' &&
typeof key === 'string' &&
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/manager/__tests__/subscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ describe('SubscriptionManager', () => {
payload: Record<string, any>,
reject = false,
): SubscribeAction {
const fetch = reject
? () => Promise.reject(new Error('Failed'))
const fetch =
reject ?
() => Promise.reject(new Error('Failed'))
: () => Promise.resolve(payload);
return {
type: SUBSCRIBE_TYPE,
Expand Down
16 changes: 4 additions & 12 deletions packages/core/src/middlewareTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ export type Dispatch<R extends Reducer<any, any>> = (
) => Promise<void>;

export type Reducer<S, A> = (prevState: S, action: A) => S;
export type ReducerState<R extends Reducer<any, any>> = R extends Reducer<
infer S,
any
>
? S
: never;
export type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<
any,
infer A
>
? A
: never;
export type ReducerState<R extends Reducer<any, any>> =
R extends Reducer<infer S, any> ? S : never;
export type ReducerAction<R extends Reducer<any, any>> =
R extends Reducer<any, infer A> ? A : never;
7 changes: 3 additions & 4 deletions packages/core/src/state/RIC.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const RIC: (cb: (...args: any[]) => void, options: any) => void = (
typeof requestIdleCallback === 'function'
? requestIdleCallback
: (cb: any) => setTimeout(cb, 0)
) as any;
typeof requestIdleCallback === 'function' ? requestIdleCallback : (
(cb: any) => setTimeout(cb, 0)
)) as any;
export default RIC;
16 changes: 7 additions & 9 deletions packages/core/src/state/__tests__/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ describe('reducer', () => {
existing: any,
incoming: any,
) {
return this.shouldReorder(
existingMeta,
incomingMeta,
existing,
incoming,
)
? existingMeta
return (
this.shouldReorder(existingMeta, incomingMeta, existing, incoming)
) ?
existingMeta
: {
...incomingMeta,
expiresAt: incoming.content
? incomingMeta.expiresAt
expiresAt:
incoming.content ?
incomingMeta.expiresAt
: existingMeta.expiresAt,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/state/reducer/setReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function filterOptimistic(
return state.optimistic.filter(
optimisticAction =>
optimisticAction.meta.key !== resolvingAction.meta.key ||
(optimisticAction.type === OPTIMISTIC_TYPE
? optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt
: optimisticAction.meta.date > resolvingAction.meta.date),
(optimisticAction.type === OPTIMISTIC_TYPE ?
optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt
: optimisticAction.meta.date > resolvingAction.meta.date),
);
}
23 changes: 9 additions & 14 deletions packages/endpoint/src/endpointTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ export interface EndpointExtendOptions<
fetch?: FetchFunction;
}

export type ParamFromFetch<F> = F extends (
params: infer P,
body?: any,
) => Promise<any>
? P
: never;
export type ParamFromFetch<F> =
F extends (params: infer P, body?: any) => Promise<any> ? P : never;

//type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U; TODO: should we use this?

Expand Down Expand Up @@ -188,11 +184,10 @@ type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;

type OnlyFirst<A extends unknown[]> = A extends [] ? [] : [A[0]];

type RemoveArray<Orig extends any[], Rem extends any[]> = Rem extends [
any,
...infer RestRem,
]
? Orig extends [any, ...infer RestOrig]
? RemoveArray<RestOrig, RestRem>
: never
: Orig;
type RemoveArray<Orig extends any[], Rem extends any[]> = Rem extends (
[any, ...infer RestRem]
) ?
Orig extends [any, ...infer RestOrig] ?
RemoveArray<RestOrig, RestRem>
: never
: Orig;
11 changes: 7 additions & 4 deletions packages/endpoint/src/indexEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export class Index<S extends Schema, P = Readonly<IndexParams<S>>> {
export type ArrayElement<ArrayType extends unknown[] | readonly unknown[]> =
ArrayType[number];

export type IndexParams<S extends Schema> = S extends {
indexes: readonly string[];
}
? {
export type IndexParams<S extends Schema> =
S extends (
{
indexes: readonly string[];
}
) ?
{
[K in Extract<
ArrayElement<S['indexes']>,
keyof AbstractInstanceType<S>
Expand Down
Loading

0 comments on commit 9aa8b60

Please sign in to comment.