style: pretty please (#207)

Co-authored-by: jacoobes <jacoobes@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2023-01-30 12:35:37 -06:00
committed by GitHub
parent f6afafa352
commit 1d6751a9cd
13 changed files with 2517 additions and 1791 deletions

4206
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,19 +1,26 @@
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 };
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;
export function single<T extends NotFunction>(cb: T): () => T;
/**
* New signature
* @param cb
*/
export function single<T extends () => unknown>(cb: T) : T;
export function single<T extends () => unknown>(cb: T): T;
/**
* Please note that on intellij, the deprecation is for all signatures, which is unintended behavior (and
* very annoying).
@@ -21,23 +28,23 @@ 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;
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;
export function transient<T extends NotFunction>(cb: T): () => () => T;
export function transient<T extends () => () => unknown>(cb: T): T;
/**
* Following iti's singleton and transient implementation,
* 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;
if (typeof cb !== 'function') return () => () => cb;
return cb;
}

View File

@@ -20,20 +20,18 @@ export function composeRoot<T extends Dependencies>(conf: DependencyConfiguratio
//Get the current container. This should have no client or possible logger yet.
const currentContainer = containerSubject.getValue();
const excludeLogger = conf.exclude?.has('@sern/logger');
if(!excludeLogger) {
if (!excludeLogger) {
currentContainer.add({
'@sern/logger' : () => new DefaultLogging()
'@sern/logger': () => new DefaultLogging(),
});
}
//Build the container based on the callback provided by the user
const container = conf.build(currentContainer);
//Check if the built container contains @sern/client or throw
// a runtime exception
Result
.wrap(() => container.get('@sern/client'))
.expect(SernError.MissingRequired);
Result.wrap(() => container.get('@sern/client')).expect(SernError.MissingRequired);
if(!excludeLogger) {
if (!excludeLogger) {
container.get('@sern/logger')?.info({ message: 'All dependencies loaded successfully.' });
}
//I'm sorry little one
@@ -61,12 +59,15 @@ export function useContainerRaw<T extends Dependencies>() {
*/
function defaultContainer() {
return createContainer()
.add({ '@sern/errors': () => new DefaultErrorHandling()})
.add({ '@sern/store' : () => new ModuleStore()})
.add(ctx => {
return {
'@sern/modules': () => new DefaultModuleManager(ctx['@sern/store'])
};
.add({ '@sern/errors': () => new DefaultErrorHandling() })
.add({ '@sern/store': () => new ModuleStore() })
.add(ctx => {
return {
'@sern/modules': () => new DefaultModuleManager(ctx['@sern/store']),
};
})
.add({ '@sern/emitter': () => new SernEmitter()}) as Container<Omit<Dependencies, '@sern/client' | '@sern/logger'>, {}>;
}
.add({ '@sern/emitter': () => new SernEmitter() }) as Container<
Omit<Dependencies, '@sern/client' | '@sern/logger'>,
{}
>;
}

View File

@@ -34,13 +34,15 @@ export default class InteractionHandler extends EventsHandler<{
concatMap(payload => executeModule(this.emitter, payload)),
catchError(handleError(this.crashHandler, this.logger)),
finalize(() => {
this.logger?.info({ message: 'interactionCreate stream closed or reached end of lifetime'});
this.logger?.info({
message: 'interactionCreate stream closed or reached end of lifetime',
});
useContainerRaw()
?.disposeAll()
.then(() => {
this.logger?.info({ message: 'Cleaning container and crashing' });
});
})
}),
)
.subscribe();
}

View File

@@ -32,13 +32,15 @@ export default class MessageHandler extends EventsHandler<{
concatMap(payload => executeModule(this.emitter, payload)),
catchError(handleError(this.crashHandler, this.logger)),
finalize(() => {
this.logger?.info({ message: 'messageCreate stream closed or reached end of lifetime'});
this.logger?.info({
message: 'messageCreate stream closed or reached end of lifetime',
});
useContainerRaw()
?.disposeAll()
.then(() => {
this.logger?.info({ message: 'Cleaning container and crashing' });
});
})
}),
)
.subscribe();
}

