@livestore/livestore 0.4.0-dev.1 → 0.4.0-dev.11

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 (61) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/effect/LiveStore.d.ts.map +1 -1
  3. package/dist/effect/LiveStore.js +2 -4
  4. package/dist/effect/LiveStore.js.map +1 -1
  5. package/dist/live-queries/base-class.d.ts.map +1 -1
  6. package/dist/live-queries/base-class.js.map +1 -1
  7. package/dist/live-queries/db-query.d.ts.map +1 -1
  8. package/dist/live-queries/db-query.js +7 -4
  9. package/dist/live-queries/db-query.js.map +1 -1
  10. package/dist/live-queries/db-query.test.js +53 -24
  11. package/dist/live-queries/db-query.test.js.map +1 -1
  12. package/dist/mod.d.ts +2 -2
  13. package/dist/mod.d.ts.map +1 -1
  14. package/dist/mod.js +1 -1
  15. package/dist/mod.js.map +1 -1
  16. package/dist/reactive.d.ts +10 -10
  17. package/dist/reactive.d.ts.map +1 -1
  18. package/dist/reactive.js +36 -27
  19. package/dist/reactive.js.map +1 -1
  20. package/dist/reactive.test.js +115 -0
  21. package/dist/reactive.test.js.map +1 -1
  22. package/dist/store/create-store.d.ts.map +1 -1
  23. package/dist/store/create-store.js +3 -3
  24. package/dist/store/create-store.js.map +1 -1
  25. package/dist/store/store-types.d.ts +13 -2
  26. package/dist/store/store-types.d.ts.map +1 -1
  27. package/dist/store/store-types.js.map +1 -1
  28. package/dist/store/store.d.ts +45 -29
  29. package/dist/store/store.d.ts.map +1 -1
  30. package/dist/store/store.js +165 -100
  31. package/dist/store/store.js.map +1 -1
  32. package/dist/utils/dev.d.ts +3 -0
  33. package/dist/utils/dev.d.ts.map +1 -1
  34. package/dist/utils/dev.js.map +1 -1
  35. package/dist/utils/tests/fixture.d.ts.map +1 -1
  36. package/dist/utils/tests/fixture.js +2 -1
  37. package/dist/utils/tests/fixture.js.map +1 -1
  38. package/dist/utils/tests/otel.d.ts +15 -14
  39. package/dist/utils/tests/otel.d.ts.map +1 -1
  40. package/dist/utils/tests/otel.js +20 -15
  41. package/dist/utils/tests/otel.js.map +1 -1
  42. package/package.json +7 -7
  43. package/src/ambient.d.ts +3 -3
  44. package/src/effect/LiveStore.ts +2 -4
  45. package/src/live-queries/__snapshots__/db-query.test.ts.snap +354 -130
  46. package/src/live-queries/base-class.ts +6 -3
  47. package/src/live-queries/db-query.test.ts +70 -24
  48. package/src/live-queries/db-query.ts +7 -4
  49. package/src/mod.ts +10 -1
  50. package/src/reactive.test.ts +150 -1
  51. package/src/reactive.ts +47 -39
  52. package/src/store/create-store.ts +12 -4
  53. package/src/store/store-types.ts +23 -2
  54. package/src/store/store.ts +262 -193
  55. package/src/utils/dev.ts +5 -0
  56. package/src/utils/tests/fixture.ts +2 -1
  57. package/src/utils/tests/otel.ts +31 -20
  58. package/dist/store/store-shutdown.test.d.ts +0 -2
  59. package/dist/store/store-shutdown.test.d.ts.map +0 -1
  60. package/dist/store/store-shutdown.test.js +0 -103
  61. package/dist/store/store-shutdown.test.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
