@livestore/livestore 0.0.58-dev.9 → 0.1.0-dev.2

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 (191) hide show
  1. package/README.md +1 -117
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/effect/LiveStore.d.ts +6 -6
  4. package/dist/effect/LiveStore.d.ts.map +1 -1
  5. package/dist/effect/LiveStore.js +1 -1
  6. package/dist/effect/LiveStore.js.map +1 -1
  7. package/dist/global-state.d.ts.map +1 -1
  8. package/dist/global-state.js +2 -1
  9. package/dist/global-state.js.map +1 -1
  10. package/dist/index.d.ts +11 -8
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/reactiveQueries/base-class.d.ts +5 -4
  15. package/dist/reactiveQueries/base-class.d.ts.map +1 -1
  16. package/dist/reactiveQueries/base-class.js.map +1 -1
  17. package/dist/reactiveQueries/computed.d.ts +35 -0
  18. package/dist/reactiveQueries/computed.d.ts.map +1 -0
  19. package/dist/reactiveQueries/computed.js +57 -0
  20. package/dist/reactiveQueries/computed.js.map +1 -0
  21. package/dist/reactiveQueries/graphql.d.ts +2 -1
  22. package/dist/reactiveQueries/graphql.d.ts.map +1 -1
  23. package/dist/reactiveQueries/graphql.js.map +1 -1
  24. package/dist/reactiveQueries/sql.d.ts +2 -2
  25. package/dist/reactiveQueries/sql.d.ts.map +1 -1
  26. package/dist/reactiveQueries/sql.js +3 -3
  27. package/dist/reactiveQueries/sql.js.map +1 -1
  28. package/dist/reactiveQueries/sql.test.js +2 -2
  29. package/dist/reactiveQueries/sql.test.js.map +1 -1
  30. package/dist/row-query.d.ts +3 -2
  31. package/dist/row-query.d.ts.map +1 -1
  32. package/dist/row-query.js +14 -10
  33. package/dist/row-query.js.map +1 -1
  34. package/dist/store/create-store.d.ts +28 -0
  35. package/dist/store/create-store.d.ts.map +1 -0
  36. package/dist/store/create-store.js +85 -0
  37. package/dist/store/create-store.js.map +1 -0
  38. package/dist/store/devtools.d.ts +19 -0
  39. package/dist/store/devtools.d.ts.map +1 -0
  40. package/dist/store/devtools.js +141 -0
  41. package/dist/store/devtools.js.map +1 -0
  42. package/dist/store/store-context.d.ts +26 -0
  43. package/dist/store/store-context.d.ts.map +1 -0
  44. package/dist/store/store-context.js +6 -0
  45. package/dist/store/store-context.js.map +1 -0
  46. package/dist/store/store-types.d.ts +98 -0
  47. package/dist/store/store-types.d.ts.map +1 -0
  48. package/dist/store/store-types.js +6 -0
  49. package/dist/store/store-types.js.map +1 -0
  50. package/dist/store/store.d.ts +88 -0
  51. package/dist/store/store.d.ts.map +1 -0
  52. package/dist/store/store.js +367 -0
  53. package/dist/store/store.js.map +1 -0
  54. package/dist/store-devtools.d.ts +2 -2
  55. package/dist/store-devtools.d.ts.map +1 -1
  56. package/dist/store-devtools.js +2 -2
  57. package/dist/store-devtools.js.map +1 -1
  58. package/dist/store.d.ts +8 -8
  59. package/dist/store.d.ts.map +1 -1
  60. package/dist/store.js +54 -54
  61. package/dist/store.js.map +1 -1
  62. package/dist/utils/dev.d.ts +1 -0
  63. package/dist/utils/dev.d.ts.map +1 -1
  64. package/dist/utils/dev.js +5 -0
  65. package/dist/utils/dev.js.map +1 -1
  66. package/dist/{react/utils → utils}/stack-info.d.ts +1 -2
  67. package/dist/utils/stack-info.d.ts.map +1 -0
  68. package/dist/{react/utils → utils}/stack-info.js +1 -9
  69. package/dist/utils/stack-info.js.map +1 -0
  70. package/dist/utils/stack-info.test.d.ts.map +1 -0
  71. package/dist/{__tests__/react/utils → utils}/stack-info.test.js +1 -1
  72. package/dist/utils/stack-info.test.js.map +1 -0
  73. package/dist/utils/tests/fixture.d.ts +259 -0
  74. package/dist/utils/tests/fixture.d.ts.map +1 -0
  75. package/dist/utils/tests/fixture.js +32 -0
  76. package/dist/utils/tests/fixture.js.map +1 -0
  77. package/dist/utils/tests/mod.d.ts +3 -0
  78. package/dist/utils/tests/mod.d.ts.map +1 -0
  79. package/dist/utils/tests/mod.js +3 -0
  80. package/dist/utils/tests/mod.js.map +1 -0
  81. package/dist/utils/tests/otel.d.ts.map +1 -0
  82. package/dist/{__tests__/react/utils → utils/tests}/otel.js +3 -3
  83. package/dist/utils/tests/otel.js.map +1 -0
  84. package/package.json +13 -20
  85. package/src/ambient.d.ts +3 -1
  86. package/src/effect/LiveStore.ts +7 -7
  87. package/src/global-state.ts +5 -1
  88. package/src/index.ts +19 -7
  89. package/src/reactiveQueries/base-class.ts +5 -4
  90. package/src/reactiveQueries/{js.ts → computed.ts} +3 -3
  91. package/src/reactiveQueries/graphql.ts +2 -1
  92. package/src/reactiveQueries/sql.test.ts +2 -2
  93. package/src/reactiveQueries/sql.ts +5 -5
  94. package/src/row-query.ts +33 -17
  95. package/src/store/create-store.ts +214 -0
  96. package/src/{store-devtools.ts → store/devtools.ts} +9 -9
  97. package/src/store/store-types.ts +110 -0
  98. package/src/{store.ts → store/store.ts} +56 -415
  99. package/src/utils/dev.ts +6 -0
  100. package/src/{__tests__/react/utils → utils}/stack-info.test.ts +1 -1
  101. package/src/{react/utils → utils}/stack-info.ts +2 -12
  102. package/src/utils/tests/fixture.ts +73 -0
  103. package/src/utils/tests/mod.ts +2 -0
  104. package/src/{__tests__/react/utils → utils/tests}/otel.ts +4 -4
  105. package/tsconfig.json +1 -2
  106. package/vitest.config.js +0 -8
  107. package/dist/__tests__/react/fixture.d.ts +0 -461
  108. package/dist/__tests__/react/fixture.d.ts.map +0 -1
  109. package/dist/__tests__/react/fixture.js +0 -68
  110. package/dist/__tests__/react/fixture.js.map +0 -1
  111. package/dist/__tests__/react/utils/otel.d.ts.map +0 -1
  112. package/dist/__tests__/react/utils/otel.js.map +0 -1
  113. package/dist/__tests__/react/utils/stack-info.test.d.ts.map +0 -1
  114. package/dist/__tests__/react/utils/stack-info.test.js.map +0 -1
  115. package/dist/react/LiveStoreContext.d.ts +0 -7
  116. package/dist/react/LiveStoreContext.d.ts.map +0 -1
  117. package/dist/react/LiveStoreContext.js +0 -13
  118. package/dist/react/LiveStoreContext.js.map +0 -1
  119. package/dist/react/LiveStoreProvider.d.ts +0 -49
  120. package/dist/react/LiveStoreProvider.d.ts.map +0 -1
  121. package/dist/react/LiveStoreProvider.js +0 -169
  122. package/dist/react/LiveStoreProvider.js.map +0 -1
  123. package/dist/react/LiveStoreProvider.test.d.ts +0 -2
  124. package/dist/react/LiveStoreProvider.test.d.ts.map +0 -1
  125. package/dist/react/LiveStoreProvider.test.js +0 -62
  126. package/dist/react/LiveStoreProvider.test.js.map +0 -1
  127. package/dist/react/components/LiveList.d.ts +0 -21
  128. package/dist/react/components/LiveList.d.ts.map +0 -1
  129. package/dist/react/components/LiveList.js +0 -31
  130. package/dist/react/components/LiveList.js.map +0 -1
  131. package/dist/react/index.d.ts +0 -11
  132. package/dist/react/index.d.ts.map +0 -1
  133. package/dist/react/index.js +0 -10
  134. package/dist/react/index.js.map +0 -1
  135. package/dist/react/useAtom.d.ts +0 -10
  136. package/dist/react/useAtom.d.ts.map +0 -1
  137. package/dist/react/useAtom.js +0 -37
  138. package/dist/react/useAtom.js.map +0 -1
  139. package/dist/react/useLocalId.d.ts +0 -10
  140. package/dist/react/useLocalId.d.ts.map +0 -1
  141. package/dist/react/useLocalId.js +0 -22
  142. package/dist/react/useLocalId.js.map +0 -1
  143. package/dist/react/useQuery.d.ts +0 -9
  144. package/dist/react/useQuery.d.ts.map +0 -1
  145. package/dist/react/useQuery.js +0 -70
  146. package/dist/react/useQuery.js.map +0 -1
  147. package/dist/react/useQuery.test.d.ts +0 -2
  148. package/dist/react/useQuery.test.d.ts.map +0 -1
  149. package/dist/react/useQuery.test.js +0 -51
  150. package/dist/react/useQuery.test.js.map +0 -1
  151. package/dist/react/useRow.d.ts +0 -46
  152. package/dist/react/useRow.d.ts.map +0 -1
  153. package/dist/react/useRow.js +0 -94
  154. package/dist/react/useRow.js.map +0 -1
  155. package/dist/react/useRow.test.d.ts +0 -2
  156. package/dist/react/useRow.test.d.ts.map +0 -1
  157. package/dist/react/useRow.test.js +0 -208
  158. package/dist/react/useRow.test.js.map +0 -1
  159. package/dist/react/useTemporaryQuery.d.ts +0 -22
  160. package/dist/react/useTemporaryQuery.d.ts.map +0 -1
  161. package/dist/react/useTemporaryQuery.js +0 -75
  162. package/dist/react/useTemporaryQuery.js.map +0 -1
  163. package/dist/react/useTemporaryQuery.test.d.ts +0 -2
  164. package/dist/react/useTemporaryQuery.test.d.ts.map +0 -1
  165. package/dist/react/useTemporaryQuery.test.js +0 -59
  166. package/dist/react/useTemporaryQuery.test.js.map +0 -1
  167. package/dist/react/utils/stack-info.d.ts.map +0 -1
  168. package/dist/react/utils/stack-info.js.map +0 -1
  169. package/dist/react/utils/useStateRefWithReactiveInput.d.ts +0 -13
  170. package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +0 -1
  171. package/dist/react/utils/useStateRefWithReactiveInput.js +0 -38
  172. package/dist/react/utils/useStateRefWithReactiveInput.js.map +0 -1
  173. package/src/__tests__/react/fixture.tsx +0 -126
  174. package/src/react/LiveStoreContext.ts +0 -20
  175. package/src/react/LiveStoreProvider.test.tsx +0 -109
  176. package/src/react/LiveStoreProvider.tsx +0 -291
  177. package/src/react/__snapshots__/useRow.test.tsx.snap +0 -359
  178. package/src/react/components/LiveList.tsx +0 -84
  179. package/src/react/index.ts +0 -19
  180. package/src/react/useAtom.ts +0 -55
  181. package/src/react/useLocalId.ts +0 -34
  182. package/src/react/useQuery.test.tsx +0 -82
  183. package/src/react/useQuery.ts +0 -106
  184. package/src/react/useRow.test.tsx +0 -345
  185. package/src/react/useRow.ts +0 -180
  186. package/src/react/useTemporaryQuery.test.tsx +0 -98
  187. package/src/react/useTemporaryQuery.ts +0 -131
  188. package/src/react/utils/useStateRefWithReactiveInput.ts +0 -51
  189. package/src/store-context.ts +0 -23
  190. /package/dist/{__tests__/react/utils → utils}/stack-info.test.d.ts +0 -0
  191. /package/dist/{__tests__/react/utils → utils/tests}/otel.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/otel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,+BAA+B,CAAA;AAEvF,KAAK,oBAAoB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CAAE,CAAA;AAEhG,eAAO,MAAM,qBAAqB,aACtB,oBAAoB,kBACd,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,yBAiCvD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAMlD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAA8B,EAC9B,aAAsD,EACtD,EAAE;IACF,MAAM,KAAK,GAAG,QAAQ,CAAC,gBAAgB,EAAE,CAAA;IACzC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAqB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAEtH,MAAM,eAAe,GAAG,aAAa,IAAI,QAAQ,CAAA;IAEjD,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC9B,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACx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AC,CAAC,MAAM,GAAG,CAAC,EAChC,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"stack-info.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/stack-info.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"stack-info.test.js","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/stack-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAA;AAEnF,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;IACpC,MAAM,UAAU,GAAG;;;;;;;;;;;;CAYpB,CAAA;IAEC,MAAM,SAAS,GAAG,8BAA8B,CAAC,UAAU,CAAC,CAAA;IAC5D,mEAAmE;IACnE,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,2BAA2B,CAAC,CAAC,CAAA;IAC3E,MAAM,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;GAqBvC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;IACrC,MAAM,UAAU,GAAG;;;;;;;;;;;;CAYpB,CAAA;IAEC,MAAM,SAAS,GAAG,8BAA8B,CAAC,UAAU,CAAC,CAAA;IAC5D,mEAAmE;IACnE,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,2BAA2B,CAAC,CAAC,CAAA;IAC3E,MAAM,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;GAavC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import type { Store } from '../store.js';
