mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
refactor console imports, added config update event
This commit is contained in:
@@ -60,7 +60,14 @@ function banner(title: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// collection of always-external packages
|
// collection of always-external packages
|
||||||
const external = ["bun:test", "node:test", "node:assert/strict", "@libsql/client"] as const;
|
const external = [
|
||||||
|
"bun:test",
|
||||||
|
"node:test",
|
||||||
|
"node:assert/strict",
|
||||||
|
"@libsql/client",
|
||||||
|
"bknd",
|
||||||
|
/^bknd\/.*/,
|
||||||
|
] as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Building backend and general API
|
* Building backend and general API
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateUserPayload } from "auth/AppAuth";
|
import type { CreateUserPayload } from "auth/AppAuth";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { Event } from "core/events";
|
import { Event } from "core/events";
|
||||||
import type { em as prototypeEm } from "data/prototype";
|
import type { em as prototypeEm } from "data/prototype";
|
||||||
import { Connection } from "data/connection/Connection";
|
import { Connection } from "data/connection/Connection";
|
||||||
@@ -34,7 +34,10 @@ export type AppPluginConfig = {
|
|||||||
export type AppPlugin = (app: App) => AppPluginConfig;
|
export type AppPlugin = (app: App) => AppPluginConfig;
|
||||||
|
|
||||||
abstract class AppEvent<A = {}> extends Event<{ app: App } & A> {}
|
abstract class AppEvent<A = {}> extends Event<{ app: App } & A> {}
|
||||||
export class AppConfigUpdatedEvent extends AppEvent {
|
export class AppConfigUpdatedEvent extends AppEvent<{
|
||||||
|
module: string;
|
||||||
|
config: ModuleConfigs[keyof ModuleConfigs];
|
||||||
|
}> {
|
||||||
static override slug = "app-config-updated";
|
static override slug = "app-config-updated";
|
||||||
}
|
}
|
||||||
export class AppBuiltEvent extends AppEvent {
|
export class AppBuiltEvent extends AppEvent {
|
||||||
@@ -265,7 +268,7 @@ export class App<C extends Connection = Connection, Options extends AppOptions =
|
|||||||
$console.log("App config updated", module);
|
$console.log("App config updated", module);
|
||||||
// @todo: potentially double syncing
|
// @todo: potentially double syncing
|
||||||
await this.build({ sync: true });
|
await this.build({ sync: true });
|
||||||
await this.emgr.emit(new AppConfigUpdatedEvent({ app: this }));
|
await this.emgr.emit(new AppConfigUpdatedEvent({ app: this, module, config }));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async onFirstBoot() {
|
protected async onFirstBoot() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { getFresh } from "./modes/fresh";
|
|||||||
import { getCached } from "./modes/cached";
|
import { getCached } from "./modes/cached";
|
||||||
import { getDurable } from "./modes/durable";
|
import { getDurable } from "./modes/durable";
|
||||||
import type { App } from "bknd";
|
import type { App } from "bknd";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace Cloudflare {
|
namespace Cloudflare {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { CloudflareBkndConfig, CloudflareEnv } from ".";
|
|||||||
import { App } from "bknd";
|
import { App } from "bknd";
|
||||||
import { makeConfig as makeAdapterConfig } from "bknd/adapter";
|
import { makeConfig as makeAdapterConfig } from "bknd/adapter";
|
||||||
import type { Context, ExecutionContext } from "hono";
|
import type { Context, ExecutionContext } from "hono";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { setCookie } from "hono/cookie";
|
import { setCookie } from "hono/cookie";
|
||||||
import { sqlite } from "bknd/adapter/sqlite";
|
import { sqlite } from "bknd/adapter/sqlite";
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { App, CreateAppConfig } from "bknd";
|
|||||||
import { createRuntimeApp, makeConfig } from "bknd/adapter";
|
import { createRuntimeApp, makeConfig } from "bknd/adapter";
|
||||||
import type { CloudflareBkndConfig, Context, CloudflareEnv } from "../index";
|
import type { CloudflareBkndConfig, Context, CloudflareEnv } from "../index";
|
||||||
import { constants, registerAsyncsExecutionContext } from "../config";
|
import { constants, registerAsyncsExecutionContext } from "../config";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
export async function getDurable<Env extends CloudflareEnv = CloudflareEnv>(
|
export async function getDurable<Env extends CloudflareEnv = CloudflareEnv>(
|
||||||
config: CloudflareBkndConfig<Env>,
|
config: CloudflareBkndConfig<Env>,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { App, type CreateAppConfig } from "bknd";
|
import { App, type CreateAppConfig } from "bknd";
|
||||||
import { config as $config, $console } from "bknd/core";
|
import { config as $config } from "bknd/core";
|
||||||
|
import { $console } from "bknd/utils";
|
||||||
import type { MiddlewareHandler } from "hono";
|
import type { MiddlewareHandler } from "hono";
|
||||||
import type { AdminControllerOptions } from "modules/server/AdminController";
|
import type { AdminControllerOptions } from "modules/server/AdminController";
|
||||||
import { Connection } from "bknd/data";
|
import { Connection } from "bknd/data";
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { serveStatic } from "@hono/node-server/serve-static";
|
|||||||
import { registerLocalMediaAdapter } from "adapter/node/storage";
|
import { registerLocalMediaAdapter } from "adapter/node/storage";
|
||||||
import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter";
|
import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter";
|
||||||
import { config as $config } from "bknd/core";
|
import { config as $config } from "bknd/core";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import type { App } from "App";
|
import type { App } from "App";
|
||||||
|
|
||||||
type NodeEnv = NodeJS.ProcessEnv;
|
type NodeEnv = NodeJS.ProcessEnv;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Authenticator, AuthPermissions, Role, type Strategy } from "auth";
|
import { Authenticator, AuthPermissions, Role, type Strategy } from "auth";
|
||||||
import type { PasswordStrategy } from "auth/authenticate/strategies";
|
import type { PasswordStrategy } from "auth/authenticate/strategies";
|
||||||
import { $console, type DB } from "core";
|
import type { DB } from "core";
|
||||||
import { secureRandomString, transformObject } from "core/utils";
|
import { $console, secureRandomString, transformObject } from "core/utils";
|
||||||
import type { Entity, EntityManager } from "data";
|
import type { Entity, EntityManager } from "data";
|
||||||
import { em, entity, enumm, type FieldSchema, text } from "data/prototype";
|
import { em, entity, enumm, type FieldSchema, text } from "data/prototype";
|
||||||
import { Module } from "modules/Module";
|
import { Module } from "modules/Module";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AppAuth } from "auth/AppAuth";
|
import { AppAuth } from "auth/AppAuth";
|
||||||
import type { CreateUser, SafeUser, User, UserPool } from "auth/authenticate/Authenticator";
|
import type { CreateUser, SafeUser, User, UserPool } from "auth/authenticate/Authenticator";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { pick } from "lodash-es";
|
import { pick } from "lodash-es";
|
||||||
import {
|
import {
|
||||||
InvalidConditionsException,
|
InvalidConditionsException,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { $console, type DB, Exception } from "core";
|
import { type DB, Exception } from "core";
|
||||||
import { addFlashMessage } from "core/server/flash";
|
import { addFlashMessage } from "core/server/flash";
|
||||||
import {
|
import {
|
||||||
|
$console,
|
||||||
type Static,
|
type Static,
|
||||||
StringEnum,
|
StringEnum,
|
||||||
type TObject,
|
type TObject,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { type Authenticator, InvalidCredentialsException, type User } from "auth";
|
import { type Authenticator, InvalidCredentialsException, type User } from "auth";
|
||||||
import { $console, tbValidator as tb } from "core";
|
import { tbValidator as tb } from "core";
|
||||||
import { hash, parse, type Static, StrictObject, StringEnum } from "core/utils";
|
import { $console, hash, parse, type Static, StrictObject, StringEnum } from "core/utils";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { compare as bcryptCompare, genSalt as bcryptGenSalt, hash as bcryptHash } from "bcryptjs";
|
import { compare as bcryptCompare, genSalt as bcryptGenSalt, hash as bcryptHash } from "bcryptjs";
|
||||||
import * as tbbox from "@sinclair/typebox";
|
import * as tbbox from "@sinclair/typebox";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { $console, Exception, Permission } from "core";
|
import { Exception, Permission } from "core";
|
||||||
import { objectTransform } from "core/utils";
|
import { $console, objectTransform } from "core/utils";
|
||||||
import type { Context } from "hono";
|
import type { Context } from "hono";
|
||||||
import type { ServerEnv } from "modules/Controller";
|
import type { ServerEnv } from "modules/Controller";
|
||||||
import { Role } from "./Role";
|
import { Role } from "./Role";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { $console, type Permission } from "core";
|
import type { Permission } from "core";
|
||||||
import { patternMatch } from "core/utils";
|
import { $console, patternMatch } from "core/utils";
|
||||||
import type { Context } from "hono";
|
import type { Context } from "hono";
|
||||||
import { createMiddleware } from "hono/factory";
|
import { createMiddleware } from "hono/factory";
|
||||||
import type { ServerEnv } from "modules/Controller";
|
import type { ServerEnv } from "modules/Controller";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import type { MiddlewareHandler } from "hono";
|
import type { MiddlewareHandler } from "hono";
|
||||||
import open from "open";
|
import open from "open";
|
||||||
import { fileExists, getRelativeDistPath } from "../../utils/sys";
|
import { fileExists, getRelativeDistPath } from "../../utils/sys";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { App, CreateAppConfig } from "App";
|
|||||||
import { StorageLocalAdapter } from "adapter/node/storage";
|
import { StorageLocalAdapter } from "adapter/node/storage";
|
||||||
import type { CliBkndConfig, CliCommand } from "cli/types";
|
import type { CliBkndConfig, CliCommand } from "cli/types";
|
||||||
import { Option } from "commander";
|
import { Option } from "commander";
|
||||||
import { colorizeConsole, config } from "core";
|
import { config } from "core";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { registries } from "modules/registries";
|
import { registries } from "modules/registries";
|
||||||
import c from "picocolors";
|
import c from "picocolors";
|
||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
startServer,
|
startServer,
|
||||||
} from "./platform";
|
} from "./platform";
|
||||||
import { createRuntimeApp, makeConfig } from "adapter";
|
import { createRuntimeApp, makeConfig } from "adapter";
|
||||||
import { isBun } from "core/utils";
|
import { colorizeConsole, isBun } from "core/utils";
|
||||||
|
|
||||||
const env_files = [".env", ".dev.vars"];
|
const env_files = [".env", ".dev.vars"];
|
||||||
dotenv.config({
|
dotenv.config({
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type { PasswordStrategy } from "auth/authenticate/strategies";
|
|||||||
import { makeAppFromEnv } from "cli/commands/run";
|
import { makeAppFromEnv } from "cli/commands/run";
|
||||||
import type { CliCommand } from "cli/types";
|
import type { CliCommand } from "cli/types";
|
||||||
import { Argument } from "commander";
|
import { Argument } from "commander";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import c from "picocolors";
|
import c from "picocolors";
|
||||||
import { isBun } from "core/utils";
|
import { isBun } from "core/utils";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { execSync, exec as nodeExec } from "node:child_process";
|
import { execSync, exec as nodeExec } from "node:child_process";
|
||||||
import { readFile, writeFile as nodeWriteFile } from "node:fs/promises";
|
import { readFile, writeFile as nodeWriteFile } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { PostHog } from "posthog-js-lite";
|
import { PostHog } from "posthog-js-lite";
|
||||||
import { getVersion } from "cli/utils/sys";
|
import { getVersion } from "cli/utils/sys";
|
||||||
import { $console, env, isDebug } from "core";
|
import { env, isDebug } from "core";
|
||||||
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
type Properties = { [p: string]: any };
|
type Properties = { [p: string]: any };
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { type Event, type EventClass, InvalidEventReturn } from "./Event";
|
import { type Event, type EventClass, InvalidEventReturn } from "./Event";
|
||||||
import { EventListener, type ListenerHandler, type ListenerMode } from "./EventListener";
|
import { EventListener, type ListenerHandler, type ListenerMode } from "./EventListener";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
export type RegisterListenerConfig =
|
export type RegisterListenerConfig =
|
||||||
| ListenerMode
|
| ListenerMode
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export {
|
|||||||
} from "./object/schema";
|
} from "./object/schema";
|
||||||
|
|
||||||
export * from "./drivers";
|
export * from "./drivers";
|
||||||
export * from "./console";
|
|
||||||
export * from "./events";
|
export * from "./events";
|
||||||
|
|
||||||
// compatibility
|
// compatibility
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { extension, guess, isMimeType } from "media/storage/mime-types-tiny";
|
|||||||
import { randomString } from "core/utils/strings";
|
import { randomString } from "core/utils/strings";
|
||||||
import type { Context } from "hono";
|
import type { Context } from "hono";
|
||||||
import { invariant } from "core/utils/runtime";
|
import { invariant } from "core/utils/runtime";
|
||||||
import { $console } from "../console";
|
import { $console } from "./console";
|
||||||
|
|
||||||
export function getContentName(request: Request): string | undefined;
|
export function getContentName(request: Request): string | undefined;
|
||||||
export function getContentName(contentDisposition: string): string | undefined;
|
export function getContentName(contentDisposition: string): string | undefined;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from "./console";
|
||||||
export * from "./browser";
|
export * from "./browser";
|
||||||
export * from "./objects";
|
export * from "./objects";
|
||||||
export * from "./strings";
|
export * from "./strings";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { $console } from "core";
|
import { $console } from "./console";
|
||||||
|
|
||||||
type ConsoleSeverity = "log" | "warn" | "error";
|
type ConsoleSeverity = "log" | "warn" | "error";
|
||||||
const _oldConsoles = {
|
const _oldConsoles = {
|
||||||
@@ -36,14 +36,14 @@ export function disableConsoleLog(severities: ConsoleSeverity[] = ["log", "warn"
|
|||||||
severities.forEach((severity) => {
|
severities.forEach((severity) => {
|
||||||
console[severity] = () => null;
|
console[severity] = () => null;
|
||||||
});
|
});
|
||||||
$console.setLevel("critical");
|
$console?.setLevel("critical");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function enableConsoleLog() {
|
export function enableConsoleLog() {
|
||||||
Object.entries(_oldConsoles).forEach(([severity, fn]) => {
|
Object.entries(_oldConsoles).forEach(([severity, fn]) => {
|
||||||
console[severity as ConsoleSeverity] = fn;
|
console[severity as ConsoleSeverity] = fn;
|
||||||
});
|
});
|
||||||
$console.resetLevel();
|
$console?.resetLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatMemoryUsage() {
|
export function formatMemoryUsage() {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { $console, isDebug } from "core";
|
|
||||||
import {
|
import {
|
||||||
DataPermissions,
|
DataPermissions,
|
||||||
type EntityData,
|
type EntityData,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { $console, config } from "core";
|
import { config } from "core";
|
||||||
import {
|
import {
|
||||||
|
$console,
|
||||||
type Static,
|
type Static,
|
||||||
StringEnum,
|
StringEnum,
|
||||||
parse,
|
parse,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { $console, type DB as DefaultDB } from "core";
|
import type { DB as DefaultDB } from "core";
|
||||||
|
import { $console } from "core/utils";
|
||||||
import { EventManager } from "core/events";
|
import { EventManager } from "core/events";
|
||||||
import { sql } from "kysely";
|
import { sql } from "kysely";
|
||||||
import { Connection } from "../connection/Connection";
|
import { Connection } from "../connection/Connection";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { $console } from "core/console";
|
import { $console } from "core/utils";
|
||||||
import type { Entity, EntityData } from "../Entity";
|
import type { Entity, EntityData } from "../Entity";
|
||||||
import type { EntityManager } from "../EntityManager";
|
import type { EntityManager } from "../EntityManager";
|
||||||
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
||||||
@@ -32,6 +32,7 @@ export class MutatorResult<T = EntityData[]> extends Result<T> {
|
|||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (!options?.silent) {
|
if (!options?.silent) {
|
||||||
$console.error("[ERROR] Mutator:", error.message);
|
$console.error("[ERROR] Mutator:", error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DB as DefaultDB, PrimaryFieldType } from "core";
|
import type { DB as DefaultDB, PrimaryFieldType } from "core";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { type EmitsEvents, EventManager } from "core/events";
|
import { type EmitsEvents, EventManager } from "core/events";
|
||||||
import { type SelectQueryBuilder, sql } from "kysely";
|
import { type SelectQueryBuilder, sql } from "kysely";
|
||||||
import { InvalidSearchParamsException } from "../../errors";
|
import { InvalidSearchParamsException } from "../../errors";
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { $console } from "core/console";
|
|
||||||
import type { Entity, EntityData } from "../Entity";
|
import type { Entity, EntityData } from "../Entity";
|
||||||
import type { EntityManager } from "../EntityManager";
|
import type { EntityManager } from "../EntityManager";
|
||||||
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
||||||
import type { Compilable, SelectQueryBuilder } from "kysely";
|
import type { Compilable, SelectQueryBuilder } from "kysely";
|
||||||
import { ensureInt } from "core/utils";
|
import { $console, ensureInt } from "core/utils";
|
||||||
|
|
||||||
export type RepositoryResultOptions = ResultOptions & {
|
export type RepositoryResultOptions = ResultOptions & {
|
||||||
silent?: boolean;
|
silent?: boolean;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { $console, type PrimaryFieldType } from "core";
|
import type { PrimaryFieldType } from "core";
|
||||||
|
import { $console } from "core/utils";
|
||||||
import { Event, InvalidEventReturn } from "core/events";
|
import { Event, InvalidEventReturn } from "core/events";
|
||||||
import type { Entity, EntityData } from "../entities";
|
import type { Entity, EntityData } from "../entities";
|
||||||
import type { RepoQuery } from "data/server/query";
|
import type { RepoQuery } from "data/server/query";
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { type Static, StringEnum, dayjs } from "core/utils";
|
import { $console, type Static, StringEnum, dayjs } from "core/utils";
|
||||||
import type { EntityManager } from "../entities";
|
import type { EntityManager } from "../entities";
|
||||||
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
|
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
|
||||||
import { $console } from "core";
|
|
||||||
import * as tbbox from "@sinclair/typebox";
|
import * as tbbox from "@sinclair/typebox";
|
||||||
import type { TFieldTSType } from "data/entities/EntityTypescript";
|
import type { TFieldTSType } from "data/entities/EntityTypescript";
|
||||||
const { Type } = tbbox;
|
const { Type } = tbbox;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { CompiledQuery, TableMetadata } from "kysely";
|
|||||||
import type { IndexMetadata, SchemaResponse } from "../connection/Connection";
|
import type { IndexMetadata, SchemaResponse } from "../connection/Connection";
|
||||||
import type { Entity, EntityManager } from "../entities";
|
import type { Entity, EntityManager } from "../entities";
|
||||||
import { PrimaryField } from "../fields";
|
import { PrimaryField } from "../fields";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
type IntrospectedTable = TableMetadata & {
|
type IntrospectedTable = TableMetadata & {
|
||||||
indices: IndexMetadata[];
|
indices: IndexMetadata[];
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { s } from "core/object/schema";
|
import { s } from "core/object/schema";
|
||||||
import { WhereBuilder, type WhereQuery } from "data/entities/query/WhereBuilder";
|
import { WhereBuilder, type WhereQuery } from "data/entities/query/WhereBuilder";
|
||||||
import { $console } from "core";
|
import { isObject, $console } from "core/utils";
|
||||||
import { isObject } from "core/utils";
|
|
||||||
import type { CoercionOptions, TAnyOf } from "jsonv-ts";
|
import type { CoercionOptions, TAnyOf } from "jsonv-ts";
|
||||||
|
|
||||||
// -------
|
// -------
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Event, EventManager, type ListenerHandler } from "core/events";
|
|||||||
import type { EmitsEvents } from "core/events";
|
import type { EmitsEvents } from "core/events";
|
||||||
import type { Task, TaskResult } from "../tasks/Task";
|
import type { Task, TaskResult } from "../tasks/Task";
|
||||||
import type { Flow } from "./Flow";
|
import type { Flow } from "./Flow";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
export type TaskLog = TaskResult & {
|
export type TaskLog = TaskResult & {
|
||||||
task: Task;
|
task: Task;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { objectTransform, transformObject } from "core/utils";
|
import { $console, transformObject } from "core/utils";
|
||||||
import { type TaskMapType, TriggerMap } from "../index";
|
import { type TaskMapType, TriggerMap } from "../index";
|
||||||
import type { Task } from "../tasks/Task";
|
import type { Task } from "../tasks/Task";
|
||||||
import { Condition, TaskConnection } from "../tasks/TaskConnection";
|
import { Condition, TaskConnection } from "../tasks/TaskConnection";
|
||||||
import { Execution } from "./Execution";
|
import { Execution } from "./Execution";
|
||||||
import { FlowTaskConnector } from "./FlowTaskConnector";
|
import { FlowTaskConnector } from "./FlowTaskConnector";
|
||||||
import { Trigger } from "./triggers/Trigger";
|
import { Trigger } from "./triggers/Trigger";
|
||||||
import { $console } from "core";
|
|
||||||
|
|
||||||
type Jsoned<T extends { toJSON: () => object }> = ReturnType<T["toJSON"]>;
|
type Jsoned<T extends { toJSON: () => object }> = ReturnType<T["toJSON"]>;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Task } from "../../tasks/Task";
|
import type { Task } from "../../tasks/Task";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
|
|
||||||
export class RuntimeExecutor {
|
export class RuntimeExecutor {
|
||||||
async run(
|
async run(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { EventManager } from "core/events";
|
import type { EventManager } from "core/events";
|
||||||
import type { Flow } from "../Flow";
|
import type { Flow } from "../Flow";
|
||||||
import { Trigger } from "./Trigger";
|
import { Trigger } from "./Trigger";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import * as tbbox from "@sinclair/typebox";
|
import * as tbbox from "@sinclair/typebox";
|
||||||
const { Type } = tbbox;
|
const { Type } = tbbox;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Task } from "../Task";
|
import { Task } from "../Task";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import * as tbbox from "@sinclair/typebox";
|
import * as tbbox from "@sinclair/typebox";
|
||||||
const { Type } = tbbox;
|
const { Type } = tbbox;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export {
|
|||||||
type ModuleManagerOptions,
|
type ModuleManagerOptions,
|
||||||
type ModuleBuildContext,
|
type ModuleBuildContext,
|
||||||
type InitialModuleConfigs,
|
type InitialModuleConfigs,
|
||||||
|
ModuleManagerEvents,
|
||||||
} from "./modules/ModuleManager";
|
} from "./modules/ModuleManager";
|
||||||
|
|
||||||
export type { ServerEnv } from "modules/Controller";
|
export type { ServerEnv } from "modules/Controller";
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { $console, type AppEntity } from "core";
|
import type { AppEntity } from "core";
|
||||||
|
import { $console } from "core/utils";
|
||||||
import type { Entity, EntityManager } from "data";
|
import type { Entity, EntityManager } from "data";
|
||||||
import { type FileUploadedEventData, Storage, type StorageAdapter, MediaPermissions } from "media";
|
import { type FileUploadedEventData, Storage, type StorageAdapter, MediaPermissions } from "media";
|
||||||
import { Module } from "modules/Module";
|
import { Module } from "modules/Module";
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { type EmitsEvents, EventManager } from "core/events";
|
import { type EmitsEvents, EventManager } from "core/events";
|
||||||
import { isFile, detectImageDimensions } from "core/utils";
|
import { $console, isFile, detectImageDimensions } from "core/utils";
|
||||||
import { isMimeType } from "media/storage/mime-types-tiny";
|
import { isMimeType } from "media/storage/mime-types-tiny";
|
||||||
import * as StorageEvents from "./events";
|
import * as StorageEvents from "./events";
|
||||||
import type { FileUploadedEventData } from "./events";
|
import type { FileUploadedEventData } from "./events";
|
||||||
import { $console } from "core";
|
|
||||||
import type { StorageAdapter } from "./StorageAdapter";
|
import type { StorageAdapter } from "./StorageAdapter";
|
||||||
|
|
||||||
export type FileListObject = {
|
export type FileListObject = {
|
||||||
|
|||||||
@@ -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 { isDebug } from "core/env";
|
||||||
import { encodeSearch } from "core/utils/reqres";
|
import { encodeSearch } from "core/utils/reqres";
|
||||||
import type { ApiFetcher } from "Api";
|
import type { ApiFetcher } from "Api";
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Guard } from "auth";
|
import { Guard } from "auth";
|
||||||
import { $console, BkndError, DebugLogger, env } from "core";
|
import { BkndError, DebugLogger, env } from "core";
|
||||||
import { EventManager } from "core/events";
|
import { $console } from "core/utils";
|
||||||
|
import { EventManager, Event } from "core/events";
|
||||||
import * as $diff from "core/object/diff";
|
import * as $diff from "core/object/diff";
|
||||||
import {
|
import {
|
||||||
Default,
|
Default,
|
||||||
@@ -126,9 +127,24 @@ interface T_INTERNAL_EM {
|
|||||||
|
|
||||||
const debug_modules = env("modules_debug");
|
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 old diffs on upgrade
|
||||||
// @todo: cleanup multiple backups on upgrade
|
// @todo: cleanup multiple backups on upgrade
|
||||||
export class ModuleManager {
|
export class ModuleManager {
|
||||||
|
static Events = ModuleManagerEvents;
|
||||||
|
|
||||||
protected modules: Modules;
|
protected modules: Modules;
|
||||||
// internal em for __bknd config table
|
// internal em for __bknd config table
|
||||||
__em!: EntityManager<T_INTERNAL_EM>;
|
__em!: EntityManager<T_INTERNAL_EM>;
|
||||||
@@ -151,7 +167,7 @@ export class ModuleManager {
|
|||||||
) {
|
) {
|
||||||
this.__em = new EntityManager([__bknd], this.connection);
|
this.__em = new EntityManager([__bknd], this.connection);
|
||||||
this.modules = {} as Modules;
|
this.modules = {} as Modules;
|
||||||
this.emgr = new EventManager();
|
this.emgr = new EventManager({ ...ModuleManagerEvents });
|
||||||
this.logger = new DebugLogger(debug_modules);
|
this.logger = new DebugLogger(debug_modules);
|
||||||
let initial = {} as Partial<ModuleConfigs>;
|
let initial = {} as Partial<ModuleConfigs>;
|
||||||
|
|
||||||
@@ -628,6 +644,13 @@ export class ModuleManager {
|
|||||||
try {
|
try {
|
||||||
// overwrite listener to run build inside this try/catch
|
// overwrite listener to run build inside this try/catch
|
||||||
module.setListener(async () => {
|
module.setListener(async () => {
|
||||||
|
await this.emgr.emit(
|
||||||
|
new ModuleManagerConfigUpdateEvent({
|
||||||
|
ctx: this.ctx(),
|
||||||
|
module: name,
|
||||||
|
config: module.config as any,
|
||||||
|
}),
|
||||||
|
);
|
||||||
await this.buildModules();
|
await this.buildModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/** @jsxImportSource hono/jsx */
|
/** @jsxImportSource hono/jsx */
|
||||||
|
|
||||||
import type { App } from "App";
|
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 { addFlashMessage } from "core/server/flash";
|
||||||
import { html } from "hono/html";
|
import { html } from "hono/html";
|
||||||
import { Fragment } from "hono/jsx";
|
import { Fragment } from "hono/jsx";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Exception, isDebug, $console } from "core";
|
import { Exception, isDebug } from "core";
|
||||||
import { type Static, StringEnum } from "core/utils";
|
import { type Static, StringEnum, $console } from "core/utils";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { Module } from "modules/Module";
|
import { Module } from "modules/Module";
|
||||||
import * as tbbox from "@sinclair/typebox";
|
import * as tbbox from "@sinclair/typebox";
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
/// <reference types="@cloudflare/workers-types" />
|
/// <reference types="@cloudflare/workers-types" />
|
||||||
|
|
||||||
import type { App } from "App";
|
import type { App } from "App";
|
||||||
import { $console, tbValidator as tb } from "core";
|
|
||||||
import {
|
import {
|
||||||
StringEnum,
|
$console,
|
||||||
TypeInvalidError,
|
TypeInvalidError,
|
||||||
datetimeStringLocal,
|
datetimeStringLocal,
|
||||||
datetimeStringUTC,
|
datetimeStringUTC,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { Connection } from "./src/data/connection/Connection";
|
|||||||
import { __bknd } from "modules/ModuleManager";
|
import { __bknd } from "modules/ModuleManager";
|
||||||
import { nodeSqlite } from "./src/adapter/node/connection/NodeSqliteConnection";
|
import { nodeSqlite } from "./src/adapter/node/connection/NodeSqliteConnection";
|
||||||
import { libsql } from "./src/data/connection/sqlite/libsql/LibsqlConnection";
|
import { libsql } from "./src/data/connection/sqlite/libsql/LibsqlConnection";
|
||||||
import { $console } from "core";
|
import { $console } from "core/utils";
|
||||||
import { createClient } from "@libsql/client";
|
import { createClient } from "@libsql/client";
|
||||||
|
|
||||||
registries.media.register("local", StorageLocalAdapter);
|
registries.media.register("local", StorageLocalAdapter);
|
||||||
|
|||||||
Reference in New Issue
Block a user