@livestore/livestore 0.0.39-dev.3 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/mutations.test.js +1 -1
- package/dist/__tests__/react/fixture.d.ts +18 -18
- package/dist/mutations.d.ts +1 -1
- package/dist/mutations.d.ts.map +1 -1
- package/dist/mutations.js +5 -1
- package/dist/mutations.js.map +1 -1
- package/dist/{update-path.d.ts → query-info.d.ts} +12 -12
- package/dist/query-info.d.ts.map +1 -0
- package/dist/{update-path.js → query-info.js} +2 -2
- package/dist/query-info.js.map +1 -0
- package/dist/react/LiveStoreContext.d.ts +0 -6
- package/dist/react/LiveStoreContext.d.ts.map +1 -1
- package/dist/react/LiveStoreContext.js.map +1 -1
- package/dist/react/useAtom.d.ts +2 -2
- package/dist/react/useAtom.d.ts.map +1 -1
- package/dist/react/useAtom.js +3 -3
- package/dist/react/useAtom.js.map +1 -1
- package/dist/react/useQuery.d.ts.map +1 -1
- package/dist/react/useRow.d.ts +2 -2
- package/dist/react/useRow.d.ts.map +1 -1
- package/dist/react/useRow.js +5 -5
- package/dist/react/useRow.js.map +1 -1
- package/dist/react/useTemporaryQuery.d.ts +2 -2
- package/dist/react/useTemporaryQuery.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +14 -8
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js +1 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/graphql.d.ts +15 -9
- package/dist/reactiveQueries/graphql.d.ts.map +1 -1
- package/dist/reactiveQueries/graphql.js +28 -8
- package/dist/reactiveQueries/graphql.js.map +1 -1
- package/dist/reactiveQueries/js.d.ts +8 -8
- package/dist/reactiveQueries/js.d.ts.map +1 -1
- package/dist/reactiveQueries/js.js +4 -4
- package/dist/reactiveQueries/js.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +11 -11
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +6 -6
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/row-query.d.ts +5 -5
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +4 -4
- package/dist/row-query.js.map +1 -1
- package/dist/schema/parse-utils.d.ts +0 -3
- package/dist/schema/parse-utils.d.ts.map +1 -1
- package/dist/schema/parse-utils.js +2 -27
- package/dist/schema/parse-utils.js.map +1 -1
- package/dist/schema/system-tables.d.ts +8 -8
- package/dist/schema/table-def.d.ts +5 -5
- package/dist/schema/table-def.d.ts.map +1 -1
- package/dist/schema/table-def.js.map +1 -1
- package/package.json +10 -10
- package/src/__tests__/mutations.test.ts +1 -1
- package/src/mutations.ts +9 -2
- package/src/{update-path.ts → query-info.ts} +15 -15
- package/src/react/LiveStoreContext.ts +0 -9
- package/src/react/useAtom.ts +6 -6
- package/src/react/useQuery.ts +1 -1
- package/src/react/useRow.ts +10 -10
- package/src/reactiveQueries/base-class.ts +19 -9
- package/src/reactiveQueries/graphql.ts +47 -13
- package/src/reactiveQueries/js.ts +13 -13
- package/src/reactiveQueries/sql.ts +22 -22
- package/src/row-query.ts +13 -13
- package/src/schema/parse-utils.ts +2 -44
- package/src/schema/table-def.ts +2 -1
- package/dist/update-path.d.ts.map +0 -1
- package/dist/update-path.js.map +0 -1
|
@@ -4,21 +4,21 @@ export declare const SCHEMA_META_TABLE = "__livestore_schema";
|
|
|
4
4
|
declare const schemaMetaTable: import("./table-def.js").TableDef<SqliteDsl.TableDefinition<"__livestore_schema", {
|
|
5
5
|
tableName: {
|
|
6
6
|
columnType: "text";
|
|
7
|
-
schema: import("@effect/schema/Schema").Schema<string, string>;
|
|
7
|
+
schema: import("@effect/schema/Schema").Schema<never, string, string>;
|
|
8
8
|
default: import("effect/Option").None<never>;
|
|
9
9
|
nullable: false;
|
|
10
10
|
primaryKey: true;
|
|
11
11
|
};
|
|
12
12
|
schemaHash: {
|
|
13
13
|
columnType: "integer";
|
|
14
|
-
schema: import("@effect/schema/Schema").Schema<number, number>;
|
|
14
|
+
schema: import("@effect/schema/Schema").Schema<never, number, number>;
|
|
15
15
|
default: import("effect/Option").None<never>;
|
|
16
16
|
nullable: false;
|
|
17
17
|
primaryKey: false;
|
|
18
18
|
};
|
|
19
19
|
updatedAt: {
|
|
20
20
|
columnType: "text";
|
|
21
|
-
schema: import("@effect/schema/Schema").Schema<string, string>;
|
|
21
|
+
schema: import("@effect/schema/Schema").Schema<never, string, string>;
|
|
22
22
|
default: import("effect/Option").None<never>;
|
|
23
23
|
nullable: false;
|
|
24
24
|
primaryKey: false;
|
|
@@ -27,7 +27,7 @@ declare const schemaMetaTable: import("./table-def.js").TableDef<SqliteDsl.Table
|
|
|
27
27
|
isSingleton: false;
|
|
28
28
|
dynamicRegistration: false;
|
|
29
29
|
disableAutomaticIdColumn: true;
|
|
30
|
-
}, import("@effect/schema/Schema").Schema<{
|
|
30
|
+
}, import("@effect/schema/Schema").Schema<never, {
|
|
31
31
|
readonly tableName: string;
|
|
32
32
|
readonly schemaHash: number;
|
|
33
33
|
readonly updatedAt: string;
|
|
@@ -40,21 +40,21 @@ export type SchemaMetaRow = FromTable.RowDecoded<typeof schemaMetaTable>;
|
|
|
40
40
|
export declare const systemTables: import("./table-def.js").TableDef<SqliteDsl.TableDefinition<"__livestore_schema", {
|
|
41
41
|
tableName: {
|
|
42
42
|
columnType: "text";
|
|
43
|
-
schema: import("@effect/schema/Schema").Schema<string, string>;
|
|
43
|
+
schema: import("@effect/schema/Schema").Schema<never, string, string>;
|
|
44
44
|
default: import("effect/Option").None<never>;
|
|
45
45
|
nullable: false;
|
|
46
46
|
primaryKey: true;
|
|
47
47
|
};
|
|
48
48
|
schemaHash: {
|
|
49
49
|
columnType: "integer";
|
|
50
|
-
schema: import("@effect/schema/Schema").Schema<number, number>;
|
|
50
|
+
schema: import("@effect/schema/Schema").Schema<never, number, number>;
|
|
51
51
|
default: import("effect/Option").None<never>;
|
|
52
52
|
nullable: false;
|
|
53
53
|
primaryKey: false;
|
|
54
54
|
};
|
|
55
55
|
updatedAt: {
|
|
56
56
|
columnType: "text";
|
|
57
|
-
schema: import("@effect/schema/Schema").Schema<string, string>;
|
|
57
|
+
schema: import("@effect/schema/Schema").Schema<never, string, string>;
|
|
58
58
|
default: import("effect/Option").None<never>;
|
|
59
59
|
nullable: false;
|
|
60
60
|
primaryKey: false;
|
|
@@ -63,7 +63,7 @@ export declare const systemTables: import("./table-def.js").TableDef<SqliteDsl.T
|
|
|
63
63
|
isSingleton: false;
|
|
64
64
|
dynamicRegistration: false;
|
|
65
65
|
disableAutomaticIdColumn: true;
|
|
66
|
-
}, import("@effect/schema/Schema").Schema<{
|
|
66
|
+
}, import("@effect/schema/Schema").Schema<never, {
|
|
67
67
|
readonly tableName: string;
|
|
68
68
|
readonly schemaHash: number;
|
|
69
69
|
readonly updatedAt: string;
|
|
@@ -6,7 +6,7 @@ export { type SqliteDsl as __SqliteDsl } from 'effect-db-schema';
|
|
|
6
6
|
export type StateType = 'singleton' | 'dynamic';
|
|
7
7
|
export type DefaultSqliteTableDef = SqliteDsl.TableDefinition<string, SqliteDsl.Columns>;
|
|
8
8
|
export type DefaultSqliteTableDefConstrained = SqliteDsl.TableDefinition<string, SqliteDsl.ConstraintColumns>;
|
|
9
|
-
export type TableDef<TSqliteDef extends DefaultSqliteTableDef = DefaultSqliteTableDefConstrained, TIsSingleColumn extends boolean = boolean, TOptions extends TableOptions = TableOptions, TSchema = Schema.Schema<SqliteDsl.AnyIfConstained<TSqliteDef['columns'], {
|
|
9
|
+
export type TableDef<TSqliteDef extends DefaultSqliteTableDef = DefaultSqliteTableDefConstrained, TIsSingleColumn extends boolean = boolean, TOptions extends TableOptions = TableOptions, TSchema = Schema.Schema<never, SqliteDsl.AnyIfConstained<TSqliteDef['columns'], {
|
|
10
10
|
readonly [K in keyof TSqliteDef['columns']]: Schema.Schema.From<TSqliteDef['columns'][K]['schema']>;
|
|
11
11
|
}>, SqliteDsl.AnyIfConstained<TSqliteDef['columns'], {
|
|
12
12
|
readonly [K in keyof TSqliteDef['columns']]: Schema.Schema.To<TSqliteDef['columns'][K]['schema']>;
|
|
@@ -38,7 +38,7 @@ export declare const table: <TName extends string, TColumns extends SqliteDsl.Co
|
|
|
38
38
|
indexes: SqliteDsl.Index[];
|
|
39
39
|
}>>(name: TName, columnOrColumns: TColumns, options?: TOptionsInput | undefined) => TableDef<SqliteDsl.TableDefinition<TName, PrettifyFlat<WithId<TColumns extends SqliteDsl.Columns ? TColumns : {
|
|
40
40
|
value: TColumns;
|
|
41
|
-
}, WithDefaults<TOptionsInput>>>>, TColumns extends SqliteDsl.ColumnDefinition<any, any> ? true : false, WithDefaults<TOptionsInput>, Schema.Schema<SqliteDsl.AnyIfConstained<PrettifyFlat<WithId<TColumns extends SqliteDsl.Columns ? TColumns : {
|
|
41
|
+
}, WithDefaults<TOptionsInput>>>>, TColumns extends SqliteDsl.ColumnDefinition<any, any> ? true : false, WithDefaults<TOptionsInput>, Schema.Schema<never, SqliteDsl.AnyIfConstained<PrettifyFlat<WithId<TColumns extends SqliteDsl.Columns ? TColumns : {
|
|
42
42
|
value: TColumns;
|
|
43
43
|
}, WithDefaults<TOptionsInput>>>, { readonly [K in keyof PrettifyFlat<WithId<TColumns extends SqliteDsl.Columns ? TColumns : {
|
|
44
44
|
value: TColumns;
|
|
@@ -51,13 +51,13 @@ export declare const table: <TName extends string, TColumns extends SqliteDsl.Co
|
|
|
51
51
|
}, WithDefaults<TOptionsInput>>>]: Schema.Schema.To<PrettifyFlat<WithId<TColumns extends SqliteDsl.Columns ? TColumns : {
|
|
52
52
|
value: TColumns;
|
|
53
53
|
}, WithDefaults<TOptionsInput>>>[K_1]["schema"]>; }>>>;
|
|
54
|
-
export declare const tableIsSingleton: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<any, any>>>(tableDef: TTableDef) => tableDef is TTableDef & {
|
|
54
|
+
export declare const tableIsSingleton: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<never, any, any>>>(tableDef: TTableDef) => tableDef is TTableDef & {
|
|
55
55
|
options: {
|
|
56
56
|
isSingleton: true;
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
-
export declare const getDefaultValuesEncoded: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<any, any>>>(tableDef: TTableDef) => Record<string, any>;
|
|
60
|
-
export declare const getDefaultValuesDecoded: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<any, any>>>(tableDef: TTableDef) => Record<string, any>;
|
|
59
|
+
export declare const getDefaultValuesEncoded: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<never, any, any>>>(tableDef: TTableDef) => Record<string, any>;
|
|
60
|
+
export declare const getDefaultValuesDecoded: <TTableDef extends TableDef<DefaultSqliteTableDefConstrained, boolean, TableOptions, Schema.Schema<never, any, any>>>(tableDef: TTableDef) => Record<string, any>;
|
|
61
61
|
type WithId<TColumns extends SqliteDsl.Columns, TOptions extends TableOptions> = TColumns & (TOptions['disableAutomaticIdColumn'] extends true ? {} : TOptions['isSingleton'] extends true ? {
|
|
62
62
|
id: SqliteDsl.ColumnDefinition<'singleton', 'singleton'>;
|
|
63
63
|
} : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-def.d.ts","sourceRoot":"","sources":["../../src/schema/table-def.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,eAAO,MAAQ,IAAI,8BAAE,OAAO,4DAAE,MAAM,+GAAE,QAAQ,sDAAE,OAA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 +62,28 @@
|
|
|
62
62
|
"lodash-es": "^4.17.21",
|
|
63
63
|
"sqlite-esm": "3.42.0-build6",
|
|
64
64
|
"uuid": "^9.0.1",
|
|
65
|
-
"@livestore/sql-queries": "0.0.39
|
|
66
|
-
"@livestore/utils": "0.0.39
|
|
67
|
-
"effect-db-schema": "0.0.39
|
|
65
|
+
"@livestore/sql-queries": "0.0.39",
|
|
66
|
+
"@livestore/utils": "0.0.39",
|
|
67
|
+
"effect-db-schema": "0.0.39"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@opentelemetry/sdk-trace-base": "1.
|
|
70
|
+
"@opentelemetry/sdk-trace-base": "1.20.0",
|
|
71
71
|
"@tauri-apps/api": "^1.5.3",
|
|
72
72
|
"@testing-library/react": "^14.1.2",
|
|
73
73
|
"@types/lodash-es": "^4.17.12",
|
|
74
|
-
"@types/react": "^18.2.
|
|
74
|
+
"@types/react": "^18.2.48",
|
|
75
75
|
"@types/react-dom": "^18.2.18",
|
|
76
76
|
"@types/uuid": "^9.0.7",
|
|
77
|
-
"jsdom": "^
|
|
77
|
+
"jsdom": "^24.0.0",
|
|
78
78
|
"react": "^18.2.0",
|
|
79
79
|
"react-dom": "^18.2.0",
|
|
80
80
|
"typescript": "5.3.3",
|
|
81
|
-
"vite": "5.0.
|
|
82
|
-
"vitest": "^1.1
|
|
81
|
+
"vite": "5.0.12",
|
|
82
|
+
"vitest": "^1.2.1"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@tauri-apps/api": "^1.4.0",
|
|
86
|
-
"graphql": "
|
|
86
|
+
"graphql": "16.x",
|
|
87
87
|
"react": "^18",
|
|
88
88
|
"react-dom": "^18"
|
|
89
89
|
},
|
|
@@ -15,7 +15,7 @@ describe('mutations', () => {
|
|
|
15
15
|
"id": "t1",
|
|
16
16
|
"text": "Task 1",
|
|
17
17
|
},
|
|
18
|
-
"sql": "INSERT INTO todos (id,
|
|
18
|
+
"sql": "INSERT INTO todos (id, text, completed) VALUES ($id, $text, $completed)",
|
|
19
19
|
"writeTables": Set {
|
|
20
20
|
"todos",
|
|
21
21
|
},
|
package/src/mutations.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as SqlQueries from '@livestore/sql-queries'
|
|
2
|
+
import { pipe, ReadonlyRecord } from '@livestore/utils/effect'
|
|
2
3
|
import type { SqliteDsl } from 'effect-db-schema'
|
|
3
4
|
|
|
4
5
|
import type { RowResult } from './row-query.js'
|
|
5
6
|
import type { LiveStoreSchema } from './schema/index.js'
|
|
6
|
-
import type
|
|
7
|
+
import { getDefaultValuesEncoded, type TableDef } from './schema/table-def.js'
|
|
7
8
|
import type { GetValForKey } from './utils/util.js'
|
|
8
9
|
|
|
9
10
|
export const makeMutations = <TDbSchema extends SqliteDsl.DbSchema>(
|
|
@@ -16,7 +17,13 @@ const mutationsForTable = <TTableDef extends TableDef>(tableDef: TTableDef): [st
|
|
|
16
17
|
const table = tableDef.sqliteDef
|
|
17
18
|
const writeTables = new Set([table.name])
|
|
18
19
|
const api = {
|
|
19
|
-
insert: (
|
|
20
|
+
insert: (values_: any) => {
|
|
21
|
+
const defaultValues = getDefaultValuesEncoded(tableDef)
|
|
22
|
+
const values = pipe(
|
|
23
|
+
tableDef.sqliteDef.columns,
|
|
24
|
+
ReadonlyRecord.map((_, columnName) => values_?.[columnName] ?? defaultValues[columnName]),
|
|
25
|
+
)
|
|
26
|
+
|
|
20
27
|
const [sql, bindValues] = SqlQueries.insertRow({
|
|
21
28
|
tableName: table.name,
|
|
22
29
|
columns: table.columns,
|
|
@@ -4,35 +4,35 @@ import { Schema } from '@livestore/utils/effect'
|
|
|
4
4
|
import type { FromTable, TableDef } from './schema/table-def.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
7
|
+
* Semantic information about a query with supported cases being:
|
|
8
|
+
* - a whole row
|
|
9
|
+
* - a single column value
|
|
10
|
+
* - a sub value in a JSON column
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
12
|
+
export type QueryInfo<TTableDef extends TableDef = TableDef> =
|
|
13
|
+
| QueryInfoNone
|
|
14
|
+
| QueryInfoRow<TTableDef>
|
|
15
|
+
| QueryInfoColJsonValue<TTableDef, GetJsonColumn<TTableDef>>
|
|
16
|
+
| QueryInfoCol<TTableDef, keyof TTableDef['sqliteDef']['columns']>
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type QueryInfoNone = {
|
|
19
19
|
_tag: 'None'
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type
|
|
22
|
+
export type QueryInfoRow<TTableDef extends TableDef> = {
|
|
23
23
|
_tag: 'Row'
|
|
24
24
|
table: TTableDef
|
|
25
25
|
id: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export type
|
|
28
|
+
export type QueryInfoCol<TTableDef extends TableDef, TColName extends keyof TTableDef['sqliteDef']['columns']> = {
|
|
29
29
|
_tag: 'Col'
|
|
30
30
|
table: TTableDef
|
|
31
31
|
id: string
|
|
32
32
|
column: TColName
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export type
|
|
35
|
+
export type QueryInfoColJsonValue<TTableDef extends TableDef, TColName extends GetJsonColumn<TTableDef>> = {
|
|
36
36
|
_tag: 'ColJsonValue'
|
|
37
37
|
table: TTableDef
|
|
38
38
|
id: string
|
|
@@ -51,7 +51,7 @@ type GetJsonColumn<TTableDef extends TableDef> = keyof {
|
|
|
51
51
|
|
|
52
52
|
// type GetObjValues<TObj extends {}> = TObj[keyof TObj]
|
|
53
53
|
|
|
54
|
-
export type UpdateValueForPath<TPath extends
|
|
54
|
+
export type UpdateValueForPath<TPath extends QueryInfo> = TPath extends { _tag: 'Row' }
|
|
55
55
|
? Partial<FromTable.RowDecodedAll<TPath['table']>>
|
|
56
56
|
: TPath extends { _tag: 'Col' }
|
|
57
57
|
? Schema.Schema.To<TPath['table']['sqliteDef']['columns'][TPath['column']]['schema']>
|
|
@@ -59,7 +59,7 @@ export type UpdateValueForPath<TPath extends UpdatePathDesc> = TPath extends { _
|
|
|
59
59
|
? { TODO: true }
|
|
60
60
|
: never
|
|
61
61
|
|
|
62
|
-
export const
|
|
62
|
+
export const storeEventForQueryInfo = <TPath extends QueryInfo>(
|
|
63
63
|
updatePath: TPath,
|
|
64
64
|
value: UpdateValueForPath<TPath>,
|
|
65
65
|
): StoreEvent => {
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import React, { useContext } from 'react'
|
|
2
2
|
|
|
3
3
|
import type { LiveStoreContext as LiveStoreContext_ } from '../effect/LiveStore.js'
|
|
4
|
-
import type { LiveQuery } from '../reactiveQueries/base-class.js'
|
|
5
|
-
|
|
6
|
-
// TODO remove this?
|
|
7
|
-
declare global {
|
|
8
|
-
// NOTE Can be extended
|
|
9
|
-
interface LiveStoreQueryTypes {
|
|
10
|
-
[key: string]: LiveQuery<any>
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
4
|
|
|
14
5
|
export const LiveStoreContext = React.createContext<LiveStoreContext_ | undefined>(undefined)
|
|
15
6
|
|
package/src/react/useAtom.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
|
|
3
|
+
import { type QueryInfoCol, type QueryInfoRow, storeEventForQueryInfo } from '../query-info.js'
|
|
3
4
|
import type { LiveQuery } from '../reactiveQueries/base-class.js'
|
|
4
|
-
import { storeEventForUpdatePath, type UpdatePathDescCol, type UpdatePathDescRow } from '../update-path.js'
|
|
5
5
|
import { useStore } from './LiveStoreContext.js'
|
|
6
6
|
import { useQueryRef } from './useQuery.js'
|
|
7
7
|
import type { Dispatch, SetStateAction } from './useRow.js'
|
|
8
8
|
|
|
9
|
-
export const useAtom = <TQuery extends LiveQuery<any,
|
|
9
|
+
export const useAtom = <TQuery extends LiveQuery<any, QueryInfoRow<any> | QueryInfoCol<any, any>>>(
|
|
10
10
|
query$: TQuery,
|
|
11
|
-
): [value: TQuery['
|
|
11
|
+
): [value: TQuery['__result!'], setValue: Dispatch<SetStateAction<TQuery['__result!']>>] => {
|
|
12
12
|
const query$Ref = useQueryRef(query$)
|
|
13
13
|
|
|
14
14
|
const { store } = useStore()
|
|
15
15
|
|
|
16
|
-
const setValue = React.useMemo<Dispatch<SetStateAction<TQuery['
|
|
16
|
+
const setValue = React.useMemo<Dispatch<SetStateAction<TQuery['__result!']>>>(() => {
|
|
17
17
|
return (newValueOrFn: any) => {
|
|
18
18
|
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn
|
|
19
19
|
|
|
20
|
-
store.applyEvents([
|
|
20
|
+
store.applyEvents([storeEventForQueryInfo(query$.queryInfo!, newValue)])
|
|
21
21
|
}
|
|
22
|
-
}, [query$.
|
|
22
|
+
}, [query$.queryInfo, query$Ref, store])
|
|
23
23
|
|
|
24
24
|
return [query$Ref.current, setValue]
|
|
25
25
|
}
|
package/src/react/useQuery.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as otel from '@opentelemetry/api'
|
|
|
2
2
|
import { isEqual } from 'lodash-es'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
5
|
-
import type { GetResult,
|
|
5
|
+
import type { GetResult, LiveQueryAny } from '../reactiveQueries/base-class.js'
|
|
6
6
|
import { useStore } from './LiveStoreContext.js'
|
|
7
7
|
import { extractStackInfoFromStackTrace, originalStackLimit } from './utils/stack-info.js'
|
|
8
8
|
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js'
|
package/src/react/useRow.ts
CHANGED
|
@@ -4,18 +4,18 @@ import { mapValues } from 'lodash-es'
|
|
|
4
4
|
import React from 'react'
|
|
5
5
|
|
|
6
6
|
import type { DbGraph, LiveQuery } from '../index.js'
|
|
7
|
+
import type { QueryInfo } from '../query-info.js'
|
|
8
|
+
import { storeEventForQueryInfo } from '../query-info.js'
|
|
7
9
|
import type { RowResult } from '../row-query.js'
|
|
8
10
|
import { rowQuery } from '../row-query.js'
|
|
9
11
|
import { type DefaultSqliteTableDef, type TableDef, tableIsSingleton, type TableOptions } from '../schema/table-def.js'
|
|
10
|
-
import type { UpdatePathDesc } from '../update-path.js'
|
|
11
|
-
import { storeEventForUpdatePath } from '../update-path.js'
|
|
12
12
|
import { useStore } from './LiveStoreContext.js'
|
|
13
13
|
import { useQueryRef } from './useQuery.js'
|
|
14
14
|
|
|
15
15
|
export type UseRowResult<TTableDef extends TableDef> = [
|
|
16
16
|
row: RowResult<TTableDef>,
|
|
17
17
|
setRow: StateSetters<TTableDef>,
|
|
18
|
-
query$: LiveQuery<RowResult<TTableDef>,
|
|
18
|
+
query$: LiveQuery<RowResult<TTableDef>, QueryInfo>,
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
export type UseRowOptionsDefaulValues<TTableDef extends TableDef> = {
|
|
@@ -69,7 +69,7 @@ export const useRow: {
|
|
|
69
69
|
cachedItem.span.addEvent('new-subscriber', { reactId })
|
|
70
70
|
|
|
71
71
|
return {
|
|
72
|
-
query$: cachedItem.query$ as LiveQuery<RowResult<TTableDef>,
|
|
72
|
+
query$: cachedItem.query$ as LiveQuery<RowResult<TTableDef>, QueryInfo>,
|
|
73
73
|
otelContext: cachedItem.otelContext,
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -83,12 +83,12 @@ export const useRow: {
|
|
|
83
83
|
const otelContext = otel.trace.setSpan(otel.context.active(), span)
|
|
84
84
|
|
|
85
85
|
const query$ = tableIsSingleton(table)
|
|
86
|
-
? (rowQuery(table, { otelContext, dbGraph }) as LiveQuery<RowResult<TTableDef>,
|
|
86
|
+
? (rowQuery(table, { otelContext, dbGraph }) as LiveQuery<RowResult<TTableDef>, QueryInfo>)
|
|
87
87
|
: (rowQuery(table as TTableDef & { options: { isSingleton: false } }, id!, {
|
|
88
88
|
otelContext,
|
|
89
89
|
defaultValues: defaultValues!,
|
|
90
90
|
dbGraph,
|
|
91
|
-
}) as any as LiveQuery<RowResult<TTableDef>,
|
|
91
|
+
}) as any as LiveQuery<RowResult<TTableDef>, QueryInfo>)
|
|
92
92
|
|
|
93
93
|
rcCache.set(table, id ?? 'singleton', query$, reactId, otelContext, span)
|
|
94
94
|
|
|
@@ -117,7 +117,7 @@ export const useRow: {
|
|
|
117
117
|
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn
|
|
118
118
|
if (query$Ref.current === newValue) return
|
|
119
119
|
|
|
120
|
-
store.applyEvents([
|
|
120
|
+
store.applyEvents([storeEventForQueryInfo(query$.queryInfo!, { value: newValue })])
|
|
121
121
|
}
|
|
122
122
|
} else {
|
|
123
123
|
const setState = // TODO: do we have a better type for the values that can go in SQLite?
|
|
@@ -130,7 +130,7 @@ export const useRow: {
|
|
|
130
130
|
// @ts-expect-error TODO fix typing
|
|
131
131
|
if (query$Ref.current[columnName] === newValue) return
|
|
132
132
|
|
|
133
|
-
store.applyEvents([
|
|
133
|
+
store.applyEvents([storeEventForQueryInfo(query$.queryInfo!, { [columnName]: newValue })])
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
setState.setMany = (columnValuesOrFn: Partial<TComponentState>) => {
|
|
@@ -147,12 +147,12 @@ export const useRow: {
|
|
|
147
147
|
return
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
store.applyEvents([
|
|
150
|
+
store.applyEvents([storeEventForQueryInfo(query$.queryInfo!, columnValues)])
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
return setState as any
|
|
154
154
|
}
|
|
155
|
-
}, [query$.
|
|
155
|
+
}, [query$.queryInfo, query$Ref, sqliteTableDef.columns, store, table.isSingleColumn])
|
|
156
156
|
|
|
157
157
|
return [query$Ref.current, setState, query$]
|
|
158
158
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type * as otel from '@opentelemetry/api'
|
|
2
2
|
import ReactDOM from 'react-dom'
|
|
3
3
|
|
|
4
|
+
import type { QueryInfo, QueryInfoNone } from '../query-info.js'
|
|
4
5
|
import type { StackInfo } from '../react/utils/stack-info.js'
|
|
5
6
|
import { type Atom, type GetAtom, ReactiveGraph, throwContextNotSetError, type Thunk } from '../reactive.js'
|
|
6
7
|
import type { QueryDebugInfo, RefreshReason, Store } from '../store.js'
|
|
7
|
-
import type { UpdatePathDesc, UpdatePathDescNone } from '../update-path.js'
|
|
8
8
|
|
|
9
9
|
export type DbGraph = ReactiveGraph<RefreshReason, QueryDebugInfo, DbContext>
|
|
10
10
|
|
|
@@ -26,12 +26,14 @@ export type GetResult<TQuery extends LiveQueryAny> = TQuery extends LiveQuery<in
|
|
|
26
26
|
|
|
27
27
|
let queryIdCounter = 0
|
|
28
28
|
|
|
29
|
-
export type LiveQueryAny = LiveQuery<any,
|
|
29
|
+
export type LiveQueryAny = LiveQuery<any, QueryInfo>
|
|
30
30
|
|
|
31
|
-
export interface LiveQuery<TResult,
|
|
31
|
+
export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoNone> {
|
|
32
32
|
id: number
|
|
33
33
|
_tag: 'js' | 'sql' | 'graphql'
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
/** This should only be used on a type-level and doesn't hold any value during runtime */
|
|
36
|
+
'__result!': TResult
|
|
35
37
|
|
|
36
38
|
/** A reactive thunk representing the query results */
|
|
37
39
|
results$: Thunk<TResult, DbContext, RefreshReason>
|
|
@@ -40,19 +42,27 @@ export interface LiveQuery<TResult, TUpdatePath extends UpdatePathDesc = UpdateP
|
|
|
40
42
|
|
|
41
43
|
run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult
|
|
42
44
|
|
|
45
|
+
runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult
|
|
46
|
+
|
|
43
47
|
destroy(): void
|
|
44
48
|
|
|
49
|
+
subscribe(
|
|
50
|
+
onNewValue: (value: TResult) => void,
|
|
51
|
+
onUnsubsubscribe?: () => void,
|
|
52
|
+
options?: { label?: string; otelContext?: otel.Context },
|
|
53
|
+
): () => void
|
|
54
|
+
|
|
45
55
|
activeSubscriptions: Set<StackInfo>
|
|
46
56
|
|
|
47
|
-
|
|
57
|
+
queryInfo: TQueryInfo
|
|
48
58
|
|
|
49
59
|
runs: number
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
export abstract class LiveStoreQueryBase<TResult,
|
|
53
|
-
implements LiveQuery<TResult,
|
|
62
|
+
export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
|
|
63
|
+
implements LiveQuery<TResult, TQueryInfo>
|
|
54
64
|
{
|
|
55
|
-
'
|
|
65
|
+
'__result!'!: TResult
|
|
56
66
|
id = queryIdCounter++
|
|
57
67
|
abstract _tag: 'js' | 'sql' | 'graphql'
|
|
58
68
|
|
|
@@ -65,7 +75,7 @@ export abstract class LiveStoreQueryBase<TResult, TUpdatePath extends UpdatePath
|
|
|
65
75
|
|
|
66
76
|
protected abstract dbGraph: DbGraph
|
|
67
77
|
|
|
68
|
-
abstract
|
|
78
|
+
abstract queryInfo: TQueryInfo
|
|
69
79
|
|
|
70
80
|
get runs() {
|
|
71
81
|
return this.results$.recomputations
|