@livestore/sync-cf 0.4.0-dev.8 → 0.4.0

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.
Files changed (100) hide show
  1. package/README.md +7 -8
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cf-worker/do/durable-object.d.ts +1 -1
  4. package/dist/cf-worker/do/durable-object.d.ts.map +1 -1
  5. package/dist/cf-worker/do/durable-object.js +15 -14
  6. package/dist/cf-worker/do/durable-object.js.map +1 -1
  7. package/dist/cf-worker/do/layer.d.ts +6 -6
  8. package/dist/cf-worker/do/layer.d.ts.map +1 -1
  9. package/dist/cf-worker/do/layer.js +32 -9
  10. package/dist/cf-worker/do/layer.js.map +1 -1
  11. package/dist/cf-worker/do/pull.d.ts +8 -3
  12. package/dist/cf-worker/do/pull.d.ts.map +1 -1
  13. package/dist/cf-worker/do/pull.js +22 -10
  14. package/dist/cf-worker/do/pull.js.map +1 -1
  15. package/dist/cf-worker/do/push.d.ts +5 -4
  16. package/dist/cf-worker/do/push.d.ts.map +1 -1
  17. package/dist/cf-worker/do/push.js +80 -41
  18. package/dist/cf-worker/do/push.js.map +1 -1
  19. package/dist/cf-worker/do/sqlite.d.ts +10 -1
  20. package/dist/cf-worker/do/sqlite.d.ts.map +1 -1
  21. package/dist/cf-worker/do/sqlite.js +13 -4
  22. package/dist/cf-worker/do/sqlite.js.map +1 -1
  23. package/dist/cf-worker/do/sync-storage.d.ts +14 -9
  24. package/dist/cf-worker/do/sync-storage.d.ts.map +1 -1
  25. package/dist/cf-worker/do/sync-storage.js +92 -18
  26. package/dist/cf-worker/do/sync-storage.js.map +1 -1
  27. package/dist/cf-worker/do/transport/do-rpc-server.d.ts +2 -1
  28. package/dist/cf-worker/do/transport/do-rpc-server.d.ts.map +1 -1
  29. package/dist/cf-worker/do/transport/do-rpc-server.js +13 -7
  30. package/dist/cf-worker/do/transport/do-rpc-server.js.map +1 -1
  31. package/dist/cf-worker/do/transport/http-rpc-server.d.ts +3 -1
  32. package/dist/cf-worker/do/transport/http-rpc-server.d.ts.map +1 -1
  33. package/dist/cf-worker/do/transport/http-rpc-server.js +24 -15
  34. package/dist/cf-worker/do/transport/http-rpc-server.js.map +1 -1
  35. package/dist/cf-worker/do/transport/ws-rpc-server.d.ts +2 -1
  36. package/dist/cf-worker/do/transport/ws-rpc-server.d.ts.map +1 -1
  37. package/dist/cf-worker/do/transport/ws-rpc-server.js +30 -8
  38. package/dist/cf-worker/do/transport/ws-rpc-server.js.map +1 -1
  39. package/dist/cf-worker/shared.d.ts +123 -30
  40. package/dist/cf-worker/shared.d.ts.map +1 -1
  41. package/dist/cf-worker/shared.js +50 -6
  42. package/dist/cf-worker/shared.js.map +1 -1
  43. package/dist/cf-worker/worker.d.ts +64 -71
  44. package/dist/cf-worker/worker.d.ts.map +1 -1
  45. package/dist/cf-worker/worker.js +70 -48
  46. package/dist/cf-worker/worker.js.map +1 -1
  47. package/dist/client/transport/do-rpc-client.d.ts.map +1 -1
  48. package/dist/client/transport/do-rpc-client.js +27 -10
  49. package/dist/client/transport/do-rpc-client.js.map +1 -1
  50. package/dist/client/transport/http-rpc-client.d.ts.map +1 -1
  51. package/dist/client/transport/http-rpc-client.js +29 -9
  52. package/dist/client/transport/http-rpc-client.js.map +1 -1
  53. package/dist/client/transport/ws-rpc-client.d.ts +2 -1
  54. package/dist/client/transport/ws-rpc-client.d.ts.map +1 -1
  55. package/dist/client/transport/ws-rpc-client.js +31 -17
  56. package/dist/client/transport/ws-rpc-client.js.map +1 -1
  57. package/dist/common/constants.d.ts +7 -0
  58. package/dist/common/constants.d.ts.map +1 -0
  59. package/dist/common/constants.js +17 -0
  60. package/dist/common/constants.js.map +1 -0
  61. package/dist/common/do-rpc-schema.d.ts +6 -6
  62. package/dist/common/do-rpc-schema.d.ts.map +1 -1
  63. package/dist/common/do-rpc-schema.js +4 -4
  64. package/dist/common/do-rpc-schema.js.map +1 -1
  65. package/dist/common/http-rpc-schema.d.ts +4 -4
  66. package/dist/common/http-rpc-schema.d.ts.map +1 -1
  67. package/dist/common/http-rpc-schema.js +4 -4
  68. package/dist/common/http-rpc-schema.js.map +1 -1
  69. package/dist/common/mod.d.ts +4 -1
  70. package/dist/common/mod.d.ts.map +1 -1
  71. package/dist/common/mod.js +4 -1
  72. package/dist/common/mod.js.map +1 -1
  73. package/dist/common/sync-message-types.d.ts +2 -2
  74. package/dist/common/sync-message-types.js +3 -3
  75. package/dist/common/sync-message-types.js.map +1 -1
  76. package/dist/common/ws-rpc-schema.d.ts +3 -3
  77. package/dist/common/ws-rpc-schema.d.ts.map +1 -1
  78. package/dist/common/ws-rpc-schema.js +3 -3
  79. package/dist/common/ws-rpc-schema.js.map +1 -1
  80. package/package.json +72 -14
  81. package/src/cf-worker/do/durable-object.ts +23 -18
  82. package/src/cf-worker/do/layer.ts +35 -13
  83. package/src/cf-worker/do/pull.ts +43 -14
  84. package/src/cf-worker/do/push.ts +107 -46
  85. package/src/cf-worker/do/sqlite.ts +14 -4
  86. package/src/cf-worker/do/sync-storage.ts +151 -31
  87. package/src/cf-worker/do/transport/do-rpc-server.ts +22 -9
  88. package/src/cf-worker/do/transport/http-rpc-server.ts +33 -13
  89. package/src/cf-worker/do/transport/ws-rpc-server.ts +40 -12
  90. package/src/cf-worker/shared.ts +149 -25
  91. package/src/cf-worker/worker.ts +138 -108
  92. package/src/client/transport/do-rpc-client.ts +41 -17
  93. package/src/client/transport/http-rpc-client.ts +43 -17
  94. package/src/client/transport/ws-rpc-client.ts +42 -19
  95. package/src/common/constants.ts +18 -0
  96. package/src/common/do-rpc-schema.ts +5 -4
  97. package/src/common/http-rpc-schema.ts +5 -4
  98. package/src/common/mod.ts +4 -2
  99. package/src/common/sync-message-types.ts +3 -3
  100. package/src/common/ws-rpc-schema.ts +4 -3
