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.
- 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 +544 -507
- 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 +14 -14
- package/src/internal/atom/dispose-atom.ts +5 -4
- package/src/internal/caching.ts +3 -3
- 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 +16 -29
- 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,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
|
/>
|
|
@@ -19,13 +19,23 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
19
19
|
store: Store,
|
|
20
20
|
continuityKey: string,
|
|
21
21
|
socket: Socket,
|
|
22
|
-
optimisticUpdates: AtomIO.
|
|
23
|
-
|
|
22
|
+
optimisticUpdates: AtomIO.TransactionOutcomeEvent<
|
|
23
|
+
AtomIO.TransactionToken<Fn>
|
|
24
|
+
>[],
|
|
25
|
+
confirmedUpdates: AtomIO.TransactionOutcomeEvent<
|
|
26
|
+
AtomIO.TransactionToken<Fn>
|
|
27
|
+
>[],
|
|
24
28
|
) =>
|
|
25
|
-
(
|
|
29
|
+
(
|
|
30
|
+
confirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,
|
|
31
|
+
): void => {
|
|
26
32
|
function reconcileEpoch(
|
|
27
|
-
optimisticUpdate: AtomIO.
|
|
28
|
-
|
|
33
|
+
optimisticUpdate: AtomIO.TransactionOutcomeEvent<
|
|
34
|
+
AtomIO.TransactionToken<Fn>
|
|
35
|
+
>,
|
|
36
|
+
confirmedUpdate: AtomIO.TransactionOutcomeEvent<
|
|
37
|
+
AtomIO.TransactionToken<Fn>
|
|
38
|
+
>,
|
|
29
39
|
): void {
|
|
30
40
|
store.logger.info(
|
|
31
41
|
`🧑⚖️`,
|
|
@@ -38,8 +48,8 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
38
48
|
return queue
|
|
39
49
|
})
|
|
40
50
|
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
41
|
-
const clientResult = JSON.stringify(optimisticUpdate.
|
|
42
|
-
const serverResult = JSON.stringify(confirmedUpdate.
|
|
51
|
+
const clientResult = JSON.stringify(optimisticUpdate.subEvents)
|
|
52
|
+
const serverResult = JSON.stringify(confirmedUpdate.subEvents)
|
|
43
53
|
if (clientResult === serverResult) {
|
|
44
54
|
store.logger.info(
|
|
45
55
|
`✅`,
|
|
@@ -56,7 +66,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
56
66
|
`❌`,
|
|
57
67
|
`continuity`,
|
|
58
68
|
continuityKey,
|
|
59
|
-
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`,
|
|
69
|
+
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,
|
|
60
70
|
)
|
|
61
71
|
}
|
|
62
72
|
store.logger.info(
|
|
@@ -99,7 +109,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
99
109
|
for (const subsequentOptimistic of optimisticUpdates) {
|
|
100
110
|
const token = {
|
|
101
111
|
type: `transaction`,
|
|
102
|
-
key: subsequentOptimistic.key,
|
|
112
|
+
key: subsequentOptimistic.token.key,
|
|
103
113
|
} as const
|
|
104
114
|
const { id, params } = subsequentOptimistic
|
|
105
115
|
actUponStore(store, token, id)(...params)
|
|
@@ -188,7 +198,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
188
198
|
`✅`,
|
|
189
199
|
`continuity`,
|
|
190
200
|
continuityKey,
|
|
191
|
-
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`,
|
|
201
|
+
`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,
|
|
192
202
|
)
|
|
193
203
|
ingestTransactionUpdate(`newValue`, confirmed, store)
|
|
194
204
|
socket.emit(`ack:${continuityKey}`, confirmed.epoch)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as AtomIO from "atom.io"
|
|
2
2
|
|
|
3
3
|
export const optimisticUpdateQueue: AtomIO.RegularAtomToken<
|
|
4
|
-
AtomIO.
|
|
5
|
-
> = AtomIO.atom<AtomIO.
|
|
4
|
+
AtomIO.TransactionOutcomeEvent<any>[]
|
|
5
|
+
> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({
|
|
6
6
|
key: `updateQueue`,
|
|
7
7
|
default: () => [],
|
|
8
8
|
})
|
|
9
9
|
|
|
10
10
|
export const confirmedUpdateQueue: AtomIO.RegularAtomToken<
|
|
11
|
-
AtomIO.
|
|
12
|
-
> = AtomIO.atom<AtomIO.
|
|
11
|
+
AtomIO.TransactionOutcomeEvent<any>[]
|
|
12
|
+
> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({
|
|
13
13
|
key: `serverConfirmedUpdateQueue`,
|
|
14
14
|
default: () => [],
|
|
15
15
|
})
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
3
|
import { actUponStore } from "atom.io/internal"
|
|
4
|
-
import type { JsonIO } from "atom.io/json"
|
|
4
|
+
import type { Json, JsonIO } from "atom.io/json"
|
|
5
5
|
import type { ContinuityToken } from "atom.io/realtime"
|
|
6
6
|
|
|
7
7
|
export function prepareToServeTransactionRequest(
|
|
8
8
|
store: Store,
|
|
9
9
|
continuity: ContinuityToken,
|
|
10
10
|
userKey: string,
|
|
11
|
-
): (
|
|
11
|
+
): (
|
|
12
|
+
event: Json.Serializable &
|
|
13
|
+
Pick<
|
|
14
|
+
TransactionOutcomeEvent<TransactionToken<JsonIO>>,
|
|
15
|
+
`id` | `params` | `token`
|
|
16
|
+
>,
|
|
17
|
+
) => void {
|
|
12
18
|
const continuityKey = continuity.key
|
|
13
|
-
return function serveTransactionRequest(
|
|
14
|
-
store.logger.info(`🛎️`, `continuity`, continuityKey, `received`,
|
|
15
|
-
const transactionKey =
|
|
16
|
-
const updateId =
|
|
19
|
+
return function serveTransactionRequest(txOutcome) {
|
|
20
|
+
store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)
|
|
21
|
+
const transactionKey = txOutcome.token.key
|
|
22
|
+
const updateId = txOutcome.id
|
|
17
23
|
const performanceKey = `tx-run:${transactionKey}:${updateId}`
|
|
18
24
|
const performanceKeyStart = `${performanceKey}:start`
|
|
19
25
|
const performanceKeyEnd = `${performanceKey}:end`
|
|
@@ -23,7 +29,7 @@ export function prepareToServeTransactionRequest(
|
|
|
23
29
|
store,
|
|
24
30
|
{ type: `transaction`, key: transactionKey },
|
|
25
31
|
updateId,
|
|
26
|
-
)(...
|
|
32
|
+
)(...txOutcome.params)
|
|
27
33
|
} catch (thrown) {
|
|
28
34
|
if (thrown instanceof Error) {
|
|
29
35
|
store.logger.error(
|
|
@@ -2,13 +2,16 @@ import type { Store } from "atom.io/internal"
|
|
|
2
2
|
import { setIntoStore } from "atom.io/internal"
|
|
3
3
|
import type { ContinuityToken } from "atom.io/realtime"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
ContinuitySyncTransactionUpdate,
|
|
7
|
+
UserKey,
|
|
8
|
+
} from "../realtime-server-stores"
|
|
6
9
|
import { userUnacknowledgedQueues } from "../realtime-server-stores"
|
|
7
10
|
|
|
8
11
|
export function prepareToTrackClientAcknowledgement(
|
|
9
12
|
store: Store,
|
|
10
13
|
continuity: ContinuityToken,
|
|
11
|
-
userKey:
|
|
14
|
+
userKey: UserKey,
|
|
12
15
|
userUnacknowledgedUpdates: ContinuitySyncTransactionUpdate[],
|
|
13
16
|
): (epoch: number) => void {
|
|
14
17
|
const continuityKey = continuity.key
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
|
|
2
2
|
import { actUponStore, IMPLICIT } from "atom.io/internal"
|
|
3
3
|
import type { JsonIO } from "atom.io/json"
|
|
4
4
|
|
|
@@ -10,10 +10,13 @@ export function realtimeActionReceiver({
|
|
|
10
10
|
store = IMPLICIT.STORE,
|
|
11
11
|
}: ServerConfig) {
|
|
12
12
|
return function actionReceiver<F extends JsonIO>(
|
|
13
|
-
tx:
|
|
13
|
+
tx: TransactionToken<F>,
|
|
14
14
|
): () => void {
|
|
15
15
|
const fillTransactionRequest = (
|
|
16
|
-
update: Pick<
|
|
16
|
+
update: Pick<
|
|
17
|
+
TransactionOutcomeEvent<TransactionToken<F>>,
|
|
18
|
+
`id` | `params`
|
|
19
|
+
>,
|
|
17
20
|
) => {
|
|
18
21
|
const performanceKey = `tx-run:${tx.key}:${update.id}`
|
|
19
22
|
const performanceKeyStart = `${performanceKey}:start`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
RegularAtomFamilyToken,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
TransactionOutcomeEvent,
|
|
4
|
+
TransactionSubEvent,
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
import { atomFamily } from "atom.io"
|
|
7
7
|
|
|
@@ -17,20 +17,19 @@ import type { UserKey } from "./server-user-store"
|
|
|
17
17
|
|
|
18
18
|
export function redactTransactionUpdateContent(
|
|
19
19
|
visibleStateKeys: string[],
|
|
20
|
-
updates:
|
|
21
|
-
):
|
|
20
|
+
updates: TransactionSubEvent[],
|
|
21
|
+
): TransactionSubEvent[] {
|
|
22
22
|
return updates
|
|
23
|
-
.map((update):
|
|
23
|
+
.map((update): TransactionSubEvent => {
|
|
24
24
|
switch (update.type) {
|
|
25
|
-
case `
|
|
25
|
+
case `transaction_outcome`: {
|
|
26
26
|
const redacted = redactTransactionUpdateContent(
|
|
27
27
|
visibleStateKeys,
|
|
28
|
-
update.
|
|
28
|
+
update.subEvents,
|
|
29
29
|
)
|
|
30
|
-
return { ...update,
|
|
30
|
+
return { ...update, subEvents: redacted }
|
|
31
31
|
}
|
|
32
32
|
case `atom_update`:
|
|
33
|
-
case `selector_update`:
|
|
34
33
|
case `molecule_creation`:
|
|
35
34
|
case `molecule_disposal`:
|
|
36
35
|
case `molecule_transfer`:
|
|
@@ -42,13 +41,11 @@ export function redactTransactionUpdateContent(
|
|
|
42
41
|
.filter((update) => {
|
|
43
42
|
switch (update.type) {
|
|
44
43
|
case `atom_update`:
|
|
45
|
-
case `selector_update`:
|
|
46
|
-
return visibleStateKeys.includes(update.key)
|
|
47
44
|
case `state_creation`:
|
|
48
45
|
case `state_disposal`:
|
|
49
46
|
return visibleStateKeys.includes(update.token.key)
|
|
50
47
|
case `molecule_creation`:
|
|
51
|
-
case `
|
|
48
|
+
case `transaction_outcome`:
|
|
52
49
|
case `molecule_disposal`:
|
|
53
50
|
case `molecule_transfer`:
|
|
54
51
|
return true
|
|
@@ -58,12 +55,12 @@ export function redactTransactionUpdateContent(
|
|
|
58
55
|
|
|
59
56
|
export const redactorAtoms: RegularAtomFamilyToken<
|
|
60
57
|
{
|
|
61
|
-
occlude: (updates:
|
|
58
|
+
occlude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]
|
|
62
59
|
},
|
|
63
60
|
UserKey
|
|
64
61
|
> = atomFamily<
|
|
65
62
|
{
|
|
66
|
-
occlude: (updates:
|
|
63
|
+
occlude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]
|
|
67
64
|
},
|
|
68
65
|
UserKey
|
|
69
66
|
>({
|
|
@@ -89,8 +86,8 @@ export const redactorAtoms: RegularAtomFamilyToken<
|
|
|
89
86
|
// })
|
|
90
87
|
|
|
91
88
|
export type ContinuitySyncTransactionUpdate = Pick<
|
|
92
|
-
|
|
93
|
-
`epoch` | `id` | `
|
|
89
|
+
TransactionOutcomeEvent<any>,
|
|
90
|
+
`epoch` | `id` | `output` | `subEvents` | `token`
|
|
94
91
|
>
|
|
95
92
|
export const userUnacknowledgedQueues: RegularAtomFamilyToken<
|
|
96
93
|
ContinuitySyncTransactionUpdate[],
|
package/src/web/persist-sync.ts
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { StateUpdate } from "atom.io"
|
|
2
|
-
|
|
3
|
-
import type { Atom, Selector, Store } from ".."
|
|
4
|
-
|
|
5
|
-
export const emitUpdate = <T>(
|
|
6
|
-
store: Store,
|
|
7
|
-
state: Atom<T> | Selector<T>,
|
|
8
|
-
update: StateUpdate<T>,
|
|
9
|
-
): void => {
|
|
10
|
-
switch (state.type) {
|
|
11
|
-
case `mutable_atom`:
|
|
12
|
-
store.logger.info(
|
|
13
|
-
`📢`,
|
|
14
|
-
state.type,
|
|
15
|
-
state.key,
|
|
16
|
-
`is now (`,
|
|
17
|
-
update.newValue,
|
|
18
|
-
`) subscribers:`,
|
|
19
|
-
state.subject.subscribers,
|
|
20
|
-
)
|
|
21
|
-
break
|
|
22
|
-
case `atom`:
|
|
23
|
-
case `writable_pure_selector`:
|
|
24
|
-
case `readonly_pure_selector`:
|
|
25
|
-
case `writable_held_selector`:
|
|
26
|
-
case `readonly_held_selector`:
|
|
27
|
-
store.logger.info(
|
|
28
|
-
`📢`,
|
|
29
|
-
state.type,
|
|
30
|
-
state.key,
|
|
31
|
-
`went (`,
|
|
32
|
-
update.oldValue,
|
|
33
|
-
`->`,
|
|
34
|
-
update.newValue,
|
|
35
|
-
`) subscribers:`,
|
|
36
|
-
state.subject.subscribers,
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
state.subject.next(update)
|
|
40
|
-
}
|