added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions

View File

@@ -23,7 +23,7 @@ export type AdminControllerOptions = {
export class AdminController extends Controller {
constructor(
private readonly app: App,
private _options: AdminControllerOptions = {}
private _options: AdminControllerOptions = {},
) {
super();
}
@@ -36,7 +36,7 @@ export class AdminController extends Controller {
return {
...this._options,
basepath: this._options.basepath ?? "/",
assets_path: this._options.assets_path ?? config.server.assets_path
assets_path: this._options.assets_path ?? config.server.assets_path,
};
}
@@ -53,7 +53,7 @@ export class AdminController extends Controller {
const hono = this.create().use(
authMiddleware({
//skip: [/favicon\.ico$/]
})
}),
);
const auth = this.app.module.auth;
@@ -66,14 +66,14 @@ export class AdminController extends Controller {
success: configs.auth.cookie.pathSuccess ?? "/",
loggedOut: configs.auth.cookie.pathLoggedOut ?? "/",
login: "/auth/login",
logout: "/auth/logout"
logout: "/auth/logout",
};
hono.use("*", async (c, next) => {
const obj = {
user: c.get("auth")?.user,
logout_route: this.withBasePath(authRoutes.logout),
color_scheme: configs.server.admin.color_scheme
color_scheme: configs.server.admin.color_scheme,
};
const html = await this.getHtml(obj);
if (!html) {
@@ -97,11 +97,11 @@ export class AdminController extends Controller {
console.log("redirecting to success");
return c.redirect(authRoutes.success);
}
}
},
}),
async (c) => {
return c.html(c.get("html")!);
}
},
);
hono.get(authRoutes.logout, async (c) => {
@@ -119,16 +119,16 @@ export class AdminController extends Controller {
console.log("redirecting");
return c.redirect(authRoutes.login);
}
},
}),
permission(SystemPermissions.schemaRead, {
onDenied: async (c) => {
addFlashMessage(c, "You not allowed to read the schema", "warning");
}
},
}),
async (c) => {
return c.html(c.get("html")!);
}
},
);
return hono;
@@ -141,12 +141,12 @@ export class AdminController extends Controller {
if (this.options.html.includes(htmlBkndContextReplace)) {
return this.options.html.replace(
htmlBkndContextReplace,
"<script>" + bknd_context + "</script>"
"<script>" + bknd_context + "</script>",
);
}
console.warn(
`Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`
`Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`,
);
return this.options.html as string;
}
@@ -160,13 +160,13 @@ export class AdminController extends Controller {
const assets = {
js: "main.js",
css: "styles.css"
css: "styles.css",
};
if (isProd) {
// @ts-ignore
const manifest = await import("bknd/dist/manifest.json", {
assert: { type: "json" }
assert: { type: "json" },
});
// @todo: load all marked as entry (incl. css)
assets.js = manifest.default["src/ui/main.tsx"].file;
@@ -217,7 +217,7 @@ export class AdminController extends Controller {
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true`
window.__vite_plugin_react_preamble_installed__ = true`,
}}
/>
<script type="module" src={"/@vite/client"} />
@@ -235,7 +235,7 @@ export class AdminController extends Controller {
</div>
<script
dangerouslySetInnerHTML={{
__html: bknd_context
__html: bknd_context,
}}
/>
{!isProd && <script type="module" src={mainPath} />}
@@ -256,21 +256,21 @@ const style = (theme: AppTheme) => {
justifyContent: "center",
alignItems: "center",
"-webkit-font-smoothing": "antialiased",
"-moz-osx-font-smoothing": "grayscale"
"-moz-osx-font-smoothing": "grayscale",
};
const styles = {
light: {
color: "rgb(9,9,11)",
backgroundColor: "rgb(250,250,250)"
backgroundColor: "rgb(250,250,250)",
},
dark: {
color: "rgb(250,250,250)",
backgroundColor: "rgb(30,31,34)"
}
backgroundColor: "rgb(30,31,34)",
},
};
return {
...base,
...styles[theme === "light" ? "light" : "dark"]
...styles[theme === "light" ? "light" : "dark"],
};
};

