@pluv/client 1.0.1 → 2.0.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.
package/src/types.ts CHANGED
@@ -1,5 +1,7 @@
1
- import type { AbstractCrdtDoc, CrdtType } from "@pluv/crdt";
1
+ import type { CrdtType } from "@pluv/crdt";
2
2
  import type {
3
+ ConnectionState,
4
+ CrdtDocLike,
3
5
  EventRecord,
4
6
  Id,
5
7
  InferIOAuthorize,
@@ -7,8 +9,8 @@ import type {
7
9
  IOLike,
8
10
  JsonObject,
9
11
  MaybePromise,
12
+ UserInfo,
10
13
  } from "@pluv/types";
11
- import type { ConnectionState } from "./enums";
12
14
  import type { PluvClient } from "./PluvClient";
13
15
 
14
16
  export interface AuthorizationState<TIO extends IOLike> {
@@ -32,7 +34,7 @@ export interface EventResolverContext<
32
34
  TPresence extends JsonObject = {},
33
35
  TStorage extends Record<string, CrdtType<any, any>> = {},
34
36
  > {
35
- doc: AbstractCrdtDoc<TStorage>;
37
+ doc: CrdtDocLike<TStorage>;
36
38
  others: readonly UserInfo<TIO, TPresence>[];
37
39
  room: string;
38
40
  user: UserInfo<TIO, TPresence>;
@@ -74,16 +76,6 @@ export type PublicKey<TMetadata extends JsonObject> =
74
76
  | string
75
77
  | ((params: PublicKeyParams<TMetadata>) => string);
76
78
 
77
- export type UpdateMyPresenceAction<TPresence extends JsonObject> =
78
- | Partial<TPresence>
79
- | ((oldPresence: TPresence | null) => Partial<TPresence>);
80
-
81
- export interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
82
- connectionId: string;
83
- presence: TPresence;
84
- user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
85
- }
86
-
87
79
  export interface WebSocketConnection {
88
80
  /**
89
81
  * @description How many times a connection attempt was made. This will increment upon each
@@ -103,12 +95,6 @@ export interface WebSocketConnection {
103
95
  state: ConnectionState;
104
96
  }
105
97
 
106
- export interface WebSocketState<TIO extends IOLike> {
107
- authorization: AuthorizationState<TIO>;
108
- connection: WebSocketConnection;
109
- webSocket: WebSocket | null;
110
- }
111
-
112
98
  export type WithMetadata<TMetadata extends JsonObject = {}> = keyof TMetadata extends never
113
99
  ? { metadata?: undefined }
114
100
  : { metadata: TMetadata };
@@ -1,84 +0,0 @@
1
- import type { AbstractCrdtDoc, CrdtType, InferCrdtJson } from "@pluv/crdt";
2
- import type { IOLike, Id, InferIOInput, InferIOOutput, JsonObject } from "@pluv/types";
3
- import type { EventNotifierSubscriptionCallback } from "./EventNotifier";
4
- import type { OtherNotifierSubscriptionCallback } from "./OtherNotifier";
5
- import type { MergeEvents, PluvRouterEventConfig } from "./PluvRouter";
6
- import type { StateNotifierSubjects, SubscriptionCallback } from "./StateNotifier";
7
- import type { UpdateMyPresenceAction, UserInfo, WebSocketConnection } from "./types";
8
-
9
- export abstract class AbstractRoom<
10
- TIO extends IOLike,
11
- TPresence extends JsonObject = {},
12
- TStorage extends Record<string, CrdtType<any, any>> = {},
13
- TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {},
14
- > {
15
- public readonly id: string;
16
-
17
- constructor(room: string) {
18
- this.id = room;
19
- }
20
-
21
- public abstract storageLoaded: boolean;
22
-
23
- public abstract broadcast<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(
24
- event: TEvent,
25
- data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>,
26
- ): void;
27
-
28
- public abstract canRedo(): boolean;
29
-
30
- public abstract canUndo(): boolean;
31
-
32
- public abstract getDoc(): AbstractCrdtDoc<TStorage>;
33
-
34
- public abstract event<TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(
35
- event: TEvent,
36
- callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>,
37
- ): () => void;
38
-
39
- public abstract getConnection(): WebSocketConnection;
40
-
41
- public abstract getMyPresence(): TPresence;
42
-
43
- public abstract getMyself(): Id<UserInfo<TIO, TPresence>> | null;
44
-
45
- public abstract getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
46
-
47
- public abstract getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
48
-
49
- public abstract getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
50
-
51
- public abstract getStorageJson(): InferCrdtJson<TStorage> | null;
52
- public abstract getStorageJson<TKey extends keyof TStorage>(
53
- type: TKey,
54
- ): InferCrdtJson<TStorage[TKey]> | null;
55
-
56
- public abstract other(
57
- connectionId: string,
58
- callback: OtherNotifierSubscriptionCallback<TIO, TPresence>,
59
- ): () => void;
60
-
61
- public abstract redo(): void;
62
-
63
- public abstract storage<TKey extends keyof TStorage>(
64
- key: TKey,
65
- fn: (value: InferCrdtJson<TStorage[TKey]>) => void,
66
- ): () => void;
67
-
68
- public abstract storageRoot(
69
- fn: (value: {
70
- [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
71
- }) => void,
72
- ): () => void;
73
-
74
- public abstract subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(
75
- name: TSubject,
76
- callback: SubscriptionCallback<TIO, TPresence, TSubject>,
77
- ): () => void;
78
-
79
- public abstract transact(fn: (storage: TStorage) => void, origin?: string): void;
80
-
81
- public abstract undo(): void;
82
-
83
- public abstract updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
84
- }
package/src/enums.ts DELETED
@@ -1,9 +0,0 @@
1
- export const ConnectionState = {
2
- Closed: "Closed",
3
- Connecting: "Connecting",
4
- Open: "Open",
5
- Unavailable: "Unavailable",
6
- Untouched: "Untouched",
7
- } as const;
8
-
9
- export type ConnectionState = (typeof ConnectionState)[keyof typeof ConnectionState];