@spoosh/plugin-debug
v0.2.0
Published
Debug plugin for Spoosh - logs detailed request lifecycle information
Downloads
569
Maintainers
Readme
@spoosh/plugin-debug
Debug plugin for Spoosh - logs detailed request lifecycle information.
Documentation · Requirements: TypeScript >= 5.0 · Peer Dependencies: @spoosh/core
Installation
npm install @spoosh/plugin-debugUsage
import { Spoosh } from "@spoosh/core";
import { debugPlugin } from "@spoosh/plugin-debug";
// Basic usage - logs all phases
const client = new Spoosh<ApiSchema, Error>("/api").use([debugPlugin()]);
// With cache logging
const client = new Spoosh<ApiSchema, Error>("/api").use([
debugPlugin({ logCache: true }),
]);
// Custom logger with object shape
const client = new Spoosh<ApiSchema, Error>("/api").use([
debugPlugin({
logger: (entry) => {
console.log(entry.phase, entry.path, entry.state.data);
},
}),
]);
// Disable in production
const client = new Spoosh<ApiSchema, Error>("/api").use([
debugPlugin({ enabled: process.env.NODE_ENV === "development" }),
]);Options
Plugin Config
| Option | Type | Default | Description |
| ---------- | -------------------------------- | ------- | ----------------------------------- |
| enabled | boolean | true | Enable/disable logging |
| logCache | boolean | false | Include cache entries in log output |
| logger | (entry: DebugLogEntry) => void | - | Custom logger function |
DebugLogEntry
| Property | Type | Description |
| ------------------ | ---------- | ------------------------------------------ |
| phase | string | Current phase (onMount, beforeFetch, etc.) |
| operationType | string | "read", "write", or "infiniteRead" |
| method | string | HTTP method |
| path | string | Request path |
| queryKey | string | Unique query key |
| requestTimestamp | number | Request timestamp |
| tags | string[] | Cache tags |
| requestOptions | unknown | Request options |
| state | object | Current state (loading, data, error, etc.) |
| response | object | Response data (if available) |
| cacheEntries | array | Cache entries (if logCache enabled) |
