@mauroandre/velojs 0.0.57 → 0.0.59
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 +91 -2
- package/agent/AGENTS.md +2 -0
- package/agent/skills/velojs-live-loader/SKILL.md +3 -1
- package/agent/skills/velojs-production-deploy/SKILL.md +7 -1
- package/agent/skills/velojs-telemetry/SKILL.md +182 -0
- package/dist/channels.d.ts +8 -1
- package/dist/channels.js +282 -227
- package/dist/cli.js +46 -32
- package/dist/events.d.ts +9 -1
- package/dist/events.js +161 -152
- package/dist/server.js +245 -198
- package/dist/sockets.d.ts +4 -1
- package/dist/sockets.js +115 -102
- package/dist/telemetry-cli.d.ts +67 -0
- package/dist/telemetry-cli.js +265 -0
- package/dist/telemetry-node.d.ts +38 -0
- package/dist/telemetry-node.js +93 -0
- package/dist/telemetry.d.ts +204 -0
- package/dist/telemetry.js +240 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { spawnSync as
|
|
1
|
+
import { spawnSync as c } from "node:child_process";
|
|
2
2
|
import { join as n, resolve as u } from "node:path";
|
|
3
3
|
import p from "node:fs";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const s = process.argv.slice(2), a = s[0], v = (t, e = []) => {
|
|
5
|
+
const r = c(t, e, {
|
|
6
6
|
stdio: "inherit",
|
|
7
7
|
cwd: process.cwd()
|
|
8
8
|
});
|
|
9
|
-
process.exit(
|
|
10
|
-
},
|
|
11
|
-
v("npx", ["vite", ...
|
|
12
|
-
},
|
|
13
|
-
const e = Date.now().toString(36),
|
|
9
|
+
process.exit(r.status ?? 0);
|
|
10
|
+
}, g = () => {
|
|
11
|
+
v("npx", ["vite", ...s.slice(1)]);
|
|
12
|
+
}, j = (t) => {
|
|
13
|
+
const e = Date.now().toString(36), r = {
|
|
14
14
|
...process.env,
|
|
15
15
|
VELO_BUILD_HASH: e,
|
|
16
|
-
...
|
|
16
|
+
...t ? { VELO_STATIC: "1" } : {}
|
|
17
17
|
};
|
|
18
18
|
console.log("Building client...");
|
|
19
|
-
const
|
|
19
|
+
const o = c("npx", ["vite", "build"], {
|
|
20
20
|
stdio: "inherit",
|
|
21
21
|
cwd: process.cwd(),
|
|
22
|
-
env:
|
|
22
|
+
env: r
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
const i =
|
|
24
|
+
o.status !== 0 && (console.error("Client build failed. Aborting."), process.exit(o.status ?? 1)), console.log("Building server...");
|
|
25
|
+
const i = c("npx", ["vite", "build", "--mode", "server"], {
|
|
26
26
|
stdio: "inherit",
|
|
27
27
|
cwd: process.cwd(),
|
|
28
|
-
env:
|
|
28
|
+
env: r
|
|
29
29
|
});
|
|
30
|
-
i.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(i.status ?? 1)), console.log("Build complete!"),
|
|
31
|
-
},
|
|
30
|
+
i.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(i.status ?? 1)), console.log("Build complete!"), t && f();
|
|
31
|
+
}, f = async () => {
|
|
32
32
|
process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
|
|
33
|
-
const e = await import(u(process.cwd(), "dist/server.js")),
|
|
34
|
-
(!
|
|
33
|
+
const e = await import(u(process.cwd(), "dist/server.js")), r = e.default, o = e.routes;
|
|
34
|
+
(!r || !o) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
|
|
35
35
|
const { generateStatic: i } = await import("./static.js");
|
|
36
|
-
await i(
|
|
36
|
+
await i(r, o);
|
|
37
37
|
}, b = () => {
|
|
38
38
|
process.env.NODE_ENV = "production";
|
|
39
|
-
const
|
|
40
|
-
v("node", [
|
|
39
|
+
const t = u(process.cwd(), "dist/server.js");
|
|
40
|
+
v("node", [t]);
|
|
41
41
|
}, d = () => {
|
|
42
42
|
console.log(`
|
|
43
43
|
VeloJS CLI
|
|
@@ -53,6 +53,8 @@ Commands:
|
|
|
53
53
|
start Start production server
|
|
54
54
|
graph [app-dir] Generate .velojs/graph.json (route tree + dependency graph)
|
|
55
55
|
graph --view Generate the graph and open an interactive viewer
|
|
56
|
+
telemetry [path] Rank the native telemetry JSONL (count, p50/p95, errors, bytes)
|
|
57
|
+
by route/action/channel; no path reads VELO_TELEMETRY_FILE
|
|
56
58
|
|
|
57
59
|
Examples:
|
|
58
60
|
velojs init my-app
|
|
@@ -63,45 +65,57 @@ Examples:
|
|
|
63
65
|
velojs graph
|
|
64
66
|
velojs graph src/app
|
|
65
67
|
velojs graph --view
|
|
68
|
+
velojs telemetry
|
|
69
|
+
velojs telemetry --last 60m
|
|
70
|
+
velojs telemetry ./telemetry.prod.jsonl
|
|
66
71
|
`);
|
|
67
72
|
};
|
|
68
|
-
switch (
|
|
73
|
+
switch (a) {
|
|
69
74
|
case "init": {
|
|
70
|
-
const { runInit:
|
|
75
|
+
const { runInit: t } = await import("./init.js");
|
|
71
76
|
try {
|
|
72
|
-
const e =
|
|
73
|
-
await
|
|
77
|
+
const e = s[1] && !s[1].startsWith("-") ? s[1] : void 0;
|
|
78
|
+
await t(e, { force: s.includes("--force") });
|
|
74
79
|
} catch (e) {
|
|
75
80
|
console.error(e.message), process.exit(1);
|
|
76
81
|
}
|
|
77
82
|
break;
|
|
78
83
|
}
|
|
79
84
|
case "dev":
|
|
80
|
-
|
|
85
|
+
g();
|
|
81
86
|
break;
|
|
82
87
|
case "build": {
|
|
83
|
-
const
|
|
84
|
-
|
|
88
|
+
const t = s.includes("--static");
|
|
89
|
+
j(t);
|
|
85
90
|
break;
|
|
86
91
|
}
|
|
87
92
|
case "start":
|
|
88
93
|
b();
|
|
89
94
|
break;
|
|
90
95
|
case "graph": {
|
|
91
|
-
const { buildGraph:
|
|
96
|
+
const { buildGraph: t } = await import("./graph.js"), e = process.cwd(), r = s[1] && !s[1].startsWith("-") ? s[1] : null, o = n(e, r ?? "app"), i = t(o), l = n(e, ".velojs");
|
|
92
97
|
p.mkdirSync(l, { recursive: !0 });
|
|
93
|
-
const
|
|
94
|
-
if (p.writeFileSync(
|
|
98
|
+
const m = n(l, "graph.json");
|
|
99
|
+
if (p.writeFileSync(m, JSON.stringify(i)), console.log("Graph written to .velojs/graph.json"), s.includes("--view")) {
|
|
95
100
|
const { serveGraphViewer: h } = await import("./graph-viewer.js"), w = await h(e);
|
|
96
101
|
console.log(`Graph viewer running at ${w} (Ctrl+C to stop)`);
|
|
97
102
|
}
|
|
98
103
|
break;
|
|
99
104
|
}
|
|
105
|
+
case "telemetry": {
|
|
106
|
+
const { runTelemetryCli: t } = await import("./telemetry-cli.js");
|
|
107
|
+
try {
|
|
108
|
+
await t(s.slice(1));
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error(e.message), process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
100
114
|
case "help":
|
|
101
115
|
case "--help":
|
|
102
116
|
case "-h":
|
|
103
117
|
d();
|
|
104
118
|
break;
|
|
105
119
|
default:
|
|
106
|
-
|
|
120
|
+
a && console.error(`Unknown command: ${a}`), d(), process.exit(1);
|
|
107
121
|
}
|
package/dist/events.d.ts
CHANGED
|
@@ -314,6 +314,14 @@ export declare function poll<TEvent>(opts: {
|
|
|
314
314
|
/**
|
|
315
315
|
* Registers a GET SSE route for the given stream at the given path.
|
|
316
316
|
* Used both by standalone streams and by stream_* discovery.
|
|
317
|
+
*
|
|
318
|
+
* `info` carries the convention identity (moduleId + stream name) into the
|
|
319
|
+
* telemetry `stream-connect` trace; standalone streams pass none and are
|
|
320
|
+
* addressed by their declared path only.
|
|
317
321
|
*/
|
|
318
|
-
export
|
|
322
|
+
export interface StreamTelemetryInfo {
|
|
323
|
+
moduleId?: string | undefined;
|
|
324
|
+
name?: string | undefined;
|
|
325
|
+
}
|
|
326
|
+
export declare function registerStreamHandler<TEvent, TSnapshot>(app: Hono, path: string, stream: EventStream<TEvent, TSnapshot>, middlewares?: Array<(c: Context, next: () => Promise<void>) => any>, info?: StreamTelemetryInfo): void;
|
|
319
327
|
export {};
|
package/dist/events.js
CHANGED
|
@@ -1,165 +1,166 @@
|
|
|
1
|
-
import { getAppContext as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { getAppContext as q } from "./app-context.js";
|
|
2
|
+
import { trace as L, byteLength as P } from "./telemetry.js";
|
|
3
|
+
const N = 2e4, k = 300 * 1e3, C = "";
|
|
4
|
+
function x(r) {
|
|
5
|
+
const n = q().pendingStreamRoutes.splice(0);
|
|
6
|
+
for (const u of n) u(r);
|
|
6
7
|
}
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return
|
|
8
|
+
const D = /* @__PURE__ */ new Set();
|
|
9
|
+
function z() {
|
|
10
|
+
return D;
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
+
function H(r = {}) {
|
|
12
13
|
if (r.broadcast && r.channel && console.warn(
|
|
13
14
|
"[velojs] createEventStream: `broadcast: true` ignores `channel`. Remove one of them — broadcast streams have no channels."
|
|
14
15
|
), (r.source ? 1 : 0) + (r.perChannelSource ? 1 : 0) + (r.pipe ? 1 : 0) > 1)
|
|
15
16
|
throw new Error(
|
|
16
17
|
"[velojs] createEventStream: `source`, `perChannelSource`, and `pipe` are mutually exclusive — pick one. `source` is stream-wide, `perChannelSource` and `pipe` are per-channel (prefer `pipe` for new code)."
|
|
17
18
|
);
|
|
18
|
-
const
|
|
19
|
-
let
|
|
20
|
-
const
|
|
21
|
-
r.source && (
|
|
22
|
-
r.source(
|
|
19
|
+
const n = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Map();
|
|
20
|
+
let l = null, i = 0;
|
|
21
|
+
const S = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), A = () => {
|
|
22
|
+
r.source && (l || (l = new AbortController(), Promise.resolve(
|
|
23
|
+
r.source(b, { abortSignal: l.signal })
|
|
23
24
|
).catch((e) => {
|
|
24
25
|
console.error("[velojs] event stream source threw:", e);
|
|
25
26
|
})));
|
|
26
|
-
},
|
|
27
|
-
i > 0 ||
|
|
28
|
-
},
|
|
29
|
-
if (!r.perChannelSource ||
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const s = (
|
|
33
|
-
|
|
27
|
+
}, I = () => {
|
|
28
|
+
i > 0 || l && (l.abort(), l = null);
|
|
29
|
+
}, d = (e) => {
|
|
30
|
+
if (!r.perChannelSource || S.has(e)) return;
|
|
31
|
+
const o = new AbortController();
|
|
32
|
+
S.set(e, o);
|
|
33
|
+
const s = (t, a) => {
|
|
34
|
+
f.emit(e, t, a);
|
|
34
35
|
};
|
|
35
36
|
Promise.resolve(
|
|
36
|
-
r.perChannelSource(e, s, { abortSignal:
|
|
37
|
-
).catch((
|
|
37
|
+
r.perChannelSource(e, s, { abortSignal: o.signal })
|
|
38
|
+
).catch((t) => {
|
|
38
39
|
console.error(
|
|
39
40
|
`[velojs] perChannelSource threw for channel "${e}":`,
|
|
40
|
-
|
|
41
|
+
t
|
|
41
42
|
);
|
|
42
43
|
});
|
|
43
|
-
},
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
}, w = (e,
|
|
47
|
-
if (!r.pipe ||
|
|
44
|
+
}, h = (e) => {
|
|
45
|
+
const o = S.get(e);
|
|
46
|
+
o && (o.abort(), S.delete(e));
|
|
47
|
+
}, w = (e, o) => {
|
|
48
|
+
if (!r.pipe || c.has(e) || !o)
|
|
48
49
|
return;
|
|
49
50
|
const s = new AbortController();
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
|
|
51
|
+
c.set(e, s);
|
|
52
|
+
let t = !1;
|
|
53
|
+
const a = (g, m) => {
|
|
54
|
+
f.emit(e, g, m);
|
|
55
|
+
}, T = () => f.close(e), j = () => {
|
|
56
|
+
t = !0;
|
|
56
57
|
};
|
|
57
58
|
Promise.resolve(
|
|
58
59
|
r.pipe({
|
|
59
|
-
send:
|
|
60
|
+
send: a,
|
|
60
61
|
keepOpen: j,
|
|
61
|
-
close:
|
|
62
|
+
close: T,
|
|
62
63
|
abortSignal: s.signal,
|
|
63
|
-
c:
|
|
64
|
-
params:
|
|
65
|
-
query:
|
|
64
|
+
c: o.c,
|
|
65
|
+
params: o.params,
|
|
66
|
+
query: o.query,
|
|
66
67
|
channel: e
|
|
67
68
|
})
|
|
68
69
|
).then(() => {
|
|
69
|
-
s.signal.aborted ||
|
|
70
|
+
s.signal.aborted || t || f.close(e);
|
|
70
71
|
}).catch((g) => {
|
|
71
72
|
console.error(
|
|
72
73
|
`[velojs] stream pipe threw for channel "${e}":`,
|
|
73
74
|
g
|
|
74
|
-
), s.signal.aborted ||
|
|
75
|
+
), s.signal.aborted || f.close(e);
|
|
75
76
|
});
|
|
76
|
-
},
|
|
77
|
-
const
|
|
78
|
-
|
|
77
|
+
}, M = (e) => {
|
|
78
|
+
const o = c.get(e);
|
|
79
|
+
o && (o.abort(), c.delete(e));
|
|
79
80
|
};
|
|
80
|
-
function
|
|
81
|
-
let
|
|
82
|
-
if (!!r.broadcast ? (
|
|
81
|
+
function b(e, o, s) {
|
|
82
|
+
let t, a, T;
|
|
83
|
+
if (!!r.broadcast ? (t = C, a = e, T = o) : (t = e, a = o, T = s), p.has(t)) {
|
|
83
84
|
console.warn(
|
|
84
|
-
`[velojs] emit() called on closed channel "${
|
|
85
|
+
`[velojs] emit() called on closed channel "${t}" — ignored. Reopen the channel by emitting to a fresh ID, or remove the close() call.`
|
|
85
86
|
);
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
|
-
if (
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
89
|
+
if (T?.snapshot) {
|
|
90
|
+
const m = u.get(t) ?? [];
|
|
91
|
+
m.push(a);
|
|
92
|
+
const R = r.bufferSize ?? 1 / 0;
|
|
93
|
+
m.length > R && m.splice(0, m.length - R), u.set(t, m);
|
|
93
94
|
}
|
|
94
|
-
const g =
|
|
95
|
+
const g = n.get(t);
|
|
95
96
|
if (g)
|
|
96
|
-
for (const
|
|
97
|
+
for (const m of g) m(a);
|
|
97
98
|
}
|
|
98
|
-
function
|
|
99
|
+
function E(e = C) {
|
|
99
100
|
if (p.has(e)) return;
|
|
100
101
|
p.add(e);
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
for (const
|
|
104
|
-
const s = r.retainMs ??
|
|
105
|
-
|
|
102
|
+
const o = n.get(e);
|
|
103
|
+
if (o)
|
|
104
|
+
for (const a of o) a.close();
|
|
105
|
+
const s = r.retainMs ?? k, t = v.get(e);
|
|
106
|
+
t && clearTimeout(t), v.set(
|
|
106
107
|
e,
|
|
107
108
|
setTimeout(() => {
|
|
108
|
-
|
|
109
|
+
u.delete(e), v.delete(e), p.delete(e);
|
|
109
110
|
}, s)
|
|
110
111
|
);
|
|
111
112
|
}
|
|
112
|
-
const
|
|
113
|
-
emit:
|
|
114
|
-
close:
|
|
113
|
+
const f = {
|
|
114
|
+
emit: b,
|
|
115
|
+
close: E,
|
|
115
116
|
__isVeloEventStream: !0,
|
|
116
117
|
__config: r,
|
|
117
|
-
__listeners:
|
|
118
|
-
__buffers:
|
|
118
|
+
__listeners: n,
|
|
119
|
+
__buffers: u,
|
|
119
120
|
__path: r.path,
|
|
120
|
-
__onConnect(e,
|
|
121
|
-
let
|
|
122
|
-
const
|
|
123
|
-
|
|
121
|
+
__onConnect(e, o, s) {
|
|
122
|
+
let t = n.get(e);
|
|
123
|
+
const a = !t || t.size === 0;
|
|
124
|
+
t || (t = /* @__PURE__ */ new Set(), n.set(e, t)), t.add(o), i++, A(), a && (d(e), w(e, s));
|
|
124
125
|
},
|
|
125
|
-
__onDisconnect(e,
|
|
126
|
-
const s =
|
|
127
|
-
s && (s.delete(
|
|
126
|
+
__onDisconnect(e, o) {
|
|
127
|
+
const s = n.get(e);
|
|
128
|
+
s && (s.delete(o), s.size === 0 && (n.delete(e), h(e), M(e)), i--, I());
|
|
128
129
|
},
|
|
129
130
|
__reset() {
|
|
130
|
-
for (const e of
|
|
131
|
-
for (const
|
|
131
|
+
for (const e of n.values())
|
|
132
|
+
for (const o of e)
|
|
132
133
|
try {
|
|
133
|
-
|
|
134
|
+
o.close();
|
|
134
135
|
} catch {
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
-
for (const e of
|
|
138
|
-
|
|
139
|
-
for (const e of h.values()) e.abort();
|
|
140
|
-
h.clear();
|
|
137
|
+
n.clear(), u.clear(), p.clear();
|
|
138
|
+
for (const e of v.values()) clearTimeout(e);
|
|
139
|
+
v.clear(), l && (l.abort(), l = null);
|
|
141
140
|
for (const e of S.values()) e.abort();
|
|
142
|
-
S.clear()
|
|
141
|
+
S.clear();
|
|
142
|
+
for (const e of c.values()) e.abort();
|
|
143
|
+
c.clear(), i = 0;
|
|
143
144
|
}
|
|
144
145
|
};
|
|
145
|
-
return r.path &&
|
|
146
|
-
|
|
147
|
-
}),
|
|
146
|
+
return r.path && q().pendingStreamRoutes.push((e) => {
|
|
147
|
+
y(e, r.path, f, r.middlewares ?? []);
|
|
148
|
+
}), D.add(f), f;
|
|
148
149
|
}
|
|
149
|
-
function
|
|
150
|
-
return async (
|
|
151
|
-
for (; !
|
|
150
|
+
function J(r) {
|
|
151
|
+
return async (_, { abortSignal: n }) => {
|
|
152
|
+
for (; !n.aborted; ) {
|
|
152
153
|
try {
|
|
153
|
-
await r.tick(
|
|
154
|
-
} catch (
|
|
155
|
-
console.error("[velojs] poll tick threw:",
|
|
154
|
+
await r.tick(_);
|
|
155
|
+
} catch (u) {
|
|
156
|
+
console.error("[velojs] poll tick threw:", u);
|
|
156
157
|
}
|
|
157
|
-
await new Promise((
|
|
158
|
-
const p = setTimeout(
|
|
159
|
-
|
|
158
|
+
await new Promise((u) => {
|
|
159
|
+
const p = setTimeout(u, r.intervalMs);
|
|
160
|
+
n.addEventListener(
|
|
160
161
|
"abort",
|
|
161
162
|
() => {
|
|
162
|
-
clearTimeout(p),
|
|
163
|
+
clearTimeout(p), u();
|
|
163
164
|
},
|
|
164
165
|
{ once: !0 }
|
|
165
166
|
);
|
|
@@ -167,75 +168,83 @@ function z(r) {
|
|
|
167
168
|
}
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
|
-
function
|
|
171
|
-
return r.req.query("channel") ??
|
|
171
|
+
function F(r) {
|
|
172
|
+
return r.req.query("channel") ?? C;
|
|
172
173
|
}
|
|
173
|
-
function
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
function y(r, _, n, u = [], p = {}) {
|
|
175
|
+
const v = async (l) => {
|
|
176
|
+
const i = L("stream-connect", {
|
|
177
|
+
route: _,
|
|
178
|
+
module: p.moduleId,
|
|
179
|
+
name: p.name
|
|
180
|
+
}), { streamSSE: S } = await import("hono/streaming");
|
|
181
|
+
let c;
|
|
182
|
+
if (n.__config.broadcast)
|
|
183
|
+
c = C;
|
|
179
184
|
else {
|
|
180
|
-
const d =
|
|
181
|
-
let
|
|
185
|
+
const d = n.__config.channel ?? F;
|
|
186
|
+
let h;
|
|
182
187
|
try {
|
|
183
|
-
|
|
184
|
-
} catch (
|
|
185
|
-
return console.error("[velojs] channel resolver threw:",
|
|
188
|
+
h = await d(l);
|
|
189
|
+
} catch (w) {
|
|
190
|
+
return console.error("[velojs] channel resolver threw:", w), i.end({ status: "error" }), l.json({ error: "internal" }, 500);
|
|
186
191
|
}
|
|
187
|
-
if (
|
|
188
|
-
return l.json({ error: "forbidden" }, 403);
|
|
189
|
-
|
|
192
|
+
if (h == null)
|
|
193
|
+
return i.end({ status: "error" }), l.json({ error: "forbidden" }, 403);
|
|
194
|
+
c = h;
|
|
190
195
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
i.setFields({ channel: c === C ? void 0 : c });
|
|
197
|
+
const A = n.__config.heartbeatMs, I = A === !1 ? 0 : A ?? N;
|
|
198
|
+
return S(l, async (d) => {
|
|
199
|
+
const h = n.__buffers.get(c);
|
|
200
|
+
if (h && h.length > 0) {
|
|
201
|
+
const t = JSON.stringify(h);
|
|
202
|
+
await d.writeSSE({ event: "snapshot", data: t }), i.enabled && i.delivery(P(t));
|
|
203
|
+
}
|
|
204
|
+
if (n.__config.snapshot) {
|
|
205
|
+
const t = await n.__config.snapshot(
|
|
206
|
+
c === C ? void 0 : c
|
|
200
207
|
);
|
|
201
|
-
t !== void 0
|
|
202
|
-
|
|
203
|
-
data:
|
|
204
|
-
}
|
|
208
|
+
if (t !== void 0) {
|
|
209
|
+
const a = JSON.stringify(t);
|
|
210
|
+
await d.writeSSE({ event: "snapshot", data: a }), i.enabled && i.delivery(P(a));
|
|
211
|
+
}
|
|
205
212
|
}
|
|
206
|
-
let
|
|
207
|
-
const
|
|
208
|
-
|
|
213
|
+
let w;
|
|
214
|
+
const M = new Promise((t) => {
|
|
215
|
+
w = t;
|
|
209
216
|
});
|
|
210
|
-
let
|
|
211
|
-
const
|
|
212
|
-
}),
|
|
213
|
-
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}))
|
|
217
|
+
let b = !1, E = null, f = Promise.resolve();
|
|
218
|
+
const e = (t) => (f = f.then(() => d.writeSSE(t)).catch(() => {
|
|
219
|
+
}), f), o = () => {
|
|
220
|
+
b || (b = !0, E && clearInterval(E), n.__onDisconnect(c, s), i.close(), w());
|
|
221
|
+
}, s = ((t) => {
|
|
222
|
+
if (b) return;
|
|
223
|
+
const a = JSON.stringify(t);
|
|
224
|
+
i.enabled && i.delivery(P(a)), e({ data: a }), n.__config.closeOn?.(t) && f.then(() => {
|
|
225
|
+
d.close(), o();
|
|
226
|
+
});
|
|
218
227
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
d.close(),
|
|
228
|
+
s.close = () => {
|
|
229
|
+
b || (e({ event: "close", data: "" }), f.then(() => {
|
|
230
|
+
d.close(), o();
|
|
222
231
|
}));
|
|
223
|
-
},
|
|
232
|
+
}, n.__onConnect(c, s, {
|
|
224
233
|
c: l,
|
|
225
234
|
params: l.req.param(),
|
|
226
235
|
query: l.req.query()
|
|
227
|
-
}), E =
|
|
228
|
-
|
|
229
|
-
},
|
|
236
|
+
}), E = I > 0 ? setInterval(() => {
|
|
237
|
+
b || e({ event: "heartbeat", data: "" });
|
|
238
|
+
}, I) : null, d.onAbort(o), i.end({ status: "ok" }), await M;
|
|
230
239
|
});
|
|
231
240
|
};
|
|
232
|
-
|
|
241
|
+
u.length > 0 ? r.on(["GET"], [_], ...u, v) : r.on(["GET"], [_], v);
|
|
233
242
|
}
|
|
234
243
|
export {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
N as DEFAULT_HEARTBEAT_MS,
|
|
245
|
+
H as createEventStream,
|
|
246
|
+
x as flushPendingStreamRoutes,
|
|
247
|
+
z as getRegisteredStreams,
|
|
248
|
+
J as poll,
|
|
249
|
+
y as registerStreamHandler
|
|
241
250
|
};
|