@livestore/common 0.0.0-snapshot-2b8a9de3ec1a701aca891ebc2c98eb328274ae9e → 0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46

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 (287) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/__tests__/fixture.d.ts +83 -221
  3. package/dist/__tests__/fixture.d.ts.map +1 -1
  4. package/dist/__tests__/fixture.js +33 -11
  5. package/dist/__tests__/fixture.js.map +1 -1
  6. package/dist/adapter-types.d.ts +36 -22
  7. package/dist/adapter-types.d.ts.map +1 -1
  8. package/dist/adapter-types.js +20 -8
  9. package/dist/adapter-types.js.map +1 -1
  10. package/dist/debug-info.d.ts.map +1 -1
  11. package/dist/debug-info.js +1 -0
  12. package/dist/debug-info.js.map +1 -1
  13. package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
  14. package/dist/devtools/devtools-messages-common.d.ts +13 -6
  15. package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
  16. package/dist/devtools/devtools-messages-common.js +6 -0
  17. package/dist/devtools/devtools-messages-common.js.map +1 -1
  18. package/dist/devtools/devtools-messages-leader.d.ts +46 -46
  19. package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
  20. package/dist/devtools/devtools-messages-leader.js +12 -13
  21. package/dist/devtools/devtools-messages-leader.js.map +1 -1
  22. package/dist/index.d.ts +2 -5
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -5
  25. package/dist/index.js.map +1 -1
  26. package/dist/leader-thread/LeaderSyncProcessor.d.ts +34 -12
  27. package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
  28. package/dist/leader-thread/LeaderSyncProcessor.js +284 -226
  29. package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
  30. package/dist/leader-thread/apply-event.d.ts +16 -0
  31. package/dist/leader-thread/apply-event.d.ts.map +1 -0
  32. package/dist/leader-thread/apply-event.js +122 -0
  33. package/dist/leader-thread/apply-event.js.map +1 -0
  34. package/dist/leader-thread/eventlog.d.ts +27 -0
  35. package/dist/leader-thread/eventlog.d.ts.map +1 -0
  36. package/dist/leader-thread/eventlog.js +123 -0
  37. package/dist/leader-thread/eventlog.js.map +1 -0
  38. package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
  39. package/dist/leader-thread/leader-worker-devtools.js +22 -23
  40. package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
  41. package/dist/leader-thread/make-leader-thread-layer.d.ts +16 -4
  42. package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
  43. package/dist/leader-thread/make-leader-thread-layer.js +36 -41
  44. package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
  45. package/dist/leader-thread/mod.d.ts +1 -1
  46. package/dist/leader-thread/mod.d.ts.map +1 -1
  47. package/dist/leader-thread/mod.js +1 -1
  48. package/dist/leader-thread/mod.js.map +1 -1
  49. package/dist/leader-thread/recreate-db.d.ts.map +1 -1
  50. package/dist/leader-thread/recreate-db.js +7 -7
  51. package/dist/leader-thread/recreate-db.js.map +1 -1
  52. package/dist/leader-thread/types.d.ts +40 -25
  53. package/dist/leader-thread/types.d.ts.map +1 -1
  54. package/dist/leader-thread/types.js.map +1 -1
  55. package/dist/materializer-helper.d.ts +23 -0
  56. package/dist/materializer-helper.d.ts.map +1 -0
  57. package/dist/materializer-helper.js +70 -0
  58. package/dist/materializer-helper.js.map +1 -0
  59. package/dist/query-builder/api.d.ts +55 -50
  60. package/dist/query-builder/api.d.ts.map +1 -1
  61. package/dist/query-builder/api.js +3 -5
  62. package/dist/query-builder/api.js.map +1 -1
  63. package/dist/query-builder/astToSql.d.ts.map +1 -1
  64. package/dist/query-builder/astToSql.js +59 -37
  65. package/dist/query-builder/astToSql.js.map +1 -1
  66. package/dist/query-builder/impl.d.ts +2 -3
  67. package/dist/query-builder/impl.d.ts.map +1 -1
  68. package/dist/query-builder/impl.js +47 -43
  69. package/dist/query-builder/impl.js.map +1 -1
  70. package/dist/query-builder/impl.test.d.ts +86 -1
  71. package/dist/query-builder/impl.test.d.ts.map +1 -1
  72. package/dist/query-builder/impl.test.js +223 -36
  73. package/dist/query-builder/impl.test.js.map +1 -1
  74. package/dist/rehydrate-from-eventlog.d.ts +15 -0
  75. package/dist/rehydrate-from-eventlog.d.ts.map +1 -0
  76. package/dist/{rehydrate-from-mutationlog.js → rehydrate-from-eventlog.js} +27 -28
  77. package/dist/rehydrate-from-eventlog.js.map +1 -0
  78. package/dist/schema/EventDef.d.ts +136 -0
  79. package/dist/schema/EventDef.d.ts.map +1 -0
  80. package/dist/schema/EventDef.js +58 -0
  81. package/dist/schema/EventDef.js.map +1 -0
  82. package/dist/schema/EventId.d.ts +10 -1
  83. package/dist/schema/EventId.d.ts.map +1 -1
  84. package/dist/schema/EventId.js +24 -3
  85. package/dist/schema/EventId.js.map +1 -1
  86. package/dist/schema/LiveStoreEvent.d.ts +255 -0
  87. package/dist/schema/LiveStoreEvent.d.ts.map +1 -0
  88. package/dist/schema/LiveStoreEvent.js +118 -0
  89. package/dist/schema/LiveStoreEvent.js.map +1 -0
  90. package/dist/schema/client-document-def.d.ts +223 -0
  91. package/dist/schema/client-document-def.d.ts.map +1 -0
  92. package/dist/schema/client-document-def.js +164 -0
  93. package/dist/schema/client-document-def.js.map +1 -0
  94. package/dist/schema/client-document-def.test.d.ts +2 -0
  95. package/dist/schema/client-document-def.test.d.ts.map +1 -0
  96. package/dist/schema/client-document-def.test.js +161 -0
  97. package/dist/schema/client-document-def.test.js.map +1 -0
  98. package/dist/schema/db-schema/dsl/mod.d.ts.map +1 -1
  99. package/dist/schema/events.d.ts +2 -0
  100. package/dist/schema/events.d.ts.map +1 -0
  101. package/dist/schema/events.js +2 -0
  102. package/dist/schema/events.js.map +1 -0
  103. package/dist/schema/mod.d.ts +4 -3
  104. package/dist/schema/mod.d.ts.map +1 -1
  105. package/dist/schema/mod.js +4 -3
  106. package/dist/schema/mod.js.map +1 -1
  107. package/dist/schema/schema.d.ts +26 -22
  108. package/dist/schema/schema.d.ts.map +1 -1
  109. package/dist/schema/schema.js +45 -43
  110. package/dist/schema/schema.js.map +1 -1
  111. package/dist/schema/sqlite-state.d.ts +12 -0
  112. package/dist/schema/sqlite-state.d.ts.map +1 -0
  113. package/dist/schema/sqlite-state.js +36 -0
  114. package/dist/schema/sqlite-state.js.map +1 -0
  115. package/dist/schema/system-tables.d.ts +121 -85
  116. package/dist/schema/system-tables.d.ts.map +1 -1
  117. package/dist/schema/system-tables.js +68 -43
  118. package/dist/schema/system-tables.js.map +1 -1
  119. package/dist/schema/table-def.d.ts +26 -96
  120. package/dist/schema/table-def.d.ts.map +1 -1
  121. package/dist/schema/table-def.js +14 -64
  122. package/dist/schema/table-def.js.map +1 -1
  123. package/dist/schema/view.d.ts +3 -0
  124. package/dist/schema/view.d.ts.map +1 -0
  125. package/dist/schema/view.js +3 -0
  126. package/dist/schema/view.js.map +1 -0
  127. package/dist/schema-management/common.d.ts +4 -4
  128. package/dist/schema-management/common.d.ts.map +1 -1
  129. package/dist/schema-management/migrations.d.ts.map +1 -1
  130. package/dist/schema-management/migrations.js +6 -6
  131. package/dist/schema-management/migrations.js.map +1 -1
  132. package/dist/schema-management/validate-mutation-defs.d.ts +3 -3
  133. package/dist/schema-management/validate-mutation-defs.d.ts.map +1 -1
  134. package/dist/schema-management/validate-mutation-defs.js +17 -17
  135. package/dist/schema-management/validate-mutation-defs.js.map +1 -1
  136. package/dist/sync/ClientSessionSyncProcessor.d.ts +16 -8
  137. package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
  138. package/dist/sync/ClientSessionSyncProcessor.js +50 -43
  139. package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
  140. package/dist/sync/next/facts.d.ts +19 -19
  141. package/dist/sync/next/facts.d.ts.map +1 -1
  142. package/dist/sync/next/facts.js +2 -2
  143. package/dist/sync/next/facts.js.map +1 -1
  144. package/dist/sync/next/history-dag-common.d.ts +3 -3
  145. package/dist/sync/next/history-dag-common.d.ts.map +1 -1
  146. package/dist/sync/next/history-dag-common.js +1 -1
  147. package/dist/sync/next/history-dag-common.js.map +1 -1
  148. package/dist/sync/next/history-dag.js +1 -1
  149. package/dist/sync/next/history-dag.js.map +1 -1
  150. package/dist/sync/next/rebase-events.d.ts +7 -7
  151. package/dist/sync/next/rebase-events.d.ts.map +1 -1
  152. package/dist/sync/next/rebase-events.js +5 -5
  153. package/dist/sync/next/rebase-events.js.map +1 -1
  154. package/dist/sync/next/test/compact-events.calculator.test.js +38 -33
  155. package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
  156. package/dist/sync/next/test/compact-events.test.js +71 -71
  157. package/dist/sync/next/test/compact-events.test.js.map +1 -1
  158. package/dist/sync/next/test/{mutation-fixtures.d.ts → event-fixtures.d.ts} +25 -25
  159. package/dist/sync/next/test/event-fixtures.d.ts.map +1 -0
  160. package/dist/sync/next/test/{mutation-fixtures.js → event-fixtures.js} +60 -25
  161. package/dist/sync/next/test/event-fixtures.js.map +1 -0
  162. package/dist/sync/next/test/mod.d.ts +1 -1
  163. package/dist/sync/next/test/mod.d.ts.map +1 -1
  164. package/dist/sync/next/test/mod.js +1 -1
  165. package/dist/sync/next/test/mod.js.map +1 -1
  166. package/dist/sync/sync.d.ts +8 -7
  167. package/dist/sync/sync.d.ts.map +1 -1
  168. package/dist/sync/sync.js.map +1 -1
  169. package/dist/sync/syncstate.d.ts +69 -93
  170. package/dist/sync/syncstate.d.ts.map +1 -1
  171. package/dist/sync/syncstate.js +143 -146
  172. package/dist/sync/syncstate.js.map +1 -1
  173. package/dist/sync/syncstate.test.js +208 -289
  174. package/dist/sync/syncstate.test.js.map +1 -1
  175. package/dist/sync/validate-push-payload.d.ts +2 -2
  176. package/dist/sync/validate-push-payload.d.ts.map +1 -1
  177. package/dist/sync/validate-push-payload.js.map +1 -1
  178. package/dist/version.d.ts +1 -1
  179. package/dist/version.js +1 -1
  180. package/package.json +2 -2
  181. package/src/__tests__/fixture.ts +36 -15
  182. package/src/adapter-types.ts +34 -23
  183. package/src/debug-info.ts +1 -0
  184. package/src/devtools/devtools-messages-common.ts +9 -0
  185. package/src/devtools/devtools-messages-leader.ts +14 -15
  186. package/src/index.ts +2 -5
  187. package/src/leader-thread/LeaderSyncProcessor.ts +485 -389
  188. package/src/leader-thread/apply-event.ts +197 -0
  189. package/src/leader-thread/eventlog.ts +199 -0
  190. package/src/leader-thread/leader-worker-devtools.ts +23 -25
  191. package/src/leader-thread/make-leader-thread-layer.ts +68 -61
  192. package/src/leader-thread/mod.ts +1 -1
  193. package/src/leader-thread/recreate-db.ts +7 -8
  194. package/src/leader-thread/types.ts +39 -29
  195. package/src/materializer-helper.ts +110 -0
  196. package/src/query-builder/api.ts +76 -102
  197. package/src/query-builder/astToSql.ts +68 -39
  198. package/src/query-builder/impl.test.ts +239 -42
  199. package/src/query-builder/impl.ts +66 -54
  200. package/src/{rehydrate-from-mutationlog.ts → rehydrate-from-eventlog.ts} +37 -40
  201. package/src/schema/EventDef.ts +216 -0
  202. package/src/schema/EventId.ts +30 -4
  203. package/src/schema/LiveStoreEvent.ts +239 -0
  204. package/src/schema/client-document-def.test.ts +188 -0
  205. package/src/schema/client-document-def.ts +436 -0
  206. package/src/schema/db-schema/dsl/mod.ts +0 -1
  207. package/src/schema/events.ts +1 -0
  208. package/src/schema/mod.ts +4 -3
  209. package/src/schema/schema.ts +78 -68
  210. package/src/schema/sqlite-state.ts +62 -0
  211. package/src/schema/system-tables.ts +54 -46
  212. package/src/schema/table-def.ts +51 -209
  213. package/src/schema/view.ts +2 -0
  214. package/src/schema-management/common.ts +4 -4
  215. package/src/schema-management/migrations.ts +8 -9
  216. package/src/schema-management/validate-mutation-defs.ts +22 -24
  217. package/src/sync/ClientSessionSyncProcessor.ts +66 -53
  218. package/src/sync/next/facts.ts +31 -32
  219. package/src/sync/next/history-dag-common.ts +4 -4
  220. package/src/sync/next/history-dag.ts +1 -1
  221. package/src/sync/next/rebase-events.ts +13 -13
  222. package/src/sync/next/test/compact-events.calculator.test.ts +45 -45
  223. package/src/sync/next/test/compact-events.test.ts +73 -73
  224. package/src/sync/next/test/event-fixtures.ts +219 -0
  225. package/src/sync/next/test/mod.ts +1 -1
  226. package/src/sync/sync.ts +9 -12
  227. package/src/sync/syncstate.test.ts +236 -323
  228. package/src/sync/syncstate.ts +218 -203
  229. package/src/sync/validate-push-payload.ts +2 -2
  230. package/src/version.ts +1 -1
  231. package/tsconfig.json +1 -0
  232. package/dist/derived-mutations.d.ts +0 -109
  233. package/dist/derived-mutations.d.ts.map +0 -1
  234. package/dist/derived-mutations.js +0 -54
  235. package/dist/derived-mutations.js.map +0 -1
  236. package/dist/derived-mutations.test.d.ts +0 -2
  237. package/dist/derived-mutations.test.d.ts.map +0 -1
  238. package/dist/derived-mutations.test.js +0 -93
  239. package/dist/derived-mutations.test.js.map +0 -1
  240. package/dist/init-singleton-tables.d.ts +0 -4
  241. package/dist/init-singleton-tables.d.ts.map +0 -1
  242. package/dist/init-singleton-tables.js +0 -16
  243. package/dist/init-singleton-tables.js.map +0 -1
  244. package/dist/leader-thread/apply-mutation.d.ts +0 -11
  245. package/dist/leader-thread/apply-mutation.d.ts.map +0 -1
  246. package/dist/leader-thread/apply-mutation.js +0 -115
  247. package/dist/leader-thread/apply-mutation.js.map +0 -1
  248. package/dist/leader-thread/mutationlog.d.ts +0 -11
  249. package/dist/leader-thread/mutationlog.d.ts.map +0 -1
  250. package/dist/leader-thread/mutationlog.js +0 -31
  251. package/dist/leader-thread/mutationlog.js.map +0 -1
  252. package/dist/leader-thread/pull-queue-set.d.ts +0 -7
  253. package/dist/leader-thread/pull-queue-set.d.ts.map +0 -1
  254. package/dist/leader-thread/pull-queue-set.js +0 -48
  255. package/dist/leader-thread/pull-queue-set.js.map +0 -1
  256. package/dist/mutation.d.ts +0 -20
  257. package/dist/mutation.d.ts.map +0 -1
  258. package/dist/mutation.js +0 -68
  259. package/dist/mutation.js.map +0 -1
  260. package/dist/query-info.d.ts +0 -41
  261. package/dist/query-info.d.ts.map +0 -1
  262. package/dist/query-info.js +0 -7
  263. package/dist/query-info.js.map +0 -1
  264. package/dist/rehydrate-from-mutationlog.d.ts +0 -14
  265. package/dist/rehydrate-from-mutationlog.d.ts.map +0 -1
  266. package/dist/rehydrate-from-mutationlog.js.map +0 -1
  267. package/dist/schema/MutationEvent.d.ts +0 -202
  268. package/dist/schema/MutationEvent.d.ts.map +0 -1
  269. package/dist/schema/MutationEvent.js +0 -105
  270. package/dist/schema/MutationEvent.js.map +0 -1
  271. package/dist/schema/mutations.d.ts +0 -115
  272. package/dist/schema/mutations.d.ts.map +0 -1
  273. package/dist/schema/mutations.js +0 -42
  274. package/dist/schema/mutations.js.map +0 -1
  275. package/dist/sync/next/test/mutation-fixtures.d.ts.map +0 -1
  276. package/dist/sync/next/test/mutation-fixtures.js.map +0 -1
  277. package/src/derived-mutations.test.ts +0 -101
  278. package/src/derived-mutations.ts +0 -170
  279. package/src/init-singleton-tables.ts +0 -24
  280. package/src/leader-thread/apply-mutation.ts +0 -187
  281. package/src/leader-thread/mutationlog.ts +0 -49
  282. package/src/leader-thread/pull-queue-set.ts +0 -67
  283. package/src/mutation.ts +0 -108
  284. package/src/query-info.ts +0 -83
  285. package/src/schema/MutationEvent.ts +0 -224
  286. package/src/schema/mutations.ts +0 -193
  287. package/src/sync/next/test/mutation-fixtures.ts +0 -228
