tinybase 5.4.0-beta.5 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/indexes/index.d.cts +2 -2
- package/@types/indexes/index.d.ts +2 -2
- package/@types/indexes/with-schemas/index.d.cts +2 -2
- package/@types/indexes/with-schemas/index.d.ts +2 -2
- package/@types/persisters/persister-durable-object-storage/index.d.cts +7 -0
- package/@types/persisters/persister-durable-object-storage/index.d.ts +7 -0
- package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +7 -0
- package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.ts +7 -0
- package/@types/queries/index.d.cts +1 -1
- package/@types/queries/index.d.ts +1 -1
- package/@types/queries/with-schemas/index.d.cts +1 -1
- package/@types/queries/with-schemas/index.d.ts +1 -1
- package/@types/store/index.d.cts +1 -1
- package/@types/store/index.d.ts +1 -1
- package/@types/store/with-schemas/index.d.cts +1 -1
- package/@types/store/with-schemas/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-server/index.d.cts +5 -2
- package/@types/synchronizers/synchronizer-ws-server/index.d.ts +5 -2
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +5 -2
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +5 -2
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +17 -2
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +17 -2
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +17 -2
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +17 -2
- package/@types/ui-react/index.d.cts +42 -0
- package/@types/ui-react/index.d.ts +42 -0
- package/@types/ui-react/with-schemas/index.d.cts +48 -0
- package/@types/ui-react/with-schemas/index.d.ts +48 -0
- package/cjs/es6/min/ui-react/index.cjs +1 -1
- package/cjs/es6/min/ui-react/index.cjs.gz +0 -0
- package/cjs/es6/min/ui-react/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/ui-react/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/ui-react/index.cjs +26 -0
- package/cjs/es6/ui-react/with-schemas/index.cjs +26 -0
- package/cjs/min/ui-react/index.cjs +1 -1
- package/cjs/min/ui-react/index.cjs.gz +0 -0
- package/cjs/min/ui-react/with-schemas/index.cjs +1 -1
- package/cjs/min/ui-react/with-schemas/index.cjs.gz +0 -0
- package/cjs/ui-react/index.cjs +3 -0
- package/cjs/ui-react/with-schemas/index.cjs +3 -0
- package/es6/min/ui-react/index.js +1 -1
- package/es6/min/ui-react/index.js.gz +0 -0
- package/es6/min/ui-react/with-schemas/index.js +1 -1
- package/es6/min/ui-react/with-schemas/index.js.gz +0 -0
- package/es6/ui-react/index.js +26 -0
- package/es6/ui-react/with-schemas/index.js +26 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/package.json +5 -5
- package/readme.md +14 -14
- package/releases.md +26 -26
- package/ui-react/index.js +3 -0
- package/ui-react/with-schemas/index.js +3 -0
- package/umd/es6/min/ui-react/index.js +1 -1
- package/umd/es6/min/ui-react/index.js.gz +0 -0
- package/umd/es6/min/ui-react/with-schemas/index.js +1 -1
- package/umd/es6/min/ui-react/with-schemas/index.js.gz +0 -0
- package/umd/es6/ui-react/index.js +26 -0
- package/umd/es6/ui-react/with-schemas/index.js +26 -0
- package/umd/min/ui-react/index.js +1 -1
- package/umd/min/ui-react/index.js.gz +0 -0
- package/umd/min/ui-react/with-schemas/index.js +1 -1
- package/umd/min/ui-react/with-schemas/index.js.gz +0 -0
- package/umd/ui-react/index.js +3 -0
- package/umd/ui-react/with-schemas/index.js +3 -0
|
@@ -51,8 +51,8 @@ export type Slice = Ids;
|
|
|
51
51
|
* can do something based on every Index in the Indexes object. See that method
|
|
52
52
|
* for specific examples.
|
|
53
53
|
* @param indexId The Id of the Index that the callback can operate on.
|
|
54
|
-
* @param
|
|
55
|
-
* in this Index.
|
|
54
|
+
* @param forEachSlice A function that will let you iterate over the Slice
|
|
55
|
+
* objects in this Index.
|
|
56
56
|
* @category Callback
|
|
57
57
|
* @since v1.0.0
|
|
58
58
|
*/
|
|
@@ -51,8 +51,8 @@ export type Slice = Ids;
|
|
|
51
51
|
* can do something based on every Index in the Indexes object. See that method
|
|
52
52
|
* for specific examples.
|
|
53
53
|
* @param indexId The Id of the Index that the callback can operate on.
|
|
54
|
-
* @param
|
|
55
|
-
* in this Index.
|
|
54
|
+
* @param forEachSlice A function that will let you iterate over the Slice
|
|
55
|
+
* objects in this Index.
|
|
56
56
|
* @category Callback
|
|
57
57
|
* @since v1.0.0
|
|
58
58
|
*/
|
|
@@ -75,8 +75,8 @@ export type Slice = Ids;
|
|
|
75
75
|
* can do something based on every Index in the Indexes object. See that method
|
|
76
76
|
* for specific examples.
|
|
77
77
|
* @param indexId The Id of the Index that the callback can operate on.
|
|
78
|
-
* @param
|
|
79
|
-
* in this Index.
|
|
78
|
+
* @param forEachSlice A function that will let you iterate over the Slice
|
|
79
|
+
* objects in this Index.
|
|
80
80
|
* @category Callback
|
|
81
81
|
* @since v1.0.0
|
|
82
82
|
*/
|
|
@@ -75,8 +75,8 @@ export type Slice = Ids;
|
|
|
75
75
|
* can do something based on every Index in the Indexes object. See that method
|
|
76
76
|
* for specific examples.
|
|
77
77
|
* @param indexId The Id of the Index that the callback can operate on.
|
|
78
|
-
* @param
|
|
79
|
-
* in this Index.
|
|
78
|
+
* @param forEachSlice A function that will let you iterate over the Slice
|
|
79
|
+
* objects in this Index.
|
|
80
80
|
* @category Callback
|
|
81
81
|
* @since v1.0.0
|
|
82
82
|
*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The persister-durable-object-storage module of the TinyBase project lets you
|
|
3
3
|
* save and load Store data to and from Cloudflare Durable Object storage (in an
|
|
4
4
|
* appropriate environment).
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Persistence guides
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
* @module persister-durable-object-storage
|
|
@@ -72,6 +73,12 @@ export interface DurableObjectStoragePersister
|
|
|
72
73
|
* A DurableObjectStoragePersister only supports MergeableStore objects, and
|
|
73
74
|
* cannot be used to persist a regular Store.
|
|
74
75
|
*
|
|
76
|
+
* Durable Objects have limitations on the data that can be stored in each key
|
|
77
|
+
* of their key-value structure. The DurableObjectStoragePersister uses one key
|
|
78
|
+
* per TinyBase Value, one key per Cell, one key per Row, and one key per Table.
|
|
79
|
+
* Mostly this is CRDT metadata, but the main caution is to ensure that each
|
|
80
|
+
* individual TinyBase Cell and Value data does not exceed the (128 KiB) limit.
|
|
81
|
+
*
|
|
75
82
|
* As well as providing a reference to the MergeableStore to persist, you must
|
|
76
83
|
* provide a `storage` parameter which identifies the Durable Object storage to
|
|
77
84
|
* persist it to.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The persister-durable-object-storage module of the TinyBase project lets you
|
|
3
3
|
* save and load Store data to and from Cloudflare Durable Object storage (in an
|
|
4
4
|
* appropriate environment).
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Persistence guides
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
* @module persister-durable-object-storage
|
|
@@ -72,6 +73,12 @@ export interface DurableObjectStoragePersister
|
|
|
72
73
|
* A DurableObjectStoragePersister only supports MergeableStore objects, and
|
|
73
74
|
* cannot be used to persist a regular Store.
|
|
74
75
|
*
|
|
76
|
+
* Durable Objects have limitations on the data that can be stored in each key
|
|
77
|
+
* of their key-value structure. The DurableObjectStoragePersister uses one key
|
|
78
|
+
* per TinyBase Value, one key per Cell, one key per Row, and one key per Table.
|
|
79
|
+
* Mostly this is CRDT metadata, but the main caution is to ensure that each
|
|
80
|
+
* individual TinyBase Cell and Value data does not exceed the (128 KiB) limit.
|
|
81
|
+
*
|
|
75
82
|
* As well as providing a reference to the MergeableStore to persist, you must
|
|
76
83
|
* provide a `storage` parameter which identifies the Durable Object storage to
|
|
77
84
|
* persist it to.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The persister-durable-object-storage module of the TinyBase project lets you
|
|
3
3
|
* save and load Store data to and from Cloudflare Durable Object storage (in an
|
|
4
4
|
* appropriate environment).
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Persistence guides
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
* @module persister-durable-object-storage
|
|
@@ -84,6 +85,12 @@ export interface DurableObjectStoragePersister<Schemas extends OptionalSchemas>
|
|
|
84
85
|
* A DurableObjectStoragePersister only supports MergeableStore objects, and
|
|
85
86
|
* cannot be used to persist a regular Store.
|
|
86
87
|
*
|
|
88
|
+
* Durable Objects have limitations on the data that can be stored in each key
|
|
89
|
+
* of their key-value structure. The DurableObjectStoragePersister uses one key
|
|
90
|
+
* per TinyBase Value, one key per Cell, one key per Row, and one key per Table.
|
|
91
|
+
* Mostly this is CRDT metadata, but the main caution is to ensure that each
|
|
92
|
+
* individual TinyBase Cell and Value data does not exceed the (128 KiB) limit.
|
|
93
|
+
*
|
|
87
94
|
* As well as providing a reference to the MergeableStore to persist, you must
|
|
88
95
|
* provide a `storage` parameter which identifies the Durable Object storage to
|
|
89
96
|
* persist it to.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The persister-durable-object-storage module of the TinyBase project lets you
|
|
3
3
|
* save and load Store data to and from Cloudflare Durable Object storage (in an
|
|
4
4
|
* appropriate environment).
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Persistence guides
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
* @module persister-durable-object-storage
|
|
@@ -84,6 +85,12 @@ export interface DurableObjectStoragePersister<Schemas extends OptionalSchemas>
|
|
|
84
85
|
* A DurableObjectStoragePersister only supports MergeableStore objects, and
|
|
85
86
|
* cannot be used to persist a regular Store.
|
|
86
87
|
*
|
|
88
|
+
* Durable Objects have limitations on the data that can be stored in each key
|
|
89
|
+
* of their key-value structure. The DurableObjectStoragePersister uses one key
|
|
90
|
+
* per TinyBase Value, one key per Cell, one key per Row, and one key per Table.
|
|
91
|
+
* Mostly this is CRDT metadata, but the main caution is to ensure that each
|
|
92
|
+
* individual TinyBase Cell and Value data does not exceed the (128 KiB) limit.
|
|
93
|
+
*
|
|
87
94
|
* As well as providing a reference to the MergeableStore to persist, you must
|
|
88
95
|
* provide a `storage` parameter which identifies the Durable Object storage to
|
|
89
96
|
* persist it to.
|
|
@@ -234,7 +234,7 @@ export type ResultTableCallback = (
|
|
|
234
234
|
* that you can do something based on every ResultRow in a ResultTable. See that
|
|
235
235
|
* method for specific examples.
|
|
236
236
|
* @param rowId The Id of the ResultRow that the callback can operate on.
|
|
237
|
-
* @param
|
|
237
|
+
* @param forEachCell A function that will let you iterate over the ResultCell
|
|
238
238
|
* values in this ResultRow.
|
|
239
239
|
* @category Callback
|
|
240
240
|
* @since v2.0.0
|
|
@@ -234,7 +234,7 @@ export type ResultTableCallback = (
|
|
|
234
234
|
* that you can do something based on every ResultRow in a ResultTable. See that
|
|
235
235
|
* method for specific examples.
|
|
236
236
|
* @param rowId The Id of the ResultRow that the callback can operate on.
|
|
237
|
-
* @param
|
|
237
|
+
* @param forEachCell A function that will let you iterate over the ResultCell
|
|
238
238
|
* values in this ResultRow.
|
|
239
239
|
* @category Callback
|
|
240
240
|
* @since v2.0.0
|
|
@@ -245,7 +245,7 @@ export type ResultTableCallback = (
|
|
|
245
245
|
* that you can do something based on every ResultRow in a ResultTable. See that
|
|
246
246
|
* method for specific examples.
|
|
247
247
|
* @param rowId The Id of the ResultRow that the callback can operate on.
|
|
248
|
-
* @param
|
|
248
|
+
* @param forEachCell A function that will let you iterate over the ResultCell
|
|
249
249
|
* values in this ResultRow.
|
|
250
250
|
* @category Callback
|
|
251
251
|
* @since v2.0.0
|
|
@@ -245,7 +245,7 @@ export type ResultTableCallback = (
|
|
|
245
245
|
* that you can do something based on every ResultRow in a ResultTable. See that
|
|
246
246
|
* method for specific examples.
|
|
247
247
|
* @param rowId The Id of the ResultRow that the callback can operate on.
|
|
248
|
-
* @param
|
|
248
|
+
* @param forEachCell A function that will let you iterate over the ResultCell
|
|
249
249
|
* values in this ResultRow.
|
|
250
250
|
* @category Callback
|
|
251
251
|
* @since v2.0.0
|
package/@types/store/index.d.cts
CHANGED
|
@@ -394,7 +394,7 @@ export type TableCellCallback = (cellId: Id, count: number) => void;
|
|
|
394
394
|
* do something based on every Row in a Table. See that method for specific
|
|
395
395
|
* examples.
|
|
396
396
|
* @param rowId The Id of the Row that the callback can operate on.
|
|
397
|
-
* @param
|
|
397
|
+
* @param forEachCell A function that will let you iterate over the Cell values
|
|
398
398
|
* in this Row.
|
|
399
399
|
* @category Callback
|
|
400
400
|
* @since v1.0.0
|
package/@types/store/index.d.ts
CHANGED
|
@@ -394,7 +394,7 @@ export type TableCellCallback = (cellId: Id, count: number) => void;
|
|
|
394
394
|
* do something based on every Row in a Table. See that method for specific
|
|
395
395
|
* examples.
|
|
396
396
|
* @param rowId The Id of the Row that the callback can operate on.
|
|
397
|
-
* @param
|
|
397
|
+
* @param forEachCell A function that will let you iterate over the Cell values
|
|
398
398
|
* in this Row.
|
|
399
399
|
* @category Callback
|
|
400
400
|
* @since v1.0.0
|
|
@@ -588,7 +588,7 @@ export type TableCellCallback<
|
|
|
588
588
|
* do something based on every Row in a Table. See that method for specific
|
|
589
589
|
* examples.
|
|
590
590
|
* @param rowId The Id of the Row that the callback can operate on.
|
|
591
|
-
* @param
|
|
591
|
+
* @param forEachCell A function that will let you iterate over the Cell values
|
|
592
592
|
* in this Row.
|
|
593
593
|
* @category Callback
|
|
594
594
|
* @since v1.0.0
|
|
@@ -588,7 +588,7 @@ export type TableCellCallback<
|
|
|
588
588
|
* do something based on every Row in a Table. See that method for specific
|
|
589
589
|
* examples.
|
|
590
590
|
* @param rowId The Id of the Row that the callback can operate on.
|
|
591
|
-
* @param
|
|
591
|
+
* @param forEachCell A function that will let you iterate over the Cell values
|
|
592
592
|
* in this Row.
|
|
593
593
|
* @category Callback
|
|
594
594
|
* @since v1.0.0
|
|
@@ -700,7 +700,10 @@ export interface WsServer {
|
|
|
700
700
|
* // On the server:
|
|
701
701
|
* const webSocketServer = new WebSocketServer({port: 8047});
|
|
702
702
|
* webSocketServer.on('connection', (_, request) => {
|
|
703
|
-
*
|
|
703
|
+
* const clientAddress = request.socket.remoteAddress;
|
|
704
|
+
* if (clientAddress == '::1' || clientAddress == '::ffff:127.0.0.1') {
|
|
705
|
+
* console.log('Local client connected');
|
|
706
|
+
* }
|
|
704
707
|
* });
|
|
705
708
|
* const server = createWsServer(webSocketServer);
|
|
706
709
|
*
|
|
@@ -709,7 +712,7 @@ export interface WsServer {
|
|
|
709
712
|
* createMergeableStore(),
|
|
710
713
|
* new WebSocket('ws://localhost:8047'),
|
|
711
714
|
* );
|
|
712
|
-
* // -> '
|
|
715
|
+
* // -> 'Local client connected'
|
|
713
716
|
*
|
|
714
717
|
* synchronizer.destroy();
|
|
715
718
|
* server.destroy();
|
|
@@ -700,7 +700,10 @@ export interface WsServer {
|
|
|
700
700
|
* // On the server:
|
|
701
701
|
* const webSocketServer = new WebSocketServer({port: 8047});
|
|
702
702
|
* webSocketServer.on('connection', (_, request) => {
|
|
703
|
-
*
|
|
703
|
+
* const clientAddress = request.socket.remoteAddress;
|
|
704
|
+
* if (clientAddress == '::1' || clientAddress == '::ffff:127.0.0.1') {
|
|
705
|
+
* console.log('Local client connected');
|
|
706
|
+
* }
|
|
704
707
|
* });
|
|
705
708
|
* const server = createWsServer(webSocketServer);
|
|
706
709
|
*
|
|
@@ -709,7 +712,7 @@ export interface WsServer {
|
|
|
709
712
|
* createMergeableStore(),
|
|
710
713
|
* new WebSocket('ws://localhost:8047'),
|
|
711
714
|
* );
|
|
712
|
-
* // -> '
|
|
715
|
+
* // -> 'Local client connected'
|
|
713
716
|
*
|
|
714
717
|
* synchronizer.destroy();
|
|
715
718
|
* server.destroy();
|
|
@@ -727,7 +727,10 @@ export interface WsServer {
|
|
|
727
727
|
* // On the server:
|
|
728
728
|
* const webSocketServer = new WebSocketServer({port: 8047});
|
|
729
729
|
* webSocketServer.on('connection', (_, request) => {
|
|
730
|
-
*
|
|
730
|
+
* const clientAddress = request.socket.remoteAddress;
|
|
731
|
+
* if (clientAddress == '::1' || clientAddress == '::ffff:127.0.0.1') {
|
|
732
|
+
* console.log('Local client connected');
|
|
733
|
+
* }
|
|
731
734
|
* });
|
|
732
735
|
* const server = createWsServer(webSocketServer);
|
|
733
736
|
*
|
|
@@ -736,7 +739,7 @@ export interface WsServer {
|
|
|
736
739
|
* createMergeableStore(),
|
|
737
740
|
* new WebSocket('ws://localhost:8047'),
|
|
738
741
|
* );
|
|
739
|
-
* // -> '
|
|
742
|
+
* // -> 'Local client connected'
|
|
740
743
|
*
|
|
741
744
|
* synchronizer.destroy();
|
|
742
745
|
* server.destroy();
|
|
@@ -727,7 +727,10 @@ export interface WsServer {
|
|
|
727
727
|
* // On the server:
|
|
728
728
|
* const webSocketServer = new WebSocketServer({port: 8047});
|
|
729
729
|
* webSocketServer.on('connection', (_, request) => {
|
|
730
|
-
*
|
|
730
|
+
* const clientAddress = request.socket.remoteAddress;
|
|
731
|
+
* if (clientAddress == '::1' || clientAddress == '::ffff:127.0.0.1') {
|
|
732
|
+
* console.log('Local client connected');
|
|
733
|
+
* }
|
|
731
734
|
* });
|
|
732
735
|
* const server = createWsServer(webSocketServer);
|
|
733
736
|
*
|
|
@@ -736,7 +739,7 @@ export interface WsServer {
|
|
|
736
739
|
* createMergeableStore(),
|
|
737
740
|
* new WebSocket('ws://localhost:8047'),
|
|
738
741
|
* );
|
|
739
|
-
* // -> '
|
|
742
|
+
* // -> 'Local client connected'
|
|
740
743
|
*
|
|
741
744
|
* synchronizer.destroy();
|
|
742
745
|
* server.destroy();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws-server-durable-object module of the TinyBase project lets
|
|
3
3
|
* you create a server that facilitates synchronization between clients, running
|
|
4
4
|
* as a Cloudflare Durable Object.
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Synchronization guide
|
|
6
7
|
* @see Todo App v6 (collaboration) demo
|
|
7
8
|
* @packageDocumentation
|
|
@@ -17,6 +18,16 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
17
18
|
* A WsServerDurableObject is the server component (running as a Cloudflare
|
|
18
19
|
* Durable Object) for synchronization between clients that are using
|
|
19
20
|
* WsSynchronizer instances.
|
|
21
|
+
*
|
|
22
|
+
* The WsServerDurableObject is an overridden implementation of the
|
|
23
|
+
* DurableObject class, so you can have access to its members as well as the
|
|
24
|
+
* TinyBase-specific methods. If you are using the storage for other data, you
|
|
25
|
+
* may want to configure a `prefix` parameter to ensure you don't accidentally
|
|
26
|
+
* collide with TinyBase data.
|
|
27
|
+
*
|
|
28
|
+
* Always remember to call the `super` implementations of the methods that
|
|
29
|
+
* TinyBase uses (the constructor, `fetch`, `webSocketMessage`, and
|
|
30
|
+
* `webSocketClose`) if you further override them.
|
|
20
31
|
* @category Creation
|
|
21
32
|
* @since v5.4.0
|
|
22
33
|
*/
|
|
@@ -26,12 +37,16 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
26
37
|
* the TinyBase clients.
|
|
27
38
|
*
|
|
28
39
|
* For basic TinyBase synchronization and persistence, you don't need to
|
|
29
|
-
* override this method, but if you do, ensure you call the super
|
|
40
|
+
* override this method, but if you do, ensure you call the `super`
|
|
41
|
+
* constructor
|
|
42
|
+
* with the two parameters.
|
|
43
|
+
* @param ctx The DurableObjectState context.
|
|
44
|
+
* @param env The DurableObjectState environment.
|
|
30
45
|
* @returns A new instance of the WsServerDurableObject.
|
|
31
46
|
* @category Creation
|
|
32
47
|
* @since v5.4.0
|
|
33
48
|
*/
|
|
34
|
-
constructor();
|
|
49
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
35
50
|
|
|
36
51
|
/**
|
|
37
52
|
* The createPersister method is used to return a persister for the Durable
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws-server-durable-object module of the TinyBase project lets
|
|
3
3
|
* you create a server that facilitates synchronization between clients, running
|
|
4
4
|
* as a Cloudflare Durable Object.
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Synchronization guide
|
|
6
7
|
* @see Todo App v6 (collaboration) demo
|
|
7
8
|
* @packageDocumentation
|
|
@@ -17,6 +18,16 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
17
18
|
* A WsServerDurableObject is the server component (running as a Cloudflare
|
|
18
19
|
* Durable Object) for synchronization between clients that are using
|
|
19
20
|
* WsSynchronizer instances.
|
|
21
|
+
*
|
|
22
|
+
* The WsServerDurableObject is an overridden implementation of the
|
|
23
|
+
* DurableObject class, so you can have access to its members as well as the
|
|
24
|
+
* TinyBase-specific methods. If you are using the storage for other data, you
|
|
25
|
+
* may want to configure a `prefix` parameter to ensure you don't accidentally
|
|
26
|
+
* collide with TinyBase data.
|
|
27
|
+
*
|
|
28
|
+
* Always remember to call the `super` implementations of the methods that
|
|
29
|
+
* TinyBase uses (the constructor, `fetch`, `webSocketMessage`, and
|
|
30
|
+
* `webSocketClose`) if you further override them.
|
|
20
31
|
* @category Creation
|
|
21
32
|
* @since v5.4.0
|
|
22
33
|
*/
|
|
@@ -26,12 +37,16 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
26
37
|
* the TinyBase clients.
|
|
27
38
|
*
|
|
28
39
|
* For basic TinyBase synchronization and persistence, you don't need to
|
|
29
|
-
* override this method, but if you do, ensure you call the super
|
|
40
|
+
* override this method, but if you do, ensure you call the `super`
|
|
41
|
+
* constructor
|
|
42
|
+
* with the two parameters.
|
|
43
|
+
* @param ctx The DurableObjectState context.
|
|
44
|
+
* @param env The DurableObjectState environment.
|
|
30
45
|
* @returns A new instance of the WsServerDurableObject.
|
|
31
46
|
* @category Creation
|
|
32
47
|
* @since v5.4.0
|
|
33
48
|
*/
|
|
34
|
-
constructor();
|
|
49
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
35
50
|
|
|
36
51
|
/**
|
|
37
52
|
* The createPersister method is used to return a persister for the Durable
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws-server-durable-object module of the TinyBase project lets
|
|
3
3
|
* you create a server that facilitates synchronization between clients, running
|
|
4
4
|
* as a Cloudflare Durable Object.
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Synchronization guide
|
|
6
7
|
* @see Todo App v6 (collaboration) demo
|
|
7
8
|
* @packageDocumentation
|
|
@@ -25,6 +26,16 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
25
26
|
* A WsServerDurableObject is the server component (running as a Cloudflare
|
|
26
27
|
* Durable Object) for synchronization between clients that are using
|
|
27
28
|
* WsSynchronizer instances.
|
|
29
|
+
*
|
|
30
|
+
* The WsServerDurableObject is an overridden implementation of the
|
|
31
|
+
* DurableObject class, so you can have access to its members as well as the
|
|
32
|
+
* TinyBase-specific methods. If you are using the storage for other data, you
|
|
33
|
+
* may want to configure a `prefix` parameter to ensure you don't accidentally
|
|
34
|
+
* collide with TinyBase data.
|
|
35
|
+
*
|
|
36
|
+
* Always remember to call the `super` implementations of the methods that
|
|
37
|
+
* TinyBase uses (the constructor, `fetch`, `webSocketMessage`, and
|
|
38
|
+
* `webSocketClose`) if you further override them.
|
|
28
39
|
* @category Creation
|
|
29
40
|
* @since v5.4.0
|
|
30
41
|
*/
|
|
@@ -37,12 +48,16 @@ export class WsServerDurableObject<
|
|
|
37
48
|
* the TinyBase clients.
|
|
38
49
|
*
|
|
39
50
|
* For basic TinyBase synchronization and persistence, you don't need to
|
|
40
|
-
* override this method, but if you do, ensure you call the super
|
|
51
|
+
* override this method, but if you do, ensure you call the `super`
|
|
52
|
+
* constructor
|
|
53
|
+
* with the two parameters.
|
|
54
|
+
* @param ctx The DurableObjectState context.
|
|
55
|
+
* @param env The DurableObjectState environment.
|
|
41
56
|
* @returns A new instance of the WsServerDurableObject.
|
|
42
57
|
* @category Creation
|
|
43
58
|
* @since v5.4.0
|
|
44
59
|
*/
|
|
45
|
-
constructor();
|
|
60
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
46
61
|
|
|
47
62
|
/**
|
|
48
63
|
* The createPersister method is used to return a persister for the Durable
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The synchronizer-ws-server-durable-object module of the TinyBase project lets
|
|
3
3
|
* you create a server that facilitates synchronization between clients, running
|
|
4
4
|
* as a Cloudflare Durable Object.
|
|
5
|
+
* @see Cloudflare Durable Objects guide
|
|
5
6
|
* @see Synchronization guide
|
|
6
7
|
* @see Todo App v6 (collaboration) demo
|
|
7
8
|
* @packageDocumentation
|
|
@@ -25,6 +26,16 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
25
26
|
* A WsServerDurableObject is the server component (running as a Cloudflare
|
|
26
27
|
* Durable Object) for synchronization between clients that are using
|
|
27
28
|
* WsSynchronizer instances.
|
|
29
|
+
*
|
|
30
|
+
* The WsServerDurableObject is an overridden implementation of the
|
|
31
|
+
* DurableObject class, so you can have access to its members as well as the
|
|
32
|
+
* TinyBase-specific methods. If you are using the storage for other data, you
|
|
33
|
+
* may want to configure a `prefix` parameter to ensure you don't accidentally
|
|
34
|
+
* collide with TinyBase data.
|
|
35
|
+
*
|
|
36
|
+
* Always remember to call the `super` implementations of the methods that
|
|
37
|
+
* TinyBase uses (the constructor, `fetch`, `webSocketMessage`, and
|
|
38
|
+
* `webSocketClose`) if you further override them.
|
|
28
39
|
* @category Creation
|
|
29
40
|
* @since v5.4.0
|
|
30
41
|
*/
|
|
@@ -37,12 +48,16 @@ export class WsServerDurableObject<
|
|
|
37
48
|
* the TinyBase clients.
|
|
38
49
|
*
|
|
39
50
|
* For basic TinyBase synchronization and persistence, you don't need to
|
|
40
|
-
* override this method, but if you do, ensure you call the super
|
|
51
|
+
* override this method, but if you do, ensure you call the `super`
|
|
52
|
+
* constructor
|
|
53
|
+
* with the two parameters.
|
|
54
|
+
* @param ctx The DurableObjectState context.
|
|
55
|
+
* @param env The DurableObjectState environment.
|
|
41
56
|
* @returns A new instance of the WsServerDurableObject.
|
|
42
57
|
* @category Creation
|
|
43
58
|
* @since v5.4.0
|
|
44
59
|
*/
|
|
45
|
-
constructor();
|
|
60
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
46
61
|
|
|
47
62
|
/**
|
|
48
63
|
* The createPersister method is used to return a persister for the Durable
|
|
@@ -499,6 +499,48 @@ export function useStoreIds(): Ids;
|
|
|
499
499
|
*/
|
|
500
500
|
export function useStore(id?: Id): Store | undefined;
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* The useStores hook is used to get a reference to all the Store objects named
|
|
504
|
+
* by Id within a Provider component context.
|
|
505
|
+
*
|
|
506
|
+
* A Provider component is used to wrap part of an application in a context. It
|
|
507
|
+
* can contain a default Store (or a set of Store objects named by Id) that can
|
|
508
|
+
* be easily accessed without having to be passed down as props through every
|
|
509
|
+
* component.
|
|
510
|
+
*
|
|
511
|
+
* The useStores hook lets you get a reference to the latter as an object.
|
|
512
|
+
* @returns An object containing all the Store objects named by Id.
|
|
513
|
+
* @example
|
|
514
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
515
|
+
* by Id. A component within it then uses the useStores hook to get a reference
|
|
516
|
+
* to the Store again.
|
|
517
|
+
*
|
|
518
|
+
* ```jsx
|
|
519
|
+
* import {Provider, useStores} from 'tinybase/ui-react';
|
|
520
|
+
* import React from 'react';
|
|
521
|
+
* import {createRoot} from 'react-dom/client';
|
|
522
|
+
* import {createStore} from 'tinybase';
|
|
523
|
+
*
|
|
524
|
+
* const App = ({store}) => (
|
|
525
|
+
* <Provider storesById={{petStore: store}}>
|
|
526
|
+
* <Pane />
|
|
527
|
+
* </Provider>
|
|
528
|
+
* );
|
|
529
|
+
* const Pane = () => (
|
|
530
|
+
* <span>{useStores()['petStore'].getListenerStats().tables}</span>
|
|
531
|
+
* );
|
|
532
|
+
*
|
|
533
|
+
* const store = createStore();
|
|
534
|
+
* const app = document.createElement('div');
|
|
535
|
+
* createRoot(app).render(<App store={store} />); // !act
|
|
536
|
+
* console.log(app.innerHTML);
|
|
537
|
+
* // -> '<span>0</span>'
|
|
538
|
+
* ```
|
|
539
|
+
* @category Store hooks
|
|
540
|
+
* @since v5.4.1
|
|
541
|
+
*/
|
|
542
|
+
export function useStores(): {[storeId: Id]: Store};
|
|
543
|
+
|
|
502
544
|
/**
|
|
503
545
|
* The useStoreOrStoreById hook is used to get a reference to a Store object
|
|
504
546
|
* from within a Provider component context, _or_ have it passed directly to
|
|
@@ -499,6 +499,48 @@ export function useStoreIds(): Ids;
|
|
|
499
499
|
*/
|
|
500
500
|
export function useStore(id?: Id): Store | undefined;
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* The useStores hook is used to get a reference to all the Store objects named
|
|
504
|
+
* by Id within a Provider component context.
|
|
505
|
+
*
|
|
506
|
+
* A Provider component is used to wrap part of an application in a context. It
|
|
507
|
+
* can contain a default Store (or a set of Store objects named by Id) that can
|
|
508
|
+
* be easily accessed without having to be passed down as props through every
|
|
509
|
+
* component.
|
|
510
|
+
*
|
|
511
|
+
* The useStores hook lets you get a reference to the latter as an object.
|
|
512
|
+
* @returns An object containing all the Store objects named by Id.
|
|
513
|
+
* @example
|
|
514
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
515
|
+
* by Id. A component within it then uses the useStores hook to get a reference
|
|
516
|
+
* to the Store again.
|
|
517
|
+
*
|
|
518
|
+
* ```jsx
|
|
519
|
+
* import {Provider, useStores} from 'tinybase/ui-react';
|
|
520
|
+
* import React from 'react';
|
|
521
|
+
* import {createRoot} from 'react-dom/client';
|
|
522
|
+
* import {createStore} from 'tinybase';
|
|
523
|
+
*
|
|
524
|
+
* const App = ({store}) => (
|
|
525
|
+
* <Provider storesById={{petStore: store}}>
|
|
526
|
+
* <Pane />
|
|
527
|
+
* </Provider>
|
|
528
|
+
* );
|
|
529
|
+
* const Pane = () => (
|
|
530
|
+
* <span>{useStores()['petStore'].getListenerStats().tables}</span>
|
|
531
|
+
* );
|
|
532
|
+
*
|
|
533
|
+
* const store = createStore();
|
|
534
|
+
* const app = document.createElement('div');
|
|
535
|
+
* createRoot(app).render(<App store={store} />); // !act
|
|
536
|
+
* console.log(app.innerHTML);
|
|
537
|
+
* // -> '<span>0</span>'
|
|
538
|
+
* ```
|
|
539
|
+
* @category Store hooks
|
|
540
|
+
* @since v5.4.1
|
|
541
|
+
*/
|
|
542
|
+
export function useStores(): {[storeId: Id]: Store};
|
|
543
|
+
|
|
502
544
|
/**
|
|
503
545
|
* The useStoreOrStoreById hook is used to get a reference to a Store object
|
|
504
546
|
* from within a Provider component context, _or_ have it passed directly to
|
|
@@ -600,6 +600,54 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
600
600
|
*/
|
|
601
601
|
useStore: (id?: Id) => Store<Schemas> | undefined;
|
|
602
602
|
|
|
603
|
+
/**
|
|
604
|
+
* The useStores hook is used to get a reference to all the Store objects named
|
|
605
|
+
* by Id within a Provider component context.
|
|
606
|
+
*
|
|
607
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
608
|
+
*
|
|
609
|
+
* ```ts override
|
|
610
|
+
* useStores(): {[storeId: Id]: Store};
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* A Provider component is used to wrap part of an application in a context. It
|
|
614
|
+
* can contain a default Store (or a set of Store objects named by Id) that can
|
|
615
|
+
* be easily accessed without having to be passed down as props through every
|
|
616
|
+
* component.
|
|
617
|
+
*
|
|
618
|
+
* The useStores hook lets you get a reference to the latter as an object.
|
|
619
|
+
* @returns An object containing all the Store objects named by Id.
|
|
620
|
+
* @example
|
|
621
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
622
|
+
* by Id. A component within it then uses the useStores hook to get a reference
|
|
623
|
+
* to the Store again.
|
|
624
|
+
*
|
|
625
|
+
* ```jsx
|
|
626
|
+
* import {Provider, useStores} from 'tinybase/ui-react';
|
|
627
|
+
* import React from 'react';
|
|
628
|
+
* import {createRoot} from 'react-dom/client';
|
|
629
|
+
* import {createStore} from 'tinybase';
|
|
630
|
+
*
|
|
631
|
+
* const App = ({store}) => (
|
|
632
|
+
* <Provider storesById={{petStore: store}}>
|
|
633
|
+
* <Pane />
|
|
634
|
+
* </Provider>
|
|
635
|
+
* );
|
|
636
|
+
* const Pane = () => (
|
|
637
|
+
* <span>{useStores()['petStore'].getListenerStats().tables}</span>
|
|
638
|
+
* );
|
|
639
|
+
*
|
|
640
|
+
* const store = createStore();
|
|
641
|
+
* const app = document.createElement('div');
|
|
642
|
+
* createRoot(app).render(<App store={store} />); // !act
|
|
643
|
+
* console.log(app.innerHTML);
|
|
644
|
+
* // -> '<span>0</span>'
|
|
645
|
+
* ```
|
|
646
|
+
* @category Store hooks
|
|
647
|
+
* @since v5.4.1
|
|
648
|
+
*/
|
|
649
|
+
useStores: () => {[storeId: Id]: Store<OptionalSchemas>};
|
|
650
|
+
|
|
603
651
|
/**
|
|
604
652
|
* The useStoreOrStoreById hook is used to get a reference to a Store object
|
|
605
653
|
* from within a Provider component context, _or_ have it passed directly to
|