@livestore/sync-cf 0.4.0-dev.20 → 0.4.0-dev.21
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/README.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/cf-worker/do/durable-object.d.ts +1 -1
- package/dist/cf-worker/do/durable-object.js +1 -1
- package/dist/cf-worker/do/layer.d.ts +2 -2
- package/dist/cf-worker/do/layer.js +1 -1
- package/dist/cf-worker/do/sqlite.d.ts +1 -1
- package/dist/cf-worker/do/sqlite.js +1 -1
- package/dist/cf-worker/worker.d.ts +1 -1
- package/dist/common/do-rpc-schema.d.ts +3 -3
- package/dist/common/do-rpc-schema.js +1 -1
- package/package.json +4 -4
- package/src/cf-worker/do/durable-object.ts +1 -1
- package/src/cf-worker/do/layer.ts +1 -1
- package/src/cf-worker/do/sqlite.ts +1 -1
- package/src/cf-worker/worker.ts +1 -1
- package/src/common/do-rpc-schema.ts +1 -1
|
@@ -7,7 +7,7 @@ export type MakeDurableObjectClass = (options?: MakeDurableObjectClassOptions) =
|
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Creates a Durable Object class for handling WebSocket-based sync.
|
|
10
|
-
* A sync
|
|
10
|
+
* A sync Durable Object is uniquely scoped to a specific `storeId`.
|
|
11
11
|
*
|
|
12
12
|
* The sync DO supports 3 transport modes:
|
|
13
13
|
* - HTTP JSON-RPC
|
|
@@ -11,7 +11,7 @@ import { makeRpcServer } from "./transport/ws-rpc-server.js";
|
|
|
11
11
|
const DurableObjectBase = (DurableObject);
|
|
12
12
|
/**
|
|
13
13
|
* Creates a Durable Object class for handling WebSocket-based sync.
|
|
14
|
-
* A sync
|
|
14
|
+
* A sync Durable Object is uniquely scoped to a specific `storeId`.
|
|
15
15
|
*
|
|
16
16
|
* The sync DO supports 3 transport modes:
|
|
17
17
|
* - HTTP JSON-RPC
|
|
@@ -14,7 +14,7 @@ export interface DoCtxInput {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
declare const DoCtx_base: Effect.Service.Class<DoCtx, "DoCtx", {
|
|
17
|
-
readonly effect: (args_0: DoCtxInput) => Effect.Effect
|
|
17
|
+
readonly effect: (args_0: DoCtxInput) => Effect.Effect<{
|
|
18
18
|
storeId: string;
|
|
19
19
|
backendId: string;
|
|
20
20
|
currentHeadRef: {
|
|
@@ -26,7 +26,7 @@ declare const DoCtx_base: Effect.Service.Class<DoCtx, "DoCtx", {
|
|
|
26
26
|
env: Env;
|
|
27
27
|
ctx: CfTypes.DurableObjectState<unknown>;
|
|
28
28
|
rpcSubscriptions: Map<string, RpcSubscription>;
|
|
29
|
-
}, UnknownError, never
|
|
29
|
+
}, UnknownError, never>;
|
|
30
30
|
}>;
|
|
31
31
|
export declare class DoCtx extends DoCtx_base {
|
|
32
32
|
}
|
|
@@ -58,7 +58,7 @@ export class DoCtx extends Effect.Service()('DoCtx', {
|
|
|
58
58
|
.toArray()[0];
|
|
59
59
|
const currentHeadRef = { current: storageRow?.currentHead ?? EventSequenceNumber.Client.ROOT.global };
|
|
60
60
|
// TODO do concistency check with eventlog table to make sure the head is consistent
|
|
61
|
-
// Should be the same backendId for lifetime of the
|
|
61
|
+
// Should be the same backendId for lifetime of the Durable Object
|
|
62
62
|
const backendId = storageRow?.backendId ?? nanoid();
|
|
63
63
|
const updateCurrentHead = (currentHead) => {
|
|
64
64
|
doSelf.ctx.storage.sql.exec(`INSERT OR REPLACE INTO "${contextTable.sqliteDef.name}" (storeId, currentHead, backendId) VALUES (?, ?, ?)`, storeId, currentHead, backendId);
|
|
@@ -139,7 +139,7 @@ export declare const eventlogTable: State.SQLite.TableDef<State.SQLite.SqliteTab
|
|
|
139
139
|
readonly sessionId: string;
|
|
140
140
|
}, never>>;
|
|
141
141
|
/**
|
|
142
|
-
* Context metadata table - one row per
|
|
142
|
+
* Context metadata table - one row per Durable Object.
|
|
143
143
|
*
|
|
144
144
|
* ⚠️ IMPORTANT: Any changes to this schema require bumping PERSISTENCE_FORMAT_VERSION in shared.ts
|
|
145
145
|
*/
|
|
@@ -21,7 +21,7 @@ export const eventlogTable = State.SQLite.table({
|
|
|
21
21
|
},
|
|
22
22
|
});
|
|
23
23
|
/**
|
|
24
|
-
* Context metadata table - one row per
|
|
24
|
+
* Context metadata table - one row per Durable Object.
|
|
25
25
|
*
|
|
26
26
|
* ⚠️ IMPORTANT: Any changes to this schema require bumping PERSISTENCE_FORMAT_VERSION in shared.ts
|
|
27
27
|
*/
|
|
@@ -17,7 +17,7 @@ export type MakeWorkerOptions<TEnv extends Env = Env, TSyncPayload = Schema.Json
|
|
|
17
17
|
/**
|
|
18
18
|
* Validates the payload during WebSocket connection establishment.
|
|
19
19
|
* Note: This runs only at connection time, not for individual push events.
|
|
20
|
-
* For push event validation, use the `onPush` callback in the
|
|
20
|
+
* For push event validation, use the `onPush` callback in the Durable Object.
|
|
21
21
|
*/
|
|
22
22
|
/**
|
|
23
23
|
* Optionally pass a schema to decode the client-provided payload into a typed object
|
|
@@ -2,7 +2,7 @@ import { InvalidPullError, InvalidPushError } from '@livestore/common';
|
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
3
|
declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema.Struct<{
|
|
4
4
|
/**
|
|
5
|
-
* While the storeId is already implied by the
|
|
5
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
6
6
|
* since a DO doesn't know its own id.name value. 🫠
|
|
7
7
|
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
8
8
|
*/
|
|
@@ -44,7 +44,7 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
44
44
|
rpcRequestId: typeof Schema.String;
|
|
45
45
|
}>, typeof InvalidPullError>, typeof Schema.Never, never> | Rpc.Rpc<"SyncDoRpc.Push", Schema.Struct<{
|
|
46
46
|
/**
|
|
47
|
-
* While the storeId is already implied by the
|
|
47
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
48
48
|
* since a DO doesn't know its own id.name value. 🫠
|
|
49
49
|
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
50
50
|
*/
|
|
@@ -62,7 +62,7 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
62
62
|
backendId: Schema.Option<Schema.SchemaClass<string, string, never>>;
|
|
63
63
|
}>, Schema.Struct<{}>, typeof InvalidPushError, never> | Rpc.Rpc<"SyncDoRpc.Ping", Schema.Struct<{
|
|
64
64
|
/**
|
|
65
|
-
* While the storeId is already implied by the
|
|
65
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
66
66
|
* since a DO doesn't know its own id.name value. 🫠
|
|
67
67
|
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
68
68
|
*/
|
|
@@ -3,7 +3,7 @@ import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
|
3
3
|
import * as SyncMessage from "./sync-message-types.js";
|
|
4
4
|
const commonPayloadFields = {
|
|
5
5
|
/**
|
|
6
|
-
* While the storeId is already implied by the
|
|
6
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
7
7
|
* since a DO doesn't know its own id.name value. 🫠
|
|
8
8
|
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
9
9
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/sync-cf",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@cloudflare/workers-types": "4.20251118.0",
|
|
13
|
-
"@livestore/common": "0.4.0-dev.
|
|
14
|
-
"@livestore/utils": "0.4.0-dev.
|
|
15
|
-
"@livestore/common-cf": "0.4.0-dev.
|
|
13
|
+
"@livestore/common": "0.4.0-dev.21",
|
|
14
|
+
"@livestore/utils": "0.4.0-dev.21",
|
|
15
|
+
"@livestore/common-cf": "0.4.0-dev.21"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
@@ -48,7 +48,7 @@ export type MakeDurableObjectClass = (options?: MakeDurableObjectClassOptions) =
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a Durable Object class for handling WebSocket-based sync.
|
|
51
|
-
* A sync
|
|
51
|
+
* A sync Durable Object is uniquely scoped to a specific `storeId`.
|
|
52
52
|
*
|
|
53
53
|
* The sync DO supports 3 transport modes:
|
|
54
54
|
* - HTTP JSON-RPC
|
|
@@ -81,7 +81,7 @@ export class DoCtx extends Effect.Service<DoCtx>()('DoCtx', {
|
|
|
81
81
|
|
|
82
82
|
// TODO do concistency check with eventlog table to make sure the head is consistent
|
|
83
83
|
|
|
84
|
-
// Should be the same backendId for lifetime of the
|
|
84
|
+
// Should be the same backendId for lifetime of the Durable Object
|
|
85
85
|
const backendId = storageRow?.backendId ?? nanoid()
|
|
86
86
|
|
|
87
87
|
const updateCurrentHead = (currentHead: EventSequenceNumber.Global.Type) => {
|
|
@@ -23,7 +23,7 @@ export const eventlogTable = State.SQLite.table({
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Context metadata table - one row per
|
|
26
|
+
* Context metadata table - one row per Durable Object.
|
|
27
27
|
*
|
|
28
28
|
* ⚠️ IMPORTANT: Any changes to this schema require bumping PERSISTENCE_FORMAT_VERSION in shared.ts
|
|
29
29
|
*/
|
package/src/cf-worker/worker.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type MakeWorkerOptions<TEnv extends Env = Env, TSyncPayload = Schema.Json
|
|
|
30
30
|
/**
|
|
31
31
|
* Validates the payload during WebSocket connection establishment.
|
|
32
32
|
* Note: This runs only at connection time, not for individual push events.
|
|
33
|
-
* For push event validation, use the `onPush` callback in the
|
|
33
|
+
* For push event validation, use the `onPush` callback in the Durable Object.
|
|
34
34
|
*/
|
|
35
35
|
/**
|
|
36
36
|
* Optionally pass a schema to decode the client-provided payload into a typed object
|
|
@@ -4,7 +4,7 @@ import * as SyncMessage from './sync-message-types.ts'
|
|
|
4
4
|
|
|
5
5
|
const commonPayloadFields = {
|
|
6
6
|
/**
|
|
7
|
-
* While the storeId is already implied by the
|
|
7
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
8
8
|
* since a DO doesn't know its own id.name value. 🫠
|
|
9
9
|
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
10
10
|
*/
|