A powerful and extendable Discord bot, with it's own module system :3 thevoid.cafe/projects/voidy

โœจ๐Ÿ“ Implement ModuleLoader and Registry, Update Loader and registry docs

+53 -8
+1 -1
docs/architecture/registry-level.md
··· 9 9 10 10 The following methods are required: 11 11 - collect (uses the ModuleLoader to collect the raw JSON output of all registry modules) [registry::preCollect, registry::postCollect] 12 - - load (uses various loaders to prepare Module contents, based on the Module's exports property, which exports an array of ModuleExportItem's.) [registry::preLoad, registry::postLoad] 12 + - prepare (uses various loaders to prepare Module contents, based on the Module's exports property, which exports an array of ModuleExportItem's.) [registry::prePrepare, registry::postPrepare] 13 13 - activate (activates the registry and all contained features) [registry::preActivate, registry::postActivate] 14 14 - unload (deactivates all modules stored in the registry and the registry itself) [registry::preUnload, registry::postUnload] 15 15
+5 -5
src/core/Loader.ts
··· 1 1 import { Glob } from "bun"; 2 2 3 3 export interface ILoader<T> { 4 - dataSource: string, 5 - store: T[]; 4 + dataSource: string 5 + store: T[] 6 6 7 - collect: () => Promise<ThisType<this>>, 8 - validate: (data: Partial<T>) => Promise<T | null>, 9 - getJSON: () => T[], 7 + collect: () => Promise<ThisType<this>> 8 + validate: (data: Partial<T>) => Promise<T | null> 9 + getJSON: () => T[] 10 10 } 11 11 12 12 export class Loader<T extends object> implements ILoader<T> {
+21 -2
src/core/Registry.ts
··· 1 - export interface IRegistry { } 1 + import type { Module } from "../loaders/ModuleLoader" 2 + 3 + export interface IRegistry { 4 + store: Module[] 5 + 6 + collect: () => Promise<void> 7 + prepare: () => Promise<void> 8 + activate: () => Promise<void> 9 + unload: () => Promise<void> 10 + } 11 + 12 + export class Registry implements IRegistry { 13 + public store: Module[] = []; 14 + 15 + public async collect() { } 16 + 17 + public async prepare() { } 18 + 19 + public async activate() { } 2 20 3 - export class Registry { } 21 + public async unload() { } 22 + }
+26
src/loaders/ModuleLoader.ts
··· 1 + import { Loader } from "../core/Loader" 2 + 3 + export interface ModuleExportsItem<T extends object> { 4 + source: string 5 + loader: Loader<T> 6 + } 7 + 8 + export interface Module { 9 + name: string 10 + description: string 11 + author: string 12 + exports: ModuleExportsItem<object>[] 13 + } 14 + 15 + export class ModuleLoader extends Loader<Module> { 16 + public override async validate(data: Partial<Module>) { 17 + if ( 18 + !data.name || 19 + !data.description || 20 + !data.author || 21 + !data.exports 22 + ) return null; 23 + 24 + return data as Module; 25 + } 26 + }