atom.io 0.40.0 → 0.40.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/data/index.d.ts +1 -1
  2. package/dist/data/index.d.ts.map +1 -1
  3. package/dist/data/index.js.map +1 -1
  4. package/dist/internal/index.d.ts +205 -196
  5. package/dist/internal/index.d.ts.map +1 -1
  6. package/dist/internal/index.js +145 -107
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/introspection/index.d.ts +6 -6
  9. package/dist/introspection/index.d.ts.map +1 -1
  10. package/dist/introspection/index.js.map +1 -1
  11. package/dist/main/index.d.ts +93 -66
  12. package/dist/main/index.d.ts.map +1 -1
  13. package/dist/main/index.js +16 -13
  14. package/dist/main/index.js.map +1 -1
  15. package/dist/react/index.d.ts +14 -14
  16. package/dist/react/index.d.ts.map +1 -1
  17. package/dist/react/index.js.map +1 -1
  18. package/dist/react-devtools/index.js +1 -1
  19. package/dist/react-devtools/index.js.map +1 -1
  20. package/dist/realtime-client/index.d.ts +3 -3
  21. package/dist/realtime-client/index.d.ts.map +1 -1
  22. package/dist/realtime-client/index.js +3 -4
  23. package/dist/realtime-client/index.js.map +1 -1
  24. package/dist/realtime-server/index.d.ts +2 -2
  25. package/dist/realtime-server/index.d.ts.map +1 -1
  26. package/package.json +2 -2
  27. package/src/data/struct.ts +2 -2
  28. package/src/internal/atom/create-regular-atom.ts +11 -9
  29. package/src/internal/atom/dispose-atom.ts +11 -8
  30. package/src/internal/atom/has-role.ts +1 -1
  31. package/src/internal/caching.ts +15 -15
  32. package/src/internal/events/ingest-creation-disposal.ts +1 -1
  33. package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
  34. package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
  35. package/src/internal/families/create-regular-atom-family.ts +21 -15
  36. package/src/internal/families/create-selector-family.ts +15 -15
  37. package/src/internal/families/create-writable-held-selector-family.ts +2 -2
  38. package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
  39. package/src/internal/families/dispose-from-store.ts +17 -7
  40. package/src/internal/families/find-in-store.ts +23 -23
  41. package/src/internal/families/get-family-of-token.ts +17 -17
  42. package/src/internal/families/mint-in-store.ts +10 -10
  43. package/src/internal/families/seek-in-store.ts +26 -26
  44. package/src/internal/get-state/get-fallback.ts +8 -8
  45. package/src/internal/get-state/get-from-store.ts +20 -8
  46. package/src/internal/get-state/read-or-compute-value.ts +78 -14
  47. package/src/internal/get-state/reduce-reference.ts +10 -10
  48. package/src/internal/index.ts +65 -60
  49. package/src/internal/install-into-store.ts +2 -1
  50. package/src/internal/join/create-join.ts +2 -2
  51. package/src/internal/join/find-relations-in-store.ts +2 -2
  52. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  53. package/src/internal/join/get-join.ts +5 -2
  54. package/src/internal/join/join-internal.ts +30 -26
  55. package/src/internal/lineage.ts +12 -1
  56. package/src/internal/molecule.ts +64 -36
  57. package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
  58. package/src/internal/mutable/create-mutable-atom.ts +2 -2
  59. package/src/internal/mutable/get-json-family.ts +3 -2
  60. package/src/internal/mutable/get-update-family.ts +7 -5
  61. package/src/internal/mutable/tracker-family.ts +8 -4
  62. package/src/internal/mutable/tracker.ts +5 -1
  63. package/src/internal/operation.ts +4 -2
  64. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  65. package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
  66. package/src/internal/selector/create-standalone-selector.ts +10 -10
  67. package/src/internal/selector/create-writable-held-selector.ts +2 -2
  68. package/src/internal/selector/create-writable-pure-selector.ts +11 -9
  69. package/src/internal/selector/dispose-selector.ts +2 -2
  70. package/src/internal/selector/register-selector.ts +2 -2
  71. package/src/internal/selector/trace-selector-atoms.ts +3 -3
  72. package/src/internal/selector/update-selector-atoms.ts +1 -1
  73. package/src/internal/set-state/become.ts +1 -3
  74. package/src/internal/set-state/dispatch-state-update.ts +10 -6
  75. package/src/internal/set-state/evict-downstream.ts +4 -1
  76. package/src/internal/set-state/operate-on-store.ts +16 -10
  77. package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
  78. package/src/internal/set-state/reset-in-store.ts +17 -16
  79. package/src/internal/set-state/set-atom-or-selector.ts +1 -1
  80. package/src/internal/set-state/set-atom.ts +1 -1
  81. package/src/internal/set-state/set-into-store.ts +34 -7
  82. package/src/internal/set-state/set-selector.ts +1 -1
  83. package/src/internal/store/deposit.ts +38 -30
  84. package/src/internal/store/mint-or-counterfeit.ts +23 -23
  85. package/src/internal/store/store.ts +23 -21
  86. package/src/internal/store/withdraw.ts +68 -62
  87. package/src/internal/subscribe/recall-state.ts +4 -1
  88. package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
  89. package/src/internal/subscribe/subscribe-to-state.ts +4 -4
  90. package/src/internal/timeline/create-timeline.ts +11 -10
  91. package/src/internal/timeline/time-travel.ts +4 -3
  92. package/src/internal/transaction/abort-transaction.ts +3 -15
  93. package/src/internal/transaction/act-upon-store.ts +1 -5
  94. package/src/internal/transaction/apply-transaction.ts +3 -15
  95. package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
  96. package/src/internal/transaction/build-transaction.ts +2 -3
  97. package/src/internal/transaction/create-transaction.ts +5 -6
  98. package/src/internal/transaction/get-epoch-number.ts +1 -7
  99. package/src/internal/transaction/set-epoch-number.ts +4 -12
  100. package/src/introspection/attach-atom-index.ts +2 -2
  101. package/src/introspection/attach-introspection-states.ts +4 -2
  102. package/src/introspection/attach-selector-index.ts +4 -2
  103. package/src/introspection/attach-timeline-family.ts +15 -13
  104. package/src/introspection/attach-timeline-index.ts +1 -1
  105. package/src/introspection/attach-transaction-index.ts +1 -1
  106. package/src/introspection/attach-transaction-logs.ts +6 -4
  107. package/src/introspection/attach-type-selectors.ts +4 -3
  108. package/src/introspection/index.ts +3 -5
  109. package/src/main/atom.ts +14 -8
  110. package/src/main/dispose-state.ts +1 -5
  111. package/src/main/events.ts +26 -26
  112. package/src/main/get-state.ts +10 -11
  113. package/src/main/realm.ts +36 -12
  114. package/src/main/reset-state.ts +5 -9
  115. package/src/main/selector.ts +40 -24
  116. package/src/main/set-state.ts +8 -11
  117. package/src/main/silo.ts +4 -3
  118. package/src/main/timeline.ts +5 -3
  119. package/src/main/tokens.ts +72 -44
  120. package/src/main/validators.ts +4 -4
  121. package/src/react/parse-state-overloads.ts +10 -10
  122. package/src/react/store-context.tsx +3 -3
  123. package/src/react/use-i.ts +6 -6
  124. package/src/react/use-loadable.ts +15 -15
  125. package/src/react/use-o.ts +9 -9
  126. package/src/react-devtools/Button.tsx +3 -2
  127. package/src/react-devtools/StateEditor.tsx +5 -3
  128. package/src/react-devtools/StateIndex.tsx +6 -4
  129. package/src/react-devtools/TimelineIndex.tsx +0 -2
  130. package/src/react-devtools/Updates.tsx +1 -1
  131. package/src/react-devtools/store.ts +18 -9
  132. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
  133. package/src/realtime-client/sync-continuity.ts +2 -2
  134. package/src/realtime-server/index.ts +2 -2
