Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArturAbdullin
Copy link

When the transformError is set, the fetch errors will be transformed into data without changing the state to error.

@@ -6,11 +6,14 @@ export type DataSourceTag = string;
declare const errorHintSymbol: unique symbol;
declare const stateHintSymbol: unique symbol;

export type NonNullableUnknown = NonNullable<unknown>;
Copy link
Collaborator

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;
Copy link
Collaborator

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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;
Copy link
Collaborator

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> =
Copy link
Collaborator

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
Copy link
Collaborator

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,
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants