-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(DataSource): add the transformError data-source function #24
base: main
Are you sure you want to change the base?
Conversation
@@ -6,11 +6,14 @@ export type DataSourceTag = string; | |||
declare const errorHintSymbol: unique symbol; | |||
declare const stateHintSymbol: unique symbol; | |||
|
|||
export type NonNullableUnknown = NonNullable<unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(blocking): Let's move it to utils.ts
* When set, the `fetch` errors will be transformed into data without changing the state to error. | ||
* @returns NonNullable | ||
*/ | ||
transformError?: (reason: unknown) => TResponseErrorTransform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(non-blocking): reason -> error
export interface DataSource< | ||
TContext, | ||
TParams, | ||
TRequest, | ||
TResponse, | ||
TResponseErrorTransform extends NonNullableUnknown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue(blocking): Move it after TError
and add default like TResponseErrorTransform extends NonNullableUnknown = NonNullableUnknown
to avoid breaking changes
export interface DataSource< | ||
TContext, | ||
TParams, | ||
TRequest, | ||
TResponse, | ||
TResponseErrorTransform extends NonNullableUnknown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(non-blocking): TResponseErrorTransform -> TErrorResponse
* When set, the `fetch` errors will be transformed into data without changing the state to error. | ||
* @returns NonNullable | ||
*/ | ||
transformError?: (reason: unknown) => TResponseErrorTransform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question(blocking): Can we use TError
here instead of unknown
?
infer TData, | ||
infer _TError, | ||
infer _TOptions, | ||
infer _TState, | ||
infer _TFetchContext | ||
> | ||
? ActualData<TData, TResponse> | ||
? ActualData<TResponse, TResponseErrorTransform, TData> | ||
: never; | ||
|
||
export type DataSourceError<TDataSource> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(blocking): Add DataSourceErrorResponse
for inferring like DataSourceError
unknown extends TResponseErrorTransform ? TResponse : TResponse | TResponseErrorTransform; | ||
|
||
export type ActualData<TResponse, TResponseErrorTransform, TData> = unknown extends TData | ||
? unknown extends TResponseErrorTransform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(blocking): Looks like you can use ActualResponse
here
QueryDataSourceContext, | ||
TParams, | ||
TRequest, | ||
TResponse, | ||
TResponseErrorTransform, | ||
TData, | ||
TError, | ||
InfiniteQueryObserverExtendedOptions< | ||
TResponse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue(blocking): You have to wrap TResponse
using ActualResponse
in the TOptions
and TState
types
When the
transformError
is set, thefetch
errors will be transformed into data without changing the state to error.