3
+ exports[`otel > QueryBuilder subscription - async iterator 1`] = `
4
4
  {
5
5
  "_name": "createStore",
6
6
  "attributes": {
@@ -40,25 +40,93 @@ exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
40
40
  },
41
41
  {
42
42
  "_name": "LiveStore:commits",
43
- "children": [
44
- {
45
- "_name": "LiveStore:commit",
46
- "attributes": {
47
- "livestore.eventTags": [
48
- "todo.created",
43
+ },
44
+ {
45
+ "_name": "LiveStore:queries",
46
+ },
47
+ ],
48
+ }
49
+ `;
50
+
51
+ exports[`otel > QueryBuilder subscription - async iterator 2`] = `
52
+ [
53
+ {
54
+ "_name": "LiveStore:commit",
55
+ "attributes": {
56
+ "livestore.eventTags": "[
57
+ "todo.created"
58
+ ]",
59
+ "livestore.eventsCount": 1,
60
+ },
61
+ "children": [
62
+ {
63
+ "_name": "client-session-sync-processor:push",
64
+ "attributes": {
65
+ "batchSize": 1,
66
+ "eventCounts": "{
67
+ "todo.created": 1
68
+ }",
69
+ "mergeResultTag": "advance",
70
+ },
71
+ "children": [
72
+ {
73
+ "_name": "client-session-sync-processor:materialize-event",
74
+ "children": [
75
+ {
76
+ "_name": "livestore.in-memory-db:execute",
77
+ "attributes": {
78
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
79
+ },
80
+ },
49
81
  ],
50
- "livestore.eventsCount": 1,
51
82
  },
52
- "children": [
53
- {
54
- "_name": "livestore.in-memory-db:execute",
55
- "attributes": {
56
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
57
- },
58
- },
59
- ],
60
- },
61
- ],
83
+ ],
84
+ },
85
+ ],
86
+ },
87
+ ]
88
+ `;
89
+
90
+ exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
91
+ {
92
+ "_name": "createStore",
93
+ "attributes": {
94
+ "debugInstanceId": "test",
95
+ "storeId": "default",
96
+ },
97
+ "children": [
98
+ {
99
+ "_name": "livestore.in-memory-db:execute",
100
+ "attributes": {
101
+ "sql.query": "
102
+ PRAGMA page_size=32768;
103
+ PRAGMA cache_size=10000;
104
+ PRAGMA synchronous='OFF';
105
+ PRAGMA temp_store='MEMORY';
106
+ PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
107
+ ",
108
+ },
109
+ },
110
+ {
111
+ "_name": "@livestore/common:LeaderSyncProcessor:push",
112
+ "attributes": {
113
+ "batch": "undefined",
114
+ "batchSize": 1,
115
+ },
116
+ },
117
+ {
118
+ "_name": "client-session-sync-processor:pull",
119
+ "attributes": {
120
+ "code.stacktrace": "<STACKTRACE>",
121
+ "span.label": "⚠︎ Interrupted",
122
+ "status.interrupted": true,
123
+ },
124
+ },
125
+ {
126
+ "_name": "LiveStore:sync",
127
+ },
128
+ {
129
+ "_name": "LiveStore:commits",
62
130
  },
63
131
  {
64
132
  "_name": "LiveStore:queries",
@@ -113,6 +181,45 @@ exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
113
181
  }
114
182
  `;
115
183
 
184
+ exports[`otel > QueryBuilder subscription - basic functionality 2`] = `
185
+ [
186
+ {
187
+ "_name": "LiveStore:commit",
188
+ "attributes": {
189
+ "livestore.eventTags": "[
190
+ "todo.created"
191
+ ]",
192
+ "livestore.eventsCount": 1,
193
+ },
194
+ "children": [
195
+ {
196
+ "_name": "client-session-sync-processor:push",
197
+ "attributes": {
198
+ "batchSize": 1,
199
+ "eventCounts": "{
200
+ "todo.created": 1
201
+ }",
202
+ "mergeResultTag": "advance",
203
+ },
204
+ "children": [
205
+ {
206
+ "_name": "client-session-sync-processor:materialize-event",
207
+ "children": [
208
+ {
209
+ "_name": "livestore.in-memory-db:execute",
210
+ "attributes": {
211
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
212
+ },
213
+ },
214
+ ],
215
+ },
216
+ ],
217
+ },
218
+ ],
219
+ },
220
+ ]
221
+ `;
222
+
116
223
  exports[`otel > QueryBuilder subscription - direct table subscription 1`] = `
