@livestore/livestore 0.4.0-dev.22 → 0.4.0-dev.23

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.
Files changed (207) hide show
  1. package/README.md +0 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/QueryCache.js +1 -1
  4. package/dist/QueryCache.js.map +1 -1
  5. package/dist/SqliteDbWrapper.d.ts +5 -5
  6. package/dist/SqliteDbWrapper.d.ts.map +1 -1
  7. package/dist/SqliteDbWrapper.js +8 -8
  8. package/dist/SqliteDbWrapper.js.map +1 -1
  9. package/dist/SqliteDbWrapper.test.js +2 -2
  10. package/dist/SqliteDbWrapper.test.js.map +1 -1
  11. package/dist/effect/LiveStore.d.ts +14 -7
  12. package/dist/effect/LiveStore.d.ts.map +1 -1
  13. package/dist/effect/LiveStore.js +0 -15
  14. package/dist/effect/LiveStore.js.map +1 -1
  15. package/dist/effect/LiveStore.test.d.ts +2 -0
  16. package/dist/effect/LiveStore.test.d.ts.map +1 -0
  17. package/dist/effect/LiveStore.test.js +42 -0
  18. package/dist/effect/LiveStore.test.js.map +1 -0
  19. package/dist/live-queries/base-class.d.ts +3 -3
  20. package/dist/live-queries/base-class.d.ts.map +1 -1
  21. package/dist/live-queries/base-class.js +2 -2
  22. package/dist/live-queries/base-class.js.map +1 -1
  23. package/dist/live-queries/client-document-get-query.d.ts +1 -1
  24. package/dist/live-queries/client-document-get-query.d.ts.map +1 -1
  25. package/dist/live-queries/client-document-get-query.js +1 -1
  26. package/dist/live-queries/client-document-get-query.js.map +1 -1
  27. package/dist/live-queries/computed.d.ts.map +1 -1
  28. package/dist/live-queries/computed.js +2 -2
  29. package/dist/live-queries/computed.js.map +1 -1
  30. package/dist/live-queries/db-query.js +14 -14
  31. package/dist/live-queries/db-query.js.map +1 -1
  32. package/dist/live-queries/db-query.test.js +2 -2
  33. package/dist/live-queries/db-query.test.js.map +1 -1
  34. package/dist/live-queries/signal.test.js +2 -2
  35. package/dist/live-queries/signal.test.js.map +1 -1
  36. package/dist/mod.d.ts +1 -1
  37. package/dist/mod.d.ts.map +1 -1
  38. package/dist/mod.js.map +1 -1
  39. package/dist/reactive.d.ts +9 -9
  40. package/dist/reactive.d.ts.map +1 -1
  41. package/dist/reactive.js +9 -26
  42. package/dist/reactive.js.map +1 -1
  43. package/dist/reactive.test.js +2 -2
  44. package/dist/reactive.test.js.map +1 -1
  45. package/dist/store/StoreRegistry.d.ts +30 -5
  46. package/dist/store/StoreRegistry.d.ts.map +1 -1
  47. package/dist/store/StoreRegistry.js +54 -31
  48. package/dist/store/StoreRegistry.js.map +1 -1
  49. package/dist/store/StoreRegistry.test.js +251 -250
  50. package/dist/store/StoreRegistry.test.js.map +1 -1
  51. package/dist/store/create-store.d.ts +6 -2
  52. package/dist/store/create-store.d.ts.map +1 -1
  53. package/dist/store/create-store.js +13 -7
  54. package/dist/store/create-store.js.map +1 -1
  55. package/dist/store/devtools.d.ts +1 -1
  56. package/dist/store/devtools.d.ts.map +1 -1
  57. package/dist/store/devtools.js +3 -3
  58. package/dist/store/devtools.js.map +1 -1
  59. package/dist/store/store-eventstream.test.js +2 -2
  60. package/dist/store/store-eventstream.test.js.map +1 -1
  61. package/dist/store/store-types.d.ts +70 -5
  62. package/dist/store/store-types.d.ts.map +1 -1
  63. package/dist/store/store-types.js.map +1 -1
  64. package/dist/store/store-types.test.js +1 -1
  65. package/dist/store/store-types.test.js.map +1 -1
  66. package/dist/store/store.d.ts +81 -2
  67. package/dist/store/store.d.ts.map +1 -1
  68. package/dist/store/store.js +128 -45
  69. package/dist/store/store.js.map +1 -1
  70. package/dist/utils/dev.js.map +1 -1
  71. package/dist/utils/stack-info.js +2 -2
  72. package/dist/utils/stack-info.js.map +1 -1
  73. package/dist/utils/tests/fixture.d.ts +1 -1
  74. package/dist/utils/tests/fixture.d.ts.map +1 -1
  75. package/dist/utils/tests/fixture.js.map +1 -1
  76. package/dist/utils/tests/otel.d.ts.map +1 -1
  77. package/dist/utils/tests/otel.js +5 -5
  78. package/dist/utils/tests/otel.js.map +1 -1
  79. package/package.json +58 -17
  80. package/src/QueryCache.ts +1 -1
  81. package/src/SqliteDbWrapper.test.ts +4 -2
  82. package/src/SqliteDbWrapper.ts +12 -11
  83. package/src/ambient.d.ts +0 -7
  84. package/src/effect/LiveStore.test.ts +61 -0
  85. package/src/effect/LiveStore.ts +17 -26
  86. package/src/live-queries/__snapshots__/db-query.test.ts.snap +336 -231
  87. package/src/live-queries/base-class.ts +7 -6
  88. package/src/live-queries/client-document-get-query.ts +4 -2
  89. package/src/live-queries/computed.ts +3 -2
  90. package/src/live-queries/db-query.test.ts +3 -2
  91. package/src/live-queries/db-query.ts +15 -15
  92. package/src/live-queries/signal.test.ts +3 -2
  93. package/src/mod.ts +1 -0
  94. package/src/reactive.test.ts +3 -2
  95. package/src/reactive.ts +22 -23
  96. package/src/store/StoreRegistry.test.ts +317 -293
  97. package/src/store/StoreRegistry.ts +63 -38
  98. package/src/store/create-store.ts +26 -11
  99. package/src/store/devtools.ts +5 -6
  100. package/src/store/store-eventstream.test.ts +4 -2
  101. package/src/store/store-types.test.ts +3 -1
  102. package/src/store/store-types.ts +47 -8
  103. package/src/store/store.ts +172 -55
  104. package/src/utils/dev.ts +2 -2
  105. package/src/utils/stack-info.ts +2 -2
  106. package/src/utils/tests/fixture.ts +2 -1
  107. package/src/utils/tests/otel.ts +8 -7
  108. package/docs/api/index.md +0 -3
  109. package/docs/building-with-livestore/complex-ui-state/index.md +0 -3
  110. package/docs/building-with-livestore/crud/index.md +0 -3
  111. package/docs/building-with-livestore/data-modeling/index.md +0 -30
  112. package/docs/building-with-livestore/debugging/index.md +0 -17
  113. package/docs/building-with-livestore/devtools/index.md +0 -79
  114. package/docs/building-with-livestore/events/index.md +0 -355
  115. package/docs/building-with-livestore/examples/ai-agent/index.md +0 -5
  116. package/docs/building-with-livestore/examples/todo-workspaces/index.md +0 -885
  117. package/docs/building-with-livestore/examples/turnbased-game/index.md +0 -7
  118. package/docs/building-with-livestore/opentelemetry/index.md +0 -227
  119. package/docs/building-with-livestore/production-checklist/index.md +0 -5
  120. package/docs/building-with-livestore/reactivity-system/index.md +0 -202
  121. package/docs/building-with-livestore/rules-for-ai-agents/index.md +0 -9
  122. package/docs/building-with-livestore/state/materializers/index.md +0 -300
  123. package/docs/building-with-livestore/state/sql-queries/index.md +0 -94
  124. package/docs/building-with-livestore/state/sqlite/index.md +0 -45
  125. package/docs/building-with-livestore/state/sqlite-schema/index.md +0 -306
  126. package/docs/building-with-livestore/state/sqlite-schema-effect/index.md +0 -300
  127. package/docs/building-with-livestore/store/index.md +0 -625
  128. package/docs/building-with-livestore/syncing/index.md +0 -136
  129. package/docs/building-with-livestore/tools/cli/index.md +0 -177
  130. package/docs/building-with-livestore/tools/mcp/index.md +0 -187
  131. package/docs/examples/cloudflare-adapter/index.md +0 -44
  132. package/docs/examples/expo-adapter/index.md +0 -44
  133. package/docs/examples/index.md +0 -55
  134. package/docs/examples/node-adapter/index.md +0 -44
  135. package/docs/examples/web-adapter/index.md +0 -52
  136. package/docs/framework-integrations/custom-elements/index.md +0 -142
  137. package/docs/framework-integrations/react-integration/index.md +0 -937
  138. package/docs/framework-integrations/solid-integration/index.md +0 -293
  139. package/docs/framework-integrations/svelte-integration/index.md +0 -42
  140. package/docs/framework-integrations/vue-integration/index.md +0 -294
  141. package/docs/getting-started/expo/index.md +0 -882
  142. package/docs/getting-started/node/index.md +0 -115
  143. package/docs/getting-started/react-web/index.md +0 -626
  144. package/docs/getting-started/solid/index.md +0 -3
  145. package/docs/getting-started/vue/index.md +0 -471
  146. package/docs/index.md +0 -208
  147. package/docs/llms.txt +0 -146
  148. package/docs/misc/CODE_OF_CONDUCT/index.md +0 -133
  149. package/docs/misc/FAQ/index.md +0 -37
  150. package/docs/misc/community/index.md +0 -88
  151. package/docs/misc/credits/index.md +0 -14
  152. package/docs/misc/design-partners/index.md +0 -13
  153. package/docs/misc/package-management/index.md +0 -21
  154. package/docs/misc/performance/index.md +0 -25
  155. package/docs/misc/resources/index.md +0 -46
  156. package/docs/misc/state-of-the-project/index.md +0 -37
  157. package/docs/misc/troubleshooting/index.md +0 -82
  158. package/docs/overview/concepts/index.md +0 -78
  159. package/docs/overview/how-livestore-works/index.md +0 -56
  160. package/docs/overview/introduction/index.md +0 -413
  161. package/docs/overview/technology-comparison/index.md +0 -40
  162. package/docs/overview/when-livestore/index.md +0 -81
  163. package/docs/overview/why-livestore/index.md +0 -111
  164. package/docs/patterns/ai/index.md +0 -15
  165. package/docs/patterns/anonymous-user-transition/index.md +0 -10
  166. package/docs/patterns/app-evolution/index.md +0 -72
  167. package/docs/patterns/auth/index.md +0 -377
  168. package/docs/patterns/effect/index.md +0 -1505
  169. package/docs/patterns/encryption/index.md +0 -6
  170. package/docs/patterns/external-data/index.md +0 -5
  171. package/docs/patterns/file-management/index.md +0 -11
  172. package/docs/patterns/file-structure/index.md +0 -14
  173. package/docs/patterns/list-ordering/index.md +0 -369
  174. package/docs/patterns/offline/index.md +0 -32
  175. package/docs/patterns/orm/index.md +0 -18
  176. package/docs/patterns/presence/index.md +0 -11
  177. package/docs/patterns/rich-text-editing/index.md +0 -11
  178. package/docs/patterns/server-side-clients/index.md +0 -97
  179. package/docs/patterns/side-effects/index.md +0 -11
  180. package/docs/patterns/state-machines/index.md +0 -11
  181. package/docs/patterns/storybook/index.md +0 -209
  182. package/docs/patterns/undo-redo/index.md +0 -9
  183. package/docs/patterns/version-control/index.md +0 -8
  184. package/docs/platform-adapters/cloudflare-durable-object-adapter/index.md +0 -453
  185. package/docs/platform-adapters/electron-adapter/index.md +0 -15
  186. package/docs/platform-adapters/expo-adapter/index.md +0 -262
  187. package/docs/platform-adapters/node-adapter/index.md +0 -160
  188. package/docs/platform-adapters/tauri-adapter/index.md +0 -15
  189. package/docs/platform-adapters/web-adapter/index.md +0 -287
  190. package/docs/sustainable-open-source/contributing/docs/index.md +0 -94
  191. package/docs/sustainable-open-source/contributing/info/index.md +0 -63
  192. package/docs/sustainable-open-source/contributing/monorepo/index.md +0 -195
  193. package/docs/sustainable-open-source/sponsoring/index.md +0 -104
  194. package/docs/sync-providers/cloudflare/index.md +0 -773
  195. package/docs/sync-providers/custom/index.md +0 -65
  196. package/docs/sync-providers/electricsql/index.md +0 -159
  197. package/docs/sync-providers/s2/index.md +0 -230
  198. package/docs/tutorial/0-welcome/index.md +0 -48
  199. package/docs/tutorial/1-setup-starter-project/index.md +0 -105
  200. package/docs/tutorial/2-deploy-to-cloudflare/index.md +0 -195
  201. package/docs/tutorial/3-read-and-write-todos-via-livestore/index.md +0 -530
  202. package/docs/tutorial/4-sync-data-via-cloudflare/index.md +0 -210
  203. package/docs/tutorial/5-expand-business-logic/index.md +0 -174
  204. package/docs/tutorial/6-persist-ui-state/index.md +0 -453
  205. package/docs/tutorial/7-next-steps/index.md +0 -22
  206. package/docs/understanding-livestore/design-decisions/index.md +0 -33
  207. package/docs/understanding-livestore/event-sourcing/index.md +0 -40
