@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.
@@ -1,17 +1,17 @@
1
1
 
2
- > @pluv/client@0.8.0 build /home/runner/work/pluv/pluv/packages/client
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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
7
+ CLI tsup v7.0.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 35.24 KB
12
- ESM ⚡️ Build success in 95ms
13
- CJS dist/index.js 36.38 KB
14
- CJS ⚡️ Build success in 96ms
11
+ CJS dist/index.js 40.23 KB
12
+ CJS ⚡️ Build success in 98ms
13
+ ESM dist/index.mjs 39.02 KB
14
+ ESM ⚡️ Build success in 100ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4360ms
17
- DTS dist/index.d.ts 11.75 KB
16
+ DTS ⚡️ Build success in 4765ms
17
+ DTS dist/index.d.ts 12.92 KB
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 | null;
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 | null;
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 _getAuthorization;
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 | null;
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 };