mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 08:36:01 +00:00
cleanup: replace console.log/warn with $console, remove commented-out code
Removed various commented-out code and replaced direct `console.log` and `console.warn` usage across the codebase with `$console` from "core" for standardized logging. Also adjusted linting rules in biome.json to enable warnings for `console.log` usage.
This commit is contained in:
@@ -29,7 +29,6 @@ export class AwsClient extends Aws4fetchClient {
|
||||
}
|
||||
|
||||
getUrl(path: string = "/", searchParamsObj: Record<string, any> = {}): string {
|
||||
//console.log("super:getUrl", path, searchParamsObj);
|
||||
const url = new URL(path);
|
||||
const converted = this.convertParams(searchParamsObj);
|
||||
Object.entries(converted).forEach(([key, value]) => {
|
||||
@@ -76,8 +75,6 @@ export class AwsClient extends Aws4fetchClient {
|
||||
}
|
||||
|
||||
const raw = await response.text();
|
||||
//console.log("raw", raw);
|
||||
//console.log(JSON.stringify(xmlToObject(raw), null, 2));
|
||||
return xmlToObject(raw) as T;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type Event, type EventClass, InvalidEventReturn } from "./Event";
|
||||
import { EventListener, type ListenerHandler, type ListenerMode } from "./EventListener";
|
||||
import { $console } from "core";
|
||||
|
||||
export type RegisterListenerConfig =
|
||||
| ListenerMode
|
||||
@@ -83,10 +84,6 @@ export class EventManager<
|
||||
} else {
|
||||
// @ts-expect-error
|
||||
slug = eventOrSlug.constructor?.slug ?? eventOrSlug.slug;
|
||||
/*eventOrSlug instanceof Event
|
||||
? // @ts-expect-error slug is static
|
||||
eventOrSlug.constructor.slug
|
||||
: eventOrSlug.slug;*/
|
||||
}
|
||||
|
||||
return !!this.events.find((e) => slug === e.slug);
|
||||
@@ -128,8 +125,7 @@ export class EventManager<
|
||||
if (listener.id) {
|
||||
const existing = this.listeners.find((l) => l.id === listener.id);
|
||||
if (existing) {
|
||||
// @todo: add a verbose option?
|
||||
//console.warn(`Listener with id "${listener.id}" already exists.`);
|
||||
$console.debug(`Listener with id "${listener.id}" already exists.`);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -191,7 +187,7 @@ export class EventManager<
|
||||
// @ts-expect-error slug is static
|
||||
const slug = event.constructor.slug;
|
||||
if (!this.enabled) {
|
||||
console.log("EventManager disabled, not emitting", slug);
|
||||
$console.debug("EventManager disabled, not emitting", slug);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -240,7 +236,7 @@ export class EventManager<
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidEventReturn) {
|
||||
this.options?.onInvalidReturn?.(_event, e);
|
||||
console.warn(`Invalid return of event listener for "${slug}": ${e.message}`);
|
||||
$console.warn(`Invalid return of event listener for "${slug}": ${e.message}`);
|
||||
} else if (this.options?.onError) {
|
||||
this.options.onError(_event, e);
|
||||
} else {
|
||||
|
||||
@@ -73,6 +73,7 @@ export class SchemaObject<Schema extends TObject> {
|
||||
forceParse: true,
|
||||
skipMark: this.isForceParse(),
|
||||
});
|
||||
|
||||
// regardless of "noEmit" – this should always be triggered
|
||||
const updatedConfig = await this.onBeforeUpdate(this._config, valid);
|
||||
|
||||
@@ -122,19 +123,15 @@ export class SchemaObject<Schema extends TObject> {
|
||||
const partial = path.length > 0 ? (set({}, path, value) as Partial<Static<Schema>>) : value;
|
||||
|
||||
this.throwIfRestricted(partial);
|
||||
//console.log(getFullPathKeys(value).map((k) => path + "." + k));
|
||||
|
||||
// overwrite arrays and primitives, only deep merge objects
|
||||
// @ts-ignore
|
||||
//console.log("---alt:new", _jsonp(mergeObject(current, partial)));
|
||||
const config = mergeObjectWith(current, partial, (objValue, srcValue) => {
|
||||
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
|
||||
return srcValue;
|
||||
}
|
||||
});
|
||||
//console.log("---new", _jsonp(config));
|
||||
|
||||
//console.log("overwritePaths", this.options?.overwritePaths);
|
||||
if (this.options?.overwritePaths) {
|
||||
const keys = getFullPathKeys(value).map((k) => {
|
||||
// only prepend path if given
|
||||
@@ -149,7 +146,6 @@ export class SchemaObject<Schema extends TObject> {
|
||||
}
|
||||
});
|
||||
});
|
||||
//console.log("overwritePaths", keys, overwritePaths);
|
||||
|
||||
if (overwritePaths.length > 0) {
|
||||
// filter out less specific paths (but only if more than 1)
|
||||
@@ -157,12 +153,10 @@ export class SchemaObject<Schema extends TObject> {
|
||||
overwritePaths.length > 1
|
||||
? overwritePaths.filter((k) =>
|
||||
overwritePaths.some((k2) => {
|
||||
//console.log("keep?", { k, k2 }, k2 !== k && k2.startsWith(k));
|
||||
return k2 !== k && k2.startsWith(k);
|
||||
}),
|
||||
)
|
||||
: overwritePaths;
|
||||
//console.log("specific", specific);
|
||||
|
||||
for (const p of specific) {
|
||||
set(config, p, get(partial, p));
|
||||
@@ -170,8 +164,6 @@ export class SchemaObject<Schema extends TObject> {
|
||||
}
|
||||
}
|
||||
|
||||
//console.log("patch", _jsonp({ path, value, partial, config, current }));
|
||||
|
||||
const newConfig = await this.set(config);
|
||||
return [partial, newConfig];
|
||||
}
|
||||
@@ -181,14 +173,11 @@ export class SchemaObject<Schema extends TObject> {
|
||||
const partial = path.length > 0 ? (set({}, path, value) as Partial<Static<Schema>>) : value;
|
||||
|
||||
this.throwIfRestricted(partial);
|
||||
//console.log(getFullPathKeys(value).map((k) => path + "." + k));
|
||||
|
||||
// overwrite arrays and primitives, only deep merge objects
|
||||
// @ts-ignore
|
||||
const config = set(current, path, value);
|
||||
|
||||
//console.log("overwrite", { path, value, partial, config, current });
|
||||
|
||||
const newConfig = await this.set(config);
|
||||
return [partial, newConfig];
|
||||
}
|
||||
@@ -198,7 +187,6 @@ export class SchemaObject<Schema extends TObject> {
|
||||
if (p.length > 1) {
|
||||
const parent = p.slice(0, -1).join(".");
|
||||
if (!has(this._config, parent)) {
|
||||
//console.log("parent", parent, JSON.stringify(this._config, null, 2));
|
||||
throw new Error(`Parent path "${parent}" does not exist`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ export class SimpleRenderer {
|
||||
}
|
||||
|
||||
static hasMarkup(template: string | object): boolean {
|
||||
//console.log("has markup?", template);
|
||||
let flat: string = "";
|
||||
|
||||
if (Array.isArray(template) || typeof template === "object") {
|
||||
@@ -34,12 +33,8 @@ export class SimpleRenderer {
|
||||
flat = String(template);
|
||||
}
|
||||
|
||||
//console.log("** flat", flat);
|
||||
|
||||
const checks = ["{{", "{%", "{#", "{:"];
|
||||
const hasMarkup = checks.some((check) => flat.includes(check));
|
||||
//console.log("--has markup?", hasMarkup);
|
||||
return hasMarkup;
|
||||
return checks.some((check) => flat.includes(check));
|
||||
}
|
||||
|
||||
async render<Given extends TemplateTypes>(template: Given): Promise<Given> {
|
||||
@@ -75,7 +70,6 @@ export class SimpleRenderer {
|
||||
}
|
||||
|
||||
async renderString(template: string): Promise<string> {
|
||||
//console.log("*** renderString", template, this.variables);
|
||||
return this.engine.parseAndRender(template, this.variables, this.options);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,11 @@ export class DebugLogger {
|
||||
}
|
||||
|
||||
context(context: string) {
|
||||
//console.log("[ settings context ]", context, this._context);
|
||||
this._context.push(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
//console.log("[ clear context ]", this._context.pop(), this._context);
|
||||
this._context.pop();
|
||||
return this;
|
||||
}
|
||||
@@ -33,6 +31,8 @@ export class DebugLogger {
|
||||
const indents = " ".repeat(Math.max(this._context.length - 1, 0));
|
||||
const context =
|
||||
this._context.length > 0 ? `[${this._context[this._context.length - 1]}]` : "";
|
||||
|
||||
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
||||
console.log(indents, context, time, ...args);
|
||||
|
||||
this.last = now;
|
||||
|
||||
@@ -4,7 +4,6 @@ import weekOfYear from "dayjs/plugin/weekOfYear.js";
|
||||
declare module "dayjs" {
|
||||
interface Dayjs {
|
||||
week(): number;
|
||||
|
||||
week(value: number): dayjs.Dayjs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { extension, guess, isMimeType } from "media/storage/mime-types-tiny";
|
||||
import { randomString } from "core/utils/strings";
|
||||
import type { Context } from "hono";
|
||||
import { invariant } from "core/utils/runtime";
|
||||
import { $console } from "../console";
|
||||
|
||||
export function getContentName(request: Request): string | undefined;
|
||||
export function getContentName(contentDisposition: string): string | undefined;
|
||||
@@ -130,7 +131,7 @@ export async function getFileFromContext(c: Context<any>): Promise<File> {
|
||||
return await blobToFile(v);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error parsing form data", e);
|
||||
$console.warn("Error parsing form data", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@@ -141,7 +142,7 @@ export async function getFileFromContext(c: Context<any>): Promise<File> {
|
||||
return await blobToFile(blob, { name: getContentName(c.req.raw), type: contentType });
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error parsing blob", e);
|
||||
$console.warn("Error parsing blob", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import { randomString } from "core/utils/strings";
|
||||
import type { Context } from "hono";
|
||||
import { extension, guess, isMimeType } from "media/storage/mime-types-tiny";
|
||||
|
||||
export function headersToObject(headers: Headers): Record<string, string> {
|
||||
if (!headers) return {};
|
||||
return { ...Object.fromEntries(headers.entries()) };
|
||||
|
||||
@@ -114,7 +114,6 @@ export function parse<Schema extends TSchema = TSchema>(
|
||||
} else if (options?.onError) {
|
||||
options.onError(Errors(schema, data));
|
||||
} else {
|
||||
//console.warn("errors", JSON.stringify([...Errors(schema, data)], null, 2));
|
||||
throw new TypeInvalidError(schema, data);
|
||||
}
|
||||
|
||||
@@ -126,13 +125,11 @@ export function parseDecode<Schema extends TSchema = TSchema>(
|
||||
schema: Schema,
|
||||
data: RecursivePartial<StaticDecode<Schema>>,
|
||||
): StaticDecode<Schema> {
|
||||
//console.log("parseDecode", schema, data);
|
||||
const parsed = Default(schema, data);
|
||||
|
||||
if (Check(schema, parsed)) {
|
||||
return parsed as StaticDecode<typeof schema>;
|
||||
}
|
||||
//console.log("errors", ...Errors(schema, data));
|
||||
|
||||
throw new TypeInvalidError(schema, data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user