@livestore/common 0.3.2-dev.0 → 0.3.2-dev.5
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 +7 -7
- package/dist/__tests__/fixture.d.ts +4 -4
- package/dist/__tests__/fixture.js +2 -2
- package/dist/adapter-types.d.ts +9 -9
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +4 -4
- 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/devtools/devtools-messages-client-session.d.ts +27 -27
- 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.js +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +35 -35
- 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/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 +5 -5
- package/dist/leader-thread/LeaderSyncProcessor.js +11 -11
- 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 +7 -7
- package/dist/leader-thread/eventlog.js +8 -8
- 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.js +3 -3
- package/dist/leader-thread/make-leader-thread-layer.d.ts +7 -7
- package/dist/leader-thread/make-leader-thread-layer.js +10 -10
- package/dist/leader-thread/materialize-event.d.ts +4 -4
- package/dist/leader-thread/materialize-event.js +7 -7
- package/dist/leader-thread/mod.d.ts +8 -8
- package/dist/leader-thread/mod.d.ts.map +1 -1
- package/dist/leader-thread/mod.js +8 -8
- package/dist/leader-thread/mod.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +5 -5
- package/dist/leader-thread/recreate-db.js +2 -2
- 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 +6 -6
- package/dist/make-client-session.d.ts +2 -2
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +2 -2
- 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.js +3 -3
- package/dist/schema/EventDef.d.ts +4 -32
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventDef.js +0 -15
- package/dist/schema/EventDef.js.map +1 -1
- package/dist/schema/EventSequenceNumber.test.js +1 -1
- package/dist/schema/LiveStoreEvent.d.ts +5 -5
- package/dist/schema/LiveStoreEvent.js +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 -8
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +2 -4
- package/dist/schema/schema.js.map +1 -1
- 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 +17 -5
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +18 -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.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 +0 -1
- 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 +6 -8
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.d.ts +5 -5
- 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 +4 -14
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +3 -3
- 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 +10 -10
- package/dist/schema/state/sqlite/system-tables.js +3 -3
- package/dist/schema/state/sqlite/table-def.d.ts +2 -2
- 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 -6
- package/dist/schema-management/migrations.js +5 -5
- 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.js +3 -3
- 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 +4 -4
- package/dist/sync/ClientSessionSyncProcessor.d.ts +17 -6
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +30 -11
- 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.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 +2 -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 +4 -4
- package/dist/sync/next/test/event-fixtures.d.ts +3 -3
- package/dist/sync/next/test/event-fixtures.js +5 -5
- 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 +4 -4
- package/dist/sync/sync.js +1 -1
- package/dist/sync/syncstate.d.ts +1 -1
- package/dist/sync/syncstate.js +2 -2
- package/dist/sync/syncstate.test.js +3 -4
- 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.js +1 -1
- package/package.json +6 -6
- package/src/ClientSessionLeaderThreadProxy.ts +7 -7
- package/src/__tests__/fixture.ts +2 -2
- package/src/adapter-types.ts +10 -9
- package/src/debug-info.ts +2 -2
- 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/index.ts +16 -16
- package/src/leader-thread/LeaderSyncProcessor.ts +14 -14
- package/src/leader-thread/connection.ts +5 -5
- package/src/leader-thread/eventlog.ts +12 -12
- package/src/leader-thread/leader-worker-devtools.ts +4 -4
- package/src/leader-thread/make-leader-thread-layer.ts +16 -16
- package/src/leader-thread/materialize-event.ts +9 -9
- package/src/leader-thread/mod.ts +8 -8
- package/src/leader-thread/recreate-db.ts +6 -6
- package/src/leader-thread/shutdown-channel.ts +1 -1
- package/src/leader-thread/types.ts +6 -6
- package/src/make-client-session.ts +3 -4
- package/src/materializer-helper.ts +11 -11
- package/src/rematerialize-from-eventlog.ts +6 -6
- package/src/schema/EventDef.ts +4 -24
- package/src/schema/EventSequenceNumber.test.ts +1 -1
- package/src/schema/LiveStoreEvent.ts +3 -3
- package/src/schema/events.ts +1 -1
- package/src/schema/mod.ts +9 -9
- package/src/schema/schema.ts +8 -11
- 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 +57 -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/mod.ts +19 -13
- package/src/schema/state/sqlite/db-schema/hash.ts +0 -1
- package/src/schema/state/sqlite/db-schema/mod.ts +2 -2
- package/src/schema/state/sqlite/mod.ts +13 -15
- package/src/schema/state/sqlite/query-builder/api.ts +5 -5
- package/src/schema/state/sqlite/query-builder/astToSql.ts +4 -4
- package/src/schema/state/sqlite/query-builder/impl.test.ts +4 -4
- package/src/schema/state/sqlite/query-builder/impl.ts +8 -16
- 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 +3 -3
- package/src/schema/state/sqlite/table-def.ts +3 -3
- package/src/schema-management/common.ts +3 -3
- package/src/schema-management/migrations.ts +11 -11
- package/src/schema-management/validate-schema.ts +4 -4
- package/src/sql-queries/index.ts +3 -3
- package/src/sql-queries/sql-queries.ts +4 -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 +4 -4
- package/src/sync/ClientSessionSyncProcessor.ts +50 -12
- 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 +2 -4
- 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 +6 -6
- package/src/sync/next/test/compact-events.calculator.test.ts +4 -4
- package/src/sync/next/test/compact-events.test.ts +5 -5
- package/src/sync/next/test/event-fixtures.ts +7 -7
- package/src/sync/next/test/mod.ts +1 -1
- package/src/sync/sync.ts +4 -4
- package/src/sync/syncstate.test.ts +9 -6
- package/src/sync/syncstate.ts +2 -2
- package/src/sync/validate-push-payload.ts +2 -2
- package/src/util.ts +0 -1
- package/src/version.ts +1 -1
@@ -2,20 +2,18 @@
|
|
2
2
|
import { casesHandled, shouldNeverHappen } from '@livestore/utils'
|
3
3
|
import { Match, Option, Predicate, Schema } from '@livestore/utils/effect'
|
4
4
|
|
5
|
-
import type { TableDefBase } from '../table-def.
|
6
|
-
import type { QueryBuilder, QueryBuilderAst } from './api.
|
7
|
-
import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './api.
|
8
|
-
import { astToSql } from './astToSql.
|
5
|
+
import type { TableDefBase } from '../table-def.ts'
|
6
|
+
import type { QueryBuilder, QueryBuilderAst } from './api.ts'
|
7
|
+
import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './api.ts'
|
8
|
+
import { astToSql } from './astToSql.ts'
|
9
9
|
export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
10
10
|
tableDef: TTableDef,
|
11
11
|
ast: QueryBuilderAst = emptyAst(tableDef),
|
12
12
|
): QueryBuilder<TResult, TTableDef, never> => {
|
13
13
|
const api = {
|
14
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
15
14
|
select() {
|
16
15
|
assertSelectQueryBuilderAst(ast)
|
17
16
|
|
18
|
-
// eslint-disable-next-line prefer-rest-params
|
19
17
|
const params = [...arguments]
|
20
18
|
|
21
19
|
// Pluck if there's only one column selected
|
@@ -43,7 +41,6 @@ export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
|
43
41
|
if (ast._tag === 'RowQuery') return invalidQueryBuilder('Cannot use where with row')
|
44
42
|
|
45
43
|
if (arguments.length === 1) {
|
46
|
-
// eslint-disable-next-line prefer-rest-params
|
47
44
|
const params = arguments[0]
|
48
45
|
const newOps = Object.entries(params)
|
49
46
|
.filter(([, value]) => value !== undefined)
|
@@ -69,7 +66,6 @@ export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
|
69
66
|
}
|
70
67
|
}
|
71
68
|
|
72
|
-
// eslint-disable-next-line prefer-rest-params
|
73
69
|
const [col, opOrValue, valueOrUndefined] = arguments
|
74
70
|
const op = valueOrUndefined === undefined ? '=' : opOrValue
|
75
71
|
const value = valueOrUndefined === undefined ? opOrValue : valueOrUndefined
|
@@ -89,14 +85,13 @@ export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
|
89
85
|
}
|
90
86
|
}
|
91
87
|
},
|
92
|
-
|
88
|
+
|
93
89
|
orderBy() {
|
94
90
|
assertSelectQueryBuilderAst(ast)
|
95
91
|
|
96
92
|
if (arguments.length === 0 || arguments.length > 2) return invalidQueryBuilder()
|
97
93
|
|
98
94
|
if (arguments.length === 1) {
|
99
|
-
// eslint-disable-next-line prefer-rest-params
|
100
95
|
const params = arguments[0] as QueryBuilder.OrderByParams<TTableDef>
|
101
96
|
return makeQueryBuilder(tableDef, {
|
102
97
|
...ast,
|
@@ -104,7 +99,6 @@ export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
|
104
99
|
})
|
105
100
|
}
|
106
101
|
|
107
|
-
// eslint-disable-next-line prefer-rest-params
|
108
102
|
const [col, direction] = arguments as any as [keyof TTableDef['sqliteDef']['columns'] & string, 'asc' | 'desc']
|
109
103
|
|
110
104
|
return makeQueryBuilder(tableDef, {
|
@@ -148,13 +142,13 @@ export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
|
148
142
|
pickFirst: { _tag: 'enabled', ...(behaviour ?? { behaviour: 'undefined' }) },
|
149
143
|
})
|
150
144
|
},
|
151
|
-
//
|
145
|
+
//
|
152
146
|
// getOrCreate() {
|
153
147
|
// if (tableDef.options.isClientDocumentTable === false) {
|
154
148
|
// return invalidQueryBuilder(`getOrCreate() is not allowed when table is not a client document table`)
|
155
149
|
// }
|
156
150
|
|
157
|
-
//
|
151
|
+
//
|
158
152
|
// const params = [...arguments]
|
159
153
|
|
160
154
|
// let id: string | number
|
@@ -277,21 +271,19 @@ const emptyAst = (tableDef: TableDefBase): QueryBuilderAst.SelectQuery => ({
|
|
277
271
|
})
|
278
272
|
|
279
273
|
// Helper functions
|
280
|
-
|
274
|
+
|
281
275
|
function assertSelectQueryBuilderAst(ast: QueryBuilderAst): asserts ast is QueryBuilderAst.SelectQuery {
|
282
276
|
if (ast._tag !== 'SelectQuery') {
|
283
277
|
return shouldNeverHappen(`Expected SelectQuery but got ${ast._tag}`)
|
284
278
|
}
|
285
279
|
}
|
286
280
|
|
287
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
288
281
|
function assertInsertQueryBuilderAst(ast: QueryBuilderAst): asserts ast is QueryBuilderAst.InsertQuery {
|
289
282
|
if (ast._tag !== 'InsertQuery') {
|
290
283
|
return shouldNeverHappen(`Expected InsertQuery but got ${ast._tag}`)
|
291
284
|
}
|
292
285
|
}
|
293
286
|
|
294
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
295
287
|
function assertWriteQueryBuilderAst(ast: QueryBuilderAst): asserts ast is QueryBuilderAst.WriteQuery {
|
296
288
|
if (ast._tag !== 'InsertQuery' && ast._tag !== 'UpdateQuery' && ast._tag !== 'DeleteQuery') {
|
297
289
|
return shouldNeverHappen(`Expected WriteQuery but got ${ast._tag}`)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { pipe, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { SqliteDsl } from './db-schema/mod.
|
5
|
-
import type { TableDef, TableDefBase } from './table-def.
|
4
|
+
import { SqliteDsl } from './db-schema/mod.ts'
|
5
|
+
import type { TableDef, TableDefBase } from './table-def.ts'
|
6
6
|
|
7
7
|
export const getDefaultValuesEncoded = <TTableDef extends TableDef>(
|
8
8
|
tableDef: TTableDef,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import * as EventSequenceNumber from '../../EventSequenceNumber.
|
4
|
-
import { SqliteDsl } from './db-schema/mod.
|
5
|
-
import { table } from './table-def.
|
3
|
+
import * as EventSequenceNumber from '../../EventSequenceNumber.ts'
|
4
|
+
import { SqliteDsl } from './db-schema/mod.ts'
|
5
|
+
import { table } from './table-def.ts'
|
6
6
|
|
7
7
|
/// State DB
|
8
8
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { Nullable } from '@livestore/utils'
|
2
2
|
import type { Schema, Types } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { SqliteDsl } from './db-schema/mod.
|
5
|
-
import type { QueryBuilder } from './query-builder/mod.
|
6
|
-
import { makeQueryBuilder, QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.
|
4
|
+
import { SqliteDsl } from './db-schema/mod.ts'
|
5
|
+
import type { QueryBuilder } from './query-builder/mod.ts'
|
6
|
+
import { makeQueryBuilder, QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.ts'
|
7
7
|
|
8
8
|
export const { blob, boolean, column, datetime, integer, isColumnDefinition, json, real, text } = SqliteDsl
|
9
9
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { SqliteDb } from '../adapter-types.
|
2
|
-
import type { ParamsObject } from '../util.
|
3
|
-
import { prepareBindValues } from '../util.
|
1
|
+
import type { SqliteDb } from '../adapter-types.ts'
|
2
|
+
import type { ParamsObject } from '../util.ts'
|
3
|
+
import { prepareBindValues } from '../util.ts'
|
4
4
|
|
5
5
|
// TODO bring back statement caching
|
6
6
|
// will require proper scope-aware cleanup etc (for testing and apps with multiple LiveStore instances)
|
@@ -1,23 +1,23 @@
|
|
1
1
|
import { memoizeByStringifyArgs } from '@livestore/utils'
|
2
2
|
import { Effect, Schema as EffectSchema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SqliteDb } from '../adapter-types.
|
5
|
-
import type { MigrationsReport, MigrationsReportEntry } from '../defs.
|
6
|
-
import type { UnexpectedError } from '../errors.
|
7
|
-
import type { LiveStoreSchema } from '../schema/mod.
|
8
|
-
import { SqliteAst, SqliteDsl } from '../schema/state/sqlite/db-schema/mod.
|
9
|
-
import type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/state/sqlite/system-tables.
|
4
|
+
import type { SqliteDb } from '../adapter-types.ts'
|
5
|
+
import type { MigrationsReport, MigrationsReportEntry } from '../defs.ts'
|
6
|
+
import type { UnexpectedError } from '../errors.ts'
|
7
|
+
import type { LiveStoreSchema } from '../schema/mod.ts'
|
8
|
+
import { SqliteAst, SqliteDsl } from '../schema/state/sqlite/db-schema/mod.ts'
|
9
|
+
import type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/state/sqlite/system-tables.ts'
|
10
10
|
import {
|
11
11
|
isStateSystemTable,
|
12
12
|
SCHEMA_EVENT_DEFS_META_TABLE,
|
13
13
|
SCHEMA_META_TABLE,
|
14
14
|
schemaEventDefsMetaTable,
|
15
15
|
stateSystemTables,
|
16
|
-
} from '../schema/state/sqlite/system-tables.
|
17
|
-
import { sql } from '../util.
|
18
|
-
import type { SchemaManager } from './common.
|
19
|
-
import { dbExecute, dbSelect } from './common.
|
20
|
-
import { validateSchema } from './validate-schema.
|
16
|
+
} from '../schema/state/sqlite/system-tables.ts'
|
17
|
+
import { sql } from '../util.ts'
|
18
|
+
import type { SchemaManager } from './common.ts'
|
19
|
+
import { dbExecute, dbSelect } from './common.ts'
|
20
|
+
import { validateSchema } from './validate-schema.ts'
|
21
21
|
|
22
22
|
const getMemoizedTimestamp = memoizeByStringifyArgs(() => new Date().toISOString())
|
23
23
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Effect, Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import { UnexpectedError } from '../adapter-types.
|
4
|
-
import type { EventDef } from '../schema/EventDef.
|
5
|
-
import type { LiveStoreSchema } from '../schema/mod.
|
6
|
-
import type { EventDefInfo, SchemaManager } from './common.
|
3
|
+
import { UnexpectedError } from '../adapter-types.ts'
|
4
|
+
import type { EventDef } from '../schema/EventDef.ts'
|
5
|
+
import type { LiveStoreSchema } from '../schema/mod.ts'
|
6
|
+
import type { EventDefInfo, SchemaManager } from './common.ts'
|
7
7
|
|
8
8
|
export const validateSchema = (schema: LiveStoreSchema, schemaManager: SchemaManager) =>
|
9
9
|
Effect.gen(function* () {
|
package/src/sql-queries/index.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './sql-queries.
|
2
|
-
export * from './sql-query-builder.
|
3
|
-
export * from './types.
|
1
|
+
export * from './sql-queries.ts'
|
2
|
+
export * from './sql-query-builder.ts'
|
3
|
+
export * from './types.ts'
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { pipe, ReadonlyArray, Schema, TreeFormatter } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.
|
5
|
-
import { sql } from '../util.
|
6
|
-
import { objectEntries } from './misc.
|
7
|
-
import * as ClientTypes from './types.
|
4
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.ts'
|
5
|
+
import { sql } from '../util.ts'
|
6
|
+
import { objectEntries } from './misc.ts'
|
7
|
+
import * as ClientTypes from './types.ts'
|
8
8
|
|
9
9
|
export type BindValues = {
|
10
10
|
readonly [columnName: string]: any
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.
|
2
|
-
import type { BindValues } from './sql-queries.
|
3
|
-
import * as SqlQueries from './sql-queries.
|
4
|
-
import type * as ClientTypes from './types.
|
1
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.ts'
|
2
|
+
import type { BindValues } from './sql-queries.ts'
|
3
|
+
import * as SqlQueries from './sql-queries.ts'
|
4
|
+
import type * as ClientTypes from './types.ts'
|
5
5
|
|
6
6
|
export type SqlQuery = [stmt: string, bindValues: BindValues, tableName: string]
|
7
7
|
|
package/src/sql-queries/types.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Prettify } from '@livestore/utils'
|
2
2
|
import type { Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.
|
4
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.ts'
|
5
5
|
|
6
6
|
export type DecodedValuesForTableAll<TSchema extends SqliteDsl.DbSchema, TTableName extends keyof TSchema> = {
|
7
7
|
[K in keyof GetColumns<TSchema, TTableName>]: Schema.Schema.Type<GetColumn<TSchema, TTableName, K>['schema']>
|
package/src/sqlite-db-helper.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import type { SqliteDb } from './adapter-types.
|
4
|
-
import { getResultSchema, isQueryBuilder } from './schema/state/sqlite/query-builder/mod.
|
5
|
-
import type { PreparedBindValues } from './util.
|
3
|
+
import type { SqliteDb } from './adapter-types.ts'
|
4
|
+
import { getResultSchema, isQueryBuilder } from './schema/state/sqlite/query-builder/mod.ts'
|
5
|
+
import type { PreparedBindValues } from './util.ts'
|
6
6
|
|
7
7
|
export const makeExecute = (
|
8
8
|
execute: (
|
package/src/sqlite-types.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { type Effect, Schema } from '@livestore/utils/effect'
|
2
|
-
import type { SqliteError, UnexpectedError } from './errors.
|
3
|
-
import type { EventSequenceNumber } from './schema/mod.
|
4
|
-
import type { QueryBuilder } from './schema/state/sqlite/query-builder/api.
|
5
|
-
import type { PreparedBindValues } from './util.
|
2
|
+
import type { SqliteError, UnexpectedError } from './errors.ts'
|
3
|
+
import type { EventSequenceNumber } from './schema/mod.ts'
|
4
|
+
import type { QueryBuilder } from './schema/state/sqlite/query-builder/api.ts'
|
5
|
+
import type { PreparedBindValues } from './util.ts'
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Common interface for SQLite databases used by LiveStore to facilitate a consistent API across different platforms.
|
@@ -1,14 +1,24 @@
|
|
1
1
|
/// <reference lib="dom" />
|
2
2
|
import { LS_DEV, shouldNeverHappen, TRACE_VERBOSE } from '@livestore/utils'
|
3
|
-
import {
|
4
|
-
|
3
|
+
import {
|
4
|
+
BucketQueue,
|
5
|
+
Effect,
|
6
|
+
FiberHandle,
|
7
|
+
Option,
|
8
|
+
Queue,
|
9
|
+
type Runtime,
|
10
|
+
Schema,
|
11
|
+
type Scope,
|
12
|
+
Stream,
|
13
|
+
Subscribable,
|
14
|
+
} from '@livestore/utils/effect'
|
5
15
|
import * as otel from '@opentelemetry/api'
|
6
16
|
|
7
|
-
import { type ClientSession, SyncError, type UnexpectedError } from '../adapter-types.
|
8
|
-
import * as EventSequenceNumber from '../schema/EventSequenceNumber.
|
9
|
-
import * as LiveStoreEvent from '../schema/LiveStoreEvent.
|
10
|
-
import { getEventDef, type LiveStoreSchema } from '../schema/mod.
|
11
|
-
import * as SyncState from './syncstate.
|
17
|
+
import { type ClientSession, SyncError, type UnexpectedError } from '../adapter-types.ts'
|
18
|
+
import * as EventSequenceNumber from '../schema/EventSequenceNumber.ts'
|
19
|
+
import * as LiveStoreEvent from '../schema/LiveStoreEvent.ts'
|
20
|
+
import { getEventDef, type LiveStoreSchema } from '../schema/mod.ts'
|
21
|
+
import * as SyncState from './syncstate.ts'
|
12
22
|
|
13
23
|
/**
|
14
24
|
* Rebase behaviour:
|
@@ -52,6 +62,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
52
62
|
span: otel.Span
|
53
63
|
params: {
|
54
64
|
leaderPushBatchSize: number
|
65
|
+
simulation?: ClientSessionSyncProcessorSimulationParams
|
55
66
|
}
|
56
67
|
/**
|
57
68
|
* Currently only used in the web adapter:
|
@@ -61,6 +72,11 @@ export const makeClientSessionSyncProcessor = ({
|
|
61
72
|
}): ClientSessionSyncProcessor => {
|
62
73
|
const eventSchema = LiveStoreEvent.makeEventDefSchemaMemo(schema)
|
63
74
|
|
75
|
+
const simSleep = <TKey extends keyof ClientSessionSyncProcessorSimulationParams>(
|
76
|
+
key: TKey,
|
77
|
+
key2: keyof ClientSessionSyncProcessorSimulationParams[TKey],
|
78
|
+
) => Effect.sleep((params.simulation?.[key]?.[key2] ?? 0) as number)
|
79
|
+
|
64
80
|
const syncStateRef = {
|
65
81
|
// The initial state is identical to the leader's initial state
|
66
82
|
current: new SyncState.SyncState({
|
@@ -161,7 +177,6 @@ export const makeClientSessionSyncProcessor = ({
|
|
161
177
|
const otelContext = otel.trace.setSpan(otel.context.active(), span)
|
162
178
|
|
163
179
|
const boot: ClientSessionSyncProcessor['boot'] = Effect.gen(function* () {
|
164
|
-
// eslint-disable-next-line unicorn/prefer-global-this
|
165
180
|
if (confirmUnsavedChanges && typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
166
181
|
const onBeforeUnload = (event: BeforeUnloadEvent) => {
|
167
182
|
if (syncStateRef.current.pending.length > 0) {
|
@@ -230,19 +245,23 @@ export const makeClientSessionSyncProcessor = ({
|
|
230
245
|
|
231
246
|
debugInfo.rebaseCount++
|
232
247
|
|
248
|
+
if (SIMULATION_ENABLED) yield* simSleep('pull', '1_before_leader_push_fiber_interrupt')
|
249
|
+
|
233
250
|
yield* FiberHandle.clear(leaderPushingFiberHandle)
|
234
251
|
|
252
|
+
if (SIMULATION_ENABLED) yield* simSleep('pull', '2_before_leader_push_queue_clear')
|
253
|
+
|
235
254
|
// Reset the leader push queue since we're rebasing and will push again
|
236
255
|
yield* BucketQueue.clear(leaderPushQueue)
|
237
256
|
|
238
|
-
yield*
|
257
|
+
if (SIMULATION_ENABLED) yield* simSleep('pull', '3_before_rebase_rollback')
|
239
258
|
|
240
259
|
if (LS_DEV) {
|
241
|
-
Effect.logDebug(
|
260
|
+
yield* Effect.logDebug(
|
242
261
|
'merge:pull:rebase: rollback',
|
243
262
|
mergeResult.rollbackEvents.length,
|
244
263
|
...mergeResult.rollbackEvents.slice(0, 10).map((_) => _.toJSON()),
|
245
|
-
)
|
264
|
+
)
|
246
265
|
}
|
247
266
|
|
248
267
|
for (let i = mergeResult.rollbackEvents.length - 1; i >= 0; i--) {
|
@@ -253,8 +272,13 @@ export const makeClientSessionSyncProcessor = ({
|
|
253
272
|
}
|
254
273
|
}
|
255
274
|
|
256
|
-
|
275
|
+
if (SIMULATION_ENABLED) yield* simSleep('pull', '4_before_leader_push_queue_offer')
|
276
|
+
|
257
277
|
yield* BucketQueue.offerAll(leaderPushQueue, mergeResult.newSyncState.pending)
|
278
|
+
|
279
|
+
if (SIMULATION_ENABLED) yield* simSleep('pull', '5_before_leader_push_fiber_run')
|
280
|
+
|
281
|
+
yield* FiberHandle.run(leaderPushingFiberHandle, backgroundLeaderPushing)
|
258
282
|
} else {
|
259
283
|
span.addEvent('merge:pull:advance', {
|
260
284
|
payloadTag: payload._tag,
|
@@ -353,3 +377,17 @@ export interface ClientSessionSyncProcessor {
|
|
353
377
|
}
|
354
378
|
}
|
355
379
|
}
|
380
|
+
|
381
|
+
// TODO turn this into a build-time "macro" so all simulation snippets are removed for production builds
|
382
|
+
const SIMULATION_ENABLED = true
|
383
|
+
|
384
|
+
export const ClientSessionSyncProcessorSimulationParams = Schema.Struct({
|
385
|
+
pull: Schema.Struct({
|
386
|
+
'1_before_leader_push_fiber_interrupt': Schema.Int.pipe(Schema.between(0, 1000)),
|
387
|
+
'2_before_leader_push_queue_clear': Schema.Int.pipe(Schema.between(0, 1000)),
|
388
|
+
'3_before_rebase_rollback': Schema.Int.pipe(Schema.between(0, 1000)),
|
389
|
+
'4_before_leader_push_queue_offer': Schema.Int.pipe(Schema.between(0, 1000)),
|
390
|
+
'5_before_leader_push_fiber_run': Schema.Int.pipe(Schema.between(0, 1000)),
|
391
|
+
}),
|
392
|
+
})
|
393
|
+
type ClientSessionSyncProcessorSimulationParams = typeof ClientSessionSyncProcessorSimulationParams.Type
|
package/src/sync/index.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './
|
3
|
-
export * from './
|
1
|
+
export * from './ClientSessionSyncProcessor.ts'
|
2
|
+
export * from './sync.ts'
|
3
|
+
export * from './validate-push-payload.ts'
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { EventSequenceNumber } from '../../schema/mod.
|
2
|
-
import { replacesFacts } from './facts.
|
3
|
-
import { graphologyDag } from './graphology_.
|
4
|
-
import type { HistoryDag } from './history-dag-common.
|
5
|
-
import { emptyHistoryDag } from './history-dag-common.
|
1
|
+
import { EventSequenceNumber } from '../../schema/mod.ts'
|
2
|
+
import { replacesFacts } from './facts.ts'
|
3
|
+
import { graphologyDag } from './graphology_.ts'
|
4
|
+
import type { HistoryDag } from './history-dag-common.ts'
|
5
|
+
import { emptyHistoryDag } from './history-dag-common.ts'
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Idea:
|
package/src/sync/next/facts.ts
CHANGED
@@ -6,10 +6,10 @@ import type {
|
|
6
6
|
EventDefFactsGroup,
|
7
7
|
EventDefFactsSnapshot,
|
8
8
|
FactsCallback,
|
9
|
-
} from '../../schema/EventDef.
|
10
|
-
import type * as EventSequenceNumber from '../../schema/EventSequenceNumber.
|
11
|
-
import { graphologyDag } from './graphology_.
|
12
|
-
import { EMPTY_FACT_VALUE, type HistoryDag, type HistoryDagNode } from './history-dag-common.
|
9
|
+
} from '../../schema/EventDef.ts'
|
10
|
+
import type * as EventSequenceNumber from '../../schema/EventSequenceNumber.ts'
|
11
|
+
import { graphologyDag } from './graphology_.ts'
|
12
|
+
import { EMPTY_FACT_VALUE, type HistoryDag, type HistoryDagNode } from './history-dag-common.ts'
|
13
13
|
|
14
14
|
export const factsSnapshotForEvents = (
|
15
15
|
events: HistoryDagNode[],
|
@@ -13,11 +13,9 @@ export declare class IGraph<
|
|
13
13
|
constructor(options?: graphologyTypes.GraphOptions)
|
14
14
|
}
|
15
15
|
|
16
|
-
export const DirectedGraph = class DirectedGraph extends graphology.DirectedGraph {
|
17
|
-
} as typeof IGraph
|
16
|
+
export const DirectedGraph = class DirectedGraph extends graphology.DirectedGraph {} as typeof IGraph
|
18
17
|
|
19
|
-
export const Graph = class Graph extends graphology.Graph {
|
20
|
-
} as typeof IGraph
|
18
|
+
export const Graph = class Graph extends graphology.Graph {} as typeof IGraph
|
21
19
|
|
22
20
|
// export const graphology = graphology_ as graphologyTypes
|
23
21
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { EventDefFactsGroup } from '../../schema/EventDef.
|
2
|
-
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.
|
3
|
-
import { graphology } from './graphology_.
|
1
|
+
import type { EventDefFactsGroup } from '../../schema/EventDef.ts'
|
2
|
+
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.ts'
|
3
|
+
import { graphology } from './graphology_.ts'
|
4
4
|
|
5
5
|
export const connectionTypeOptions = ['parent', 'facts'] as const
|
6
6
|
export type ConnectionType = (typeof connectionTypeOptions)[number]
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.
|
2
|
-
import { factsToString, validateFacts } from './facts.
|
3
|
-
import { emptyHistoryDag, type HistoryDagNode, rootParentNum } from './history-dag-common.
|
1
|
+
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.ts'
|
2
|
+
import { factsToString, validateFacts } from './facts.ts'
|
3
|
+
import { emptyHistoryDag, type HistoryDagNode, rootParentNum } from './history-dag-common.ts'
|
4
4
|
|
5
5
|
export const historyDagFromNodes = (dagNodes: HistoryDagNode[], options?: { skipFactsCheck: boolean }) => {
|
6
6
|
if (options?.skipFactsCheck !== true) {
|
package/src/sync/next/mod.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './
|
3
|
-
export * from './
|
4
|
-
export * from './
|
5
|
-
export * from './rebase-events.
|
1
|
+
export * from './compact-events.ts'
|
2
|
+
export * from './facts.ts'
|
3
|
+
export * from './history-dag.ts'
|
4
|
+
export * from './history-dag-common.ts'
|
5
|
+
export * from './rebase-events.ts'
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import type { EventDef, EventDefFactsSnapshot } from '../../schema/EventDef.
|
2
|
-
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.
|
3
|
-
import type * as LiveStoreEvent from '../../schema/LiveStoreEvent.
|
1
|
+
import type { EventDef, EventDefFactsSnapshot } from '../../schema/EventDef.ts'
|
2
|
+
import * as EventSequenceNumber from '../../schema/EventSequenceNumber.ts'
|
3
|
+
import type * as LiveStoreEvent from '../../schema/LiveStoreEvent.ts'
|
4
4
|
import {
|
5
5
|
applyFactGroups,
|
6
|
-
factsIntersect,
|
7
6
|
type FactValidationResult,
|
7
|
+
factsIntersect,
|
8
8
|
getFactsGroupForEventArgs,
|
9
9
|
validateFacts,
|
10
|
-
} from './facts.
|
11
|
-
import type { HistoryDagNode } from './history-dag-common.
|
10
|
+
} from './facts.ts'
|
11
|
+
import type { HistoryDagNode } from './history-dag-common.ts'
|
12
12
|
|
13
13
|
export type RebaseEventWithConflict = HistoryDagNode & {
|
14
14
|
conflictType: 'overlap' | 'missing-requirement'
|
@@ -2,10 +2,10 @@ import { defineEvent } from '@livestore/common/schema'
|
|
2
2
|
import { Schema } from '@livestore/utils/effect'
|
3
3
|
import { describe, expect, it } from 'vitest'
|
4
4
|
|
5
|
-
import { compactEvents } from '../compact-events.
|
6
|
-
import { historyDagFromNodes } from '../history-dag.
|
7
|
-
import { customSerializer } from './compact-events.test.
|
8
|
-
import { printEvent, toEventNodes } from './event-fixtures.
|
5
|
+
import { compactEvents } from '../compact-events.ts'
|
6
|
+
import { historyDagFromNodes } from '../history-dag.ts'
|
7
|
+
import { customSerializer } from './compact-events.test.ts'
|
8
|
+
import { printEvent, toEventNodes } from './event-fixtures.ts'
|
9
9
|
|
10
10
|
expect.addSnapshotSerializer(customSerializer)
|
11
11
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { EventDefFacts } from '@livestore/common/schema'
|
2
2
|
import { describe, expect, it } from 'vitest'
|
3
3
|
|
4
|
-
import { compactEvents } from '../compact-events.
|
5
|
-
import { historyDagFromNodes } from '../history-dag.
|
6
|
-
import type { HistoryDagNode } from '../history-dag-common.
|
7
|
-
import { EMPTY_FACT_VALUE } from '../history-dag-common.
|
8
|
-
import { events as eventDefs, printEvent, toEventNodes } from './event-fixtures.
|
4
|
+
import { compactEvents } from '../compact-events.ts'
|
5
|
+
import { historyDagFromNodes } from '../history-dag.ts'
|
6
|
+
import type { HistoryDagNode } from '../history-dag-common.ts'
|
7
|
+
import { EMPTY_FACT_VALUE } from '../history-dag-common.ts'
|
8
|
+
import { events as eventDefs, printEvent, toEventNodes } from './event-fixtures.ts'
|
9
9
|
|
10
10
|
const customStringify = (value: any): string => {
|
11
11
|
if (value === null) {
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
-
import type { EventDef } from '../../../schema/EventDef.
|
4
|
-
import { defineEvent, defineFacts } from '../../../schema/EventDef.
|
5
|
-
import * as EventSequenceNumber from '../../../schema/EventSequenceNumber.
|
6
|
-
import { factsSnapshotForDag, getFactsGroupForEventArgs } from '../facts.
|
7
|
-
import { historyDagFromNodes } from '../history-dag.
|
8
|
-
import type { HistoryDagNode } from '../history-dag-common.
|
9
|
-
import { rootEventNode } from '../history-dag-common.
|
3
|
+
import type { EventDef } from '../../../schema/EventDef.ts'
|
4
|
+
import { defineEvent, defineFacts } from '../../../schema/EventDef.ts'
|
5
|
+
import * as EventSequenceNumber from '../../../schema/EventSequenceNumber.ts'
|
6
|
+
import { factsSnapshotForDag, getFactsGroupForEventArgs } from '../facts.ts'
|
7
|
+
import { historyDagFromNodes } from '../history-dag.ts'
|
8
|
+
import type { HistoryDagNode } from '../history-dag-common.ts'
|
9
|
+
import { rootEventNode } from '../history-dag-common.ts'
|
10
10
|
|
11
11
|
export const printEvent = ({ seqNum, parentSeqNum, factsGroup, ...rest }: HistoryDagNode) => ({
|
12
12
|
seqNum: EventSequenceNumber.toString(seqNum),
|
@@ -1 +1 @@
|
|
1
|
-
export * from './event-fixtures.
|
1
|
+
export * from './event-fixtures.ts'
|
package/src/sync/sync.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { Effect, HttpClient, Option, Scope, Stream, SubscriptionRef } from '@livestore/utils/effect'
|
2
2
|
import { Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { UnexpectedError } from '../adapter-types.
|
5
|
-
import type { InitialSyncOptions } from '../leader-thread/types.
|
6
|
-
import * as EventSequenceNumber from '../schema/EventSequenceNumber.
|
7
|
-
import type * as LiveStoreEvent from '../schema/LiveStoreEvent.
|
4
|
+
import type { UnexpectedError } from '../adapter-types.ts'
|
5
|
+
import type { InitialSyncOptions } from '../leader-thread/types.ts'
|
6
|
+
import * as EventSequenceNumber from '../schema/EventSequenceNumber.ts'
|
7
|
+
import type * as LiveStoreEvent from '../schema/LiveStoreEvent.ts'
|
8
8
|
|
9
9
|
/**
|
10
10
|
* Those arguments can be used to implement multi-tenancy etc and are passed in from the store.
|
@@ -1,16 +1,17 @@
|
|
1
|
-
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
2
1
|
import { describe, expect, it } from 'vitest'
|
3
2
|
|
4
|
-
import * as EventSequenceNumber from '../schema/EventSequenceNumber.
|
5
|
-
import * as LiveStoreEvent from '../schema/LiveStoreEvent.
|
6
|
-
import * as SyncState from './syncstate.
|
3
|
+
import * as EventSequenceNumber from '../schema/EventSequenceNumber.ts'
|
4
|
+
import * as LiveStoreEvent from '../schema/LiveStoreEvent.ts'
|
5
|
+
import * as SyncState from './syncstate.ts'
|
7
6
|
|
8
7
|
class TestEvent extends LiveStoreEvent.EncodedWithMeta {
|
8
|
+
public readonly payload: string
|
9
|
+
public readonly isClient: boolean
|
9
10
|
constructor(
|
10
11
|
seqNum: EventSequenceNumber.EventSequenceNumberInput,
|
11
12
|
parentSeqNum: EventSequenceNumber.EventSequenceNumberInput,
|
12
|
-
|
13
|
-
|
13
|
+
payload: string,
|
14
|
+
isClient: boolean,
|
14
15
|
) {
|
15
16
|
super({
|
16
17
|
seqNum: EventSequenceNumber.make(seqNum),
|
@@ -20,6 +21,8 @@ class TestEvent extends LiveStoreEvent.EncodedWithMeta {
|
|
20
21
|
clientId: 'static-local-id',
|
21
22
|
sessionId: 'static-session-id',
|
22
23
|
})
|
24
|
+
this.payload = payload
|
25
|
+
this.isClient = isClient
|
23
26
|
}
|
24
27
|
|
25
28
|
rebase_ = (parentSeqNum: EventSequenceNumber.EventSequenceNumber, rebaseGeneration: number) => {
|