View File

@@ -16,29 +16,29 @@ export const serverConfigSchema = Type.Object(
logo_return_path: Type.Optional(
Type.String({
default: "/",
description: "Path to return to after *clicking* the logo"
})
)
description: "Path to return to after *clicking* the logo",
}),
),
},
{ default: {}, additionalProperties: false }
{ default: {}, additionalProperties: false },
),
cors: Type.Object(
{
origin: Type.String({ default: "*" }),
allow_methods: Type.Array(StringEnum(serverMethods), {
default: serverMethods,
uniqueItems: true
uniqueItems: true,
}),
allow_headers: Type.Array(Type.String(), {
default: ["Content-Type", "Content-Length", "Authorization", "Accept"]
})
default: ["Content-Type", "Content-Length", "Authorization", "Accept"],
}),
},
{ default: {}, additionalProperties: false }
)
{ default: {}, additionalProperties: false },
),
},
{
additionalProperties: false
}
additionalProperties: false,
},
);
export type AppServerConfig = Static<typeof serverConfigSchema>;
@@ -70,8 +70,8 @@ export class AppServer extends Module<typeof serverConfigSchema> {
cors({
origin: this.config.cors.origin,
allowMethods: this.config.cors.allow_methods,
allowHeaders: this.config.cors.allow_headers
})
allowHeaders: this.config.cors.allow_headers,
}),
);
// add an initial fallback route
@@ -83,7 +83,7 @@ export class AppServer extends Module<typeof serverConfigSchema> {
if (new URL(c.req.url).pathname === "/") {
c.res = undefined;
c.res = Response.json({
bknd: "hello world!"
bknd: "hello world!",
});
}
}

View File

