From 8e2ba871c4c5c37514256c1ce3fb0f82e6c0ef84 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 15 Apr 2023 16:48:04 -0500 Subject: [PATCH] chore:update paths --- src/core/dependencies/index.ts | 2 +- src/core/dependencies/lifetimeFunctions.ts | 38 +------- src/core/platform/strategy.ts | 1 + src/core/sernEmitter.ts | 2 +- src/core/structures/context.ts | 9 +- src/core/structures/enums.ts | 8 +- src/handler/sern.ts | 4 +- src/handler/structures/context.ts | 107 --------------------- src/types/handler.ts | 8 +- src/types/plugin.ts | 6 +- 10 files changed, 21 insertions(+), 164 deletions(-) delete mode 100644 src/handler/structures/context.ts diff --git a/src/core/dependencies/index.ts b/src/core/dependencies/index.ts index dde2b2b..52bef44 100644 --- a/src/core/dependencies/index.ts +++ b/src/core/dependencies/index.ts @@ -1,2 +1,2 @@ -export { single, transient, many } from './lifetimeFunctions'; +export { single, transient } from './lifetimeFunctions'; export { useContainerRaw } from './provider'; diff --git a/src/core/dependencies/lifetimeFunctions.ts b/src/core/dependencies/lifetimeFunctions.ts index 3fd66e6..2a84afa 100644 --- a/src/core/dependencies/lifetimeFunctions.ts +++ b/src/core/dependencies/lifetimeFunctions.ts @@ -1,21 +1,4 @@ import { _const } from '../utilities/functions'; - -type NotFunction = - | string - | number - | boolean - | null - | undefined - | bigint - | readonly any[] - | { apply?: never; [k: string]: any } - | { call?: never; [k: string]: any }; - -/** - * @deprecated - * @param cb - */ -export function single(cb: T): () => T; /** * New signature * @since 2.0.0 @@ -31,16 +14,9 @@ export function single unknown>(cb: T): T; * @param cb */ export function single(cb: T) { - if (typeof cb === 'function') return cb; return () => cb; } -/** - * @deprecated - * @param cb - * Deprecated signature - */ -export function transient(cb: T): () => () => T; -export function transient () => unknown>(cb: T): T; + /** * @__PURE__ * @since 2.0.0 @@ -48,16 +24,6 @@ export function transient () => unknown>(cb: T): T; * use transient if you want a new dependency every time your container getter is called * @param cb */ -export function transient(cb: (() => () => T) | T) { - if (typeof cb !== 'function') return () => () => cb; +export function transient(cb: (() => () => T) ) { return cb; } - -/** - * @__PURE__ - * @deprecated - * @param value - * Please use the transient function instead - */ -// prettier-ignore -export const many = (value: T) => () => _const(value); diff --git a/src/core/platform/strategy.ts b/src/core/platform/strategy.ts index a0b8247..3597992 100644 --- a/src/core/platform/strategy.ts +++ b/src/core/platform/strategy.ts @@ -18,4 +18,5 @@ interface WebsocketStrategy { interface ServerlessStrategy { type: DispatchType.Serverless; + endpoint: string; } diff --git a/src/core/sernEmitter.ts b/src/core/sernEmitter.ts index 7ab0035..42ea093 100644 --- a/src/core/sernEmitter.ts +++ b/src/core/sernEmitter.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import type { Payload, SernEventsMapping } from '../types/handler'; -import { PayloadType } from '../handler/structures'; +import { PayloadType } from '../core/structures'; import type { Module } from '../types/module'; /** diff --git a/src/core/structures/context.ts b/src/core/structures/context.ts index 5d8e05d..d7ae796 100644 --- a/src/core/structures/context.ts +++ b/src/core/structures/context.ts @@ -1,12 +1,9 @@ import { Result as Either } from 'ts-results-es'; -export abstract class Context { - private constructor(private _: Either){} - - abstract get message(): Left; - abstract get interaction(): Right; - +export interface Context { + get message(): Left; + get interaction(): Right; } function safeUnwrap(res: Either) { diff --git a/src/core/structures/enums.ts b/src/core/structures/enums.ts index 122ed22..ea4a209 100644 --- a/src/core/structures/enums.ts +++ b/src/core/structures/enums.ts @@ -139,10 +139,10 @@ export enum PayloadType { Warning = 'warning', } -export const enum ApplicationCommandType { - User, - Message, - ChatInput +export enum ApplicationCommandType { + ChatInput = 1, + User = 2, + Message = 3 } diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 6fda81b..a0e831b 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -1,6 +1,6 @@ -import type { Wrapper, CommandType, EventType, PluginType } from '../core/structures'; +import { Wrapper, CommandType, EventType, PluginType } from '../core/structures'; import { makeEventsHandler } from './events/userDefinedEventsHandling'; -import type { AnyEventPlugin, ControlPlugin, InitPlugin, Plugin } from '../types/plugin'; +import { AnyEventPlugin, ControlPlugin, InitPlugin, type Plugin } from '../types/plugin'; import { makeInteractionCreate } from './events/interactionHandler'; import { makeReadyEvent } from './events/readyHandler'; import { makeMessageCreate } from './events/messageHandler'; diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts deleted file mode 100644 index 61ad0c3..0000000 --- a/src/handler/structures/context.ts +++ /dev/null @@ -1,107 +0,0 @@ -import type { - ChatInputCommandInteraction, - Client, - InteractionReplyOptions, - Message, - Snowflake, - MessageReplyOptions, - User, -} from 'discord.js'; -import { Result as Either, Ok as Left, Err as Right } from 'ts-results-es'; -import type { ReplyOptions } from '../../types/handler'; -import { SernError } from './errors'; - -function safeUnwrap(res: Either) { - return res.val; -} -/** - * @since 1.0.0 - * Provides values shared between - * Message and ChatInputCommandInteraction - */ -export default class Context { - private constructor(private ctx: Either) {} - - /** - * Getting the Message object. Crashes if module type is - * CommandType.Slash or the event fired in a Both command was - * ChatInputCommandInteraction - */ - public get message() { - return this.ctx.expect(SernError.MismatchEvent); - } - /** - * Getting the ChatInputCommandInteraction object. Crashes if module type is - * CommandType.Text or the event fired in a Both command was - * Message - */ - public get interaction() { - return this.ctx.expectErr(SernError.MismatchEvent); - } - - public get id(): Snowflake { - return this.ctx.val.id; - } - - public get channel() { - return this.ctx.val.channel; - } - /** - * If context is holding a message, message.author - * else, interaction.user - */ - public get user(): User { - return safeUnwrap(this.ctx.map(m => m.author).mapErr(i => i.user)); - } - - public get createdTimestamp(): number { - return this.ctx.val.createdTimestamp; - } - - public get guild() { - return this.ctx.val.guild; - } - - public get guildId() { - return this.ctx.val.guildId; - } - - /* - * interactions can return APIGuildMember if the guild it is emitted from is not cached - */ - public get member() { - return this.ctx.val.member; - } - - public get client(): Client { - return this.ctx.val.client; - } - - public get inGuild(): boolean { - return this.ctx.val.inGuild(); - } - public isMessage() { - return this.ctx.map(() => true).unwrapOr(false); - } - - public isSlash() { - return !this.isMessage(); - } - - static wrap(wrappable: ChatInputCommandInteraction | Message): Context { - if ('token' in wrappable) { - return new Context(Right(wrappable)); - } - return new Context(Left(wrappable)); - } - - public reply(content: ReplyOptions) { - return safeUnwrap( - this.ctx - .map(m => m.reply(content as string | MessageReplyOptions)) - .mapErr(i => - i.reply(content as string | InteractionReplyOptions).then(() => i.fetchReply()), - ), - ); - } -} diff --git a/src/types/handler.ts b/src/types/handler.ts index 1648c27..112ae5b 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -1,12 +1,12 @@ import type { CommandInteractionOptionResolver } from 'discord.js'; -import type { PayloadType } from '../handler/structures/enums'; +import type { PayloadType } from '../core/structures/enums'; import type { InteractionReplyOptions, MessageReplyOptions } from 'discord.js'; import type { EventEmitter } from 'events'; import type { CommandModule, EventModule, AnyModule } from './module'; import type { UnpackFunction } from 'iti'; -import type { ErrorHandling, Logging, ModuleManager } from '../handler/contracts'; -import type { ModuleStore } from '../handler/structures/moduleStore'; -import type SernEmitter from '../handler/sernEmitter'; +import type { ErrorHandling, Logging, ModuleManager } from '../core/contracts'; +import type { ModuleStore } from '../core/structures/moduleStore'; +import type SernEmitter from '../core/sernEmitter'; import type { Container } from 'iti'; // Thanks to @kelsny export type ParseType = { diff --git a/src/types/plugin.ts b/src/types/plugin.ts index 502c2c6..3658f99 100644 --- a/src/types/plugin.ts +++ b/src/types/plugin.ts @@ -13,11 +13,11 @@ import type { Awaitable } from 'discord.js'; import type { Err, Ok, Result } from 'ts-results-es'; -import type { PluginType } from '../handler/structures/enums'; +import type { PluginType } from '../core/structures/enums'; import type { CommandModule, EventModule } from './module'; -import type { CommandArgs, InitArgs } from '../handler/plugins'; +import type { CommandArgs, InitArgs } from '../core/plugins'; import type { Deprecated, Processed } from './handler'; -import type { CommandType } from '../handler/structures/enums'; +import type { CommandType } from '../core/structures/enums'; export type PluginResult = Awaitable; export type VoidResult = Result;