chore:update paths

This commit is contained in:
Jacob Nguyen
2023-04-15 16:48:04 -05:00
parent 83f6568d84
commit 8e2ba871c4
10 changed files with 21 additions and 164 deletions

View File

@@ -1,2 +1,2 @@
export { single, transient, many } from './lifetimeFunctions';
export { single, transient } from './lifetimeFunctions';
export { useContainerRaw } from './provider';

View File

@@ -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<T extends NotFunction>(cb: T): () => T;
/**
* New signature
* @since 2.0.0
@@ -31,16 +14,9 @@ export function single<T extends () => unknown>(cb: T): T;
* @param cb
*/
export function single<T>(cb: T) {
if (typeof cb === 'function') return cb;
return () => cb;
}
/**
* @deprecated
* @param cb
* Deprecated signature
*/
export function transient<T extends NotFunction>(cb: T): () => () => T;
export function transient<T extends () => () => unknown>(cb: T): T;
/**
* @__PURE__
* @since 2.0.0
@@ -48,16 +24,6 @@ export function transient<T extends () => () => unknown>(cb: T): T;
* use transient if you want a new dependency every time your container getter is called
* @param cb
*/
export function transient<T>(cb: (() => () => T) | T) {
if (typeof cb !== 'function') return () => () => cb;
export function transient<T>(cb: (() => () => T) ) {
return cb;
}
/**
* @__PURE__
* @deprecated
* @param value
* Please use the transient function instead
*/
// prettier-ignore
export const many = <T>(value: T) => () => _const(value);

View File

@@ -18,4 +18,5 @@ interface WebsocketStrategy {
interface ServerlessStrategy {
type: DispatchType.Serverless;
endpoint: string;
}

View File

@@ -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';
/**

View File

@@ -1,12 +1,9 @@
import { Result as Either } from 'ts-results-es';
export abstract class Context<Left, Right> {
private constructor(private _: Either<Left, Right>){}
abstract get message(): Left;
abstract get interaction(): Right;
export interface Context<Left, Right> {
get message(): Left;
get interaction(): Right;
}
function safeUnwrap<T>(res: Either<T, T>) {

View File

@@ -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
}

View File

@@ -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';

View File

@@ -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<T>(res: Either<T, T>) {
return res.val;
}
/**
* @since 1.0.0
* Provides values shared between
* Message and ChatInputCommandInteraction
*/
export default class Context {
private constructor(private ctx: Either<Message, ChatInputCommandInteraction>) {}
/**
* 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()),
),
);
}
}

View File

@@ -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<T> = {

View File

@@ -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<VoidResult>;
export type VoidResult = Result<void, void>;