@livestore/react 0.3.0-dev.9 → 0.3.0
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/LiveStoreContext.d.ts +10 -4
- package/dist/LiveStoreContext.d.ts.map +1 -1
- package/dist/LiveStoreContext.js +1 -11
- package/dist/LiveStoreContext.js.map +1 -1
- package/dist/LiveStoreProvider.d.ts +29 -12
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +84 -55
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +80 -29
- package/dist/LiveStoreProvider.test.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +122 -556
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +71 -30
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.d.ts +2 -2
- package/dist/experimental/components/LiveList.d.ts.map +1 -1
- package/dist/experimental/components/LiveList.js +10 -6
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/mod.d.ts +4 -5
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -5
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts +61 -0
- package/dist/useClientDocument.d.ts.map +1 -0
- package/dist/useClientDocument.js +79 -0
- package/dist/useClientDocument.js.map +1 -0
- package/dist/useClientDocument.test.d.ts +2 -0
- package/dist/useClientDocument.test.d.ts.map +1 -0
- package/dist/useClientDocument.test.js +175 -0
- package/dist/useClientDocument.test.js.map +1 -0
- package/dist/useQuery.d.ts +25 -3
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +67 -47
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.d.ts +1 -1
- package/dist/useQuery.test.d.ts.map +1 -1
- package/dist/useQuery.test.js +86 -24
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useRcResource.d.ts +76 -0
- package/dist/useRcResource.d.ts.map +1 -0
- package/dist/useRcResource.js +152 -0
- package/dist/useRcResource.js.map +1 -0
- package/dist/useRcResource.test.d.ts +2 -0
- package/dist/useRcResource.test.d.ts.map +1 -0
- package/dist/useRcResource.test.js +122 -0
- package/dist/useRcResource.test.js.map +1 -0
- package/dist/useStore.d.ts +9 -0
- package/dist/useStore.d.ts.map +1 -0
- package/dist/useStore.js +28 -0
- package/dist/useStore.js.map +1 -0
- package/dist/utils/useStateRefWithReactiveInput.d.ts.map +1 -1
- package/package.json +19 -13
- package/src/LiveStoreContext.ts +11 -16
- package/src/LiveStoreProvider.test.tsx +176 -37
- package/src/LiveStoreProvider.tsx +156 -81
- package/src/__snapshots__/useClientDocument.test.tsx.snap +613 -0
- package/src/__snapshots__/useQuery.test.tsx.snap +2011 -0
- package/src/__tests__/fixture.tsx +74 -47
- package/src/experimental/components/LiveList.tsx +10 -7
- package/src/mod.ts +5 -6
- package/src/useClientDocument.test.tsx +306 -0
- package/src/useClientDocument.ts +157 -0
- package/src/useQuery.test.tsx +182 -71
- package/src/useQuery.ts +95 -58
- package/src/useRcResource.test.tsx +167 -0
- package/src/useRcResource.ts +182 -0
- package/src/useStore.ts +36 -0
- package/dist/useAtom.d.ts +0 -5
- package/dist/useAtom.d.ts.map +0 -1
- package/dist/useAtom.js +0 -38
- package/dist/useAtom.js.map +0 -1
- package/dist/useRow.d.ts +0 -50
- package/dist/useRow.d.ts.map +0 -1
- package/dist/useRow.js +0 -93
- package/dist/useRow.js.map +0 -1
- package/dist/useRow.test.d.ts +0 -2
- package/dist/useRow.test.d.ts.map +0 -1
- package/dist/useRow.test.js +0 -202
- package/dist/useRow.test.js.map +0 -1
- package/dist/useScopedQuery.d.ts +0 -33
- package/dist/useScopedQuery.d.ts.map +0 -1
- package/dist/useScopedQuery.js +0 -87
- package/dist/useScopedQuery.js.map +0 -1
- package/dist/useScopedQuery.test.d.ts +0 -2
- package/dist/useScopedQuery.test.d.ts.map +0 -1
- package/dist/useScopedQuery.test.js +0 -60
- package/dist/useScopedQuery.test.js.map +0 -1
- package/src/__snapshots__/useRow.test.tsx.snap +0 -360
- package/src/useAtom.ts +0 -52
- package/src/useRow.test.tsx +0 -344
- package/src/useRow.ts +0 -188
- package/src/useScopedQuery.test.tsx +0 -96
- package/src/useScopedQuery.ts +0 -143
- package/tsconfig.json +0 -20
- package/vitest.config.js +0 -17
@@ -1,360 +0,0 @@
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
2
|
-
|
3
|
-
exports[`useRow > otel > should update the data based on component key strictMode={ strictMode: false } 1`] = `
|
4
|
-
{
|
5
|
-
"_name": "createStore",
|
6
|
-
"attributes": {
|
7
|
-
"debugInstanceId": "test",
|
8
|
-
"storeId": "default",
|
9
|
-
},
|
10
|
-
"children": [
|
11
|
-
{
|
12
|
-
"_name": "livestore.in-memory-db:execute",
|
13
|
-
"attributes": {
|
14
|
-
"sql.query": "
|
15
|
-
PRAGMA page_size=32768;
|
16
|
-
PRAGMA cache_size=10000;
|
17
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
18
|
-
PRAGMA synchronous='OFF';
|
19
|
-
PRAGMA temp_store='MEMORY';
|
20
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
21
|
-
",
|
22
|
-
},
|
23
|
-
},
|
24
|
-
{
|
25
|
-
"_name": "LiveStore:createStore",
|
26
|
-
},
|
27
|
-
{
|
28
|
-
"_name": "sql-in-memory-select",
|
29
|
-
"attributes": {
|
30
|
-
"sql.cached": false,
|
31
|
-
"sql.query": "SELECT 1 FROM 'UserInfo' WHERE id = ?",
|
32
|
-
"sql.rowsCount": 0,
|
33
|
-
},
|
34
|
-
},
|
35
|
-
{
|
36
|
-
"_name": "sql-in-memory-select",
|
37
|
-
"attributes": {
|
38
|
-
"sql.cached": false,
|
39
|
-
"sql.query": "SELECT 1 FROM 'UserInfo' WHERE id = ?",
|
40
|
-
"sql.rowsCount": 1,
|
41
|
-
},
|
42
|
-
},
|
43
|
-
{
|
44
|
-
"_name": "LiveStore:sync",
|
45
|
-
},
|
46
|
-
{
|
47
|
-
"_name": "LiveStore:mutations",
|
48
|
-
"children": [
|
49
|
-
{
|
50
|
-
"_name": "LiveStore:mutate",
|
51
|
-
"attributes": {
|
52
|
-
"livestore.mutateLabel": "mutate",
|
53
|
-
},
|
54
|
-
"children": [
|
55
|
-
{
|
56
|
-
"_name": "LiveStore:mutate:applyMutations",
|
57
|
-
"attributes": {
|
58
|
-
"livestore.mutateLabel": "mutate",
|
59
|
-
},
|
60
|
-
"children": [
|
61
|
-
{
|
62
|
-
"_name": "livestore.in-memory-db:execute",
|
63
|
-
"attributes": {
|
64
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
65
|
-
},
|
66
|
-
},
|
67
|
-
],
|
68
|
-
},
|
69
|
-
],
|
70
|
-
},
|
71
|
-
],
|
72
|
-
},
|
73
|
-
{
|
74
|
-
"_name": "LiveStore:queries",
|
75
|
-
"children": [
|
76
|
-
{
|
77
|
-
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
78
|
-
"attributes": {
|
79
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
80
|
-
"sql.rowsCount": 1,
|
81
|
-
},
|
82
|
-
"children": [
|
83
|
-
{
|
84
|
-
"_name": "sql-in-memory-select",
|
85
|
-
"attributes": {
|
86
|
-
"sql.cached": false,
|
87
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
88
|
-
"sql.rowsCount": 1,
|
89
|
-
},
|
90
|
-
},
|
91
|
-
],
|
92
|
-
},
|
93
|
-
{
|
94
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
95
|
-
"attributes": {
|
96
|
-
"id": "u1",
|
97
|
-
},
|
98
|
-
"children": [
|
99
|
-
{
|
100
|
-
"_name": "LiveStore:mutate",
|
101
|
-
"attributes": {
|
102
|
-
"livestore.mutateLabel": "mutate",
|
103
|
-
},
|
104
|
-
"children": [
|
105
|
-
{
|
106
|
-
"_name": "LiveStore:mutate:applyMutations",
|
107
|
-
"attributes": {
|
108
|
-
"livestore.mutateLabel": "mutate",
|
109
|
-
},
|
110
|
-
"children": [
|
111
|
-
{
|
112
|
-
"_name": "livestore.in-memory-db:execute",
|
113
|
-
"attributes": {
|
114
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
115
|
-
},
|
116
|
-
},
|
117
|
-
],
|
118
|
-
},
|
119
|
-
],
|
120
|
-
},
|
121
|
-
{
|
122
|
-
"_name": "LiveStore:useQuery:db(row:UserInfo:u1)",
|
123
|
-
"attributes": {
|
124
|
-
"label": "db(row:UserInfo:u1)",
|
125
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
126
|
-
},
|
127
|
-
"children": [
|
128
|
-
{
|
129
|
-
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
130
|
-
"attributes": {
|
131
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
132
|
-
"sql.rowsCount": 1,
|
133
|
-
},
|
134
|
-
"children": [
|
135
|
-
{
|
136
|
-
"_name": "sql-in-memory-select",
|
137
|
-
"attributes": {
|
138
|
-
"sql.cached": false,
|
139
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
140
|
-
"sql.rowsCount": 1,
|
141
|
-
},
|
142
|
-
},
|
143
|
-
],
|
144
|
-
},
|
145
|
-
{
|
146
|
-
"_name": "LiveStore.subscribe",
|
147
|
-
"attributes": {
|
148
|
-
"label": "db(row:UserInfo:u1)",
|
149
|
-
"queryLabel": "db(row:UserInfo:u1)",
|
150
|
-
},
|
151
|
-
},
|
152
|
-
],
|
153
|
-
},
|
154
|
-
],
|
155
|
-
},
|
156
|
-
{
|
157
|
-
"_name": "LiveStore:useRow:UserInfo:u2",
|
158
|
-
"attributes": {
|
159
|
-
"id": "u2",
|
160
|
-
},
|
161
|
-
"children": [
|
162
|
-
{
|
163
|
-
"_name": "LiveStore:useQuery:db(row:UserInfo:u2)",
|
164
|
-
"attributes": {
|
165
|
-
"label": "db(row:UserInfo:u2)",
|
166
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
167
|
-
},
|
168
|
-
"children": [
|
169
|
-
{
|
170
|
-
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
171
|
-
"attributes": {
|
172
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
173
|
-
"sql.rowsCount": 1,
|
174
|
-
},
|
175
|
-
"children": [
|
176
|
-
{
|
177
|
-
"_name": "sql-in-memory-select",
|
178
|
-
"attributes": {
|
179
|
-
"sql.cached": false,
|
180
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
181
|
-
"sql.rowsCount": 1,
|
182
|
-
},
|
183
|
-
},
|
184
|
-
],
|
185
|
-
},
|
186
|
-
{
|
187
|
-
"_name": "LiveStore.subscribe",
|
188
|
-
"attributes": {
|
189
|
-
"label": "db(row:UserInfo:u2)",
|
190
|
-
"queryLabel": "db(row:UserInfo:u2)",
|
191
|
-
},
|
192
|
-
},
|
193
|
-
],
|
194
|
-
},
|
195
|
-
],
|
196
|
-
},
|
197
|
-
],
|
198
|
-
},
|
199
|
-
],
|
200
|
-
}
|
201
|
-
`;
|
202
|
-
|
203
|
-
exports[`useRow > otel > should update the data based on component key strictMode={ strictMode: true } 1`] = `
|
204
|
-
{
|
205
|
-
"_name": "createStore",
|
206
|
-
"attributes": {
|
207
|
-
"debugInstanceId": "test",
|
208
|
-
"storeId": "default",
|
209
|
-
},
|
210
|
-
"children": [
|
211
|
-
{
|
212
|
-
"_name": "livestore.in-memory-db:execute",
|
213
|
-
"attributes": {
|
214
|
-
"sql.query": "
|
215
|
-
PRAGMA page_size=32768;
|
216
|
-
PRAGMA cache_size=10000;
|
217
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
218
|
-
PRAGMA synchronous='OFF';
|
219
|
-
PRAGMA temp_store='MEMORY';
|
220
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
221
|
-
",
|
222
|
-
},
|
223
|
-
},
|
224
|
-
{
|
225
|
-
"_name": "LiveStore:createStore",
|
226
|
-
},
|
227
|
-
{
|
228
|
-
"_name": "sql-in-memory-select",
|
229
|
-
"attributes": {
|
230
|
-
"sql.cached": false,
|
231
|
-
"sql.query": "SELECT 1 FROM 'UserInfo' WHERE id = ?",
|
232
|
-
"sql.rowsCount": 0,
|
233
|
-
},
|
234
|
-
},
|
235
|
-
{
|
236
|
-
"_name": "sql-in-memory-select",
|
237
|
-
"attributes": {
|
238
|
-
"sql.cached": false,
|
239
|
-
"sql.query": "SELECT 1 FROM 'UserInfo' WHERE id = ?",
|
240
|
-
"sql.rowsCount": 1,
|
241
|
-
},
|
242
|
-
},
|
243
|
-
{
|
244
|
-
"_name": "LiveStore:sync",
|
245
|
-
},
|
246
|
-
{
|
247
|
-
"_name": "LiveStore:mutations",
|
248
|
-
"children": [
|
249
|
-
{
|
250
|
-
"_name": "LiveStore:mutate",
|
251
|
-
"attributes": {
|
252
|
-
"livestore.mutateLabel": "mutate",
|
253
|
-
},
|
254
|
-
"children": [
|
255
|
-
{
|
256
|
-
"_name": "LiveStore:mutate:applyMutations",
|
257
|
-
"attributes": {
|
258
|
-
"livestore.mutateLabel": "mutate",
|
259
|
-
},
|
260
|
-
"children": [
|
261
|
-
{
|
262
|
-
"_name": "livestore.in-memory-db:execute",
|
263
|
-
"attributes": {
|
264
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
265
|
-
},
|
266
|
-
},
|
267
|
-
],
|
268
|
-
},
|
269
|
-
],
|
270
|
-
},
|
271
|
-
],
|
272
|
-
},
|
273
|
-
{
|
274
|
-
"_name": "LiveStore:queries",
|
275
|
-
"children": [
|
276
|
-
{
|
277
|
-
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
278
|
-
"attributes": {
|
279
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
280
|
-
"sql.rowsCount": 1,
|
281
|
-
},
|
282
|
-
"children": [
|
283
|
-
{
|
284
|
-
"_name": "sql-in-memory-select",
|
285
|
-
"attributes": {
|
286
|
-
"sql.cached": false,
|
287
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
288
|
-
"sql.rowsCount": 1,
|
289
|
-
},
|
290
|
-
},
|
291
|
-
],
|
292
|
-
},
|
293
|
-
{
|
294
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
295
|
-
"attributes": {
|
296
|
-
"id": "u1",
|
297
|
-
},
|
298
|
-
"children": [
|
299
|
-
{
|
300
|
-
"_name": "LiveStore:mutate",
|
301
|
-
"attributes": {
|
302
|
-
"livestore.mutateLabel": "mutate",
|
303
|
-
},
|
304
|
-
"children": [
|
305
|
-
{
|
306
|
-
"_name": "LiveStore:mutate:applyMutations",
|
307
|
-
"attributes": {
|
308
|
-
"livestore.mutateLabel": "mutate",
|
309
|
-
},
|
310
|
-
"children": [
|
311
|
-
{
|
312
|
-
"_name": "livestore.in-memory-db:execute",
|
313
|
-
"attributes": {
|
314
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
315
|
-
},
|
316
|
-
},
|
317
|
-
],
|
318
|
-
},
|
319
|
-
],
|
320
|
-
},
|
321
|
-
{
|
322
|
-
"_name": "LiveStore:useQuery:db(row:UserInfo:u1)",
|
323
|
-
"attributes": {
|
324
|
-
"label": "db(row:UserInfo:u1)",
|
325
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
326
|
-
},
|
327
|
-
"children": [
|
328
|
-
{
|
329
|
-
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
330
|
-
"attributes": {
|
331
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
332
|
-
"sql.rowsCount": 1,
|
333
|
-
},
|
334
|
-
"children": [
|
335
|
-
{
|
336
|
-
"_name": "sql-in-memory-select",
|
337
|
-
"attributes": {
|
338
|
-
"sql.cached": false,
|
339
|
-
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
340
|
-
"sql.rowsCount": 1,
|
341
|
-
},
|
342
|
-
},
|
343
|
-
],
|
344
|
-
},
|
345
|
-
{
|
346
|
-
"_name": "LiveStore.subscribe",
|
347
|
-
"attributes": {
|
348
|
-
"label": "db(row:UserInfo:u1)",
|
349
|
-
"queryLabel": "db(row:UserInfo:u1)",
|
350
|
-
},
|
351
|
-
},
|
352
|
-
],
|
353
|
-
},
|
354
|
-
],
|
355
|
-
},
|
356
|
-
],
|
357
|
-
},
|
358
|
-
],
|
359
|
-
}
|
360
|
-
`;
|
package/src/useAtom.ts
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
import type { DerivedMutationHelperFns, QueryInfo } from '@livestore/common'
|
2
|
-
import type { DbSchema } from '@livestore/common/schema'
|
3
|
-
import type { SqliteDsl } from '@livestore/db-schema'
|
4
|
-
import type { LiveQuery } from '@livestore/livestore'
|
5
|
-
import React from 'react'
|
6
|
-
|
7
|
-
import { useStore } from './LiveStoreContext.js'
|
8
|
-
import { useQueryRef } from './useQuery.js'
|
9
|
-
import type { Dispatch, SetStateAction } from './useRow.js'
|
10
|
-
|
11
|
-
export const useAtom = <
|
12
|
-
// TODO also support colJsonValue
|
13
|
-
TQuery extends LiveQuery<any, QueryInfo.Row | QueryInfo.Col>,
|
14
|
-
>(
|
15
|
-
query$: TQuery,
|
16
|
-
): [value: TQuery['__result!'], setValue: Dispatch<SetStateAction<Partial<TQuery['__result!']>>>] => {
|
17
|
-
const query$Ref = useQueryRef(query$)
|
18
|
-
|
19
|
-
const { store } = useStore()
|
20
|
-
|
21
|
-
// TODO make API equivalent to useRow
|
22
|
-
const setValue = React.useMemo<Dispatch<SetStateAction<TQuery['__result!']>>>(() => {
|
23
|
-
return (newValueOrFn: any) => {
|
24
|
-
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn
|
25
|
-
const table = query$.queryInfo.table as DbSchema.TableDef &
|
26
|
-
DerivedMutationHelperFns<SqliteDsl.Columns, DbSchema.TableOptions>
|
27
|
-
|
28
|
-
if (query$.queryInfo._tag === 'Row') {
|
29
|
-
if (table.options.isSingleton && table.options.isSingleColumn) {
|
30
|
-
store.mutate(table.update(newValue))
|
31
|
-
} else if (table.options.isSingleColumn) {
|
32
|
-
store.mutate(table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }))
|
33
|
-
} else {
|
34
|
-
store.mutate(table.update({ where: { id: query$.queryInfo.id }, values: newValue }))
|
35
|
-
}
|
36
|
-
} else {
|
37
|
-
if (table.options.isSingleton && table.options.isSingleColumn) {
|
38
|
-
store.mutate(table.update({ [query$.queryInfo.column]: newValue }))
|
39
|
-
} else {
|
40
|
-
store.mutate(
|
41
|
-
table.update({
|
42
|
-
where: { id: query$.queryInfo.id },
|
43
|
-
values: { [query$.queryInfo.column]: newValue },
|
44
|
-
}),
|
45
|
-
)
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}, [query$.queryInfo, query$Ref, store])
|
50
|
-
|
51
|
-
return [query$Ref.current, setValue]
|
52
|
-
}
|