mirror of
https://github.com/sern-handler/handler
synced 2026-06-27 18:22:14 +00:00
refactor: remove unneeded signatures and fix imports
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import type { Container } from 'iti';
|
||||
import type { AnyDependencies, DependencyConfiguration, MapDeps, ServerlessDependencies, WebsocketDependencies } from '../types/core';
|
||||
import type { AnyDependencies, DependencyConfiguration, MapDeps, ServerlessDependencies, WebsocketDependencies, Wrapper } from '../types/core';
|
||||
import { DefaultErrorHandling, DefaultLogging, DefaultModuleManager } from './contracts';
|
||||
import { Result } from 'ts-results-es';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { createContainer } from 'iti';
|
||||
import { ModuleStore, SernEmitter } from './structures';
|
||||
import { AnyWrapper, ServerlessWrapper, WebsocketWrapper } from './structures/wrapper';
|
||||
|
||||
export const containerSubject = new BehaviorSubject(defaultContainer());
|
||||
|
||||
@@ -100,22 +99,11 @@ const requiredDependencyKeys = [
|
||||
'@sern/logger',
|
||||
] as const;
|
||||
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
export function makeFetcher<Dep extends WebsocketDependencies>(containerConfig : WebsocketWrapper['containerConfig'])
|
||||
: <const Keys extends (keyof Dep)[]>(ks: [...Keys]) => MapDeps<Dep, [...typeof requiredDependencyKeys, ...Keys]>;
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
export function makeFetcher<Dep extends ServerlessDependencies>(containerConfig: ServerlessWrapper['containerConfig'])
|
||||
: <const Keys extends (keyof Dep)[]>(ks: [...Keys]) => MapDeps<Dep, [...typeof requiredDependencyKeys, ...Keys]>;
|
||||
/**
|
||||
* A way for sern to grab only the necessary dependencies.
|
||||
* Returns a function which allows for the user to call for more dependencies.
|
||||
*/
|
||||
export function makeFetcher<Dep extends AnyDependencies>(containerConfig : AnyWrapper['containerConfig']) {
|
||||
export function makeFetcher<Dep extends AnyDependencies>(containerConfig : Wrapper['containerConfig']) {
|
||||
return <const Keys extends (keyof Dep)[]>(otherKeys: [...Keys]) =>
|
||||
containerConfig.get(...requiredDependencyKeys, ...otherKeys as (keyof AnyDependencies)[]) as MapDeps<
|
||||
Dep,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './contracts';
|
||||
export * from './platform';
|
||||
export * from './plugins';
|
||||
export * from './structures';
|
||||
export { single, transient, useContainerRaw, makeDependencies } from './dependencies'
|
||||
|
||||
@@ -3,12 +3,12 @@ import { type Result, Err, Ok } from 'ts-results-es';
|
||||
import { Processed } from '../types/core';
|
||||
import { Module } from '../types/module';
|
||||
import * as assert from 'node:assert'
|
||||
import * as util from 'node:util'
|
||||
import util from 'node:util'
|
||||
import { type Observable, from, mergeMap, ObservableInput } from 'rxjs';
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { basename, join, resolve } from 'path';
|
||||
|
||||
type ModuleResult<T> = Promise<Result<Processed<T>, SernError>>
|
||||
export type ModuleResult<T> = Promise<Result<Processed<T>, SernError>>
|
||||
export type Loader<T> = (absPath: string) => ModuleResult<T>
|
||||
|
||||
export async function defaultModuleLoader<T extends Module>(
|
||||
|
||||
@@ -50,13 +50,6 @@ export function callPlugin(args: unknown): OperatorFunction<
|
||||
|
||||
export const arrayifySource = map(src => (Array.isArray(src) ? (src as unknown[]) : [src]));
|
||||
|
||||
export const fillDefaults = <T extends AnyModule>({ module, absPath }: ImportPayload<T>) => {
|
||||
module.description ??= '...'
|
||||
return {
|
||||
absPath,
|
||||
module
|
||||
} as ImportPayload<Processed<T>>;
|
||||
};
|
||||
|
||||
/**
|
||||
* If the current value in Result stream is an error, calls callback.
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
export const enum DispatchType {
|
||||
Websocket,
|
||||
Serverless
|
||||
}
|
||||
|
||||
export type PlatformStrategy =
|
||||
| WebsocketStrategy
|
||||
| ServerlessStrategy;
|
||||
|
||||
export interface WebsocketStrategy {
|
||||
type: DispatchType.Websocket;
|
||||
eventNames: [interactioncreate: string, messagecreate: string, ready: string]
|
||||
defaultPrefix?: string;
|
||||
}
|
||||
|
||||
export interface ServerlessStrategy {
|
||||
type: DispatchType.Serverless;
|
||||
}
|
||||
|
||||
export function makeWebsocketAdapter(
|
||||
eventNames: [interactioncreate: string, messagecreate: string, ready: string],
|
||||
defaultPrefix?: string
|
||||
): WebsocketStrategy {
|
||||
return {
|
||||
type: DispatchType.Websocket,
|
||||
eventNames,
|
||||
defaultPrefix
|
||||
};
|
||||
}
|
||||
|
||||
export function makeServerlessAdapter(): ServerlessStrategy {
|
||||
return {
|
||||
type: DispatchType.Serverless,
|
||||
};
|
||||
}
|
||||
|
||||
export const discordjs = ( defaultPrefix?: string ) => makeWebsocketAdapter(
|
||||
['interactionCreate', 'messageCreate', 'ready'],
|
||||
defaultPrefix
|
||||
)
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { CommandType } from '../structures/enums';
|
||||
import type { PluginType } from '../structures/enums';
|
||||
import type { CommandType, PluginType, EventType } from '../structures/enums';
|
||||
import type { Module } from '../../types/module';
|
||||
import type { Processed } from '../../types/core';
|
||||
import { EventType } from '../structures/enums';
|
||||
import { CommandArgsMatrix, EventArgsMatrix } from '../../types/module';
|
||||
|
||||
export interface InitArgs<T extends Processed<Module>> {
|
||||
|
||||
@@ -14,7 +14,7 @@ export function makePlugin<V extends unknown[]>(
|
||||
}
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @__PURE__
|
||||
*/
|
||||
export function EventInitPlugin<I extends EventType>(
|
||||
execute: (...args: EventArgs<I, PluginType.Init>) => PluginResult,
|
||||
@@ -23,7 +23,7 @@ export function EventInitPlugin<I extends EventType>(
|
||||
}
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @__PURE__
|
||||
*/
|
||||
export function CommandInitPlugin<I extends CommandType>(
|
||||
execute: (...args: CommandArgs<I, PluginType.Init>) => PluginResult,
|
||||
@@ -32,7 +32,7 @@ export function CommandInitPlugin<I extends CommandType>(
|
||||
}
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @__PURE__
|
||||
*/
|
||||
export function CommandControlPlugin<I extends CommandType>(
|
||||
execute: (...args: CommandArgs<I, PluginType.Control>) => PluginResult,
|
||||
@@ -41,7 +41,7 @@ export function CommandControlPlugin<I extends CommandType>(
|
||||
}
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @__PURE__
|
||||
*/
|
||||
export function EventControlPlugin<I extends EventType>(
|
||||
execute: (...args: EventArgs<I, PluginType.Control>) => PluginResult,
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import { AutocompleteInteraction, CommandInteraction, ModalSubmitInteraction } from "discord.js";
|
||||
import { BaseInteraction, InteractionType, MessageComponentInteraction } from "discord.js";
|
||||
import { AnySelectMenuInteraction, AutocompleteInteraction, ButtonInteraction, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, ModalSubmitInteraction, UserContextMenuCommandInteraction } from "discord.js";
|
||||
import { InteractionType } from "discord.js";
|
||||
|
||||
|
||||
export function isMessageComponent(i: BaseInteraction): i is MessageComponentInteraction {
|
||||
interface InteractionTypable {
|
||||
type: InteractionType
|
||||
}
|
||||
//discord.js pls fix ur typings or i will >:(
|
||||
type AnyMessageComponentInteraction = AnySelectMenuInteraction | ButtonInteraction;
|
||||
type AnyCommandInteraction = ChatInputCommandInteraction | MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction;
|
||||
export function isMessageComponent(i: InteractionTypable): i is AnyMessageComponentInteraction {
|
||||
return i.type === InteractionType.MessageComponent;
|
||||
}
|
||||
|
||||
export function isCommand(i: BaseInteraction): i is CommandInteraction {
|
||||
export function isCommand(i: InteractionTypable): i is AnyCommandInteraction {
|
||||
return i.type === InteractionType.ApplicationCommand;
|
||||
}
|
||||
export function isAutocomplete(i: BaseInteraction): i is AutocompleteInteraction {
|
||||
export function isAutocomplete(i: InteractionTypable): i is AutocompleteInteraction {
|
||||
return i.type === InteractionType.ApplicationCommandAutocomplete;
|
||||
}
|
||||
|
||||
export function isModal(i: BaseInteraction): i is ModalSubmitInteraction {
|
||||
export function isModal(i: InteractionTypable): i is ModalSubmitInteraction {
|
||||
return i.type === InteractionType.ModalSubmit;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { SernError } from './errors';
|
||||
import * as assert from 'node:assert'
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import type { ServerlessDependencies, WebsocketDependencies } from '../../types/core';
|
||||
import { DispatchType, ServerlessStrategy, WebsocketStrategy } from '../platform';
|
||||
|
||||
export interface DefaultWrapper {
|
||||
commands: string;
|
||||
defaultPrefix?: string;
|
||||
events?: string;
|
||||
containerConfig: {
|
||||
get: (...keys: (keyof WebsocketDependencies)[]) => unknown[];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface WebsocketWrapper {
|
||||
readonly platform: WebsocketStrategy;
|
||||
commands: string;
|
||||
/**
|
||||
* @deprecated
|
||||
* Please specify this in platform specification
|
||||
*/
|
||||
defaultPrefix?: string;
|
||||
events?: string;
|
||||
containerConfig: {
|
||||
get: (...keys: (keyof WebsocketDependencies)[]) => unknown[];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* Type alias for WebsocketWrapper
|
||||
*/
|
||||
export type Wrapper = WebsocketWrapper | ServerlessWrapper
|
||||
|
||||
export interface ServerlessWrapper {
|
||||
readonly platform: ServerlessStrategy
|
||||
commands: string[];
|
||||
events?: string[];
|
||||
containerConfig: {
|
||||
get: (...keys: (keyof ServerlessDependencies)[]) => unknown[];
|
||||
}
|
||||
}
|
||||
|
||||
export type AnyWrapper =
|
||||
| WebsocketWrapper
|
||||
| ServerlessWrapper
|
||||
|
||||
|
||||
export function isServerless(wrapper: AnyWrapper): wrapper is ServerlessWrapper {
|
||||
return wrapper.platform.type === DispatchType.Serverless;
|
||||
}
|
||||
Reference in New Issue
Block a user