fix up tests and cleanup

This commit is contained in:
Jacob Nguyen
2024-06-22 12:10:52 -05:00
parent 7c8e39defb
commit 1d8dbb8962
8 changed files with 60 additions and 61 deletions

View File

@@ -1,10 +1,13 @@
import type { IntoDependencies } from '../types/ioc';
import { Service as $Service, Services as $Services } from '@sern/ioc/global'
import { Container } from '@sern/ioc';
import * as Contracts from './interfaces';
import * as __Services from './structures/default-services';
import type { Logging } from './interfaces';
import { __init_container, useContainerRaw } from '@sern/ioc/global';
import { EventEmitter } from 'node:events';
import { Client } from 'discord.js';
import { Module } from '../types/core-modules';
import { UnpackFunction } from '../types/utility';
export function disposeAll(logger: Logging|undefined) {
useContainerRaw()
@@ -117,3 +120,37 @@ export function transient<T>(cb: () => () => T) {
return cb()();
}
export type DependencyFromKey<T extends keyof Dependencies> = Dependencies[T];
export type IntoDependencies<Tuple extends [...any[]]> = {
[Index in keyof Tuple]: UnpackFunction<NonNullable<DependencyFromKey<Tuple[Index]>>>; //Unpack and make NonNullable
} & { length: Tuple['length'] };
export interface CoreDependencies {
/**
* discord.js client.
*/
'@sern/client': Client;
/**
* sern emitter listens to events that happen throughout
* the handler. some include module.register, module.activate.
*/
'@sern/emitter': Contracts.Emitter;
/**
* An error handler which is the final step before
* the sern process actually crashes.
*/
'@sern/errors': Contracts.ErrorHandling;
/**
* Optional logger. Performs ... logging
*/
'@sern/logger'?: Contracts.Logging;
/**
* Readonly module store. sern stores these
* by module.meta.id -> Module
*/
'@sern/modules': Map<string, Module>;
}

View File

@@ -40,3 +40,6 @@ export const controller = {
next: (val?: Record<string,unknown>) => Ok(val),
stop: (val?: string) => Err(val),
};
export type Controller = typeof controller;

View File

@@ -1,5 +1,5 @@
import type { ActivitiesOptions } from "discord.js";
import type { IntoDependencies } from "../types/ioc";
import type { IntoDependencies } from "./ioc";
import type { Emitter } from "./interfaces";
type Status = 'online' | 'idle' | 'invisible' | 'dnd'

View File

@@ -38,7 +38,6 @@ export type {
export type { Payload, SernEventsMapping } from './types/utility';
export type { CoreDependencies } from './types/ioc';
export {
commandModule,
@@ -48,12 +47,23 @@ export {
export * from './core/presences'
export * from './core/interfaces'
import type { controller } from './core/create-plugins';
export type Controller = typeof controller
export * from './core/create-plugins';
export * from './core/plugin';
export { CommandType, PluginType, PayloadType, EventType } from './core/structures/enums';
export { Context } from './core/structures/context';
export { makeDependencies, single, transient, Service, Services } from './core/ioc';
export { type CoreDependencies, makeDependencies, single, transient, Service, Services } from './core/ioc';
import type { Container } from '@sern/ioc';
/**
* @deprecated This old signature will be incompatible with future versions of sern.
* ```ts
* To switch your old code:
await makeDependencies(({ add }) => {
add('@sern/client', new Client())
})
* ```
*/
export interface DependencyConfiguration {
build: (root: Container) => Container;
}

View File

@@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */
import { CoreDependencies } from './ioc';
import { CoreDependencies } from '../core/ioc';
declare global {
/**

View File

@@ -1,51 +0,0 @@
import type { Container } from '@sern/ioc';
import * as Contracts from '../core/interfaces';
import type { UnpackFunction } from './utility'
import type { Client } from 'discord.js'
import { Module } from './core-modules';
export interface CoreDependencies {
/**
* discord.js client.
*/
'@sern/client': Client;
/**
* sern emitter listens to events that happen throughout
* the handler. some include module.register, module.activate.
*/
'@sern/emitter': Contracts.Emitter;
/**
* An error handler which is the final step before
* the sern process actually crashes.
*/
'@sern/errors': Contracts.ErrorHandling;
/**
* Optional logger. Performs ... logging
*/
'@sern/logger'?: Contracts.Logging;
/**
* Readonly module store. sern stores these
* by module.meta.id -> Module
*/
'@sern/modules': Map<string, Module>;
}
export type DependencyFromKey<T extends keyof Dependencies> = Dependencies[T];
export type IntoDependencies<Tuple extends [...any[]]> = {
[Index in keyof Tuple]: UnpackFunction<NonNullable<DependencyFromKey<Tuple[Index]>>>; //Unpack and make NonNullable
} & { length: Tuple['length'] };
/**
* @deprecated This old signature will be incompatible with future versions of sern.
* ```ts
* To switch your old code:
await makeDependencies(({ add }) => {
add('@sern/client', new Client())
})
* ```
*/
export interface DependencyConfiguration {
build: (root: Container) => Container;
}

View File

@@ -3,7 +3,7 @@ import {
CommandControlPlugin,
CommandInitPlugin,
EventInitPlugin,
} from '../../src/core/create-plugins';
} from '../../src';
import { PluginType, controller } from '../../src';
describe('create-plugins', () => {

View File

@@ -7,7 +7,7 @@ import { faker } from '@faker-js/faker';
import { Module } from '../src/types/core-modules';
import { Processed } from '../src/types/core-modules';
import { EventEmitter } from 'events';
import { EventType } from '../dist/core/structures/enums';
import { EventType } from '../src/core/structures/enums';
import { CommandControlPlugin, CommandInitPlugin, CommandType, controller } from '../src';
vi.mock('discord.js', async (importOriginal) => {