ksdjkldsfld

This commit is contained in:
Jacob Nguyen
2024-05-16 00:21:29 -05:00
parent 203e8c8ecf
commit 44c072f401
10 changed files with 70 additions and 68 deletions

View File

@@ -1,7 +1,6 @@
import type { DependencyConfiguration } from '../../types/ioc';
import { Container } from './container';
import * as __Services from '../structures/default-services';
import { UnpackedDependencies } from '../../types/utility';
import type { Logging } from '../interfaces';
import { __add_container, __init_container, __swap_container, useContainerRaw } from './global';
import { EventEmitter } from 'node:events';
@@ -14,7 +13,7 @@ export function disposeAll(logger: Logging|undefined) {
type Insertable =
| ((container: UnpackedDependencies) => object)
| ((container: Dependencies) => object)
| object
const dependencyBuilder = (container: Container, excluded: string[] ) => {
return {
@@ -26,7 +25,8 @@ const dependencyBuilder = (container: Container, excluded: string[] ) => {
if(typeof v !== 'function') {
container.addSingleton(key, v)
} else {
container.addWiredSingleton(key, (cntr) => v(cntr as UnpackedDependencies))
//@ts-ignore
container.addWiredSingleton(key, (cntr) => v(cntr))
}
},
/**
@@ -53,7 +53,6 @@ const dependencyBuilder = (container: Container, excluded: string[] ) => {
type ValidDependencyConfig =
| ((c: ReturnType<typeof dependencyBuilder>) => any)
| DependencyConfiguration;
/**
* Given the user's conf, check for any excluded/included dependency keys.
@@ -79,13 +78,14 @@ async function composeRoot(
if (!hasLogger) {
container.get<Logging>('@sern/logger')
?.info({ message: 'All dependencies loaded successfully.' });
?.info({ message: 'All dependencies loaded successfully.' });
}
container.ready();
await container.ready();
}
export async function makeDependencies (conf: ValidDependencyConfig) {
await __init_container({ autowire: false });
if(typeof conf === 'function') {
const excluded: string[] = [];
conf(dependencyBuilder(useContainerRaw(), excluded));

View File

@@ -35,14 +35,12 @@ interface PluginExecutable {
* Calls any plugin with {args}.
* @param args if an array, its spread and plugin called.
*/
export function callPlugin(args: unknown): OperatorFunction<PluginExecutable, VoidResult>
export function callPlugin(plugin: PluginExecutable, args: unknown)
{
return concatMap(async plugin => {
if (Array.isArray(args)) {
return plugin.execute(...args);
}
return plugin.execute(args);
});
if (Array.isArray(args)) {
return plugin.execute(...args);
}
return plugin.execute(args);
}
export const arrayifySource = <T>(src: T) =>
@@ -52,7 +50,7 @@ export const arrayifySource = <T>(src: T) =>
* Checks if the stream of results is all ok.
*/
export const everyPluginOk: OperatorFunction<VoidResult, boolean> =
pipe(every(result => result.isOk()),
pipe(every(result => result.isOk()), //this shortcircuits
defaultIfEmpty(true));
export const sharedEventStream = <T>(e: Emitter, eventName: string) =>

View File

@@ -61,7 +61,7 @@ export class Cron extends EventEmitter {
//@ts-ignore
if(!cron.validate(module.pattern)) {
throw Error("Invalid cron expression while adding")
throw Error("Invalid cron expression while adding " + module.name)
}
this.modules.set(module.name!, module as CronEventCommand);
}