tinybase 5.4.0-beta.3 → 5.4.0-beta.5
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/mergeable-store/index.d.cts +5 -4
- package/@types/mergeable-store/index.d.ts +5 -4
- package/@types/mergeable-store/with-schemas/index.d.cts +5 -4
- package/@types/mergeable-store/with-schemas/index.d.ts +5 -4
- package/@types/persisters/index.d.cts +1 -0
- package/@types/persisters/index.d.ts +1 -0
- package/@types/persisters/persister-durable-object-storage/index.d.cts +25 -17
- package/@types/persisters/persister-durable-object-storage/index.d.ts +25 -17
- package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +26 -18
- package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.ts +26 -18
- package/@types/persisters/persister-partykit-server/index.d.cts +12 -0
- package/@types/persisters/persister-partykit-server/index.d.ts +12 -0
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +15 -0
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +15 -0
- package/@types/persisters/with-schemas/index.d.cts +1 -0
- package/@types/persisters/with-schemas/index.d.ts +1 -0
- package/@types/store/index.d.cts +10 -8
- package/@types/store/index.d.ts +10 -8
- package/@types/store/with-schemas/index.d.cts +10 -8
- package/@types/store/with-schemas/index.d.ts +10 -8
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +206 -28
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +206 -28
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +219 -28
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +219 -28
- package/cjs/es6/index.cjs +0 -1
- package/cjs/es6/indexes/index.cjs +1 -1
- package/cjs/es6/indexes/with-schemas/index.cjs +1 -1
- package/cjs/es6/metrics/index.cjs +1 -1
- package/cjs/es6/metrics/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/index.cjs +1 -1
- package/cjs/es6/min/index.cjs.gz +0 -0
- package/cjs/es6/min/indexes/index.cjs +1 -1
- package/cjs/es6/min/indexes/index.cjs.gz +0 -0
- package/cjs/es6/min/indexes/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/indexes/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/metrics/index.cjs +1 -1
- package/cjs/es6/min/metrics/index.cjs.gz +0 -0
- package/cjs/es6/min/metrics/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/metrics/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/persisters/persister-durable-object-storage/index.cjs +1 -1
- package/cjs/es6/min/persisters/persister-durable-object-storage/index.cjs.gz +0 -0
- package/cjs/es6/min/persisters/persister-durable-object-storage/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/persisters/persister-durable-object-storage/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/queries/index.cjs +1 -1
- package/cjs/es6/min/queries/index.cjs.gz +0 -0
- package/cjs/es6/min/queries/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/queries/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/relationships/index.cjs +1 -1
- package/cjs/es6/min/relationships/index.cjs.gz +0 -0
- package/cjs/es6/min/relationships/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/relationships/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs +1 -1
- package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs.gz +0 -0
- package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/min/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/persisters/persister-durable-object-storage/index.cjs +1 -1
- package/cjs/es6/persisters/persister-durable-object-storage/with-schemas/index.cjs +1 -1
- package/cjs/es6/persisters/persister-partykit-client/index.cjs +2 -5
- package/cjs/es6/persisters/persister-partykit-client/with-schemas/index.cjs +2 -5
- package/cjs/es6/queries/index.cjs +0 -1
- package/cjs/es6/queries/with-schemas/index.cjs +0 -1
- package/cjs/es6/relationships/index.cjs +1 -1
- package/cjs/es6/relationships/with-schemas/index.cjs +1 -1
- package/cjs/es6/synchronizers/synchronizer-ws-server-durable-object/index.cjs +10 -6
- package/cjs/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +10 -6
- package/cjs/es6/with-schemas/index.cjs +0 -1
- package/cjs/min/persisters/persister-durable-object-storage/index.cjs +1 -1
- package/cjs/min/persisters/persister-durable-object-storage/index.cjs.gz +0 -0
- package/cjs/min/persisters/persister-durable-object-storage/with-schemas/index.cjs +1 -1
- package/cjs/min/persisters/persister-durable-object-storage/with-schemas/index.cjs.gz +0 -0
- package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs +1 -1
- package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs.gz +0 -0
- package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +1 -1
- package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs.gz +0 -0
- package/cjs/persisters/persister-durable-object-storage/index.cjs +1 -1
- package/cjs/persisters/persister-durable-object-storage/with-schemas/index.cjs +1 -1
- package/cjs/persisters/persister-partykit-client/index.cjs +2 -5
- package/cjs/persisters/persister-partykit-client/with-schemas/index.cjs +2 -5
- package/cjs/synchronizers/synchronizer-ws-server-durable-object/index.cjs +3 -3
- package/cjs/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +3 -3
- package/es6/index.js +0 -1
- package/es6/indexes/index.js +1 -1
- package/es6/indexes/with-schemas/index.js +1 -1
- package/es6/metrics/index.js +1 -1
- package/es6/metrics/with-schemas/index.js +1 -1
- package/es6/min/index.js +1 -1
- package/es6/min/index.js.gz +0 -0
- package/es6/min/indexes/index.js +1 -1
- package/es6/min/indexes/index.js.gz +0 -0
- package/es6/min/indexes/with-schemas/index.js +1 -1
- package/es6/min/indexes/with-schemas/index.js.gz +0 -0
- package/es6/min/metrics/index.js +1 -1
- package/es6/min/metrics/index.js.gz +0 -0
- package/es6/min/metrics/with-schemas/index.js +1 -1
- package/es6/min/metrics/with-schemas/index.js.gz +0 -0
- package/es6/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/es6/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/es6/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/es6/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/es6/min/persisters/persister-file/index.js +1 -1
- package/es6/min/persisters/persister-file/index.js.gz +0 -0
- package/es6/min/persisters/persister-file/with-schemas/index.js +1 -1
- package/es6/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
- package/es6/min/queries/index.js +1 -1
- package/es6/min/queries/index.js.gz +0 -0
- package/es6/min/queries/with-schemas/index.js +1 -1
- package/es6/min/queries/with-schemas/index.js.gz +0 -0
- package/es6/min/relationships/index.js +1 -1
- package/es6/min/relationships/index.js.gz +0 -0
- package/es6/min/relationships/with-schemas/index.js +1 -1
- package/es6/min/relationships/with-schemas/index.js.gz +0 -0
- package/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/es6/min/ui-react-dom/index.js +1 -1
- package/es6/min/ui-react-dom/index.js.gz +0 -0
- package/es6/min/ui-react-dom/with-schemas/index.js +1 -1
- package/es6/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/es6/min/ui-react-inspector/index.js +1 -1
- package/es6/min/ui-react-inspector/index.js.gz +0 -0
- package/es6/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/es6/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/es6/min/with-schemas/index.js +1 -1
- package/es6/min/with-schemas/index.js.gz +0 -0
- package/es6/persisters/persister-durable-object-storage/index.js +1 -1
- package/es6/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/es6/persisters/persister-file/index.js +1 -1
- package/es6/persisters/persister-file/with-schemas/index.js +1 -1
- package/es6/persisters/persister-partykit-client/index.js +2 -5
- package/es6/persisters/persister-partykit-client/with-schemas/index.js +2 -5
- package/es6/queries/index.js +0 -1
- package/es6/queries/with-schemas/index.js +0 -1
- package/es6/relationships/index.js +1 -1
- package/es6/relationships/with-schemas/index.js +1 -1
- package/es6/synchronizers/synchronizer-ws-server-durable-object/index.js +10 -6
- package/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +10 -6
- package/es6/ui-react-dom/index.js +8 -8
- package/es6/ui-react-dom/with-schemas/index.js +8 -8
- package/es6/ui-react-inspector/index.js +4 -4
- package/es6/ui-react-inspector/with-schemas/index.js +4 -4
- package/es6/with-schemas/index.js +0 -1
- package/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-file/index.js +1 -1
- package/min/persisters/persister-file/index.js.gz +0 -0
- package/min/persisters/persister-file/with-schemas/index.js +1 -1
- package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/package.json +1 -1
- package/persisters/persister-durable-object-storage/index.js +1 -1
- package/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/persisters/persister-file/index.js +1 -1
- package/persisters/persister-file/with-schemas/index.js +1 -1
- package/persisters/persister-partykit-client/index.js +2 -5
- package/persisters/persister-partykit-client/with-schemas/index.js +2 -5
- package/readme.md +2 -2
- package/releases.md +17 -5
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +3 -3
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +3 -3
- package/ui-react-dom/index.js +8 -8
- package/ui-react-dom/with-schemas/index.js +8 -8
- package/ui-react-inspector/index.js +4 -4
- package/ui-react-inspector/with-schemas/index.js +4 -4
- package/umd/es6/index.js +0 -1
- package/umd/es6/indexes/index.js +1 -5
- package/umd/es6/indexes/with-schemas/index.js +1 -5
- package/umd/es6/metrics/index.js +1 -5
- package/umd/es6/metrics/with-schemas/index.js +1 -5
- package/umd/es6/min/index.js +1 -1
- package/umd/es6/min/index.js.gz +0 -0
- package/umd/es6/min/indexes/index.js +1 -1
- package/umd/es6/min/indexes/index.js.gz +0 -0
- package/umd/es6/min/indexes/with-schemas/index.js +1 -1
- package/umd/es6/min/indexes/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/metrics/index.js +1 -1
- package/umd/es6/min/metrics/index.js.gz +0 -0
- package/umd/es6/min/metrics/with-schemas/index.js +1 -1
- package/umd/es6/min/metrics/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/umd/es6/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/umd/es6/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/umd/es6/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/queries/index.js +1 -1
- package/umd/es6/min/queries/index.js.gz +0 -0
- package/umd/es6/min/queries/with-schemas/index.js +1 -1
- package/umd/es6/min/queries/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/relationships/index.js +1 -1
- package/umd/es6/min/relationships/index.js.gz +0 -0
- package/umd/es6/min/relationships/with-schemas/index.js +1 -1
- package/umd/es6/min/relationships/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/umd/es6/min/with-schemas/index.js +1 -1
- package/umd/es6/min/with-schemas/index.js.gz +0 -0
- package/umd/es6/persisters/persister-durable-object-storage/index.js +1 -1
- package/umd/es6/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/umd/es6/persisters/persister-partykit-client/index.js +2 -5
- package/umd/es6/persisters/persister-partykit-client/with-schemas/index.js +2 -5
- package/umd/es6/queries/index.js +0 -1
- package/umd/es6/queries/with-schemas/index.js +0 -1
- package/umd/es6/relationships/index.js +1 -5
- package/umd/es6/relationships/with-schemas/index.js +1 -5
- package/umd/es6/synchronizers/synchronizer-ws-server-durable-object/index.js +10 -6
- package/umd/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +10 -6
- package/umd/es6/with-schemas/index.js +0 -1
- package/umd/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/umd/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/umd/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/umd/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/umd/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/umd/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/umd/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/umd/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/umd/persisters/persister-durable-object-storage/index.js +1 -1
- package/umd/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/umd/persisters/persister-partykit-client/index.js +2 -5
- package/umd/persisters/persister-partykit-client/with-schemas/index.js +2 -5
- package/umd/synchronizers/synchronizer-ws-server-durable-object/index.js +3 -3
- package/umd/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +3 -3
|
@@ -22,30 +22,52 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
22
22
|
*/
|
|
23
23
|
export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
24
24
|
/**
|
|
25
|
-
* The
|
|
26
|
-
*
|
|
25
|
+
* The constructor is used to create the Durable Object that will synchronize
|
|
26
|
+
* the TinyBase clients.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* For basic TinyBase synchronization and persistence, you don't need to
|
|
29
|
+
* override this method, but if you do, ensure you call the super constructor.
|
|
30
|
+
* @returns A new instance of the WsServerDurableObject.
|
|
31
|
+
* @category Creation
|
|
32
|
+
* @since v5.4.0
|
|
33
|
+
*/
|
|
34
|
+
constructor();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The createPersister method is used to return a persister for the Durable
|
|
38
|
+
* Object to preserve Store data when clients are not connected.
|
|
39
|
+
*
|
|
40
|
+
* In other words, override this method to enable persistence of the Store
|
|
41
|
+
* data that the Durable Object is synchronizing between clients.
|
|
42
|
+
*
|
|
43
|
+
* This should almost certainly return a DurableObjectStoragePersister,
|
|
44
|
+
* created with the createDurableObjectStoragePersister function. This will
|
|
45
|
+
* ensure that the Store is serialized to the Durable Object KV-based storage.
|
|
46
|
+
*
|
|
47
|
+
* Returning `undefined` from this method will disable persistence.
|
|
30
48
|
* @example
|
|
31
|
-
* This example
|
|
32
|
-
*
|
|
33
|
-
* WsServerDurableObject instance) and then gets the storage reference back
|
|
34
|
-
* out again.
|
|
49
|
+
* This example enables Durable Object persistence by creating a Persister
|
|
50
|
+
* object within the createPersister method of a WsServerDurableObject.
|
|
35
51
|
*
|
|
36
52
|
* ```js yolo
|
|
53
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
37
54
|
* import {createDurableObjectStoragePersister} from 'tinybase/persisters/persister-durable-object-storage';
|
|
38
55
|
* import {createMergeableStore} from 'tinybase';
|
|
39
56
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
57
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
58
|
+
* createPersister() {
|
|
59
|
+
* const store = createMergeableStore();
|
|
60
|
+
* const persister = createDurableObjectStoragePersister(
|
|
61
|
+
* store,
|
|
62
|
+
* this.ctx.storage,
|
|
63
|
+
* );
|
|
64
|
+
* return persister;
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
48
67
|
* ```
|
|
68
|
+
* @returns A new instance of a DurableObjectStoragePersister (or a promise to
|
|
69
|
+
* resolve one) that will be used to persist data to the Durable Object.
|
|
70
|
+
* Return `undefined` if that functionality is not required.
|
|
49
71
|
* @category Creation
|
|
50
72
|
* @since v5.4.0
|
|
51
73
|
*/
|
|
@@ -57,6 +79,23 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
57
79
|
/**
|
|
58
80
|
* The getPathId method is used to get the Id of the path that is being
|
|
59
81
|
* served.
|
|
82
|
+
*
|
|
83
|
+
* This is useful for when you want to know which path the current Durable
|
|
84
|
+
* Object is serving - for the purposes of logging, for example.
|
|
85
|
+
* @returns The Id of the path being served by the Durable Object.
|
|
86
|
+
* @example
|
|
87
|
+
* This example logs the path being served by the Durable Object every time a
|
|
88
|
+
* synchronization method is handled.
|
|
89
|
+
*
|
|
90
|
+
* ```js yolo
|
|
91
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
92
|
+
*
|
|
93
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
94
|
+
* onMessage() {
|
|
95
|
+
* console.info('Message received on path: ', this.getPathId());
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
60
99
|
* @category Getter
|
|
61
100
|
* @since v5.4.0
|
|
62
101
|
*/
|
|
@@ -64,18 +103,56 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
64
103
|
|
|
65
104
|
/**
|
|
66
105
|
* The getClientIds method is used to access a list of all the connected
|
|
67
|
-
* clients on
|
|
106
|
+
* clients on the path.
|
|
68
107
|
*
|
|
69
|
-
* Note that if you call this method from the onClientId method as a
|
|
70
|
-
* getting removed, it will still be returned in the list of client
|
|
108
|
+
* Note that if you call this method from within the onClientId method as a
|
|
109
|
+
* client is getting removed, it will still be returned in the list of client
|
|
110
|
+
* Ids.
|
|
111
|
+
* @returns The Ids of the clients being served by the Durable Object.
|
|
112
|
+
* @example
|
|
113
|
+
* This example logs the list of clients being served by the Durable Object
|
|
114
|
+
* every time a synchronization method is handled.
|
|
115
|
+
*
|
|
116
|
+
* ```js yolo
|
|
117
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
118
|
+
*
|
|
119
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
120
|
+
* onMessage() {
|
|
121
|
+
* console.info('Clients on path: ', this.getClientIds());
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
71
125
|
* @category Getter
|
|
72
126
|
* @since v5.4.0
|
|
73
127
|
*/
|
|
74
|
-
getClientIds(
|
|
128
|
+
getClientIds(): Ids;
|
|
75
129
|
|
|
76
130
|
/**
|
|
77
131
|
* The onPathId method is called when the first client connects to, or the
|
|
78
132
|
* last client disconnects from, the server with a given path Id.
|
|
133
|
+
*
|
|
134
|
+
* This method is called with the path Id and an IdAddedOrRemoved flag
|
|
135
|
+
* indicating whether it this is being triggered by the first client joining
|
|
136
|
+
* (`1`) or the last client leaving (`-1`).
|
|
137
|
+
* @param pathId The Id of the path being served by the Durable Object.
|
|
138
|
+
* @param addedOrRemoved Whether the path had the first joiner, or the last
|
|
139
|
+
* leaver.
|
|
140
|
+
* @example
|
|
141
|
+
* This example logs the Id of the path being served by the Durable Object
|
|
142
|
+
* when the first client joins (the path Id is 'added'), and when the last
|
|
143
|
+
* client leaves (the path Id is 'removed').
|
|
144
|
+
*
|
|
145
|
+
* ```js yolo
|
|
146
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
147
|
+
*
|
|
148
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
149
|
+
* onPathId(pathId, addedOrRemoved) {
|
|
150
|
+
* console.info(
|
|
151
|
+
* (addedOrRemoved ? 'Added' : 'Removed') + ` path ${pathId}`,
|
|
152
|
+
* );
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
79
156
|
* @category Event
|
|
80
157
|
* @since v5.4.0
|
|
81
158
|
*/
|
|
@@ -84,6 +161,34 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
84
161
|
/**
|
|
85
162
|
* The onClientId method is called when a client connects to, or disconnects
|
|
86
163
|
* from, the server.
|
|
164
|
+
*
|
|
165
|
+
* This method is called with the path Id, the client Id, and an
|
|
166
|
+
* IdAddedOrRemoved flag indicating whether it this is being triggered by
|
|
167
|
+
* the client joining (`1`) or the client leaving (`-1`).
|
|
168
|
+
*
|
|
169
|
+
* Note that if you call the getClientIds method from within this method as a
|
|
170
|
+
* client is getting removed, it will still be returned in the list of client
|
|
171
|
+
* Ids.
|
|
172
|
+
* @param pathId The Id of the path being served by the Durable Object.
|
|
173
|
+
* @param clientId The Id of the client joining or leaving.
|
|
174
|
+
* @param addedOrRemoved Whether the client is joining or leaving.
|
|
175
|
+
* @example
|
|
176
|
+
* This example logs every client that joins (the client Id is 'added') or
|
|
177
|
+
* leaves (the client Id is 'removed') on the path being served by the Durable
|
|
178
|
+
* Object.
|
|
179
|
+
*
|
|
180
|
+
* ```js yolo
|
|
181
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
182
|
+
*
|
|
183
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
184
|
+
* onClientId(pathId, clientId, addedOrRemoved) {
|
|
185
|
+
* console.info(
|
|
186
|
+
* (addedOrRemoved ? 'Added' : 'Removed') +
|
|
187
|
+
* ` client ${clientId} on path ${pathId}`,
|
|
188
|
+
* );
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
87
192
|
* @category Event
|
|
88
193
|
* @since v5.4.0
|
|
89
194
|
*/
|
|
@@ -92,20 +197,93 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
92
197
|
/**
|
|
93
198
|
* The onMessage method is called when a message is handled by the server.
|
|
94
199
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
200
|
+
* This is useful if you want to debug the synchronization process, though be
|
|
201
|
+
* aware that this method is called very frequently. It is called with the Id
|
|
202
|
+
* of the client the message came _from_, the the Id of the client the message
|
|
203
|
+
* is to be forwarded _to_, and the remainder of the message itself.
|
|
204
|
+
*
|
|
205
|
+
* Since this method is called often, it should be performant. The path Id is
|
|
206
|
+
* not passed as an argument, since it has a small cost to provide by default.
|
|
207
|
+
* You can use the getPathId method yourself if that information is needed.
|
|
208
|
+
* @param fromClientId The Id of the client that send the message.
|
|
209
|
+
* @param toClientId The Id of the client to receive the message (or empty for
|
|
210
|
+
* a broadcast).
|
|
211
|
+
* @param remainder The remainder of the body of the message.
|
|
212
|
+
* @example
|
|
213
|
+
* This example logs every message routed by the Durable Object between
|
|
214
|
+
* clients.
|
|
215
|
+
*
|
|
216
|
+
* ```js yolo
|
|
217
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
218
|
+
*
|
|
219
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
220
|
+
* onMessage(fromClientId, toClientId, remainder) {
|
|
221
|
+
* console.info(
|
|
222
|
+
* `Message from '${fromClientId}' to '${toClientId}': ${remainder}`,
|
|
223
|
+
* );
|
|
224
|
+
* }
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
99
227
|
* @category Event
|
|
100
228
|
* @since v5.4.0
|
|
101
229
|
*/
|
|
102
|
-
onMessage(
|
|
230
|
+
onMessage(fromClientId: Id, toClientId: Id, remainder: string): void;
|
|
103
231
|
}
|
|
104
232
|
|
|
105
233
|
/**
|
|
106
|
-
* The getWsServerDurableObjectFetch function returns a convenient
|
|
107
|
-
*
|
|
108
|
-
* given namespace.
|
|
234
|
+
* The getWsServerDurableObjectFetch function returns a convenient handler for a
|
|
235
|
+
* Cloudflare worker to route requests to the fetch handler of a
|
|
236
|
+
* WsServerDurableObject for the given namespace.
|
|
237
|
+
*
|
|
238
|
+
* The implementation of the function that this returns requires the request to
|
|
239
|
+
* be a WebSocket 'Upgrade' request, and for the client to have provided a
|
|
240
|
+
* `sec-websocket-key` header that the server can use as a unique key for the
|
|
241
|
+
* client.
|
|
242
|
+
*
|
|
243
|
+
* It then takes the path of the HTTP request and routes the upgrade request to
|
|
244
|
+
* a Durable Object (in the given namespace) for that path. From then on, the
|
|
245
|
+
* Durable Object handles all the WebSocket communication.
|
|
246
|
+
*
|
|
247
|
+
* Note that you'll need to have a Wrangler configuration that connects your
|
|
248
|
+
* Durable Object class to the namespace. In other words, you'll have something
|
|
249
|
+
* like this in your `wrangler.toml` file.
|
|
250
|
+
*
|
|
251
|
+
* ```toml
|
|
252
|
+
* [[durable_objects.bindings]]
|
|
253
|
+
* name = "MyDurableObjects"
|
|
254
|
+
* class_name = "MyDurableObject"
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* Note that it is not required to use this handler to route TinyBase client
|
|
258
|
+
* requests in your Cloudflare app. If you have your own custom routing logic,
|
|
259
|
+
* path scheme, or authentication, for example, you can easily implement that in
|
|
260
|
+
* the worker's fetch method yourself. See the [Durable Objects
|
|
261
|
+
* documentation](https://developers.cloudflare.com/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#invoking-the-fetch-handler)
|
|
262
|
+
* for examples.
|
|
263
|
+
*
|
|
264
|
+
* You can also pass a newly created request to the Durable Object's `fetch`
|
|
265
|
+
* method. For example, you can overwrite the 'path' that the Durable Object
|
|
266
|
+
* thinks it is serving, perhaps to inject a unique authenticated user Id that
|
|
267
|
+
* wasn't actually provided by the client WebSocket.
|
|
268
|
+
* @param namespace A string for the namespace of the Durable Objects that you
|
|
269
|
+
* want this worker to route requests to.
|
|
270
|
+
* @returns A fetch handler that routes WebSocket upgrade requests to a Durable
|
|
271
|
+
* Object.
|
|
272
|
+
* @example
|
|
273
|
+
* This example sets up default routing of the WebSocket upgrade request to a
|
|
274
|
+
* Durable Object in the `MyDurableObjects` namespace. This would require the
|
|
275
|
+
* `wrangler.toml` configuration shown above.
|
|
276
|
+
*
|
|
277
|
+
* ```js yolo
|
|
278
|
+
* import {
|
|
279
|
+
* WsServerDurableObject,
|
|
280
|
+
* getWsServerDurableObjectFetch,
|
|
281
|
+
* } from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
282
|
+
*
|
|
283
|
+
* export class MyDurableObject extends WsServerDurableObject {}
|
|
284
|
+
*
|
|
285
|
+
* export default {fetch: getWsServerDurableObjectFetch('MyDurableObjects')};
|
|
286
|
+
* ```
|
|
109
287
|
* @category Creation
|
|
110
288
|
* @since v5.4.0
|
|
111
289
|
*/
|
|
@@ -22,30 +22,52 @@ import {DurableObject} from 'cloudflare:workers';
|
|
|
22
22
|
*/
|
|
23
23
|
export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
24
24
|
/**
|
|
25
|
-
* The
|
|
26
|
-
*
|
|
25
|
+
* The constructor is used to create the Durable Object that will synchronize
|
|
26
|
+
* the TinyBase clients.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* For basic TinyBase synchronization and persistence, you don't need to
|
|
29
|
+
* override this method, but if you do, ensure you call the super constructor.
|
|
30
|
+
* @returns A new instance of the WsServerDurableObject.
|
|
31
|
+
* @category Creation
|
|
32
|
+
* @since v5.4.0
|
|
33
|
+
*/
|
|
34
|
+
constructor();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The createPersister method is used to return a persister for the Durable
|
|
38
|
+
* Object to preserve Store data when clients are not connected.
|
|
39
|
+
*
|
|
40
|
+
* In other words, override this method to enable persistence of the Store
|
|
41
|
+
* data that the Durable Object is synchronizing between clients.
|
|
42
|
+
*
|
|
43
|
+
* This should almost certainly return a DurableObjectStoragePersister,
|
|
44
|
+
* created with the createDurableObjectStoragePersister function. This will
|
|
45
|
+
* ensure that the Store is serialized to the Durable Object KV-based storage.
|
|
46
|
+
*
|
|
47
|
+
* Returning `undefined` from this method will disable persistence.
|
|
30
48
|
* @example
|
|
31
|
-
* This example
|
|
32
|
-
*
|
|
33
|
-
* WsServerDurableObject instance) and then gets the storage reference back
|
|
34
|
-
* out again.
|
|
49
|
+
* This example enables Durable Object persistence by creating a Persister
|
|
50
|
+
* object within the createPersister method of a WsServerDurableObject.
|
|
35
51
|
*
|
|
36
52
|
* ```js yolo
|
|
53
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
37
54
|
* import {createDurableObjectStoragePersister} from 'tinybase/persisters/persister-durable-object-storage';
|
|
38
55
|
* import {createMergeableStore} from 'tinybase';
|
|
39
56
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
57
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
58
|
+
* createPersister() {
|
|
59
|
+
* const store = createMergeableStore();
|
|
60
|
+
* const persister = createDurableObjectStoragePersister(
|
|
61
|
+
* store,
|
|
62
|
+
* this.ctx.storage,
|
|
63
|
+
* );
|
|
64
|
+
* return persister;
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
48
67
|
* ```
|
|
68
|
+
* @returns A new instance of a DurableObjectStoragePersister (or a promise to
|
|
69
|
+
* resolve one) that will be used to persist data to the Durable Object.
|
|
70
|
+
* Return `undefined` if that functionality is not required.
|
|
49
71
|
* @category Creation
|
|
50
72
|
* @since v5.4.0
|
|
51
73
|
*/
|
|
@@ -57,6 +79,23 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
57
79
|
/**
|
|
58
80
|
* The getPathId method is used to get the Id of the path that is being
|
|
59
81
|
* served.
|
|
82
|
+
*
|
|
83
|
+
* This is useful for when you want to know which path the current Durable
|
|
84
|
+
* Object is serving - for the purposes of logging, for example.
|
|
85
|
+
* @returns The Id of the path being served by the Durable Object.
|
|
86
|
+
* @example
|
|
87
|
+
* This example logs the path being served by the Durable Object every time a
|
|
88
|
+
* synchronization method is handled.
|
|
89
|
+
*
|
|
90
|
+
* ```js yolo
|
|
91
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
92
|
+
*
|
|
93
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
94
|
+
* onMessage() {
|
|
95
|
+
* console.info('Message received on path: ', this.getPathId());
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
60
99
|
* @category Getter
|
|
61
100
|
* @since v5.4.0
|
|
62
101
|
*/
|
|
@@ -64,18 +103,56 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
64
103
|
|
|
65
104
|
/**
|
|
66
105
|
* The getClientIds method is used to access a list of all the connected
|
|
67
|
-
* clients on
|
|
106
|
+
* clients on the path.
|
|
68
107
|
*
|
|
69
|
-
* Note that if you call this method from the onClientId method as a
|
|
70
|
-
* getting removed, it will still be returned in the list of client
|
|
108
|
+
* Note that if you call this method from within the onClientId method as a
|
|
109
|
+
* client is getting removed, it will still be returned in the list of client
|
|
110
|
+
* Ids.
|
|
111
|
+
* @returns The Ids of the clients being served by the Durable Object.
|
|
112
|
+
* @example
|
|
113
|
+
* This example logs the list of clients being served by the Durable Object
|
|
114
|
+
* every time a synchronization method is handled.
|
|
115
|
+
*
|
|
116
|
+
* ```js yolo
|
|
117
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
118
|
+
*
|
|
119
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
120
|
+
* onMessage() {
|
|
121
|
+
* console.info('Clients on path: ', this.getClientIds());
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
71
125
|
* @category Getter
|
|
72
126
|
* @since v5.4.0
|
|
73
127
|
*/
|
|
74
|
-
getClientIds(
|
|
128
|
+
getClientIds(): Ids;
|
|
75
129
|
|
|
76
130
|
/**
|
|
77
131
|
* The onPathId method is called when the first client connects to, or the
|
|
78
132
|
* last client disconnects from, the server with a given path Id.
|
|
133
|
+
*
|
|
134
|
+
* This method is called with the path Id and an IdAddedOrRemoved flag
|
|
135
|
+
* indicating whether it this is being triggered by the first client joining
|
|
136
|
+
* (`1`) or the last client leaving (`-1`).
|
|
137
|
+
* @param pathId The Id of the path being served by the Durable Object.
|
|
138
|
+
* @param addedOrRemoved Whether the path had the first joiner, or the last
|
|
139
|
+
* leaver.
|
|
140
|
+
* @example
|
|
141
|
+
* This example logs the Id of the path being served by the Durable Object
|
|
142
|
+
* when the first client joins (the path Id is 'added'), and when the last
|
|
143
|
+
* client leaves (the path Id is 'removed').
|
|
144
|
+
*
|
|
145
|
+
* ```js yolo
|
|
146
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
147
|
+
*
|
|
148
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
149
|
+
* onPathId(pathId, addedOrRemoved) {
|
|
150
|
+
* console.info(
|
|
151
|
+
* (addedOrRemoved ? 'Added' : 'Removed') + ` path ${pathId}`,
|
|
152
|
+
* );
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
79
156
|
* @category Event
|
|
80
157
|
* @since v5.4.0
|
|
81
158
|
*/
|
|
@@ -84,6 +161,34 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
84
161
|
/**
|
|
85
162
|
* The onClientId method is called when a client connects to, or disconnects
|
|
86
163
|
* from, the server.
|
|
164
|
+
*
|
|
165
|
+
* This method is called with the path Id, the client Id, and an
|
|
166
|
+
* IdAddedOrRemoved flag indicating whether it this is being triggered by
|
|
167
|
+
* the client joining (`1`) or the client leaving (`-1`).
|
|
168
|
+
*
|
|
169
|
+
* Note that if you call the getClientIds method from within this method as a
|
|
170
|
+
* client is getting removed, it will still be returned in the list of client
|
|
171
|
+
* Ids.
|
|
172
|
+
* @param pathId The Id of the path being served by the Durable Object.
|
|
173
|
+
* @param clientId The Id of the client joining or leaving.
|
|
174
|
+
* @param addedOrRemoved Whether the client is joining or leaving.
|
|
175
|
+
* @example
|
|
176
|
+
* This example logs every client that joins (the client Id is 'added') or
|
|
177
|
+
* leaves (the client Id is 'removed') on the path being served by the Durable
|
|
178
|
+
* Object.
|
|
179
|
+
*
|
|
180
|
+
* ```js yolo
|
|
181
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
182
|
+
*
|
|
183
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
184
|
+
* onClientId(pathId, clientId, addedOrRemoved) {
|
|
185
|
+
* console.info(
|
|
186
|
+
* (addedOrRemoved ? 'Added' : 'Removed') +
|
|
187
|
+
* ` client ${clientId} on path ${pathId}`,
|
|
188
|
+
* );
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
87
192
|
* @category Event
|
|
88
193
|
* @since v5.4.0
|
|
89
194
|
*/
|
|
@@ -92,20 +197,93 @@ export class WsServerDurableObject<Env = unknown> extends DurableObject<Env> {
|
|
|
92
197
|
/**
|
|
93
198
|
* The onMessage method is called when a message is handled by the server.
|
|
94
199
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
200
|
+
* This is useful if you want to debug the synchronization process, though be
|
|
201
|
+
* aware that this method is called very frequently. It is called with the Id
|
|
202
|
+
* of the client the message came _from_, the the Id of the client the message
|
|
203
|
+
* is to be forwarded _to_, and the remainder of the message itself.
|
|
204
|
+
*
|
|
205
|
+
* Since this method is called often, it should be performant. The path Id is
|
|
206
|
+
* not passed as an argument, since it has a small cost to provide by default.
|
|
207
|
+
* You can use the getPathId method yourself if that information is needed.
|
|
208
|
+
* @param fromClientId The Id of the client that send the message.
|
|
209
|
+
* @param toClientId The Id of the client to receive the message (or empty for
|
|
210
|
+
* a broadcast).
|
|
211
|
+
* @param remainder The remainder of the body of the message.
|
|
212
|
+
* @example
|
|
213
|
+
* This example logs every message routed by the Durable Object between
|
|
214
|
+
* clients.
|
|
215
|
+
*
|
|
216
|
+
* ```js yolo
|
|
217
|
+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
218
|
+
*
|
|
219
|
+
* export class MyDurableObject extends WsServerDurableObject {
|
|
220
|
+
* onMessage(fromClientId, toClientId, remainder) {
|
|
221
|
+
* console.info(
|
|
222
|
+
* `Message from '${fromClientId}' to '${toClientId}': ${remainder}`,
|
|
223
|
+
* );
|
|
224
|
+
* }
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
99
227
|
* @category Event
|
|
100
228
|
* @since v5.4.0
|
|
101
229
|
*/
|
|
102
|
-
onMessage(
|
|
230
|
+
onMessage(fromClientId: Id, toClientId: Id, remainder: string): void;
|
|
103
231
|
}
|
|
104
232
|
|
|
105
233
|
/**
|
|
106
|
-
* The getWsServerDurableObjectFetch function returns a convenient
|
|
107
|
-
*
|
|
108
|
-
* given namespace.
|
|
234
|
+
* The getWsServerDurableObjectFetch function returns a convenient handler for a
|
|
235
|
+
* Cloudflare worker to route requests to the fetch handler of a
|
|
236
|
+
* WsServerDurableObject for the given namespace.
|
|
237
|
+
*
|
|
238
|
+
* The implementation of the function that this returns requires the request to
|
|
239
|
+
* be a WebSocket 'Upgrade' request, and for the client to have provided a
|
|
240
|
+
* `sec-websocket-key` header that the server can use as a unique key for the
|
|
241
|
+
* client.
|
|
242
|
+
*
|
|
243
|
+
* It then takes the path of the HTTP request and routes the upgrade request to
|
|
244
|
+
* a Durable Object (in the given namespace) for that path. From then on, the
|
|
245
|
+
* Durable Object handles all the WebSocket communication.
|
|
246
|
+
*
|
|
247
|
+
* Note that you'll need to have a Wrangler configuration that connects your
|
|
248
|
+
* Durable Object class to the namespace. In other words, you'll have something
|
|
249
|
+
* like this in your `wrangler.toml` file.
|
|
250
|
+
*
|
|
251
|
+
* ```toml
|
|
252
|
+
* [[durable_objects.bindings]]
|
|
253
|
+
* name = "MyDurableObjects"
|
|
254
|
+
* class_name = "MyDurableObject"
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* Note that it is not required to use this handler to route TinyBase client
|
|
258
|
+
* requests in your Cloudflare app. If you have your own custom routing logic,
|
|
259
|
+
* path scheme, or authentication, for example, you can easily implement that in
|
|
260
|
+
* the worker's fetch method yourself. See the [Durable Objects
|
|
261
|
+
* documentation](https://developers.cloudflare.com/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#invoking-the-fetch-handler)
|
|
262
|
+
* for examples.
|
|
263
|
+
*
|
|
264
|
+
* You can also pass a newly created request to the Durable Object's `fetch`
|
|
265
|
+
* method. For example, you can overwrite the 'path' that the Durable Object
|
|
266
|
+
* thinks it is serving, perhaps to inject a unique authenticated user Id that
|
|
267
|
+
* wasn't actually provided by the client WebSocket.
|
|
268
|
+
* @param namespace A string for the namespace of the Durable Objects that you
|
|
269
|
+
* want this worker to route requests to.
|
|
270
|
+
* @returns A fetch handler that routes WebSocket upgrade requests to a Durable
|
|
271
|
+
* Object.
|
|
272
|
+
* @example
|
|
273
|
+
* This example sets up default routing of the WebSocket upgrade request to a
|
|
274
|
+
* Durable Object in the `MyDurableObjects` namespace. This would require the
|
|
275
|
+
* `wrangler.toml` configuration shown above.
|
|
276
|
+
*
|
|
277
|
+
* ```js yolo
|
|
278
|
+
* import {
|
|
279
|
+
* WsServerDurableObject,
|
|
280
|
+
* getWsServerDurableObjectFetch,
|
|
281
|
+
* } from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
|
|
282
|
+
*
|
|
283
|
+
* export class MyDurableObject extends WsServerDurableObject {}
|
|
284
|
+
*
|
|
285
|
+
* export default {fetch: getWsServerDurableObjectFetch('MyDurableObjects')};
|
|
286
|
+
* ```
|
|
109
287
|
* @category Creation
|
|
110
288
|
* @since v5.4.0
|
|
111
289
|
*/
|