mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
refactor console imports, added config update event
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { $console, type PrimaryFieldType } from "core";
|
||||
import type { PrimaryFieldType } from "core";
|
||||
import { $console } from "core/utils";
|
||||
import { isDebug } from "core/env";
|
||||
import { encodeSearch } from "core/utils/reqres";
|
||||
import type { ApiFetcher } from "Api";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Guard } from "auth";
|
||||
import { $console, BkndError, DebugLogger, env } from "core";
|
||||
import { EventManager } from "core/events";
|
||||
import { BkndError, DebugLogger, env } from "core";
|
||||
import { $console } from "core/utils";
|
||||
import { EventManager, Event } from "core/events";
|
||||
import * as $diff from "core/object/diff";
|
||||
import {
|
||||
Default,
|
||||
@@ -126,9 +127,24 @@ interface T_INTERNAL_EM {
|
||||
|
||||
const debug_modules = env("modules_debug");
|
||||
|
||||
abstract class ModuleManagerEvent<A = {}> extends Event<{ ctx: ModuleBuildContext } & A> {}
|
||||
export class ModuleManagerConfigUpdateEvent<
|
||||
Module extends keyof ModuleConfigs,
|
||||
> extends ModuleManagerEvent<{
|
||||
module: Module;
|
||||
config: ModuleConfigs[Module];
|
||||
}> {
|
||||
static override slug = "mm-config-update";
|
||||
}
|
||||
export const ModuleManagerEvents = {
|
||||
ModuleManagerConfigUpdateEvent,
|
||||
};
|
||||
|
||||
// @todo: cleanup old diffs on upgrade
|
||||
// @todo: cleanup multiple backups on upgrade
|
||||
export class ModuleManager {
|
||||
static Events = ModuleManagerEvents;
|
||||
|
||||
protected modules: Modules;
|
||||
// internal em for __bknd config table
|
||||
__em!: EntityManager<T_INTERNAL_EM>;
|
||||
@@ -151,7 +167,7 @@ export class ModuleManager {
|
||||
) {
|
||||
this.__em = new EntityManager([__bknd], this.connection);
|
||||
this.modules = {} as Modules;
|
||||
this.emgr = new EventManager();
|
||||
this.emgr = new EventManager({ ...ModuleManagerEvents });
|
||||
this.logger = new DebugLogger(debug_modules);
|
||||
let initial = {} as Partial<ModuleConfigs>;
|
||||
|
||||
@@ -628,6 +644,13 @@ export class ModuleManager {
|
||||
try {
|
||||
// overwrite listener to run build inside this try/catch
|
||||
module.setListener(async () => {
|
||||
await this.emgr.emit(
|
||||
new ModuleManagerConfigUpdateEvent({
|
||||
ctx: this.ctx(),
|
||||
module: name,
|
||||
config: module.config as any,
|
||||
}),
|
||||
);
|
||||
await this.buildModules();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/** @jsxImportSource hono/jsx */
|
||||
|
||||
import type { App } from "App";
|
||||
import { $console, config, isDebug } from "core";
|
||||
import { config, isDebug } from "core";
|
||||
import { $console } from "core/utils";
|
||||
import { addFlashMessage } from "core/server/flash";
|
||||
import { html } from "hono/html";
|
||||
import { Fragment } from "hono/jsx";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Exception, isDebug, $console } from "core";
|
||||
import { type Static, StringEnum } from "core/utils";
|
||||
import { Exception, isDebug } from "core";
|
||||
import { type Static, StringEnum, $console } from "core/utils";
|
||||
import { cors } from "hono/cors";
|
||||
import { Module } from "modules/Module";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
|
||||
import type { App } from "App";
|
||||
import { $console, tbValidator as tb } from "core";
|
||||
import {
|
||||
StringEnum,
|
||||
$console,
|
||||
TypeInvalidError,
|
||||
datetimeStringLocal,
|
||||
datetimeStringUTC,
|
||||
|
||||
Reference in New Issue
Block a user