@pluv/client 0.8.0 → 0.9.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +56 -0
- package/dist/index.d.ts +32 -8
- package/dist/index.js +233 -100
- package/dist/index.mjs +232 -100
- package/package.json +10 -8
- package/src/AbstractRoom.ts +1 -1
- package/src/AbstractStorageStore.ts +21 -0
- package/src/CrdtManager.ts +64 -0
- package/src/MockedRoom.ts +2 -2
- package/src/PluvClient.ts +9 -6
- package/src/PluvRoom.ts +162 -73
- package/src/StorageStore.ts +31 -0
- package/src/index.ts +7 -1
- package/src/utils/debounce.ts +27 -0
- package/src/utils/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.
|
|
2
|
+
> @pluv/client@0.9.0 build /home/runner/work/pluv/pluv/packages/client
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup
|
|
7
|
+
[34mCLI[39m tsup v7.0.0
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m40.23 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 98ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m39.02 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 100ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4765ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m12.92 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 829d31b: Added support for defining persistant frontend storage for rooms via a new `addons` option on rooms.
|
|
8
|
+
|
|
9
|
+
This also introduces the first new addon `@pluv/addon-indexeddb`, which is more-or-less the equivalent to `y-indexeddb` which you can install like so:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @pluv/addon-indexeddb
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To use this new addon, simply pass it to options when creating a room:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { addonIndexedDB } from "@pluv/addon-indexeddb";
|
|
19
|
+
import { createClient } from "@pluv/client";
|
|
20
|
+
|
|
21
|
+
const client = createClient({
|
|
22
|
+
// ...
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const room = client.createRoom("my-new-room", {
|
|
26
|
+
addons: [
|
|
27
|
+
// Define your addons in an array like so
|
|
28
|
+
addonIndexedDB(),
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or when using `@pluv/react`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const PluvRoom = createRoomBundle({
|
|
37
|
+
// ...
|
|
38
|
+
addons: [
|
|
39
|
+
// Define your addons in an array like so
|
|
40
|
+
addonIndexedDB(),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 8d11672: bumped dependencies to latest
|
|
48
|
+
- Updated dependencies [8d11672]
|
|
49
|
+
- Updated dependencies [829d31b]
|
|
50
|
+
- @pluv/crdt-yjs@0.4.0
|
|
51
|
+
- @pluv/types@0.2.1
|
|
52
|
+
|
|
53
|
+
## 0.8.1
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- 2c9c5c3: changed my-presence to be non-nullable
|
|
58
|
+
|
|
3
59
|
## 0.8.0
|
|
4
60
|
|
|
5
61
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonOb
|
|
|
53
53
|
abstract broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
54
54
|
abstract event<TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>): () => void;
|
|
55
55
|
abstract getConnection(): WebSocketConnection;
|
|
56
|
-
abstract getMyPresence(): TPresence
|
|
56
|
+
abstract getMyPresence(): TPresence;
|
|
57
57
|
abstract getMyself(): Id<UserInfo<TIO, TPresence>> | null;
|
|
58
58
|
abstract getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
|
|
59
59
|
abstract getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
|
|
@@ -64,6 +64,17 @@ declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonOb
|
|
|
64
64
|
abstract updateMyPresence(presence: Partial<TPresence>): void;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
declare abstract class AbstractStorageStore {
|
|
68
|
+
room: string;
|
|
69
|
+
constructor(room: string);
|
|
70
|
+
abstract addUpdate(update: string): Promise<void>;
|
|
71
|
+
abstract destroy(): Promise<void>;
|
|
72
|
+
abstract flatten(encodedState: string): Promise<void>;
|
|
73
|
+
abstract getShouldFlatten(): Promise<boolean>;
|
|
74
|
+
abstract getUpdates(start?: number): Promise<readonly string[]>;
|
|
75
|
+
abstract initialize(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
interface CrdtManagerOptions<TStorage extends Record<string, AbstractType<any>> = {}> {
|
|
68
79
|
encodedState?: string | Uint8Array | null;
|
|
69
80
|
initialStorage?: () => TStorage;
|
|
@@ -94,11 +105,19 @@ type RoomEndpoints<TIO extends IOLike> = {
|
|
|
94
105
|
} : {
|
|
95
106
|
authEndpoint?: undefined;
|
|
96
107
|
});
|
|
108
|
+
type PluvRoomAddon<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = (input: PluvRoomAddonInput<TIO, TPresence, TStorage>) => Partial<PluvRoomAddonResult>;
|
|
109
|
+
interface PluvRoomAddonInput<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> {
|
|
110
|
+
room: PluvRoom<TIO, TPresence, TStorage>;
|
|
111
|
+
}
|
|
112
|
+
interface PluvRoomAddonResult {
|
|
113
|
+
storage: AbstractStorageStore;
|
|
114
|
+
}
|
|
97
115
|
type PluvRoomDebug<TIO extends IOLike> = Id<{
|
|
98
116
|
output: readonly (keyof InferIOOutput<TIO>)[];
|
|
99
117
|
input: readonly (keyof InferIOInput<TIO>)[];
|
|
100
118
|
}>;
|
|
101
119
|
type PluvRoomOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = {
|
|
120
|
+
addons?: readonly PluvRoomAddon<TIO, TPresence, TStorage>[];
|
|
102
121
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
103
122
|
onAuthorizationFail?: (error: Error) => void;
|
|
104
123
|
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
@@ -109,12 +128,12 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
109
128
|
private _crdtNotifier;
|
|
110
129
|
private _debug;
|
|
111
130
|
private _eventNotifier;
|
|
112
|
-
private _initialStorage;
|
|
113
131
|
private _intervals;
|
|
114
132
|
private _listeners;
|
|
115
133
|
private _otherNotifier;
|
|
116
134
|
private _state;
|
|
117
135
|
private _stateNotifier;
|
|
136
|
+
private _storageStore;
|
|
118
137
|
private _subscriptions;
|
|
119
138
|
private _timeouts;
|
|
120
139
|
private _windowListeners;
|
|
@@ -124,10 +143,10 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
124
143
|
get webSocket(): WebSocket | null;
|
|
125
144
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
126
145
|
connect(): Promise<void>;
|
|
127
|
-
disconnect(): void
|
|
146
|
+
disconnect(): Promise<void>;
|
|
128
147
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
129
148
|
getConnection(): WebSocketConnection;
|
|
130
|
-
getMyPresence: () => TPresence
|
|
149
|
+
getMyPresence: () => TPresence;
|
|
131
150
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
132
151
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
133
152
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
@@ -136,6 +155,8 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
136
155
|
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
137
156
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
138
157
|
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
158
|
+
private _addToStorageStore;
|
|
159
|
+
private _applyStorageStore;
|
|
139
160
|
private _attachWindowListeners;
|
|
140
161
|
private _attachWsListeners;
|
|
141
162
|
private _clearInterval;
|
|
@@ -143,8 +164,11 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
143
164
|
private _closeWs;
|
|
144
165
|
private _detachWindowListeners;
|
|
145
166
|
private _detachWsListeners;
|
|
146
|
-
private
|
|
167
|
+
private _emitSharedTypes;
|
|
168
|
+
private _flattenStorageStore;
|
|
169
|
+
private _getAddon;
|
|
147
170
|
private _getAuthFetchOptions;
|
|
171
|
+
private _getAuthorization;
|
|
148
172
|
private _getWsEndpoint;
|
|
149
173
|
private _handleExit;
|
|
150
174
|
private _handlePresenceUpdatedMessage;
|
|
@@ -195,7 +219,7 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
|
|
|
195
219
|
enter: (room: string | PluvRoom<TIO, any, any>) => Promise<PluvRoom<TIO, JsonObject, any>>;
|
|
196
220
|
getRoom: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}>(room: string) => PluvRoom<TIO, TPresence, TStorage> | null;
|
|
197
221
|
getRooms: () => readonly PluvRoom<TIO, JsonObject, any>[];
|
|
198
|
-
leave: (room: string | PluvRoom<TIO, any, any>) => void
|
|
222
|
+
leave: (room: string | PluvRoom<TIO, any, any>) => Promise<void>;
|
|
199
223
|
private _logDebug;
|
|
200
224
|
}
|
|
201
225
|
|
|
@@ -221,7 +245,7 @@ declare class MockedRoom<TIO extends IOLike, TPresence extends JsonObject = {},
|
|
|
221
245
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
222
246
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
223
247
|
getConnection(): WebSocketConnection;
|
|
224
|
-
getMyPresence: () => TPresence
|
|
248
|
+
getMyPresence: () => TPresence;
|
|
225
249
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
226
250
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
227
251
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
@@ -246,4 +270,4 @@ declare namespace y {
|
|
|
246
270
|
};
|
|
247
271
|
}
|
|
248
272
|
|
|
249
|
-
export { AbstractRoom, ConnectionState, MockedRoom, MockedRoomConfig, MockedRoomEvents, PluvClient, PluvClientOptions, PluvRoom, PluvRoomDebug, UserInfo, WebSocketConnection, WebSocketState, createClient, y };
|
|
273
|
+
export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, MockedRoomConfig, MockedRoomEvents, PluvClient, PluvClientOptions, PluvRoom, PluvRoomAddon, PluvRoomAddonInput, PluvRoomAddonResult, PluvRoomDebug, UserInfo, WebSocketConnection, WebSocketState, createClient, y };
|