@kfiross44/valtio-inspector 0.9.1 → 0.9.3
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/attachInspector.d.ts +9 -1
- package/dist/attachInspector.d.ts.map +1 -1
- package/dist/attachInspector.js +17 -47
- package/dist/attachInspector.js.map +1 -1
- package/dist/cli.js +15 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/attachInspector.ts +11 -63
- package/src/cli.ts +17 -1
- package/kfiross44-valtio-inspector-0.9.0.tgz +0 -0
|
@@ -6,6 +6,14 @@ type AttachOptions = {
|
|
|
6
6
|
/** Custom inspector URL (default: http://localhost:7777) */
|
|
7
7
|
inspectorUrl?: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Attach a Valtio proxy store to the inspector.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* attachInspector(myStore, { name: 'auth' })
|
|
14
|
+
*
|
|
15
|
+
* ⚠️ Wrap in process.env.NODE_ENV !== 'production' to exclude from builds.
|
|
16
|
+
*/
|
|
17
|
+
export declare function attachInspector(state: object, options: AttachOptions): () => void;
|
|
10
18
|
export {};
|
|
11
19
|
//# sourceMappingURL=attachInspector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachInspector.d.ts","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG;IACnB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;
|
|
1
|
+
{"version":3,"file":"attachInspector.d.ts","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG;IACnB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI,CAsCjF"}
|
package/dist/attachInspector.js
CHANGED
|
@@ -2,61 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.attachInspector = attachInspector;
|
|
4
4
|
const valtio_1 = require("valtio");
|
|
5
|
+
/**
|
|
6
|
+
* Attach a Valtio proxy store to the inspector.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* attachInspector(myStore, { name: 'auth' })
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ Wrap in process.env.NODE_ENV !== 'production' to exclude from builds.
|
|
12
|
+
*/
|
|
5
13
|
function attachInspector(state, options) {
|
|
6
14
|
if (typeof window === 'undefined' && typeof process !== 'undefined') {
|
|
7
15
|
// Node.js / SSR — skip silently
|
|
8
16
|
return () => { };
|
|
9
17
|
}
|
|
10
18
|
const { name, debounce = 100, inspectorUrl = 'http://localhost:7777' } = options;
|
|
11
|
-
const wsUrl = inspectorUrl.startsWith('https')
|
|
12
|
-
? inspectorUrl.replace('https', 'wss')
|
|
13
|
-
: inspectorUrl.replace('http', 'ws');
|
|
14
19
|
let timeout = null;
|
|
15
|
-
let ws = null;
|
|
16
|
-
let reconnectAttempts = 0;
|
|
17
|
-
const queue = [];
|
|
18
|
-
function connect() {
|
|
19
|
-
ws = new WebSocket(wsUrl);
|
|
20
|
-
ws.onopen = () => {
|
|
21
|
-
reconnectAttempts = 0;
|
|
22
|
-
// flush queue
|
|
23
|
-
while (queue.length) {
|
|
24
|
-
ws.send(JSON.stringify(queue.shift()));
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
ws.onclose = () => {
|
|
28
|
-
const delay = Math.min(1000 * 2 ** reconnectAttempts, 10000);
|
|
29
|
-
reconnectAttempts++;
|
|
30
|
-
setTimeout(connect, delay);
|
|
31
|
-
};
|
|
32
|
-
ws.onerror = () => {
|
|
33
|
-
ws?.close();
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
20
|
function send() {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// queue for later
|
|
47
|
-
queue.push(payload);
|
|
48
|
-
// fallback to HTTP (optional)
|
|
49
|
-
fetch(`${inspectorUrl}/state`, {
|
|
50
|
-
method: 'POST',
|
|
51
|
-
headers: { 'Content-Type': 'application/json' },
|
|
52
|
-
body: JSON.stringify(payload)
|
|
53
|
-
}).catch(() => {
|
|
54
|
-
// Inspector not running — fail silently
|
|
55
|
-
});
|
|
56
|
-
}
|
|
21
|
+
const data = (0, valtio_1.snapshot)(state);
|
|
22
|
+
fetch(`${inspectorUrl}/state`, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: { 'Content-Type': 'application/json' },
|
|
25
|
+
body: JSON.stringify({ store: name, data })
|
|
26
|
+
}).catch(() => {
|
|
27
|
+
// Inspector not running — fail silently
|
|
28
|
+
});
|
|
57
29
|
}
|
|
58
|
-
// init connection
|
|
59
|
-
connect();
|
|
60
30
|
// Send initial snapshot immediately
|
|
61
31
|
send();
|
|
62
32
|
const unsubscribe = (0, valtio_1.subscribe)(state, () => {
|
|
@@ -64,11 +34,11 @@ function attachInspector(state, options) {
|
|
|
64
34
|
clearTimeout(timeout);
|
|
65
35
|
timeout = setTimeout(send, debounce);
|
|
66
36
|
});
|
|
37
|
+
// Return cleanup function
|
|
67
38
|
return () => {
|
|
68
39
|
if (timeout)
|
|
69
40
|
clearTimeout(timeout);
|
|
70
41
|
unsubscribe();
|
|
71
|
-
ws?.close();
|
|
72
42
|
};
|
|
73
43
|
}
|
|
74
44
|
//# sourceMappingURL=attachInspector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachInspector.js","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"attachInspector.js","sourceRoot":"","sources":["../src/attachInspector.ts"],"names":[],"mappings":";;AAmBA,0CAsCC;AAzDD,mCAA4C;AAW5C;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,KAAa,EAAE,OAAsB;IACnE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACpE,gCAAgC;QAChC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;IAED,MAAM,EACJ,IAAI,EACJ,QAAQ,GAAG,GAAG,EACd,YAAY,GAAG,uBAAuB,EACvC,GAAG,OAAO,CAAA;IAEX,IAAI,OAAO,GAAyC,IAAI,CAAA;IAExD,SAAS,IAAI;QACX,MAAM,IAAI,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAA;QAC5B,KAAK,CAAC,GAAG,YAAY,QAAQ,EAAE;YAC7B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;SAC5C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,wCAAwC;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE,CAAA;IAEN,MAAM,WAAW,GAAG,IAAA,kBAAS,EAAC,KAAK,EAAE,GAAG,EAAE;QACxC,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAA;QAClC,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,0BAA0B;IAC1B,OAAO,GAAG,EAAE;QACV,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAA;QAClC,WAAW,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -2,5 +2,19 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const server_1 = require("./server");
|
|
5
|
-
(
|
|
5
|
+
console.log("🚀 Inspector server is starting...");
|
|
6
|
+
try {
|
|
7
|
+
(0, server_1.startServer)();
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
console.error("💥 CRITICAL ERROR DURING STARTUP:", err);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
// תפיסת שגיאות אסינכרוניות שלא נתפסו
|
|
14
|
+
process.on('uncaughtException', (err) => {
|
|
15
|
+
console.error('🔥 Uncaught Exception:', err);
|
|
16
|
+
});
|
|
17
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
18
|
+
console.error('⚠️ Unhandled Rejection at:', promise, 'reason:', reason);
|
|
19
|
+
});
|
|
6
20
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qCAAuC;AAEvC,IAAA,oBAAW,GAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qCAAuC;AAEvC,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAElD,IAAI,CAAC;IACH,IAAA,oBAAW,GAAE,CAAC;AAChB,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,qCAAqC;AACrC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;IACnD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/attachInspector.ts
CHANGED
|
@@ -17,12 +17,7 @@ type AttachOptions = {
|
|
|
17
17
|
*
|
|
18
18
|
* ⚠️ Wrap in process.env.NODE_ENV !== 'production' to exclude from builds.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export function attachInspector<T extends object>(
|
|
23
|
-
state: T,
|
|
24
|
-
options: AttachOptions
|
|
25
|
-
): () => void {
|
|
20
|
+
export function attachInspector(state: object, options: AttachOptions): () => void {
|
|
26
21
|
if (typeof window === 'undefined' && typeof process !== 'undefined') {
|
|
27
22
|
// Node.js / SSR — skip silently
|
|
28
23
|
return () => {}
|
|
@@ -34,66 +29,19 @@ export function attachInspector<T extends object>(
|
|
|
34
29
|
inspectorUrl = 'http://localhost:7777'
|
|
35
30
|
} = options
|
|
36
31
|
|
|
37
|
-
const wsUrl = inspectorUrl.startsWith('https')
|
|
38
|
-
? inspectorUrl.replace('https', 'wss')
|
|
39
|
-
: inspectorUrl.replace('http', 'ws')
|
|
40
|
-
|
|
41
32
|
let timeout: ReturnType<typeof setTimeout> | null = null
|
|
42
|
-
let ws: WebSocket | null = null
|
|
43
|
-
let reconnectAttempts = 0
|
|
44
|
-
const queue: any[] = []
|
|
45
|
-
|
|
46
|
-
function connect() {
|
|
47
|
-
ws = new WebSocket(wsUrl)
|
|
48
|
-
|
|
49
|
-
ws.onopen = () => {
|
|
50
|
-
reconnectAttempts = 0
|
|
51
|
-
|
|
52
|
-
// flush queue
|
|
53
|
-
while (queue.length) {
|
|
54
|
-
ws!.send(JSON.stringify(queue.shift()))
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
ws.onclose = () => {
|
|
59
|
-
const delay = Math.min(1000 * 2 ** reconnectAttempts, 10000)
|
|
60
|
-
reconnectAttempts++
|
|
61
|
-
|
|
62
|
-
setTimeout(connect, delay)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
ws.onerror = () => {
|
|
66
|
-
ws?.close()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
33
|
|
|
70
34
|
function send() {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} else {
|
|
80
|
-
// queue for later
|
|
81
|
-
queue.push(payload)
|
|
82
|
-
|
|
83
|
-
// fallback to HTTP (optional)
|
|
84
|
-
fetch(`${inspectorUrl}/state`, {
|
|
85
|
-
method: 'POST',
|
|
86
|
-
headers: { 'Content-Type': 'application/json' },
|
|
87
|
-
body: JSON.stringify(payload)
|
|
88
|
-
}).catch(() => {
|
|
89
|
-
// Inspector not running — fail silently
|
|
90
|
-
})
|
|
91
|
-
}
|
|
35
|
+
const data = snapshot(state)
|
|
36
|
+
fetch(`${inspectorUrl}/state`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: { 'Content-Type': 'application/json' },
|
|
39
|
+
body: JSON.stringify({ store: name, data })
|
|
40
|
+
}).catch(() => {
|
|
41
|
+
// Inspector not running — fail silently
|
|
42
|
+
})
|
|
92
43
|
}
|
|
93
44
|
|
|
94
|
-
// init connection
|
|
95
|
-
connect()
|
|
96
|
-
|
|
97
45
|
// Send initial snapshot immediately
|
|
98
46
|
send()
|
|
99
47
|
|
|
@@ -102,9 +50,9 @@ export function attachInspector<T extends object>(
|
|
|
102
50
|
timeout = setTimeout(send, debounce)
|
|
103
51
|
})
|
|
104
52
|
|
|
53
|
+
// Return cleanup function
|
|
105
54
|
return () => {
|
|
106
55
|
if (timeout) clearTimeout(timeout)
|
|
107
56
|
unsubscribe()
|
|
108
|
-
ws?.close()
|
|
109
57
|
}
|
|
110
|
-
}
|
|
58
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -2,4 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { startServer } from './server';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
console.log("🚀 Inspector server is starting...");
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
startServer();
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error("💥 CRITICAL ERROR DURING STARTUP:", err);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// תפיסת שגיאות אסינכרוניות שלא נתפסו
|
|
15
|
+
process.on('uncaughtException', (err) => {
|
|
16
|
+
console.error('🔥 Uncaught Exception:', err);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
20
|
+
console.error('⚠️ Unhandled Rejection at:', promise, 'reason:', reason);
|
|
21
|
+
});
|
|
Binary file
|