@@ -1,8 +1,8 @@
1
- import { InvalidPullError, InvalidPushError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } 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 durable object, we still need the explicit storeId
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
  */
@@ -42,9 +42,9 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
42
42
  }>, Schema.TaggedStruct<"NoMore", {}>]>;
43
43
  backendId: Schema.SchemaClass<string, string, never>;
44
44
  rpcRequestId: typeof Schema.String;
45
- }>, typeof InvalidPullError>, typeof Schema.Never, never> | Rpc.Rpc<"SyncDoRpc.Push", Schema.Struct<{
45
+ }>, Schema.Union<[typeof UnknownError, typeof BackendIdMismatchError]>>, typeof Schema.Never, never> | Rpc.Rpc<"SyncDoRpc.Push", Schema.Struct<{
46
46
  /**
47
- * While the storeId is already implied by the durable object, we still need the explicit storeId
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
  */
@@ -60,9 +60,9 @@ declare const SyncDoRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncDoRpc.Pull", Schema
60
60
  sessionId: typeof Schema.String;
61
61
  }>>;
62
62
  backendId: Schema.Option<Schema.SchemaClass<string, string, never>>;
63
- }>, Schema.Struct<{}>, typeof InvalidPushError, never> | Rpc.Rpc<"SyncDoRpc.Ping", Schema.Struct<{
63
+ }>, Schema.Struct<{}>, Schema.Union<[typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never> | Rpc.Rpc<"SyncDoRpc.Ping", Schema.Struct<{
64
64
  /**
65
- * While the storeId is already implied by the durable object, we still need the explicit storeId
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
  */
@@ -1 +1 @@
1
- {"version":3,"file":"do-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/do-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;;IAI7D;;;;OAIG;;IAEH,6CAA6C;;IAOzC,wDAAwD;;;;;IAGxD,qEAAqE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAhBzE;;;;OAIG;;IAEH,6CAA6C;;;;;;;;;;;;IAN7C;;;;OAIG;;IAEH,6CAA6C;;;AAI/C,qBAAa,SAAU,SAAQ,cAsC9B;CAAG"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAhBzE;;;;OAIG;;IAEH,6CAA6C;;;;;;;;;;;;IAN7C;;;;OAIG;;IAEH,6CAA6C;;;AAI/C,qBAAa,SAAU,SAAQ,cAsC9B;CAAG"}
@@ -1,9 +1,9 @@
1
- import { InvalidPullError, InvalidPushError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
2
2
  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 durable object, we still need the explicit storeId
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
  */
@@ -29,7 +29,7 @@ export class SyncDoRpc extends RpcGroup.make(Rpc.make('SyncDoRpc.Pull', {
29
29
  rpcRequestId: Schema.String,
30
30
  ...SyncMessage.PullResponse.fields,
31
31
  }),
32
- error: InvalidPullError,
32
+ error: Schema.Union(UnknownError, BackendIdMismatchError),
33
33
  stream: true,
34
34
  }), Rpc.make('SyncDoRpc.Push', {
35
35
  payload: {
@@ -37,7 +37,7 @@ export class SyncDoRpc extends RpcGroup.make(Rpc.make('SyncDoRpc.Pull', {
37
37
  ...commonPayloadFields,
38
38
  },
39
39
  success: SyncMessage.PushAck,
40
- error: InvalidPushError,
40
+ error: Schema.Union(UnknownError, ServerAheadError, BackendIdMismatchError),
41
41
  }), Rpc.make('SyncDoRpc.Ping', {
42
42
  payload: {
43
43
  ...commonPayloadFields,
@@ -1 +1 @@
1
- {"version":3,"file":"do-rpc-schema.js","sourceRoot":"","sources":["../../src/common/do-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD,MAAM,mBAAmB,GAAG;IAC1B;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC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ACzB,OAAO,EAAE;QACP,GAAG,mBAAmB;KACvB;IACD,OAAO,EAAE,MAAM,CAAC,IAAI;CACrB,CAAC,CACH;CAAG"}
@@ -1,4 +1,4 @@
1
- import { InvalidPullError, InvalidPushError, UnexpectedError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
2
2
  import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
3
3
  declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.Pull", Schema.Struct<{
4
4
  cursor: Schema.Option<Schema.Struct<{
@@ -27,7 +27,7 @@ declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.Pull", Sc
27
27
  remaining: typeof Schema.Number;
28
28
  }>, Schema.TaggedStruct<"NoMore", {}>]>;
29
29
  backendId: Schema.SchemaClass<string, string, never>;
30
- }>, typeof InvalidPullError>, typeof Schema.Never, never> | Rpc.Rpc<"SyncHttpRpc.Push", Schema.Struct<{
30
+ }>, Schema.Union<[typeof UnknownError, typeof BackendIdMismatchError]>>, typeof Schema.Never, never> | Rpc.Rpc<"SyncHttpRpc.Push", Schema.Struct<{
31
31
  batch: Schema.Array$<Schema.Struct<{
32
32
  name: typeof Schema.String;
33
33
  args: typeof Schema.Any;
@@ -39,12 +39,12 @@ declare const SyncHttpRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncHttpRpc.Pull", Sc
39
39
  backendId: Schema.Option<Schema.SchemaClass<string, string, never>>;
40
40
  storeId: typeof Schema.String;
41
41
  payload: Schema.optional<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
42
- }>, Schema.Struct<{}>, typeof InvalidPushError, never> | Rpc.Rpc<"SyncHttpRpc.Ping", Schema.Struct<{
42
+ }>, Schema.Struct<{}>, Schema.Union<[typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never> | Rpc.Rpc<"SyncHttpRpc.Ping", Schema.Struct<{
43
43
  storeId: typeof Schema.String;
44
44
  payload: Schema.optional<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
45
45
  }>, Schema.Struct<{
46
46
  _tag: Schema.tag<"SyncMessage.Pong">;
47
- }>, typeof UnexpectedError, never>>;
47
+ }>, typeof UnknownError, never>>;
48
48
  /**
49
49
  * HTTP RPC Schema for LiveStore CF Sync Provider
50
50
  *
@@ -1 +1 @@
1
- {"version":3,"file":"http-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/http-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/D;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,gBA4BhC;CAAG"}
1
+ {"version":3,"file":"http-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/http-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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI/D;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,gBA4BhC;CAAG"}
@@ -1,4 +1,4 @@
1
- import { InvalidPullError, InvalidPushError, UnexpectedError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
2
2
  import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
3
3
  import * as SyncMessage from "./sync-message-types.js";
4
4
  /**
@@ -15,7 +15,7 @@ export class SyncHttpRpc extends RpcGroup.make(Rpc.make('SyncHttpRpc.Pull', {
15
15
  ...SyncMessage.PullRequest.fields,
16
16
  }),
17
17
  success: SyncMessage.PullResponse,
18
- error: InvalidPullError,
18
+ error: Schema.Union(UnknownError, BackendIdMismatchError),
19
19
  stream: true,
20
20
  }), Rpc.make('SyncHttpRpc.Push', {
21
21
  payload: Schema.Struct({
@@ -24,14 +24,14 @@ export class SyncHttpRpc extends RpcGroup.make(Rpc.make('SyncHttpRpc.Pull', {
24
24
  ...SyncMessage.PushRequest.fields,
25
25
  }),
26
26
  success: SyncMessage.PushAck,
27
- error: InvalidPushError,
27
+ error: Schema.Union(UnknownError, ServerAheadError, BackendIdMismatchError),
28
28
  }), Rpc.make('SyncHttpRpc.Ping', {
29
29
  payload: Schema.Struct({
30
30
  storeId: Schema.String,
31
31
  payload: Schema.optional(Schema.JsonValue),
32
32
  }),
33
33
  success: SyncMessage.Pong,
34
- error: UnexpectedError,
34
+ error: UnknownError,
35
35
  })) {
36
36
  }
37
37
  //# sourceMappingURL=http-rpc-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-rpc-schema.js","sourceRoot":"","sources":["../../src/common/http-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,WAAY,SAAQ,QAAQ,CAAC,IAAI,CAC5C,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;QAC1C,GAAG,WAAW,CAAC,WAAW,CAAC,MAA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,CAAC,MAAM,CAAC,SAAS,CAAC;QAC1C,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM;KAClC,CAAC;IACF,OAAO,EAAE,WAAW,CAAC,YAAY;IACjC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,sBAAsB,CAAC;IACzD,MAAM,EAAE,IAAI;CACb,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;QAC1C,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM;KAClC,CAAC;IACF,OAAO,EAAE,WAAW,CAAC,OAAO;IAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,CAAC;CAC5E,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;KAC3C,CAAC;IACF,OAAO,EAAE,WAAW,CAAC,IAAI;IACzB,KAAK,EAAE,YAAY;CACpB,CAAC,CACH;CAAG"}
@@ -1,11 +1,14 @@
1
+ import { OversizeChunkItemError, splitChunkBySize } from '@livestore/common/sync';
1
2
  import { Schema } from '@livestore/utils/effect';
2
3
  export type { CfTypes } from '@livestore/common-cf';
4
+ export * from './constants.ts';
3
5
  export { SyncHttpRpc } from './http-rpc-schema.ts';
4
6
  export * as SyncMessage from './sync-message-types.ts';
7
+ export { OversizeChunkItemError, splitChunkBySize };
5
8
  export declare const SearchParamsSchema: Schema.Struct<{
6
9
  storeId: typeof Schema.String;
7
10
  payload: Schema.UndefinedOr<Schema.transform<Schema.transformOrFail<Schema.SchemaClass<string, string, never>, typeof Schema.String, never>, Schema.transform<Schema.SchemaClass<unknown, string, never>, Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>>>;
8
- transport: Schema.Union<[Schema.Literal<["http"]>, Schema.Literal<["ws"]>]>;
11
+ transport: Schema.Literal<["http", "ws"]>;
9
12
  }>;
10
13
  export type SearchParams = typeof SearchParamsSchema.Type;
11
14
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/common/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEnD,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,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,CAAA;AAEnD,eAAO,MAAM,kBAAkB;;;;EAK7B,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA"}
@@ -1,10 +1,13 @@
1
+ import { OversizeChunkItemError, splitChunkBySize } from '@livestore/common/sync';
1
2
  import { Schema } from '@livestore/utils/effect';
3
+ export * from "./constants.js";
2
4
  export { SyncHttpRpc } from "./http-rpc-schema.js";
3
5
  export * as SyncMessage from "./sync-message-types.js";
6
+ export { OversizeChunkItemError, splitChunkBySize };
4
7
  export const SearchParamsSchema = Schema.Struct({
5
8
  storeId: Schema.String,
6
9
  payload: Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(Schema.JsonValue)).pipe(Schema.UndefinedOr),
7
10
  // NOTE `do-rpc` is handled differently
8
- transport: Schema.Union(Schema.Literal('http'), Schema.Literal('ws')),
11
+ transport: Schema.Literal('http', 'ws'),
9
12
  });
10
13
  //# sourceMappingURL=mod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/common/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACnH,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE,CAAC,CAAA"}
1
+ {"version":3,"file":"mod.js","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;AAGhD,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,CAAA;AAEnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACnH,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;CACxC,CAAC,CAAA"}
@@ -51,8 +51,8 @@ export declare const emptyPullResponse: (backendId: string) => {
51
51
  readonly eventEncoded: {
52
52
  readonly name: string;
53
53
  readonly args: any;
54
- readonly seqNum: any;
55
- readonly parentSeqNum: any;
54
+ readonly seqNum: number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">;
55
+ readonly parentSeqNum: number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">;
56
56
  readonly clientId: string;
57
57
  readonly sessionId: string;
58
58
  };
@@ -14,12 +14,12 @@ export const PullRequest = Schema.Struct({
14
14
  /** Omitting the cursor will start from the beginning */
15
15
  cursor: Schema.Option(Schema.Struct({
16
16
  backendId: BackendId,
17
- eventSequenceNumber: EventSequenceNumber.GlobalEventSequenceNumber,
17
+ eventSequenceNumber: EventSequenceNumber.Global.Schema,
18
18
  })),
19
19
  }).annotations({ title: '@livestore/sync-cf:PullRequest' });
20
20
  export const PullResponse = Schema.Struct({
21
21
  batch: Schema.Array(Schema.Struct({
22
- eventEncoded: LiveStoreEvent.AnyEncodedGlobal,
22
+ eventEncoded: LiveStoreEvent.Global.Encoded,
23
23
  metadata: Schema.Option(SyncMetadata),
24
24
  })),
25
25
  pageInfo: SyncBackend.PullResPageInfo,
@@ -31,7 +31,7 @@ export const emptyPullResponse = (backendId) => PullResponse.make({
31
31
  backendId,
32
32
  });
33
33
  export const PushRequest = Schema.Struct({
34
- batch: Schema.Array(LiveStoreEvent.AnyEncodedGlobal),
34
+ batch: Schema.Array(LiveStoreEvent.Global.Encoded),
35
35
  backendId: Schema.Option(BackendId),
36
36
  }).annotations({ title: '@livestore/sync-cf:PushRequest' });
37
37
  export const PushAck = Schema.Struct({}).annotations({
@@ -1 +1 @@
1
- {"version":3,"file":"sync-message-types.js","sourceRoot":"","sources":["../../src/common/sync-message-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD;;;;GAIG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,0BAA0B,EAAE;IAC1E,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,iCAAiC,EAAE,CAAC,CAAA;AAI5D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,SAAS,EAAE,SAAS;QACpB,mBAAmB,EAAE,mBAAmB,CAAC,yBAAyB;KACnE,CAAC,CACH;CACF,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,CAAC,CAAA;AAI3D,MAAM,CAAC,MAAM,YAAY,GAAG,M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EAAE,KAAK,EAAE,qCAAqC,EAAE,CAAC,CAAA;AAIhE,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,+BAA+B,EAAE;IACpF,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC,MAAM;KAC/B,CAAC;CACH,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAC,CAAA;AAIjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,KAAK,CAChD,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,sBAAsB,EACtB,iBAAiB,CAClB,CAAA;AAGD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,KAAK,CAChD,WAAW,EACX,WAAW,EACX,IAAI,EACJ,qBAAqB,EACrB,gBAAgB,CACjB,CAAA;AAGD,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { InvalidPullError, InvalidPushError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
2
2
  import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
3
3
  declare const SyncWsRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncWsRpc.Pull", Schema.Struct<{
4
4
  cursor: Schema.Option<Schema.Struct<{
@@ -29,7 +29,7 @@ declare const SyncWsRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncWsRpc.Pull", Schema
29
29
  remaining: typeof Schema.Number;
30
30
  }>, Schema.TaggedStruct<"NoMore", {}>]>;
31
31
  backendId: Schema.SchemaClass<string, string, never>;
32
- }>, typeof InvalidPullError>, typeof Schema.Never, never> | Rpc.Rpc<"SyncWsRpc.Push", Schema.Struct<{
32
+ }>, Schema.Union<[typeof UnknownError, typeof BackendIdMismatchError]>>, typeof Schema.Never, never> | Rpc.Rpc<"SyncWsRpc.Push", Schema.Struct<{
33
33
  batch: Schema.Array$<Schema.Struct<{
34
34
  name: typeof Schema.String;
35
35
  args: typeof Schema.Any;
@@ -41,7 +41,7 @@ declare const SyncWsRpc_base: RpcGroup.RpcGroup<Rpc.Rpc<"SyncWsRpc.Pull", Schema
41
41
  backendId: Schema.Option<Schema.SchemaClass<string, string, never>>;
42
42
  storeId: typeof Schema.String;
43
43
  payload: Schema.optional<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
44
- }>, Schema.Struct<{}>, typeof InvalidPushError, never>>;
44
+ }>, Schema.Struct<{}>, Schema.Union<[typeof UnknownError, typeof ServerAheadError, typeof BackendIdMismatchError]>, never>>;
45
45
  /**
46
46
  * WebSocket RPC Schema for LiveStore CF Sync Provider
47
47
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ws-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/ws-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;;;;;;;;IAezD,qEAAqE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAZ3E;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,cAwB9B;CAAG"}
1
+ {"version":3,"file":"ws-rpc-schema.d.ts","sourceRoot":"","sources":["../../src/common/ws-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;;;;;;;;IAgBzD,qEAAqE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAZ3E;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,cAwB9B;CAAG"}
@@ -1,4 +1,4 @@
1
- import { InvalidPullError, InvalidPushError } from '@livestore/common';
1
+ import { BackendIdMismatchError, ServerAheadError, UnknownError } from '@livestore/common';
2
2
  import { Rpc, RpcGroup, Schema } from '@livestore/utils/effect';
3
3
  import * as SyncMessage from "./sync-message-types.js";
4
4
  /**
@@ -17,7 +17,7 @@ export class SyncWsRpc extends RpcGroup.make(Rpc.make('SyncWsRpc.Pull', {
17
17
  ...SyncMessage.PullRequest.fields,
18
18
  }),
19
19
  success: SyncMessage.PullResponse,
20
- error: InvalidPullError,
20
+ error: Schema.Union(UnknownError, BackendIdMismatchError),
21
21
  stream: true,
22
22
  }), Rpc.make('SyncWsRpc.Push', {
23
23
  payload: Schema.Struct({
@@ -26,7 +26,7 @@ export class SyncWsRpc extends RpcGroup.make(Rpc.make('SyncWsRpc.Pull', {
26
26
  ...SyncMessage.PushRequest.fields,
27
27
  }),
28
28
  success: SyncMessage.PushAck,
29
- error: InvalidPushError,
29
+ error: Schema.Union(UnknownError, ServerAheadError, BackendIdMismatchError),
30
30
  })) {
31
31
  }
32
32
  //# sourceMappingURL=ws-rpc-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ws-rpc-schema.js","sourceRoot":"","sources":["../../src/common/ws-rpc-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,QAAQ,CAAC,IAAI,CAC1C,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,OAAO,EAAE,MAAM,CAAC,Q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O,EAAE,WAAW,CAAC,YAAY;IACjC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,sBAAsB,CAAC;IACzD,MAAM,EAAE,IAAI;CACb,CAAC,EACF,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;QAC1C,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM;KAClC,CAAC;IACF,OAAO,EAAE,WAAW,CAAC,OAAO;IAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,CAAC;CAC5E,CAAC,CAGH;CAAG"}
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "@livestore/sync-cf",
3
- "version": "0.4.0-dev.8",
3
+ "version": "0.4.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/livestorejs/livestore.git"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "package.json",
12
+ "src",
13
+ "README.md"
14
+ ],
4
15
  "type": "module",
5
16
  "sideEffects": false,
6
17
  "exports": {
@@ -8,22 +19,69 @@
8
19
  "./common": "./dist/common/mod.js",
9
20
  "./cf-worker": "./dist/cf-worker/mod.js"
10
21
  },
11
- "dependencies": {
12
- "@cloudflare/workers-types": "4.20250823.0",
13
- "@livestore/common": "0.4.0-dev.8",
14
- "@livestore/utils": "0.4.0-dev.8",
15
- "@livestore/common-cf": "0.4.0-dev.8"
16
- },
17
- "files": [
18
- "dist",
19
- "src",
20
- "package.json",
21
- "README.md"
22
- ],
23
- "license": "Apache-2.0",
24
22
  "publishConfig": {
25
23
  "access": "public"
26
24
  },
25
+ "dependencies": {
26
+ "@cloudflare/workers-types": "4.20251118.0",
27
+ "@livestore/common": "^0.4.0",
28
+ "@livestore/common-cf": "^0.4.0",
29
+ "@livestore/utils": "^0.4.0"
30
+ },
31
+ "devDependencies": {
32
+ "@effect/ai": "0.35.0",
33
+ "@effect/cli": "0.75.1",
34
+ "@effect/cluster": "0.58.2",
35
+ "@effect/experimental": "0.60.0",
36
+ "@effect/opentelemetry": "0.63.0",
37
+ "@effect/platform": "0.96.1",
38
+ "@effect/platform-browser": "0.76.0",
39
+ "@effect/platform-bun": "0.89.0",
40
+ "@effect/platform-node": "0.106.0",
41
+ "@effect/printer": "0.49.0",
42
+ "@effect/printer-ansi": "0.49.0",
43
+ "@effect/rpc": "0.75.1",
44
+ "@effect/sql": "0.51.1",
45
+ "@effect/typeclass": "0.40.0",
46
+ "@effect/vitest": "0.29.0",
47
+ "@opentelemetry/api": "1.9.0",
48
+ "@opentelemetry/resources": "2.2.0",
49
+ "@standard-schema/spec": "1.1.0",
50
+ "effect": "3.21.2"
51
+ },
52
+ "peerDependencies": {
53
+ "@effect/ai": "^0.35.0",
54
+ "@effect/cli": "^0.75.1",
55
+ "@effect/cluster": "^0.58.2",
56
+ "@effect/experimental": "^0.60.0",
57
+ "@effect/opentelemetry": "^0.63.0",
58
+ "@effect/platform": "^0.96.1",
59
+ "@effect/platform-browser": "^0.76.0",
60
+ "@effect/platform-bun": "^0.89.0",
61
+ "@effect/platform-node": "^0.106.0",
62
+ "@effect/printer": "^0.49.0",
63
+ "@effect/printer-ansi": "^0.49.0",
64
+ "@effect/rpc": "^0.75.1",
65
+ "@effect/sql": "^0.51.1",
66
+ "@effect/typeclass": "^0.40.0",
67
+ "@effect/vitest": "^0.29.0",
68
+ "@opentelemetry/api": "^1.9.0",
69
+ "@opentelemetry/resources": "^2.2.0",
70
+ "@standard-schema/spec": "^1.1.0",
71
+ "effect": "^3.21.2"
72
+ },
73
+ "$genie": {
74
+ "source": "package.json.genie.ts",
75
+ "warning": "DO NOT EDIT - changes will be overwritten",
76
+ "workspaceClosureDirs": [
77
+ "packages/@livestore/common",
78
+ "packages/@livestore/common-cf",
79
+ "packages/@livestore/sync-cf",
80
+ "packages/@livestore/utils",
81
+ "packages/@livestore/utils-dev",
82
+ "packages/@livestore/webmesh"
83
+ ]
84
+ },
27
85
  "scripts": {
28
86
  "test": "echo 'No tests yet'"
29
87
  }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
 
3
3
  import { DurableObject } from 'cloudflare:workers'
4
+
4
5
  import { type CfTypes, setupDurableObjectWebSocketRpc } from '@livestore/common-cf'
5
6
  import { CfDeclare } from '@livestore/common-cf/declare'
6
7
  import {
@@ -14,10 +15,12 @@ import {
14
15
  Schema,
15
16
  type Scope,
16
17
  } from '@livestore/utils/effect'
18
+
17
19
  import {
18
20
  type Env,
19
- getSyncRequestSearchParams,
21
+ extractForwardedHeaders,
20
22
  type MakeDurableObjectClassOptions,
23
+ matchSyncRequest,
21
24
  type SyncBackendRpcInterface,
22
25
  WebSocketAttachmentSchema,
23
26
  } from '../shared.ts'
@@ -36,7 +39,7 @@ declare class WebSocketRequestResponsePair extends CfDeclare.WebSocketRequestRes
36
39
  const DurableObjectBase = DurableObject as any as new (
37
40
  state: CfTypes.DurableObjectState,
38
41
  env: Env,
39
- ) => CfTypes.DurableObject
42
+ ) => CfTypes.DurableObject & { ctx: CfTypes.DurableObjectState; env: Env }
40
43
 
41
44
  // Type aliases needed to avoid TS bug https://github.com/microsoft/TypeScript/issues/55021
42
45
  export type DoState = CfTypes.DurableObjectState
@@ -48,7 +51,7 @@ export type MakeDurableObjectClass = (options?: MakeDurableObjectClassOptions) =
48
51
 
49
52
  /**
50
53
  * Creates a Durable Object class for handling WebSocket-based sync.
51
- * A sync durable object is uniquely scoped to a specific `storeId`.
54
+ * A sync Durable Object is uniquely scoped to a specific `storeId`.
52
55
  *
53
56
  * The sync DO supports 3 transport modes:
54
57
  * - HTTP JSON-RPC
@@ -87,30 +90,26 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
87
90
 
88
91
  const Logging = Logger.consoleWithThread('SyncDo')
89
92
 
90
- const Observability = options?.otel?.baseUrl
91
- ? Otlp.layer({
93
+ const Observability: Layer.Layer<never> = options?.otel?.baseUrl !== undefined
94
+ ? (Otlp.layer({
92
95
  baseUrl: options.otel.baseUrl,
93
96
  tracerExportInterval: 50,
94
97
  resource: {
95
98
  serviceName: options.otel.serviceName ?? 'sync-cf-do',
96
99
  },
97
- }).pipe(Layer.provide(FetchHttpClient.layer))
100
+ }).pipe(Layer.provide(FetchHttpClient.layer)) as Layer.Layer<never>)
98
101
  : Layer.empty
99
102
 
100
103
  return class SyncBackendDOBase extends DurableObjectBase implements SyncBackendRpcInterface {
101
104
  __DURABLE_OBJECT_BRAND = 'SyncBackendDOBase' as never
102
- ctx: CfTypes.DurableObjectState
103
- env: Env
104
105
 
105
106
  constructor(ctx: CfTypes.DurableObjectState, env: Env) {
106
107
  super(ctx, env)
107
- this.ctx = ctx
108
- this.env = env
109
108
 
110
109
  const WebSocketRpcServerLive = makeRpcServer({ doSelf: this, doOptions: options })
111
110
 
112
111
  // This registers the `webSocketMessage` and `webSocketClose` handlers
113
- if (enabledTransports.has('ws')) {
112
+ if (enabledTransports.has('ws') === true) {
114
113
  setupDurableObjectWebSocketRpc({
115
114
  doSelf: this,
116
115
  rpcLayer: WebSocketRpcServerLive,
@@ -146,29 +145,33 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
146
145
  }
147
146
  }
148
147
 
149
- fetch = async (request: Request): Promise<Response> =>
148
+ override fetch = async (request: Request): Promise<Response> =>
150
149
  Effect.gen(this, function* () {
151
- const requestParamsResult = getSyncRequestSearchParams(request)
152
- if (requestParamsResult._tag === 'None') {
150
+ const searchParams = matchSyncRequest(request)
151
+ if (searchParams === undefined) {
153
152
  throw new Error('No search params found in request URL')
154
153
  }
155
154
 
156
- const { storeId, payload, transport } = requestParamsResult.value
155
+ const { storeId, payload, transport } = searchParams
157
156
 
158
157
  if (enabledTransports.has(transport) === false) {
159
158
  throw new Error(`Transport ${transport} is not enabled (based on \`options.enabledTransports\`)`)
160
159
  }
161
160
 
161
+ // Extract headers to forward based on configuration (available for all transports)
162
+ const headers = extractForwardedHeaders(request, options?.forwardHeaders)
163
+
162
164
  if (transport === 'http') {
163
- return yield* this.handleHttp(request)
165
+ return yield* this.handleHttp(request, headers)
164
166
  }
165
167
 
166
168
  if (transport === 'ws') {
167
169
  const { 0: client, 1: server } = new WebSocketPair()
168
170
 
169
171
  // Since we're using websocket hibernation, we need to remember the storeId for subsequent `webSocketMessage` calls
172
+ // Also store forwarded headers so they're available after hibernation resume
170
173
  server.serializeAttachment(
171
- Schema.encodeSync(WebSocketAttachmentSchema)({ storeId, payload, pullRequestIds: [] }),
174
+ Schema.encodeSync(WebSocketAttachmentSchema)({ storeId, payload, pullRequestIds: [], headers }),
172
175
  )
173
176
 
174
177
  // See https://developers.cloudflare.com/durable-objects/examples/websocket-hibernation-server
@@ -224,9 +227,11 @@ export const makeDurableObject: MakeDurableObjectClass = (options) => {
224
227
  *
225
228
  * Requires the `enable_request_signal` compatibility flag to properly support `pull` streaming responses
226
229
  */
227
- private handleHttp = (request: CfTypes.Request) =>
230
+ private handleHttp = (request: CfTypes.Request, forwardedHeaders: Record<string, string> | undefined) =>
228
231
  createHttpRpcHandler({
229
232
  request,
233
+ ...(options?.http?.responseHeaders !== undefined ? { responseHeaders: options.http.responseHeaders } : {}),
234
+ ...(forwardedHeaders !== undefined ? { forwardedHeaders } : {}),
230
235
  }).pipe(Effect.withSpan('@livestore/sync-cf:durable-object:handleHttp'))
231
236
 
232
237
  private runEffectAsPromise = <T, E = never>(effect: Effect.Effect<T, E, Scope.Scope>): Promise<T> =>