@livestore/sync-cf 0.5.0-dev.0 → 0.5.0-dev.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/README.md +5 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/cf-worker/do/durable-object.d.ts.map +1 -1
- package/dist/cf-worker/do/durable-object.js +34 -30
- package/dist/cf-worker/do/durable-object.js.map +1 -1
- package/dist/cf-worker/do/layer.d.ts.map +1 -1
- package/dist/cf-worker/do/layer.js +2 -2
- package/dist/cf-worker/do/observability.d.ts +23 -0
- package/dist/cf-worker/do/observability.d.ts.map +1 -0
- package/dist/cf-worker/do/observability.js +52 -0
- package/dist/cf-worker/do/observability.js.map +1 -0
- package/dist/cf-worker/do/observability.test.d.ts +2 -0
- package/dist/cf-worker/do/observability.test.d.ts.map +1 -0
- package/dist/cf-worker/do/observability.test.js +204 -0
- package/dist/cf-worker/do/observability.test.js.map +1 -0
- package/dist/cf-worker/do/pull.d.ts.map +1 -1
- package/dist/cf-worker/do/pull.js +3 -3
- package/dist/cf-worker/do/push.d.ts +2 -2
- package/dist/cf-worker/do/push.d.ts.map +1 -1
- package/dist/cf-worker/do/push.js +7 -6
- package/dist/cf-worker/do/push.js.map +1 -1
- package/dist/cf-worker/do/push.test.js +1 -1
- package/dist/cf-worker/do/sqlite.js +1 -1
- package/dist/cf-worker/do/sync-storage.d.ts.map +1 -1
- package/dist/cf-worker/do/sync-storage.js +3 -3
- package/dist/cf-worker/do/transport/do-rpc-server.d.ts +15 -0
- package/dist/cf-worker/do/transport/do-rpc-server.d.ts.map +1 -1
- package/dist/cf-worker/do/transport/do-rpc-server.js +23 -7
- package/dist/cf-worker/do/transport/do-rpc-server.js.map +1 -1
- package/dist/cf-worker/do/transport/do-rpc-server.test.d.ts +2 -0
- package/dist/cf-worker/do/transport/do-rpc-server.test.d.ts.map +1 -0
- package/dist/cf-worker/do/transport/do-rpc-server.test.js +28 -0
- package/dist/cf-worker/do/transport/do-rpc-server.test.js.map +1 -0
- package/dist/cf-worker/do/transport/http-rpc-server.js +6 -6
- package/dist/cf-worker/do/transport/ws-rpc-server.d.ts +8 -1
- package/dist/cf-worker/do/transport/ws-rpc-server.d.ts.map +1 -1
- package/dist/cf-worker/do/transport/ws-rpc-server.js +32 -24
- package/dist/cf-worker/do/transport/ws-rpc-server.js.map +1 -1
- package/dist/cf-worker/mod.js +3 -3
- package/dist/cf-worker/shared.d.ts +17 -12
- package/dist/cf-worker/shared.d.ts.map +1 -1
- package/dist/cf-worker/shared.js +2 -2
- package/dist/cf-worker/shared.js.map +1 -1
- package/dist/cf-worker/worker.d.ts +3 -3
- package/dist/cf-worker/worker.d.ts.map +1 -1
- package/dist/cf-worker/worker.js +2 -2
- package/dist/cf-worker/worker.js.map +1 -1
- package/dist/client/mod.js +3 -3
- package/dist/client/transport/do-rpc-client.d.ts +6 -3
- package/dist/client/transport/do-rpc-client.d.ts.map +1 -1
- package/dist/client/transport/do-rpc-client.js +65 -20
- package/dist/client/transport/do-rpc-client.js.map +1 -1
- package/dist/client/transport/do-rpc-client.test.d.ts +2 -0
- package/dist/client/transport/do-rpc-client.test.d.ts.map +1 -0
- package/dist/client/transport/do-rpc-client.test.js +268 -0
- package/dist/client/transport/do-rpc-client.test.js.map +1 -0
- package/dist/client/transport/http-rpc-client.d.ts.map +1 -1
- package/dist/client/transport/http-rpc-client.js +20 -10
- package/dist/client/transport/http-rpc-client.js.map +1 -1
- package/dist/client/transport/rpc-client-error.d.ts +5 -0
- package/dist/client/transport/rpc-client-error.d.ts.map +1 -0
- package/dist/client/transport/rpc-client-error.js +8 -0
- package/dist/client/transport/rpc-client-error.js.map +1 -0
- package/dist/client/transport/rpc-client-error.test.d.ts +2 -0
- package/dist/client/transport/rpc-client-error.test.d.ts.map +1 -0
- package/dist/client/transport/rpc-client-error.test.js +33 -0
- package/dist/client/transport/rpc-client-error.test.js.map +1 -0
- package/dist/client/transport/ws-rpc-client.d.ts.map +1 -1
- package/dist/client/transport/ws-rpc-client.js +18 -12
- package/dist/client/transport/ws-rpc-client.js.map +1 -1
- package/dist/common/do-rpc-schema.d.ts +24 -11
- package/dist/common/do-rpc-schema.d.ts.map +1 -1
- package/dist/common/do-rpc-schema.js +10 -1
- package/dist/common/do-rpc-schema.js.map +1 -1
- package/dist/common/http-rpc-schema.d.ts +8 -8
- package/dist/common/http-rpc-schema.js +1 -1
- package/dist/common/mod.d.ts +1 -0
- package/dist/common/mod.d.ts.map +1 -1
- package/dist/common/mod.js +4 -3
- package/dist/common/mod.js.map +1 -1
- package/dist/common/sync-message-types.d.ts.map +1 -1
- package/dist/common/ws-rpc-schema.d.ts +1 -1
- package/dist/common/ws-rpc-schema.js +1 -1
- package/package.json +41 -41
- package/src/cf-worker/do/durable-object.ts +42 -45
- package/src/cf-worker/do/observability.test.ts +337 -0
- package/src/cf-worker/do/observability.ts +121 -0
- package/src/cf-worker/do/push.ts +3 -2
- package/src/cf-worker/do/transport/do-rpc-server.test.ts +32 -0
- package/src/cf-worker/do/transport/do-rpc-server.ts +23 -1
- package/src/cf-worker/do/transport/ws-rpc-server.ts +45 -21
- package/src/cf-worker/shared.ts +13 -6
- package/src/cf-worker/worker.ts +1 -1
- package/src/client/transport/do-rpc-client.test.ts +411 -0
- package/src/client/transport/do-rpc-client.ts +100 -18
- package/src/client/transport/http-rpc-client.ts +20 -9
- package/src/client/transport/rpc-client-error.test.ts +41 -0
- package/src/client/transport/rpc-client-error.ts +9 -0
- package/src/client/transport/ws-rpc-client.ts +15 -10
- package/src/common/do-rpc-schema.ts +10 -0
- package/src/common/mod.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client-error.js","sourceRoot":"","sources":["../../../src/client/transport/rpc-client-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAuB,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAE7E,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAoC,EAAiC,EAAE,CACvG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IAC1D,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,CAAC;IAC3E,CAAC,CAAC,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IAC7C,CAAC,CAAC,IAAI,YAAY,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client-error.test.d.ts","sourceRoot":"","sources":["../../../src/client/transport/rpc-client-error.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { IsOfflineError, UnknownError } from '@livestore/common';
|
|
3
|
+
import { HttpClientError, RpcClientError, Socket } from '@livestore/utils/effect';
|
|
4
|
+
import { mapRpcClientError } from './rpc-client-error.js';
|
|
5
|
+
const socketReasons = [
|
|
6
|
+
new Socket.SocketCloseError({ code: 1012, closeReason: 'Restart' }),
|
|
7
|
+
new Socket.SocketReadError({ cause: new Error('Disconnected') }),
|
|
8
|
+
new Socket.SocketWriteError({ cause: new Error('Disconnected') }),
|
|
9
|
+
new Socket.SocketOpenError({ kind: 'Timeout', cause: new Error('Unavailable') }),
|
|
10
|
+
new Socket.SocketUpgradeError({ cause: new Error('Upgrade failed') }),
|
|
11
|
+
];
|
|
12
|
+
it.each(socketReasons)('maps $\u005ftag to offline', (reason) => {
|
|
13
|
+
const result = mapRpcClientError(new RpcClientError.RpcClientError({ reason }));
|
|
14
|
+
expect(result).toBeInstanceOf(IsOfflineError);
|
|
15
|
+
expect(result.cause).toBe(reason);
|
|
16
|
+
});
|
|
17
|
+
it('maps an HTTP transport failure to offline', () => {
|
|
18
|
+
const reason = new HttpClientError.HttpClientErrorSchema({ kind: 'TransportError' });
|
|
19
|
+
const result = mapRpcClientError(new RpcClientError.RpcClientError({ reason }));
|
|
20
|
+
expect(result).toBeInstanceOf(IsOfflineError);
|
|
21
|
+
expect(result.cause).toBe(reason);
|
|
22
|
+
});
|
|
23
|
+
const protocolReasons = [
|
|
24
|
+
new RpcClientError.RpcClientDefect({ message: 'Malformed RPC response', cause: new Error('Invalid message') }),
|
|
25
|
+
...['EncodeError', 'DecodeError', 'InvalidUrlError', 'StatusCodeError', 'EmptyBodyError'].map((kind) => new HttpClientError.HttpClientErrorSchema({ kind })),
|
|
26
|
+
];
|
|
27
|
+
it.each(protocolReasons)('keeps protocol failure $\u005ftag terminal', (reason) => {
|
|
28
|
+
const error = new RpcClientError.RpcClientError({ reason });
|
|
29
|
+
const result = mapRpcClientError(error);
|
|
30
|
+
expect(result).toBeInstanceOf(UnknownError);
|
|
31
|
+
expect(result.cause).toBe(error);
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=rpc-client-error.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client-error.test.js","sourceRoot":"","sources":["../../../src/client/transport/rpc-client-error.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,aAAa,GAAG;IACpB,IAAI,MAAM,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,CA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,GAAG;IACtB,IAAI,cAAc,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAC9G,GAAI,CAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,CAAW,CAAC,GAAG,CACtG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,CAAC,CAC9D;CACF,CAAA;AAED,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,4CAA4C,EAAE,CAAC,MAAM,EAAE,EAAE;IAChF,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3D,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACvC,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IAC3C,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-rpc-client.d.ts","sourceRoot":"","sources":["../../../src/client/transport/ws-rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ws-rpc-client.d.ts","sourceRoot":"","sources":["../../../src/client/transport/ws-rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,mBAAmB,CAAA;AAG7D,OAAO,EACL,QAAQ,EACR,MAAM,EAQN,KAAK,KAAK,EAMX,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAItE,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;IAChH,IAAI,CAAC,EAAE;QACL;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB;;;WAGG;QACH,cAAc,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;QAC/B;;;WAGG;QACH,eAAe,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;KACjC,CAAA;CACF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,YACX,aAAa,KAAG,WAAW,CAAC,sBAAsB,CAAC,YAAY,CA8IrE,CAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyncBackend, UnknownError } from '@livestore/common';
|
|
2
2
|
import { splitArrayBySize } from '@livestore/common/sync';
|
|
3
3
|
import { Duration, Effect, Layer, Option, ReadonlyArray as EffectArray, RpcClient, RpcSerialization, Schedule, Schema, Socket, Stream, Struct, SubscriptionRef, UrlParams, } from '@livestore/utils/effect';
|
|
4
|
-
import { MAX_PUSH_EVENTS_PER_REQUEST, MAX_WS_MESSAGE_BYTES } from
|
|
5
|
-
import { SearchParamsSchema } from
|
|
6
|
-
import { SyncWsRpc } from
|
|
4
|
+
import { MAX_PUSH_EVENTS_PER_REQUEST, MAX_WS_MESSAGE_BYTES } from '../../common/constants.js';
|
|
5
|
+
import { SearchParamsSchema } from '../../common/mod.js';
|
|
6
|
+
import { SyncWsRpc } from '../../common/ws-rpc-schema.js';
|
|
7
|
+
import { mapRpcClientError } from './rpc-client-error.js';
|
|
7
8
|
/**
|
|
8
9
|
* Creates a sync backend that uses WebSocket to communicate with the sync backend.
|
|
9
10
|
*
|
|
@@ -48,7 +49,10 @@ export const makeWsSync = (options) => ({ storeId, payload }) => Effect.gen(func
|
|
|
48
49
|
const pinger = yield* RpcClient.SocketPinger.pipe(Effect.provide(ctx));
|
|
49
50
|
yield* pinger.ping;
|
|
50
51
|
yield* SubscriptionRef.set(isConnected, true);
|
|
51
|
-
}).pipe(Effect.
|
|
52
|
+
}).pipe(Effect.timeoutOrElse({
|
|
53
|
+
duration: pingTimeout,
|
|
54
|
+
orElse: () => SubscriptionRef.set(isConnected, false),
|
|
55
|
+
}), UnknownError.mapToUnknownError, Effect.withSpan('ping'));
|
|
52
56
|
const backendIdHelper = yield* SyncBackend.makeBackendIdHelper;
|
|
53
57
|
return SyncBackend.of({
|
|
54
58
|
isConnected,
|
|
@@ -61,8 +65,8 @@ export const makeWsSync = (options) => ({ storeId, payload }) => Effect.gen(func
|
|
|
61
65
|
backendId: backendIdHelper.get().pipe(Option.getOrThrow),
|
|
62
66
|
}))),
|
|
63
67
|
live: options?.live === true,
|
|
64
|
-
}).pipe(Stream.tap((res) => backendIdHelper.lazySet(res.backendId)), Stream.map((res) => Struct.omit(res, ['backendId'])), Stream.mapError((cause) => cause._tag === 'RpcClientError'
|
|
65
|
-
?
|
|
68
|
+
}).pipe(Stream.tap((res) => backendIdHelper.lazySet(res.backendId)), Stream.map((res) => Struct.omit(res, ['backendId'])), Stream.mapError((cause) => cause._tag === 'RpcClientError'
|
|
69
|
+
? mapRpcClientError(cause)
|
|
66
70
|
: cause._tag === 'UnknownError' || cause._tag === 'BackendIdMismatchError'
|
|
67
71
|
? cause
|
|
68
72
|
: new UnknownError({ cause })), Stream.withSpan('pull')),
|
|
@@ -89,11 +93,13 @@ export const makeWsSync = (options) => ({ storeId, payload }) => Effect.gen(func
|
|
|
89
93
|
payload,
|
|
90
94
|
batch: batchChunk,
|
|
91
95
|
backendId: backendIdHelper.get(),
|
|
92
|
-
}).pipe(Effect.mapError((cause) => cause._tag === '
|
|
93
|
-
cause
|
|
94
|
-
cause._tag === '
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
}).pipe(Effect.mapError((cause) => cause._tag === 'RpcClientError'
|
|
97
|
+
? mapRpcClientError(cause)
|
|
98
|
+
: cause._tag === 'UnknownError' ||
|
|
99
|
+
cause._tag === 'ServerAheadError' ||
|
|
100
|
+
cause._tag === 'BackendIdMismatchError'
|
|
101
|
+
? cause
|
|
102
|
+
: new UnknownError({ cause })));
|
|
97
103
|
}
|
|
98
104
|
}),
|
|
99
105
|
ping,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-rpc-client.js","sourceRoot":"","sources":["../../../src/client/transport/ws-rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ws-rpc-client.js","sourceRoot":"","sources":["../../../src/client/transport/ws-rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,aAAa,IAAI,WAAW,EAC5B,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,MAAM,EAEN,MAAM,EACN,MAAM,EACN,MAAM,EACN,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAkCzD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,OAAsB,EAAoD,EAAE,CAC7E,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CACvB,MAAM,CAAC,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,oBAAoB;YAC1B,WAAW,EAAE,kFAAkF;YAC/F,QAAQ,EAAE,IAAI;YACd,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,IAAI;YACvB,QAAQ,EAAE,IAAI;SACf;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
|
-
declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.
|
|
3
|
+
declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Ping", Schema.Struct<{
|
|
4
|
+
/**
|
|
5
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
6
|
+
* since a DO doesn't know its own id.name value. 🫠
|
|
7
|
+
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
8
|
+
*/
|
|
9
|
+
storeId: Schema.String;
|
|
10
|
+
/** Needed for various reasons (e.g. auth) */
|
|
11
|
+
payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
12
|
+
}>, Schema.Void, Schema.Never, never, never> | Rpc.Rpc<"SyncDoRpc.Pull", Schema.Struct<{
|
|
4
13
|
/**
|
|
5
14
|
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
6
15
|
* since a DO doesn't know its own id.name value. 🫠
|
|
@@ -21,7 +30,7 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
21
30
|
readonly durableObjectId: Schema.String;
|
|
22
31
|
}>;
|
|
23
32
|
}>>;
|
|
24
|
-
}>, import("effect/
|
|
33
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Struct<{
|
|
25
34
|
readonly batch: Schema.$Array<Schema.Struct<{
|
|
26
35
|
readonly eventEncoded: Schema.Struct<{
|
|
27
36
|
readonly name: Schema.String;
|
|
@@ -42,14 +51,6 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
42
51
|
readonly backendId: Schema.String;
|
|
43
52
|
readonly rpcRequestId: Schema.String;
|
|
44
53
|
}>, Schema.Union<readonly [typeof UnknownError, typeof BackendIdMismatchError]>>, Schema.Never, never, never> | Rpc.Rpc<"SyncDoRpc.Push", Schema.Struct<{
|
|
45
|
-
/**
|
|
46
|
-
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
47
|
-
* since a DO doesn't know its own id.name value. 🫠
|
|
48
|
-
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
49
|
-
*/
|
|
50
|
-
storeId: Schema.String;
|
|
51
|
-
/** Needed for various reasons (e.g. auth) */
|
|
52
|
-
payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
53
54
|
batch: Schema.$Array<Schema.Struct<{
|
|
54
55
|
readonly name: Schema.String;
|
|
55
56
|
readonly args: Schema.Any;
|
|
@@ -59,7 +60,6 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
59
60
|
readonly sessionId: Schema.String;
|
|
60
61
|
}>>;
|
|
61
62
|
backendId: Schema.Option<Schema.String>;
|
|
62
|
-
}>, Schema.Struct<{}>, Schema.Union<readonly [typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never, never> | Rpc.Rpc<"SyncDoRpc.Ping", Schema.Struct<{
|
|
63
63
|
/**
|
|
64
64
|
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
65
65
|
* since a DO doesn't know its own id.name value. 🫠
|
|
@@ -68,6 +68,19 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
|
|
|
68
68
|
storeId: Schema.String;
|
|
69
69
|
/** Needed for various reasons (e.g. auth) */
|
|
70
70
|
payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
71
|
+
}>, Schema.Struct<{}>, Schema.Union<readonly [typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never, never> | Rpc.Rpc<"SyncDoRpc.Unsubscribe", Schema.Struct<{
|
|
72
|
+
/**
|
|
73
|
+
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
74
|
+
* since a DO doesn't know its own id.name value. 🫠
|
|
75
|
+
* https://community.cloudflare.com/t/how-can-i-get-the-name-of-a-durable-object-from-itself/505961/8
|
|
76
|
+
*/
|
|
77
|
+
storeId: Schema.String;
|
|
78
|
+
/** Needed for various reasons (e.g. auth) */
|
|
79
|
+
payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
80
|
+
/** Client DO id whose live-pull subscription row to drop. */
|
|
81
|
+
durableObjectId: Schema.String;
|
|
82
|
+
/** Request id of the live pull that registered the row; the row is only dropped if it still matches. */
|
|
83
|
+
requestId: Schema.String;
|
|
71
84
|
}>, Schema.Void, Schema.Never, never, never>>;
|
|
72
85
|
export declare class SyncDoRpc extends SyncDoRpc_base {
|
|
73
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"do-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/do-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC1F,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;;IAK7D;;;;OAIG;;IAEH,6CAA6C;;IAOzC,wDAAwD;;;;;IAGxD,qEAAqE
|
|
1
|
+
{"version":3,"file":"do-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/do-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC1F,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;;IAK7D;;;;OAIG;;IAEH,6CAA6C;;;IAN7C;;;;OAIG;;IAEH,6CAA6C;;IAOzC,wDAAwD;;;;;IAGxD,qEAAqE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAhBzE;;;;OAIG;;IAEH,6CAA6C;;;IAN7C;;;;OAIG;;IAEH,6CAA6C;;IA4CzC,6DAA6D;;IAE7D,wGAAwG;;;AA1C9G,qBAAa,SAAU,SAAQ,cAgD9B;CAAG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
|
-
import * as SyncMessage from
|
|
3
|
+
import * as SyncMessage from './sync-message-types.js';
|
|
4
4
|
const commonPayloadFields = {
|
|
5
5
|
/**
|
|
6
6
|
* While the storeId is already implied by the Durable Object, we still need the explicit storeId
|
|
@@ -43,6 +43,15 @@ export class SyncDoRpc extends RpcGroup.make(Rpc.make('SyncDoRpc.Pull', {
|
|
|
43
43
|
...commonPayloadFields,
|
|
44
44
|
},
|
|
45
45
|
success: Schema.Void,
|
|
46
|
+
}), Rpc.make('SyncDoRpc.Unsubscribe', {
|
|
47
|
+
payload: {
|
|
48
|
+
/** Client DO id whose live-pull subscription row to drop. */
|
|
49
|
+
durableObjectId: Schema.String,
|
|
50
|
+
/** Request id of the live pull that registered the row; the row is only dropped if it still matches. */
|
|
51
|
+
requestId: Schema.String,
|
|
52
|
+
...commonPayloadFields,
|
|
53
|
+
},
|
|
54
|
+
success: Schema.Void,
|
|
46
55
|
})) {
|
|
47
56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MAAM,CAAC,MAAM;gBAC1B,eAAe,EAAE,MAAM,CAAC,MAAM;aAC/B,CAAC;SACH,CAAC,CACH;QACD,GAAG,mBAAmB;KACvB;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC,MAAM;QAC3B,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM;KACnC,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;IAC3D,MAAM,EAAE,IAAI;CACb,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACzB,OAAO,EAAE;QACP,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM;QACjC,GAAG,mBAAmB;KACvB;IACD,OAAO,EAAE,WAAW,CAAC,OAAO;IAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;CAC9E,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACzB,OAAO,EAAE;QACP,GAAG,mBAAmB;KACvB;IACD,OAAO,EAAE,MAAM,CAAC,IAAI;CACrB,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE;IAChC,OAAO,EAAE;QACP,6DAA6D;QAC7D,eAAe,EAAE,MAAM,CAAC,MAAM;QAC9B,wGAAwG;QACxG,SAAS,EAAE,MAAM,CAAC,MAAM;QACxB,GAAG,mBAAmB;KACvB;IACD,OAAO,EAAE,MAAM,CAAC,IAAI;CACrB,CAAC,CACH;CAAG"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
|
-
declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.
|
|
3
|
+
declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.Ping", Schema.Struct<{
|
|
4
|
+
readonly storeId: Schema.String;
|
|
5
|
+
readonly payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
6
|
+
}>, Schema.Struct<{
|
|
7
|
+
readonly _tag: Schema.tag<"SyncMessage.Pong">;
|
|
8
|
+
}>, typeof UnknownError, never, never> | Rpc.Rpc<"SyncHttpRpc.Pull", Schema.Struct<{
|
|
4
9
|
readonly cursor: Schema.Option<Schema.Struct<{
|
|
5
10
|
readonly backendId: Schema.String;
|
|
6
11
|
readonly eventSequenceNumber: Schema.brand<Schema.Int, "GlobalEventSequenceNumber">;
|
|
7
12
|
}>>;
|
|
8
13
|
readonly storeId: Schema.String;
|
|
9
14
|
readonly payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
10
|
-
}>, import("effect/
|
|
15
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Struct<{
|
|
11
16
|
readonly batch: Schema.$Array<Schema.Struct<{
|
|
12
17
|
readonly eventEncoded: Schema.Struct<{
|
|
13
18
|
readonly name: Schema.String;
|
|
@@ -38,12 +43,7 @@ declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.Pull", Sc
|
|
|
38
43
|
readonly backendId: Schema.Option<Schema.String>;
|
|
39
44
|
readonly storeId: Schema.String;
|
|
40
45
|
readonly payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
41
|
-
}>, Schema.Struct<{}>, Schema.Union<readonly [typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never, never
|
|
42
|
-
readonly storeId: Schema.String;
|
|
43
|
-
readonly payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
44
|
-
}>, Schema.Struct<{
|
|
45
|
-
readonly _tag: Schema.tag<"SyncMessage.Pong">;
|
|
46
|
-
}>, typeof UnknownError, never, never>>;
|
|
46
|
+
}>, Schema.Struct<{}>, Schema.Union<readonly [typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never, never>>;
|
|
47
47
|
/**
|
|
48
48
|
* HTTP RPC Schema for LiveStore CF Sync Provider
|
|
49
49
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
|
-
import * as SyncMessage from
|
|
3
|
+
import * as SyncMessage from './sync-message-types.js';
|
|
4
4
|
/**
|
|
5
5
|
* HTTP RPC Schema for LiveStore CF Sync Provider
|
|
6
6
|
*
|
package/dist/common/mod.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { OversizeChunkItemError, splitArrayBySize } from '@livestore/common/sync
|
|
|
2
2
|
import { Schema } from '@livestore/utils/effect';
|
|
3
3
|
export type { CfTypes } from '@livestore/common-cf';
|
|
4
4
|
export * from './constants.ts';
|
|
5
|
+
export { SyncDoRpc } from './do-rpc-schema.ts';
|
|
5
6
|
export { SyncHttpRpc } from './http-rpc-schema.ts';
|
|
6
7
|
export * as SyncMessage from './sync-message-types.ts';
|
|
7
8
|
export declare const SearchParamsSchema: Schema.Struct<{
|
package/dist/common/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/common/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD,eAAO,MAAM,kBAAkB;;;;EAK7B,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/common/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD,eAAO,MAAM,kBAAkB;;;;EAK7B,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA"}
|
package/dist/common/mod.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { OversizeChunkItemError, splitArrayBySize } from '@livestore/common/sync';
|
|
2
2
|
import { Schema } from '@livestore/utils/effect';
|
|
3
|
-
export * from
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
3
|
+
export * from './constants.js';
|
|
4
|
+
export { SyncDoRpc } from './do-rpc-schema.js';
|
|
5
|
+
export { SyncHttpRpc } from './http-rpc-schema.js';
|
|
6
|
+
export * as SyncMessage from './sync-message-types.js';
|
|
6
7
|
export const SearchParamsSchema = Schema.Struct({
|
|
7
8
|
storeId: Schema.String,
|
|
8
9
|
payload: Schema.optional(Schema.StringFromUriComponent.pipe(Schema.decodeTo(Schema.fromJsonString(Schema.Json)))),
|
package/dist/common/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/common/mod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,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjH,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC3C,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-message-types.d.ts","sourceRoot":"","sources":["../../src/common/sync-message-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD;;;;GAIG;AAEH,eAAO,MAAM,YAAY;;;EAGgC,CAAA;AAEzD,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,eAAO,MAAM,WAAW;IACtB,wDAAwD;;;;;EAOF,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAEjD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;EASgC,CAAA;AAEzD,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"sync-message-types.d.ts","sourceRoot":"","sources":["../../src/common/sync-message-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD;;;;GAIG;AAEH,eAAO,MAAM,YAAY;;;EAGgC,CAAA;AAEzD,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,eAAO,MAAM,WAAW;IACtB,wDAAwD;;;;;EAOF,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAEjD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;EASgC,CAAA;AAEzD,eAAO,MAAM,iBAAiB,cAAe,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CAK/C,CAAA;AAEJ,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA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;;;MAiG2B,CAAA;AACrF,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA"}
|
|
@@ -9,7 +9,7 @@ declare const SyncWsRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncWsRpc.Pull", Schema
|
|
|
9
9
|
readonly payload: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
10
10
|
/** Whether to keep the pull stream alive and wait for more events */
|
|
11
11
|
readonly live: Schema.Boolean;
|
|
12
|
-
}>, import("effect/
|
|
12
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Struct<{
|
|
13
13
|
readonly batch: Schema.$Array<Schema.Struct<{
|
|
14
14
|
readonly eventEncoded: Schema.Struct<{
|
|
15
15
|
readonly name: Schema.String;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
|
|
2
2
|
import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
|
|
3
|
-
import * as SyncMessage from
|
|
3
|
+
import * as SyncMessage from './sync-message-types.js';
|
|
4
4
|
/**
|
|
5
5
|
* WebSocket RPC Schema for LiveStore CF Sync Provider
|
|
6
6
|
*
|
package/package.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$genie": {
|
|
3
|
+
"source": "package.json.genie.ts",
|
|
4
|
+
"warning": "DO NOT EDIT - changes will be overwritten",
|
|
5
|
+
"workspaceClosureDirs": [
|
|
6
|
+
"packages/@livestore/common",
|
|
7
|
+
"packages/@livestore/common-cf",
|
|
8
|
+
"packages/@livestore/sync-cf",
|
|
9
|
+
"packages/@livestore/utils",
|
|
10
|
+
"packages/@livestore/utils-dev",
|
|
11
|
+
"packages/@livestore/webmesh"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
2
14
|
"name": "@livestore/sync-cf",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
15
|
+
"version": "0.5.0-dev.1",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
4
18
|
"license": "Apache-2.0",
|
|
5
19
|
"repository": {
|
|
6
20
|
"type": "git",
|
|
7
21
|
"url": "git+https://github.com/livestorejs/livestore.git"
|
|
8
22
|
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./client": "./dist/client/mod.js",
|
|
25
|
+
"./common": "./dist/common/mod.js",
|
|
26
|
+
"./cf-worker": "./dist/cf-worker/mod.js"
|
|
27
|
+
},
|
|
9
28
|
"files": [
|
|
10
29
|
"dist",
|
|
11
30
|
"package.json",
|
|
12
31
|
"src",
|
|
13
32
|
"README.md"
|
|
14
33
|
],
|
|
15
|
-
"type": "module",
|
|
16
|
-
"sideEffects": false,
|
|
17
|
-
"exports": {
|
|
18
|
-
"./client": "./dist/client/mod.js",
|
|
19
|
-
"./common": "./dist/common/mod.js",
|
|
20
|
-
"./cf-worker": "./dist/cf-worker/mod.js"
|
|
21
|
-
},
|
|
22
|
-
"publishConfig": {
|
|
23
|
-
"access": "public"
|
|
24
|
-
},
|
|
25
34
|
"dependencies": {
|
|
26
35
|
"@cloudflare/workers-types": "4.20251118.0",
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/common": "^0.5.0-dev.
|
|
29
|
-
"@livestore/
|
|
36
|
+
"@livestore/common": "^0.5.0-dev.1",
|
|
37
|
+
"@livestore/common-cf": "^0.5.0-dev.1",
|
|
38
|
+
"@livestore/utils": "^0.5.0-dev.1"
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
32
|
-
"@effect/opentelemetry": "4.0.
|
|
33
|
-
"@effect/platform-browser": "4.0.
|
|
34
|
-
"@effect/platform-bun": "4.0.
|
|
35
|
-
"@effect/platform-node": "4.0.
|
|
36
|
-
"@effect/platform-node-shared": "4.0.
|
|
37
|
-
"@effect/vitest": "4.0.
|
|
41
|
+
"@effect/opentelemetry": "4.0.3",
|
|
42
|
+
"@effect/platform-browser": "4.0.3",
|
|
43
|
+
"@effect/platform-bun": "4.0.3",
|
|
44
|
+
"@effect/platform-node": "4.0.3",
|
|
45
|
+
"@effect/platform-node-shared": "4.0.3",
|
|
46
|
+
"@effect/vitest": "4.0.3",
|
|
47
|
+
"@livestore/utils-dev": "^0.5.0-dev.1",
|
|
38
48
|
"@opentelemetry/api": "1.9.0",
|
|
39
49
|
"@opentelemetry/resources": "2.2.0",
|
|
40
50
|
"@standard-schema/spec": "1.1.0",
|
|
41
|
-
"effect": "4.0.
|
|
42
|
-
"vitest": "4.1.9"
|
|
43
|
-
"@livestore/utils-dev": "^0.5.0-dev.0"
|
|
51
|
+
"effect": "4.0.3",
|
|
52
|
+
"vitest": "4.1.9"
|
|
44
53
|
},
|
|
45
54
|
"peerDependencies": {
|
|
46
|
-
"@effect/opentelemetry": "^4.0.
|
|
47
|
-
"@effect/platform-browser": "^4.0.
|
|
48
|
-
"@effect/platform-bun": "^4.0.
|
|
49
|
-
"@effect/platform-node": "^4.0.
|
|
50
|
-
"@effect/platform-node-shared": "^4.0.
|
|
51
|
-
"@effect/vitest": "^4.0.
|
|
55
|
+
"@effect/opentelemetry": "^4.0.3",
|
|
56
|
+
"@effect/platform-browser": "^4.0.3",
|
|
57
|
+
"@effect/platform-bun": "^4.0.3",
|
|
58
|
+
"@effect/platform-node": "^4.0.3",
|
|
59
|
+
"@effect/platform-node-shared": "^4.0.3",
|
|
60
|
+
"@effect/vitest": "^4.0.3",
|
|
52
61
|
"@opentelemetry/api": "^1.9.0",
|
|
53
62
|
"@opentelemetry/resources": "^2.2.0",
|
|
54
63
|
"@standard-schema/spec": "^1.1.0",
|
|
55
|
-
"effect": "^4.0.
|
|
64
|
+
"effect": "^4.0.3"
|
|
56
65
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"warning": "DO NOT EDIT - changes will be overwritten",
|
|
60
|
-
"workspaceClosureDirs": [
|
|
61
|
-
"packages/@livestore/common",
|
|
62
|
-
"packages/@livestore/common-cf",
|
|
63
|
-
"packages/@livestore/sync-cf",
|
|
64
|
-
"packages/@livestore/utils",
|
|
65
|
-
"packages/@livestore/utils-dev",
|
|
66
|
-
"packages/@livestore/webmesh"
|
|
67
|
-
]
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "vitest run"
|
|
@@ -4,17 +4,7 @@ import { DurableObject } from 'cloudflare:workers'
|
|
|
4
4
|
|
|
5
5
|
import { type CfTypes, setupDurableObjectWebSocketRpc } from '@livestore/common-cf'
|
|
6
6
|
import { CfDeclare } from '@livestore/common-cf/declare'
|
|
7
|
-
import {
|
|
8
|
-
Effect,
|
|
9
|
-
FetchHttpClient,
|
|
10
|
-
Layer,
|
|
11
|
-
Logger,
|
|
12
|
-
Otlp,
|
|
13
|
-
References,
|
|
14
|
-
RpcMessage,
|
|
15
|
-
Schema,
|
|
16
|
-
type Scope,
|
|
17
|
-
} from '@livestore/utils/effect'
|
|
7
|
+
import { Effect, Layer, Logger, References, RpcMessage, Schema, type Scope } from '@livestore/utils/effect'
|
|
18
8
|
|
|
19
9
|
import {
|
|
20
10
|
type Env,
|
|
@@ -25,6 +15,7 @@ import {
|
|
|
25
15
|
WebSocketAttachmentSchema,
|
|
26
16
|
} from '../shared.ts'
|
|
27
17
|
import * as DoCtx from './layer.ts'
|
|
18
|
+
import { makeObservability } from './observability.ts'
|
|
28
19
|
import { createDoRpcHandler } from './transport/do-rpc-server.ts'
|
|
29
20
|
import { createHttpRpcHandler } from './transport/http-rpc-server.ts'
|
|
30
21
|
import { makeRpcServer } from './transport/ws-rpc-server.ts'
|
|
@@ -88,24 +79,18 @@ export type MakeDurableObjectClass = (options?: MakeDurableObjectClassOptions) =
|
|
|
88
79
|
export const makeDurableObject: MakeDurableObjectClass = (options) => {
|
|
89
80
|
const enabledTransports = options?.enabledTransports ?? new Set(['http', 'ws', 'do-rpc'])
|
|
90
81
|
|
|
91
|
-
const Observability: Layer.Layer<never> =
|
|
92
|
-
options?.otel?.baseUrl !== undefined
|
|
93
|
-
? Otlp.layerJson({
|
|
94
|
-
baseUrl: options.otel.baseUrl,
|
|
95
|
-
tracerExportInterval: 50,
|
|
96
|
-
resource: {
|
|
97
|
-
serviceName: options.otel.serviceName ?? 'sync-cf-do',
|
|
98
|
-
},
|
|
99
|
-
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
100
|
-
: Layer.empty
|
|
101
|
-
|
|
102
82
|
return class SyncBackendDOBase extends DurableObjectBase implements SyncBackendRpcInterface {
|
|
103
83
|
__DURABLE_OBJECT_BRAND = 'SyncBackendDOBase' as never
|
|
84
|
+
private readonly observability = makeObservability(options?.otel)
|
|
104
85
|
|
|
105
86
|
constructor(ctx: CfTypes.DurableObjectState, env: Env) {
|
|
106
87
|
super(ctx, env)
|
|
107
88
|
|
|
108
|
-
const WebSocketRpcServerLive = makeRpcServer({
|
|
89
|
+
const WebSocketRpcServerLive = makeRpcServer({
|
|
90
|
+
doSelf: this,
|
|
91
|
+
doOptions: options,
|
|
92
|
+
observability: this.observability,
|
|
93
|
+
})
|
|
109
94
|
|
|
110
95
|
// This registers the `webSocketMessage` and `webSocketClose` handlers
|
|
111
96
|
if (enabledTransports.has('ws') === true) {
|
|
@@ -117,7 +102,6 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
|
|
|
117
102
|
// in combination with DO hibernation
|
|
118
103
|
onMessage: (request, ws) => {
|
|
119
104
|
if (request._tag === 'Request' && request.tag === 'SyncWsRpc.Pull') {
|
|
120
|
-
// Is Pull request: add requestId to pullRequestIds
|
|
121
105
|
const attachment = ws.deserializeAttachment()
|
|
122
106
|
const { pullRequestIds, ...rest } = Schema.decodeUnknownSync(WebSocketAttachmentSchema)(attachment)
|
|
123
107
|
ws.serializeAttachment(
|
|
@@ -126,20 +110,10 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
|
|
|
126
110
|
pullRequestIds: [...pullRequestIds, request.id],
|
|
127
111
|
}),
|
|
128
112
|
)
|
|
129
|
-
} else if (request._tag === 'Interrupt') {
|
|
130
|
-
// Is Interrupt request: remove requestId from pullRequestIds
|
|
131
|
-
const attachment = ws.deserializeAttachment()
|
|
132
|
-
const { pullRequestIds, ...rest } = Schema.decodeUnknownSync(WebSocketAttachmentSchema)(attachment)
|
|
133
|
-
ws.serializeAttachment(
|
|
134
|
-
Schema.encodeSync(WebSocketAttachmentSchema)({
|
|
135
|
-
...rest,
|
|
136
|
-
pullRequestIds: pullRequestIds.filter((id) => id !== request.requestId),
|
|
137
|
-
}),
|
|
138
|
-
)
|
|
139
|
-
// TODO also emit `Exit` stream RPC message
|
|
140
113
|
}
|
|
141
114
|
},
|
|
142
|
-
|
|
115
|
+
onRequestExit: (requestId, ws) => removePullRequestId(ws, requestId),
|
|
116
|
+
onProtocolDefect: clearPullRequestIds,
|
|
143
117
|
})
|
|
144
118
|
}
|
|
145
119
|
}
|
|
@@ -219,10 +193,11 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
|
|
|
219
193
|
throw new Error('Do RPC transport is not enabled (based on `options.enabledTransports`)')
|
|
220
194
|
}
|
|
221
195
|
|
|
222
|
-
return createDoRpcHandler({
|
|
223
|
-
|
|
224
|
-
this
|
|
225
|
-
|
|
196
|
+
return createDoRpcHandler({
|
|
197
|
+
payload,
|
|
198
|
+
input: { doSelf: this, doOptions: options },
|
|
199
|
+
observability: this.observability,
|
|
200
|
+
}).pipe(Effect.withSpan('@livestore/sync-cf:durable-object:rpc'), this.runEffectAsPromise)
|
|
226
201
|
}
|
|
227
202
|
|
|
228
203
|
/**
|
|
@@ -242,14 +217,36 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
|
|
|
242
217
|
Effect.tapCauseLogPretty,
|
|
243
218
|
Effect.annotateLogs({ thread: 'SyncDo' }),
|
|
244
219
|
Effect.provide(
|
|
245
|
-
Layer.mergeAll(
|
|
246
|
-
Observability,
|
|
247
|
-
Logger.layer([Logger.consoleStructured]),
|
|
248
|
-
Layer.succeed(References.MinimumLogLevel, 'Debug'),
|
|
249
|
-
),
|
|
220
|
+
Layer.mergeAll(Logger.layer([Logger.consoleStructured]), Layer.succeed(References.MinimumLogLevel, 'Debug')),
|
|
250
221
|
),
|
|
251
222
|
Effect.scoped,
|
|
223
|
+
this.observability.effect,
|
|
252
224
|
Effect.runPromise,
|
|
253
225
|
)
|
|
254
226
|
}
|
|
255
227
|
}
|
|
228
|
+
|
|
229
|
+
const removePullRequestId = (ws: CfTypes.WebSocket, requestId: string | number) =>
|
|
230
|
+
updatePullRequestIds(ws, (pullRequestIds) =>
|
|
231
|
+
pullRequestIds.includes(requestId) === true ? pullRequestIds.filter((id) => id !== requestId) : pullRequestIds,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
const clearPullRequestIds = (ws: CfTypes.WebSocket) =>
|
|
235
|
+
updatePullRequestIds(ws, (pullRequestIds) => (pullRequestIds.length === 0 ? pullRequestIds : []))
|
|
236
|
+
|
|
237
|
+
const updatePullRequestIds = (
|
|
238
|
+
ws: CfTypes.WebSocket,
|
|
239
|
+
update: (pullRequestIds: ReadonlyArray<string | number>) => ReadonlyArray<string | number>,
|
|
240
|
+
) => {
|
|
241
|
+
const attachment = ws.deserializeAttachment()
|
|
242
|
+
const { pullRequestIds, ...rest } = Schema.decodeUnknownSync(WebSocketAttachmentSchema)(attachment)
|
|
243
|
+
const nextPullRequestIds = update(pullRequestIds)
|
|
244
|
+
if (nextPullRequestIds === pullRequestIds) return
|
|
245
|
+
|
|
246
|
+
ws.serializeAttachment(
|
|
247
|
+
Schema.encodeSync(WebSocketAttachmentSchema)({
|
|
248
|
+
...rest,
|
|
249
|
+
pullRequestIds: nextPullRequestIds,
|
|
250
|
+
}),
|
|
251
|
+
)
|
|
252
|
+
}
|