@jskit-ai/realtime 0.1.155 → 0.1.157
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/package.json +25 -69
- package/patterns/realtime-application/PATTERN.md +69 -0
- package/patterns/realtime-application/example/.env.example +1 -0
- package/patterns/realtime-application/example/package.json +8 -0
- package/patterns/realtime-application/example/src/placement.js +17 -0
- package/src/client/RealtimeClientProvider.js +81 -203
- package/src/server/RealtimeProvider.js +98 -0
- package/src/server/realtimeAudience.js +220 -0
- package/src/server/realtimeDelivery.js +41 -0
- package/test/entrypoints.boundary.test.js +6 -12
- package/test/providerRuntime.test.js +187 -730
- package/test/realtimeApplicationPattern.test.js +16 -0
- package/src/client/listeners.js +0 -68
- package/src/server/RealtimeServiceProvider.js +0 -764
- package/test/clientListeners.test.js +0 -66
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
|
|
5
|
+
test("realtime application pattern keeps Redis and placement explicit", async () => {
|
|
6
|
+
const root = new URL("../patterns/realtime-application/", import.meta.url);
|
|
7
|
+
const source = await Promise.all([
|
|
8
|
+
readFile(new URL("PATTERN.md", root), "utf8"),
|
|
9
|
+
readFile(new URL("example/.env.example", root), "utf8"),
|
|
10
|
+
readFile(new URL("example/src/placement.js", root), "utf8")
|
|
11
|
+
]).then((parts) => parts.join("\n"));
|
|
12
|
+
|
|
13
|
+
assert.match(source, /REALTIME_REDIS_URL/u);
|
|
14
|
+
assert.match(source, /realtime\.connection\.indicator/u);
|
|
15
|
+
assert.doesNotMatch(source, /promptLabel|promptHint|\$\{option:/u);
|
|
16
|
+
});
|
package/src/client/listeners.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
-
|
|
3
|
-
function normalizeListenerEntries(value) {
|
|
4
|
-
const queue = Array.isArray(value) ? [...value] : [value];
|
|
5
|
-
const listeners = [];
|
|
6
|
-
|
|
7
|
-
while (queue.length > 0) {
|
|
8
|
-
const entry = queue.shift();
|
|
9
|
-
if (Array.isArray(entry)) {
|
|
10
|
-
queue.push(...entry);
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (entry == null) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
listeners.push(entry);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return listeners;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function normalizeRealtimeClientListener(entry) {
|
|
23
|
-
if (typeof entry === "function") {
|
|
24
|
-
return Object.freeze({
|
|
25
|
-
listenerId: String(entry.name || "anonymous"),
|
|
26
|
-
event: "*",
|
|
27
|
-
matches: null,
|
|
28
|
-
handle: entry
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (entry && typeof entry === "object" && typeof entry.handle === "function") {
|
|
33
|
-
const event = normalizeText(entry.event) || "*";
|
|
34
|
-
return Object.freeze({
|
|
35
|
-
...entry,
|
|
36
|
-
listenerId: String(entry.listenerId || "anonymous"),
|
|
37
|
-
event,
|
|
38
|
-
matches: typeof entry.matches === "function" ? entry.matches : null
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function registerRealtimeClientListener(app, token, factory) {
|
|
46
|
-
if (!app || typeof app.singleton !== "function" || typeof app.tag !== "function") {
|
|
47
|
-
throw new Error("registerRealtimeClientListener requires application singleton()/tag().");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
app.singleton(token, factory);
|
|
51
|
-
app.tag(token, "jskit.runtime.realtime.client.listeners");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function resolveRealtimeClientListeners(scope) {
|
|
55
|
-
if (!scope || typeof scope.resolveTag !== "function") {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return normalizeListenerEntries(scope.resolveTag("jskit.runtime.realtime.client.listeners"))
|
|
60
|
-
.map((entry) => normalizeRealtimeClientListener(entry))
|
|
61
|
-
.filter(Boolean);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
normalizeRealtimeClientListener,
|
|
66
|
-
registerRealtimeClientListener,
|
|
67
|
-
resolveRealtimeClientListeners
|
|
68
|
-
};
|