117
224
  {
118
225
  "_name": "createStore",
@@ -153,25 +260,6 @@ exports[`otel > QueryBuilder subscription - direct table subscription 1`] = `
153
260
  },
154
261
  {
155
262
  "_name": "LiveStore:commits",
156
- "children": [
157
- {
158
- "_name": "LiveStore:commit",
159
- "attributes": {
160
- "livestore.eventTags": [
161
- "todo.created",
162
- ],
163
- "livestore.eventsCount": 1,
164
- },
165
- "children": [
166
- {
167
- "_name": "livestore.in-memory-db:execute",
168
- "attributes": {
169
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
170
- },
171
- },
172
- ],
173
- },
174
- ],
175
263
  },
176
264
  {
177
265
  "_name": "LiveStore:queries",
@@ -226,6 +314,45 @@ exports[`otel > QueryBuilder subscription - direct table subscription 1`] = `
226
314
  }
227
315
  `;
228
316
 
317
+ exports[`otel > QueryBuilder subscription - direct table subscription 2`] = `
318
+ [
319
+ {
320
+ "_name": "LiveStore:commit",
321
+ "attributes": {
322
+ "livestore.eventTags": "[
323
+ "todo.created"
324
+ ]",
325
+ "livestore.eventsCount": 1,
326
+ },
327
+ "children": [
328
+ {
329
+ "_name": "client-session-sync-processor:push",
330
+ "attributes": {
331
+ "batchSize": 1,
332
+ "eventCounts": "{
333
+ "todo.created": 1
334
+ }",
335
+ "mergeResultTag": "advance",
336
+ },
337
+ "children": [
338
+ {
339
+ "_name": "client-session-sync-processor:materialize-event",
340
+ "children": [
341
+ {
342
+ "_name": "livestore.in-memory-db:execute",
343
+ "attributes": {
344
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
345
+ },
346
+ },
347
+ ],
348
+ },
349
+ ],
350
+ },
351
+ ],
352
+ },
353
+ ]
354
+ `;
355
+
229
356
  exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
230
357
  {
231
358
  "_name": "createStore",
@@ -273,42 +400,6 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
273
400
  },
274
401
  {
275
402
  "_name": "LiveStore:commits",
276
- "children": [
277
- {
278
- "_name": "LiveStore:commit",
279
- "attributes": {
280
- "livestore.eventTags": [
281
- "todo.created",
282
- ],
283
- "livestore.eventsCount": 1,
284
- },
285
- "children": [
286
- {
287
- "_name": "livestore.in-memory-db:execute",
288
- "attributes": {
289
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
290
- },
291
- },
292
- ],
293
- },
294
- {
295
- "_name": "LiveStore:commit",
296
- "attributes": {
297
- "livestore.eventTags": [
298
- "todo.created",
299
- ],
300
- "livestore.eventsCount": 1,
301
- },
302
- "children": [
303
- {
304
- "_name": "livestore.in-memory-db:execute",
305
- "attributes": {
306
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
307
- },
308
- },
309
- ],
310
- },
311
- ],
312
403
  },
313
404
  {
314
405
  "_name": "LiveStore:queries",
@@ -389,6 +480,79 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
389
480
  }
390
481
  `;
391
482
 
