atom.io 0.36.3 → 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.
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/eslint-plugin/index.js +1 -2
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +66 -98
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +543 -504
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +2 -2
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/json/index.d.ts +2 -1
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +154 -139
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +54 -56
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +3 -3
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +6 -6
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +5 -5
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +10 -12
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +1 -3
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/use-o-DXPncKmZ.js.map +1 -1
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +5 -5
- package/src/internal/atom/dispose-atom.ts +5 -4
- package/src/internal/caching.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +3 -5
- package/src/internal/families/create-readonly-pure-selector-family.ts +3 -5
- package/src/internal/families/create-regular-atom-family.ts +3 -6
- package/src/internal/families/create-writable-held-selector-family.ts +3 -5
- package/src/internal/families/create-writable-pure-selector-family.ts +3 -5
- package/src/internal/families/find-in-store.ts +17 -34
- package/src/internal/families/init-family-member.ts +5 -87
- package/src/internal/families/mint-in-store.ts +74 -0
- package/src/internal/get-state/read-or-compute-value.ts +4 -2
- package/src/internal/index.ts +19 -18
- package/src/internal/ingest-updates/ingest-atom-update.ts +7 -7
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +11 -11
- package/src/internal/ingest-updates/ingest-selector-update.ts +8 -4
- package/src/internal/ingest-updates/ingest-transaction-update.ts +5 -6
- package/src/internal/install-into-store.ts +2 -2
- package/src/internal/join/join-internal.ts +1 -1
- package/src/internal/molecule.ts +12 -9
- package/src/internal/mutable/create-mutable-atom-family.ts +3 -6
- package/src/internal/mutable/tracker.ts +2 -2
- package/src/internal/mutable/transceiver.ts +6 -4
- package/src/internal/operation.ts +17 -14
- package/src/internal/selector/create-readonly-held-selector.ts +9 -7
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -5
- package/src/internal/selector/create-writable-held-selector.ts +12 -21
- package/src/internal/selector/create-writable-pure-selector.ts +15 -28
- package/src/internal/selector/dispose-selector.ts +6 -1
- package/src/internal/selector/get-selector-dependency-keys.ts +2 -6
- package/src/internal/selector/register-selector.ts +64 -74
- package/src/internal/selector/trace-selector-atoms.ts +2 -2
- package/src/internal/selector/update-selector-atoms.ts +2 -2
- package/src/internal/set-state/dispatch-state-update.ts +101 -0
- package/src/internal/set-state/operate-on-store.ts +126 -0
- package/src/internal/set-state/reset-atom-or-selector.ts +24 -15
- package/src/internal/set-state/set-atom-or-selector.ts +9 -4
- package/src/internal/set-state/set-atom.ts +4 -49
- package/src/internal/set-state/set-into-store.ts +11 -77
- package/src/internal/set-state/set-selector.ts +35 -0
- package/src/internal/store/store.ts +4 -4
- package/src/internal/subscribe/subscribe-in-store.ts +3 -3
- package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +57 -101
- package/src/internal/timeline/time-travel.ts +1 -1
- package/src/internal/transaction/abort-transaction.ts +1 -1
- package/src/internal/transaction/apply-transaction.ts +7 -7
- package/src/internal/transaction/build-transaction.ts +10 -9
- package/src/internal/transaction/create-transaction.ts +4 -3
- package/src/internal/transaction/index.ts +6 -2
- package/src/introspection/attach-introspection-states.ts +2 -2
- package/src/introspection/attach-transaction-logs.ts +13 -6
- package/src/json/index.ts +3 -1
- package/src/main/atom.ts +2 -1
- package/src/main/events.ts +109 -0
- package/src/main/get-state.ts +1 -1
- package/src/main/index.ts +3 -0
- package/src/main/subscribe.ts +9 -19
- package/src/main/timeline.ts +3 -21
- package/src/main/transaction.ts +0 -65
- package/src/main/validators.ts +8 -2
- package/src/react-devtools/TimelineIndex.tsx +1 -1
- package/src/react-devtools/TransactionIndex.tsx +5 -3
- package/src/react-devtools/Updates.tsx +54 -46
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +20 -10
- package/src/realtime-client/realtime-client-stores/client-sync-store.ts +4 -4
- package/src/realtime-client/sync-continuity.ts +1 -1
- package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +14 -8
- package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +5 -2
- package/src/realtime-server/continuity/subscribe-to-continuity-actions.ts +1 -1
- package/src/realtime-server/realtime-action-receiver.ts +6 -3
- package/src/realtime-server/realtime-server-stores/server-sync-store.ts +13 -16
- package/src/transceivers/set-rtx/set-rtx.ts +1 -3
- package/src/web/persist-sync.ts +2 -2
- package/src/internal/set-state/emit-update.ts +0 -40
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
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
|
-
|
|
25
|
+
TransactionOutcomeEvent<TransactionToken<Fn>>[],
|
|
26
26
|
string
|
|
27
27
|
>
|
|
28
28
|
timelineIndex: AtomToken<TimelineToken<any>[]>
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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<
|
|
11
|
+
): ReadonlyPureSelectorFamilyToken<
|
|
12
|
+
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
13
|
+
string
|
|
14
|
+
> => {
|
|
8
15
|
const transactionUpdateLogAtoms = createRegularAtomFamily<
|
|
9
|
-
|
|
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
|
-
|
|
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:
|
|
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>>
|
package/src/main/get-state.ts
CHANGED
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
|
package/src/main/subscribe.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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:
|
|
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:
|
|
53
|
+
handleUpdate: (update: TimelineEvent<M> | `redo` | `undo`) => void,
|
|
64
54
|
key?: string,
|
|
65
55
|
): () => void
|
|
66
56
|
export function subscribe(
|
package/src/main/timeline.ts
CHANGED
|
@@ -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:
|
|
38
|
+
update: TimelineEvent<ManagedAtom>,
|
|
57
39
|
timeline: Timeline<TimelineManageable>,
|
|
58
40
|
) => boolean
|
|
59
41
|
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -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`>
|
package/src/main/validators.ts
CHANGED
|
@@ -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
|
|
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
|
-
:
|
|
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<
|
|
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
|
/>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
AtomToken,
|
|
3
|
+
AtomUpdateEvent,
|
|
4
|
+
TimelineEvent,
|
|
5
|
+
TransactionOutcomeEvent,
|
|
6
|
+
TransactionToken,
|
|
5
7
|
} from "atom.io"
|
|
6
|
-
import type { Fn } from "atom.io/internal"
|
|
7
8
|
import { discoverType, prettyJson } from "atom.io/introspection"
|
|
8
9
|
import { stringifyJson } from "atom.io/json"
|
|
9
10
|
import * as React from "react"
|
|
@@ -12,11 +13,11 @@ import * as React from "react"
|
|
|
12
13
|
|
|
13
14
|
const AtomUpdateFC: React.FC<{
|
|
14
15
|
serialNumber: number
|
|
15
|
-
atomUpdate:
|
|
16
|
+
atomUpdate: AtomUpdateEvent<AtomToken<unknown>>
|
|
16
17
|
}> = ({ atomUpdate }) => {
|
|
17
18
|
return (
|
|
18
19
|
<article
|
|
19
|
-
key={atomUpdate.key}
|
|
20
|
+
key={atomUpdate.token.key}
|
|
20
21
|
className="node atom_update"
|
|
21
22
|
onClick={() => {
|
|
22
23
|
console.log(atomUpdate)
|
|
@@ -25,10 +26,15 @@ const AtomUpdateFC: React.FC<{
|
|
|
25
26
|
console.log(atomUpdate)
|
|
26
27
|
}}
|
|
27
28
|
>
|
|
28
|
-
<span className="detail">{atomUpdate.key}: </span>
|
|
29
|
+
<span className="detail">{atomUpdate.token.key}: </span>
|
|
29
30
|
<span>
|
|
30
31
|
<span className="summary">
|
|
31
|
-
{
|
|
32
|
+
{
|
|
33
|
+
prettyJson.diff(
|
|
34
|
+
atomUpdate.update.oldValue,
|
|
35
|
+
atomUpdate.update.newValue,
|
|
36
|
+
).summary
|
|
37
|
+
}
|
|
32
38
|
</span>
|
|
33
39
|
</span>
|
|
34
40
|
</article>
|
|
@@ -37,12 +43,12 @@ const AtomUpdateFC: React.FC<{
|
|
|
37
43
|
|
|
38
44
|
const TransactionUpdateFC: React.FC<{
|
|
39
45
|
serialNumber: number
|
|
40
|
-
transactionUpdate:
|
|
46
|
+
transactionUpdate: TransactionOutcomeEvent<TransactionToken<any>>
|
|
41
47
|
}> = ({ serialNumber, transactionUpdate }) => {
|
|
42
48
|
return (
|
|
43
49
|
<article
|
|
44
50
|
className="node transaction_update"
|
|
45
|
-
data-testid={`transaction-update-${transactionUpdate.key}-${serialNumber}`}
|
|
51
|
+
data-testid={`transaction-update-${transactionUpdate.token.key}-${serialNumber}`}
|
|
46
52
|
>
|
|
47
53
|
<header>
|
|
48
54
|
<h4>{serialNumber}</h4>
|
|
@@ -88,31 +94,30 @@ const TransactionUpdateFC: React.FC<{
|
|
|
88
94
|
</section>
|
|
89
95
|
<section className="transaction_impact">
|
|
90
96
|
<span className="detail">impact: </span>
|
|
91
|
-
{transactionUpdate.
|
|
97
|
+
{transactionUpdate.subEvents
|
|
92
98
|
.filter(
|
|
93
|
-
(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
!token.key.startsWith(`👁🗨`),
|
|
99
|
+
(txSubEvent) =>
|
|
100
|
+
txSubEvent.type !== `molecule_creation` &&
|
|
101
|
+
txSubEvent.type !== `molecule_disposal` &&
|
|
102
|
+
txSubEvent.type !== `molecule_transfer` &&
|
|
103
|
+
txSubEvent.type !== `state_creation` &&
|
|
104
|
+
txSubEvent.type !== `state_disposal` &&
|
|
105
|
+
!txSubEvent.token.key.startsWith(`👁🗨`),
|
|
100
106
|
)
|
|
101
107
|
.map((update, index) => {
|
|
102
108
|
switch (update.type) {
|
|
103
109
|
case `atom_update`:
|
|
104
|
-
case `selector_update`:
|
|
105
110
|
return (
|
|
106
111
|
<article.AtomUpdate
|
|
107
|
-
key={`${transactionUpdate.key}:${index}:${update.key}`}
|
|
112
|
+
key={`${transactionUpdate.token.key}:${index}:${update.token.key}`}
|
|
108
113
|
serialNumber={index}
|
|
109
114
|
atomUpdate={update}
|
|
110
115
|
/>
|
|
111
116
|
)
|
|
112
|
-
case `
|
|
117
|
+
case `transaction_outcome`:
|
|
113
118
|
return (
|
|
114
119
|
<TransactionUpdateFC
|
|
115
|
-
key={`${transactionUpdate.key}:${index}:${update.key}`}
|
|
120
|
+
key={`${transactionUpdate.token.key}:${index}:${update.token.key}`}
|
|
116
121
|
serialNumber={index}
|
|
117
122
|
transactionUpdate={update}
|
|
118
123
|
/>
|
|
@@ -132,49 +137,50 @@ const TransactionUpdateFC: React.FC<{
|
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
export const TimelineUpdateFC: React.FC<{
|
|
135
|
-
timelineUpdate:
|
|
140
|
+
timelineUpdate: TimelineEvent<any>
|
|
136
141
|
serialNumber: number
|
|
137
142
|
}> = ({ timelineUpdate, serialNumber }) => {
|
|
138
|
-
return `
|
|
143
|
+
return timelineUpdate.type === `atom_update` ||
|
|
144
|
+
timelineUpdate.type === `selector_update` ||
|
|
145
|
+
timelineUpdate.type === `transaction_outcome` ? (
|
|
139
146
|
<article
|
|
140
147
|
className="node timeline_update"
|
|
141
|
-
data-testid={`timeline-update-${typeof timelineUpdate.key === `string` ? timelineUpdate.key : stringifyJson(timelineUpdate.key)}-${serialNumber}`}
|
|
148
|
+
data-testid={`timeline-update-${typeof timelineUpdate.token.key === `string` ? timelineUpdate.token.key : stringifyJson(timelineUpdate.token.key)}-${serialNumber}`}
|
|
142
149
|
>
|
|
143
150
|
<header>
|
|
144
151
|
<h4>
|
|
145
|
-
{timelineUpdate.timestamp}: {timelineUpdate.type} (
|
|
146
|
-
)
|
|
152
|
+
{timelineUpdate.timestamp}: {timelineUpdate.type} (
|
|
153
|
+
{timelineUpdate.token.key})
|
|
147
154
|
</h4>
|
|
148
155
|
</header>
|
|
149
156
|
<main>
|
|
150
|
-
{timelineUpdate.type === `
|
|
151
|
-
timelineUpdate.
|
|
157
|
+
{timelineUpdate.type === `transaction_outcome` ? (
|
|
158
|
+
timelineUpdate.subEvents
|
|
152
159
|
.filter(
|
|
153
|
-
(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
!token.key.startsWith(`👁🗨`),
|
|
160
|
+
(subEvent) =>
|
|
161
|
+
subEvent.type !== `molecule_creation` &&
|
|
162
|
+
subEvent.type !== `molecule_disposal` &&
|
|
163
|
+
subEvent.type !== `molecule_transfer` &&
|
|
164
|
+
subEvent.type !== `state_creation` &&
|
|
165
|
+
subEvent.type !== `state_disposal` &&
|
|
166
|
+
!subEvent.token.key.startsWith(`👁🗨`),
|
|
160
167
|
)
|
|
161
|
-
.map((
|
|
162
|
-
switch (
|
|
168
|
+
.map((subEvent, index) => {
|
|
169
|
+
switch (subEvent.type) {
|
|
163
170
|
case `atom_update`:
|
|
164
|
-
case `selector_update`:
|
|
165
171
|
return (
|
|
166
172
|
<article.AtomUpdate
|
|
167
|
-
key={`${timelineUpdate.key}:${index}:${
|
|
173
|
+
key={`${timelineUpdate.token.key}:${index}:${subEvent.token.key}`}
|
|
168
174
|
serialNumber={index}
|
|
169
|
-
atomUpdate={
|
|
175
|
+
atomUpdate={subEvent}
|
|
170
176
|
/>
|
|
171
177
|
)
|
|
172
|
-
case `
|
|
178
|
+
case `transaction_outcome`:
|
|
173
179
|
return (
|
|
174
180
|
<TransactionUpdateFC
|
|
175
|
-
key={`${timelineUpdate.key}:${index}:${
|
|
181
|
+
key={`${timelineUpdate.token.key}:${index}:${subEvent.token.key}`}
|
|
176
182
|
serialNumber={index}
|
|
177
|
-
transactionUpdate={
|
|
183
|
+
transactionUpdate={subEvent}
|
|
178
184
|
/>
|
|
179
185
|
)
|
|
180
186
|
case `molecule_creation`:
|
|
@@ -187,11 +193,13 @@ export const TimelineUpdateFC: React.FC<{
|
|
|
187
193
|
})
|
|
188
194
|
) : timelineUpdate.type === `selector_update` ? (
|
|
189
195
|
timelineUpdate.atomUpdates
|
|
190
|
-
.filter(
|
|
196
|
+
.filter(
|
|
197
|
+
(atomUpdateEvent) => !atomUpdateEvent.token.key.startsWith(`👁🗨`),
|
|
198
|
+
)
|
|
191
199
|
.map((atomUpdate, index) => {
|
|
192
200
|
return (
|
|
193
201
|
<article.AtomUpdate
|
|
194
|
-
key={`${timelineUpdate.key}:${index}:${atomUpdate.key}`}
|
|
202
|
+
key={`${timelineUpdate.token.key}:${index}:${atomUpdate.token.key}`}
|
|
195
203
|
serialNumber={index}
|
|
196
204
|
atomUpdate={atomUpdate}
|
|
197
205
|
/>
|