@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.
@@ -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> = { clientId, remaining, data: userInfo };
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(other.presence ?? {}, (value) => typeof value !== "undefined");
199
- const presence = { ...this.initialPresence, ...cleanedPresence, ...cleanedPatch } as TPresence;
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 = { ...this.initialPresence, ...cleanedPresence, ...cleanedPatch } as TPresence;
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(connectionId: string, clientId: string): Set<[connectionId: string][0]> {
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 { InferMetadata, PublicKey, PublicKeyParams, UserInfo, WebSocketConnection, WebSocketState } from "./types";
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>>(callback: InferCallback<TIO>): InferCallback<TIO> => callback;
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 }) => `wss://connect.pluv.io/api/room?room=${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
- > = (data: TInput, context: EventResolverContext<TIO, TPresence, TStorage>) => MaybePromise<TOutput | void>;
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> = string | ((params: PublicKeyParams<TMetadata>) => string);
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>
@@ -1,4 +1,7 @@
1
- export const pickBy = <T extends Record<string, any>>(obj: T, by: (value: T[keyof T]) => boolean): Partial<T> => {
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