483
+ exports[`otel > QueryBuilder subscription - unsubscribe functionality 2`] = `
484
+ [
485
+ {
486
+ "_name": "LiveStore:commit",
487
+ "attributes": {
488
+ "livestore.eventTags": "[
489
+ "todo.created"
490
+ ]",
491
+ "livestore.eventsCount": 1,
492
+ },
493
+ "children": [
494
+ {
495
+ "_name": "client-session-sync-processor:push",
496
+ "attributes": {
497
+ "batchSize": 1,
498
+ "eventCounts": "{
499
+ "todo.created": 1
500
+ }",
501
+ "mergeResultTag": "advance",
502
+ },
503
+ "children": [
504
+ {
505
+ "_name": "client-session-sync-processor:materialize-event",
506
+ "children": [
507
+ {
508
+ "_name": "livestore.in-memory-db:execute",
509
+ "attributes": {
510
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
511
+ },
512
+ },
513
+ ],
514
+ },
515
+ ],
516
+ },
517
+ ],
518
+ },
519
+ {
520
+ "_name": "LiveStore:commit",
521
+ "attributes": {
522
+ "livestore.eventTags": "[
523
+ "todo.created"
524
+ ]",
525
+ "livestore.eventsCount": 1,
526
+ },
527
+ "children": [
528
+ {
529
+ "_name": "client-session-sync-processor:push",
530
+ "attributes": {
531
+ "batchSize": 1,
532
+ "eventCounts": "{
533
+ "todo.created": 1
534
+ }",
535
+ "mergeResultTag": "advance",
536
+ },
537
+ "children": [
538
+ {
539
+ "_name": "client-session-sync-processor:materialize-event",
540
+ "children": [
541
+ {
542
+ "_name": "livestore.in-memory-db:execute",
543
+ "attributes": {
544
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
545
+ },
546
+ },
547
+ ],
548
+ },
549
+ ],
550
+ },
551
+ ],
552
+ },
553
+ ]
554
+ `;
555
+
392
556
  exports[`otel > otel 3`] = `
393
557
  {
394
558
  "_name": "createStore",
@@ -429,25 +593,6 @@ exports[`otel > otel 3`] = `
429
593
  },
430
594
  {
431
595
  "_name": "LiveStore:commits",
432
- "children": [
433
- {
434
- "_name": "LiveStore:commit",
435
- "attributes": {
436
- "livestore.eventTags": [
437
- "todo.created",
438
- ],
439
- "livestore.eventsCount": 1,
440
- },
441
- "children": [
442
- {
443
- "_name": "livestore.in-memory-db:execute",
444
- "attributes": {
445
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
446
- },
447
- },
448
- ],
449
- },
450
- ],
451
596
  },
452
597
  {
453
598
  "_name": "LiveStore:queries",
@@ -492,6 +637,45 @@ exports[`otel > otel 3`] = `
492
637
  }
493
638
  `;
494
639
 
640
+ exports[`otel > otel 4`] = `
641
+ [
642
+ {
643
+ "_name": "LiveStore:commit",
644
+ "attributes": {
645
+ "livestore.eventTags": "[
646
+ "todo.created"
647
+ ]",
648
+ "livestore.eventsCount": 1,
649
+ },
650
+ "children": [
651
+ {
652
+ "_name": "client-session-sync-processor:push",
653
+ "attributes": {
654
+ "batchSize": 1,
655
+ "eventCounts": "{
656
+ "todo.created": 1
657
+ }",
658
+ "mergeResultTag": "advance",
659
+ },
660
+ "children": [
661
+ {
662
+ "_name": "client-session-sync-processor:materialize-event",
663
+ "children": [
664
+ {
665
+ "_name": "livestore.in-memory-db:execute",
666
+ "attributes": {
667
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
668
+ },
669
+ },
670
+ ],
671
+ },
672
+ ],
673
+ },
674
+ ],
675
+ },
676
+ ]
677
+ `;
678
+
495
679
  exports[`otel > with thunks 1`] = `
496
680
  {
497
681
  "atoms": [
@@ -704,25 +888,6 @@ exports[`otel > with thunks 7`] = `
704
888
  },
705
889
  {
706
890
  "_name": "LiveStore:commits",
707
- "children": [
708
- {
709
- "_name": "LiveStore:commit",
710
- "attributes": {
711
- "livestore.eventTags": [
712
- "todo.created",
713
- ],
714
- "livestore.eventsCount": 1,
715
- },
716
- "children": [
717
- {
718
- "_name": "livestore.in-memory-db:execute",
719
- "attributes": {
720
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
721
- },
722
- },
723
- ],
724
- },
725
- ],
726
891
  },
