@livestore/react 0.4.0-dev.21 → 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 (125) hide show
  1. package/README.md +1 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/StoreRegistryContext.d.ts +56 -0
  4. package/dist/StoreRegistryContext.d.ts.map +1 -0
  5. package/dist/StoreRegistryContext.js +61 -0
  6. package/dist/StoreRegistryContext.js.map +1 -0
  7. package/dist/__tests__/fixture.d.ts +8 -280
  8. package/dist/__tests__/fixture.d.ts.map +1 -1
  9. package/dist/__tests__/fixture.js +9 -84
  10. package/dist/__tests__/fixture.js.map +1 -1
  11. package/dist/experimental/components/LiveList.d.ts +4 -2
  12. package/dist/experimental/components/LiveList.d.ts.map +1 -1
  13. package/dist/experimental/components/LiveList.js +9 -7
  14. package/dist/experimental/components/LiveList.js.map +1 -1
  15. package/dist/experimental/mod.d.ts +0 -1
  16. package/dist/experimental/mod.d.ts.map +1 -1
  17. package/dist/experimental/mod.js +0 -1
  18. package/dist/experimental/mod.js.map +1 -1
  19. package/dist/mod.d.ts +8 -5
  20. package/dist/mod.d.ts.map +1 -1
  21. package/dist/mod.js +6 -4
  22. package/dist/mod.js.map +1 -1
  23. package/dist/useClientDocument.d.ts +1 -26
  24. package/dist/useClientDocument.d.ts.map +1 -1
  25. package/dist/useClientDocument.js +3 -17
  26. package/dist/useClientDocument.js.map +1 -1
  27. package/dist/useClientDocument.test.js +12 -4
  28. package/dist/useClientDocument.test.js.map +1 -1
  29. package/dist/useQuery.d.ts +4 -5
  30. package/dist/useQuery.d.ts.map +1 -1
  31. package/dist/useQuery.js +12 -85
  32. package/dist/useQuery.js.map +1 -1
  33. package/dist/useQuery.test.js +7 -8
  34. package/dist/useQuery.test.js.map +1 -1
  35. package/dist/useRcResource.d.ts.map +1 -1
  36. package/dist/useRcResource.js +9 -5
  37. package/dist/useRcResource.js.map +1 -1
  38. package/dist/useRcResource.test.js +1 -1
  39. package/dist/useRcResource.test.js.map +1 -1
  40. package/dist/useStore.d.ts +61 -46
  41. package/dist/useStore.d.ts.map +1 -1
  42. package/dist/useStore.js +75 -60
  43. package/dist/useStore.js.map +1 -1
  44. package/dist/useStore.test.d.ts.map +1 -0
  45. package/dist/{experimental/multi-store/useStore.test.js → useStore.test.js} +70 -27
  46. package/dist/useStore.test.js.map +1 -0
  47. package/dist/useSyncStatus.d.ts +22 -0
  48. package/dist/useSyncStatus.d.ts.map +1 -0
  49. package/dist/useSyncStatus.js +28 -0
  50. package/dist/useSyncStatus.js.map +1 -0
  51. package/package.json +69 -26
  52. package/src/StoreRegistryContext.tsx +70 -0
  53. package/src/__snapshots__/useClientDocument.test.tsx.snap +112 -78
  54. package/src/__tests__/fixture.tsx +23 -118
  55. package/src/experimental/components/LiveList.tsx +22 -9
  56. package/src/experimental/mod.ts +0 -1
  57. package/src/mod.ts +8 -12
  58. package/src/useClientDocument.test.tsx +16 -6
  59. package/src/useClientDocument.ts +7 -61
  60. package/src/useQuery.test.tsx +8 -8
  61. package/src/useQuery.ts +30 -119
  62. package/src/useRcResource.test.tsx +1 -1
  63. package/src/useRcResource.ts +10 -5
  64. package/src/{experimental/multi-store/useStore.test.tsx → useStore.test.tsx} +117 -39
  65. package/src/useStore.ts +106 -65
  66. package/src/useSyncStatus.ts +34 -0
  67. package/dist/LiveStoreContext.d.ts +0 -40
  68. package/dist/LiveStoreContext.d.ts.map +0 -1
  69. package/dist/LiveStoreContext.js +0 -21
  70. package/dist/LiveStoreContext.js.map +0 -1
  71. package/dist/LiveStoreProvider.d.ts +0 -73
  72. package/dist/LiveStoreProvider.d.ts.map +0 -1
  73. package/dist/LiveStoreProvider.js +0 -233
  74. package/dist/LiveStoreProvider.js.map +0 -1
  75. package/dist/LiveStoreProvider.test.d.ts +0 -2
  76. package/dist/LiveStoreProvider.test.d.ts.map +0 -1
  77. package/dist/LiveStoreProvider.test.js +0 -117
  78. package/dist/LiveStoreProvider.test.js.map +0 -1
  79. package/dist/experimental/multi-store/StoreRegistry.d.ts +0 -105
  80. package/dist/experimental/multi-store/StoreRegistry.d.ts.map +0 -1
  81. package/dist/experimental/multi-store/StoreRegistry.js +0 -184
  82. package/dist/experimental/multi-store/StoreRegistry.js.map +0 -1
  83. package/dist/experimental/multi-store/StoreRegistry.test.d.ts +0 -2
  84. package/dist/experimental/multi-store/StoreRegistry.test.d.ts.map +0 -1
  85. package/dist/experimental/multi-store/StoreRegistry.test.js +0 -381
  86. package/dist/experimental/multi-store/StoreRegistry.test.js.map +0 -1
  87. package/dist/experimental/multi-store/StoreRegistryContext.d.ts +0 -10
  88. package/dist/experimental/multi-store/StoreRegistryContext.d.ts.map +0 -1
  89. package/dist/experimental/multi-store/StoreRegistryContext.js +0 -15
  90. package/dist/experimental/multi-store/StoreRegistryContext.js.map +0 -1
  91. package/dist/experimental/multi-store/mod.d.ts +0 -6
  92. package/dist/experimental/multi-store/mod.d.ts.map +0 -1
  93. package/dist/experimental/multi-store/mod.js +0 -6
  94. package/dist/experimental/multi-store/mod.js.map +0 -1
  95. package/dist/experimental/multi-store/storeOptions.d.ts +0 -4
  96. package/dist/experimental/multi-store/storeOptions.d.ts.map +0 -1
  97. package/dist/experimental/multi-store/storeOptions.js +0 -4
  98. package/dist/experimental/multi-store/storeOptions.js.map +0 -1
  99. package/dist/experimental/multi-store/types.d.ts +0 -25
  100. package/dist/experimental/multi-store/types.d.ts.map +0 -1
  101. package/dist/experimental/multi-store/types.js +0 -2
  102. package/dist/experimental/multi-store/types.js.map +0 -1
  103. package/dist/experimental/multi-store/useStore.d.ts +0 -11
  104. package/dist/experimental/multi-store/useStore.d.ts.map +0 -1
  105. package/dist/experimental/multi-store/useStore.js +0 -16
  106. package/dist/experimental/multi-store/useStore.js.map +0 -1
  107. package/dist/experimental/multi-store/useStore.test.d.ts.map +0 -1
  108. package/dist/experimental/multi-store/useStore.test.js.map +0 -1
  109. package/dist/utils/stack-info.d.ts +0 -4
  110. package/dist/utils/stack-info.d.ts.map +0 -1
  111. package/dist/utils/stack-info.js +0 -10
  112. package/dist/utils/stack-info.js.map +0 -1
  113. package/src/LiveStoreContext.ts +0 -41
  114. package/src/LiveStoreProvider.test.tsx +0 -248
  115. package/src/LiveStoreProvider.tsx +0 -430
  116. package/src/ambient.d.ts +0 -1
  117. package/src/experimental/multi-store/StoreRegistry.test.ts +0 -518
  118. package/src/experimental/multi-store/StoreRegistry.ts +0 -253
  119. package/src/experimental/multi-store/StoreRegistryContext.tsx +0 -23
  120. package/src/experimental/multi-store/mod.ts +0 -5
  121. package/src/experimental/multi-store/storeOptions.ts +0 -8
  122. package/src/experimental/multi-store/types.ts +0 -37
  123. package/src/experimental/multi-store/useStore.ts +0 -26
  124. package/src/utils/stack-info.ts +0 -13
  125. /package/dist/{experimental/multi-store/useStore.test.d.ts → useStore.test.d.ts} +0 -0
