@capybara-devtools/core 0.2.1 → 0.3.1
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 +2 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -4
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/state/context.d.ts +102 -0
- package/dist/plugins/state/context.d.ts.map +1 -0
- package/dist/plugins/state/context.js +765 -0
- package/dist/plugins/state/context.js.map +1 -0
- package/dist/plugins/state/engine.d.ts +71 -0
- package/dist/plugins/state/engine.d.ts.map +1 -0
- package/dist/plugins/state/engine.js +710 -0
- package/dist/plugins/state/engine.js.map +1 -0
- package/dist/plugins/state/index.d.ts +59 -0
- package/dist/plugins/state/index.d.ts.map +1 -0
- package/dist/plugins/state/index.js +52 -0
- package/dist/plugins/state/index.js.map +1 -0
- package/dist/plugins/state/redux.d.ts +43 -0
- package/dist/plugins/state/redux.d.ts.map +1 -0
- package/dist/plugins/state/redux.js +580 -0
- package/dist/plugins/state/redux.js.map +1 -0
- package/dist/plugins/state/registry.d.ts +22 -0
- package/dist/plugins/state/registry.d.ts.map +1 -0
- package/dist/plugins/state/registry.js +109 -0
- package/dist/plugins/state/registry.js.map +1 -0
- package/dist/plugins/state/swr.d.ts +49 -0
- package/dist/plugins/state/swr.d.ts.map +1 -0
- package/dist/plugins/state/swr.js +359 -0
- package/dist/plugins/state/swr.js.map +1 -0
- package/dist/plugins/state/tanstack.d.ts +31 -0
- package/dist/plugins/state/tanstack.d.ts.map +1 -0
- package/dist/plugins/state/tanstack.js +461 -0
- package/dist/plugins/state/tanstack.js.map +1 -0
- package/dist/plugins/state/zustand.d.ts +21 -0
- package/dist/plugins/state/zustand.d.ts.map +1 -0
- package/dist/plugins/state/zustand.js +70 -0
- package/dist/plugins/state/zustand.js.map +1 -0
- package/package.json +11 -2
- package/src/client.ts +12 -6
- package/src/index.ts +19 -0
- package/src/plugins/state/context.ts +831 -0
- package/src/plugins/state/engine.ts +739 -0
- package/src/plugins/state/index.ts +112 -0
- package/src/plugins/state/redux.ts +609 -0
- package/src/plugins/state/registry.ts +126 -0
- package/src/plugins/state/swr.ts +375 -0
- package/src/plugins/state/tanstack.ts +488 -0
- package/src/plugins/state/zustand.ts +82 -0
package/src/client.ts
CHANGED
|
@@ -16,7 +16,8 @@ import { errorMessage, randomId } from './utils.js';
|
|
|
16
16
|
type ConsoleMethod = (...args: unknown[]) => void;
|
|
17
17
|
|
|
18
18
|
export interface PluginContext {
|
|
19
|
-
|
|
19
|
+
/** `ts` dates the event when it happened earlier than now, e.g. a state change sent in a later batch. */
|
|
20
|
+
emit<K extends EventKind>(kind: K, payload: EventPayloads[K], ts?: number): void;
|
|
20
21
|
serialize(value: unknown): SerializedValue;
|
|
21
22
|
/** Console methods saved before any plugin patched them. SDK diagnostics written here are not captured. */
|
|
22
23
|
console: { log: ConsoleMethod; warn: ConsoleMethod; error: ConsoleMethod };
|
|
@@ -33,7 +34,7 @@ export interface Plugin {
|
|
|
33
34
|
export interface ClientOptions {
|
|
34
35
|
/** e.g. `ws://192.168.1.5:7357/client` */
|
|
35
36
|
url: string;
|
|
36
|
-
session: Omit<SessionInfo, 'id' | 'startedAt'>;
|
|
37
|
+
session: Omit<SessionInfo, 'id' | 'startedAt' | 'plugins'>;
|
|
37
38
|
plugins?: Plugin[];
|
|
38
39
|
/** Events kept for replay after a reconnect. Default 2000. */
|
|
39
40
|
maxBufferEvents?: number;
|
|
@@ -73,11 +74,16 @@ export function createClient(options: ClientOptions): CapybaraClient {
|
|
|
73
74
|
// Two clients would patch console and network twice.
|
|
74
75
|
getActiveClient()?.stop();
|
|
75
76
|
|
|
76
|
-
const
|
|
77
|
+
const plugins = options.plugins ?? [];
|
|
78
|
+
const session: SessionInfo = {
|
|
79
|
+
...options.session,
|
|
80
|
+
id: randomId(),
|
|
81
|
+
startedAt: Date.now(),
|
|
82
|
+
plugins: plugins.map((p) => p.name),
|
|
83
|
+
};
|
|
77
84
|
const maxEvents = options.maxBufferEvents ?? 2_000;
|
|
78
85
|
const maxChars = options.maxBufferBytes ?? 8 * 1024 * 1024;
|
|
79
86
|
const flushInterval = options.flushInterval ?? 50;
|
|
80
|
-
const plugins = options.plugins ?? [];
|
|
81
87
|
const originalConsole = {
|
|
82
88
|
log: console.log.bind(console),
|
|
83
89
|
warn: console.warn.bind(console),
|
|
@@ -97,11 +103,11 @@ export function createClient(options: ClientOptions): CapybaraClient {
|
|
|
97
103
|
|
|
98
104
|
const send = (message: ClientToServer) => connection.send(JSON.stringify(message));
|
|
99
105
|
|
|
100
|
-
const emit: PluginContext['emit'] = (kind, payload) => {
|
|
106
|
+
const emit: PluginContext['emit'] = (kind, payload, ts) => {
|
|
101
107
|
if (stopped) return;
|
|
102
108
|
let json: string;
|
|
103
109
|
try {
|
|
104
|
-
json = JSON.stringify({ seq: seq + 1, ts: Date.now(), kind, payload });
|
|
110
|
+
json = JSON.stringify({ seq: seq + 1, ts: ts ?? Date.now(), kind, payload });
|
|
105
111
|
} catch {
|
|
106
112
|
return;
|
|
107
113
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,3 +10,22 @@ export { hookWebSockets } from './plugins/websocket.js';
|
|
|
10
10
|
export type { WebSocketEventKind, WebSocketHookOptions } from './plugins/websocket.js';
|
|
11
11
|
export { storagePlugin } from './plugins/storage.js';
|
|
12
12
|
export type { StorageAdapter } from './plugins/storage.js';
|
|
13
|
+
export { statePlugin } from './plugins/state/index.js';
|
|
14
|
+
export type { StatePluginOptions, StateSink, StoreDriver } from './plugins/state/index.js';
|
|
15
|
+
export { walkProviders } from './plugins/state/context.js';
|
|
16
|
+
export type {
|
|
17
|
+
Fiber as ReactFiber,
|
|
18
|
+
FiberRoot as ReactFiberRoot,
|
|
19
|
+
ProviderHit,
|
|
20
|
+
WalkCursor,
|
|
21
|
+
WalkProvidersOptions,
|
|
22
|
+
WalkProvidersResult,
|
|
23
|
+
} from './plugins/state/context.js';
|
|
24
|
+
export { capybaraReduxEnhancer, connectReduxStore } from './plugins/state/redux.js';
|
|
25
|
+
export type { ReduxStoreEnhancer, ReduxStoreLike, ReduxStoreOptions } from './plugins/state/redux.js';
|
|
26
|
+
export { watchZustand } from './plugins/state/zustand.js';
|
|
27
|
+
export type { WatchZustandOptions, ZustandStoreLike } from './plugins/state/zustand.js';
|
|
28
|
+
export { createQueryClientDriver, summarizeMutation, summarizeQuery, watchQueryClient } from './plugins/state/tanstack.js';
|
|
29
|
+
export type { QueryClientLike, WatchQueryClientOptions } from './plugins/state/tanstack.js';
|
|
30
|
+
export { summarizeSWREntry, swrMiddleware, swrProvider, watchSWR } from './plugins/state/swr.js';
|
|
31
|
+
export type { SWRCacheLike, SWRHandle, WatchSWROptions } from './plugins/state/swr.js';
|