mirror of
https://github.com/sern-handler/handler
synced 2026-06-16 21:02:16 +00:00
fix text compile
This commit is contained in:
@@ -13,6 +13,7 @@ export const parseCallsite = (fpath: string) => {
|
||||
return { name: pathobj.name,
|
||||
absPath : path.posix.format(pathobj) }
|
||||
}
|
||||
|
||||
export const shouldHandle = (pth: string, filenam: string) => {
|
||||
const file_name = filenam+path.extname(pth);
|
||||
let newPath = path.join(path.dirname(pth), file_name)
|
||||
@@ -22,7 +23,6 @@ export const shouldHandle = (pth: string, filenam: string) => {
|
||||
}
|
||||
|
||||
|
||||
export type ModuleResult<T> = Promise<ImportPayload<T>>;
|
||||
|
||||
/**
|
||||
* Import any module based on the absolute path.
|
||||
|
||||
@@ -51,14 +51,13 @@ export const arrayifySource = map(src => (Array.isArray(src) ? (src as unknown[]
|
||||
/**
|
||||
* Checks if the stream of results is all ok.
|
||||
*/
|
||||
export const everyPluginOk: OperatorFunction<VoidResult, boolean> = pipe(
|
||||
every(result => result.isOk()),
|
||||
defaultIfEmpty(true),
|
||||
);
|
||||
export const everyPluginOk: OperatorFunction<VoidResult, boolean> =
|
||||
pipe(every(result => result.isOk()),
|
||||
defaultIfEmpty(true));
|
||||
|
||||
export const sharedEventStream = <T>(e: Emitter, eventName: string) =>
|
||||
(fromEvent(e, eventName) as Observable<T>).pipe(share());
|
||||
|
||||
export const sharedEventStream = <T>(e: Emitter, eventName: string) => {
|
||||
return (fromEvent(e, eventName) as Observable<T>).pipe(share());
|
||||
};
|
||||
|
||||
export function handleError<C>(crashHandler: ErrorHandling, emitter: Emitter, logging?: Logging) {
|
||||
return (pload: unknown, caught: Observable<C>) => {
|
||||
@@ -80,5 +79,3 @@ export const filterTap = <K, R>(onErr: (e: R) => void): OperatorFunction<Result<
|
||||
onErr(result.error);
|
||||
return EMPTY
|
||||
}))
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { assertType, describe, it } from 'vitest';
|
||||
|
||||
import { ModuleStore } from '../../src';
|
||||
import * as DefaultContracts from '../../src/core/structures/services';
|
||||
import * as Contracts from '../../src/core/contracts/index.js';
|
||||
import { __Services } from '../../src/core/structures';
|
||||
import * as Contracts from '../../src/core/interfaces';
|
||||
|
||||
describe('default contracts', () => {
|
||||
it('should satisfy contracts', () => {
|
||||
assertType<Contracts.Logging>(new DefaultContracts.DefaultLogging());
|
||||
assertType<Contracts.ErrorHandling>(new DefaultContracts.DefaultErrorHandling());
|
||||
assertType<Contracts.ModuleManager>(
|
||||
new DefaultContracts.DefaultModuleManager(new ModuleStore()),
|
||||
);
|
||||
assertType<Contracts.CoreModuleStore>(new ModuleStore());
|
||||
assertType<Contracts.Logging>(new __Services.DefaultLogging());
|
||||
assertType<Contracts.ErrorHandling>(new __Services.DefaultErrorHandling());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { SpyInstance, afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { CoreContainer } from '../../src/core/ioc/container';
|
||||
import { DefaultLogging } from '../../src/core';
|
||||
import { __Services } from '../../src/core/structures/';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { commandModule, CommandType } from '../../src';
|
||||
import * as Id from '../../src/core/id';
|
||||
import { CommandMeta } from '../../src/types/core-modules';
|
||||
|
||||
function createRandomCommandModules() {
|
||||
return commandModule({
|
||||
type: CommandType.Slash,
|
||||
@@ -19,7 +18,7 @@ describe('services', () => {
|
||||
let consoleMock: SpyInstance;
|
||||
beforeEach(() => {
|
||||
container = new CoreContainer();
|
||||
container.add({ '@sern/logger': () => new DefaultLogging() });
|
||||
container.add({ '@sern/logger': () => new __Services.DefaultLogging() });
|
||||
container.ready();
|
||||
consoleMock = vi.spyOn(container.get('@sern/logger'), 'error').mockImplementation(() => {});
|
||||
});
|
||||
@@ -27,31 +26,6 @@ describe('services', () => {
|
||||
afterAll(() => {
|
||||
consoleMock.mockReset();
|
||||
});
|
||||
it('module-store.ts', async () => {
|
||||
const modules = faker.helpers.multiple(createRandomCommandModules, {
|
||||
count: 40,
|
||||
});
|
||||
|
||||
const paths = faker.helpers
|
||||
.multiple(faker.system.directoryPath, { count: 40 })
|
||||
.map((path, i) => `${path}/${modules[i]}.js`);
|
||||
|
||||
const metadata: CommandMeta[] = modules.map((cm, i) => ({
|
||||
id: Id.create(cm.name!, cm.type),
|
||||
isClass: false,
|
||||
fullPath: `${paths[i]}/${cm.name}.js`,
|
||||
}));
|
||||
const moduleManager = container.get('@sern/modules');
|
||||
let i = 0;
|
||||
for (const m of modules) {
|
||||
moduleManager.set(Id.create(m.name!, m.type), paths[i]);
|
||||
moduleManager.setMetadata(m, metadata[i]);
|
||||
i++;
|
||||
}
|
||||
for (const m of modules) {
|
||||
expect(moduleManager.getMetadata(m), 'module references do not exist').toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
//todo add more
|
||||
it('error-handling', () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { beforeEach, describe, expect, vi, it } from 'vitest';
|
||||
import { createResultResolver, eventDispatcher } from '../../src/handlers/_internal';
|
||||
import { eventDispatcher } from '../../src/handlers/dispatchers';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { Module } from '../../src/core/types/modules';
|
||||
import { Processed } from '../../src/handlers/types';
|
||||
|
||||
Reference in New Issue
Block a user