@livestore/common 0.0.56-dev.2 → 0.0.56-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 +18 -11
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +9 -3
- package/dist/adapter-types.js.map +1 -1
- package/dist/devtools/devtools-messages.d.ts +13 -2
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +7 -2
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/rehydrate-from-mutationlog.d.ts +2 -2
- package/dist/rehydrate-from-mutationlog.d.ts.map +1 -1
- package/dist/rehydrate-from-mutationlog.js +10 -18
- package/dist/rehydrate-from-mutationlog.js.map +1 -1
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema-management/common.d.ts.map +1 -1
- package/dist/schema-management/common.js +4 -1
- package/dist/schema-management/common.js.map +1 -1
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +2 -5
- package/dist/schema-management/migrations.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter-types.ts +20 -12
- package/src/devtools/devtools-messages.ts +7 -2
- package/src/rehydrate-from-mutationlog.ts +15 -24
- package/src/schema/index.ts +4 -4
- package/src/schema-management/common.ts +5 -1
- package/src/schema-management/migrations.ts +3 -8
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { memoizeByRef, shouldNeverHappen } from '@livestore/utils'
|
|
2
2
|
import { Chunk, Effect, Option, Schema, Stream } from '@livestore/utils/effect'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type MigrationOptionsFromMutationLog,
|
|
6
|
-
SqliteError,
|
|
7
|
-
type SynchronousDatabase,
|
|
8
|
-
UnexpectedError,
|
|
9
|
-
} from './adapter-types.js'
|
|
4
|
+
import { type MigrationOptionsFromMutationLog, type SynchronousDatabase, UnexpectedError } from './adapter-types.js'
|
|
10
5
|
import { getExecArgsFromMutation } from './mutation.js'
|
|
11
6
|
import type { LiveStoreSchema, MutationDef, MutationLogMetaRow } from './schema/index.js'
|
|
12
7
|
import { MUTATION_LOG_META_TABLE } from './schema/index.js'
|
|
@@ -73,26 +68,22 @@ This likely means the schema has changed in an incompatible way.
|
|
|
73
68
|
|
|
74
69
|
const execArgsArr = getExecArgsFromMutation({ mutationDef, mutationEventDecoded })
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const getRowsChanged = db.execute(statementSql, bindValues)
|
|
80
|
-
if (
|
|
81
|
-
import.meta.env.DEV &&
|
|
82
|
-
getRowsChanged() === 0 &&
|
|
83
|
-
migrationOptions.logging?.excludeAffectedRows?.(statementSql) !== true
|
|
84
|
-
) {
|
|
71
|
+
const makeExecuteOptions = (statementSql: string, bindValues: any) => ({
|
|
72
|
+
onRowsChanged: (rowsChanged: number) => {
|
|
73
|
+
if (rowsChanged === 0 && migrationOptions.logging?.excludeAffectedRows?.(statementSql) !== true) {
|
|
85
74
|
console.warn(`Mutation "${mutationDef.name}" did not affect any rows:`, statementSql, bindValues)
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
for (const { statementSql, bindValues } of execArgsArr) {
|
|
80
|
+
// TODO cache prepared statements for mutations
|
|
81
|
+
db.execute(
|
|
82
|
+
statementSql,
|
|
83
|
+
bindValues,
|
|
84
|
+
import.meta.env.DEV ? makeExecuteOptions(statementSql, bindValues) : undefined,
|
|
85
|
+
)
|
|
86
|
+
// console.log(`Re-executed mutation ${mutationSql}`, bindValues)
|
|
96
87
|
}
|
|
97
88
|
}).pipe(Effect.withSpan(`@livestore/common:rehydrateFromMutationLog:processMutation`))
|
|
98
89
|
|
package/src/schema/index.ts
CHANGED
|
@@ -39,6 +39,9 @@ export type LiveStoreSchema<
|
|
|
39
39
|
|
|
40
40
|
migrationOptions: MigrationOptions
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @default 'default'
|
|
44
|
+
*/
|
|
42
45
|
key: string
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -47,9 +50,6 @@ export type InputSchema = {
|
|
|
47
50
|
readonly mutations?: ReadonlyArray<MutationDef.Any> | Record<string, MutationDef.Any>
|
|
48
51
|
/**
|
|
49
52
|
* Can be used to isolate multiple LiveStore apps running in the same origin
|
|
50
|
-
*
|
|
51
|
-
* Make sure you also use this key in the `storage` options (e.g. directory, prefix etc) to make sure
|
|
52
|
-
* different instances of LiveStore aren't overlapping on the storage level.
|
|
53
53
|
*/
|
|
54
54
|
readonly key?: string
|
|
55
55
|
}
|
|
@@ -118,7 +118,7 @@ export const makeSchema = <TInputSchema extends InputSchema>(
|
|
|
118
118
|
mutations,
|
|
119
119
|
migrationOptions: inputSchema.migrations ?? { strategy: 'hard-reset' },
|
|
120
120
|
hash,
|
|
121
|
-
key: inputSchema.key ?? '',
|
|
121
|
+
key: inputSchema.key ?? 'default',
|
|
122
122
|
} satisfies LiveStoreSchema
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -16,6 +16,8 @@ export const dbExecute = (db: SynchronousDatabase, queryStr: string, bindValues?
|
|
|
16
16
|
const preparedBindValues = bindValues ? prepareBindValues(bindValues, queryStr) : undefined
|
|
17
17
|
|
|
18
18
|
stmt.execute(preparedBindValues)
|
|
19
|
+
|
|
20
|
+
stmt.finalize()
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export const dbSelect = <T>(db: SynchronousDatabase, queryStr: string, bindValues?: ParamsObject) => {
|
|
@@ -25,7 +27,9 @@ export const dbSelect = <T>(db: SynchronousDatabase, queryStr: string, bindValue
|
|
|
25
27
|
// cachedStmts.set(queryStr, stmt)
|
|
26
28
|
// }
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
const res = stmt.select<T>(bindValues ? prepareBindValues(bindValues, queryStr) : undefined)
|
|
31
|
+
stmt.finalize()
|
|
32
|
+
return res
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export interface SchemaManager {
|
|
@@ -28,14 +28,9 @@ export const makeSchemaManager = (db: SynchronousDatabase): Effect.Effect<Schema
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
|
-
getMutationDefInfos: () =>
|
|
32
|
-
|
|
33
|
-
db,
|
|
34
|
-
sql`SELECT * FROM ${SCHEMA_MUTATIONS_META_TABLE}`,
|
|
35
|
-
)
|
|
31
|
+
getMutationDefInfos: () =>
|
|
32
|
+
dbSelect<SchemaMutationsMetaRow>(db, sql`SELECT * FROM ${SCHEMA_MUTATIONS_META_TABLE}`),
|
|
36
33
|
|
|
37
|
-
return schemaMutationsMetaRows
|
|
38
|
-
},
|
|
39
34
|
setMutationDefInfo: (info) => {
|
|
40
35
|
dbExecute(
|
|
41
36
|
db,
|
|
@@ -128,7 +123,7 @@ export const migrateTable = ({
|
|
|
128
123
|
skipMetaTable?: boolean
|
|
129
124
|
}) =>
|
|
130
125
|
Effect.gen(function* () {
|
|
131
|
-
console.log(`Migrating table '${tableAst.name}'...`)
|
|
126
|
+
// console.log(`Migrating table '${tableAst.name}'...`)
|
|
132
127
|
const tableName = tableAst.name
|
|
133
128
|
const columnSpec = makeColumnSpec(tableAst)
|
|
134
129
|
|