@@ -1,262 +0,0 @@
1
- # Expo Adapter
2
-
3
- The Expo adapter enables LiveStore in React Native applications built with [Expo](https://expo.dev). It uses native SQLite via `expo-sqlite` for high-performance local persistence on iOS and Android devices.
4
-
5
- ## Key Features
6
-
7
- - **Signals-based reactivity** — High-performance state management with fine-grained updates
8
- - **iOS and Android support** — Works seamlessly on both platforms with native performance
9
- - **Native SQLite storage** — Uses `expo-sqlite` for fast, reliable persistence directly on the device
10
- - **Offline-first** — Full functionality without network connectivity; syncs when connected
11
- - **Real-time sync** — Optional sync backend integration for multi-device data synchronization
12
- - **Integrated devtools** — Debug and inspect your store via the [LiveStore Devtools](/building-with-livestore/devtools)
13
-
14
- ## Requirements
15
-
16
- - [Expo New Architecture](https://docs.expo.dev/guides/new-architecture/) (Fabric) must be enabled
17
- - `expo-sqlite` ^16.0.0
18
- - `expo-application` ^7.0.0
19
-
20
- :::note
21
- Expo Web is not currently supported. See [#130](https://github.com/livestorejs/livestore/issues/130) for progress.
22
- :::
23
-
24
- ## Installation
25
-
26
- ```bash
27
- npm install @livestore/adapter-expo @livestore/livestore @livestore/react expo-sqlite expo-application
28
- ```
29
-
30
- For a complete setup including sync and devtools, see the [Expo getting started guide](/getting-started/expo).
31
-
32
- ## Basic Usage
33
-
34
- Create an adapter and a custom `useAppStore()` hook, then set up a `StoreRegistry` with `<StoreRegistryProvider>`:
35
-
36
- ## `reference/platform-adapters/expo-adapter/usage.tsx`
37
-
38
- ```tsx filename="reference/platform-adapters/expo-adapter/usage.tsx"
39
-
40
- const adapter = makePersistedAdapter()
41
-
42
- const useAppStore = () =>
43
- useStore({
44
- storeId: 'my-app',
45
- schema,
46
- adapter,
47
- batchUpdates,
48
- })
49
-
50
- export const App = () => {
51
- const [storeRegistry] = useState(() => new StoreRegistry())
52
- return (
53
- <SafeAreaView style={{ flex: 1 }}>
54
- <Suspense fallback={<Text>Loading...</Text>}>
55
- <StoreRegistryProvider storeRegistry={storeRegistry}>
56
- <TodoList />
57
- </StoreRegistryProvider>
58
- </Suspense>
59
- </SafeAreaView>
60
- )
61
- }
62
-
63
- const TodoList = () => {
64
- const store = useAppStore()
65
- const todos = store.useQuery(queryDb(tables.todos.select()))
66
- return <Text>{todos.length} todos</Text>
67
- }
68
- ```
69
-
70
- ### `reference/platform-adapters/expo-adapter/schema.ts`
71
-
72
- ```ts filename="reference/platform-adapters/expo-adapter/schema.ts"
73
-
74
- export const tables = {
75
- todos: State.SQLite.table({
76
- name: 'todos',
77
- columns: {
78
- id: State.SQLite.text({ primaryKey: true }),
79
- text: State.SQLite.text(),
80
- completed: State.SQLite.boolean({ default: false }),
81
- },
82
- }),
83
- } as const
84
-
85
- const events = {
86
- todoCreated: Events.synced({
87
- name: 'v1.TodoCreated',
88
- schema: Schema.Struct({ id: Schema.String, text: Schema.String }),
89
- }),
90
- } as const
91
-
92
- const materializers = State.SQLite.materializers(events, {
93
- [events.todoCreated.name]: defineMaterializer(events.todoCreated, ({ id, text }) =>
94
- tables.todos.insert({ id, text, completed: false }),
95
- ),
96
- })
97
-
98
- const state = State.SQLite.makeState({ tables, materializers })
99
-
100
- export const schema = makeSchema({ events, state })
101
- ```
102
-
103
- For more details on the registry, and hooks, see the [React integration guide](/framework-integrations/react-integration).
104
-
105
- ## Configuration Options
106
-
107
- ## `reference/platform-adapters/expo-adapter/adapter.ts`
108
-
109
- ```ts filename="reference/platform-adapters/expo-adapter/adapter.ts"
110
- /** biome-ignore-all lint/correctness/noUnusedVariables: docs snippet keeps inline adapter */
111
- // ---cut---
112
-
113
- const adapter = makePersistedAdapter({
114
- storage: {
115
- // Optional: custom base directory (defaults to expo-sqlite's default)
116
- // directory: '/custom/path/to/databases',
117
- subDirectory: 'my-app',
118
- },
119
- })
120
- ```
121
-
122
- ### Available Options
123
-
124
- | Option | Type | Description |
125
- |--------|------|-------------|
126
- | `storage.directory` | `string` | Base directory for database files (defaults to `expo-sqlite`'s default directory) |
127
- | `storage.subDirectory` | `string` | Subdirectory relative to `directory` for organizing databases |
128
- | `sync` | `SyncOptions` | Sync backend configuration (see [Syncing](/building-with-livestore/syncing)) |
129
- | `clientId` | `string` | Custom client identifier (defaults to device ID) |
130
- | `sessionId` | `string` | Session identifier (defaults to `'static'`) |
131
- | `resetPersistence` | `boolean` | Clear local databases on startup (development only) |
132
-
133
- ## Adding a Sync Backend
134
-
135
- Connect to a sync backend for multi-device synchronization:
136
-
137
- ## `reference/platform-adapters/expo-adapter/sync-backend.ts`
138
-
139
- ```ts filename="reference/platform-adapters/expo-adapter/sync-backend.ts"
140
- /** biome-ignore-all lint/correctness/noUnusedVariables: docs snippet keeps inline adapter */
141
- // ---cut---
142
-
143
- const adapter = makePersistedAdapter({
144
- sync: { backend: makeWsSync({ url: 'wss://your-sync-backend.com' }) },
145
- })
146
- ```
147
-
148
- See the [Syncing documentation](/building-with-livestore/syncing) for available sync providers and configuration options.
149
-
150
- ## Platform Notes
151
-
152
- ### Android
153
-
154
- Android requires HTTPS for network connections by default. During development with a local sync backend using `http://` or `ws://`, add `expo-build-properties` to allow cleartext traffic:
155
-
156
- ```bash
157
- npx expo install expo-build-properties
158
- ```
159
-
160
- Then configure `app.json`:
161
-
162
- ```json
163
- {
164
- "expo": {
165
- "plugins": [
166
- [
167
- "expo-build-properties",
168
- {
169
- "android": {
170
- "usesCleartextTraffic": true
171
- }
172
- }
173
- ]
174
- ]
175
- }
176
- }
177
- ```
178
-
179
- See [Expo build properties documentation](https://docs.expo.dev/versions/latest/sdk/build-properties/#pluginconfigtypeandroid) for more details.
180
-
181
- ### iOS
182
-
183
- No special configuration required. The adapter automatically retrieves the iOS vendor ID for client identification.
184
-
185
- ## Devtools
186
-
187
- LiveStore provides integrated devtools for debugging your store. In development, press `shift + m` in the Expo CLI terminal, then select "LiveStore Devtools" to open the browser-based inspector.
188
-
189
- See the [Devtools reference](/building-with-livestore/devtools) for full documentation.
190
-
191
- ## Storage & Persistence
192
-
193
- ### Database Location
194
-
195
- Databases are stored in the device's SQLite directory. The exact path depends on your setup:
196
-
197
- **Expo Go:**
198
- ```bash
199
- open $(find $(xcrun simctl get_app_container booted host.exp.Exponent data) -path "*/Documents/ExponentExperienceData/*livestore*" -print -quit)/SQLite
200
- ```
201
-
202
- **Development builds:**
203
- ```bash
204
- open $(xcrun simctl get_app_container booted [APP_BUNDLE_ID] data)/Documents/SQLite
205
- ```
206
-
207
- Replace `[APP_BUNDLE_ID]` with your app's bundle identifier (e.g., `dev.livestore.myapp`).
208
-
209
- ### Resetting Local Persistence
210
-
211
- During development, you can clear local databases on startup:
212
-
213
- ## `reference/platform-adapters/expo-adapter/reset-persistence.ts`
214
-
215
- ```ts filename="reference/platform-adapters/expo-adapter/reset-persistence.ts"
216
-
217
- const resetPersistence = process.env.EXPO_PUBLIC_LIVESTORE_RESET === 'true'
218
-
219
- const _adapter = makePersistedAdapter({
220
- storage: { subDirectory: 'dev' },
221
- resetPersistence,
222
- })
223
- ```
224
-
225
- :::caution
226
- This deletes all local LiveStore data for the configured store. It only clears on-device data and does not affect any connected sync backend. Ensure this flag is disabled in production builds.
227
- :::
228
-
229
- ## Architecture
230
-
231
- The Expo adapter runs LiveStore directly in the main JavaScript thread, using native SQLite bindings provided by `expo-sqlite`. This differs from the [web adapter](/platform-adapters/web-adapter), which uses web workers and WASM-based SQLite.
232
-
233
- ```
234
- ┌─────────────────────────────────────────┐
235
- │ React Native App │
236
- │ ┌───────────────────────────────────┐ │
237
- │ │ LiveStore Client │ │
238
- │ │ ┌─────────────┐ ┌─────────────┐ │ │
239
- │ │ │ State DB │ │ Eventlog DB │ │ │
240
- │ │ │(expo-sqlite)│ │(expo-sqlite)│ │ │
241
- │ │ └─────────────┘ └─────────────┘ │ │
242
- │ └───────────────────────────────────┘ │
243
- └─────────────────────────────────────────┘
244
-
245
- ▼ WebSocket
246
- ┌───────────────┐
247
- │ Sync Backend │
248
- │ (optional) │
249
- └───────────────┘
250
- ```
251
-
252
- ## Future Improvements
253
-
254
- We're exploring moving database operations to a background thread to further improve UI responsiveness during intensive writes. Follow [livestore/livestore](https://github.com/livestorejs/livestore) for updates.
255
-
256
- ## See Also
257
-
258
- - [Expo Getting Started Guide](/getting-started/expo) — Complete setup tutorial
259
- - [Expo Adapter Examples](/examples/expo-adapter) — Example applications
260
- - [React Integration](/framework-integrations/react-integration) — Provider and hooks documentation
261
- - [Syncing](/building-with-livestore/syncing) — Multi-device synchronization
262
- - [Devtools](/building-with-livestore/devtools) — Debugging and inspection tools
@@ -1,160 +0,0 @@
1
- # Node adapter
2
-
3
- Works with Node.js, Bun and Deno.
4
-
5
- ## Example
6
-
7
- ## `reference/platform-adapters/node-adapter/adapter.ts`
8
-
9
- ```ts filename="reference/platform-adapters/node-adapter/adapter.ts"
10
- /** biome-ignore-all lint/correctness/noUnusedVariables: docs snippet keeps inline adapter */
11
- // ---cut---
12
-
13
- const adapter = makeAdapter({
14
- storage: { type: 'fs' },
15
- // or in-memory:
16
- // storage: { type: 'in-memory' },
17
- sync: { backend: makeWsSync({ url: 'ws://localhost:8787' }) },
18
- // To enable devtools:
19
- // devtools: { schemaPath: new URL('./schema.ts', import.meta.url) },
20
- })
21
- ```
22
-
23
- ## Resetting local persistence
24
-
25
- During development you can instruct the adapter to wipe the locally persisted state and eventlog databases on startup:
26
-
27
- ## `reference/platform-adapters/node-adapter/reset-persistence.ts`
28
-
29
- ```ts filename="reference/platform-adapters/node-adapter/reset-persistence.ts"
30
- /** biome-ignore-all lint/correctness/noUnusedVariables: docs snippet keeps inline adapter */
31
- // ---cut---
32
-
33
- const resetPersistence = process.env.NODE_ENV !== 'production' && Boolean(process.env.RESET_LIVESTORE)
34
-
35
- const adapter = makeAdapter({
36
- storage: { type: 'fs' },
37
- resetPersistence,
38
- })
39
- ```
40
-
41
- :::caution
42
- This will delete all local data for the given `storeId` and `clientId`. It only clears local persistence and does not reset any connected sync backend. Only enable it for debugging scenarios.
43
- :::
44
-
45
- ### Worker adapter
46
-
47
- The worker adapter can be used for more advanced scenarios where it's preferable to reduce the load of the main thread and run persistence/syncing in a worker thread.
48
-
49
- ## `reference/platform-adapters/node-adapter/worker-main.ts`
50
-
51
- ```ts filename="reference/platform-adapters/node-adapter/worker-main.ts"
52
- /** biome-ignore-all lint/correctness/noUnusedVariables: snippet keeps adapter inline for docs */
53
- // ---cut---
54
-
55
- const adapter = makeWorkerAdapter({
56
- storage: { type: 'fs' },
57
- workerUrl: new URL('./livestore.worker.js', import.meta.url),
58
- })
59
- ```
60
-
61
- ## `reference/platform-adapters/node-adapter/worker-worker.ts`
62
-
63
- ```ts filename="reference/platform-adapters/node-adapter/worker-worker.ts"
64
-
65
- makeWorker({
66
- schema,
67
- sync: { backend: makeWsSync({ url: 'ws://localhost:8787' }) },
68
- })
69
- ```
70
-
71
- ### `reference/platform-adapters/node-adapter/schema.ts`
72
-
73
- ```ts filename="reference/platform-adapters/node-adapter/schema.ts"
74
-
75
- const tables = {
76
- todos: State.SQLite.table({
77
- name: 'todos',
78
- columns: {
79
- id: State.SQLite.text({ primaryKey: true }),
80
- text: State.SQLite.text(),
81
- completed: State.SQLite.boolean({ default: false }),
82
- },
83
- }),
84
- } as const
85
-
86
- const events = {
87
- todoCreated: Events.synced({
88
- name: 'v1.TodoCreated',
89
- schema: Schema.Struct({ id: Schema.String, text: Schema.String }),
90
- }),
91
- } as const
92
-
93
- const materializers = State.SQLite.materializers(events, {
94
- [events.todoCreated.name]: defineMaterializer(events.todoCreated, ({ id, text }) =>
95
- tables.todos.insert({ id, text, completed: false }),
96
- ),
97
- })
98
-
99
- const state = State.SQLite.makeState({ tables, materializers })
100
-
101
- export const schema = makeSchema({ events, state })
102
- ```
103
-
104
- #### Logging
105
-
106
- You can control what the Node worker logs and how it's formatted.
107
- Pass two optional options to `makeWorker`:
108
-
109
- - `logger` — where/format of logs (e.g. pretty console output)
110
- - `logLevel` — how verbose logs are (`LogLevel.None` silences logs)
111
-
112
- ## `reference/platform-adapters/node-adapter/worker-logging.ts`
113
-
114
- ```ts filename="reference/platform-adapters/node-adapter/worker-logging.ts"
115
-
116
- makeWorker({
117
- schema,
118
- // readable console output by thread name
119
- logger: Logger.prettyWithThread('livestore-node-leader-thread'),
120
- // choose verbosity: None | Error | Warning | Info | Debug
121
- logLevel: LogLevel.Info,
122
- })
123
- ```
124
-
125
- ### `reference/platform-adapters/node-adapter/schema.ts`
126
-
127
- ```ts filename="reference/platform-adapters/node-adapter/schema.ts"
128
-
129
- const tables = {
130
- todos: State.SQLite.table({
131
- name: 'todos',
132
- columns: {
133
- id: State.SQLite.text({ primaryKey: true }),
134
- text: State.SQLite.text(),
135
- completed: State.SQLite.boolean({ default: false }),
136
- },
137
- }),
138
- } as const
139
-
140
- const events = {
141
- todoCreated: Events.synced({
142
- name: 'v1.TodoCreated',
143
- schema: Schema.Struct({ id: Schema.String, text: Schema.String }),
144
- }),
145
- } as const
146
-
147
- const materializers = State.SQLite.materializers(events, {
148
- [events.todoCreated.name]: defineMaterializer(events.todoCreated, ({ id, text }) =>
149
- tables.todos.insert({ id, text, completed: false }),
150
- ),
151
- })
152
-
153
- const state = State.SQLite.makeState({ tables, materializers })
154
-
155
- export const schema = makeSchema({ events, state })
156
- ```
157
-
158
- Tips:
159
- - Use `LogLevel.None` to keep test output quiet.
160
- - Keep the default (Debug) when diagnosing issues.
@@ -1,15 +0,0 @@
1
- # Tauri adapter
2
-
3
- ## Native Tauri adapter
4
-
5
- While LiveStore doesn't yet support a native Tauri adapter (see [this issue](https://github.com/livestorejs/livestore/issues/125) for more details), you can already use the [web adapter](./web-adapter.md) with Tauri.
6
-
7
- The goal of the native Tauri adapter is for LiveStore to leverage native platform APIs and capabilities including:
8
-
9
- - Native file system access (instead of going through the browser abstraction layer)
10
- - Background sync capabilities
11
- - ...
12
-
13
- ## Example using the web adapter
14
-
15
- See this example of a Tauri app using the web adapter: [tauri-todomvc-sync-cf](https://github.com/bohdanbirdie/tauri-todomvc-sync-cf)