diff --git a/src/core/structures/context.ts b/src/core/structures/context.ts index d7ae796..3701636 100644 --- a/src/core/structures/context.ts +++ b/src/core/structures/context.ts @@ -1,18 +1,31 @@ -import { Result as Either } from 'ts-results-es'; +import { Result as Either, Ok, Err } from 'ts-results-es'; - -export interface Context { - get message(): Left; - get interaction(): Right; +/** + * + * @since 3.0.0 + * + */ +export interface CoreContext { + get message(): M; + get interaction(): I; } -function safeUnwrap(res: Either) { +export function safeUnwrap(res: Either) { return res.val; } -export function wrap( - val: Left|Right, - fa: (val: Left|Right) => Either -) { - return fa(val); +export function wrap( + val: B|A, +): Either { + if(typeof val !== 'object' || Array.isArray(val) || val == null) { + throw Error("Could not form correct Context." + "Recieved " + val) + } + const msgInteractionObject = (val as unknown as { interaction: unknown }).interaction; + //falsy comparison: ==. Checks if its null OR undefined + if(msgInteractionObject == null) { + return Ok(val as A) + } + return Err(val as B); } + + diff --git a/src/core/structures/index.ts b/src/core/structures/index.ts index 007e816..35f1363 100644 --- a/src/core/structures/index.ts +++ b/src/core/structures/index.ts @@ -1,6 +1,3 @@ -import { Context } from './context'; -import type Wrapper from './wrapper'; -import { ModuleStore } from './moduleStore'; export * from './errors'; export * from './enums'; -export { Context, Wrapper, ModuleStore }; +export * from './moduleStore'; diff --git a/src/core/structures/wrapper.ts b/src/core/structures/wrapper.ts index 4a5b32a..b61984e 100644 --- a/src/core/structures/wrapper.ts +++ b/src/core/structures/wrapper.ts @@ -1,5 +1,5 @@ import type { ServerlessDependencies, WebsocketDependencies } from '../../types/handler'; -import { DispatchType, ServerlessStrategy, WebsocketStrategy } from '../platform/strategy'; +import { DispatchType, ServerlessStrategy, WebsocketStrategy } from '../platform'; export interface WebsocketWrapper { @@ -19,7 +19,7 @@ export interface WebsocketWrapper { * @deprecated * Type alias for WebsocketWrapper */ -export type Wrapper = WebsocketWrapper +export type Wrapper = WebsocketWrapper | ServerlessWrapper export interface ServerlessWrapper { readonly platform: ServerlessStrategy