Remove module store, manager, and Intializable type

This commit is contained in:
Jacob Nguyen
2024-04-28 19:34:08 -05:00
parent 3d10ee1c59
commit 76ee9c6edf
13 changed files with 27 additions and 158 deletions

View File

@@ -1,5 +1,4 @@
export { CommandType, PluginType, PayloadType, EventType } from './enums';
export * from './context';
export * from './services';
export * from './module-store';

View File

@@ -1,11 +0,0 @@
import { CommandMeta, Module } from '../../types/core-modules';
/*
* @deprecated
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
* For interacting with modules, use the ModuleManager instead.
*/
export class ModuleStore {
metadata = new WeakMap<Module, CommandMeta>();
commands = new Map<string, Module>();
}

View File

@@ -1,3 +1,2 @@
export * from './error-handling';
export * from './logger';
export * from './module-manager';

View File

@@ -1,51 +0,0 @@
import * as Id from '../../../core/id';
import { CoreModuleStore, ModuleManager } from '../../contracts';
import { CommandMeta, CommandModule, CommandModuleDefs, Module } from '../../../types/core-modules';
import { CommandType } from '../enums';
/**
* @internal
* @since 2.0.0
* Version 4.0.0 will internalize this api. Please refrain from using DefaultModuleManager!
*/
export class DefaultModuleManager implements ModuleManager {
constructor(private moduleStore: CoreModuleStore) {}
getByNameCommandType<T extends CommandType>(name: string, commandType: T) {
const module = this.get(Id.create(name, commandType));
if (!module) {
return undefined;
}
return module as CommandModuleDefs[T];
}
setMetadata(m: Module, c: CommandMeta): void {
this.moduleStore.metadata.set(m, c);
}
getMetadata(m: Module): CommandMeta {
const maybeModule = this.moduleStore.metadata.get(m);
if (!maybeModule) {
throw Error('Could not find metadata in store for ' + m);
}
return maybeModule;
}
get(id: string) {
return this.moduleStore.commands.get(id);
}
set(id: string, path: CommandModule): void {
this.moduleStore.commands.set(id, path);
}
//not tested
getPublishableCommands(): CommandModule[] {
const entries = this.moduleStore.commands.entries();
const publishable = 0b000000110;
return Array.from(entries)
.filter(([id]) => {
const last_entry = id.at(-1);
return last_entry == 'B' || !(publishable & Number.parseInt(last_entry!));
})
.map(([, path]) => path as CommandModule);
}
}