@couch-kit/client 0.7.0 → 0.8.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/CHANGELOG.md +18 -0
- package/dist/index.js +58 -0
- package/lib/debug-panel.d.ts +55 -0
- package/lib/debug-panel.d.ts.map +1 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/debug-panel.ts +127 -0
- package/src/index.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @couch-kit/client
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#21](https://github.com/faluciano/react-native-couch-kit/pull/21) [`f1e836d`](https://github.com/faluciano/react-native-couch-kit/commit/f1e836d8f17821f0da20db7c3c552552c9b22133) Thanks [@faluciano](https://github.com/faluciano)! - Add `useDebugPanel` hook for capturing debug information (action log, state history, connection status, RTT). Gated behind `debug: true` option.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`f1e836d`](https://github.com/faluciano/react-native-couch-kit/commit/f1e836d8f17821f0da20db7c3c552552c9b22133)]:
|
|
12
|
+
- @couch-kit/core@0.8.0
|
|
13
|
+
|
|
14
|
+
## 0.7.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`978616b`](https://github.com/faluciano/react-native-couch-kit/commit/978616b767031e02e24fe48de8dbdf37d15be783)]:
|
|
19
|
+
- @couch-kit/core@0.7.0
|
|
20
|
+
|
|
3
21
|
## 0.7.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -315,9 +315,67 @@ function usePreload(assets, sendMessage) {
|
|
|
315
315
|
}, [stableAssets]);
|
|
316
316
|
return { loaded, progress, failedAssets };
|
|
317
317
|
}
|
|
318
|
+
// src/debug-panel.ts
|
|
319
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
|
|
320
|
+
function useDebugPanel(options) {
|
|
321
|
+
const { enabled, state, status, rtt, maxEntries = 50 } = options;
|
|
322
|
+
const nextIdRef = useRef4(0);
|
|
323
|
+
const prevStateRef = useRef4(null);
|
|
324
|
+
const [actionLog, setActionLog] = useState4([]);
|
|
325
|
+
const [stateHistory, setStateHistory] = useState4([]);
|
|
326
|
+
const clearHistory = useCallback3(() => {
|
|
327
|
+
setActionLog([]);
|
|
328
|
+
setStateHistory([]);
|
|
329
|
+
nextIdRef.current = 0;
|
|
330
|
+
}, []);
|
|
331
|
+
const logAction = useCallback3((action, source = "local") => {
|
|
332
|
+
if (!enabled)
|
|
333
|
+
return;
|
|
334
|
+
setActionLog((prev) => {
|
|
335
|
+
const entry = {
|
|
336
|
+
id: nextIdRef.current++,
|
|
337
|
+
action,
|
|
338
|
+
timestamp: Date.now(),
|
|
339
|
+
source
|
|
340
|
+
};
|
|
341
|
+
const next = [...prev, entry];
|
|
342
|
+
return next.length > maxEntries ? next.slice(-maxEntries) : next;
|
|
343
|
+
});
|
|
344
|
+
}, [enabled, maxEntries]);
|
|
345
|
+
useEffect4(() => {
|
|
346
|
+
if (!enabled || state === null || state === prevStateRef.current)
|
|
347
|
+
return;
|
|
348
|
+
prevStateRef.current = state;
|
|
349
|
+
setStateHistory((prev) => {
|
|
350
|
+
const entry = {
|
|
351
|
+
id: nextIdRef.current++,
|
|
352
|
+
state,
|
|
353
|
+
timestamp: Date.now()
|
|
354
|
+
};
|
|
355
|
+
const next = [...prev, entry];
|
|
356
|
+
return next.length > maxEntries ? next.slice(-maxEntries) : next;
|
|
357
|
+
});
|
|
358
|
+
}, [enabled, state, maxEntries]);
|
|
359
|
+
useEffect4(() => {
|
|
360
|
+
if (!enabled) {
|
|
361
|
+
clearHistory();
|
|
362
|
+
prevStateRef.current = null;
|
|
363
|
+
}
|
|
364
|
+
}, [enabled, clearHistory]);
|
|
365
|
+
return {
|
|
366
|
+
enabled,
|
|
367
|
+
actionLog,
|
|
368
|
+
stateHistory,
|
|
369
|
+
connectionStatus: status,
|
|
370
|
+
rtt: rtt > 0 ? rtt : null,
|
|
371
|
+
clearHistory,
|
|
372
|
+
logAction
|
|
373
|
+
};
|
|
374
|
+
}
|
|
318
375
|
export {
|
|
319
376
|
useServerTime,
|
|
320
377
|
usePreload,
|
|
321
378
|
useGameClient,
|
|
379
|
+
useDebugPanel,
|
|
322
380
|
calculateTimeSync
|
|
323
381
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A recorded debug action entry.
|
|
3
|
+
*/
|
|
4
|
+
export interface DebugActionEntry {
|
|
5
|
+
id: number;
|
|
6
|
+
action: unknown;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
source: "local" | "remote";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A state history entry for debugging.
|
|
12
|
+
*/
|
|
13
|
+
export interface DebugStateEntry<S = unknown> {
|
|
14
|
+
id: number;
|
|
15
|
+
state: S;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Debug panel data returned by useDebugPanel.
|
|
20
|
+
*/
|
|
21
|
+
export interface DebugPanelData<S = unknown> {
|
|
22
|
+
/** Whether debug mode is active */
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
/** Log of actions (sent and received) */
|
|
25
|
+
actionLog: DebugActionEntry[];
|
|
26
|
+
/** History of state changes */
|
|
27
|
+
stateHistory: DebugStateEntry<S>[];
|
|
28
|
+
/** Current connection status */
|
|
29
|
+
connectionStatus: string;
|
|
30
|
+
/** Current round-trip time in ms */
|
|
31
|
+
rtt: number | null;
|
|
32
|
+
/** Clear all debug history */
|
|
33
|
+
clearHistory: () => void;
|
|
34
|
+
/** Manually log an action (e.g., from sendAction wrapper) */
|
|
35
|
+
logAction: (action: unknown, source?: "local" | "remote") => void;
|
|
36
|
+
}
|
|
37
|
+
export interface UseDebugPanelOptions<S = unknown> {
|
|
38
|
+
/** Whether debug capture is active */
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
/** Current game state from useGameClient */
|
|
41
|
+
state: S | null;
|
|
42
|
+
/** Connection status from useGameClient */
|
|
43
|
+
status: string;
|
|
44
|
+
/** RTT from useGameClient */
|
|
45
|
+
rtt: number;
|
|
46
|
+
/** Maximum number of entries to keep in logs */
|
|
47
|
+
maxEntries?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook that provides debug panel data for development.
|
|
51
|
+
* Tracks state changes, connection status, and action history.
|
|
52
|
+
* Designed to be consumed by DebugOverlay or custom debug UI.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useDebugPanel<S = unknown>(options: UseDebugPanelOptions<S>): DebugPanelData<S>;
|
|
55
|
+
//# sourceMappingURL=debug-panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-panel.d.ts","sourceRoot":"","sources":["../src/debug-panel.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,mCAAmC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,+BAA+B;IAC/B,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,gCAAgC;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,6DAA6D;IAC7D,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;CACnE;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,4CAA4C;IAC5C,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAChB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EACvC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,cAAc,CAAC,CAAC,CAAC,CAiEnB"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@couch-kit/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"clean": "rm -rf dist lib"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@couch-kit/core": "0.
|
|
50
|
+
"@couch-kit/core": "0.8.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"react": "^18.2.0",
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A recorded debug action entry.
|
|
5
|
+
*/
|
|
6
|
+
export interface DebugActionEntry {
|
|
7
|
+
id: number;
|
|
8
|
+
action: unknown;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
source: "local" | "remote";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A state history entry for debugging.
|
|
15
|
+
*/
|
|
16
|
+
export interface DebugStateEntry<S = unknown> {
|
|
17
|
+
id: number;
|
|
18
|
+
state: S;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Debug panel data returned by useDebugPanel.
|
|
24
|
+
*/
|
|
25
|
+
export interface DebugPanelData<S = unknown> {
|
|
26
|
+
/** Whether debug mode is active */
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
/** Log of actions (sent and received) */
|
|
29
|
+
actionLog: DebugActionEntry[];
|
|
30
|
+
/** History of state changes */
|
|
31
|
+
stateHistory: DebugStateEntry<S>[];
|
|
32
|
+
/** Current connection status */
|
|
33
|
+
connectionStatus: string;
|
|
34
|
+
/** Current round-trip time in ms */
|
|
35
|
+
rtt: number | null;
|
|
36
|
+
/** Clear all debug history */
|
|
37
|
+
clearHistory: () => void;
|
|
38
|
+
/** Manually log an action (e.g., from sendAction wrapper) */
|
|
39
|
+
logAction: (action: unknown, source?: "local" | "remote") => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UseDebugPanelOptions<S = unknown> {
|
|
43
|
+
/** Whether debug capture is active */
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
/** Current game state from useGameClient */
|
|
46
|
+
state: S | null;
|
|
47
|
+
/** Connection status from useGameClient */
|
|
48
|
+
status: string;
|
|
49
|
+
/** RTT from useGameClient */
|
|
50
|
+
rtt: number;
|
|
51
|
+
/** Maximum number of entries to keep in logs */
|
|
52
|
+
maxEntries?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Hook that provides debug panel data for development.
|
|
57
|
+
* Tracks state changes, connection status, and action history.
|
|
58
|
+
* Designed to be consumed by DebugOverlay or custom debug UI.
|
|
59
|
+
*/
|
|
60
|
+
export function useDebugPanel<S = unknown>(
|
|
61
|
+
options: UseDebugPanelOptions<S>,
|
|
62
|
+
): DebugPanelData<S> {
|
|
63
|
+
const { enabled, state, status, rtt, maxEntries = 50 } = options;
|
|
64
|
+
const nextIdRef = useRef(0);
|
|
65
|
+
const prevStateRef = useRef<S | null>(null);
|
|
66
|
+
|
|
67
|
+
const [actionLog, setActionLog] = useState<DebugActionEntry[]>([]);
|
|
68
|
+
const [stateHistory, setStateHistory] = useState<DebugStateEntry<S>[]>([]);
|
|
69
|
+
|
|
70
|
+
const clearHistory = useCallback(() => {
|
|
71
|
+
setActionLog([]);
|
|
72
|
+
setStateHistory([]);
|
|
73
|
+
nextIdRef.current = 0;
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
const logAction = useCallback(
|
|
77
|
+
(action: unknown, source: "local" | "remote" = "local") => {
|
|
78
|
+
if (!enabled) return;
|
|
79
|
+
|
|
80
|
+
setActionLog((prev) => {
|
|
81
|
+
const entry: DebugActionEntry = {
|
|
82
|
+
id: nextIdRef.current++,
|
|
83
|
+
action,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
source,
|
|
86
|
+
};
|
|
87
|
+
const next = [...prev, entry];
|
|
88
|
+
return next.length > maxEntries ? next.slice(-maxEntries) : next;
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
[enabled, maxEntries],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Track state changes
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!enabled || state === null || state === prevStateRef.current) return;
|
|
97
|
+
prevStateRef.current = state;
|
|
98
|
+
|
|
99
|
+
setStateHistory((prev) => {
|
|
100
|
+
const entry: DebugStateEntry<S> = {
|
|
101
|
+
id: nextIdRef.current++,
|
|
102
|
+
state,
|
|
103
|
+
timestamp: Date.now(),
|
|
104
|
+
};
|
|
105
|
+
const next = [...prev, entry];
|
|
106
|
+
return next.length > maxEntries ? next.slice(-maxEntries) : next;
|
|
107
|
+
});
|
|
108
|
+
}, [enabled, state, maxEntries]);
|
|
109
|
+
|
|
110
|
+
// Reset when disabled
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!enabled) {
|
|
113
|
+
clearHistory();
|
|
114
|
+
prevStateRef.current = null;
|
|
115
|
+
}
|
|
116
|
+
}, [enabled, clearHistory]);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
enabled,
|
|
120
|
+
actionLog,
|
|
121
|
+
stateHistory,
|
|
122
|
+
connectionStatus: status,
|
|
123
|
+
rtt: rtt > 0 ? rtt : null,
|
|
124
|
+
clearHistory,
|
|
125
|
+
logAction,
|
|
126
|
+
};
|
|
127
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./client";
|
|
2
|
+
export * from "./time-sync";
|
|
3
|
+
export * from "./assets";
|
|
4
|
+
export * from "./debug-panel";
|