mirror of
https://github.com/sern-handler/handler
synced 2026-06-25 09:12:15 +00:00
type alias
This commit is contained in:
@@ -3,6 +3,7 @@ import type {
|
||||
CommandModule,
|
||||
CommandModuleDefs,
|
||||
Module,
|
||||
OnError,
|
||||
} from '../../types/core-modules';
|
||||
import { CommandType } from '../structures';
|
||||
|
||||
@@ -12,8 +13,8 @@ interface MetadataAccess {
|
||||
}
|
||||
|
||||
interface OnErrorAccess {
|
||||
getErrorCallback(m: Module): Record<string,Function>|undefined;
|
||||
setErrorCallback(m: Module, c: Record<string,Function>): void;
|
||||
getErrorCallback(m: Module): OnError;
|
||||
setErrorCallback(m: Module, c: NonNullable<OnError>): void;
|
||||
}
|
||||
/**
|
||||
* @since 2.0.0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CommandMeta, Module } from '../../types/core-modules';
|
||||
import type { CommandMeta, Module, OnError } from '../../types/core-modules';
|
||||
|
||||
/**
|
||||
* Represents a core module store that stores IDs mapped to file paths.
|
||||
@@ -6,5 +6,5 @@ import type { CommandMeta, Module } from '../../types/core-modules';
|
||||
export interface CoreModuleStore {
|
||||
commands: Map<string, string>;
|
||||
metadata: WeakMap<Module, CommandMeta>;
|
||||
onError: WeakMap<Module, Record<string,Function>>;
|
||||
onError: WeakMap<Module, NonNullable<OnError>>;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { basename, extname, join, resolve, parse } from 'path';
|
||||
import assert from 'assert';
|
||||
import { createRequire } from 'node:module';
|
||||
import type { ImportPayload, Wrapper } from '../types/core';
|
||||
import type { Module } from '../types/core-modules';
|
||||
import type { Module, OnError } from '../types/core-modules';
|
||||
|
||||
export type ModuleResult<T> = Promise<ImportPayload<T>>;
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function importModule<T>(absPath: string) {
|
||||
.unwrapOr({ module: commandModule, onError }) as T;
|
||||
}
|
||||
interface FileExtras {
|
||||
onError : Record<string, Function>|undefined
|
||||
onError : OnError
|
||||
}
|
||||
|
||||
export async function defaultModuleLoader<T extends Module>(absPath: string): ModuleResult<T> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CommandMeta, Module } from '../../types/core-modules';
|
||||
import { CommandMeta, Module, OnError } from '../../types/core-modules';
|
||||
import { CoreModuleStore } from '../contracts';
|
||||
|
||||
/*
|
||||
@@ -7,7 +7,7 @@ import { CoreModuleStore } from '../contracts';
|
||||
* For interacting with modules, use the ModuleManager instead.
|
||||
*/
|
||||
export class ModuleStore implements CoreModuleStore {
|
||||
onError = new WeakMap<Module, Record<string, Function>>();
|
||||
onError = new WeakMap<Module, NonNullable<OnError>>();
|
||||
metadata = new WeakMap<Module, CommandMeta>();
|
||||
commands = new Map<string, string>();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Id from '../../../core/id';
|
||||
import { CoreModuleStore, ModuleManager } from '../../contracts';
|
||||
import { Files } from '../../_internal';
|
||||
import { CommandMeta, CommandModule, CommandModuleDefs, Module } from '../../../types/core-modules';
|
||||
import { CommandMeta, CommandModule, CommandModuleDefs, Module, OnError } from '../../../types/core-modules';
|
||||
import { CommandType } from '../enums';
|
||||
/**
|
||||
* @internal
|
||||
@@ -12,10 +12,10 @@ export class DefaultModuleManager implements ModuleManager {
|
||||
constructor(private moduleStore: CoreModuleStore) {}
|
||||
|
||||
|
||||
getErrorCallback(m: Module): Record<string, Function> | undefined {
|
||||
getErrorCallback(m: Module): OnError {
|
||||
return this.moduleStore.onError.get(m);
|
||||
}
|
||||
setErrorCallback(m: Module, c: Record<string, Function>): void {
|
||||
setErrorCallback(m: Module, c: NonNullable<OnError>): void {
|
||||
this.moduleStore.onError.set(m, c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user