@hyper-fetch/plugin-devtools 9.9.0 → 10.1.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.
@@ -20,8 +20,79 @@ export enum EventSourceType {
20
20
  SUBMIT_DISPATCHER = "submitDispatcher",
21
21
  FETCH_DISPATCHER = "fetchDispatcher",
22
22
  CUSTOM_EVENT = "customEvent",
23
+ /** Events of the sockets passed in the `sockets` option */
24
+ SOCKET = "socket",
25
+ /** How many observers the application has, see `ObserverEvents` */
26
+ OBSERVERS = "observers",
23
27
  }
24
28
 
29
+ /** What happens to the sockets HyperFlow inspects */
30
+ export enum SocketEvents {
31
+ /** The socket's identity and current state. Sent when the plugin starts and every time HyperFlow connects. */
32
+ REGISTERED = "SOCKET_REGISTERED",
33
+ CONNECTING = "SOCKET_CONNECTING",
34
+ CONNECTED = "SOCKET_CONNECTED",
35
+ DISCONNECTED = "SOCKET_DISCONNECTED",
36
+ RECONNECTING = "SOCKET_RECONNECTING",
37
+ RECONNECT_FAILED = "SOCKET_RECONNECT_FAILED",
38
+ ERROR = "SOCKET_ERROR",
39
+ /** A message arrived on a topic */
40
+ MESSAGE_RECEIVED = "SOCKET_MESSAGE_RECEIVED",
41
+ /** An emitter sent a message */
42
+ MESSAGE_SENT = "SOCKET_MESSAGE_SENT",
43
+ /** An emitter failed to send a message */
44
+ MESSAGE_FAILED = "SOCKET_MESSAGE_FAILED",
45
+ }
46
+
47
+ export type DevtoolsSocketStatus = "connecting" | "connected" | "disconnected" | "reconnecting" | "failed";
48
+
49
+ /** The data of every socket event */
50
+ export type DevtoolsSocketEventData = {
51
+ /** Identifies the socket within the application */
52
+ socketId: string;
53
+ url: string;
54
+ adapterName: string;
55
+ /** When it happened in the application */
56
+ timestamp: number;
57
+ /** State of the socket after the event, set on `REGISTERED` */
58
+ status?: DevtoolsSocketStatus;
59
+ topic?: string;
60
+ /** Received data or sent payload */
61
+ data?: unknown;
62
+ /** Adapter details of a received message */
63
+ extra?: unknown;
64
+ error?: { name: string; message: string } | unknown;
65
+ /** Reconnection attempt */
66
+ attempts?: number;
67
+ };
68
+
69
+ /** What happens to the observers of the application's cache keys and query keys */
70
+ export enum ObserverEvents {
71
+ /**
72
+ * Observer counts changed. Sent with the counts of one key whenever an observer subscribes or unsubscribes, and with
73
+ * the counts of every key the plugin knows each time HyperFlow connects.
74
+ */
75
+ CHANGED = "OBSERVERS_CHANGED",
76
+ }
77
+
78
+ /**
79
+ * The data of `ObserverEvents.CHANGED`. Only the user's application knows its observers, so the plugin reports them.
80
+ * Keys not listed keep their previous counts.
81
+ */
82
+ export type DevtoolsObserversEventData = {
83
+ /**
84
+ * Observers by cache key: subscriptions to the data of the key, one for every mounted `useFetch`, `useSubmit` and
85
+ * `useCache` reading it, plus every `cache.events.onDataByKey` of the application.
86
+ */
87
+ cache: Record<string, number>;
88
+ /**
89
+ * Observers by query key: subscriptions to the loading state or the queue of the key, one for every mounted
90
+ * `useFetch`, `useSubmit` and `useQueue` using it, plus every `onLoadingByQueue` and `onQueueChangeByKey` of the
91
+ * application.
92
+ */
93
+ queues: Record<string, number>;
94
+ };
95
+
25
96
  /*
26
97
  * Internal communication events used to communicate state between plugin and devtools app
27
98
  * */
@@ -1,3 +1,5 @@
1
+ import type { SocketInstance } from "@hyper-fetch/sockets";
2
+
1
3
  export type DevtoolsPluginOptions = {
2
4
  /**
3
5
  * Name of your application, it will be displayed in the HyperFlow app
@@ -19,4 +21,15 @@ export type DevtoolsPluginOptions = {
19
21
  * Displayed alongside the app name in HyperFlow to distinguish deployments.
20
22
  */
21
23
  environment?: string;
24
+ /**
25
+ * The `WebSocket` constructor used to connect to HyperFlow. Defaults to the global `WebSocket` of browsers,
26
+ * Node.js 22+, Deno and Bun. On older Node.js pass the one from the `ws` package: `import { WebSocket } from "ws"`.
27
+ */
28
+ WebSocket?: typeof WebSocket;
29
+ /**
30
+ * Sockets to inspect in HyperFlow next to the requests of the client: their connection, the messages they receive
31
+ * and send, and their errors.
32
+ * @example DevtoolsPlugin({ appName: "My App", sockets: [socket] })
33
+ */
34
+ sockets?: SocketInstance[];
22
35
  };
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "types": ["node"],
4
5
  "paths": {
5
6
  "@hyper-fetch/plugin-devtools": ["./src"]
6
7
  }
@@ -1,42 +0,0 @@
1
- import { Client } from "@hyper-fetch/core";
2
- import { createHttpMockingServer, createWebsocketMockingServer } from "@hyper-fetch/testing";
3
-
4
- import { DevtoolsPlugin } from "../../src/index";
5
-
6
- const {
7
- startServer: startWebsocketServer,
8
- stopServer: stopWebsocketServer,
9
- // emitListenerEvent,
10
- // expectEmitterEvent,
11
- } = createWebsocketMockingServer("ws://localhost:2137");
12
- const {
13
- resetMocks,
14
- startServer,
15
- stopServer,
16
- // mockRequest
17
- } = createHttpMockingServer();
18
-
19
- describe("Backend Devtools - Socket Test", () => {
20
- let client = new Client({ url: "shared-base-url" }).addPlugin(DevtoolsPlugin({ appName: "TestApp" }));
21
- let request = client.createRequest()({ endpoint: "/shared-endpoint" });
22
-
23
- beforeAll(() => {
24
- startServer();
25
- startWebsocketServer();
26
- });
27
- beforeEach(() => {
28
- client = new Client({ url: "shared-base-url" });
29
- request = client.createRequest()({ endpoint: "/shared-endpoint" });
30
- vi.resetAllMocks();
31
- vi.clearAllMocks();
32
- resetMocks();
33
- });
34
- afterAll(() => {
35
- stopWebsocketServer();
36
- stopServer();
37
- });
38
- it("should send REQUEST_CREATED event when a request is created", async () => {
39
- console.warn("test", request);
40
- expect(true).toBe(true);
41
- });
42
- });