@livestore/livestore 0.0.25 → 0.0.27

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 (206) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/QueryCache.d.ts +1 -1
  3. package/dist/QueryCache.d.ts.map +1 -1
  4. package/dist/QueryCache.js +50 -60
  5. package/dist/QueryCache.js.map +1 -1
  6. package/dist/__tests__/react/fixture.d.ts +21 -6
  7. package/dist/__tests__/react/fixture.d.ts.map +1 -1
  8. package/dist/__tests__/react/fixture.js +13 -14
  9. package/dist/__tests__/react/fixture.js.map +1 -1
  10. package/dist/__tests__/react/useQuery.test.js +5 -5
  11. package/dist/__tests__/react/useQuery.test.js.map +1 -1
  12. package/dist/__tests__/react/useRow.test.d.ts +2 -0
  13. package/dist/__tests__/react/useRow.test.d.ts.map +1 -0
  14. package/dist/__tests__/react/{useComponentState.test.js → useRow.test.js} +21 -26
  15. package/dist/__tests__/react/useRow.test.js.map +1 -0
  16. package/dist/__tests__/react/utils/stack-info.test.js +32 -0
  17. package/dist/__tests__/react/utils/stack-info.test.js.map +1 -1
  18. package/dist/__tests__/reactiveQueries/sql.test.js +4 -4
  19. package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -1
  20. package/dist/effect/LiveStore.d.ts +3 -3
  21. package/dist/effect/LiveStore.d.ts.map +1 -1
  22. package/dist/effect/LiveStore.js +1 -1
  23. package/dist/effect/LiveStore.js.map +1 -1
  24. package/dist/global-state.d.ts +19 -0
  25. package/dist/global-state.d.ts.map +1 -0
  26. package/dist/global-state.js +20 -0
  27. package/dist/global-state.js.map +1 -0
  28. package/dist/inMemoryDatabase.d.ts +3 -3
  29. package/dist/inMemoryDatabase.d.ts.map +1 -1
  30. package/dist/inMemoryDatabase.js +13 -7
  31. package/dist/inMemoryDatabase.js.map +1 -1
  32. package/dist/index.d.ts +5 -9
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +4 -5
  35. package/dist/index.js.map +1 -1
  36. package/dist/migrations.d.ts +4 -4
  37. package/dist/migrations.d.ts.map +1 -1
  38. package/dist/migrations.js +34 -28
  39. package/dist/migrations.js.map +1 -1
  40. package/dist/react/LiveStoreContext.js.map +1 -1
  41. package/dist/react/LiveStoreProvider.d.ts +2 -2
  42. package/dist/react/LiveStoreProvider.d.ts.map +1 -1
  43. package/dist/react/LiveStoreProvider.js.map +1 -1
  44. package/dist/react/index.d.ts +1 -2
  45. package/dist/react/index.d.ts.map +1 -1
  46. package/dist/react/index.js +1 -1
  47. package/dist/react/index.js.map +1 -1
  48. package/dist/react/useQuery.d.ts +3 -0
  49. package/dist/react/useQuery.d.ts.map +1 -1
  50. package/dist/react/useQuery.js +5 -4
  51. package/dist/react/useQuery.js.map +1 -1
  52. package/dist/react/useRow.d.ts +33 -0
  53. package/dist/react/useRow.d.ts.map +1 -0
  54. package/dist/react/useRow.js +136 -0
  55. package/dist/react/useRow.js.map +1 -0
  56. package/dist/react/useTemporaryQuery.d.ts +2 -0
  57. package/dist/react/useTemporaryQuery.d.ts.map +1 -1
  58. package/dist/react/useTemporaryQuery.js +28 -11
  59. package/dist/react/useTemporaryQuery.js.map +1 -1
  60. package/dist/react/utils/stack-info.d.ts.map +1 -1
  61. package/dist/react/utils/stack-info.js +3 -2
  62. package/dist/react/utils/stack-info.js.map +1 -1
  63. package/dist/react/utils/useStateRefWithReactiveInput.js.map +1 -1
  64. package/dist/reactive.d.ts +1 -1
  65. package/dist/reactive.d.ts.map +1 -1
  66. package/dist/reactive.js +47 -44
  67. package/dist/reactive.js.map +1 -1
  68. package/dist/reactiveQueries/base-class.d.ts +6 -2
  69. package/dist/reactiveQueries/base-class.d.ts.map +1 -1
  70. package/dist/reactiveQueries/base-class.js +10 -12
  71. package/dist/reactiveQueries/base-class.js.map +1 -1
  72. package/dist/reactiveQueries/graphql.d.ts +2 -2
  73. package/dist/reactiveQueries/graphql.d.ts.map +1 -1
  74. package/dist/reactiveQueries/graphql.js +56 -50
  75. package/dist/reactiveQueries/graphql.js.map +1 -1
  76. package/dist/reactiveQueries/js.d.ts +1 -2
  77. package/dist/reactiveQueries/js.d.ts.map +1 -1
  78. package/dist/reactiveQueries/js.js +25 -15
  79. package/dist/reactiveQueries/js.js.map +1 -1
  80. package/dist/reactiveQueries/sql.d.ts +3 -3
  81. package/dist/reactiveQueries/sql.d.ts.map +1 -1
  82. package/dist/reactiveQueries/sql.js +39 -34
  83. package/dist/reactiveQueries/sql.js.map +1 -1
  84. package/dist/row-query.d.ts +21 -0
  85. package/dist/row-query.d.ts.map +1 -0
  86. package/dist/row-query.js +77 -0
  87. package/dist/row-query.js.map +1 -0
  88. package/dist/schema/action.d.ts +30 -0
  89. package/dist/schema/action.d.ts.map +1 -0
  90. package/dist/schema/action.js +3 -0
  91. package/dist/schema/action.js.map +1 -0
  92. package/dist/schema/index.d.ts +28 -0
  93. package/dist/schema/index.d.ts.map +1 -0
  94. package/dist/schema/index.js +26 -0
  95. package/dist/schema/index.js.map +1 -0
  96. package/dist/schema/system-tables.d.ts +24 -0
  97. package/dist/schema/system-tables.d.ts.map +1 -0
  98. package/dist/schema/system-tables.js +11 -0
  99. package/dist/schema/system-tables.js.map +1 -0
  100. package/dist/schema/table-def.d.ts +161 -0
  101. package/dist/schema/table-def.d.ts.map +1 -0
  102. package/dist/schema/table-def.js +53 -0
  103. package/dist/schema/table-def.js.map +1 -0
  104. package/dist/storage/in-memory/index.d.ts +1 -1
  105. package/dist/storage/in-memory/index.d.ts.map +1 -1
  106. package/dist/storage/in-memory/index.js +6 -7
  107. package/dist/storage/in-memory/index.js.map +1 -1
  108. package/dist/storage/index.d.ts +1 -1
  109. package/dist/storage/index.d.ts.map +1 -1
  110. package/dist/storage/tauri/index.d.ts +1 -1
  111. package/dist/storage/tauri/index.d.ts.map +1 -1
  112. package/dist/storage/tauri/index.js +25 -23
  113. package/dist/storage/tauri/index.js.map +1 -1
  114. package/dist/storage/utils/idb.js +3 -1
  115. package/dist/storage/utils/idb.js.map +1 -1
  116. package/dist/storage/web-worker/index.d.ts +1 -1
  117. package/dist/storage/web-worker/index.d.ts.map +1 -1
  118. package/dist/storage/web-worker/index.js +38 -34
  119. package/dist/storage/web-worker/index.js.map +1 -1
  120. package/dist/storage/web-worker/worker.d.ts +1 -1
  121. package/dist/storage/web-worker/worker.d.ts.map +1 -1
  122. package/dist/storage/web-worker/worker.js +1 -1
  123. package/dist/storage/web-worker/worker.js.map +1 -1
  124. package/dist/store.d.ts +9 -10
  125. package/dist/store.d.ts.map +1 -1
  126. package/dist/store.js +282 -265
  127. package/dist/store.js.map +1 -1
  128. package/dist/utils/bounded-collections.d.ts.map +1 -0
  129. package/dist/utils/bounded-collections.js +90 -0
  130. package/dist/utils/bounded-collections.js.map +1 -0
  131. package/dist/utils/otel.d.ts.map +1 -0
  132. package/dist/{otel.js → utils/otel.js} +1 -1
  133. package/dist/utils/otel.js.map +1 -0
  134. package/dist/utils/util.d.ts.map +1 -0
  135. package/dist/utils/util.js.map +1 -0
  136. package/package.json +12 -12
  137. package/src/QueryCache.ts +2 -2
  138. package/src/__tests__/react/fixture.tsx +15 -15
  139. package/src/__tests__/react/useQuery.test.tsx +5 -5
  140. package/src/__tests__/react/{useComponentState.test.tsx → useRow.test.tsx} +27 -28
  141. package/src/__tests__/react/utils/stack-info.test.ts +34 -0
  142. package/src/__tests__/reactiveQueries/sql.test.ts +4 -4
  143. package/src/effect/LiveStore.ts +6 -6
  144. package/src/global-state.ts +26 -0
  145. package/src/inMemoryDatabase.ts +6 -4
  146. package/src/index.ts +18 -17
  147. package/src/migrations.ts +41 -35
  148. package/src/react/LiveStoreProvider.tsx +2 -2
  149. package/src/react/index.ts +7 -9
  150. package/src/react/useQuery.ts +10 -4
  151. package/src/react/useRow.ts +221 -0
  152. package/src/react/useTemporaryQuery.ts +43 -11
  153. package/src/react/utils/stack-info.ts +4 -2
  154. package/src/reactive.ts +1 -1
  155. package/src/reactiveQueries/base-class.ts +8 -2
  156. package/src/reactiveQueries/graphql.ts +4 -3
  157. package/src/reactiveQueries/js.ts +3 -4
  158. package/src/reactiveQueries/sql.ts +6 -6
  159. package/src/row-query.ts +142 -0
  160. package/src/schema/action.ts +41 -0
  161. package/src/schema/index.ts +63 -0
  162. package/src/schema/system-tables.ts +21 -0
  163. package/src/schema/table-def.ts +199 -0
  164. package/src/storage/in-memory/index.ts +1 -1
  165. package/src/storage/index.ts +2 -1
  166. package/src/storage/tauri/index.ts +2 -2
  167. package/src/storage/web-worker/index.ts +1 -1
  168. package/src/storage/web-worker/worker.ts +2 -2
  169. package/src/store.ts +39 -27
  170. package/dist/__tests__/react/useComponentState.test.d.ts +0 -2
  171. package/dist/__tests__/react/useComponentState.test.d.ts.map +0 -1
  172. package/dist/__tests__/react/useComponentState.test.js.map +0 -1
  173. package/dist/bounded-collections.d.ts.map +0 -1
  174. package/dist/bounded-collections.js +0 -103
  175. package/dist/bounded-collections.js.map +0 -1
  176. package/dist/componentKey.d.ts +0 -20
  177. package/dist/componentKey.d.ts.map +0 -1
  178. package/dist/componentKey.js +0 -3
  179. package/dist/componentKey.js.map +0 -1
  180. package/dist/otel.d.ts.map +0 -1
  181. package/dist/otel.js.map +0 -1
  182. package/dist/react/useComponentState.d.ts +0 -50
  183. package/dist/react/useComponentState.d.ts.map +0 -1
  184. package/dist/react/useComponentState.js +0 -226
  185. package/dist/react/useComponentState.js.map +0 -1
  186. package/dist/reactiveQueries/graph.d.ts +0 -10
  187. package/dist/reactiveQueries/graph.d.ts.map +0 -1
  188. package/dist/reactiveQueries/graph.js +0 -6
  189. package/dist/reactiveQueries/graph.js.map +0 -1
  190. package/dist/schema.d.ts +0 -81
  191. package/dist/schema.d.ts.map +0 -1
  192. package/dist/schema.js +0 -46
  193. package/dist/schema.js.map +0 -1
  194. package/dist/util.d.ts.map +0 -1
  195. package/dist/util.js.map +0 -1
  196. package/src/componentKey.ts +0 -9
  197. package/src/react/useComponentState.ts +0 -385
  198. package/src/reactiveQueries/graph.ts +0 -15
  199. package/src/schema.ts +0 -143
  200. /package/dist/{bounded-collections.d.ts → utils/bounded-collections.d.ts} +0 -0
  201. /package/dist/{otel.d.ts → utils/otel.d.ts} +0 -0
  202. /package/dist/{util.d.ts → utils/util.d.ts} +0 -0
  203. /package/dist/{util.js → utils/util.js} +0 -0
  204. /package/src/{bounded-collections.ts → utils/bounded-collections.ts} +0 -0
  205. /package/src/{otel.ts → utils/otel.ts} +0 -0
  206. /package/src/{util.ts → utils/util.ts} +0 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Creates a map that has a fixed number of entries.
