@pluv/client 0.44.2 → 1.0.1
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +24 -0
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +71 -43
- package/dist/index.mjs +71 -43
- package/package.json +5 -5
- package/src/AbstractRoom.ts +3 -1
- package/src/CrdtManager.ts +35 -23
- package/src/CrdtNotifier.ts +4 -1
- package/src/EventNotifier.ts +11 -5
- package/src/MockedRoom.ts +21 -11
- package/src/OtherNotifier.ts +8 -2
- package/src/PluvClient.ts +3 -1
- package/src/PluvProcedure.ts +6 -2
- package/src/PluvRoom.ts +90 -45
- package/src/PluvRouter.ts +4 -1
- package/src/StateNotifier.ts +4 -1
- package/src/UsersManager.ts +23 -5
- package/src/index.ts +8 -1
- package/src/infer.ts +3 -1
- package/src/register.ts +2 -1
- package/src/types.ts +7 -2
- package/src/utils/pickBy.ts +4 -1
package/src/UsersManager.ts
CHANGED
|
@@ -129,7 +129,11 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
|
|
|
129
129
|
if (!userInfo) return null;
|
|
130
130
|
|
|
131
131
|
const remaining = this._getConnectionIds(clientId)?.size ?? 0;
|
|
132
|
-
const result: DeleteConnectionResult<TIO, TPresence> = {
|
|
132
|
+
const result: DeleteConnectionResult<TIO, TPresence> = {
|
|
133
|
+
clientId,
|
|
134
|
+
remaining,
|
|
135
|
+
data: userInfo,
|
|
136
|
+
};
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
139
|
* @description A user may have multiple websocket connections open. If one connection is
|
|
@@ -195,8 +199,15 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
|
|
|
195
199
|
if (!other) return null;
|
|
196
200
|
|
|
197
201
|
const cleanedPatch = pickBy(patch ?? {}, (value) => typeof value !== "undefined");
|
|
198
|
-
const cleanedPresence = pickBy(
|
|
199
|
-
|
|
202
|
+
const cleanedPresence = pickBy(
|
|
203
|
+
other.presence ?? {},
|
|
204
|
+
(value) => typeof value !== "undefined",
|
|
205
|
+
);
|
|
206
|
+
const presence = {
|
|
207
|
+
...this.initialPresence,
|
|
208
|
+
...cleanedPresence,
|
|
209
|
+
...cleanedPatch,
|
|
210
|
+
} as TPresence;
|
|
200
211
|
const validated = this._presence ? this._presence.parse(presence) : presence;
|
|
201
212
|
|
|
202
213
|
this._others.set(clientId, { ...other, presence: validated });
|
|
@@ -255,7 +266,11 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
|
|
|
255
266
|
public updateMyPresence(patch: Partial<TPresence>): TPresence {
|
|
256
267
|
const cleanedPatch = pickBy(patch, (value) => typeof value !== "undefined");
|
|
257
268
|
const cleanedPresence = pickBy(this._myPresence, (value) => typeof value !== "undefined");
|
|
258
|
-
const updated = {
|
|
269
|
+
const updated = {
|
|
270
|
+
...this.initialPresence,
|
|
271
|
+
...cleanedPresence,
|
|
272
|
+
...cleanedPatch,
|
|
273
|
+
} as TPresence;
|
|
259
274
|
const bytes = new TextEncoder().encode(JSON.stringify(updated)).length;
|
|
260
275
|
|
|
261
276
|
if (!!this._limits.presenceMaxSize && bytes > this._limits.presenceMaxSize) {
|
|
@@ -297,7 +312,10 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
|
|
|
297
312
|
return set ?? null;
|
|
298
313
|
}
|
|
299
314
|
|
|
300
|
-
private _setConnectionId(
|
|
315
|
+
private _setConnectionId(
|
|
316
|
+
connectionId: string,
|
|
317
|
+
clientId: string,
|
|
318
|
+
): Set<[connectionId: string][0]> {
|
|
301
319
|
const set = this._idMap.fromClientId.get(clientId) ?? new Set<string>();
|
|
302
320
|
const updated = set.add(connectionId);
|
|
303
321
|
|
package/src/index.ts
CHANGED
|
@@ -23,4 +23,11 @@ export type {
|
|
|
23
23
|
export type { MergeEvents, PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
24
24
|
export { register } from "./register";
|
|
25
25
|
export type { RegisterParams } from "./register";
|
|
26
|
-
export type {
|
|
26
|
+
export type {
|
|
27
|
+
InferMetadata,
|
|
28
|
+
PublicKey,
|
|
29
|
+
PublicKeyParams,
|
|
30
|
+
UserInfo,
|
|
31
|
+
WebSocketConnection,
|
|
32
|
+
WebSocketState,
|
|
33
|
+
} from "./types";
|
package/src/infer.ts
CHANGED
|
@@ -5,4 +5,6 @@ export type InferCallback<TIO extends IOLike<any, any>> = (i: typeof identity) =
|
|
|
5
5
|
io: (io: TIO) => TIO;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const infer = <TIO extends IOLike<any, any>>(
|
|
8
|
+
export const infer = <TIO extends IOLike<any, any>>(
|
|
9
|
+
callback: InferCallback<TIO>,
|
|
10
|
+
): InferCallback<TIO> => callback;
|
package/src/register.ts
CHANGED
|
@@ -9,7 +9,8 @@ export interface RegisterParams<TMetadata extends JsonObject> {
|
|
|
9
9
|
export const register = <TMetadata extends JsonObject>(params: RegisterParams<TMetadata>) => {
|
|
10
10
|
const { authEndpoint, publicKey } = params;
|
|
11
11
|
|
|
12
|
-
const wsEndpoint: WsEndpoint<TMetadata> = ({ room }) =>
|
|
12
|
+
const wsEndpoint: WsEndpoint<TMetadata> = ({ room }) =>
|
|
13
|
+
`wss://connect.pluv.io/api/room?room=${room}`;
|
|
13
14
|
|
|
14
15
|
return {
|
|
15
16
|
authEndpoint,
|
package/src/types.ts
CHANGED
|
@@ -22,7 +22,10 @@ export type EventResolver<
|
|
|
22
22
|
TOutput extends EventRecord<string, any> = {},
|
|
23
23
|
TPresence extends JsonObject = {},
|
|
24
24
|
TStorage extends Record<string, CrdtType<any, any>> = {},
|
|
25
|
-
> = (
|
|
25
|
+
> = (
|
|
26
|
+
data: TInput,
|
|
27
|
+
context: EventResolverContext<TIO, TPresence, TStorage>,
|
|
28
|
+
) => MaybePromise<TOutput | void>;
|
|
26
29
|
|
|
27
30
|
export interface EventResolverContext<
|
|
28
31
|
TIO extends IOLike = IOLike,
|
|
@@ -67,7 +70,9 @@ export interface PluvClientLimits {
|
|
|
67
70
|
export interface PublicKeyParams<TMetadata extends JsonObject> {
|
|
68
71
|
metadata: TMetadata;
|
|
69
72
|
}
|
|
70
|
-
export type PublicKey<TMetadata extends JsonObject> =
|
|
73
|
+
export type PublicKey<TMetadata extends JsonObject> =
|
|
74
|
+
| string
|
|
75
|
+
| ((params: PublicKeyParams<TMetadata>) => string);
|
|
71
76
|
|
|
72
77
|
export type UpdateMyPresenceAction<TPresence extends JsonObject> =
|
|
73
78
|
| Partial<TPresence>
|
package/src/utils/pickBy.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export const pickBy = <T extends Record<string, any>>(
|
|
1
|
+
export const pickBy = <T extends Record<string, any>>(
|
|
2
|
+
obj: T,
|
|
3
|
+
by: (value: T[keyof T]) => boolean,
|
|
4
|
+
): Partial<T> => {
|
|
2
5
|
const result: Partial<T> = {};
|
|
3
6
|
const keys: (keyof T)[] = Object.keys(obj);
|
|
4
7
|
|