@livestore/common 0.0.0-snapshot-602081dfd603e6c8df88a70befeba936cad39aac → 0.0.0-snapshot-f6ec49b1a18859aad769f0a0d8edf8bae231ed07
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/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/leader-thread/LeaderSyncProcessor.js +3 -1
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +1 -1
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutation.js +13 -2
- package/dist/mutation.js.map +1 -1
- package/dist/query-builder/api.d.ts +118 -20
- package/dist/query-builder/api.d.ts.map +1 -1
- package/dist/query-builder/api.js.map +1 -1
- package/dist/query-builder/astToSql.d.ts +7 -0
- package/dist/query-builder/astToSql.d.ts.map +1 -0
- package/dist/query-builder/astToSql.js +168 -0
- package/dist/query-builder/astToSql.js.map +1 -0
- package/dist/query-builder/impl.d.ts +1 -5
- package/dist/query-builder/impl.d.ts.map +1 -1
- package/dist/query-builder/impl.js +130 -96
- package/dist/query-builder/impl.js.map +1 -1
- package/dist/query-builder/impl.test.js +94 -0
- package/dist/query-builder/impl.test.js.map +1 -1
- package/dist/query-builder/mod.d.ts +7 -0
- package/dist/query-builder/mod.d.ts.map +1 -1
- package/dist/query-builder/mod.js +7 -0
- package/dist/query-builder/mod.js.map +1 -1
- package/dist/query-info.d.ts +4 -1
- package/dist/query-info.d.ts.map +1 -1
- package/dist/query-info.js.map +1 -1
- package/dist/schema/db-schema/dsl/mod.d.ts +7 -5
- package/dist/schema/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/db-schema/dsl/mod.js +6 -0
- package/dist/schema/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/mutations.d.ts +11 -2
- package/dist/schema/mutations.d.ts.map +1 -1
- package/dist/schema/mutations.js.map +1 -1
- package/dist/schema/table-def.d.ts +7 -3
- package/dist/schema/table-def.d.ts.map +1 -1
- package/dist/schema/table-def.js +7 -1
- package/dist/schema/table-def.js.map +1 -1
- package/dist/sync/sync.d.ts +7 -0
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/src/leader-thread/LeaderSyncProcessor.ts +3 -1
- package/src/leader-thread/leader-worker-devtools.ts +1 -1
- package/src/mutation.ts +20 -3
- package/src/query-builder/api.ts +192 -15
- package/src/query-builder/astToSql.ts +203 -0
- package/src/query-builder/impl.test.ts +104 -0
- package/src/query-builder/impl.ts +157 -113
- package/src/query-builder/mod.ts +7 -0
- package/src/query-info.ts +6 -1
- package/src/schema/db-schema/dsl/mod.ts +30 -2
- package/src/schema/mutations.ts +12 -1
- package/src/schema/table-def.ts +14 -4
- package/src/sync/sync.ts +4 -0
- package/src/version.ts +1 -1
package/src/query-info.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { DbSchema } from './schema/mod.js'
|
|
|
9
9
|
*
|
|
10
10
|
* This information is currently only used for derived mutations.
|
|
11
11
|
*/
|
|
12
|
-
export type QueryInfo = QueryInfo.None | QueryInfo.Row | QueryInfo.Col | QueryInfo.ColJsonValue
|
|
12
|
+
export type QueryInfo = QueryInfo.None | QueryInfo.Row | QueryInfo.Col | QueryInfo.ColJsonValue | QueryInfo.Write
|
|
13
13
|
// export type QueryInfo<TTableDef extends DbSchema.TableDefBase = DbSchema.TableDefBase> =
|
|
14
14
|
// | QueryInfo.None
|
|
15
15
|
// | QueryInfo.Row<TTableDef>
|
|
@@ -45,6 +45,11 @@ export namespace QueryInfo {
|
|
|
45
45
|
jsonPath: string
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// NOTE Not yet used but we might want to use this in order to avoid write queries in read-only situations
|
|
49
|
+
export type Write = {
|
|
50
|
+
_tag: 'Write'
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
// NOTE maybe we want to bring back type-params back like below
|
|
49
54
|
// export type Row<TTableDef extends DbSchema.TableDefBase> = {
|
|
50
55
|
// _tag: 'Row'
|
|
@@ -52,8 +52,13 @@ export type AnyIfConstained<In, Out> = '__constrained' extends keyof In ? any :
|
|
|
52
52
|
export type EmptyObjIfConstained<In> = '__constrained' extends keyof In ? {} : In
|
|
53
53
|
|
|
54
54
|
export type StructSchemaForColumns<TCols extends ConstraintColumns> = Schema.Schema<
|
|
55
|
-
AnyIfConstained<TCols,
|
|
56
|
-
AnyIfConstained<TCols,
|
|
55
|
+
AnyIfConstained<TCols, FromColumns.RowDecoded<TCols>>,
|
|
56
|
+
AnyIfConstained<TCols, FromColumns.RowEncoded<TCols>>
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export type InsertStructSchemaForColumns<TCols extends ConstraintColumns> = Schema.Schema<
|
|
60
|
+
AnyIfConstained<TCols, FromColumns.InsertRowDecoded<TCols>>,
|
|
61
|
+
AnyIfConstained<TCols, FromColumns.InsertRowEncoded<TCols>>
|
|
57
62
|
>
|
|
58
63
|
|
|
59
64
|
export const structSchemaForTable = <TTableDefinition extends TableDefinition<any, any>>(
|
|
@@ -63,6 +68,20 @@ export const structSchemaForTable = <TTableDefinition extends TableDefinition<an
|
|
|
63
68
|
title: tableDef.name,
|
|
64
69
|
}) as any
|
|
65
70
|
|
|
71
|
+
export const insertStructSchemaForTable = <TTableDefinition extends TableDefinition<any, any>>(
|
|
72
|
+
tableDef: TTableDefinition,
|
|
73
|
+
): InsertStructSchemaForColumns<TTableDefinition['columns']> =>
|
|
74
|
+
Schema.Struct(
|
|
75
|
+
Object.fromEntries(
|
|
76
|
+
tableDef.ast.columns.map((column) => [
|
|
77
|
+
column.name,
|
|
78
|
+
column.nullable === true || column.default._tag === 'Some' ? Schema.optional(column.schema) : column.schema,
|
|
79
|
+
]),
|
|
80
|
+
),
|
|
81
|
+
).annotations({
|
|
82
|
+
title: tableDef.name,
|
|
83
|
+
}) as any
|
|
84
|
+
|
|
66
85
|
const columsToAst = (columns: Columns): ReadonlyArray<SqliteAst.Column> => {
|
|
67
86
|
return Object.entries(columns).map(([name, column]) => {
|
|
68
87
|
return {
|
|
@@ -161,6 +180,10 @@ export namespace FromColumns {
|
|
|
161
180
|
readonly [K in keyof TColumns]: Schema.Schema.Type<TColumns[K]['schema']>
|
|
162
181
|
}
|
|
163
182
|
|
|
183
|
+
export type RowEncodedAll<TColumns extends Columns> = {
|
|
184
|
+
readonly [K in keyof TColumns]: Schema.Schema.Encoded<TColumns[K]['schema']>
|
|
185
|
+
}
|
|
186
|
+
|
|
164
187
|
export type RowEncoded<TColumns extends Columns> = Types.Simplify<
|
|
165
188
|
Nullable<Pick<RowEncodeNonNullable<TColumns>, NullableColumnNames<TColumns>>> &
|
|
166
189
|
Omit<RowEncodeNonNullable<TColumns>, NullableColumnNames<TColumns>>
|
|
@@ -192,4 +215,9 @@ export namespace FromColumns {
|
|
|
192
215
|
Pick<RowDecodedAll<TColumns>, RequiredInsertColumnNames<TColumns>> &
|
|
193
216
|
Partial<Omit<RowDecodedAll<TColumns>, RequiredInsertColumnNames<TColumns>>>
|
|
194
217
|
>
|
|
218
|
+
|
|
219
|
+
export type InsertRowEncoded<TColumns extends Columns> = Types.Simplify<
|
|
220
|
+
Pick<RowEncodedAll<TColumns>, RequiredInsertColumnNames<TColumns>> &
|
|
221
|
+
Partial<Omit<RowEncodedAll<TColumns>, RequiredInsertColumnNames<TColumns>>>
|
|
222
|
+
>
|
|
195
223
|
}
|
package/src/schema/mutations.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
|
2
2
|
|
|
3
|
+
import type { QueryBuilder } from '../query-builder/mod.js'
|
|
3
4
|
import type { BindValues } from '../sql-queries/sql-queries.js'
|
|
4
5
|
|
|
5
6
|
export type MutationDefMap = {
|
|
@@ -20,7 +21,10 @@ export type InternalMutationSchema<TRecord extends MutationDefRecord = MutationD
|
|
|
20
21
|
|
|
21
22
|
export type MutationDefSqlResult<TTo> =
|
|
22
23
|
| SingleOrReadonlyArray<string>
|
|
23
|
-
| ((
|
|
24
|
+
| ((
|
|
25
|
+
args: TTo,
|
|
26
|
+
context: { currentFacts: MutationEventFacts; clientOnly: boolean },
|
|
27
|
+
) => SingleOrReadonlyArray<
|
|
24
28
|
| string
|
|
25
29
|
| {
|
|
26
30
|
sql: string
|
|
@@ -28,8 +32,15 @@ export type MutationDefSqlResult<TTo> =
|
|
|
28
32
|
bindValues: BindValues
|
|
29
33
|
writeTables?: ReadonlySet<string>
|
|
30
34
|
}
|
|
35
|
+
| QueryBuilder.Any
|
|
31
36
|
>)
|
|
32
37
|
|
|
38
|
+
export type MutationHandlerResult = {
|
|
39
|
+
sql: string
|
|
40
|
+
bindValues: BindValues
|
|
41
|
+
writeTables?: ReadonlySet<string>
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
export type SingleOrReadonlyArray<T> = T | ReadonlyArray<T>
|
|
34
45
|
|
|
35
46
|
export type MutationDef<TName extends string, TFrom, TTo> = {
|
package/src/schema/table-def.ts
CHANGED
|
@@ -19,12 +19,12 @@ export type DefaultSqliteTableDefConstrained = SqliteDsl.TableDefinition<string,
|
|
|
19
19
|
export type TableDefBase<
|
|
20
20
|
TSqliteDef extends DefaultSqliteTableDef = DefaultSqliteTableDefConstrained,
|
|
21
21
|
TOptions extends TableOptions = TableOptions,
|
|
22
|
-
TSchema = SqliteDsl.StructSchemaForColumns<TSqliteDef['columns']>,
|
|
23
22
|
> = {
|
|
24
23
|
sqliteDef: TSqliteDef
|
|
25
24
|
options: TOptions
|
|
26
25
|
// Derived from `sqliteDef`, so only exposed for convenience
|
|
27
|
-
schema:
|
|
26
|
+
schema: SqliteDsl.StructSchemaForColumns<TSqliteDef['columns']>
|
|
27
|
+
insertSchema: SqliteDsl.InsertStructSchemaForColumns<TSqliteDef['columns']>
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export type TableDef<
|
|
@@ -47,7 +47,10 @@ export type TableDef<
|
|
|
47
47
|
options: TOptions
|
|
48
48
|
// Derived from `sqliteDef`, so only exposed for convenience
|
|
49
49
|
schema: TSchema
|
|
50
|
-
|
|
50
|
+
insertSchema: SqliteDsl.InsertStructSchemaForColumns<TSqliteDef['columns']>
|
|
51
|
+
query: QueryBuilder<ReadonlyArray<Schema.Schema.Type<TSchema>>, TableDefBase<TSqliteDef & {}, TOptions>>
|
|
52
|
+
readonly Type: Schema.Schema.Type<TSchema>
|
|
53
|
+
readonly Encoded: Schema.Schema.Encoded<TSchema>
|
|
51
54
|
} & (TOptions['deriveMutations']['enabled'] extends true
|
|
52
55
|
? DerivedMutationHelperFns<TSqliteDef['columns'], TOptions>
|
|
53
56
|
: {})
|
|
@@ -195,7 +198,14 @@ export const table = <
|
|
|
195
198
|
const isSingleColumn = SqliteDsl.isColumnDefinition(columnOrColumns) === true
|
|
196
199
|
|
|
197
200
|
const schema = SqliteDsl.structSchemaForTable(sqliteDef)
|
|
198
|
-
const
|
|
201
|
+
const insertSchema = SqliteDsl.insertStructSchemaForTable(sqliteDef)
|
|
202
|
+
const tableDef = {
|
|
203
|
+
sqliteDef,
|
|
204
|
+
options: options_,
|
|
205
|
+
schema,
|
|
206
|
+
insertSchema,
|
|
207
|
+
} satisfies TableDefBase
|
|
208
|
+
|
|
199
209
|
const query = makeQueryBuilder(tableDef)
|
|
200
210
|
// const tableDef = { ...tableDefBase, query } satisfies TableDef
|
|
201
211
|
|
package/src/sync/sync.ts
CHANGED
|
@@ -59,6 +59,10 @@ export type SyncBackend<TSyncMetadata = Schema.JsonValue> = {
|
|
|
59
59
|
HttpClient.HttpClient
|
|
60
60
|
>
|
|
61
61
|
isConnected: SubscriptionRef.SubscriptionRef<boolean>
|
|
62
|
+
/**
|
|
63
|
+
* Metadata describing the sync backend.
|
|
64
|
+
*/
|
|
65
|
+
metadata: { name: string; description: string } & Record<string, Schema.JsonValue>
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
export class IsOfflineError extends Schema.TaggedError<IsOfflineError>()('IsOfflineError', {}) {}
|
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.24' as const
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|