@jskit-ai/realtime 0.2.40 → 0.2.42

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/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - **Breaking.** The Redis backplane's address is read from `REALTIME_REDIS_URL`, the name the realtime guide, the `realtime/realtime-application` pattern and its `.env.example` give. It was read from `REDIS_URL`, so an app that set the documented name stayed on the in-process adapter, and each of its copies behind a load balancer delivered events only to the browsers connected to that copy. An app that set `REDIS_URL` for realtime sets `REALTIME_REDIS_URL` instead; `REDIS_NAMESPACE` is unchanged. The pattern's test now reads the name from the runtime, so the two cannot drift apart again.
5
6
  - A publish to a user or workspace room no longer reads the memberships of every online actor. It asks each audience contributor about the actors of the sockets outside its target rooms only for those rooms' scopes, `resolveActorsScopes(actorIds, { scopes })`, and keeps only those rooms of the answer, while the actors already inside are looked up in full for their checks. A contributor that ignores `scopes` still answers correctly. Before, every write action read the memberships of every signed-in socket's actor, so the cost grew with everyone online, also for an event to one user.
6
7
  - Since 0.2.20, an event a background job publishes (an action run with no request, so no request workspace) no longer reads its audience's `audienceUsers` in the `workspaceId` its payload names: with no workspace or user in its scope it reads with no context, so an audience over an owned table reaches nobody. Run the job's action with the workspace in its context (`context.workspace`, or a visibility scope naming it) so its audience reads there.
7
8
  - Since 0.2.20, `all_workspace_users` on an event written on a customer's or a public surface reaches the users of the workspace the request resolved; before, such an event reached no workspace's users. An audience meant for the writer alone names the user instead.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/realtime",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -24,7 +24,7 @@
24
24
  "socket.io-client": "^4.8.3"
25
25
  },
26
26
  "peerDependencies": {
27
- "@jskit-ai/kernel": "0.2.26",
27
+ "@jskit-ai/kernel": "0.2.27",
28
28
  "vue": "^3.5.13"
29
29
  },
30
30
  "description": "Thin, generic realtime runtime wrappers for socket.io server and client.",
@@ -1 +1,2 @@
1
+ # Empty for one server process. With several copies of the app, the same Redis on every copy.
1
2
  REALTIME_REDIS_URL=
@@ -2,7 +2,7 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/realtime": "0.2.40",
6
- "@jskit-ai/shell-web": "0.2.37"
5
+ "@jskit-ai/realtime": "0.2.42",
6
+ "@jskit-ai/shell-web": "0.2.39"
7
7
  }
8
8
  }
@@ -3,7 +3,8 @@ import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
3
3
  import { toRequestPathname } from "@jskit-ai/kernel/shared/surface/paths";
4
4
 
5
5
  const SOCKET_IO_PATH = "/socket.io";
6
- const REDIS_URL_ENV_KEY = "REDIS_URL";
6
+ // The name the realtime guide, the realtime-application pattern and its .env.example give.
7
+ const REDIS_URL_ENV_KEY = "REALTIME_REDIS_URL";
7
8
  const REDIS_NAMESPACE_ENV_KEY = "REDIS_NAMESPACE";
8
9
 
9
10
  /** @param {import("@jskit-ai/kernel/server/types").RuntimeFastify | null} fastify */
@@ -2,15 +2,20 @@ import assert from "node:assert/strict";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import test from "node:test";
4
4
 
5
+ import { REDIS_URL_ENV_KEY } from "../src/server/runtime.js";
6
+
5
7
  test("realtime application pattern keeps Redis and placement explicit", async () => {
6
8
  const root = new URL("../patterns/realtime-application/", import.meta.url);
7
- const source = await Promise.all([
9
+ const [pattern, envExample, placement] = await Promise.all([
8
10
  readFile(new URL("PATTERN.md", root), "utf8"),
9
11
  readFile(new URL("example/.env.example", root), "utf8"),
10
12
  readFile(new URL("example/src/placement.js", root), "utf8")
11
- ]).then((parts) => parts.join("\n"));
13
+ ]);
14
+ const source = [pattern, envExample, placement].join("\n");
12
15
 
13
- assert.match(source, /REALTIME_REDIS_URL/u);
16
+ // The setting the example and the pattern name is the one the runtime reads.
17
+ assert.deepEqual(envExample.split("\n").filter((line) => line.trim() && !line.startsWith("#")), [`${REDIS_URL_ENV_KEY}=`]);
18
+ assert.match(pattern, new RegExp(`\`${REDIS_URL_ENV_KEY}\``, "u"));
14
19
  assert.match(source, /realtime\.connection\.indicator/u);
15
20
  assert.doesNotMatch(source, /promptLabel|promptHint|\$\{option:/u);
16
21
  });
@@ -203,6 +203,13 @@ test("resolveRealtimeRedisUrl reads and normalizes env URL", () => {
203
203
  assert.equal(resolveRealtimeRedisUrl({ [REDIS_URL_ENV_KEY]: " redis://localhost:6379 " }), "redis://localhost:6379");
204
204
  });
205
205
 
206
+ test("the Redis backplane is REALTIME_REDIS_URL, the name the guide and the pattern give, and not REDIS_URL", () => {
207
+ // Before, it was REDIS_URL: an app that set the documented name stayed on the in-process adapter, and each of its
208
+ // copies delivered events only to its own browsers.
209
+ assert.equal(resolveRealtimeRedisUrl({ REALTIME_REDIS_URL: "redis://localhost:6379" }), "redis://localhost:6379");
210
+ assert.equal(resolveRealtimeRedisUrl({ REDIS_URL: "redis://localhost:6379" }), "");
211
+ });
212
+
206
213
  test("resolveRealtimeRedisNamespace reads and normalizes env namespace", () => {
207
214
  assert.equal(resolveRealtimeRedisNamespace({}), "");
208
215
  assert.equal(