@@ -1,16 +1,16 @@
1
- import { defineMutation } from '@livestore/common/schema'
1
+ import { defineEvent } from '@livestore/common/schema'
2
2
  import { Schema } from '@livestore/utils/effect'
3
3
  import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import { compactEvents } from '../compact-events.js'
6
6
  import { historyDagFromNodes } from '../history-dag.js'
7
7
  import { customSerializer } from './compact-events.test.js'
8
- import { toEventNodes } from './mutation-fixtures.js'
8
+ import { toEventNodes } from './event-fixtures.js'
9
9
 
10
10
  expect.addSnapshotSerializer(customSerializer)
11
11
 
12
12
  const compact = (events: any[]) => {
13
- const dag = historyDagFromNodes(toEventNodes(events, mutations, 'client-id', 'session-id'))
13
+ const dag = historyDagFromNodes(toEventNodes(events, eventDefs, 'client-id', 'session-id'))
14
14
  const compacted = compactEvents(dag)
15
15
 
16
16
  return Array.from(compacted.dag.nodeEntries())
@@ -23,98 +23,98 @@ const facts = {
23
23
  multiplyByZero: `multiplyByZero`,
24
24
  }
25
25
 
26
- const mutations = {
27
- add: defineMutation('add', Schema.Struct({ value: Schema.Number }), 'UPDATE values SET value = value + $value', {}),
28
- multiply: defineMutation(
29
- 'multiply',
30
- Schema.Struct({ value: Schema.Number }),
31
- 'UPDATE values SET value = value * $value',
32
- {
33
- facts: ({ value }, currentFacts) => ({
34
- modify: {
35
- set: value === 0 || currentFacts.has(facts.multiplyByZero) ? [facts.multiplyByZero] : [],
36
- unset: value === 0 ? [] : [facts.multiplyByZero],
37
- },
38
- }),
39
- },
40
- ),
26
+ const eventDefs = {
27
+ add: defineEvent({
28
+ name: 'add',
29
+ schema: Schema.Struct({ value: Schema.Number }),
30
+ }),
31
+ multiply: defineEvent({
32
+ name: 'multiply',
33
+ schema: Schema.Struct({ value: Schema.Number }),
34
+ facts: ({ value }, currentFacts) => ({
35
+ modify: {
36
+ set: value === 0 || currentFacts.has(facts.multiplyByZero) ? [facts.multiplyByZero] : [],
37
+ unset: value === 0 ? [] : [facts.multiplyByZero],
38
+ },
39
+ }),
40
+ }),
41
41
  // TODO divide by zero
42
42
  }
43
43
 
44
44
  describe('compactEvents calculator', () => {
45
45
  it('1 + 1', () => {
46
46
  const expected = compact([
47
- mutations.add({ value: 1 }), // 0
48
- mutations.add({ value: 1 }), // 1
47
+ eventDefs.add({ value: 1 }), // 0
48
+ eventDefs.add({ value: 1 }), // 1
49
49
  ])
50
50
 
51
51
  expect(expected).toMatchInlineSnapshot(`
52
52
  [
53
- { id: 0, parentId: -1, mutation: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
54
- { id: 1, parentId: 0, mutation: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
53
+ { id: 1, parentId: 0, name: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
54
+ { id: 2, parentId: 1, name: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
55
55
  ]
56
56
  `)
57
57
  })
58
58
 
59
59
  it('2 * 2', () => {
60
60
  const expected = compact([
61
- mutations.multiply({ value: 2 }), // 0
62
- mutations.multiply({ value: 2 }), // 1
61
+ eventDefs.multiply({ value: 2 }), // 0
62
+ eventDefs.multiply({ value: 2 }), // 1
63
63
  ])
64
64
 
65
65
  expect(expected).toMatchInlineSnapshot(`
66
66
  [
67
- { id: 0, parentId: -1, mutation: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero -multiplyByZero" }
68
- { id: 1, parentId: 0, mutation: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero -multiplyByZero" }
67
+ { id: 1, parentId: 0, name: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero -multiplyByZero" }
68
+ { id: 2, parentId: 1, name: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero -multiplyByZero" }
69
69
  ]
70
70
  `)
71
71
  })
72
72
 
73
73
  it('2 * 2 * 0', () => {
74
74
  const expected = compact([
75
- mutations.multiply({ value: 2 }), // 0
76
- mutations.multiply({ value: 2 }), // 1
77
- mutations.multiply({ value: 0 }), // 2
75
+ eventDefs.multiply({ value: 2 }), // 0
76
+ eventDefs.multiply({ value: 2 }), // 1
77
+ eventDefs.multiply({ value: 0 }), // 2
78
78
  ])
79
79
 
80
80
  expect(expected).toMatchInlineSnapshot(`
81
81
  [
82
- { id: 2, parentId: -1, mutation: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
82
+ { id: 3, parentId: 0, name: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
83
83
  ]
84
84
  `)
85
85
  })
86
86
 
87
87
  it('2 * 2 * 0 + 1', () => {
88
88
  const expected = compact([
89
- mutations.multiply({ value: 2 }), // 0
90
- mutations.multiply({ value: 2 }), // 1
91
- mutations.multiply({ value: 0 }), // 2
92
- mutations.add({ value: 1 }), // 3
89
+ eventDefs.multiply({ value: 2 }), // 0
90
+ eventDefs.multiply({ value: 2 }), // 1
91
+ eventDefs.multiply({ value: 0 }), // 2
92
+ eventDefs.add({ value: 1 }), // 3
93
93
  ])
94
94
 
95
95
  expect(expected).toMatchInlineSnapshot(`
96
96
  [
97
- { id: 2, parentId: -1, mutation: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
98
- { id: 3, parentId: 2, mutation: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
97
+ { id: 3, parentId: 0, name: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
98
+ { id: 4, parentId: 3, name: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
99
99
  ]
100
100
  `)
101
101
  })
102
102
 
103
103
  it('1 + 2 * 0 * 2 + 1', () => {
104
104
  const expected = compact([
105
- mutations.add({ value: 1 }), // 0
106
- mutations.multiply({ value: 2 }), // 1
107
- mutations.multiply({ value: 0 }), // 2
108
- mutations.multiply({ value: 2 }), // 3
109
- mutations.add({ value: 1 }), // 4
105
+ eventDefs.add({ value: 1 }), // 0
106
+ eventDefs.multiply({ value: 2 }), // 1
107
+ eventDefs.multiply({ value: 0 }), // 2
108
+ eventDefs.multiply({ value: 2 }), // 3
109
+ eventDefs.add({ value: 1 }), // 4
110
110
  ])
111
111
 
112
112
  expect(expected).toMatchInlineSnapshot(`
113
113
  [
114
- { id: 0, parentId: -1, mutation: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
115
- { id: 2, parentId: 0, mutation: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
116
- { id: 3, parentId: 2, mutation: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero +multiplyByZero -multiplyByZero" }
117
- { id: 4, parentId: 3, mutation: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
114
+ { id: 1, parentId: 0, name: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
115
+ { id: 3, parentId: 1, name: "multiply", args: { value: 0 }, clientId: "client-id", sessionId: "session-id", facts: "+multiplyByZero" }
116
+ { id: 4, parentId: 3, name: "multiply", args: { value: 2 }, clientId: "client-id", sessionId: "session-id", facts: "?multiplyByZero +multiplyByZero -multiplyByZero" }
117
+ { id: 5, parentId: 4, name: "add", args: { value: 1 }, clientId: "client-id", sessionId: "session-id", facts: "" }
118
118
  ]
119
119
  `)
120
120
  })
@@ -1,11 +1,11 @@
1
- import type { MutationEventFacts } from '@livestore/common/schema'
1
+ import type { EventDefFacts } from '@livestore/common/schema'
2
2
  import { describe, expect, it } from 'vitest'
3
3
 
4
4
  import { compactEvents } from '../compact-events.js'
5
5
  import { historyDagFromNodes } from '../history-dag.js'
6
6
  import type { HistoryDagNode } from '../history-dag-common.js'
7
7
  import { EMPTY_FACT_VALUE } from '../history-dag-common.js'
8
- import { mutations, toEventNodes } from './mutation-fixtures.js'
8
+ import { events as eventDefs, toEventNodes } from './event-fixtures.js'
9
9
 
10
10
  const customStringify = (value: any): string => {
11
11
  if (value === null) {
@@ -58,7 +58,7 @@ const factsToString = (facts: HistoryDagNode['factsGroup']) =>
58
58
  .flat()
59
59
  .join(' ')
60
60
 
61
- const factsSetToString = (facts: MutationEventFacts, prefix: string) =>
61
+ const factsSetToString = (facts: EventDefFacts, prefix: string) =>
62
62
  Array.from(facts.entries()).map(([key, value]) => prefix + key + (value === EMPTY_FACT_VALUE ? '' : `=${value}`))
63
63
 
64
64
  export const customSerializer = {
@@ -71,7 +71,7 @@ export const customSerializer = {
71
71
  expect.addSnapshotSerializer(customSerializer)
72
72
 
73
73
  const compact = (events: any[]) => {
74
- const dag = historyDagFromNodes(toEventNodes(events, mutations, 'client-id', 'session-id'))
74
+ const dag = historyDagFromNodes(toEventNodes(events, eventDefs, 'client-id', 'session-id'))
75
75
  const compacted = compactEvents(dag)
76
76
 
77
77
  return Array.from(compacted.dag.nodeEntries())
@@ -83,90 +83,90 @@ const compact = (events: any[]) => {
83
83
  describe('compactEvents todo app', () => {
84
84
  it('todoCompleted', () => {
85
85
  const expected = compact([
86
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
87
- mutations.todoCompleted({ id: 'A' }), // 1
88
- mutations.todoCompleted({ id: 'A' }), // 2
86
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
87
+ eventDefs.todoCompleted({ id: 'A' }), // 1
88
+ eventDefs.todoCompleted({ id: 'A' }), // 2
89
89
  ])
90
90
 
91
91
  expect(expected).toMatchInlineSnapshot(`
92
92
  [
93
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
94
- { id: 2, parentId: 0, mutation: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
93
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
94
+ { id: 3, parentId: 1, name: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
95
95
  ]
96
96
  `)
97
97
  })
98
98
 
99
99
  it('toggleTodo', () => {
100
100
  const expected = compact([
101
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
102
- mutations.toggleTodo({ id: 'A' }), // 1
103
- mutations.toggleTodo({ id: 'A' }), // 2
104
- mutations.toggleTodo({ id: 'A' }), // 3
101
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
102
+ eventDefs.toggleTodo({ id: 'A' }), // 1
103
+ eventDefs.toggleTodo({ id: 'A' }), // 2
104
+ eventDefs.toggleTodo({ id: 'A' }), // 3
105
105
  ])
106
106
 
107
107
  expect(expected).toMatchInlineSnapshot(`
108
108
  [
109
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
110
- { id: 1, parentId: 0, mutation: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
111
- { id: 2, parentId: 1, mutation: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
112
- { id: 3, parentId: 2, mutation: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
109
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
110
+ { id: 2, parentId: 1, name: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
111
+ { id: 3, parentId: 2, name: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
112
+ { id: 4, parentId: 3, name: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
113
113
  ]
114
114
  `)
115
115
  })
116
116
 
117
117
  it('todoCompleted / toggleTodo', () => {
118
118
  const expected = compact([
119
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
120
- mutations.toggleTodo({ id: 'A' }), // 1
121
- mutations.toggleTodo({ id: 'A' }), // 2
122
- mutations.todoCompleted({ id: 'A' }), // 3
123
- mutations.todoCompleted({ id: 'A' }), // 4
124
- mutations.toggleTodo({ id: 'A' }), // 5
119
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
120
+ eventDefs.toggleTodo({ id: 'A' }), // 1
121
+ eventDefs.toggleTodo({ id: 'A' }), // 2
122
+ eventDefs.todoCompleted({ id: 'A' }), // 3
123
+ eventDefs.todoCompleted({ id: 'A' }), // 4
124
+ eventDefs.toggleTodo({ id: 'A' }), // 5
125
125
  ])
126
126
 
127
127
  expect(expected).toMatchInlineSnapshot(`
128
128
  [
129
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
130
- { id: 4, parentId: 0, mutation: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
131
- { id: 5, parentId: 4, mutation: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
129
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
130
+ { id: 5, parentId: 1, name: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
131
+ { id: 6, parentId: 5, name: "toggleTodo", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
132
132
  ]
133
133
  `)
134
134
  })
135
135
 
136
136
  it('readonly setTextTodo', () => {
137
137
  const expected = compact([
138
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
139
- mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
140
- mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
141
- mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 3
138
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
139
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: false }), // 1
140
+ eventDefs.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
141
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: true }), // 3
142
142
  ])
143
143
 
144
144
  expect(expected).toMatchInlineSnapshot(`
145
145
  [
146
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
147
- { id: 1, parentId: 0, mutation: "setReadonlyTodo", args: { id: "A", readonly: false }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=true" }
148
- { id: 2, parentId: 1, mutation: "setTextTodo", args: { id: "A", text: "buy soy milk" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
149
- { id: 3, parentId: 2, mutation: "setReadonlyTodo", args: { id: "A", readonly: true }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=false" }
146
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
147
+ { id: 2, parentId: 1, name: "setReadonlyTodo", args: { id: "A", readonly: false }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=true" }
148
+ { id: 3, parentId: 2, name: "setTextTodo", args: { id: "A", text: "buy soy milk" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
149
+ { id: 4, parentId: 3, name: "setReadonlyTodo", args: { id: "A", readonly: true }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=false" }
150
150
  ]
151
151
  `)
152
152
  })
153
153
 
154
154
  it('readonly setTextTodo 2', () => {
155
155
  const expected = compact([
156
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
157
- mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
158
- mutations.todoCompleted({ id: 'A' }), // 2
159
- mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 3
160
- mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 4
156
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
157
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: false }), // 1
158
+ eventDefs.todoCompleted({ id: 'A' }), // 2
159
+ eventDefs.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 3
160
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: true }), // 4
161
161
  ])
162
162
 
163
163
  expect(expected).toMatchInlineSnapshot(`
164
164
  [
165
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
166
- { id: 1, parentId: 0, mutation: "setReadonlyTodo", args: { id: "A", readonly: false }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=true" }
167
- { id: 2, parentId: 1, mutation: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
168
- { id: 3, parentId: 2, mutation: "setTextTodo", args: { id: "A", text: "buy soy milk" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
169
- { id: 4, parentId: 3, mutation: "setReadonlyTodo", args: { id: "A", readonly: true }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=false" }
165
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
166
+ { id: 2, parentId: 1, name: "setReadonlyTodo", args: { id: "A", readonly: false }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=true" }
167
+ { id: 3, parentId: 2, name: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
168
+ { id: 4, parentId: 3, name: "setTextTodo", args: { id: "A", text: "buy soy milk" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
169
+ { id: 5, parentId: 4, name: "setReadonlyTodo", args: { id: "A", readonly: true }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A +todo-is-writeable-A=false" }
170
170
  ]
171
171
  `)
172
172
  })
@@ -174,15 +174,15 @@ describe('compactEvents todo app', () => {
174
174
  it('readonly setTextTodo - should fail', () => {
175
175
  const expected = () =>
176
176
  compact([
177
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
178
- mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
179
- mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
180
- mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 3
181
- mutations.setTextTodo({ id: 'A', text: 'buy oat milk' }), // 4
177
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
178
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: false }), // 1
179
+ eventDefs.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
180
+ eventDefs.setReadonlyTodo({ id: 'A', readonly: true }), // 3
181
+ eventDefs.setTextTodo({ id: 'A', text: 'buy oat milk' }), // 4
182
182
  ])
183
183
 
184
184
  expect(expected).toThrowErrorMatchingInlineSnapshot(`
185
- [Error: Mutation setTextTodo requires facts that have not been set yet.
185
+ [Error: Event setTextTodo requires facts that have not been set yet.
186
186
  Requires: todo-exists-A, todo-is-writeable-A=true
187
187
  Facts Snapshot: todo-exists-A, todo-is-writeable-A=false, todo-completed-A=false, todo-text-updated-A]
188
188
  `)
@@ -190,43 +190,43 @@ describe('compactEvents todo app', () => {
190
190
 
191
191
  it('todoCompleteds', () => {
192
192
  const expected = compact([
193
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
194
- mutations.createTodo({ id: 'B', text: 'buy bread' }), // 1
195
- mutations.createTodo({ id: 'C', text: 'buy cheese' }), // 2
196
- mutations.todoCompleteds({ ids: ['A', 'B', 'C'] }), // 3
197
- mutations.toggleTodo({ id: 'A' }), // 4
198
- mutations.todoCompleted({ id: 'A' }), // 5
193
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
194
+ eventDefs.createTodo({ id: 'B', text: 'buy bread' }), // 1
195
+ eventDefs.createTodo({ id: 'C', text: 'buy cheese' }), // 2
196
+ eventDefs.todoCompleteds({ ids: ['A', 'B', 'C'] }), // 3
197
+ eventDefs.toggleTodo({ id: 'A' }), // 4
198
+ eventDefs.todoCompleted({ id: 'A' }), // 5
199
199
  ])
200
200
 
201
201
  expect(expected).toMatchInlineSnapshot(`
202
202
  [
203
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
204
- { id: 1, parentId: 0, mutation: "createTodo", args: { id: "B", text: "buy bread" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
205
- { id: 2, parentId: 1, mutation: "createTodo", args: { id: "C", text: "buy cheese" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
206
- { id: 3, parentId: 2, mutation: "todoCompleteds", args: { ids: ["A", "B", "C"] }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
207
- { id: 5, parentId: 3, mutation: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
203
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
204
+ { id: 2, parentId: 1, name: "createTodo", args: { id: "B", text: "buy bread" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
205
+ { id: 3, parentId: 2, name: "createTodo", args: { id: "C", text: "buy cheese" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
206
+ { id: 4, parentId: 3, name: "todoCompleteds", args: { ids: ["A", "B", "C"] }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
207
+ { id: 6, parentId: 4, name: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
208
208
  ]
209
209
  `)
210
210
  })
211
211
 
212
212
  it('todoCompleteds 2', () => {
213
213
  const expected = compact([
214
- mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
215
- mutations.createTodo({ id: 'B', text: 'buy bread' }), // 1
216
- mutations.createTodo({ id: 'C', text: 'buy cheese' }), // 2
217
- mutations.toggleTodo({ id: 'A' }), // 3
218
- mutations.todoCompleteds({ ids: ['A', 'B', 'C'] }), // 4
219
- mutations.toggleTodo({ id: 'A' }), // 5
220
- mutations.todoCompleted({ id: 'A' }), // 6
214
+ eventDefs.createTodo({ id: 'A', text: 'buy milk' }), // 0
215
+ eventDefs.createTodo({ id: 'B', text: 'buy bread' }), // 1
216
+ eventDefs.createTodo({ id: 'C', text: 'buy cheese' }), // 2
217
+ eventDefs.toggleTodo({ id: 'A' }), // 3
218
+ eventDefs.todoCompleteds({ ids: ['A', 'B', 'C'] }), // 4
219
+ eventDefs.toggleTodo({ id: 'A' }), // 5
220
+ eventDefs.todoCompleted({ id: 'A' }), // 6
221
221
  ])
222
222
 
223
223
  expect(expected).toMatchInlineSnapshot(`
224
224
  [
225
- { id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
226
- { id: 1, parentId: 0, mutation: "createTodo", args: { id: "B", text: "buy bread" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
227
- { id: 2, parentId: 1, mutation: "createTodo", args: { id: "C", text: "buy cheese" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
228
- { id: 4, parentId: 2, mutation: "todoCompleteds", args: { ids: ["A", "B", "C"] }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
229
- { id: 6, parentId: 4, mutation: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
225
+ { id: 1, parentId: 0, name: "createTodo", args: { id: "A", text: "buy milk" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
226
+ { id: 2, parentId: 1, name: "createTodo", args: { id: "B", text: "buy bread" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
227
+ { id: 3, parentId: 2, name: "createTodo", args: { id: "C", text: "buy cheese" }, clientId: "client-id", sessionId: "session-id", facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
228
+ { id: 5, parentId: 3, name: "todoCompleteds", args: { ids: ["A", "B", "C"] }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
229
+ { id: 7, parentId: 5, name: "todoCompleted", args: { id: "A" }, clientId: "client-id", sessionId: "session-id", facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
230
230
  ]
231
231
  `)
232
232
  })