mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
optimized module manager seeding, added type support for new api hooks and reduced amount of dist chunks
This commit is contained in:
@@ -35,6 +35,8 @@ import { AppFlows } from "../flows/AppFlows";
|
||||
import { AppMedia } from "../media/AppMedia";
|
||||
import type { Module, ModuleBuildContext } from "./Module";
|
||||
|
||||
export type { ModuleBuildContext };
|
||||
|
||||
export const MODULES = {
|
||||
server: AppServer,
|
||||
data: AppData<any>,
|
||||
@@ -75,7 +77,10 @@ export type ModuleManagerOptions = {
|
||||
) => Promise<void>;
|
||||
// base path for the hono instance
|
||||
basePath?: string;
|
||||
// doesn't perform validity checks for given/fetched config
|
||||
trustFetched?: boolean;
|
||||
// runs when initial config provided on a fresh database
|
||||
seed?: (ctx: ModuleBuildContext) => Promise<void>;
|
||||
};
|
||||
|
||||
type ConfigTable<Json = ModuleConfigs> = {
|
||||
@@ -294,7 +299,7 @@ export class ModuleManager {
|
||||
version,
|
||||
json: configs,
|
||||
updated_at: new Date()
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
type: "config",
|
||||
version
|
||||
@@ -448,6 +453,9 @@ export class ModuleManager {
|
||||
await this.buildModules();
|
||||
await this.save();
|
||||
|
||||
// run initial setup
|
||||
await this.setupInitial();
|
||||
|
||||
this.logger.clear();
|
||||
return this;
|
||||
}
|
||||
@@ -462,6 +470,18 @@ export class ModuleManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected async setupInitial() {
|
||||
const ctx = {
|
||||
...this.ctx(),
|
||||
// disable events for initial setup
|
||||
em: this.ctx().em.fork()
|
||||
};
|
||||
|
||||
// perform a sync
|
||||
await ctx.em.schema().sync({ force: true });
|
||||
await this.options?.seed?.(ctx);
|
||||
}
|
||||
|
||||
get<K extends keyof Modules>(key: K): Modules[K] {
|
||||
if (!(key in this.modules)) {
|
||||
throw new Error(`Module "${key}" doesn't exist, cannot get`);
|
||||
|
||||
Reference in New Issue
Block a user