727
892
  {
728
893
  "_name": "LiveStore:queries",
@@ -773,6 +938,45 @@ exports[`otel > with thunks 7`] = `
773
938
  }
774
939
  `;
775
940
 
941
+ exports[`otel > with thunks 8`] = `
942
+ [
943
+ {
944
+ "_name": "LiveStore:commit",
945
+ "attributes": {
946
+ "livestore.eventTags": "[
947
+ "todo.created"
948
+ ]",
949
+ "livestore.eventsCount": 1,
950
+ },
951
+ "children": [
952
+ {
953
+ "_name": "client-session-sync-processor:push",
954
+ "attributes": {
955
+ "batchSize": 1,
956
+ "eventCounts": "{
957
+ "todo.created": 1
958
+ }",
959
+ "mergeResultTag": "advance",
960
+ },
961
+ "children": [
962
+ {
963
+ "_name": "client-session-sync-processor:materialize-event",
964
+ "children": [
965
+ {
966
+ "_name": "livestore.in-memory-db:execute",
967
+ "attributes": {
968
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
969
+ },
970
+ },
971
+ ],
972
+ },
973
+ ],
974
+ },
975
+ ],
976
+ },
977
+ ]
978
+ `;
979
+
776
980
  exports[`otel > with thunks with query builder and without labels 3`] = `
777
981
  {
778
982
  "_name": "createStore",
@@ -813,25 +1017,6 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
813
1017
  },
814
1018
  {
815
1019
  "_name": "LiveStore:commits",
816
- "children": [
817
- {
818
- "_name": "LiveStore:commit",
819
- "attributes": {
820
- "livestore.eventTags": [
821
- "todo.created",
822
- ],
823
- "livestore.eventsCount": 1,
824
- },
825
- "children": [
826
- {
827
- "_name": "livestore.in-memory-db:execute",
828
- "attributes": {
829
- "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
830
- },
831
- },
832
- ],
833
- },
834
- ],
835
1020
  },
836
1021
  {
837
1022
  "_name": "LiveStore:queries",
@@ -881,3 +1066,42 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
881
1066
  ],
882
1067
  }
883
1068
  `;
1069
+
1070
+ exports[`otel > with thunks with query builder and without labels 4`] = `
1071
+ [
1072
+ {
1073
+ "_name": "LiveStore:commit",
1074
+ "attributes": {
1075
+ "livestore.eventTags": "[
1076
+ "todo.created"
1077
+ ]",
1078
+ "livestore.eventsCount": 1,
1079
+ },
1080
+ "children": [
1081
+ {
1082
+ "_name": "client-session-sync-processor:push",
1083
+ "attributes": {
1084
+ "batchSize": 1,
1085
+ "eventCounts": "{
1086
+ "todo.created": 1
1087
+ }",
1088
+ "mergeResultTag": "advance",
1089
+ },
1090
+ "children": [
1091
+ {
1092
+ "_name": "client-session-sync-processor:materialize-event",
1093
+ "children": [
1094
+ {
1095
+ "_name": "livestore.in-memory-db:execute",
1096
+ "attributes": {
1097
+ "sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
1098
+ },
1099
+ },
1100
+ ],
1101
+ },
1102
+ ],
1103
+ },
1104
+ ],
1105
+ },
1106
+ ]
1107
+ `;
@@ -166,10 +166,13 @@ export abstract class LiveStoreQueryBase<TResult> implements LiveQuery<TResult>
166
166
 
167
167
  // subscribe = (
168
168
  // onNewValue: (value: TResult) => void,
169
- // onUnsubsubscribe?: () => void,
170
- // options?: { label?: string; otelContext?: otel.Context } | undefined,
169
+ // options?: {
170
+ // label?: string
171
+ // otelContext?: otel.Context
172
+ // onUnsubsubscribe?: () => void
173
+ // },
171
174
  // ): (() => void) =>
172
- // this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
175
+ // this.reactivityGraph.context?.store.subscribe(this, onNewValue, options) ??
173
176
  // RG.throwContextNotSetError(this.reactivityGraph)
174
177
  }
175
178