sse-cat 3.0.0 → 3.0.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/lib/subscribe-events.js +16 -17
- package/lib/subscribe-events.js.map +1 -1
- package/package.json +2 -2
package/lib/subscribe-events.js
CHANGED
|
@@ -4,29 +4,24 @@ import { Request } from 'extra-fetch';
|
|
|
4
4
|
import { isntUndefined } from '@blackglory/prelude';
|
|
5
5
|
import { AbortController, AbortError } from 'extra-abort';
|
|
6
6
|
export async function* subscribeMessages(url, { events, headers, heartbeat }) {
|
|
7
|
-
let cancelHeartbeatTimeout
|
|
8
|
-
let lastEventId
|
|
7
|
+
let cancelHeartbeatTimeout;
|
|
8
|
+
let lastEventId;
|
|
9
9
|
while (true) {
|
|
10
10
|
try {
|
|
11
11
|
const controller = new AbortController();
|
|
12
|
-
for await (const { event = 'message', data, id } of fetchEvents(() => new Request(url, { headers, signal: controller.signal }), {
|
|
12
|
+
for await (const { event = 'message', data, id } of fetchEvents(() => new Request(url, { headers, signal: controller.signal }), {
|
|
13
|
+
lastEventId,
|
|
14
|
+
onOpen() {
|
|
15
|
+
if (heartbeat) {
|
|
16
|
+
resetHeartbeatTimeout(controller, heartbeat.timeout);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
})) {
|
|
13
20
|
if (isntUndefined(lastEventId)) {
|
|
14
21
|
lastEventId = id;
|
|
15
22
|
}
|
|
16
|
-
if (heartbeat) {
|
|
17
|
-
|
|
18
|
-
if (heartbeat.event === event) {
|
|
19
|
-
cancelHeartbeatTimeout();
|
|
20
|
-
cancelHeartbeatTimeout = setTimeout(heartbeat.timeout, () => {
|
|
21
|
-
controller.abort();
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
cancelHeartbeatTimeout = setTimeout(heartbeat.timeout, () => {
|
|
27
|
-
controller.abort();
|
|
28
|
-
});
|
|
29
|
-
}
|
|
23
|
+
if (heartbeat && event === heartbeat.event) {
|
|
24
|
+
resetHeartbeatTimeout(controller, heartbeat.timeout);
|
|
30
25
|
}
|
|
31
26
|
if (events.includes(event)) {
|
|
32
27
|
if (isntUndefined(data)) {
|
|
@@ -47,5 +42,9 @@ export async function* subscribeMessages(url, { events, headers, heartbeat }) {
|
|
|
47
42
|
cancelHeartbeatTimeout === null || cancelHeartbeatTimeout === void 0 ? void 0 : cancelHeartbeatTimeout();
|
|
48
43
|
}
|
|
49
44
|
}
|
|
45
|
+
function resetHeartbeatTimeout(controller, timeout) {
|
|
46
|
+
cancelHeartbeatTimeout === null || cancelHeartbeatTimeout === void 0 ? void 0 : cancelHeartbeatTimeout();
|
|
47
|
+
cancelHeartbeatTimeout = setTimeout(timeout, () => controller.abort());
|
|
48
|
+
}
|
|
50
49
|
}
|
|
51
50
|
//# sourceMappingURL=subscribe-events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-events.js","sourceRoot":"","sources":["../src/subscribe-events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOzD,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,iBAAiB,CACtC,GAAW,EACX,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAI3B;IAED,IAAI,
|
|
1
|
+
{"version":3,"file":"subscribe-events.js","sourceRoot":"","sources":["../src/subscribe-events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,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CAAC,CAAA;aACR;SACF;gBAAS;YACR,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,EAAI,CAAA;SAC3B;KACF;IAED,SAAS,qBAAqB,CAAC,UAA2B,EAAE,OAAe;QACzE,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,EAAI,CAAA;QAC1B,sBAAsB,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IACxE,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sse-cat",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Command-line client for Server-Sent Events(SSE).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"extra-abort": "^0.3.7",
|
|
79
79
|
"extra-fetch": "^4.0.7",
|
|
80
80
|
"extra-filesystem": "^0.5.1",
|
|
81
|
-
"extra-sse": "^0.3.
|
|
81
|
+
"extra-sse": "^0.3.1",
|
|
82
82
|
"extra-timers": "^0.2.6",
|
|
83
83
|
"justypes": "^4.2.1"
|
|
84
84
|
}
|