mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix: add modes export, fix event firing with modes and cloudflare
This commit is contained in:
@@ -85,7 +85,12 @@ async function buildApi() {
|
||||
sourcemap,
|
||||
watch,
|
||||
define,
|
||||
entry: ["src/index.ts", "src/core/utils/index.ts", "src/plugins/index.ts"],
|
||||
entry: [
|
||||
"src/index.ts",
|
||||
"src/core/utils/index.ts",
|
||||
"src/plugins/index.ts",
|
||||
"src/modes/index.ts",
|
||||
],
|
||||
outDir: "dist",
|
||||
external: [...external],
|
||||
metafile: true,
|
||||
|
||||
@@ -180,6 +180,11 @@
|
||||
"import": "./dist/plugins/index.js",
|
||||
"require": "./dist/plugins/index.js"
|
||||
},
|
||||
"./modes": {
|
||||
"types": "./dist/types/modes/index.d.ts",
|
||||
"import": "./dist/modes/index.js",
|
||||
"require": "./dist/modes/index.js"
|
||||
},
|
||||
"./adapter/sqlite": {
|
||||
"types": "./dist/types/adapter/sqlite/edge.d.ts",
|
||||
"import": {
|
||||
|
||||
@@ -295,6 +295,7 @@ export class App<
|
||||
return this.module.auth.createUser(p);
|
||||
}
|
||||
|
||||
// @todo: potentially add option to clone the app, so that when used in listeners, it won't trigger listeners
|
||||
getApi(options?: LocalApiOptions) {
|
||||
const fetcher = this.server.request as typeof fetch;
|
||||
if (options && options instanceof Request) {
|
||||
|
||||
@@ -37,19 +37,19 @@ export async function createApp<Env extends CloudflareEnv = CloudflareEnv>(
|
||||
config: CloudflareBkndConfig<Env> = {},
|
||||
ctx: Partial<CloudflareContext<Env>> = {},
|
||||
) {
|
||||
const appConfig = await makeConfig(
|
||||
const appConfig = await makeConfig(config, ctx);
|
||||
return await createRuntimeApp<Env>(
|
||||
{
|
||||
...config,
|
||||
...appConfig,
|
||||
onBuilt: async (app) => {
|
||||
if (ctx.ctx) {
|
||||
registerAsyncsExecutionContext(app, ctx?.ctx);
|
||||
}
|
||||
await config.onBuilt?.(app);
|
||||
await appConfig.onBuilt?.(app);
|
||||
},
|
||||
},
|
||||
ctx,
|
||||
ctx?.env,
|
||||
);
|
||||
return await createRuntimeApp<Env>(appConfig, ctx?.env);
|
||||
}
|
||||
|
||||
// compatiblity
|
||||
|
||||
@@ -158,6 +158,7 @@ export async function makeConfig<Env extends CloudflareEnv = CloudflareEnv>(
|
||||
sessionHelper.set(c, session);
|
||||
await next();
|
||||
});
|
||||
appConfig.options?.manager?.onServerInit?.(server);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -205,7 +205,17 @@ export class EventManager<
|
||||
if (listener.mode === "sync") {
|
||||
syncs.push(listener);
|
||||
} else {
|
||||
asyncs.push(async () => await listener.handler(event, listener.event.slug));
|
||||
asyncs.push(async () => {
|
||||
try {
|
||||
await listener.handler(event, listener.event.slug);
|
||||
} catch (e) {
|
||||
if (this.options?.onError) {
|
||||
this.options.onError(event, e);
|
||||
} else {
|
||||
$console.error("Error executing async listener", listener, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Remove if `once` is true, otherwise keep
|
||||
return !listener.once;
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
pickKeys,
|
||||
mcpTool,
|
||||
convertNumberedObjectToArray,
|
||||
mergeObject,
|
||||
} from "bknd/utils";
|
||||
import * as SystemPermissions from "modules/permissions";
|
||||
import type { AppDataConfig } from "../data-schema";
|
||||
|
||||
@@ -50,6 +50,7 @@ export { getFlashMessage } from "core/server/flash";
|
||||
export * from "core/drivers";
|
||||
export { Event, InvalidEventReturn } from "core/events/Event";
|
||||
export type {
|
||||
EventListener,
|
||||
ListenerMode,
|
||||
ListenerHandler,
|
||||
} from "core/events/EventListener";
|
||||
|
||||
@@ -68,6 +68,7 @@ export function hybrid<Args>({
|
||||
const mm = app.modules as DbModuleManager;
|
||||
mm.buildSyncConfig = syncSchemaOptions;
|
||||
}
|
||||
await appConfig.beforeBuild?.(app);
|
||||
},
|
||||
config: fileConfig,
|
||||
options: {
|
||||
|
||||
@@ -59,8 +59,8 @@ export type BkndModeConfig<Args = any, Additional = {}> = BkndConfig<
|
||||
export async function makeModeConfig<
|
||||
Args = any,
|
||||
Config extends BkndModeConfig<Args> = BkndModeConfig<Args>,
|
||||
>(_config: Config, args: Args) {
|
||||
const appConfig = typeof _config.app === "function" ? await _config.app(args) : _config.app;
|
||||
>({ app, ..._config }: Config, args: Args) {
|
||||
const appConfig = typeof app === "function" ? await app(args) : app;
|
||||
|
||||
const config = {
|
||||
..._config,
|
||||
|
||||
Reference in New Issue
Block a user