@pluv/client 0.11.1 → 0.12.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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +254 -0
- package/dist/index.d.mts +31 -8
- package/dist/index.d.ts +31 -8
- package/dist/index.js +150 -36
- package/dist/index.mjs +150 -36
- package/package.json +7 -7
- package/src/AbstractRoom.ts +29 -10
- package/src/AbstractStorageStore.ts +0 -2
- package/src/CrdtManager.ts +33 -10
- package/src/CrdtNotifier.ts +14 -2
- package/src/EventNotifier.ts +3 -3
- package/src/MockedRoom.ts +85 -22
- package/src/OtherNotifier.ts +3 -3
- package/src/PluvClient.ts +6 -6
- package/src/PluvRoom.ts +121 -26
- package/src/StateNotifier.ts +6 -6
- package/src/UsersManager.ts +4 -4
- package/src/createClient.ts +1 -1
- package/src/index.ts +4 -1
- package/src/types.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.
|
|
2
|
+
> @pluv/client@0.12.1 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
|
|
@@ -8,11 +8,11 @@
|
|
|
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[32m44.05 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 109ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m42.81 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 110ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4203ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m14.23 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.23 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,259 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cae08aa: Updated storage from `getStorage` to never return null
|
|
8
|
+
- @pluv/crdt-yjs@0.12.1
|
|
9
|
+
- @pluv/types@0.12.1
|
|
10
|
+
|
|
11
|
+
## 0.12.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 436040b: Added ability to undo and redo changes to storage.
|
|
16
|
+
|
|
17
|
+
## @pluv/crdt-yjs
|
|
18
|
+
|
|
19
|
+
`@pluv/crdt-yjs` now exposes 5 new methods: `canRedo`, `canUndo`, `redo`, `undo` and `trackOrigins`.
|
|
20
|
+
|
|
21
|
+
Refer to the code-example below to better understand how to undo and redo with your doc.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// Example
|
|
25
|
+
import { array, doc } from "@pluv/crdt-yjs";
|
|
26
|
+
|
|
27
|
+
// Create your doc with your shared-types
|
|
28
|
+
const myDoc = doc({
|
|
29
|
+
messages: array<string>([]),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @description Track origins to enable undos and redos for your document.
|
|
34
|
+
* trackOrigins must be called before any storage mutations, to enable those
|
|
35
|
+
* mutations to be undone/redone.
|
|
36
|
+
*/
|
|
37
|
+
myDoc.trackOrigins({
|
|
38
|
+
/**
|
|
39
|
+
* @description This is the same `captureTimeout` option from yjs's UndoManager.
|
|
40
|
+
* This specifies a number in ms, during which edits are merged together to be
|
|
41
|
+
* undone together. Set this to 0, to track each transacted change individually.
|
|
42
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
43
|
+
* @default 500
|
|
44
|
+
*/
|
|
45
|
+
captureTimeout: 500,
|
|
46
|
+
/**
|
|
47
|
+
* @desription This is the same `trackedOrigins` option from yjs's UndoManager.
|
|
48
|
+
* This specifies transaction origins (strings only) to filter which transactions
|
|
49
|
+
* can be undone.
|
|
50
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
51
|
+
* @default undefined
|
|
52
|
+
*/
|
|
53
|
+
trackedOrigins: ["user-123"],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @description Check whether calling undo will mutate storage
|
|
58
|
+
* @returns boolean
|
|
59
|
+
*/
|
|
60
|
+
myDoc.canUndo();
|
|
61
|
+
/**
|
|
62
|
+
* @description Check whether calling redo will mutate storage
|
|
63
|
+
* @returns boolean
|
|
64
|
+
*/
|
|
65
|
+
myDoc.canRedo();
|
|
66
|
+
|
|
67
|
+
// Perform a storage mutation within a transaction so that it can be affected
|
|
68
|
+
// by undo/redo operations.
|
|
69
|
+
myDoc.transact(() => {
|
|
70
|
+
myDoc.get("messages").push(["hello world!"]);
|
|
71
|
+
}, "user-123");
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @description Undoes the last valid mutation to storage
|
|
75
|
+
*/
|
|
76
|
+
myDoc.undo();
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @description Re-applies the last undone mutation to storage
|
|
80
|
+
*/
|
|
81
|
+
myDoc.redo();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## @pluv/client
|
|
85
|
+
|
|
86
|
+
`@pluv/client`'s `PluvRoom` and `MockedRoom` now exposes 5 new methods: `canRedo`, `canUndo`, `redo`, `undo` and `transact`.
|
|
87
|
+
|
|
88
|
+
Refer to the code-example below to better understand how to undo and redo with your `PluvRoom`.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { createClient, y } from "@pluv/client";
|
|
92
|
+
|
|
93
|
+
const client = createClient({});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @description When a room is created, undo/redo will automatically
|
|
97
|
+
* be configured to filter for changes made by the connected user
|
|
98
|
+
* (so that users only undo/redo their changes).
|
|
99
|
+
*/
|
|
100
|
+
const room = client.createRoom("my-room", {
|
|
101
|
+
initialStorage: () => ({
|
|
102
|
+
messages: y.array<string>([]),
|
|
103
|
+
}),
|
|
104
|
+
/**
|
|
105
|
+
* @description This is the same `captureTimeout` option from yjs's UndoManager.
|
|
106
|
+
* This specifies a number in ms, during which edits are merged together to be
|
|
107
|
+
* undone together. Set this to 0, to track each transacted change individually.
|
|
108
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
109
|
+
* @default 500
|
|
110
|
+
*/
|
|
111
|
+
captureTimeout: 500,
|
|
112
|
+
/**
|
|
113
|
+
* @desription This is the same `trackedOrigins` option from yjs's UndoManager.
|
|
114
|
+
* This specifies transaction origins (strings only) to filter which transactions
|
|
115
|
+
* can be undone.
|
|
116
|
+
* When omitted, the user's connection id will be tracked. When provided,
|
|
117
|
+
* specifies additional tracked origins besides the user's connection id.
|
|
118
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
119
|
+
* @default undefined
|
|
120
|
+
*/
|
|
121
|
+
trackedOrigins: ["user-123"],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @description Check whether calling undo will mutate storage
|
|
126
|
+
* @returns boolean
|
|
127
|
+
*/
|
|
128
|
+
room.canUndo();
|
|
129
|
+
/**
|
|
130
|
+
* @description Check whether calling redo will mutate storage
|
|
131
|
+
* @returns boolean
|
|
132
|
+
*/
|
|
133
|
+
room.canRedo();
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @description Calling transact will enable a storage mutation to be undone/redone.
|
|
137
|
+
* When called without an origin, the origin will default to the user's connection
|
|
138
|
+
* id.
|
|
139
|
+
*
|
|
140
|
+
* You can specify a 2nd parameter to transact with a different transaction origin.
|
|
141
|
+
*/
|
|
142
|
+
room.transact(() => {
|
|
143
|
+
room.get("messages").push(["hello world!"]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// This will also be undoable because `"user-123"` is a tracked origin.
|
|
147
|
+
room.transact(() => {
|
|
148
|
+
room.get("messages").push(["hello world!"]);
|
|
149
|
+
}, "user-123");
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @description Undoes the last valid mutation to storage
|
|
153
|
+
*/
|
|
154
|
+
room.undo();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @description Re-applies the last undone mutation to storage
|
|
158
|
+
*/
|
|
159
|
+
room.redo();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## @pluv/react
|
|
163
|
+
|
|
164
|
+
`@pluv/react`'s `createRoomBundle` now exposes 5 new react hooks: `usePluvCanRedo`, `usePluvCanUndo`, `usePluvRedo`, `usePluvUndo` and `usePluvTransact`.
|
|
165
|
+
|
|
166
|
+
Refer to the code-example below to better understand how to undo and redo with your `createRoomBundle`.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { createBundle, createClient, y } from "@pluv/react";
|
|
170
|
+
import { type io } from "./io";
|
|
171
|
+
|
|
172
|
+
const client = createClient<typeof io>();
|
|
173
|
+
|
|
174
|
+
const { createRoomBundle } = createBundle(client);
|
|
175
|
+
|
|
176
|
+
const {
|
|
177
|
+
usePluvCanRedo,
|
|
178
|
+
usePluvCanUndo,
|
|
179
|
+
usePluvRedo,
|
|
180
|
+
usePluvStorage,
|
|
181
|
+
usePluvTransact,
|
|
182
|
+
usePluvUndo,
|
|
183
|
+
} = createRoomBundle({
|
|
184
|
+
initialStorage: () => ({
|
|
185
|
+
messages: y.array<string>([]),
|
|
186
|
+
}),
|
|
187
|
+
/**
|
|
188
|
+
* @description This is the same `captureTimeout` option from yjs's UndoManager.
|
|
189
|
+
* This specifies a number in ms, during which edits are merged together to be
|
|
190
|
+
* undone together. Set this to 0, to track each transacted change individually.
|
|
191
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
192
|
+
* @default 500
|
|
193
|
+
*/
|
|
194
|
+
captureTimeout: 500,
|
|
195
|
+
/**
|
|
196
|
+
* @desription This is the same `trackedOrigins` option from yjs's UndoManager.
|
|
197
|
+
* This specifies transaction origins (strings only) to filter which transactions
|
|
198
|
+
* can be undone.
|
|
199
|
+
* When omitted, the user's connection id will be tracked. When provided,
|
|
200
|
+
* specifies additional tracked origins besides the user's connection id.
|
|
201
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
202
|
+
* @default undefined
|
|
203
|
+
*/
|
|
204
|
+
trackedOrigins: ["user-123"],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @description Check whether calling undo will mutate storage
|
|
209
|
+
*/
|
|
210
|
+
const canUndo: boolean = usePluvCanUndo();
|
|
211
|
+
/**
|
|
212
|
+
* @description Check whether calling redo will mutate storage
|
|
213
|
+
*/
|
|
214
|
+
const canRedo: boolean = usePluvCanRedo();
|
|
215
|
+
|
|
216
|
+
const [messages, sharedType] = usePluvStorage("messages");
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @description Calling transact will enable a storage mutation to be undone/redone.
|
|
220
|
+
* When called without an origin, the origin will default to the user's connection
|
|
221
|
+
* id.
|
|
222
|
+
*
|
|
223
|
+
* You can specify a 2nd parameter to transact with a different transaction origin.
|
|
224
|
+
*/
|
|
225
|
+
const transact = usePluvTransact();
|
|
226
|
+
|
|
227
|
+
transact(() => {
|
|
228
|
+
sharedType?.push(["hello world!"]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// This will also be undoable because `"user-123"` is a tracked origin.
|
|
232
|
+
transact(() => {
|
|
233
|
+
sharedType?.push(["hello world!"]);
|
|
234
|
+
}, "user-123");
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @description Undoes the last valid mutation to storage
|
|
238
|
+
*/
|
|
239
|
+
const undo = usePluvUndo();
|
|
240
|
+
|
|
241
|
+
undo();
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @description Re-applies the last undone mutation to storage
|
|
245
|
+
*/
|
|
246
|
+
const redo = usePluvRedo();
|
|
247
|
+
|
|
248
|
+
redo();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Patch Changes
|
|
252
|
+
|
|
253
|
+
- Updated dependencies [436040b]
|
|
254
|
+
- @pluv/crdt-yjs@0.12.0
|
|
255
|
+
- @pluv/types@0.12.0
|
|
256
|
+
|
|
3
257
|
## 0.11.1
|
|
4
258
|
|
|
5
259
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InferYjsSharedTypeJson, array, map, object, text, xmlElement, xmlFragment, xmlText } from '@pluv/crdt-yjs';
|
|
2
|
-
export { InferYjsSharedTypeJson } from '@pluv/crdt-yjs';
|
|
1
|
+
import { InferYjsSharedTypeJson, TrackOriginOptions, array, map, object, text, xmlElement, xmlFragment, xmlText } from '@pluv/crdt-yjs';
|
|
2
|
+
export { InferYjsSharedTypeJson, TrackOriginOptions } from '@pluv/crdt-yjs';
|
|
3
3
|
import * as _pluv_types from '@pluv/types';
|
|
4
4
|
import { IOLike, InferIOOutput, Id, IOEventMessage, JsonObject, InferIOAuthorizeUser, InferIOAuthorize, InferIOInput, InputZodLike, InferIOAuthorizeRequired } from '@pluv/types';
|
|
5
5
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
@@ -51,16 +51,24 @@ declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonOb
|
|
|
51
51
|
readonly id: string;
|
|
52
52
|
constructor(room: string);
|
|
53
53
|
abstract broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
54
|
+
abstract canRedo(): boolean;
|
|
55
|
+
abstract canUndo(): boolean;
|
|
54
56
|
abstract event<TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>): () => void;
|
|
55
57
|
abstract getConnection(): WebSocketConnection;
|
|
56
58
|
abstract getMyPresence(): TPresence;
|
|
57
59
|
abstract getMyself(): Id<UserInfo<TIO, TPresence>> | null;
|
|
58
60
|
abstract getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
|
|
59
61
|
abstract getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
|
|
60
|
-
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey]
|
|
62
|
+
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
61
63
|
abstract other(connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>): () => void;
|
|
64
|
+
abstract redo(): void;
|
|
62
65
|
abstract storage<TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void): () => void;
|
|
66
|
+
abstract storageRoot(fn: (value: {
|
|
67
|
+
[P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>;
|
|
68
|
+
}) => void): () => void;
|
|
63
69
|
abstract subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>): () => void;
|
|
70
|
+
abstract transact(fn: (storage: TStorage) => void, origin?: string): void;
|
|
71
|
+
abstract undo(): void;
|
|
64
72
|
abstract updateMyPresence(presence: Partial<TPresence>): void;
|
|
65
73
|
}
|
|
66
74
|
|
|
@@ -75,10 +83,10 @@ declare abstract class AbstractStorageStore {
|
|
|
75
83
|
abstract initialize(): Promise<void>;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
|
|
86
|
+
type CrdtManagerOptions<TStorage extends Record<string, AbstractType<any>> = {}> = {
|
|
79
87
|
encodedState?: string | Uint8Array | null;
|
|
80
88
|
initialStorage?: () => TStorage;
|
|
81
|
-
}
|
|
89
|
+
} & TrackOriginOptions;
|
|
82
90
|
|
|
83
91
|
type UsersManagerConfig<TPresence extends JsonObject = {}> = {
|
|
84
92
|
initialPresence?: TPresence;
|
|
@@ -121,9 +129,10 @@ type PluvRoomOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TSto
|
|
|
121
129
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
122
130
|
onAuthorizationFail?: (error: Error) => void;
|
|
123
131
|
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
124
|
-
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = RoomEndpoints<TIO> & PluvRoomOptions<TIO, TPresence, TStorage
|
|
132
|
+
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = RoomEndpoints<TIO> & PluvRoomOptions<TIO, TPresence, TStorage> & TrackOriginOptions;
|
|
125
133
|
declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
126
134
|
readonly _endpoints: RoomEndpoints<TIO>;
|
|
135
|
+
private _captureTimeout;
|
|
127
136
|
private _crdtManager;
|
|
128
137
|
private _crdtNotifier;
|
|
129
138
|
private _debug;
|
|
@@ -136,12 +145,15 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
136
145
|
private _storageStore;
|
|
137
146
|
private _subscriptions;
|
|
138
147
|
private _timeouts;
|
|
148
|
+
private _trackedOrigins;
|
|
139
149
|
private _windowListeners;
|
|
140
150
|
private _wsListeners;
|
|
141
151
|
private _usersManager;
|
|
142
152
|
constructor(room: string, options: RoomConfig<TIO, TPresence, TStorage>);
|
|
143
153
|
get webSocket(): WebSocket | null;
|
|
144
154
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
155
|
+
canRedo: () => boolean;
|
|
156
|
+
canUndo: () => boolean;
|
|
145
157
|
connect(): Promise<void>;
|
|
146
158
|
disconnect(): Promise<void>;
|
|
147
159
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
@@ -150,10 +162,14 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
150
162
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
151
163
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
152
164
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
153
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey]
|
|
165
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
154
166
|
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
167
|
+
redo: () => void;
|
|
155
168
|
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
169
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>; }) => void) => (() => void);
|
|
156
170
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
171
|
+
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
172
|
+
undo: () => void;
|
|
157
173
|
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
158
174
|
private _addToStorageStore;
|
|
159
175
|
private _applyStorageStore;
|
|
@@ -169,6 +185,7 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
169
185
|
private _getAddon;
|
|
170
186
|
private _getAuthFetchOptions;
|
|
171
187
|
private _getAuthorization;
|
|
188
|
+
private _getTrackedOrigins;
|
|
172
189
|
private _getWsEndpoint;
|
|
173
190
|
private _handleExit;
|
|
174
191
|
private _handlePresenceUpdatedMessage;
|
|
@@ -243,16 +260,22 @@ declare class MockedRoom<TIO extends IOLike, TPresence extends JsonObject = {},
|
|
|
243
260
|
private _usersManager;
|
|
244
261
|
constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TStorage>);
|
|
245
262
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
263
|
+
canRedo: () => boolean;
|
|
264
|
+
canUndo: () => boolean;
|
|
246
265
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
247
266
|
getConnection(): WebSocketConnection;
|
|
248
267
|
getMyPresence: () => TPresence;
|
|
249
268
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
250
269
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
251
270
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
252
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey]
|
|
271
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
253
272
|
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
273
|
+
redo: () => void;
|
|
254
274
|
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
275
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>; }) => void) => (() => void);
|
|
255
276
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
277
|
+
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
278
|
+
undo: () => void;
|
|
256
279
|
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
257
280
|
private _observeCrdt;
|
|
258
281
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InferYjsSharedTypeJson, array, map, object, text, xmlElement, xmlFragment, xmlText } from '@pluv/crdt-yjs';
|
|
2
|
-
export { InferYjsSharedTypeJson } from '@pluv/crdt-yjs';
|
|
1
|
+
import { InferYjsSharedTypeJson, TrackOriginOptions, array, map, object, text, xmlElement, xmlFragment, xmlText } from '@pluv/crdt-yjs';
|
|
2
|
+
export { InferYjsSharedTypeJson, TrackOriginOptions } from '@pluv/crdt-yjs';
|
|
3
3
|
import * as _pluv_types from '@pluv/types';
|
|
4
4
|
import { IOLike, InferIOOutput, Id, IOEventMessage, JsonObject, InferIOAuthorizeUser, InferIOAuthorize, InferIOInput, InputZodLike, InferIOAuthorizeRequired } from '@pluv/types';
|
|
5
5
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
@@ -51,16 +51,24 @@ declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonOb
|
|
|
51
51
|
readonly id: string;
|
|
52
52
|
constructor(room: string);
|
|
53
53
|
abstract broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
54
|
+
abstract canRedo(): boolean;
|
|
55
|
+
abstract canUndo(): boolean;
|
|
54
56
|
abstract event<TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>): () => void;
|
|
55
57
|
abstract getConnection(): WebSocketConnection;
|
|
56
58
|
abstract getMyPresence(): TPresence;
|
|
57
59
|
abstract getMyself(): Id<UserInfo<TIO, TPresence>> | null;
|
|
58
60
|
abstract getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
|
|
59
61
|
abstract getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
|
|
60
|
-
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey]
|
|
62
|
+
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
61
63
|
abstract other(connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>): () => void;
|
|
64
|
+
abstract redo(): void;
|
|
62
65
|
abstract storage<TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void): () => void;
|
|
66
|
+
abstract storageRoot(fn: (value: {
|
|
67
|
+
[P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>;
|
|
68
|
+
}) => void): () => void;
|
|
63
69
|
abstract subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>): () => void;
|
|
70
|
+
abstract transact(fn: (storage: TStorage) => void, origin?: string): void;
|
|
71
|
+
abstract undo(): void;
|
|
64
72
|
abstract updateMyPresence(presence: Partial<TPresence>): void;
|
|
65
73
|
}
|
|
66
74
|
|
|
@@ -75,10 +83,10 @@ declare abstract class AbstractStorageStore {
|
|
|
75
83
|
abstract initialize(): Promise<void>;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
|
|
86
|
+
type CrdtManagerOptions<TStorage extends Record<string, AbstractType<any>> = {}> = {
|
|
79
87
|
encodedState?: string | Uint8Array | null;
|
|
80
88
|
initialStorage?: () => TStorage;
|
|
81
|
-
}
|
|
89
|
+
} & TrackOriginOptions;
|
|
82
90
|
|
|
83
91
|
type UsersManagerConfig<TPresence extends JsonObject = {}> = {
|
|
84
92
|
initialPresence?: TPresence;
|
|
@@ -121,9 +129,10 @@ type PluvRoomOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TSto
|
|
|
121
129
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
122
130
|
onAuthorizationFail?: (error: Error) => void;
|
|
123
131
|
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
124
|
-
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = RoomEndpoints<TIO> & PluvRoomOptions<TIO, TPresence, TStorage
|
|
132
|
+
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = RoomEndpoints<TIO> & PluvRoomOptions<TIO, TPresence, TStorage> & TrackOriginOptions;
|
|
125
133
|
declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
126
134
|
readonly _endpoints: RoomEndpoints<TIO>;
|
|
135
|
+
private _captureTimeout;
|
|
127
136
|
private _crdtManager;
|
|
128
137
|
private _crdtNotifier;
|
|
129
138
|
private _debug;
|
|
@@ -136,12 +145,15 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
136
145
|
private _storageStore;
|
|
137
146
|
private _subscriptions;
|
|
138
147
|
private _timeouts;
|
|
148
|
+
private _trackedOrigins;
|
|
139
149
|
private _windowListeners;
|
|
140
150
|
private _wsListeners;
|
|
141
151
|
private _usersManager;
|
|
142
152
|
constructor(room: string, options: RoomConfig<TIO, TPresence, TStorage>);
|
|
143
153
|
get webSocket(): WebSocket | null;
|
|
144
154
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
155
|
+
canRedo: () => boolean;
|
|
156
|
+
canUndo: () => boolean;
|
|
145
157
|
connect(): Promise<void>;
|
|
146
158
|
disconnect(): Promise<void>;
|
|
147
159
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
@@ -150,10 +162,14 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
150
162
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
151
163
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
152
164
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
153
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey]
|
|
165
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
154
166
|
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
167
|
+
redo: () => void;
|
|
155
168
|
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
169
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>; }) => void) => (() => void);
|
|
156
170
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
171
|
+
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
172
|
+
undo: () => void;
|
|
157
173
|
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
158
174
|
private _addToStorageStore;
|
|
159
175
|
private _applyStorageStore;
|
|
@@ -169,6 +185,7 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
169
185
|
private _getAddon;
|
|
170
186
|
private _getAuthFetchOptions;
|
|
171
187
|
private _getAuthorization;
|
|
188
|
+
private _getTrackedOrigins;
|
|
172
189
|
private _getWsEndpoint;
|
|
173
190
|
private _handleExit;
|
|
174
191
|
private _handlePresenceUpdatedMessage;
|
|
@@ -243,16 +260,22 @@ declare class MockedRoom<TIO extends IOLike, TPresence extends JsonObject = {},
|
|
|
243
260
|
private _usersManager;
|
|
244
261
|
constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TStorage>);
|
|
245
262
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
263
|
+
canRedo: () => boolean;
|
|
264
|
+
canUndo: () => boolean;
|
|
246
265
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
247
266
|
getConnection(): WebSocketConnection;
|
|
248
267
|
getMyPresence: () => TPresence;
|
|
249
268
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
250
269
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
251
270
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
252
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey]
|
|
271
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
253
272
|
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
273
|
+
redo: () => void;
|
|
254
274
|
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
275
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>; }) => void) => (() => void);
|
|
255
276
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
277
|
+
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
278
|
+
undo: () => void;
|
|
256
279
|
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
257
280
|
private _observeCrdt;
|
|
258
281
|
}
|