@@ -0,0 +1,56 @@
1
+ import * as React from 'react';
2
+ import type { StoreRegistry } from '@livestore/livestore';
3
+ export declare const StoreRegistryContext: React.Context<StoreRegistry | undefined>;
4
+ export type StoreRegistryProviderProps = {
5
+ storeRegistry: StoreRegistry;
6
+ children: React.ReactNode;
7
+ };
8
+ /**
9
+ * React context provider that makes a {@link StoreRegistry} available to descendant components.
10
+ *
11
+ * Wrap your application (or a subtree) with this provider to enable {@link useStore} and
12
+ * {@link useStoreRegistry} hooks within that tree.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { StoreRegistry } from '@livestore/livestore'
17
+ * import { StoreRegistryProvider } from '@livestore/react'
18
+ * import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
19
+ *
20
+ * const storeRegistry = new StoreRegistry({
21
+ * defaultOptions: { batchUpdates }
22
+ * })
23
+ *
24
+ * function App() {
25
+ * return (
26
+ * <StoreRegistryProvider storeRegistry={storeRegistry}>
27
+ * <MyComponent />
28
+ * </StoreRegistryProvider>
29
+ * )
30
+ * }
31
+ * ```
32
+ */
33
+ export declare const StoreRegistryProvider: ({ storeRegistry, children }: StoreRegistryProviderProps) => React.JSX.Element;
34
+ /**
35
+ * Hook to access the {@link StoreRegistry} from context. Useful for advanced operations like preloading.
36
+ *
37
+ * @param override - Optional registry to use instead of the context value.
38
+ * When provided, skips context lookup entirely.
39
+ * @returns The registry provided by the nearest {@link StoreRegistryProvider} ancestor, or the `override` if provided.
40
+ * @throws Error if called outside a {@link StoreRegistryProvider} and no override is provided
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * function PreloadButton({ issueId }: { issueId: string }) {
45
+ * const storeRegistry = useStoreRegistry()
46
+ *
47
+ * const handleMouseEnter = () => {
48
+ * storeRegistry.preload(issueStoreOptions(issueId))
49
+ * }
50
+ *
51
+ * return <button onMouseEnter={handleMouseEnter}>View Issue</button>
52
+ * }
53
+ * ```
54
+ */
55
+ export declare const useStoreRegistry: (override?: StoreRegistry) => StoreRegistry;
56
+ //# sourceMappingURL=StoreRegistryContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoreRegistryContext.d.ts","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,eAAO,MAAM,oBAAoB,0CAA4D,CAAA;AAE7F,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,qBAAqB,GAAI,6BAA6B,0BAA0B,KAAG,KAAK,CAAC,GAAG,CAAC,OAEzG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,aAAa,kBAQxD,CAAA"}
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ export const StoreRegistryContext = React.createContext(undefined);
4
+ /**
5
+ * React context provider that makes a {@link StoreRegistry} available to descendant components.
6
+ *
7
+ * Wrap your application (or a subtree) with this provider to enable {@link useStore} and
8
+ * {@link useStoreRegistry} hooks within that tree.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import { StoreRegistry } from '@livestore/livestore'
13
+ * import { StoreRegistryProvider } from '@livestore/react'
14
+ * import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
15
+ *
16
+ * const storeRegistry = new StoreRegistry({
17
+ * defaultOptions: { batchUpdates }
18
+ * })
19
+ *
20
+ * function App() {
21
+ * return (
22
+ * <StoreRegistryProvider storeRegistry={storeRegistry}>
23
+ * <MyComponent />
24
+ * </StoreRegistryProvider>
25
+ * )
26
+ * }
27
+ * ```
28
+ */
29
+ export const StoreRegistryProvider = ({ storeRegistry, children }) => {
30
+ return _jsx(StoreRegistryContext, { value: storeRegistry, children: children });
31
+ };
32
+ /**
33
+ * Hook to access the {@link StoreRegistry} from context. Useful for advanced operations like preloading.
34
+ *
35
+ * @param override - Optional registry to use instead of the context value.
36
+ * When provided, skips context lookup entirely.
37
+ * @returns The registry provided by the nearest {@link StoreRegistryProvider} ancestor, or the `override` if provided.
38
+ * @throws Error if called outside a {@link StoreRegistryProvider} and no override is provided
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * function PreloadButton({ issueId }: { issueId: string }) {
43
+ * const storeRegistry = useStoreRegistry()
44
+ *
45
+ * const handleMouseEnter = () => {
46
+ * storeRegistry.preload(issueStoreOptions(issueId))
47
+ * }
48
+ *
49
+ * return <button onMouseEnter={handleMouseEnter}>View Issue</button>
50
+ * }
51
+ * ```
52
+ */
53
+ export const useStoreRegistry = (override) => {
54
+ if (override !== undefined)
55
+ return override;
56
+ const storeRegistry = React.use(StoreRegistryContext);
57
+ if (storeRegistry == null)
58
+ throw new Error('useStoreRegistry() must be used within <StoreRegistryProvider>');
59
+ return storeRegistry;
60
+ };
61
+ //# sourceMappingURL=StoreRegistryContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoreRegistryContext.js","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAA4B,SAAS,CAAC,CAAA;AAO7F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,aAAa,EAAE,QAAQ,EAA8B,EAAqB,EAAE;IAClH,OAAO,KAAC,oBAAoB,IAAC,KAAK,EAAE,aAAa,YAAG,QAAQ,GAAwB,CAAA;AACtF,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAwB,EAAE,EAAE;IAC3D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAA;IAE3C,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAErD,IAAI,aAAa,IAAI,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;IAE5G,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
@@ -1,289 +1,17 @@
1
- import { type UnknownError } from '@livestore/common';
2
- import { State } from '@livestore/common/schema';
3
- import type { LiveStoreSchema, SqliteDsl, Store } from '@livestore/livestore';
4
- import { Effect, Schema, type Scope } from '@livestore/utils/effect';
5
- import type * as otel from '@opentelemetry/api';
1
+ import type { UnknownError } from '@livestore/common';
2
+ import { type AppState, type CreateTodoMvcStoreOptions, events, type Filter, schema, type Todo, tables } from '@livestore/framework-toolkit/testing';
3
+ import type { Store } from '@livestore/livestore';
4
+ import { Effect, type Scope } from '@livestore/utils/effect';
6
5
  import React from 'react';
