var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { PiniaColadaDebugPlugin: () => PiniaColadaDebugPlugin, showMessage: () => showMessage, useDebugData: () => useDebugData }); module.exports = __toCommonJS(src_exports); var import_pinia = require("pinia"); var import_vue = require("vue"); var tick = () => new Promise((r) => setTimeout(r, 0)); var useDebugData = (0, import_pinia.defineStore)("pinia-colada-debug", () => { const totalRefetches = (0, import_vue.ref)(0); const refetchingEntries = (0, import_vue.shallowReactive)(/* @__PURE__ */ new Set()); const totalErrors = (0, import_vue.ref)(0); const totalSuccess = (0, import_vue.ref)(0); function addRefetchingEntry(entry) { refetchingEntries.add(entry); totalRefetches.value++; } function removeRefetchingEntry(entry) { refetchingEntries.delete(entry); } return { refetchingEntries, totalErrors, totalSuccess, totalRefetches, addRefetchingEntry, removeRefetchingEntry }; }); function PiniaColadaDebugPlugin() { return ({ queryCache, pinia }) => { const debugData = useDebugData(pinia); queryCache.$onAction(async ({ name, onError, after, args }) => { if (name === "fetch" || name === "refresh") { const [entry] = args; await tick(); if (entry.asyncStatus.value === "loading" || entry.state.value.status === "pending") { debugData.addRefetchingEntry(entry); showMessage("\u{1F504}", "refetch", `[${entry.key.join(", ")}]`, entry); after(() => { debugData.removeRefetchingEntry(entry); if (entry.state.value.status === "error") { debugData.totalErrors++; showMessage( "error", "refetch failed", `[${entry.key.join(", ")}]`, entry.state.value.error ); } else { debugData.totalSuccess++; showMessage( "\u2705", "refetch", `[${entry.key.join(", ")}]`, entry.state.value.data ); } }); onError((error) => { showMessage( "error", "Unexpected Error", `[${entry.key.join(", ")}]`, error ); }); } } else if (name === "setQueryData") { const [key, data] = args; showMessage("log", "setQueryData", `[${key.join(", ")}]`, data); } else if (name === "invalidate") { const [entry] = args; showMessage("\u{1F5D1}\uFE0F", "invalidateEntry", `[${entry.key.join(", ")}]`); } }); }; } var LOG_MESSAGES_COLOR = { info: "background: #bfdbfe; color: #1e1e1e", log: "background: #f9fafb; color: #1e1e1e", warn: "background: #f97316; color: #0b0b0b", error: "background: #ff5e56; color: #2e2e2e", debug: "background: #212a2b; color: #fefefe", trace: "background: #000; color: #fff" }; var LABELS_FOR_TYPE = { info: "\u2139\uFE0F", log: "\u{1F4DD}", // warn: '⚠️', // NOTE: doesn't show well in Chromium browsers warn: "\u{1F6A7}", error: "\u26D4\uFE0F", debug: "\u{1F41E}", trace: "\u{1F50D}" }; var MD_BOLD_RE = /\*\*(.*?)\*\*/g; var MD_CODE_RE = /`(.*?)`/g; function applyTextStyles(text) { const styles = []; const newText = text.replace(MD_BOLD_RE, (_m, text2, pos) => { styles.push({ pos, style: ["font-weight: bold;", "font-weight: normal;"] }); return `%c${text2}%c`; }).replace(MD_CODE_RE, (_m, text2, pos) => { styles.push({ pos, style: ["font-family: monospace;", "font-family: inherit;"] }); return `%c\`${text2}\`%c`; }); return [ newText, ...styles.sort((a, b) => a.pos - b.pos).flatMap((s) => s.style) ]; } function showMessage(type, title, subtitle, ...messages) { if (process.env.NODE_ENV !== "development" && type !== "error" && type !== "warn") { return; } const isGroup = messages.length > 0; const label = LABELS_FOR_TYPE[type] ?? type; const labelStyle = LOG_MESSAGES_COLOR[type] ?? LOG_MESSAGES_COLOR.info; const collapsed = true; const method = isGroup ? collapsed ? "groupCollapsed" : "group" : "log"; const color = "#e2e8f0"; const bgColor = "#171717"; console[method]( `%c ${label} %c ${title} %c ${subtitle}`, `${labelStyle}; padding: 1px; border-radius: 0.3em 0 0 0.3em; font-size: 1em;`, `background:${bgColor}; color: ${color}; padding: 1px; border-radius: 0 0.3em 0.3em 0; font-size: 1em;`, // reset styles "background: transparent; color: inherit; font-weight: normal; font-size: 1em;" ); let activeStyle = ""; messages.forEach((m) => { let tempStyle = ""; let mdStyles = []; if (m instanceof Error) { console.error(m); } else if (m !== void 0) { if (typeof m !== "string") { console.log(m); return; } if (m.startsWith("```")) { activeStyle = `font-family: monospace;`; tempStyle += `color: gray; padding: 1px; border-radius: ${m === "```" ? "0 0 3px 3px" : "3px 3px 0 0"};`; } else if (typeof m === "string" && !m.includes("http")) { ; [m, ...mdStyles] = applyTextStyles(m); } if (activeStyle || tempStyle) { console.log(`%c${m}`, activeStyle + tempStyle, ...mdStyles); } else { console.log(m, ...mdStyles); } if (m === "```") { activeStyle = ""; } else if (m.startsWith("```")) { activeStyle += "background-color: black; color: palegreen; padding: 0.5em; width: 100%;"; } } }); if (isGroup) console.groupEnd(); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PiniaColadaDebugPlugin, showMessage, useDebugData }); //# sourceMappingURL=index.cjs.map