@livestore/common 0.3.0-dev.21 → 0.3.0-dev.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/common",
3
- "version": "0.3.0-dev.21",
3
+ "version": "0.3.0-dev.23",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -54,7 +54,7 @@
54
54
  "graphology": "0.26.0-alpha1",
55
55
  "graphology-dag": "0.4.1",
56
56
  "graphology-types": "0.24.8",
57
- "@livestore/utils": "0.3.0-dev.21"
57
+ "@livestore/utils": "0.3.0-dev.23"
58
58
  },
59
59
  "devDependencies": {
60
60
  "vitest": "^3.0.8"
@@ -239,6 +239,12 @@ export type Adapter = (opts: {
239
239
  bootStatusQueue: Queue.Queue<BootStatus>
240
240
  shutdown: (cause: Cause.Cause<any>) => void
241
241
  connectDevtoolsToStore: ConnectDevtoolsToStore
242
+ /**
243
+ * Payload that will be passed to the sync backend when connecting
244
+ *
245
+ * @default undefined
246
+ */
247
+ syncPayload: Schema.JsonValue | undefined
242
248
  }) => Effect.Effect<ClientSession, UnexpectedError, Scope.Scope>
243
249
 
244
250
  export const MigrationsReportEntry = Schema.Struct({
@@ -1,4 +1,4 @@
1
- import type { HttpClient, Scope } from '@livestore/utils/effect'
1
+ import type { HttpClient, Schema, Scope } from '@livestore/utils/effect'
2
2
  import { Deferred, Effect, Layer, Queue, SubscriptionRef } from '@livestore/utils/effect'
3
3
 
4
4
  import type { BootStatus, MakeSqliteDb, MigrationsReport, SqliteError } from '../adapter-types.js'
@@ -28,6 +28,7 @@ export const makeLeaderThreadLayer = ({
28
28
  schema,
29
29
  storeId,
30
30
  clientId,
31
+ syncPayload,
31
32
  makeSqliteDb,
32
33
  syncOptions,
33
34
  dbReadModel,
@@ -36,6 +37,7 @@ export const makeLeaderThreadLayer = ({
36
37
  shutdownChannel,
37
38
  }: {
38
39
  storeId: string
40
+ syncPayload: Schema.JsonValue | undefined
39
41
  clientId: string
40
42
  schema: LiveStoreSchema
41
43
  makeSqliteDb: MakeSqliteDb
@@ -54,7 +56,9 @@ export const makeLeaderThreadLayer = ({
54
56
  dbReadModel.select<{ count: number }>(sql`select count(*) as count from sqlite_master`)[0]!.count === 0
55
57
 
56
58
  const syncBackend =
57
- syncOptions?.makeBackend === undefined ? undefined : yield* syncOptions.makeBackend({ storeId, clientId })
59
+ syncOptions?.makeBackend === undefined
60
+ ? undefined
61
+ : yield* syncOptions.makeBackend({ storeId, clientId, payload: syncPayload })
58
62
 
59
63
  const initialBlockingSyncContext = yield* makeInitialBlockingSyncContext({
60
64
  initialSyncOptions: syncOptions?.initialSyncOptions ?? { _tag: 'Skip' },
package/src/sync/sync.ts CHANGED
@@ -12,10 +12,13 @@ import type * as MutationEvent from '../schema/MutationEvent.js'
12
12
  export type MakeBackendArgs = {
13
13
  storeId: string
14
14
  clientId: string
15
+ payload: Schema.JsonValue | undefined
15
16
  }
16
17
 
17
18
  export type SyncOptions = {
18
- makeBackend?: (args: MakeBackendArgs) => Effect.Effect<SyncBackend<any>, UnexpectedError, Scope.Scope>
19
+ makeBackend?: (
20
+ args: MakeBackendArgs,
21
+ ) => Effect.Effect<SyncBackend<any>, UnexpectedError, Scope.Scope | HttpClient.HttpClient>
19
22
  /** @default { _tag: 'Skip' } */
20
23
  initialSyncOptions?: InitialSyncOptions
21
24
  }
package/src/version.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // import packageJson from '../package.json' with { type: 'json' }
3
3
  // export const liveStoreVersion = packageJson.version
4
4
 
5
- export const liveStoreVersion = '0.3.0-dev.21' as const
5
+ export const liveStoreVersion = '0.3.0-dev.23' as const
6
6
 
7
7
  /**
8
8
  * This version number is incremented whenever the internal storage format changes in a breaking way.
@@ -1,28 +0,0 @@
1
- import type { ParseResult, Scope, WebChannel } from '@livestore/utils/effect';
2
- import { Duration, Effect, Schema, Subscribable } from '@livestore/utils/effect';
3
- export declare const RequestSessions: Schema.TaggedStruct<"RequestSessions", {}>;
4
- export type RequestSessions = typeof RequestSessions.Type;
5
- export declare const SessionInfo: Schema.TaggedStruct<"SessionInfo", {
6
- storeId: typeof Schema.String;
7
- clientId: typeof Schema.String;
8
- sessionId: typeof Schema.String;
9
- }>;
10
- export type SessionInfo = typeof SessionInfo.Type;
11
- export declare const Message: Schema.Union<[Schema.TaggedStruct<"RequestSessions", {}>, Schema.TaggedStruct<"SessionInfo", {
12
- storeId: typeof Schema.String;
13
- clientId: typeof Schema.String;
14
- sessionId: typeof Schema.String;
15
- }>]>;
16
- export type Message = typeof Message.Type;
17
- /** Usually called in client session */
18
- export declare const provideSessionInfo: ({ webChannel, sessionInfo, }: {
19
- webChannel: WebChannel.WebChannel<Message, Message>;
20
- sessionInfo: SessionInfo;
21
- }) => Effect.Effect<void, ParseResult.ParseError>;
22
- /** Usually called in devtools */
23
- export declare const requestSessionInfoSubscription: ({ webChannel, pollInterval, staleTimeout, }: {
24
- webChannel: WebChannel.WebChannel<Message, Message>;
25
- pollInterval?: Duration.DurationInput;
26
- staleTimeout?: Duration.DurationInput;
27
- }) => Effect.Effect<Subscribable.Subscribable<Set<SessionInfo>>, ParseResult.ParseError, Scope.Scope>;
28
- //# sourceMappingURL=devtools-sessions-channel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools-sessions-channel.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools-sessions-channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,EAEL,QAAQ,EACR,MAAM,EAIN,MAAM,EAEN,YAAY,EAEb,MAAM,yBAAyB,CAAA;AAEhC,eAAO,MAAM,eAAe,4CAA6C,CAAA;AACzE,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA;AAEzD,eAAO,MAAM,WAAW;;;;EAItB,CAAA;AACF,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAEjD,eAAO,MAAM,OAAO;;;;IAA6C,CAAA;AACjE,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAEzC,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,GAAI,8BAGhC;IACD,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,WAAW,EAAE,WAAW,CAAA;CACzB,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,UAAU,CAU1C,CAAA;AAEJ,iCAAiC;AACjC,eAAO,MAAM,8BAA8B,GAAI,6CAI5C;IACD,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,YAAY,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;IACrC,YAAY,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;CACtC,KAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CA2C9F,CAAA"}
@@ -1,34 +0,0 @@
1
- import { Data, Duration, Effect, FiberMap, HashSet, Schedule, Schema, Stream, Subscribable, SubscriptionRef, } from '@livestore/utils/effect';
2
- export const RequestSessions = Schema.TaggedStruct('RequestSessions', {});
3
- export const SessionInfo = Schema.TaggedStruct('SessionInfo', {
4
- storeId: Schema.String,
5
- clientId: Schema.String,
6
- sessionId: Schema.String,
7
- });
8
- export const Message = Schema.Union(RequestSessions, SessionInfo);
9
- /** Usually called in client session */
10
- export const provideSessionInfo = ({ webChannel, sessionInfo, }) => Effect.gen(function* () {
11
- yield* webChannel.send(sessionInfo);
12
- yield* webChannel.listen.pipe(Stream.flatten(), Stream.filter(Schema.is(RequestSessions)), Stream.tap(() => webChannel.send(sessionInfo)), Stream.runDrain);
13
- });
14
- /** Usually called in devtools */
15
- export const requestSessionInfoSubscription = ({ webChannel, pollInterval = Duration.seconds(1), staleTimeout = Duration.seconds(5), }) => Effect.gen(function* () {
16
- yield* webChannel
17
- .send(RequestSessions.make({}))
18
- .pipe(Effect.repeat(Schedule.spaced(pollInterval)), Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
19
- const timeoutFiberMap = yield* FiberMap.make();
20
- const sessionInfoSubRef = yield* SubscriptionRef.make(HashSet.empty());
21
- yield* webChannel.listen.pipe(Stream.flatten(), Stream.filter(Schema.is(SessionInfo)), Stream.map(Data.struct), Stream.tap(Effect.fn(function* (sessionInfo) {
22
- yield* SubscriptionRef.getAndUpdate(sessionInfoSubRef, HashSet.add(sessionInfo));
23
- // Remove sessionInfo from cache after staleTimeout (unless a new identical item resets the timeout)
24
- yield* FiberMap.run(timeoutFiberMap, sessionInfo, Effect.gen(function* () {
25
- yield* Effect.sleep(staleTimeout);
26
- yield* SubscriptionRef.getAndUpdate(sessionInfoSubRef, HashSet.remove(sessionInfo));
27
- }));
28
- })), Stream.runDrain, Effect.tapCauseLogPretty, Effect.forkScoped);
29
- return Subscribable.make({
30
- get: sessionInfoSubRef.get.pipe(Effect.map((sessionInfos) => new Set(sessionInfos))),
31
- changes: sessionInfoSubRef.changes.pipe(Stream.map((sessionInfos) => new Set(sessionInfos))),
32
- });
33
- });
34
- //# sourceMappingURL=devtools-sessions-channel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools-sessions-channel.js","sourceRoot":"","sources":["../../src/devtools/devtools-sessions-channel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,YAAY,EACZ,eAAe,GAChB,MAAM,yBAAyB,CAAA;AAEhC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,CAAC,i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AC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;QACpF,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;KAC7F,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,39 +0,0 @@
1
- import { Schema } from '@livestore/utils/effect';
2
- export * from './devtools-messages.js';
3
- export * from './devtools-window-message.js';
4
- export * as SessionsChannel from './devtools-sessions-channel.js';
5
- export declare const ClientSessionInfo: Schema.Struct<{
6
- storeId: typeof Schema.String;
7
- clientId: typeof Schema.String;
8
- sessionId: typeof Schema.String;
9
- }>;
10
- export declare const DevtoolsMode: Schema.Union<[Schema.TaggedStruct<"expo", {
11
- clientSessionInfo: Schema.UndefinedOr<Schema.Struct<{
12
- storeId: typeof Schema.String;
13
- clientId: typeof Schema.String;
14
- sessionId: typeof Schema.String;
15
- }>>;
16
- }>, Schema.TaggedStruct<"node", {
17
- clientSessionInfo: Schema.UndefinedOr<Schema.Struct<{
18
- storeId: typeof Schema.String;
19
- clientId: typeof Schema.String;
20
- sessionId: typeof Schema.String;
21
- }>>;
22
- url: typeof Schema.String;
23
- }>, Schema.TaggedStruct<"web", {
24
- clientSessionInfo: Schema.UndefinedOr<Schema.Struct<{
25
- storeId: typeof Schema.String;
26
- clientId: typeof Schema.String;
27
- sessionId: typeof Schema.String;
28
- }>>;
29
- }>, Schema.TaggedStruct<"browser-extension", {
30
- clientSessionInfo: Schema.UndefinedOr<Schema.Struct<{
31
- storeId: typeof Schema.String;
32
- clientId: typeof Schema.String;
33
- sessionId: typeof Schema.String;
34
- }>>;
35
- }>]>;
36
- export type DevtoolsMode = typeof DevtoolsMode.Type;
37
- export declare const DevtoolsModeTag: Schema.SchemaClass<"expo" | "node" | "web" | "browser-extension", "expo" | "node" | "web" | "browser-extension", never>;
38
- export type DevtoolsModeTag = typeof DevtoolsModeTag.Type;
39
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,OAAO,KAAK,eAAe,MAAM,gCAAgC,CAAA;AACjE,eAAO,MAAM,iBAAiB;;;;EAI5B,CAAA;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;IAexB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,eAAO,MAAM,eAAe,yHAA6D,CAAA;AACzF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA"}
@@ -1,23 +0,0 @@
1
- import { Schema } from '@livestore/utils/effect';
2
- export * from './devtools-messages.js';
3
- export * from './devtools-window-message.js';
4
- export * as SessionsChannel from './devtools-sessions-channel.js';
5
- export const ClientSessionInfo = Schema.Struct({
6
- storeId: Schema.String,
7
- clientId: Schema.String,
8
- sessionId: Schema.String,
9
- });
10
- export const DevtoolsMode = Schema.Union(Schema.TaggedStruct('expo', {
11
- clientSessionInfo: Schema.UndefinedOr(ClientSessionInfo),
12
- }),
13
- // TODO add storeId, clientId and sessionId for Node
14
- Schema.TaggedStruct('node', {
15
- clientSessionInfo: Schema.UndefinedOr(ClientSessionInfo),
16
- url: Schema.String,
17
- }), Schema.TaggedStruct('web', {
18
- clientSessionInfo: Schema.UndefinedOr(ClientSessionInfo),
19
- }), Schema.TaggedStruct('browser-extension', {
20
- clientSessionInfo: Schema.UndefinedOr(ClientSessionInfo),
21
- }));
22
- export const DevtoolsModeTag = DevtoolsMode.pipe(Schema.pluck('_tag'), Schema.typeSchema);
23
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,OAAO,KAAK,eAAe,MAAM,gCAAgC,CAAA;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CACtC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;IAC1B,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;CACzD,CAAC;AACF,oDAAoD;AACpD,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;IAC1B,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;IACxD,GAAG,EAAE,MAAM,CAAC,MAAM;CACnB,CAAC,EACF,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE;IACzB,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;CACzD,CAAC,EACF,MAAM,CAAC,YAAY,CAAC,mBAAmB,EAAE;IACvC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;CACzD,CAAC,CACH,CAAA;AAID,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA"}