3
- export declare const LiveStoreContext: React.Context<import("../store-context.js").LiveStoreContextRunning | undefined>;
4
- export declare const useStore: () => {
5
- store: Store;
6
- };
7
- //# sourceMappingURL=LiveStoreContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreContext.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAGzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,eAAO,MAAM,gBAAgB,kFAAgE,CAAA;AAE7F,eAAO,MAAM,QAAQ,QAAO;IAAE,KAAK,EAAE,KAAK,CAAA;CAYzC,CAAA"}
@@ -1,13 +0,0 @@
1
- import React, { useContext } from 'react';
2
- export const LiveStoreContext = React.createContext(undefined);
3
- export const useStore = () => {
4
- const storeContext = useContext(LiveStoreContext);
5
- if (storeContext === undefined) {
6
- throw new Error(`useStore can only be used inside StoreContext.Provider`);
7
- }
8
- if (storeContext.stage !== 'running') {
9
- throw new Error(`useStore can only be used after the store is running`);
10
- }
11
- return storeContext;
12
- };
13
- //# sourceMappingURL=LiveStoreContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreContext.js","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAKzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAgC,SAAS,CAAC,CAAA;AAE7F,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAqB,EAAE;IAC7C,MAAM,YAAY,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAEjD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;IAC3E,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
@@ -1,49 +0,0 @@
1
- import type { BootDb, BootStatus, IntentionalShutdownCause, StoreAdapterFactory } from '@livestore/common';
2
- import { UnexpectedError } from '@livestore/common';
3
- import type { LiveStoreSchema } from '@livestore/common/schema';
4
- import { Effect } from '@livestore/utils/effect';
5
- import type * as otel from '@opentelemetry/api';
6
- import type { ReactElement, ReactNode } from 'react';
7
- import type { BaseGraphQLContext, GraphQLOptions, OtelOptions } from '../store.js';
8
- import { StoreAbort } from '../store-context.js';
9
- interface LiveStoreProviderProps<GraphQLContext> {
10
- schema: LiveStoreSchema;
11
- /**
12
- * The `storeId` can be used to isolate multiple stores from each other.
13
- * So it can be useful for multi-tenancy scenarios.
14
- *
15
- * The `storeId` is also used for persistence.
16
- *
17
- * Make sure to also provide `storeId` to `mountDevtools` in `_devtools.html`.
18
- *
19
- * @default 'default'
20
- */
21
- storeId?: string;
22
- boot?: (db: BootDb, parentSpan: otel.Span) => void | Promise<void> | Effect.Effect<void, unknown, otel.Tracer>;
23
- graphQLOptions?: GraphQLOptions<GraphQLContext>;
24
- otelOptions?: OtelOptions;
25
- renderLoading: (status: BootStatus) => ReactElement;
26
- renderError?: (error: UnexpectedError | unknown) => ReactElement;
27
- renderShutdown?: (cause: IntentionalShutdownCause | StoreAbort) => ReactElement;
28
- adapter: StoreAdapterFactory;
29
- /**
30
- * In order for LiveStore to apply multiple mutations in a single render,
31
- * you need to pass the `batchUpdates` function from either `react-dom` or `react-native`.
32
- *
33
- * ```ts
34
- * // With React DOM
35
- * import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
36
- *
37
- * // With React Native
38
- * import { unstable_batchedUpdates as batchUpdates } from 'react-native'
39
- * ```
40
- */
41
- batchUpdates: (run: () => void) => void;
42
- disableDevtools?: boolean;
43
- signal?: AbortSignal;
44
- }
45
- export declare const LiveStoreProvider: <GraphQLContext extends BaseGraphQLContext>({ renderLoading, renderError, renderShutdown, graphQLOptions, otelOptions, children, schema, storeId, boot, adapter, batchUpdates, disableDevtools, signal, }: LiveStoreProviderProps<GraphQLContext> & {
46
- children?: ReactNode;
47
- }) => JSX.Element;
48
- export {};
49
- //# sourceMappingURL=LiveStoreProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,EAAE,MAAM,EAAsC,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGpD,OAAO,KAAK,EAAE,kBAAkB,EAAsB,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGtG,OAAO,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAA;AAGlE,UAAU,sBAAsB,CAAC,cAAc;IAC7C,MAAM,EAAE,eAAe,CAAA;IACvB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC9G,cAAc,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IAC/C,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,YAAY,CAAA;IACnD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,KAAK,YAAY,CAAA;IAChE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,GAAG,UAAU,KAAK,YAAY,CAAA;IAC/E,OAAO,EAAE,mBAAmB,CAAA;IAC5B;;;;;;;;;;;OAWG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IACvC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAkBD,eAAO,MAAM,iBAAiB,GAAI,cAAc,SAAS,kBAAkB,iKAcxE,sBAAsB,CAAC,cAAc,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,GAAG,CAAC,OA6B1E,CAAA"}
@@ -1,169 +0,0 @@
1
- import { UnexpectedError } from '@livestore/common';
2
- import { errorToString } from '@livestore/utils';
3
- import { Effect, FiberSet, Logger, LogLevel, Schema } from '@livestore/utils/effect';
4
- import React from 'react';
5
- import { createStore } from '../store.js';
6
- import { StoreAbort, StoreInterrupted } from '../store-context.js';
7
- import { LiveStoreContext } from './LiveStoreContext.js';
8
- const defaultRenderError = (error) => (React.createElement(React.Fragment, null, Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)));
9
- const defaultRenderShutdown = (cause) => {
10
- const reason = cause._tag === 'LiveStore.StoreAbort'
11
- ? 'abort signal'
12
- : cause.reason === 'devtools-import'
13
- ? 'devtools import'
14
- : cause.reason === 'devtools-reset'
15
- ? 'devtools reset'
16
- : 'unknown reason';
17
- return React.createElement(React.Fragment, null,
18
- "LiveStore Shutdown due to ",
19
- reason);
20
- };
21
- export const LiveStoreProvider = ({ renderLoading, renderError = defaultRenderError, renderShutdown = defaultRenderShutdown, graphQLOptions, otelOptions, children, schema, storeId = 'default', boot, adapter, batchUpdates, disableDevtools, signal, }) => {
22
- const storeCtx = useCreateStore({
23
- storeId,
24
- schema,
25
- graphQLOptions,
26
- otelOptions,
27
- boot,
28
- adapter,
29
- batchUpdates,
30
- disableDevtools,
31
- signal,
32
- });
33
- if (storeCtx.stage === 'error') {
34
- return renderError(storeCtx.error);
35
- }
36
- if (storeCtx.stage === 'shutdown') {
37
- return renderShutdown(storeCtx.cause);
38
- }
39
- if (storeCtx.stage !== 'running') {
40
- return renderLoading(storeCtx);
41
- }
42
- globalThis.__debugLiveStore ??= {};
43
- globalThis.__debugLiveStore[storeId] = storeCtx.store;
44
- return React.createElement(LiveStoreContext.Provider, { value: storeCtx }, children);
45
- };
46
- const semaphoreMap = new Map();
47
- const withSemaphore = (storeId) => {
48
- let semaphore = semaphoreMap.get(storeId);
49
- if (!semaphore) {
50
- semaphore = Effect.makeSemaphore(1).pipe(Effect.runSync);
51
- semaphoreMap.set(storeId, semaphore);
52
- }
53
- return semaphore.withPermits(1);
54
- };
55
- const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, reactivityGraph, signal, }) => {
56
- const [_, rerender] = React.useState(0);
57
- const ctxValueRef = React.useRef({
58
- value: { stage: 'loading' },
59
- fiberSet: undefined,
60
- counter: 0,
61
- });
62
- // console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
63
- const inputPropsCacheRef = React.useRef({
64
- schema,
65
- graphQLOptions,
66
- otelOptions,
67
- boot,
68
- adapter,
69
- batchUpdates,
70
- disableDevtools,
71
- reactivityGraph,
72
- signal,
73
- });
74
- const interrupt = (fiberSet, error) => Effect.gen(function* () {
75
- yield* FiberSet.clear(fiberSet);
76
- yield* FiberSet.run(fiberSet, Effect.fail(error));
77
- }).pipe(Effect.tapErrorCause((cause) => Effect.logDebug(`[@livestore/livestore/react] interupting`, cause)), Effect.runFork);
78
- if (inputPropsCacheRef.current.schema !== schema ||
79
- inputPropsCacheRef.current.graphQLOptions !== graphQLOptions ||
80
- inputPropsCacheRef.current.otelOptions !== otelOptions ||
81
- inputPropsCacheRef.current.boot !== boot ||
82
- inputPropsCacheRef.current.adapter !== adapter ||
83
- inputPropsCacheRef.current.batchUpdates !== batchUpdates ||
84
- inputPropsCacheRef.current.disableDevtools !== disableDevtools ||
85
- inputPropsCacheRef.current.reactivityGraph !== reactivityGraph ||
86
- inputPropsCacheRef.current.signal !== signal) {
87
- inputPropsCacheRef.current = {
88
- schema,
89
- graphQLOptions,
90
- otelOptions,
91
- boot,
92
- adapter,
93
- batchUpdates,
94
- disableDevtools,
95
- reactivityGraph,
96
- signal,
97
- };
98
- if (ctxValueRef.current.fiberSet !== undefined) {
99
- interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted());
100
- ctxValueRef.current.fiberSet = undefined;
101
- }
102
- ctxValueRef.current = { value: { stage: 'loading' }, fiberSet: undefined, counter: ctxValueRef.current.counter + 1 };
103
- }
104
- React.useEffect(() => {
105
- const counter = ctxValueRef.current.counter;
106
- const setContextValue = (value) => {
107
- if (ctxValueRef.current.counter !== counter)
108
- return;
109
- ctxValueRef.current.value = value;
110
- rerender((c) => c + 1);
111
- };
112
- signal?.addEventListener('abort', () => {
113
- if (ctxValueRef.current.fiberSet !== undefined && ctxValueRef.current.counter === counter) {
114
- interrupt(ctxValueRef.current.fiberSet, new StoreAbort());
115
- ctxValueRef.current.fiberSet = undefined;
116
- }
117
- });
118
- Effect.gen(function* () {
119
- const fiberSet = yield* FiberSet.make();
120
- ctxValueRef.current.fiberSet = fiberSet;
121
- yield* Effect.gen(function* () {
122
- const store = yield* createStore({
123
- fiberSet,
124
- schema,
125
- storeId,
126
- graphQLOptions,
127
- otelOptions,
128
- boot,
129
- adapter,
130
- reactivityGraph,
131
- batchUpdates,
132
- disableDevtools,
133
- onBootStatus: (status) => {
134
- if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
135
- return;
136
- setContextValue(status);
137
- },
138
- });
139
- setContextValue({ stage: 'running', store });
140
- yield* Effect.never;
141
- }).pipe(Effect.scoped, FiberSet.run(fiberSet));
142
- const shutdownContext = (cause) => Effect.sync(() => setContextValue({ stage: 'shutdown', cause }));
143
- yield* FiberSet.join(fiberSet).pipe(Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)), Effect.catchTag('LiveStore.StoreAbort', (cause) => shutdownContext(cause)), Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))), Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))), Effect.exit);
144
- }).pipe(Effect.scoped,
145
- // NOTE we're running the code above in a semaphore to make sure a previous store is always fully
146
- // shutdown before a new one is created - especially when shutdown logic is async. You can't trust `React.useEffect`.
147
- // Thank you to Mattia Manzati for this idea.
148
- withSemaphore(storeId), Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: 'window' }), Effect.provide(Logger.pretty), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runFork);
149
- return () => {
150
- if (ctxValueRef.current.fiberSet !== undefined) {
151
- interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted());
152
- ctxValueRef.current.fiberSet = undefined;
153
- }
154
- };
155
- }, [
156
- schema,
157
- graphQLOptions,
158
- otelOptions,
159
- boot,
160
- adapter,
161
- batchUpdates,
162
- disableDevtools,
163
- signal,
164
- reactivityGraph,
165
- storeId,
166
- ]);
167
- return ctxValueRef.current.value;
168
- };
169
- //# sourceMappingURL=LiveStoreProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"m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1C,MAAM,CAAC,OAAO,CACf,CAAA;QAED,OAAO,GAAG,EAAE;YACV,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC/C,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA;gBAC/D,WAAW,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAA;YAC1C,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE;QACD,MAAM;QACN,cAAc;QACd,WAAW;QACX,IAAI;QACJ,OAAO;QACP,YAAY;QACZ,eAAe;QACf,MAAM;QACN,eAAe;QACf,OAAO;KACR,CAAC,CAAA;IAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;AAClC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LiveStoreProvider.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreProvider.test.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.test.tsx"],"names":[],"mappings":""}
@@ -1,62 +0,0 @@
1
- import { sql } from '@livestore/common';
2
- import { Schema } from '@livestore/utils/effect';
3
- import { makeInMemoryAdapter } from '@livestore/web';
4
- import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
5
- import React from 'react';
6
- import { unstable_batchedUpdates as batchUpdates } from 'react-dom';
7
- import { describe, expect, it } from 'vitest';
8
- import { schema, tables } from '../__tests__/react/fixture.js';
9
- import { querySQL } from '../reactiveQueries/sql.js';
10
- import * as LiveStoreReact from './index.js';
11
- import { LiveStoreProvider } from './LiveStoreProvider.js';
12
- describe('LiveStoreProvider', () => {
13
- it('simple', async () => {
14
- let appRenderCount = 0;
15
- const allTodos$ = querySQL(`select * from todos`, { schema: Schema.Array(tables.todos.schema) });
16
- const App = () => {
17
- appRenderCount++;
18
- const todos = LiveStoreReact.useQuery(allTodos$);
19
- return React.createElement("div", null, JSON.stringify(todos));
20
- };
21
- const abortController = new AbortController();
22
- const Root = ({ forceUpdate }) => {
23
- const bootCb = React.useCallback((db) => db.execute(sql `INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
24
- // eslint-disable-next-line react-hooks/exhaustive-deps
25
- const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
26
- return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
27
- "Loading LiveStore: ",
28
- status.stage), adapter: adapterMemo, boot: bootCb, signal: abortController.signal, batchUpdates: batchUpdates },
29
- React.createElement(App, null)));
30
- };
31
- const { rerender } = render(React.createElement(Root, { forceUpdate: 1 }));
32
- expect(appRenderCount).toBe(0);
33
- await waitForElementToBeRemoved(() => screen.getByText((_) => _.startsWith('Loading LiveStore')));
34
- expect(appRenderCount).toBe(1);
35
- rerender(React.createElement(Root, { forceUpdate: 2 }));
36
- await waitFor(() => screen.getByText('Loading LiveStore: loading'));
37
- await waitFor(() => screen.getByText((_) => _.includes('buy milk')));
38
- expect(appRenderCount).toBe(2);
39
- abortController.abort();
40
- await waitFor(() => screen.getByText('LiveStore Shutdown due to abort signal'));
41
- });
42
- it('error during boot', async () => {
43
- let appRenderCount = 0;
44
- const App = () => {
45
- appRenderCount++;
46
- return React.createElement("div", null, "hello world");
47
- };
48
- const Root = ({ forceUpdate }) => {
49
- const bootCb = React.useCallback((db) => db.execute(sql `INSERT INTO todos_mising_table (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
50
- // eslint-disable-next-line react-hooks/exhaustive-deps
51
- const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
52
- return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
53
- "Loading LiveStore: ",
54
- status.stage), adapter: adapterMemo, boot: bootCb, batchUpdates: batchUpdates },
55
- React.createElement(App, null)));
56
- };
57
- render(React.createElement(Root, { forceUpdate: 1 }));
58
- expect(appRenderCount).toBe(0);
59
- await waitFor(() => screen.getByText((_) => _.startsWith('LiveStore.UnexpectedError')));
60
- });
61
- });
62
- //# sourceMappingURL=LiveStoreProvider.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveStoreProvider.test.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAC3F,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,uBAAuB,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtB,IAAI,cAAc,GAAG,CAAC,CAAA;QAEtB,MAAM,SAAS,GAAG,QAAQ,CAAC,qBAAqB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAEhG,MAAM,GAAG,GAAG,GAAG,EAAE;YACf,cAAc,EAAE,CAAA;YAEhB,MAAM,KAAK,GAAG,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,EACpB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY;gBAE1B,oBAAC,GAAG,OAAG,CACW,CACrB,CAAA;QACH,CAAC,CAAA;QAED,MAAM,CAAC,oBAAC,IAAI,IAAC,WAAW,EAAE,CAAC,GAAI,CAAC,CAAA;QAEhC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAE9B,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAA;IACzF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import type { LiveQuery } from '../../reactiveQueries/base-class.js';
3
- export type LiveListProps<TItem> = {
4
- items$: LiveQuery<ReadonlyArray<TItem>>;
5
- renderItem: (item: TItem, opts: {
6
- index: number;
7
- isInitialListRender: boolean;
8
- }) => React.ReactNode;
9
- /** Needs to be unique across all list items */
10
- getKey: (item: TItem, index: number) => string | number;
11
- };
12
- /**
13
- * This component is a helper component for rendering a list of items for a LiveQuery of an array of items.
14
- * The idea is that instead of letting React handle the rendering of the items array directly,
15
- * we derive a item LiveQuery for each item which moves the reactivity to the item level when a single item changes.
16
- *
17
- * In the future we want to make this component even more efficient by using incremental rendering (https://github.com/livestorejs/livestore/pull/55)
18
- * e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
19
- */
20
- export declare const LiveList: <TItem>({ items$, renderItem, getKey }: LiveListProps<TItem>) => React.ReactNode;
21
- //# sourceMappingURL=LiveList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/react/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAA;AAWpE,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAEvC,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,kCAAmC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,SA8B7F,CAAA"}
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { computed } from '../../reactiveQueries/js.js';
3
- import { useQuery } from '../useQuery.js';
4
- import { useTemporaryQuery } from '../useTemporaryQuery.js';
5
- /**
6
- * This component is a helper component for rendering a list of items for a LiveQuery of an array of items.
7
- * The idea is that instead of letting React handle the rendering of the items array directly,
8
- * we derive a item LiveQuery for each item which moves the reactivity to the item level when a single item changes.
9
- *
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
- * e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
12
- */
13
- export const LiveList = ({ items$, renderItem, getKey }) => {
14
- const [hasMounted, setHasMounted] = React.useState(false);
15
- React.useEffect(() => setHasMounted(true), []);
16
- const keysCb = React.useCallback(() => computed((get) => get(items$).map(getKey)), [getKey, items$]);
17
- const keys = useTemporaryQuery(keysCb, 'fixed');
18
- const arr = React.useMemo(() => keys.map((key) =>
19
- // TODO figure out a way so that `item$` returns an ordered lookup map to more efficiently find the item by key
20
- [key, computed((get) => get(items$).find((item) => getKey(item, 0) === key))]), [getKey, items$, keys]);
21
- return (React.createElement(React.Fragment, null, arr.map(([key, item$], index) => (React.createElement(ItemWrapperMemo, { key: key, itemKey: key, "item$": item$, opts: { isInitialListRender: !hasMounted, index }, renderItem: renderItem })))));
22
- };
23
- const ItemWrapper = ({ item$, opts, renderItem, }) => {
24
- const item = useQuery(item$);
25
- return React.createElement(React.Fragment, null, renderItem(item, opts));
26
- };
27
- const ItemWrapperMemo = React.memo(ItemWrapper, (prev, next) => prev.itemKey === next.itemKey &&
28
- prev.renderItem === prev.renderItem &&
29
- prev.opts.index === next.opts.index &&
30
- prev.opts.isInitialListRender === next.opts.isInitialListRender);
31
- //# sourceMappingURL=LiveList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveList.js","sourceRoot":"","sources":["../../../src/react/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAgB3D;;;;;;;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,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IAE9C,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACpG,MAAM,IAAI,GAAG,iBA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I,CAAC,IAAI,CAAC,KAAK;IACnC,IAAI,CAAC,IAAI,CAAC,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAC5C,CAAA"}
@@ -1,11 +0,0 @@
1
- export { LiveStoreContext, useStore } from './LiveStoreContext.js';
2
- export { LiveStoreProvider } from './LiveStoreProvider.js';
3
- export { useQuery } from './useQuery.js';
4
- export { useTemporaryQuery } from './useTemporaryQuery.js';
5
- export { useStackInfo } from './utils/stack-info.js';
6
- export { useRow, type StateSetters, type SetStateAction, type Dispatch, type UseRowResult as UseStateResult, } from './useRow.js';
7
- export { useAtom } from './useAtom.js';
8
- export { useLocalId, getLocalId } from './useLocalId.js';
9
- export { LiveList, type LiveListProps } from './components/LiveList.js';
10
- export type { TypedDocumentNode } from '@graphql-typed-document-node/core';
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,IAAI,cAAc,GACpC,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAGvE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA"}
@@ -1,10 +0,0 @@
1
- export { LiveStoreContext, useStore } from './LiveStoreContext.js';
2
- export { LiveStoreProvider } from './LiveStoreProvider.js';
3
- export { useQuery } from './useQuery.js';
4
- export { useTemporaryQuery } from './useTemporaryQuery.js';
5
- export { useStackInfo } from './utils/stack-info.js';
6
- export { useRow, } from './useRow.js';
7
- export { useAtom } from './useAtom.js';
8
- export { useLocalId, getLocalId } from './useLocalId.js';
9
- export { LiveList } from './components/LiveList.js';
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,MAAM,GAKP,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAA"}
@@ -1,10 +0,0 @@
1
- import { type QueryInfoCol, type QueryInfoRow } from '@livestore/common';
2
- import type { DbSchema } from '@livestore/common/schema';
3
- import type { LiveQuery } from '../reactiveQueries/base-class.js';
4
- import type { Dispatch, SetStateAction } from './useRow.js';
5
- export declare const useAtom: <TQuery extends LiveQuery<any, QueryInfoRow<TTableDef> | QueryInfoCol<TTableDef, any>>, TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDefConstrained, boolean, DbSchema.TableOptions & {
6
- deriveMutations: {
7
- enabled: true;
8
- };
9
- }>>(query$: TQuery) => [value: TQuery["__result!"], setValue: Dispatch<SetStateAction<Partial<TQuery["__result!"]>>>];
10
- //# sourceMappingURL=useAtom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAtom.d.ts","sourceRoot":"","sources":["../../src/react/useAtom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAGjE,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3D,eAAO,MAAM,OAAO,GAClB,MAAM,SAAS,SAAS,CAAC,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,EACrF,SAAS,SAAS,QAAQ,CAAC,QAAQ,CACjC,QAAQ,CAAC,gCAAgC,EACzC,OAAO,EACP,QAAQ,CAAC,YAAY,GAAG;IAAE,eAAe,EAAE;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,CAAA;CAAE,CAC/D,UAEO,MAAM,KACb,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAoC/F,CAAA"}
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { useStore } from './LiveStoreContext.js';
3
- import { useQueryRef } from './useQuery.js';
4
- export const useAtom = (query$) => {
5
- const query$Ref = useQueryRef(query$);
6
- const { store } = useStore();
7
- // TODO make API equivalent to useRow
8
- const setValue = React.useMemo(() => {
9
- return (newValueOrFn) => {
10
- const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn;
11
- if (query$.queryInfo._tag === 'Row') {
12
- if (query$.queryInfo.table.options.isSingleton && query$.queryInfo.table.isSingleColumn) {
13
- store.mutate(query$.queryInfo.table.update(newValue));
14
- }
15
- else if (query$.queryInfo.table.options.isSingleColumn) {
16
- store.mutate(query$.queryInfo.table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }));
17
- }
18
- else {
19
- store.mutate(query$.queryInfo.table.update({ where: { id: query$.queryInfo.id }, values: newValue }));
20
- }
21
- }
22
- else {
23
- if (query$.queryInfo.table.options.isSingleton && query$.queryInfo.table.isSingleColumn) {
24
- store.mutate(query$.queryInfo.table.update({ [query$.queryInfo.column]: newValue }));
25
- }
26
- else {
27
- store.mutate(query$.queryInfo.table.update({
28
- where: { id: query$.queryInfo.id },
29
- values: { [query$.queryInfo.column]: newValue },
30
- }));
31
- }
32
- }
33
- };
34
- }, [query$.queryInfo, query$Ref, store]);
35
- return [query$Ref.current, setValue];
36
- };
37
- //# sourceMappingURL=useAtom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAtom.js","sourceRoot":"","sources":["../../src/react/useAtom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,OAAO,GAAG,CAQrB,MAAc,EACkF,EAAE;IAClG,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAErC,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE5B,qCAAqC;IACrC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAgD,GAAG,EAAE;QACjF,OAAO,CAAC,YAAiB,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,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BAAM,CAAC;oBACN,KAAK,CAAC,MAAM,CACV,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;wBAC5B,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE;wBAClC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE;qBAChD,CAAC,CACH,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;IAExC,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;AACtC,CAAC,CAAA"}
@@ -1,10 +0,0 @@
1
- type LocalIdOptions = {
2
- key: string;
3
- storageType: 'session' | 'local';
4
- storageKeyPrefix: string;
5
- makeId: () => string;
6
- };
7
- export declare const useLocalId: (opts?: Partial<LocalIdOptions>) => string;
8
- export declare const getLocalId: (opts?: Partial<LocalIdOptions>) => string;
9
- export {};
10
- //# sourceMappingURL=useLocalId.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLocalId.d.ts","sourceRoot":"","sources":["../../src/react/useLocalId.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,SAAS,GAAG,OAAO,CAAA;IAChC,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,MAAM,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,UAAU,UAAW,OAAO,CAAC,cAAc,CAAC,WAAkD,CAAA;AAE3G,eAAO,MAAM,UAAU,UAAW,OAAO,CAAC,cAAc,CAAC,WAoBxD,CAAA"}
@@ -1,22 +0,0 @@
1
- /* eslint-disable unicorn/prefer-global-this */
2
- import { cuid } from '@livestore/utils/cuid';
3
- import React from 'react';
4
- export const useLocalId = (opts) => React.useMemo(() => getLocalId(opts), [opts]);
5
- export const getLocalId = (opts) => {
6
- // TODO find a better way to handle this
7
- // Currently `getLocalId` gets imported and called in some worker-side code
8
- // during development where Vite isn't tree-shaking yet.
9
- if (typeof window === 'undefined' || window.localStorage === undefined || window.sessionStorage === undefined) {
10
- return '';
11
- }
12
- const { key = '', storageType = 'session', storageKeyPrefix = 'livestore:localid:', makeId = cuid } = opts ?? {};
13
- const storage = storageType === 'session' ? window.sessionStorage : window.localStorage;
14
- const fullKey = `${storageKeyPrefix}:${key}`;
15
- const storedKey = storage.getItem(fullKey);
16
- if (storedKey)
17
- return storedKey;
18
- const newKey = makeId();
19
- storage.setItem(fullKey, newKey);
20
- return newKey;
21
- };
22
- //# sourceMappingURL=useLocalId.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLocalId.js","sourceRoot":"","sources":["../../src/react/useLocalId.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AAE3G,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE;IAC3D,wCAAwC;IACxC,2EAA2E;IAC3E,wDAAwD;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QAC9G,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,WAAW,GAAG,SAAS,EAAE,gBAAgB,GAAG,oBAAoB,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;IAEhH,MAAM,OAAO,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAA;IACvF,MAAM,OAAO,GAAG,GAAG,gBAAgB,IAAI,GAAG,EAAE,CAAA;IAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE1C,IAAI,SAAS;QAAE,OAAO,SAAS,CAAA;IAE/B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA;IACvB,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAEhC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -1,9 +0,0 @@
1
- import * as otel from '@opentelemetry/api';
2
- import React from 'react';
3
- import type { GetResult, LiveQueryAny } from '../reactiveQueries/base-class.js';
4
- export declare const useQuery: <TQuery extends LiveQueryAny>(query: TQuery) => GetResult<TQuery>;
5
- /**
6
- *
7
- */
8
- export declare const useQueryRef: <TQuery extends LiveQueryAny>(query$: TQuery, parentOtelContext?: otel.Context) => React.MutableRefObject<GetResult<TQuery>>;
9
- //# sourceMappingURL=useQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/react/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAiB/E,eAAO,MAAM,QAAQ,GAAI,MAAM,SAAS,YAAY,SAAS,MAAM,KAAG,SAAS,CAAC,MAAM,CAA+B,CAAA;AAErH;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,YAAY,UAC7C,MAAM,sBACM,IAAI,CAAC,OAAO,KAC/B,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,CA4E1C,CAAA"}