@livestore/livestore 0.0.58-dev.1 → 0.0.58-dev.10
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/README.md +1 -117
- package/dist/.tsbuildinfo +1 -1
- package/dist/effect/LiveStore.d.ts +3 -3
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +1 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/global-state.d.ts.map +1 -1
- package/dist/global-state.js +2 -1
- package/dist/global-state.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +1 -1
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +1 -1
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +4 -4
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +2 -2
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/row-query.d.ts +3 -2
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +18 -10
- package/dist/row-query.js.map +1 -1
- package/dist/store-devtools.d.ts +2 -2
- package/dist/store-devtools.d.ts.map +1 -1
- package/dist/store-devtools.js +3 -3
- package/dist/store-devtools.js.map +1 -1
- package/dist/store.d.ts +23 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +90 -59
- package/dist/store.js.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +1 -0
- package/dist/utils/dev.js.map +1 -1
- package/dist/{react/utils → utils}/stack-info.d.ts +1 -2
- package/dist/utils/stack-info.d.ts.map +1 -0
- package/dist/{react/utils → utils}/stack-info.js +1 -9
- package/dist/utils/stack-info.js.map +1 -0
- package/dist/utils/stack-info.test.d.ts.map +1 -0
- package/dist/{__tests__/react/utils → utils}/stack-info.test.js +1 -1
- package/dist/utils/stack-info.test.js.map +1 -0
- package/dist/utils/tests/fixture.d.ts +259 -0
- package/dist/utils/tests/fixture.d.ts.map +1 -0
- package/dist/utils/tests/fixture.js +33 -0
- package/dist/utils/tests/fixture.js.map +1 -0
- package/dist/utils/tests/mod.d.ts +3 -0
- package/dist/utils/tests/mod.d.ts.map +1 -0
- package/dist/utils/tests/mod.js +3 -0
- package/dist/utils/tests/mod.js.map +1 -0
- package/dist/utils/tests/otel.d.ts.map +1 -0
- package/dist/utils/tests/otel.js.map +1 -0
- package/package.json +17 -24
- package/src/ambient.d.ts +3 -0
- package/src/effect/LiveStore.ts +4 -4
- package/src/global-state.ts +5 -1
- package/src/index.ts +17 -4
- package/src/reactiveQueries/base-class.ts +1 -1
- package/src/reactiveQueries/sql.test.ts +2 -2
- package/src/reactiveQueries/sql.ts +5 -5
- package/src/row-query.ts +36 -16
- package/src/store-devtools.ts +5 -5
- package/src/store.ts +146 -78
- package/src/utils/dev.ts +1 -0
- package/src/{__tests__/react/utils → utils}/stack-info.test.ts +1 -1
- package/src/{react/utils → utils}/stack-info.ts +2 -12
- package/src/utils/tests/fixture.ts +77 -0
- package/src/utils/tests/mod.ts +2 -0
- package/tsconfig.json +1 -2
- package/vitest.config.js +0 -8
- package/dist/__tests__/react/fixture.d.ts +0 -461
- package/dist/__tests__/react/fixture.d.ts.map +0 -1
- package/dist/__tests__/react/fixture.js +0 -68
- package/dist/__tests__/react/fixture.js.map +0 -1
- package/dist/__tests__/react/utils/otel.d.ts.map +0 -1
- package/dist/__tests__/react/utils/otel.js.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.d.ts.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.js.map +0 -1
- package/dist/react/LiveStoreContext.d.ts +0 -7
- package/dist/react/LiveStoreContext.d.ts.map +0 -1
- package/dist/react/LiveStoreContext.js +0 -13
- package/dist/react/LiveStoreContext.js.map +0 -1
- package/dist/react/LiveStoreProvider.d.ts +0 -47
- package/dist/react/LiveStoreProvider.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.js +0 -169
- package/dist/react/LiveStoreProvider.js.map +0 -1
- package/dist/react/LiveStoreProvider.test.d.ts +0 -2
- package/dist/react/LiveStoreProvider.test.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.test.js +0 -62
- package/dist/react/LiveStoreProvider.test.js.map +0 -1
- package/dist/react/components/LiveList.d.ts +0 -21
- package/dist/react/components/LiveList.d.ts.map +0 -1
- package/dist/react/components/LiveList.js +0 -31
- package/dist/react/components/LiveList.js.map +0 -1
- package/dist/react/index.d.ts +0 -11
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -10
- package/dist/react/index.js.map +0 -1
- package/dist/react/useAtom.d.ts +0 -10
- package/dist/react/useAtom.d.ts.map +0 -1
- package/dist/react/useAtom.js +0 -37
- package/dist/react/useAtom.js.map +0 -1
- package/dist/react/useLocalId.d.ts +0 -10
- package/dist/react/useLocalId.d.ts.map +0 -1
- package/dist/react/useLocalId.js +0 -21
- package/dist/react/useLocalId.js.map +0 -1
- package/dist/react/useQuery.d.ts +0 -9
- package/dist/react/useQuery.d.ts.map +0 -1
- package/dist/react/useQuery.js +0 -69
- package/dist/react/useQuery.js.map +0 -1
- package/dist/react/useQuery.test.d.ts +0 -2
- package/dist/react/useQuery.test.d.ts.map +0 -1
- package/dist/react/useQuery.test.js +0 -51
- package/dist/react/useQuery.test.js.map +0 -1
- package/dist/react/useRow.d.ts +0 -46
- package/dist/react/useRow.d.ts.map +0 -1
- package/dist/react/useRow.js +0 -94
- package/dist/react/useRow.js.map +0 -1
- package/dist/react/useRow.test.d.ts +0 -2
- package/dist/react/useRow.test.d.ts.map +0 -1
- package/dist/react/useRow.test.js +0 -562
- package/dist/react/useRow.test.js.map +0 -1
- package/dist/react/useTemporaryQuery.d.ts +0 -22
- package/dist/react/useTemporaryQuery.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.js +0 -70
- package/dist/react/useTemporaryQuery.js.map +0 -1
- package/dist/react/useTemporaryQuery.test.d.ts +0 -2
- package/dist/react/useTemporaryQuery.test.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.test.js +0 -37
- package/dist/react/useTemporaryQuery.test.js.map +0 -1
- package/dist/react/utils/stack-info.d.ts.map +0 -1
- package/dist/react/utils/stack-info.js.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +0 -13
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.js +0 -38
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +0 -1
- package/src/__tests__/react/fixture.tsx +0 -126
- package/src/react/LiveStoreContext.ts +0 -20
- package/src/react/LiveStoreProvider.test.tsx +0 -109
- package/src/react/LiveStoreProvider.tsx +0 -289
- package/src/react/components/LiveList.tsx +0 -84
- package/src/react/index.ts +0 -19
- package/src/react/useAtom.ts +0 -55
- package/src/react/useLocalId.ts +0 -33
- package/src/react/useQuery.test.tsx +0 -82
- package/src/react/useQuery.ts +0 -105
- package/src/react/useRow.test.tsx +0 -699
- package/src/react/useRow.ts +0 -180
- package/src/react/useTemporaryQuery.test.tsx +0 -56
- package/src/react/useTemporaryQuery.ts +0 -121
- package/src/react/utils/useStateRefWithReactiveInput.ts +0 -51
- /package/dist/{__tests__/react/utils → utils}/stack-info.test.d.ts +0 -0
- /package/dist/{__tests__/react/utils → utils/tests}/otel.d.ts +0 -0
- /package/dist/{__tests__/react/utils → utils/tests}/otel.js +0 -0
- /package/src/{__tests__/react/utils → utils/tests}/otel.ts +0 -0
|
@@ -1,699 +0,0 @@
|
|
|
1
|
-
import { Effect, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
|
2
|
-
import * as otel from '@opentelemetry/api'
|
|
3
|
-
import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
|
|
4
|
-
import { render, renderHook } from '@testing-library/react'
|
|
5
|
-
import React from 'react'
|
|
6
|
-
import { describe, expect, it } from 'vitest'
|
|
7
|
-
|
|
8
|
-
import { makeTodoMvc, tables, todos } from '../__tests__/react/fixture.js'
|
|
9
|
-
import { getSimplifiedRootSpan } from '../__tests__/react/utils/otel.js'
|
|
10
|
-
import * as LiveStore from '../index.js'
|
|
11
|
-
import * as LiveStoreReact from './index.js'
|
|
12
|
-
import type { StackInfo } from './utils/stack-info.js'
|
|
13
|
-
|
|
14
|
-
// NOTE running tests concurrently doesn't work with the default global db graph
|
|
15
|
-
describe.concurrent('useRow', () => {
|
|
16
|
-
it('should update the data based on component key', () =>
|
|
17
|
-
Effect.gen(function* () {
|
|
18
|
-
const { wrapper, AppComponentSchema, store, reactivityGraph, makeRenderCount } = yield* makeTodoMvc({
|
|
19
|
-
useGlobalReactivityGraph: false,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const renderCount = makeRenderCount()
|
|
23
|
-
|
|
24
|
-
const { result, rerender } = renderHook(
|
|
25
|
-
(userId: string) => {
|
|
26
|
-
renderCount.inc()
|
|
27
|
-
|
|
28
|
-
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph })
|
|
29
|
-
return { state, setState }
|
|
30
|
-
},
|
|
31
|
-
{ wrapper, initialProps: 'u1' },
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
expect(result.current.state.id).toBe('u1')
|
|
35
|
-
expect(result.current.state.username).toBe('')
|
|
36
|
-
expect(renderCount.val).toBe(1)
|
|
37
|
-
|
|
38
|
-
React.act(() =>
|
|
39
|
-
store.mutate(
|
|
40
|
-
LiveStore.rawSqlMutation({
|
|
41
|
-
sql: LiveStore.sql`INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')`,
|
|
42
|
-
}),
|
|
43
|
-
),
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
rerender('u2')
|
|
47
|
-
|
|
48
|
-
expect(result.current.state.id).toBe('u2')
|
|
49
|
-
expect(result.current.state.username).toBe('username_u2')
|
|
50
|
-
expect(renderCount.val).toBe(2)
|
|
51
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise))
|
|
52
|
-
|
|
53
|
-
// TODO add a test that makes sure React doesn't re-render when a setter is used to set the same value
|
|
54
|
-
|
|
55
|
-
it('should update the data reactively - via setState', () =>
|
|
56
|
-
Effect.gen(function* () {
|
|
57
|
-
const { wrapper, AppComponentSchema, reactivityGraph, makeRenderCount } = yield* makeTodoMvc({
|
|
58
|
-
useGlobalReactivityGraph: false,
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const renderCount = makeRenderCount()
|
|
62
|
-
|
|
63
|
-
const { result } = renderHook(
|
|
64
|
-
(userId: string) => {
|
|
65
|
-
renderCount.inc()
|
|
66
|
-
|
|
67
|
-
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph })
|
|
68
|
-
return { state, setState }
|
|
69
|
-
},
|
|
70
|
-
{ wrapper, initialProps: 'u1' },
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
expect(result.current.state.id).toBe('u1')
|
|
74
|
-
expect(result.current.state.username).toBe('')
|
|
75
|
-
expect(renderCount.val).toBe(1)
|
|
76
|
-
|
|
77
|
-
React.act(() => result.current.setState.username('username_u1_hello'))
|
|
78
|
-
|
|
79
|
-
expect(result.current.state.id).toBe('u1')
|
|
80
|
-
expect(result.current.state.username).toBe('username_u1_hello')
|
|
81
|
-
expect(renderCount.val).toBe(2)
|
|
82
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise))
|
|
83
|
-
|
|
84
|
-
it('should update the data reactively - via raw store mutation', () =>
|
|
85
|
-
Effect.gen(function* () {
|
|
86
|
-
const { wrapper, AppComponentSchema, store, reactivityGraph, makeRenderCount } = yield* makeTodoMvc({
|
|
87
|
-
useGlobalReactivityGraph: false,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const renderCount = makeRenderCount()
|
|
91
|
-
|
|
92
|
-
const { result } = renderHook(
|
|
93
|
-
(userId: string) => {
|
|
94
|
-
renderCount.inc()
|
|
95
|
-
|
|
96
|
-
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph })
|
|
97
|
-
return { state, setState }
|
|
98
|
-
},
|
|
99
|
-
{ wrapper, initialProps: 'u1' },
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
expect(result.current.state.id).toBe('u1')
|
|
103
|
-
expect(result.current.state.username).toBe('')
|
|
104
|
-
expect(renderCount.val).toBe(1)
|
|
105
|
-
|
|
106
|
-
React.act(() =>
|
|
107
|
-
store.mutate(
|
|
108
|
-
LiveStore.rawSqlMutation({
|
|
109
|
-
sql: LiveStore.sql`UPDATE UserInfo SET username = 'username_u1_hello' WHERE id = 'u1';`,
|
|
110
|
-
}),
|
|
111
|
-
),
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
expect(result.current.state.id).toBe('u1')
|
|
115
|
-
expect(result.current.state.username).toBe('username_u1_hello')
|
|
116
|
-
expect(renderCount.val).toBe(2)
|
|
117
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise))
|
|
118
|
-
|
|
119
|
-
it('should work for a larger app', () =>
|
|
120
|
-
Effect.gen(function* () {
|
|
121
|
-
const { wrapper, store, reactivityGraph, makeRenderCount, AppRouterSchema } = yield* makeTodoMvc({
|
|
122
|
-
useGlobalReactivityGraph: false,
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const allTodos$ = LiveStore.querySQL(`select * from todos`, {
|
|
126
|
-
label: 'allTodos',
|
|
127
|
-
schema: Schema.Array(tables.todos.schema),
|
|
128
|
-
reactivityGraph,
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
const appRouterRenderCount = makeRenderCount()
|
|
132
|
-
let globalSetState: LiveStoreReact.StateSetters<typeof AppRouterSchema> | undefined
|
|
133
|
-
const AppRouter: React.FC = () => {
|
|
134
|
-
appRouterRenderCount.inc()
|
|
135
|
-
|
|
136
|
-
const [state, setState] = LiveStoreReact.useRow(AppRouterSchema, { reactivityGraph })
|
|
137
|
-
|
|
138
|
-
globalSetState = setState
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<div>
|
|
142
|
-
<TasksList setTaskId={setState.currentTaskId} />
|
|
143
|
-
<div role="current-id">Current Task Id: {state.currentTaskId ?? '-'}</div>
|
|
144
|
-
{state.currentTaskId ? <TaskDetails id={state.currentTaskId} /> : <div>Click on a task to see details</div>}
|
|
145
|
-
</div>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const TasksList: React.FC<{ setTaskId: (_: string) => void }> = ({ setTaskId }) => {
|
|
150
|
-
const allTodos = LiveStoreReact.useQuery(allTodos$)
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<div>
|
|
154
|
-
{allTodos.map((_) => (
|
|
155
|
-
<div key={_.id} onClick={() => setTaskId(_.id)}>
|
|
156
|
-
{_.id}
|
|
157
|
-
</div>
|
|
158
|
-
))}
|
|
159
|
-
</div>
|
|
160
|
-
)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const TaskDetails: React.FC<{ id: string }> = ({ id }) => {
|
|
164
|
-
const [todo] = LiveStoreReact.useRow(todos, id, { reactivityGraph })
|
|
165
|
-
return <div role="content">{JSON.stringify(todo)}</div>
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const renderResult = render(<AppRouter />, { wrapper })
|
|
169
|
-
|
|
170
|
-
expect(appRouterRenderCount.val).toBe(1)
|
|
171
|
-
|
|
172
|
-
React.act(() =>
|
|
173
|
-
store.mutate(
|
|
174
|
-
LiveStore.rawSqlMutation({
|
|
175
|
-
sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
176
|
-
}),
|
|
177
|
-
),
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
expect(appRouterRenderCount.val).toBe(1)
|
|
181
|
-
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: -"')
|
|
182
|
-
|
|
183
|
-
React.act(() => globalSetState!.currentTaskId('t1'))
|
|
184
|
-
|
|
185
|
-
expect(appRouterRenderCount.val).toBe(2)
|
|
186
|
-
expect(renderResult.getByRole('content').innerHTML).toMatchInlineSnapshot(
|
|
187
|
-
`"{"completed":false,"id":"t1","text":"buy milk"}"`,
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t1"')
|
|
191
|
-
|
|
192
|
-
React.act(() =>
|
|
193
|
-
store.mutate(
|
|
194
|
-
LiveStore.rawSqlMutation({
|
|
195
|
-
sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t2', 'buy eggs', 0)`,
|
|
196
|
-
}),
|
|
197
|
-
AppRouterSchema.update({ where: { id: 'singleton' }, values: { currentTaskId: 't2' } }),
|
|
198
|
-
LiveStore.rawSqlMutation({
|
|
199
|
-
sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t3', 'buy bread', 0)`,
|
|
200
|
-
}),
|
|
201
|
-
),
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
expect(appRouterRenderCount.val).toBe(3)
|
|
205
|
-
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t2"')
|
|
206
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise))
|
|
207
|
-
|
|
208
|
-
it('should work for a useRow query chained with a useTemporary query', () =>
|
|
209
|
-
Effect.gen(function* () {
|
|
210
|
-
const { store, wrapper, AppComponentSchema, reactivityGraph, makeRenderCount } = yield* makeTodoMvc({
|
|
211
|
-
useGlobalReactivityGraph: false,
|
|
212
|
-
})
|
|
213
|
-
const renderCount = makeRenderCount()
|
|
214
|
-
|
|
215
|
-
store.mutate(
|
|
216
|
-
todos.insert({ id: 't1', text: 'buy milk', completed: false }),
|
|
217
|
-
todos.insert({ id: 't2', text: 'buy bread', completed: false }),
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
const { result, unmount, rerender } = renderHook(
|
|
221
|
-
(userId: string) => {
|
|
222
|
-
renderCount.inc()
|
|
223
|
-
|
|
224
|
-
const [_row, _setRow, rowState$] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph })
|
|
225
|
-
const todos = LiveStoreReact.useTemporaryQuery(
|
|
226
|
-
() =>
|
|
227
|
-
LiveStore.querySQL(
|
|
228
|
-
(get) => LiveStore.sql`select * from todos where text like '%${get(rowState$).text}%'`,
|
|
229
|
-
{
|
|
230
|
-
schema: Schema.Array(tables.todos.schema),
|
|
231
|
-
reactivityGraph,
|
|
232
|
-
label: 'todosFiltered',
|
|
233
|
-
},
|
|
234
|
-
),
|
|
235
|
-
userId,
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
return { todos }
|
|
239
|
-
},
|
|
240
|
-
{ wrapper, initialProps: 'u1' },
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
React.act(() =>
|
|
244
|
-
store.mutate(
|
|
245
|
-
LiveStore.rawSqlMutation({
|
|
246
|
-
sql: LiveStore.sql`INSERT INTO UserInfo (id, username, text) VALUES ('u2', 'username_u2', 'milk')`,
|
|
247
|
-
}),
|
|
248
|
-
),
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
expect(result.current.todos.length).toBe(2)
|
|
252
|
-
// expect(result.current.state.username).toBe('')
|
|
253
|
-
expect(renderCount.val).toBe(1)
|
|
254
|
-
|
|
255
|
-
rerender('u2')
|
|
256
|
-
|
|
257
|
-
expect(result.current.todos.length).toBe(1)
|
|
258
|
-
expect(renderCount.val).toBe(2)
|
|
259
|
-
|
|
260
|
-
unmount()
|
|
261
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise))
|
|
262
|
-
|
|
263
|
-
let cachedProvider: BasicTracerProvider | undefined
|
|
264
|
-
|
|
265
|
-
describe('otel', () => {
|
|
266
|
-
const exporter = new InMemorySpanExporter()
|
|
267
|
-
|
|
268
|
-
const provider = cachedProvider ?? new BasicTracerProvider()
|
|
269
|
-
cachedProvider = provider
|
|
270
|
-
provider.addSpanProcessor(new SimpleSpanProcessor(exporter))
|
|
271
|
-
provider.register()
|
|
272
|
-
|
|
273
|
-
const otelTracer = otel.trace.getTracer('test')
|
|
274
|
-
|
|
275
|
-
const span = otelTracer.startSpan('test')
|
|
276
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span)
|
|
277
|
-
|
|
278
|
-
it('should update the data based on component key', async () => {
|
|
279
|
-
const { strictMode } = await Effect.gen(function* () {
|
|
280
|
-
const { wrapper, AppComponentSchema, store, reactivityGraph, makeRenderCount, strictMode } = yield* makeTodoMvc(
|
|
281
|
-
{ useGlobalReactivityGraph: false, otelContext, otelTracer },
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
const renderCount = makeRenderCount()
|
|
285
|
-
|
|
286
|
-
const { result, rerender, unmount } = renderHook(
|
|
287
|
-
(userId: string) => {
|
|
288
|
-
renderCount.inc()
|
|
289
|
-
|
|
290
|
-
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph })
|
|
291
|
-
return { state, setState }
|
|
292
|
-
},
|
|
293
|
-
{ wrapper, initialProps: 'u1' },
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
expect(result.current.state.id).toBe('u1')
|
|
297
|
-
expect(result.current.state.username).toBe('')
|
|
298
|
-
expect(renderCount.val).toBe(1)
|
|
299
|
-
|
|
300
|
-
React.act(() =>
|
|
301
|
-
store.mutate(
|
|
302
|
-
LiveStore.rawSqlMutation({
|
|
303
|
-
sql: LiveStore.sql`INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')`,
|
|
304
|
-
}),
|
|
305
|
-
),
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
rerender('u2')
|
|
309
|
-
|
|
310
|
-
expect(result.current.state.id).toBe('u2')
|
|
311
|
-
expect(result.current.state.username).toBe('username_u2')
|
|
312
|
-
expect(renderCount.val).toBe(2)
|
|
313
|
-
|
|
314
|
-
unmount()
|
|
315
|
-
span.end()
|
|
316
|
-
|
|
317
|
-
return { strictMode }
|
|
318
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise)
|
|
319
|
-
|
|
320
|
-
const mapAttributes = (attributes: otel.Attributes) => {
|
|
321
|
-
return ReadonlyRecord.map(attributes, (val, key) => {
|
|
322
|
-
if (key === 'stackInfo') {
|
|
323
|
-
const stackInfo = JSON.parse(val as string) as StackInfo
|
|
324
|
-
// stackInfo.frames.shift() // Removes `renderHook.wrapper` from the stack
|
|
325
|
-
stackInfo.frames.forEach((_) => {
|
|
326
|
-
if (_.name.includes('renderHook.wrapper')) {
|
|
327
|
-
_.name = 'renderHook.wrapper'
|
|
328
|
-
}
|
|
329
|
-
_.filePath = '__REPLACED_FOR_SNAPSHOT__'
|
|
330
|
-
})
|
|
331
|
-
return JSON.stringify(stackInfo)
|
|
332
|
-
}
|
|
333
|
-
return val
|
|
334
|
-
})
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (strictMode) {
|
|
338
|
-
expect(getSimplifiedRootSpan(exporter, mapAttributes)).toMatchInlineSnapshot(`
|
|
339
|
-
{
|
|
340
|
-
"_name": "test",
|
|
341
|
-
"children": [
|
|
342
|
-
{
|
|
343
|
-
"_name": "livestore.in-memory-db:execute",
|
|
344
|
-
"attributes": {
|
|
345
|
-
"sql.query": "
|
|
346
|
-
PRAGMA page_size=32768;
|
|
347
|
-
PRAGMA cache_size=10000;
|
|
348
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
349
|
-
PRAGMA synchronous='OFF';
|
|
350
|
-
PRAGMA temp_store='MEMORY';
|
|
351
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
352
|
-
",
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
"_name": "sql-in-memory-select",
|
|
357
|
-
"attributes": {
|
|
358
|
-
"sql.cached": false,
|
|
359
|
-
"sql.query": "select 1 from UserInfo where id = 'u1'",
|
|
360
|
-
"sql.rowsCount": 0,
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
"_name": "sql-in-memory-select",
|
|
365
|
-
"attributes": {
|
|
366
|
-
"sql.cached": false,
|
|
367
|
-
"sql.query": "select 1 from UserInfo where id = 'u2'",
|
|
368
|
-
"sql.rowsCount": 1,
|
|
369
|
-
},
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
"_name": "LiveStore:mutations",
|
|
373
|
-
"children": [
|
|
374
|
-
{
|
|
375
|
-
"_name": "LiveStore:mutate",
|
|
376
|
-
"attributes": {
|
|
377
|
-
"livestore.mutateLabel": "mutate",
|
|
378
|
-
},
|
|
379
|
-
"children": [
|
|
380
|
-
{
|
|
381
|
-
"_name": "LiveStore:processWrites",
|
|
382
|
-
"attributes": {
|
|
383
|
-
"livestore.mutateLabel": "mutate",
|
|
384
|
-
},
|
|
385
|
-
"children": [
|
|
386
|
-
{
|
|
387
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
388
|
-
"attributes": {
|
|
389
|
-
"livestore.args": "{
|
|
390
|
-
"sql": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')"
|
|
391
|
-
}",
|
|
392
|
-
"livestore.mutation": "livestore.RawSql",
|
|
393
|
-
},
|
|
394
|
-
"children": [
|
|
395
|
-
{
|
|
396
|
-
"_name": "livestore.in-memory-db:execute",
|
|
397
|
-
"attributes": {
|
|
398
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
],
|
|
402
|
-
},
|
|
403
|
-
],
|
|
404
|
-
},
|
|
405
|
-
],
|
|
406
|
-
},
|
|
407
|
-
],
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
"_name": "LiveStore:queries",
|
|
411
|
-
"children": [
|
|
412
|
-
{
|
|
413
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
414
|
-
"attributes": {
|
|
415
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
416
|
-
"sql.rowsCount": 1,
|
|
417
|
-
},
|
|
418
|
-
"children": [
|
|
419
|
-
{
|
|
420
|
-
"_name": "sql-in-memory-select",
|
|
421
|
-
"attributes": {
|
|
422
|
-
"sql.cached": false,
|
|
423
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
424
|
-
"sql.rowsCount": 1,
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
],
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
|
431
|
-
"attributes": {
|
|
432
|
-
"id": "u1",
|
|
433
|
-
},
|
|
434
|
-
"children": [
|
|
435
|
-
{
|
|
436
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
437
|
-
"attributes": {
|
|
438
|
-
"livestore.args": "{
|
|
439
|
-
"id": "u1"
|
|
440
|
-
}",
|
|
441
|
-
"livestore.mutation": "_Derived_Create_UserInfo",
|
|
442
|
-
},
|
|
443
|
-
"children": [
|
|
444
|
-
{
|
|
445
|
-
"_name": "livestore.in-memory-db:execute",
|
|
446
|
-
"attributes": {
|
|
447
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
|
448
|
-
},
|
|
449
|
-
},
|
|
450
|
-
],
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u1)",
|
|
454
|
-
"attributes": {
|
|
455
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
456
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
457
|
-
},
|
|
458
|
-
"children": [
|
|
459
|
-
{
|
|
460
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
461
|
-
"attributes": {
|
|
462
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
463
|
-
"sql.rowsCount": 1,
|
|
464
|
-
},
|
|
465
|
-
"children": [
|
|
466
|
-
{
|
|
467
|
-
"_name": "sql-in-memory-select",
|
|
468
|
-
"attributes": {
|
|
469
|
-
"sql.cached": false,
|
|
470
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
471
|
-
"sql.rowsCount": 1,
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
],
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
"_name": "LiveStore.subscribe",
|
|
478
|
-
"attributes": {
|
|
479
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
480
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
481
|
-
},
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
"_name": "LiveStore.subscribe",
|
|
485
|
-
"attributes": {
|
|
486
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
487
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
488
|
-
},
|
|
489
|
-
},
|
|
490
|
-
],
|
|
491
|
-
},
|
|
492
|
-
],
|
|
493
|
-
},
|
|
494
|
-
],
|
|
495
|
-
},
|
|
496
|
-
],
|
|
497
|
-
}
|
|
498
|
-
`)
|
|
499
|
-
// Below: Strict mode disabled
|
|
500
|
-
} else {
|
|
501
|
-
expect(getSimplifiedRootSpan(exporter, mapAttributes)).toMatchInlineSnapshot(`
|
|
502
|
-
{
|
|
503
|
-
"_name": "test",
|
|
504
|
-
"children": [
|
|
505
|
-
{
|
|
506
|
-
"_name": "livestore.in-memory-db:execute",
|
|
507
|
-
"attributes": {
|
|
508
|
-
"sql.query": "
|
|
509
|
-
PRAGMA page_size=32768;
|
|
510
|
-
PRAGMA cache_size=10000;
|
|
511
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
512
|
-
PRAGMA synchronous='OFF';
|
|
513
|
-
PRAGMA temp_store='MEMORY';
|
|
514
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
515
|
-
",
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
"_name": "sql-in-memory-select",
|
|
520
|
-
"attributes": {
|
|
521
|
-
"sql.cached": false,
|
|
522
|
-
"sql.query": "select 1 from UserInfo where id = 'u1'",
|
|
523
|
-
"sql.rowsCount": 0,
|
|
524
|
-
},
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
"_name": "sql-in-memory-select",
|
|
528
|
-
"attributes": {
|
|
529
|
-
"sql.cached": false,
|
|
530
|
-
"sql.query": "select 1 from UserInfo where id = 'u2'",
|
|
531
|
-
"sql.rowsCount": 1,
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
"_name": "LiveStore:mutations",
|
|
536
|
-
"children": [
|
|
537
|
-
{
|
|
538
|
-
"_name": "LiveStore:mutate",
|
|
539
|
-
"attributes": {
|
|
540
|
-
"livestore.mutateLabel": "mutate",
|
|
541
|
-
},
|
|
542
|
-
"children": [
|
|
543
|
-
{
|
|
544
|
-
"_name": "LiveStore:processWrites",
|
|
545
|
-
"attributes": {
|
|
546
|
-
"livestore.mutateLabel": "mutate",
|
|
547
|
-
},
|
|
548
|
-
"children": [
|
|
549
|
-
{
|
|
550
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
551
|
-
"attributes": {
|
|
552
|
-
"livestore.args": "{
|
|
553
|
-
"sql": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')"
|
|
554
|
-
}",
|
|
555
|
-
"livestore.mutation": "livestore.RawSql",
|
|
556
|
-
},
|
|
557
|
-
"children": [
|
|
558
|
-
{
|
|
559
|
-
"_name": "livestore.in-memory-db:execute",
|
|
560
|
-
"attributes": {
|
|
561
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
|
562
|
-
},
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
},
|
|
566
|
-
],
|
|
567
|
-
},
|
|
568
|
-
],
|
|
569
|
-
},
|
|
570
|
-
],
|
|
571
|
-
},
|
|
572
|
-
{
|
|
573
|
-
"_name": "LiveStore:queries",
|
|
574
|
-
"children": [
|
|
575
|
-
{
|
|
576
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
577
|
-
"attributes": {
|
|
578
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
579
|
-
"sql.rowsCount": 1,
|
|
580
|
-
},
|
|
581
|
-
"children": [
|
|
582
|
-
{
|
|
583
|
-
"_name": "sql-in-memory-select",
|
|
584
|
-
"attributes": {
|
|
585
|
-
"sql.cached": false,
|
|
586
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
587
|
-
"sql.rowsCount": 1,
|
|
588
|
-
},
|
|
589
|
-
},
|
|
590
|
-
],
|
|
591
|
-
},
|
|
592
|
-
{
|
|
593
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
|
594
|
-
"attributes": {
|
|
595
|
-
"id": "u1",
|
|
596
|
-
},
|
|
597
|
-
"children": [
|
|
598
|
-
{
|
|
599
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
600
|
-
"attributes": {
|
|
601
|
-
"livestore.args": "{
|
|
602
|
-
"id": "u1"
|
|
603
|
-
}",
|
|
604
|
-
"livestore.mutation": "_Derived_Create_UserInfo",
|
|
605
|
-
},
|
|
606
|
-
"children": [
|
|
607
|
-
{
|
|
608
|
-
"_name": "livestore.in-memory-db:execute",
|
|
609
|
-
"attributes": {
|
|
610
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
|
611
|
-
},
|
|
612
|
-
},
|
|
613
|
-
],
|
|
614
|
-
},
|
|
615
|
-
{
|
|
616
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u1)",
|
|
617
|
-
"attributes": {
|
|
618
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
619
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
620
|
-
},
|
|
621
|
-
"children": [
|
|
622
|
-
{
|
|
623
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
624
|
-
"attributes": {
|
|
625
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
626
|
-
"sql.rowsCount": 1,
|
|
627
|
-
},
|
|
628
|
-
"children": [
|
|
629
|
-
{
|
|
630
|
-
"_name": "sql-in-memory-select",
|
|
631
|
-
"attributes": {
|
|
632
|
-
"sql.cached": false,
|
|
633
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
634
|
-
"sql.rowsCount": 1,
|
|
635
|
-
},
|
|
636
|
-
},
|
|
637
|
-
],
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
"_name": "LiveStore.subscribe",
|
|
641
|
-
"attributes": {
|
|
642
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
643
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
644
|
-
},
|
|
645
|
-
},
|
|
646
|
-
],
|
|
647
|
-
},
|
|
648
|
-
],
|
|
649
|
-
},
|
|
650
|
-
{
|
|
651
|
-
"_name": "LiveStore:useRow:UserInfo:u2",
|
|
652
|
-
"attributes": {
|
|
653
|
-
"id": "u2",
|
|
654
|
-
},
|
|
655
|
-
"children": [
|
|
656
|
-
{
|
|
657
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u2)",
|
|
658
|
-
"attributes": {
|
|
659
|
-
"label": "sql(rowQuery:query:UserInfo:u2)",
|
|
660
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
661
|
-
},
|
|
662
|
-
"children": [
|
|
663
|
-
{
|
|
664
|
-
"_name": "sql:select * from UserInfo where id = 'u2' limit 1",
|
|
665
|
-
"attributes": {
|
|
666
|
-
"sql.query": "select * from UserInfo where id = 'u2' limit 1",
|
|
667
|
-
"sql.rowsCount": 1,
|
|
668
|
-
},
|
|
669
|
-
"children": [
|
|
670
|
-
{
|
|
671
|
-
"_name": "sql-in-memory-select",
|
|
672
|
-
"attributes": {
|
|
673
|
-
"sql.cached": false,
|
|
674
|
-
"sql.query": "select * from UserInfo where id = 'u2' limit 1",
|
|
675
|
-
"sql.rowsCount": 1,
|
|
676
|
-
},
|
|
677
|
-
},
|
|
678
|
-
],
|
|
679
|
-
},
|
|
680
|
-
{
|
|
681
|
-
"_name": "LiveStore.subscribe",
|
|
682
|
-
"attributes": {
|
|
683
|
-
"label": "sql(rowQuery:query:UserInfo:u2)",
|
|
684
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u2)",
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
],
|
|
688
|
-
},
|
|
689
|
-
],
|
|
690
|
-
},
|
|
691
|
-
],
|
|
692
|
-
},
|
|
693
|
-
],
|
|
694
|
-
}
|
|
695
|
-
`)
|
|
696
|
-
}
|
|
697
|
-
})
|
|
698
|
-
})
|
|
699
|
-
})
|