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
|
@@ -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
|
-
}
|