@livestore/common 0.3.1 → 0.3.2-dev.1
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/ClientSessionLeaderThreadProxy.d.ts +35 -0
- package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -0
- package/dist/ClientSessionLeaderThreadProxy.js +6 -0
- package/dist/ClientSessionLeaderThreadProxy.js.map +1 -0
- package/dist/__tests__/fixture.d.ts +4 -4
- package/dist/__tests__/fixture.js +2 -2
- package/dist/adapter-types.d.ts +11 -162
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +5 -49
- package/dist/adapter-types.js.map +1 -1
- package/dist/debug-info.d.ts +2 -2
- package/dist/debug-info.js +2 -2
- package/dist/defs.d.ts +20 -0
- package/dist/defs.d.ts.map +1 -0
- package/dist/defs.js +12 -0
- package/dist/defs.js.map +1 -0
- package/dist/devtools/devtools-messages-client-session.d.ts +29 -27
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +4 -4
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-common.js +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +37 -35
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +4 -4
- package/dist/devtools/devtools-messages.d.ts +3 -3
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +3 -3
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/devtools/mod.d.ts +3 -3
- package/dist/devtools/mod.js +3 -3
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +36 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +10 -11
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +122 -132
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/connection.d.ts +4 -4
- package/dist/leader-thread/connection.js +2 -2
- package/dist/leader-thread/eventlog.d.ts +21 -10
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +39 -24
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +3 -3
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +4 -5
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +7 -7
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +44 -14
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +4 -4
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +14 -8
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/mod.d.ts +8 -7
- package/dist/leader-thread/mod.d.ts.map +1 -1
- package/dist/leader-thread/mod.js +8 -7
- package/dist/leader-thread/mod.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +14 -7
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +3 -5
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +1 -1
- package/dist/leader-thread/shutdown-channel.js +1 -1
- package/dist/leader-thread/types.d.ts +8 -10
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/make-client-session.d.ts +3 -3
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +3 -3
- package/dist/make-client-session.js.map +1 -1
- package/dist/materializer-helper.d.ts +5 -5
- package/dist/materializer-helper.js +5 -5
- package/dist/rematerialize-from-eventlog.d.ts +4 -4
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +13 -5
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef.d.ts +5 -5
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventDef.js +2 -2
- package/dist/schema/EventDef.js.map +1 -1
- package/dist/schema/EventSequenceNumber.d.ts +20 -2
- package/dist/schema/EventSequenceNumber.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber.js +71 -19
- package/dist/schema/EventSequenceNumber.js.map +1 -1
- package/dist/schema/EventSequenceNumber.test.js +89 -4
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent.d.ts +26 -12
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent.js +13 -5
- package/dist/schema/LiveStoreEvent.js.map +1 -1
- package/dist/schema/events.d.ts +1 -1
- package/dist/schema/events.d.ts.map +1 -1
- package/dist/schema/events.js +1 -1
- package/dist/schema/events.js.map +1 -1
- package/dist/schema/mod.d.ts +9 -9
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +9 -9
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +4 -4
- package/dist/schema/schema.js +3 -3
- package/dist/schema/state/mod.d.ts +2 -2
- package/dist/schema/state/mod.js +2 -2
- package/dist/schema/state/sqlite/client-document-def.d.ts +5 -5
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +6 -6
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +4 -6
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +2 -2
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +3 -3
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/hash.js +3 -2
- package/dist/schema/state/sqlite/db-schema/hash.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/mod.d.ts +2 -2
- package/dist/schema/state/sqlite/db-schema/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/mod.js +2 -2
- package/dist/schema/state/sqlite/db-schema/mod.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +7 -7
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +7 -7
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.d.ts +40 -13
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts +2 -2
- package/dist/schema/state/sqlite/query-builder/astToSql.js +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +2 -2
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +20 -25
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts +1 -81
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +36 -22
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/mod.d.ts +2 -2
- package/dist/schema/state/sqlite/query-builder/mod.js +2 -2
- package/dist/schema/state/sqlite/schema-helpers.d.ts +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js +1 -1
- package/dist/schema/state/sqlite/system-tables.d.ts +72 -67
- package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables.js +11 -20
- package/dist/schema/state/sqlite/system-tables.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.d.ts +3 -3
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +2 -2
- package/dist/schema-management/common.d.ts +2 -2
- package/dist/schema-management/common.js +1 -1
- package/dist/schema-management/migrations.d.ts +6 -4
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +5 -5
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts +4 -4
- package/dist/schema-management/validate-schema.js +1 -1
- package/dist/sql-queries/index.d.ts +3 -3
- package/dist/sql-queries/index.js +3 -3
- package/dist/sql-queries/sql-queries.d.ts +2 -2
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.js +5 -3
- package/dist/sql-queries/sql-queries.js.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts +3 -3
- package/dist/sql-queries/sql-query-builder.js +1 -1
- package/dist/sql-queries/types.d.ts +1 -1
- package/dist/sqlite-db-helper.d.ts +2 -2
- package/dist/sqlite-db-helper.js +1 -1
- package/dist/sqlite-types.d.ts +72 -0
- package/dist/sqlite-types.d.ts.map +1 -0
- package/dist/sqlite-types.js +5 -0
- package/dist/sqlite-types.js.map +1 -0
- package/dist/sync/ClientSessionSyncProcessor.d.ts +22 -7
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +43 -21
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/index.d.ts +3 -3
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +3 -3
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/next/compact-events.d.ts +1 -1
- package/dist/sync/next/compact-events.js +4 -4
- package/dist/sync/next/facts.d.ts +3 -3
- package/dist/sync/next/facts.js +2 -2
- package/dist/sync/next/graphology.d.ts.map +1 -1
- package/dist/sync/next/graphology.js +0 -6
- package/dist/sync/next/graphology.js.map +1 -1
- package/dist/sync/next/graphology_.d.ts +1 -1
- package/dist/sync/next/graphology_.d.ts.map +1 -1
- package/dist/sync/next/graphology_.js +1 -1
- package/dist/sync/next/graphology_.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +3 -3
- package/dist/sync/next/history-dag-common.js +2 -2
- package/dist/sync/next/history-dag.d.ts +2 -2
- package/dist/sync/next/history-dag.js +3 -3
- package/dist/sync/next/mod.d.ts +5 -5
- package/dist/sync/next/mod.d.ts.map +1 -1
- package/dist/sync/next/mod.js +5 -5
- package/dist/sync/next/mod.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +4 -4
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js +3 -2
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +4 -4
- package/dist/sync/next/test/compact-events.test.js +5 -5
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/event-fixtures.d.ts +3 -3
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/event-fixtures.js +17 -8
- package/dist/sync/next/test/event-fixtures.js.map +1 -1
- package/dist/sync/next/test/mod.d.ts +1 -1
- package/dist/sync/next/test/mod.js +1 -1
- package/dist/sync/sync.d.ts +6 -4
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +4 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/syncstate.d.ts +14 -5
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +25 -12
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +20 -21
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/validate-push-payload.d.ts +2 -2
- package/dist/sync/validate-push-payload.js +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +0 -1
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +6 -5
- package/src/ClientSessionLeaderThreadProxy.ts +40 -0
- package/src/__tests__/fixture.ts +2 -2
- package/src/adapter-types.ts +21 -167
- package/src/debug-info.ts +2 -2
- package/src/defs.ts +17 -0
- package/src/devtools/devtools-messages-client-session.ts +4 -4
- package/src/devtools/devtools-messages-common.ts +1 -1
- package/src/devtools/devtools-messages-leader.ts +4 -4
- package/src/devtools/devtools-messages.ts +3 -3
- package/src/devtools/mod.ts +3 -3
- package/src/errors.ts +49 -0
- package/src/index.ts +16 -16
- package/src/leader-thread/LeaderSyncProcessor.ts +154 -193
- package/src/leader-thread/connection.ts +5 -5
- package/src/leader-thread/eventlog.ts +89 -67
- package/src/leader-thread/leader-worker-devtools.ts +5 -6
- package/src/leader-thread/make-leader-thread-layer.ts +64 -20
- package/src/leader-thread/materialize-event.ts +17 -10
- package/src/leader-thread/mod.ts +8 -7
- package/src/leader-thread/recreate-db.ts +101 -93
- package/src/leader-thread/shutdown-channel.ts +1 -1
- package/src/leader-thread/types.ts +10 -15
- package/src/make-client-session.ts +5 -6
- package/src/materializer-helper.ts +11 -11
- package/src/rematerialize-from-eventlog.ts +16 -8
- package/src/schema/EventDef.ts +8 -6
- package/src/schema/EventSequenceNumber.test.ts +121 -4
- package/src/schema/EventSequenceNumber.ts +95 -23
- package/src/schema/LiveStoreEvent.ts +23 -7
- package/src/schema/events.ts +1 -1
- package/src/schema/mod.ts +9 -9
- package/src/schema/schema.ts +7 -7
- package/src/schema/state/mod.ts +2 -2
- package/src/schema/state/sqlite/client-document-def.test.ts +9 -7
- package/src/schema/state/sqlite/client-document-def.ts +45 -33
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +1 -1
- package/src/schema/state/sqlite/db-schema/ast/validate.ts +1 -1
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +1 -1
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +2 -2
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +19 -13
- package/src/schema/state/sqlite/db-schema/hash.ts +3 -4
- package/src/schema/state/sqlite/db-schema/mod.ts +2 -2
- package/src/schema/state/sqlite/mod.ts +13 -13
- package/src/schema/state/sqlite/query-builder/api.ts +43 -13
- package/src/schema/state/sqlite/query-builder/astToSql.ts +4 -4
- package/src/schema/state/sqlite/query-builder/impl.test.ts +63 -23
- package/src/schema/state/sqlite/query-builder/impl.ts +23 -28
- package/src/schema/state/sqlite/query-builder/mod.ts +2 -2
- package/src/schema/state/sqlite/schema-helpers.ts +2 -2
- package/src/schema/state/sqlite/system-tables.ts +12 -25
- package/src/schema/state/sqlite/table-def.ts +4 -4
- package/src/schema-management/common.ts +3 -3
- package/src/schema-management/migrations.ts +11 -9
- package/src/schema-management/validate-schema.ts +4 -4
- package/src/sql-queries/index.ts +3 -3
- package/src/sql-queries/sql-queries.ts +6 -4
- package/src/sql-queries/sql-query-builder.ts +4 -4
- package/src/sql-queries/types.ts +1 -1
- package/src/sqlite-db-helper.ts +3 -3
- package/src/sqlite-types.ts +76 -0
- package/src/sync/ClientSessionSyncProcessor.ts +65 -30
- package/src/sync/index.ts +3 -3
- package/src/sync/next/compact-events.ts +5 -5
- package/src/sync/next/facts.ts +4 -4
- package/src/sync/next/graphology.ts +3 -11
- package/src/sync/next/graphology_.ts +1 -1
- package/src/sync/next/history-dag-common.ts +3 -3
- package/src/sync/next/history-dag.ts +3 -3
- package/src/sync/next/mod.ts +5 -5
- package/src/sync/next/rebase-events.ts +7 -6
- package/src/sync/next/test/compact-events.calculator.test.ts +4 -4
- package/src/sync/next/test/compact-events.test.ts +6 -6
- package/src/sync/next/test/event-fixtures.ts +19 -10
- package/src/sync/next/test/mod.ts +1 -1
- package/src/sync/sync.ts +7 -4
- package/src/sync/syncstate.test.ts +25 -22
- package/src/sync/syncstate.ts +33 -12
- package/src/sync/validate-push-payload.ts +2 -2
- package/src/util.ts +0 -1
- package/src/version.ts +1 -1
package/src/adapter-types.ts
CHANGED
@@ -1,31 +1,23 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
export
|
20
|
-
|
21
|
-
finish: () => void
|
22
|
-
}
|
23
|
-
|
24
|
-
export type SqliteDbChangeset = {
|
25
|
-
// TODO combining changesets (requires changes in the SQLite WASM binding)
|
26
|
-
invert: () => SqliteDbChangeset
|
27
|
-
apply: () => void
|
28
|
-
}
|
1
|
+
import {
|
2
|
+
type Cause,
|
3
|
+
type Effect,
|
4
|
+
type Queue,
|
5
|
+
Schema,
|
6
|
+
type Scope,
|
7
|
+
type SubscriptionRef,
|
8
|
+
type WebChannel,
|
9
|
+
} from '@livestore/utils/effect'
|
10
|
+
|
11
|
+
import type { ClientSessionLeaderThreadProxy } from './ClientSessionLeaderThreadProxy.ts'
|
12
|
+
import type * as Devtools from './devtools/mod.ts'
|
13
|
+
import type { IntentionalShutdownCause, SyncError, UnexpectedError } from './errors.ts'
|
14
|
+
import type { LiveStoreSchema } from './schema/mod.ts'
|
15
|
+
import type { SqliteDb } from './sqlite-types.ts'
|
16
|
+
|
17
|
+
export * as ClientSessionLeaderThreadProxy from './ClientSessionLeaderThreadProxy.ts'
|
18
|
+
export * from './defs.ts'
|
19
|
+
export * from './errors.ts'
|
20
|
+
export * from './sqlite-types.ts'
|
29
21
|
|
30
22
|
export interface ClientSession {
|
31
23
|
/** SQLite database with synchronous API running in the same thread (usually in-memory) */
|
@@ -35,91 +27,13 @@ export interface ClientSession {
|
|
35
27
|
sessionId: string
|
36
28
|
/** Status info whether current session is leader or not */
|
37
29
|
lockStatus: SubscriptionRef.SubscriptionRef<LockStatus>
|
38
|
-
shutdown: (cause: Cause.Cause<UnexpectedError | IntentionalShutdownCause>) => Effect.Effect<void>
|
30
|
+
shutdown: (cause: Cause.Cause<UnexpectedError | IntentionalShutdownCause | SyncError>) => Effect.Effect<void>
|
39
31
|
/** A proxy API to communicate with the leader thread */
|
40
32
|
leaderThread: ClientSessionLeaderThreadProxy
|
41
33
|
/** A unique identifier for the current instance of the client session. Used for debugging purposes. */
|
42
34
|
debugInstanceId: string
|
43
35
|
}
|
44
36
|
|
45
|
-
export const LeaderPullCursor = Schema.Struct({
|
46
|
-
mergeCounter: Schema.Number,
|
47
|
-
eventNum: EventSequenceNumber.EventSequenceNumber,
|
48
|
-
})
|
49
|
-
|
50
|
-
export type LeaderPullCursor = typeof LeaderPullCursor.Type
|
51
|
-
|
52
|
-
export interface ClientSessionLeaderThreadProxy {
|
53
|
-
events: {
|
54
|
-
pull: (args: {
|
55
|
-
cursor: LeaderPullCursor
|
56
|
-
}) => Stream.Stream<{ payload: typeof PayloadUpstream.Type; mergeCounter: number }, UnexpectedError>
|
57
|
-
/** It's important that a client session doesn't call `push` concurrently. */
|
58
|
-
push(batch: ReadonlyArray<LiveStoreEvent.AnyEncoded>): Effect.Effect<void, UnexpectedError | LeaderAheadError>
|
59
|
-
}
|
60
|
-
/** The initial state after the leader thread has booted */
|
61
|
-
readonly initialState: {
|
62
|
-
/** The latest event sequence number during boot. Used for the client session to resume syncing. */
|
63
|
-
readonly leaderHead: EventSequenceNumber.EventSequenceNumber
|
64
|
-
/** The migrations report from the leader thread */
|
65
|
-
readonly migrationsReport: MigrationsReport
|
66
|
-
}
|
67
|
-
export: Effect.Effect<Uint8Array, UnexpectedError>
|
68
|
-
getEventlogData: Effect.Effect<Uint8Array, UnexpectedError>
|
69
|
-
getSyncState: Effect.Effect<SyncState, UnexpectedError>
|
70
|
-
/** For debugging purposes it can be useful to manually trigger devtools messages (e.g. to reset the database) */
|
71
|
-
sendDevtoolsMessage: (message: Devtools.Leader.MessageToApp) => Effect.Effect<void, UnexpectedError>
|
72
|
-
}
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Common interface for SQLite databases used by LiveStore to facilitate a consistent API across different platforms.
|
76
|
-
* Always assumes a synchronous SQLite build with the `bytecode` and `session` extensions enabled.
|
77
|
-
* Can be either in-memory or persisted to disk.
|
78
|
-
*/
|
79
|
-
export interface SqliteDb<TReq = any, TMetadata extends TReq = TReq> {
|
80
|
-
_tag: 'SqliteDb'
|
81
|
-
metadata: TMetadata
|
82
|
-
prepare(queryStr: string): PreparedStatement
|
83
|
-
execute(
|
84
|
-
queryStr: string,
|
85
|
-
bindValues?: PreparedBindValues | undefined,
|
86
|
-
options?: { onRowsChanged?: (rowsChanged: number) => void },
|
87
|
-
): void
|
88
|
-
execute(queryBuilder: QueryBuilder.Any, options?: { onRowsChanged?: (rowsChanged: number) => void }): void
|
89
|
-
|
90
|
-
select<T>(queryStr: string, bindValues?: PreparedBindValues | undefined): ReadonlyArray<T>
|
91
|
-
select<T>(queryBuilder: QueryBuilder<T, any, any>): ReadonlyArray<T>
|
92
|
-
|
93
|
-
export(): Uint8Array
|
94
|
-
import: (data: Uint8Array | SqliteDb<TReq>) => void
|
95
|
-
close(): void
|
96
|
-
destroy(): void
|
97
|
-
session(): SqliteDbSession
|
98
|
-
makeChangeset: (data: Uint8Array) => SqliteDbChangeset
|
99
|
-
}
|
100
|
-
|
101
|
-
// TODO refactor this helper type. It's quite cumbersome to use and should be revisited.
|
102
|
-
export type MakeSqliteDb<
|
103
|
-
TReq = { dbPointer: number; persistenceInfo: PersistenceInfo },
|
104
|
-
TInput_ extends { _tag: string } = { _tag: string },
|
105
|
-
TMetadata_ extends TReq = TReq,
|
106
|
-
R = never,
|
107
|
-
> = <
|
108
|
-
TInput extends TInput_,
|
109
|
-
TMetadata extends TMetadata_ & { _tag: TInput['_tag'] } = TMetadata_ & { _tag: TInput['_tag'] },
|
110
|
-
>(
|
111
|
-
input: TInput,
|
112
|
-
) => Effect.Effect<SqliteDb<TReq, Extract<TMetadata, { _tag: TInput['_tag'] }>>, SqliteError | UnexpectedError, R>
|
113
|
-
|
114
|
-
export const PersistenceInfo = Schema.Struct(
|
115
|
-
{
|
116
|
-
fileName: Schema.String,
|
117
|
-
},
|
118
|
-
{ key: Schema.String, value: Schema.Any },
|
119
|
-
).annotations({ title: 'LiveStore.PersistenceInfo' })
|
120
|
-
|
121
|
-
export type PersistenceInfo<With extends {} = {}> = typeof PersistenceInfo.Type & With
|
122
|
-
|
123
37
|
export type ResetMode = 'all-data' | 'only-app-db'
|
124
38
|
|
125
39
|
export const BootStateProgress = Schema.Struct({
|
@@ -164,50 +78,6 @@ export type SessionIdSymbol = typeof SessionIdSymbol
|
|
164
78
|
|
165
79
|
export type LockStatus = 'has-lock' | 'no-lock'
|
166
80
|
|
167
|
-
export class UnexpectedError extends Schema.TaggedError<UnexpectedError>()('LiveStore.UnexpectedError', {
|
168
|
-
cause: Schema.Defect,
|
169
|
-
note: Schema.optional(Schema.String),
|
170
|
-
payload: Schema.optional(Schema.Any),
|
171
|
-
}) {
|
172
|
-
static mapToUnexpectedError = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
173
|
-
effect.pipe(
|
174
|
-
Effect.mapError((cause) => (Schema.is(UnexpectedError)(cause) ? cause : new UnexpectedError({ cause }))),
|
175
|
-
Effect.catchAllDefect((cause) => new UnexpectedError({ cause })),
|
176
|
-
)
|
177
|
-
|
178
|
-
static mapToUnexpectedErrorStream = <A, E, R>(stream: Stream.Stream<A, E, R>) =>
|
179
|
-
stream.pipe(
|
180
|
-
Stream.mapError((cause) => (Schema.is(UnexpectedError)(cause) ? cause : new UnexpectedError({ cause }))),
|
181
|
-
)
|
182
|
-
}
|
183
|
-
|
184
|
-
export class IntentionalShutdownCause extends Schema.TaggedError<IntentionalShutdownCause>()(
|
185
|
-
'LiveStore.IntentionalShutdownCause',
|
186
|
-
{
|
187
|
-
reason: Schema.Literal('devtools-reset', 'devtools-import', 'adapter-reset', 'manual'),
|
188
|
-
},
|
189
|
-
) {}
|
190
|
-
|
191
|
-
export class StoreInterrupted extends Schema.TaggedError<StoreInterrupted>()('LiveStore.StoreInterrupted', {
|
192
|
-
reason: Schema.String,
|
193
|
-
}) {}
|
194
|
-
|
195
|
-
export class SqliteError extends Schema.TaggedError<SqliteError>()('LiveStore.SqliteError', {
|
196
|
-
query: Schema.optional(
|
197
|
-
Schema.Struct({
|
198
|
-
sql: Schema.String,
|
199
|
-
bindValues: Schema.Union(Schema.Record({ key: Schema.String, value: Schema.Any }), Schema.Array(Schema.Any)),
|
200
|
-
}),
|
201
|
-
),
|
202
|
-
/** The SQLite result code */
|
203
|
-
// code: Schema.optional(Schema.Number),
|
204
|
-
// Added string support for Expo SQLite (we should refactor this to have a unified error type)
|
205
|
-
code: Schema.optional(Schema.Union(Schema.Number, Schema.String)),
|
206
|
-
/** The original SQLite3 error */
|
207
|
-
cause: Schema.Defect,
|
208
|
-
note: Schema.optional(Schema.String),
|
209
|
-
}) {}
|
210
|
-
|
211
81
|
// TODO possibly allow a combination of these options
|
212
82
|
// TODO allow a way to stream the migration progress back to the app
|
213
83
|
export type MigrationOptions =
|
@@ -258,19 +128,3 @@ export interface AdapterArgs {
|
|
258
128
|
*/
|
259
129
|
syncPayload: Schema.JsonValue | undefined
|
260
130
|
}
|
261
|
-
|
262
|
-
export const MigrationsReportEntry = Schema.Struct({
|
263
|
-
tableName: Schema.String,
|
264
|
-
hashes: Schema.Struct({
|
265
|
-
expected: Schema.Number,
|
266
|
-
actual: Schema.optional(Schema.Number),
|
267
|
-
}),
|
268
|
-
})
|
269
|
-
|
270
|
-
export const MigrationsReport = Schema.Struct({
|
271
|
-
migrations: Schema.Array(MigrationsReportEntry),
|
272
|
-
})
|
273
|
-
|
274
|
-
export type MigrationsReport = typeof MigrationsReport.Type
|
275
|
-
|
276
|
-
export type MigrationsReportEntry = typeof MigrationsReportEntry.Type
|
package/src/debug-info.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
/// <reference lib="dom" />
|
2
2
|
import { ParseResult, Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { BoundArray } from './bounded-collections.
|
5
|
-
import { PreparedBindValues } from './util.
|
4
|
+
import { BoundArray } from './bounded-collections.ts'
|
5
|
+
import { PreparedBindValues } from './util.ts'
|
6
6
|
|
7
7
|
export type SlowQueryInfo = {
|
8
8
|
queryStr: string
|
package/src/defs.ts
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Schema } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
export const MigrationsReportEntry = Schema.Struct({
|
4
|
+
tableName: Schema.String,
|
5
|
+
hashes: Schema.Struct({
|
6
|
+
expected: Schema.Number,
|
7
|
+
actual: Schema.optional(Schema.Number),
|
8
|
+
}),
|
9
|
+
})
|
10
|
+
|
11
|
+
export const MigrationsReport = Schema.Struct({
|
12
|
+
migrations: Schema.Array(MigrationsReportEntry),
|
13
|
+
})
|
14
|
+
|
15
|
+
export type MigrationsReport = typeof MigrationsReport.Type
|
16
|
+
|
17
|
+
export type MigrationsReportEntry = typeof MigrationsReportEntry.Type
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import { DebugInfo } from '../debug-info.
|
4
|
-
import { EventSequenceNumber } from '../schema/mod.
|
5
|
-
import { PreparedBindValues } from '../util.
|
6
|
-
import { LSDClientSessionChannelMessage, LSDClientSessionReqResMessage } from './devtools-messages-common.
|
3
|
+
import { DebugInfo } from '../debug-info.ts'
|
4
|
+
import { EventSequenceNumber } from '../schema/mod.ts'
|
5
|
+
import { PreparedBindValues } from '../util.ts'
|
6
|
+
import { LSDClientSessionChannelMessage, LSDClientSessionReqResMessage } from './devtools-messages-common.ts'
|
7
7
|
|
8
8
|
export class DebugInfoReq extends LSDClientSessionReqResMessage('LSD.ClientSession.DebugInfoReq', {}) {}
|
9
9
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Schema, Transferable } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import * as LiveStoreEvent from '../schema/LiveStoreEvent.
|
4
|
-
import { EventSequenceNumber } from '../schema/mod.
|
5
|
-
import * as SyncState from '../sync/syncstate.
|
6
|
-
import { LeaderReqResMessage, LSDMessage, LSDReqResMessage, NetworkStatus } from './devtools-messages-common.
|
3
|
+
import * as LiveStoreEvent from '../schema/LiveStoreEvent.ts'
|
4
|
+
import { EventSequenceNumber } from '../schema/mod.ts'
|
5
|
+
import * as SyncState from '../sync/syncstate.ts'
|
6
|
+
import { LeaderReqResMessage, LSDMessage, LSDReqResMessage, NetworkStatus } from './devtools-messages-common.ts'
|
7
7
|
|
8
8
|
export class ResetAllDataReq extends LSDReqResMessage('LSD.Leader.ResetAllDataReq', {
|
9
9
|
mode: Schema.Literal('all-data', 'only-app-db'),
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * as ClientSession from './devtools-messages-client-session.
|
2
|
-
export *
|
3
|
-
export * from './devtools-messages-
|
1
|
+
export * as ClientSession from './devtools-messages-client-session.ts'
|
2
|
+
export * from './devtools-messages-common.ts'
|
3
|
+
export * as Leader from './devtools-messages-leader.ts'
|
package/src/devtools/mod.ts
CHANGED
@@ -3,10 +3,10 @@ import { Schema } from '@livestore/utils/effect'
|
|
3
3
|
import { nanoid } from '@livestore/utils/nanoid'
|
4
4
|
import type { MeshNode } from '@livestore/webmesh'
|
5
5
|
|
6
|
-
import * as SessionInfo from './devtools-sessioninfo.
|
6
|
+
import * as SessionInfo from './devtools-sessioninfo.ts'
|
7
7
|
|
8
|
-
export * from './devtools-messages.
|
9
|
-
export * as SessionInfo from './devtools-sessioninfo.
|
8
|
+
export * from './devtools-messages.ts'
|
9
|
+
export * as SessionInfo from './devtools-sessioninfo.ts'
|
10
10
|
|
11
11
|
export const DevtoolsMode = Schema.Union(
|
12
12
|
Schema.TaggedStruct('node', {
|
package/src/errors.ts
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
import { Effect, Schema, Stream } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
export class UnexpectedError extends Schema.TaggedError<UnexpectedError>()('LiveStore.UnexpectedError', {
|
4
|
+
cause: Schema.Defect,
|
5
|
+
note: Schema.optional(Schema.String),
|
6
|
+
payload: Schema.optional(Schema.Any),
|
7
|
+
}) {
|
8
|
+
static mapToUnexpectedError = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
9
|
+
effect.pipe(
|
10
|
+
Effect.mapError((cause) => (Schema.is(UnexpectedError)(cause) ? cause : new UnexpectedError({ cause }))),
|
11
|
+
Effect.catchAllDefect((cause) => new UnexpectedError({ cause })),
|
12
|
+
)
|
13
|
+
|
14
|
+
static mapToUnexpectedErrorStream = <A, E, R>(stream: Stream.Stream<A, E, R>) =>
|
15
|
+
stream.pipe(
|
16
|
+
Stream.mapError((cause) => (Schema.is(UnexpectedError)(cause) ? cause : new UnexpectedError({ cause }))),
|
17
|
+
)
|
18
|
+
}
|
19
|
+
|
20
|
+
export class SyncError extends Schema.TaggedError<SyncError>()('LiveStore.SyncError', {
|
21
|
+
cause: Schema.Defect,
|
22
|
+
}) {}
|
23
|
+
|
24
|
+
export class IntentionalShutdownCause extends Schema.TaggedError<IntentionalShutdownCause>()(
|
25
|
+
'LiveStore.IntentionalShutdownCause',
|
26
|
+
{
|
27
|
+
reason: Schema.Literal('devtools-reset', 'devtools-import', 'adapter-reset', 'manual'),
|
28
|
+
},
|
29
|
+
) {}
|
30
|
+
|
31
|
+
export class StoreInterrupted extends Schema.TaggedError<StoreInterrupted>()('LiveStore.StoreInterrupted', {
|
32
|
+
reason: Schema.String,
|
33
|
+
}) {}
|
34
|
+
|
35
|
+
export class SqliteError extends Schema.TaggedError<SqliteError>()('LiveStore.SqliteError', {
|
36
|
+
query: Schema.optional(
|
37
|
+
Schema.Struct({
|
38
|
+
sql: Schema.String,
|
39
|
+
bindValues: Schema.Union(Schema.Record({ key: Schema.String, value: Schema.Any }), Schema.Array(Schema.Any)),
|
40
|
+
}),
|
41
|
+
),
|
42
|
+
/** The SQLite result code */
|
43
|
+
// code: Schema.optional(Schema.Number),
|
44
|
+
// Added string support for Expo SQLite (we should refactor this to have a unified error type)
|
45
|
+
code: Schema.optional(Schema.Union(Schema.Number, Schema.String)),
|
46
|
+
/** The original SQLite3 error */
|
47
|
+
cause: Schema.Defect,
|
48
|
+
note: Schema.optional(Schema.String),
|
49
|
+
}) {}
|
package/src/index.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './
|
3
|
-
export * from './
|
4
|
-
export * from './
|
5
|
-
export * from './
|
6
|
-
export * from './
|
7
|
-
export * from './
|
8
|
-
export *
|
9
|
-
export * from './
|
10
|
-
export * from './
|
11
|
-
export * from './
|
12
|
-
export * from './
|
13
|
-
export *
|
14
|
-
export * from './
|
15
|
-
export * from './
|
16
|
-
export *
|
1
|
+
export * from './adapter-types.ts'
|
2
|
+
export * from './bounded-collections.ts'
|
3
|
+
export * from './debug-info.ts'
|
4
|
+
export * as Devtools from './devtools/mod.ts'
|
5
|
+
export * from './make-client-session.ts'
|
6
|
+
export * from './materializer-helper.ts'
|
7
|
+
export * from './otel.ts'
|
8
|
+
export * from './rematerialize-from-eventlog.ts'
|
9
|
+
export * from './schema/state/sqlite/query-builder/mod.ts'
|
10
|
+
export * from './schema/state/sqlite/system-tables.ts'
|
11
|
+
export * from './schema-management/migrations.ts'
|
12
|
+
export * as SqliteDbHelper from './sqlite-db-helper.ts'
|
13
|
+
export * from './sync/index.ts'
|
14
|
+
export * as SyncState from './sync/syncstate.ts'
|
15
|
+
export * from './util.ts'
|
16
|
+
export * from './version.ts'
|