3
+ * Once hitting the bound, earliest insertions are removed
4
+ */
5
+ export default class BoundMap {
6
+ #map = new Map();
7
+ #sizeLimit;
8
+ constructor(sizeLimit) {
9
+ this.#sizeLimit = sizeLimit;
10
+ }
11
+ onEvict;
12
+ set = (key, value) => {
13
+ this.#map.set(key, value);
14
+ // console.log(this.#map.size, this.#sizeLimit);
15
+ if (this.#map.size > this.#sizeLimit) {
16
+ const firstKey = this.#map.keys().next().value;
17
+ this.#map.delete(firstKey);
18
+ if (this.onEvict) {
19
+ this.onEvict(firstKey);
20
+ }
21
+ }
22
+ };
23
+ get = (key) => {
24
+ return this.#map.get(key);
25
+ };
26
+ delete = (key) => {
27
+ this.#map.delete(key);
28
+ };
29
+ keys = () => {
30
+ return this.#map.keys();
31
+ };
32
+ }
33
+ export class BoundSet {
34
+ #map;
35
+ constructor(sizeLimit) {
36
+ this.#map = new BoundMap(sizeLimit);
37
+ this.#map.onEvict = this.#onEvict;
38
+ }
39
+ #onEvict = (v) => {
40
+ if (this.onEvict) {
41
+ this.onEvict(v);
42
+ }
43
+ };
44
+ onEvict;
45
+ add = (v) => {
46
+ this.#map.set(v, v);
47
+ };
48
+ [Symbol.iterator] = () => {
49
+ return this.#map.keys();
50
+ };
51
+ }
52
+ export class BoundArray {
53
+ #array = [];
54
+ #sizeLimit;
55
+ constructor(sizeLimit) {
56
+ this.#sizeLimit = sizeLimit;
57
+ }
58
+ onEvict;
59
+ push = (v) => {
60
+ this.#array.push(v);
61
+ if (this.#array.length > this.#sizeLimit) {
62
+ const first = this.#array.shift();
63
+ if (first && this.onEvict) {
64
+ this.onEvict(first);
65
+ }
66
+ }
67
+ };
68
+ get = (index) => {
69
+ return this.#array[index];
70
+ };
71
+ delete = (index) => {
72
+ this.#array.splice(index, 1);
73
+ };
74
+ get length() {
75
+ return this.#array.length;
76
+ }
77
+ [Symbol.iterator] = () => {
78
+ return this.#array[Symbol.iterator]();
79
+ };
80
+ map = (fn) => {
81
+ return this.#array.map(fn);
82
+ };
83
+ clear = () => {
84
+ this.#array = [];
85
+ };
86
+ sort = (fn) => {
87
+ return this.#array.sort(fn);
88
+ };
89
+ }
90
+ //# sourceMappingURL=bounded-collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounded-collections.js","sourceRoot":"","sources":["../../src/utils/bounded-collections.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,IAAI,GAAG,IAAI,GAAG,EAAQ,CAAA;IACtB,UAAU,CAAQ;IAElB,YAAY,SAAiB;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;IAC7B,CAAC;IAED,OAAO,CAAgC;IAEvC,GAAG,GAAG,CAAC,GAAM,EAAE,KAAQ,EAAE,EAAE;QACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACzB,gDAAgD;QAChD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAA;YAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC1B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,IAAI,CAAC,OAAO,CAAC,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+ {"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/utils/otel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE/C,eAAO,MAAM,qBAAqB,SAAU,KAAK,IAAI,KAAG,MAGvD,CAAA;AAED,eAAO,MAAM,2BAA2B,SAAU,KAAK,IAAI,KAAG,mBACF,CAAA"}
@@ -1,6 +1,6 @@
1
1
  export const getDurationMsFromSpan = (span) => {
2
2
  const durationHr = span._duration;
3
- return durationHr[0] * 1000 + durationHr[1] / 1000000;
3
+ return durationHr[0] * 1000 + durationHr[1] / 1_000_000;
4
4
  };
