Skip to content

Commit

Permalink
internal: Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jan 17, 2024
1 parent 65ea741 commit 4565fde
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 151 deletions.
13 changes: 6 additions & 7 deletions packages/endpoint/src/endpointTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ 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;
10 changes: 4 additions & 6 deletions packages/normalizr/src/endpoint/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export type ResolveType<E extends (...args: any) => any> =
ReturnType<E> extends Promise<infer R> ? R : never;

/** Fallback to schema if fetch function isn't defined */
export type InferReturn<
F extends FetchFunction,
S extends Schema | undefined,
> = S extends undefined ? ReturnType<F>
: ReturnType<F> extends unknown ? Promise<Denormalize<S>>
: ReturnType<F>;
export type InferReturn<F extends FetchFunction, S extends Schema | undefined> =
S extends undefined ? ReturnType<F>
: ReturnType<F> extends unknown ? Promise<Denormalize<S>>
: ReturnType<F>;
19 changes: 10 additions & 9 deletions packages/redux/src/prepareStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ type ReducersMapObject<
S = any,
A extends { type: string } = any,
PreloadedState = S,
> = keyof PreloadedState extends keyof S ?
{
[K in keyof S]: Reducer<
S[K],
A,
K extends keyof PreloadedState ? PreloadedState[K] : never
>;
}
: never;
> =
keyof PreloadedState extends keyof S ?
{
[K in keyof S]: Reducer<
S[K],
A,
K extends keyof PreloadedState ? PreloadedState[K] : never
>;
}
: never;
86 changes: 44 additions & 42 deletions packages/rest/src/OptionsToFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,51 @@ export type OptionsToFunction<
O extends PartialRestGenerics,
E extends { body?: any; path?: string; method?: string },
F extends FetchFunction,
> = 'path' extends keyof O ?
RestFetch<
'searchParams' extends keyof O ?
O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
: PathArgs<Exclude<O['path'], undefined>>,
OptionsToBodyArgument<
'body' extends keyof O ? O : E,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: 'body' extends keyof O ?
RestFetch<
'searchParams' extends keyof O ?
O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
: PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
O,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: 'searchParams' extends keyof O ?
RestFetch<
O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
E,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: (
this: ThisParameterType<F>,
...args: Parameters<F>
) => Promise<
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>;
> =
'path' extends keyof O ?
RestFetch<
'searchParams' extends keyof O ?
O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
: PathArgs<Exclude<O['path'], undefined>>,
OptionsToBodyArgument<
'body' extends keyof O ? O : E,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: 'body' extends keyof O ?
RestFetch<
'searchParams' extends keyof O ?
O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
: PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
O,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: 'searchParams' extends keyof O ?
RestFetch<
O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
E,
'method' extends keyof O ? O['method'] : E['method']
>,
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>
: (
this: ThisParameterType<F>,
...args: Parameters<F>
) => Promise<
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>
>;