View File

@@ -32,7 +32,7 @@ export function callPlugin(args: unknown): OperatorFunction<
return pipe(
concatMap(async plugin => {
const isNewPlugin = Reflect.has(plugin, guayin);
if(isNewPlugin) {
if (isNewPlugin) {
if (Array.isArray(args)) {
return plugin.execute(...args);
}

View File

@@ -52,13 +52,13 @@ export function processEvents({ containerConfig, events }: Wrapper) {
tap(dispatcher => dispatcher.subscribe()),
catchError(handleError(errorHandling, logger)),
finalize(() => {
logger?.info({ message: 'an event module reached end of lifetime'});
logger?.info({ message: 'an event module reached end of lifetime' });
useContainerRaw()
?.disposeAll()
.then(() => {
logger?.info({ message: 'Cleaning container and crashing' });
});
})
}),
)
.subscribe();
}

View File

@@ -16,7 +16,8 @@ import type {
StringSelectCommand,
TextCommand,
UserSelectCommand,
ContextMenuMsg, Module,
ContextMenuMsg,
Module,
} from '../../types/module';
import type { Args, Payload, Processed, SlashOptions } from '../../types/handler';
import type Context from '../structures/context';

View File

@@ -10,7 +10,7 @@ export function makePlugin<V extends unknown[]>(
return {
type,
execute,
[guayin]: undefined
[guayin]: undefined,
} as Plugin<V>;
}

View File

@@ -15,4 +15,4 @@ export * from './handler/structures';
export * from './handler/plugins';
export * from './handler/contracts';
export { SernEmitter };
export * from './handler/dependencies';
export * from './handler/dependencies';

View File

@@ -62,8 +62,8 @@ export type MapDeps<Deps extends Dependencies, T extends readonly unknown[]> = T
//Basically, '@sern/client' | '@sern/store' | '@sern/modules' | '@sern/error' | '@sern/emitter' will be provided defaults, and you can exclude the rest
export type OptionalDependencies = '@sern/logger';
export type Processed<T> = T & { name: string; description: string };
export type Deprecated<Message extends string> = [never, Message]
export type Deprecated<Message extends string> = [never, Message];
export interface DependencyConfiguration<T extends Dependencies> {
exclude?: Set<OptionalDependencies>;
build: (root: Container<Omit<Dependencies, '@sern/client'>, {}>) => Container<T, {}>
}
exclude?: Set<OptionalDependencies>;
build: (root: Container<Omit<Dependencies, '@sern/client'>, {}>) => Container<T, {}>;
}

View File

@@ -22,8 +22,8 @@ export type PluginResult = Awaitable<VoidResult>;
export type VoidResult = Result<void, void>;
export interface Controller {
next: () => Ok<void>
stop: () => Err<void>
next: () => Ok<void>;
stop: () => Err<void>;
}
export interface Plugin<Args extends any[] = any[]> {
type: PluginType;
@@ -50,7 +50,10 @@ export interface CommandPlugin<T extends CommandType = CommandType> {
name?: string;
description?: string;
type: PluginType.Command;
execute: (m: InitArgs<Processed<CommandModule>>, controller?: Deprecated<'Please import controller instead'>) => PluginResult;
execute: (
m: InitArgs<Processed<CommandModule>>,
controller?: Deprecated<'Please import controller instead'>,
) => PluginResult;
}
/**
* @deprecated
@@ -60,7 +63,7 @@ export interface EventPlugin<T extends CommandType> {
name?: string;
description?: string;
type: PluginType.Event;
execute: (args : CommandArgs<T, PluginType.Event>, controller?: Controller) => PluginResult
execute: (args: CommandArgs<T, PluginType.Event>, controller?: Controller) => PluginResult;
}
export type DiscordEmitterPlugin = Deprecated<'Please view alternatives: '>;
export type ExternalEmitterPlugin = Deprecated<'Please view alternatives: '>;