@livestore/common 0.0.55-dev.2 → 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 +37 -15
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +8 -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 +35 -2
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/index.js +36 -2
- 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 +8 -3
- package/src/devtools/devtools-window-message.ts +1 -1
- package/src/devtools/index.ts +36 -3
- package/src/schema/index.ts +10 -0
package/src/devtools/index.ts
CHANGED
|
@@ -1,13 +1,46 @@
|
|
|
1
|
+
import type { Effect, Scope } from '@livestore/utils/effect'
|
|
1
2
|
import { BrowserChannel, Schema } from '@livestore/utils/effect'
|
|
2
3
|
|
|
3
4
|
export * from './devtools-messages.js'
|
|
4
5
|
export * from './devtools-window-message.js'
|
|
5
6
|
|
|
6
7
|
export namespace WebBridge {
|
|
7
|
-
export
|
|
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> =>
|
|
8
41
|
BrowserChannel.broadcastChannel({
|
|
9
42
|
channelName: `livestore-web-bridge-devtools${key ? `-${key}` : ''}`,
|
|
10
|
-
listenSchema:
|
|
11
|
-
sendSchema:
|
|
43
|
+
listenSchema: All,
|
|
44
|
+
sendSchema: All,
|
|
12
45
|
})
|
|
13
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
|
|