From 0c4bdf8ca4604a52dedce1f0745373cb05498178 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:58:00 +0100 Subject: [PATCH] chore: remove dist --- .gitignore | 1 + dist/logs.d.ts | 21 -- dist/logs.js | 351 --------------------------------- dist/logs.js.map | 1 - dist/pretty-logs-TeMdXxew.d.ts | 47 ----- dist/pretty-logs.d.ts | 1 - dist/pretty-logs.js | 154 --------------- dist/pretty-logs.js.map | 1 - 8 files changed, 1 insertion(+), 576 deletions(-) delete mode 100644 dist/logs.d.ts delete mode 100644 dist/logs.js delete mode 100644 dist/logs.js.map delete mode 100644 dist/pretty-logs-TeMdXxew.d.ts delete mode 100644 dist/pretty-logs.d.ts delete mode 100644 dist/pretty-logs.js delete mode 100644 dist/pretty-logs.js.map diff --git a/.gitignore b/.gitignore index 6dab845..027622f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ static/dist .env # vscode .vscode +/dist \ No newline at end of file diff --git a/dist/logs.d.ts b/dist/logs.d.ts deleted file mode 100644 index d8bc1c3..0000000 --- a/dist/logs.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { P as PrettyLogs, M as Metadata, L as LogReturn, a as LogLevel } from './pretty-logs-TeMdXxew.js'; - -declare class Logs { - private _maxLevel; - static console: PrettyLogs; - private _log; - private _addDiagnosticInformation; - ok(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - info(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - error(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - debug(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - fatal(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - verbose(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null; - constructor(logLevel: LogLevel); - static _commentMetaData(metadata: Metadata, level: LogLevel): string; - private _diffColorCommentMessage; - private _getNumericLevel; - static convertErrorsIntoObjects(obj: unknown): Metadata | unknown; -} - -export { Logs }; diff --git a/dist/logs.js b/dist/logs.js deleted file mode 100644 index aac37f3..0000000 --- a/dist/logs.js +++ /dev/null @@ -1,351 +0,0 @@ -// src/supabase/helpers/tables/pretty-logs.ts -import util from "util"; - -// src/supabase/constants.ts -var COLORS = { - reset: "\x1B[0m", - bright: "\x1B[1m", - dim: "\x1B[2m", - underscore: "\x1B[4m", - blink: "\x1B[5m", - reverse: "\x1B[7m", - hidden: "\x1B[8m", - fgBlack: "\x1B[30m", - fgRed: "\x1B[31m", - fgGreen: "\x1B[32m", - fgYellow: "\x1B[33m", - fgBlue: "\x1B[34m", - fgMagenta: "\x1B[35m", - fgCyan: "\x1B[36m", - fgWhite: "\x1B[37m", - bgBlack: "\x1B[40m", - bgRed: "\x1B[41m", - bgGreen: "\x1B[42m", - bgYellow: "\x1B[43m", - bgBlue: "\x1B[44m", - bgMagenta: "\x1B[45m", - bgCyan: "\x1B[46m", - bgWhite: "\x1B[47m" -}; -var LOG_LEVEL = { - FATAL: "fatal", - ERROR: "error", - INFO: "info", - VERBOSE: "verbose", - DEBUG: "debug" -}; - -// src/supabase/helpers/tables/pretty-logs.ts -var PrettyLogs = class { - constructor() { - this.ok = this.ok.bind(this); - this.info = this.info.bind(this); - this.error = this.error.bind(this); - this.fatal = this.fatal.bind(this); - this.debug = this.debug.bind(this); - this.verbose = this.verbose.bind(this); - } - fatal(message, metadata) { - this._logWithStack(LOG_LEVEL.FATAL, message, metadata); - } - error(message, metadata) { - this._logWithStack(LOG_LEVEL.ERROR, message, metadata); - } - ok(message, metadata) { - this._logWithStack("ok", message, metadata); - } - info(message, metadata) { - this._logWithStack(LOG_LEVEL.INFO, message, metadata); - } - debug(message, metadata) { - this._logWithStack(LOG_LEVEL.DEBUG, message, metadata); - } - verbose(message, metadata) { - this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata); - } - _logWithStack(type, message, metaData) { - this._log(type, message); - if (typeof metaData === "string") { - this._log(type, metaData); - return; - } - if (metaData) { - const metadata = metaData; - let stack = metadata?.error?.stack || metadata?.stack; - if (!stack) { - const stackTrace = new Error().stack?.split("\n"); - if (stackTrace) { - stackTrace.splice(0, 4); - stack = stackTrace.filter((line) => line.includes(".ts:")).join("\n"); - } - } - const newMetadata = { ...metadata }; - delete newMetadata.message; - delete newMetadata.name; - delete newMetadata.stack; - if (!this._isEmpty(newMetadata)) { - this._log(type, newMetadata); - } - if (typeof stack == "string") { - const prettyStack = this._formatStackTrace(stack, 1); - const colorizedStack = this._colorizeText(prettyStack, COLORS.dim); - this._log(type, colorizedStack); - } else if (stack) { - const prettyStack = this._formatStackTrace(stack.join("\n"), 1); - const colorizedStack = this._colorizeText(prettyStack, COLORS.dim); - this._log(type, colorizedStack); - } else { - throw new Error("Stack is null"); - } - } - } - _colorizeText(text, color) { - if (!color) { - throw new Error(`Invalid color: ${color}`); - } - return color.concat(text).concat(COLORS.reset); - } - _formatStackTrace(stack, linesToRemove = 0, prefix = "") { - const lines = stack.split("\n"); - for (let i = 0; i < linesToRemove; i++) { - lines.shift(); - } - return lines.map((line) => `${prefix}${line.replace(/\s*at\s*/, " \u21B3 ")}`).join("\n"); - } - _isEmpty(obj) { - return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== "function"); - } - _log(type, message) { - const defaultSymbols = { - fatal: "\xD7", - ok: "\u2713", - error: "\u26A0", - info: "\u203A", - debug: "\u203A\u203A", - verbose: "\u{1F4AC}" - }; - const symbol = defaultSymbols[type]; - const messageFormatted = typeof message === "string" ? message : util.inspect(message, { showHidden: true, depth: null, breakLength: Infinity }); - const lines = messageFormatted.split("\n"); - const logString = lines.map((line, index) => { - const prefix = index === 0 ? ` ${symbol}` : ` ${" ".repeat(symbol.length)}`; - return `${prefix} ${line}`; - }).join("\n"); - const fullLogString = logString; - const colorMap = { - fatal: ["error", COLORS.fgRed], - ok: ["log", COLORS.fgGreen], - error: ["warn", COLORS.fgYellow], - info: ["info", COLORS.dim], - debug: ["debug", COLORS.fgMagenta], - verbose: ["debug", COLORS.dim] - }; - const _console = console[colorMap[type][0]]; - if (typeof _console === "function") { - _console(this._colorizeText(fullLogString, colorMap[type][1])); - } else { - throw new Error(fullLogString); - } - } -}; - -// src/supabase/types/log-types.ts -var LogReturn = class { - logMessage; - metadata; - constructor(logMessage, metadata) { - this.logMessage = logMessage; - this.metadata = metadata; - } -}; - -// src/supabase/helpers/tables/logs.ts -var Logs = class _Logs { - _maxLevel = -1; - static console; - _log({ level, consoleLog, logMessage, metadata, type }) { - if (this._getNumericLevel(level) > this._maxLevel) - return null; - consoleLog(logMessage, metadata || void 0); - return new LogReturn( - { - raw: logMessage, - diff: this._diffColorCommentMessage(type, logMessage), - type, - level - }, - metadata - ); - } - _addDiagnosticInformation(metadata) { - if (!metadata) { - metadata = {}; - } - if (typeof metadata == "string" || typeof metadata == "number") { - metadata = { message: metadata }; - } - const stackLines = new Error().stack?.split("\n") || []; - if (stackLines.length > 3) { - const callerLine = stackLines[3]; - const match = callerLine.match(/at (\S+)/); - if (match) { - metadata.caller = match[1]; - } - } - return metadata; - } - ok(log, metadata, postComment) { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.INFO, - consoleLog: _Logs.console.ok, - logMessage: log, - metadata, - postComment, - type: "ok" - }); - } - info(log, metadata, postComment) { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.INFO, - consoleLog: _Logs.console.info, - logMessage: log, - metadata, - postComment, - type: "info" - }); - } - error(log, metadata, postComment) { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.ERROR, - consoleLog: _Logs.console.error, - logMessage: log, - metadata, - postComment, - type: "error" - }); - } - debug(log, metadata, postComment) { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.DEBUG, - consoleLog: _Logs.console.debug, - logMessage: log, - metadata, - postComment, - type: "debug" - }); - } - fatal(log, metadata, postComment) { - if (!metadata) { - metadata = _Logs.convertErrorsIntoObjects(new Error(log)); - const stack = metadata.stack; - stack.splice(1, 1); - metadata.stack = stack; - } - if (metadata instanceof Error) { - metadata = _Logs.convertErrorsIntoObjects(metadata); - const stack = metadata.stack; - stack.splice(1, 1); - metadata.stack = stack; - } - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.FATAL, - consoleLog: _Logs.console.fatal, - logMessage: log, - metadata, - postComment, - type: "fatal" - }); - } - verbose(log, metadata, postComment) { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.VERBOSE, - consoleLog: _Logs.console.verbose, - logMessage: log, - metadata, - postComment, - type: "verbose" - }); - } - constructor(logLevel) { - this._maxLevel = this._getNumericLevel(logLevel); - _Logs.console = new PrettyLogs(); - } - static _commentMetaData(metadata, level) { - _Logs.console.debug("the main place that metadata is being serialized as an html comment"); - const prettySerialized = JSON.stringify(metadata, null, 2); - if (level === LOG_LEVEL.FATAL) { - return ["```json", prettySerialized, "```"].join("\n"); - } else { - return [""].join("\n"); - } - } - _diffColorCommentMessage(type, message) { - const diffPrefix = { - fatal: "-", - // - text in red - ok: "+", - // + text in green - error: "!" - // ! text in orange - // info: "#", // # text in gray - // debug: "@@@@",// @@ text in purple (and bold)@@ - // error: null, - // warn: null, - // info: null, - // verbose: "#", - // debug: "#", - }; - const selected = diffPrefix[type]; - if (selected) { - message = message.trim().split("\n").map((line) => `${selected} ${line}`).join("\n"); - } else if (type === "debug") { - message = message.split("\n").map((line) => `@@ ${line} @@`).join("\n"); - } else { - message = message.split("\n").map((line) => `# ${line}`).join("\n"); - } - const diffHeader = "```diff"; - const diffFooter = "```"; - return [diffHeader, message, diffFooter].join("\n"); - } - _getNumericLevel(level) { - switch (level) { - case LOG_LEVEL.FATAL: - return 0; - case LOG_LEVEL.ERROR: - return 1; - case LOG_LEVEL.INFO: - return 2; - case LOG_LEVEL.VERBOSE: - return 4; - case LOG_LEVEL.DEBUG: - return 5; - default: - return -1; - } - } - static convertErrorsIntoObjects(obj) { - if (obj instanceof Error) { - return { - message: obj.message, - name: obj.name, - stack: obj.stack ? obj.stack.split("\n") : null - }; - } else if (typeof obj === "object" && obj !== null) { - const keys = Object.keys(obj); - keys.forEach((key) => { - obj[key] = this.convertErrorsIntoObjects(obj[key]); - }); - } - return obj; - } -}; -export { - Logs -}; -//# sourceMappingURL=logs.js.map \ No newline at end of file diff --git a/dist/logs.js.map b/dist/logs.js.map deleted file mode 100644 index d22382d..0000000 --- a/dist/logs.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/supabase/helpers/tables/pretty-logs.ts","../src/supabase/constants.ts","../src/supabase/types/log-types.ts","../src/supabase/helpers/tables/logs.ts"],"sourcesContent":["import util from \"util\";\r\nimport { Colors, Metadata, PrettyLogsWithOk } from \"../../types/log-types\";\r\nimport { COLORS, LOG_LEVEL } from \"../../constants\";\r\n\r\nexport class PrettyLogs {\r\n constructor() {\r\n this.ok = this.ok.bind(this);\r\n this.info = this.info.bind(this);\r\n this.error = this.error.bind(this);\r\n this.fatal = this.fatal.bind(this);\r\n this.debug = this.debug.bind(this);\r\n this.verbose = this.verbose.bind(this);\r\n }\r\n public fatal(message: string, metadata?: Metadata | string | unknown) {\r\n this._logWithStack(LOG_LEVEL.FATAL, message, metadata);\r\n }\r\n\r\n public error(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.ERROR, message, metadata);\r\n }\r\n\r\n public ok(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(\"ok\", message, metadata);\r\n }\r\n\r\n public info(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.INFO, message, metadata);\r\n }\r\n\r\n public debug(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.DEBUG, message, metadata);\r\n }\r\n\r\n public verbose(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata);\r\n }\r\n\r\n private _logWithStack(type: PrettyLogsWithOk, message: string, metaData?: Metadata | string | unknown) {\r\n this._log(type, message);\r\n if (typeof metaData === \"string\") {\r\n this._log(type, metaData);\r\n return;\r\n }\r\n if (metaData) {\r\n const metadata = metaData as Metadata;\r\n let stack = metadata?.error?.stack || metadata?.stack;\r\n if (!stack) {\r\n // generate and remove the top four lines of the stack trace\r\n const stackTrace = new Error().stack?.split(\"\\n\");\r\n if (stackTrace) {\r\n stackTrace.splice(0, 4);\r\n stack = stackTrace.filter((line) => line.includes(\".ts:\")).join(\"\\n\");\r\n }\r\n }\r\n const newMetadata = { ...metadata };\r\n delete newMetadata.message;\r\n delete newMetadata.name;\r\n delete newMetadata.stack;\r\n\r\n if (!this._isEmpty(newMetadata)) {\r\n this._log(type, newMetadata);\r\n }\r\n\r\n if (typeof stack == \"string\") {\r\n const prettyStack = this._formatStackTrace(stack, 1);\r\n const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);\r\n this._log(type, colorizedStack);\r\n } else if (stack) {\r\n const prettyStack = this._formatStackTrace((stack as unknown as string[]).join(\"\\n\"), 1);\r\n const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);\r\n this._log(type, colorizedStack);\r\n } else {\r\n throw new Error(\"Stack is null\");\r\n }\r\n }\r\n }\r\n\r\n private _colorizeText(text: string, color: Colors): string {\r\n if (!color) {\r\n throw new Error(`Invalid color: ${color}`);\r\n }\r\n return color.concat(text).concat(COLORS.reset);\r\n }\r\n\r\n private _formatStackTrace(stack: string, linesToRemove = 0, prefix = \"\"): string {\r\n const lines = stack.split(\"\\n\");\r\n for (let i = 0; i < linesToRemove; i++) {\r\n lines.shift(); // Remove the top line\r\n }\r\n return lines\r\n .map((line) => `${prefix}${line.replace(/\\s*at\\s*/, \" ↳ \")}`) // Replace 'at' and prefix every line\r\n .join(\"\\n\");\r\n }\r\n\r\n private _isEmpty(obj: Record) {\r\n return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== \"function\");\r\n }\r\n\r\n private _log(type: PrettyLogsWithOk, message: string | Record) {\r\n const defaultSymbols: Record = {\r\n fatal: \"×\",\r\n ok: \"✓\",\r\n error: \"⚠\",\r\n info: \"›\",\r\n debug: \"››\",\r\n verbose: \"💬\",\r\n };\r\n\r\n const symbol = defaultSymbols[type];\r\n\r\n // Formatting the message\r\n const messageFormatted = typeof message === \"string\" ? message : util.inspect(message, { showHidden: true, depth: null, breakLength: Infinity });\r\n // const messageFormatted =\r\n // typeof message === \"string\" ? message : JSON.stringify(Logs.convertErrorsIntoObjects(message));\r\n\r\n // Constructing the full log string with the prefix symbol\r\n const lines = messageFormatted.split(\"\\n\");\r\n const logString = lines\r\n .map((line, index) => {\r\n // Add the symbol only to the first line and keep the indentation for the rest\r\n const prefix = index === 0 ? `\\t${symbol}` : `\\t${\" \".repeat(symbol.length)}`;\r\n return `${prefix} ${line}`;\r\n })\r\n .join(\"\\n\");\r\n\r\n const fullLogString = logString;\r\n\r\n const colorMap: Record = {\r\n fatal: [\"error\", COLORS.fgRed],\r\n ok: [\"log\", COLORS.fgGreen],\r\n error: [\"warn\", COLORS.fgYellow],\r\n info: [\"info\", COLORS.dim],\r\n debug: [\"debug\", COLORS.fgMagenta],\r\n verbose: [\"debug\", COLORS.dim],\r\n };\r\n\r\n const _console = console[colorMap[type][0] as keyof typeof console] as (...args: string[]) => void;\r\n if (typeof _console === \"function\") {\r\n _console(this._colorizeText(fullLogString, colorMap[type][1]));\r\n } else {\r\n throw new Error(fullLogString);\r\n }\r\n }\r\n}\r\n","export const COLORS = {\r\n reset: \"\\x1b[0m\",\r\n bright: \"\\x1b[1m\",\r\n dim: \"\\x1b[2m\",\r\n underscore: \"\\x1b[4m\",\r\n blink: \"\\x1b[5m\",\r\n reverse: \"\\x1b[7m\",\r\n hidden: \"\\x1b[8m\",\r\n\r\n fgBlack: \"\\x1b[30m\",\r\n fgRed: \"\\x1b[31m\",\r\n fgGreen: \"\\x1b[32m\",\r\n fgYellow: \"\\x1b[33m\",\r\n fgBlue: \"\\x1b[34m\",\r\n fgMagenta: \"\\x1b[35m\",\r\n fgCyan: \"\\x1b[36m\",\r\n fgWhite: \"\\x1b[37m\",\r\n\r\n bgBlack: \"\\x1b[40m\",\r\n bgRed: \"\\x1b[41m\",\r\n bgGreen: \"\\x1b[42m\",\r\n bgYellow: \"\\x1b[43m\",\r\n bgBlue: \"\\x1b[44m\",\r\n bgMagenta: \"\\x1b[45m\",\r\n bgCyan: \"\\x1b[46m\",\r\n bgWhite: \"\\x1b[47m\",\r\n} as const;\r\n\r\nexport const LOG_LEVEL = {\r\n FATAL: \"fatal\",\r\n ERROR: \"error\",\r\n INFO: \"info\",\r\n VERBOSE: \"verbose\",\r\n DEBUG: \"debug\",\r\n} as const;\r\n","import { COLORS, LOG_LEVEL } from \"../constants\";\r\nimport { Database } from \"./database\";\r\n\r\ntype LogFunction = (message: string, metadata?: Metadata) => void;\r\nexport type Colors = (typeof COLORS)[keyof typeof COLORS];\r\nexport type LogLevel = (typeof LOG_LEVEL)[keyof typeof LOG_LEVEL];\r\nexport type PrettyLogsWithOk = \"ok\" | LogLevel;\r\nexport type LogInsert = Database[\"public\"][\"Tables\"][\"logs\"][\"Insert\"];\r\nexport type LogMessage = { raw: string; diff: string; level: LogLevel; type: PrettyLogsWithOk };\r\n\r\nexport type LogParams = {\r\n level: LogLevel;\r\n consoleLog: LogFunction;\r\n logMessage: string;\r\n metadata?: Metadata;\r\n postComment?: boolean;\r\n type: PrettyLogsWithOk;\r\n};\r\n\r\nexport interface Metadata {\r\n error?: { stack?: string };\r\n stack?: string | string[] | null;\r\n message?: string;\r\n name?: string;\r\n [key: string]: unknown;\r\n}\r\n\r\nexport class LogReturn {\r\n logMessage: LogMessage;\r\n metadata?: Metadata;\r\n\r\n constructor(logMessage: LogMessage, metadata?: Metadata) {\r\n this.logMessage = logMessage;\r\n this.metadata = metadata;\r\n }\r\n}\r\n","import { PrettyLogs } from \"./pretty-logs\";\r\nimport { Metadata, LogLevel, LogParams, LogReturn } from \"../../types/log-types\";\r\nimport { LOG_LEVEL } from \"../../constants\";\r\n\r\nexport class Logs {\r\n private _maxLevel = -1;\r\n static console: PrettyLogs;\r\n\r\n private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn | null {\r\n if (this._getNumericLevel(level) > this._maxLevel) return null; // filter out more verbose logs according to maxLevel set in config\r\n\r\n // needs to generate three versions of the information.\r\n // they must all first serialize the error object if it exists\r\n // - the comment to post on supabase (must be raw)\r\n // - the comment to post on github (must include diff syntax)\r\n // - the comment to post on the console (must be colorized)\r\n\r\n consoleLog(logMessage, metadata || undefined);\r\n return new LogReturn(\r\n {\r\n raw: logMessage,\r\n diff: this._diffColorCommentMessage(type, logMessage),\r\n type,\r\n level,\r\n },\r\n metadata\r\n );\r\n }\r\n\r\n private _addDiagnosticInformation(metadata: Record | string | number | null | undefined) {\r\n // this is a utility function to get the name of the function that called the log\r\n // I have mixed feelings on this because it manipulates metadata later possibly without the developer understanding why and where,\r\n // but seems useful for the metadata parser to understand where the comment originated from\r\n\r\n if (!metadata) {\r\n metadata = {};\r\n }\r\n if (typeof metadata == \"string\" || typeof metadata == \"number\") {\r\n // TODO: think i need to support every data type\r\n metadata = { message: metadata };\r\n }\r\n\r\n const stackLines = new Error().stack?.split(\"\\n\") || [];\r\n if (stackLines.length > 3) {\r\n const callerLine = stackLines[3]; // .replace(process.cwd(), \"\");\r\n const match = callerLine.match(/at (\\S+)/);\r\n if (match) {\r\n metadata.caller = match[1];\r\n }\r\n }\r\n\r\n return metadata;\r\n }\r\n\r\n public ok(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.INFO,\r\n consoleLog: Logs.console.ok,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"ok\",\r\n });\r\n }\r\n\r\n public info(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.INFO,\r\n consoleLog: Logs.console.info,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"info\",\r\n });\r\n }\r\n\r\n public error(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.ERROR,\r\n consoleLog: Logs.console.error,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"error\",\r\n });\r\n }\r\n\r\n public debug(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.DEBUG,\r\n consoleLog: Logs.console.debug,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"debug\",\r\n });\r\n }\r\n\r\n public fatal(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n if (!metadata) {\r\n metadata = Logs.convertErrorsIntoObjects(new Error(log)) as Metadata;\r\n const stack = metadata.stack as string[];\r\n stack.splice(1, 1);\r\n metadata.stack = stack;\r\n }\r\n\r\n if (metadata instanceof Error) {\r\n metadata = Logs.convertErrorsIntoObjects(metadata) as Metadata;\r\n const stack = metadata.stack as string[];\r\n stack.splice(1, 1);\r\n metadata.stack = stack;\r\n }\r\n\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.FATAL,\r\n consoleLog: Logs.console.fatal,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"fatal\",\r\n });\r\n }\r\n\r\n verbose(log: string, metadata?: Metadata, postComment?: boolean): LogReturn | null {\r\n metadata = this._addDiagnosticInformation(metadata);\r\n return this._log({\r\n level: LOG_LEVEL.VERBOSE,\r\n consoleLog: Logs.console.verbose,\r\n logMessage: log,\r\n metadata,\r\n postComment,\r\n type: \"verbose\",\r\n });\r\n }\r\n\r\n constructor(logLevel: LogLevel) {\r\n this._maxLevel = this._getNumericLevel(logLevel);\r\n Logs.console = new PrettyLogs();\r\n }\r\n\r\n static _commentMetaData(metadata: Metadata, level: LogLevel) {\r\n Logs.console.debug(\"the main place that metadata is being serialized as an html comment\");\r\n const prettySerialized = JSON.stringify(metadata, null, 2);\r\n // first check if metadata is an error, then post it as a json comment\r\n // otherwise post it as an html comment\r\n if (level === LOG_LEVEL.FATAL) {\r\n return [\"```json\", prettySerialized, \"```\"].join(\"\\n\");\r\n } else {\r\n return [\"\"].join(\"\\n\");\r\n }\r\n }\r\n\r\n private _diffColorCommentMessage(type: string, message: string) {\r\n const diffPrefix = {\r\n fatal: \"-\", // - text in red\r\n ok: \"+\", // + text in green\r\n error: \"!\", // ! text in orange\r\n // info: \"#\", // # text in gray\r\n // debug: \"@@@@\",// @@ text in purple (and bold)@@\r\n // error: null,\r\n // warn: null,\r\n // info: null,\r\n // verbose: \"#\",\r\n // debug: \"#\",\r\n };\r\n const selected = diffPrefix[type as keyof typeof diffPrefix];\r\n\r\n if (selected) {\r\n message = message\r\n .trim() // Remove leading and trailing whitespace\r\n .split(\"\\n\")\r\n .map((line) => `${selected} ${line}`)\r\n .join(\"\\n\");\r\n } else if (type === \"debug\") {\r\n // debug has special formatting\r\n message = message\r\n .split(\"\\n\")\r\n .map((line) => `@@ ${line} @@`)\r\n .join(\"\\n\"); // debug: \"@@@@\",\r\n } else {\r\n // default to gray\r\n message = message\r\n .split(\"\\n\")\r\n .map((line) => `# ${line}`)\r\n .join(\"\\n\");\r\n }\r\n\r\n const diffHeader = \"```diff\";\r\n const diffFooter = \"```\";\r\n\r\n return [diffHeader, message, diffFooter].join(\"\\n\");\r\n }\r\n\r\n private _getNumericLevel(level: LogLevel) {\r\n switch (level) {\r\n case LOG_LEVEL.FATAL:\r\n return 0;\r\n case LOG_LEVEL.ERROR:\r\n return 1;\r\n case LOG_LEVEL.INFO:\r\n return 2;\r\n case LOG_LEVEL.VERBOSE:\r\n return 4;\r\n case LOG_LEVEL.DEBUG:\r\n return 5;\r\n default:\r\n return -1; // Invalid level\r\n }\r\n }\r\n static convertErrorsIntoObjects(obj: unknown): Metadata | unknown {\r\n // this is a utility function to render native errors in the console, the database, and on GitHub.\r\n if (obj instanceof Error) {\r\n return {\r\n message: obj.message,\r\n name: obj.name,\r\n stack: obj.stack ? obj.stack.split(\"\\n\") : null,\r\n };\r\n } else if (typeof obj === \"object\" && obj !== null) {\r\n const keys = Object.keys(obj);\r\n keys.forEach((key) => {\r\n obj[key] = this.convertErrorsIntoObjects(obj[key]);\r\n });\r\n }\r\n return obj;\r\n }\r\n}\r\n"],"mappings":";AAAA,OAAO,UAAU;;;ACAV,IAAM,SAAS;AAAA,EACpB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EAER,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AAAA,EAET,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AACX;AAEO,IAAM,YAAY;AAAA,EACvB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;;;AD9BO,IAAM,aAAN,MAAiB;AAAA,EACtB,cAAc;AACZ,SAAK,KAAK,KAAK,GAAG,KAAK,IAAI;AAC3B,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;AAC/B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,EACvC;AAAA,EACO,MAAM,SAAiB,UAAwC;AACpE,SAAK,cAAc,UAAU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OAAO,IAAI,QAAQ,IAAI,MAAM,MAAM,IAAI,IAAI;AAAA,MAC7C;AAAA,IACF,WAAW,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAClD,YAAM,OAAO,OAAO,KAAK,GAAG;AAC5B,WAAK,QAAQ,CAAC,QAAQ;AACpB,YAAI,GAAG,IAAI,KAAK,yBAAyB,IAAI,GAAG,CAAC;AAAA,MACnD,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;","names":[]} \ No newline at end of file diff --git a/dist/pretty-logs-TeMdXxew.d.ts b/dist/pretty-logs-TeMdXxew.d.ts deleted file mode 100644 index 92916f6..0000000 --- a/dist/pretty-logs-TeMdXxew.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -declare const LOG_LEVEL: { - readonly FATAL: "fatal"; - readonly ERROR: "error"; - readonly INFO: "info"; - readonly VERBOSE: "verbose"; - readonly DEBUG: "debug"; -}; - -type LogLevel = (typeof LOG_LEVEL)[keyof typeof LOG_LEVEL]; -type PrettyLogsWithOk = "ok" | LogLevel; -type LogMessage = { - raw: string; - diff: string; - level: LogLevel; - type: PrettyLogsWithOk; -}; -interface Metadata { - error?: { - stack?: string; - }; - stack?: string | string[] | null; - message?: string; - name?: string; - [key: string]: unknown; -} -declare class LogReturn { - logMessage: LogMessage; - metadata?: Metadata; - constructor(logMessage: LogMessage, metadata?: Metadata); -} - -declare class PrettyLogs { - constructor(); - fatal(message: string, metadata?: Metadata | string | unknown): void; - error(message: string, metadata?: Metadata | string): void; - ok(message: string, metadata?: Metadata | string): void; - info(message: string, metadata?: Metadata | string): void; - debug(message: string, metadata?: Metadata | string): void; - verbose(message: string, metadata?: Metadata | string): void; - private _logWithStack; - private _colorizeText; - private _formatStackTrace; - private _isEmpty; - private _log; -} - -export { LogReturn as L, type Metadata as M, PrettyLogs as P, type LogLevel as a }; diff --git a/dist/pretty-logs.d.ts b/dist/pretty-logs.d.ts deleted file mode 100644 index 247d105..0000000 --- a/dist/pretty-logs.d.ts +++ /dev/null @@ -1 +0,0 @@ -export { P as PrettyLogs } from './pretty-logs-TeMdXxew.js'; diff --git a/dist/pretty-logs.js b/dist/pretty-logs.js deleted file mode 100644 index 22bd0c8..0000000 --- a/dist/pretty-logs.js +++ /dev/null @@ -1,154 +0,0 @@ -// src/supabase/helpers/tables/pretty-logs.ts -import util from "util"; - -// src/supabase/constants.ts -var COLORS = { - reset: "\x1B[0m", - bright: "\x1B[1m", - dim: "\x1B[2m", - underscore: "\x1B[4m", - blink: "\x1B[5m", - reverse: "\x1B[7m", - hidden: "\x1B[8m", - fgBlack: "\x1B[30m", - fgRed: "\x1B[31m", - fgGreen: "\x1B[32m", - fgYellow: "\x1B[33m", - fgBlue: "\x1B[34m", - fgMagenta: "\x1B[35m", - fgCyan: "\x1B[36m", - fgWhite: "\x1B[37m", - bgBlack: "\x1B[40m", - bgRed: "\x1B[41m", - bgGreen: "\x1B[42m", - bgYellow: "\x1B[43m", - bgBlue: "\x1B[44m", - bgMagenta: "\x1B[45m", - bgCyan: "\x1B[46m", - bgWhite: "\x1B[47m" -}; -var LOG_LEVEL = { - FATAL: "fatal", - ERROR: "error", - INFO: "info", - VERBOSE: "verbose", - DEBUG: "debug" -}; - -// src/supabase/helpers/tables/pretty-logs.ts -var PrettyLogs = class { - constructor() { - this.ok = this.ok.bind(this); - this.info = this.info.bind(this); - this.error = this.error.bind(this); - this.fatal = this.fatal.bind(this); - this.debug = this.debug.bind(this); - this.verbose = this.verbose.bind(this); - } - fatal(message, metadata) { - this._logWithStack(LOG_LEVEL.FATAL, message, metadata); - } - error(message, metadata) { - this._logWithStack(LOG_LEVEL.ERROR, message, metadata); - } - ok(message, metadata) { - this._logWithStack("ok", message, metadata); - } - info(message, metadata) { - this._logWithStack(LOG_LEVEL.INFO, message, metadata); - } - debug(message, metadata) { - this._logWithStack(LOG_LEVEL.DEBUG, message, metadata); - } - verbose(message, metadata) { - this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata); - } - _logWithStack(type, message, metaData) { - this._log(type, message); - if (typeof metaData === "string") { - this._log(type, metaData); - return; - } - if (metaData) { - const metadata = metaData; - let stack = metadata?.error?.stack || metadata?.stack; - if (!stack) { - const stackTrace = new Error().stack?.split("\n"); - if (stackTrace) { - stackTrace.splice(0, 4); - stack = stackTrace.filter((line) => line.includes(".ts:")).join("\n"); - } - } - const newMetadata = { ...metadata }; - delete newMetadata.message; - delete newMetadata.name; - delete newMetadata.stack; - if (!this._isEmpty(newMetadata)) { - this._log(type, newMetadata); - } - if (typeof stack == "string") { - const prettyStack = this._formatStackTrace(stack, 1); - const colorizedStack = this._colorizeText(prettyStack, COLORS.dim); - this._log(type, colorizedStack); - } else if (stack) { - const prettyStack = this._formatStackTrace(stack.join("\n"), 1); - const colorizedStack = this._colorizeText(prettyStack, COLORS.dim); - this._log(type, colorizedStack); - } else { - throw new Error("Stack is null"); - } - } - } - _colorizeText(text, color) { - if (!color) { - throw new Error(`Invalid color: ${color}`); - } - return color.concat(text).concat(COLORS.reset); - } - _formatStackTrace(stack, linesToRemove = 0, prefix = "") { - const lines = stack.split("\n"); - for (let i = 0; i < linesToRemove; i++) { - lines.shift(); - } - return lines.map((line) => `${prefix}${line.replace(/\s*at\s*/, " \u21B3 ")}`).join("\n"); - } - _isEmpty(obj) { - return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== "function"); - } - _log(type, message) { - const defaultSymbols = { - fatal: "\xD7", - ok: "\u2713", - error: "\u26A0", - info: "\u203A", - debug: "\u203A\u203A", - verbose: "\u{1F4AC}" - }; - const symbol = defaultSymbols[type]; - const messageFormatted = typeof message === "string" ? message : util.inspect(message, { showHidden: true, depth: null, breakLength: Infinity }); - const lines = messageFormatted.split("\n"); - const logString = lines.map((line, index) => { - const prefix = index === 0 ? ` ${symbol}` : ` ${" ".repeat(symbol.length)}`; - return `${prefix} ${line}`; - }).join("\n"); - const fullLogString = logString; - const colorMap = { - fatal: ["error", COLORS.fgRed], - ok: ["log", COLORS.fgGreen], - error: ["warn", COLORS.fgYellow], - info: ["info", COLORS.dim], - debug: ["debug", COLORS.fgMagenta], - verbose: ["debug", COLORS.dim] - }; - const _console = console[colorMap[type][0]]; - if (typeof _console === "function") { - _console(this._colorizeText(fullLogString, colorMap[type][1])); - } else { - throw new Error(fullLogString); - } - } -}; -export { - PrettyLogs -}; -//# sourceMappingURL=pretty-logs.js.map \ No newline at end of file diff --git a/dist/pretty-logs.js.map b/dist/pretty-logs.js.map deleted file mode 100644 index f0ab67e..0000000 --- a/dist/pretty-logs.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/supabase/helpers/tables/pretty-logs.ts","../src/supabase/constants.ts"],"sourcesContent":["import util from \"util\";\r\nimport { Colors, Metadata, PrettyLogsWithOk } from \"../../types/log-types\";\r\nimport { COLORS, LOG_LEVEL } from \"../../constants\";\r\n\r\nexport class PrettyLogs {\r\n constructor() {\r\n this.ok = this.ok.bind(this);\r\n this.info = this.info.bind(this);\r\n this.error = this.error.bind(this);\r\n this.fatal = this.fatal.bind(this);\r\n this.debug = this.debug.bind(this);\r\n this.verbose = this.verbose.bind(this);\r\n }\r\n public fatal(message: string, metadata?: Metadata | string | unknown) {\r\n this._logWithStack(LOG_LEVEL.FATAL, message, metadata);\r\n }\r\n\r\n public error(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.ERROR, message, metadata);\r\n }\r\n\r\n public ok(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(\"ok\", message, metadata);\r\n }\r\n\r\n public info(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.INFO, message, metadata);\r\n }\r\n\r\n public debug(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.DEBUG, message, metadata);\r\n }\r\n\r\n public verbose(message: string, metadata?: Metadata | string) {\r\n this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata);\r\n }\r\n\r\n private _logWithStack(type: PrettyLogsWithOk, message: string, metaData?: Metadata | string | unknown) {\r\n this._log(type, message);\r\n if (typeof metaData === \"string\") {\r\n this._log(type, metaData);\r\n return;\r\n }\r\n if (metaData) {\r\n const metadata = metaData as Metadata;\r\n let stack = metadata?.error?.stack || metadata?.stack;\r\n if (!stack) {\r\n // generate and remove the top four lines of the stack trace\r\n const stackTrace = new Error().stack?.split(\"\\n\");\r\n if (stackTrace) {\r\n stackTrace.splice(0, 4);\r\n stack = stackTrace.filter((line) => line.includes(\".ts:\")).join(\"\\n\");\r\n }\r\n }\r\n const newMetadata = { ...metadata };\r\n delete newMetadata.message;\r\n delete newMetadata.name;\r\n delete newMetadata.stack;\r\n\r\n if (!this._isEmpty(newMetadata)) {\r\n this._log(type, newMetadata);\r\n }\r\n\r\n if (typeof stack == \"string\") {\r\n const prettyStack = this._formatStackTrace(stack, 1);\r\n const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);\r\n this._log(type, colorizedStack);\r\n } else if (stack) {\r\n const prettyStack = this._formatStackTrace((stack as unknown as string[]).join(\"\\n\"), 1);\r\n const colorizedStack = this._colorizeText(prettyStack, COLORS.dim);\r\n this._log(type, colorizedStack);\r\n } else {\r\n throw new Error(\"Stack is null\");\r\n }\r\n }\r\n }\r\n\r\n private _colorizeText(text: string, color: Colors): string {\r\n if (!color) {\r\n throw new Error(`Invalid color: ${color}`);\r\n }\r\n return color.concat(text).concat(COLORS.reset);\r\n }\r\n\r\n private _formatStackTrace(stack: string, linesToRemove = 0, prefix = \"\"): string {\r\n const lines = stack.split(\"\\n\");\r\n for (let i = 0; i < linesToRemove; i++) {\r\n lines.shift(); // Remove the top line\r\n }\r\n return lines\r\n .map((line) => `${prefix}${line.replace(/\\s*at\\s*/, \" ↳ \")}`) // Replace 'at' and prefix every line\r\n .join(\"\\n\");\r\n }\r\n\r\n private _isEmpty(obj: Record) {\r\n return !Reflect.ownKeys(obj).some((key) => typeof obj[String(key)] !== \"function\");\r\n }\r\n\r\n private _log(type: PrettyLogsWithOk, message: string | Record) {\r\n const defaultSymbols: Record = {\r\n fatal: \"×\",\r\n ok: \"✓\",\r\n error: \"⚠\",\r\n info: \"›\",\r\n debug: \"››\",\r\n verbose: \"💬\",\r\n };\r\n\r\n const symbol = defaultSymbols[type];\r\n\r\n // Formatting the message\r\n const messageFormatted = typeof message === \"string\" ? message : util.inspect(message, { showHidden: true, depth: null, breakLength: Infinity });\r\n // const messageFormatted =\r\n // typeof message === \"string\" ? message : JSON.stringify(Logs.convertErrorsIntoObjects(message));\r\n\r\n // Constructing the full log string with the prefix symbol\r\n const lines = messageFormatted.split(\"\\n\");\r\n const logString = lines\r\n .map((line, index) => {\r\n // Add the symbol only to the first line and keep the indentation for the rest\r\n const prefix = index === 0 ? `\\t${symbol}` : `\\t${\" \".repeat(symbol.length)}`;\r\n return `${prefix} ${line}`;\r\n })\r\n .join(\"\\n\");\r\n\r\n const fullLogString = logString;\r\n\r\n const colorMap: Record = {\r\n fatal: [\"error\", COLORS.fgRed],\r\n ok: [\"log\", COLORS.fgGreen],\r\n error: [\"warn\", COLORS.fgYellow],\r\n info: [\"info\", COLORS.dim],\r\n debug: [\"debug\", COLORS.fgMagenta],\r\n verbose: [\"debug\", COLORS.dim],\r\n };\r\n\r\n const _console = console[colorMap[type][0] as keyof typeof console] as (...args: string[]) => void;\r\n if (typeof _console === \"function\") {\r\n _console(this._colorizeText(fullLogString, colorMap[type][1]));\r\n } else {\r\n throw new Error(fullLogString);\r\n }\r\n }\r\n}\r\n","export const COLORS = {\r\n reset: \"\\x1b[0m\",\r\n bright: \"\\x1b[1m\",\r\n dim: \"\\x1b[2m\",\r\n underscore: \"\\x1b[4m\",\r\n blink: \"\\x1b[5m\",\r\n reverse: \"\\x1b[7m\",\r\n hidden: \"\\x1b[8m\",\r\n\r\n fgBlack: \"\\x1b[30m\",\r\n fgRed: \"\\x1b[31m\",\r\n fgGreen: \"\\x1b[32m\",\r\n fgYellow: \"\\x1b[33m\",\r\n fgBlue: \"\\x1b[34m\",\r\n fgMagenta: \"\\x1b[35m\",\r\n fgCyan: \"\\x1b[36m\",\r\n fgWhite: \"\\x1b[37m\",\r\n\r\n bgBlack: \"\\x1b[40m\",\r\n bgRed: \"\\x1b[41m\",\r\n bgGreen: \"\\x1b[42m\",\r\n bgYellow: \"\\x1b[43m\",\r\n bgBlue: \"\\x1b[44m\",\r\n bgMagenta: \"\\x1b[45m\",\r\n bgCyan: \"\\x1b[46m\",\r\n bgWhite: \"\\x1b[47m\",\r\n} as const;\r\n\r\nexport const LOG_LEVEL = {\r\n FATAL: \"fatal\",\r\n ERROR: \"error\",\r\n INFO: \"info\",\r\n VERBOSE: \"verbose\",\r\n DEBUG: \"debug\",\r\n} as const;\r\n"],"mappings":";AAAA,OAAO,UAAU;;;ACAV,IAAM,SAAS;AAAA,EACpB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EAER,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AAAA,EAET,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AACX;AAEO,IAAM,YAAY;AAAA,EACvB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;;;AD9BO,IAAM,aAAN,MAAiB;AAAA,EACtB,cAAc;AACZ,SAAK,KAAK,KAAK,GAAG,KAAK,IAAI;AAC3B,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;AAC/B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SA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