@livestore/sync-s2 0.4.0 → 0.5.0-dev.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.
package/src/api-schema.ts CHANGED
@@ -5,9 +5,9 @@ import { S2SeqNum } from './types.ts'
5
5
 
6
6
  export const PullArgs = Schema.Struct({
7
7
  storeId: Schema.String,
8
- s2SeqNum: Schema.Union(S2SeqNum, Schema.Literal('from-start')),
8
+ s2SeqNum: Schema.Union([S2SeqNum, Schema.Literal('from-start')]),
9
9
  live: Schema.Boolean,
10
- payload: Schema.UndefinedOr(Schema.JsonValue),
10
+ payload: Schema.optional(Schema.Json),
11
11
  })
12
12
 
13
13
  export const PushPayload = Schema.Struct({
@@ -19,7 +19,7 @@ export type PullArgs = typeof PullArgs.Type
19
19
  export type PushPayload = typeof PushPayload.Type
20
20
 
21
21
  /** Encoded form for query parameter `args` */
22
- export const ArgsSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PullArgs))
22
+ export const ArgsSchema = Schema.StringFromUriComponent.pipe(Schema.decodeTo(Schema.fromJsonString(PullArgs)))
23
23
 
24
24
  export const PushResponse = Schema.Struct({ success: Schema.Boolean })
25
25
  export type PushResponse = typeof PushResponse.Type
package/src/decode.ts CHANGED
@@ -7,11 +7,11 @@ import { S2SeqNum } from './types.ts'
7
7
  const ReadBatchSchema = Schema.Struct({
8
8
  records: Schema.Array(
9
9
  Schema.Struct({
10
- body: Schema.optional(Schema.parseJson(LiveStoreEvent.Global.Encoded)),
10
+ body: Schema.optional(Schema.NullOr(Schema.fromJsonString(LiveStoreEvent.Global.Encoded))),
11
11
  seq_num: S2SeqNum,
12
12
  }),
13
13
  ),
14
- }).annotations({ title: '@livestore/sync-s2:ReadBatchSchema' })
14
+ }).annotate({ title: '@livestore/sync-s2:ReadBatchSchema' })
15
15
 
16
16
  export const decodeReadBatch = (
17
17
  readBatch: typeof HttpClientGenerated.ReadBatch.Type,
@@ -21,7 +21,7 @@ export const decodeReadBatch = (
21
21
  }> => {
22
22
  const decoded = Schema.decodeSync(ReadBatchSchema)(readBatch)
23
23
  return decoded.records
24
- .filter((r): r is { body: LiveStoreEvent.Global.Encoded; seq_num: S2SeqNum } => r.body !== undefined)
24
+ .filter((r): r is { body: LiveStoreEvent.Global.Encoded; seq_num: S2SeqNum } => r.body != null)
25
25
  .map((r) => ({
26
26
  eventEncoded: r.body,
27
27
  metadata: Option.some({ s2SeqNum: r.seq_num }),