@livestore/common 0.0.55-dev.1 → 0.0.55-dev.3
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/dist/.tsbuildinfo +1 -1
- package/dist/adapter-types.d.ts +4 -9
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/devtools/devtools-messages.d.ts +67 -15
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +19 -4
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/devtools/devtools-window-message.d.ts +1 -1
- package/dist/devtools/devtools-window-message.js +1 -1
- package/dist/devtools/devtools-window-message.js.map +1 -1
- package/dist/devtools/index.d.ts +37 -0
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/index.js +43 -0
- package/dist/devtools/index.js.map +1 -1
- package/dist/schema/index.d.ts +8 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -0
- package/dist/schema/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter-types.ts +10 -4
- package/src/devtools/devtools-messages.ts +21 -3
- package/src/devtools/devtools-window-message.ts +1 -1
- package/src/devtools/index.ts +44 -0
- package/src/schema/index.ts +10 -0
|
@@ -135,10 +135,24 @@ export class MessagePortForStoreRes extends LSDReqResMessage('LSD.MessagePortFor
|
|
|
135
135
|
port: Transferable.MessagePort,
|
|
136
136
|
}) {}
|
|
137
137
|
|
|
138
|
-
export class
|
|
138
|
+
export class NetworkStatusSubscribe extends LSDReqResMessage('LSD.NetworkStatusSubscribe', {}) {}
|
|
139
|
+
export class NetworkStatusUnsubscribe extends LSDReqResMessage('LSD.NetworkStatusUnsubscribe', {}) {}
|
|
140
|
+
|
|
141
|
+
export class NetworkStatusRes extends LSDReqResMessage('LSD.NetworkStatusRes', {
|
|
139
142
|
networkStatus: NetworkStatus,
|
|
140
143
|
}) {}
|
|
141
144
|
|
|
145
|
+
export class SyncingInfoReq extends LSDReqResMessage('LSD.SyncingInfoReq', {}) {}
|
|
146
|
+
|
|
147
|
+
export class SyncingInfo extends Schema.Struct({
|
|
148
|
+
enabled: Schema.Boolean,
|
|
149
|
+
metadata: Schema.Record({ key: Schema.String, value: Schema.Any }),
|
|
150
|
+
}) {}
|
|
151
|
+
|
|
152
|
+
export class SyncingInfoRes extends LSDReqResMessage('LSD.SyncingInfoRes', {
|
|
153
|
+
syncingInfo: SyncingInfo,
|
|
154
|
+
}) {}
|
|
155
|
+
|
|
142
156
|
export class DevtoolsReady extends LSDMessage('LSD.DevtoolsReady', {}) {}
|
|
143
157
|
|
|
144
158
|
export class DevtoolsConnected extends LSDChannelMessage('LSD.DevtoolsConnected', {}) {}
|
|
@@ -147,7 +161,7 @@ export class AppHostReady extends LSDChannelMessage('LSD.AppHostReady', {
|
|
|
147
161
|
isLeaderTab: Schema.Boolean,
|
|
148
162
|
}) {}
|
|
149
163
|
|
|
150
|
-
export class Disconnect extends
|
|
164
|
+
export class Disconnect extends LSDChannelMessage('LSD.Disconnect', {}) {}
|
|
151
165
|
|
|
152
166
|
export class Ping extends LSDReqResMessage('LSD.Ping', {}) {}
|
|
153
167
|
|
|
@@ -159,12 +173,15 @@ export const MessageToAppHostCoordinator = Schema.Union(
|
|
|
159
173
|
MutationLogReq,
|
|
160
174
|
ResetAllDataReq,
|
|
161
175
|
MessagePortForStoreRes,
|
|
176
|
+
NetworkStatusSubscribe,
|
|
177
|
+
NetworkStatusUnsubscribe,
|
|
162
178
|
DevtoolsReady,
|
|
163
179
|
Disconnect,
|
|
164
180
|
DevtoolsConnected,
|
|
165
181
|
RunMutationReq,
|
|
166
182
|
Ping,
|
|
167
183
|
DatabaseFileInfoReq,
|
|
184
|
+
SyncingInfoReq,
|
|
168
185
|
).annotations({ identifier: 'LSD.MessageToAppHostCoordinator' })
|
|
169
186
|
|
|
170
187
|
export type MessageToAppHostCoordinator = typeof MessageToAppHostCoordinator.Type
|
|
@@ -193,10 +210,11 @@ export const MessageFromAppHostCoordinator = Schema.Union(
|
|
|
193
210
|
Disconnect,
|
|
194
211
|
MutationBroadcast,
|
|
195
212
|
AppHostReady,
|
|
196
|
-
|
|
213
|
+
NetworkStatusRes,
|
|
197
214
|
RunMutationRes,
|
|
198
215
|
Pong,
|
|
199
216
|
DatabaseFileInfoRes,
|
|
217
|
+
SyncingInfoRes,
|
|
200
218
|
).annotations({ identifier: 'LSD.MessageFromAppHostCoordinator' })
|
|
201
219
|
|
|
202
220
|
export type MessageFromAppHostCoordinator = typeof MessageFromAppHostCoordinator.Type
|
|
@@ -4,7 +4,7 @@ const channelId = Schema.String
|
|
|
4
4
|
|
|
5
5
|
export namespace DevtoolsWindowMessage {
|
|
6
6
|
/** Message is being created in contentscript-iframe, sent to contentscript and then sent to Store */
|
|
7
|
-
export class MessagePortReady extends Schema.TaggedStruct('LSD.WindowMessage.
|
|
7
|
+
export class MessagePortReady extends Schema.TaggedStruct('LSD.WindowMessage.MessagePortReady', {
|
|
8
8
|
port: Transferable.MessagePort,
|
|
9
9
|
channelId,
|
|
10
10
|
}) {}
|
package/src/devtools/index.ts
CHANGED
|
@@ -1,2 +1,46 @@
|
|
|
1
|
+
import type { Effect, Scope } from '@livestore/utils/effect'
|
|
2
|
+
import { BrowserChannel, Schema } from '@livestore/utils/effect'
|
|
3
|
+
|
|
1
4
|
export * from './devtools-messages.js'
|
|
2
5
|
export * from './devtools-window-message.js'
|
|
6
|
+
|
|
7
|
+
export namespace WebBridge {
|
|
8
|
+
export class AppHostReady extends Schema.TaggedStruct('LSD.WebBridge.AppHostReady', {
|
|
9
|
+
channelId: Schema.String,
|
|
10
|
+
isLeader: Schema.Boolean,
|
|
11
|
+
}) {}
|
|
12
|
+
|
|
13
|
+
export class DevtoolsReady extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsReady', {
|
|
14
|
+
devtoolsId: Schema.String,
|
|
15
|
+
}) {}
|
|
16
|
+
|
|
17
|
+
export class ConnectToDevtools extends Schema.TaggedStruct('LSD.WebBridge.ConnectToDevtools', {
|
|
18
|
+
devtoolsId: Schema.String,
|
|
19
|
+
channelId: Schema.String,
|
|
20
|
+
/**
|
|
21
|
+
* Given the m:n relationship between devtools and app hosts and the fact that channelIds are usually
|
|
22
|
+
* sticky, we generate a new unique id for the lifetime of the web bridge.
|
|
23
|
+
*/
|
|
24
|
+
webBridgeId: Schema.String,
|
|
25
|
+
isLeader: Schema.Boolean,
|
|
26
|
+
}) {}
|
|
27
|
+
|
|
28
|
+
export class AppHostWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.AppHostWillDisconnect', {
|
|
29
|
+
channelId: Schema.String,
|
|
30
|
+
}) {}
|
|
31
|
+
|
|
32
|
+
// export class DevtoolsWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsWillDisconnect', {
|
|
33
|
+
// channelId: Schema.String,
|
|
34
|
+
// }) {}
|
|
35
|
+
|
|
36
|
+
export class All extends Schema.Union(AppHostReady, DevtoolsReady, ConnectToDevtools, AppHostWillDisconnect) {}
|
|
37
|
+
|
|
38
|
+
export const makeBroadcastChannel = (
|
|
39
|
+
key?: string,
|
|
40
|
+
): Effect.Effect<BrowserChannel.BrowserChannel<typeof All.Type, typeof All.Type>, never, Scope.Scope> =>
|
|
41
|
+
BrowserChannel.broadcastChannel({
|
|
42
|
+
channelName: `livestore-web-bridge-devtools${key ? `-${key}` : ''}`,
|
|
43
|
+
listenSchema: All,
|
|
44
|
+
sendSchema: All,
|
|
45
|
+
})
|
|
46
|
+
}
|
package/src/schema/index.ts
CHANGED
|
@@ -40,11 +40,20 @@ export type LiveStoreSchema<
|
|
|
40
40
|
readonly hash: number
|
|
41
41
|
|
|
42
42
|
migrationOptions: MigrationOptions
|
|
43
|
+
|
|
44
|
+
key: string
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export type InputSchema = {
|
|
46
48
|
readonly tables: Record<string, TableDef> | ReadonlyArray<TableDef>
|
|
47
49
|
readonly mutations?: ReadonlyArray<MutationDef.Any> | Record<string, MutationDef.Any>
|
|
50
|
+
/**
|
|
51
|
+
* Can be used to isolate multiple LiveStore apps running in the same origin
|
|
52
|
+
*
|
|
53
|
+
* Make sure you also use this key in the `storage` options (e.g. directory, prefix etc) to make sure
|
|
54
|
+
* different instances of LiveStore aren't overlapping on the storage level.
|
|
55
|
+
*/
|
|
56
|
+
readonly key?: string
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
export const makeSchema = <TInputSchema extends InputSchema>(
|
|
@@ -111,6 +120,7 @@ export const makeSchema = <TInputSchema extends InputSchema>(
|
|
|
111
120
|
mutations,
|
|
112
121
|
migrationOptions: inputSchema.migrations ?? { strategy: 'hard-reset' },
|
|
113
122
|
hash,
|
|
123
|
+
key: inputSchema.key ?? '',
|
|
114
124
|
} satisfies LiveStoreSchema
|
|
115
125
|
}
|
|
116
126
|
|