export type OptionsToBodyArgument<
O extends { body?: any },
Method extends string | undefined,
> = Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' ?
'body' extends keyof O ?
O['body']
: any
: undefined;
> =
Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' ?
'body' extends keyof O ?
O['body']
: any
: undefined;
172 changes: 89 additions & 83 deletions packages/rest/src/RestEndpointTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,89 +208,95 @@ type OptionsToRestEndpoint<
O extends PartialRestGenerics,
E extends RestInstanceBase & { body?: any; paginationField?: string },
F extends FetchFunction,
> = 'path' extends keyof O ?
RestType<
'searchParams' extends keyof O ?
O['searchParams'] extends undefined ?
PathArgs<Exclude<O['path'], undefined>>
: O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
: PathArgs<Exclude<O['path'], undefined>>,
OptionsToBodyArgument<
'body' extends keyof O ? O : E,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: Exclude<O['path'], undefined>;
body: 'body' extends keyof O ? O['body'] : E['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ? O['paginationField']
: E['paginationField'];
}
>
: 'body' extends keyof O ?
RestType<
'searchParams' extends keyof O ?
> =
'path' extends keyof O ?
RestType<
'searchParams' extends keyof O ?
O['searchParams'] extends undefined ?
PathArgs<Exclude<O['path'], undefined>>
: O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
: PathArgs<Exclude<O['path'], undefined>>,
OptionsToBodyArgument<
'body' extends keyof O ? O : E,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: Exclude<O['path'], undefined>;
body: 'body' extends keyof O ? O['body'] : E['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ?
O['paginationField']
: E['paginationField'];
}
>
: 'body' extends keyof O ?
RestType<
'searchParams' extends keyof O ?
O['searchParams'] extends undefined ?
PathArgs<Exclude<O['path'], undefined>>
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
: PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
O,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: E['path'];
body: O['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ?
O['paginationField']
: Extract<E['paginationField'], string>;
}
>
: 'searchParams' extends keyof O ?
RestType<
O['searchParams'] extends undefined ?
PathArgs<Exclude<O['path'], undefined>>
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
: PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
O,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: E['path'];
body: O['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ? O['paginationField']
: Extract<E['paginationField'], string>;
}
>
: 'searchParams' extends keyof O ?
RestType<
O['searchParams'] extends undefined ?
PathArgs<Exclude<O['path'], undefined>>
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
E,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: E['path'];
body: E['body'];
searchParams: O['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ? O['paginationField']
: Extract<E['paginationField'], string>;
}
>
: RestInstance<
F,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
{
path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
body: 'body' extends keyof O ? O['body'] : E['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ? O['paginationField']
: E['paginationField'];
}
>;
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
OptionsToBodyArgument<
E,
'method' extends keyof O ? O['method'] : E['method']
>,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
{
path: E['path'];
body: E['body'];
searchParams: O['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ?
O['paginationField']
: Extract<E['paginationField'], string>;
}
>
: RestInstance<
F,
'schema' extends keyof O ? O['schema'] : E['schema'],
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
{
path: 'path' extends keyof O ? Exclude<O['path'], undefined>
: E['path'];
body: 'body' extends keyof O ? O['body'] : E['body'];
searchParams: 'searchParams' extends keyof O ? O['searchParams']
: E['searchParams'];
method: 'method' extends keyof O ? O['method'] : E['method'];
paginationField: 'paginationField' extends keyof O ?
O['paginationField']
: E['paginationField'];
}
>;

export type RestExtendedEndpoint<
O extends PartialRestGenerics,
Expand Down Expand Up @@ -577,8 +583,8 @@ type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;

export type KeyofRestEndpoint = keyof RestInstance;

export type FromFallBack<K extends keyof E, O, E> = K extends keyof O ? O[K]
: E[K];
export type FromFallBack<K extends keyof E, O, E> =
K extends keyof O ? O[K] : E[K];

export type FetchMutate<
A extends readonly any[] = // eslint-disable-next-line @typescript-eslint/ban-types
Expand Down
9 changes: 5 additions & 4 deletions packages/rest/src/mapCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export default function mapCollection<
type MapCollection<
M extends <C extends schema.Collection>(collection: C) => any,
S extends Schema | undefined,
> = S extends schema.Collection ? ReturnType<M>
: S extends schema.Object<infer T> ? MapCollection<M, T>
: S extends { [K: string]: any } ? MapObject<M, S>
: never;
> =
S extends schema.Collection ? ReturnType<M>
: S extends schema.Object<infer T> ? MapCollection<M, T>
: S extends { [K: string]: any } ? MapObject<M, S>
: never;

export type MapObject<
M extends (collection: schema.Collection) => any,
Expand Down

1 comment on commit 4565fde

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 4565fde Previous: b1b3c47 Ratio
normalizeLong 398 ops/sec (±3.27%) 443 ops/sec (±0.38%) 1.11
infer All 9046 ops/sec (±0.78%) 9086 ops/sec (±2.23%) 1.00
denormalizeLong 276 ops/sec (±1.82%) 271 ops/sec (±2.08%) 0.98
denormalizeLong donotcache 732 ops/sec (±1.11%) 722 ops/sec (±0.56%) 0.99
denormalizeShort donotcache 500x 1238 ops/sec (±0.17%) 1264 ops/sec (±0.10%) 1.02
denormalizeShort 500x 874 ops/sec (±0.36%) 889 ops/sec (±0.36%) 1.02
denormalizeLong with mixin Entity 255 ops/sec (±0.78%) 271 ops/sec (±0.44%) 1.06
denormalizeLong withCache 5910 ops/sec (±0.16%) 5788 ops/sec (±0.15%) 0.98
denormalizeLongAndShort withEntityCacheOnly 1468 ops/sec (±0.35%) 1483 ops/sec (±0.51%) 1.01
denormalizeLong All withCache 6998 ops/sec (±0.16%) 6879 ops/sec (±1.00%) 0.98
denormalizeLong Query-sorted withCache 6654 ops/sec (±0.23%) 6618 ops/sec (±0.34%) 0.99
getResponse 5344 ops/sec (±1.18%) 5573 ops/sec (±1.41%) 1.04
getResponse (null) 2839306 ops/sec (±0.19%) 2809978 ops/sec (±0.49%) 0.99
getResponse (clear cache) 255 ops/sec (±0.65%) 257 ops/sec (±0.51%) 1.01
getSmallResponse 2048 ops/sec (±0.21%) 2061 ops/sec (±0.35%) 1.01
getSmallInferredResponse 1768 ops/sec (±0.09%) 1775 ops/sec (±0.14%) 1.00
getResponse Query-sorted 642 ops/sec (±1.27%) 677 ops/sec (±1.34%) 1.05
getResponse Collection 4939 ops/sec (±1.61%) 4970 ops/sec (±0.98%) 1.01
setLong 408 ops/sec (±2.55%) 446 ops/sec (±0.25%) 1.09
setLongWithMerge 177 ops/sec (±0.44%) 180 ops/sec (±0.30%) 1.02
setLongWithSimpleMerge 194 ops/sec (±0.26%) 190 ops/sec (±0.41%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.