@@ -9,7 +9,7 @@ import {
datetimeStringLocal,
datetimeStringUTC,
getTimezone,
getTimezoneOffset
getTimezoneOffset,
} from "core/utils";
import { getRuntimeKey } from "core/utils";
import type { Context, Hono } from "hono";
@@ -19,7 +19,7 @@ import {
MODULE_NAMES,
type ModuleConfigs,
type ModuleKey,
getDefaultConfig
getDefaultConfig,
} from "modules/ModuleManager";
import * as SystemPermissions from "modules/permissions";
import { generateOpenAPI } from "modules/server/openapi";
@@ -64,8 +64,8 @@ export class SystemController extends Controller {
tb(
"query",
Type.Object({
secrets: Type.Optional(booleanLike)
})
secrets: Type.Optional(booleanLike),
}),
),
async (c) => {
// @todo: allow secrets if authenticated user is admin
@@ -81,11 +81,11 @@ export class SystemController extends Controller {
? {
version: this.app.version(),
module,
config: config[module]
config: config[module],
}
: config
: config,
);
}
},
);
async function handleConfigUpdateResponse(c: Context<any>, cb: () => Promise<ConfigUpdate>) {
@@ -97,7 +97,7 @@ export class SystemController extends Controller {
if (e instanceof TypeInvalidError) {
return c.json(
{ success: false, type: "type-invalid", errors: e.errors },
{ status: 400 }
{ status: 400 },
);
}
if (e instanceof Error) {
@@ -114,8 +114,8 @@ export class SystemController extends Controller {
tb(
"query",
Type.Object({
force: Type.Optional(booleanLike)
})
force: Type.Optional(booleanLike),
}),
),
async (c) => {
const module = c.req.param("module") as any;
@@ -129,7 +129,7 @@ export class SystemController extends Controller {
// force overwrite defined keys
const newConfig = {
...this.app.module[module].config,
...value
...value,
};
await this.app.mutateConfig(module).set(newConfig);
} else {
@@ -138,10 +138,10 @@ export class SystemController extends Controller {
return {
success: true,
module,
config: this.app.module[module].config
config: this.app.module[module].config,
};
});
}
},
);
hono.post("/add/:module/:path", permission(SystemPermissions.configWrite), async (c) => {
@@ -160,7 +160,7 @@ export class SystemController extends Controller {
return {
success: true,
module,
config: this.app.module[module].config
config: this.app.module[module].config,
};
});
});
@@ -176,7 +176,7 @@ export class SystemController extends Controller {
return {
success: true,
module,
config: this.app.module[module].config
config: this.app.module[module].config,
};
});
});
@@ -192,7 +192,7 @@ export class SystemController extends Controller {
return {
success: true,
module,
config: this.app.module[module].config
config: this.app.module[module].config,
};
});
});
@@ -207,7 +207,7 @@ export class SystemController extends Controller {
return {
success: true,
module,
config: this.app.module[module].config
config: this.app.module[module].config,
};
});
});
@@ -228,8 +228,8 @@ export class SystemController extends Controller {
"query",
Type.Object({
config: Type.Optional(booleanLike),
secrets: Type.Optional(booleanLike)
})
secrets: Type.Optional(booleanLike),
}),
),
async (c) => {
const module = c.req.param("module") as ModuleKey | undefined;
@@ -245,7 +245,7 @@ export class SystemController extends Controller {
module,
version,
schema: schema[module],
config: config ? this.app.module[module].toJSON(secrets) : undefined
config: config ? this.app.module[module].toJSON(secrets) : undefined,
});
}
@@ -254,9 +254,9 @@ export class SystemController extends Controller {
version,
schema,
config: config ? this.app.toJSON(secrets) : undefined,
permissions: this.app.modules.ctx().guard.getPermissionNames()
permissions: this.app.modules.ctx().guard.getPermissionNames(),
});
}
},
);
hono.post(
@@ -264,8 +264,8 @@ export class SystemController extends Controller {
tb(
"query",
Type.Object({
sync: Type.Optional(booleanLike)
})
sync: Type.Optional(booleanLike),
}),
),
async (c) => {
const { sync } = c.req.valid("query") as Record<string, boolean>;
@@ -273,7 +273,7 @@ export class SystemController extends Controller {
await this.app.build({ sync });
return c.json({ success: true, options: { sync } });
}
},
);
hono.get("/ping", (c) => c.json({ pong: true }));
@@ -286,9 +286,9 @@ export class SystemController extends Controller {
name: getTimezone(),
offset: getTimezoneOffset(),
local: datetimeStringLocal(),
utc: datetimeStringUTC()
}
})
utc: datetimeStringUTC(),
},
}),
);
hono.get("/openapi.json", async (c) => {

View File

@@ -22,14 +22,14 @@ function systemRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
content: {
"application/json": {
schema: Type.Object({
pong: Type.Boolean({ default: true })
})
}
}
}
pong: Type.Boolean({ default: true }),
}),
},
},
},
},
tags
}
tags,
},
},
"/config": {
get: {
@@ -45,14 +45,14 @@ function systemRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
data: Type.Object({}),
auth: Type.Object({}),
flows: Type.Object({}),
media: Type.Object({})
})
}
}
}
media: Type.Object({}),
}),
},
},
},
},
tags
}
tags,
},
},
"/schema": {
get: {
@@ -69,16 +69,16 @@ function systemRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
data: Type.Object({}),
auth: Type.Object({}),
flows: Type.Object({}),
media: Type.Object({})
})
})
}
}
}
media: Type.Object({}),
}),
}),
},
},
},
},
tags
}
}
tags,
},
},
};
return { paths: prefixPaths(paths, "/api/system") };
@@ -87,42 +87,42 @@ function systemRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
function dataRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
const schemas = {
entityData: Type.Object({
id: Type.Number() as any
})
id: Type.Number() as any,
}),
};
const repoManyResponses: OAS.ResponsesObject = {
"200": {
description: "List of entities",
content: {
"application/json": {
schema: Type.Array(schemas.entityData)
}
}
}
schema: Type.Array(schemas.entityData),
},
},
},
};
const repoSingleResponses: OAS.ResponsesObject = {
"200": {
description: "Entity",
content: {
"application/json": {
schema: schemas.entityData
}
}
}
schema: schemas.entityData,
},
},
},
};
const params = {
entity: {
name: "entity",
in: "path",
required: true,
schema: Type.String()
schema: Type.String(),
},
entityId: {
name: "id",
in: "path",
required: true,
schema: Type.Number() as any
}
schema: Type.Number() as any,
},
};
const tags = ["data"];
@@ -132,7 +132,7 @@ function dataRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
summary: "List entities",
parameters: [params.entity],
responses: repoManyResponses,
tags
tags,
},
post: {
summary: "Create entity",
@@ -140,20 +140,20 @@ function dataRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
requestBody: {
content: {
"application/json": {
schema: Type.Object({})
}
}
schema: Type.Object({}),
},
},
},
responses: repoSingleResponses,
tags
}
tags,
},
},
"/entity/{entity}/{id}": {
get: {
summary: "Get entity",
parameters: [params.entity, params.entityId],
responses: repoSingleResponses,
tags
tags,
},
patch: {
summary: "Update entity",
@@ -161,24 +161,24 @@ function dataRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
requestBody: {
content: {
"application/json": {
schema: Type.Object({})
}
}
schema: Type.Object({}),
},
},
},
responses: repoSingleResponses,
tags
tags,
},
delete: {
summary: "Delete entity",
parameters: [params.entity, params.entityId],
responses: {
"200": {
description: "Entity deleted"
}
description: "Entity deleted",
},
},
tags
}
}
tags,
},
},
};
return { paths: prefixPaths(paths, config.data.basepath!) };
@@ -189,8 +189,8 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
user: Type.Object({
id: Type.String(),
email: Type.String(),
name: Type.String()
})
name: Type.String(),
}),
};
const tags = ["auth"];
@@ -203,10 +203,10 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
"application/json": {
schema: Type.Object({
email: Type.String(),
password: Type.String()
})
}
}
password: Type.String(),
}),
},
},
},
responses: {
"200": {
@@ -214,14 +214,14 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
content: {
"application/json": {
schema: Type.Object({
user: schemas.user
})
}
}
}
user: schemas.user,
}),
},
},
},
},
tags
}
tags,
},
},
"/password/register": {
post: {
@@ -231,10 +231,10 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
"application/json": {
schema: Type.Object({
email: Type.String(),
password: Type.String()
})
}
}
password: Type.String(),
}),
},
},
},
responses: {
"200": {
@@ -242,14 +242,14 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
content: {
"application/json": {
schema: Type.Object({
user: schemas.user
})
}
}
}
user: schemas.user,
}),
},
},
},
},
tags
}
tags,
},
},
"/me": {
get: {
@@ -260,14 +260,14 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
content: {
"application/json": {
schema: Type.Object({
user: schemas.user
})
}
}
}
user: schemas.user,
}),
},
},
},
},
tags
}
tags,
},
},
"/strategies": {
get: {
@@ -278,15 +278,15 @@ function authRoutes(config: ModuleConfigs): { paths: OAS.Document["paths"] } {
content: {
"application/json": {
schema: Type.Object({
strategies: Type.Object({})
})
}
}
}
strategies: Type.Object({}),
}),
},
},
},
},
tags
}
}
tags,
},
},
};
return { paths: prefixPaths(paths, config.auth.basepath!) };
@@ -301,12 +301,12 @@ export function generateOpenAPI(config: ModuleConfigs): OAS.Document {
openapi: "3.1.0",
info: {
title: "bknd API",
version: "0.0.0"
version: "0.0.0",
},
paths: {
...system.paths,
...data.paths,
...auth.paths
}
...auth.paths,
},
};
}