mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: make Context platform specific, CoreContext as Core
This commit is contained in:
@@ -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<Left, Right> {
|
||||
get message(): Left;
|
||||
get interaction(): Right;
|
||||
/**
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
*/
|
||||
export interface CoreContext<M, I> {
|
||||
get message(): M;
|
||||
get interaction(): I;
|
||||
}
|
||||
|
||||
function safeUnwrap<T>(res: Either<T, T>) {
|
||||
export function safeUnwrap<T>(res: Either<T, T>) {
|
||||
return res.val;
|
||||
}
|
||||
|
||||
export function wrap<Left, Right>(
|
||||
val: Left|Right,
|
||||
fa: (val: Left|Right) => Either<Left, Right>
|
||||
) {
|
||||
return fa(val);
|
||||
export function wrap<A extends unknown, B extends unknown>(
|
||||
val: B|A,
|
||||
): Either<A,B> {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user