7
6
  import * as LiveStoreReact from '../mod.ts';
8
- export type Todo = {
9
- id: string;
10
- text: string;
11
- completed: boolean;
12
- };
13
- export type Filter = 'all' | 'active' | 'completed';
14
- export type AppState = {
15
- newTodoText: string;
16
- filter: Filter;
17
- };
18
- export declare const events: {
19
- todoCreated: State.SQLite.EventDef<"todoCreated", {
20
- readonly id: string;
21
- readonly text: string;
22
- readonly completed: boolean;
23
- }, {
24
- readonly id: string;
25
- readonly text: string;
26
- readonly completed: boolean;
27
- }>;
28
- todoUpdated: State.SQLite.EventDef<"todoUpdated", {
29
- readonly id: string;
30
- readonly text?: string | undefined;
31
- readonly completed?: boolean | undefined;
32
- }, {
33
- readonly id: string;
34
- readonly text?: string | undefined;
35
- readonly completed?: boolean | undefined;
36
- }>;
37
- AppRouterSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"AppRouter", {
38
- readonly currentTaskId: string | null;
39
- }, {
40
- partialSet: true;
41
- default: {
42
- id: "singleton";
43
- value: {
44
- readonly currentTaskId: null;
45
- };
46
- };
47
- }>;
48
- UserInfoSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"UserInfo", {
49
- readonly text: string;
50
- readonly username: string;
51
- }, {
52
- partialSet: true;
53
- default: {
54
- id: undefined;
55
- value: {
56
- readonly username: "";
57
- readonly text: "";
58
- };
59
- };
60
- }>;
61
- KvSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"Kv", any, {
62
- partialSet: false;
63
- default: {
64
- id: undefined;
65
- value: null;
66
- };
67
- }>;
68
- };
69
- export declare const tables: {
70
- todos: State.SQLite.TableDef<State.SQLite.SqliteTableDefForInput<"todos", {
71
- readonly id: {
72
- columnType: "text";
73
- schema: Schema.Schema<string, string, never>;
74
- default: import("effect/Option").None<never>;
75
- nullable: false;
76
- primaryKey: true;
77
- autoIncrement: false;
78
- };
79
- readonly text: {
80
- columnType: "text";
81
- schema: Schema.Schema<string, string, never>;
82
- default: import("effect/Option").Some<"">;
83
- nullable: false;
84
- primaryKey: false;
85
- autoIncrement: false;
86
- };
87
- readonly completed: {
88
- columnType: "integer";
89
- schema: Schema.Schema<boolean, number, never>;
90
- default: import("effect/Option").Some<false>;
91
- nullable: false;
92
- primaryKey: false;
93
- autoIncrement: false;
94
- };
95
- }>, State.SQLite.WithDefaults<{
96
- readonly id: {
97
- columnType: "text";
98
- schema: Schema.Schema<string, string, never>;
99
- default: import("effect/Option").None<never>;
100
- nullable: false;
101
- primaryKey: true;
102
- autoIncrement: false;
103
- };
104
- readonly text: {
105
- columnType: "text";
106
- schema: Schema.Schema<string, string, never>;
107
- default: import("effect/Option").Some<"">;
108
- nullable: false;
109
- primaryKey: false;
110
- autoIncrement: false;
111
- };
112
- readonly completed: {
113
- columnType: "integer";
114
- schema: Schema.Schema<boolean, number, never>;
115
- default: import("effect/Option").Some<false>;
116
- nullable: false;
117
- primaryKey: false;
118
- autoIncrement: false;
119
- };
120
- }>, Schema.Schema<{
121
- readonly id: string;
122
- readonly text: string;
123
- readonly completed: boolean;
124
- }, {
125
- readonly id: string;
126
- readonly text: string;
127
- readonly completed: number;
128
- }, never>>;
129
- app: State.SQLite.TableDef<State.SQLite.SqliteTableDefForInput<"app", {
130
- readonly id: {
131
- columnType: "text";
132
- schema: Schema.Schema<string, string, never>;
133
- default: import("effect/Option").Some<"static">;
134
- nullable: false;
135
- primaryKey: true;
136
- autoIncrement: false;
137
- };
138
- readonly newTodoText: {
139
- columnType: "text";
140
- schema: Schema.Schema<string | null, string | null, never>;
141
- default: import("effect/Option").Some<"">;
142
- nullable: true;
143
- primaryKey: false;
144
- autoIncrement: false;
145
- };
146
- readonly filter: {
147
- columnType: "text";
148
- schema: Schema.Schema<string, string, never>;
149
- default: import("effect/Option").Some<"all">;
150
- nullable: false;
151
- primaryKey: false;
152
- autoIncrement: false;
153
- };
154
- }>, State.SQLite.WithDefaults<{
155
- readonly id: {
156
- columnType: "text";
157
- schema: Schema.Schema<string, string, never>;
158
- default: import("effect/Option").Some<"static">;
159
- nullable: false;
160
- primaryKey: true;
161
- autoIncrement: false;
162
- };
163
- readonly newTodoText: {
164
- columnType: "text";
165
- schema: Schema.Schema<string | null, string | null, never>;
166
- default: import("effect/Option").Some<"">;
167
- nullable: true;
168
- primaryKey: false;
169
- autoIncrement: false;
170
- };
171
- readonly filter: {
172
- columnType: "text";
173
- schema: Schema.Schema<string, string, never>;
174
- default: import("effect/Option").Some<"all">;
175
- nullable: false;
176
- primaryKey: false;
177
- autoIncrement: false;
178
- };
179
- }>, Schema.Schema<{
180
- readonly id: string;
181
- readonly newTodoText: string | null;
182
- readonly filter: string;
183
- }, {
184
- readonly id: string;
185
- readonly newTodoText: string | null;
186
- readonly filter: string;
187
- }, never>>;
188
- userInfo: State.SQLite.ClientDocumentTableDef<"UserInfo", {
189
- readonly text: string;
190
- readonly username: string;
191
- }, {
192
- readonly text: string;
193
- readonly username: string;
194
- }, {
195
- partialSet: true;
196
- default: {
197
- id: undefined;
198
- value: {
199
- readonly username: "";
200
- readonly text: "";
201
- };
202
- };
203
- }>;
204
- AppRouterSchema: State.SQLite.ClientDocumentTableDef<"AppRouter", {
205
- readonly currentTaskId: string | null;
206
- }, {
207
- readonly currentTaskId: string | null;
208
- }, {
209
- partialSet: true;
210
- default: {
211
- id: "singleton";
212
- value: {
213
- readonly currentTaskId: null;
214
- };
215
- };
216
- }>;
217
- kv: State.SQLite.ClientDocumentTableDef<"Kv", any, any, {
218
- partialSet: false;
219
- default: {
220
- id: undefined;
221
- value: null;
222
- };
223
- }>;
224
- };
225
- export declare const schema: import("@livestore/livestore").FromInputSchema.DeriveSchema<{
226
- state: import("@livestore/livestore").InternalState;
227
- events: {
228
- todoCreated: State.SQLite.EventDef<"todoCreated", {
229
- readonly id: string;
230
- readonly text: string;
231
- readonly completed: boolean;
232
- }, {
233
- readonly id: string;
234
- readonly text: string;
235
- readonly completed: boolean;
236
- }>;
237
- todoUpdated: State.SQLite.EventDef<"todoUpdated", {
238
- readonly id: string;
239
- readonly text?: string | undefined;
240
- readonly completed?: boolean | undefined;
241
- }, {
242
- readonly id: string;
243
- readonly text?: string | undefined;
244
- readonly completed?: boolean | undefined;
245
- }>;
246
- AppRouterSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"AppRouter", {
247
- readonly currentTaskId: string | null;
248
- }, {
249
- partialSet: true;
250
- default: {
251
- id: "singleton";
252
- value: {
253
- readonly currentTaskId: null;
254
- };
255
- };
256
- }>;
257
- UserInfoSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"UserInfo", {
258
- readonly text: string;
259
- readonly username: string;
260
- }, {
261
- partialSet: true;
262
- default: {
263
- id: undefined;
264
- value: {
265
- readonly username: "";
266
- readonly text: "";
267
- };
268
- };
269
- }>;
270
- KvSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"Kv", any, {
271
- partialSet: false;
272
- default: {
273
- id: undefined;
274
- value: null;
275
- };
276
- }>;
277
- };
278
- }>;
279
- export type MakeTodoMvcReactOptions = {
280
- otelTracer?: otel.Tracer | undefined;
281
- otelContext?: otel.Context | undefined;
7
+ export { events, schema, tables };
8
+ export type { AppState, Filter, Todo };
9
+ export type MakeTodoMvcReactOptions = CreateTodoMvcStoreOptions & {
282
10
  strictMode?: boolean | undefined;
283
11
  };
284
12
  export declare const makeTodoMvcReact: (opts?: MakeTodoMvcReactOptions) => Effect.Effect<{
285
13
  wrapper: ({ children }: any) => React.JSX.Element;
286
- store: Store<LiveStoreSchema<SqliteDsl.DbSchema, State.SQLite.EventDefRecord>, {}> & LiveStoreReact.ReactApi;
14
+ store: Store<typeof schema> & LiveStoreReact.ReactApi;
287
15
  renderCount: {
288
16
  readonly val: number;
289
17
  inc: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAsB,KAAK,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,SA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,CAAC,EAAE,uBAAuB,KAAK,MAAM,CAAC,MAAM,CAC9E;IACE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;IACjD,KAAK,EAAE,KAAK,CAAC,OAAO,MAAM,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAA;IACrD,WAAW,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CACvD,EACD,YAAY,EACZ,KAAK,CAAC,KAAK,CA8BT,CAAA"}
@@ -1,81 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { makeInMemoryAdapter } from '@livestore/adapter-web';
3
- import { provideOtel } from '@livestore/common';
4
- import { Events, makeSchema, State } from '@livestore/common/schema';
5
- import { createStore } from '@livestore/livestore';
6
- import { omitUndefineds } from '@livestore/utils';
7
- import { Effect, Schema } from '@livestore/utils/effect';
2
+ import { createTodoMvcStore, events, schema, tables, } from '@livestore/framework-toolkit/testing';
3
+ import { Effect } from '@livestore/utils/effect';
8
4
  import React from 'react';
9
5
  import * as LiveStoreReact from "../mod.js";
10
- const todos = State.SQLite.table({
11
- name: 'todos',
12
- columns: {
13
- id: State.SQLite.text({ primaryKey: true }),
14
- text: State.SQLite.text({ default: '', nullable: false }),
15
- completed: State.SQLite.boolean({ default: false, nullable: false }),
16
- },
17
- });
18
- const app = State.SQLite.table({
19
- name: 'app',
20
- columns: {
21
- id: State.SQLite.text({ primaryKey: true, default: 'static' }),
22
- newTodoText: State.SQLite.text({ default: '', nullable: true }),
23
- filter: State.SQLite.text({ default: 'all', nullable: false }),
24
- },
25
- });
26
- const userInfo = State.SQLite.clientDocument({
27
- name: 'UserInfo',
28
- schema: Schema.Struct({
29
- username: Schema.String,
30
- text: Schema.String,
31
- }),
32
- default: { value: { username: '', text: '' } },
33
- });
34
- const AppRouterSchema = State.SQLite.clientDocument({
35
- name: 'AppRouter',
36
- schema: Schema.Struct({
37
- currentTaskId: Schema.String.pipe(Schema.NullOr),
38
- }),
39
- default: {
40
- value: { currentTaskId: null },
41
- id: 'singleton',
42
- },
43
- });
44
- const kv = State.SQLite.clientDocument({
45
- name: 'Kv',
46
- schema: Schema.Any,
47
- default: { value: null },
48
- });
49
- export const events = {
50
- todoCreated: Events.synced({
51
- name: 'todoCreated',
52
- schema: Schema.Struct({ id: Schema.String, text: Schema.String, completed: Schema.Boolean }),
53
- }),
54
- todoUpdated: Events.synced({
55
- name: 'todoUpdated',
56
- schema: Schema.Struct({
57
- id: Schema.String,
58
- text: Schema.String.pipe(Schema.optional),
59
- completed: Schema.Boolean.pipe(Schema.optional),
60
- }),
61
- }),
62
- AppRouterSet: AppRouterSchema.set,
63
- UserInfoSet: userInfo.set,
64
- KvSet: kv.set,
65
- };
66
- const materializers = State.SQLite.materializers(events, {
67
- todoCreated: ({ id, text, completed }) => todos.insert({ id, text, completed }),
68
- todoUpdated: ({ id, text, completed }) => todos.update({ ...omitUndefineds({ completed, text }) }).where({ id }),
69
- });
70
- export const tables = { todos, app, userInfo, AppRouterSchema, kv };
71
- const state = State.SQLite.makeState({ tables, materializers });
72
- export const schema = makeSchema({ state, events });
6
+ // Re-export shared types and schema
7
+ export { events, schema, tables };
73
8
  export const makeTodoMvcReact = (opts = {}) => Effect.gen(function* () {
74
9
  const { strictMode } = opts;
75
10
  const makeRenderCount = () => {
76
11
  let val = 0;
77
12
  const inc = () => {
78
- val += strictMode ? 0.5 : 1;
13
+ val += strictMode === true ? 0.5 : 1;
79
14
  };
80
15
  return {
81
16
  get val() {
@@ -84,21 +19,11 @@ export const makeTodoMvcReact = (opts = {}) => Effect.gen(function* () {
84
19
  inc,
85
20
  };
86
21
  };
87
- const store = yield* createStore({
88
- schema,
89
- storeId: 'default',
90
- adapter: makeInMemoryAdapter(),
91
- debug: { instanceId: 'test' },
92
- });
22
+ const store = yield* createTodoMvcStore(opts);
93
23
  const storeWithReactApi = LiveStoreReact.withReactApi(store);
94
- // TODO improve typing of `LiveStoreContext`
95
- const storeContext = {
96
- stage: 'running',
97
- store: storeWithReactApi,
98
- };
99
- const MaybeStrictMode = strictMode ? React.StrictMode : React.Fragment;
100
- const wrapper = ({ children }) => (_jsx(MaybeStrictMode, { children: _jsx(LiveStoreReact.LiveStoreContext.Provider, { value: storeContext, children: children }) }));
24
+ const MaybeStrictMode = strictMode === true ? React.StrictMode : React.Fragment;
25
+ const wrapper = ({ children }) => _jsx(MaybeStrictMode, { children: children });
101
26
  const renderCount = makeRenderCount();
102
27
  return { wrapper, store: storeWithReactApi, renderCount };
103
- }).pipe(provideOtel(omitUndefineds({ parentSpanContext: opts.otelContext, otelTracer: opts.otelTracer })));
28
+ });
104
29
  //# sourceMappingURL=fixture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAc,MAAM,yBAAyB,CAAA;AAEpE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,cAAc,MAAM,WAAW,CAAA;AAe3C,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;IAC/B,IAAI,EAAE,OAAO;IACb,OAAO,EAAE;QACP,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC3C,IAAI,EAAE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CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;IAC3B,MAAM,eAAe,GAAG,GAAG,EAAE;QAC3B,IAAI,GAAG,GAAG,CAAC,CAAA;QAEX,MAAM,GAAG,GAAG,GAAG,EAAE;YACf,GAAG,IAAI,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,CAAC,CAAA;QAED,OAAO;YACL,IAAI,GAAG;gBACL,OAAO,GAAG,CAAA;YACZ,CAAC;YACD,GAAG;SACJ,CAAA;IACH,CAAC,CAAA;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;IAE7C,MAAM,iBAAiB,GAAG,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAE5D,MAAM,eAAe,GAAG,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAA;IAE/E,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAO,EAAE,EAAE,CAAC,KAAC,eAAe,cAAE,QAAQ,GAAmB,CAAA;IAEpF,MAAM,WAAW,GAAG,eAAe,EAAE,CAAA;IAErC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAA;AAC3D,CAAC,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import type { LiveQueryDef } from '@livestore/livestore';
1
+ import type { LiveQueryDef, Store } from '@livestore/livestore';
2
2
  import React from 'react';
3
3
  export type LiveListProps<TItem> = {
4
4
  items$: LiveQueryDef<ReadonlyArray<TItem>>;
@@ -8,6 +8,8 @@ export type LiveListProps<TItem> = {
8
8
  }) => React.ReactNode;
9
9
  /** Needs to be unique across all list items */
10
10
  getKey: (item: TItem, index: number) => string | number;
11
+ /** The store instance to use for queries */
12
+ store: Store<any, any>;
11
13
  };
12
14
  /**
13
15
  * This component is a helper component for rendering a list of items for a LiveQuery of an array of items.
@@ -17,5 +19,5 @@ export type LiveListProps<TItem> = {
17
19
  * In the future we want to make this component even more efficient by using incremental rendering (https://github.com/livestorejs/livestore/pull/55)
18
20
  * e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
19
21
  */
20
- export declare const LiveList: <TItem>({ items$, renderItem, getKey }: LiveListProps<TItem>) => React.ReactNode;
22
+ export declare const LiveList: <TItem>({ items$, renderItem, getKey, store }: LiveListProps<TItem>) => React.ReactNode;
21
23
  //# sourceMappingURL=LiveList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAE1C,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAA;IACnG,+CAA+C;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;CACxD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,EAAG,gCAAgC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,SAkC7F,CAAA"}
1
+ {"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAE1C,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAA;IACnG,+CAA+C;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACvD,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,EAAG,uCAAuC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,SAuCpG,CAAA"}
@@ -10,10 +10,10 @@ import { useQuery } from "../../useQuery.js";
10
10
  * In the future we want to make this component even more efficient by using incremental rendering (https://github.com/livestorejs/livestore/pull/55)
11
11
  * e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
12
12
  */
13
- export const LiveList = ({ items$, renderItem, getKey }) => {
13
+ export const LiveList = ({ items$, renderItem, getKey, store }) => {
14
14
  const [hasMounted, setHasMounted] = React.useState(false);
15
15
  React.useEffect(() => setHasMounted(true), []);
16
- const keys = useQuery(computed((get) => get(items$).map(getKey)));
16
+ const keys = useQuery(computed((get) => get(items$).map(getKey)), { store });
17
17
  const arr = React.useMemo(() => keys.map((key) =>
18
18
  // TODO figure out a way so that `item$` returns an ordered lookup map to more efficiently find the item by key
19
19
  [
@@ -22,14 +22,16 @@ export const LiveList = ({ items$, renderItem, getKey }) => {
22
22
  deps: [key],
23
23
  }),
24
24
  ]), [getKey, items$, keys]);
25
- return (_jsx(_Fragment, { children: arr.map(([key, item$], index) => (_jsx(ItemWrapperMemo, { itemKey: key, "item$": item$, opts: { isInitialListRender: !hasMounted, index }, renderItem: renderItem }, key))) }));
25
+ return (_jsx(_Fragment, { children: arr.map(([key, item$], index) => (_jsx(ItemWrapperMemo, { itemKey: key, "item$": item$, store: store, index: index, isInitialListRender: !hasMounted, renderItem: renderItem }, key))) }));
26
26
  };
27
- const ItemWrapper = ({ item$, opts, renderItem, }) => {
28
- const item = useQuery(item$);
27
+ const ItemWrapper = ({ item$, index, isInitialListRender, renderItem, store, }) => {
28
+ const item = useQuery(item$, { store });
29
+ const opts = React.useMemo(() => ({ index, isInitialListRender }), [index, isInitialListRender]);
29
30
  return _jsx(_Fragment, { children: renderItem(item, opts) });
30
31
  };
31
32
  const ItemWrapperMemo = React.memo(ItemWrapper, (prev, next) => prev.itemKey === next.itemKey &&
32
33
  prev.renderItem === next.renderItem &&
33
- prev.opts.index === next.opts.index &&
34
- prev.opts.isInitialListRender === next.opts.isInitialListRender);
34
+ prev.store === next.store &&
35
+ prev.index === next.index &&
36
+ prev.isInitialListRender === next.isInitialListRender);
35
37
  //# sourceMappingURL=LiveList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LiveList.js","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAgB5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAwB,EAAmB,EAAE;IACxG,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEzD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,aAAa,CA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KAAK;IACzB,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK;IACzB,IAAI,CAAC,mBAAmB,KAAK,IAAI,CAAC,mBAAmB,CAClC,CAAA"}
@@ -1,3 +1,2 @@
1
1
  export { LiveList, type LiveListProps } from './components/LiveList.tsx';
2
- export * from './multi-store/mod.ts';
3
2
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACxE,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA"}
@@ -1,3 +1,2 @@
1
1
  export { LiveList } from "./components/LiveList.js";
2
- export * from "./multi-store/mod.js";
3
2
  //# sourceMappingURL=mod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA2B,CAAA;AACxE,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA2B,CAAA"}