Renamed endpoint operations to handlers

This commit is contained in:
Luis Alvarez 2021-05-20 17:55:50 -05:00
parent 6bcf9f9e75
commit 012f4b052f
8 changed files with 26 additions and 36 deletions

View File

@ -58,9 +58,9 @@ export type RemoveItemHook = CartHooks['removeItem']
export type CartSchema = Core.CartSchema<CartTypes> export type CartSchema = Core.CartSchema<CartTypes>
export type CartOperations = Core.CartOperations<CartTypes> export type CartHandlers = Core.CartHandlers<CartTypes>
export type GetCartOperation = CartOperations['getCart'] export type GetCartHandler = CartHandlers['getCart']
export type AddItemOperation = CartOperations['addItem'] export type AddItemHandler = CartHandlers['addItem']
export type UpdateItemOperation = CartOperations['updateItem'] export type UpdateItemHandler = CartHandlers['updateItem']
export type RemoveItemOperation = CartOperations['removeItem'] export type RemoveItemHandler = CartHandlers['removeItem']

View File

@ -33,12 +33,12 @@ export type EndpointContext<
E extends EndpointSchemaBase E extends EndpointSchemaBase
> = { > = {
handler: Endpoint<C, E> handler: Endpoint<C, E>
operations: EndpointHandlers<C, E> handlers: EndpointHandlers<C, E>
} }
export type EndpointSchemaBase = { export type EndpointSchemaBase = {
options: {} options: {}
operations: { handlers: {
[k: string]: { data?: any; body?: any } [k: string]: { data?: any; body?: any }
} }
} }
@ -52,11 +52,11 @@ export type EndpointHandlers<
C extends CommerceAPI, C extends CommerceAPI,
E extends EndpointSchemaBase E extends EndpointSchemaBase
> = { > = {
[H in keyof E['operations']]: APIHandler< [H in keyof E['handlers']]: APIHandler<
C, C,
EndpointHandlers<C, E>, EndpointHandlers<C, E>,
E['operations'][H]['data'], E['handlers'][H]['data'],
E['operations'][H]['body'], E['handlers'][H]['body'],
E['options'] E['options']
> >
} }
@ -122,7 +122,7 @@ export function getEndpoint<
res, res,
commerce, commerce,
config: cfg, config: cfg,
operations: context.operations, handlers: context.handlers,
options: context.options ?? {}, options: context.options ?? {},
}) })
} }

View File

@ -20,7 +20,7 @@ export type APIHandlerContext<
res: NextApiResponse<APIResponse<Data>> res: NextApiResponse<APIResponse<Data>>
commerce: C commerce: C
config: C['provider']['config'] config: C['provider']['config']
operations: H handlers: H
/** /**
* Custom configs that may be used by a particular handler * Custom configs that may be used by a particular handler
*/ */

View File

@ -136,37 +136,33 @@ export type RemoveItemHook<T extends CartTypes = CartTypes> = {
export type CartSchema<T extends CartTypes = CartTypes> = { export type CartSchema<T extends CartTypes = CartTypes> = {
endpoint: { endpoint: {
options: {} options: {}
operations: CartOperations<T> handlers: CartHandlers<T>
} }
} }
export type CartOperations<T extends CartTypes = CartTypes> = { export type CartHandlers<T extends CartTypes = CartTypes> = {
getCart: GetCartOperation<T> getCart: GetCartHandler<T>
addItem: AddItemOperation<T> addItem: AddItemHandler<T>
updateItem: UpdateItemOperation<T> updateItem: UpdateItemHandler<T>
removeItem: RemoveItemOperation<T> removeItem: RemoveItemHandler<T>
} }
export type GetCartOperation< export type GetCartHandler<T extends CartTypes = CartTypes> = GetCartHook<T> & {
T extends CartTypes = CartTypes
> = GetCartHook<T> & {
body: { cartId?: string } body: { cartId?: string }
} }
export type AddItemOperation< export type AddItemHandler<T extends CartTypes = CartTypes> = AddItemHook<T> & {
T extends CartTypes = CartTypes
> = AddItemHook<T> & {
body: { cartId: string } body: { cartId: string }
} }
export type UpdateItemOperation< export type UpdateItemHandler<
T extends CartTypes = CartTypes T extends CartTypes = CartTypes
> = UpdateItemHook<T> & { > = UpdateItemHook<T> & {
data: T['cart'] data: T['cart']
body: { cartId: string } body: { cartId: string }
} }
export type RemoveItemOperation< export type RemoveItemHandler<
T extends CartTypes = CartTypes T extends CartTypes = CartTypes
> = RemoveItemHook<T> & { > = RemoveItemHook<T> & {
body: { cartId: string } body: { cartId: string }

View File

@ -8,16 +8,10 @@ export type CustomerTypes = {
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = { export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
endpoint: { endpoint: {
options: {} options: {}
operations: { handlers: {
getLoggedInCustomer: { getLoggedInCustomer: {
data: { customer: T['customer'] } | null data: { customer: T['customer'] } | null
} }
} }
} }
} }
// export type CustomerOperations<T extends CustomerTypes = CustomerTypes> = {
// getLoggedInCustomer: GetCartOperation<T>
// }
// export type GetLoggedInCustomerOperation = {}

View File

@ -10,7 +10,7 @@ export type LoginTypes = {
export type LoginSchema<T extends LoginTypes = LoginTypes> = { export type LoginSchema<T extends LoginTypes = LoginTypes> = {
endpoint: { endpoint: {
options: {} options: {}
operations: { handlers: {
login: { login: {
data: null data: null
body: T['body'] body: T['body']

View File

@ -1,7 +1,7 @@
export type LogoutSchema = { export type LogoutSchema = {
endpoint: { endpoint: {
options: {} options: {}
operations: { handlers: {
logout: { logout: {
data: null data: null
body: { redirectTo?: string } body: { redirectTo?: string }

View File

@ -12,7 +12,7 @@ export type SignupTypes = {
export type SignupSchema<T extends SignupTypes = SignupTypes> = { export type SignupSchema<T extends SignupTypes = SignupTypes> = {
endpoint: { endpoint: {
options: {} options: {}
operations: { handlers: {
signup: { signup: {
data: null data: null
body: T['body'] body: T['body']