merged origin/release/0.12

This commit is contained in:
dswbx
2025-04-11 13:10:25 +02:00
79 changed files with 177 additions and 544 deletions
+3 -4
View File
@@ -1,4 +1,4 @@
import type { PrimaryFieldType } from "core";
import { $console, type PrimaryFieldType } from "core";
import { isDebug } from "core/env";
import { encodeSearch } from "core/utils/reqres";
@@ -87,7 +87,6 @@ export abstract class ModuleApi<Options extends BaseModuleApiOptions = BaseModul
// only add token if initial headers not provided
if (this.options.token && this.options.token_transport === "header") {
//console.log("setting token", this.options.token);
headers.set("Authorization", `Bearer ${this.options.token}`);
}
@@ -245,7 +244,7 @@ export class FetchPromise<T = ApiResponse<any>> implements Promise<T> {
const fetcher = this.options?.fetcher ?? fetch;
if (this.verbose) {
console.log("[FetchPromise] Request", {
$console.debug("[FetchPromise] Request", {
method: this.request.method,
url: this.request.url,
});
@@ -253,7 +252,7 @@ export class FetchPromise<T = ApiResponse<any>> implements Promise<T> {
const res = await fetcher(this.request);
if (this.verbose) {
console.log("[FetchPromise] Response", {
$console.debug("[FetchPromise] Response", {
res: res,
ok: res.ok,
status: res.status,
+3 -3
View File
@@ -561,7 +561,7 @@ export class ModuleManager {
}
return async (...args) => {
console.log("[Safe Mutate]", name);
$console.log("[Safe Mutate]", name);
try {
// overwrite listener to run build inside this try/catch
module.setListener(async () => {
@@ -583,12 +583,12 @@ export class ModuleManager {
return result;
} catch (e) {
console.error("[Safe Mutate] failed", e);
$console.error("[Safe Mutate] failed", e);
// revert to previous config & rebuild using original listener
this.setConfigs(copy);
await this.onModuleConfigUpdated(name, module.config as any);
console.log("[Safe Mutate] reverted");
$console.warn("[Safe Mutate] reverted");
// make sure to throw the error
throw e;
-1
View File
@@ -1 +0,0 @@
export { auth, permission } from "auth/middlewares";
+2 -9
View File
@@ -1,7 +1,6 @@
import { _jsonp, transformObject } from "core/utils";
import { type Kysely, sql } from "kysely";
import { transformObject } from "core/utils";
import type { Kysely } from "kysely";
import { set } from "lodash-es";
import type { InitialModuleConfigs } from "modules/ModuleManager";
export type MigrationContext = {
db: Kysely<any>;
@@ -17,7 +16,6 @@ export type Migration = {
export const migrations: Migration[] = [
{
version: 1,
//schema: true,
up: async (config) => config,
},
{
@@ -28,7 +26,6 @@ export const migrations: Migration[] = [
},
{
version: 3,
//schema: true,
up: async (config) => config,
},
{
@@ -46,7 +43,6 @@ export const migrations: Migration[] = [
{
version: 5,
up: async (config, { db }) => {
//console.log("config", _jsonp(config));
const cors = config.server.cors?.allow_methods ?? [];
set(config.server, "cors.allow_methods", [...new Set([...cors, "PATCH"])]);
return config;
@@ -114,15 +110,12 @@ export async function migrateTo(
config: GenericConfigObject,
ctx: MigrationContext,
): Promise<[number, GenericConfigObject]> {
//console.log("migrating from", current, "to", CURRENT_VERSION, config);
const todo = migrations.filter((m) => m.version > current && m.version <= to);
//console.log("todo", todo.length);
let updated = Object.assign({}, config);
let i = 0;
let version = current;
for (const migration of todo) {
//console.log("-- running migration", i + 1, "of", todo.length, { version: migration.version });
try {
updated = await migration.up(updated, ctx);
version = migration.version;
+4 -4
View File
@@ -1,7 +1,7 @@
/** @jsxImportSource hono/jsx */
import type { App } from "App";
import { config, isDebug } from "core";
import { $console, config, isDebug } from "core";
import { addFlashMessage } from "core/server/flash";
import { html } from "hono/html";
import { Fragment } from "hono/jsx";
@@ -99,7 +99,7 @@ export class AdminController extends Controller {
onGranted: async (c) => {
// @todo: add strict test to permissions middleware?
if (c.get("auth")?.user) {
console.log("redirecting to success");
$console.log("redirecting to success");
return c.redirect(authRoutes.success);
}
},
@@ -122,7 +122,7 @@ export class AdminController extends Controller {
onDenied: async (c) => {
addFlashMessage(c, "You are not authorized to access the Admin UI", "error");
console.log("redirecting");
$console.log("redirecting");
return c.redirect(authRoutes.login);
},
}),
@@ -150,7 +150,7 @@ export class AdminController extends Controller {
);
}
console.warn(
$console.warn(
`Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`,
);
return this.options.html as string;
+2 -5
View File
@@ -1,4 +1,4 @@
import { Exception, isDebug } from "core";
import { Exception, isDebug, $console } from "core";
import { type Static, StringEnum } from "core/utils";
import { cors } from "hono/cors";
import { Module } from "modules/Module";
@@ -31,8 +31,6 @@ export const serverConfigSchema = Type.Object(
export type AppServerConfig = Static<typeof serverConfigSchema>;
export class AppServer extends Module<typeof serverConfigSchema> {
//private admin_html?: string;
override getRestrictedPaths() {
return [];
}
@@ -72,14 +70,13 @@ export class AppServer extends Module<typeof serverConfigSchema> {
this.client.onError((err, c) => {
//throw err;
console.error(err);
$console.error(err);
if (err instanceof Response) {
return err;
}
if (err instanceof Exception) {
console.log("---is exception", err.code);
return c.json(err.toJSON(), err.code as any);
}
+1 -2
View File
@@ -100,7 +100,7 @@ export class SystemController extends Controller {
try {
return c.json(await cb(), { status: 202 });
} catch (e) {
console.error(e);
$console.error("config update error", e);
if (e instanceof TypeInvalidError) {
return c.json(
@@ -161,7 +161,6 @@ export class SystemController extends Controller {
if (this.app.modules.get(module).schema().has(path)) {
return c.json({ success: false, path, error: "Path already exists" }, { status: 400 });
}
console.log("-- add", module, path, value);
return await handleConfigUpdateResponse(c, async () => {
await this.app.mutateConfig(module).patch(path, value);