From f0413fa0a406c2bb69c0946e6f6a1a386990a54a Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Fri, 14 May 2021 13:37:15 -0500 Subject: [PATCH] Moved types --- framework/commerce/api/operations.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/framework/commerce/api/operations.ts b/framework/commerce/api/operations.ts index 353c1e332..4e511b5d9 100644 --- a/framework/commerce/api/operations.ts +++ b/framework/commerce/api/operations.ts @@ -5,11 +5,9 @@ const noop = () => { throw new Error('Not implemented') } -export type LoginResult = T +const OPERATIONS = ['login'] as const -export const OPERATIONS = ['login'] as const - -export const defaultOperations = OPERATIONS.reduce((ops, k) => { +const defaultOperations = OPERATIONS.reduce((ops, k) => { ops[k] = noop return ops }, {} as { [K in AllowedOperations]: typeof noop }) @@ -19,13 +17,18 @@ export function getOperations

( ctx: { commerce: CommerceAPI

} ) { return OPERATIONS.reduce>((carry, k) => { - carry[k] = ops[k]({ ...ctx, operations: carry }) + const op = ops[k] + if (op) { + carry[k] = op({ ...ctx, operations: carry }) + } return carry - }, defaultOperations) as APIOperations2

+ }, defaultOperations) as AllOperations

} export type AllowedOperations = typeof OPERATIONS[number] +export type LoginResult = T + export type Operations

= { login: { (opts: { @@ -44,11 +47,15 @@ export type Operations

= { } export type APIOperations

= { - [K in keyof Operations

]: (ctx: OperationContext

) => Operations

[K] + [K in keyof Operations

]?: (ctx: OperationContext

) => Operations

[K] } -export type APIOperations2

= { - [K in keyof APIOperations

]: ReturnType +export type AllOperations

= { + [K in keyof APIOperations

]: P['operations'][K] extends ( + ...args: any + ) => any + ? ReturnType + : typeof noop } export type OperationContext

= {