tinybase 5.0.0-beta.27 → 5.0.0-beta.28
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/@types/_internal/ui-react/with-schemas/index.d.cts +274 -0
- package/@types/_internal/ui-react/with-schemas/index.d.ts +274 -0
- package/@types/checkpoints/index.d.cts +30 -1
- package/@types/checkpoints/index.d.ts +30 -1
- package/@types/checkpoints/with-schemas/index.d.cts +30 -1
- package/@types/checkpoints/with-schemas/index.d.ts +30 -1
- package/@types/common/index.d.cts +9 -0
- package/@types/common/index.d.ts +9 -0
- package/@types/common/with-schemas/index.d.cts +9 -0
- package/@types/common/with-schemas/index.d.ts +9 -0
- package/@types/index.d.cts +1 -0
- package/@types/index.d.ts +1 -0
- package/@types/indexes/index.d.cts +32 -1
- package/@types/indexes/index.d.ts +32 -1
- package/@types/indexes/with-schemas/index.d.cts +32 -1
- package/@types/indexes/with-schemas/index.d.ts +32 -1
- package/@types/mergeable-store/index.d.cts +0 -2
- package/@types/mergeable-store/index.d.ts +0 -2
- package/@types/mergeable-store/with-schemas/index.d.cts +2 -2
- package/@types/mergeable-store/with-schemas/index.d.ts +2 -2
- package/@types/metrics/index.d.cts +30 -4
- package/@types/metrics/index.d.ts +30 -4
- package/@types/metrics/with-schemas/index.d.cts +30 -4
- package/@types/metrics/with-schemas/index.d.ts +30 -4
- package/@types/persisters/index.d.cts +87 -25
- package/@types/persisters/index.d.ts +87 -25
- package/@types/persisters/persister-automerge/index.d.cts +4 -4
- package/@types/persisters/persister-automerge/index.d.ts +4 -4
- package/@types/persisters/persister-automerge/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-automerge/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-browser/index.d.cts +7 -4
- package/@types/persisters/persister-browser/index.d.ts +7 -4
- package/@types/persisters/persister-browser/with-schemas/index.d.cts +7 -4
- package/@types/persisters/persister-browser/with-schemas/index.d.ts +7 -4
- package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +4 -4
- package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +4 -4
- package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-electric-sql/index.d.cts +4 -4
- package/@types/persisters/persister-electric-sql/index.d.ts +4 -4
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-expo-sqlite/index.d.cts +4 -4
- package/@types/persisters/persister-expo-sqlite/index.d.ts +4 -4
- package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-file/index.d.cts +6 -4
- package/@types/persisters/persister-file/index.d.ts +6 -4
- package/@types/persisters/persister-file/with-schemas/index.d.cts +6 -4
- package/@types/persisters/persister-file/with-schemas/index.d.ts +6 -4
- package/@types/persisters/persister-indexed-db/index.d.cts +5 -4
- package/@types/persisters/persister-indexed-db/index.d.ts +5 -4
- package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +5 -4
- package/@types/persisters/persister-indexed-db/with-schemas/index.d.ts +5 -4
- package/@types/persisters/persister-libsql/index.d.cts +5 -4
- package/@types/persisters/persister-libsql/index.d.ts +5 -4
- package/@types/persisters/persister-libsql/with-schemas/index.d.cts +5 -4
- package/@types/persisters/persister-libsql/with-schemas/index.d.ts +5 -4
- package/@types/persisters/persister-partykit-client/index.d.cts +12 -6
- package/@types/persisters/persister-partykit-client/index.d.ts +12 -6
- package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +12 -6
- package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +12 -6
- package/@types/persisters/persister-partykit-server/index.d.cts +11 -3
- package/@types/persisters/persister-partykit-server/index.d.ts +11 -3
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +11 -3
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +11 -3
- package/@types/persisters/persister-powersync/index.d.cts +5 -4
- package/@types/persisters/persister-powersync/index.d.ts +5 -4
- package/@types/persisters/persister-powersync/with-schemas/index.d.cts +5 -4
- package/@types/persisters/persister-powersync/with-schemas/index.d.ts +5 -4
- package/@types/persisters/persister-remote/index.d.cts +6 -4
- package/@types/persisters/persister-remote/index.d.ts +6 -4
- package/@types/persisters/persister-remote/with-schemas/index.d.cts +6 -4
- package/@types/persisters/persister-remote/with-schemas/index.d.ts +6 -4
- package/@types/persisters/persister-sqlite-wasm/index.d.cts +4 -4
- package/@types/persisters/persister-sqlite-wasm/index.d.ts +4 -4
- package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-sqlite3/index.d.cts +4 -4
- package/@types/persisters/persister-sqlite3/index.d.ts +4 -4
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-yjs/index.d.cts +4 -4
- package/@types/persisters/persister-yjs/index.d.ts +4 -4
- package/@types/persisters/persister-yjs/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-yjs/with-schemas/index.d.ts +4 -4
- package/@types/persisters/with-schemas/index.d.cts +87 -25
- package/@types/persisters/with-schemas/index.d.ts +87 -25
- package/@types/queries/index.d.cts +64 -4
- package/@types/queries/index.d.ts +64 -4
- package/@types/queries/with-schemas/index.d.cts +64 -4
- package/@types/queries/with-schemas/index.d.ts +64 -4
- package/@types/relationships/index.d.cts +34 -1
- package/@types/relationships/index.d.ts +34 -1
- package/@types/relationships/with-schemas/index.d.cts +34 -1
- package/@types/relationships/with-schemas/index.d.ts +34 -1
- package/@types/store/index.d.cts +125 -0
- package/@types/store/index.d.ts +125 -0
- package/@types/store/with-schemas/index.d.cts +125 -0
- package/@types/store/with-schemas/index.d.ts +125 -0
- package/@types/synchronizers/index.d.cts +32 -10
- package/@types/synchronizers/index.d.ts +32 -10
- package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +114 -0
- package/@types/synchronizers/synchronizer-broadcast-channel/index.d.ts +114 -0
- package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +128 -0
- package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.ts +128 -0
- package/@types/synchronizers/synchronizer-local/index.d.cts +16 -17
- package/@types/synchronizers/synchronizer-local/index.d.ts +16 -17
- package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +16 -17
- package/@types/synchronizers/synchronizer-local/with-schemas/index.d.ts +16 -17
- package/@types/synchronizers/synchronizer-ws-client/index.d.cts +66 -6
- package/@types/synchronizers/synchronizer-ws-client/index.d.ts +66 -6
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +77 -6
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +77 -6
- package/@types/synchronizers/synchronizer-ws-server/index.d.cts +486 -7
- package/@types/synchronizers/synchronizer-ws-server/index.d.ts +486 -7
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +486 -7
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +486 -7
- package/@types/synchronizers/with-schemas/index.d.cts +29 -11
- package/@types/synchronizers/with-schemas/index.d.ts +29 -11
- package/@types/tools/index.d.cts +22 -0
- package/@types/tools/index.d.ts +22 -0
- package/@types/tools/with-schemas/index.d.cts +22 -0
- package/@types/tools/with-schemas/index.d.ts +22 -0
- package/@types/ui-react/index.d.cts +375 -1
- package/@types/ui-react/index.d.ts +375 -1
- package/@types/ui-react/with-schemas/index.d.cts +100 -1
- package/@types/ui-react/with-schemas/index.d.ts +100 -1
- package/@types/ui-react-dom/index.d.cts +112 -0
- package/@types/ui-react-dom/index.d.ts +112 -0
- package/@types/ui-react-dom/with-schemas/index.d.cts +112 -0
- package/@types/ui-react-dom/with-schemas/index.d.ts +112 -0
- package/@types/ui-react-inspector/index.d.cts +6 -2
- package/@types/ui-react-inspector/index.d.ts +6 -2
- package/@types/ui-react-inspector/with-schemas/index.d.cts +118 -2
- package/@types/ui-react-inspector/with-schemas/index.d.ts +118 -2
- package/@types/with-schemas/index.d.cts +1 -0
- package/@types/with-schemas/index.d.ts +1 -0
- package/cjs/es6/index.cjs +2 -2
- package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/index.cjs +1 -0
- package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/index.cjs.gz +0 -0
- package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +1 -0
- package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
- package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
- package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/synchronizers/index.cjs +2 -2
- package/cjs/es6/synchronizers/synchronizer-broadcast-channel/index.cjs +628 -0
- package/cjs/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +628 -0
- package/cjs/es6/synchronizers/synchronizer-local/index.cjs +4 -4
- package/cjs/es6/synchronizers/synchronizer-local/with-schemas/index.cjs +4 -4
- package/cjs/es6/synchronizers/synchronizer-ws-client/index.cjs +15 -21
- package/cjs/es6/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +15 -21
- package/cjs/es6/synchronizers/with-schemas/index.cjs +2 -2
- package/cjs/es6/with-schemas/index.cjs +2 -2
- package/cjs/index.cjs +2 -2
- package/cjs/min/synchronizers/synchronizer-broadcast-channel/index.cjs +1 -0
- package/cjs/min/synchronizers/synchronizer-broadcast-channel/index.cjs.gz +0 -0
- package/cjs/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +1 -0
- package/cjs/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs.gz +0 -0
- package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
- package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
- package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
- package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
- package/cjs/synchronizers/index.cjs +2 -2
- package/cjs/synchronizers/synchronizer-broadcast-channel/index.cjs +500 -0
- package/cjs/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +500 -0
- package/cjs/synchronizers/synchronizer-local/index.cjs +4 -4
- package/cjs/synchronizers/synchronizer-local/with-schemas/index.cjs +4 -4
- package/cjs/synchronizers/synchronizer-ws-client/index.cjs +15 -21
- package/cjs/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +15 -21
- package/cjs/synchronizers/with-schemas/index.cjs +2 -2
- package/cjs/with-schemas/index.cjs +2 -2
- package/es6/index.js +2 -2
- package/es6/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
- package/es6/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
- package/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/es6/synchronizers/index.js +2 -2
- package/es6/synchronizers/synchronizer-broadcast-channel/index.js +626 -0
- package/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +626 -0
- package/es6/synchronizers/synchronizer-local/index.js +4 -4
- package/es6/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
- package/es6/synchronizers/synchronizer-ws-client/index.js +15 -21
- package/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
- package/es6/synchronizers/with-schemas/index.js +2 -2
- package/es6/with-schemas/index.js +2 -2
- package/index.js +2 -2
- package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
- package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/package.json +105 -1
- package/readme.md +9 -9
- package/releases.md +4 -4
- package/synchronizers/index.js +2 -2
- package/synchronizers/synchronizer-broadcast-channel/index.js +498 -0
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +498 -0
- package/synchronizers/synchronizer-local/index.js +4 -4
- package/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
- package/synchronizers/synchronizer-ws-client/index.js +15 -21
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
- package/synchronizers/with-schemas/index.js +2 -2
- package/umd/es6/index.js +2 -2
- package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
- package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
- package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/umd/es6/synchronizers/index.js +2 -2
- package/umd/es6/synchronizers/synchronizer-broadcast-channel/index.js +654 -0
- package/umd/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +654 -0
- package/umd/es6/synchronizers/synchronizer-local/index.js +4 -4
- package/umd/es6/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
- package/umd/es6/synchronizers/synchronizer-ws-client/index.js +15 -21
- package/umd/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
- package/umd/es6/synchronizers/with-schemas/index.js +2 -2
- package/umd/es6/with-schemas/index.js +2 -2
- package/umd/index.js +2 -2
- package/umd/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
- package/umd/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/umd/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
- package/umd/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/umd/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/umd/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/umd/synchronizers/index.js +2 -2
- package/umd/synchronizers/synchronizer-broadcast-channel/index.js +516 -0
- package/umd/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +516 -0
- package/umd/synchronizers/synchronizer-local/index.js +4 -4
- package/umd/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
- package/umd/synchronizers/synchronizer-ws-client/index.js +15 -21
- package/umd/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
- package/umd/synchronizers/with-schemas/index.js +2 -2
- package/umd/with-schemas/index.js +2 -2
- package/with-schemas/index.js +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws module of the TinyBase project lets you synchronize
|
|
3
3
|
* MergeableStore data to and from other MergeableStore instances via WebSockets
|
|
4
4
|
* facilitated by a server.
|
|
5
|
-
* @see
|
|
5
|
+
* @see Synchronization guide
|
|
6
6
|
* @see Todo App v6 (collaboration) demo
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
* @module synchronizer-ws-client
|
|
@@ -21,6 +21,8 @@ import type {WebSocket as WsWebSocket} from 'ws';
|
|
|
21
21
|
* This includes the browser-native WebSocket type, as well as the WebSocket
|
|
22
22
|
* type from the well-known `ws` package (such that the Synchronizer can be used
|
|
23
23
|
* in a server environment).
|
|
24
|
+
* @category Creation
|
|
25
|
+
* @since v5.0.0
|
|
24
26
|
*/
|
|
25
27
|
export type WebSocketTypes = WebSocket | WsWebSocket;
|
|
26
28
|
|
|
@@ -29,12 +31,12 @@ export type WebSocketTypes = WebSocket | WsWebSocket;
|
|
|
29
31
|
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
30
32
|
* via WebSockets facilitated by a server.
|
|
31
33
|
*
|
|
34
|
+
* You should use the createWsSynchronizer function to create a WsSynchronizer
|
|
35
|
+
* object.
|
|
36
|
+
*
|
|
32
37
|
* It is a minor extension to the Synchronizer interface and simply provides an
|
|
33
38
|
* extra getWebSocket method for accessing a reference to the WebSocket being
|
|
34
39
|
* used.
|
|
35
|
-
*
|
|
36
|
-
* You should use the createWsSynchronizer function to create a WsSynchronizer
|
|
37
|
-
* object.
|
|
38
40
|
* @category Synchronizer
|
|
39
41
|
* @since v5.0.0
|
|
40
42
|
*/
|
|
@@ -43,7 +45,7 @@ export interface WsSynchronizer<
|
|
|
43
45
|
WebSocketType extends WebSocketTypes,
|
|
44
46
|
> extends Synchronizer<Schemas> {
|
|
45
47
|
/**
|
|
46
|
-
* The getWebSocket method returns reference to the WebSocket being used for
|
|
48
|
+
* The getWebSocket method returns a reference to the WebSocket being used for
|
|
47
49
|
* synchronization.
|
|
48
50
|
* @returns The WebSocket reference.
|
|
49
51
|
* @example
|
|
@@ -75,8 +77,77 @@ export interface WsSynchronizer<
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/**
|
|
78
|
-
* The createWsSynchronizer function
|
|
80
|
+
* The createWsSynchronizer function creates a WsSynchronizer object that can
|
|
81
|
+
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
82
|
+
* via WebSockets facilitated by a WsServer.
|
|
83
|
+
*
|
|
84
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
85
|
+
*
|
|
86
|
+
* ```ts override
|
|
87
|
+
* createWsSynchronizer<WebSocketType extends WebSocketTypes>(
|
|
88
|
+
* store: MergeableStore,
|
|
89
|
+
* webSocket: WebSocketType,
|
|
90
|
+
* requestTimeoutSeconds?: number,
|
|
91
|
+
* onIgnoredError?: (error: any) => void,
|
|
92
|
+
* ): Promise<WsSynchronizer<WebSocketType>>;
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* As well as providing a reference to the MergeableStore to persist, you must
|
|
96
|
+
* provide a configured WebSocket to send synchronization messages over.
|
|
97
|
+
*
|
|
98
|
+
* This method is asynchronous because it will await the websocket's connection
|
|
99
|
+
* to the server. You will need to `await` a call to this function or handle the
|
|
100
|
+
* return type natively as a Promise.
|
|
101
|
+
* @param store The MergeableStore to synchronize.
|
|
102
|
+
* @param webSocket The WebSocket to send synchronization messages over.
|
|
103
|
+
* @param requestTimeoutSeconds An optional time in seconds that the
|
|
104
|
+
* Synchronizer will wait for responses to request messages, defaulting to 1.
|
|
105
|
+
* @param onIgnoredError An optional handler for the errors that the
|
|
106
|
+
* Synchronizer would otherwise ignore when trying to synchronize data. This is
|
|
107
|
+
* suitable for debugging synchronization issues in a development environment.
|
|
108
|
+
* @returns A reference to the new WsSynchronizer object.
|
|
109
|
+
* @example
|
|
110
|
+
* This example creates two WsSynchronizer objects to synchronize one
|
|
111
|
+
* MergeableStore to another via a server.
|
|
112
|
+
*
|
|
113
|
+
* ```js
|
|
114
|
+
* import {WebSocket, WebSocketServer} from 'ws';
|
|
115
|
+
* import {createMergeableStore} from 'tinybase';
|
|
116
|
+
* import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
|
|
117
|
+
* import {createWsSynchronizer} from 'tinybase/synchronizers/synchronizer-ws-client';
|
|
118
|
+
*
|
|
119
|
+
* const server = createWsServer(new WebSocketServer({port: 8047}));
|
|
120
|
+
*
|
|
121
|
+
* const store1 = createMergeableStore();
|
|
122
|
+
* const store2 = createMergeableStore();
|
|
123
|
+
*
|
|
124
|
+
* const synchronizer1 = await createWsSynchronizer(
|
|
125
|
+
* store1,
|
|
126
|
+
* new WebSocket('ws://localhost:8047'),
|
|
127
|
+
* );
|
|
128
|
+
* const synchronizer2 = await createWsSynchronizer(
|
|
129
|
+
* store2,
|
|
130
|
+
* new WebSocket('ws://localhost:8047'),
|
|
131
|
+
* );
|
|
132
|
+
*
|
|
133
|
+
* await synchronizer1.startSync();
|
|
134
|
+
* await synchronizer2.startSync();
|
|
135
|
+
*
|
|
136
|
+
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
137
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
138
|
+
*
|
|
139
|
+
* // ...
|
|
140
|
+
* console.log(store1.getTables());
|
|
141
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
142
|
+
* console.log(store2.getTables());
|
|
143
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
144
|
+
*
|
|
145
|
+
* synchronizer1.destroy();
|
|
146
|
+
* synchronizer2.destroy();
|
|
147
|
+
* server.destroy();
|
|
148
|
+
* ```
|
|
79
149
|
* @category Creation
|
|
150
|
+
* @since v5.0.0
|
|
80
151
|
*/
|
|
81
152
|
export function createWsSynchronizer<
|
|
82
153
|
Schemas extends OptionalSchemas,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws module of the TinyBase project lets you synchronize
|
|
3
3
|
* MergeableStore data to and from other MergeableStore instances via WebSockets
|
|
4
4
|
* facilitated by a server.
|
|
5
|
-
* @see
|
|
5
|
+
* @see Synchronization guide
|
|
6
6
|
* @see Todo App v6 (collaboration) demo
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
* @module synchronizer-ws-client
|
|
@@ -21,6 +21,8 @@ import type {WebSocket as WsWebSocket} from 'ws';
|
|
|
21
21
|
* This includes the browser-native WebSocket type, as well as the WebSocket
|
|
22
22
|
* type from the well-known `ws` package (such that the Synchronizer can be used
|
|
23
23
|
* in a server environment).
|
|
24
|
+
* @category Creation
|
|
25
|
+
* @since v5.0.0
|
|
24
26
|
*/
|
|
25
27
|
export type WebSocketTypes = WebSocket | WsWebSocket;
|
|
26
28
|
|
|
@@ -29,12 +31,12 @@ export type WebSocketTypes = WebSocket | WsWebSocket;
|
|
|
29
31
|
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
30
32
|
* via WebSockets facilitated by a server.
|
|
31
33
|
*
|
|
34
|
+
* You should use the createWsSynchronizer function to create a WsSynchronizer
|
|
35
|
+
* object.
|
|
36
|
+
*
|
|
32
37
|
* It is a minor extension to the Synchronizer interface and simply provides an
|
|
33
38
|
* extra getWebSocket method for accessing a reference to the WebSocket being
|
|
34
39
|
* used.
|
|
35
|
-
*
|
|
36
|
-
* You should use the createWsSynchronizer function to create a WsSynchronizer
|
|
37
|
-
* object.
|
|
38
40
|
* @category Synchronizer
|
|
39
41
|
* @since v5.0.0
|
|
40
42
|
*/
|
|
@@ -43,7 +45,7 @@ export interface WsSynchronizer<
|
|
|
43
45
|
WebSocketType extends WebSocketTypes,
|
|
44
46
|
> extends Synchronizer<Schemas> {
|
|
45
47
|
/**
|
|
46
|
-
* The getWebSocket method returns reference to the WebSocket being used for
|
|
48
|
+
* The getWebSocket method returns a reference to the WebSocket being used for
|
|
47
49
|
* synchronization.
|
|
48
50
|
* @returns The WebSocket reference.
|
|
49
51
|
* @example
|
|
@@ -75,8 +77,77 @@ export interface WsSynchronizer<
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/**
|
|
78
|
-
* The createWsSynchronizer function
|
|
80
|
+
* The createWsSynchronizer function creates a WsSynchronizer object that can
|
|
81
|
+
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
82
|
+
* via WebSockets facilitated by a WsServer.
|
|
83
|
+
*
|
|
84
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
85
|
+
*
|
|
86
|
+
* ```ts override
|
|
87
|
+
* createWsSynchronizer<WebSocketType extends WebSocketTypes>(
|
|
88
|
+
* store: MergeableStore,
|
|
89
|
+
* webSocket: WebSocketType,
|
|
90
|
+
* requestTimeoutSeconds?: number,
|
|
91
|
+
* onIgnoredError?: (error: any) => void,
|
|
92
|
+
* ): Promise<WsSynchronizer<WebSocketType>>;
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* As well as providing a reference to the MergeableStore to persist, you must
|
|
96
|
+
* provide a configured WebSocket to send synchronization messages over.
|
|
97
|
+
*
|
|
98
|
+
* This method is asynchronous because it will await the websocket's connection
|
|
99
|
+
* to the server. You will need to `await` a call to this function or handle the
|
|
100
|
+
* return type natively as a Promise.
|
|
101
|
+
* @param store The MergeableStore to synchronize.
|
|
102
|
+
* @param webSocket The WebSocket to send synchronization messages over.
|
|
103
|
+
* @param requestTimeoutSeconds An optional time in seconds that the
|
|
104
|
+
* Synchronizer will wait for responses to request messages, defaulting to 1.
|
|
105
|
+
* @param onIgnoredError An optional handler for the errors that the
|
|
106
|
+
* Synchronizer would otherwise ignore when trying to synchronize data. This is
|
|
107
|
+
* suitable for debugging synchronization issues in a development environment.
|
|
108
|
+
* @returns A reference to the new WsSynchronizer object.
|
|
109
|
+
* @example
|
|
110
|
+
* This example creates two WsSynchronizer objects to synchronize one
|
|
111
|
+
* MergeableStore to another via a server.
|
|
112
|
+
*
|
|
113
|
+
* ```js
|
|
114
|
+
* import {WebSocket, WebSocketServer} from 'ws';
|
|
115
|
+
* import {createMergeableStore} from 'tinybase';
|
|
116
|
+
* import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
|
|
117
|
+
* import {createWsSynchronizer} from 'tinybase/synchronizers/synchronizer-ws-client';
|
|
118
|
+
*
|
|
119
|
+
* const server = createWsServer(new WebSocketServer({port: 8047}));
|
|
120
|
+
*
|
|
121
|
+
* const store1 = createMergeableStore();
|
|
122
|
+
* const store2 = createMergeableStore();
|
|
123
|
+
*
|
|
124
|
+
* const synchronizer1 = await createWsSynchronizer(
|
|
125
|
+
* store1,
|
|
126
|
+
* new WebSocket('ws://localhost:8047'),
|
|
127
|
+
* );
|
|
128
|
+
* const synchronizer2 = await createWsSynchronizer(
|
|
129
|
+
* store2,
|
|
130
|
+
* new WebSocket('ws://localhost:8047'),
|
|
131
|
+
* );
|
|
132
|
+
*
|
|
133
|
+
* await synchronizer1.startSync();
|
|
134
|
+
* await synchronizer2.startSync();
|
|
135
|
+
*
|
|
136
|
+
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
137
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
138
|
+
*
|
|
139
|
+
* // ...
|
|
140
|
+
* console.log(store1.getTables());
|
|
141
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
142
|
+
* console.log(store2.getTables());
|
|
143
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
144
|
+
*
|
|
145
|
+
* synchronizer1.destroy();
|
|
146
|
+
* synchronizer2.destroy();
|
|
147
|
+
* server.destroy();
|
|
148
|
+
* ```
|
|
79
149
|
* @category Creation
|
|
150
|
+
* @since v5.0.0
|
|
80
151
|
*/
|
|
81
152
|
export function createWsSynchronizer<
|
|
82
153
|
Schemas extends OptionalSchemas,
|