5
5
  export const getStartTimeHighResFromSpan = (span) => span._performanceStartTime;
6
6
  //# sourceMappingURL=otel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../src/utils/otel.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAe,EAAU,EAAE;IAC/D,MAAM,UAAU,GAAsC,IAAY,CAAC,SAAS,CAAA;IAC5E,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AACzD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,IAAe,EAAuB,EAAE,CACjF,IAAY,CAAC,qBAA4C,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/utils/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAEpD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AACnD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAAA;AAE1D,MAAM,MAAM,QAAQ,GAAG,QAAQ,EAAE,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/livestore",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -28,8 +28,8 @@
28
28
  "default": "./dist/effect/index.js"
29
29
  },
30
30
  "./util": {
31
- "types": "./dist/util.d.ts",
32
- "default": "./dist/util.js"
31
+ "types": "./dist/utils/util.d.ts",
32
+ "default": "./dist/utils/util.js"
33
33
  }
34
34
  },
35
35
  "types": "./dist/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "./dist/effect/index.d.ts"
43
43
  ],
44
44
  "util": [
45
- "./dist/util.d.ts"
45
+ "./dist/utils/util.d.ts"
46
46
  ]
47
47
  }
48
48
  },
@@ -53,22 +53,22 @@
53
53
  "lodash-es": "^4.17.21",
