@voltro/plugin-presence 0.84.0 → 0.86.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.
@@ -1,70 +1,14 @@
1
1
  # Third-Party Notices — @voltro/plugin-presence
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/plugin-presence itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (13 packages).
8
+ Generated from the resolved runtime dependency closure (10 packages).
9
9
 
10
10
  ---
11
11
 
12
- ## @effect/experimental@0.61.1
13
-
14
- License: MIT
15
-
16
- ```
17
- MIT License
18
-
19
- Copyright (c) 2023-present The Contributors
20
-
21
- Permission is hereby granted, free of charge, to any person obtaining a copy
22
- of this software and associated documentation files (the "Software"), to deal
23
- in the Software without restriction, including without limitation the rights
24
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
- copies of the Software, and to permit persons to whom the Software is
26
- furnished to do so, subject to the following conditions:
27
-
28
- The above copyright notice and this permission notice shall be included in all
29
- copies or substantial portions of the Software.
30
-
31
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
- SOFTWARE.
38
- ```
39
-
40
- ## @effect/sql@0.52.1
41
-
42
- License: MIT
43
-
44
- ```
45
- MIT License
46
-
47
- Copyright (c) 2023-present The Contributors
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to deal
51
- in the Software without restriction, including without limitation the rights
52
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in all
57
- copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- SOFTWARE.
66
- ```
67
-
68
12
  ## @tanstack/devtools-event-client@0.4.4
69
13
 
70
14
  License: MIT
@@ -233,34 +177,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
233
177
  SOFTWARE.
234
178
  ```
235
179
 
236
- ## layerr@3.0.0
237
-
238
- License: MIT
239
-
240
- ```
241
- MIT License
242
-
243
- Copyright (c) 2020 Perry Mitchell
244
-
245
- Permission is hereby granted, free of charge, to any person obtaining a copy
246
- of this software and associated documentation files (the "Software"), to deal
247
- in the Software without restriction, including without limitation the rights
248
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
249
- copies of the Software, and to permit persons to whom the Software is
250
- furnished to do so, subject to the following conditions:
251
-
252
- The above copyright notice and this permission notice shall be included in all
253
- copies or substantial portions of the Software.
254
-
255
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
256
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
257
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
258
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
259
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
260
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
261
- SOFTWARE.
262
- ```
263
-
264
180
  ## typeid-js@1.2.0
265
181
 
266
182
  License: Apache-2.0
@@ -469,14 +385,14 @@ Apache License
469
385
  limitations under the License.
470
386
  ```
471
387
 
472
- ## ulidx@2.4.1
388
+ ## ulid@3.0.2
473
389
 
474
390
  License: MIT
475
391
 
