@livestore/react 0.3.0-dev.11 → 0.3.0-dev.14

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.
@@ -14,7 +14,6 @@ exports[`useRow > otel > should update the data based on component key strictMod
14
14
  "sql.query": "
15
15
  PRAGMA page_size=32768;
16
16
  PRAGMA cache_size=10000;
17
- PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
18
17
  PRAGMA synchronous='OFF';
19
18
  PRAGMA temp_store='MEMORY';
20
19
  PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
@@ -211,7 +210,6 @@ exports[`useRow > otel > should update the data based on component key strictMod
211
210
  "sql.query": "
212
211
  PRAGMA page_size=32768;
213
212
  PRAGMA cache_size=10000;
214
- PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
215
213
  PRAGMA synchronous='OFF';
216
214
  PRAGMA temp_store='MEMORY';
217
215
  PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
@@ -1,9 +1,9 @@
1
+ import { makeInMemoryAdapter } from '@livestore/adapter-web'
1
2
  import { provideOtel } from '@livestore/common'
2
3
  import { DbSchema, makeSchema } from '@livestore/common/schema'
3
4
  import type { LiveStoreContextRunning } from '@livestore/livestore'
4
5
  import { createStore } from '@livestore/livestore'
5
6
  import { Effect } from '@livestore/utils/effect'
6
- import { makeInMemoryAdapter } from '@livestore/web'
7
7
  import type * as otel from '@opentelemetry/api'
8
8
  import React from 'react'
9
9
 
package/src/useAtom.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { DerivedMutationHelperFns, QueryInfo } from '@livestore/common'
2
- import type { DbSchema } from '@livestore/common/schema'
3
- import type { SqliteDsl } from '@livestore/db-schema'
2
+ import type { DbSchema, SqliteDsl } from '@livestore/common/schema'
4
3
  import type { GetResult, LiveQueryDef, Store } from '@livestore/livestore'
5
4
  import { shouldNeverHappen } from '@livestore/utils'
6
5
  import React from 'react'
package/src/useRow.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { QueryInfo, RowQuery } from '@livestore/common'
2
2
  import { SessionIdSymbol } from '@livestore/common'
3
+ import type { SqliteDsl } from '@livestore/common/schema'
3
4
  import { DbSchema } from '@livestore/common/schema'
4
- import type { SqliteDsl } from '@livestore/db-schema'
5
5
  import type { LiveQuery, LiveQueryDef, Store } from '@livestore/livestore'
6
6
  import { queryDb } from '@livestore/livestore'
7
7
  import { shouldNeverHappen } from '@livestore/utils'
@@ -51,7 +51,7 @@ export const useRow: {
51
51
  >(
52
52
  table: TTableDef,
53
53
  // TODO adjust so it works with arbitrary primary keys or unique constraints
54
- id: string | SessionIdSymbol,
54
+ id: string | SessionIdSymbol | number,
55
55
  options?: Partial<RowQuery.RequiredColumnsOptions<TTableDef>> & { store?: Store },
56
56
  ): UseRowResult<TTableDef>
57
57
 
@@ -64,7 +64,7 @@ export const useRow: {
64
64
  >(
65
65
  table: TTableDef,
66
66
  // TODO adjust so it works with arbitrary primary keys or unique constraints
67
- id: string | SessionIdSymbol,
67
+ id: string | SessionIdSymbol | number,
68
68
  options: RowQuery.RequiredColumnsOptions<TTableDef> & { store?: Store },
69
69
  ): UseRowResult<TTableDef>
70
70
  } = <
@@ -74,13 +74,18 @@ export const useRow: {
74
74
  >,
75
75
  >(
76
76
  table: TTableDef,
77
- idOrOptions?: string | SessionIdSymbol | { store?: Store },
77
+ idOrOptions?: string | SessionIdSymbol | number | { store?: Store },
78
78
  options_?: Partial<RowQuery.RequiredColumnsOptions<TTableDef>> & { store?: Store },
79
79
  ): UseRowResult<TTableDef> => {
80
80
  const sqliteTableDef = table.sqliteDef
81
- const id = typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol ? idOrOptions : undefined
81
+ const id =
82
+ typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol || typeof idOrOptions === 'number'
83
+ ? idOrOptions
84
+ : undefined
82
85
  const options: (Partial<RowQuery.RequiredColumnsOptions<TTableDef>> & { store?: Store }) | undefined =
83
- typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol ? options_ : idOrOptions
86
+ typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol || typeof idOrOptions === 'number'
87
+ ? options_
88
+ : idOrOptions
84
89
  const { insertValues } = options ?? {}
85
90
 
86
91
  type TComponentState = SqliteDsl.FromColumns.RowDecoded<TTableDef['sqliteDef']['columns']>
@@ -102,7 +107,7 @@ export const useRow: {
102
107
 
103
108
  // console.debug('useRow', tableName, id)
104
109
 
105
- const idStr = id === SessionIdSymbol ? 'session' : id
110
+ const idVal = id === SessionIdSymbol ? 'session' : id
106
111
  const rowQuery = table.query.row as any
107
112
 
108
113
  type QueryDef = LiveQueryDef<RowQuery.Result<TTableDef>, QueryInfo.Row>
@@ -110,12 +115,12 @@ export const useRow: {
110
115
  () =>
111
116
  DbSchema.tableIsSingleton(table)
112
117
  ? queryDb(rowQuery(), {})
113
- : queryDb(rowQuery(id!, { insertValues: insertValues! }), { deps: idStr! }),
114
- [id, insertValues, rowQuery, table, idStr],
118
+ : queryDb(rowQuery(id!, { insertValues: insertValues! }), { deps: idVal! }),
119
+ [id, insertValues, rowQuery, table, idVal],
115
120
  )
116
121
 
117
122
  const queryRef = useQueryRef(queryDef, {
118
- otelSpanName: `LiveStore:useRow:${tableName}${idStr === undefined ? '' : `:${idStr}`}`,
123
+ otelSpanName: `LiveStore:useRow:${tableName}${idVal === undefined ? '' : `:${idVal}`}`,
119
124
  store: options?.store,
120
125
  })
121
126
 
package/tsconfig.json CHANGED
@@ -11,9 +11,8 @@
11
11
  },
12
12
  "include": ["./src"],
13
13
  "references": [
14
- { "path": "../db-schema" },
15
14
  { "path": "../common" },
16
- { "path": "../web" },
15
+ { "path": "../adapter-web" },
17
16
  { "path": "../livestore" },
18
17
  { "path": "../utils" }
19
18
  ]