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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The synchronizers module of the TinyBase project lets you synchronize
|
|
3
3
|
* MergeableStore data to and from other MergeableStore instances.
|
|
4
|
-
* @see
|
|
4
|
+
* @see Synchronization guide
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
* @module synchronizers
|
|
7
7
|
* @since v5.0.0
|
|
@@ -27,35 +27,51 @@ import type {MergeableStore} from '../mergeable-store/index.d.cts';
|
|
|
27
27
|
export const enum Message {
|
|
28
28
|
/**
|
|
29
29
|
* A message that is a response to a previous request.
|
|
30
|
+
* @category Enum
|
|
31
|
+
* @since v5.0.0
|
|
30
32
|
*/
|
|
31
33
|
Response = 0,
|
|
32
34
|
/**
|
|
33
35
|
* A message that is a request to get ContentHashes from another
|
|
34
36
|
* MergeableStore.
|
|
37
|
+
* @category Enum
|
|
38
|
+
* @since v5.0.0
|
|
35
39
|
*/
|
|
36
40
|
GetContentHashes = 1,
|
|
37
41
|
/**
|
|
38
42
|
* A message that contains ContentHashes.
|
|
43
|
+
* @category Enum
|
|
44
|
+
* @since v5.0.0
|
|
39
45
|
*/
|
|
40
46
|
ContentHashes = 2,
|
|
41
47
|
/**
|
|
42
48
|
* A message that contains a ContentDiff.
|
|
49
|
+
* @category Enum
|
|
50
|
+
* @since v5.0.0
|
|
43
51
|
*/
|
|
44
52
|
ContentDiff = 3,
|
|
45
53
|
/**
|
|
46
54
|
* A message that is a request to get a TableDiff from another MergeableStore.
|
|
55
|
+
* @category Enum
|
|
56
|
+
* @since v5.0.0
|
|
47
57
|
*/
|
|
48
58
|
GetTableDiff = 4,
|
|
49
59
|
/**
|
|
50
60
|
* A message that is a request to get a RowDiff from another MergeableStore.
|
|
61
|
+
* @category Enum
|
|
62
|
+
* @since v5.0.0
|
|
51
63
|
*/
|
|
52
64
|
GetRowDiff = 5,
|
|
53
65
|
/**
|
|
54
66
|
* A message that is a request to get a CellDiff from another MergeableStore.
|
|
67
|
+
* @category Enum
|
|
68
|
+
* @since v5.0.0
|
|
55
69
|
*/
|
|
56
70
|
GetCellDiff = 6,
|
|
57
71
|
/**
|
|
58
72
|
* A message that is a request to get a ValueDiff from another MergeableStore.
|
|
73
|
+
* @category Enum
|
|
74
|
+
* @since v5.0.0
|
|
59
75
|
*/
|
|
60
76
|
GetValueDiff = 7,
|
|
61
77
|
}
|
|
@@ -118,16 +134,20 @@ export type Send = (
|
|
|
118
134
|
export type SynchronizerStats = {
|
|
119
135
|
/**
|
|
120
136
|
* The number of times messages have been sent.
|
|
137
|
+
* @category Stat
|
|
138
|
+
* @since v5.0.0
|
|
121
139
|
*/
|
|
122
140
|
sends: number;
|
|
123
141
|
/**
|
|
124
142
|
* The number of times messages has been received.
|
|
143
|
+
* @category Stat
|
|
144
|
+
* @since v5.0.0
|
|
125
145
|
*/
|
|
126
146
|
receives: number;
|
|
127
147
|
};
|
|
128
148
|
|
|
129
149
|
/**
|
|
130
|
-
*
|
|
150
|
+
* A Synchronizer object lets you synchronize MergeableStore data with another
|
|
131
151
|
* TinyBase client or system.
|
|
132
152
|
*
|
|
133
153
|
* This is useful for sharing data between users, or between devices of a single
|
|
@@ -369,9 +389,9 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
369
389
|
* medium of communication used.
|
|
370
390
|
* @param store The MergeableStore to synchronize.
|
|
371
391
|
* @param send A Send function for sending a message.
|
|
372
|
-
* @param
|
|
373
|
-
* that is passed a Receive function that you need to ensure
|
|
374
|
-
* messages.
|
|
392
|
+
* @param registerReceive A callback (called once when the Synchronizer is
|
|
393
|
+
* created) that is passed a Receive function that you need to ensure will
|
|
394
|
+
* receive messages addressed or broadcast to this client.
|
|
375
395
|
* @param destroy A function called when destroying the Persister which can be
|
|
376
396
|
* used to clean up underlying resources.
|
|
377
397
|
* @param requestTimeoutSeconds An number of seconds before a request sent from
|
|
@@ -407,7 +427,7 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
407
427
|
* remoteBus.push([clientId, requestId, message, body]);
|
|
408
428
|
* },
|
|
409
429
|
* (receive) => {
|
|
410
|
-
* //
|
|
430
|
+
* // registerReceive
|
|
411
431
|
* timer = setInterval(() => {
|
|
412
432
|
* if (localBus.length > 0) {
|
|
413
433
|
* receive(...localBus.shift());
|
|
@@ -429,11 +449,13 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
429
449
|
* await synchronizer2.startSync();
|
|
430
450
|
*
|
|
431
451
|
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
452
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
453
|
+
*
|
|
432
454
|
* // ...
|
|
433
455
|
* console.log(store1.getTables());
|
|
434
|
-
* // -> {pets: {fido: {species: 'dog'}}}
|
|
456
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
435
457
|
* console.log(store2.getTables());
|
|
436
|
-
* // -> {pets: {fido: {species: 'dog'}}}
|
|
458
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
437
459
|
*
|
|
438
460
|
* synchronizer1.destroy();
|
|
439
461
|
* synchronizer2.destroy();
|
|
@@ -444,7 +466,7 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
444
466
|
export function createCustomSynchronizer(
|
|
445
467
|
store: MergeableStore,
|
|
446
468
|
send: Send,
|
|
447
|
-
|
|
469
|
+
registerReceive: (receive: Receive) => void,
|
|
448
470
|
destroy: () => void,
|
|
449
471
|
requestTimeoutSeconds: number,
|
|
450
472
|
onIgnoredError?: (error: any) => void,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The synchronizers module of the TinyBase project lets you synchronize
|
|
3
3
|
* MergeableStore data to and from other MergeableStore instances.
|
|
4
|
-
* @see
|
|
4
|
+
* @see Synchronization guide
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
* @module synchronizers
|
|
7
7
|
* @since v5.0.0
|
|
@@ -27,35 +27,51 @@ import type {MergeableStore} from '../mergeable-store/index.d.ts';
|
|
|
27
27
|
export const enum Message {
|
|
28
28
|
/**
|
|
29
29
|
* A message that is a response to a previous request.
|
|
30
|
+
* @category Enum
|
|
31
|
+
* @since v5.0.0
|
|
30
32
|
*/
|
|
31
33
|
Response = 0,
|
|
32
34
|
/**
|
|
33
35
|
* A message that is a request to get ContentHashes from another
|
|
34
36
|
* MergeableStore.
|
|
37
|
+
* @category Enum
|
|
38
|
+
* @since v5.0.0
|
|
35
39
|
*/
|
|
36
40
|
GetContentHashes = 1,
|
|
37
41
|
/**
|
|
38
42
|
* A message that contains ContentHashes.
|
|
43
|
+
* @category Enum
|
|
44
|
+
* @since v5.0.0
|
|
39
45
|
*/
|
|
40
46
|
ContentHashes = 2,
|
|
41
47
|
/**
|
|
42
48
|
* A message that contains a ContentDiff.
|
|
49
|
+
* @category Enum
|
|
50
|
+
* @since v5.0.0
|
|
43
51
|
*/
|
|
44
52
|
ContentDiff = 3,
|
|
45
53
|
/**
|
|
46
54
|
* A message that is a request to get a TableDiff from another MergeableStore.
|
|
55
|
+
* @category Enum
|
|
56
|
+
* @since v5.0.0
|
|
47
57
|
*/
|
|
48
58
|
GetTableDiff = 4,
|
|
49
59
|
/**
|
|
50
60
|
* A message that is a request to get a RowDiff from another MergeableStore.
|
|
61
|
+
* @category Enum
|
|
62
|
+
* @since v5.0.0
|
|
51
63
|
*/
|
|
52
64
|
GetRowDiff = 5,
|
|
53
65
|
/**
|
|
54
66
|
* A message that is a request to get a CellDiff from another MergeableStore.
|
|
67
|
+
* @category Enum
|
|
68
|
+
* @since v5.0.0
|
|
55
69
|
*/
|
|
56
70
|
GetCellDiff = 6,
|
|
57
71
|
/**
|
|
58
72
|
* A message that is a request to get a ValueDiff from another MergeableStore.
|
|
73
|
+
* @category Enum
|
|
74
|
+
* @since v5.0.0
|
|
59
75
|
*/
|
|
60
76
|
GetValueDiff = 7,
|
|
61
77
|
}
|
|
@@ -118,16 +134,20 @@ export type Send = (
|
|
|
118
134
|
export type SynchronizerStats = {
|
|
119
135
|
/**
|
|
120
136
|
* The number of times messages have been sent.
|
|
137
|
+
* @category Stat
|
|
138
|
+
* @since v5.0.0
|
|
121
139
|
*/
|
|
122
140
|
sends: number;
|
|
123
141
|
/**
|
|
124
142
|
* The number of times messages has been received.
|
|
143
|
+
* @category Stat
|
|
144
|
+
* @since v5.0.0
|
|
125
145
|
*/
|
|
126
146
|
receives: number;
|
|
127
147
|
};
|
|
128
148
|
|
|
129
149
|
/**
|
|
130
|
-
*
|
|
150
|
+
* A Synchronizer object lets you synchronize MergeableStore data with another
|
|
131
151
|
* TinyBase client or system.
|
|
132
152
|
*
|
|
133
153
|
* This is useful for sharing data between users, or between devices of a single
|
|
@@ -369,9 +389,9 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
369
389
|
* medium of communication used.
|
|
370
390
|
* @param store The MergeableStore to synchronize.
|
|
371
391
|
* @param send A Send function for sending a message.
|
|
372
|
-
* @param
|
|
373
|
-
* that is passed a Receive function that you need to ensure
|
|
374
|
-
* messages.
|
|
392
|
+
* @param registerReceive A callback (called once when the Synchronizer is
|
|
393
|
+
* created) that is passed a Receive function that you need to ensure will
|
|
394
|
+
* receive messages addressed or broadcast to this client.
|
|
375
395
|
* @param destroy A function called when destroying the Persister which can be
|
|
376
396
|
* used to clean up underlying resources.
|
|
377
397
|
* @param requestTimeoutSeconds An number of seconds before a request sent from
|
|
@@ -407,7 +427,7 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
407
427
|
* remoteBus.push([clientId, requestId, message, body]);
|
|
408
428
|
* },
|
|
409
429
|
* (receive) => {
|
|
410
|
-
* //
|
|
430
|
+
* // registerReceive
|
|
411
431
|
* timer = setInterval(() => {
|
|
412
432
|
* if (localBus.length > 0) {
|
|
413
433
|
* receive(...localBus.shift());
|
|
@@ -429,11 +449,13 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
429
449
|
* await synchronizer2.startSync();
|
|
430
450
|
*
|
|
431
451
|
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
452
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
453
|
+
*
|
|
432
454
|
* // ...
|
|
433
455
|
* console.log(store1.getTables());
|
|
434
|
-
* // -> {pets: {fido: {species: 'dog'}}}
|
|
456
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
435
457
|
* console.log(store2.getTables());
|
|
436
|
-
* // -> {pets: {fido: {species: 'dog'}}}
|
|
458
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
437
459
|
*
|
|
438
460
|
* synchronizer1.destroy();
|
|
439
461
|
* synchronizer2.destroy();
|
|
@@ -444,7 +466,7 @@ export interface Synchronizer extends Persister<Persists.MergeableStoreOnly> {
|
|
|
444
466
|
export function createCustomSynchronizer(
|
|
445
467
|
store: MergeableStore,
|
|
446
468
|
send: Send,
|
|
447
|
-
|
|
469
|
+
registerReceive: (receive: Receive) => void,
|
|
448
470
|
destroy: () => void,
|
|
449
471
|
requestTimeoutSeconds: number,
|
|
450
472
|
onIgnoredError?: (error: any) => void,
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The synchronizer-broadcast-channel module of the TinyBase project lets you
|
|
3
|
+
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
4
|
+
* via a browser's BroadcastChannel API.
|
|
5
|
+
* @see Synchronization guide
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module synchronizer-broadcast-channel
|
|
8
|
+
* @since v5.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {MergeableStore} from '../../mergeable-store/index.d.cts';
|
|
12
|
+
import type {Synchronizer} from '../index.d.cts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The BroadcastChannelSynchronizer interface represents a Synchronizer that
|
|
16
|
+
* lets you synchronize MergeableStore data to and from other MergeableStore
|
|
17
|
+
* instances via a browser's BroadcastChannel API.
|
|
18
|
+
*
|
|
19
|
+
* You should use the createBroadcastChannelSynchronizer function to create a
|
|
20
|
+
* BroadcastChannelSynchronizer object.
|
|
21
|
+
*
|
|
22
|
+
* It is a minor extension to the Synchronizer interface and simply provides an
|
|
23
|
+
* extra getChannelName method for accessing the name of the channel being used.
|
|
24
|
+
* @category Synchronizer
|
|
25
|
+
* @since v5.0.0
|
|
26
|
+
*/
|
|
27
|
+
export interface BroadcastChannelSynchronizer extends Synchronizer {
|
|
28
|
+
/**
|
|
29
|
+
* The getChannelName method returns the name of the channel being used for
|
|
30
|
+
* synchronization.
|
|
31
|
+
* @returns The channel name.
|
|
32
|
+
* @example
|
|
33
|
+
* This example creates a BroadcastChannelSynchronizer object for a
|
|
34
|
+
* newly-created MergeableStore and then gets the channel name back out again.
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
38
|
+
* import {createMergeableStore} from 'tinybase';
|
|
39
|
+
*
|
|
40
|
+
* const store = createMergeableStore();
|
|
41
|
+
* const synchronizer = await createBroadcastChannelSynchronizer(
|
|
42
|
+
* store,
|
|
43
|
+
* 'channelA',
|
|
44
|
+
* );
|
|
45
|
+
*
|
|
46
|
+
* console.log(synchronizer.getChannelName());
|
|
47
|
+
* // -> 'channelA'
|
|
48
|
+
*
|
|
49
|
+
* synchronizer.destroy();
|
|
50
|
+
* ```
|
|
51
|
+
* @category Getter
|
|
52
|
+
* @since v5.0.0
|
|
53
|
+
*/
|
|
54
|
+
getChannelName(): string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The createBroadcastChannelSynchronizer function creates a
|
|
59
|
+
* BroadcastChannelSynchronizer object that can synchronize MergeableStore data
|
|
60
|
+
* to and from other MergeableStore instances via a browser's BroadcastChannel
|
|
61
|
+
* API.
|
|
62
|
+
*
|
|
63
|
+
* As well as providing a reference to the MergeableStore to persist, you must
|
|
64
|
+
* provide a channel name, used by all the browser tabs, workers, or contexts
|
|
65
|
+
* that need to synchronize together.
|
|
66
|
+
* @param store The MergeableStore to synchronize.
|
|
67
|
+
* @param channelName The name of the channel to use.
|
|
68
|
+
* @param onIgnoredError An optional handler for the errors that the
|
|
69
|
+
* Synchronizer would otherwise ignore when trying to synchronize data. This is
|
|
70
|
+
* suitable for debugging synchronization issues in a development environment.
|
|
71
|
+
* @returns A reference to the new BroadcastChannelSynchronizer object.
|
|
72
|
+
* @example
|
|
73
|
+
* This example creates two BroadcastChannelSynchronizer objects to synchronize
|
|
74
|
+
* one MergeableStore to another.
|
|
75
|
+
*
|
|
76
|
+
* ```js
|
|
77
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
78
|
+
* import {createMergeableStore} from 'tinybase';
|
|
79
|
+
*
|
|
80
|
+
* const store1 = createMergeableStore();
|
|
81
|
+
* const store2 = createMergeableStore();
|
|
82
|
+
*
|
|
83
|
+
* const synchronizer1 = createBroadcastChannelSynchronizer(
|
|
84
|
+
* store1,
|
|
85
|
+
* 'channelA',
|
|
86
|
+
* );
|
|
87
|
+
* const synchronizer2 = createBroadcastChannelSynchronizer(
|
|
88
|
+
* store2,
|
|
89
|
+
* 'channelA',
|
|
90
|
+
* );
|
|
91
|
+
*
|
|
92
|
+
* await synchronizer1.startSync();
|
|
93
|
+
* await synchronizer2.startSync();
|
|
94
|
+
*
|
|
95
|
+
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
96
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
97
|
+
*
|
|
98
|
+
* // ...
|
|
99
|
+
* console.log(store1.getTables());
|
|
100
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
101
|
+
* console.log(store2.getTables());
|
|
102
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
103
|
+
*
|
|
104
|
+
* synchronizer1.destroy();
|
|
105
|
+
* synchronizer2.destroy();
|
|
106
|
+
* ```
|
|
107
|
+
* @category Creation
|
|
108
|
+
* @since v5.0.0
|
|
109
|
+
*/
|
|
110
|
+
export function createBroadcastChannelSynchronizer(
|
|
111
|
+
store: MergeableStore,
|
|
112
|
+
channelName: string,
|
|
113
|
+
onIgnoredError?: (error: any) => void,
|
|
114
|
+
): BroadcastChannelSynchronizer;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The synchronizer-broadcast-channel module of the TinyBase project lets you
|
|
3
|
+
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
4
|
+
* via a browser's BroadcastChannel API.
|
|
5
|
+
* @see Synchronization guide
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module synchronizer-broadcast-channel
|
|
8
|
+
* @since v5.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {MergeableStore} from '../../mergeable-store/index.d.ts';
|
|
12
|
+
import type {Synchronizer} from '../index.d.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The BroadcastChannelSynchronizer interface represents a Synchronizer that
|
|
16
|
+
* lets you synchronize MergeableStore data to and from other MergeableStore
|
|
17
|
+
* instances via a browser's BroadcastChannel API.
|
|
18
|
+
*
|
|
19
|
+
* You should use the createBroadcastChannelSynchronizer function to create a
|
|
20
|
+
* BroadcastChannelSynchronizer object.
|
|
21
|
+
*
|
|
22
|
+
* It is a minor extension to the Synchronizer interface and simply provides an
|
|
23
|
+
* extra getChannelName method for accessing the name of the channel being used.
|
|
24
|
+
* @category Synchronizer
|
|
25
|
+
* @since v5.0.0
|
|
26
|
+
*/
|
|
27
|
+
export interface BroadcastChannelSynchronizer extends Synchronizer {
|
|
28
|
+
/**
|
|
29
|
+
* The getChannelName method returns the name of the channel being used for
|
|
30
|
+
* synchronization.
|
|
31
|
+
* @returns The channel name.
|
|
32
|
+
* @example
|
|
33
|
+
* This example creates a BroadcastChannelSynchronizer object for a
|
|
34
|
+
* newly-created MergeableStore and then gets the channel name back out again.
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
38
|
+
* import {createMergeableStore} from 'tinybase';
|
|
39
|
+
*
|
|
40
|
+
* const store = createMergeableStore();
|
|
41
|
+
* const synchronizer = await createBroadcastChannelSynchronizer(
|
|
42
|
+
* store,
|
|
43
|
+
* 'channelA',
|
|
44
|
+
* );
|
|
45
|
+
*
|
|
46
|
+
* console.log(synchronizer.getChannelName());
|
|
47
|
+
* // -> 'channelA'
|
|
48
|
+
*
|
|
49
|
+
* synchronizer.destroy();
|
|
50
|
+
* ```
|
|
51
|
+
* @category Getter
|
|
52
|
+
* @since v5.0.0
|
|
53
|
+
*/
|
|
54
|
+
getChannelName(): string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The createBroadcastChannelSynchronizer function creates a
|
|
59
|
+
* BroadcastChannelSynchronizer object that can synchronize MergeableStore data
|
|
60
|
+
* to and from other MergeableStore instances via a browser's BroadcastChannel
|
|
61
|
+
* API.
|
|
62
|
+
*
|
|
63
|
+
* As well as providing a reference to the MergeableStore to persist, you must
|
|
64
|
+
* provide a channel name, used by all the browser tabs, workers, or contexts
|
|
65
|
+
* that need to synchronize together.
|
|
66
|
+
* @param store The MergeableStore to synchronize.
|
|
67
|
+
* @param channelName The name of the channel to use.
|
|
68
|
+
* @param onIgnoredError An optional handler for the errors that the
|
|
69
|
+
* Synchronizer would otherwise ignore when trying to synchronize data. This is
|
|
70
|
+
* suitable for debugging synchronization issues in a development environment.
|
|
71
|
+
* @returns A reference to the new BroadcastChannelSynchronizer object.
|
|
72
|
+
* @example
|
|
73
|
+
* This example creates two BroadcastChannelSynchronizer objects to synchronize
|
|
74
|
+
* one MergeableStore to another.
|
|
75
|
+
*
|
|
76
|
+
* ```js
|
|
77
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
78
|
+
* import {createMergeableStore} from 'tinybase';
|
|
79
|
+
*
|
|
80
|
+
* const store1 = createMergeableStore();
|
|
81
|
+
* const store2 = createMergeableStore();
|
|
82
|
+
*
|
|
83
|
+
* const synchronizer1 = createBroadcastChannelSynchronizer(
|
|
84
|
+
* store1,
|
|
85
|
+
* 'channelA',
|
|
86
|
+
* );
|
|
87
|
+
* const synchronizer2 = createBroadcastChannelSynchronizer(
|
|
88
|
+
* store2,
|
|
89
|
+
* 'channelA',
|
|
90
|
+
* );
|
|
91
|
+
*
|
|
92
|
+
* await synchronizer1.startSync();
|
|
93
|
+
* await synchronizer2.startSync();
|
|
94
|
+
*
|
|
95
|
+
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
96
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
97
|
+
*
|
|
98
|
+
* // ...
|
|
99
|
+
* console.log(store1.getTables());
|
|
100
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
101
|
+
* console.log(store2.getTables());
|
|
102
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
103
|
+
*
|
|
104
|
+
* synchronizer1.destroy();
|
|
105
|
+
* synchronizer2.destroy();
|
|
106
|
+
* ```
|
|
107
|
+
* @category Creation
|
|
108
|
+
* @since v5.0.0
|
|
109
|
+
*/
|
|
110
|
+
export function createBroadcastChannelSynchronizer(
|
|
111
|
+
store: MergeableStore,
|
|
112
|
+
channelName: string,
|
|
113
|
+
onIgnoredError?: (error: any) => void,
|
|
114
|
+
): BroadcastChannelSynchronizer;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The synchronizer-broadcast-channel module of the TinyBase project lets you
|
|
3
|
+
* synchronize MergeableStore data to and from other MergeableStore instances
|
|
4
|
+
* via a browser's BroadcastChannel API.
|
|
5
|
+
* @see Synchronization guide
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module synchronizer-broadcast-channel
|
|
8
|
+
* @since v5.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.cts';
|
|
12
|
+
import type {OptionalSchemas} from '../../../store/with-schemas/index.d.cts';
|
|
13
|
+
import type {Synchronizer} from '../../with-schemas/index.d.cts';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The BroadcastChannelSynchronizer interface represents a Synchronizer that
|
|
17
|
+
* lets you synchronize MergeableStore data to and from other MergeableStore
|
|
18
|
+
* instances via a browser's BroadcastChannel API.
|
|
19
|
+
*
|
|
20
|
+
* You should use the createBroadcastChannelSynchronizer function to create a
|
|
21
|
+
* BroadcastChannelSynchronizer object.
|
|
22
|
+
*
|
|
23
|
+
* It is a minor extension to the Synchronizer interface and simply provides an
|
|
24
|
+
* extra getChannelName method for accessing the name of the channel being used.
|
|
25
|
+
* @category Synchronizer
|
|
26
|
+
* @since v5.0.0
|
|
27
|
+
*/
|
|
28
|
+
export interface BroadcastChannelSynchronizer<Schemas extends OptionalSchemas>
|
|
29
|
+
extends Synchronizer<Schemas> {
|
|
30
|
+
/**
|
|
31
|
+
* The getChannelName method returns the name of the channel being used for
|
|
32
|
+
* synchronization.
|
|
33
|
+
* @returns The channel name.
|
|
34
|
+
* @example
|
|
35
|
+
* This example creates a BroadcastChannelSynchronizer object for a
|
|
36
|
+
* newly-created MergeableStore and then gets the channel name back out again.
|
|
37
|
+
*
|
|
38
|
+
* ```js
|
|
39
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
40
|
+
* import {createMergeableStore} from 'tinybase';
|
|
41
|
+
*
|
|
42
|
+
* const store = createMergeableStore();
|
|
43
|
+
* const synchronizer = await createBroadcastChannelSynchronizer(
|
|
44
|
+
* store,
|
|
45
|
+
* 'channelA',
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* console.log(synchronizer.getChannelName());
|
|
49
|
+
* // -> 'channelA'
|
|
50
|
+
*
|
|
51
|
+
* synchronizer.destroy();
|
|
52
|
+
* ```
|
|
53
|
+
* @category Getter
|
|
54
|
+
* @since v5.0.0
|
|
55
|
+
*/
|
|
56
|
+
getChannelName(): string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The createBroadcastChannelSynchronizer function creates a
|
|
61
|
+
* BroadcastChannelSynchronizer object that can synchronize MergeableStore data
|
|
62
|
+
* to and from other MergeableStore instances via a browser's BroadcastChannel
|
|
63
|
+
* API.
|
|
64
|
+
*
|
|
65
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
66
|
+
*
|
|
67
|
+
* ```ts override
|
|
68
|
+
* createBroadcastChannelSynchronizer(
|
|
69
|
+
* store: MergeableStore,
|
|
70
|
+
* channelName: string,
|
|
71
|
+
* onIgnoredError?: (error: any) => void,
|
|
72
|
+
* ): BroadcastChannelSynchronizer;
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* As well as providing a reference to the MergeableStore to persist, you must
|
|
76
|
+
* provide a channel name, used by all the browser tabs, workers, or contexts
|
|
77
|
+
* that need to synchronize together.
|
|
78
|
+
* @param store The MergeableStore to synchronize.
|
|
79
|
+
* @param channelName The name of the channel to use.
|
|
80
|
+
* @param onIgnoredError An optional handler for the errors that the
|
|
81
|
+
* Synchronizer would otherwise ignore when trying to synchronize data. This is
|
|
82
|
+
* suitable for debugging synchronization issues in a development environment.
|
|
83
|
+
* @returns A reference to the new BroadcastChannelSynchronizer object.
|
|
84
|
+
* @example
|
|
85
|
+
* This example creates two BroadcastChannelSynchronizer objects to synchronize
|
|
86
|
+
* one MergeableStore to another.
|
|
87
|
+
*
|
|
88
|
+
* ```js
|
|
89
|
+
* import {createBroadcastChannelSynchronizer} from 'tinybase/synchronizers/synchronizer-broadcast-channel';
|
|
90
|
+
* import {createMergeableStore} from 'tinybase';
|
|
91
|
+
*
|
|
92
|
+
* const store1 = createMergeableStore();
|
|
93
|
+
* const store2 = createMergeableStore();
|
|
94
|
+
*
|
|
95
|
+
* const synchronizer1 = createBroadcastChannelSynchronizer(
|
|
96
|
+
* store1,
|
|
97
|
+
* 'channelA',
|
|
98
|
+
* );
|
|
99
|
+
* const synchronizer2 = createBroadcastChannelSynchronizer(
|
|
100
|
+
* store2,
|
|
101
|
+
* 'channelA',
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* await synchronizer1.startSync();
|
|
105
|
+
* await synchronizer2.startSync();
|
|
106
|
+
*
|
|
107
|
+
* store1.setTables({pets: {fido: {species: 'dog'}}});
|
|
108
|
+
* store2.setTables({pets: {felix: {species: 'cat'}}});
|
|
109
|
+
*
|
|
110
|
+
* // ...
|
|
111
|
+
* console.log(store1.getTables());
|
|
112
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
113
|
+
* console.log(store2.getTables());
|
|
114
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
115
|
+
*
|
|
116
|
+
* synchronizer1.destroy();
|
|
117
|
+
* synchronizer2.destroy();
|
|
118
|
+
* ```
|
|
119
|
+
* @category Creation
|
|
120
|
+
* @since v5.0.0
|
|
121
|
+
*/
|
|
122
|
+
export function createBroadcastChannelSynchronizer<
|
|
123
|
+
Schemas extends OptionalSchemas,
|
|
124
|
+
>(
|
|
125
|
+
store: MergeableStore<Schemas>,
|
|
126
|
+
channelName: string,
|
|
127
|
+
onIgnoredError?: (error: any) => void,
|
|
128
|
+
): BroadcastChannelSynchronizer<Schemas>;
|