54
54
  "sqlite-esm": "3.42.0-build6",
55
55
  "uuid": "^9.0.1",
56
- "@livestore/utils": "0.0.25",
57
- "effect-db-schema": "0.0.25"
56
+ "@livestore/utils": "0.0.27",
57
+ "effect-db-schema": "0.0.27"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@opentelemetry/sdk-trace-base": "1.18.1",
61
61
  "@tauri-apps/api": "^1.5.1",
62
62
  "@testing-library/react": "^14.1.2",
63
- "@types/lodash-es": "^4.17.11",
64
- "@types/react": "^18.2.37",
65
- "@types/react-dom": "^18.2.15",
63
+ "@types/lodash-es": "^4.17.12",
64
+ "@types/react": "^18.2.39",
65
+ "@types/react-dom": "^18.2.17",
66
66
  "@types/uuid": "^9.0.7",
67
- "jsdom": "^22.1.0",
67
+ "jsdom": "^23.0.1",
68
68
  "react": "^18.2.0",
69
69
  "react-dom": "^18.2.0",
70
- "typescript": "5.2.2",
71
- "vite": "5.0.0",
70
+ "typescript": "5.3.2",
71
+ "vite": "5.0.4",
72
72
  "vitest": "^0.34.6"
73
73
  },
74
74
  "peerDependencies": {
package/src/QueryCache.ts CHANGED
@@ -1,5 +1,5 @@
1
- import BoundMap, { BoundSet } from './bounded-collections.js'
2
- import type { Bindable } from './util.js'
1
+ import BoundMap, { BoundSet } from './utils/bounded-collections.js'
2
+ import type { Bindable } from './utils/util.js'
3
3
 
4
4
  type Opaque<BaseType, BrandType = unknown> = BaseType & {
5
5
  readonly [Symbols.base]: BaseType
@@ -2,8 +2,8 @@ import type * as otel from '@opentelemetry/api'
2
2
  import React from 'react'
3
3
  import initSqlite3Wasm from 'sqlite-esm'
4
4
 
5
- import * as LiveStore from '../../index.js'
6
- import { sql } from '../../index.js'
5
+ import type { LiveStoreContext } from '../../index.js'
6
+ import { createStore, DbSchema, makeSchema, sql } from '../../index.js'
7
7
  import * as LiveStoreReact from '../../react/index.js'
8
8
  import { InMemoryStorage } from '../../storage/in-memory/index.js'
9
9
 
@@ -20,17 +20,17 @@ export type AppState = {
20
20
  filter: Filter
21
21
  }
22
22
 
23
- export const schema = LiveStore.makeSchema({
23
+ export const schema = makeSchema({
24
24
  tables: {
25
- todos: LiveStore.DbSchema.table('todos', {
26
- id: LiveStore.DbSchema.text({ primaryKey: true }),
27
- text: LiveStore.DbSchema.text({ default: '', nullable: false }),
28
- completed: LiveStore.DbSchema.boolean({ default: false, nullable: false }),
25
+ todos: DbSchema.table('todos', {
26
+ id: DbSchema.text({ primaryKey: true }),
27
+ text: DbSchema.text({ default: '', nullable: false }),
28
+ completed: DbSchema.boolean({ default: false, nullable: false }),
29
29
  }),
30
- app: LiveStore.DbSchema.table('app', {
31
- id: LiveStore.DbSchema.text({ primaryKey: true }),
32
- newTodoText: LiveStore.DbSchema.text({ default: '', nullable: true }),
33
- filter: LiveStore.DbSchema.text({ default: 'all', nullable: false }),
30
+ app: DbSchema.table('app', {
31
+ id: DbSchema.text({ primaryKey: true }),
32
+ newTodoText: DbSchema.text({ default: '', nullable: true }),
33
+ filter: DbSchema.text({ default: 'all', nullable: false }),
34
34
  }),
35
35
  },
36
36
  actions: {
@@ -59,8 +59,8 @@ export const makeTodoMvc = async ({
59
59
  otelTracer?: otel.Tracer
60
60
  otelContext?: otel.Context
61
61
  } = {}) => {
62
- const AppComponentSchema = LiveStore.defineComponentStateSchema('UserInfo', {
63
- username: LiveStore.DbSchema.text({ default: '' }),
62
+ const AppComponentSchema = DbSchema.table('UserInfo', {
63
+ username: DbSchema.text({ default: '' }),
64
64
  })
65
65
 
66
66
  const sqlite3 = await initSqlite3Wasm({
@@ -68,7 +68,7 @@ export const makeTodoMvc = async ({
68
68
  printErr: (message) => console.error(`[livestore sqlite] ${message}`),
69
69
  })
70
70
 
71
- const store = await LiveStore.createStore({
71
+ const store = await createStore({
72
72
  schema,
73
73
  loadStorage: () => InMemoryStorage.load(),
74
74
  boot: (db) => db.execute(sql`INSERT OR IGNORE INTO app (id, newTodoText, filter) VALUES ('static', '', 'all');`),
@@ -77,7 +77,7 @@ export const makeTodoMvc = async ({
77
77
  otelRootSpanContext: otelContext,
78
78
  })
79
79
 
80
- const storeContext: LiveStore.LiveStoreContext = { store }
80
+ const storeContext: LiveStoreContext = { store }
81
81
 
82
82
  const wrapper = ({ children }: any) => (
83
83
  <LiveStoreReact.LiveStoreContext.Provider value={storeContext}>{children}</LiveStoreReact.LiveStoreContext.Provider>
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import * as LiveStoreReact from '../../react/index.js'
6
6
  import { querySQL } from '../../reactiveQueries/sql.js'
7
- import { sql } from '../../util.js'
7
+ import { sql } from '../../utils/util.js'
8
8
  import type { Todo } from './fixture.js'
9
9
  import { makeTodoMvc } from './fixture.js'
10
10
 
@@ -29,7 +29,7 @@ describe('useQuery', () => {
29
29
  expect(renderCount).toBe(1)
30
30
 
31
31
  act(() =>
32
- store.applyEvent('RawSql', {
32
+ store.applyEvent('livestore.RawSql', {
33
33
  sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
34
34
  writeTables: ['todos'],
35
35
  }),
@@ -48,12 +48,12 @@ describe('useQuery', () => {
48
48
  const todo1$ = querySQL<Todo>(`select * from todos where id = 't1'`, { label: 'libraryTracksView1' })
49
49
  const todo2$ = querySQL<Todo>(`select * from todos where id = 't2'`, { label: 'libraryTracksView2' })
50
50
 
51
- store.applyEvent('RawSql', {
51
+ store.applyEvent('livestore.RawSql', {
52
52
  sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
53
53
  writeTables: ['todos'],
54
54
  })
55
55
 
56
- store.applyEvent('RawSql', {
56
+ store.applyEvent('livestore.RawSql', {
57
57
  sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t2', 'buy eggs', 0)`,
58
58
  writeTables: ['todos'],
59
59
  })
@@ -73,7 +73,7 @@ describe('useQuery', () => {
73
73
  expect(renderCount).toBe(1)
74
74
 
75
75
  act(() =>
76
- store.applyEvent('RawSql', {
76
+ store.applyEvent('livestore.RawSql', {
77
77
  sql: sql`UPDATE todos SET text = 'buy soy milk' WHERE id = 't1'`,
78
78
  writeTables: ['todos'],
79
79
  }),
@@ -7,7 +7,7 @@ import * as LiveStoreReact from '../../react/index.js'
7
7
  import type { Todo } from './fixture.js'
8
8
  import { makeTodoMvc } from './fixture.js'
9
9
 
10
- describe('useComponentState', () => {
10
+ describe('useRow', () => {
11
11
  it('should update the data based on component key', async () => {
12
12
  let renderCount = 0
13
13
 
@@ -17,10 +17,8 @@ describe('useComponentState', () => {
17
17
  (userId: string) => {
18
18
  renderCount++
19
19
 
20
- return LiveStoreReact.useComponentState({
21
- schema: AppComponentSchema,
22
- componentKey: { name: 'UserInfo', id: userId },
23
- })
20
+ const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId)
21
+ return { state, setState }
24
22
  },
25
23
  { wrapper, initialProps: 'u1' },
26
24
  )
@@ -30,7 +28,7 @@ describe('useComponentState', () => {
30
28
  expect(renderCount).toBe(1)
31
29
 
32
30
  act(() => {
33
- void store.execute(LiveStore.sql`INSERT INTO components__UserInfo (id, username) VALUES ('u2', 'username_u2');`)
31
+ void store.execute(LiveStore.sql`INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2');`)
34
32
  })
35
33
 
36
34
  rerender('u2')
@@ -49,10 +47,8 @@ describe('useComponentState', () => {
49
47
  (userId: string) => {
50
48
  renderCount++
51
49
 
52
- return LiveStoreReact.useComponentState({
53
- schema: AppComponentSchema,
54
- componentKey: { name: 'UserInfo', id: userId },
55
- })
50
+ const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId)
51
+ return { state, setState }
56
52
  },
57
53
  { wrapper, initialProps: 'u1' },
58
54
  )
@@ -77,10 +73,8 @@ describe('useComponentState', () => {
77
73
  (userId: string) => {
78
74
  renderCount++
79
75
 
80
- return LiveStoreReact.useComponentState({
81
- schema: AppComponentSchema,
82
- componentKey: { name: 'UserInfo', id: userId },
83
- })
76
+ const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId)
77
+ return { state, setState }
84
78
  },
85
79
  { wrapper, initialProps: 'u1' },
86
80
  )
@@ -92,7 +86,7 @@ describe('useComponentState', () => {
92
86
  act(() => result.current.setState.username('username_u1_hello'))
93
87
 
94
88
  act(() => {
95
- void store.execute(LiveStore.sql`UPDATE components__UserInfo SET username = 'username_u1_hello' WHERE id = 'u1';`)
89
+ void store.execute(LiveStore.sql`UPDATE UserInfo SET username = 'username_u1_hello' WHERE id = 'u1';`)
96
90
  })
97
91
 
98
92
  expect(result.current.state.id).toBe('u1')
@@ -105,18 +99,20 @@ describe('useComponentState', () => {
105
99
 
106
100
  const { wrapper, store } = await makeTodoMvc()
107
101
 
108
- const AppRouterSchema = LiveStore.defineComponentStateSchema('AppRouter', {
109
- currentTaskId: LiveStore.DbSchema.text({ default: null, nullable: true }),
110
- })
111
-
112
- const componentKey = { name: 'AppRouter', id: 'static' }
102
+ const AppRouterSchema = LiveStore.DbSchema.table(
103
+ 'AppRouter',
104
+ {
105
+ currentTaskId: LiveStore.DbSchema.text({ default: null, nullable: true }),
106
+ },
107
+ { isSingleton: true },
108
+ )
113
109
 
114
110
  let appRouterRenderCount = 0
115
- let globalSetState: LiveStoreReact.Setters<LiveStoreReact.GetStateTypeEncoded<typeof AppRouterSchema>> | undefined
111
+ let globalSetState: LiveStoreReact.StateSetters<typeof AppRouterSchema> | undefined
116
112
  const AppRouter: React.FC = () => {
117
113
  appRouterRenderCount++
118
114
 
119
- const { state, setState } = LiveStoreReact.useComponentState({ schema: AppRouterSchema, componentKey })
115
+ const [state, setState] = LiveStoreReact.useRow(AppRouterSchema)
120
116
 
121
117
  globalSetState = setState
122
118
 
@@ -155,7 +151,7 @@ describe('useComponentState', () => {
155
151
  expect(appRouterRenderCount).toBe(1)
156
152
 
157
153
  act(() =>
158
- store.applyEvent('RawSql', {
154
+ store.applyEvent('livestore.RawSql', {
159
155
  sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`,
160
156
  writeTables: ['todos'],
161
157
  }),
@@ -176,22 +172,23 @@ describe('useComponentState', () => {
176
172
  act(() =>
177
173
  store.applyEvents([
178
174
  {
179
- eventType: 'RawSql',
175
+ eventType: 'livestore.RawSql',
180
176
  args: {
181
177
  sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t2', 'buy eggs', 0);`,
182
178
  writeTables: ['todos'],
183
179
  },
184
180
  },
185
181
  {
186
- eventType: 'updateComponentState',
182
+ eventType: 'livestore.UpdateComponentState',
187
183
  args: {
188
- componentKey: { _tag: 'custom', componentName: 'AppRouter', id: 'static' },
184
+ id: 'singleton',
189
185
  columnNames: ['currentTaskId'],
190
- currentTaskId: 't2',
186
+ tableName: AppRouterSchema.schema.name,
187
+ bindValues: { currentTaskId: 't2' },
191
188
  },
192
189
  },
193
190
  {
194
- eventType: 'RawSql',
191
+ eventType: 'livestore.RawSql',
195
192
  args: {
196
193
  sql: LiveStore.sql`INSERT INTO todos (id, text, completed) VALUES ('t3', 'buy bread', 0);`,
197
194
  writeTables: ['todos'],
@@ -204,3 +201,5 @@ describe('useComponentState', () => {
204
201
  expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t2"')
205
202
  })
206
203
  })
204
+
205
+ // TODO add otel tests
@@ -43,3 +43,37 @@ Error
43
43
  }
44
44
  `)
45
45
  })
46
+
47
+ it('Tracklist_ stacktrace', async () => {
48
+ const stackTrace = `\
49
+ stack Error
50
+ at https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1701368568351:19:23
51
+ at mountMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-YKTDXTVC.js?v=86daed82:12817:27)
52
+ at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-YKTDXTVC.js?v=86daed82:13141:24)
53
+ at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-7P4K3U7O.js?v=86daed82:1094:29)
54
+ at useQueryRef (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1701368568351:16:29)
55
+ at Module.useQuery (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1701368568351:13:36)
56
+ at Tracklist_ (https://localhost:8081/src/components/Tracklist/Tracklist.tsx?t=1701368568351:148:44)
57
+ at renderWithHooks (https://localhost:8081/node_modules/.vite-web/deps/chunk-YKTDXTVC.js?v=86daed82:12171:26)
58
+ at mountIndeterminateComponent (https://localhost:8081/node_modules/.vite-web/deps/chunk-YKTDXTVC.js?v=86daed82:14921:21)
59
+ at beginWork (https://localhost:8081/node_modules/.vite-web/deps/chunk-YKTDXTVC.js?v=86daed82:15902:22)
60
+ `
61
+
62
+ const stackInfo = extractStackInfoFromStackTrace(stackTrace)
63
+ // Replacing file paths for snapshot testing as they are not stable
64
+ stackInfo.frames.forEach((_) => (_.filePath = '__REPLACED_FOR_SNAPSHOT__'))
65
+ expect(stackInfo).toMatchInlineSnapshot(`
66
+ {
67
+ "frames": [
68
+ {
69
+ "filePath": "__REPLACED_FOR_SNAPSHOT__",
70
+ "name": "Tracklist_",
71
+ },
72
+ {
73
+ "filePath": "__REPLACED_FOR_SNAPSHOT__",
74
+ "name": "useQuery",
75
+ },
76
+ ],
77
+ }
78
+ `)
79
+ })
@@ -33,7 +33,7 @@ describe('otel', () => {
33
33
  const query = querySQL(`select * from todos`, { queriedTables: new Set(['todos']) })
34
34
  expect(query.run()).toMatchInlineSnapshot('[]')
35
35
 
36
- store.applyEvent('RawSql', {
36
+ store.applyEvent('livestore.RawSql', {
37
37
  sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`,
38
38
  writeTables: ['todos'],
39
39
  })
@@ -92,7 +92,7 @@ describe('otel', () => {
92
92
  {
93
93
  "_name": "LiveStore:applyEventWithoutRefresh",
94
94
  "attributes": {
95
- "livestore.actionType": "RawSql",
95
+ "livestore.actionType": "livestore.RawSql",
96
96
  "livestore.args": "{
97
97
  \\"sql\\": \\"INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);\\",
98
98
  \\"writeTables\\": [
@@ -175,7 +175,7 @@ describe('otel', () => {
175
175
  }
176
176
  `)
177
177
 
178
- store.applyEvent('RawSql', {
178
+ store.applyEvent('livestore.RawSql', {
179
179
  sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`,
180
180
  writeTables: ['todos'],
181
181
  })
@@ -232,7 +232,7 @@ describe('otel', () => {
232
232
  {
233
233
  "_name": "LiveStore:applyEventWithoutRefresh",
234
234
  "attributes": {
235
- "livestore.actionType": "RawSql",
235
+ "livestore.actionType": "livestore.RawSql",
236
236
  "livestore.args": "{
237
237
  \\"sql\\": \\"INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);\\",
238
238
  \\"writeTables\\": [
@@ -5,7 +5,7 @@ import type { GraphQLSchema } from 'graphql'
5
5
  import initSqlite3Wasm from 'sqlite-esm'
6
6
 
7
7
  import type { InMemoryDatabase } from '../inMemoryDatabase.js'
8
- import type { Schema } from '../schema.js'
8
+ import type { LiveStoreSchema } from '../schema/index.js'
9
9
  import type { StorageInit } from '../storage/index.js'
10
10
  import type { BaseGraphQLContext, GraphQLOptions, LiveStoreQuery, Store } from '../store.js'
11
11
  import { createStore } from '../store.js'
@@ -25,7 +25,7 @@ export type LiveStoreContext = {
25
25
  export type QueryDefinition = (store: Store) => LiveStoreQuery
26
26
 
27
27
  export type LiveStoreCreateStoreOptions<GraphQLContext extends BaseGraphQLContext> = {
28
- schema: Schema
28
+ schema: LiveStoreSchema
29
29
  loadStorage: () => StorageInit | Promise<StorageInit>
30
30
  graphQLOptions?: GraphQLOptions<GraphQLContext>
31
31
  otelTracer?: otel.Tracer
@@ -43,7 +43,7 @@ export const DeferredStoreContext = Context.Tag<DeferredStoreContext>(
43
43
  // export const DeferredStoreContext = Effect.cached(Effect.flatMap(StoreContext, (_) => Effect.succeed(_)))
44
44
 
45
45
  export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
46
- schema: Schema
46
+ schema: LiveStoreSchema
47
47
  loadStorage: () => StorageInit | Promise<StorageInit>
48
48
  graphQLOptions?: {
49
49
  schema: Effect.Effect<otel.Tracer, never, GraphQLSchema>
@@ -55,9 +55,9 @@ export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
55
55
  export const LiveStoreContextLayer = <GraphQLContext extends BaseGraphQLContext>(
56
56
  props: LiveStoreContextProps<GraphQLContext>,
57
57
  ): Layer.Layer<otel.Tracer, never, LiveStoreContext> =>
58
- Layer.provide(
59
- LiveStoreContextDeferred,
60
- Layer.scoped(LiveStoreContext, makeLiveStoreContext(props)).pipe(Layer.withSpan('LiveStore')),
58
+ Layer.scoped(LiveStoreContext, makeLiveStoreContext(props)).pipe(
59
+ Layer.withSpan('LiveStore'),
60
+ Layer.provide(LiveStoreContextDeferred),
61
61
  )
62
62
 
63
63
  export const LiveStoreContextDeferred = Layer.effect(DeferredStoreContext, Deferred.make<never, LiveStoreContext>())
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * LiveStore currently relies on some global state in order to simplify the end-user API.
4
+ * This however also has the downside that LiveStore can't be used in multiple instances in the same app.
5
+ * It could possibly also lead to some other problems.
6
+ *
7
+ * We should find some better way to do this and ideally remove this global state.
8
+ *
9
+ * Another approach could be to use the global state by default but provide an additional way to let the user
10
+ * explicitly pass instances of state below into the LiveStore constructors.
11
+ *
12
+ */
13
+
14
+ import ReactDOM from 'react-dom'
15
+
16
+ import { ReactiveGraph } from './reactive.js'
17
+ import type { DbContext } from './reactiveQueries/base-class.js'
18
+ import type { TableDef } from './schema/table-def.js'
19
+ import type { QueryDebugInfo, RefreshReason } from './store.js'
20
+
21
+ export const dbGraph = new ReactiveGraph<RefreshReason, QueryDebugInfo, DbContext>({
22
+ // TODO also find a better way to only use this effects wrapper when used in a React app
23
+ effectsWrapper: (run) => ReactDOM.unstable_batchedUpdates(() => run()),
24
+ })
25
+
26
+ export const dynamicallyRegisteredTables: Map<string, TableDef> = new Map()
@@ -4,12 +4,12 @@ import { shouldNeverHappen } from '@livestore/utils'
4
4
  import type * as otel from '@opentelemetry/api'
5
5
  import type * as Sqlite from 'sqlite-esm'
6
6
 
7
- import BoundMap, { BoundArray } from './bounded-collections.js'
8
7
  // import { EVENTS_TABLE_NAME } from './events.js'
9
8
  import { sql } from './index.js'
10
- import { getDurationMsFromSpan, getStartTimeHighResFromSpan } from './otel.js'
11
9
  import QueryCache from './QueryCache.js'
12
- import type { Bindable, PreparedBindValues } from './util.js'
10
+ import BoundMap, { BoundArray } from './utils/bounded-collections.js'
11
+ import { getDurationMsFromSpan, getStartTimeHighResFromSpan } from './utils/otel.js'
12
+ import type { Bindable, PreparedBindValues } from './utils/util.js'
13
13
 
14
14
  type DatabaseWithCAPI = Sqlite.Database & { capi: Sqlite.CAPI }
15
15
 
@@ -135,9 +135,11 @@ export class InMemoryDatabase {
135
135
  execute(
136
136
  query: string,
137
137
  bindValues?: PreparedBindValues,
138
- writeTables?: string[],
138
+ writeTables?: ReadonlyArray<string>,
139
139
  options?: { hasNoEffects?: boolean; otelContext?: otel.Context },
140
140
  ): { durationMs: number } {
141
+ // console.debug('in-memory-db:execute', query, bindValues)
142
+
141
143
  return this.otelTracer.startActiveSpan(
142
144
  'livestore.in-memory-db:execute',
143
145
  // TODO truncate query string