@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
@@ -0,0 +1,32 @@
1
+ import { Schema } from '@livestore/utils/effect';
2
+ export declare const PullArgs: Schema.Struct<{
3
+ storeId: typeof Schema.String;
4
+ s2SeqNum: Schema.Union<[Schema.BrandSchema<number & import("effect/Brand").Brand<"S2SeqNum">, number, never>, Schema.Literal<["from-start"]>]>;
5
+ live: typeof Schema.Boolean;
6
+ payload: Schema.UndefinedOr<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
7
+ }>;
8
+ export declare const PushPayload: Schema.Struct<{
9
+ storeId: typeof Schema.String;
10
+ batch: Schema.Array$<Schema.Struct<{
11
+ name: typeof Schema.String;
12
+ args: typeof Schema.Any;
13
+ seqNum: Schema.BrandSchema<number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">, number, never>;
14
+ parentSeqNum: Schema.BrandSchema<number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">, number, never>;
15
+ clientId: typeof Schema.String;
16
+ sessionId: typeof Schema.String;
17
+ }>>;
18
+ }>;
19
+ export type PullArgs = typeof PullArgs.Type;
20
+ export type PushPayload = typeof PushPayload.Type;
21
+ /** Encoded form for query parameter `args` */
22
+ export declare const ArgsSchema: Schema.transform<Schema.transformOrFail<Schema.SchemaClass<string, string, never>, typeof Schema.String, never>, Schema.transform<Schema.SchemaClass<unknown, string, never>, Schema.Struct<{
23
+ storeId: typeof Schema.String;
24
+ s2SeqNum: Schema.Union<[Schema.BrandSchema<number & import("effect/Brand").Brand<"S2SeqNum">, number, never>, Schema.Literal<["from-start"]>]>;
25
+ live: typeof Schema.Boolean;
26
+ payload: Schema.UndefinedOr<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
27
+ }>>>;
28
+ export declare const PushResponse: Schema.Struct<{
29
+ success: typeof Schema.Boolean;
30
+ }>;
31
+ export type PushResponse = typeof PushResponse.Type;
32
+ //# sourceMappingURL=api-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-schema.d.ts","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGhD,eAAO,MAAM,QAAQ;;;;;EAKnB,CAAA;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;EAGtB,CAAA;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAC3C,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAEjD,8CAA8C;AAC9C,eAAO,MAAM,UAAU;;;;;IAA4E,CAAA;AAEnG,eAAO,MAAM,YAAY;;EAA6C,CAAA;AACtE,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { LiveStoreEvent } from '@livestore/common/schema';
2
+ import { Schema } from '@livestore/utils/effect';
3
+ import { S2SeqNum } from "./types.js";
4
+ export const PullArgs = Schema.Struct({
5
+ storeId: Schema.String,
6
+ s2SeqNum: Schema.Union(S2SeqNum, Schema.Literal('from-start')),
7
+ live: Schema.Boolean,
8
+ payload: Schema.UndefinedOr(Schema.JsonValue),
9
+ });
10
+ export const PushPayload = Schema.Struct({
11
+ storeId: Schema.String,
12
+ batch: Schema.Array(LiveStoreEvent.AnyEncodedGlobal),
13
+ });
14
+ /** Encoded form for query parameter `args` */
15
+ export const ArgsSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PullArgs));
16
+ export const PushResponse = Schema.Struct({ success: Schema.Boolean });
17
+ //# sourceMappingURL=api-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-schema.js","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,EAAE,MAAM,CAAC,OAAO;IACpB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;CAC9C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;CACrD,CAAC,CAAA;AAKF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEnG,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api-schema.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-schema.test.d.ts","sourceRoot":"","sources":["../src/api-schema.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { Schema } from '@livestore/utils/effect';
2
+ import { describe, expect, it } from 'vitest';
3
+ import * as Api from "./api-schema.js";
4
+ import { decodePullArgsFromSearchParams } from "./make-s2-url.js";
5
+ import { s2SeqNum } from "./types.js";
6
+ describe('ApiSchema', () => {
7
+ it('encodes and decodes PullArgs via args search param', () => {
8
+ const args = Api.PullArgs.make({ storeId: 'store-1', s2SeqNum: s2SeqNum(42), live: true, payload: { a: 1 } });
9
+ const encoded = Schema.encodeSync(Api.ArgsSchema)(args);
10
+ const sp = new URLSearchParams({ args: encoded });
11
+ const roundtrip = decodePullArgsFromSearchParams(sp);
12
+ expect(roundtrip).toEqual(args);
13
+ });
14
+ it('decodes PushPayload with typed events', () => {
15
+ const payload = Api.PushPayload.make({ storeId: 's', batch: [] });
16
+ const decoded = Schema.decodeUnknownEither(Api.PushPayload)(payload);
17
+ expect(decoded._tag).toBe('Right');
18
+ });
19
+ });
20
+ //# sourceMappingURL=api-schema.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-schema.test.js","sourceRoot":"","sources":["../src/api-schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QAC7G,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAA;QACvD,MAAM,EAAE,GAAG,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QACjD,MAAM,SAAS,GAAG,8BAA8B,CAAC,EAAE,CAAC,CAAA;QACpD,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,OAAO,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;QACjE,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAA;QACpE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { LiveStoreEvent } from '@livestore/common/schema';
2
+ import { Option } from '@livestore/utils/effect';
3
+ import type * as HttpClientGenerated from './http-client-generated.ts';
4
+ import { S2SeqNum } from './types.ts';
5
+ export declare const decodeReadBatch: (readBatch: typeof HttpClientGenerated.ReadBatch.Type) => ReadonlyArray<{
6
+ eventEncoded: LiveStoreEvent.AnyEncodedGlobal;
7
+ metadata: Option.Option<{
8
+ s2SeqNum: S2SeqNum;
9
+ }>;
10
+ }>;
11
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAU,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,KAAK,mBAAmB,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAWrC,eAAO,MAAM,eAAe,GAC1B,WAAW,OAAO,mBAAmB,CAAC,SAAS,CAAC,IAAI,KACnD,aAAa,CAAC;IACf,YAAY,EAAE,cAAc,CAAC,gBAAgB,CAAA;IAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAA;CAChD,CAQA,CAAA"}
package/dist/decode.js ADDED
@@ -0,0 +1,19 @@
1
+ import { LiveStoreEvent } from '@livestore/common/schema';
2
+ import { Option, Schema } from '@livestore/utils/effect';
3
+ import { S2SeqNum } from "./types.js";
4
+ const ReadBatchSchema = Schema.Struct({
5
+ records: Schema.Array(Schema.Struct({
6
+ body: Schema.optional(Schema.parseJson(LiveStoreEvent.AnyEncodedGlobal)),
7
+ seq_num: S2SeqNum,
8
+ })),
9
+ }).annotations({ title: '@livestore/sync-s2:ReadBatchSchema' });
10
+ export const decodeReadBatch = (readBatch) => {
11
+ const decoded = Schema.decodeSync(ReadBatchSchema)(readBatch);
12
+ return decoded.records
13
+ .filter((r) => r.body !== undefined)
14
+ .map((r) => ({
15
+ eventEncoded: r.body,
16
+ metadata: Option.some({ s2SeqNum: r.seq_num }),
17
+ }));
18
+ };
19
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC,KAAK,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QACxE,OAAO,EAAE,QAAQ;KAClB,CAAC,CACH;CACF,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,oCAAoC,EAAE,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAoD,EAInD,EAAE;IACH,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,SAAS,CAAC,CAAA;IAC7D,OAAO,OAAO,CAAC,OAAO;SACnB,MAAM,CAAC,CAAC,CAAC,EAAqE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;SACtG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACX,YAAY,EAAE,CAAC,CAAC,IAAI;QACpB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;KAC/C,CAAC,CAAC,CAAA;AACP,CAAC,CAAA"}