diff --git a/src/core/contracts/emitter.ts b/src/core/contracts/emitter.ts deleted file mode 100644 index 11bbc28..0000000 --- a/src/core/contracts/emitter.ts +++ /dev/null @@ -1,9 +0,0 @@ -//i deleted it, hmm so how should we allow users to enable localization? -// a -import type { AnyFunction } from '../../types/utility'; - -export interface Emitter { - addListener(eventName: string | symbol, listener: AnyFunction): this; - removeListener(eventName: string | symbol, listener: AnyFunction): this; - emit(eventName: string | symbol, ...payload: any[]): boolean; -} diff --git a/src/core/contracts/error-handling.ts b/src/core/contracts/error-handling.ts deleted file mode 100644 index d5e9455..0000000 --- a/src/core/contracts/error-handling.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @since 2.0.0 - */ -export interface ErrorHandling { - /** - * @deprecated - * Version 4 will remove this method - */ - crash(err: Error): never; - /** - * A function that is called on every throw. - * @param error - */ - updateAlive(error: Error): void; - -} diff --git a/src/core/contracts/hooks.ts b/src/core/contracts/hooks.ts deleted file mode 100644 index ee329dd..0000000 --- a/src/core/contracts/hooks.ts +++ /dev/null @@ -1,16 +0,0 @@ - -/** - * Represents an initialization contract. - * Let dependencies implement this to initiate some logic. - */ -export interface Init { - init(): unknown; -} - -/** - * Represents a Disposable contract. - * Let dependencies implement this to dispose and cleanup. - */ -export interface Disposable { - dispose(): unknown; -} diff --git a/src/core/contracts/index.ts b/src/core/contracts/index.ts deleted file mode 100644 index fdd9bc6..0000000 --- a/src/core/contracts/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './error-handling'; -export * from './logging'; -export * from './hooks'; -export * from './emitter'; - diff --git a/src/core/contracts/logging.ts b/src/core/contracts/logging.ts deleted file mode 100644 index 9ceb761..0000000 --- a/src/core/contracts/logging.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @since 2.0.0 - */ -export interface Logging { - error(payload: LogPayload): void; - warning(payload: LogPayload): void; - info(payload: LogPayload): void; - debug(payload: LogPayload): void; -} - -export type LogPayload = { message: T }; diff --git a/src/core/id.ts b/src/core/id.ts index 50a781e..91ab87b 100644 --- a/src/core/id.ts +++ b/src/core/id.ts @@ -8,17 +8,12 @@ import { CommandType, EventType } from './structures'; */ export function reconstruct(event: T) { switch (event.type) { - case InteractionType.MessageComponent: { - return [`${event.customId}_C${event.componentType}`]; - } + case InteractionType.MessageComponent: return [`${event.customId}_C${event.componentType}`]; case InteractionType.ApplicationCommand: - case InteractionType.ApplicationCommandAutocomplete: { + case InteractionType.ApplicationCommandAutocomplete: return [`${event.commandName}_A${event.commandType}`, `${event.commandName}_B`]; - } //Modal interactions are classified as components for sern - case InteractionType.ModalSubmit: { - return [`${event.customId}_M`]; - } + case InteractionType.ModalSubmit: return [`${event.customId}_M`]; } } /** diff --git a/src/core/index.ts b/src/core/index.ts index ef0881d..079589f 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,4 +1,4 @@ -export * from './contracts'; +export * from './interfaces'; export * from './create-plugins'; export * from './structures'; export * from './ioc'; diff --git a/src/core/interfaces.ts b/src/core/interfaces.ts new file mode 100644 index 0000000..9c1ab4f --- /dev/null +++ b/src/core/interfaces.ts @@ -0,0 +1,54 @@ +import type { AnyFunction } from '../types/utility'; + + +/** + * Represents an initialization contract. + * Let dependencies implement this to initiate some logic. + */ +export interface Init { + init(): unknown; +} + +/** + * Represents a Disposable contract. + * Let dependencies implement this to dispose and cleanup. + */ +export interface Disposable { + dispose(): unknown; +} + +export interface Emitter { + addListener(eventName: string | symbol, listener: AnyFunction): this; + removeListener(eventName: string | symbol, listener: AnyFunction): this; + emit(eventName: string | symbol, ...payload: any[]): boolean; +} + + +/** + * @since 2.0.0 + */ +export interface ErrorHandling { + /** + * @deprecated + * Version 4 will remove this method + */ + crash(err: Error): never; + /** + * A function that is called on every throw. + * @param error + */ + updateAlive(error: Error): void; + +} + +/** + * @since 2.0.0 + */ +export interface Logging { + error(payload: LogPayload): void; + warning(payload: LogPayload): void; + info(payload: LogPayload): void; + debug(payload: LogPayload): void; +} + +export type LogPayload = { message: T }; diff --git a/src/core/ioc/base.ts b/src/core/ioc/base.ts index 5994783..6c65c75 100644 --- a/src/core/ioc/base.ts +++ b/src/core/ioc/base.ts @@ -5,7 +5,7 @@ import { CoreContainer } from './container'; import { Result } from 'ts-results-es'; import { __Services } from '../_internal'; import { AnyFunction } from '../../types/utility'; -import type { Logging } from '../contracts/logging'; +import type { Logging } from '../interfaces'; import type { UnpackFunction } from 'iti'; //SIDE EFFECT: GLOBAL DI let containerSubject: CoreContainer>; diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index 98dd2ca..3040d67 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -6,7 +6,7 @@ import { createRequire } from 'node:module'; import type { ImportPayload, Wrapper } from '../types/core'; import type { Module } from '../types/core-modules'; import { existsSync } from 'fs'; -import type { Logging } from './contracts/logging'; +import type { Logging } from './interfaces'; export const parseCallsite = (fpath: string) => { @@ -76,7 +76,7 @@ export const getFullPathTree = (dir: string) => readPaths(path.resolve(dir)); export const filename = (p: string) => fmtFileName(path.basename(p)); -const validExtensions = ['.js', '.cjs', '.mts', '.mjs', '.cts', '.ts', '']; +const validExtensions = ['.js', '.ts', '']; const isSkippable = (filename: string) => { //empty string is for non extension files (directories) return filename[0] === '!' || !validExtensions.includes(path.extname(filename)); @@ -90,23 +90,19 @@ async function deriveFileInfo(dir: string, file: string) { } async function* readPaths(dir: string): AsyncGenerator { - try { - const files = await readdir(dir); - for (const file of files) { - const { fullPath, fileStats, base } = await deriveFileInfo(dir, file); - if (fileStats.isDirectory()) { - //Todo: refactor so that i dont repeat myself for files (line 71) - if (!isSkippable(base)) { - yield* readPaths(fullPath); - } - } else { - if (!isSkippable(base)) { - yield 'file:///' + fullPath; - } + const files = await readdir(dir); + for (const file of files) { + const { fullPath, fileStats, base } = await deriveFileInfo(dir, file); + if (fileStats.isDirectory()) { + //Todo: refactor so that i dont repeat myself for files (line 71) + if (!isSkippable(base)) { + yield* readPaths(fullPath); + } + } else { + if (!isSkippable(base)) { + yield 'file:///' + fullPath; } } - } catch (err) { - throw err; } } diff --git a/src/core/modules.ts b/src/core/modules.ts index 0b3946e..96136aa 100644 --- a/src/core/modules.ts +++ b/src/core/modules.ts @@ -2,8 +2,6 @@ import { ClientEvents } from 'discord.js'; import { EventType } from '../core/structures'; import type { AnyEventPlugin, } from '../types/core-plugin'; import type { - CommandModule, - EventModule, InputCommand, InputEvent, } from '../types/core-modules'; diff --git a/src/core/operators.ts b/src/core/operators.ts index 5350de4..44fbf54 100644 --- a/src/core/operators.ts +++ b/src/core/operators.ts @@ -16,7 +16,7 @@ import { pipe, share, } from 'rxjs'; -import { Emitter, ErrorHandling, Logging } from './contracts'; +import { Emitter, ErrorHandling, Logging } from './interfaces'; import util from 'node:util'; import type { PluginResult } from '../types/core-plugin'; import type { Result } from 'ts-results-es' diff --git a/src/core/presences.ts b/src/core/presences.ts index 6e66431..33ad8cd 100644 --- a/src/core/presences.ts +++ b/src/core/presences.ts @@ -1,6 +1,6 @@ import type { ActivitiesOptions } from "discord.js"; import type { IntoDependencies } from "../types/ioc"; -import type { Emitter } from "./contracts/emitter"; +import type { Emitter } from "./interfaces"; type Status = 'online' | 'idle' | 'invisible' | 'dnd' type PresenceReduce = (previous: Result) => Result; diff --git a/src/core/structures/services/error-handling.ts b/src/core/structures/services/error-handling.ts index 143639c..7f53117 100644 --- a/src/core/structures/services/error-handling.ts +++ b/src/core/structures/services/error-handling.ts @@ -1,4 +1,4 @@ -import { ErrorHandling } from '../../contracts'; +import { ErrorHandling } from '../../interfaces'; /** * @internal diff --git a/src/core/structures/services/logger.ts b/src/core/structures/services/logger.ts index 5de19c7..9459791 100644 --- a/src/core/structures/services/logger.ts +++ b/src/core/structures/services/logger.ts @@ -1,4 +1,4 @@ -import { LogPayload, Logging } from '../../contracts'; +import { LogPayload, Logging } from '../../interfaces'; /** * @internal diff --git a/src/handlers/dispatchers.ts b/src/handlers/dispatchers.ts index e1218b6..8bf6cff 100644 --- a/src/handlers/dispatchers.ts +++ b/src/handlers/dispatchers.ts @@ -61,10 +61,8 @@ export function createDispatcher(payload: { module: Processed; event: BaseInteraction; }) { - assert.ok( - CommandType.Text !== payload.module.type, - SernError.MismatchEvent + 'Found text command in interaction stream', - ); + assert.ok(CommandType.Text !== payload.module.type, + SernError.MismatchEvent + 'Found text command in interaction stream'); switch (payload.module.type) { case CommandType.Slash: case CommandType.Both: { diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index 6eff29f..f66f4e9 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -85,7 +85,7 @@ export function createInteractionHandler( export function createMessageHandler( source: Observable, defaultPrefix: string, - mg: any, //TODO + mg: any, ) { return createGenericHandler(source, async event => { const [prefix, ...rest] = fmt(event.content, defaultPrefix); diff --git a/src/handlers/ready-event.ts b/src/handlers/ready-event.ts index 7be2e7a..8b1a671 100644 --- a/src/handlers/ready-event.ts +++ b/src/handlers/ready-event.ts @@ -1,8 +1,13 @@ import { ObservableInput, concat, first, fromEvent, ignoreElements, pipe, tap } from 'rxjs'; import { _Module } from '../core/_internal'; -import { Logging, } from '../core/contracts'; +import { Logging, } from '../core/interfaces'; import type { DependencyList } from '../types/ioc'; +const once = (log: Logging | undefined) => pipe( + tap(() => { log?.info({ message: "Waiting on discord client to be ready..." }) }), + first(), + ignoreElements()) + export function readyHandler( [sEmitter, , log ,, client]: DependencyList, allPaths: ObservableInput, @@ -17,7 +22,4 @@ export function readyHandler( // `Found ${module.name} at ${module.meta.fullPath}, which does not have a valid type`); } -const once = (log: Logging | undefined) => pipe( - tap(() => { log?.info({ message: "Waiting on discord client to be ready..." }) }), - first(), - ignoreElements()) + diff --git a/src/index.ts b/src/index.ts index 1f0af39..9bbe41e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,7 +40,7 @@ export type { Wrapper } from './types/core'; export type { Args, SlashOptions, Payload, SernEventsMapping } from './types/utility'; -export type { Singleton, Transient, CoreDependencies, Initializable } from './types/ioc'; +export type { Singleton, Transient, CoreDependencies } from './types/ioc'; export { commandModule, diff --git a/src/types/ioc.ts b/src/types/ioc.ts index 290ce28..303ed24 100644 --- a/src/types/ioc.ts +++ b/src/types/ioc.ts @@ -1,5 +1,5 @@ import { Container, UnpackFunction } from 'iti'; -import * as Contracts from '../core/contracts'; +import * as Contracts from '../core/interfaces'; /** * Type to annotate that something is a singleton. * T is created once and lazily.