@livestore/common 0.3.0-dev.42 → 0.3.0-dev.44
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/__tests__/fixture.d.ts +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-leader.d.ts +24 -24
- package/dist/make-client-session.d.ts +2 -1
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +8 -1
- package/dist/make-client-session.js.map +1 -1
- package/dist/schema/schema.d.ts +8 -8
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +2 -2
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
- package/src/make-client-session.ts +14 -0
- package/src/schema/schema.ts +6 -6
- package/src/schema/state/sqlite/mod.ts +2 -2
- package/src/version.ts +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@livestore/common",
|
3
|
-
"version": "0.3.0-dev.
|
3
|
+
"version": "0.3.0-dev.44",
|
4
4
|
"type": "module",
|
5
5
|
"sideEffects": false,
|
6
6
|
"exports": {
|
@@ -54,12 +54,12 @@
|
|
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.
|
58
|
-
"@livestore/webmesh": "0.3.0-dev.
|
57
|
+
"@livestore/utils": "0.3.0-dev.44",
|
58
|
+
"@livestore/webmesh": "0.3.0-dev.44"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|
61
|
-
"vitest": "^3.1.
|
62
|
-
"@livestore/utils-dev": "0.3.0-dev.
|
61
|
+
"vitest": "^3.1.2",
|
62
|
+
"@livestore/utils-dev": "0.3.0-dev.44"
|
63
63
|
},
|
64
64
|
"files": [
|
65
65
|
"package.json",
|
@@ -11,6 +11,7 @@ import type {
|
|
11
11
|
UnexpectedError,
|
12
12
|
} from './adapter-types.js'
|
13
13
|
import * as Devtools from './devtools/mod.js'
|
14
|
+
import { liveStoreVersion } from './version.js'
|
14
15
|
|
15
16
|
declare global {
|
16
17
|
// eslint-disable-next-line no-var
|
@@ -30,6 +31,7 @@ export const makeClientSession = <R>({
|
|
30
31
|
shutdown,
|
31
32
|
connectWebmeshNode,
|
32
33
|
webmeshMode,
|
34
|
+
registerBeforeUnload,
|
33
35
|
}: AdapterArgs & {
|
34
36
|
clientId: string
|
35
37
|
sessionId: string
|
@@ -41,6 +43,7 @@ export const makeClientSession = <R>({
|
|
41
43
|
sessionInfo: Devtools.SessionInfo.SessionInfo
|
42
44
|
}) => Effect.Effect<void, UnexpectedError, Scope.Scope | R>
|
43
45
|
webmeshMode: 'direct' | 'proxy'
|
46
|
+
registerBeforeUnload: (onBeforeUnload: () => void) => () => void
|
44
47
|
}): Effect.Effect<ClientSession, never, Scope.Scope | R> =>
|
45
48
|
Effect.gen(function* () {
|
46
49
|
const devtools: ClientSession['devtools'] = devtoolsEnabled
|
@@ -92,6 +95,17 @@ export const makeClientSession = <R>({
|
|
92
95
|
mode: webmeshMode,
|
93
96
|
})
|
94
97
|
|
98
|
+
const onBeforeUnload = () => {
|
99
|
+
clientSessionDevtoolsChannel
|
100
|
+
.send(Devtools.ClientSession.Disconnect.make({ clientId, liveStoreVersion, sessionId }))
|
101
|
+
.pipe(Effect.runFork)
|
102
|
+
}
|
103
|
+
|
104
|
+
yield* Effect.acquireRelease(
|
105
|
+
Effect.sync(() => registerBeforeUnload(onBeforeUnload)),
|
106
|
+
(unsub) => Effect.sync(() => unsub()),
|
107
|
+
)
|
108
|
+
|
95
109
|
yield* connectDevtoolsToStore(clientSessionDevtoolsChannel)
|
96
110
|
},
|
97
111
|
Effect.tapCauseLogPretty,
|
package/src/schema/schema.ts
CHANGED
@@ -11,17 +11,17 @@ import type { TableDef } from './state/sqlite/table-def.js'
|
|
11
11
|
export const LiveStoreSchemaSymbol = Symbol.for('livestore.LiveStoreSchema')
|
12
12
|
export type LiveStoreSchemaSymbol = typeof LiveStoreSchemaSymbol
|
13
13
|
|
14
|
-
export
|
14
|
+
export interface LiveStoreSchema<
|
15
15
|
TDbSchema extends SqliteDsl.DbSchema = SqliteDsl.DbSchema,
|
16
16
|
TEventsDefRecord extends EventDefRecord = EventDefRecord,
|
17
|
-
>
|
17
|
+
> {
|
18
18
|
readonly LiveStoreSchemaSymbol: LiveStoreSchemaSymbol
|
19
19
|
/** Only used on type-level */
|
20
20
|
readonly _DbSchemaType: TDbSchema
|
21
21
|
/** Only used on type-level */
|
22
22
|
readonly _EventDefMapType: TEventsDefRecord
|
23
23
|
|
24
|
-
readonly state:
|
24
|
+
readonly state: InternalState
|
25
25
|
readonly eventsDefsMap: Map<string, EventDef.AnyWithoutFn>
|
26
26
|
readonly devtools: {
|
27
27
|
/** @default 'default' */
|
@@ -30,7 +30,7 @@ export type LiveStoreSchema<
|
|
30
30
|
}
|
31
31
|
|
32
32
|
// TODO abstract this further away from sqlite/tables
|
33
|
-
export
|
33
|
+
export interface InternalState {
|
34
34
|
readonly sqlite: {
|
35
35
|
readonly tables: Map<string, TableDef.Any>
|
36
36
|
readonly migrations: MigrationOptions
|
@@ -40,9 +40,9 @@ export type State = {
|
|
40
40
|
readonly materializers: Map<string, Materializer>
|
41
41
|
}
|
42
42
|
|
43
|
-
export
|
43
|
+
export interface InputSchema {
|
44
44
|
readonly events: ReadonlyArray<EventDef.AnyWithoutFn> | Record<string, EventDef.AnyWithoutFn>
|
45
|
-
readonly state:
|
45
|
+
readonly state: InternalState
|
46
46
|
readonly devtools?: {
|
47
47
|
/**
|
48
48
|
* This alias value is used to disambiguate between multiple schemas in the devtools.
|
@@ -2,7 +2,7 @@ import { shouldNeverHappen } from '@livestore/utils'
|
|
2
2
|
|
3
3
|
import type { MigrationOptions } from '../../../adapter-types.js'
|
4
4
|
import { type Materializer, rawSqlEvent, rawSqlMaterializer } from '../../EventDef.js'
|
5
|
-
import type {
|
5
|
+
import type { InternalState } from '../../schema.js'
|
6
6
|
import { ClientDocumentTableDefSymbol, tableIsClientDocumentTable } from './client-document-def.js'
|
7
7
|
import { SqliteAst } from './db-schema/mod.js'
|
8
8
|
import { stateSystemTables } from './system-tables.js'
|
@@ -18,7 +18,7 @@ export {
|
|
18
18
|
} from './client-document-def.js'
|
19
19
|
export * from '../../EventDef.js'
|
20
20
|
|
21
|
-
export const makeState = <TStateInput extends InputState>(inputSchema: TStateInput):
|
21
|
+
export const makeState = <TStateInput extends InputState>(inputSchema: TStateInput): InternalState => {
|
22
22
|
const inputTables: ReadonlyArray<TableDef> = Array.isArray(inputSchema.tables)
|
23
23
|
? inputSchema.tables
|
24
24
|
: Object.values(inputSchema.tables)
|
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.
|
5
|
+
export const liveStoreVersion = '0.3.0-dev.44' as const
|
6
6
|
|
7
7
|
/**
|
8
8
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|