@livestore/sync-s2 0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796

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 (48) hide show
  1. package/LICENSE +201 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/api-schema.d.ts +32 -0
  4. package/dist/api-schema.d.ts.map +1 -0
  5. package/dist/api-schema.js +17 -0
  6. package/dist/api-schema.js.map +1 -0
  7. package/dist/api-schema.test.d.ts +2 -0
  8. package/dist/api-schema.test.d.ts.map +1 -0
  9. package/dist/api-schema.test.js +20 -0
  10. package/dist/api-schema.test.js.map +1 -0
  11. package/dist/decode.d.ts +11 -0
  12. package/dist/decode.d.ts.map +1 -0
  13. package/dist/decode.js +19 -0
  14. package/dist/decode.js.map +1 -0
  15. package/dist/http-client-generated.d.ts +1477 -0
  16. package/dist/http-client-generated.d.ts.map +1 -0
  17. package/dist/http-client-generated.js +830 -0
  18. package/dist/http-client-generated.js.map +1 -0
  19. package/dist/make-s2-url.d.ts +7 -0
  20. package/dist/make-s2-url.d.ts.map +1 -0
  21. package/dist/make-s2-url.js +16 -0
  22. package/dist/make-s2-url.js.map +1 -0
  23. package/dist/mod.d.ts +8 -0
  24. package/dist/mod.d.ts.map +1 -0
  25. package/dist/mod.js +7 -0
  26. package/dist/mod.js.map +1 -0
  27. package/dist/s2-proxy-helpers.d.ts +61 -0
  28. package/dist/s2-proxy-helpers.d.ts.map +1 -0
  29. package/dist/s2-proxy-helpers.js +143 -0
  30. package/dist/s2-proxy-helpers.js.map +1 -0
  31. package/dist/sync-provider.d.ts +60 -0
  32. package/dist/sync-provider.d.ts.map +1 -0
  33. package/dist/sync-provider.js +154 -0
  34. package/dist/sync-provider.js.map +1 -0
  35. package/dist/types.d.ts +25 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +13 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +29 -0
  40. package/src/api-schema.test.ts +21 -0
  41. package/src/api-schema.ts +24 -0
  42. package/src/decode.ts +28 -0
  43. package/src/http-client-generated.ts +1341 -0
  44. package/src/make-s2-url.ts +23 -0
  45. package/src/mod.ts +7 -0
  46. package/src/s2-proxy-helpers.ts +196 -0
  47. package/src/sync-provider.ts +267 -0
  48. package/src/types.ts +26 -0
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@livestore/sync-s2",
3
+ "version": "0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": "./dist/mod.js",
8
+ "./s2-proxy-helpers": "./dist/s2-proxy-helpers.js"
9
+ },
10
+ "dependencies": {
11
+ "@livestore/common": "0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796",
12
+ "@livestore/livestore": "0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796",
13
+ "@livestore/utils": "0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796"
14
+ },
15
+ "devDependencies": {},
16
+ "files": [
17
+ "package.json",
18
+ "src",
19
+ "dist"
20
+ ],
21
+ "license": "Apache-2.0",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "",
27
+ "test": "echo 'No tests yet'"
28
+ }
29
+ }
@@ -0,0 +1,21 @@
1
+ import { Schema } from '@livestore/utils/effect'
2
+ import { describe, expect, it } from 'vitest'
3
+ import * as Api from './api-schema.ts'
4
+ import { decodePullArgsFromSearchParams } from './make-s2-url.ts'
5
+ import { s2SeqNum } from './types.ts'
6
+
7
+ describe('ApiSchema', () => {
8
+ it('encodes and decodes PullArgs via args search param', () => {
9
+ const args = Api.PullArgs.make({ storeId: 'store-1', s2SeqNum: s2SeqNum(42), live: true, payload: { a: 1 } })
10
+ const encoded = Schema.encodeSync(Api.ArgsSchema)(args)
11
+ const sp = new URLSearchParams({ args: encoded })
12
+ const roundtrip = decodePullArgsFromSearchParams(sp)
13
+ expect(roundtrip).toEqual(args)
14
+ })
15
+
16
+ it('decodes PushPayload with typed events', () => {
17
+ const payload = Api.PushPayload.make({ storeId: 's', batch: [] })
18
+ const decoded = Schema.decodeUnknownEither(Api.PushPayload)(payload)
19
+ expect(decoded._tag).toBe('Right')
20
+ })
21
+ })
@@ -0,0 +1,24 @@
1
+ import { LiveStoreEvent } from '@livestore/common/schema'
2
+ import { Schema } from '@livestore/utils/effect'
3
+ import { S2SeqNum } from './types.ts'
4
+
5
+ export const PullArgs = Schema.Struct({
6
+ storeId: Schema.String,
7
+ s2SeqNum: Schema.Union(S2SeqNum, Schema.Literal('from-start')),
8
+ live: Schema.Boolean,
9
+ payload: Schema.UndefinedOr(Schema.JsonValue),
10
+ })
11
+
12
+ export const PushPayload = Schema.Struct({
13
+ storeId: Schema.String,
14
+ batch: Schema.Array(LiveStoreEvent.AnyEncodedGlobal),
15
+ })
16
+
17
+ export type PullArgs = typeof PullArgs.Type
18
+ export type PushPayload = typeof PushPayload.Type
19
+
20
+ /** Encoded form for query parameter `args` */
21
+ export const ArgsSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PullArgs))
22
+
23
+ export const PushResponse = Schema.Struct({ success: Schema.Boolean })
24
+ export type PushResponse = typeof PushResponse.Type
package/src/decode.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { LiveStoreEvent } from '@livestore/common/schema'
2
+ import { Option, Schema } from '@livestore/utils/effect'
3
+ import type * as HttpClientGenerated from './http-client-generated.ts'
4
+ import { S2SeqNum } from './types.ts'
5
+
6
+ const ReadBatchSchema = Schema.Struct({
7
+ records: Schema.Array(
8
+ Schema.Struct({
9
+ body: Schema.optional(Schema.parseJson(LiveStoreEvent.AnyEncodedGlobal)),
10
+ seq_num: S2SeqNum,
11
+ }),
12
+ ),
13
+ }).annotations({ title: '@livestore/sync-s2:ReadBatchSchema' })
14
+
15
+ export const decodeReadBatch = (
16
+ readBatch: typeof HttpClientGenerated.ReadBatch.Type,
17
+ ): ReadonlyArray<{
18
+ eventEncoded: LiveStoreEvent.AnyEncodedGlobal
19
+ metadata: Option.Option<{ s2SeqNum: S2SeqNum }>
20
+ }> => {
21
+ const decoded = Schema.decodeSync(ReadBatchSchema)(readBatch)
22
+ return decoded.records
23
+ .filter((r): r is { body: LiveStoreEvent.AnyEncodedGlobal; seq_num: S2SeqNum } => r.body !== undefined)
24
+ .map((r) => ({
25
+ eventEncoded: r.body,
26
+ metadata: Option.some({ s2SeqNum: r.seq_num }),
27
+ }))
28
+ }