mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Renamed fetchInput to fetcherInput
This commit is contained in:
parent
746028f25b
commit
3b74f8d854
@ -101,14 +101,14 @@ export type CartHooks<T extends CartTypes = CartTypes> = {
|
|||||||
export type GetCartHook<T extends CartTypes = CartTypes> = {
|
export type GetCartHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: {}
|
input: {}
|
||||||
fetchInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddItemHook<T extends CartTypes = CartTypes> = {
|
export type AddItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart']
|
data: T['cart']
|
||||||
input: T['itemBody']
|
input: T['itemBody']
|
||||||
fetchInput: T['itemBody']
|
fetcherInput: T['itemBody']
|
||||||
body: { item: T['itemBody'] }
|
body: { item: T['itemBody'] }
|
||||||
actionInput: T['itemBody']
|
actionInput: T['itemBody']
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ export type AddItemHook<T extends CartTypes = CartTypes> = {
|
|||||||
export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: { item?: T['item']; wait?: number }
|
input: { item?: T['item']; wait?: number }
|
||||||
fetchInput: { itemId: string; item: T['itemBody'] }
|
fetcherInput: { itemId: string; item: T['itemBody'] }
|
||||||
body: { itemId: string; item: T['itemBody'] }
|
body: { itemId: string; item: T['itemBody'] }
|
||||||
actionInput: T['itemBody'] & { id: string }
|
actionInput: T['itemBody'] & { id: string }
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
|||||||
export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: { item?: T['item'] }
|
input: { item?: T['item'] }
|
||||||
fetchInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
body: { itemId: string }
|
body: { itemId: string }
|
||||||
actionInput: { id: string }
|
actionInput: { id: string }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ export type CustomerTypes = {
|
|||||||
export type CustomerHook<T extends CustomerTypes = CustomerTypes> = {
|
export type CustomerHook<T extends CustomerTypes = CustomerTypes> = {
|
||||||
data: T['customer'] | null
|
data: T['customer'] | null
|
||||||
fetchData: { customer: T['customer'] } | null
|
fetchData: { customer: T['customer'] } | null
|
||||||
// actionInput: T['body']
|
|
||||||
// fetchInput: T['body']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
||||||
|
@ -10,7 +10,7 @@ export type LoginTypes = {
|
|||||||
export type LoginHook<T extends LoginTypes = LoginTypes> = {
|
export type LoginHook<T extends LoginTypes = LoginTypes> = {
|
||||||
data: null
|
data: null
|
||||||
actionInput: LoginBody
|
actionInput: LoginBody
|
||||||
fetchInput: LoginBody
|
fetcherInput: LoginBody
|
||||||
body: T['body']
|
body: T['body']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ export type SearchProductsHook<T extends ProductTypes = ProductTypes> = {
|
|||||||
data: T['product'][]
|
data: T['product'][]
|
||||||
body: T['searchBody']
|
body: T['searchBody']
|
||||||
input: T['searchBody']
|
input: T['searchBody']
|
||||||
fetchInput: T['searchBody']
|
fetcherInput: T['searchBody']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
||||||
|
@ -13,7 +13,7 @@ export type SignupHook<T extends SignupTypes = SignupTypes> = {
|
|||||||
data: null
|
data: null
|
||||||
body: T['body']
|
body: T['body']
|
||||||
actionInput: T['body']
|
actionInput: T['body']
|
||||||
fetchInput: T['body']
|
fetcherInput: T['body']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
||||||
|
@ -15,21 +15,21 @@ export type GetWishlistHook<T extends WishlistTypes = WishlistTypes> = {
|
|||||||
data: T['wishlist'] | null
|
data: T['wishlist'] | null
|
||||||
body: { includeProducts?: boolean }
|
body: { includeProducts?: boolean }
|
||||||
input: { includeProducts?: boolean }
|
input: { includeProducts?: boolean }
|
||||||
fetchInput: { customerId: string; includeProducts?: boolean }
|
fetcherInput: { customerId: string; includeProducts?: boolean }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
|
export type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
|
||||||
data: T['wishlist']
|
data: T['wishlist']
|
||||||
body: { item: T['itemBody'] }
|
body: { item: T['itemBody'] }
|
||||||
fetchInput: { item: T['itemBody'] }
|
fetcherInput: { item: T['itemBody'] }
|
||||||
actionInput: T['itemBody']
|
actionInput: T['itemBody']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
|
export type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
|
||||||
data: T['wishlist'] | null
|
data: T['wishlist'] | null
|
||||||
body: { itemId: string }
|
body: { itemId: string }
|
||||||
fetchInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
actionInput: { id: string }
|
actionInput: { id: string }
|
||||||
input: { wishlist?: { includeProducts?: boolean } }
|
input: { wishlist?: { includeProducts?: boolean } }
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ export type HookFetcherFn<H extends HookSchemaBase> = (
|
|||||||
|
|
||||||
export type HookFetcherContext<H extends HookSchemaBase> = {
|
export type HookFetcherContext<H extends HookSchemaBase> = {
|
||||||
options: HookFetcherOptions
|
options: HookFetcherOptions
|
||||||
input: H['fetchInput']
|
input: H['fetcherInput']
|
||||||
fetch: <T = H['fetchData'], B = H['body']>(
|
fetch: <T = H['fetchData'], B = H['body']>(
|
||||||
options: FetcherOptions<B>
|
options: FetcherOptions<B>
|
||||||
) => Promise<T>
|
) => Promise<T>
|
||||||
@ -74,7 +74,7 @@ export type HookSchemaBase = {
|
|||||||
// Input expected by the hook
|
// Input expected by the hook
|
||||||
input?: {}
|
input?: {}
|
||||||
// Input expected before doing a fetch operation (aka fetch handler)
|
// Input expected before doing a fetch operation (aka fetch handler)
|
||||||
fetchInput?: {}
|
fetcherInput?: {}
|
||||||
// Body object expected by the fetch operation
|
// Body object expected by the fetch operation
|
||||||
body?: {}
|
body?: {}
|
||||||
// Data returned by the fetch operation
|
// Data returned by the fetch operation
|
||||||
@ -98,7 +98,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
|
|||||||
useHook(
|
useHook(
|
||||||
context: SWRHookContext<H>
|
context: SWRHookContext<H>
|
||||||
): HookFunction<
|
): HookFunction<
|
||||||
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetchInput']> },
|
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetcherInput']> },
|
||||||
ResponseState<H['data']> & H['swrState']
|
ResponseState<H['data']> & H['swrState']
|
||||||
>
|
>
|
||||||
fetchOptions: HookFetcherOptions
|
fetchOptions: HookFetcherOptions
|
||||||
@ -108,7 +108,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
|
|||||||
export type SWRHookContext<H extends SWRHookSchemaBase> = {
|
export type SWRHookContext<H extends SWRHookSchemaBase> = {
|
||||||
useData(context?: {
|
useData(context?: {
|
||||||
input?: HookFetchInput | HookSWRInput
|
input?: HookFetchInput | HookSWRInput
|
||||||
swrOptions?: SwrOptions<H['data'], H['fetchInput']>
|
swrOptions?: SwrOptions<H['data'], H['fetcherInput']>
|
||||||
}): ResponseState<H['data']>
|
}): ResponseState<H['data']>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,11 +127,13 @@ export type MutationHook<H extends MutationSchemaBase> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type MutationHookContext<H extends MutationSchemaBase> = {
|
export type MutationHookContext<H extends MutationSchemaBase> = {
|
||||||
fetch: keyof H['fetchInput'] extends never
|
fetch: keyof H['fetcherInput'] extends never
|
||||||
? () => H['data'] | Promise<H['data']>
|
? () => H['data'] | Promise<H['data']>
|
||||||
: Partial<H['fetchInput']> extends H['fetchInput']
|
: Partial<H['fetcherInput']> extends H['fetcherInput']
|
||||||
? (context?: { input?: H['fetchInput'] }) => H['data'] | Promise<H['data']>
|
? (context?: {
|
||||||
: (context: { input: H['fetchInput'] }) => H['data'] | Promise<H['data']>
|
input?: H['fetcherInput']
|
||||||
|
}) => H['data'] | Promise<H['data']>
|
||||||
|
: (context: { input: H['fetcherInput'] }) => H['data'] | Promise<H['data']>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SwrOptions<Data, Input = null, Result = any> = ConfigInterface<
|
export type SwrOptions<Data, Input = null, Result = any> = ConfigInterface<
|
||||||
|
@ -22,7 +22,7 @@ export type UseData = <H extends SWRHookSchemaBase>(
|
|||||||
},
|
},
|
||||||
input: HookFetchInput | HookSWRInput,
|
input: HookFetchInput | HookSWRInput,
|
||||||
fetcherFn: Fetcher,
|
fetcherFn: Fetcher,
|
||||||
swrOptions?: SwrOptions<H['data'], H['fetchInput']>
|
swrOptions?: SwrOptions<H['data'], H['fetcherInput']>
|
||||||
) => ResponseState<H['data']>
|
) => ResponseState<H['data']>
|
||||||
|
|
||||||
const useData: UseData = (options, input, fetcherFn, swrOptions) => {
|
const useData: UseData = (options, input, fetcherFn, swrOptions) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user