@velajs/vela 1.16.0 → 1.17.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.
Files changed (36) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.js +1 -1
  3. package/dist/live/index.d.ts +12 -0
  4. package/dist/live/index.js +16 -0
  5. package/dist/live/live.cursor.d.ts +22 -0
  6. package/dist/live/live.cursor.js +56 -0
  7. package/dist/live/live.decorators.d.ts +32 -0
  8. package/dist/live/live.decorators.js +46 -0
  9. package/dist/live/live.delta.d.ts +15 -0
  10. package/dist/live/live.delta.js +51 -0
  11. package/dist/live/live.engine.d.ts +81 -0
  12. package/dist/live/live.engine.js +448 -0
  13. package/dist/live/live.invalidation.d.ts +27 -0
  14. package/dist/live/live.invalidation.js +56 -0
  15. package/dist/live/live.module.d.ts +28 -0
  16. package/dist/live/live.module.js +83 -0
  17. package/dist/live/live.tokens.d.ts +9 -0
  18. package/dist/live/live.tokens.js +8 -0
  19. package/dist/live/live.types.d.ts +138 -0
  20. package/dist/live/live.types.js +1 -0
  21. package/dist/live/presence.d.ts +44 -0
  22. package/dist/live/presence.js +130 -0
  23. package/dist/websocket/index.d.ts +3 -3
  24. package/dist/websocket/index.js +2 -2
  25. package/dist/websocket/websocket.decorators.d.ts +14 -0
  26. package/dist/websocket/websocket.decorators.js +23 -1
  27. package/dist/websocket/websocket.tokens.d.ts +7 -0
  28. package/dist/websocket/websocket.tokens.js +6 -0
  29. package/dist/websocket/websocket.types.d.ts +16 -0
  30. package/dist/websocket/ws-dispatcher.d.ts +9 -0
  31. package/dist/websocket/ws-dispatcher.js +64 -1
  32. package/dist/websocket-node/index.d.ts +2 -0
  33. package/dist/websocket-node/index.js +1 -0
  34. package/dist/websocket-node/redis-live.d.ts +24 -0
  35. package/dist/websocket-node/redis-live.js +57 -0
  36. package/package.json +6 -1
@@ -0,0 +1,57 @@
1
+ const swallow = (op)=>{
2
+ void Promise.resolve(op).catch(()=>{});
3
+ };
4
+ /**
5
+ * Cross-instance live-invalidation driver for node/bun via Redis pub/sub —
6
+ * the live sibling of the WebSocket `redis()` sync driver, carrying TAGS
7
+ * instead of frames. Local-first: `dispatch` applies to this instance's
8
+ * engine immediately (its log stamps the returned commit cursor), then fans
9
+ * the command out so every peer re-runs ITS local subscriptions.
10
+ *
11
+ * Guarantees (same honesty as `redis()`): at-most-once, no cross-publisher
12
+ * ordering, no replay. Each instance keeps its own per-process epoch, so a
13
+ * client reconnecting onto a different instance always receives a full
14
+ * snapshot — exactly the protocol's multi-instance-node rule. Real cursor
15
+ * resume needs a shared ordered log (the Cloudflare DO transport).
16
+ */ export function redisLive(options) {
17
+ const prefix = options.prefix ?? 'vela:live';
18
+ const channel = `${prefix}:invalidate`;
19
+ const origin = crypto.randomUUID();
20
+ let sink;
21
+ let bound = false;
22
+ const onMessage = (ch, message)=>{
23
+ if (ch !== channel) return;
24
+ let cmd;
25
+ try {
26
+ cmd = JSON.parse(message);
27
+ } catch {
28
+ return;
29
+ }
30
+ if (cmd.origin === origin) return; // our own publish — already applied locally
31
+ if (sink) swallow(sink.applyInvalidation(cmd));
32
+ };
33
+ return {
34
+ kind: 'redis',
35
+ bind (boundSink) {
36
+ sink = boundSink;
37
+ if (bound) return; // idempotent — never stack duplicate 'message' listeners
38
+ bound = true;
39
+ swallow(options.sub.subscribe(channel));
40
+ options.sub.on('message', onMessage);
41
+ },
42
+ async dispatch (cmd) {
43
+ swallow(options.pub.publish(channel, JSON.stringify({
44
+ ...cmd,
45
+ origin
46
+ })));
47
+ return sink?.applyInvalidation(cmd);
48
+ },
49
+ stop () {
50
+ if (!bound) return;
51
+ bound = false;
52
+ options.sub.off?.('message', onMessage);
53
+ options.sub.removeListener?.('message', onMessage);
54
+ swallow(options.sub.unsubscribe?.(channel));
55
+ }
56
+ };
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/vela",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "NestJS-compatible framework for edge runtimes, powered by Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,6 +38,10 @@
38
38
  "types": "./dist/queue/index.d.ts",
39
39
  "import": "./dist/queue/index.js"
40
40
  },
41
+ "./live": {
42
+ "types": "./dist/live/index.d.ts",
43
+ "import": "./dist/live/index.js"
44
+ },
41
45
  "./storage": {
42
46
  "types": "./dist/storage/index.d.ts",
43
47
  "import": "./dist/storage/index.js"
@@ -84,6 +88,7 @@
84
88
  "node": ">=20"
85
89
  },
86
90
  "dependencies": {
91
+ "@velajs/live-protocol": "^1.0.0",
87
92
  "hono": "^4.12.26"
88
93
  },
89
94
  "peerDependencies": {