476
392
  ```
477
- MIT License
393
+ The MIT License (MIT)
478
394
 
479
- Copyright (c) 2021 Perry Mitchell
395
+ Copyright (c) 2017 Alizain Feerasta
480
396
 
481
397
  Permission is hereby granted, free of charge, to any person obtaining a copy
482
398
  of this software and associated documentation files (the "Software"), to deal
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Schema } from 'effect';
2
+ import { YieldableError } from 'effect/Cause';
2
3
 
3
4
  /** The caller has no presence identity — an anonymous subject (no subject id)
4
5
  * that also passed no explicit `key`. There's nothing stable to register a
@@ -7,11 +8,9 @@ import { Schema } from 'effect';
7
8
  export declare class PresenceKeyMissing extends PresenceKeyMissing_base {
8
9
  }
9
10
 
10
- declare const PresenceKeyMissing_base: Schema.TaggedErrorClass<PresenceKeyMissing, "PresenceKeyMissing", {
11
- readonly _tag: Schema.tag<"PresenceKeyMissing">;
12
- } & {
13
- channel: typeof Schema.String;
14
- }>;
11
+ declare const PresenceKeyMissing_base: Schema.Class<PresenceKeyMissing, Schema.TaggedStruct<"PresenceKeyMissing", {
12
+ readonly channel: Schema.String;
13
+ }>, YieldableError>;
15
14
 
16
15
  /** The presence store isn't bound — `bindDataStore` never ran. This is a boot/
17
16
  * wiring bug (the plugin wasn't installed on an app with a DataStore), not a
@@ -19,8 +18,6 @@ declare const PresenceKeyMissing_base: Schema.TaggedErrorClass<PresenceKeyMissin
19
18
  export declare class PresenceStoreUnavailable extends PresenceStoreUnavailable_base {
20
19
  }
21
20
 
22
- declare const PresenceStoreUnavailable_base: Schema.TaggedErrorClass<PresenceStoreUnavailable, "PresenceStoreUnavailable", {
23
- readonly _tag: Schema.tag<"PresenceStoreUnavailable">;
24
- }>;
21
+ declare const PresenceStoreUnavailable_base: Schema.Class<PresenceStoreUnavailable, Schema.TaggedStruct<"PresenceStoreUnavailable", {}>, YieldableError>;
25
22
 
26
23
  export { }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Effect } from 'effect';
3
3
  import { ReactivityChannel } from '@voltro/protocol';
4
4
  import { Schema } from 'effect';
5
5
  import { VoltroPlugin } from '@voltro/protocol';
6
+ import { YieldableError } from 'effect/Cause';
6
7
 
7
8
  /**
8
9
  * Wire a tracker to the transport and the membership registry.
@@ -84,11 +85,9 @@ export declare type PresenceDelta = {
84
85
  export declare class PresenceKeyMissing extends PresenceKeyMissing_base {
85
86
  }
86
87
 
87
- declare const PresenceKeyMissing_base: Schema.TaggedErrorClass<PresenceKeyMissing, "PresenceKeyMissing", {
88
- readonly _tag: Schema.tag<"PresenceKeyMissing">;
89
- } & {
90
- channel: typeof Schema.String;
91
- }>;
88
+ declare const PresenceKeyMissing_base: Schema.Class<PresenceKeyMissing, Schema.TaggedStruct<"PresenceKeyMissing", {
89
+ readonly channel: Schema.String;
90
+ }>, YieldableError>;
92
91
 
93
92
  export declare interface PresenceMember {
94
93
  /** Stable per-client key — the subject id, or a client-supplied one. */
@@ -222,9 +221,7 @@ export declare const presenceRoster: ReactivityChannel;
222
221
  export declare class PresenceStoreUnavailable extends PresenceStoreUnavailable_base {
223
222
  }
224
223
 
225
- declare const PresenceStoreUnavailable_base: Schema.TaggedErrorClass<PresenceStoreUnavailable, "PresenceStoreUnavailable", {
226
- readonly _tag: Schema.tag<"PresenceStoreUnavailable">;
227
- }>;
224
+ declare const PresenceStoreUnavailable_base: Schema.Class<PresenceStoreUnavailable, Schema.TaggedStruct<"PresenceStoreUnavailable", {}>, YieldableError>;
228
225
 
229
226
  /**
230
227
  * The merged presence view this instance can see.
@@ -245,6 +242,7 @@ export declare class PresenceTracker {
245
242
  /** This instance's id — the owner stamped on everything it tracks. */
246
243
  get owner(): string;
247
244
  private branch;
245
+ private removeMember;
248
246
  /**
249
247
  * Record a heartbeat from a client THIS instance holds.
250
248
  *
package/dist/index.js CHANGED
@@ -1,293 +1,116 @@
1
- import { PresenceKeyMissing as e, PresenceStoreUnavailable as t } from "./errors.js";
2
- import { BASE_NAME as n, heartbeatDescriptor as r, leaveDescriptor as i, listDescriptor as a, presenceRoster as o, presenceRpcClientImports as s } from "./rpc.js";
3
- import { Effect as c } from "effect";
4
- import { definePlugin as l, pluginInstanceName as u, publishReactivity as d } from "@voltro/protocol";
5
- //#region src/tracker.ts
6
- var f = (e, t) => `${e ?? "~"}::${t}`, p = (e) => e === void 0 ? "undefined" : typeof e != "object" || !e ? JSON.stringify(e) ?? "undefined" : Array.isArray(e) ? `[${e.map(p).join(",")}]` : `{${Object.entries(e).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${p(t)}`).join(",")}}`, m = (e, t) => e === t || e !== null && t !== null && p(e) === p(t), h = class {
7
- partitions = /* @__PURE__ */ new Map();
8
- selfId;
9
- now;
10
- constructor(e) {
11
- this.selfId = e.instanceId, this.now = e.now ?? Date.now;
12
- }
13
- get owner() {
14
- return this.selfId;
15
- }
16
- branch(e, t, n) {
17
- let r = this.partitions.get(e);
18
- r === void 0 && (r = /* @__PURE__ */ new Map(), this.partitions.set(e, r));
19
- let i = f(t, n), a = r.get(i);
20
- return a === void 0 && (a = {
21
- tenantId: t,
22
- channel: n,
23
- members: /* @__PURE__ */ new Map()
24
- }, r.set(i, a)), a;
25
- }
26
- track(e) {
27
- let t = this.now(), n = e.meta ?? null, { members: r } = this.branch(this.selfId, e.tenantId, e.channel), i = r.get(e.key);
28
- return r.set(e.key, {
29
- key: e.key,
30
- meta: n,
31
- lastSeen: t
32
- }), {
33
- delta: {
34
- op: "set",
35
- channel: e.channel,
36
- tenantId: e.tenantId,
37
- key: e.key,
38
- meta: n,
39
- lastSeen: t
40
- },
41
- changed: i === void 0 || !m(i.meta, n)
42
- };
43
- }
44
- untrack(e) {
45
- let t = this.branch(this.selfId, e.tenantId, e.channel).members.delete(e.key);
46
- return {
47
- delta: {
48
- op: "remove",
49
- channel: e.channel,
50
- tenantId: e.tenantId,
51
- key: e.key
52
- },
53
- changed: t
54
- };
55
- }
56
- apply(e, t) {
57
- if (e === this.selfId) return !1;
58
- let { members: n } = this.branch(e, t.tenantId, t.channel);
59
- if (t.op === "remove") return n.delete(t.key);
60
- let r = n.get(t.key);
61
- return n.set(t.key, {
62
- key: t.key,
63
- meta: t.meta,
64
- lastSeen: t.lastSeen
65
- }), r === void 0 || !m(r.meta, t.meta);
66
- }
67
- dropOwner(e) {
68
- if (e === this.selfId) return 0;
69
- let t = this.partitions.get(e);
70
- if (t === void 0) return 0;
71
- let n = 0;
72
- for (let e of t.values()) n += e.members.size;
73
- return this.partitions.delete(e), n;
74
- }
75
- sweep(e) {
76
- let t = this.partitions.get(this.selfId);
77
- if (t === void 0) return [];
78
- let n = this.now() - e, r = [];
79
- for (let e of t.values()) for (let [t, i] of e.members) i.lastSeen >= n || (e.members.delete(t), r.push({
80
- op: "remove",
81
- channel: e.channel,
82
- tenantId: e.tenantId,
83
- key: t
84
- }));
85
- return r;
86
- }
87
- ownSnapshot() {
88
- let e = [], t = this.partitions.get(this.selfId);
89
- if (t === void 0) return e;
90
- for (let n of t.values()) for (let t of n.members.values()) e.push({
91
- op: "set",
92
- channel: n.channel,
93
- tenantId: n.tenantId,
94
- key: t.key,
95
- meta: t.meta,
96
- lastSeen: t.lastSeen
97
- });
98
- return e;
99
- }
100
- roster(e, t) {
101
- let n = f(t, e), r = [];
102
- for (let [i, a] of this.partitions) {
103
- let o = a.get(n);
104
- if (o !== void 0) for (let n of o.members.values()) r.push({
105
- ...n,
106
- owner: i,
107
- channel: e,
108
- tenantId: t
109
- });
110
- }
111
- return r.sort((e, t) => t.lastSeen - e.lastSeen);
112
- }
113
- owners() {
114
- return [...this.partitions.entries()].map(([e, t]) => {
115
- let n = 0;
116
- for (let e of t.values()) n += e.members.size;
117
- return {
118
- owner: e,
119
- members: n
120
- };
121
- });
122
- }
123
- size() {
124
- return this.owners().reduce((e, t) => e + t.members, 0);
125
- }
126
- }, g = "voltro:presence", _ = (e) => typeof e == "object" && !!e && typeof e.owner == "string" && typeof e.delta == "object" && e.delta !== null, v = (e) => typeof e == "object" && !!e && typeof e.owner == "string" && Array.isArray(e.sync), y = (e) => {
127
- let t = new h({
128
- instanceId: e.instanceId,
129
- ...e.now === void 0 ? {} : { now: e.now }
130
- }), n = e.logger, r = () => {
131
- try {
132
- e.onRosterChanged?.();
133
- } catch {}
134
- }, i = e.membership.onChange((e) => {
135
- if (e.kind === "joined") {
136
- l();
137
- return;
138
- }
139
- let i = t.dropOwner(e.instanceId);
140
- i > 0 && (n?.warn("presence: dropped members of a departed instance", {
141
- instanceId: e.instanceId,
142
- members: i,
143
- reason: e.kind
144
- }), r()), e.kind === "restarted" && l();
145
- }), a = e.provider, o = e.channel ?? "voltro:presence", s = (e) => {
146
- a !== void 0 && c.runPromise(a.publish(o, JSON.stringify(e))).catch(() => {});
147
- }, l = () => {
148
- let n = t.ownSnapshot();
149
- n.length !== 0 && s({
150
- owner: e.instanceId,
151
- sync: n
152
- });
153
- }, u;
154
- return a !== void 0 && c.runPromise(a.subscribe(o, (e) => {
155
- let n;
156
- try {
157
- n = JSON.parse(e);
158
- } catch {
159
- return;
160
- }
161
- if (v(n)) {
162
- let e = !1;
163
- for (let r of n.sync) e = t.apply(n.owner, r) || e;
164
- e && r();
165
- return;
166
- }
167
- _(n) && t.apply(n.owner, n.delta) && r();
168
- })).then((e) => {
169
- u = e;
170
- }, (e) => {
171
- n?.warn("presence: could not subscribe — this instance will only see its own members", { cause: e });
172
- }), {
173
- tracker: t,
174
- hasTransport: a !== void 0,
175
- announce: (t) => {
176
- s({
177
- owner: e.instanceId,
178
- delta: t
179
- });
180
- },
181
- detach: () => {
182
- i(), u?.();
183
- }
184
- };
185
- }, b = n, x = (n = {}) => {
186
- if (n.timeoutMs !== void 0 && n.timeoutMs < 1e3) throw Error(`presencePlugin: \`timeoutMs\` is ${n.timeoutMs}, which expires every member before it can heartbeat again.
1
+ import { PresenceTracker as e } from "./tracker.js";
2
+ import { PRESENCE_BROADCAST_CHANNEL as t, attachPresenceBus as n } from "./trackerBus.js";
3
+ import { PresenceKeyMissing as r, PresenceStoreUnavailable as i } from "./errors.js";
4
+ import { BASE_NAME as a, heartbeatDescriptor as o, leaveDescriptor as s, listDescriptor as c, presenceRoster as l, presenceRpcClientImports as u } from "./rpc.js";
5
+ import { Effect as d } from "effect";
6
+ import { definePlugin as f, pluginInstanceName as p, publishReactivity as m } from "@voltro/protocol";
7
+ //#region src/index.ts
8
+ var h = a, g = (e = {}) => {
9
+ if (e.timeoutMs !== void 0 && e.timeoutMs < 1e3) throw Error(`presencePlugin: \`timeoutMs\` is ${e.timeoutMs}, which expires every member before it can heartbeat again.
187
10
  A member is online for \`timeoutMs\` after its last heartbeat, and \`usePresence\` beats every 15s by default — so this must be LARGER than your client's
188
11
  \`heartbeatMs\`, comfortably. The default pair is 30s server / 15s client.
189
12
  There is no "never expire" spelling: omit \`timeoutMs\` for the default.`);
190
- let f, p = n.timeoutMs ?? 3e4, m = Math.max(1e3, Math.floor(n.sweepIntervalMs ?? p / 3)), h = u({
191
- base: b,
192
- alias: n.alias,
193
- instance: n.name
194
- }), g, _, v, x, S = () => {
195
- x === void 0 && g !== void 0 && (x = setInterval(() => {
196
- let e = g;
13
+ let t, a = e.timeoutMs ?? 3e4, g = Math.max(1e3, Math.floor(e.sweepIntervalMs ?? a / 3)), _ = p({
14
+ base: h,
15
+ alias: e.alias,
16
+ instance: e.name
17
+ }), v, y, b, x, S = () => {
18
+ x === void 0 && v !== void 0 && (x = setInterval(() => {
19
+ let e = v;
197
20
  if (e === void 0) return;
198
- let t = e.tracker.sweep(p);
21
+ let t = e.tracker.sweep(a);
199
22
  if (t.length !== 0) {
200
23
  for (let n of t) e.announce(n);
201
24
  T();
202
25
  }
203
- }, m), x.unref?.());
26
+ }, g), x.unref?.());
204
27
  }, C = (e, t) => typeof t == "string" && t.length > 0 ? t : e.request.subject?.id ?? null, w = (e) => e.request.subject?.tenantId ?? null, T = () => {
205
- d(_, o);
28
+ m(y, l);
206
29
  }, E = [
207
30
  {
208
- ...r,
31
+ ...o,
209
32
  description: "Register/refresh the caller's presence in a channel.",
210
- execute: (r, i) => c.gen(function* () {
211
- let a = r;
212
- if (!g) return yield* c.fail(new t({}));
213
- let o = C(i, a.key);
214
- if (o === null) return yield* c.fail(new e({ channel: a.channel }));
215
- let s = n.resolveMember !== void 0 && v !== void 0 ? yield* c.promise(async () => n.resolveMember({
216
- subject: i.request.subject,
33
+ execute: (t, n) => d.gen(function* () {
34
+ let a = t;
35
+ if (!v) return yield* d.fail(new i({}));
36
+ let o = C(n, a.key);
37
+ if (o === null) return yield* d.fail(new r({ channel: a.channel }));
38
+ let s = e.resolveMember !== void 0 && b !== void 0 ? yield* d.promise(async () => e.resolveMember({
39
+ subject: n.request.subject,
217
40
  channel: a.channel,
218
41
  key: o,
219
- store: v
220
- })) : void 0, l = n.resolveMember !== void 0 && n.identityFields !== void 0 ? Object.fromEntries(Object.entries(a.meta ?? {}).filter(([e]) => !n.identityFields.includes(e))) : a.meta, u = s === void 0 ? l : {
221
- ...l ?? {},
42
+ store: b
43
+ })) : void 0, c = e.resolveMember !== void 0 && e.identityFields !== void 0 ? Object.fromEntries(Object.entries(a.meta ?? {}).filter(([t]) => !e.identityFields.includes(t))) : a.meta, l = s === void 0 ? c : {
44
+ ...c ?? {},
222
45
  ...s
223
- }, d = g.tracker.track({
46
+ }, u = v.tracker.track({
224
47
  channel: a.channel,
225
- tenantId: w(i),
48
+ tenantId: w(n),
226
49
  key: o,
227
- ...u === void 0 ? {} : { meta: u }
50
+ ...l === void 0 ? {} : { meta: l }
228
51
  });
229
- return g.announce(d.delta), d.changed && T(), { ok: !0 };
52
+ return v.announce(u.delta), u.changed && T(), { ok: !0 };
230
53
  })
231
54
  },
232
55
  {
233
- ...a,
56
+ ...c,
234
57
  description: "The online roster of a channel (heartbeat-fresh members). Push-driven — updates live.",
235
- execute: (e, n) => c.gen(function* () {
236
- return g ? g.tracker.roster(e.channel, w(n)).map((e) => ({
58
+ execute: (e, t) => d.gen(function* () {
59
+ return v ? v.tracker.roster(e.channel, w(t)).map((e) => ({
237
60
  key: e.key,
238
61
  meta: e.meta
239
- })) : yield* c.fail(new t({}));
62
+ })) : yield* d.fail(new i({}));
240
63
  })
241
64
  },
242
65
  {
243
- ...i,
66
+ ...s,
244
67
  description: "Remove the caller's presence from a channel.",
245
- execute: (n, r) => c.gen(function* () {
246
- let i = n;
247
- if (!g) return yield* c.fail(new t({}));
248
- let a = C(r, i.key);
249
- if (a === null) return yield* c.fail(new e({ channel: i.channel }));
250
- let o = g.tracker.untrack({
251
- channel: i.channel,
252
- tenantId: w(r),
68
+ execute: (e, t) => d.gen(function* () {
69
+ let n = e;
70
+ if (!v) return yield* d.fail(new i({}));
71
+ let a = C(t, n.key);
72
+ if (a === null) return yield* d.fail(new r({ channel: n.channel }));
73
+ let o = v.tracker.untrack({
74
+ channel: n.channel,
75
+ tenantId: w(t),
253
76
  key: a
254
77
  });
255
- return g.announce(o.delta), o.changed && T(), { ok: !0 };
78
+ return v.announce(o.delta), o.changed && T(), { ok: !0 };
256
79
  })
257
80
  }
258
81
  ];
259
- return l({
260
- name: h,
261
- baseName: b,
82
+ return f({
83
+ name: _,
84
+ baseName: h,
262
85
  description: "Ephemeral realtime presence — heartbeat roster per channel.",
263
86
  routes: E,
264
- rpcClientDescriptors: s,
87
+ rpcClientDescriptors: u,
265
88
  bindDataStore: (e, t) => {
266
- _ = e, v = e;
267
- let n = t;
268
- g = y({
269
- instanceId: n?.instanceId ?? `presence-${process.pid}`,
270
- membership: n?.membership ?? { onChange: () => () => {} },
271
- ...n?.broadcast === void 0 ? {} : { provider: n.broadcast },
272
- ...n?.broadcastChannels?.presence === void 0 ? {} : { channel: n.broadcastChannels.presence },
89
+ y = e, b = e;
90
+ let r = t;
91
+ v = n({
92
+ instanceId: r?.instanceId ?? `presence-${process.pid}`,
93
+ membership: r?.membership ?? { onChange: () => () => {} },
94
+ ...r?.broadcast === void 0 ? {} : { provider: r.broadcast },
95
+ ...r?.broadcastChannels?.presence === void 0 ? {} : { channel: r.broadcastChannels.presence },
273
96
  onRosterChanged: T
274
97
  });
275
98
  },
276
- onActivate: (e) => c.sync(() => {
99
+ onActivate: (e) => d.sync(() => {
277
100
  S(), e.logger.info("presence active", {
278
- timeoutMs: p,
279
- sweepEveryMs: m
101
+ timeoutMs: a,
102
+ sweepEveryMs: g
280
103
  });
281
- let t = Number(process.env.VOLTRO_PRESENCE_BROKER_GRACE_MS ?? 5e3), n = setTimeout(() => {
282
- let t = g?.hasTransport === !0;
104
+ let n = Number(process.env.VOLTRO_PRESENCE_BROKER_GRACE_MS ?? 5e3), r = setTimeout(() => {
105
+ let t = v?.hasTransport === !0;
283
106
  e.logger.info("presence transport", { crossInstance: t }), !t && e.logger.warn("presence: no broadcast provider — each replica sees only the clients CONNECTED TO IT. Correct for a single instance; on more than one, every screen shows a fraction of the room and nothing reports it. Add @voltro/plugin-broadcast (redis:// or nats://) to share the roster.");
284
- }, t);
285
- n.unref?.(), f = n;
107
+ }, n);
108
+ r.unref?.(), t = r;
286
109
  }),
287
- onDeactivate: () => c.sync(() => {
288
- f !== void 0 && (clearTimeout(f), f = void 0), x !== void 0 && (clearInterval(x), x = void 0), g?.detach(), g = void 0, _ = void 0, v = void 0;
110
+ onDeactivate: () => d.sync(() => {
111
+ t !== void 0 && (clearTimeout(t), t = void 0), x !== void 0 && (clearInterval(x), x = void 0), v?.detach(), v = void 0, y = void 0, b = void 0;
289
112
  })
290
113
  });
291
114
  };
292
115
  //#endregion
293
- export { g as PRESENCE_BROADCAST_CHANNEL, e as PresenceKeyMissing, t as PresenceStoreUnavailable, h as PresenceTracker, y as attachPresenceBus, x as presencePlugin, o as presenceRoster };
116
+ export { t as PRESENCE_BROADCAST_CHANNEL, r as PresenceKeyMissing, i as PresenceStoreUnavailable, e as PresenceTracker, n as attachPresenceBus, g as presencePlugin, l as presenceRoster };
package/dist/rpc.d.ts CHANGED
@@ -3,6 +3,7 @@ import { PluginRpcClientDescriptor } from '@voltro/protocol';
3
3
  import { QueryProcedureDescriptor } from '@voltro/protocol';
4
4
  import { ReactivityChannel } from '@voltro/protocol';
5
5
  import { Schema } from 'effect';
6
+ import { YieldableError } from 'effect/Cause';
6
7
 
7
8
  /**
8
9
  * The plugin's canonical package name — the key an app's `alias` is recorded
@@ -17,25 +18,25 @@ import { Schema } from 'effect';
17
18
  export declare const BASE_NAME = "@voltro/plugin-presence";
18
19
 
19
20
  export declare const heartbeatDescriptor: MutationProcedureDescriptor<"presence.heartbeat", Schema.Struct<{
20
- channel: typeof Schema.String;
21
- key: Schema.optional<typeof Schema.String>;
22
- meta: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
21
+ readonly channel: Schema.String;
22
+ readonly key: Schema.optional<Schema.String>;
23
+ readonly meta: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
23
24
  }>, Schema.Struct<{
24
- ok: typeof Schema.Boolean;
25
- }>, Schema.Union<[typeof PresenceKeyMissing, typeof PresenceStoreUnavailable]>>;
25
+ readonly ok: Schema.Boolean;
26
+ }>, Schema.Union<readonly [typeof PresenceKeyMissing, typeof PresenceStoreUnavailable]>>;
26
27
 
27
28
  export declare const leaveDescriptor: MutationProcedureDescriptor<"presence.leave", Schema.Struct<{
28
- channel: typeof Schema.String;
29
- key: Schema.optional<typeof Schema.String>;
29
+ readonly channel: Schema.String;
30
+ readonly key: Schema.optional<Schema.String>;
30
31
  }>, Schema.Struct<{
31
- ok: typeof Schema.Boolean;
32
- }>, Schema.Union<[typeof PresenceKeyMissing, typeof PresenceStoreUnavailable]>>;
32
+ readonly ok: Schema.Boolean;
33
+ }>, Schema.Union<readonly [typeof PresenceKeyMissing, typeof PresenceStoreUnavailable]>>;
33
34
 
34
35
  export declare const listDescriptor: QueryProcedureDescriptor<"presence.list", Schema.Struct<{
35
- channel: typeof Schema.String;
36
- }>, Schema.Array$<Schema.Struct<{
37
- key: typeof Schema.String;
38
- meta: Schema.NullOr<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
36
+ readonly channel: Schema.String;
37
+ }>, Schema.$Array<Schema.Struct<{
38
+ readonly key: Schema.String;
39
+ readonly meta: Schema.NullOr<Schema.$Record<Schema.String, Schema.Unknown>>;
39
40
  }>>, typeof PresenceStoreUnavailable>;
40
41
 
41
42
  /** The caller has no presence identity — an anonymous subject (no subject id)
@@ -45,11 +46,9 @@ export declare const listDescriptor: QueryProcedureDescriptor<"presence.list", S
45
46
  declare class PresenceKeyMissing extends PresenceKeyMissing_base {
46
47
  }
47
48
 
48
- declare const PresenceKeyMissing_base: Schema.TaggedErrorClass<PresenceKeyMissing, "PresenceKeyMissing", {
49
- readonly _tag: Schema.tag<"PresenceKeyMissing">;
50
- } & {
51
- channel: typeof Schema.String;
52
- }>;
49
+ declare const PresenceKeyMissing_base: Schema.Class<PresenceKeyMissing, Schema.TaggedStruct<"PresenceKeyMissing", {
50
+ readonly channel: Schema.String;
51
+ }>, YieldableError>;
53
52
 
54
53
  /**
55
54
  * The roster's reactivity channel — presence's push target.
@@ -76,8 +75,6 @@ export declare const presenceRpcClientImports: ReadonlyArray<PluginRpcClientDesc
76
75
  declare class PresenceStoreUnavailable extends PresenceStoreUnavailable_base {
77
76
  }
78
77
 
79
- declare const PresenceStoreUnavailable_base: Schema.TaggedErrorClass<PresenceStoreUnavailable, "PresenceStoreUnavailable", {
80
- readonly _tag: Schema.tag<"PresenceStoreUnavailable">;
81
- }>;
78
+ declare const PresenceStoreUnavailable_base: Schema.Class<PresenceStoreUnavailable, Schema.TaggedStruct<"PresenceStoreUnavailable", {}>, YieldableError>;
82
79
 
83
80
  export { }
package/dist/rpc.js CHANGED
@@ -4,22 +4,16 @@ import { defineMutation as r, defineQuery as i, reactivityChannel as a } from "@
4
4
  //#region src/rpc.ts
5
5
  var o = "@voltro/plugin-presence", s = a("presence"), c = n.Struct({
6
6
  key: n.String,
7
- meta: n.NullOr(n.Record({
8
- key: n.String,
9
- value: n.Unknown
10
- }))
7
+ meta: n.NullOr(n.Record(n.String, n.Unknown))
11
8
  }), l = r({
12
9
  name: "presence.heartbeat",
13
10
  input: n.Struct({
14
11
  channel: n.String,
15
12
  key: n.optional(n.String),
16
- meta: n.optional(n.Record({
17
- key: n.String,
18
- value: n.Unknown
19
- }))
13
+ meta: n.optional(n.Record(n.String, n.Unknown))
20
14
  }),
21
15
  output: n.Struct({ ok: n.Boolean }),
22
- error: n.Union(e, t),
16
+ error: n.Union([e, t]),
23
17
  openAccess: "presence serves anonymous-capable apps; the tracked key defaults to the caller's own subject id (PresenceKeyMissing without one) and entries are tenant-scoped in the tracker"
24
18
  }), u = i({
25
19
  name: "presence.list",
@@ -35,7 +29,7 @@ var o = "@voltro/plugin-presence", s = a("presence"), c = n.Struct({
35
29
  key: n.optional(n.String)
36
30
  }),
37
31
  output: n.Struct({ ok: n.Boolean }),
38
- error: n.Union(e, t),
32
+ error: n.Union([e, t]),
39
33
  openAccess: "presence serves anonymous-capable apps; the key to remove defaults to the caller's own subject id (PresenceKeyMissing without one) and removal is tenant-scoped in the tracker"
40
34
  }), f = [
41
35
  {