@mugenlabs/logtape-devtools 0.2.1 → 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/dist/index.d.ts CHANGED
@@ -1,31 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Sink } from '@logtape/logtape';
3
-
4
- type LogLevel = "trace" | "debug" | "info" | "warning" | "error" | "fatal";
5
- declare const LOG_LEVELS: LogLevel[];
6
- interface DevtoolsLogRecord {
7
- /** Source location of the log call (only present when `experimentalCaptureStackTrace` is enabled). */
8
- caller?: string;
9
- category: string[];
10
- id: string;
11
- level: LogLevel;
12
- message: unknown[];
13
- messageText: string;
14
- properties: Record<string, unknown>;
15
- timestamp: number;
16
- }
17
-
18
- type Listener = () => void;
19
- interface LogStore {
20
- addRecord(record: DevtoolsLogRecord): void;
21
- clear(): void;
22
- getSnapshot(): DevtoolsLogRecord[];
23
- setMaxSize(size: number): void;
24
- subscribe(listener: Listener): () => void;
25
- }
26
- declare function createLogStore(maxSize?: number): LogStore;
27
- /** Default shared store instance used when no custom store is provided */
28
- declare const defaultLogStore: LogStore;
1
+ import { LogStore, DevtoolsSinkOptions, DevtoolsSink } from './sink.js';
2
+ export { DevtoolsLogRecord, LOG_LEVELS, LogLevel, LogStoreOptions, createDevtoolsSink, createLogStore, defaultLogStore } from './sink.js';
3
+ import * as _tanstack_react_devtools from '@tanstack/react-devtools';
4
+ import { TanStackDevtoolsReactPlugin } from '@tanstack/react-devtools';
5
+ import '@logtape/logtape';
29
6
 
30
7
  interface LogTapeDevtoolsPluginOptions {
31
8
  /** Whether to open the devtools panel by default. Default: true */
@@ -46,60 +23,45 @@ interface LogTapeDevtoolsPluginOptions {
46
23
  * <TanStackDevtools plugins={[createLogTapeDevtoolsPlugin()]} />
47
24
  * ```
48
25
  */
49
- declare const createLogTapeDevtoolsPlugin: (options?: LogTapeDevtoolsPluginOptions) => {
50
- defaultOpen: boolean;
51
- id: string;
52
- name: string;
53
- render: react_jsx_runtime.JSX.Element;
54
- };
55
-
56
- interface Props {
57
- store: LogStore;
58
- }
59
- declare const LogTapeDevtoolsPlugin: ({ store }: Props) => react_jsx_runtime.JSX.Element;
26
+ declare const createLogTapeDevtoolsPlugin: (options?: LogTapeDevtoolsPluginOptions) => TanStackDevtoolsReactPlugin;
60
27
 
61
- interface DevtoolsSinkOptions {
62
- /**
63
- * Capture the source location of each log call via stack trace parsing.
64
- *
65
- * **Experimental / dev-only** — relies on `new Error().stack` which is
66
- * engine-dependent. Automatically disabled in production builds (when
67
- * `process.env.NODE_ENV === "production"`) because minified bundles
68
- * produce meaningless file/line references. Note that source maps do not
69
- * help here — browsers do not apply source maps to `Error.stack`.
70
- *
71
- * Set `forceStackTrace` to `true` to override the production guard — useful
72
- * when your production build ships unminified code.
73
- *
74
- * @default true
75
- */
76
- experimentalCaptureStackTrace?: boolean;
77
- /**
78
- * Force stack trace capture even in production builds.
79
- * Only has an effect when `experimentalCaptureStackTrace` is `true`.
80
- *
81
- * @default false
82
- */
83
- forceStackTrace?: boolean;
84
- /** Custom log store instance. Defaults to the shared store. */
28
+ /** Options for {@link createLogTapeDevtools}. */
29
+ interface CreateLogTapeDevtoolsOptions {
30
+ /** Plugin options, minus `store` — the shared store is wired automatically. */
31
+ plugin?: Omit<LogTapeDevtoolsPluginOptions, "store">;
32
+ /** Sink options, minus `store` — the shared store is wired automatically. */
33
+ sink?: Omit<DevtoolsSinkOptions, "store">;
34
+ /** Store shared by the sink and the plugin. Defaults to the shared store. */
85
35
  store?: LogStore;
86
36
  }
87
37
  /**
88
- * Creates a LogTape sink that forwards log records to the devtools panel.
38
+ * Creates a LogTape sink and its matching TanStack DevTools plugin, both wired
39
+ * to the same store.
89
40
  *
90
- * Usage:
91
- * ```ts
92
- * import { configure } from "@logtape/logtape";
93
- * import { createDevtoolsSink } from "@mugenlabs/logtape-devtools";
41
+ * Use this instead of calling `createDevtoolsSink` and
42
+ * `createLogTapeDevtoolsPlugin` separately when you do not need to hold on to
43
+ * the store yourself.
44
+ *
45
+ * ```tsx
46
+ * import { configure, getLogger } from "@logtape/logtape";
47
+ * import { TanStackDevtools } from "@tanstack/react-devtools";
48
+ * import { createLogTapeDevtools } from "@mugenlabs/logtape-devtools";
49
+ *
50
+ * const { sink, plugin } = createLogTapeDevtools();
94
51
  *
95
52
  * await configure({
96
- * sinks: { devtools: createDevtoolsSink() },
97
- * loggers: [
98
- * { category: ["app"], lowestLevel: "debug", sinks: ["devtools"] },
99
- * ],
53
+ * sinks: { devtools: sink },
54
+ * loggers: [{ category: [], lowestLevel: "trace", sinks: ["devtools"] }],
100
55
  * });
56
+ *
57
+ * function App() {
58
+ * return <TanStackDevtools plugins={[plugin]} />;
59
+ * }
101
60
  * ```
102
61
  */
103
- declare function createDevtoolsSink(options?: DevtoolsSinkOptions): Sink;
62
+ declare function createLogTapeDevtools(options?: CreateLogTapeDevtoolsOptions): {
63
+ plugin: _tanstack_react_devtools.TanStackDevtoolsReactPlugin;
64
+ sink: DevtoolsSink;
65
+ };
104
66
 
105
- export { type DevtoolsLogRecord, type DevtoolsSinkOptions, LOG_LEVELS, type LogLevel, type LogStore, LogTapeDevtoolsPlugin, type LogTapeDevtoolsPluginOptions, createDevtoolsSink, createLogStore, createLogTapeDevtoolsPlugin, defaultLogStore };
67
+ export { type CreateLogTapeDevtoolsOptions, DevtoolsSink, DevtoolsSinkOptions, LogStore, type LogTapeDevtoolsPluginOptions, createLogTapeDevtools, createLogTapeDevtoolsPlugin };