atom.io 0.36.2 → 0.37.0

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 (120) hide show
  1. package/dist/data/index.d.ts.map +1 -1
  2. package/dist/data/index.js.map +1 -1
  3. package/dist/eslint-plugin/index.js +1 -2
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +66 -98
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +544 -507
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/introspection/index.d.ts +2 -2
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +1 -1
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/json/index.d.ts +2 -1
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js.map +1 -1
  16. package/dist/main/index.d.ts +154 -139
  17. package/dist/main/index.d.ts.map +1 -1
  18. package/dist/main/index.js.map +1 -1
  19. package/dist/react/index.d.ts.map +1 -1
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react-devtools/index.d.ts.map +1 -1
  22. package/dist/react-devtools/index.js +54 -56
  23. package/dist/react-devtools/index.js.map +1 -1
  24. package/dist/realtime/index.d.ts.map +1 -1
  25. package/dist/realtime/index.js.map +1 -1
  26. package/dist/realtime-client/index.d.ts +3 -3
  27. package/dist/realtime-client/index.d.ts.map +1 -1
  28. package/dist/realtime-client/index.js +6 -6
  29. package/dist/realtime-client/index.js.map +1 -1
  30. package/dist/realtime-react/index.d.ts.map +1 -1
  31. package/dist/realtime-react/index.js.map +1 -1
  32. package/dist/realtime-server/index.d.ts +5 -5
  33. package/dist/realtime-server/index.d.ts.map +1 -1
  34. package/dist/realtime-server/index.js +10 -12
  35. package/dist/realtime-server/index.js.map +1 -1
  36. package/dist/realtime-testing/index.d.ts.map +1 -1
  37. package/dist/realtime-testing/index.js.map +1 -1
  38. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  39. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  40. package/dist/transceivers/set-rtx/index.js +1 -3
  41. package/dist/transceivers/set-rtx/index.js.map +1 -1
  42. package/dist/use-o-DXPncKmZ.js.map +1 -1
  43. package/dist/web/index.d.ts +2 -2
  44. package/dist/web/index.d.ts.map +1 -1
  45. package/dist/web/index.js.map +1 -1
  46. package/package.json +14 -14
  47. package/src/internal/atom/dispose-atom.ts +5 -4
  48. package/src/internal/caching.ts +3 -3
  49. package/src/internal/families/create-readonly-held-selector-family.ts +3 -5
  50. package/src/internal/families/create-readonly-pure-selector-family.ts +3 -5
  51. package/src/internal/families/create-regular-atom-family.ts +3 -6
  52. package/src/internal/families/create-writable-held-selector-family.ts +3 -5
  53. package/src/internal/families/create-writable-pure-selector-family.ts +3 -5
  54. package/src/internal/families/find-in-store.ts +17 -34
  55. package/src/internal/families/init-family-member.ts +5 -87
  56. package/src/internal/families/mint-in-store.ts +74 -0
  57. package/src/internal/get-state/read-or-compute-value.ts +4 -2
  58. package/src/internal/index.ts +19 -18
  59. package/src/internal/ingest-updates/ingest-atom-update.ts +7 -7
  60. package/src/internal/ingest-updates/ingest-creation-disposal.ts +11 -11
  61. package/src/internal/ingest-updates/ingest-selector-update.ts +8 -4
  62. package/src/internal/ingest-updates/ingest-transaction-update.ts +5 -6
  63. package/src/internal/install-into-store.ts +2 -2
  64. package/src/internal/join/join-internal.ts +1 -1
  65. package/src/internal/molecule.ts +12 -9
  66. package/src/internal/mutable/create-mutable-atom-family.ts +3 -6
  67. package/src/internal/mutable/tracker.ts +2 -2
  68. package/src/internal/mutable/transceiver.ts +6 -4
  69. package/src/internal/operation.ts +17 -14
  70. package/src/internal/selector/create-readonly-held-selector.ts +9 -7
  71. package/src/internal/selector/create-readonly-pure-selector.ts +8 -5
  72. package/src/internal/selector/create-writable-held-selector.ts +12 -21
  73. package/src/internal/selector/create-writable-pure-selector.ts +16 -29
  74. package/src/internal/selector/dispose-selector.ts +6 -1
  75. package/src/internal/selector/get-selector-dependency-keys.ts +2 -6
  76. package/src/internal/selector/register-selector.ts +64 -74
  77. package/src/internal/selector/trace-selector-atoms.ts +2 -2
  78. package/src/internal/selector/update-selector-atoms.ts +2 -2
  79. package/src/internal/set-state/dispatch-state-update.ts +101 -0
  80. package/src/internal/set-state/operate-on-store.ts +126 -0
  81. package/src/internal/set-state/reset-atom-or-selector.ts +24 -15
  82. package/src/internal/set-state/set-atom-or-selector.ts +9 -4
  83. package/src/internal/set-state/set-atom.ts +4 -49
  84. package/src/internal/set-state/set-into-store.ts +11 -77
  85. package/src/internal/set-state/set-selector.ts +35 -0
  86. package/src/internal/store/store.ts +4 -4
  87. package/src/internal/subscribe/subscribe-in-store.ts +3 -3
  88. package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
  89. package/src/internal/timeline/create-timeline.ts +57 -101
  90. package/src/internal/timeline/time-travel.ts +1 -1
  91. package/src/internal/transaction/abort-transaction.ts +1 -1
  92. package/src/internal/transaction/apply-transaction.ts +7 -7
  93. package/src/internal/transaction/build-transaction.ts +10 -9
  94. package/src/internal/transaction/create-transaction.ts +4 -3
  95. package/src/internal/transaction/index.ts +6 -2
  96. package/src/introspection/attach-introspection-states.ts +2 -2
  97. package/src/introspection/attach-transaction-logs.ts +13 -6
  98. package/src/json/index.ts +3 -1
  99. package/src/main/atom.ts +2 -1
  100. package/src/main/events.ts +109 -0
  101. package/src/main/get-state.ts +1 -1
  102. package/src/main/index.ts +3 -0
  103. package/src/main/subscribe.ts +9 -19
  104. package/src/main/timeline.ts +3 -21
  105. package/src/main/transaction.ts +0 -65
  106. package/src/main/validators.ts +8 -2
  107. package/src/react-devtools/TimelineIndex.tsx +1 -1
  108. package/src/react-devtools/TransactionIndex.tsx +5 -3
  109. package/src/react-devtools/Updates.tsx +54 -46
  110. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +20 -10
  111. package/src/realtime-client/realtime-client-stores/client-sync-store.ts +4 -4
  112. package/src/realtime-client/sync-continuity.ts +1 -1
  113. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +14 -8
  114. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +5 -2
  115. package/src/realtime-server/continuity/subscribe-to-continuity-actions.ts +1 -1
  116. package/src/realtime-server/realtime-action-receiver.ts +6 -3
  117. package/src/realtime-server/realtime-server-stores/server-sync-store.ts +13 -16
  118. package/src/transceivers/set-rtx/set-rtx.ts +1 -3
  119. package/src/web/persist-sync.ts +2 -2
  120. package/src/internal/set-state/emit-update.ts +0 -40
