@mugenlabs/logtape-devtools 0.2.0 → 0.3.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,7 @@
1
+ import * as _logtape_logtape from '@logtape/logtape';
1
2
  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;
3
+ import { LogStore, DevtoolsSinkOptions } from './sink.js';
4
+ export { DevtoolsLogRecord, LOG_LEVELS, LogLevel, LogStoreOptions, createDevtoolsSink, createLogStore, defaultLogStore } from './sink.js';
29
5
 
30
6
  interface LogTapeDevtoolsPluginOptions {
31
7
  /** Whether to open the devtools panel by default. Default: true */
@@ -53,53 +29,48 @@ declare const createLogTapeDevtoolsPlugin: (options?: LogTapeDevtoolsPluginOptio
53
29
  render: react_jsx_runtime.JSX.Element;
54
30
  };
55
31
 
56
- interface Props {
57
- store: LogStore;
58
- }
59
- declare const LogTapeDevtoolsPlugin: ({ store }: Props) => react_jsx_runtime.JSX.Element;
60
-
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. */
32
+ /** Options for {@link createLogTapeDevtools}. */
33
+ interface CreateLogTapeDevtoolsOptions {
34
+ /** Plugin options, minus `store` — the shared store is wired automatically. */
35
+ plugin?: Omit<LogTapeDevtoolsPluginOptions, "store">;
36
+ /** Sink options, minus `store` — the shared store is wired automatically. */
37
+ sink?: Omit<DevtoolsSinkOptions, "store">;
38
+ /** Store shared by the sink and the plugin. Defaults to the shared store. */
85
39
  store?: LogStore;
86
40
  }
87
41
  /**
88
- * Creates a LogTape sink that forwards log records to the devtools panel.
42
+ * Creates a LogTape sink and its matching TanStack DevTools plugin, both wired
43
+ * to the same store.
89
44
  *
90
- * Usage:
91
- * ```ts
92
- * import { configure } from "@logtape/logtape";
93
- * import { createDevtoolsSink } from "@mugenlabs/logtape-devtools";
45
+ * Use this instead of calling `createDevtoolsSink` and
46
+ * `createLogTapeDevtoolsPlugin` separately when you do not need to hold on to
47
+ * the store yourself.
48
+ *
49
+ * ```tsx
50
+ * import { configure, getLogger } from "@logtape/logtape";
51
+ * import { TanStackDevtools } from "@tanstack/react-devtools";
52
+ * import { createLogTapeDevtools } from "@mugenlabs/logtape-devtools";
53
+ *
54
+ * const { sink, plugin } = createLogTapeDevtools();
94
55
  *
95
56
  * await configure({
96
- * sinks: { devtools: createDevtoolsSink() },
97
- * loggers: [
98
- * { category: ["app"], lowestLevel: "debug", sinks: ["devtools"] },
99
- * ],
57
+ * sinks: { devtools: sink },
58
+ * loggers: [{ category: [], lowestLevel: "trace", sinks: ["devtools"] }],
100
59
  * });
60
+ *
61
+ * function App() {
62
+ * return <TanStackDevtools plugins={[plugin]} />;
63
+ * }
101
64
  * ```
102
65
  */
103
- declare function createDevtoolsSink(options?: DevtoolsSinkOptions): Sink;
66
+ declare function createLogTapeDevtools(options?: CreateLogTapeDevtoolsOptions): {
67
+ plugin: {
68
+ defaultOpen: boolean;
69
+ id: string;
70
+ name: string;
71
+ render: react_jsx_runtime.JSX.Element;
72
+ };
73
+ sink: _logtape_logtape.Sink;
74
+ };
104
75
 
105
- export { type DevtoolsLogRecord, type DevtoolsSinkOptions, LOG_LEVELS, type LogLevel, type LogStore, LogTapeDevtoolsPlugin, type LogTapeDevtoolsPluginOptions, createDevtoolsSink, createLogStore, createLogTapeDevtoolsPlugin, defaultLogStore };
76
+ export { type CreateLogTapeDevtoolsOptions, DevtoolsSinkOptions, LogStore, type LogTapeDevtoolsPluginOptions, createLogTapeDevtools, createLogTapeDevtoolsPlugin };