@real-router/logger-plugin 0.3.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  ▼ Router transition
13
13
  [logger-plugin] Transition: home → users.profile {from: {...}, to: {...}}
14
14
  [logger-plugin] Changed: { id: "123" → "456" }, Added: {"sort":"name"}
15
+ [logger-plugin] Leave approved {to: {...}, from: {...}}
15
16
  [logger-plugin] Transition success (1.23ms) {to: {...}, from: {...}}
16
17
  ```
17
18
 
@@ -88,6 +89,7 @@ With `usePerformanceMarks: true`, creates marks visible in DevTools Performance
88
89
 
89
90
  ```
90
91
  router:transition-start:{from}→{to}
92
+ router:leave-approved:{from}→{to}
91
93
  router:transition-end:{from}→{to}
92
94
  router:transition:{from}→{to} (measure)
93
95
  router:lifetime (measure: start → stop)
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=`logger-plugin`,t=`[@real-router/${e}]`,n={level:`all`,usePerformanceMarks:!1,showParamsDiff:!0,showTiming:!0,context:e},r=()=>typeof console<`u`&&typeof console.group==`function`&&typeof console.groupEnd==`function`,i=e=>{let t=!1;return{open(n){!e||t||(console.group(n),t=!0)},close(){!e||!t||(console.groupEnd(),t=!1)},isOpen(){return t}}},a=e=>e?.name??`(none)`,o=(e,t)=>{if(e===null)return``;let n=t()-e;return!Number.isFinite(n)||n<0?` (?)`:n<.1?` (${(n*1e3).toFixed(2)}μs)`:` (${n.toFixed(2)}ms)`},s=(e,t)=>`${e}→${t}`,c=(e,t)=>{let n={},r={},i={},a=!1;for(let r in e)r in t?e[r]!==t[r]&&(n[r]={from:e[r],to:t[r]},a=!0):(i[r]=e[r],a=!0);for(let n in t)n in e||(r[n]=t[n],a=!0);return a?{changed:n,added:r,removed:i}:null},l=(e,t)=>{let n=[],r=Object.entries(e.changed);if(r.length>0){let e=[];for(let[t,{from:n,to:i}]of r)e.push(`${t}: ${JSON.stringify(n)} → ${JSON.stringify(i)}`);n.push(`Changed: { ${e.join(`, `)} }`)}Object.keys(e.added).length>0&&n.push(`Added: ${JSON.stringify(e.added)}`),Object.keys(e.removed).length>0&&n.push(`Removed: ${JSON.stringify(e.removed)}`),console.log(`[${t}] ${n.join(`, `)}`)},u=()=>typeof performance<`u`&&typeof performance.mark==`function`&&typeof performance.measure==`function`,d=(e,t)=>{let n=e&&u();return{mark(e){n&&performance.mark(e)},measure(e,r,i){if(n)try{performance.measure(e,r,i)}catch(n){console.warn(`[${t}] Failed to create performance measure: ${e}`,n)}}}};let f=0,p=0;function m(){return()=>{let e=Date.now();return e<f&&(p+=f-e),f=e,e+p}}const h=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():m(),g=()=>h();var _=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=``;#f=``;constructor(e){this.#e=e.level===`all`,this.#t=e.level!==`none`&&e.level!==`errors`,this.#n=e.level!==`none`,this.#r=this.#t&&e.showParamsDiff,this.#i=e.showTiming,this.#a=e.usePerformanceMarks,this.#o=`[${e.context}]`,this.#s=e.context,this.#c=i(r()),this.#l=d(e.usePerformanceMarks,e.context)}getPlugin(){return{onStart:()=>{this.#l.mark(`router:start`),this.#e&&console.log(`${this.#o} Router started`)},onStop:()=>{this.#c.close(),this.#l.mark(`router:stop`),this.#l.measure(`router:lifetime`,`router:start`,`router:stop`),this.#e&&console.log(`${this.#o} Router stopped`)},onTransitionStart:(e,t)=>{this.#c.open(`Router transition`),this.#u=this.#i?g():null;let n=a(t),r=a(e);this.#a&&(this.#d=s(n,r),this.#f=`router:transition-start:${this.#d}`,this.#l.mark(this.#f)),this.#t&&(console.log(`${this.#o} Transition: ${n} → ${r}`,{from:t,to:e}),this.#p(e,t))},onTransitionSuccess:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-end:${e}`;this.#l.mark(t),this.#l.measure(`router:transition:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.log(`${this.#o} Transition success${n}`,{to:e,from:t})}this.#m()},onTransitionCancel:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-cancel:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-cancelled:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.warn(`${this.#o} Transition cancelled${n}`,{to:e,from:t})}this.#m()},onTransitionError:(e,t,n)=>{if(this.#a){let e=this.#d,t=`router:transition-error:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-failed:${e}`,this.#f,t)}if(this.#n){let r=this.#i?o(this.#u,g):``;console.error(`${this.#o} Transition error: ${n.code}${r}`,{error:n,stack:n.stack,to:e,from:t})}this.#m()},teardown:()=>{this.#m()}}}#p(e,t){if(!this.#r||!t||e.name!==t.name)return;let n=c(t.params,e.params);n&&l(n,this.#s)}#m(){this.#c.close(),this.#d=``,this.#f=``,this.#u=null}};const v=new Set([`all`,`transitions`,`errors`,`none`]);function y(e){if(e!==void 0){if(typeof e!=`object`||!e)throw TypeError(`${t} Options must be an object`);if(e.level!==void 0&&!v.has(e.level))throw TypeError(`${t} Invalid level: "${e.level}". Expected: ${[...v].join(`, `)}`);if(e.context!==void 0&&(typeof e.context!=`string`||e.context.length===0))throw TypeError(`${t} Option "context" must be a non-empty string`);if(e.showTiming!==void 0&&typeof e.showTiming!=`boolean`)throw TypeError(`${t} Option "showTiming" must be a boolean`);if(e.showParamsDiff!==void 0&&typeof e.showParamsDiff!=`boolean`)throw TypeError(`${t} Option "showParamsDiff" must be a boolean`);if(e.usePerformanceMarks!==void 0&&typeof e.usePerformanceMarks!=`boolean`)throw TypeError(`${t} Option "usePerformanceMarks" must be a boolean`)}}function b(e){y(e);let t={...n,...e};return()=>new _(t).getPlugin()}exports.loggerPluginFactory=b;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=`logger-plugin`,t=`[@real-router/${e}]`,n={level:`all`,usePerformanceMarks:!1,showParamsDiff:!0,showTiming:!0,context:e},r=()=>typeof console<`u`&&typeof console.group==`function`&&typeof console.groupEnd==`function`,i=e=>{let t=!1;return{open(n){!e||t||(console.group(n),t=!0)},close(){!e||!t||(console.groupEnd(),t=!1)},isOpen(){return t}}},a=e=>e?.name??`(none)`,o=(e,t)=>{if(e===null)return``;let n=t()-e;return!Number.isFinite(n)||n<0?` (?)`:n<.1?` (${(n*1e3).toFixed(2)}μs)`:` (${n.toFixed(2)}ms)`},s=(e,t)=>`${e}→${t}`,c=(e,t)=>{let n={},r={},i={},a=!1;for(let r in e)r in t?e[r]!==t[r]&&(n[r]={from:e[r],to:t[r]},a=!0):(i[r]=e[r],a=!0);for(let n in t)n in e||(r[n]=t[n],a=!0);return a?{changed:n,added:r,removed:i}:null},l=(e,t)=>{let n=[],r=Object.entries(e.changed);if(r.length>0){let e=[];for(let[t,{from:n,to:i}]of r)e.push(`${t}: ${JSON.stringify(n)} → ${JSON.stringify(i)}`);n.push(`Changed: { ${e.join(`, `)} }`)}Object.keys(e.added).length>0&&n.push(`Added: ${JSON.stringify(e.added)}`),Object.keys(e.removed).length>0&&n.push(`Removed: ${JSON.stringify(e.removed)}`),console.log(`[${t}] ${n.join(`, `)}`)},u=()=>typeof performance<`u`&&typeof performance.mark==`function`&&typeof performance.measure==`function`,d=(e,t)=>{let n=e&&u();return{mark(e){n&&performance.mark(e)},measure(e,r,i){if(n)try{performance.measure(e,r,i)}catch(n){console.warn(`[${t}] Failed to create performance measure: ${e}`,n)}}}};let f=0,p=0;function m(){return()=>{let e=Date.now();return e<f&&(p+=f-e),f=e,e+p}}const h=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():m(),g=()=>h();var _=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=``;#f=``;constructor(e){this.#e=e.level===`all`,this.#t=e.level!==`none`&&e.level!==`errors`,this.#n=e.level!==`none`,this.#r=this.#t&&e.showParamsDiff,this.#i=e.showTiming,this.#a=e.usePerformanceMarks,this.#o=`[${e.context}]`,this.#s=e.context,this.#c=i(r()),this.#l=d(e.usePerformanceMarks,e.context)}getPlugin(){return{onStart:()=>{this.#l.mark(`router:start`),this.#e&&console.log(`${this.#o} Router started`)},onStop:()=>{this.#c.close(),this.#l.mark(`router:stop`),this.#l.measure(`router:lifetime`,`router:start`,`router:stop`),this.#e&&console.log(`${this.#o} Router stopped`)},onTransitionStart:(e,t)=>{this.#c.open(`Router transition`),this.#u=this.#i?g():null;let n=a(t),r=a(e);this.#a&&(this.#d=s(n,r),this.#f=`router:transition-start:${this.#d}`,this.#l.mark(this.#f)),this.#t&&(console.log(`${this.#o} Transition: ${n} → ${r}`,{from:t,to:e}),this.#p(e,t))},onTransitionLeaveApprove:(e,t)=>{this.#a&&this.#l.mark(`router:leave-approved:${this.#d}`),this.#t&&console.log(`${this.#o} Leave approved`,{to:e,from:t})},onTransitionSuccess:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-end:${e}`;this.#l.mark(t),this.#l.measure(`router:transition:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.log(`${this.#o} Transition success${n}`,{to:e,from:t})}this.#m()},onTransitionCancel:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-cancel:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-cancelled:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.warn(`${this.#o} Transition cancelled${n}`,{to:e,from:t})}this.#m()},onTransitionError:(e,t,n)=>{if(this.#a){let e=this.#d,t=`router:transition-error:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-failed:${e}`,this.#f,t)}if(this.#n){let r=this.#i?o(this.#u,g):``;console.error(`${this.#o} Transition error: ${n.code}${r}`,{error:n,stack:n.stack,to:e,from:t})}this.#m()},teardown:()=>{this.#m()}}}#p(e,t){if(!this.#r||!t||e.name!==t.name)return;let n=c(t.params,e.params);n&&l(n,this.#s)}#m(){this.#c.close(),this.#d=``,this.#f=``,this.#u=null}};const v=new Set([`all`,`transitions`,`errors`,`none`]);function y(e){if(e!==void 0){if(typeof e!=`object`||!e)throw TypeError(`${t} Options must be an object`);if(e.level!==void 0&&!v.has(e.level))throw TypeError(`${t} Invalid level: "${e.level}". Expected: ${[...v].join(`, `)}`);if(e.context!==void 0&&(typeof e.context!=`string`||e.context.length===0))throw TypeError(`${t} Option "context" must be a non-empty string`);if(e.showTiming!==void 0&&typeof e.showTiming!=`boolean`)throw TypeError(`${t} Option "showTiming" must be a boolean`);if(e.showParamsDiff!==void 0&&typeof e.showParamsDiff!=`boolean`)throw TypeError(`${t} Option "showParamsDiff" must be a boolean`);if(e.usePerformanceMarks!==void 0&&typeof e.usePerformanceMarks!=`boolean`)throw TypeError(`${t} Option "usePerformanceMarks" must be a boolean`)}}function b(e){y(e);let t={...n,...e};return()=>new _(t).getPlugin()}exports.loggerPluginFactory=b;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#logLifecycle","#logTransition","#logError","#shouldLogParams","#shouldShowTiming","#usePerf","#prefix","#context","#groups","#perf","#transitionStartTime","#transitionLabel","#startMarkName","#logParamsIfNeeded","#resetTransitionState"],"sources":["../../src/constants.ts","../../src/internal/console-groups.ts","../../src/internal/formatting.ts","../../src/internal/params-diff.ts","../../src/internal/performance-marks.ts","../../src/internal/timing.ts","../../src/plugin.ts","../../src/validation.ts","../../src/factory.ts"],"sourcesContent":["// packages/logger-plugin/src/constants.ts\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nexport const LOGGER_CONTEXT = \"logger-plugin\";\n\nexport const ERROR_PREFIX = `[@real-router/${LOGGER_CONTEXT}]`;\n\nexport const DEFAULT_CONFIG: Required<LoggerPluginConfig> = {\n level: \"all\",\n usePerformanceMarks: false,\n showParamsDiff: true,\n showTiming: true,\n context: LOGGER_CONTEXT,\n};\n","// packages/logger-plugin/src/internal/console-groups.ts\n\n/**\n * Checks if console.group is supported in the current environment.\n */\nexport const supportsConsoleGroups = (): boolean => {\n return (\n typeof console !== \"undefined\" &&\n typeof console.group === \"function\" &&\n typeof console.groupEnd === \"function\"\n );\n};\n\n/**\n * Manager for handling console groups\n */\nexport interface GroupManager {\n /**\n * Opens a group if it's not already open\n */\n open: (label: string) => void;\n /**\n * Closes a group if it's open\n */\n close: () => void;\n /**\n * Checks if a group is currently open\n */\n isOpen: () => boolean;\n}\n\n/**\n * Creates a manager for handling console groups.\n * Prevents duplicate group opening.\n *\n * @param enabled - Whether groups are supported in the environment\n * @returns Object with open and close methods\n */\nexport const createGroupManager = (enabled: boolean): GroupManager => {\n let isOpened = false;\n\n return {\n /**\n * Opens a group if it's not already open.\n */\n open(label: string): void {\n if (!enabled || isOpened) {\n return;\n }\n\n console.group(label);\n isOpened = true;\n },\n\n /**\n * Closes a group if it's open.\n */\n close(): void {\n if (!enabled || !isOpened) {\n return;\n }\n\n console.groupEnd();\n isOpened = false;\n },\n\n /**\n * Checks if a group is currently open.\n */\n isOpen(): boolean {\n return isOpened;\n },\n };\n};\n","// packages/logger-plugin/src/internal/formatting.ts\n\nimport type { State } from \"@real-router/core\";\n\n/**\n * Formats route name for logging output.\n * Handles undefined/null.\n */\nexport const formatRouteName = (state?: State): string => {\n return state?.name ?? \"(none)\";\n};\n\n/**\n * Formats execution time information.\n * Uses adaptive units:\n * - Microseconds (μs) for <0.1ms\n * - Milliseconds (ms) for ≥0.1ms\n *\n * @param startTime - Start time or null\n * @param now - Function to get current time\n * @returns String with time or empty string\n */\nexport const formatTiming = (\n startTime: number | null,\n now: () => number,\n): string => {\n if (startTime === null) {\n return \"\";\n }\n\n const durationMs = now() - startTime;\n\n if (!Number.isFinite(durationMs) || durationMs < 0) {\n return \" (?)\";\n }\n\n if (durationMs < 0.1) {\n const durationMks = (durationMs * 1000).toFixed(2);\n\n return ` (${durationMks}μs)`;\n } else {\n const duration = durationMs.toFixed(2);\n\n return ` (${duration}ms)`;\n }\n};\n\n/**\n * Creates a label for Performance API from route names.\n */\nexport const createTransitionLabel = (\n fromRoute: string,\n toRoute: string,\n): string => {\n return `${fromRoute}→${toRoute}`;\n};\n","// packages/logger-plugin/src/internal/params-diff.ts\n\nimport type { Params } from \"@real-router/core\";\n\nexport interface ParamsDiff {\n changed: Record<string, { from: unknown; to: unknown }>;\n added: Record<string, unknown>;\n removed: Record<string, unknown>;\n}\n\n/**\n * Calculates differences between two parameter objects.\n * Performs only shallow comparison.\n *\n * @param fromParams - Previous parameters\n * @param toParams - New parameters\n * @returns Object with differences or null if there are no changes\n */\nexport const getParamsDiff = (\n fromParams: Params,\n toParams: Params,\n): ParamsDiff | null => {\n const changed: ParamsDiff[\"changed\"] = {};\n const added: ParamsDiff[\"added\"] = {};\n const removed: ParamsDiff[\"removed\"] = {};\n\n // Track if any changes found to avoid iterating through objects at the end.\n // This is a performance optimization: instead of calling Object.keys().length\n // three times to check if objects are empty, we set this flag when we find\n // any change and check it once at the end.\n let hasChanges = false;\n\n // Find changed and removed\n for (const key in fromParams) {\n if (!(key in toParams)) {\n removed[key] = fromParams[key];\n hasChanges = true;\n } else if (fromParams[key] !== toParams[key]) {\n changed[key] = { from: fromParams[key], to: toParams[key] };\n hasChanges = true;\n }\n }\n\n // Find added\n for (const key in toParams) {\n if (!(key in fromParams)) {\n added[key] = toParams[key];\n hasChanges = true;\n }\n }\n\n // Return null if there are no changes\n if (!hasChanges) {\n return null;\n }\n\n return { changed, added, removed };\n};\n\n/**\n * Formats and logs parameter differences.\n *\n * @param diff - Object with differences\n * @param context - Context for console\n */\nexport const logParamsDiff = (diff: ParamsDiff, context: string): void => {\n const parts: string[] = [];\n\n // Cache entries to avoid double iteration\n const changedEntries = Object.entries(diff.changed);\n\n if (changedEntries.length > 0) {\n const items: string[] = [];\n\n for (const [key, { from, to }] of changedEntries) {\n items.push(`${key}: ${JSON.stringify(from)} → ${JSON.stringify(to)}`);\n }\n\n parts.push(`Changed: { ${items.join(\", \")} }`);\n }\n\n if (Object.keys(diff.added).length > 0) {\n parts.push(`Added: ${JSON.stringify(diff.added)}`);\n }\n\n if (Object.keys(diff.removed).length > 0) {\n parts.push(`Removed: ${JSON.stringify(diff.removed)}`);\n }\n\n console.log(`[${context}] ${parts.join(\", \")}`);\n};\n","// packages/logger-plugin/src/internal/performance-marks.ts\n\n/**\n * Checks if Performance API is supported in the current environment.\n */\nexport const supportsPerformanceAPI = (): boolean => {\n return (\n typeof performance !== \"undefined\" &&\n typeof performance.mark === \"function\" &&\n typeof performance.measure === \"function\"\n );\n};\n\n/**\n * Performance tracker interface with mark and measure methods.\n */\nexport interface PerformanceTracker {\n mark: (name: string) => void;\n measure: (measureName: string, startMark: string, endMark: string) => void;\n}\n\n/**\n * Creates a tracker for working with the Performance API.\n * Ignores calls if the API is unavailable.\n *\n * @param enabled - Whether the functionality is enabled (from config)\n * @param context - Context for error logging\n * @returns Object with mark and measure methods\n */\nexport const createPerformanceTracker = (\n enabled: boolean,\n context: string,\n): PerformanceTracker => {\n const isSupported = enabled && supportsPerformanceAPI();\n\n return {\n /**\n * Creates a performance mark with the specified name.\n */\n mark(name: string): void {\n if (!isSupported) {\n return;\n }\n\n performance.mark(name);\n },\n\n /**\n * Creates a performance measure between two marks.\n * Logs a warning if the marks don't exist.\n */\n measure(measureName: string, startMark: string, endMark: string): void {\n if (!isSupported) {\n return;\n }\n\n try {\n performance.measure(measureName, startMark, endMark);\n } catch (error) {\n console.warn(\n `[${context}] Failed to create performance measure: ${measureName}`,\n error,\n );\n }\n },\n };\n};\n","// packages/logger-plugin/src/internal/timing.ts\n\n/**\n * Function that returns high-resolution timestamp in milliseconds.\n */\ntype TimeProvider = () => number;\n\n/**\n * State for Date.now() monotonic emulation\n */\nlet lastTimestamp = 0;\nlet timeOffset = 0;\n\n/**\n * Creates monotonic Date.now() wrapper that ensures time never goes backwards.\n *\n * @returns Time provider function with monotonic guarantee\n */\nfunction createMonotonicDateNow(): TimeProvider {\n // eslint-disable-next-line unicorn/consistent-function-scoping -- closure over module-level lastTimestamp/timeOffset\n return (): number => {\n const current: number = Date.now();\n\n if (current < lastTimestamp) {\n timeOffset += lastTimestamp - current;\n }\n\n lastTimestamp = current;\n\n return current + timeOffset;\n };\n}\n\n/**\n * Initialize time provider based on environment.\n * Uses performance.now() in modern environments (Node.js 16+, all browsers),\n * falls back to monotonic Date.now() wrapper for edge cases.\n */\nconst nowFn: TimeProvider =\n typeof performance !== \"undefined\" && typeof performance.now === \"function\"\n ? (): number => performance.now()\n : createMonotonicDateNow();\n\n/**\n * Returns high-resolution monotonic timestamp.\n *\n * Uses performance.now() in modern environments (Node.js 16+, all browsers).\n * Falls back to monotonic Date.now() wrapper (~1ms precision) for edge cases.\n *\n * @returns Timestamp in milliseconds\n */\nexport const now = (): number => nowFn();\n","// packages/logger-plugin/src/plugin.ts\n\nimport {\n createGroupManager,\n supportsConsoleGroups,\n} from \"./internal/console-groups\";\nimport {\n formatRouteName,\n formatTiming,\n createTransitionLabel,\n} from \"./internal/formatting\";\nimport { getParamsDiff, logParamsDiff } from \"./internal/params-diff\";\nimport { createPerformanceTracker } from \"./internal/performance-marks\";\nimport { now } from \"./internal/timing\";\n\nimport type { GroupManager } from \"./internal/console-groups\";\nimport type { PerformanceTracker } from \"./internal/performance-marks\";\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { Plugin, RouterError, State } from \"@real-router/core\";\n\nexport class LoggerPlugin {\n readonly #logLifecycle: boolean;\n readonly #logTransition: boolean;\n readonly #logError: boolean;\n\n readonly #shouldLogParams: boolean;\n readonly #shouldShowTiming: boolean;\n readonly #usePerf: boolean;\n\n readonly #prefix: string;\n readonly #context: string;\n\n readonly #groups: GroupManager;\n readonly #perf: PerformanceTracker;\n\n // Transition state\n #transitionStartTime: number | null = null;\n #transitionLabel = \"\";\n #startMarkName = \"\";\n\n constructor(config: Required<LoggerPluginConfig>) {\n this.#logLifecycle = config.level === \"all\";\n this.#logTransition = config.level !== \"none\" && config.level !== \"errors\";\n this.#logError = config.level !== \"none\";\n\n this.#shouldLogParams = this.#logTransition && config.showParamsDiff;\n this.#shouldShowTiming = config.showTiming;\n this.#usePerf = config.usePerformanceMarks;\n\n this.#prefix = `[${config.context}]`;\n this.#context = config.context;\n\n this.#groups = createGroupManager(supportsConsoleGroups());\n this.#perf = createPerformanceTracker(\n config.usePerformanceMarks,\n config.context,\n );\n }\n\n getPlugin(): Plugin {\n return {\n onStart: () => {\n this.#perf.mark(\"router:start\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router started`);\n }\n },\n\n onStop: () => {\n this.#groups.close();\n\n this.#perf.mark(\"router:stop\");\n this.#perf.measure(\"router:lifetime\", \"router:start\", \"router:stop\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router stopped`);\n }\n },\n\n onTransitionStart: (toState: State, fromState?: State) => {\n this.#groups.open(\"Router transition\");\n this.#transitionStartTime = this.#shouldShowTiming ? now() : null;\n\n const fromRoute = formatRouteName(fromState);\n const toRoute = formatRouteName(toState);\n\n if (this.#usePerf) {\n this.#transitionLabel = createTransitionLabel(fromRoute, toRoute);\n this.#startMarkName = `router:transition-start:${this.#transitionLabel}`;\n this.#perf.mark(this.#startMarkName);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Transition: ${fromRoute} → ${toRoute}`, {\n from: fromState,\n to: toState,\n });\n\n this.#logParamsIfNeeded(toState, fromState);\n }\n },\n\n onTransitionSuccess: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const endMark = `router:transition-end:${label}`;\n\n this.#perf.mark(endMark);\n this.#perf.measure(\n `router:transition:${label}`,\n this.#startMarkName,\n endMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.log(`${this.#prefix} Transition success${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionCancel: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const cancelMark = `router:transition-cancel:${label}`;\n\n this.#perf.mark(cancelMark);\n this.#perf.measure(\n `router:transition-cancelled:${label}`,\n this.#startMarkName,\n cancelMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.warn(`${this.#prefix} Transition cancelled${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionError: (\n toState: State | undefined,\n fromState: State | undefined,\n err: RouterError,\n ) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const errorMark = `router:transition-error:${label}`;\n\n this.#perf.mark(errorMark);\n this.#perf.measure(\n `router:transition-failed:${label}`,\n this.#startMarkName,\n errorMark,\n );\n }\n\n if (this.#logError) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.error(\n `${this.#prefix} Transition error: ${err.code}${timing}`,\n {\n error: err,\n stack: err.stack,\n to: toState,\n from: fromState,\n },\n );\n }\n\n this.#resetTransitionState();\n },\n\n teardown: () => {\n this.#resetTransitionState();\n },\n };\n }\n\n #logParamsIfNeeded(toState: State, fromState?: State): void {\n if (!this.#shouldLogParams || !fromState) {\n return;\n }\n\n if (toState.name !== fromState.name) {\n return;\n }\n\n const diff = getParamsDiff(fromState.params, toState.params);\n\n if (diff) {\n logParamsDiff(diff, this.#context);\n }\n }\n\n #resetTransitionState(): void {\n this.#groups.close();\n this.#transitionLabel = \"\";\n this.#startMarkName = \"\";\n this.#transitionStartTime = null;\n }\n}\n","// packages/logger-plugin/src/validation.ts\n\nimport { ERROR_PREFIX } from \"./constants\";\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nconst VALID_LEVELS = new Set([\"all\", \"transitions\", \"errors\", \"none\"]);\n\nexport function validateOptions(options?: Partial<LoggerPluginConfig>): void {\n if (options === undefined) {\n return;\n }\n\n // Runtime defense: typeof null === \"object\", so check identity first.\n // TypeScript excludes null from the parameter type, but JS callers may pass it.\n if (options === (null as never) || typeof options !== \"object\") {\n throw new TypeError(`${ERROR_PREFIX} Options must be an object`);\n }\n\n if (options.level !== undefined && !VALID_LEVELS.has(options.level)) {\n throw new TypeError(\n `${ERROR_PREFIX} Invalid level: \"${options.level}\". Expected: ${[...VALID_LEVELS].join(\", \")}`,\n );\n }\n\n if (\n options.context !== undefined &&\n (typeof options.context !== \"string\" || options.context.length === 0)\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"context\" must be a non-empty string`,\n );\n }\n\n if (\n options.showTiming !== undefined &&\n typeof options.showTiming !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showTiming\" must be a boolean`,\n );\n }\n\n if (\n options.showParamsDiff !== undefined &&\n typeof options.showParamsDiff !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showParamsDiff\" must be a boolean`,\n );\n }\n\n if (\n options.usePerformanceMarks !== undefined &&\n typeof options.usePerformanceMarks !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"usePerformanceMarks\" must be a boolean`,\n );\n }\n}\n","// packages/logger-plugin/src/factory.ts\n\nimport { DEFAULT_CONFIG } from \"./constants\";\nimport { LoggerPlugin } from \"./plugin\";\nimport { validateOptions } from \"./validation\";\n\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { PluginFactory } from \"@real-router/core\";\n\nexport function loggerPluginFactory(\n options?: Partial<LoggerPluginConfig>,\n): PluginFactory {\n validateOptions(options);\n\n const config: Required<LoggerPluginConfig> = {\n ...DEFAULT_CONFIG,\n ...options,\n };\n\n return () => new LoggerPlugin(config).getPlugin();\n}\n"],"mappings":"mEAIA,MAAa,EAAiB,gBAEjB,EAAe,iBAAiB,EAAe,GAE/C,EAA+C,CAC1D,MAAO,MACP,oBAAqB,GACrB,eAAgB,GAChB,WAAY,GACZ,QAAS,EACV,CCTY,MAET,OAAO,QAAY,KACnB,OAAO,QAAQ,OAAU,YACz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AC,MAAO,cAAe,SAAU,OAAO,CAAC,CAEtE,SAAgB,EAAgB,EAA6C,CACvE,OAAY,IAAA,GAMhB,IAAmC,OAAO,GAAY,WAAlD,EACF,MAAU,UAAU,GAAG,EAAa,4BAA4B,CAGlE,GAAI,EAAQ,QAAU,IAAA,IAAa,CAAC,EAAa,IAAI,EAAQ,MAAM,CACjE,MAAU,UACR,GAAG,EAAa,mBAAmB,EAAQ,MAAM,eAAe,CAAC,GAAG,EAAa,CAAC,KAAK,KAAK,GAC7F,CAGH,GACE,EAAQ,UAAY,IAAA,KACnB,OAAO,EAAQ,SAAY,UAAY,EAAQ,QAAQ,SAAW,GAEnE,MAAU,UACR,GAAG,EAAa,8CACjB,CAGH,GACE,EAAQ,aAAe,IAAA,IACvB,OAAO,EAAQ,YAAe,UAE9B,MAAU,UACR,GAAG,EAAa,wCACjB,CAGH,GACE,EAAQ,iBAAmB,IAAA,IAC3B,OAAO,EAAQ,gBAAmB,UAElC,MAAU,UACR,GAAG,EAAa,4CACjB,CAGH,GACE,EAAQ,sBAAwB,IAAA,IAChC,OAAO,EAAQ,qBAAwB,UAEvC,MAAU,UACR,GAAG,EAAa,iDACjB,ECjDL,SAAgB,EACd,EACe,CACf,EAAgB,EAAQ,CAExB,IAAM,EAAuC,CAC3C,GAAG,EACH,GAAG,EACJ,CAED,UAAa,IAAI,EAAa,EAAO,CAAC,WAAW"}
1
+ {"version":3,"file":"index.js","names":["#logLifecycle","#logTransition","#logError","#shouldLogParams","#shouldShowTiming","#usePerf","#prefix","#context","#groups","#perf","#transitionStartTime","#transitionLabel","#startMarkName","#logParamsIfNeeded","#resetTransitionState"],"sources":["../../src/constants.ts","../../src/internal/console-groups.ts","../../src/internal/formatting.ts","../../src/internal/params-diff.ts","../../src/internal/performance-marks.ts","../../src/internal/timing.ts","../../src/plugin.ts","../../src/validation.ts","../../src/factory.ts"],"sourcesContent":["// packages/logger-plugin/src/constants.ts\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nexport const LOGGER_CONTEXT = \"logger-plugin\";\n\nexport const ERROR_PREFIX = `[@real-router/${LOGGER_CONTEXT}]`;\n\nexport const DEFAULT_CONFIG: Required<LoggerPluginConfig> = {\n level: \"all\",\n usePerformanceMarks: false,\n showParamsDiff: true,\n showTiming: true,\n context: LOGGER_CONTEXT,\n};\n","// packages/logger-plugin/src/internal/console-groups.ts\n\n/**\n * Checks if console.group is supported in the current environment.\n */\nexport const supportsConsoleGroups = (): boolean => {\n return (\n typeof console !== \"undefined\" &&\n typeof console.group === \"function\" &&\n typeof console.groupEnd === \"function\"\n );\n};\n\n/**\n * Manager for handling console groups\n */\nexport interface GroupManager {\n /**\n * Opens a group if it's not already open\n */\n open: (label: string) => void;\n /**\n * Closes a group if it's open\n */\n close: () => void;\n /**\n * Checks if a group is currently open\n */\n isOpen: () => boolean;\n}\n\n/**\n * Creates a manager for handling console groups.\n * Prevents duplicate group opening.\n *\n * @param enabled - Whether groups are supported in the environment\n * @returns Object with open and close methods\n */\nexport const createGroupManager = (enabled: boolean): GroupManager => {\n let isOpened = false;\n\n return {\n /**\n * Opens a group if it's not already open.\n */\n open(label: string): void {\n if (!enabled || isOpened) {\n return;\n }\n\n console.group(label);\n isOpened = true;\n },\n\n /**\n * Closes a group if it's open.\n */\n close(): void {\n if (!enabled || !isOpened) {\n return;\n }\n\n console.groupEnd();\n isOpened = false;\n },\n\n /**\n * Checks if a group is currently open.\n */\n isOpen(): boolean {\n return isOpened;\n },\n };\n};\n","// packages/logger-plugin/src/internal/formatting.ts\n\nimport type { State } from \"@real-router/core\";\n\n/**\n * Formats route name for logging output.\n * Handles undefined/null.\n */\nexport const formatRouteName = (state?: State): string => {\n return state?.name ?? \"(none)\";\n};\n\n/**\n * Formats execution time information.\n * Uses adaptive units:\n * - Microseconds (μs) for <0.1ms\n * - Milliseconds (ms) for ≥0.1ms\n *\n * @param startTime - Start time or null\n * @param now - Function to get current time\n * @returns String with time or empty string\n */\nexport const formatTiming = (\n startTime: number | null,\n now: () => number,\n): string => {\n if (startTime === null) {\n return \"\";\n }\n\n const durationMs = now() - startTime;\n\n if (!Number.isFinite(durationMs) || durationMs < 0) {\n return \" (?)\";\n }\n\n if (durationMs < 0.1) {\n const durationMks = (durationMs * 1000).toFixed(2);\n\n return ` (${durationMks}μs)`;\n } else {\n const duration = durationMs.toFixed(2);\n\n return ` (${duration}ms)`;\n }\n};\n\n/**\n * Creates a label for Performance API from route names.\n */\nexport const createTransitionLabel = (\n fromRoute: string,\n toRoute: string,\n): string => {\n return `${fromRoute}→${toRoute}`;\n};\n","// packages/logger-plugin/src/internal/params-diff.ts\n\nimport type { Params } from \"@real-router/core\";\n\nexport interface ParamsDiff {\n changed: Record<string, { from: unknown; to: unknown }>;\n added: Record<string, unknown>;\n removed: Record<string, unknown>;\n}\n\n/**\n * Calculates differences between two parameter objects.\n * Performs only shallow comparison.\n *\n * @param fromParams - Previous parameters\n * @param toParams - New parameters\n * @returns Object with differences or null if there are no changes\n */\nexport const getParamsDiff = (\n fromParams: Params,\n toParams: Params,\n): ParamsDiff | null => {\n const changed: ParamsDiff[\"changed\"] = {};\n const added: ParamsDiff[\"added\"] = {};\n const removed: ParamsDiff[\"removed\"] = {};\n\n // Track if any changes found to avoid iterating through objects at the end.\n // This is a performance optimization: instead of calling Object.keys().length\n // three times to check if objects are empty, we set this flag when we find\n // any change and check it once at the end.\n let hasChanges = false;\n\n // Find changed and removed\n for (const key in fromParams) {\n if (!(key in toParams)) {\n removed[key] = fromParams[key];\n hasChanges = true;\n } else if (fromParams[key] !== toParams[key]) {\n changed[key] = { from: fromParams[key], to: toParams[key] };\n hasChanges = true;\n }\n }\n\n // Find added\n for (const key in toParams) {\n if (!(key in fromParams)) {\n added[key] = toParams[key];\n hasChanges = true;\n }\n }\n\n // Return null if there are no changes\n if (!hasChanges) {\n return null;\n }\n\n return { changed, added, removed };\n};\n\n/**\n * Formats and logs parameter differences.\n *\n * @param diff - Object with differences\n * @param context - Context for console\n */\nexport const logParamsDiff = (diff: ParamsDiff, context: string): void => {\n const parts: string[] = [];\n\n // Cache entries to avoid double iteration\n const changedEntries = Object.entries(diff.changed);\n\n if (changedEntries.length > 0) {\n const items: string[] = [];\n\n for (const [key, { from, to }] of changedEntries) {\n items.push(`${key}: ${JSON.stringify(from)} → ${JSON.stringify(to)}`);\n }\n\n parts.push(`Changed: { ${items.join(\", \")} }`);\n }\n\n if (Object.keys(diff.added).length > 0) {\n parts.push(`Added: ${JSON.stringify(diff.added)}`);\n }\n\n if (Object.keys(diff.removed).length > 0) {\n parts.push(`Removed: ${JSON.stringify(diff.removed)}`);\n }\n\n console.log(`[${context}] ${parts.join(\", \")}`);\n};\n","// packages/logger-plugin/src/internal/performance-marks.ts\n\n/**\n * Checks if Performance API is supported in the current environment.\n */\nexport const supportsPerformanceAPI = (): boolean => {\n return (\n typeof performance !== \"undefined\" &&\n typeof performance.mark === \"function\" &&\n typeof performance.measure === \"function\"\n );\n};\n\n/**\n * Performance tracker interface with mark and measure methods.\n */\nexport interface PerformanceTracker {\n mark: (name: string) => void;\n measure: (measureName: string, startMark: string, endMark: string) => void;\n}\n\n/**\n * Creates a tracker for working with the Performance API.\n * Ignores calls if the API is unavailable.\n *\n * @param enabled - Whether the functionality is enabled (from config)\n * @param context - Context for error logging\n * @returns Object with mark and measure methods\n */\nexport const createPerformanceTracker = (\n enabled: boolean,\n context: string,\n): PerformanceTracker => {\n const isSupported = enabled && supportsPerformanceAPI();\n\n return {\n /**\n * Creates a performance mark with the specified name.\n */\n mark(name: string): void {\n if (!isSupported) {\n return;\n }\n\n performance.mark(name);\n },\n\n /**\n * Creates a performance measure between two marks.\n * Logs a warning if the marks don't exist.\n */\n measure(measureName: string, startMark: string, endMark: string): void {\n if (!isSupported) {\n return;\n }\n\n try {\n performance.measure(measureName, startMark, endMark);\n } catch (error) {\n console.warn(\n `[${context}] Failed to create performance measure: ${measureName}`,\n error,\n );\n }\n },\n };\n};\n","// packages/logger-plugin/src/internal/timing.ts\n\n/**\n * Function that returns high-resolution timestamp in milliseconds.\n */\ntype TimeProvider = () => number;\n\n/**\n * State for Date.now() monotonic emulation\n */\nlet lastTimestamp = 0;\nlet timeOffset = 0;\n\n/**\n * Creates monotonic Date.now() wrapper that ensures time never goes backwards.\n *\n * @returns Time provider function with monotonic guarantee\n */\nfunction createMonotonicDateNow(): TimeProvider {\n // eslint-disable-next-line unicorn/consistent-function-scoping -- closure over module-level lastTimestamp/timeOffset\n return (): number => {\n const current: number = Date.now();\n\n if (current < lastTimestamp) {\n timeOffset += lastTimestamp - current;\n }\n\n lastTimestamp = current;\n\n return current + timeOffset;\n };\n}\n\n/**\n * Initialize time provider based on environment.\n * Uses performance.now() in modern environments (Node.js 16+, all browsers),\n * falls back to monotonic Date.now() wrapper for edge cases.\n */\nconst nowFn: TimeProvider =\n typeof performance !== \"undefined\" && typeof performance.now === \"function\"\n ? (): number => performance.now()\n : createMonotonicDateNow();\n\n/**\n * Returns high-resolution monotonic timestamp.\n *\n * Uses performance.now() in modern environments (Node.js 16+, all browsers).\n * Falls back to monotonic Date.now() wrapper (~1ms precision) for edge cases.\n *\n * @returns Timestamp in milliseconds\n */\nexport const now = (): number => nowFn();\n","// packages/logger-plugin/src/plugin.ts\n\nimport {\n createGroupManager,\n supportsConsoleGroups,\n} from \"./internal/console-groups\";\nimport {\n formatRouteName,\n formatTiming,\n createTransitionLabel,\n} from \"./internal/formatting\";\nimport { getParamsDiff, logParamsDiff } from \"./internal/params-diff\";\nimport { createPerformanceTracker } from \"./internal/performance-marks\";\nimport { now } from \"./internal/timing\";\n\nimport type { GroupManager } from \"./internal/console-groups\";\nimport type { PerformanceTracker } from \"./internal/performance-marks\";\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { Plugin, RouterError, State } from \"@real-router/core\";\n\nexport class LoggerPlugin {\n readonly #logLifecycle: boolean;\n readonly #logTransition: boolean;\n readonly #logError: boolean;\n\n readonly #shouldLogParams: boolean;\n readonly #shouldShowTiming: boolean;\n readonly #usePerf: boolean;\n\n readonly #prefix: string;\n readonly #context: string;\n\n readonly #groups: GroupManager;\n readonly #perf: PerformanceTracker;\n\n // Transition state\n #transitionStartTime: number | null = null;\n #transitionLabel = \"\";\n #startMarkName = \"\";\n\n constructor(config: Required<LoggerPluginConfig>) {\n this.#logLifecycle = config.level === \"all\";\n this.#logTransition = config.level !== \"none\" && config.level !== \"errors\";\n this.#logError = config.level !== \"none\";\n\n this.#shouldLogParams = this.#logTransition && config.showParamsDiff;\n this.#shouldShowTiming = config.showTiming;\n this.#usePerf = config.usePerformanceMarks;\n\n this.#prefix = `[${config.context}]`;\n this.#context = config.context;\n\n this.#groups = createGroupManager(supportsConsoleGroups());\n this.#perf = createPerformanceTracker(\n config.usePerformanceMarks,\n config.context,\n );\n }\n\n getPlugin(): Plugin {\n return {\n onStart: () => {\n this.#perf.mark(\"router:start\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router started`);\n }\n },\n\n onStop: () => {\n this.#groups.close();\n\n this.#perf.mark(\"router:stop\");\n this.#perf.measure(\"router:lifetime\", \"router:start\", \"router:stop\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router stopped`);\n }\n },\n\n onTransitionStart: (toState: State, fromState?: State) => {\n this.#groups.open(\"Router transition\");\n this.#transitionStartTime = this.#shouldShowTiming ? now() : null;\n\n const fromRoute = formatRouteName(fromState);\n const toRoute = formatRouteName(toState);\n\n if (this.#usePerf) {\n this.#transitionLabel = createTransitionLabel(fromRoute, toRoute);\n this.#startMarkName = `router:transition-start:${this.#transitionLabel}`;\n this.#perf.mark(this.#startMarkName);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Transition: ${fromRoute} → ${toRoute}`, {\n from: fromState,\n to: toState,\n });\n\n this.#logParamsIfNeeded(toState, fromState);\n }\n },\n\n onTransitionLeaveApprove: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n this.#perf.mark(`router:leave-approved:${this.#transitionLabel}`);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Leave approved`, {\n to: toState,\n from: fromState,\n });\n }\n },\n\n onTransitionSuccess: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const endMark = `router:transition-end:${label}`;\n\n this.#perf.mark(endMark);\n this.#perf.measure(\n `router:transition:${label}`,\n this.#startMarkName,\n endMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.log(`${this.#prefix} Transition success${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionCancel: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const cancelMark = `router:transition-cancel:${label}`;\n\n this.#perf.mark(cancelMark);\n this.#perf.measure(\n `router:transition-cancelled:${label}`,\n this.#startMarkName,\n cancelMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.warn(`${this.#prefix} Transition cancelled${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionError: (\n toState: State | undefined,\n fromState: State | undefined,\n err: RouterError,\n ) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const errorMark = `router:transition-error:${label}`;\n\n this.#perf.mark(errorMark);\n this.#perf.measure(\n `router:transition-failed:${label}`,\n this.#startMarkName,\n errorMark,\n );\n }\n\n if (this.#logError) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.error(\n `${this.#prefix} Transition error: ${err.code}${timing}`,\n {\n error: err,\n stack: err.stack,\n to: toState,\n from: fromState,\n },\n );\n }\n\n this.#resetTransitionState();\n },\n\n teardown: () => {\n this.#resetTransitionState();\n },\n };\n }\n\n #logParamsIfNeeded(toState: State, fromState?: State): void {\n if (!this.#shouldLogParams || !fromState) {\n return;\n }\n\n if (toState.name !== fromState.name) {\n return;\n }\n\n const diff = getParamsDiff(fromState.params, toState.params);\n\n if (diff) {\n logParamsDiff(diff, this.#context);\n }\n }\n\n #resetTransitionState(): void {\n this.#groups.close();\n this.#transitionLabel = \"\";\n this.#startMarkName = \"\";\n this.#transitionStartTime = null;\n }\n}\n","// packages/logger-plugin/src/validation.ts\n\nimport { ERROR_PREFIX } from \"./constants\";\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nconst VALID_LEVELS = new Set([\"all\", \"transitions\", \"errors\", \"none\"]);\n\nexport function validateOptions(options?: Partial<LoggerPluginConfig>): void {\n if (options === undefined) {\n return;\n }\n\n // Runtime defense: typeof null === \"object\", so check identity first.\n // TypeScript excludes null from the parameter type, but JS callers may pass it.\n if (options === (null as never) || typeof options !== \"object\") {\n throw new TypeError(`${ERROR_PREFIX} Options must be an object`);\n }\n\n if (options.level !== undefined && !VALID_LEVELS.has(options.level)) {\n throw new TypeError(\n `${ERROR_PREFIX} Invalid level: \"${options.level}\". Expected: ${[...VALID_LEVELS].join(\", \")}`,\n );\n }\n\n if (\n options.context !== undefined &&\n (typeof options.context !== \"string\" || options.context.length === 0)\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"context\" must be a non-empty string`,\n );\n }\n\n if (\n options.showTiming !== undefined &&\n typeof options.showTiming !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showTiming\" must be a boolean`,\n );\n }\n\n if (\n options.showParamsDiff !== undefined &&\n typeof options.showParamsDiff !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showParamsDiff\" must be a boolean`,\n );\n }\n\n if (\n options.usePerformanceMarks !== undefined &&\n typeof options.usePerformanceMarks !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"usePerformanceMarks\" must be a boolean`,\n );\n }\n}\n","// packages/logger-plugin/src/factory.ts\n\nimport { DEFAULT_CONFIG } from \"./constants\";\nimport { LoggerPlugin } from \"./plugin\";\nimport { validateOptions } from \"./validation\";\n\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { PluginFactory } from \"@real-router/core\";\n\nexport function loggerPluginFactory(\n options?: Partial<LoggerPluginConfig>,\n): PluginFactory {\n validateOptions(options);\n\n const config: Required<LoggerPluginConfig> = {\n ...DEFAULT_CONFIG,\n ...options,\n };\n\n return () => new LoggerPlugin(config).getPlugin();\n}\n"],"mappings":"mEAIA,MAAa,EAAiB,gBAEjB,EAAe,iBAAiB,EAAe,GAE/C,EAA+C,CAC1D,MAAO,MACP,oBAAqB,GACrB,eAAgB,GAChB,WAAY,GACZ,QAAS,EACV,CCTY,MAET,OAAO,QAAY,KACnB,OAAO,QAAQ,OAAU,YACzB,OAAO,QAAQ,UAAa,WA6BnB,EAAsB,GAAmC,CACpE,IAAI,EAAW,GAEf,MAAO,CAIL,KAAK,EAAqB,CACpB,CAAC,GAAW,IAIhB,QAAQ,MAAM,EAAM,CACpB,EAAW,KAMb,OAAc,CACR,CAAC,GAAW,CAAC,IAIjB,QAAQ,UAAU,CAClB,EAAW,KAMb,QAAkB,CAChB,OAAO,GAEV,EChEU,EAAmB,GACvB,GAAO,MAAQ,SAaX,GACX,EACA,IACW,CACX,GAAI,IAAc,KAChB,MAAO,GAGT,IAAM,EAAa,GAAK,CAAG,EAazB,MAXE,CAAC,OAAO,SAAS,EAAW,EAAI,EAAa,EACxC,OAGL,EAAa,GAGR,MAFc,EAAa,KAAM,QAAQ,EAAE,CAE1B,KAIjB,KAFU,EAAW,QAAQ,EAAE,CAEjB,MAOZ,GACX,EACA,IAEO,GAAG,EAAU,GAAG,ICpCZ,GACX,EACA,IACsB,CACtB,IAAM,EAAiC,EAAE,CACnC,EAA6B,EAAE,CAC/B,EAAiC,EAAE,CAMrC,EAAa,GAGjB,IAAK,IAAM,KAAO,EACV,KAAO,EAGF,EAAW,KAAS,EAAS,KACtC,EAAQ,GAAO,CAAE,KAAM,EAAW,GAAM,GAAI,EAAS,GAAM,CAC3D,EAAa,KA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AAG,EAAa,4CACjB,CAGH,GACE,EAAQ,sBAAwB,IAAA,IAChC,OAAO,EAAQ,qBAAwB,UAEvC,MAAU,UACR,GAAG,EAAa,iDACjB,ECjDL,SAAgB,EACd,EACe,CACf,EAAgB,EAAQ,CAExB,IAAM,EAAuC,CAC3C,GAAG,EACH,GAAG,EACJ,CAED,UAAa,IAAI,EAAa,EAAO,CAAC,WAAW"}
@@ -1,2 +1,2 @@
1
- const e=`logger-plugin`,t=`[@real-router/${e}]`,n={level:`all`,usePerformanceMarks:!1,showParamsDiff:!0,showTiming:!0,context:e},r=()=>typeof console<`u`&&typeof console.group==`function`&&typeof console.groupEnd==`function`,i=e=>{let t=!1;return{open(n){!e||t||(console.group(n),t=!0)},close(){!e||!t||(console.groupEnd(),t=!1)},isOpen(){return t}}},a=e=>e?.name??`(none)`,o=(e,t)=>{if(e===null)return``;let n=t()-e;return!Number.isFinite(n)||n<0?` (?)`:n<.1?` (${(n*1e3).toFixed(2)}μs)`:` (${n.toFixed(2)}ms)`},s=(e,t)=>`${e}→${t}`,c=(e,t)=>{let n={},r={},i={},a=!1;for(let r in e)r in t?e[r]!==t[r]&&(n[r]={from:e[r],to:t[r]},a=!0):(i[r]=e[r],a=!0);for(let n in t)n in e||(r[n]=t[n],a=!0);return a?{changed:n,added:r,removed:i}:null},l=(e,t)=>{let n=[],r=Object.entries(e.changed);if(r.length>0){let e=[];for(let[t,{from:n,to:i}]of r)e.push(`${t}: ${JSON.stringify(n)} → ${JSON.stringify(i)}`);n.push(`Changed: { ${e.join(`, `)} }`)}Object.keys(e.added).length>0&&n.push(`Added: ${JSON.stringify(e.added)}`),Object.keys(e.removed).length>0&&n.push(`Removed: ${JSON.stringify(e.removed)}`),console.log(`[${t}] ${n.join(`, `)}`)},u=()=>typeof performance<`u`&&typeof performance.mark==`function`&&typeof performance.measure==`function`,d=(e,t)=>{let n=e&&u();return{mark(e){n&&performance.mark(e)},measure(e,r,i){if(n)try{performance.measure(e,r,i)}catch(n){console.warn(`[${t}] Failed to create performance measure: ${e}`,n)}}}};let f=0,p=0;function m(){return()=>{let e=Date.now();return e<f&&(p+=f-e),f=e,e+p}}const h=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():m(),g=()=>h();var _=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=``;#f=``;constructor(e){this.#e=e.level===`all`,this.#t=e.level!==`none`&&e.level!==`errors`,this.#n=e.level!==`none`,this.#r=this.#t&&e.showParamsDiff,this.#i=e.showTiming,this.#a=e.usePerformanceMarks,this.#o=`[${e.context}]`,this.#s=e.context,this.#c=i(r()),this.#l=d(e.usePerformanceMarks,e.context)}getPlugin(){return{onStart:()=>{this.#l.mark(`router:start`),this.#e&&console.log(`${this.#o} Router started`)},onStop:()=>{this.#c.close(),this.#l.mark(`router:stop`),this.#l.measure(`router:lifetime`,`router:start`,`router:stop`),this.#e&&console.log(`${this.#o} Router stopped`)},onTransitionStart:(e,t)=>{this.#c.open(`Router transition`),this.#u=this.#i?g():null;let n=a(t),r=a(e);this.#a&&(this.#d=s(n,r),this.#f=`router:transition-start:${this.#d}`,this.#l.mark(this.#f)),this.#t&&(console.log(`${this.#o} Transition: ${n} → ${r}`,{from:t,to:e}),this.#p(e,t))},onTransitionSuccess:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-end:${e}`;this.#l.mark(t),this.#l.measure(`router:transition:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.log(`${this.#o} Transition success${n}`,{to:e,from:t})}this.#m()},onTransitionCancel:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-cancel:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-cancelled:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.warn(`${this.#o} Transition cancelled${n}`,{to:e,from:t})}this.#m()},onTransitionError:(e,t,n)=>{if(this.#a){let e=this.#d,t=`router:transition-error:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-failed:${e}`,this.#f,t)}if(this.#n){let r=this.#i?o(this.#u,g):``;console.error(`${this.#o} Transition error: ${n.code}${r}`,{error:n,stack:n.stack,to:e,from:t})}this.#m()},teardown:()=>{this.#m()}}}#p(e,t){if(!this.#r||!t||e.name!==t.name)return;let n=c(t.params,e.params);n&&l(n,this.#s)}#m(){this.#c.close(),this.#d=``,this.#f=``,this.#u=null}};const v=new Set([`all`,`transitions`,`errors`,`none`]);function y(e){if(e!==void 0){if(typeof e!=`object`||!e)throw TypeError(`${t} Options must be an object`);if(e.level!==void 0&&!v.has(e.level))throw TypeError(`${t} Invalid level: "${e.level}". Expected: ${[...v].join(`, `)}`);if(e.context!==void 0&&(typeof e.context!=`string`||e.context.length===0))throw TypeError(`${t} Option "context" must be a non-empty string`);if(e.showTiming!==void 0&&typeof e.showTiming!=`boolean`)throw TypeError(`${t} Option "showTiming" must be a boolean`);if(e.showParamsDiff!==void 0&&typeof e.showParamsDiff!=`boolean`)throw TypeError(`${t} Option "showParamsDiff" must be a boolean`);if(e.usePerformanceMarks!==void 0&&typeof e.usePerformanceMarks!=`boolean`)throw TypeError(`${t} Option "usePerformanceMarks" must be a boolean`)}}function b(e){y(e);let t={...n,...e};return()=>new _(t).getPlugin()}export{b as loggerPluginFactory};
1
+ const e=`logger-plugin`,t=`[@real-router/${e}]`,n={level:`all`,usePerformanceMarks:!1,showParamsDiff:!0,showTiming:!0,context:e},r=()=>typeof console<`u`&&typeof console.group==`function`&&typeof console.groupEnd==`function`,i=e=>{let t=!1;return{open(n){!e||t||(console.group(n),t=!0)},close(){!e||!t||(console.groupEnd(),t=!1)},isOpen(){return t}}},a=e=>e?.name??`(none)`,o=(e,t)=>{if(e===null)return``;let n=t()-e;return!Number.isFinite(n)||n<0?` (?)`:n<.1?` (${(n*1e3).toFixed(2)}μs)`:` (${n.toFixed(2)}ms)`},s=(e,t)=>`${e}→${t}`,c=(e,t)=>{let n={},r={},i={},a=!1;for(let r in e)r in t?e[r]!==t[r]&&(n[r]={from:e[r],to:t[r]},a=!0):(i[r]=e[r],a=!0);for(let n in t)n in e||(r[n]=t[n],a=!0);return a?{changed:n,added:r,removed:i}:null},l=(e,t)=>{let n=[],r=Object.entries(e.changed);if(r.length>0){let e=[];for(let[t,{from:n,to:i}]of r)e.push(`${t}: ${JSON.stringify(n)} → ${JSON.stringify(i)}`);n.push(`Changed: { ${e.join(`, `)} }`)}Object.keys(e.added).length>0&&n.push(`Added: ${JSON.stringify(e.added)}`),Object.keys(e.removed).length>0&&n.push(`Removed: ${JSON.stringify(e.removed)}`),console.log(`[${t}] ${n.join(`, `)}`)},u=()=>typeof performance<`u`&&typeof performance.mark==`function`&&typeof performance.measure==`function`,d=(e,t)=>{let n=e&&u();return{mark(e){n&&performance.mark(e)},measure(e,r,i){if(n)try{performance.measure(e,r,i)}catch(n){console.warn(`[${t}] Failed to create performance measure: ${e}`,n)}}}};let f=0,p=0;function m(){return()=>{let e=Date.now();return e<f&&(p+=f-e),f=e,e+p}}const h=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():m(),g=()=>h();var _=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=``;#f=``;constructor(e){this.#e=e.level===`all`,this.#t=e.level!==`none`&&e.level!==`errors`,this.#n=e.level!==`none`,this.#r=this.#t&&e.showParamsDiff,this.#i=e.showTiming,this.#a=e.usePerformanceMarks,this.#o=`[${e.context}]`,this.#s=e.context,this.#c=i(r()),this.#l=d(e.usePerformanceMarks,e.context)}getPlugin(){return{onStart:()=>{this.#l.mark(`router:start`),this.#e&&console.log(`${this.#o} Router started`)},onStop:()=>{this.#c.close(),this.#l.mark(`router:stop`),this.#l.measure(`router:lifetime`,`router:start`,`router:stop`),this.#e&&console.log(`${this.#o} Router stopped`)},onTransitionStart:(e,t)=>{this.#c.open(`Router transition`),this.#u=this.#i?g():null;let n=a(t),r=a(e);this.#a&&(this.#d=s(n,r),this.#f=`router:transition-start:${this.#d}`,this.#l.mark(this.#f)),this.#t&&(console.log(`${this.#o} Transition: ${n} → ${r}`,{from:t,to:e}),this.#p(e,t))},onTransitionLeaveApprove:(e,t)=>{this.#a&&this.#l.mark(`router:leave-approved:${this.#d}`),this.#t&&console.log(`${this.#o} Leave approved`,{to:e,from:t})},onTransitionSuccess:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-end:${e}`;this.#l.mark(t),this.#l.measure(`router:transition:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.log(`${this.#o} Transition success${n}`,{to:e,from:t})}this.#m()},onTransitionCancel:(e,t)=>{if(this.#a){let e=this.#d,t=`router:transition-cancel:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-cancelled:${e}`,this.#f,t)}if(this.#t){let n=this.#i?o(this.#u,g):``;console.warn(`${this.#o} Transition cancelled${n}`,{to:e,from:t})}this.#m()},onTransitionError:(e,t,n)=>{if(this.#a){let e=this.#d,t=`router:transition-error:${e}`;this.#l.mark(t),this.#l.measure(`router:transition-failed:${e}`,this.#f,t)}if(this.#n){let r=this.#i?o(this.#u,g):``;console.error(`${this.#o} Transition error: ${n.code}${r}`,{error:n,stack:n.stack,to:e,from:t})}this.#m()},teardown:()=>{this.#m()}}}#p(e,t){if(!this.#r||!t||e.name!==t.name)return;let n=c(t.params,e.params);n&&l(n,this.#s)}#m(){this.#c.close(),this.#d=``,this.#f=``,this.#u=null}};const v=new Set([`all`,`transitions`,`errors`,`none`]);function y(e){if(e!==void 0){if(typeof e!=`object`||!e)throw TypeError(`${t} Options must be an object`);if(e.level!==void 0&&!v.has(e.level))throw TypeError(`${t} Invalid level: "${e.level}". Expected: ${[...v].join(`, `)}`);if(e.context!==void 0&&(typeof e.context!=`string`||e.context.length===0))throw TypeError(`${t} Option "context" must be a non-empty string`);if(e.showTiming!==void 0&&typeof e.showTiming!=`boolean`)throw TypeError(`${t} Option "showTiming" must be a boolean`);if(e.showParamsDiff!==void 0&&typeof e.showParamsDiff!=`boolean`)throw TypeError(`${t} Option "showParamsDiff" must be a boolean`);if(e.usePerformanceMarks!==void 0&&typeof e.usePerformanceMarks!=`boolean`)throw TypeError(`${t} Option "usePerformanceMarks" must be a boolean`)}}function b(e){y(e);let t={...n,...e};return()=>new _(t).getPlugin()}export{b as loggerPluginFactory};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#logLifecycle","#logTransition","#logError","#shouldLogParams","#shouldShowTiming","#usePerf","#prefix","#context","#groups","#perf","#transitionStartTime","#transitionLabel","#startMarkName","#logParamsIfNeeded","#resetTransitionState"],"sources":["../../src/constants.ts","../../src/internal/console-groups.ts","../../src/internal/formatting.ts","../../src/internal/params-diff.ts","../../src/internal/performance-marks.ts","../../src/internal/timing.ts","../../src/plugin.ts","../../src/validation.ts","../../src/factory.ts"],"sourcesContent":["// packages/logger-plugin/src/constants.ts\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nexport const LOGGER_CONTEXT = \"logger-plugin\";\n\nexport const ERROR_PREFIX = `[@real-router/${LOGGER_CONTEXT}]`;\n\nexport const DEFAULT_CONFIG: Required<LoggerPluginConfig> = {\n level: \"all\",\n usePerformanceMarks: false,\n showParamsDiff: true,\n showTiming: true,\n context: LOGGER_CONTEXT,\n};\n","// packages/logger-plugin/src/internal/console-groups.ts\n\n/**\n * Checks if console.group is supported in the current environment.\n */\nexport const supportsConsoleGroups = (): boolean => {\n return (\n typeof console !== \"undefined\" &&\n typeof console.group === \"function\" &&\n typeof console.groupEnd === \"function\"\n );\n};\n\n/**\n * Manager for handling console groups\n */\nexport interface GroupManager {\n /**\n * Opens a group if it's not already open\n */\n open: (label: string) => void;\n /**\n * Closes a group if it's open\n */\n close: () => void;\n /**\n * Checks if a group is currently open\n */\n isOpen: () => boolean;\n}\n\n/**\n * Creates a manager for handling console groups.\n * Prevents duplicate group opening.\n *\n * @param enabled - Whether groups are supported in the environment\n * @returns Object with open and close methods\n */\nexport const createGroupManager = (enabled: boolean): GroupManager => {\n let isOpened = false;\n\n return {\n /**\n * Opens a group if it's not already open.\n */\n open(label: string): void {\n if (!enabled || isOpened) {\n return;\n }\n\n console.group(label);\n isOpened = true;\n },\n\n /**\n * Closes a group if it's open.\n */\n close(): void {\n if (!enabled || !isOpened) {\n return;\n }\n\n console.groupEnd();\n isOpened = false;\n },\n\n /**\n * Checks if a group is currently open.\n */\n isOpen(): boolean {\n return isOpened;\n },\n };\n};\n","// packages/logger-plugin/src/internal/formatting.ts\n\nimport type { State } from \"@real-router/core\";\n\n/**\n * Formats route name for logging output.\n * Handles undefined/null.\n */\nexport const formatRouteName = (state?: State): string => {\n return state?.name ?? \"(none)\";\n};\n\n/**\n * Formats execution time information.\n * Uses adaptive units:\n * - Microseconds (μs) for <0.1ms\n * - Milliseconds (ms) for ≥0.1ms\n *\n * @param startTime - Start time or null\n * @param now - Function to get current time\n * @returns String with time or empty string\n */\nexport const formatTiming = (\n startTime: number | null,\n now: () => number,\n): string => {\n if (startTime === null) {\n return \"\";\n }\n\n const durationMs = now() - startTime;\n\n if (!Number.isFinite(durationMs) || durationMs < 0) {\n return \" (?)\";\n }\n\n if (durationMs < 0.1) {\n const durationMks = (durationMs * 1000).toFixed(2);\n\n return ` (${durationMks}μs)`;\n } else {\n const duration = durationMs.toFixed(2);\n\n return ` (${duration}ms)`;\n }\n};\n\n/**\n * Creates a label for Performance API from route names.\n */\nexport const createTransitionLabel = (\n fromRoute: string,\n toRoute: string,\n): string => {\n return `${fromRoute}→${toRoute}`;\n};\n","// packages/logger-plugin/src/internal/params-diff.ts\n\nimport type { Params } from \"@real-router/core\";\n\nexport interface ParamsDiff {\n changed: Record<string, { from: unknown; to: unknown }>;\n added: Record<string, unknown>;\n removed: Record<string, unknown>;\n}\n\n/**\n * Calculates differences between two parameter objects.\n * Performs only shallow comparison.\n *\n * @param fromParams - Previous parameters\n * @param toParams - New parameters\n * @returns Object with differences or null if there are no changes\n */\nexport const getParamsDiff = (\n fromParams: Params,\n toParams: Params,\n): ParamsDiff | null => {\n const changed: ParamsDiff[\"changed\"] = {};\n const added: ParamsDiff[\"added\"] = {};\n const removed: ParamsDiff[\"removed\"] = {};\n\n // Track if any changes found to avoid iterating through objects at the end.\n // This is a performance optimization: instead of calling Object.keys().length\n // three times to check if objects are empty, we set this flag when we find\n // any change and check it once at the end.\n let hasChanges = false;\n\n // Find changed and removed\n for (const key in fromParams) {\n if (!(key in toParams)) {\n removed[key] = fromParams[key];\n hasChanges = true;\n } else if (fromParams[key] !== toParams[key]) {\n changed[key] = { from: fromParams[key], to: toParams[key] };\n hasChanges = true;\n }\n }\n\n // Find added\n for (const key in toParams) {\n if (!(key in fromParams)) {\n added[key] = toParams[key];\n hasChanges = true;\n }\n }\n\n // Return null if there are no changes\n if (!hasChanges) {\n return null;\n }\n\n return { changed, added, removed };\n};\n\n/**\n * Formats and logs parameter differences.\n *\n * @param diff - Object with differences\n * @param context - Context for console\n */\nexport const logParamsDiff = (diff: ParamsDiff, context: string): void => {\n const parts: string[] = [];\n\n // Cache entries to avoid double iteration\n const changedEntries = Object.entries(diff.changed);\n\n if (changedEntries.length > 0) {\n const items: string[] = [];\n\n for (const [key, { from, to }] of changedEntries) {\n items.push(`${key}: ${JSON.stringify(from)} → ${JSON.stringify(to)}`);\n }\n\n parts.push(`Changed: { ${items.join(\", \")} }`);\n }\n\n if (Object.keys(diff.added).length > 0) {\n parts.push(`Added: ${JSON.stringify(diff.added)}`);\n }\n\n if (Object.keys(diff.removed).length > 0) {\n parts.push(`Removed: ${JSON.stringify(diff.removed)}`);\n }\n\n console.log(`[${context}] ${parts.join(\", \")}`);\n};\n","// packages/logger-plugin/src/internal/performance-marks.ts\n\n/**\n * Checks if Performance API is supported in the current environment.\n */\nexport const supportsPerformanceAPI = (): boolean => {\n return (\n typeof performance !== \"undefined\" &&\n typeof performance.mark === \"function\" &&\n typeof performance.measure === \"function\"\n );\n};\n\n/**\n * Performance tracker interface with mark and measure methods.\n */\nexport interface PerformanceTracker {\n mark: (name: string) => void;\n measure: (measureName: string, startMark: string, endMark: string) => void;\n}\n\n/**\n * Creates a tracker for working with the Performance API.\n * Ignores calls if the API is unavailable.\n *\n * @param enabled - Whether the functionality is enabled (from config)\n * @param context - Context for error logging\n * @returns Object with mark and measure methods\n */\nexport const createPerformanceTracker = (\n enabled: boolean,\n context: string,\n): PerformanceTracker => {\n const isSupported = enabled && supportsPerformanceAPI();\n\n return {\n /**\n * Creates a performance mark with the specified name.\n */\n mark(name: string): void {\n if (!isSupported) {\n return;\n }\n\n performance.mark(name);\n },\n\n /**\n * Creates a performance measure between two marks.\n * Logs a warning if the marks don't exist.\n */\n measure(measureName: string, startMark: string, endMark: string): void {\n if (!isSupported) {\n return;\n }\n\n try {\n performance.measure(measureName, startMark, endMark);\n } catch (error) {\n console.warn(\n `[${context}] Failed to create performance measure: ${measureName}`,\n error,\n );\n }\n },\n };\n};\n","// packages/logger-plugin/src/internal/timing.ts\n\n/**\n * Function that returns high-resolution timestamp in milliseconds.\n */\ntype TimeProvider = () => number;\n\n/**\n * State for Date.now() monotonic emulation\n */\nlet lastTimestamp = 0;\nlet timeOffset = 0;\n\n/**\n * Creates monotonic Date.now() wrapper that ensures time never goes backwards.\n *\n * @returns Time provider function with monotonic guarantee\n */\nfunction createMonotonicDateNow(): TimeProvider {\n // eslint-disable-next-line unicorn/consistent-function-scoping -- closure over module-level lastTimestamp/timeOffset\n return (): number => {\n const current: number = Date.now();\n\n if (current < lastTimestamp) {\n timeOffset += lastTimestamp - current;\n }\n\n lastTimestamp = current;\n\n return current + timeOffset;\n };\n}\n\n/**\n * Initialize time provider based on environment.\n * Uses performance.now() in modern environments (Node.js 16+, all browsers),\n * falls back to monotonic Date.now() wrapper for edge cases.\n */\nconst nowFn: TimeProvider =\n typeof performance !== \"undefined\" && typeof performance.now === \"function\"\n ? (): number => performance.now()\n : createMonotonicDateNow();\n\n/**\n * Returns high-resolution monotonic timestamp.\n *\n * Uses performance.now() in modern environments (Node.js 16+, all browsers).\n * Falls back to monotonic Date.now() wrapper (~1ms precision) for edge cases.\n *\n * @returns Timestamp in milliseconds\n */\nexport const now = (): number => nowFn();\n","// packages/logger-plugin/src/plugin.ts\n\nimport {\n createGroupManager,\n supportsConsoleGroups,\n} from \"./internal/console-groups\";\nimport {\n formatRouteName,\n formatTiming,\n createTransitionLabel,\n} from \"./internal/formatting\";\nimport { getParamsDiff, logParamsDiff } from \"./internal/params-diff\";\nimport { createPerformanceTracker } from \"./internal/performance-marks\";\nimport { now } from \"./internal/timing\";\n\nimport type { GroupManager } from \"./internal/console-groups\";\nimport type { PerformanceTracker } from \"./internal/performance-marks\";\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { Plugin, RouterError, State } from \"@real-router/core\";\n\nexport class LoggerPlugin {\n readonly #logLifecycle: boolean;\n readonly #logTransition: boolean;\n readonly #logError: boolean;\n\n readonly #shouldLogParams: boolean;\n readonly #shouldShowTiming: boolean;\n readonly #usePerf: boolean;\n\n readonly #prefix: string;\n readonly #context: string;\n\n readonly #groups: GroupManager;\n readonly #perf: PerformanceTracker;\n\n // Transition state\n #transitionStartTime: number | null = null;\n #transitionLabel = \"\";\n #startMarkName = \"\";\n\n constructor(config: Required<LoggerPluginConfig>) {\n this.#logLifecycle = config.level === \"all\";\n this.#logTransition = config.level !== \"none\" && config.level !== \"errors\";\n this.#logError = config.level !== \"none\";\n\n this.#shouldLogParams = this.#logTransition && config.showParamsDiff;\n this.#shouldShowTiming = config.showTiming;\n this.#usePerf = config.usePerformanceMarks;\n\n this.#prefix = `[${config.context}]`;\n this.#context = config.context;\n\n this.#groups = createGroupManager(supportsConsoleGroups());\n this.#perf = createPerformanceTracker(\n config.usePerformanceMarks,\n config.context,\n );\n }\n\n getPlugin(): Plugin {\n return {\n onStart: () => {\n this.#perf.mark(\"router:start\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router started`);\n }\n },\n\n onStop: () => {\n this.#groups.close();\n\n this.#perf.mark(\"router:stop\");\n this.#perf.measure(\"router:lifetime\", \"router:start\", \"router:stop\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router stopped`);\n }\n },\n\n onTransitionStart: (toState: State, fromState?: State) => {\n this.#groups.open(\"Router transition\");\n this.#transitionStartTime = this.#shouldShowTiming ? now() : null;\n\n const fromRoute = formatRouteName(fromState);\n const toRoute = formatRouteName(toState);\n\n if (this.#usePerf) {\n this.#transitionLabel = createTransitionLabel(fromRoute, toRoute);\n this.#startMarkName = `router:transition-start:${this.#transitionLabel}`;\n this.#perf.mark(this.#startMarkName);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Transition: ${fromRoute} → ${toRoute}`, {\n from: fromState,\n to: toState,\n });\n\n this.#logParamsIfNeeded(toState, fromState);\n }\n },\n\n onTransitionSuccess: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const endMark = `router:transition-end:${label}`;\n\n this.#perf.mark(endMark);\n this.#perf.measure(\n `router:transition:${label}`,\n this.#startMarkName,\n endMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.log(`${this.#prefix} Transition success${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionCancel: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const cancelMark = `router:transition-cancel:${label}`;\n\n this.#perf.mark(cancelMark);\n this.#perf.measure(\n `router:transition-cancelled:${label}`,\n this.#startMarkName,\n cancelMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.warn(`${this.#prefix} Transition cancelled${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionError: (\n toState: State | undefined,\n fromState: State | undefined,\n err: RouterError,\n ) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const errorMark = `router:transition-error:${label}`;\n\n this.#perf.mark(errorMark);\n this.#perf.measure(\n `router:transition-failed:${label}`,\n this.#startMarkName,\n errorMark,\n );\n }\n\n if (this.#logError) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.error(\n `${this.#prefix} Transition error: ${err.code}${timing}`,\n {\n error: err,\n stack: err.stack,\n to: toState,\n from: fromState,\n },\n );\n }\n\n this.#resetTransitionState();\n },\n\n teardown: () => {\n this.#resetTransitionState();\n },\n };\n }\n\n #logParamsIfNeeded(toState: State, fromState?: State): void {\n if (!this.#shouldLogParams || !fromState) {\n return;\n }\n\n if (toState.name !== fromState.name) {\n return;\n }\n\n const diff = getParamsDiff(fromState.params, toState.params);\n\n if (diff) {\n logParamsDiff(diff, this.#context);\n }\n }\n\n #resetTransitionState(): void {\n this.#groups.close();\n this.#transitionLabel = \"\";\n this.#startMarkName = \"\";\n this.#transitionStartTime = null;\n }\n}\n","// packages/logger-plugin/src/validation.ts\n\nimport { ERROR_PREFIX } from \"./constants\";\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nconst VALID_LEVELS = new Set([\"all\", \"transitions\", \"errors\", \"none\"]);\n\nexport function validateOptions(options?: Partial<LoggerPluginConfig>): void {\n if (options === undefined) {\n return;\n }\n\n // Runtime defense: typeof null === \"object\", so check identity first.\n // TypeScript excludes null from the parameter type, but JS callers may pass it.\n if (options === (null as never) || typeof options !== \"object\") {\n throw new TypeError(`${ERROR_PREFIX} Options must be an object`);\n }\n\n if (options.level !== undefined && !VALID_LEVELS.has(options.level)) {\n throw new TypeError(\n `${ERROR_PREFIX} Invalid level: \"${options.level}\". Expected: ${[...VALID_LEVELS].join(\", \")}`,\n );\n }\n\n if (\n options.context !== undefined &&\n (typeof options.context !== \"string\" || options.context.length === 0)\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"context\" must be a non-empty string`,\n );\n }\n\n if (\n options.showTiming !== undefined &&\n typeof options.showTiming !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showTiming\" must be a boolean`,\n );\n }\n\n if (\n options.showParamsDiff !== undefined &&\n typeof options.showParamsDiff !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showParamsDiff\" must be a boolean`,\n );\n }\n\n if (\n options.usePerformanceMarks !== undefined &&\n typeof options.usePerformanceMarks !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"usePerformanceMarks\" must be a boolean`,\n );\n }\n}\n","// packages/logger-plugin/src/factory.ts\n\nimport { DEFAULT_CONFIG } from \"./constants\";\nimport { LoggerPlugin } from \"./plugin\";\nimport { validateOptions } from \"./validation\";\n\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { PluginFactory } from \"@real-router/core\";\n\nexport function loggerPluginFactory(\n options?: Partial<LoggerPluginConfig>,\n): PluginFactory {\n validateOptions(options);\n\n const config: Required<LoggerPluginConfig> = {\n ...DEFAULT_CONFIG,\n ...options,\n };\n\n return () => new LoggerPlugin(config).getPlugin();\n}\n"],"mappings":"AAIA,MAAa,EAAiB,gBAEjB,EAAe,iBAAiB,EAAe,GAE/C,EAA+C,CAC1D,MAAO,MACP,oBAAqB,GACrB,eAAgB,GAChB,WAAY,GACZ,QAAS,EACV,CCTY,MAET,OAAO,QAAY,KACnB,OAAO,QAAQ,OAAU,YACzB,OAAO,QAAQ,UAAa,WA6BnB,EAAsB,GAAmC,CACpE,IAAI,EAAW,GAEf,MAAO,CAIL,KAAK,EAAqB,CACpB,CAAC,GAAW,IAIhB,QAAQ,MAAM,EAAM,CACpB,EAAW,KAMb,OAAc,CACR,CAAC,GAAW,CAAC,IAIjB,QAAQ,UAAU,CAClB,EAAW,KAMb,QAAkB,CAChB,OAAO,GAEV,EChEU,EAAmB,GACvB,GAAO,MAAQ,SAaX,GACX,EACA,IACW,CACX,GAAI,IAAc,KAChB,MAAO,GAGT,IAAM,EAAa,GAAK,CAAG,EAazB,MAXE,CAAC,OAAO,SAAS,EAAW,E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AAW,GAEnE,MAAU,UACR,GAAG,EAAa,8CACjB,CAGH,GACE,EAAQ,aAAe,IAAA,IACvB,OAAO,EAAQ,YAAe,UAE9B,MAAU,UACR,GAAG,EAAa,wCACjB,CAGH,GACE,EAAQ,iBAAmB,IAAA,IAC3B,OAAO,EAAQ,gBAAmB,UAElC,MAAU,UACR,GAAG,EAAa,4CACjB,CAGH,GACE,EAAQ,sBAAwB,IAAA,IAChC,OAAO,EAAQ,qBAAwB,UAEvC,MAAU,UACR,GAAG,EAAa,iDACjB,ECjDL,SAAgB,EACd,EACe,CACf,EAAgB,EAAQ,CAExB,IAAM,EAAuC,CAC3C,GAAG,EACH,GAAG,EACJ,CAED,UAAa,IAAI,EAAa,EAAO,CAAC,WAAW"}
1
+ {"version":3,"file":"index.mjs","names":["#logLifecycle","#logTransition","#logError","#shouldLogParams","#shouldShowTiming","#usePerf","#prefix","#context","#groups","#perf","#transitionStartTime","#transitionLabel","#startMarkName","#logParamsIfNeeded","#resetTransitionState"],"sources":["../../src/constants.ts","../../src/internal/console-groups.ts","../../src/internal/formatting.ts","../../src/internal/params-diff.ts","../../src/internal/performance-marks.ts","../../src/internal/timing.ts","../../src/plugin.ts","../../src/validation.ts","../../src/factory.ts"],"sourcesContent":["// packages/logger-plugin/src/constants.ts\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nexport const LOGGER_CONTEXT = \"logger-plugin\";\n\nexport const ERROR_PREFIX = `[@real-router/${LOGGER_CONTEXT}]`;\n\nexport const DEFAULT_CONFIG: Required<LoggerPluginConfig> = {\n level: \"all\",\n usePerformanceMarks: false,\n showParamsDiff: true,\n showTiming: true,\n context: LOGGER_CONTEXT,\n};\n","// packages/logger-plugin/src/internal/console-groups.ts\n\n/**\n * Checks if console.group is supported in the current environment.\n */\nexport const supportsConsoleGroups = (): boolean => {\n return (\n typeof console !== \"undefined\" &&\n typeof console.group === \"function\" &&\n typeof console.groupEnd === \"function\"\n );\n};\n\n/**\n * Manager for handling console groups\n */\nexport interface GroupManager {\n /**\n * Opens a group if it's not already open\n */\n open: (label: string) => void;\n /**\n * Closes a group if it's open\n */\n close: () => void;\n /**\n * Checks if a group is currently open\n */\n isOpen: () => boolean;\n}\n\n/**\n * Creates a manager for handling console groups.\n * Prevents duplicate group opening.\n *\n * @param enabled - Whether groups are supported in the environment\n * @returns Object with open and close methods\n */\nexport const createGroupManager = (enabled: boolean): GroupManager => {\n let isOpened = false;\n\n return {\n /**\n * Opens a group if it's not already open.\n */\n open(label: string): void {\n if (!enabled || isOpened) {\n return;\n }\n\n console.group(label);\n isOpened = true;\n },\n\n /**\n * Closes a group if it's open.\n */\n close(): void {\n if (!enabled || !isOpened) {\n return;\n }\n\n console.groupEnd();\n isOpened = false;\n },\n\n /**\n * Checks if a group is currently open.\n */\n isOpen(): boolean {\n return isOpened;\n },\n };\n};\n","// packages/logger-plugin/src/internal/formatting.ts\n\nimport type { State } from \"@real-router/core\";\n\n/**\n * Formats route name for logging output.\n * Handles undefined/null.\n */\nexport const formatRouteName = (state?: State): string => {\n return state?.name ?? \"(none)\";\n};\n\n/**\n * Formats execution time information.\n * Uses adaptive units:\n * - Microseconds (μs) for <0.1ms\n * - Milliseconds (ms) for ≥0.1ms\n *\n * @param startTime - Start time or null\n * @param now - Function to get current time\n * @returns String with time or empty string\n */\nexport const formatTiming = (\n startTime: number | null,\n now: () => number,\n): string => {\n if (startTime === null) {\n return \"\";\n }\n\n const durationMs = now() - startTime;\n\n if (!Number.isFinite(durationMs) || durationMs < 0) {\n return \" (?)\";\n }\n\n if (durationMs < 0.1) {\n const durationMks = (durationMs * 1000).toFixed(2);\n\n return ` (${durationMks}μs)`;\n } else {\n const duration = durationMs.toFixed(2);\n\n return ` (${duration}ms)`;\n }\n};\n\n/**\n * Creates a label for Performance API from route names.\n */\nexport const createTransitionLabel = (\n fromRoute: string,\n toRoute: string,\n): string => {\n return `${fromRoute}→${toRoute}`;\n};\n","// packages/logger-plugin/src/internal/params-diff.ts\n\nimport type { Params } from \"@real-router/core\";\n\nexport interface ParamsDiff {\n changed: Record<string, { from: unknown; to: unknown }>;\n added: Record<string, unknown>;\n removed: Record<string, unknown>;\n}\n\n/**\n * Calculates differences between two parameter objects.\n * Performs only shallow comparison.\n *\n * @param fromParams - Previous parameters\n * @param toParams - New parameters\n * @returns Object with differences or null if there are no changes\n */\nexport const getParamsDiff = (\n fromParams: Params,\n toParams: Params,\n): ParamsDiff | null => {\n const changed: ParamsDiff[\"changed\"] = {};\n const added: ParamsDiff[\"added\"] = {};\n const removed: ParamsDiff[\"removed\"] = {};\n\n // Track if any changes found to avoid iterating through objects at the end.\n // This is a performance optimization: instead of calling Object.keys().length\n // three times to check if objects are empty, we set this flag when we find\n // any change and check it once at the end.\n let hasChanges = false;\n\n // Find changed and removed\n for (const key in fromParams) {\n if (!(key in toParams)) {\n removed[key] = fromParams[key];\n hasChanges = true;\n } else if (fromParams[key] !== toParams[key]) {\n changed[key] = { from: fromParams[key], to: toParams[key] };\n hasChanges = true;\n }\n }\n\n // Find added\n for (const key in toParams) {\n if (!(key in fromParams)) {\n added[key] = toParams[key];\n hasChanges = true;\n }\n }\n\n // Return null if there are no changes\n if (!hasChanges) {\n return null;\n }\n\n return { changed, added, removed };\n};\n\n/**\n * Formats and logs parameter differences.\n *\n * @param diff - Object with differences\n * @param context - Context for console\n */\nexport const logParamsDiff = (diff: ParamsDiff, context: string): void => {\n const parts: string[] = [];\n\n // Cache entries to avoid double iteration\n const changedEntries = Object.entries(diff.changed);\n\n if (changedEntries.length > 0) {\n const items: string[] = [];\n\n for (const [key, { from, to }] of changedEntries) {\n items.push(`${key}: ${JSON.stringify(from)} → ${JSON.stringify(to)}`);\n }\n\n parts.push(`Changed: { ${items.join(\", \")} }`);\n }\n\n if (Object.keys(diff.added).length > 0) {\n parts.push(`Added: ${JSON.stringify(diff.added)}`);\n }\n\n if (Object.keys(diff.removed).length > 0) {\n parts.push(`Removed: ${JSON.stringify(diff.removed)}`);\n }\n\n console.log(`[${context}] ${parts.join(\", \")}`);\n};\n","// packages/logger-plugin/src/internal/performance-marks.ts\n\n/**\n * Checks if Performance API is supported in the current environment.\n */\nexport const supportsPerformanceAPI = (): boolean => {\n return (\n typeof performance !== \"undefined\" &&\n typeof performance.mark === \"function\" &&\n typeof performance.measure === \"function\"\n );\n};\n\n/**\n * Performance tracker interface with mark and measure methods.\n */\nexport interface PerformanceTracker {\n mark: (name: string) => void;\n measure: (measureName: string, startMark: string, endMark: string) => void;\n}\n\n/**\n * Creates a tracker for working with the Performance API.\n * Ignores calls if the API is unavailable.\n *\n * @param enabled - Whether the functionality is enabled (from config)\n * @param context - Context for error logging\n * @returns Object with mark and measure methods\n */\nexport const createPerformanceTracker = (\n enabled: boolean,\n context: string,\n): PerformanceTracker => {\n const isSupported = enabled && supportsPerformanceAPI();\n\n return {\n /**\n * Creates a performance mark with the specified name.\n */\n mark(name: string): void {\n if (!isSupported) {\n return;\n }\n\n performance.mark(name);\n },\n\n /**\n * Creates a performance measure between two marks.\n * Logs a warning if the marks don't exist.\n */\n measure(measureName: string, startMark: string, endMark: string): void {\n if (!isSupported) {\n return;\n }\n\n try {\n performance.measure(measureName, startMark, endMark);\n } catch (error) {\n console.warn(\n `[${context}] Failed to create performance measure: ${measureName}`,\n error,\n );\n }\n },\n };\n};\n","// packages/logger-plugin/src/internal/timing.ts\n\n/**\n * Function that returns high-resolution timestamp in milliseconds.\n */\ntype TimeProvider = () => number;\n\n/**\n * State for Date.now() monotonic emulation\n */\nlet lastTimestamp = 0;\nlet timeOffset = 0;\n\n/**\n * Creates monotonic Date.now() wrapper that ensures time never goes backwards.\n *\n * @returns Time provider function with monotonic guarantee\n */\nfunction createMonotonicDateNow(): TimeProvider {\n // eslint-disable-next-line unicorn/consistent-function-scoping -- closure over module-level lastTimestamp/timeOffset\n return (): number => {\n const current: number = Date.now();\n\n if (current < lastTimestamp) {\n timeOffset += lastTimestamp - current;\n }\n\n lastTimestamp = current;\n\n return current + timeOffset;\n };\n}\n\n/**\n * Initialize time provider based on environment.\n * Uses performance.now() in modern environments (Node.js 16+, all browsers),\n * falls back to monotonic Date.now() wrapper for edge cases.\n */\nconst nowFn: TimeProvider =\n typeof performance !== \"undefined\" && typeof performance.now === \"function\"\n ? (): number => performance.now()\n : createMonotonicDateNow();\n\n/**\n * Returns high-resolution monotonic timestamp.\n *\n * Uses performance.now() in modern environments (Node.js 16+, all browsers).\n * Falls back to monotonic Date.now() wrapper (~1ms precision) for edge cases.\n *\n * @returns Timestamp in milliseconds\n */\nexport const now = (): number => nowFn();\n","// packages/logger-plugin/src/plugin.ts\n\nimport {\n createGroupManager,\n supportsConsoleGroups,\n} from \"./internal/console-groups\";\nimport {\n formatRouteName,\n formatTiming,\n createTransitionLabel,\n} from \"./internal/formatting\";\nimport { getParamsDiff, logParamsDiff } from \"./internal/params-diff\";\nimport { createPerformanceTracker } from \"./internal/performance-marks\";\nimport { now } from \"./internal/timing\";\n\nimport type { GroupManager } from \"./internal/console-groups\";\nimport type { PerformanceTracker } from \"./internal/performance-marks\";\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { Plugin, RouterError, State } from \"@real-router/core\";\n\nexport class LoggerPlugin {\n readonly #logLifecycle: boolean;\n readonly #logTransition: boolean;\n readonly #logError: boolean;\n\n readonly #shouldLogParams: boolean;\n readonly #shouldShowTiming: boolean;\n readonly #usePerf: boolean;\n\n readonly #prefix: string;\n readonly #context: string;\n\n readonly #groups: GroupManager;\n readonly #perf: PerformanceTracker;\n\n // Transition state\n #transitionStartTime: number | null = null;\n #transitionLabel = \"\";\n #startMarkName = \"\";\n\n constructor(config: Required<LoggerPluginConfig>) {\n this.#logLifecycle = config.level === \"all\";\n this.#logTransition = config.level !== \"none\" && config.level !== \"errors\";\n this.#logError = config.level !== \"none\";\n\n this.#shouldLogParams = this.#logTransition && config.showParamsDiff;\n this.#shouldShowTiming = config.showTiming;\n this.#usePerf = config.usePerformanceMarks;\n\n this.#prefix = `[${config.context}]`;\n this.#context = config.context;\n\n this.#groups = createGroupManager(supportsConsoleGroups());\n this.#perf = createPerformanceTracker(\n config.usePerformanceMarks,\n config.context,\n );\n }\n\n getPlugin(): Plugin {\n return {\n onStart: () => {\n this.#perf.mark(\"router:start\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router started`);\n }\n },\n\n onStop: () => {\n this.#groups.close();\n\n this.#perf.mark(\"router:stop\");\n this.#perf.measure(\"router:lifetime\", \"router:start\", \"router:stop\");\n\n if (this.#logLifecycle) {\n console.log(`${this.#prefix} Router stopped`);\n }\n },\n\n onTransitionStart: (toState: State, fromState?: State) => {\n this.#groups.open(\"Router transition\");\n this.#transitionStartTime = this.#shouldShowTiming ? now() : null;\n\n const fromRoute = formatRouteName(fromState);\n const toRoute = formatRouteName(toState);\n\n if (this.#usePerf) {\n this.#transitionLabel = createTransitionLabel(fromRoute, toRoute);\n this.#startMarkName = `router:transition-start:${this.#transitionLabel}`;\n this.#perf.mark(this.#startMarkName);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Transition: ${fromRoute} → ${toRoute}`, {\n from: fromState,\n to: toState,\n });\n\n this.#logParamsIfNeeded(toState, fromState);\n }\n },\n\n onTransitionLeaveApprove: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n this.#perf.mark(`router:leave-approved:${this.#transitionLabel}`);\n }\n\n if (this.#logTransition) {\n console.log(`${this.#prefix} Leave approved`, {\n to: toState,\n from: fromState,\n });\n }\n },\n\n onTransitionSuccess: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const endMark = `router:transition-end:${label}`;\n\n this.#perf.mark(endMark);\n this.#perf.measure(\n `router:transition:${label}`,\n this.#startMarkName,\n endMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.log(`${this.#prefix} Transition success${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionCancel: (toState: State, fromState?: State) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const cancelMark = `router:transition-cancel:${label}`;\n\n this.#perf.mark(cancelMark);\n this.#perf.measure(\n `router:transition-cancelled:${label}`,\n this.#startMarkName,\n cancelMark,\n );\n }\n\n if (this.#logTransition) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.warn(`${this.#prefix} Transition cancelled${timing}`, {\n to: toState,\n from: fromState,\n });\n }\n\n this.#resetTransitionState();\n },\n\n onTransitionError: (\n toState: State | undefined,\n fromState: State | undefined,\n err: RouterError,\n ) => {\n if (this.#usePerf) {\n const label = this.#transitionLabel;\n const errorMark = `router:transition-error:${label}`;\n\n this.#perf.mark(errorMark);\n this.#perf.measure(\n `router:transition-failed:${label}`,\n this.#startMarkName,\n errorMark,\n );\n }\n\n if (this.#logError) {\n const timing = this.#shouldShowTiming\n ? formatTiming(this.#transitionStartTime, now)\n : \"\";\n\n console.error(\n `${this.#prefix} Transition error: ${err.code}${timing}`,\n {\n error: err,\n stack: err.stack,\n to: toState,\n from: fromState,\n },\n );\n }\n\n this.#resetTransitionState();\n },\n\n teardown: () => {\n this.#resetTransitionState();\n },\n };\n }\n\n #logParamsIfNeeded(toState: State, fromState?: State): void {\n if (!this.#shouldLogParams || !fromState) {\n return;\n }\n\n if (toState.name !== fromState.name) {\n return;\n }\n\n const diff = getParamsDiff(fromState.params, toState.params);\n\n if (diff) {\n logParamsDiff(diff, this.#context);\n }\n }\n\n #resetTransitionState(): void {\n this.#groups.close();\n this.#transitionLabel = \"\";\n this.#startMarkName = \"\";\n this.#transitionStartTime = null;\n }\n}\n","// packages/logger-plugin/src/validation.ts\n\nimport { ERROR_PREFIX } from \"./constants\";\n\nimport type { LoggerPluginConfig } from \"./types\";\n\nconst VALID_LEVELS = new Set([\"all\", \"transitions\", \"errors\", \"none\"]);\n\nexport function validateOptions(options?: Partial<LoggerPluginConfig>): void {\n if (options === undefined) {\n return;\n }\n\n // Runtime defense: typeof null === \"object\", so check identity first.\n // TypeScript excludes null from the parameter type, but JS callers may pass it.\n if (options === (null as never) || typeof options !== \"object\") {\n throw new TypeError(`${ERROR_PREFIX} Options must be an object`);\n }\n\n if (options.level !== undefined && !VALID_LEVELS.has(options.level)) {\n throw new TypeError(\n `${ERROR_PREFIX} Invalid level: \"${options.level}\". Expected: ${[...VALID_LEVELS].join(\", \")}`,\n );\n }\n\n if (\n options.context !== undefined &&\n (typeof options.context !== \"string\" || options.context.length === 0)\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"context\" must be a non-empty string`,\n );\n }\n\n if (\n options.showTiming !== undefined &&\n typeof options.showTiming !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showTiming\" must be a boolean`,\n );\n }\n\n if (\n options.showParamsDiff !== undefined &&\n typeof options.showParamsDiff !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"showParamsDiff\" must be a boolean`,\n );\n }\n\n if (\n options.usePerformanceMarks !== undefined &&\n typeof options.usePerformanceMarks !== \"boolean\"\n ) {\n throw new TypeError(\n `${ERROR_PREFIX} Option \"usePerformanceMarks\" must be a boolean`,\n );\n }\n}\n","// packages/logger-plugin/src/factory.ts\n\nimport { DEFAULT_CONFIG } from \"./constants\";\nimport { LoggerPlugin } from \"./plugin\";\nimport { validateOptions } from \"./validation\";\n\nimport type { LoggerPluginConfig } from \"./types\";\nimport type { PluginFactory } from \"@real-router/core\";\n\nexport function loggerPluginFactory(\n options?: Partial<LoggerPluginConfig>,\n): PluginFactory {\n validateOptions(options);\n\n const config: Required<LoggerPluginConfig> = {\n ...DEFAULT_CONFIG,\n ...options,\n };\n\n return () => new LoggerPlugin(config).getPlugin();\n}\n"],"mappings":"AAIA,MAAa,EAAiB,gBAEjB,EAAe,iBAAiB,EAAe,GAE/C,EAA+C,CAC1D,MAAO,MACP,oBAAqB,GACrB,eAAgB,GAChB,WAAY,GACZ,QAAS,EACV,CCTY,MA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KAC7B,OAGF,IAAM,EAAO,EAAc,EAAU,OAAQ,EAAQ,OAAO,CAExD,GACF,EAAc,EAAM,MAAA,EAAc,CAItC,IAA8B,CAC5B,MAAA,EAAa,OAAO,CACpB,MAAA,EAAwB,GACxB,MAAA,EAAsB,GACtB,MAAA,EAA4B,OClOhC,MAAM,EAAe,IAAI,IAAI,CAAC,MAAO,cAAe,SAAU,OAAO,CAAC,CAEtE,SAAgB,EAAgB,EAA6C,CACvE,OAAY,IAAA,GAMhB,IAAmC,OAAO,GAAY,WAAlD,EACF,MAAU,UAAU,GAAG,EAAa,4BAA4B,CAGlE,GAAI,EAAQ,QAAU,IAAA,IAAa,CAAC,EAAa,IAAI,EAAQ,MAAM,CACjE,MAAU,UACR,GAAG,EAAa,mBAAmB,EAAQ,MAAM,eAAe,CAAC,GAAG,EAAa,CAAC,KAAK,KAAK,GAC7F,CAGH,GACE,EAAQ,UAAY,IAAA,KACnB,OAAO,EAAQ,SAAY,UAAY,EAAQ,QAAQ,SAAW,GAEnE,MAAU,UACR,GAAG,EAAa,8CACjB,CAGH,GACE,EAAQ,aAAe,IAAA,IACvB,OAAO,EAAQ,YAAe,UAE9B,MAAU,UACR,GAAG,EAAa,wCACjB,CAGH,GACE,EAAQ,iBAAmB,IAAA,IAC3B,OAAO,EAAQ,gBAAmB,UAElC,MAAU,UACR,GAAG,EAAa,4CACjB,CAGH,GACE,EAAQ,sBAAwB,IAAA,IAChC,OAAO,EAAQ,qBAAwB,UAEvC,MAAU,UACR,GAAG,EAAa,iDACjB,ECjDL,SAAgB,EACd,EACe,CACf,EAAgB,EAAQ,CAExB,IAAM,EAAuC,CAC3C,GAAG,EACH,GAAG,EACJ,CAED,UAAa,IAAI,EAAa,EAAO,CAAC,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/logger-plugin",
3
- "version": "0.3.7",
3
+ "version": "0.4.0",
4
4
  "type": "commonjs",
5
5
  "description": "Development logging plugin with transition tracking and performance metrics",
6
6
  "main": "./dist/cjs/index.js",
@@ -45,7 +45,7 @@
45
45
  "homepage": "https://github.com/greydragon888/real-router",
46
46
  "sideEffects": false,
47
47
  "dependencies": {
48
- "@real-router/core": "^0.42.0"
48
+ "@real-router/core": "^0.44.0"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsdown --config-loader unrun",
package/src/plugin.ts CHANGED
@@ -101,6 +101,19 @@ export class LoggerPlugin {
101
101
  }
102
102
  },
103
103
 
104
+ onTransitionLeaveApprove: (toState: State, fromState?: State) => {
105
+ if (this.#usePerf) {
106
+ this.#perf.mark(`router:leave-approved:${this.#transitionLabel}`);
107
+ }
108
+
109
+ if (this.#logTransition) {
110
+ console.log(`${this.#prefix} Leave approved`, {
111
+ to: toState,
112
+ from: fromState,
113
+ });
114
+ }
115
+ },
116
+
104
117
  onTransitionSuccess: (toState: State, fromState?: State) => {
105
118
  if (this.#usePerf) {
106
119
  const label = this.#transitionLabel;