@@ -4,6 +4,7 @@ import type {
4
4
  getState,
5
5
  resetState,
6
6
  setState,
7
+ TransactionToken,
7
8
  } from "atom.io"
8
9
 
9
10
  import { arbitrary } from "../arbitrary"
@@ -23,7 +24,7 @@ import type { ChildStore, RootStore } from "./is-root-store"
23
24
 
24
25
  export const buildTransaction = (
25
26
  store: Store,
26
- key: string,
27
+ token: TransactionToken<any>,
27
28
  params: any[],
28
29
  id: string,
29
30
  ): ChildStore => {
@@ -65,15 +66,16 @@ export const buildTransaction = (
65
66
  }),
66
67
  miscResources: new LazyMap(parent.miscResources),
67
68
  }
68
- const epoch = getEpochNumberOfAction(store, key)
69
+ const epoch = getEpochNumberOfAction(store, token.key)
69
70
  const transactionMeta: TransactionProgress<Fn> = {
70
71
  phase: `building`,
71
72
  update: {
72
- type: `transaction_update`,
73
- key,
73
+ type: `transaction_outcome`,
74
+ token,
74
75
  id,
75
76
  epoch: epoch === undefined ? Number.NaN : epoch + 1,
76
- updates: [],
77
+ timestamp: Date.now(),
78
+ subEvents: [],
77
79
  params,
78
80
  output: undefined,
79
81
  },
@@ -86,11 +88,10 @@ export const buildTransaction = (
86
88
  reset: ((...ps: Parameters<typeof resetState>) => {
87
89
  resetInStore(child, ...ps)
88
90
  }) as typeof resetState,
89
- run: (token, identifier = arbitrary()) =>
90
- actUponStore(child, token, identifier),
91
+ run: (t, identifier = arbitrary()) => actUponStore(child, t, identifier),
91
92
  find: ((...ps: Parameters<typeof findState>) =>
92
93
  findInStore(store, ...ps)) as typeof findState,
93
- json: (token) => getJsonToken(child, token),
94
+ json: (t) => getJsonToken(child, t),
94
95
  dispose: ((...ps: Parameters<typeof disposeState>) => {
95
96
  disposeFromStore(child, ...ps)
96
97
  }) as typeof disposeState,
@@ -104,7 +105,7 @@ export const buildTransaction = (
104
105
  store.logger.info(
105
106
  `🛫`,
106
107
  `transaction`,
107
- key,
108
+ token.key,
108
109
  `Building transaction with params:`,
109
110
  params,
110
111
  )
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  TransactionOptions,
3
+ TransactionOutcomeEvent,
3
4
  TransactionToken,
4
- TransactionUpdate,
5
5
  } from "atom.io"
6
6
 
7
7
  import { newest } from "../lineage"
@@ -17,7 +17,7 @@ export type Transaction<F extends Fn> = {
17
17
  key: string
18
18
  type: `transaction`
19
19
  install: (store: Store) => void
20
- subject: Subject<TransactionUpdate<F>>
20
+ subject: Subject<TransactionOutcomeEvent<TransactionToken<F>>>
21
21
  run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
22
22
  }
23
23
 
@@ -31,7 +31,8 @@ export function createTransaction<F extends Fn>(
31
31
  key,
32
32
  type: `transaction`,
33
33
  run: (params: Parameters<F>, id: string) => {
34
- const childStore = buildTransaction(store, key, params, id)
34
+ const token = deposit(newTransaction)
35
+ const childStore = buildTransaction(store, token, params, id)
35
36
  try {
36
37
  const target = newest(store)
37
38
  const { toolkit } = childStore.transactionMeta
@@ -1,4 +1,8 @@
1
- import type { ActorToolkit, TransactionUpdate } from "atom.io"
1
+ import type {
2
+ ActorToolkit,
3
+ TransactionOutcomeEvent,
4
+ TransactionToken,
5
+ } from "atom.io"
2
6
 
3
7
  import type { Junction } from "../junction"
4
8
  import type { Fn } from "../utility-types"
@@ -18,7 +22,7 @@ export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
18
22
 
19
23
  export type TransactionProgress<F extends Fn> = {
20
24
  phase: `applying` | `building`
21
- update: TransactionUpdate<F>
25
+ update: TransactionOutcomeEvent<TransactionToken<F>>
22
26
  toolkit: ActorToolkit
23
27
  }
24
28
 
@@ -3,8 +3,8 @@ import type {
3
3
  Loadable,
4
4
  ReadonlyPureSelectorFamilyToken,
5
5
  TimelineToken,
6
+ TransactionOutcomeEvent,
6
7
  TransactionToken,
7
- TransactionUpdate,
8
8
  } from "atom.io"
9
9
  import type { Fn, Store, Timeline } from "atom.io/internal"
10
10
 
@@ -22,7 +22,7 @@ export type IntrospectionStates = {
22
22
  selectorIndex: AtomToken<SelectorTokenIndex>
23
23
  transactionIndex: AtomToken<TransactionToken<Fn>[]>
24
24
  transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
25
- TransactionUpdate<Fn>[],
25
+ TransactionOutcomeEvent<TransactionToken<Fn>>[],
26
26
  string
27
27
  >
28
28
  timelineIndex: AtomToken<TimelineToken<any>[]>
@@ -1,12 +1,19 @@
1
- import type { ReadonlyPureSelectorFamilyToken, TransactionUpdate } from "atom.io"
2
- import type { Fn, Store } from "atom.io/internal"
1
+ import type {
2
+ ReadonlyPureSelectorFamilyToken,
3
+ TransactionOutcomeEvent,
4
+ TransactionToken,
5
+ } from "atom.io"
6
+ import type { Store } from "atom.io/internal"
3
7
  import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
4
8
 
5
9
  export const attachTransactionLogs = (
6
10
  store: Store,
7
- ): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Fn>[], string> => {
11
+ ): ReadonlyPureSelectorFamilyToken<
12
+ TransactionOutcomeEvent<TransactionToken<any>>[],
13
+ string
14
+ > => {
8
15
  const transactionUpdateLogAtoms = createRegularAtomFamily<
9
- TransactionUpdate<Fn>[],
16
+ TransactionOutcomeEvent<TransactionToken<any>>[],
10
17
  string
11
18
  >(store, {
12
19
  key: `🔍 Transaction Update Log (Internal)`,
@@ -15,7 +22,7 @@ export const attachTransactionLogs = (
15
22
  ({ setSelf }) => {
16
23
  const tx = store.transactions.get(key)
17
24
  tx?.subject.subscribe(`introspection`, (transactionUpdate) => {
18
- if (transactionUpdate.key === key) {
25
+ if (transactionUpdate.token.key === key) {
19
26
  setSelf((state) => [...state, transactionUpdate])
20
27
  }
21
28
  })
@@ -23,7 +30,7 @@ export const attachTransactionLogs = (
23
30
  ],
24
31
  })
25
32
  const findTransactionUpdateLogState = createSelectorFamily<
26
- TransactionUpdate<Fn>[],
33
+ TransactionOutcomeEvent<TransactionToken<any>>[],
27
34
  string
28
35
  >(store, {
29
36
  key: `🔍 Transaction Update Log`,
package/src/json/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ViewOf } from "atom.io"
2
+
1
3
  export * from "./entries"
2
4
 
3
5
  export type primitive = boolean | number | string | null
@@ -80,7 +82,7 @@ export type Canonical = primitive | ReadonlyArray<Canonical>
80
82
  export type JsonIO = (...params: Json.Serializable[]) => Json.Serializable | void
81
83
 
82
84
  export type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {
83
- toJson: (t: T) => J
85
+ toJson: (t: ViewOf<T>) => J
84
86
  fromJson: (json: J) => T
85
87
  }
86
88
 
package/src/main/atom.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  } from "atom.io/internal"
9
9
  import type { Canonical } from "atom.io/json"
10
10
 
11
+ import type { StateUpdate } from "./events"
11
12
  import type { Setter } from "./set-state"
12
13
  import type {
13
14
  MutableAtomFamilyToken,
@@ -75,7 +76,7 @@ export type Effectors<T> = {
75
76
  */
76
77
  setSelf: <New extends T>(next: New | Setter<T, New>) => void
77
78
  /** Subscribe to changes to the atom */
78
- onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
79
+ onSet: (callback: (options: StateUpdate<T>) => void) => void
79
80
  }
80
81
 
81
82
  export type RegularAtomFamilyOptions<T, K extends Canonical> = {
@@ -0,0 +1,109 @@
1
+ import type { ViewOf } from "atom.io"
2
+ import type { Canonical, stringified } from "atom.io/json"
3
+
4
+ import type { AtomOnly, TimelineManageable } from "./timeline"
5
+ import type {
6
+ AtomToken,
7
+ ReadableToken,
8
+ SelectorToken,
9
+ TransactionToken,
10
+ } from "./tokens"
11
+ import type { TokenType } from "./validators"
12
+
13
+ export type StateUpdate<T> = {
14
+ readonly oldValue: ViewOf<T>
15
+ readonly newValue: ViewOf<T>
16
+ }
17
+
18
+ export type AtomUpdateEvent<A extends AtomToken<any>> = {
19
+ type: `atom_update`
20
+ token: A
21
+ update: StateUpdate<TokenType<A>>
22
+ timestamp: number
23
+ }
24
+
25
+ export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
26
+ type: `selector_update`
27
+ token: SelectorToken<any>
28
+ atomUpdates: AtomUpdateEvent<AtomOnly<A>>[]
29
+ timestamp: number
30
+ }
31
+
32
+ export type StateLifecycleEvent<R extends ReadableToken<any>> =
33
+ | StateCreationEvent<R>
34
+ | StateDisposalEvent<R>
35
+ export type StateCreationEvent<R extends ReadableToken<any>> = {
36
+ type: `state_creation`
37
+ token: R
38
+ timestamp: number
39
+ }
40
+ export type StateDisposalEvent<R extends ReadableToken<any>> =
41
+ | AtomDisposalEvent<R>
42
+ | SelectorDisposalEvent<R>
43
+
44
+ export type AtomDisposalEvent<R extends ReadableToken<any>> = {
45
+ type: `state_disposal`
46
+ subType: `atom`
47
+ token: R
48
+ value: TokenType<R>
49
+ timestamp: number
50
+ }
51
+ export type SelectorDisposalEvent<R extends ReadableToken<any>> = {
52
+ type: `state_disposal`
53
+ subType: `selector`
54
+ token: R
55
+ timestamp: number
56
+ }
57
+
58
+ export type MoleculeCreationEvent = {
59
+ type: `molecule_creation`
60
+ key: Canonical
61
+ provenance: Canonical
62
+ timestamp: number
63
+ }
64
+
65
+ export type MoleculeDisposalEvent = {
66
+ type: `molecule_disposal`
67
+ key: Canonical
68
+ provenance: stringified<Canonical>[]
69
+ values: [key: string, value: any][]
70
+ timestamp: number
71
+ }
72
+
73
+ export type MoleculeTransferEvent = {
74
+ type: `molecule_transfer`
75
+ key: Canonical
76
+ exclusive: boolean
77
+ from: Canonical[]
78
+ to: Canonical[]
79
+ timestamp: number
80
+ }
81
+
82
+ export type TransactionSubEvent =
83
+ | AtomUpdateEvent<AtomToken<any>>
84
+ | MoleculeCreationEvent
85
+ | MoleculeDisposalEvent
86
+ | MoleculeTransferEvent
87
+ | StateCreationEvent<ReadableToken<unknown>>
88
+ | StateDisposalEvent<ReadableToken<unknown>>
89
+ | TransactionOutcomeEvent<TransactionToken<any>>
90
+
91
+ export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
92
+ type: `transaction_outcome`
93
+ token: T
94
+ id: string
95
+ epoch: number
96
+ timestamp: number
97
+ subEvents: TransactionSubEvent[]
98
+ params: Parameters<TokenType<T>>
99
+ output: ReturnType<TokenType<T>>
100
+ }
101
+
102
+ export type TimelineEvent<ManagedAtom extends TimelineManageable> =
103
+ | AtomUpdateEvent<AtomOnly<ManagedAtom>>
104
+ | MoleculeCreationEvent
105
+ | MoleculeDisposalEvent
106
+ | StateCreationEvent<AtomOnly<ManagedAtom>>
107
+ | StateDisposalEvent<AtomOnly<ManagedAtom>>
108
+ | TimelineSelectorUpdateEvent<ManagedAtom>
109
+ | TransactionOutcomeEvent<TransactionToken<any>>
@@ -1,4 +1,4 @@
1
- import type { ViewOf } from "atom.io/internal"
1
+ import type { ViewOf } from "atom.io"
2
2
  import { getFromStore, IMPLICIT } from "atom.io/internal"
3
3
  import type { Canonical } from "atom.io/json"
4
4
 
package/src/main/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./atom"
2
2
  export * from "./dispose-state"
3
+ export type * from "./events"
3
4
  export * from "./find-state"
4
5
  export * from "./get-state"
5
6
  export * from "./join"
@@ -23,3 +24,5 @@ export * from "./validators"
23
24
  * As a result, we consider any state that can be a set to a Promise to be a "loadable" state, whose value may or may not be a Promise at any given time.
24
25
  */
25
26
  export type Loadable<T> = Promise<T> | T
27
+
28
+ export type ViewOf<T> = T extends { READONLY_VIEW: infer View } ? View : T
@@ -1,27 +1,17 @@
1
- import type { Flat, Fn } from "atom.io/internal"
1
+ import type { Fn } from "atom.io/internal"
2
2
  import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
3
3
 
4
4
  import type {
5
- FamilyMetadata,
6
- ReadableToken,
7
- TimelineManageable,
8
- TimelineToken,
9
- TimelineUpdate,
10
- TransactionToken,
11
- TransactionUpdate,
12
- } from "."
5
+ StateUpdate,
6
+ TimelineEvent,
7
+ TransactionOutcomeEvent,
8
+ } from "./events"
9
+ import type { TimelineManageable } from "./timeline"
10
+ import type { ReadableToken, TimelineToken, TransactionToken } from "./tokens"
13
11
 
14
- export type StateUpdate<T> = { newValue: T; oldValue: T }
15
- export type KeyedStateUpdate<T> = Flat<
16
- StateUpdate<T> & {
17
- key: string
18
- type: `atom_update` | `selector_update`
19
- family?: FamilyMetadata
20
- }
21
- >
22
12
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
23
13
  export type TransactionUpdateHandler<F extends Fn> = (
24
- data: TransactionUpdate<F>,
14
+ data: TransactionOutcomeEvent<TransactionToken<F>>,
25
15
  ) => void
26
16
 
27
17
  /**
@@ -60,7 +50,7 @@ export function subscribe<F extends Fn>(
60
50
  */
61
51
  export function subscribe<M extends TimelineManageable>(
62
52
  token: TimelineToken<M>,
63
- handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
53
+ handleUpdate: (update: TimelineEvent<M> | `redo` | `undo`) => void,
64
54
  key?: string,
65
55
  ): () => void
66
56
  export function subscribe(
@@ -1,16 +1,7 @@
1
- import type {
2
- Timeline,
3
- TimelineAtomUpdate,
4
- TimelineMoleculeCreation,
5
- TimelineMoleculeDisposal,
6
- TimelineSelectorUpdate,
7
- TimelineStateCreation,
8
- TimelineStateDisposal,
9
- TimelineTransactionUpdate,
10
- } from "atom.io/internal"
1
+ import type { Timeline } from "atom.io/internal"
11
2
  import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
12
3
 
13
- import type { AtomFamilyToken, AtomToken, TimelineToken } from "."
4
+ import type { AtomFamilyToken, AtomToken, TimelineEvent, TimelineToken } from "."
14
5
 
15
6
  export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
16
7
  export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
@@ -37,15 +28,6 @@ export const undo = (timeline: TimelineToken<any>): void => {
37
28
  timeTravel(IMPLICIT.STORE, `undo`, timeline)
38
29
  }
39
30
 
40
- export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
41
- | TimelineAtomUpdate<ManagedAtom>
42
- | TimelineMoleculeCreation
43
- | TimelineMoleculeDisposal
44
- | TimelineSelectorUpdate<ManagedAtom>
45
- | TimelineStateCreation<AtomOnly<ManagedAtom>>
46
- | TimelineStateDisposal<AtomOnly<ManagedAtom>>
47
- | TimelineTransactionUpdate
48
-
49
31
  export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
50
32
  /** The unique identifier of the timeline */
51
33
  key: string
@@ -53,7 +35,7 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
53
35
  scope: ManagedAtom[]
54
36
  /** A function that determines whether a given update should be recorded */
55
37
  shouldCapture?: (
56
- update: TimelineUpdate<ManagedAtom>,
38
+ update: TimelineEvent<ManagedAtom>,
57
39
  timeline: Timeline<TimelineManageable>,
58
40
  ) => boolean
59
41
  }
@@ -5,82 +5,17 @@ import {
5
5
  createTransaction,
6
6
  IMPLICIT,
7
7
  } from "atom.io/internal"
8
- import type { Canonical, stringified } from "atom.io/json"
9
8
 
10
9
  import type { disposeState } from "./dispose-state"
11
10
  import type { findState } from "./find-state"
12
11
  import type { getState } from "./get-state"
13
12
  import type { resetState } from "./reset-state"
14
13
  import type { setState } from "./set-state"
15
- import type { KeyedStateUpdate } from "./subscribe"
16
14
  import type {
17
15
  MutableAtomToken,
18
- ReadableToken,
19
16
  TransactionToken,
20
17
  WritablePureSelectorToken,
21
18
  } from "./tokens"
22
- import type { TokenType } from "./validators"
23
-
24
- export type StateCreation<Token extends ReadableToken<any>> = {
25
- type: `state_creation`
26
- token: Token
27
- }
28
- export type StateDisposal<Token extends ReadableToken<any>> =
29
- | AtomDisposal<Token>
30
- | SelectorDisposal<Token>
31
- export type StateLifecycleEvent<Token extends ReadableToken<any>> =
32
- | StateCreation<Token>
33
- | StateDisposal<Token>
34
-
35
- export type AtomDisposal<Token extends ReadableToken<any>> = {
36
- type: `state_disposal`
37
- subType: `atom`
38
- token: Token
39
- value: TokenType<Token>
40
- }
41
- export type SelectorDisposal<Token extends ReadableToken<any>> = {
42
- type: `state_disposal`
43
- subType: `selector`
44
- token: Token
45
- }
46
-
47
- export type MoleculeCreation = {
48
- type: `molecule_creation`
49
- key: Canonical
50
- provenance: Canonical
51
- }
52
- export type MoleculeDisposal = {
53
- type: `molecule_disposal`
54
- key: Canonical
55
- provenance: stringified<Canonical>[]
56
- values: [key: string, value: any][]
57
- }
58
- export type MoleculeTransfer = {
59
- type: `molecule_transfer`
60
- key: Canonical
61
- exclusive: boolean
62
- from: Canonical[]
63
- to: Canonical[]
64
- }
65
-
66
- export type TransactionUpdateContent =
67
- | KeyedStateUpdate<unknown>
68
- | MoleculeCreation
69
- | MoleculeDisposal
70
- | MoleculeTransfer
71
- | StateCreation<ReadableToken<unknown>>
72
- | StateDisposal<ReadableToken<unknown>>
73
- | TransactionUpdate<Fn>
74
-
75
- export type TransactionUpdate<F extends Fn> = {
76
- type: `transaction_update`
77
- key: string
78
- id: string
79
- epoch: number
80
- updates: TransactionUpdateContent[]
81
- params: Parameters<F>
82
- output: ReturnType<F>
83
- }
84
19
 
85
20
  export type ReaderToolkit = Pick<ActorToolkit, `find` | `get` | `json`>
86
21
  export type WriterToolkit = Pick<ActorToolkit, `find` | `get` | `json` | `set`>
@@ -7,6 +7,7 @@ import type {
7
7
  ReadonlyPureSelectorToken,
8
8
  RegularAtomFamilyToken,
9
9
  RegularAtomToken,
10
+ TransactionToken,
10
11
  WritableFamilyToken,
11
12
  WritablePureSelectorFamilyToken,
12
13
  WritablePureSelectorToken,
@@ -14,12 +15,17 @@ import type {
14
15
  } from "./tokens"
15
16
 
16
17
  export type TokenType<
17
- Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>,
18
+ Comparison extends
19
+ | ReadableFamilyToken<any, any>
20
+ | ReadableToken<any>
21
+ | TransactionToken<any>,
18
22
  > = Comparison extends ReadableToken<infer RepresentedValue>
19
23
  ? RepresentedValue
20
24
  : Comparison extends ReadableFamilyToken<infer RepresentedValue, any>
21
25
  ? RepresentedValue
22
- : never
26
+ : Comparison extends TransactionToken<infer Fn>
27
+ ? Fn
28
+ : never
23
29
 
24
30
  export function isToken<KnownToken extends RegularAtomToken<any>>(
25
31
  knownToken: KnownToken,
@@ -68,7 +68,7 @@ export const TimelineLog: FC<{
68
68
  update.type !== `molecule_disposal` &&
69
69
  update.type !== `state_creation` &&
70
70
  update.type !== `state_disposal` ? (
71
- <Fragment key={update.key + index + timeline.at}>
71
+ <Fragment key={update.token.key + index + timeline.at}>
72
72
  {index === timeline.at ? <YouAreHere /> : null}
73
73
  <article.TimelineUpdate
74
74
  timelineUpdate={update}
@@ -1,8 +1,8 @@
1
1
  import type {
2
2
  ReadonlyPureSelectorToken,
3
3
  RegularAtomToken,
4
+ TransactionOutcomeEvent,
4
5
  TransactionToken,
5
- TransactionUpdate,
6
6
  } from "atom.io"
7
7
  import { findInStore, type Fn } from "atom.io/internal"
8
8
  import { useI, useO } from "atom.io/react"
@@ -15,7 +15,9 @@ import { article } from "./Updates"
15
15
  export const TransactionLog: FC<{
16
16
  token: TransactionToken<Fn>
17
17
  isOpenState: RegularAtomToken<boolean>
18
- logState: ReadonlyPureSelectorToken<TransactionUpdate<Fn>[]>
18
+ logState: ReadonlyPureSelectorToken<
19
+ TransactionOutcomeEvent<TransactionToken<Fn>>[]
20
+ >
19
21
  }> = ({ token, isOpenState, logState }) => {
20
22
  const log = useO(logState)
21
23
  const isOpen = useO(isOpenState)
@@ -41,7 +43,7 @@ export const TransactionLog: FC<{
41
43
  <main>
42
44
  {log.map((update, index) => (
43
45
  <article.TransactionUpdate
44
- key={update.key + index}
46
+ key={update.token.key + index}
45
47
  serialNumber={index}
46
48
  transactionUpdate={update}
47
49
  />