@pluv/client 0.15.0 → 0.16.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 +9 -9
- package/CHANGELOG.md +182 -37
- package/README.md +9 -12
- package/dist/index.d.mts +65 -77
- package/dist/index.d.ts +65 -77
- package/dist/index.js +271 -303
- package/dist/index.mjs +270 -313
- package/package.json +7 -11
- package/src/AbstractRoom.ts +13 -8
- package/src/CrdtManager.ts +55 -57
- package/src/CrdtNotifier.ts +12 -12
- package/src/MockedRoom.ts +44 -40
- package/src/OtherNotifier.ts +1 -1
- package/src/PluvClient.ts +4 -4
- package/src/PluvRoom.ts +67 -76
- package/src/StateNotifier.ts +8 -5
- package/src/index.ts +6 -11
- package/src/y.ts +0 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.
|
|
2
|
+
> @pluv/client@0.16.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 v8.0.
|
|
7
|
+
[34mCLI[39m tsup v8.0.2
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m41.52 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 144ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m42.79 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 158ms
|
|
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 3847ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m13.94 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.94 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,156 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4280220: ## Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Storage types are now kept on the root of the document.
|
|
10
|
+
- Previously, `@pluv/crdt-yjs` kept all shared-types on a hidden Yjs Map called `storage` on the root of the Yjs Doc. Now all shared-types are kept on the root of the Yjs Doc instead. This behavior should be more in-line with how shared-types are documented to be used from Yjs.
|
|
11
|
+
- `@pluv/client` and `@pluv/react` no-longer re-export `@pluv/crdt-yjs`. This package will now need to be installed separately.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# if installing @pluv/client
|
|
15
|
+
npm install @pluv/client @pluv/crdt-yjs
|
|
16
|
+
# if installing @pluv/react
|
|
17
|
+
npm install @pluv/react @pluv/crdt-yjs
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Before:
|
|
22
|
+
import { createClient, y } from "@pluv/client";
|
|
23
|
+
// After:
|
|
24
|
+
import { createClient } from "@pluv/client";
|
|
25
|
+
import { yjs } from "@pluv/crdt-yjs"; // y renamed to yjs
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- The `y` import has been renamed to `yjs`.
|
|
29
|
+
```ts
|
|
30
|
+
// Before:
|
|
31
|
+
import { y } from "@pluv/crdt-yjs";
|
|
32
|
+
// After:
|
|
33
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
34
|
+
```
|
|
35
|
+
- `@pluv/crdt-yjs` functions no-longer return Yjs shared-types directly, but instead return an `AbstractCrdtType` from `@pluv/crdt` (new package). This also affects methods that return storage shared types in both `@pluv/client` and `@pluv/react` from functions like `PluvRoom.getStorage` and `PluvRoom.useStorage`.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// Before:
|
|
39
|
+
import { y } from "@pluv/crdt-yjs";
|
|
40
|
+
import type { Array as YArray, Map as YMap } from "yjs";
|
|
41
|
+
|
|
42
|
+
const array: YArray<YMap<{ message: string }>> = y.array([
|
|
43
|
+
y.object({ message: "Hello" }),
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
array.push([y.object({ message: "World!" })]);
|
|
47
|
+
|
|
48
|
+
// After:
|
|
49
|
+
import type { CrdtYjsArray, CrdtYjsObject } from "@pluv/crdt-yjs";
|
|
50
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
51
|
+
import type { Array as YArray } from "yjs";
|
|
52
|
+
|
|
53
|
+
const array: CrdtYjsArray<CrdtYjsObject<{ message: string }>> = yjs.array([
|
|
54
|
+
yjs.object({ message: "Hello" }),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
array.push(yjs.object({ message: "World!" }));
|
|
58
|
+
|
|
59
|
+
// use .value to get the underlying yjs type
|
|
60
|
+
const yarray: YArray<YMap<{ message: string }>> = array.value;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `initialStorage` must now use the `doc` function from `@pluv/crdt-yjs` to be defined. This also affects `@pluv/react`.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// Before:
|
|
67
|
+
import { createClient, y } from "@pluv/client";
|
|
68
|
+
|
|
69
|
+
const client = createClient({
|
|
70
|
+
/* ... */
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
client.createRoom({
|
|
74
|
+
// ...
|
|
75
|
+
initialStorage: () => ({
|
|
76
|
+
messages: y.array([y.object({ message: "Hello world!" })]),
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// After:
|
|
81
|
+
import { createClient } from "@pluv/client";
|
|
82
|
+
// This is now imported separately
|
|
83
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
84
|
+
|
|
85
|
+
const client = createClient({
|
|
86
|
+
/* ... */
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
client.createRoom({
|
|
90
|
+
// ...
|
|
91
|
+
initialStorage: yjs.doc(() => ({
|
|
92
|
+
messages: yjs.array([yjs.object({ message: "Hello world!" })]),
|
|
93
|
+
})),
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- `@pluv/client` can now instead use [loro](https://github.com/loro-dev/loro) instead of [yjs](https://github.com/yjs/yjs).
|
|
98
|
+
```bash
|
|
99
|
+
npm install @pluv/client @pluv/crdt-loro loro-crdt
|
|
100
|
+
```
|
|
101
|
+
- If you are using storage features with pluv, `@pluv/io` must now specify which crdt library (i.e. `@pluv/crdt-yjs` or `@pluv/crdt-loro`) it is meant to use.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { loro } from "@pluv/crdt-loro";
|
|
105
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
106
|
+
import { createIO } from "@pluv/io";
|
|
107
|
+
|
|
108
|
+
const io = createIO({
|
|
109
|
+
// ...
|
|
110
|
+
// If using loro
|
|
111
|
+
crdt: loro,
|
|
112
|
+
// If using yjs
|
|
113
|
+
crdt: yjs,
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- `PluvRoom.getDoc()` from `@pluv/client` no-longer returns the Yjs Doc instance, but rather a `AbstractCrdtDoc` instance from `@pluv/crdt`. This also affects the hook from `@pluv/react`.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// Before:
|
|
121
|
+
import { Doc as YDoc } from "yjs";
|
|
122
|
+
|
|
123
|
+
const room: PluvRoom = client.createRoom({
|
|
124
|
+
/* ... */
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const doc: YDoc = room.getDoc();
|
|
128
|
+
|
|
129
|
+
// After:
|
|
130
|
+
import { CrdtYjsDoc } from "@pluv/crdt-yjs";
|
|
131
|
+
import { Doc as YDoc } from "yjs";
|
|
132
|
+
|
|
133
|
+
const room: PluvRoom = client.createRoom({
|
|
134
|
+
/* ... */
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const doc: CrdtYjsDoc<any> = room.getDoc();
|
|
138
|
+
const ydoc: YDoc = doc.value;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- `@pluv/client` and `@pluv/react` now may return `null` when retrieving storage while storage is being initialized.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const sharedType = room.getStorage("messages"); // This may be null
|
|
145
|
+
|
|
146
|
+
const [data, sharedType] = useStorage("messages"); // data and sharedType may both be null
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- @pluv/crdt@0.16.0
|
|
152
|
+
- @pluv/types@0.16.0
|
|
153
|
+
|
|
3
154
|
## 0.15.0
|
|
4
155
|
|
|
5
156
|
### Patch Changes
|
|
@@ -218,7 +369,7 @@
|
|
|
218
369
|
|
|
219
370
|
## @pluv/react
|
|
220
371
|
|
|
221
|
-
`@pluv/react`'s `createRoomBundle` now exposes 5 new react hooks: `
|
|
372
|
+
`@pluv/react`'s `createRoomBundle` now exposes 5 new react hooks: `useCanRedo`, `useCanUndo`, `useRedo`, `useUndo` and `useTransact`.
|
|
222
373
|
|
|
223
374
|
Refer to the code-example below to better understand how to undo and redo with your `createRoomBundle`.
|
|
224
375
|
|
|
@@ -230,47 +381,41 @@
|
|
|
230
381
|
|
|
231
382
|
const { createRoomBundle } = createBundle(client);
|
|
232
383
|
|
|
233
|
-
const {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
* specifies additional tracked origins besides the user's connection id.
|
|
258
|
-
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
259
|
-
* @default undefined
|
|
260
|
-
*/
|
|
261
|
-
trackedOrigins: ["user-123"],
|
|
262
|
-
});
|
|
384
|
+
const { useCanRedo, useCanUndo, useRedo, useStorage, useTransact, useUndo } =
|
|
385
|
+
createRoomBundle({
|
|
386
|
+
initialStorage: () => ({
|
|
387
|
+
messages: y.array<string>([]),
|
|
388
|
+
}),
|
|
389
|
+
/**
|
|
390
|
+
* @description This is the same `captureTimeout` option from yjs's UndoManager.
|
|
391
|
+
* This specifies a number in ms, during which edits are merged together to be
|
|
392
|
+
* undone together. Set this to 0, to track each transacted change individually.
|
|
393
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
394
|
+
* @default 500
|
|
395
|
+
*/
|
|
396
|
+
captureTimeout: 500,
|
|
397
|
+
/**
|
|
398
|
+
* @desription This is the same `trackedOrigins` option from yjs's UndoManager.
|
|
399
|
+
* This specifies transaction origins (strings only) to filter which transactions
|
|
400
|
+
* can be undone.
|
|
401
|
+
* When omitted, the user's connection id will be tracked. When provided,
|
|
402
|
+
* specifies additional tracked origins besides the user's connection id.
|
|
403
|
+
* @see (@link https://docs.yjs.dev/api/undo-manager)
|
|
404
|
+
* @default undefined
|
|
405
|
+
*/
|
|
406
|
+
trackedOrigins: ["user-123"],
|
|
407
|
+
});
|
|
263
408
|
|
|
264
409
|
/**
|
|
265
410
|
* @description Check whether calling undo will mutate storage
|
|
266
411
|
*/
|
|
267
|
-
const canUndo: boolean =
|
|
412
|
+
const canUndo: boolean = useCanUndo();
|
|
268
413
|
/**
|
|
269
414
|
* @description Check whether calling redo will mutate storage
|
|
270
415
|
*/
|
|
271
|
-
const canRedo: boolean =
|
|
416
|
+
const canRedo: boolean = useCanRedo();
|
|
272
417
|
|
|
273
|
-
const [messages, sharedType] =
|
|
418
|
+
const [messages, sharedType] = useStorage("messages");
|
|
274
419
|
|
|
275
420
|
/**
|
|
276
421
|
* @description Calling transact will enable a storage mutation to be undone/redone.
|
|
@@ -279,7 +424,7 @@
|
|
|
279
424
|
*
|
|
280
425
|
* You can specify a 2nd parameter to transact with a different transaction origin.
|
|
281
426
|
*/
|
|
282
|
-
const transact =
|
|
427
|
+
const transact = useTransact();
|
|
283
428
|
|
|
284
429
|
transact(() => {
|
|
285
430
|
sharedType.push(["hello world!"]);
|
|
@@ -293,14 +438,14 @@
|
|
|
293
438
|
/**
|
|
294
439
|
* @description Undoes the last valid mutation to storage
|
|
295
440
|
*/
|
|
296
|
-
const undo =
|
|
441
|
+
const undo = useUndo();
|
|
297
442
|
|
|
298
443
|
undo();
|
|
299
444
|
|
|
300
445
|
/**
|
|
301
446
|
* @description Re-applies the last undone mutation to storage
|
|
302
447
|
*/
|
|
303
|
-
const redo =
|
|
448
|
+
const redo = useRedo();
|
|
304
449
|
|
|
305
450
|
redo();
|
|
306
451
|
```
|
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
<br />
|
|
6
6
|
<img src="https://github.com/pluv-io/pluv/blob/master/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="180" style="border-radius:16px" />
|
|
7
7
|
<br />
|
|
8
|
-
Pluv.IO (preview)
|
|
8
|
+
<a href="https://pluv.io/docs/introduction">Pluv.IO (preview)</a>
|
|
9
9
|
<br />
|
|
10
10
|
</h1>
|
|
11
11
|
|
|
12
12
|
<h3 align="center">Multi-platform, E2E type-safe realtime packages</h3>
|
|
13
|
-
<h4 align="center">💕 Inspired by <a href="https://trpc.io">trpc</a> 💕
|
|
13
|
+
<h4 align="center">💕 Inspired by <a href="https://trpc.io">trpc</a> 💕 <a href="https://docs.yjs.dev/">yjs</a> 💕 and <a href="https://developers.cloudflare.com/">Cloudflare</a> 💕 </h4>
|
|
14
14
|
|
|
15
15
|
<p align="center">
|
|
16
16
|
<a href="https://www.npmjs.com/package/@pluv/client">
|
|
@@ -19,14 +19,10 @@
|
|
|
19
19
|
<a href="https://github.com/pluv-io/pluv/blob/master/LICENSE">
|
|
20
20
|
<img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
|
|
21
21
|
</a>
|
|
22
|
-
<img src="https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555" alt="TypeScript" />
|
|
23
22
|
<a href="https://commitizen.github.io/cz-cli/">
|
|
24
23
|
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" />
|
|
25
24
|
</a>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<p align="center">
|
|
29
|
-
<img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
|
|
25
|
+
<img src="https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555" alt="TypeScript" />
|
|
30
26
|
</p>
|
|
31
27
|
|
|
32
28
|
## `@pluv/client`
|
|
@@ -39,13 +35,13 @@
|
|
|
39
35
|
|
|
40
36
|
```bash
|
|
41
37
|
# npm
|
|
42
|
-
npm install @pluv/client yjs
|
|
38
|
+
npm install @pluv/client @pluv/crdt-yjs yjs
|
|
43
39
|
|
|
44
40
|
# yarn
|
|
45
|
-
yarn add @pluv/client yjs
|
|
41
|
+
yarn add @pluv/client @pluv/crdt-yjs yjs
|
|
46
42
|
|
|
47
43
|
# pnpm
|
|
48
|
-
pnpm add @pluv/client yjs
|
|
44
|
+
pnpm add @pluv/client @pluv/crdt-yjs yjs
|
|
49
45
|
```
|
|
50
46
|
|
|
51
47
|
If you plan on using presence and/or storage, make sure to also install `zod`.
|
|
@@ -53,7 +49,8 @@ If you plan on using presence and/or storage, make sure to also install `zod`.
|
|
|
53
49
|
## Basic Example
|
|
54
50
|
|
|
55
51
|
```ts
|
|
56
|
-
import { createClient
|
|
52
|
+
import { createClient } from "@pluv/client";
|
|
53
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
57
54
|
import { z } from "zod";
|
|
58
55
|
// Import the PluvIO instance as a type from your server file
|
|
59
56
|
import { type io } from "./server";
|
|
@@ -79,7 +76,7 @@ interface Storage {
|
|
|
79
76
|
// Create a room to join
|
|
80
77
|
const room = client.createRoom<Presence, Storage>("my-room", {
|
|
81
78
|
initialPresence: { cursor: null },
|
|
82
|
-
initialStorage: () => ({ messages:
|
|
79
|
+
initialStorage: yjs.doc(() => ({ messages: yjs.array([]) })),
|
|
83
80
|
onAuthorizationFail: (error) => {
|
|
84
81
|
console.log(error.message);
|
|
85
82
|
},
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { AbstractCrdtType, AbstractCrdtDoc, InferCrdtStorageJson, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
2
|
+
export { AbstractCrdtType, InferCrdtStorageJson } from '@pluv/crdt';
|
|
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';
|
|
6
|
-
import { AbstractType, Doc } from 'yjs';
|
|
7
|
-
export { AbstractType } from 'yjs';
|
|
8
6
|
import { Subject } from 'wonka';
|
|
9
7
|
|
|
10
8
|
type EventNotifierSubscriptionCallback<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
@@ -43,29 +41,31 @@ interface StateNotifierSubjects<TIO extends IOLike, TPresence extends JsonObject
|
|
|
43
41
|
"my-presence": Subject<TPresence | null>;
|
|
44
42
|
myself: Subject<Readonly<Id<UserInfo<TIO>>> | null>;
|
|
45
43
|
others: Subject<readonly Id<UserInfo<TIO>>[]>;
|
|
44
|
+
"storage-loaded": Subject<boolean>;
|
|
46
45
|
}
|
|
47
46
|
type InferSubjectValue<TIO extends IOLike, TPresence extends JsonObject, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = StateNotifierSubjects<TIO, TPresence>[TSubject] extends Subject<infer IValue> ? Id<IValue> : never;
|
|
48
47
|
type SubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = (value: InferSubjectValue<TIO, TPresence, TSubject>) => void;
|
|
49
48
|
|
|
50
|
-
declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
49
|
+
declare abstract class AbstractRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> {
|
|
51
50
|
readonly id: string;
|
|
52
51
|
constructor(room: string);
|
|
52
|
+
abstract storageLoaded: boolean;
|
|
53
53
|
abstract broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
54
54
|
abstract canRedo(): boolean;
|
|
55
55
|
abstract canUndo(): boolean;
|
|
56
|
-
abstract getDoc():
|
|
56
|
+
abstract getDoc(): AbstractCrdtDoc<TStorage>;
|
|
57
57
|
abstract event<TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>): () => void;
|
|
58
58
|
abstract getConnection(): WebSocketConnection;
|
|
59
59
|
abstract getMyPresence(): TPresence;
|
|
60
60
|
abstract getMyself(): Id<UserInfo<TIO, TPresence>> | null;
|
|
61
61
|
abstract getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
|
|
62
62
|
abstract getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
|
|
63
|
-
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
63
|
+
abstract getStorage<TKey extends keyof TStorage>(key: TKey): TStorage[TKey] | null;
|
|
64
64
|
abstract other(connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>): () => void;
|
|
65
65
|
abstract redo(): void;
|
|
66
|
-
abstract storage<TKey extends keyof TStorage>(key: TKey, fn: (value:
|
|
66
|
+
abstract storage<TKey extends keyof TStorage>(key: TKey, fn: (value: InferCrdtStorageJson<TStorage[TKey]>) => void): () => void;
|
|
67
67
|
abstract storageRoot(fn: (value: {
|
|
68
|
-
[P in keyof TStorage]:
|
|
68
|
+
[P in keyof TStorage]: InferCrdtStorageJson<TStorage[P]>;
|
|
69
69
|
}) => void): () => void;
|
|
70
70
|
abstract subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>): () => void;
|
|
71
71
|
abstract transact(fn: (storage: TStorage) => void, origin?: string): void;
|
|
@@ -84,16 +84,56 @@ declare abstract class AbstractStorageStore {
|
|
|
84
84
|
abstract initialize(): Promise<void>;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
type CrdtManagerOptions<TStorage extends Record<string,
|
|
87
|
+
type CrdtManagerOptions<TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> = {
|
|
88
88
|
encodedState?: string | Uint8Array | null;
|
|
89
|
-
initialStorage?:
|
|
90
|
-
}
|
|
89
|
+
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
type UsersManagerConfig<TPresence extends JsonObject = {}> = {
|
|
93
93
|
initialPresence?: TPresence;
|
|
94
94
|
presence?: InputZodLike<TPresence>;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
type MockedRoomEvents<TIO extends IOLike> = Partial<{
|
|
98
|
+
[P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>>;
|
|
99
|
+
}>;
|
|
100
|
+
type MockedRoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> = {
|
|
101
|
+
events?: MockedRoomEvents<TIO>;
|
|
102
|
+
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
103
|
+
declare class MockedRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
104
|
+
private _crdtManager;
|
|
105
|
+
private _crdtNotifier;
|
|
106
|
+
private _eventNotifier;
|
|
107
|
+
private _events?;
|
|
108
|
+
private _otherNotifier;
|
|
109
|
+
private _state;
|
|
110
|
+
private _stateNotifier;
|
|
111
|
+
private _subscriptions;
|
|
112
|
+
private _usersManager;
|
|
113
|
+
constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TStorage>);
|
|
114
|
+
get storageLoaded(): boolean;
|
|
115
|
+
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
116
|
+
canRedo: () => boolean;
|
|
117
|
+
canUndo: () => boolean;
|
|
118
|
+
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
119
|
+
getConnection(): WebSocketConnection;
|
|
120
|
+
getDoc(): AbstractCrdtDoc<TStorage>;
|
|
121
|
+
getMyPresence: () => TPresence;
|
|
122
|
+
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
123
|
+
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
124
|
+
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
125
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey] | null;
|
|
126
|
+
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
127
|
+
redo: () => void;
|
|
128
|
+
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferCrdtStorageJson<TStorage[TKey]>) => void) => (() => void);
|
|
129
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferCrdtStorageJson<TStorage[P]>; }) => void) => (() => void);
|
|
130
|
+
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
131
|
+
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
132
|
+
undo: () => void;
|
|
133
|
+
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
134
|
+
private _observeCrdt;
|
|
135
|
+
}
|
|
136
|
+
|
|
97
137
|
declare global {
|
|
98
138
|
var process: {
|
|
99
139
|
env: {
|
|
@@ -114,8 +154,8 @@ type RoomEndpoints<TIO extends IOLike> = {
|
|
|
114
154
|
} : {
|
|
115
155
|
authEndpoint?: undefined;
|
|
116
156
|
});
|
|
117
|
-
type PluvRoomAddon<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
118
|
-
interface PluvRoomAddonInput<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
157
|
+
type PluvRoomAddon<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> = (input: PluvRoomAddonInput<TIO, TPresence, TStorage>) => Partial<PluvRoomAddonResult>;
|
|
158
|
+
interface PluvRoomAddonInput<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> {
|
|
119
159
|
room: PluvRoom<TIO, TPresence, TStorage>;
|
|
120
160
|
}
|
|
121
161
|
interface PluvRoomAddonResult {
|
|
@@ -125,15 +165,14 @@ type PluvRoomDebug<TIO extends IOLike> = Id<{
|
|
|
125
165
|
output: readonly (keyof InferIOOutput<TIO>)[];
|
|
126
166
|
input: readonly (keyof InferIOInput<TIO>)[];
|
|
127
167
|
}>;
|
|
128
|
-
type PluvRoomOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
168
|
+
type PluvRoomOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> = {
|
|
129
169
|
addons?: readonly PluvRoomAddon<TIO, TPresence, TStorage>[];
|
|
130
170
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
131
171
|
onAuthorizationFail?: (error: Error) => void;
|
|
132
172
|
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
133
|
-
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
134
|
-
declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
173
|
+
type RoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> = RoomEndpoints<TIO> & PluvRoomOptions<TIO, TPresence, TStorage>;
|
|
174
|
+
declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
135
175
|
readonly _endpoints: RoomEndpoints<TIO>;
|
|
136
|
-
private _captureTimeout;
|
|
137
176
|
private _crdtManager;
|
|
138
177
|
private _crdtNotifier;
|
|
139
178
|
private _debug;
|
|
@@ -146,11 +185,11 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
146
185
|
private _storageStore;
|
|
147
186
|
private _subscriptions;
|
|
148
187
|
private _timeouts;
|
|
149
|
-
private _trackedOrigins;
|
|
150
188
|
private _windowListeners;
|
|
151
189
|
private _wsListeners;
|
|
152
190
|
private _usersManager;
|
|
153
191
|
constructor(room: string, options: RoomConfig<TIO, TPresence, TStorage>);
|
|
192
|
+
get storageLoaded(): boolean;
|
|
154
193
|
get webSocket(): WebSocket | null;
|
|
155
194
|
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
156
195
|
canRedo: () => boolean;
|
|
@@ -159,16 +198,16 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
159
198
|
disconnect(): Promise<void>;
|
|
160
199
|
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
161
200
|
getConnection(): WebSocketConnection;
|
|
162
|
-
getDoc():
|
|
201
|
+
getDoc(): AbstractCrdtDoc<TStorage>;
|
|
163
202
|
getMyPresence: () => TPresence;
|
|
164
203
|
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
165
204
|
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
166
205
|
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
167
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
206
|
+
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey] | null;
|
|
168
207
|
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
169
208
|
redo: () => void;
|
|
170
|
-
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value:
|
|
171
|
-
storageRoot: (fn: (value: { [P in keyof TStorage]:
|
|
209
|
+
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferCrdtStorageJson<TStorage[TKey]>) => void) => (() => void);
|
|
210
|
+
storageRoot: (fn: (value: { [P in keyof TStorage]: InferCrdtStorageJson<TStorage[P]>; }) => void) => (() => void);
|
|
172
211
|
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
173
212
|
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
174
213
|
undo: () => void;
|
|
@@ -187,7 +226,6 @@ declare class PluvRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TS
|
|
|
187
226
|
private _getAddon;
|
|
188
227
|
private _getAuthFetchOptions;
|
|
189
228
|
private _getAuthorization;
|
|
190
|
-
private _getTrackedOrigins;
|
|
191
229
|
private _getWsEndpoint;
|
|
192
230
|
private _handleExit;
|
|
193
231
|
private _handlePresenceUpdatedMessage;
|
|
@@ -234,9 +272,9 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
|
|
|
234
272
|
private _wsEndpoint;
|
|
235
273
|
private _rooms;
|
|
236
274
|
constructor(options: PluvClientOptions<TIO>);
|
|
237
|
-
createRoom: <TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
275
|
+
createRoom: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}>(room: string, options: PluvRoomOptions<TIO, TPresence, TStorage>) => PluvRoom<TIO, TPresence, TStorage>;
|
|
238
276
|
enter: (room: string | PluvRoom<TIO, any, any>) => Promise<PluvRoom<TIO, JsonObject, any>>;
|
|
239
|
-
getRoom: <TPresence extends JsonObject = {}, TStorage extends Record<string,
|
|
277
|
+
getRoom: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractCrdtType<any, any>> = {}>(room: string) => PluvRoom<TIO, TPresence, TStorage> | null;
|
|
240
278
|
getRooms: () => readonly PluvRoom<TIO, JsonObject, any>[];
|
|
241
279
|
leave: (room: string | PluvRoom<TIO, any, any>) => Promise<void>;
|
|
242
280
|
private _logDebug;
|
|
@@ -244,54 +282,4 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
|
|
|
244
282
|
|
|
245
283
|
declare const createClient: <TIO extends IOLike<_pluv_types.IOAuthorize<any, any>, {}, {}, {}, {}> = IOLike<_pluv_types.IOAuthorize<any, any>, {}, {}, {}, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
|
|
246
284
|
|
|
247
|
-
type MockedRoomEvents
|
|
248
|
-
[P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>>;
|
|
249
|
-
}>;
|
|
250
|
-
type MockedRoomConfig<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> = {
|
|
251
|
-
events?: MockedRoomEvents<TIO>;
|
|
252
|
-
} & Omit<CrdtManagerOptions<TStorage>, "encodedState"> & UsersManagerConfig<TPresence>;
|
|
253
|
-
declare class MockedRoom<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
254
|
-
private _crdtManager;
|
|
255
|
-
private _crdtNotifier;
|
|
256
|
-
private _eventNotifier;
|
|
257
|
-
private _events?;
|
|
258
|
-
private _otherNotifier;
|
|
259
|
-
private _state;
|
|
260
|
-
private _stateNotifier;
|
|
261
|
-
private _subscriptions;
|
|
262
|
-
private _usersManager;
|
|
263
|
-
constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TStorage>);
|
|
264
|
-
broadcast<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>): void;
|
|
265
|
-
canRedo: () => boolean;
|
|
266
|
-
canUndo: () => boolean;
|
|
267
|
-
event: <TEvent extends keyof InferIOOutput<TIO>>(event: TEvent, callback: EventNotifierSubscriptionCallback<TIO, TEvent>) => (() => void);
|
|
268
|
-
getConnection(): WebSocketConnection;
|
|
269
|
-
getDoc(): Doc;
|
|
270
|
-
getMyPresence: () => TPresence;
|
|
271
|
-
getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
|
|
272
|
-
getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
|
|
273
|
-
getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
|
|
274
|
-
getStorage: <TKey extends keyof TStorage>(key: TKey) => TStorage[TKey];
|
|
275
|
-
other: (connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO>) => (() => void);
|
|
276
|
-
redo: () => void;
|
|
277
|
-
storage: <TKey extends keyof TStorage>(key: TKey, fn: (value: InferYjsSharedTypeJson<TStorage[TKey]>) => void) => (() => void);
|
|
278
|
-
storageRoot: (fn: (value: { [P in keyof TStorage]: InferYjsSharedTypeJson<TStorage[P]>; }) => void) => (() => void);
|
|
279
|
-
subscribe: <TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => (() => void);
|
|
280
|
-
transact: (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
281
|
-
undo: () => void;
|
|
282
|
-
updateMyPresence: (presence: Partial<TPresence>) => void;
|
|
283
|
-
private _observeCrdt;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
declare const y_array: typeof array;
|
|
287
|
-
declare const y_map: typeof map;
|
|
288
|
-
declare const y_object: typeof object;
|
|
289
|
-
declare const y_text: typeof text;
|
|
290
|
-
declare const y_xmlElement: typeof xmlElement;
|
|
291
|
-
declare const y_xmlFragment: typeof xmlFragment;
|
|
292
|
-
declare const y_xmlText: typeof xmlText;
|
|
293
|
-
declare namespace y {
|
|
294
|
-
export { y_array as array, y_map as map, y_object as object, y_text as text, y_xmlElement as xmlElement, y_xmlFragment as xmlFragment, y_xmlText as xmlText };
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, y };
|
|
285
|
+
export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient };
|