refactor(biome): formats from biome

This commit is contained in:
2025-10-15 14:28:22 -05:00
parent 94e1198f63
commit 27fa45614e
4 changed files with 131 additions and 132 deletions

View File

@@ -1,42 +1,42 @@
import { import {
text, boolean,
pgTable, jsonb,
timestamp, pgTable,
uuid, text,
uniqueIndex, timestamp,
jsonb, uniqueIndex,
boolean, uuid,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod"; import { z } from "zod";
export const settings = pgTable( export const settings = pgTable(
"settings", "settings",
{ {
settings_id: uuid("settings_id").defaultRandom().primaryKey(), settings_id: uuid("settings_id").defaultRandom().primaryKey(),
name: text("name").notNull(), name: text("name").notNull(),
value: text("value").notNull(), // this is used in junction with active, only needed if the setting isnt a bool value: text("value").notNull(), // this is used in junction with active, only needed if the setting isnt a bool
description: text("description"), description: text("description"),
moduleName: text("moduleName"), // what part of lst dose it belong to this is used to split the settings out later moduleName: text("moduleName"), // what part of lst dose it belong to this is used to split the settings out later
active: boolean("active").default(true), active: boolean("active").default(true),
roles: jsonb("roles").notNull().default(["systemAdmin"]), // role or roles to see this goes along with the moduleName, need to have a x role in module to see this setting. roles: jsonb("roles").notNull().default(["systemAdmin"]), // role or roles to see this goes along with the moduleName, need to have a x role in module to see this setting.
add_User: text("add_User").default("LST_System").notNull(), add_User: text("add_User").default("LST_System").notNull(),
add_Date: timestamp("add_Date").defaultNow(), add_Date: timestamp("add_Date").defaultNow(),
upd_user: text("upd_User").default("LST_System").notNull(), upd_user: text("upd_User").default("LST_System").notNull(),
upd_date: timestamp("upd_date").defaultNow(), upd_date: timestamp("upd_date").defaultNow(),
}, },
(table) => [ (table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`), // uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("name").on(table.name), uniqueIndex("name").on(table.name),
] ],
); );
export const settingSchema = createSelectSchema(settings); export const settingSchema = createSelectSchema(settings);
export const newSettingSchema = createInsertSchema(settings, { export const newSettingSchema = createInsertSchema(settings, {
name: z.string().min(3, { name: z.string().min(3, {
message: "The name of the setting must be longer than 3 letters", message: "The name of the setting must be longer than 3 letters",
}), }),
}); });
export type Setting = z.infer<typeof settingSchema>; export type Setting = z.infer<typeof settingSchema>;

View File

@@ -1,42 +1,42 @@
import build from "pino-abstract-transport"; import build from "pino-abstract-transport";
import { db } from "../db/db.js"; import { db } from "../db/db.js";
import { logs, type Log } from "../db/schema/logs.js"; import { type Log, logs } from "../db/schema/logs.js";
import { tryCatch } from "../utils/tryCatch.js"; import { tryCatch } from "../utils/tryCatch.js";
const pinoLogLevels: any = { const pinoLogLevels: any = {
10: "trace", 10: "trace",
20: "debug", 20: "debug",
30: "info", 30: "info",
40: "warn", 40: "warn",
50: "error", 50: "error",
60: "fatal", 60: "fatal",
}; };
// Create a custom transport function // Create a custom transport function
export default async function (log: Log) { export default async function (log: Log) {
//const {username, service, level, msg, ...extra} = log; //const {username, service, level, msg, ...extra} = log;
try { try {
return build(async function (source) { return build(async (source) => {
for await (let obj of source) { for await (const obj of source) {
// convert to the name to make it more easy to find later :P // convert to the name to make it more easy to find later :P
const levelName = pinoLogLevels[obj.level] || "unknown"; const levelName = pinoLogLevels[obj.level] || "unknown";
const res = await tryCatch( const res = await tryCatch(
db.insert(logs).values({ db.insert(logs).values({
level: levelName, level: levelName,
module: obj?.module?.toLowerCase(), module: obj?.module?.toLowerCase(),
subModule: obj?.subModule?.toLowerCase(), subModule: obj?.subModule?.toLowerCase(),
hostname: obj?.hostname?.toLowerCase(), hostname: obj?.hostname?.toLowerCase(),
message: obj.msg, message: obj.msg,
stack: obj?.stack, stack: obj?.stack,
}) }),
); );
if (res.error) { if (res.error) {
console.log(res.error); console.log(res.error);
} }
} }
}); });
} catch (err) { } catch (err) {
console.error("Error inserting log into database:", err); console.error("Error inserting log into database:", err);
} }
} }

View File

@@ -1,48 +1,48 @@
import pino, { type Logger } from "pino"; import pino, { type Logger } from "pino";
export let logLevel = process.env.LOG_LEVEL || "info"; export const logLevel = process.env.LOG_LEVEL || "info";
const transport = pino.transport({ const transport = pino.transport({
targets: [ targets: [
{ {
target: "pino-pretty", target: "pino-pretty",
options: { options: {
colorize: true, colorize: true,
singleLine: true, singleLine: true,
// customPrettifiers: { // customPrettifiers: {
// time: (time) => `🕰 ${time}`, // time: (time) => `🕰 ${time}`,
// }, // },
destination: process.stdout.fd, destination: process.stdout.fd,
}, },
}, },
{ {
target: "./dbTransport.js", target: "./dbTransport.js",
}, },
{ {
target: "./notification.js", target: "./notification.js",
}, },
// Only log to Go if LST_USE_GO=true // Only log to Go if LST_USE_GO=true
...(process.env.LST_USE_GO === "true" ...(process.env.LST_USE_GO === "true"
? [ ? [
{ {
target: "./goTransport.js", // New transport for Go target: "./goTransport.js", // New transport for Go
}, },
] ]
: []), : []),
], ],
}); });
export const rootLogger: Logger = pino( export const rootLogger: Logger = pino(
{ {
level: logLevel, level: logLevel,
redact: { paths: ["email", "password"], remove: true }, redact: { paths: ["email", "password"], remove: true },
}, },
transport transport,
); );
/** /**
* factory to create child to log things for us * factory to create child to log things for us
*/ */
export function createLogger(bindings: Record<string, unknown>): Logger { export function createLogger(bindings: Record<string, unknown>): Logger {
return rootLogger.child(bindings); return rootLogger.child(bindings);
} }

View File

@@ -1,52 +1,51 @@
import build from "pino-abstract-transport"; import build from "pino-abstract-transport";
import { type Log } from "../db/schema/logs.js"; import type { Log } from "../db/schema/logs.js";
import { validateEnv } from "../utils/envValidator.js"; import { validateEnv } from "../utils/envValidator.js";
import { sendNotify } from "../utils/notify.js"; import { sendNotify } from "../utils/notify.js";
const env = validateEnv(process.env); const env = validateEnv(process.env);
const pinoLogLevels: any = { const pinoLogLevels: any = {
10: "trace", 10: "trace",
20: "debug", 20: "debug",
30: "info", 30: "info",
40: "warn", 40: "warn",
50: "error", 50: "error",
60: "fatal", 60: "fatal",
}; };
// discord function // discord function
export default async function (log: Log) { export default async function (log: Log) {
//const {username, service, level, msg, ...extra} = log; //const {username, service, level, msg, ...extra} = log;
try { try {
return build(async function (source) { return build(async (source) => {
for await (let obj of source) { for await (const obj of source) {
// convert to the name to make it more easy to find later :P // convert to the name to make it more easy to find later :P
const levelName = pinoLogLevels[obj.level] || "unknown"; const levelName = pinoLogLevels[obj.level] || "unknown";
const newlog = { const newlog = {
level: levelName, level: levelName,
module: obj.module module: obj.module ? String(obj.module).toLowerCase() : undefined,
? String(obj.module).toLowerCase() subModule: obj.subModule
: undefined, ? String(obj.subModule).toLowerCase()
subModule: obj.subModule : undefined,
? String(obj.subModule).toLowerCase() hostname: obj.hostname
: undefined, ? String(obj.hostname).toLowerCase()
hostname: obj.hostname : undefined,
? String(obj.hostname).toLowerCase() message: obj.msg,
: undefined, stack: obj.stack ? obj.stack : undefined,
message: obj.msg, };
stack: obj.stack ? obj.stack : undefined, if (!process.env.WEBHOOK_URL) {
}; console.log("WebHook is missing we wont move foward.");
if (!process.env.WEBHOOK_URL) { return;
console.log("WebHook is missing we wont move foward."); }
return;
}
if (obj.level >= 60 && obj.notify) { if (obj.level >= 60 && obj.notify) {
sendNotify(newlog as Log); sendNotify(newlog as Log);
} }
} }
}); });
} catch (err) { } catch (err) {
console.error("Error inserting log into database:", err); console.error("Error inserting log into database:", err);
} }
} }