@pluv/client 0.17.3 → 0.19.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,11 +1,4 @@
1
- import type {
2
- Id,
3
- InferIOAuthorize,
4
- InferIOAuthorizeUser,
5
- InputZodLike,
6
- IOLike,
7
- JsonObject,
8
- } from "@pluv/types";
1
+ import type { Id, InferIOAuthorize, InferIOAuthorizeUser, InputZodLike, IOLike, JsonObject } from "@pluv/types";
9
2
  import type { UserInfo } from "./types";
10
3
 
11
4
  export type Presence = Record<string, unknown>;
@@ -15,10 +8,7 @@ export type UsersManagerConfig<TPresence extends JsonObject = {}> = {
15
8
  presence?: InputZodLike<TPresence>;
16
9
  };
17
10
 
18
- export class UsersManager<
19
- TIO extends IOLike,
20
- TPresence extends JsonObject = {},
21
- > {
11
+ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}> {
22
12
  private _initialPresence: TPresence;
23
13
  /**
24
14
  * @description This presence can be updated while the user is not
@@ -60,10 +50,7 @@ export class UsersManager<
60
50
  return Array.from(this._others.values());
61
51
  }
62
52
 
63
- public patchPresence(
64
- connectionId: string,
65
- patch: Partial<TPresence>,
66
- ): void {
53
+ public patchPresence(connectionId: string, patch: Partial<TPresence>): void {
67
54
  if (this._myself?.connectionId === connectionId) {
68
55
  const presence = {
69
56
  ...this._myPresence,
@@ -98,10 +85,7 @@ export class UsersManager<
98
85
  this._others.delete(connectionId);
99
86
  }
100
87
 
101
- public setMyself(
102
- connectionId: string,
103
- user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>,
104
- ): void {
88
+ public setMyself(connectionId: string, user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>): void {
105
89
  this._myself = {
106
90
  connectionId,
107
91
  presence: this._initialPresence,
@@ -2,8 +2,6 @@ import type { IOLike } from "@pluv/types";
2
2
  import type { PluvClientOptions } from "./PluvClient";
3
3
  import { PluvClient } from "./PluvClient";
4
4
 
5
- export const createClient = <TIO extends IOLike = IOLike>(
6
- options: PluvClientOptions<TIO>,
7
- ): PluvClient<TIO> => {
5
+ export const createClient = <TIO extends IOLike = IOLike>(options: PluvClientOptions<TIO>): PluvClient<TIO> => {
8
6
  return new PluvClient<TIO>(options);
9
7
  };
package/src/index.ts CHANGED
@@ -1,10 +1,5 @@
1
1
  export type { AbstractCrdtType, InferCrdtStorageJson } from "@pluv/crdt";
2
- export type {
3
- BaseUser,
4
- EventMessage,
5
- EventRecord,
6
- IOEventMessage,
7
- } from "@pluv/types";
2
+ export type { BaseUser, EventMessage, EventRecord, IOEventMessage } from "@pluv/types";
8
3
  export { AbstractRoom } from "./AbstractRoom";
9
4
  export { AbstractStorageStore } from "./AbstractStorageStore";
10
5
  export { MockedRoom } from "./MockedRoom";
@@ -12,12 +7,7 @@ export type { MockedRoomConfig, MockedRoomEvents } from "./MockedRoom";
12
7
  export { PluvClient } from "./PluvClient";
13
8
  export type { PluvClientOptions } from "./PluvClient";
14
9
  export { PluvRoom } from "./PluvRoom";
15
- export type {
16
- PluvRoomAddon,
17
- PluvRoomAddonInput,
18
- PluvRoomAddonResult,
19
- PluvRoomDebug,
20
- } from "./PluvRoom";
10
+ export type { PluvRoomAddon, PluvRoomAddonInput, PluvRoomAddonResult, PluvRoomDebug } from "./PluvRoom";
21
11
  export { createClient } from "./createClient";
22
12
  export { ConnectionState } from "./types";
23
13
  export type { UserInfo, WebSocketConnection, WebSocketState } from "./types";
package/src/types.ts CHANGED
@@ -1,10 +1,4 @@
1
- import type {
2
- Id,
3
- InferIOAuthorize,
4
- InferIOAuthorizeUser,
5
- IOLike,
6
- JsonObject,
7
- } from "@pluv/types";
1
+ import type { Id, InferIOAuthorize, InferIOAuthorizeUser, IOLike, JsonObject } from "@pluv/types";
8
2
 
9
3
  export interface AuthorizationState<TIO extends IOLike> {
10
4
  token: string | null;
@@ -23,6 +17,16 @@ export interface InternalSubscriptions {
23
17
  observeCrdt: (() => void) | null;
24
18
  }
25
19
 
20
+ export type UpdateMyPresenceAction<TPresence extends JsonObject> =
21
+ | Partial<TPresence>
22
+ | ((oldPresence: TPresence | null) => Partial<TPresence>);
23
+
24
+ export interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
25
+ connectionId: string;
26
+ presence: TPresence;
27
+ user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
28
+ }
29
+
26
30
  export interface WebSocketConnection {
27
31
  count: number;
28
32
  id: string | null;
@@ -34,12 +38,3 @@ export interface WebSocketState<TIO extends IOLike> {
34
38
  connection: WebSocketConnection;
35
39
  webSocket: WebSocket | null;
36
40
  }
37
-
38
- export interface UserInfo<
39
- TIO extends IOLike,
40
- TPresence extends JsonObject = {},
41
- > {
42
- connectionId: string;
43
- presence: TPresence;
44
- user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
45
- }