@@ -72,15 +72,18 @@ import type { Timeline } from "../timeline"
72
72
  import type { Transaction } from "../transaction"
73
73
  import type { Store } from "./store"
74
74
 
75
- export function withdraw<T>(
75
+ export function withdraw<T, E>(
76
76
  store: Store,
77
- token: RegularAtomToken<T>,
78
- ): RegularAtom<T>
77
+ token: RegularAtomToken<T, any, E>,
78
+ ): RegularAtom<T, E>
79
79
  export function withdraw<T extends Transceiver<any, any, any>>(
80
80
  store: Store,
81
81
  token: MutableAtomToken<T, any>,
82
82
  ): MutableAtom<T>
83
- export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
83
+ export function withdraw<T, E>(
84
+ store: Store,
85
+ token: AtomToken<T, any, E>,
86
+ ): Atom<T, E>
84
87
  export function withdraw<T>(
85
88
  store: Store,
86
89
  token: WritableHeldSelectorToken<T>,
@@ -89,52 +92,55 @@ export function withdraw<T>(
89
92
  store: Store,
90
93
  token: ReadonlyHeldSelectorToken<T>,
91
94
  ): ReadonlyHeldSelector<T>
92
- export function withdraw<T>(
95
+ export function withdraw<T, E>(
93
96
  store: Store,
94
- token: WritablePureSelectorToken<T>,
95
- ): WritablePureSelector<T>
96
- export function withdraw<T>(
97
+ token: WritablePureSelectorToken<T, any, E>,
98
+ ): WritablePureSelector<T, E>
99
+ export function withdraw<T, E>(
97
100
  store: Store,
98
- token: ReadonlyPureSelectorToken<T>,
99
- ): ReadonlyPureSelector<T>
100
- export function withdraw<T>(
101
+ token: ReadonlyPureSelectorToken<T, any, E>,
102
+ ): ReadonlyPureSelector<T, E>
103
+ export function withdraw<T, E>(
101
104
  store: Store,
102
- token: ReadonlySelectorToken<T>,
103
- ): ReadonlySelector<T>
104
- export function withdraw<T>(
105
+ token: ReadonlySelectorToken<T, any, E>,
106
+ ): ReadonlySelector<T, E>
107
+ export function withdraw<T, E>(
105
108
  store: Store,
106
- token: WritableSelectorToken<T>,
107
- ): WritableSelector<T>
109
+ token: WritableSelectorToken<T, any, E>,
110
+ ): WritableSelector<T, E>
108
111
  export function withdraw<T>(
109
112
  store: Store,
110
113
  token: HeldSelectorToken<T>,
111
114
  ): HeldSelector<T>
112
- export function withdraw<T>(
115
+ export function withdraw<T, E>(
113
116
  store: Store,
114
- token: PureSelectorToken<T>,
115
- ): PureSelector<T>
116
- export function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>
117
- export function withdraw<T>(
117
+ token: PureSelectorToken<T, any, E>,
118
+ ): PureSelector<T, E>
119
+ export function withdraw<T, E>(
118
120
  store: Store,
119
- token: WritableToken<T>,
120
- ): WritableState<T>
121
- export function withdraw<T>(
121
+ token: SelectorToken<T, any, E>,
122
+ ): Selector<T, E>
123
+ export function withdraw<T, E>(
122
124
  store: Store,
123
- token: ReadableToken<T>,
124
- ): ReadableState<T>
125
+ token: WritableToken<T, any, E>,
126
+ ): WritableState<T, E>
127
+ export function withdraw<T, E>(
128
+ store: Store,
129
+ token: ReadableToken<T, any, E>,
130
+ ): ReadableState<T, E>
125
131
 
126
- export function withdraw<T, K extends Canonical>(
132
+ export function withdraw<T, K extends Canonical, E>(
127
133
  store: Store,
128
- token: RegularAtomFamilyToken<T, K>,
129
- ): RegularAtomFamily<T, K>
134
+ token: RegularAtomFamilyToken<T, K, E>,
135
+ ): RegularAtomFamily<T, K, E>
130
136
  export function withdraw<
131
137
  T extends Transceiver<any, any, any>,
132
138
  K extends Canonical,
133
139
  >(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>
134
- export function withdraw<T, K extends Canonical>(
140
+ export function withdraw<T, K extends Canonical, E>(
135
141
  store: Store,
136
- token: AtomFamilyToken<T, K>,
137
- ): AtomFamily<T, K>
142
+ token: AtomFamilyToken<T, K, E>,
143
+ ): AtomFamily<T, K, E>
138
144
  export function withdraw<T, K extends Canonical>(
139
145
  store: Store,
140
146
  token: ReadonlyHeldSelectorFamilyToken<T, K>,
@@ -143,42 +149,42 @@ export function withdraw<T, K extends Canonical>(
143
149
  store: Store,
144
150
  token: WritableHeldSelectorFamilyToken<T, K>,
145
151
  ): WritableHeldSelectorFamily<T, K>
146
- export function withdraw<T, K extends Canonical>(
152
+ export function withdraw<T, K extends Canonical, E>(
147
153
  store: Store,
148
- token: ReadonlyPureSelectorFamilyToken<T, K>,
149
- ): ReadonlyPureSelectorFamily<T, K>
150
- export function withdraw<T, K extends Canonical>(
154
+ token: ReadonlyPureSelectorFamilyToken<T, K, E>,
155
+ ): ReadonlyPureSelectorFamily<T, K, E>
156
+ export function withdraw<T, K extends Canonical, E>(
151
157
  store: Store,
152
- token: WritablePureSelectorFamilyToken<T, K>,
153
- ): WritablePureSelectorFamily<T, K>
154
- export function withdraw<T, K extends Canonical>(
158
+ token: WritablePureSelectorFamilyToken<T, K, E>,
159
+ ): WritablePureSelectorFamily<T, K, E>
160
+ export function withdraw<T, K extends Canonical, E>(
155
161
  store: Store,
156
- token: ReadonlySelectorFamilyToken<T, K>,
157
- ): ReadonlySelectorFamily<T, K>
158
- export function withdraw<T, K extends Canonical>(
162
+ token: ReadonlySelectorFamilyToken<T, K, E>,
163
+ ): ReadonlySelectorFamily<T, K, E>
164
+ export function withdraw<T, K extends Canonical, E>(
159
165
  store: Store,
160
- token: WritableSelectorFamilyToken<T, K>,
161
- ): WritableSelectorFamily<T, K>
166
+ token: WritableSelectorFamilyToken<T, K, E>,
167
+ ): WritableSelectorFamily<T, K, E>
162
168
  export function withdraw<T, K extends Canonical>(
163
169
  store: Store,
164
170
  token: HeldSelectorFamilyToken<T, K>,
165
171
  ): HeldSelectorFamily<T, K>
166
- export function withdraw<T, K extends Canonical>(
172
+ export function withdraw<T, K extends Canonical, E>(
167
173
  store: Store,
168
- token: PureSelectorFamilyToken<T, K>,
169
- ): PureSelectorFamily<T, K>
170
- export function withdraw<T, K extends Canonical>(
174
+ token: PureSelectorFamilyToken<T, K, E>,
175
+ ): PureSelectorFamily<T, K, E>
176
+ export function withdraw<T, K extends Canonical, E>(
171
177
  store: Store,
172
- token: SelectorFamilyToken<T, K>,
173
- ): SelectorFamily<T, K>
174
- export function withdraw<T, K extends Canonical>(
178
+ token: SelectorFamilyToken<T, K, E>,
179
+ ): SelectorFamily<T, K, E>
180
+ export function withdraw<T, K extends Canonical, E>(
175
181
  store: Store,
176
- token: WritableFamilyToken<T, K>,
177
- ): WritableFamily<T, K>
178
- export function withdraw<T, K extends Canonical>(
182
+ token: WritableFamilyToken<T, K, E>,
183
+ ): WritableFamily<T, K, E>
184
+ export function withdraw<T, K extends Canonical, E>(
179
185
  store: Store,
180
- token: ReadableFamilyToken<T, K>,
181
- ): ReadableFamily<T, K>
186
+ token: ReadableFamilyToken<T, K, E>,
187
+ ): ReadableFamily<T, K, E>
182
188
 
183
189
  export function withdraw<T extends Fn>(
184
190
  store: Store,
@@ -189,14 +195,14 @@ export function withdraw<T>(
189
195
  token: TimelineToken<T>,
190
196
  ): Timeline<T extends TimelineManageable ? T : never>
191
197
 
192
- export function withdraw<T>(
198
+ export function withdraw<T, E>(
193
199
  store: Store,
194
- token: WritableToken<T>,
195
- ): WritableState<T>
196
- export function withdraw<T>(
200
+ token: WritableToken<T, any, E>,
201
+ ): WritableState<T, E>
202
+ export function withdraw<T, E>(
197
203
  store: Store,
198
- token: ReadableToken<T>,
199
- ): ReadableState<T>
204
+ token: ReadableToken<T, any, E>,
205
+ ): ReadableState<T, E>
200
206
 
201
207
  export function withdraw(
202
208
  store: Store,
@@ -2,7 +2,10 @@ import type { ReadableState } from ".."
2
2
  import { newest } from "../lineage"
3
3
  import type { Store } from "../store"
4
4
 
5
- export const recallState = <T>(store: Store, state: ReadableState<T>): T => {
5
+ export const recallState = <T, E>(
6
+ store: Store,
7
+ state: ReadableState<T, E>,
8
+ ): T => {
6
9
  const target = newest(store)
7
10
  if (target.operation.open) {
8
11
  return target.operation.prev.get(state.key)
@@ -5,8 +5,8 @@ import { recallState } from "./recall-state"
5
5
 
6
6
  export const subscribeToRootDependency = (
7
7
  target: Store,
8
- selector: Selector<any>,
9
- atom: Atom<any>,
8
+ selector: Selector<any, any>,
9
+ atom: Atom<any, any>,
10
10
  ): (() => void) => {
11
11
  return atom.subject.subscribe(
12
12
  `${selector.type}:${selector.key}`,
@@ -7,11 +7,11 @@ import type { Store } from "../store"
7
7
  import { withdraw } from "../store"
8
8
  import { subscribeToRootDependency } from "./subscribe-to-root-atoms"
9
9
 
10
- export function subscribeToState<T>(
10
+ export function subscribeToState<T, E>(
11
11
  store: Store,
12
- token: ReadableToken<T>,
12
+ token: ReadableToken<T, any, E>,
13
13
  key: string,
14
- handleUpdate: UpdateHandler<T>,
14
+ handleUpdate: UpdateHandler<E | T>,
15
15
  ): () => void {
16
16
  function safelyHandleUpdate(update: StateUpdate<any>): void {
17
17
  if (store.operation.open) {
@@ -33,7 +33,7 @@ export function subscribeToState<T>(
33
33
  state.type === `writable_pure_selector` ||
34
34
  state.type === `readonly_pure_selector`
35
35
  const rootSubs = new Map<string, () => void>()
36
- let updateHandler: UpdateHandler<T> = safelyHandleUpdate
36
+ let updateHandler: UpdateHandler<E | T> = safelyHandleUpdate
37
37
  if (isSelector) {
38
38
  readOrComputeValue(store, state)
39
39
  for (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {
@@ -21,6 +21,7 @@ import { newest } from "../lineage"
21
21
  import { getUpdateToken } from "../mutable"
22
22
  import { deposit, type Store, withdraw } from "../store"
23
23
  import { Subject } from "../subject"
24
+ import type { RootStore } from "../transaction"
24
25
  import { isChildStore } from "../transaction"
25
26
 
26
27
  export type Timeline<ManagedAtom extends TimelineManageable> = {
@@ -31,13 +32,13 @@ export type Timeline<ManagedAtom extends TimelineManageable> = {
31
32
  history: TimelineEvent<ManagedAtom>[]
32
33
  selectorTime: number | null
33
34
  transactionKey: string | null
34
- install: (store: Store) => void
35
+ install: (store: RootStore) => void
35
36
  subject: Subject<TimelineEvent<ManagedAtom> | `redo` | `undo`>
36
37
  subscriptions: Map<string, () => void>
37
38
  }
38
39
 
39
40
  export function createTimeline<ManagedAtom extends TimelineManageable>(
40
- store: Store,
41
+ store: RootStore,
41
42
  options: TimelineOptions<ManagedAtom>,
42
43
  data?: Timeline<ManagedAtom>,
43
44
  ): TimelineToken<ManagedAtom> {
@@ -62,7 +63,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
62
63
  case `atom`:
63
64
  case `mutable_atom`:
64
65
  {
65
- const atomToken: AtomToken<ManagedAtom> = initialTopic
66
+ const atomToken: AtomToken<any, any, any> = initialTopic
66
67
  const atomKey = atomToken.key
67
68
  let existingTimelineKey = target.timelineTopics.getRelatedKey(atomKey)
68
69
  if (`family` in atomToken) {
@@ -94,7 +95,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
94
95
  case `atom_family`:
95
96
  case `mutable_atom_family`:
96
97
  {
97
- const familyToken: AtomFamilyToken<any, any> = initialTopic
98
+ const familyToken: AtomFamilyToken<any, any, any> = initialTopic
98
99
  const familyKey = familyToken.key
99
100
  const existingTimelineKey =
100
101
  target.timelineTopics.getRelatedKey(familyKey)
@@ -124,7 +125,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
124
125
 
125
126
  function addAtomToTimeline(
126
127
  store: Store,
127
- atomToken: AtomToken<any>,
128
+ atomToken: AtomToken<any, any, any>,
128
129
  tl: Timeline<any>,
129
130
  ): void {
130
131
  reduceReference(store, atomToken)
@@ -191,7 +192,7 @@ function addAtomToTimeline(
191
192
  tl.selectorTime = null
192
193
 
193
194
  const atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any> = {
194
- write: true,
195
+ checkpoint: true,
195
196
  type: `atom_update`,
196
197
  token: deposit(atom),
197
198
  update,
@@ -213,7 +214,7 @@ function addAtomToTimeline(
213
214
 
214
215
  function addAtomFamilyToTimeline(
215
216
  store: Store,
216
- atomFamilyToken: AtomFamilyToken<any, any>,
217
+ atomFamilyToken: AtomFamilyToken<any, any, any>,
217
218
  tl: Timeline<any>,
218
219
  ): void {
219
220
  const family = withdraw(store, atomFamilyToken)
@@ -267,7 +268,7 @@ function joinTransaction(
267
268
 
268
269
  const timelineTransactionUpdate: TimelineEvent<any> &
269
270
  TransactionOutcomeEvent<TransactionToken<any>> = {
270
- write: true,
271
+ checkpoint: true,
271
272
  ...transactionUpdate,
272
273
  subEvents: subEventsFiltered,
273
274
  }
@@ -282,7 +283,7 @@ function joinTransaction(
282
283
  function buildSelectorUpdate(
283
284
  store: Store,
284
285
  tl: Timeline<any>,
285
- atomToken: AtomToken<any>,
286
+ atomToken: AtomToken<any, any, any>,
286
287
  eventOrUpdate: StateCreationEvent<any> | StateUpdate<any>,
287
288
  currentSelectorToken: WritablePureSelectorToken<any>,
288
289
  currentSelectorTime: number,
@@ -291,7 +292,7 @@ function buildSelectorUpdate(
291
292
  if (currentSelectorTime !== tl.selectorTime) {
292
293
  const selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any> =
293
294
  (latestUpdate = {
294
- write: true,
295
+ checkpoint: true,
295
296
  type: `selector_update`,
296
297
  timestamp: currentSelectorTime,
297
298
  token: currentSelectorToken,
@@ -52,7 +52,10 @@ export const timeTravel = (
52
52
  switch (action) {
53
53
  case `undo`:
54
54
  --nextIndex
55
- while (nextIndex !== 0 && timelineData.history[nextIndex].write !== true) {
55
+ while (
56
+ nextIndex !== 0 &&
57
+ timelineData.history[nextIndex].checkpoint !== true
58
+ ) {
56
59
  --nextIndex
57
60
  }
58
61
  events = timelineData.history.slice(nextIndex, timelineData.at).reverse()
@@ -88,8 +91,6 @@ export const timeTravel = (
88
91
  ingestDisposalEvent(store, event, applying)
89
92
  break
90
93
  }
91
- case `molecule_creation`:
92
- case `molecule_disposal`:
93
94
  }
94
95
  }
95
96
 
@@ -1,19 +1,7 @@
1
- import { newest } from "../lineage"
2
- import type { Store } from "../store"
3
- import { isChildStore } from "./is-root-store"
1
+ import type { ChildStore } from "./is-root-store"
4
2
 
5
- export const abortTransaction = (store: Store): void => {
6
- const target = newest(store)
7
- if (!isChildStore(target)) {
8
- store.logger.warn(
9
- `🐞`,
10
- `transaction`,
11
- `???`,
12
- `abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,
13
- )
14
- return
15
- }
16
- store.logger.info(
3
+ export const abortTransaction = (target: ChildStore): void => {
4
+ target.logger.info(
17
5
  `🪂`,
18
6
  `transaction`,
19
7
  target.transactionMeta.update.token.key,
@@ -1,6 +1,5 @@
1
1
  import type { TransactionToken } from "atom.io"
2
2
 
3
- import { NotFoundError } from "../not-found-error"
4
3
  import type { Store } from "../store"
5
4
  import { withdraw } from "../store"
6
5
  import type { Fn } from "../utility-types"
@@ -12,9 +11,6 @@ export function actUponStore<F extends Fn>(
12
11
  ): (...parameters: Parameters<F>) => ReturnType<F> {
13
12
  return (...parameters: Parameters<F>): ReturnType<F> => {
14
13
  const tx = withdraw(store, token)
15
- if (tx) {
16
- return tx.run(parameters, id)
17
- }
18
- throw new NotFoundError(token, store)
14
+ return tx.run(parameters, id)
19
15
  }
20
16
  }
@@ -1,30 +1,18 @@
1
1
  import { ingestTransactionOutcomeEvent } from "../events"
2
2
  import { newest } from "../lineage"
3
- import type { Store } from "../store"
4
3
  import { withdraw } from "../store"
5
4
  import type { Fn } from "../utility-types"
5
+ import type { ChildStore } from "./is-root-store"
6
6
  import { isChildStore, isRootStore } from "./is-root-store"
7
7
  import { setEpochNumberOfAction } from "./set-epoch-number"
8
8
 
9
9
  export function applyTransaction<F extends Fn>(
10
- store: Store,
10
+ store: ChildStore,
11
11
  output: ReturnType<F>,
12
12
  ): void {
13
13
  const child = newest(store)
14
14
  const { parent } = child
15
- if (
16
- parent === null ||
17
- !isChildStore(child) ||
18
- child.transactionMeta?.phase !== `building`
19
- ) {
20
- store.logger.warn(
21
- `🐞`,
22
- `transaction`,
23
- `???`,
24
- `applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,
25
- )
26
- return
27
- }
15
+
28
16
  child.transactionMeta.phase = `applying`
29
17
  child.transactionMeta.update.output = output
30
18
  parent.child = null
@@ -1,15 +1,10 @@
1
- import type { Store } from "../store"
2
- import { isRootStore } from "./is-root-store"
1
+ import type { RootStore } from "./is-root-store"
3
2
 
4
3
  export function assignTransactionToContinuity(
5
- store: Store,
4
+ store: RootStore,
6
5
  continuityKey: string,
7
6
  transactionKey: string,
8
7
  ): void {
9
- const isRoot = isRootStore(store)
10
- if (!isRoot) {
11
- return
12
- }
13
8
  const { epoch, actionContinuities } = store.transactionMeta
14
9
  actionContinuities.set(continuityKey, transactionKey)
15
10
  if (!epoch.has(continuityKey)) {
@@ -15,19 +15,18 @@ import { newest } from "../lineage"
15
15
  import { getJsonToken } from "../mutable"
16
16
  import { MapOverlay } from "../overlays/map-overlay"
17
17
  import { resetInStore, setIntoStore } from "../set-state"
18
- import type { Store } from "../store"
19
18
  import type { Fn } from "../utility-types"
20
19
  import type { TransactionProgress } from "."
21
20
  import { actUponStore, getEpochNumberOfAction } from "."
22
21
  import type { ChildStore, RootStore } from "./is-root-store"
23
22
 
24
23
  export const buildTransaction = (
25
- store: Store,
24
+ store: RootStore,
26
25
  token: TransactionToken<any>,
27
26
  params: any[],
28
27
  id: string,
29
28
  ): ChildStore => {
30
- const parent = newest(store) as ChildStore | RootStore
29
+ const parent = newest(store)
31
30
  const childBase: Omit<ChildStore, `transactionMeta`> = {
32
31
  parent,
33
32
  child: null,
@@ -5,24 +5,24 @@ import type {
5
5
  } from "atom.io"
6
6
 
7
7
  import { newest } from "../lineage"
8
- import type { Store } from "../store"
9
8
  import { deposit } from "../store"
10
9
  import { Subject } from "../subject"
11
10
  import type { Fn } from "../utility-types"
12
11
  import { abortTransaction } from "./abort-transaction"
13
12
  import { applyTransaction } from "./apply-transaction"
14
13
  import { buildTransaction } from "./build-transaction"
14
+ import type { RootStore } from "./is-root-store"
15
15
 
16
16
  export type Transaction<F extends Fn> = {
17
17
  key: string
18
18
  type: `transaction`
19
- install: (store: Store) => void
19
+ install: (store: RootStore) => void
20
20
  subject: Subject<TransactionOutcomeEvent<TransactionToken<F>>>
21
21
  run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
22
22
  }
23
23
 
24
24
  export function createTransaction<F extends Fn>(
25
- store: Store,
25
+ store: RootStore,
26
26
  options: TransactionOptions<F>,
27
27
  ): TransactionToken<F> {
28
28
  const { key } = options
@@ -32,10 +32,9 @@ export function createTransaction<F extends Fn>(
32
32
  type: `transaction`,
33
33
  run: (params: Parameters<F>, id: string) => {
34
34
  const token = deposit(newTransaction)
35
- const childStore = buildTransaction(store, token, params, id)
35
+ const target = buildTransaction(store, token, params, id)
36
36
  try {
37
- const target = newest(store)
38
- const { toolkit } = childStore.transactionMeta
37
+ const { toolkit } = target.transactionMeta
39
38
  const output = options.do(toolkit, ...params)
40
39
  applyTransaction<F>(target, output)
41
40
  return output
@@ -1,6 +1,4 @@
1
- import type { Store } from "../store"
2
1
  import type { RootStore } from "./is-root-store"
3
- import { isRootStore } from "./is-root-store"
4
2
 
5
3
  export function getContinuityKey(
6
4
  store: RootStore,
@@ -21,13 +19,9 @@ export function getEpochNumberOfContinuity(
21
19
  }
22
20
 
23
21
  export function getEpochNumberOfAction(
24
- store: Store,
22
+ store: RootStore,
25
23
  transactionKey: string,
26
24
  ): number | undefined {
27
- const isRoot = isRootStore(store)
28
- if (!isRoot) {
29
- return undefined
30
- }
31
25
  const continuityKey = getContinuityKey(store, transactionKey)
32
26
  if (continuityKey === undefined) {
33
27
  return undefined
@@ -1,27 +1,19 @@
1
- import type { Store } from "../store"
2
1
  import { getContinuityKey } from "./get-epoch-number"
3
- import { isRootStore } from "./is-root-store"
2
+ import type { RootStore } from "./is-root-store"
4
3
 
5
4
  export function setEpochNumberOfContinuity(
6
- store: Store,
5
+ store: RootStore,
7
6
  continuityKey: string,
8
7
  newEpoch: number,
9
8
  ): void {
10
- const isRoot = isRootStore(store)
11
- if (isRoot && continuityKey) {
12
- store.transactionMeta.epoch.set(continuityKey, newEpoch)
13
- }
9
+ store.transactionMeta.epoch.set(continuityKey, newEpoch)
14
10
  }
15
11
 
16
12
  export function setEpochNumberOfAction(
17
- store: Store,
13
+ store: RootStore,
18
14
  transactionKey: string,
19
15
  newEpoch: number,
20
16
  ): void {
21
- const isRoot = isRootStore(store)
22
- if (!isRoot) {
23
- return
24
- }
25
17
  const continuityKey = getContinuityKey(store, transactionKey)
26
18
 
27
19
  if (continuityKey !== undefined) {
@@ -8,10 +8,10 @@ import {
8
8
 
9
9
  import type { WritableTokenIndex } from "."
10
10
 
11
- export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>
11
+ export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown, any, unknown>>
12
12
 
13
13
  export const attachAtomIndex = (store: Store): AtomToken<AtomTokenIndex> => {
14
- return createRegularAtom<AtomTokenIndex>(
14
+ return createRegularAtom<AtomTokenIndex, never, never>(
15
15
  store,
16
16
  {
17
17
  key: `🔍 Atom Token Index`,
@@ -6,7 +6,7 @@ import type {
6
6
  TransactionOutcomeEvent,
7
7
  TransactionToken,
8
8
  } from "atom.io"
9
- import type { Fn, Store, Timeline } from "atom.io/internal"
9
+ import type { Fn, RootStore, Store, Timeline } from "atom.io/internal"
10
10
 
11
11
  import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
12
12
  import type { SelectorTokenIndex } from "./attach-selector-index"
@@ -30,7 +30,9 @@ export type IntrospectionStates = {
30
30
  typeSelectors: ReadonlyPureSelectorFamilyToken<Loadable<string>, string>
31
31
  }
32
32
 
33
- export const attachIntrospectionStates = (store: Store): IntrospectionStates => {
33
+ export const attachIntrospectionStates = (
34
+ store: RootStore,
35
+ ): IntrospectionStates => {
34
36
  return {
35
37
  atomIndex: attachAtomIndex(store),
36
38
  selectorIndex: attachSelectorIndex(store),
@@ -8,12 +8,14 @@ import {
8
8
 
9
9
  import type { WritableTokenIndex } from "."
10
10
 
11
- export type SelectorTokenIndex = WritableTokenIndex<SelectorToken<unknown>>
11
+ export type SelectorTokenIndex = WritableTokenIndex<
12
+ SelectorToken<unknown, any, any>
13
+ >
12
14
 
13
15
  export const attachSelectorIndex = (
14
16
  store: Store,
15
17
  ): AtomToken<SelectorTokenIndex> => {
16
- return createRegularAtom<SelectorTokenIndex>(
18
+ return createRegularAtom<SelectorTokenIndex, never, never>(
17
19
  store,
18
20
  {
19
21
  key: `🔍 Selector Token Index`,